Advanced Strategic Command
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Friends | List of all members
MapField Class Reference

a single field of the map More...

#include <mapfield.h>

Classes

class  ObjectRemovalStrategy
 Interface for removing objects from a field when it turns out that they can no longer exist. More...
 
struct  Resourceview
 
struct  View
 some variables for the viewcalculation algorithm. see viewcalculation.cpp for details More...
 

Public Types

typedef list< MineMineContainer
 
typedef vector< ::ObjectObjectContainer
 

Public Member Functions

 MapField (GameMap *gamemap_, int index_)
 
void operator= (const MapField &f)
 
void setMap (GameMap *gamemap_, int index_)
 
GameMapgetMap () const
 
const TerrainTypegetTerrainType () const
 returns the terrain of the field More...
 
void changeTerrainType (const TerrainType *terrain)
 changes the terrain type to a new one; weather is not changed More...
 
int getMineralMaterial () const
 
int getMineralFuel () const
 
void setMineralMaterial (int material)
 
void setMineralFuel (int fuel)
 
VehiclegetVehicle () const
 
MinegetMine (int n)
 returns the nth mine. This function should only be used by legacy code; new code should store an iterator instead of an index More...
 
bool addobject (const ObjectType *obj, int dir=-1, bool force=false, ObjectRemovalStrategy *objectRemovalStrategy=NULL)
 add an object to the field More...
 
bool removeObject (const ObjectType *obj, bool force=false, ObjectRemovalStrategy *objectRemovalStrategy=NULL)
 removes all objects of the given type from the field More...
 
void sortobjects (void)
 sorts the objects. Since objects can be on different levels of height, the lower one must be displayed first More...
 
void moveUnitHere (Vehicle *veh)
 registers the unit on the field, and unregisters it whereever it previously was More...
 
ObjectcheckForObject (const ObjectType *o)
 checks if there are objects from the given type on the field and returns them More...
 
void deleteeverything (void)
 deletes everything placed on the field More...
 
void setparams (ObjectRemovalStrategy *objectRemovalStrategy)
 recalculates the terrain properties, movemalus etc from the terraintype and the objects, More...
 
void setparams ()
 uses the SimpleObjectRemoval strategy More...
 
int getdefensebonus (void)
 the defense bonus that unit get when they are attacked More...
 
int getattackbonus (void)
 the attack bonus that unit get when they are attacking More...
 
int getWeather ()
 the weather that is on this field More...
 
void setWeather (int weather)
 
ASCString getName ()
 
int getjamming (void)
 the radar jamming that is on this field More...
 
int getmovemalus (const Vehicle *veh)
 
int getmovemalus (int type)
 
int mineattacks (const Vehicle *veh)
 can any of the mines on this field attack this unit More...
 
int mineowner (void)
 the player who placed the mines on this field. More...
 
bool unitHere (const Vehicle *veh)
 checks if the unit is standing on this field. Since units are being cloned for some checks, this method should be used instead of comparing the pointers to the unit More...
 
ContainerBasegetContainer ()
 returns a pointer to the ContainerBase of the field or NULL if there is none More...
 
const ContainerBasegetContainer () const
 
BuildinggetBuildingEntrance ()
 returns the building if there is one with its entrance on this field More...
 
void removeBuilding ()
 if there is a building on the field, the building is deleted (may affect othere fields too, depending on building size) More...
 
void removeUnit ()
 if there is a unit on the field, the unit will be deleted More...
 
bool putmine (int owner, MineTypes typ, int strength)
 put a mine of type typ for player owner and a punch of strength on the field. Strength is an absolute value (unlike the basestrength of a mine or the punch of the mine-weapon, which are just factors) More...
 
void removemine (int num)
 removes a mine More...
 
void endRound (int turn)
 
void setVisibility (VisibilityStates valtoset, int actplayer)
 The visibility status for all players is stored in a bitmapped variable. More...
 
VisibilityStates getVisibility (int actplayer)
 
int getx ()
 
int gety ()
 
MapCoordinate getPosition ()
 
int getMemoryFootprint () const
 
 ~MapField ()
 
void setaTemp (Uint8 atemp)
 Various algorithms need to store some information in the fields they process. More...
 
