gecco.server.unitmanager
Class UnitManager

java.lang.Object
  |
  +--gecco.server.unitmanager.UnitManager

public class UnitManager
extends Object

This class acts as a container for all units in the game. It keeps track all units and unit types, the observers of all units, and certain things.

Author:
Henrik Bäärnhielm, Karl Hasselström, Henrik Hägerström

Field Summary
protected  HashMap activeUnits
          All active units for each role, hashed on the role name.
protected  HashSet godseyeRoles
          All gods eye roles!
protected  String[] roles
          Array containing _all_ roles, including the gods eye roles!
protected  HashMap rolesToAlienUnitsMap
          For each role, the set of units alien to that role, hashed on the role name.
protected  HashMap rolesToObserverUnitsMap
          For each role, the set of units that the role observes, hashed on the role name.
protected  HashMap units
          Contains all units, hashed on their handles.
protected  HashMap unitTypes
          All unit types in the game, hashed on their names.
protected  HashSet[] xArray
          An array of sets, one set for each x coordinate on the map.
protected  HashSet[] yArray
          An array of sets, one set for each y coordinate on the map.
 
Constructor Summary
UnitManager(Set roles, Set godseyeRoles)
          Constructor for the UnitManager object
 
Method Summary
 boolean activateUnit(String role, Unit unit)
          Mark a unit as active for a given role.
 void addUnitType(UnitType unitType)
          Adds a new unit type.
 Unit createUnit(String unitTypeName)
          Creates a unit of a given unit type.
 boolean deactivateUnit(String role, Unit unit)
          Mark a unit as non-active for a given role.
 void deleteUnit(Unit unit, double lastKnownX, double lastKnownY)
          Delete a unit from the game.
 Set getAlienUnits(String role)
          Gets the set of units that is alien to a given role.
 Collection getAllUnits()
          Gets all units in the game.
 Set getBlockedActions(Unit u)
          Gets the set of blocked actions of a given unit.
 int[] getCommandingUnits(String role)
          Gets the handles of all units that a given role commands.
 Set getGodsEyeRoles()
          Gets the GodsEyeRoles attribute of the UnitManager object
 int[] getHandles()
          Gets the BlockedActionStrings attribute of the UnitManager object Gets the UnblockedActionStrings attribute of the UnitManager object Gets the handles of all units in the game.
 Set getObservingUnits(String role)
          Gets the set of units that a given role observes.
 int getRange(Unit u)
          Gets the visibility range of a given unit.
 String[] getRoles()
          Gets the Roles attribute of the UnitManager object
 String[] getRolesAlienToUnit(Unit unit)
          Gets the names of all roles that is alien to a given unit.
 String[] getRolesObservingUnit(Unit unit)
          Gets the names of all roles that observes a given unit.
 Set getUnblockedActions(Unit u)
          Gets the set of non-blocked actions of a given unit.
 Unit getUnit(int handle)
          Gets a unit, given its handle.
 Set getUnitsAtAutomatonPosition(int x, int y)
          Gets the set of units at a given position.
 UnitType getUnitType(String unitType)
          Gets a unit type, given its name.
 Collection getUnitTypes()
          Gets all unit types in the game.
 void initializeUnitPosition(Unit unit)
          Initialises a unit.
 boolean isGodseye(String role)
          Determines if a given role has status as god's eye.
 boolean isRoleCommander(String role)
          Determines if a given role commands any unit.
 boolean isUnitActive(String role, int unit)
          Determines if a given is active for a given role.
 void reportObserverForUnit(String role, Unit u)
          Mark a given role as observer for a given unit.
 void reportUpdatedUnitPosition(Unit unit, int oldX, int oldY)
          Report that a units position has been updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

units

protected HashMap units
Contains all units, hashed on their handles.


roles

protected String[] roles
Array containing _all_ roles, including the gods eye roles!


godseyeRoles

protected HashSet godseyeRoles
All gods eye roles!


activeUnits

protected HashMap activeUnits
All active units for each role, hashed on the role name. A unit is active for a role if the role can see the unit, either because the role observes the unit or because the unit is inside the visibility range of some unit that the role observes.


unitTypes

protected HashMap unitTypes
All unit types in the game, hashed on their names.


rolesToObserverUnitsMap

protected HashMap rolesToObserverUnitsMap
For each role, the set of units that the role observes, hashed on the role name.


rolesToAlienUnitsMap

protected HashMap rolesToAlienUnitsMap
For each role, the set of units alien to that role, hashed on the role name.


xArray

protected HashSet[] xArray
An array of sets, one set for each x coordinate on the map. Each set contains the units that currently is at a point with that x coordinate.


yArray

protected HashSet[] yArray
An array of sets, one set for each y coordinate on the map. Each set contains the units that currently is at a point with that y coordinate.

Constructor Detail

UnitManager

public UnitManager(Set roles,
                   Set godseyeRoles)
Constructor for the UnitManager object

Parameters:
roles - The roles in the game.
godseyeRoles - The roles with god's eye status.
Method Detail

getRoles

