Building Class Reference

An actual building on the map, which references a BuildingType Buildings have an owner,. More...

#include <buildings.h>

Inheritance diagram for Building:

Inheritance graph
[legend]
List of all members.

Public Member Functions

const BuildingTypegetType () const
 Building (GameMap *map, const MapCoordinate &entryPosition, const BuildingType *type, int player, bool setupImages=true, bool chainToField=true)
bool canRepair (const ContainerBase *item) const
 checks whether the item can be repaired provided that it is in range
void write (tnstream &stream, bool includeLoadedUnits=true) const
void read (tnstream &stream)
void execnetcontrol (void)
 executes the resource net operations, like filling the tanks with fuel.
int putResource (int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
 scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only internally! )
int getResource (int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
int getAvailableResource (int amount, int resourcetype, int scope=1) const
Resources putResource (const Resources &res, bool queryonly, int scope=1, int player=-1)
Resources getResource (const Resources &res, bool queryonly, int scope=1, int player=-1)
int getIdentification () const
const SurfacegetPicture (const BuildingType::LocalCoordinate &localCoordinate) const
 returns the picture of the building. It may depend on the current weather of the fields the building is standing on
void paintSingleField (Surface &s, SPoint imgpos, BuildingType::LocalCoordinate pos) const
virtual Surface getImage () const
 returns an image for the Container.
bool isBuilding () const
void convert (int player, bool recursive=true)
 changes the building's owner.
void registerForNewOwner (int player)
 this is a low level functions that changes the registration in the map. It's called by convert(int,bool)
void addview ()
 Adds the view and jamming of the building to the player's global radar field.
void resetview ()
 resets the internal view state, so that addview() can be executed again
void removeview ()
 Removes the view and jamming of the building from the player's global radar field.
bool isViewing () const
 returns true if the buildings' view is currently added to the maps global visibility.
int getArmor () const
 returns the armor of the building.
MapFieldgetEntryField () const
 returns the field the buildings entry is standing on
MapCoordinate3D getEntry () const
 returns the position of the buildings entry
MapFieldgetField (const BuildingType::LocalCoordinate &localCoordinates) const
 returns the pointer to the field which the given part of the building is standing on
MapCoordinate getFieldCoordinates (const BuildingType::LocalCoordinate &localCoordinates) const
 returns the absolute map coordinate of the given part of the building
BuildingType::LocalCoordinate getLocalCoordinate (const MapCoordinate &field) const
 converts a global coordinate into a local coordinate.
MapCoordinate3D getPosition () const
 returns the position of the buildings entry
MapCoordinate3D getPosition3D () const
 returns the position of the buildings entry
int chainbuildingtofield (const MapCoordinate &entryPos, bool setupImages=true)
 registers the building at the given position on the map
int unchainbuildingfromfield (void)
 unregister the building from the map position
int getCompletion () const
 returns the completion of the building.
void setCompletion (int completion, bool setupImages=true)
 Sets the level of completion of the building.
void endRound (void)
 hook that is called when a turn ends
ASCString getName () const
 returns a name for the building. If the building itself has a name, it will be returned. If it doesn't, the name of the building type will be returned.
int getAmmo (int type, int num, bool queryOnly)
int getAmmo (int type, int num) const
int putAmmo (int type, int num, bool queryOnly)
int maxAmmo (int type) const
int getHeight () const
 returns the bitmapped level of height. Only one bit will be set, of course
 ~Building ()
virtual int repairableDamage () const
 returns the amount of damate that can still be repaired this turn
int getMemoryFootprint () const

Static Public Member Functions

static BuildingnewFromStream (GameMap *gamemap, tnstream &stream, bool chainToField=true)

Public Attributes

const BuildingTypetyp
int ammo [waffenanzahl]
 the ammo that is stored in the building
int netcontrol
 a bitmapped variable containing the status of the resource-net connection.
int connection
 bitmapped: are there events that are triggered by actions affecting this building
bool visible
 is the building visible? Building can be made invisible, but this feature should be used only in some very special cases
AiValueaiparam [8]
int lastmineddist
Resources actstorage
 the current storage of Resources

Protected Member Functions

const ResourceMatrixgetRepairEfficiency () const
 when a ContainerBase is repair by this ContainerBase, the default cost can be customized with this matrix.
virtual void postRepair (int oldDamage)
 is called after a repair is performed. Vehicles use this to reduce their experience.
vector< MapCoordinategetCoveredFields ()

Protected Attributes

ResourceMatrix repairEfficiency

Friends

class tprocessminingfields

Detailed Description

An actual building on the map, which references a BuildingType Buildings have an owner,.

Unlike a Vehicle, a Building can not move, can not shoot and may cover several fields on the map

Definition at line 38 of file buildings.h.


Constructor & Destructor Documentation

Building::Building ( GameMap map,
const MapCoordinate entryPosition,
const BuildingType type,
int  player,
bool  setupImages = true,
bool  chainToField = true 
)

Definition at line 46 of file buildings.cpp.

References aiparam, ammo, Player::buildingList, chainbuildingtofield(), connection, ContainerBase::damage, ContainerBase::gamemap, lastmineddist, netcontrol, GameMap::player, visible, and waffenanzahl.

Referenced by newFromStream().

Building::~Building (  ) 

Definition at line 429 of file buildings.cpp.

References aiparam, Player::buildingList, ContainerBase::color, ContainerBase::gamemap, GameMap::player, and unchainbuildingfromfield().


Member Function Documentation

const BuildingType* Building::getType (  )  const [inline]

Definition at line 50 of file buildings.h.

References typ.

bool Building::canRepair ( const ContainerBase item  )  const [virtual]

checks whether the item can be repaired provided that it is in range

Implements ContainerBase.

Definition at line 93 of file buildings.cpp.

References ContainerBaseType::ExternalRepair, ContainerBaseType::hasFunction(), ContainerBaseType::InternalUnitRepair, and typ.

Building * Building::newFromStream ( GameMap gamemap,
tnstream stream,
bool  chainToField = true 
) [static]

Definition at line 523 of file buildings.cpp.

References ContainerBase::bi_resourceplus, Building(), ContainerBase::color, ContainerBase::gamemap, GameMap::getbuildingtype_byid(), tnstream::getDeviceName(), tnstream::readChar(), readData(), tnstream::readInt(), tnstream::readWord(), Resources::resource(), and typ.

Referenced by Reinforcements::execute(), ClipBoardBase::place(), tspfldloaders::readfields(), and DestructContainer::undoAction().

void Building::write ( tnstream stream,
bool  includeLoadedUnits = true 
) const [virtual]

Implements ContainerBase.

Definition at line 451 of file buildings.cpp.

References actstorage, ammo, ContainerBase::bi_resourceplus, BUILDINGVERSIONLIMIT, ContainerBase::cargo, ContainerBase::color, ContainerBase::damage, getCompletion(), getEntry(), ContainerBaseType::id, ContainerBase::internalUnitProduction, max(), ContainerBase::maxplus, ContainerBase::maxresearchpoints, ContainerBase::name, netcontrol, ContainerBase::plus, ContainerBase::privateName, ContainerBase::repairedThisTurn, ContainerBase::researchpoints, Resources::resource(), resourceTypeNum, typ, ContainerBase::view, visible, waffenanzahl, tnstream::writeChar(), tnstream::writeInt(), tnstream::writeString(), and tnstream::writeWord().

Referenced by ClipBoardBase::addBuilding(), and tspfldloaders::writefields().

void Building::read ( tnstream stream  )  [virtual]

Implements ContainerBase.

Definition at line 567 of file buildings.cpp.

References ContainerBase::bi_resourceplus, tnstream::readChar(), tnstream::readInt(), tnstream::readWord(), and Resources::resource().

void Building::execnetcontrol ( void   ) 

executes the resource net operations, like filling the tanks with fuel.

See also:
netcontrol

Definition at line 214 of file controls.cpp.

References actstorage, cnet_moveenergyout, cnet_stopenergyinput, cnet_stopenergyoutput, cnet_storeenergy, ContainerBase::getMap(), getResource(), ContainerBase::getStorageCapacity(), netcontrol, npop, npush, putResource(), and Resources::resource().

int Building::putResource ( int  amount,
int  resourcetype,
bool  queryonly,
int  scope = 1,
int  player = -1 
) [virtual]

scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only internally! )