Uint8 getaTemp ()
 
void setaTemp2 (Uint8 atemp2)
 
Uint8 getaTemp2 ()
 
void setTempw (Uint16 tempw)
 
Uint16 getTempw ()
 
void setTemp3 (int temp3)
 
int getTemp3 ()
 
void setTemp4 (int temp4)
 
int getTemp4 ()
 

Static Public Member Functions

static void resetView (GameMap *gamemap, int playersToReset)
 

Public Attributes

TerrainType::Weathertyp
 the terraintype of the field More...
 
Uint8 fuel
 mineral resources on this field. More...
 
Uint8 material
 
Uint16 visible
 can this field be seen be the player. Variable is bitmapped; two bits for each player. These two bits can have the states defined in VisibilityStates More...
 
int viewbonus
 units standing on this object will get a bonus to their view More...
 
Vehiclevehicle
 
Vehiclesecondvehicle
 two units and the same field are only allowed temporary during movement More...
 
Buildingbuilding
 
Resourceviewresourceview
 the mineral resources that were seen by a player on this field; since the actual amount may have decreased since the player looked, this value is not identical to the fuel and material fields. More...
 
MineContainer mines
 
ObjectContainer objects
 
TerrainBits bdt
 the terraintype properties. They determine which units can move over the field. This variable is recalculated from the terraintype and objects each time something on the field changes (setparams) More...
 
int connection
 are any events connected to this field More...
 
struct MapField::View view [8]
 

Protected Member Functions

 MapField ()
 

Friends

class GameMap
 

Detailed Description

a single field of the map

Definition at line 26 of file mapfield.h.

Member Typedef Documentation

Definition at line 116 of file mapfield.h.

typedef vector< ::Object> MapField::ObjectContainer

Definition at line 123 of file mapfield.h.

Constructor & Destructor Documentation

MapField::MapField ( )
inlineprotected

Definition at line 31 of file mapfield.h.

MapField::MapField ( GameMap gamemap_,
int  index_ 
)
inline

Definition at line 34 of file mapfield.h.

References setMap().

MapField::~MapField ( )

Definition at line 673 of file mapfield.cpp.

References resourceview.

Member Function Documentation

bool MapField::addobject ( const ObjectType obj,
int  dir = -1,
bool  force = false,
MapField::ObjectRemovalStrategy objectRemovalStrategy = NULL 
)

add an object to the field

Parameters
objThe object type
dirThe direction of the object type; -1 to use default direction
forcePut the object there even if it cannot normally be placed on this terrain
Returns
true on success, false if the object could not be build

Definition at line 212 of file mapfield.cpp.

References ObjectType::buildable(), calculateobject(), checkForObject(), Object::dir, getx(), gety(), ObjectType::lifetime, AgeableItem::lifetimer, objects, setparams(), and sortobjects().

Referenced by copyFieldStep2(), trunreplay::execnextreplaymove(), AddObject::fieldOperator(), ObjectItem::place(), placeObject(), SpawnObject::runAction(), transformMap(), and RemoveObject::undoAction().

void MapField::changeTerrainType ( const TerrainType terrain)

changes the terrain type to a new one; weather is not changed

Definition at line 182 of file mapfield.cpp.

References getWeather(), setparams(), typ, and TerrainType::weather.

Object * MapField::checkForObject ( const ObjectType o)
void MapField::deleteeverything ( void  )

deletes everything placed on the field

Definition at line 295 of file mapfield.cpp.

References building, setparams(), and vehicle.

Referenced by copyFieldStep1(), and GameMap::resize().

void MapField::endRound ( int  turn)

Definition at line 129 of file mapfield.cpp.

References AgeableItem::age(), mines, objects, and setparams().

Referenced by GameMap::endRound().

Uint8 MapField::getaTemp ( )
Uint8 MapField::getaTemp2 ( )
int MapField::getattackbonus ( void  )

the attack bonus that unit get when they are attacking

Definition at line 490 of file mapfield.cpp.

References TerrainType::Weather::attackbonus, objects, and typ.

Referenced by DashboardPanel::eval(), tunitattacksunit::setup(), tunitattacksbuilding::setup(), tunitattacksobject::setup(), and viewterraininfo().

