org.gjt.universe
Class FleetBase

java.lang.Object
  |
  +--org.gjt.universe.DBItem
        |
        +--org.gjt.universe.FleetBase
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
FleetStd

public abstract class FleetBase
extends DBItem

Abstract base class for representing a group of ships moving together or stationed in the same location.

Version:
$Id: FleetBase.java,v 1.9 2001/05/21 07:58:38 noordvyk Exp $
See Also:
Serialized Form

Field Summary
private static FleetID currentID
           
private  FleetID ID
           
private  Location location
           
private  java.lang.String name
           
private  CivID owner
           
private  VectorShipID ships
           
 
Constructor Summary
protected FleetBase()
          This method creates the special undefined fleet.
protected FleetBase(CivID AID, java.lang.String in_name, Location loc)
          This method is the designated constructor for instances of this class.
 
Method Summary
 void addShip(ShipID HID)
          This method adds the ship with the given unique ID to the fleet, removing it from any other fleet to which it might have previously belonged.
protected  void announceCreation()
          This method announces, via a notification posted on the default notification center that the instance exists.
 boolean colonize(PlanetID PID)
          This method causes the receiving fleet to attempt to colonize the planet with the given ID using one of the colonization ships present in the fleet.
 FleetID getID()
          This method returns the unique ID of the fleet.
static FleetID getID(java.lang.String in_name)
          This method looks up a fleet by its name.
 Index getIndex()
          This method is present for compatibility reasons.
 Location getLocation()
          This method returns the current location of the fleet.
 java.lang.String getName()
          Returns the name of the fleet that should be shown in the UI
 CivID getOwner()
           
 VectorShipID getShips()
          This method returns a vector containing the IDs all of the ships in the fleet.
 int getSize()
          Returns the number of ships in the fleet.
 SpeedBase getSpeed()
          This method returns the speed of the fleet.
 boolean isColonizable()
          This method returns true if one or more of the ships in the fleet is capable of creating a colony.
 boolean move(Location destination)
          This method moves the fleet to the specified location.
 void removeShip(ShipID HID)
          This method removes the ship with the given ID from the fleet.
 void setLocation(Location newValue)
          This method sets the current location of the fleet.
 void setName(java.lang.String new_name)
          Sets the name of the fleet that should be shown in the UI.
 boolean transitWormhole(Wormhole wormhole)
          This method transits the fleet through the specified wormhole through the end-point at the current location and though to the star system on the other side.
 
Methods inherited from class org.gjt.universe.DBItem
specificDisplayDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentID

private static FleetID currentID

ID

private FleetID ID

owner

private CivID owner

name

private java.lang.String name

ships

private VectorShipID ships

location

private Location location
Constructor Detail

FleetBase

protected FleetBase(CivID AID,
                    java.lang.String in_name,
                    Location loc)
This method is the designated constructor for instances of this class. The new instance will be added to the master list of fleets in the game. The created instance will be owned by the given civ, have the given name, and be at the given location.

Parameters:
AID - The unique ID of the civ who owns the fleet.
in_name - The name of the fleet (as shown in the UI)
loc - The initial location of the fleet.

FleetBase

protected FleetBase()
This method creates the special undefined fleet. Other subclasses should use the designated constructor instead.

Method Detail

announceCreation

protected void announceCreation()
This method announces, via a notification posted on the default notification center that the instance exists. Final subclasses should call this as the last step of their constructors, when they are ready to be accessed. This is done this way rather than simply performing the announcement in one of the constructors of FleetBase in order to allow the subclass to ensure that it is in a sane state before being accessed by observers.


getID

public FleetID getID()
This method returns the unique ID of the fleet.


getIndex

public Index getIndex()
This method is present for compatibility reasons. It simply returns the unique ID of the fleet.

Specified by:
getIndex in class DBItem

getID

public static FleetID getID(java.lang.String in_name)
This method looks up a fleet by its name. Since the name of a fleet is not guaranteed to be unique, it is not guaranteed which instance will be returned in the event of a duplicate.


getName

public java.lang.String getName()
Returns the name of the fleet that should be shown in the UI

Specified by:
getName in class DBItem

setName

public void setName(java.lang.String new_name)
Sets the name of the fleet that should be shown in the UI. The change will be announced via a NAME_CHANGED FleetNotification.


getOwner

public CivID getOwner()
Overrides:
getOwner in class DBItem

getLocation

public Location getLocation()
This method returns the current location of the fleet.

Overrides:
getLocation in class DBItem

setLocation

public void setLocation(Location newValue)
This method sets the current location of the fleet. If the new location is non-null (i.e. the fleet isn't simply being eliminated), that a MOVE fleet notification will be posted to inform interested parties of the change. This method will inform any planets and systems where the fleet was or now is of the change so that they can update their fleet lists.

Parameters:
newValue - The new location of the fleet.

getShips

public VectorShipID getShips()
This method returns a vector containing the IDs all of the ships in the fleet.


addShip

public void addShip(ShipID HID)
This method adds the ship with the given unique ID to the fleet, removing it from any other fleet to which it might have previously belonged. The increase in ships will be announced via a SHIPS_CHANGED FleetNotificaiton.

Parameters:
HID - The ID of the ship to be inserted.

removeShip

public void removeShip(ShipID HID)
This method removes the ship with the given ID from the fleet. If this leaves the fleet with no ships, the fleet itself will cease to exist. The reduction in ships will be announced via a SHIPS_CHANGED FleetNotificaiton, unless the fleet is eliminated, in which case an ELIMINATED notificaiton will be posted instead.

Parameters:
HID - The unique ID of the ship to be removed from the fleet.

getSize

public int getSize()
Returns the number of ships in the fleet.


getSpeed

public SpeedBase getSpeed()
This method returns the speed of the fleet. The speed of a fleet will be the speed of the slowest ship.


move

public boolean move(Location destination)
This method moves the fleet to the specified location. Speed of the fleet is taken into consideration when moving. A return value of true indicates that the move has moved to its final destination.


transitWormhole

public boolean transitWormhole(Wormhole wormhole)
This method transits the fleet through the specified wormhole through the end-point at the current location and though to the star system on the other side. This method will only succeed if one of the wormhole's current end-points is actually at the fleet's current location. Thus if the wormhole end-point has oscillated away, the fleet will not do anthing. If successful and the wormhole is unstable, this method will handle adjusting the structural integrity of the wormhole to reflect the stress of transit by the fleet. This in turn may cause the wormhole to collapse behind the fleet.

Parameters:
wormhole - The wormhole to be transited.
Returns:
True if the transit was successful and false otherwise.

isColonizable

public boolean isColonizable()
This method returns true if one or more of the ships in the fleet is capable of creating a colony.


colonize

public boolean colonize(PlanetID PID)
This method causes the receiving fleet to attempt to colonize the planet with the given ID using one of the colonization ships present in the fleet. If the receiving fleet has no colonization vessels, then this method will fail. Otherwise, the selected colonization vessel is eliminated (it is dissembled and its components used to construct the new colony). If the colony ship was the last vessel in the fleet, the fleet will be eliminated. This method returns true if a colony was successfully created and false otherwise.

Parameters:
PID - The unique ID of the planet to be colonized.


Copyright © 2001 Universe Dev Team All Rights Reserved.