org.mars_sim.msp.core.structure.building
Class BuildingManager

java.lang.Object
  extended by org.mars_sim.msp.core.structure.building.BuildingManager
All Implemented Interfaces:
Serializable

public class BuildingManager
extends Object
implements Serializable

The BuildingManager manages the settlement's buildings.

See Also:
Serialized Form

Field Summary
static String ADD_BUILDING_EVENT
           
static String REMOVE_BUILDING_EVENT
           
 
Constructor Summary
BuildingManager(Settlement settlement)
          Constructor to construct buildings from settlement config template.
BuildingManager(Settlement settlement, List<BuildingTemplate> buildingTemplates)
          Constructor to construct buildings from name list.
 
Method Summary
 void addBuilding(Building newBuilding)
          Adds a new building to the settlement.
 void addBuilding(BuildingTemplate template)
          Adds a building with a template to the settlement.
static void addPersonToBuilding(Person person, Building building)
          Adds the person to the building if possible.
static void addToRandomBuilding(GroundVehicle vehicle, Settlement settlement)
          Adds a ground vehicle to a random ground vehicle maintenance building within a settlement.
static void addToRandomBuilding(Person person, Settlement settlement)
          Adds a person to a random inhabitable building within a settlement.
 boolean checkIfNewBuildingLocationOpen(double xLoc, double yLoc, double width, double length, double facing)
          Checks if a new building's proposed location is open or intersects with existing buildings or construction sites.
 boolean checkIfNewBuildingLocationOpen(double xLoc, double yLoc, double width, double length, double facing, ConstructionSite site)
          Checks if a new building's proposed location is open or intersects with existing buildings or construction sites.
 void destroy()
          Prepare object for garbage collection.
static Map<Building,Double> getBestRelationshipBuildings(Person person, List<Building> buildingList)
          Gets a map of buildings and their probabilities for being chosen based on the best relationships for a given person from a list of buildings.
static Building getBuilding(Person person)
          Gets the building a given person is in.
static Building getBuilding(Vehicle vehicle)
          Gets the vehicle maintenance building a given vehicle is in.
 int getBuildingNum()
          Gets the number of buildings at the settlement.
 List<Building> getBuildings()
          Gets the settlement's collection of buildings.
 List<Building> getBuildings(String functionName)
          Gets the buildings in a settlement that has a given function.
 List<Building> getBuildingsOfName(String buildingName)
          Gets the buildings in the settlement with a given building name.
 double getBuildingValue(Building building)
          Gets the value of a building at the settlement.
 double getBuildingValue(String buildingName, boolean newBuilding)
          Gets the value of a named building at the settlement.
static List<Building> getLeastCrowdedBuildings(List<Building> buildingList)
          Gets a list of the least crowded buildings from a given list of buildings with life support.
static List<Building> getNonMalfunctioningBuildings(List<Building> buildingList)
          Gets a list of buildings that don't have any malfunctions from a list of buildings.
 Settlement getSettlement()
          Gets the building manager's settlement.
static List<Building> getUncrowdedBuildings(List<Building> buildingList)
          Gets a list of uncrowded buildings from a given list of buildings with life support.
 boolean hasBuildingFrame(String frameName)
          Checks if a building frame exists at the settlement.
 void removeBuilding(Building oldBuilding)
          Removes a building from the settlement.
static void removePersonFromBuilding(Person person, Building building)
          Removes the person from a building if possible.
 void timePassing(double time)
          Time passing for all buildings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADD_BUILDING_EVENT

public static final String ADD_BUILDING_EVENT
See Also:
Constant Field Values

REMOVE_BUILDING_EVENT

public static final String REMOVE_BUILDING_EVENT
See Also:
Constant Field Values
Constructor Detail

BuildingManager

public BuildingManager(Settlement settlement)
Constructor to construct buildings from settlement config template.

Parameters:
settlement - the manager's settlement.
Throws:
Exception - if buildings cannot be constructed.

BuildingManager

public BuildingManager(Settlement settlement,
                       List<BuildingTemplate> buildingTemplates)
Constructor to construct buildings from name list.

Parameters:
settlement - the manager's settlement
buildingTemplates - the settlement's building templates.
Throws:
Exception - if buildings cannot be constructed.
Method Detail

getSettlement

public Settlement getSettlement()
Gets the building manager's settlement.

Returns:
settlement

addBuilding

public void addBuilding(Building newBuilding)
Adds a new building to the settlement.

Parameters:
newBuilding - the building to add.

removeBuilding

public void removeBuilding(Building oldBuilding)
Removes a building from the settlement.

Parameters:
oldBuilding - the building to remove.

addBuilding

public void addBuilding(BuildingTemplate template)
Adds a building with a template to the settlement.

Parameters:
template - the building template.
Throws:
Exception - if error creating or adding building.

getBuildings

public List<Building> getBuildings()
Gets the settlement's collection of buildings.

Returns:
collection of buildings

getBuildings

public List<Building> getBuildings(String functionName)
Gets the buildings in a settlement that has a given function.

