rescuecore
Class RescueObject

java.lang.Object
  extended byrescuecore.RescueObject
All Implemented Interfaces:
RescueConstants, java.io.Serializable
Direct Known Subclasses:
Building, Humanoid, Node, River, RiverNode, Road, World

public abstract class RescueObject
extends java.lang.Object
implements RescueConstants, java.io.Serializable

This is the base class for all objects in the simulation environment

See Also:
Serialized Form

Field Summary
protected  int id
          The kernel-assigned id
 
Fields inherited from interface rescuecore.RescueConstants
AGENT_TYPE_AMBULANCE_CENTER, AGENT_TYPE_AMBULANCE_TEAM, AGENT_TYPE_ANY, AGENT_TYPE_ANY_AGENT, AGENT_TYPE_ANY_BUILDING, AGENT_TYPE_ANY_MOBILE, AGENT_TYPE_CIVILIAN, AGENT_TYPE_FIRE_BRIGADE, AGENT_TYPE_FIRE_STATION, AGENT_TYPE_POLICE_FORCE, AGENT_TYPE_POLICE_OFFICE, AK_ACKNOWLEDGE, AK_CLEAR, AK_CONNECT, AK_EXTINGUISH, AK_LOAD, AK_MOVE, AK_RESCUE, AK_REST, AK_SAY, AK_TELL, AK_UNLOAD, BYTE_SIZE, COMMAND_ACKNOWLEDGE, COMMAND_CLEAR, COMMAND_CONNECT, COMMAND_EXTINGUISH, COMMAND_LOAD, COMMAND_MOVE, COMMAND_RESCUE, COMMAND_REST, COMMAND_SAY, COMMAND_TELL, COMMAND_UNLOAD, FIERYNESS_BURNING, FIERYNESS_BURNT_OUT, FIERYNESS_HEATING, FIERYNESS_INFERNO, FIERYNESS_MODERATELY_BURNT, FIERYNESS_NOT_BURNT, FIERYNESS_SLIGHTLY_BURNT, FIERYNESS_VERY_BURNT, GK_CONNECT_ERROR, GK_CONNECT_OK, HEADER_NULL, INT_SIZE, INTERNAL_TYPE_AMBULANCE_CENTER, INTERNAL_TYPE_AMBULANCE_TEAM, INTERNAL_TYPE_ANY_BUILDING, INTERNAL_TYPE_ANY_HUMANOID, INTERNAL_TYPE_ANY_PLATOON, INTERNAL_TYPE_BUILDING, INTERNAL_TYPE_CAR, INTERNAL_TYPE_CIVILIAN, INTERNAL_TYPE_FIRE_BRIGADE, INTERNAL_TYPE_FIRE_STATION, INTERNAL_TYPE_NODE, INTERNAL_TYPE_POLICE_FORCE, INTERNAL_TYPE_POLICE_OFFICE, INTERNAL_TYPE_REFUGE, INTERNAL_TYPE_RIVER, INTERNAL_TYPE_RIVER_NODE, INTERNAL_TYPE_ROAD, INTERNAL_TYPE_WORLD, KA_CONNECT_ERROR, KA_CONNECT_OK, KA_HEAR, KA_SENSE, KG_ACKNOWLEDGE, KG_CONNECT, KG_UPDATE, KS_COMMANDS, KS_CONNECT_ERROR, KS_CONNECT_OK, KS_UPDATE, KV_CONNECT_ERROR, KV_CONNECT_OK, KV_UPDATE, MAX_CENTER_MESSAGES, MAX_EXTINGUISH_DISTANCE, MAX_EXTINGUISH_POWER, MAX_HP, MAX_PLATOON_MESSAGES, MAX_RESCUE_DISTANCE, MAX_WATER, PROPERTY_BLOCK, PROPERTY_BROKENNESS, PROPERTY_BUILDING_APEXES, PROPERTY_BUILDING_AREA_GROUND, PROPERTY_BUILDING_AREA_TOTAL, PROPERTY_BUILDING_ATTRIBUTES, PROPERTY_BUILDING_CODE, PROPERTY_BUILDING_SHAPE_ID, PROPERTY_BURIEDNESS, PROPERTY_CARS_PASS_TO_HEAD, PROPERTY_CARS_PASS_TO_TAIL, PROPERTY_DAMAGE, PROPERTY_DIRECTION, PROPERTY_EDGES, PROPERTY_ENTRANCES, PROPERTY_FIERYNESS, PROPERTY_FLOORS, PROPERTY_HEAD, PROPERTY_HP, PROPERTY_HUMANS_PASS_TO_HEAD, PROPERTY_HUMANS_PASS_TO_TAIL, PROPERTY_IGNITION, PROPERTY_LATITUDE, PROPERTY_LENGTH, PROPERTY_LINES_TO_HEAD, PROPERTY_LINES_TO_TAIL, PROPERTY_LONGITUDE, PROPERTY_MAX, PROPERTY_MEDIAN_STRIP, PROPERTY_NULL, PROPERTY_POCKET_TO_TURN_ACROSS, PROPERTY_POSITION, PROPERTY_POSITION_EXTRA, PROPERTY_POSITION_HISTORY, PROPERTY_REPAIR_COST, PROPERTY_ROAD_KIND, PROPERTY_SHORTCUT_TO_TURN, PROPERTY_SIGNAL, PROPERTY_SIGNAL_TIMING, PROPERTY_STAMINA, PROPERTY_START_TIME, PROPERTY_STRETCHED_LENGTH, PROPERTY_TAIL, PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_INT, PROPERTY_TYPE_INT_ARRAY, PROPERTY_WATER_QUANTITY, PROPERTY_WIDTH, PROPERTY_WIDTH_FOR_WALKERS, PROPERTY_WIND_DIRECTION, PROPERTY_WIND_FORCE, PROPERTY_X, PROPERTY_Y, SAY_LENGTH, SHORT_SIZE, SK_ACKNOWLEDGE, SK_CONNECT, SK_UPDATE, TELL_LENGTH, TYPE_AMBULANCE_CENTER, TYPE_AMBULANCE_TEAM, TYPE_BUILDING, TYPE_CAR, TYPE_CIVILIAN, TYPE_FIRE_BRIGADE, TYPE_FIRE_STATION, TYPE_NODE, TYPE_NULL, TYPE_POLICE_FORCE, TYPE_POLICE_OFFICE, TYPE_REFUGE, TYPE_RIVER, TYPE_RIVER_NODE, TYPE_ROAD, TYPE_WORLD, VK_ACKNOWLEDGE, VK_CONNECT
 
