com.pegacat.vcf.data
Class Unit

java.lang.Object
  |
  +--com.pegacat.vcf.data.VoyagerObject
        |
        +--com.pegacat.vcf.data.Unit

public class Unit
extends VoyagerObject

A Unit in Voyager - can be any civilian/military/space unit. A voyager 'thing', rather than a location. Any thing which can be (theoretically!) moved from one place to another.

contains a 3D location, name, system/world location (or equivalently, last location visited for units in warp)

This class can be subclassed for specific units.

Note that this class has a large number of static methods that allow access to particular objects.


Field Summary
protected static java.util.Vector allUnits
           
protected  java.lang.String exactType
          the type name of the unit (e.g.
protected  int id
          the unit's unique i.d.
protected static Unit[] idArray
          A fast look up array of all units by id number.
protected  java.lang.String unitType
          the unit type (e.g.
protected static java.util.HashMap unitVectors
          the poor mans database :
a list of all the vectors that hold pointers to the various units.
 
Fields inherited from class com.pegacat.vcf.data.VoyagerObject
location, name, text
 
Constructor Summary
Unit(java.lang.String name, VoyagerLocation location, java.lang.String description, java.lang.String unitType, int id, java.lang.String exactType)
           
 
Method Summary
static void addUnit(Unit unit, java.lang.String key)
          This method is used internally to add units to an internal vector array, indexed by a particular key (unit types, world location etc.).
static Unit getID(int id)
           
static java.util.Vector getVector(java.lang.String type)
          Looks up a particular type of object by name, either generically ("SHIPS"), or exact type "TRADE 7".
static void printKey(java.lang.String key)
          Print out a particular Vector of Units, based on a key, for debug purposes...
 java.lang.String toString()
          returns a generic string representation, similar to (But *not* guaranteed to be identical to) the Voyager game representation (e.g.
 
Methods inherited from class com.pegacat.vcf.data.VoyagerObject
getLocation, getName, getNamedPosition, getText, getX, getY, getZ
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected int id
the unit's unique i.d. number

unitType

protected java.lang.String unitType
the unit type (e.g. "Ship" | "REU")

exactType

protected java.lang.String exactType
the type name of the unit (e.g. "Trade 7")

unitVectors

protected static java.util.HashMap unitVectors

the poor mans database :
a list of all the vectors that hold pointers to the various units. A particular unit will be pointed to by four such vectors - the 'all' vector, a 'type' vector, a 'specific type' vector, and a world lookup (by canonical world name). As well as the unit id vector, of course, and a hashmap world lookup. Aargh.


idArray

protected static Unit[] idArray
A fast look up array of all units by id number.

allUnits

protected static java.util.Vector allUnits
Constructor Detail

Unit

public Unit(java.lang.String name,
            VoyagerLocation location,
            java.lang.String description,
            java.lang.String unitType,
            int id,
            java.lang.String exactType)
Method Detail

toString

public java.lang.String toString()
returns a generic string representation, similar to (But *not* guaranteed to be identical to) the Voyager game representation (e.g. SHIP[1999] TRADE 7.
Overrides:
toString in class java.lang.Object

getID

public static Unit getID(int id)

getVector

public static java.util.Vector getVector(java.lang.String type)

Looks up a particular type of object by name, either generically ("SHIPS"), or exact type "TRADE 7". Note that this is currently case sensitive, and the string passed must be an EXACT minimal match of the type of object required - i.e. same capitalisation, and no excess whitespace. (Basically we're doing a hashmap lookup, and currently I don't want to slow it down with excess string ops.)

The reason for all this is that it allows as yet unknown objects to be looked up, as well as user-named objects. Utility methods are provided to look up standard objects.

Parameters:
type - the name of things to look for, such as "SHIP" or "TRADE 7". Worlds can be looked up by VoyagerLocation, or by string (for the string version, use the 'canonical' form, all lowercase, with a single lead character 'w112b' or 's112'.
Returns:
a vector containing all the objects of that particular type. Note that this will be an empty vector if none have been discovered.

addUnit

public static void addUnit(Unit unit,
                           java.lang.String key)
This method is used internally to add units to an internal vector array, indexed by a particular key (unit types, world location etc.). It might also be used by plugins, but it's not clear why you would need to do this...

printKey

public static void printKey(java.lang.String key)
Print out a particular Vector of Units, based on a key, for debug purposes...