cad.simcad.worldsimulator.objects.units
Class MyUnit

java.lang.Object
  |
  +--cad.simcad.worldsimulator.objects.SimulatedObject
        |
        +--cad.simcad.worldsimulator.objects.units.MyUnit
All Implemented Interfaces:
Drawable2DObject, PathUser, java.io.Serializable, SimObject
Direct Known Subclasses:
Ambulance, Car, Villager

public abstract class MyUnit
extends SimulatedObject
implements PathUser, Drawable2DObject

Version:
1.0
Author:
Charles-Philip Bentley
See Also:
Serialized Form

Field Summary
protected  double _baseTurnIncrement
           
protected  double _boundingRadius
           
protected  PathPlace _pp
           
protected  PathPlace _previousOne
           
protected  boolean _recomputing
           
protected  double _savedMovPoints
           
protected  int _state
          state for the move method
protected  UnitControler _uc
           
protected  UnitMediator _um
           
protected  int _velocity
           
static int IncrementWaypoint
           
static int ReachedGoal
           
static int WaitingForPath
           
 
Fields inherited from class cad.simcad.worldsimulator.objects.SimulatedObject
_am, _className, _height, _id, _name, _om, _owner, _serial, _sime, _stateId, _width
 
Constructor Summary
MyUnit(SimEnvironment sime, PathPlace current, UnitMediator um, Owner owner, java.lang.String className)
          Creates new Unit on a Map A unit has the following properties 1) It belongs to a Map, on which it is has a position 2) the position on that map 3) Owner 4) it is waiting to a Path
 
Method Summary
 void debug(java.lang.String msg, int lvl)
           
 void firePathComputed(PathPlaceSet path)
          Notice the PathUser that a Path has been computed for him.
 double getBoundingCircleRadius()
          This allows to ask the radius of the objects bounding circle.
 PathPlace getCurrentPathPlace()
          Return the current PathPlace the PathUser is on
 int getHeight()
          Return the y height of the object
 java.awt.Color getMiniMapColor()
          Return the Color for a totally zoomed out view
 java.lang.String getObjectType()
          Return the Type of the SimObject
 Owner getOwner()
           
 UnitControler getUnitControler()
           
 int getVelocity()
          Here the velocity of an object can be asked.
 int getWidth()
          Return the x width of the object
 int getX()
          Return the X coordinate where the object should be drawn
 int getY()
          Return the Y coordinate where the object should be drawn
 boolean isCollision(PathPlace mp)
          Returns true if the Unit goes in collision if it moves on the PathPlace mp
 void move()
          Top of movement state loop: { If we're in IncrementWaypoint state: Increment our waypoint.
 void resolveNewMove(PathPlace m)
          the map place that couldn't be reached
 void setState(int i)
           
 void setVelocity(int value)
          To change the velocity of an object.
 void stopObject()
          Stop the object activity
 void stopUnit()
           
 void takeTurn()
          This method returns the object name.
protected  void updateStateId(PathPlace from, PathPlace to)
           
 
Methods inherited from class cad.simcad.worldsimulator.objects.SimulatedObject
getClassName, getId, getName, getSerialNumber, getStateId, setStateId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cad.simcad.objectserver.spec.pathfinding.PathUser
getDeformFactor, getId, getMaxSteepNessRatio, getName
 

Field Detail

IncrementWaypoint

public static final int IncrementWaypoint
See Also:
Constant Field Values

ReachedGoal

public static final int ReachedGoal
See Also:
Constant Field Values

WaitingForPath

public static final int WaitingForPath
See Also:
Constant Field Values

_velocity

protected int _velocity

_state

protected int _state
state for the move method


_boundingRadius

protected double _boundingRadius

_uc

protected UnitControler _uc

_pp

protected PathPlace _pp

_recomputing

protected boolean _recomputing

_um

protected UnitMediator _um

_savedMovPoints

protected double _savedMovPoints

_baseTurnIncrement

protected double _baseTurnIncrement

_previousOne

protected PathPlace _previousOne
Constructor Detail

MyUnit

public MyUnit(SimEnvironment sime,
              PathPlace current,
              UnitMediator um,
              Owner owner,
              java.lang.String className)
Creates new Unit on a Map A unit has the following properties 1) It belongs to a Map, on which it is has a position 2) the position on that map 3) Owner 4) it is waiting to a Path