Constructor Summary
protected RescueObject(int type)
          Construct a new RescueObject of a given type
 
Method Summary
 void addPropertyListener(PropertyListener l)
          Add a PropertyListener
static RescueObject decode(java.io.DataInput in, int timestamp)
          Decode a new RescueObject from a buffer and update the pointer
static RescueObject decode(int type, int id, java.io.DataInput in, int timestamp)
          Decode a new RescueObject from a buffer and update the pointer
static RescueObject[] decodeObjects(java.io.DataInput in, int timestamp)
          Decode a set of objects from a buffer.
 boolean equals(java.lang.Object o)
           
protected  void firePropertyChanged(int property, int timestep)
           
 int getID()
          Get this objects id
 int getInternalType()
          Get this objects internal type
 int getLastPropertyUpdate(int property)
          Get the last time a property was updated
protected  java.lang.String getPropertiesString()
          Get a String representation of all this object's properties
 Property getProperty(int property)
           
 boolean getPropertyAsBoolean(int property)
           
 int getPropertyAsInt(int property)
           
 int[] getPropertyAsIntArray(int property)
           
 java.lang.String getPropertyAsString(int property)
           
 int getType()
          Get this objects type
 int hashCode()
           
 boolean isAmbulanceCenter()
          Is this object an ambulance center?
 boolean isAmbulanceTeam()
          Is this object an ambulance team?
 boolean isBuilding()
          Is this object a building?
 boolean isCivilian()
          Is this object a civilian?
 boolean isFireBrigade()
          Is this object a fire brigade?
 boolean isFireStation()
          Is this object a fire station?
 boolean isHumanoid()
          Is this object a humanoid?
 boolean isNode()
          Is this object a node?
 boolean isPoliceForce()
          Is this object a police force?
 boolean isPoliceOffice()
          Is this object a police office?
 boolean isPropertyValueKnown(int property)
          Is the value of a particular property known or assumed?
 boolean isRefuge()
          Is this object a refuge?
 boolean isRoad()
          Is this object a road?
 boolean propertyExists(int property)
          Get all property types known by this object
 void removePropertyListener(PropertyListener l)
          Remove a PropertyListener
 java.lang.String toLongString()
           
 java.lang.String toString()
           
static int typeToInternalType(int type)
          Convert a robocup rescue type into an internal, bitwise type
 void update(java.io.DataInput in, int timestamp)
          Update properties of this object using Objects data from a buffer
 boolean updateProperty(int property, int timestamp, boolean newValue)
          Update the value of a property
 boolean updateProperty(int property, int timestamp, int newValue)
          Update the value of a property
 boolean updateProperty(int property, int timestamp, int[] newValue)
          Update the value of a property
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected int id
The kernel-assigned id