Building * MapField::getBuildingEntrance ( )

returns the building if there is one with its entrance on this field

Definition at line 321 of file mapfield.cpp.

References bdt, building, cbbuildingentry, and getTerrainBitType().

ContainerBase * MapField::getContainer ( )
const ContainerBase * MapField::getContainer ( ) const

Definition at line 339 of file mapfield.cpp.

References building, and vehicle.

int MapField::getdefensebonus ( void  )

the defense bonus that unit get when they are attacked

Definition at line 506 of file mapfield.cpp.

References TerrainType::Weather::defensebonus, objects, and typ.

Referenced by DashboardPanel::eval(), tunitattacksunit::setup(), tunitattacksbuilding::setup(), tunitattacksobject::setup(), and viewterraininfo().

int MapField::getjamming ( void  )

the radar jamming that is on this field

Definition at line 537 of file mapfield.cpp.

References TerrainType::Weather::basicjamming, objects, and typ.

Referenced by DashboardPanel::eval(), VisibilityLayer::paintSingleField(), tdrawgettempline::putpix8(), and viewterraininfo().

GameMap* MapField::getMap ( void  ) const
inline
int MapField::getMemoryFootprint ( ) const

Definition at line 666 of file mapfield.cpp.

Referenced by MemoryMeasurement::measure().

Mine & MapField::getMine ( int  n)

returns the nth mine. This function should only be used by legacy code; new code should store an iterator instead of an index

Definition at line 204 of file mapfield.cpp.

References mines.

Referenced by copyFieldStep2(), and tmineattacksunit::setup().

int MapField::getMineralFuel ( ) const

Definition at line 90 of file mapfield.cpp.

References fuel.

int MapField::getMineralMaterial ( ) const

Definition at line 85 of file mapfield.cpp.

References material.

int MapField::getmovemalus ( const Vehicle veh)
int MapField::getmovemalus ( int  type)

Definition at line 573 of file mapfield.cpp.

ASCString MapField::getName ( )
MapCoordinate MapField::getPosition ( void  )

Definition at line 578 of file mapfield.cpp.

References getx(), and gety().

Referenced by ActionObjectRemovalStrategy::removeObject().

int MapField::getTemp3 ( )

Definition at line 74 of file mapfield.cpp.

References GameMap::temp3.

Referenced by evaluateviewcalculation().

int MapField::getTemp4 ( )

Definition at line 81 of file mapfield.cpp.

References GameMap::temp4.

Uint16 MapField::getTempw ( )

Definition at line 67 of file mapfield.cpp.

References GameMap::temp, and GameMap::temp2.

const TerrainType * MapField::getTerrainType ( ) const

returns the terrain of the field

Definition at line 177 of file mapfield.cpp.

References TerrainType::Weather::terraintype, and typ.

Vehicle* MapField::getVehicle ( ) const
inline
VisibilityStates MapField::getVisibility ( int  actplayer)
inline

Definition at line 240 of file mapfield.h.

References visible.

Referenced by Player::swap(), and testDebugFunction().

int MapField::getWeather ( void  )
int MapField::getx ( void  )
int MapField::gety ( void  )
int MapField::mineattacks ( const Vehicle veh)

can any of the mines on this field attack this unit

Definition at line 194 of file mapfield.cpp.

References mines.

Referenced by AntiMineAStar3D::getMoveCost(), and MoveUnit::runAction().

int MapField::mineowner ( void  )

the player who placed the mines on this field.

Definition at line 454 of file mapfield.cpp.

References mines.

Referenced by tplayerchange::anzeige(), calcvisibilityfield(), getmovemalus(), putmine(), and MoveUnit::runAction().

void MapField::moveUnitHere ( Vehicle veh)

registers the unit on the field, and unregisters it whereever it previously was

Definition at line 362 of file mapfield.cpp.

References getx(), gety(), Vehicle::setnewposition(), Vehicle::unregisterPosition(), and vehicle.

void MapField::operator= ( const MapField f)

Definition at line 155 of file mapfield.cpp.

References bdt, building, connection, fuel, material, mines, objects, resourceview, typ, vehicle, view, and visible.