Parameters:
functionName - the name of the building.
Returns:
list of buildings.

getBuildingsOfName

public List<Building> getBuildingsOfName(String buildingName)
Gets the buildings in the settlement with a given building name.

Parameters:
buildingName - the building name.
Returns:
list of buildings.

getBuildingNum

public int getBuildingNum()
Gets the number of buildings at the settlement.

Returns:
number of buildings

timePassing

public void timePassing(double time)
Time passing for all buildings.

Parameters:
time - amount of time passing (in millisols)
Throws:
Exception - if error.

addToRandomBuilding

public static void addToRandomBuilding(Person person,
                                       Settlement settlement)
Adds a person to a random inhabitable building within a settlement.

Parameters:
person - the person to add.
settlement - the settlement to find a building.
Throws:
BuildingException - if person cannot be added to any building.

addToRandomBuilding

public static void addToRandomBuilding(GroundVehicle vehicle,
                                       Settlement settlement)
Adds a ground vehicle to a random ground vehicle maintenance building within a settlement.

Parameters:
vehicle - the ground vehicle to add.
settlement - the settlement to find a building.
Throws:
BuildingException - if vehicle cannot be added to any building.

getBuilding

public static Building getBuilding(Person person)
Gets the building a given person is in.

Returns:
building or null if none.

getBuilding

public static Building getBuilding(Vehicle vehicle)
Gets the vehicle maintenance building a given vehicle is in.

Returns:
building or null if none.

getUncrowdedBuildings

public static List<Building> getUncrowdedBuildings(List<Building> buildingList)
Gets a list of uncrowded buildings from a given list of buildings with life support.

Parameters:
buildingList - list of buildings with the life support function.
Returns:
list of buildings that are not at or above maximum occupant capacity.
Throws:
BuildingException - if building in list does not have the life support function.

getLeastCrowdedBuildings

public static List<Building> getLeastCrowdedBuildings(List<Building> buildingList)
Gets a list of the least crowded buildings from a given list of buildings with life support.

Parameters:
buildingList - list of buildings with the life support function.
Returns:
list of least crowded buildings.
Throws:
BuildingException - if building in list does not have the life support function.

getBestRelationshipBuildings

public static Map<Building,Double> getBestRelationshipBuildings(Person person,
                                                                List<Building> buildingList)
Gets a map of buildings and their probabilities for being chosen based on the best relationships for a given person from a list of buildings.

Parameters:
person - the person to check for.
buildingList - the list of buildings to filter.
Returns:
map of buildings and their probabilities.

getNonMalfunctioningBuildings

public static List<Building> getNonMalfunctioningBuildings(List<Building> buildingList)
Gets a list of buildings that don't have any malfunctions from a list of buildings.

Parameters:
buildingList - the list of buildings.
Returns:
list of buildings without malfunctions.

addPersonToBuilding

public static void addPersonToBuilding(Person person,
                                       Building building)
Adds the person to the building if possible.

Parameters:
person - the person to add.
building - the building to add the person to.

removePersonFromBuilding

public static void removePersonFromBuilding(Person person,
                                            Building building)
Removes the person from a building if possible.

Parameters:
person - the person to remove.
building - the building to remove the person from.

getBuildingValue

public double getBuildingValue(String buildingName,
                               boolean newBuilding)
Gets the value of a named building at the settlement.

Parameters:
buildingName - the building name.
newBuilding - true if adding a new building.
Returns:
building value (VP).

getBuildingValue

public double getBuildingValue(Building building)
Gets the value of a building at the settlement.

Parameters:
building - the building.
Returns:
building value (VP).
Throws:
Exception - if error getting building value.

checkIfNewBuildingLocationOpen

public boolean checkIfNewBuildingLocationOpen(double xLoc,
                                              double yLoc,
                                              double width,
                                              double length,
                                              double facing)
Checks if a new building's proposed location is open or intersects with existing buildings or construction sites.

Parameters:
xLoc - the new building's X location.
yLoc - the new building's Y location.
width - the new building's width (meters).
length - the new building's length (meters).
facing - the new building's facing (degrees clockwise from North).
Returns:
true if new building location is open.

checkIfNewBuildingLocationOpen

public boolean checkIfNewBuildingLocationOpen(double xLoc,
                                              double yLoc,
                                              double width,
                                              double length,
                                              double facing,
                                              ConstructionSite site)
Checks if a new building's proposed location is open or intersects with existing buildings or construction sites.

Parameters:
xLoc - the new building's X location.
yLoc - the new building's Y location.
width - the new building's width (meters).
length - the new building's length (meters).
facing - the new building's facing (degrees clockwise from North).
site - the new construction site or null if none.
Returns:
true if new building location is open.

hasBuildingFrame

public boolean hasBuildingFrame(String frameName)
Checks if a building frame exists at the settlement. Either with an existing building or at a construction site.

Parameters:
frameName - the frame's name.
Returns:
true if frame exists.

destroy

public void destroy()
Prepare object for garbage collection.



Copyright © 2009-2013. All Rights Reserved.