Constructor Detail

RescueObject

protected RescueObject(int type)
Construct a new RescueObject of a given type

Parameters:
type - The type of this object
See Also:
RescueConstants.TYPE_CIVILIAN, RescueConstants.TYPE_FIRE_BRIGADE, RescueConstants.TYPE_AMBULANCE_TEAM, RescueConstants.TYPE_POLICE_FORCE, RescueConstants.TYPE_ROAD, RescueConstants.TYPE_NODE, RescueConstants.TYPE_RIVER, RescueConstants.TYPE_RIVER_NODE, RescueConstants.TYPE_BUILDING, RescueConstants.TYPE_REFUGE, RescueConstants.TYPE_FIRE_STATION, RescueConstants.TYPE_AMBULANCE_CENTER, RescueConstants.TYPE_POLICE_OFFICE, RescueConstants.TYPE_WORLD, RescueConstants.TYPE_CAR
Method Detail

getType

public int getType()
Get this objects type

Returns:
The type of this object
See Also:
RescueConstants.TYPE_CIVILIAN, RescueConstants.TYPE_FIRE_BRIGADE, RescueConstants.TYPE_AMBULANCE_TEAM, RescueConstants.TYPE_POLICE_FORCE, RescueConstants.TYPE_ROAD, RescueConstants.TYPE_NODE, RescueConstants.TYPE_RIVER, RescueConstants.TYPE_RIVER_NODE, RescueConstants.TYPE_BUILDING, RescueConstants.TYPE_REFUGE, RescueConstants.TYPE_FIRE_STATION, RescueConstants.TYPE_AMBULANCE_CENTER, RescueConstants.TYPE_POLICE_OFFICE, RescueConstants.TYPE_WORLD, RescueConstants.TYPE_CAR

getInternalType

public int getInternalType()
Get this objects internal type

Returns:
The internal type of this object
See Also:
RescueConstants.INTERNAL_TYPE_CIVILIAN, RescueConstants.INTERNAL_TYPE_FIRE_BRIGADE, RescueConstants.INTERNAL_TYPE_AMBULANCE_TEAM, RescueConstants.INTERNAL_TYPE_POLICE_FORCE, RescueConstants.INTERNAL_TYPE_CAR, RescueConstants.INTERNAL_TYPE_BUILDING, RescueConstants.INTERNAL_TYPE_REFUGE, RescueConstants.INTERNAL_TYPE_FIRE_STATION, RescueConstants.INTERNAL_TYPE_POLICE_OFFICE, RescueConstants.INTERNAL_TYPE_AMBULANCE_CENTER, RescueConstants.INTERNAL_TYPE_ROAD, RescueConstants.INTERNAL_TYPE_NODE, RescueConstants.INTERNAL_TYPE_RIVER, RescueConstants.INTERNAL_TYPE_RIVER_NODE, RescueConstants.INTERNAL_TYPE_WORLD, RescueConstants.INTERNAL_TYPE_ANY_BUILDING, RescueConstants.INTERNAL_TYPE_ANY_HUMANOID

getID

public int getID()
Get this objects id


hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object o)

addPropertyListener

public void addPropertyListener(PropertyListener l)
Add a PropertyListener

Parameters:
l - The listener that will be notified of changes to any properties in this object

removePropertyListener

public void removePropertyListener(PropertyListener l)
Remove a PropertyListener

Parameters:
l - The listener that will no longer be notified of changes to any properties in this object

getPropertiesString

protected java.lang.String getPropertiesString()
Get a String representation of all this object's properties

Returns:
A String representation of all this object's properties

propertyExists

public boolean propertyExists(int property)
Get all property types known by this object

