netwar.game
Class GameObject

java.lang.Object
  |
  +--netwar.game.GameObject
Direct Known Subclasses:
Base, Unit

public abstract class GameObject
extends java.lang.Object

Abstract class to define a GameObject. This defines any object which:
occupies at least one Hex,
has vertical aspects (it isn't flat at z = 0),
(optionally) can be destroyed by weapons,
(optionally) has a weapon.

Author:
Group N2 - Project Netwar, Daniel Grund

Field Summary
protected  int action
          Code number indicating the animation sequence in progress.
 SelfSortingMutualDistanceSquared firstSSMDS
          The head of the linked list which provides the distanceSquared and Point3D offset from this GameObject to each other GameObject, sorted from closest to farthest.
protected  int frame
          The number of frames remaining until this animation sequence is completed.
protected static Vector GameObjects
          Vector of GameObjects containing all currently active GameObjects.
protected  int goalX
          X part of the hex coord of the long term goal.
protected  int goalY
          Y part of the hex coord of the long term goal.
protected  int mode
          Code number indicating the long term goal set by this object.
protected  int myID
          The ID number of this GameObject.
protected  Player myPlayer
          The Player who owns this game Object.
protected  int reload
          The number of frames remaining until the primary weapon is reloaded.
protected  GameObject target
          The GameObject which is being pursued and/or shot at by this GameObject.
protected  SelfSortingMutualDistanceSquared targetSSMDS
          The SSMDS which provides distanceSquared and offset data for the target.
protected  Point3D[] vr
          Point3d's for locations within the hex.
protected  int x
          X part of current hex coordinate.
protected  int y
          Y part of current hex coordinate
 
Constructor Summary
GameObject()
           
 
Method Summary
protected abstract  boolean aim()
          If a turret is available, rotate it toward the target.
protected abstract  void animateDie()
          Perform the data changes for one frame of animation while dying.
protected abstract  void animateMake()
          Perform the data changes for one frame of animation while being made.
 void center()
          Cause the HexViewer's view to be centered on this GameObject.
protected  void createVectors()
          Initialize the Point3Ds used for this Base.
 boolean damageable()
          Return true if an explosion can possibly damage this object.
abstract  void draw(GameViewer v)
          Draw this GameObject onto GameViewer v, by using v's drawing methods.
protected  boolean fire()
          Attempt to fire a shot at the target.
protected abstract  int framesToDie()
          Returns the number of frames of animation for the death sequence.
protected abstract  int framesToMake()
          Returns the number of frames of animation for the creation sequence.
abstract  float getHeight()
          Return the height of this GameObject for selection box and explosion hit calculations.
 int getID()
          Accessor for ID.
 java.awt.Color getMinimapColor()
          Get the Color for displaying this object on the minimap.
static GameObject getObjectWithID(int ID)
          Given an ID number, finds the GameObject with that ID.
 Player getPlayer()
          Accessor for Player
abstract  float getWidth()
          Return the width of this GameObject for selection box and explosion hit calculations.
 boolean isDead()
          Return true if the object is not a valid target for attacks nor following.
 Point3D locate()
          Accessor for vr[0].
static GameObject newGameObject(GameObject u, int startX, int startY, int p, Player team)
          Adds a GameObject into the game at the specified location, on the specified team.
protected  void param(int p)
          Arbitrary initialization.
 void recieveDamage(int dam)
          Apply damage to this object.
protected  void removeMe()
          Removes this GameObject from the game.
protected  GameObject scan()
          GameObject scanner! Finds the nearest living enemy.
 float scanRangeSquared()
          Determines the distance to scan for nearby enemies.
abstract  void setGoal()
          Clear the current long-term goal.
abstract  void setGoal(GameObject u)
          Set the current long-term goal to a GameObject.
abstract  void setGoal(int gx, int gy)
          Set the current long-term goal to a location, at hex coordinate (gx, gy).
protected abstract  void update()
          Perform operations for this time step.
static void updateAll()
          Called by the game cycle update system to cause all GameObjects to perform one time-step of animations and decision making.
abstract  int weaponDelay()
          Return the number of frames to wait between firing shots.
abstract  float weaponRangeSquared()
          Return the square of the maximum weapon range of this GameObject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GameObjects

protected static Vector GameObjects
Vector of GameObjects containing all currently active GameObjects.

myID

protected int myID
The ID number of this GameObject. A GameObject must have an ID so it can be referenced by Commands, which may take some time before they are implemented (so an object may be deleted before then) and will be implemented on all computers involved in the game.

myPlayer

protected Player myPlayer
The Player who owns this game Object. It can be compared for friend-or-foe recognition, and can be accessed to acquire the team color, and other team wide facts.

firstSSMDS

public SelfSortingMutualDistanceSquared firstSSMDS
The head of the linked list which provides the distanceSquared and Point3D offset from this GameObject to each other GameObject, sorted from closest to farthest.

vr

protected Point3D[] vr
Point3d's for locations within the hex. I.e. 0,0,0 is the floor at hex center. vr[0] is a Point3d for where the center of the hex is if the GameObject is currently centered in the hex.

x

protected int x
X part of current hex coordinate.

y

protected int y
Y part of current hex coordinate

action

protected int action
Code number indicating the animation sequence in progress.
0 = only passive animations.
1 = rotating left.
2 = rotating right.
3 = moving forward.
4 = being created.
5 = dying.

frame

protected int frame
The number of frames remaining until this animation sequence is completed.

reload

protected int reload
The number of frames remaining until the primary weapon is reloaded.

mode

protected int mode
Code number indicating the long term goal set by this object.
0 = Wait for orders/watch for targets.
1 = Go to hex whose coordinates are (goalX, goalY).
2 = Pursue GameObject target; try to keep it within followDistance() hexes.

goalX

protected int goalX
X part of the hex coord of the long term goal.

goalY

protected int goalY
Y part of the hex coord of the long term goal.

target

protected GameObject target
The GameObject which is being pursued and/or shot at by this GameObject.

targetSSMDS

protected SelfSortingMutualDistanceSquared targetSSMDS
The SSMDS which provides distanceSquared and offset data for the target.
Constructor Detail

GameObject

public GameObject()
Method Detail

newGameObject

public static GameObject newGameObject(GameObject u,
                                       int startX,
                                       int startY,
                                       int p,
                                       Player team)
Adds a GameObject into the game at the specified location, on the specified team. This performs the following initialization processes:
Assigns a new unique ID number to the GameObject.
Adds the GameObject into the main Vector of GameObjects.
Sets the hex coordinates of the GameObject to those passed to this method.
Calls the param() method of the GameObject, giving it p as the parameter. This allows an arbitrary initialization to take place, which may require an integer.
Calls the CreateVectors() method of the GameObject, which allows the 3D location data to be initialized.
Integrates this GameObject into the SSMDS distance tracking system.
Initializes the animation sequence to the first frame of the creation graphics.
Sets the Player's team to that passed to this method.
Puts the GameObject in the hex identified by the parameters. It is the calling method's responsibility to ensure that the hex is a valid location to make this GameObject.
Parameters:
u - The GameObject to be incorporated into the game.
startX - The X part of the hex coordinate to start the object in.
startY - The Y part of the hex coordinate to start the object in.
p - The parameter for the arbitrary initialization method param().
team - The player which owns this object. May be null, for a neutral object.
Returns:
u, the GameObject which was just incorporated.

removeMe

protected void removeMe()
Removes this GameObject from the game. This involves the following de-integration processes:
Removes this object from the SSMDS tracking system.
Removes this object from the GameObjects Vector.
Removing the object from the Hex reservation system is the responsibility of the calling method.

getObjectWithID

public static GameObject getObjectWithID(int ID)
Given an ID number, finds the GameObject with that ID.
Parameters:
ID - The ID number of the GameObject.
Returns:
The GameObject with that ID, or null if none exists with that ID.

scan

protected GameObject scan()
GameObject scanner! Finds the nearest living enemy. If none is within weapon range, return null Will ignore destroyable neutrals (i.e. breakable obstacles like trees)
Returns:
The nearest living enemy GameObject, or null

getID

public int getID()
Accessor for ID.
Returns:
This GameObject's unique ID number.

getPlayer

public Player getPlayer()
Accessor for Player
Returns:
This GameObject's Player (should be null for neutrals)

locate

public Point3D locate()
Accessor for vr[0].
Returns:
The location of the ground-center of the GameObject, in game-space.

setGoal

public abstract void setGoal()
Clear the current long-term goal.

setGoal

public abstract void setGoal(int gx,
                             int gy)
Set the current long-term goal to a location, at hex coordinate (gx, gy).
Parameters:
gx - The x coordinate of the goal, in hex coords.
gy - The y coordinate of the goal, in hex coords.

setGoal

public abstract void setGoal(GameObject u)
Set the current long-term goal to a GameObject.
Parameters:
u - The GameObject which is the goal.

updateAll

public static void updateAll()
Called by the game cycle update system to cause all GameObjects to perform one time-step of animations and decision making. This calls update() on each GameObject in the GameObjects Vector.

update

protected abstract void update()
Perform operations for this time step. Specifically, perform the Point3D transforms for any/all animations, fire at an enemy if possible, and do any required decision making.

framesToMake

protected abstract int framesToMake()
Returns the number of frames of animation for the creation sequence.
Returns:
The number of frames needed to animate creation.

framesToDie

protected abstract int framesToDie()
Returns the number of frames of animation for the death sequence.
Returns:
The number of frames needed to animate death.

createVectors

protected void createVectors()
Initialize the Point3Ds used for this Base. These are the location of the ground-center of the Base in game-space, and the relative locations of the triangle/line vertices relative to that point.

draw

public abstract void draw(GameViewer v)
Draw this GameObject onto GameViewer v, by using v's drawing methods.
Parameters:
v - The GameViewer which will display this GameObject.
See Also:
HexViewer

animateMake

protected abstract void animateMake()
Perform the data changes for one frame of animation while being made.

animateDie

protected abstract void animateDie()
Perform the data changes for one frame of animation while dying.

getHeight

public abstract float getHeight()
Return the height of this GameObject for selection box and explosion hit calculations.
Returns:
The height of the GameObject in game-space units.

getWidth

public abstract float getWidth()
Return the width of this GameObject for selection box and explosion hit calculations.
Returns:
The width of the GameObject in game-space units.

weaponRangeSquared

public abstract float weaponRangeSquared()
Return the square of the maximum weapon range of this GameObject.
Returns:
The square of the weapons range in game-space units.

scanRangeSquared

public float scanRangeSquared()
Determines the distance to scan for nearby enemies. By default the range is equal to the weapon range. If it is higher, a Unit can detect a distant enemy and close the gap in order to fire.
Returns:
The square of the distance to scan for nearby enemies.

weaponDelay

public abstract int weaponDelay()
Return the number of frames to wait between firing shots.

aim

protected abstract boolean aim()
If a turret is available, rotate it toward the target.
Returns:
true iff the target is within the firing arc.

fire

protected boolean fire()
Attempt to fire a shot at the target.
Returns:
true iff the shot was successfully fired.

param

protected void param(int p)
Arbitrary initialization. Called by newGameObject() with a passed in parameter. param p An integer which may be used or ignored by the GameObject, as needed.

getMinimapColor

public java.awt.Color getMinimapColor()
Get the Color for displaying this object on the minimap. GameObjects are displayed as single pixels on the minimap, so a Color is sufficient to draw them.
Returns:
Unless overridden, this returns Color.orange.darker() for neutrals, Team Color for non-neutrals.

isDead

public boolean isDead()
Return true if the object is not a valid target for attacks nor following. This is always true for indestructable obstacles. Otherwise, it is true only when the Unit/obstacle is destroyed. This is necessary to allow a GameObject to become completely dereferenced.
Returns:
True iff the unit is destroyed or it is both immobile and indestructable.

damageable

public boolean damageable()
Return true if an explosion can possibly damage this object.
Returns:
True iff the object is damageable.

recieveDamage

public void recieveDamage(int dam)
Apply damage to this object. A GameObject can apply its own rules for taking damage. The 'standard' is to track a health integer, which is reduced by (dam - armor) for each hit, with a minimum loss of 1 per hit.
Parameters:
dam - The number of damage points to be inflicted.

center

public void center()
Cause the HexViewer's view to be centered on this GameObject.