OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
OpenXcom::SavedBattleGame Class Reference

The battlescape data that gets written to disk when the game is saved. More...

#include <SavedBattleGame.h>

Public Member Functions

 SavedBattleGame ()
 Creates a new battle save, based on the current generic save. More...
 
 ~SavedBattleGame ()
 Cleans up the saved game. More...
 
void load (const YAML::Node &node, Ruleset *rule, SavedGame *savedGame)
 Loads a saved battle game from YAML. More...
 
YAML::Node save () const
 Saves a saved battle game to YAML. More...
 
void initMap (int mapsize_x, int mapsize_y, int mapsize_z)
 Sets the dimensions of the map and initializes it. More...
 
void initUtilities (ResourcePack *res)
 Initialises the pathfinding and tileengine. More...
 
std::vector< MapDataSet * > * getMapDataSets ()
 Gets the game's mapdatafiles. More...
 
void setMissionType (const std::string &missionType)
 Sets the mission type. More...
 
std::string getMissionType () const
 Gets the mission type. More...
 
void setGlobalShade (int shade)
 Sets the global shade. More...
 
int getGlobalShade () const
 Gets the global shade. More...
 
Tile ** getTiles () const
 Gets a pointer to the tiles, a tile is the smallest component of battlescape. More...
 
std::vector< Node * > * getNodes ()
 Gets a pointer to the list of nodes. More...
 
std::vector< BattleItem * > * getItems ()
 Gets a pointer to the list of items. More...
 
std::vector< BattleUnit * > * getUnits ()
 Gets a pointer to the list of units. More...
 
int getMapSizeX () const
 Gets terrain size x. More...
 
int getMapSizeY () const
 Gets terrain size y. More...
 
int getMapSizeZ () const
 Gets terrain size z. More...
 
int getMapSizeXYZ () const
 Gets terrain x*y*z. More...
 
int getTileIndex (const Position &pos) const
 Converts coordinates into a unique index. More...
 
void getTileCoords (int index, int *x, int *y, int *z) const
 Converts a tile index to its coordinates. More...
 
TilegetTile (const Position &pos) const
 Gets the Tile at a given position on the map. More...
 
BattleUnitgetSelectedUnit () const
 Gets the currently selected unit. More...
 
void setSelectedUnit (BattleUnit *unit)
 Sets the currently selected unit. More...
 