Implements ContainerBase.

Definition at line 246 of file controls.cpp.

References ContainerBase::getMap(), StaticResourceNet::getresource(), getResource(), MapCoordinate::x, and MapCoordinate::y.

Referenced by convert(), execnetcontrol(), AddResources::execute(), and getResource().

int Building::getResource ( int  amount,
int  resourcetype,
bool  queryonly,
int  scope = 1,
int  player = -1 
) [virtual]

Implements ContainerBase.

Definition at line 263 of file controls.cpp.

References ContainerBase::getMap(), StaticResourceNet::getresource(), putResource(), MapCoordinate::x, and MapCoordinate::y.

Referenced by execnetcontrol(), trunreplay::execnextreplaymove(), putResource(), and PutTribute::start().

int Building::getAvailableResource ( int  amount,
int  resourcetype,
int  scope = 1 
) const [virtual]

Implements ContainerBase.

Definition at line 280 of file controls.cpp.

References ContainerBase::getMap(), StaticResourceNet::getresource(), MapCoordinate::x, and MapCoordinate::y.

Referenced by DashboardPanel::showUnitData().

Resources Building::putResource ( const Resources res,
bool  queryonly,
int  scope = 1,
int  player = -1 
) [inline]

Reimplemented from ContainerBase.

Definition at line 88 of file buildings.h.

