OpenXcom  1.0
Open-source clone of the original X-Com
SavedBattleGame.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <vector>
21 #include <string>
22 #include <yaml-cpp/yaml.h>
23 #include "BattleUnit.h"
24 #include "../Mod/AlienDeployment.h"
25 
26 namespace OpenXcom
27 {
28 
29 class Tile;
30 class SavedGame;
31 class MapDataSet;
32 class Node;
33 class BattlescapeState;
34 class Position;
35 class Pathfinding;
36 class TileEngine;
37 class BattleItem;
38 class Mod;
39 class State;
40 class RuleItem;
41 
48 {
49 private:
50  BattlescapeState *_battleState;
51  int _mapsize_x, _mapsize_y, _mapsize_z;
52  std::vector<MapDataSet*> _mapDataSets;
53  Tile **_tiles;
54  BattleUnit *_selectedUnit, *_lastSelectedUnit;
55  std::vector<Node*> _nodes;
56  std::vector<BattleUnit*> _units;
57  std::vector<BattleItem*> _items, _deleted;
58  Pathfinding *_pathfinding;
59  TileEngine *_tileEngine;
60  std::string _missionType;
61  int _globalShade;
62  UnitFaction _side;
63  int _turn;
64  bool _debugMode;
65  bool _aborted;
66  int _itemId;
67  int _objectiveType, _objectivesDestroyed, _objectivesNeeded;
68  std::vector<BattleUnit*> _exposedUnits;
69  std::list<BattleUnit*> _fallingUnits;
70  bool _unitsFalling, _cheating;
71  std::vector<Position> _tileSearch, _storageSpace;
72  BattleActionType _tuReserved;
73  bool _kneelReserved;
74  std::vector< std::vector<std::pair<int, int> > > _baseModules;
75  int _depth, _ambience;
76  double _ambientVolume;
77  std::vector<BattleItem*> _recoverGuaranteed, _recoverConditional;
78  std::string _music;
79  int _turnLimit, _cheatTurn;
80  ChronoTrigger _chronoTrigger;
81  bool _beforeGame;
83  BattleUnit *selectPlayerUnit(int dir, bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
84 public:
90  void load(const YAML::Node& node, Mod *mod, SavedGame* savedGame);
92  YAML::Node save() const;
94  void initMap(int mapsize_x, int mapsize_y, int mapsize_z, bool resetTerrain = true);
96  void initUtilities(Mod *mod);
98  std::vector<MapDataSet*> *getMapDataSets();
100  void setMissionType(const std::string &missionType);
102  std::string getMissionType() const;
104  void setGlobalShade(int shade);
106  int getGlobalShade() const;
108  Tile **getTiles() const;
110  std::vector<Node*> *getNodes();
112  std::vector<BattleItem*> *getItems();
114  std::vector<BattleUnit*> *getUnits();
116  int getMapSizeX() const;
118  int getMapSizeY() const;
120  int getMapSizeZ() const;
122  int getMapSizeXYZ() const;
123 
130  inline int getTileIndex(Position pos) const
131  {
132  return pos.z * _mapsize_y * _mapsize_x + pos.y * _mapsize_x + pos.x;
133  }
134 
136  void getTileCoords(int index, int *x, int *y, int *z) const;
137 
145  inline Tile *getTile(Position pos) const
146  {
147  if (pos.x < 0 || pos.y < 0 || pos.z < 0
148  || pos.x >= _mapsize_x || pos.y >= _mapsize_y || pos.z >= _mapsize_z)
149  return 0;
150 
151  return _tiles[getTileIndex(pos)];
152  }
153 
155  BattleUnit *getSelectedUnit() const;
157  void setSelectedUnit(BattleUnit *unit);
159  BattleUnit *selectPreviousPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
161  BattleUnit *selectNextPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
165  Pathfinding *getPathfinding() const;
167  TileEngine *getTileEngine() const;
169  UnitFaction getSide() const;
171  int getTurn() const;
173  void endTurn();
175  void setDebugMode();
177  bool getDebugMode() const;
179  void loadMapResources(Mod *mod);
181  void resetUnitTiles();
183  void removeItem(BattleItem *item);
185  void setAborted(bool flag);
187  bool isAborted() const;
189  void setObjectiveCount(int counter);
191  void addDestroyedObjective();
193  bool allObjectivesDestroyed() const;
195  int *getCurrentItemId();
197  Node *getSpawnNode(int nodeRank, BattleUnit *unit);
199  Node *getPatrolNode(bool scout, BattleUnit *unit, Node *fromNode);
201  void prepareNewTurn();
203  void reviveUnconsciousUnits();
207  bool setUnitPosition(BattleUnit *bu, Position position, bool testOnly = false);
209  bool addFallingUnit(BattleUnit* unit);
211  std::list<BattleUnit*> *getFallingUnits();
213  void setUnitsFalling(bool fall);
215  bool getUnitsFalling() const;
225  int getMoraleModifier(BattleUnit* unit = 0);
227  bool eyesOnTarget(UnitFaction faction, BattleUnit* unit);
229  bool placeUnitNearPosition(BattleUnit *unit, const Position& entryPoint, bool largeFriend);
231  void resetTurnCounter();
233  void resetTiles();
235  const std::vector<Position> &getTileSearch() const;
237  bool isCheating() const;
239  BattleActionType getTUReserved() const;
241  void setTUReserved(BattleActionType reserved);
243  bool getKneelReserved() const;
245  void setKneelReserved(bool reserved);
247  std::vector<Position> &getStorageSpace();
249  void randomizeItemLocations(Tile *t);
251  std::vector< std::vector<std::pair<int, int> > > &getModuleMap();
253  void calculateModuleMap();
257  int getDepth() const;
259  void setDepth(int depth);
261  void setPaletteByDepth(State *state);
263  void setAmbientSound(int sound);
265  int getAmbientSound() const;
267  std::vector<BattleItem*> *getGuaranteedRecoveredItems();
269  std::vector<BattleItem*> *getConditionalRecoveredItems();
271  std::string &getMusic();
273  void setMusic(const std::string& track);
275  void setObjectiveType(int type);
277  SpecialTileType getObjectiveType() const;
279  void setAmbientVolume(double volume);
281  double getAmbientVolume() const;
283  int getTurnLimit() const;
285  ChronoTrigger getChronoTrigger() const;
287  void setTurnLimit(int limit);
289  void setChronoTrigger(ChronoTrigger trigger);
291  void setCheatTurn(int turn);
293  bool isBeforeGame() const;
295  bool isItemUsable(RuleItem *item) const;
297  void resetUnitHitStates();
298 };
299 
300 }
void setTUReserved(BattleActionType reserved)
set the reserved fire mode.
Definition: SavedBattleGame.cpp:1806
void setDebugMode()
Sets debug mode.
Definition: SavedBattleGame.cpp:916
void loadMapResources(Mod *mod)
Load map resources.
Definition: SavedBattleGame.cpp:343
TileEngine * getTileEngine() const
Gets a pointer to the tileengine.
Definition: SavedBattleGame.cpp:795
A utility class that modifies tile properties on a battlescape map.
Definition: TileEngine.h:38
YAML::Node save() const
Saves a saved battle game to YAML.
Definition: SavedBattleGame.cpp:380
bool addFallingUnit(BattleUnit *unit)
Adds this unit to the vector of falling units.
Definition: SavedBattleGame.cpp:1597
bool getUnitsFalling() const
Checks the status of the switch that says "there are units falling".
Definition: SavedBattleGame.cpp:1638
void endTurn()
Ends the turn.
Definition: SavedBattleGame.cpp:830
void setUnitsFalling(bool fall)
Toggles the switch that says "there are units falling, start the fall state".
Definition: SavedBattleGame.cpp:1629
Tile * getTile(Position pos) const
Gets the Tile at a given position on the map.
Definition: SavedBattleGame.h:145
std::vector< BattleUnit * > * getUnits()
Gets a pointer to the list of units.
Definition: SavedBattleGame.cpp:768
std::vector< MapDataSet * > * getMapDataSets()
Gets the game&#39;s mapdatafiles.
Definition: SavedBattleGame.cpp:804
void resetUnitHitStates()
Reset all the unit hit state flags.
Definition: SavedBattleGame.cpp:2071
bool isAborted() const
Checks if the mission was aborted.
Definition: SavedBattleGame.cpp:1113
A game state that receives user input and reacts accordingly.
Definition: State.h:44
BattlescapeGame * getBattleGame()
Gets a pointer to the BattlescapeGame.
Definition: SavedBattleGame.cpp:948
void setBattleState(BattlescapeState *bs)
Sets the pointer to the BattlescapeState.
Definition: SavedBattleGame.cpp:957
int getDepth() const
get the depth of the battlescape game.
Definition: SavedBattleGame.cpp:1880
void setPaletteByDepth(State *state)
uses the depth variable to set a palette.
Definition: SavedBattleGame.cpp:1898
void setObjectiveType(int type)
Sets the objective type for this mission.
Definition: SavedBattleGame.cpp:1970
void resetUnitTiles()
Resets tiles units are standing on.
Definition: SavedBattleGame.cpp:965
std::vector< BattleItem * > * getConditionalRecoveredItems()
gets the list of items we MIGHT get.
Definition: SavedBattleGame.cpp:1943
SpecialTileType getObjectiveType() const
Gets the objective type of this mission.
Definition: SavedBattleGame.cpp:1979
int * getCurrentItemId()
Gets the current item ID.
Definition: SavedBattleGame.cpp:1162
The game data that gets written to disk when the game is saved.
Definition: SavedGame.h:99
void resetTurnCounter()
Resets the turn counter.
Definition: SavedBattleGame.cpp:1755
int getTurn() const
Gets the turn number.
Definition: SavedBattleGame.cpp:822
std::vector< BattleItem * > * getItems()
Gets a pointer to the list of items.
Definition: SavedBattleGame.cpp:777
Contains all the game-specific static data that never changes throughout the game, like rulesets and resources.
Definition: Mod.h:87
BattleUnit * getSelectedUnit() const
Gets the currently selected unit.
Definition: SavedBattleGame.cpp:629
int getTurnLimit() const
Gets the turn limit for this mission.
Definition: SavedBattleGame.cpp:2008
void prepareNewTurn()
Carries out new turn preparations.
Definition: SavedBattleGame.cpp:1294
std::vector< BattleItem * > * getGuaranteedRecoveredItems()
gets the list of items we&#39;re guaranteed.
Definition: SavedBattleGame.cpp:1934
void removeUnconsciousBodyItem(BattleUnit *bu)
Removes the body item that corresponds to the unit.
Definition: SavedBattleGame.cpp:1491
void resetTiles()
Resets the visibility of all tiles on the map.
Definition: SavedBattleGame.cpp:1766
bool allObjectivesDestroyed() const
Checks if all the objectives are destroyed.
Definition: SavedBattleGame.cpp:1153
UnitFaction getSide() const
Gets the playing side.
Definition: SavedBattleGame.cpp:813
void setDepth(int depth)
set the depth of the battlescape game.
Definition: SavedBattleGame.cpp:1889
void setAmbientVolume(double volume)
sets the ambient sound effect;
Definition: SavedBattleGame.cpp:1990
void randomizeItemLocations(Tile *t)
move all the leftover items to random locations in the storage tiles vector.
Definition: SavedBattleGame.cpp:1013
void setSelectedUnit(BattleUnit *unit)
Sets the currently selected unit.
Definition: SavedBattleGame.cpp:638
void setAborted(bool flag)
Sets whether the mission was aborted.
Definition: SavedBattleGame.cpp:1104
int getMapSizeZ() const
Gets terrain size z.
Definition: SavedBattleGame.cpp:597
int getMapSizeXYZ() const
Gets terrain x*y*z.
Definition: SavedBattleGame.cpp:606
void setMusic(const std::string &track)
Set the name of the music track.
Definition: SavedBattleGame.cpp:1961
std::vector< std::vector< std::pair< int, int > > > & getModuleMap()
get a reference to the baseModules map.
Definition: SavedBattleGame.cpp:1836
SavedGame * getGeoscapeSave()
a shortcut to the geoscape save.
Definition: SavedBattleGame.cpp:1871
Node * getSpawnNode(int nodeRank, BattleUnit *unit)
Gets a spawn node.
Definition: SavedBattleGame.cpp:1173
void removeItem(BattleItem *item)
Removes an item from the game.
Definition: SavedBattleGame.cpp:1036
int getMapSizeY() const
Gets terrain size y.
Definition: SavedBattleGame.cpp:588
Represents a specific type of item.
Definition: RuleItem.h:40
int getMoraleModifier(BattleUnit *unit=0)
Gets the morale modifier for XCom based on the highest ranked, living XCom unit, or the modifier for ...
Definition: SavedBattleGame.cpp:1670
void setAmbientSound(int sound)
sets the ambient sound effect;
Definition: SavedBattleGame.cpp:1916
void initUtilities(Mod *mod)
Initialises the pathfinding and tileengine.
Definition: SavedBattleGame.cpp:531
void setMissionType(const std::string &missionType)
Sets the mission type.
Definition: SavedBattleGame.cpp:543
Node * getPatrolNode(bool scout, BattleUnit *unit, Node *fromNode)
Gets a patrol node.
Definition: SavedBattleGame.cpp:1218
BattleUnit * selectUnit(Position pos)
Selects the unit with position on map.
Definition: SavedBattleGame.cpp:741
BattleActionType getTUReserved() const
get the reserved fire mode.
Definition: SavedBattleGame.cpp:1797
Represents a single item in the battlescape.
Definition: BattleItem.h:37
bool setUnitPosition(BattleUnit *bu, Position position, bool testOnly=false)
Sets or tries to set a unit of a certain size on a certain position of the map.
Definition: SavedBattleGame.cpp:1512
std::string & getMusic()
Get the name of the music track.
Definition: SavedBattleGame.cpp:1952
bool placeUnitNearPosition(BattleUnit *unit, const Position &entryPoint, bool largeFriend)
Attempts to place a unit on or near entryPoint.
Definition: SavedBattleGame.cpp:1719
void setChronoTrigger(ChronoTrigger trigger)
Sets the action that triggers when the timer runs out.
Definition: SavedBattleGame.cpp:2035
void setObjectiveCount(int counter)
Sets how many objectives need to be destroyed.
Definition: SavedBattleGame.cpp:1121
Pathfinding * getPathfinding() const
Gets the pathfinding object.
Definition: SavedBattleGame.cpp:786
bool isBeforeGame() const
Check whether the battle has actually commenced or not.
Definition: SavedBattleGame.cpp:2049
BattleUnit * getHighestRankedXCom()
Gets the highest ranked, living XCom unit.
Definition: SavedBattleGame.cpp:1647
double getAmbientVolume() const
gets the ambient sound effect;
Definition: SavedBattleGame.cpp:1999
BattleUnit * selectNextPlayerUnit(bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
Selects the next soldier.
Definition: SavedBattleGame.cpp:664
void calculateModuleMap()
calculate the number of map modules remaining
Definition: SavedBattleGame.cpp:1846
int getMapSizeX() const
Gets terrain size x.
Definition: SavedBattleGame.cpp:579
void load(const YAML::Node &node, Mod *mod, SavedGame *savedGame)
Loads a saved battle game from YAML.
Definition: SavedBattleGame.cpp:118
std::vector< Node * > * getNodes()
Gets a pointer to the list of nodes.
Definition: SavedBattleGame.cpp:759
bool isItemUsable(RuleItem *item) const
Checks if an item is usable on this map.
Definition: SavedBattleGame.cpp:2058
int getAmbientSound() const
gets the ambient sound effect;
Definition: SavedBattleGame.cpp:1925
~SavedBattleGame()
Cleans up the saved game.
Definition: SavedBattleGame.cpp:65
bool getDebugMode() const
Gets debug mode.
Definition: SavedBattleGame.cpp:930
bool isCheating() const
check if the AI has engaged cheat mode.
Definition: SavedBattleGame.cpp:1788
Tile ** getTiles() const
Gets a pointer to the tiles, a tile is the smallest component of battlescape.
Definition: SavedBattleGame.cpp:479
void getTileCoords(int index, int *x, int *y, int *z) const
Converts a tile index to its coordinates.
Definition: SavedBattleGame.cpp:618
Basic element of which a battle map is build.
Definition: Tile.h:42
std::vector< Position > & getStorageSpace()
give me access to the storage tiles vector.
Definition: SavedBattleGame.cpp:1004
BattleUnit * selectPreviousPlayerUnit(bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
Selects the previous soldier.
Definition: SavedBattleGame.cpp:651
int getGlobalShade() const
Gets the global shade.
Definition: SavedBattleGame.cpp:570
bool getKneelReserved() const
get whether we are reserving TUs to kneel.
Definition: SavedBattleGame.cpp:1815
void setGlobalShade(int shade)
Sets the global shade.
Definition: SavedBattleGame.cpp:561
Battlescape game - the core game engine of the battlescape game.
Definition: BattlescapeGame.h:68
ChronoTrigger getChronoTrigger() const
Gets the action that triggers when the timer runs out.
Definition: SavedBattleGame.cpp:2017
A utility class that calculates the shortest path between two points on the battlescape map...
Definition: Pathfinding.h:35
void setTurnLimit(int limit)
Sets the turn limit for this mission.
Definition: SavedBattleGame.cpp:2026
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:47
void addDestroyedObjective()
increments the objective counter.
Definition: SavedBattleGame.cpp:1130
void setCheatTurn(int turn)
Sets the turn to start the aliens cheating.
Definition: SavedBattleGame.cpp:2044
void initMap(int mapsize_x, int mapsize_y, int mapsize_z, bool resetTerrain=true)
Sets the dimensions of the map and initializes it.
Definition: SavedBattleGame.cpp:490
Represents a node/spawnpoint in the battlescape, loaded from RMP files.
Definition: Node.h:32
std::string getMissionType() const
Gets the mission type.
Definition: SavedBattleGame.cpp:552
void setKneelReserved(bool reserved)
set whether we are reserving TUs to kneel.
Definition: SavedBattleGame.cpp:1824
Easy handling of X-Y-Z coordinates.
Definition: Position.h:28
MIDI track.
Definition: GMCat.cpp:40
BattlescapeState * getBattleState()
Gets a pointer to the BattlescapeState.
Definition: SavedBattleGame.cpp:939
Battlescape screen which shows the tactical battle.
Definition: BattlescapeState.h:47
int getTileIndex(Position pos) const
Converts coordinates into a unique index.
Definition: SavedBattleGame.h:130
SavedBattleGame()
Creates a new battle save, based on the current generic save.
Definition: SavedBattleGame.cpp:50
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:59
void reviveUnconsciousUnits()
Revives unconscious units (healthcheck).
Definition: SavedBattleGame.cpp:1452
Definition: BaseInfoState.cpp:40
const std::vector< Position > & getTileSearch() const
get an 11x11 grid of positions (-10 to +10) to check.
Definition: SavedBattleGame.cpp:1779
bool eyesOnTarget(UnitFaction faction, BattleUnit *unit)
Checks whether a particular faction has eyes on *unit (whether any unit on that faction sees *unit)...
Definition: SavedBattleGame.cpp:1577
std::list< BattleUnit * > * getFallingUnits()
Gets the vector of falling units.
Definition: SavedBattleGame.cpp:1620