bool MapField::putmine ( int  owner,
MineTypes  typ,
int  strength 
)

put a mine of type typ for player owner and a punch of strength on the field. Strength is an absolute value (unlike the basestrength of a mine or the punch of the mine-weapon, which are just factors)

Definition at line 441 of file mapfield.cpp.

References cgp_maxminesonfield, GameMap::getgameparameter(), mineowner(), and mines.

Referenced by copyFieldStep2(), MineItem::place(), and SpawnMine::runAction().

void MapField::removeBuilding ( )

if there is a building on the field, the building is deleted (may affect othere fields too, depending on building size)

Definition at line 348 of file mapfield.cpp.

References building.

void MapField::removemine ( int  num)

removes a mine

Parameters
numThe position of the mine; if num is -1, the last mine is removed)

Definition at line 463 of file mapfield.cpp.

References mines.

Referenced by execaction().

bool MapField::removeObject ( const ObjectType obj,
bool  force = false,
ObjectRemovalStrategy objectRemovalStrategy = NULL 
)

removes all objects of the given type from the field

Parameters
objthe object type to remove
forceremove the object even if there are obstacles on the field (like a building standing on the object)
Returns
if the removal was successful

Definition at line 256 of file mapfield.cpp.

References GameMap::actplayer, building, calculateobject(), ContainerBase::getOwner(), getx(), gety(), objects, setparams(), and vehicle.

Referenced by checkobjectsforremoval(), clearField(), copyFieldStep1(), execaction(), trunreplay::execnextreplaymove(), ObjectItem::remove(), RemoveObject::runAction(), transformMap(), and SpawnObject::undoAction().

void MapField::removeUnit ( )

if there is a unit on the field, the unit will be deleted

Definition at line 354 of file mapfield.cpp.

References vehicle.

void MapField::resetView ( GameMap gamemap,
int  playersToReset 
)
static

Definition at line 413 of file mapfield.cpp.

References GameMap::field, GameMap::getPlayerCount(), visible, GameMap::xsize, and GameMap::ysize.

Referenced by GameMap::endRound().

void MapField::setaTemp ( Uint8  atemp)
void MapField::setaTemp2 ( Uint8  atemp2)
void MapField::setMap ( GameMap gamemap_,
int  index_ 
)
inline

Definition at line 37 of file mapfield.h.

Referenced by GameMap::allocateFields(), generatemap(), and MapField().

void MapField::setMineralFuel ( int  fuel)

Definition at line 105 of file mapfield.cpp.

References fuel.

void MapField::setMineralMaterial ( int  material)

Definition at line 95 of file mapfield.cpp.

References material.

void MapField::setparams ( ObjectRemovalStrategy objectRemovalStrategy)
void MapField::setparams ( )
void MapField::setTemp3 ( int  temp3)

Definition at line 71 of file mapfield.cpp.

References GameMap::temp3.

Referenced by evaluateviewcalculation().

void MapField::setTemp4 ( int  temp4)

Definition at line 78 of file mapfield.cpp.

References GameMap::temp4.

void MapField::setTempw ( Uint16  tempw)

Definition at line 63 of file mapfield.cpp.

References GameMap::temp, and GameMap::temp2.

Referenced by tspfldloaders::readfields(), and WeaponRange::testfield().

void MapField::setVisibility ( VisibilityStates  valtoset,
int  actplayer 
)

The visibility status for all players is stored in a bitmapped variable.

This functions changes the status in this variable for a single player

Parameters
valtosetthe value that is going to be written into the visibility variable
actplayerthe player for which the view is changed

Definition at line 404 of file mapfield.cpp.

References visible.

Referenced by evaluatevisibilityfield(), Player::resetView(), and Player::swap().

void MapField::setWeather ( int  weather)
void MapField::sortobjects ( void  )

sorts the objects. Since objects can be on different levels of height, the lower one must be displayed first

Definition at line 436 of file mapfield.cpp.

References compareObjectHeight(), and objects.

Referenced by addobject(), tspfldloaders::readfields(), and transformMap().

bool MapField::unitHere ( const Vehicle veh)

checks if the unit is standing on this field. Since units are being cloned for some checks, this method should be used instead of comparing the pointers to the unit

Definition at line 311 of file mapfield.cpp.