References ContainerBase::putResource().

Resources Building::getResource ( const Resources res,
bool  queryonly,
int  scope = 1,
int  player = -1 
) [inline]

Reimplemented from ContainerBase.

Definition at line 89 of file buildings.h.

References ContainerBase::getResource().

int Building::getIdentification (  )  const [virtual]

Implements ContainerBase.

Definition at line 100 of file buildings.cpp.

References getPosition(), MapCoordinate::x, and MapCoordinate::y.

const Surface & Building::getPicture ( const BuildingType::LocalCoordinate localCoordinate  )  const

returns the picture of the building. It may depend on the current weather of the fields the building is standing on

Definition at line 188 of file buildings.cpp.

References getField(), BuildingType::getPicture(), MapField::getWeather(), and typ.

Referenced by paintSingleField().

void Building::paintSingleField ( Surface s,
SPoint  imgpos,
BuildingType::LocalCoordinate  pos 
) const

Definition at line 198 of file buildings.cpp.

References chfahrend, getHeight(), getPicture(), and ContainerBase::paintField().

Referenced by MapRenderer::paintSingleField(), and GetTargetImage::visit().

Surface Building::getImage (  )  const [virtual]

returns an image for the Container.

Note:
Buildings have a size of several fields. The image returned here is therefore not suited to be painted on the map, as map-painting is done on a per-field basis

Implements ContainerBase.

Definition at line 229 of file buildings.cpp.

References ASC_max(), ASC_min(), Surface::createSurface(), fielddisthalfx, fielddistx, fielddisty, BuildingType::fieldExists(), fieldsizex, fieldsizey, ContainerBase::getOwningPlayer(), maxint, BuildingType::paint(), Surface::transparent, and typ.

bool Building::isBuilding (  )  const [inline, virtual]

Implements ContainerBase.

Definition at line 106 of file buildings.h.

void Building::convert ( int  player,
bool  recursive = true 
)

changes the building's owner.

Parameters:
player range: 0 .. 8

Definition at line 105 of file buildings.cpp.

References actstorage, addview(), ContainerBase::anyContainerConquered, GameMap::bi_resource, Player::buildingList, ContainerBase::cargo, cnet_stopenergyinput, ContainerBase::color, ContainerBase::conquered, fatalError(), ContainerBase::gamemap, ContainerBase::getOwner(), ContainerBaseType::hasFunction(), GameMap::isResourceGlobal(), netcontrol, GameMap::player, putResource(), removeview(), Resources::resource(), ContainerBaseType::SelfDestructOnConquer, and typ.

Referenced by trunreplay::execnextreplaymove(), and ChangeBuildingOwner::execute().

void Building::registerForNewOwner ( int  player  )  [virtual]

this is a low level functions that changes the registration in the map. It's called by convert(int,bool)

Implements ContainerBase.

Definition at line 162 of file buildings.cpp.

