megamek.common
Class Building

java.lang.Object
  extended by megamek.common.Building
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
FuelTank

public class Building
extends java.lang.Object
implements java.io.Serializable

This class represents a single, possibly multi-hex building on the board.

Version:
$Revision: 7587 $
Author:
Suvarov454@sourceforge.net (James A. Damour )
See Also:
Serialized Form

Nested Class Summary
 class Building.DemolitionCharge
           
 
Field Summary
static int FORTRESS
           
static int GUN_EMPLACEMENT
           
static int HANGAR
           
static int HARDENED
           
static int HEAVY
           
static int LIGHT
          Various construction types.
static int MEDIUM
           
static int STANDARD
          Various building types
protected static int UNKNOWN
          Generic flag for uninitialized values.
static int WALL
           
 
Constructor Summary
Building(Coords coords, IBoard board, int structureType)
          Construct a building for the given coordinates from the board's information.
Building(int bldgClass, int type, int id, java.lang.String name, java.util.Vector<Coords> coords)
          Creates a new building of the specified type, name, ID, and coordinates.
 
Method Summary
 void addDemolitionCharge(int playerId, int damage)
           
 boolean equals(java.lang.Object other)
          Override Object#equals(Object).
 int getAbsorbtion(Coords pos)
           
 int getArmor(Coords coords)
           
 int getBldgClass()
          Get the building class, per TacOps rules.
 int getCollapsedHexCount()
           
 java.util.Enumeration<Coords> getCoords()
          Get the coordinates that the building occupies.
 int getCurrentCF(Coords coords)
          Get the current construction factor of the building hex at the passed coords.
 double getDamageFromScale()
           
 double getDamageToScale()
           
static int getDefaultCF(int type)
          Get the default construction factor for the given type of building.
 int getId()
          Get the ID of this building.
 java.lang.String getName()
          Get the name of this building.
 int getOriginalHexCount()
           
 int getPhaseCF(Coords coords)
          Get the construction factor of the building hex at the passed coords at the start of the current phase.
 int getType()
          Get the construction type of the building.
 boolean hasCFIn(Coords coords)
          Determins if the coord exist in the currentCF has.
