         Total Annihilation Unit Selector
                   Version 1.0
                by Andrew Griffin 
           (andrew_griffin@bigfoot.com)
                14 November, 1997


Please don't email me if you cannot get this to work - most
likely if you can't it is because you don't have Java 1.1
installed/have stuffed up the installation process.

This program is meant to be of some help to those people
interested in making single player missions (or changing
the original ones). It can be used to change what units can
be built in a single player mission, and takes away the
need to remember the unit abbreviations.
Read the 'What You Can Do With These Files' carefully so
that you don't stuff up - it is very easy to disable the
Commander and then wonder where the hell it is when the
mission starts :)


============
= Java 1.1 =
============
This is a Java 1.1 program, and hence you need the Java 1.1
(or later) runtime environment to use it. Go to the Javasoft
website:
  http://www.javasoft.com/products/jdk/1.1/jre/index.html
and download the JRE package and install that (the latest version
is something like 1.1.4), or the JDK if you are into developing
your own Java stuff.
(Java 1.1 has a much nicer event model than 1.0)
Java 1.1 is definitely worth the download.


Using This Program
==================
The program should start up almost immediately (unless you
have stuffed something up). What you should see are two list
containing all of the CORE and ARM units in the game.
These lists allow you to select multiple items at the same
time (you don't have to do anything fancy to do this, just
click on the ones you want).


Starting the program
====================
What you run depends on whether you have the JRE or the JDK.
If you have the JRE, then you run this program like:
jre unitselect
or 
jrew unitselect

If you have the JDK, you run it like:
java unitselect
or
javaw unitselect

I would recommend making a batch file for this.


The Interface
=============
  Um, pretty easy really - just 2 lists and some menu options.
You click on the menu to select the units you want.

File Menu
---------
  There are 2 commands in the File menu: Save Selection and
Exit.

- Save Selection: When chosen, you get the normal Save dialog
  box. After you have chosen what to call the file, it gets
  written out. 
- Exit: Exits the program

Edit Menu
---------
  There are 5 commands in the Edit menu: Select All ARM Units,
Invert ARM Selection, Select All CORE Units, Invert CORE
Selection, and Clear Both Lists.

- Select All ARM Units: Everything in the list of ARM units
  becomes selected.
- Invert ARM Selection: Currently selected ARM units become
  deselected, and units not currently selected become selected.
- Select All CORE Units: Everything in the list of CORE units
  becomes selected.
- Invert CORE Selection: Currently selected CORE units become
  deselected, and units not currently selected become selected.
- Clear Both Lists: All items in both lists are deselected.


What You Can Do With These Files
================================
  Each single player mission has a .tdf file that determines
which units can be built in that mission. This file is
pointed to in the 'useonlyunits' line of the mission's .ota
file.

  The .tdf files pointed to by this line are stored in the
/camps/useonly directory in your TA directory (you have to
make these new directories). Then you simply have to put your
new .tdf file that you created with this program into this
directory, and it will get used (provided that you have given
it the correct name).

  Although you can easilly change the 'useonlyunits' line in the
.ota file, it is much easier to just give your new .tdf file a
name such that it will be used in place of one of the original
mission .tdf files. The filenames have a very easy format, which
is simply:
for ARM missions   -  ac??.tdf where ?? is the mission number,
  from 01 to 25.
for CORE missions  -  cc??.tdf where ?? is the mission number,
  from 01 to 25.

  What you have to be aware of is that not only do these files
control what you can build, but they also control what appears
on the map at the start of the mission. So, when you have placed
the units in your single player mission (however you do that), you
need to also activate them in this file. If you have placed a unit
on the map, but it doesn't appear in this file, then it will
not appear in the game! Take care that you don't leave anything
out.


Including New Units
===================
  When Cavedog start releasing new units, they can very easilly
be added to the lists, simply by editing the unitsel.ini file.
You can add (or delete) stuff from each of the lists very
easilly. You can even determine how many items will appear on
the list at the same time.
  Read the unitsel.ini file to see how to do this.


blackmane
(Andrew Griffin)
http://www.geocities.com/TimesSquare/5458


Java programming tip of the day:
When doing the invert function for the lists, you need to
do a single 'if' statement in the for loop to check whether
each item in the list is currently active. It makes the most
sense (and is easiest) to just do a isIndexSelected(int) call
for that item. However, this is very slow (relatively, anyway).
What you want to do is a small amount of work beforehand, and
create an array of booleans. Then do a getSelectedIndexes()
to create an array of ints, and do a simple loop populating
the booleans with relevant trues. Then, when it comes to the
'if' statement, you are just checking this array of booleans
rather than doing a call to isIndexSelected. It is also a good
idea to do a setVisible(false) on the lists when doing this.
Likewise with filling a TextArea, it speeds it up immensely by
setting visible to false and then back again after the operation.

Here's the code for my invert function:
// note that while it is much easier just to use a
// single call to isIndexSelected for the if{} rather
// than setting up the used[] array, it is also very slow.
// Using the used[] array makes this basically as fast
// as the selectAll function, despite the added initialisation
// overhead.
// I wasn't sure whether the booleans get set to 0 upon
// creation, but it is best to be safe than sorry. num is
// unnecessary as you can get the number of items from the
// List itseld, but I didn't do it that way :)
void invertAll(List list, int num)
{
  int i;
  boolean used[] = new boolean[num];
  int temp[] = list.getSelectedIndexes();
  for (i=0; i<num; i++)
    used[i] = false;
  for (i=0; i<temp.length; i++)
    used[temp[i]] = true;
  list.setVisible(false);
  for (i=0; i<num; i++)
  {
    if (used[i])
    //if (list.isIndexSelected(i))
    list.deselect(i);
  else
    list.select(i);
  }
  list.setVisible(true);
}