References addview(), ContainerBase::anyContainerConquered, Player::buildingList, ContainerBase::color, ContainerBase::conquered, ContainerBase::gamemap, ContainerBase::getOwner(), GameMap::player, and removeview().

void Building::addview (  )  [virtual]

Adds the view and jamming of the building to the player's global radar field.

Implements ContainerBase.

Definition at line 353 of file buildings.cpp.

References fatalError(), ContainerBase::gamemap, tcomputebuildingview::init(), and SearchFields::startsearch().

Referenced by convert(), Reinforcements::execute(), registerForNewOwner(), and DestructContainer::undoAction().

void Building::resetview (  ) 

resets the internal view state, so that addview() can be executed again

Definition at line 365 of file buildings.cpp.

void Building::removeview (  )  [virtual]

Removes the view and jamming of the building from the player's global radar field.

Implements ContainerBase.

Definition at line 371 of file buildings.cpp.

References ContainerBase::color, fatalError(), ContainerBase::gamemap, tcomputebuildingview::init(), and SearchFields::startsearch().

Referenced by convert(), registerForNewOwner(), and DestructContainer::runAction().

bool Building::isViewing (  )  const [inline]

returns true if the buildings' view is currently added to the maps global visibility.

See also:
viewcalculation.cpp

Definition at line 127 of file buildings.h.

Referenced by DestructContainer::runAction().

int Building::getArmor (  )  const [virtual]

returns the armor of the building.

See also:
BuildingType::_armor

Implements ContainerBase.

Definition at line 393 of file buildings.cpp.

References BuildingType::_armor, cgp_buildingarmor, ContainerBase::gamemap, GameMap::getgameparameter(), and typ.

Referenced by DashboardPanel::showUnitData().

MapField * Building::getEntryField (  )  const

returns the field the buildings entry is standing on

Definition at line 405 of file buildings.cpp.

References BuildingType::entry, getField(), and typ.

Referenced by SearchReconquerBuilding::canUnitCapture(), copyFieldStep2(), and MapNetwork::searchbuilding().

MapCoordinate3D Building::getEntry (  )  const

returns the position of the buildings entry

Definition at line 410 of file buildings.cpp.

References ContainerBaseType::height, and typ.

Referenced by PutResource::checkbuilding(), GetResource::checkbuilding(), getPosition(), getPosition3D(), tcomputebuildingview::init(), movebuilding(), PutTribute::puttribute(), transformMap(), DestructContainer::undoAction(), and write().

MapField * Building::getField ( const BuildingType::LocalCoordinate localCoordinates  )  const

returns the pointer to the field which the given part of the building is standing on

Definition at line 399 of file buildings.cpp.

References ContainerBase::gamemap, GameMap::getField(), and getFieldCoordinates().

Referenced by chainbuildingtofield(), getEntryField(), getPicture(), BuildingSeen::getState(), tcomputebuildingview::init(), DestructContainer::runAction(), MapField::setparams(), and unchainbuildingfromfield().

MapCoordinate Building::getFieldCoordinates ( const BuildingType::LocalCoordinate localCoordinates  )  const

returns the absolute map coordinate of the given part of the building

Definition at line 417 of file buildings.cpp.

References BuildingType::getFieldCoordinate(), and typ.

Referenced by chainbuildingtofield(), getCoveredFields(), getField(), DestructContainer::runAction(), and MapNetwork::searchbuilding().

BuildingType::LocalCoordinate Building::getLocalCoordinate ( const MapCoordinate field  )  const

converts a global coordinate into a local coordinate.

Definition at line 423 of file buildings.cpp.

References BuildingType::getLocalCoordinate(), and typ.

Referenced by chainbuildingtofield(), and MapRenderer::paintSingleField().

MapCoordinate3D Building::getPosition ( void   )  const [inline, virtual]

returns the position of the buildings entry

Implements ContainerBase.

Definition at line 150 of file buildings.h.

References getEntry().

Referenced by Reinforcements::execute(), getBuildingReference(), getIdentification(), SpawnBuilding::runAction(), and tunitattacksbuilding::setresult().

MapCoordinate3D Building::getPosition3D (  )  const

returns the position of the buildings entry

Definition at line 385 of file buildings.cpp.

References getEntry(), MapCoordinate3D::setnum(), MapCoordinate::x, and MapCoordinate::y.