public String[] getRoles()
Gets the Roles attribute of the UnitManager object

Returns:
The array of role names.

getGodsEyeRoles

public Set getGodsEyeRoles()
Gets the GodsEyeRoles attribute of the UnitManager object

Returns:
The set of roles with god's eye status.

isGodseye

public boolean isGodseye(String role)
Determines if a given role has status as god's eye.

Parameters:
role - A role name.
Returns:
true if the role has god's eye status, false otherwise

getAllUnits

public Collection getAllUnits()
Gets all units in the game.

Returns:
A collection of all units.

getUnit

public Unit getUnit(int handle)
Gets a unit, given its handle.

Parameters:
handle - A handle of a unit.
Returns:
The unit with the given handle, or null, if no such unit exists.

getUnitType

public UnitType getUnitType(String unitType)
Gets a unit type, given its name.

Parameters:
unitType - The name of the unit type.
Returns:
The unit type.

getBlockedActions

public Set getBlockedActions(Unit u)
Gets the set of blocked actions of a given unit.

Parameters:
u - The unit.
Returns:
The set of blocked actions.

getUnblockedActions

public Set getUnblockedActions(Unit u)
Gets the set of non-blocked actions of a given unit.

Parameters:
u - The unit.
Returns:
The set of non-blocked actions.

getHandles

public int[] getHandles()
Gets the BlockedActionStrings attribute of the UnitManager object Gets the UnblockedActionStrings attribute of the UnitManager object Gets the handles of all units in the game.

Returns:
The BlockedActionStrings value

getCommandingUnits

public int[] getCommandingUnits(String role)
Gets the handles of all units that a given role commands.

Parameters:
role - The name of the role.
Returns:
An array of handles that the role commands.

getRange

public int getRange(Unit u)
Gets the visibility range of a given unit.

Parameters:
u - The unit.
Returns:
The range of the unit.

getRolesObservingUnit

public String[] getRolesObservingUnit(Unit unit)
Gets the names of all roles that observes a given unit.

Parameters:
unit - The unit.
Returns:
An array of role names observing the unit.

getRolesAlienToUnit

public String[] getRolesAlienToUnit(Unit unit)
Gets the names of all roles that is alien to a given unit.

Parameters:
unit - A unit.
Returns:
An array of role names alien to the unit.

getObservingUnits

public Set getObservingUnits(String role)
Gets the set of units that a given role observes.

Parameters:
role - The role name.
Returns:
The set of units that the role observes.

getAlienUnits

public Set getAlienUnits(String role)
Gets the set of units that is alien to a given role.

Parameters:
role - The role name.
Returns:
The set of alien units.

getUnitsAtAutomatonPosition

public Set getUnitsAtAutomatonPosition(int x,
                                       int y)
Gets the set of units at a given position.

Parameters:
x - The x coordinate of the position.
y - The y coordinate of the position.
Returns:
The set of units at the position.

isUnitActive

public boolean isUnitActive(String role,
                            int unit)
Determines if a given is active for a given role.

Parameters:
role - The name of the role.
unit - The handle of the unit.
Returns:
true if the unit is active for the role, false otherwise.

isRoleCommander

public boolean isRoleCommander(String role)
Determines if a given role commands any unit.

Parameters:
role - The name of the role.
Returns:
true if there exists a unit which the role commands, false otherwise.

getUnitTypes

public Collection getUnitTypes()
Gets all unit types in the game.

Returns:
The collection of all unit types.

createUnit

public Unit createUnit(String unitTypeName)
Creates a unit of a given unit type.

Parameters:
unitTypeName - The name of the unit type.
Returns:
A new unit of the given type.

reportObserverForUnit

public void reportObserverForUnit(String role,
                                  Unit u)
Mark a given role as observer for a given unit.

Parameters:
role - The role name.
u - The unit.

addUnitType

public void addUnitType(UnitType unitType)
Adds a new unit type.

Parameters:
unitType - The unit type to be added.

initializeUnitPosition

public void initializeUnitPosition(Unit unit)
Initialises a unit.

Parameters:
unit - The unit.

reportUpdatedUnitPosition

public void reportUpdatedUnitPosition(Unit unit,
                                      int oldX,
                                      int oldY)
Report that a units position has been updated.

Parameters:
unit - The unit.
oldX - The x coordinate of the old position.
oldY - The y coordinate of the old position.

activateUnit

public boolean activateUnit(String role,
                            Unit unit)
Mark a unit as active for a given role.

Parameters:
role - The name of the role.
unit - The unit.
Returns:
true if the unit was not active already, false otherwise

deactivateUnit

public boolean deactivateUnit(String role,
                              Unit unit)
Mark a unit as non-active for a given role.

Parameters:
role - The name of the role.
unit - The unit.
Returns:
true if the unit was active for the given role, false otherwise

deleteUnit

public void deleteUnit(Unit unit,
                       double lastKnownX,
                       double lastKnownY)
Delete a unit from the game.

Parameters:
unit - The unit to be deleted.
lastKnownX - The x coordinate of the last position of the unit.
lastKnownY - The y coordinate of the last position of the unit.