References Vehicle::networkid, and vehicle.

Referenced by Vehicle::canMove(), Vehicle::endOwnTurn(), AStar3D::findPath(), and Vehicle::getPosition3D().

Friends And Related Function Documentation

friend class GameMap
friend

Definition at line 31 of file mapfield.h.

Member Data Documentation

TerrainBits MapField::bdt
Building* MapField::building

Definition at line 102 of file mapfield.h.

Referenced by SelectBuildingFromMap::accept(), BuildingConquered::arm(), BuildingLost::arm(), BuildingSeen::arm(), attackpossible(), ContextMenu::DeleteBuilding::available(), GuiFunctions::OpenContainer::available(), ObjectType::buildable(), ConstructBuildingCommand::buildingFits(), calcMoveMalus(), calculateobject(), calcvisibilityfield(), Building::chainbuildingtofield(), checkunitsforremoval(), clearField(), copyFieldStep2(), deleteeverything(), DashboardPanel::eval(), evaluatevisibilityfield(), execaction(), trunreplay::execnextreplaymove(), ChangeBuildingDamage::execute(), ChangeBuildingOwner::execute(), AddProductionCapability::execute(), AddResources::execute(), Reinforcements::execute(), fieldAccessible(), ResourceNet::fieldavail(), AnyUnitEntersPolygon::fieldOperator(), JumpDriveCommand::fieldReachable(), fieldvisiblenow(), AStar3D::findPath(), Vehicle::freeWeight(), SpawnBuilding::getBuilding(), getBuildingEntrance(), getContainer(), GameMap::getContainer(), BuildingPositionTrigger::getName(), BuildingConquered::getState(), BuildingDestroyed::getState(), BuildingSeen::getState(), DestructBuildingCommand::go(), AttackCommand::go(), tgiveunitawaydlg::init(), NewGuiHost::mapIconProcessing(), movebuilding(), operator=(), ContainerInfoLayer::paintSingleField(), MapRenderer::paintSingleField(), PipeLayer::paintSingleField(), SelectionHolder::pickup(), ClipBoardBase::place(), VehicleItem::place(), placeBuilding(), putbuilding(), tspfldloaders::readfields(), removeBuilding(), removeObject(), UnitTypeTransformation::run(), VehicleAttackAction::runAction(), SpawnBuilding::runAction(), MoveUnit::runAction(), MapNetwork::searchAllVehiclesNextToBuildings(), MapNetwork::searchbuilding(), MapNetwork::searchfield(), setparams(), MapNetwork::start(), testAiMovement5(), testAiMovement6(), testAiMovement7(), testRecycling(), testresearch1(), testresearch2(), testTransferControl(), transformMap(), Building::unchainbuildingfromfield(), SpawnBuilding::undoAction(), OverviewMapHolder::updateField(), VehicleCounterFactory::VehicleCounterFactory(), viewterraininfo(), tspfldloaders::writefields(), and GameMap::~GameMap().

int MapField::connection
Uint8 MapField::fuel
Uint8 MapField::material
MineContainer MapField::mines
ObjectContainer MapField::objects
Resourceview* MapField::resourceview

the mineral resources that were seen by a player on this field; since the actual amount may have decreased since the player looked, this value is not identical to the fuel and material fields.

Definition at line 114 of file mapfield.h.

Referenced by DiscoverResources::ResourceViewState::initFromField(), operator=(), ResourceGraphLayer::paintSingleField(), tspfldloaders::readfields(), Player::resetView(), Player::swap(), MiningStation::testfield(), tspfldloaders::writefields(), DiscoverResources::ResourceViewState::writeToField(), and ~MapField().

Vehicle* MapField::secondvehicle

two units and the same field are only allowed temporary during movement

Definition at line 92 of file mapfield.h.

Referenced by calcvisibilityfield(), getVehicle(), Vehicle::paint(), MapRenderer::paintSingleField(), MoveUnit::runAction(), DestructContainer::runAction(), and Vehicle::~Vehicle().

TerrainType::Weather* MapField::typ
Vehicle* MapField::vehicle

Definition at line 89 of file mapfield.h.