Returns:
An array containing all the property types known by this object
See Also:
RescueConstants.PROPERTY_NULL, RescueConstants.PROPERTY_START_TIME, RescueConstants.PROPERTY_LONGITUDE, RescueConstants.PROPERTY_LATITUDE, RescueConstants.PROPERTY_WIND_FORCE, RescueConstants.PROPERTY_WIND_DIRECTION, RescueConstants.PROPERTY_X, RescueConstants.PROPERTY_Y, RescueConstants.PROPERTY_DIRECTION, RescueConstants.PROPERTY_POSITION, RescueConstants.PROPERTY_POSITION_HISTORY, RescueConstants.PROPERTY_POSITION_EXTRA, RescueConstants.PROPERTY_STAMINA, RescueConstants.PROPERTY_HP, RescueConstants.PROPERTY_DAMAGE, RescueConstants.PROPERTY_BURIEDNESS, RescueConstants.PROPERTY_FLOORS, RescueConstants.PROPERTY_BUILDING_ATTRIBUTES, RescueConstants.PROPERTY_IGNITION, RescueConstants.PROPERTY_BROKENNESS, RescueConstants.PROPERTY_FIERYNESS, RescueConstants.PROPERTY_ENTRANCES, RescueConstants.PROPERTY_BUILDING_SHAPE_ID, RescueConstants.PROPERTY_BUILDING_CODE, RescueConstants.PROPERTY_BUILDING_AREA_GROUND, RescueConstants.PROPERTY_BUILDING_AREA_TOTAL, RescueConstants.PROPERTY_BUILDING_APEXES, RescueConstants.PROPERTY_WATER_QUANTITY, RescueConstants.PROPERTY_STRETCHED_LENGTH, RescueConstants.PROPERTY_HEAD, RescueConstants.PROPERTY_TAIL, RescueConstants.PROPERTY_LENGTH, RescueConstants.PROPERTY_ROAD_KIND, RescueConstants.PROPERTY_CARS_PASS_TO_HEAD, RescueConstants.PROPERTY_CARS_PASS_TO_TAIL, RescueConstants.PROPERTY_HUMANS_PASS_TO_HEAD, RescueConstants.PROPERTY_HUMANS_PASS_TO_TAIL, RescueConstants.PROPERTY_WIDTH, RescueConstants.PROPERTY_BLOCK, RescueConstants.PROPERTY_REPAIR_COST, RescueConstants.PROPERTY_MEDIAN_STRIP, RescueConstants.PROPERTY_LINES_TO_HEAD, RescueConstants.PROPERTY_LINES_TO_TAIL, RescueConstants.PROPERTY_WIDTH_FOR_WALKERS, RescueConstants.PROPERTY_EDGES, RescueConstants.PROPERTY_SIGNAL, RescueConstants.PROPERTY_SIGNAL_TIMING, RescueConstants.PROPERTY_SHORTCUT_TO_TURN, RescueConstants.PROPERTY_POCKET_TO_TURN_ACROSS

getProperty

public Property getProperty(int property)
                     throws UnknownPropertyException
Throws:
UnknownPropertyException

getPropertyAsString

public java.lang.String getPropertyAsString(int property)
                                     throws UnknownPropertyException
Throws:
UnknownPropertyException

getPropertyAsInt

public int getPropertyAsInt(int property)
                     throws UnknownPropertyException
Throws:
UnknownPropertyException

getPropertyAsIntArray

public int[] getPropertyAsIntArray(int property)
                            throws UnknownPropertyException
Throws:
UnknownPropertyException

getPropertyAsBoolean

public boolean getPropertyAsBoolean(int property)
                             throws UnknownPropertyException
Throws:
UnknownPropertyException

getLastPropertyUpdate

public int getLastPropertyUpdate(int property)
                          throws UnknownPropertyException
Get the last time a property was updated

Parameters:
property - The property we want
Returns:
The last time the property was updated
Throws:
UnknownPropertyException - if the property is unknown

isPropertyValueKnown

public boolean isPropertyValueKnown(int property)
                             throws UnknownPropertyException
Is the value of a particular property known or assumed?

Parameters:
property - The property we want
Returns:
True if and only if the last time the property was updated after timestep 0
Throws:
UnknownPropertyException - if the property is unknown

updateProperty

public boolean updateProperty(int property,
                              int timestamp,
                              int newValue)
                       throws UnknownPropertyException
Update the value of a property

Parameters:
property - The property to update
timestamp - The current time step. If this update is more recent than the current value of the property then the update will proceed
newValue - The new value of the property
Returns:
true if and only if the update was successful. An update will not occur if the new value is less recent than our current information, or if the current value is the same as the new value
Throws:
UnknownPropertyException - if the property is not recognised

updateProperty

public boolean updateProperty(int property,
                              int timestamp,
                              int[] newValue)
                       throws UnknownPropertyException
Update the value of a property

Parameters:
property - The property to update
timestamp - The current time step. If this update is more recent than the current value of the property then the update will proceed
newValue - The new value of the property
Returns:
true if and only if the update was successful. An update will not occur if the new value is less recent than our current information, or if the current value is the same as the new value
Throws:
UnknownPropertyException - if the property is not recognised

updateProperty

public boolean updateProperty(int property,
                              int timestamp,
                              boolean newValue)
                       throws UnknownPropertyException