BattleUnitselectPreviousPlayerUnit (bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
 Selects the previous soldier. More...
 
BattleUnitselectNextPlayerUnit (bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
 Selects the next soldier. More...
 
BattleUnitselectUnit (const Position &pos)
 Selects the unit with position on map. More...
 
PathfindinggetPathfinding () const
 Gets the pathfinding object. More...
 
TileEnginegetTileEngine () const
 Gets a pointer to the tileengine. More...
 
UnitFaction getSide () const
 Gets the playing side. More...
 
int getTurn () const
 Gets the turn number. More...
 
void endTurn ()
 Ends the turn. More...
 
void setDebugMode ()
 Sets debug mode. More...
 
bool getDebugMode () const
 Gets debug mode. More...
 
void loadMapResources (Game *game)
 Load map resources. More...
 
void resetUnitTiles ()
 Resets tiles units are standing on. More...
 
void removeItem (BattleItem *item)
 Removes an item from the game. More...
 
void setAborted (bool flag)
 Sets whether the mission was aborted. More...
 
bool isAborted () const
 Checks if the mission was aborted. More...
 
void setObjectiveDestroyed (bool flag)
 Sets whether the objective is destroyed. More...
 
bool isObjectiveDestroyed ()
 Checks if the objective is detroyed. More...
 
int * getCurrentItemId ()
 Gets the current item ID. More...
 
NodegetSpawnNode (int nodeRank, BattleUnit *unit)
 Gets a spawn node. More...
 
NodegetPatrolNode (bool scout, BattleUnit *unit, Node *fromNode)
 Gets a patrol node. More...
 
void prepareNewTurn ()
 Carries out new turn preparations. More...
 
void reviveUnconsciousUnits ()
 Revives unconscious units (healthcheck). More...
 
void removeUnconsciousBodyItem (BattleUnit *bu)
 Removes the body item that corresponds to the unit.
 
bool setUnitPosition (BattleUnit *bu, const Position &position, bool testOnly=false)
 Sets or tries to set a unit of a certain size on a certain position of the map. More...
 
bool addFallingUnit (BattleUnit *unit)
 Adds this unit to the vector of falling units. More...
 
std::list< BattleUnit * > * getFallingUnits ()
 Gets the vector of falling units. More...
 
void setUnitsFalling (bool fall)
 Toggles the switch that says "there are units falling, start the fall state". More...
 
bool getUnitsFalling () const
 Checks the status of the switch that says "there are units falling". More...
 
BattlescapeStategetBattleState ()
 Gets a pointer to the BattlescapeState. More...
 
BattlescapeGamegetBattleGame ()
 Gets a pointer to the BattlescapeGame. More...
 
void setBattleState (BattlescapeState *bs)
 Sets the pointer to the BattlescapeState. More...
 
BattleUnitgetHighestRankedXCom ()
 Gets the highest ranked, living XCom unit. More...
 
int getMoraleModifier (BattleUnit *unit=0)
 Gets the morale modifier for XCom based on the highest ranked, living XCom unit, or the modifier for the unit passed to this function. More...
 
bool eyesOnTarget (UnitFaction faction, BattleUnit *unit)
 Checks whether a particular faction has eyes on *unit (whether any unit on that faction sees *unit). More...
 
bool placeUnitNearPosition (BattleUnit *unit, Position entryPoint)
 Attempts to place a unit on or near entryPoint. More...
 
void resetTurnCounter ()
 Resets the turn counter.
 
void resetTiles ()
 Resets the visibility of all tiles on the map. More...
 
const std::vector< PositiongetTileSearch ()
 get an 11x11 grid of positions (-10 to +10) to check. More...
 
bool isCheating ()
 check if the AI has engaged cheat mode. More...
 
BattleActionType getTUReserved () const
 get the reserved fire mode. More...
 
void setTUReserved (BattleActionType reserved)
 set the reserved fire mode. More...
 
bool getKneelReserved () const
 get whether we are reserving TUs to kneel. More...
 
void setKneelReserved (bool reserved)
 set whether we are reserving TUs to kneel. More...
 
std::vector< Position > & getStorageSpace ()
 give me access to the storage tiles vector. More...
 
void randomizeItemLocations (Tile *t)
 move all the leftover items to random locations in the storage tiles vector. More...
 
std::vector< std::vector
< std::pair< int, int > > > & 
getModuleMap ()
 get a reference to the baseModules map. More...
 
void calculateModuleMap ()
 calculate the number of map modules remaining More...
 
SavedGamegetGeoscapeSave ()
 a shortcut to the geoscape save. More...
 

Detailed Description

The battlescape data that gets written to disk when the game is saved.

A saved game holds all the variable info in a game like mapdata, soldiers, items, etc.

Constructor & Destructor Documentation

OpenXcom::SavedBattleGame::SavedBattleGame ( )

Creates a new battle save, based on the current generic save.

Initializes a brand new battlescape saved game.

OpenXcom::SavedBattleGame::~SavedBattleGame ( )

Cleans up the saved game.

Deletes the game content from memory.

Member Function Documentation

bool OpenXcom::SavedBattleGame::addFallingUnit ( BattleUnit unit)

Adds this unit to the vector of falling units.

Adds this unit to the vector of falling units, if it doesn't already exist.

Parameters
unitThe unit.
Returns
Was the unit added?
void OpenXcom::SavedBattleGame::calculateModuleMap ( )

calculate the number of map modules remaining

calculate the number of map modules remaining by counting the map objects on the top floor who have the baseModule flag set.

we store this data in the grid as outlined in the comments above, in pairs representing intial and current values.

void OpenXcom::SavedBattleGame::endTurn ( )

Ends the turn.

Ends the current turn and progresses to the next one.

bool OpenXcom::SavedBattleGame::eyesOnTarget ( UnitFaction  faction,
BattleUnit unit 
)

Checks whether a particular faction has eyes on *unit (whether any unit on that faction sees *unit).

Checks whether anyone on a particular faction is looking at the unit.

Similar to getSpottingUnits() but returns a bool and stops searching if one positive hit is found.

Parameters
factionFaction to check through.
unitWhom to spot.
Returns
True when the unit can be seen
BattlescapeGame * OpenXcom::SavedBattleGame::getBattleGame ( )

Gets a pointer to the BattlescapeGame.

Gets the BattlescapeState.

Returns
Pointer to the BattlescapeState.
BattlescapeState * OpenXcom::SavedBattleGame::getBattleState ( )

Gets a pointer to the BattlescapeState.

Gets the BattlescapeState.

Returns
Pointer to the BattlescapeState.
int * OpenXcom::SavedBattleGame::getCurrentItemId ( )

Gets the current item ID.

Returns
Current item ID pointer.
bool OpenXcom::SavedBattleGame::getDebugMode ( ) const

Gets debug mode.

Gets the current debug mode.

Returns
Debug mode.
std::list< BattleUnit * > * OpenXcom::SavedBattleGame::getFallingUnits ( )

Gets the vector of falling units.

Gets all units in the battlescape that are falling.

Returns
The falling units in the battlescape.
SavedGame * OpenXcom::SavedBattleGame::getGeoscapeSave ( )

a shortcut to the geoscape save.

get a pointer to the geoscape save

Returns
a pointer to the geoscape save.
int OpenXcom::SavedBattleGame::getGlobalShade ( ) const

Gets the global shade.

Returns
The global shade.
BattleUnit * OpenXcom::SavedBattleGame::getHighestRankedXCom ( )

Gets the highest ranked, living XCom unit.

Returns
The highest ranked, living XCom unit.
std::vector< BattleItem * > * OpenXcom::SavedBattleGame::getItems ( )

Gets a pointer to the list of items.

Gets the list of items.

Returns
Pointer to the list of items.
bool OpenXcom::SavedBattleGame::getKneelReserved ( ) const

get whether we are reserving TUs to kneel.

Gets the kneel reservation setting.

Returns
Should we reserve an extra 4 TUs to kneel?
std::vector< MapDataSet * > * OpenXcom::SavedBattleGame::getMapDataSets ( )

Gets the game's mapdatafiles.

Gets the array of mapblocks.

Returns
Pointer to the array of mapblocks.
int OpenXcom::SavedBattleGame::getMapSizeX ( ) const

Gets terrain size x.

Gets the map width.

Returns
The map width (Size X) in tiles.
int OpenXcom::SavedBattleGame::getMapSizeXYZ ( ) const

Gets terrain x*y*z.

Gets the map size in tiles.

Returns
The map size.
int OpenXcom::SavedBattleGame::getMapSizeY ( ) const

Gets terrain size y.

Gets the map length.

Returns
The map length (Size Y) in tiles.
int OpenXcom::SavedBattleGame::getMapSizeZ ( ) const

Gets terrain size z.

Gets the map height.

Returns
The map height (Size Z) in layers.
std::string OpenXcom::SavedBattleGame::getMissionType ( ) const

Gets the mission type.

Returns
The mission type.
std::vector< std::vector< std::pair< int, int > > > & OpenXcom::SavedBattleGame::getModuleMap ( )

get a reference to the baseModules map.

Return a reference to the base module destruction map this map contains information on how many destructible base modules remain at any given grid reference in the basescape, using [x][y] format.

-1 for "no items" 0 for "destroyed" and any actual number represents how many left.

Returns
the base module damage map.
int OpenXcom::SavedBattleGame::getMoraleModifier ( BattleUnit unit = 0)

Gets the morale modifier for XCom based on the highest ranked, living XCom unit, or the modifier for the unit passed to this function.

Gets the morale modifier for.

  • either XCom based on the highest ranked, living XCom unit,
  • or the unit passed to this function.
    Parameters
    unitUnit.
    Returns
    The morale modifier.
std::vector< Node * > * OpenXcom::SavedBattleGame::getNodes ( )

Gets a pointer to the list of nodes.

Gets the list of nodes.

Returns
Pointer to the list of nodes.
Pathfinding * OpenXcom::SavedBattleGame::getPathfinding ( ) const

Gets the pathfinding object.

Returns
Pointer to the pathfinding object.
Node * OpenXcom::SavedBattleGame::getPatrolNode ( bool  scout,
BattleUnit unit,
Node fromNode 
)

Gets a patrol node.

Finds a fitting node where a unit can patrol to.

Parameters
scoutIs the unit scouting?
unitPointer to the unit (to get its position).
fromNodePointer to the node the unit is at.
Returns
Pointer to the choosen node.
BattleUnit * OpenXcom::SavedBattleGame::getSelectedUnit ( ) const

Gets the currently selected unit.

Returns
Pointer to BattleUnit.
UnitFaction OpenXcom::SavedBattleGame::getSide ( ) const

Gets the playing side.

Gets the side currently playing.

Returns
The unit faction currently playing.
Node * OpenXcom::SavedBattleGame::getSpawnNode ( int  nodeRank,
BattleUnit unit 
)

Gets a spawn node.

Finds a fitting node where a unit can spawn.

Parameters
nodeRankRank of the node (this is not the rank of the alien!).
unitPointer to the unit (to get its position).
Returns
Pointer to the chosen node.
std::vector< Position > & OpenXcom::SavedBattleGame::getStorageSpace ( )

give me access to the storage tiles vector.

Gives access to the "storage space" vector, for distribution of items in base defense missions.

Returns
Vector of storage positions.
Tile* OpenXcom::SavedBattleGame::getTile ( const Position pos) const
inline

Gets the Tile at a given position on the map.

This method is called over 50mil+ times per turn so it seems useful to inline it.

Parameters
posMap position.
Returns
Pointer to the tile at that position.
void OpenXcom::SavedBattleGame::getTileCoords ( int  index,
int *  x,
int *  y,
int *  z 
) const

Converts a tile index to its coordinates.

Converts a tile index to coordinates.

Parameters
indexThe (unique) tileindex.
xPointer to the X coordinate.
yPointer to the Y coordinate.
zPointer to the Z coordinate.
TileEngine * OpenXcom::SavedBattleGame::getTileEngine ( ) const

Gets a pointer to the tileengine.

Gets the terrain modifier object.

Returns
Pointer to the terrain modifier object.
int OpenXcom::SavedBattleGame::getTileIndex ( const Position pos) const
inline

Converts coordinates into a unique index.

getTile() calls this every time, so should be inlined along with it.

Parameters
posThe position to convert.
Returns
A unique index.
Tile ** OpenXcom::SavedBattleGame::getTiles ( ) const

Gets a pointer to the tiles, a tile is the smallest component of battlescape.

Gets the array of tiles.

Returns
A pointer to the Tile array.
const std::vector< Position > OpenXcom::SavedBattleGame::getTileSearch ( )

get an 11x11 grid of positions (-10 to +10) to check.

Returns
the tilesearch vector for use in AI functions.
BattleActionType OpenXcom::SavedBattleGame::getTUReserved ( ) const

get the reserved fire mode.

Gets the TU reserved type.

Returns
A battleactiontype.
int OpenXcom::SavedBattleGame::getTurn ( ) const

Gets the turn number.

Gets the current turn number.

Returns
The current turn.
std::vector< BattleUnit * > * OpenXcom::SavedBattleGame::getUnits ( )

Gets a pointer to the list of units.

Gets the list of units.

Returns
Pointer to the list of units.
bool OpenXcom::SavedBattleGame::getUnitsFalling ( ) const

Checks the status of the switch that says "there are units falling".

Returns whether there are any units falling in the battlescape.

Returns
True if there are any units falling in the battlescape.
void OpenXcom::SavedBattleGame::initMap ( int  mapsize_x,
int  mapsize_y,
int  mapsize_z 
)

Sets the dimensions of the map and initializes it.

Initializes the array of tiles and creates a pathfinding object.

Parameters
mapsize_x
mapsize_y
mapsize_z
void OpenXcom::SavedBattleGame::initUtilities ( ResourcePack res)

Initialises the pathfinding and tileengine.

Initializes the map utilities.

Parameters
resPointer to resource pack.
bool OpenXcom::SavedBattleGame::isAborted ( ) const

Checks if the mission was aborted.

Returns whether the mission was aborted or successful.

Returns
True, if the mission was aborted, or false, if the mission was successful.
bool OpenXcom::SavedBattleGame::isCheating ( )

check if the AI has engaged cheat mode.

is the AI allowed to cheat?

Returns
true if cheating.
bool OpenXcom::SavedBattleGame::isObjectiveDestroyed ( )

Checks if the objective is detroyed.

Returns whether the objective is detroyed.

Returns
True if the objective is destroyed.
void OpenXcom::SavedBattleGame::load ( const YAML::Node &  node,
Ruleset rule,
SavedGame savedGame 
)

Loads a saved battle game from YAML.

Loads the saved battle game from a YAML file.

Parameters
nodeYAML node.
rulefor the saved game.
savedGamePointer to saved game.
void OpenXcom::SavedBattleGame::loadMapResources ( Game game)

Load map resources.

Loads the resources required by the map in the battle save.

Parameters
gamePointer to the game.
bool OpenXcom::SavedBattleGame::placeUnitNearPosition ( BattleUnit unit,
Position  entryPoint 
)

Attempts to place a unit on or near entryPoint.

Places a unit on or near a position.

Parameters
unitThe unit to place.
entryPointThe position around which to attempt to place the unit.
Returns
True if the unit was successfully placed.
void OpenXcom::SavedBattleGame::prepareNewTurn ( )

Carries out new turn preparations.

Carries out new turn preparations such as fire and smoke spreading.

void OpenXcom::SavedBattleGame::randomizeItemLocations ( Tile t)

move all the leftover items to random locations in the storage tiles vector.

Move all the leftover items in base defense missions to random locations in the storage facilities.

Parameters
tthe tile where all our goodies are initially stored.
void OpenXcom::SavedBattleGame::removeItem ( BattleItem item)

Removes an item from the game.

Eg. when ammo item is depleted.

Parameters
itemThe Item to remove.
void OpenXcom::SavedBattleGame::resetTiles ( )

Resets the visibility of all tiles on the map.

Resets visibility of all the tiles on the map.

void OpenXcom::SavedBattleGame::resetUnitTiles ( )

Resets tiles units are standing on.

Resets all the units to their current standing tile(s).

void OpenXcom::SavedBattleGame::reviveUnconsciousUnits ( )

Revives unconscious units (healthcheck).

Checks for units that are unconcious and revives them if they shouldn't be.

Revived units need a tile to stand on. If the unit's current position is occupied, then all directions around the tile are searched for a free tile to place the unit in. If no free tile is found the unit stays unconscious.

YAML::Node OpenXcom::SavedBattleGame::save ( ) const

Saves a saved battle game to YAML.

Saves the saved battle game to a YAML file.

Returns
YAML node.
BattleUnit * OpenXcom::SavedBattleGame::selectNextPlayerUnit ( bool  checkReselect = false,
bool  setReselect = false,
bool  checkInventory = false 
)

Selects the next soldier.

Selects the next player unit.

Parameters
checkReselectWhether to check if we should reselect a unit.
setReselectDon't reselect a unit.
checkInventoryWhether to check if the unit has an inventory.
Returns
Pointer to new selected BattleUnit, NULL if none can be selected.
See also
selectPlayerUnit
BattleUnit * OpenXcom::SavedBattleGame::selectPreviousPlayerUnit ( bool  checkReselect = false,
bool  setReselect = false,
bool  checkInventory = false 
)

Selects the previous soldier.

Selects the previous player unit.

Parameters
checkReselectWhether to check if we should reselect a unit.
setReselectDon't reselect a unit.
checkInventoryWhether to check if the unit has an inventory.
Returns
Pointer to new selected BattleUnit, NULL if none can be selected.
See also
selectPlayerUnit
BattleUnit * OpenXcom::SavedBattleGame::selectUnit ( const Position pos)

Selects the unit with position on map.

Selects the unit at the given position on the map.

Parameters
posPosition.
Returns
Pointer to a BattleUnit, or 0 when none is found.
void OpenXcom::SavedBattleGame::setAborted ( bool  flag)

Sets whether the mission was aborted.

Sets whether the mission was aborted or successful.

Parameters
flagTrue, if the mission was aborted, or false, if the mission was successful.
void OpenXcom::SavedBattleGame::setBattleState ( BattlescapeState bs)

Sets the pointer to the BattlescapeState.

Sets the BattlescapeState.

Parameters
bsA Pointer to a BattlescapeState.
void OpenXcom::SavedBattleGame::setDebugMode ( )

Sets debug mode.

Turns on debug mode.

void OpenXcom::SavedBattleGame::setGlobalShade ( int  shade)

Sets the global shade.

Parameters
shadeThe global shade.
void OpenXcom::SavedBattleGame::setKneelReserved ( bool  reserved)

set whether we are reserving TUs to kneel.

Sets the kneel reservation setting.

Parameters
reservedShould we reserve an extra 4 TUs to kneel?
void OpenXcom::SavedBattleGame::setMissionType ( const std::string &  missionType)

Sets the mission type.

Parameters
missionTypeThe mission type.
void OpenXcom::SavedBattleGame::setObjectiveDestroyed ( bool  flag)

Sets whether the objective is destroyed.

Parameters
flagTrue if the objective is destroyed.
void OpenXcom::SavedBattleGame::setSelectedUnit ( BattleUnit unit)

Sets the currently selected unit.

Parameters
unitPointer to BattleUnit.
void OpenXcom::SavedBattleGame::setTUReserved ( BattleActionType  reserved)

set the reserved fire mode.

Sets the TU reserved type.

Parameters
reservedA battleactiontype.
bool OpenXcom::SavedBattleGame::setUnitPosition ( BattleUnit bu,
const Position position,
bool  testOnly = false 
)

Sets or tries to set a unit of a certain size on a certain position of the map.

Places units on the map.

Handles large units that are placed on multiple tiles.

Parameters
buThe unit to be placed.
positionThe position to place the unit.
testOnlyIf true then just checks if the unit can be placed at the position.
Returns
True if the unit could be successfully placed.
void OpenXcom::SavedBattleGame::setUnitsFalling ( bool  fall)

Toggles the switch that says "there are units falling, start the fall state".

Parameters
fallTrue if there are any units falling in the battlescape.

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