int Building::chainbuildingtofield ( const MapCoordinate entryPos,
bool  setupImages = true 
)

registers the building at the given position on the map

Definition at line 268 of file buildings.cpp.

References MapField::bdt, GameMap::calculateAllObjects(), ContainerBase::cargo, cbbuildingentry, chtieffliegend, BuildingType::entry, BuildingType::fieldExists(), ContainerBase::gamemap, getField(), getFieldCoordinates(), getLocalCoordinate(), getTerrainBitType(), MapField::objects, typ, visible, warningMessage(), BuildingType::LocalCoordinate::x, MapCoordinate::x, BuildingType::LocalCoordinate::y, and MapCoordinate::y.

Referenced by Building(), Reinforcements::execute(), movebuilding(), ClipBoardBase::place(), transformMap(), and DestructContainer::undoAction().

int Building::unchainbuildingfromfield ( void   ) 

unregister the building from the map position

Definition at line 332 of file buildings.cpp.

References MapField::building, cbbuildingentry, BuildingType::fieldExists(), getField(), getTerrainBitType(), and typ.

Referenced by movebuilding(), DestructContainer::runAction(), transformMap(), and ~Building().

int Building::getCompletion (  )  const [inline]

returns the completion of the building.

See also:
setCompletion(int,bool)

Definition at line 162 of file buildings.h.

Referenced by tcomputebuildingview::init(), SpawnBuilding::runAction(), SpawnBuilding::undoAction(), and write().

void Building::setCompletion ( int  completion,
bool  setupImages = true 
)

Sets the level of completion of the building.

Parameters:
completion range: 0 .. typ->construction_steps-1 . If completion == typ->construction_steps-1 the building is completed and working.
setupImages Are the building image pointer of the fields the building is standing on updated?
See also:
Buildingtype::construction_steps

Definition at line 259 of file buildings.cpp.

Referenced by putbuilding(), SpawnBuilding::runAction(), and SpawnBuilding::undoAction().

void Building::endRound ( void   )  [virtual]

hook that is called when a turn ends

Reimplemented from ContainerBase.

Definition at line 750 of file buildings.cpp.

References ContainerBase::endRound(), and ContainerBase::repairedThisTurn.

ASCString Building::getName (  )  const [virtual]

returns a name for the building. If the building itself has a name, it will be returned. If it doesn't, the name of the building type will be returned.

Implements ContainerBase.

Definition at line 711 of file buildings.cpp.

References ContainerBaseType::name, ContainerBase::name, and typ.

Referenced by getBuildingReference(), and BuildingPositionTrigger::getName().

int Building::getAmmo ( int  type,
int  num,
bool  queryOnly 
) [virtual]

Implements ContainerBase.

Definition at line 719 of file buildings.cpp.

References ammo, and min().

int Building::getAmmo ( int  type,
int  num 
) const [virtual]

Implements ContainerBase.

Definition at line 730 of file buildings.cpp.

References ammo, and min().

int Building::putAmmo ( int  type,
int  num,
bool  queryOnly 
) [virtual]

Implements ContainerBase.

Definition at line 737 of file buildings.cpp.

References ammo.

Referenced by trunreplay::execnextreplaymove().

int Building::maxAmmo ( int  type  )  const [inline, virtual]

Implements ContainerBase.

Definition at line 181 of file buildings.h.

References maxint.

int Building::getHeight (  )  const [inline, virtual]

returns the bitmapped level of height. Only one bit will be set, of course

Implements ContainerBase.

Definition at line 185 of file buildings.h.

References ContainerBaseType::height, and typ.

Referenced by paintSingleField().

int Building::repairableDamage (  )  const [virtual]

returns the amount of damate that can still be repaired this turn

Implements ContainerBase.

Definition at line 78 of file buildings.cpp.

References cgp_maxbuildingrepair, ContainerBase::damage, GameMap::getgameparameter(), ContainerBase::getMap(), and ContainerBase::repairedThisTurn.

Referenced by RepairBuildingCommand::avail().

int Building::getMemoryFootprint (  )  const

Definition at line 768 of file buildings.cpp.

const ResourceMatrix& Building::getRepairEfficiency (  )  const [inline, protected, virtual]