Method Detail

getCurrentPathPlace

public PathPlace getCurrentPathPlace()
Description copied from interface: PathUser
Return the current PathPlace the PathUser is on

Specified by:
getCurrentPathPlace in interface PathUser
Specified by:
getCurrentPathPlace in class SimulatedObject
Returns:
The current PathPlace, null if the PathUser has no PathPlace set already

getOwner

public Owner getOwner()

getUnitControler

public UnitControler getUnitControler()

move

public void move()
Top of movement state loop: { If we're in IncrementWaypoint state: Increment our waypoint. If we're on a patrol Grab the next waypoint as defined by the patrol direction. Set state to WaitingForPath. Else If we're out of waypoints Set state to ReachedGoal. Else Set state to WaitingForPath. If we're in ReachedGoal state: Make the appropriate notifications (if any). We're done. Stop the walking animation. Exit function. If we're in WaitingForPath state: Find a path and save it. If we could not find one We've failed. Exit function. Calculate the direction we need to head in to get to our desired waypoint. Modify that direction by any limitations such as turn radius. Using that new direction, calculate where we'll end up after this move. If that new position causes a collision Set state to WaitingForPath. Jump back to the top of the loop. Using the current and future position: If we're closer to the waypoint before moving Set state to IncrementWaypoint Go back to top of loop. If we're going to jump over the waypoint during this move Set state to IncrementWaypoint. Break out of loop. } Set the accelerations accordingly. Do the actual move. Set or update any animation hooks that we might have. Update our predicted positions


updateStateId

protected void updateStateId(PathPlace from,
                             PathPlace to)

takeTurn

public void takeTurn()
Description copied from interface: SimObject
This method returns the object name. Name used to be shown

Specified by:
takeTurn in interface SimObject
Returns:
a String object

isCollision

public boolean isCollision(PathPlace mp)
Returns true if the Unit goes in collision if it moves on the PathPlace mp


resolveNewMove

public void resolveNewMove(PathPlace m)
the map place that couldn't be reached


setVelocity

public void setVelocity(int value)
To change the velocity of an object.


getVelocity

public int getVelocity()
Here the velocity of an object can be asked.


getBoundingCircleRadius

public double getBoundingCircleRadius()
This allows to ask the radius of the objects bounding circle.

Specified by:
getBoundingCircleRadius in interface SimObject
Returns:
a double value, the radius of the Bounding circle for this object

firePathComputed

public void firePathComputed(PathPlaceSet path)
Description copied from interface: PathUser
Notice the PathUser that a Path has been computed for him.

Specified by:
firePathComputed in interface PathUser
Parameters:
path - A PathPlaceSet.

setState

public void setState(int i)

getX

public int getX()
Return the X coordinate where the object should be drawn

Specified by:
getX in interface Drawable2DObject

getY

public int getY()
Description copied from interface: Drawable2DObject
Return the Y coordinate where the object should be drawn

Specified by:
getY in interface Drawable2DObject

getHeight

public int getHeight()
Description copied from interface: Drawable2DObject
Return the y height of the object

Specified by:
getHeight in interface Drawable2DObject
Overrides:
getHeight in class SimulatedObject
Returns:
a positive integer value

getWidth

public int getWidth()
Description copied from interface: Drawable2DObject
Return the x width of the object

Specified by:
getWidth in interface Drawable2DObject
Overrides:
getWidth in class SimulatedObject
Returns:
a positive integer value

getMiniMapColor

public java.awt.Color getMiniMapColor()
Description copied from interface: Drawable2DObject
Return the Color for a totally zoomed out view

Specified by:
getMiniMapColor in interface Drawable2DObject

stopUnit

public void stopUnit()

debug

public void debug(java.lang.String msg,
                  int lvl)

getObjectType

public java.lang.String getObjectType()
Description copied from interface: SimObject
Return the Type of the SimObject

Specified by:
getObjectType in interface SimObject
Returns:
A String describing the type of the SimObject (unit, structure)

stopObject

public void stopObject()
Description copied from interface: SimObject
Stop the object activity

Specified by:
stopObject in interface SimObject
Specified by:
stopObject in class SimulatedObject

Logo

With the help of www.sourceforge.net and www.info.ucl.ac.be