Update the value of a property

Parameters:
property - The property to update
timestamp - The current time step. If this update is more recent than the current value of the property then the update will proceed
newValue - The new value of the property
Returns:
true if and only if the update was successful. An update will not occur if the new value is less recent than our current information, or if the current value is the same as the new value
Throws:
UnknownPropertyException - if the property is not recognised

toString

public java.lang.String toString()

toLongString

public java.lang.String toLongString()

update

public final void update(java.io.DataInput in,
                         int timestamp)
                  throws UnknownPropertyException,
                         java.io.IOException
Update properties of this object using Objects data from a buffer

Parameters:
in - A DataInput to read data from
timestamp - The timestamp of the update
Throws:
java.io.IOException - if something goes wrong
UnknownPropertyException - if an unrecognised property shows up

decode

public static RescueObject decode(java.io.DataInput in,
                                  int timestamp)
                           throws UnknownTypeException,
                                  UnknownPropertyException,
                                  java.io.IOException
Decode a new RescueObject from a buffer and update the pointer

Parameters:
in - A DataInput to read data from
timestamp - The current simulation timestamp
Returns:
The next RescueObject in the buffer. Returns null if the next object is TYPE_NULL.
Throws:
UnknownTypeException - if an unknown object type appears
UnknownPropertyException - if an unknown property shows up
java.io.IOException - if there is an IO problem
See Also:
RescueConstants.TYPE_NULL

decode

public static RescueObject decode(int type,
                                  int id,
                                  java.io.DataInput in,
                                  int timestamp)
                           throws UnknownTypeException,
                                  UnknownPropertyException,
                                  java.io.IOException
Decode a new RescueObject from a buffer and update the pointer

Parameters:
type - The type of this object
id - The id of this object
in - A DataInput to read data from
timestamp - The current simulation timestamp
Returns:
The next RescueObject in the buffer. Returns null if the next object is TYPE_NULL.
Throws:
UnknownTypeException - if an unknown object type appears
UnknownPropertyException - if an unknown property shows up
java.io.IOException - if there is an IO problem
See Also:
RescueConstants.TYPE_NULL

decodeObjects

public static RescueObject[] decodeObjects(java.io.DataInput in,
                                           int timestamp)
                                    throws UnknownTypeException,
                                           UnknownPropertyException,
                                           java.io.IOException
Decode a set of objects from a buffer. This method repeatedly calls @{link #decodeObject(byte[], MutableInteger)} until null is returned, then returns an array containing all non-null results

Parameters:
in - The DataInput to read data from
timestamp - The current simulation timestamp
Returns:
The next RescueObject array in the buffer
Throws:
UnknownTypeException - if an unknown object type appears
UnknownPropertyException - if an unknown property shows up
java.io.IOException - if there is an IO problem
See Also:
RescueConstants.TYPE_NULL

typeToInternalType

public static int typeToInternalType(int type)
Convert a robocup rescue type into an internal, bitwise type

Parameters:
type - The rescue type to convert
Returns:
The corresponding internal type

isBuilding

public boolean isBuilding()
Is this object a building?

Returns:
true if and only if this object is a building

isRefuge

public boolean isRefuge()
Is this object a refuge?

Returns:
true if and only if this object is a refuge

isFireStation

public boolean isFireStation()
Is this object a fire station?

Returns:
true if and only if this object is a fire station

isPoliceOffice

public boolean isPoliceOffice()
Is this object a police office?

Returns:
true if and only if this object is a police office

isAmbulanceCenter

public boolean isAmbulanceCenter()
Is this object an ambulance center?

Returns:
true if and only if this object is an ambulance center

isRoad

public boolean isRoad()
Is this object a road?

Returns:
true if and only if this object is a road

isNode

public boolean isNode()
Is this object a node?

Returns:
true if and only if this object is a node

isCivilian

public boolean isCivilian()
Is this object a civilian?

Returns:
true if and only if this object is a civilian

isHumanoid

public boolean isHumanoid()
Is this object a humanoid?

Returns:
true if and only if this object is a humanoid

isAmbulanceTeam

public boolean isAmbulanceTeam()
Is this object an ambulance team?

Returns:
true if and only if this object is an ambulance

isPoliceForce

public boolean isPoliceForce()
Is this object a police force?

Returns:
true if and only if this object is a police force

isFireBrigade

public boolean isFireBrigade()
Is this object a fire brigade?

Returns:
true if and only if this object is a fire brigade

firePropertyChanged

protected void firePropertyChanged(int property,
                                   int timestep)