when a ContainerBase is repair by this ContainerBase, the default cost can be customized with this matrix.

Note:
This effects both reparing another ContainerBase as well as self-repsir

Implements ContainerBase.

Definition at line 196 of file buildings.h.

References repairEfficiency.

void Building::postRepair ( int  oldDamage  )  [protected, virtual]

is called after a repair is performed. Vehicles use this to reduce their experience.

Implements ContainerBase.

Definition at line 88 of file buildings.cpp.

References ContainerBase::damage, and ContainerBase::repairedThisTurn.

vector< MapCoordinate > Building::getCoveredFields (  )  [protected, virtual]

Implements ContainerBase.

Definition at line 757 of file buildings.cpp.

References BuildingType::fieldExists(), getFieldCoordinates(), and typ.


Friends And Related Function Documentation

friend class tprocessminingfields [friend]

Definition at line 43 of file buildings.h.


Member Data Documentation

const BuildingType* Building::typ

Definition at line 48 of file buildings.h.

Referenced by attackpossible(), calculateobject(), calcvisibilityfield(), canRepair(), chainbuildingtofield(), ServiceChecker::check(), convert(), copyFieldStep2(), trunreplay::execnextreplaymove(), Reinforcements::execute(), fieldAccessible(), fieldvisiblenow(), getArmor(), getCoveredFields(), getEntry(), getEntryField(), getFieldCoordinates(), DestructBuildingCommand::getFields(), getHeight(), getImage(), getLocalCoordinate(), getName(), getPicture(), BuildingSeen::getState(), getType(), DestructBuildingCommand::go(), tcomputebuildingview::init(), BuildingValues::init(), newFromStream(), MapRenderer::paintSingleField(), SelectionHolder::pickup(), ClipBoardBase::place(), placeBuilding(), SpawnBuilding::runAction(), DestructContainer::runAction(), MapField::setparams(), DashboardPanel::showUnitData(), transformMap(), unchainbuildingfromfield(), SpawnBuilding::undoAction(), GetTargetImage::visit(), and write().

int Building::ammo[waffenanzahl]

the ammo that is stored in the building

Definition at line 50 of file buildings.h.

Referenced by Building(), copyBuildingData(), trunreplay::execnextreplaymove(), getAmmo(), BuildingValues::init(), putAmmo(), and write().

int Building::netcontrol

a bitmapped variable containing the status of the resource-net connection.

See also:
execnetcontrol()
Deprecated:

Definition at line 57 of file buildings.h.

Referenced by Building(), GetResourceCapacity::checkbuilding(), PutTribute::checkbuilding(), PutResource::checkbuilding(), GetResource::checkbuilding(), convert(), copyBuildingData(), execnetcontrol(), SpawnBuilding::runAction(), and write().

int Building::connection

bitmapped: are there events that are triggered by actions affecting this building

Definition at line 60 of file buildings.h.

Referenced by BuildingSeen::arm(), Building(), evaluatevisibilityfield(), and SpawnBuilding::runAction().

bool Building::visible

is the building visible? Building can be made invisible, but this feature should be used only in some very special cases

Definition at line 63 of file buildings.h.

Referenced by Building(), chainbuildingtofield(), copyBuildingData(), BuildingValues::init(), MapRenderer::paintSingleField(), SpawnBuilding::runAction(), and write().

AiValue* Building::aiparam[8]

Definition at line 66 of file buildings.h.

Referenced by Building(), SearchReconquerBuilding::unitfound(), and ~Building().

int Building::lastmineddist

Definition at line 70 of file buildings.h.

Referenced by Building(), and copyBuildingData().

Resources Building::actstorage

the current storage of Resources

Definition at line 89 of file buildings.h.

Referenced by PutTribute::checkbuilding(), PutResource::checkbuilding(), GetResource::checkbuilding(), convert(), copyBuildingData(), execnetcontrol(), BuildingValues::init(), SpawnBuilding::runAction(), and write().

ResourceMatrix Building::repairEfficiency [protected]

Definition at line 195 of file buildings.h.

Referenced by getRepairEfficiency().


The documentation for this class was generated from the following files:
Generated on Mon Feb 6 01:47:22 2012 for Advanced Strategic Command by  doxygen 1.5.1