protected  void include(Coords coords, IBoard board, int structureType)
          Update this building to include the new hex (and all hexes off the new hex, which aren't already included).
 boolean isBurning(Coords coords)
          Determine if this building is on fire.
 boolean isIn(Coords coords)
          Determine if the building occupies given coordinates.
 void removeHex(Coords coords)
          Remove one building hex from the building
 void setArmor(int a, Coords coords)
           
 void setBurning(boolean onFire, Coords coords)
          Set the flag that indicates that this building is on fire.
 void setCurrentCF(int cf, Coords coords)
          Set the current construction factor of the building hex.
 void setPhaseCF(int cf, Coords coords)
          Set the construction factor of the building hex for the start of the next phase.
 java.lang.String toString()
          Get a String for this building.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNKNOWN

protected static final int UNKNOWN
Generic flag for uninitialized values.

See Also:
Constant Field Values

LIGHT

public static final int LIGHT
Various construction types.

See Also:
Constant Field Values

MEDIUM

public static final int MEDIUM
See Also:
Constant Field Values

HEAVY

public static final int HEAVY
See Also:
Constant Field Values

HARDENED

public static final int HARDENED
See Also:
Constant Field Values

WALL

public static final int WALL
See Also:
Constant Field Values

STANDARD

public static final int STANDARD
Various building types

See Also:
Constant Field Values

HANGAR

public static final int HANGAR
See Also:
Constant Field Values

FORTRESS

public static final int FORTRESS
See Also:
Constant Field Values

GUN_EMPLACEMENT

public static final int GUN_EMPLACEMENT
See Also:
Constant Field Values
Constructor Detail

Building

public Building(Coords coords,
                IBoard board,
                int structureType)
Construct a building for the given coordinates from the board's information. If the building covers multiple hexes, every hex will be included in the building.

Parameters:
coords - - the Coords of a hex of the building. If the building covers multiple hexes, this constructor will include them all in this building automatically.
board - - the game's Board object.
Throws:
an - IllegalArgumentException will be thrown if the given coordinates do not contain a building, or if the building covers multiple hexes with different CFs.

Building

public Building(int bldgClass,
                int type,
                int id,
                java.lang.String name,
                java.util.Vector<Coords> coords)
Creates a new building of the specified type, name, ID, and coordinates. Do *not* use this method unless you have carefully examined this class. The construction factors for the building will be based on the type.

Parameters:
type - The int type of the building.
id - The int ID of this building.
name - The String name of this building.
coords - The Vector of Coords for this building. This object is used directly without being copied.
Throws:
an - IllegalArgumentException will be thrown if the given coordinates do not contain a building, or if the building covers multiple hexes with different CFs.
Method Detail

include

protected void include(Coords coords,
                       IBoard board,
                       int structureType)
Update this building to include the new hex (and all hexes off the new hex, which aren't already included).

Parameters:
coords - - the Coords of the new hex.
board - - the game's IBoard object.
Throws:
an - IllegalArgumentException will be thrown if the given coordinates do not contain a building, or if the building covers multiple hexes with different CF.

getId

public int getId()
Get the ID of this building. The same ID applies to all hexes.

Returns:
the int ID of the building.

isIn

public boolean isIn(Coords coords)
Determine if the building occupies given coordinates. Multi-hex buildings will occupy multiple coordinates. Only one building per hex.

Parameters:
coords - - the Coords being examined.
Returns:
true if the building occupies the coordinates. false otherwise.

hasCFIn

public boolean hasCFIn(Coords coords)
Determins if the coord exist in the currentCF has.

Parameters:
coords - - the Coords being examined.
Returns:
true if the building has CF at the coordinates. false otherwise.

getCoords

public java.util.Enumeration<Coords> getCoords()
Get the coordinates that the building occupies.

Returns:
an Enumeration of the Coord objects.

getType

public int getType()
Get the construction type of the building. This value will be one of the constants, LIGHT, MEDIUM, HEAVY, or HARDENED.

Returns:
the int code of the building's construction type.

getBldgClass

public int getBldgClass()
Get the building class, per TacOps rules.

Returns:
the int code of the building's classification.

getCurrentCF

public int getCurrentCF(Coords coords)
Get the current construction factor of the building hex at the passed coords. Any damage immediately updates this value.

Parameters:
coords - - the Coords> of the hex in question
Returns:
the int value of the building hex's current construction factor. This value will be greater than or equal to zero.

getPhaseCF

public int getPhaseCF(Coords coords)
Get the construction factor of the building hex at the passed coords at the start of the current phase. Damage that is received during the phase is applied at the end of the phase.

Parameters:
coords - - the Coords> of the hex in question
Returns:
the int value of the building's construction factor at the start of this phase. This value will be greater than or equal to zero.

getArmor

public int getArmor(Coords coords)

setCurrentCF

public void setCurrentCF(int cf,
                         Coords coords)
Set the current construction factor of the building hex. Call this method immediately when the building sustains any damage.

Parameters:
coords - - the Coords> of the hex in question
cf - - the int value of the building hex's current construction factor. This value must be greater than or equal to zero.
Throws:
If - the passed value is less than zero, an IllegalArgumentException is thrown.

setPhaseCF

public void setPhaseCF(int cf,
                       Coords coords)
Set the construction factor of the building hex for the start of the next phase. Call this method at the end of the phase to apply damage sustained by the building during the phase.

Parameters:
coords - - the Coords> of the hex in question
cf - - the int value of the building's current construction factor. This value must be greater than or equal to zero.
Throws:
If - the passed value is less than zero, an IllegalArgumentException is thrown.

setArmor

public void setArmor(int a,
                     Coords coords)

getName

public java.lang.String getName()
Get the name of this building.

Returns:
the String name of this building.

getDefaultCF

public static int getDefaultCF(int type)
Get the default construction factor for the given type of building.

Parameters:
type - - the int construction type of the building.
Returns:
the int default construction factor for that type of building. If a bad type value is passed, the constant Building.UNKNOWN will be returned instead.

equals

public boolean equals(java.lang.Object other)
Override Object#equals(Object).

Overrides:
equals in class java.lang.Object
Parameters:
other - - the other Object to compare to this Building.
Returns:
true if the other object is the same as this Building. The value false will be returned if the other object is null, is not a Buildig, or if it is not the same as this Building.

toString

public java.lang.String toString()
Get a String for this building.

Overrides:
toString in class java.lang.Object

isBurning

public boolean isBurning(Coords coords)
Determine if this building is on fire.

Returns:
true if the building is on fire.

setBurning

public void setBurning(boolean onFire,
                       Coords coords)
Set the flag that indicates that this building is on fire.

Parameters:
onFire - - a boolean value that indicates whether this building is on fire.

addDemolitionCharge

public void addDemolitionCharge(int playerId,
                                int damage)

removeHex

public void removeHex(Coords coords)
Remove one building hex from the building

Parameters:
coords - - the Coords of the hex to be removed

getOriginalHexCount

public int getOriginalHexCount()

getCollapsedHexCount

public int getCollapsedHexCount()

getDamageFromScale

public double getDamageFromScale()
Returns:
the damage scale multiplier for units passing through this building

getDamageToScale

public double getDamageToScale()
Returns:
the damage scale multiplier for damage applied to this building (and occupants)

getAbsorbtion

public int getAbsorbtion(Coords pos)
Returns:
the amount of damage the building absorbs