Referenced by SelectUnitFromMap::accept(), attackpossible(), GuiFunctions::MovementBase::available(), ContextMenu::DeleteVehicle::available(), GuiFunctions::Ascend::available(), GuiFunctions::Descend::available(), GuiFunctions::Attack::available(), GuiFunctions::PowerSwitch::available(), GuiFunctions::UnitInfo::available(), GuiFunctions::DestructBuilding::available(), GuiFunctions::OpenContainer::available(), GuiFunctions::EnableReactionfire::available(), GuiFunctions::DisableReactionfire::available(), GuiFunctions::JumpDriveIcon::available(), GuiFunctions::RepairUnit::available(), GuiFunctions::PutMine::available(), GuiFunctions::BuildObject::available(), GuiFunctions::BuildVehicleCommand::available(), GuiFunctions::ConstructBuilding::available(), ConstructBuildingCommand::buildingFits(), calcMoveMalus(), Building::chainbuildingtofield(), checkunitsforremoval(), clearField(), copyFieldStep2(), deleteeverything(), GameMap::endTurn(), DashboardPanel::eval(), execaction(), trunreplay::execnextreplaymove(), GuiFunctions::MovementBase::execute(), GuiFunctions::Attack::execute(), GuiFunctions::PowerSwitch::execute(), GuiFunctions::DestructBuilding::execute(), Reinforcements::execute(), GuiFunctions::EnableReactionfire::execute(), GuiFunctions::DisableReactionfire::execute(), GuiFunctions::JumpDriveIcon::execute(), GuiFunctions::RepairUnit::execute(), GuiFunctions::PutMine::execute(), GuiFunctions::BuildObject::execute(), GuiFunctions::ConstructBuilding::execute(), executeUserAction(), ConstructUnitCommand::externalConstructionAvail(), fieldAccessible(), JumpDriveCommand::fieldReachable(), fieldvisiblenow(), AStar3D::findPath(), Vehicle::freeWeight(), getContainer(), getmaxwindspeedforunit(), StratAStar3D::getMoveCost(), GuiFunctions::AttackGui::getName(), GuiFunctions::RepairUnit::getName(), getSelectedUnit(), ContextMenu::ContainerProperties::getText(), ContextMenu::ContainerCargo::getText(), GameMap::getUnit(), getVehicle(), tgiveunitawaydlg::init(), NewGuiHost::mapIconProcessing(), movebuilding(), moveUnitHere(), UnitInfoPanel::onClick(), UnitWeaponRangeLayer::operateField(), UnitMovementRangeLayer::operateField(), operator=(), ContainerInfoLayer::paintSingleField(), MapRenderer::paintSingleField(), ReactionFireLayer::paintSingleField(), UnitInfoLayer::paintSingleField(), UnitTrainingLayer::paintSingleField(), SelectionHolder::pickup(), ClipBoardBase::place(), VehicleItem::place(), placeUnit(), putbuilding(), tspfldloaders::readfields(), removeObject(), removeUnit(), UnitTypeTransformation::run(), VehicleAttackAction::runAction(), MoveUnit::runAction(), UnitFieldRegistration::runAction(), DestructContainer::runAction(), MapNetwork::searchvehicle(), selectunit(), tmapgenerator::setmap(), AttackCommand::setTarget(), showCargoSummary(), AI::showFieldInformation(), showUnitAiProperties(), MapNetwork::start(), testAutoRepair(), SearchReconquerBuilding::testfield(), FindUnitPlacementPos::testfield(), testManualRepair(), testSelfDamage(), UnitFieldRegistration::undoAction(), UnitAttacksUnit_FakeHemming::UnitAttacksUnit_FakeHemming(), unitHere(), unitInfoDialog(), Vehicle::unregisterPosition(), OverviewMapHolder::updateField(), VehicleCounterFactory::VehicleCounterFactory(), viewterraininfo(), viewUnitSetinfo(), tspfldloaders::writefields(), GameMap::~GameMap(), and Vehicle::~Vehicle().

struct MapField::View MapField::view[8]
int MapField::viewbonus

units standing on this object will get a bonus to their view

Definition at line 66 of file mapfield.h.

Referenced by setparams().

Uint16 MapField::visible

The documentation for this class was generated from the following files: