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 
47 {
48 private:
49  BattlescapeState *_battleState;
50  int _mapsize_x, _mapsize_y, _mapsize_z;
51  std::vector<MapDataSet*> _mapDataSets;
52  Tile **_tiles;
53  BattleUnit *_selectedUnit, *_lastSelectedUnit;
54  std::vector<Node*> _nodes;
55  std::vector<BattleUnit*> _units;
56  std::vector<BattleItem*> _items, _deleted;
57  Pathfinding *_pathfinding;
58  TileEngine *_tileEngine;
59  std::string _missionType;
60  int _globalShade;
61  UnitFaction _side;
62  int _turn;
63  bool _debugMode;
64  bool _aborted;
65  int _itemId;
66  int _objectiveType, _objectivesDestroyed, _objectivesNeeded;
67  std::vector<BattleUnit*> _exposedUnits;
68  std::list<BattleUnit*> _fallingUnits;
69  bool _unitsFalling, _cheating;
70  std::vector<Position> _tileSearch, _storageSpace;
71  BattleActionType _tuReserved;
72  bool _kneelReserved;
73  std::vector< std::vector<std::pair<int, int> > > _baseModules;
74  int _depth, _ambience;
75  double _ambientVolume;
76  std::vector<BattleItem*> _recoverGuaranteed, _recoverConditional;
77  std::string _music;
78  int _turnLimit, _cheatTurn;
79  ChronoTrigger _chronoTrigger;
80  bool _beforeGame;
82  BattleUnit *selectPlayerUnit(int dir, bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
83 public:
89  void load(const YAML::Node& node, Mod *mod, SavedGame* savedGame);
91  YAML::Node save() const;
93  void initMap(int mapsize_x, int mapsize_y, int mapsize_z);
95  void initUtilities(Mod *mod);
97  std::vector<MapDataSet*> *getMapDataSets();
99  void setMissionType(const std::string &missionType);
101  std::string getMissionType() const;
103  void setGlobalShade(int shade);
105  int getGlobalShade() const;
107  Tile **getTiles() const;
109  std::vector<Node*> *getNodes();
111  std::vector<BattleItem*> *getItems();
113  std::vector<BattleUnit*> *getUnits();
115  int getMapSizeX() const;
117  int getMapSizeY() const;
119  int getMapSizeZ() const;
121  int getMapSizeXYZ() const;
122 
129  inline int getTileIndex(Position pos) const
130  {
131  return pos.z * _mapsize_y * _mapsize_x + pos.y * _mapsize_x + pos.x;
132  }
133 
135  void getTileCoords(int index, int *x, int *y, int *z) const;
136 
144  inline Tile *getTile(Position pos) const
145  {
146  if (pos.x < 0 || pos.y < 0 || pos.z < 0
147  || pos.x >= _mapsize_x || pos.y >= _mapsize_y || pos.z >= _mapsize_z)
148  return 0;
149 
150  return _tiles[getTileIndex(pos)];
151  }
152 
154  BattleUnit *getSelectedUnit() const;
156  void setSelectedUnit(BattleUnit *unit);
158  BattleUnit *selectPreviousPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
160  BattleUnit *selectNextPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
164  Pathfinding *getPathfinding() const;
166  TileEngine *getTileEngine() const;
168  UnitFaction getSide() const;
170  int getTurn() const;
172  void endTurn();
174  void setDebugMode();
176  bool getDebugMode() const;
178  void loadMapResources(Mod *mod);
180  void resetUnitTiles();
182  void removeItem(BattleItem *item);
184  void setAborted(bool flag);
186  bool isAborted() const;
188  void setObjectiveCount(int counter);
190  void addDestroyedObjective();
192  bool allObjectivesDestroyed() const;
194  int *getCurrentItemId();
196  Node *getSpawnNode(int nodeRank, BattleUnit *unit);
198  Node *getPatrolNode(bool scout, BattleUnit *unit, Node *fromNode);
200  void prepareNewTurn();
202  void reviveUnconsciousUnits();
206  bool setUnitPosition(BattleUnit *bu, Position position, bool testOnly = false);
208  bool addFallingUnit(BattleUnit* unit);
210  std::list<BattleUnit*> *getFallingUnits();
212  void setUnitsFalling(bool fall);
214  bool getUnitsFalling() const;
224  int getMoraleModifier(BattleUnit* unit = 0);
226  bool eyesOnTarget(UnitFaction faction, BattleUnit* unit);
228  bool placeUnitNearPosition(BattleUnit *unit, const Position& entryPoint, bool largeFriend);
230  void resetTurnCounter();
232  void resetTiles();
234  const std::vector<Position> &getTileSearch() const;
236  bool isCheating() const;
238  BattleActionType getTUReserved() const;
240  void setTUReserved(BattleActionType reserved);
242  bool getKneelReserved() const;
244  void setKneelReserved(bool reserved);
246  std::vector<Position> &getStorageSpace();
248  void randomizeItemLocations(Tile *t);
250  std::vector< std::vector<std::pair<int, int> > > &getModuleMap();
252  void calculateModuleMap();
256  int getDepth() const;
258  void setDepth(int depth);
260  void setPaletteByDepth(State *state);
262  void setAmbientSound(int sound);
264  int getAmbientSound() const;
266  std::vector<BattleItem*> *getGuaranteedRecoveredItems();
268  std::vector<BattleItem*> *getConditionalRecoveredItems();
270  std::string &getMusic();
272  void setMusic(const std::string& track);
274  void setObjectiveType(int type);
276  SpecialTileType getObjectiveType() const;
278  void setAmbientVolume(double volume);
280  double getAmbientVolume() const;
282  int getTurnLimit() const;
284  ChronoTrigger getChronoTrigger() const;
286  void setTurnLimit(int limit);
288  void setChronoTrigger(ChronoTrigger trigger);
290  void setCheatTurn(int turn);
291  bool isBeforeGame() const;
292 };
293 
294 }
void setTUReserved(BattleActionType reserved)
set the reserved fire mode.
Definition: SavedBattleGame.cpp:1799
void setDebugMode()
Sets debug mode.
Definition: SavedBattleGame.cpp:914
void loadMapResources(Mod *mod)
Load map resources.
Definition: SavedBattleGame.cpp:346
TileEngine * getTileEngine() const
Gets a pointer to the tileengine.
Definition: SavedBattleGame.cpp:793
A utility class that modifies tile properties on a battlescape map.
Definition: TileEngine.h:37
YAML::Node save() const
Saves a saved battle game to YAML.
Definition: SavedBattleGame.cpp:382
bool addFallingUnit(BattleUnit *unit)
Adds this unit to the vector of falling units.
Definition: SavedBattleGame.cpp:1590
bool getUnitsFalling() const
Checks the status of the switch that says "there are units falling".
Definition: SavedBattleGame.cpp:1631
void endTurn()
Ends the turn.
Definition: SavedBattleGame.cpp:828
void setUnitsFalling(bool fall)
Toggles the switch that says "there are units falling, start the fall state".
Definition: SavedBattleGame.cpp:1622
Tile * getTile(Position pos) const
Gets the Tile at a given position on the map.
Definition: SavedBattleGame.h:144
std::vector< BattleUnit * > * getUnits()
Gets a pointer to the list of units.
Definition: SavedBattleGame.cpp:766
std::vector< MapDataSet * > * getMapDataSets()
Gets the game&#39;s mapdatafiles.
Definition: SavedBattleGame.cpp:802
void initMap(int mapsize_x, int mapsize_y, int mapsize_z)
Sets the dimensions of the map and initializes it.
Definition: SavedBattleGame.cpp:492
bool isAborted() const
Checks if the mission was aborted.
Definition: SavedBattleGame.cpp:1102
A game state that receives user input and reacts accordingly.
Definition: State.h:43
BattlescapeGame * getBattleGame()
Gets a pointer to the BattlescapeGame.
Definition: SavedBattleGame.cpp:946
void setBattleState(BattlescapeState *bs)
Sets the pointer to the BattlescapeState.
Definition: SavedBattleGame.cpp:955
int getDepth() const
get the depth of the battlescape game.
Definition: SavedBattleGame.cpp:1873
void setPaletteByDepth(State *state)
uses the depth variable to set a palette.
Definition: SavedBattleGame.cpp:1891
void setObjectiveType(int type)
Sets the objective type for this mission.
Definition: SavedBattleGame.cpp:1963
void resetUnitTiles()
Resets tiles units are standing on.
Definition: SavedBattleGame.cpp:963
std::vector< BattleItem * > * getConditionalRecoveredItems()
gets the list of items we MIGHT get.
Definition: SavedBattleGame.cpp:1936
SpecialTileType getObjectiveType() const
Gets the objective type of this mission.
Definition: SavedBattleGame.cpp:1972
int * getCurrentItemId()
Gets the current item ID.
Definition: SavedBattleGame.cpp:1156
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:1748
int getTurn() const
Gets the turn number.
Definition: SavedBattleGame.cpp:820
std::vector< BattleItem * > * getItems()
Gets a pointer to the list of items.
Definition: SavedBattleGame.cpp:775
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:627
int getTurnLimit() const
Gets the turn limit for this mission.
Definition: SavedBattleGame.cpp:2001
void prepareNewTurn()
Carries out new turn preparations.
Definition: SavedBattleGame.cpp:1288
std::vector< BattleItem * > * getGuaranteedRecoveredItems()
gets the list of items we&#39;re guaranteed.
Definition: SavedBattleGame.cpp:1927
void removeUnconsciousBodyItem(BattleUnit *bu)
Removes the body item that corresponds to the unit.
Definition: SavedBattleGame.cpp:1484
void resetTiles()
Resets the visibility of all tiles on the map.
Definition: SavedBattleGame.cpp:1759
bool allObjectivesDestroyed() const
Checks if all the objectives are destroyed.
Definition: SavedBattleGame.cpp:1147
UnitFaction getSide() const
Gets the playing side.
Definition: SavedBattleGame.cpp:811
void setDepth(int depth)
set the depth of the battlescape game.
Definition: SavedBattleGame.cpp:1882
void setAmbientVolume(double volume)
sets the ambient sound effect;
Definition: SavedBattleGame.cpp:1983
void randomizeItemLocations(Tile *t)
move all the leftover items to random locations in the storage tiles vector.
Definition: SavedBattleGame.cpp:1011
void setSelectedUnit(BattleUnit *unit)
Sets the currently selected unit.
Definition: SavedBattleGame.cpp:636
void setAborted(bool flag)
Sets whether the mission was aborted.
Definition: SavedBattleGame.cpp:1093
int getMapSizeZ() const
Gets terrain size z.
Definition: SavedBattleGame.cpp:595
int getMapSizeXYZ() const
Gets terrain x*y*z.
Definition: SavedBattleGame.cpp:604
void setMusic(const std::string &track)
Set the name of the music track.
Definition: SavedBattleGame.cpp:1954
std::vector< std::vector< std::pair< int, int > > > & getModuleMap()
get a reference to the baseModules map.
Definition: SavedBattleGame.cpp:1829
SavedGame * getGeoscapeSave()
a shortcut to the geoscape save.
Definition: SavedBattleGame.cpp:1864
Node * getSpawnNode(int nodeRank, BattleUnit *unit)
Gets a spawn node.
Definition: SavedBattleGame.cpp:1167
void removeItem(BattleItem *item)
Removes an item from the game.
Definition: SavedBattleGame.cpp:1034
int getMapSizeY() const
Gets terrain size y.
Definition: SavedBattleGame.cpp:586
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:1663
void setAmbientSound(int sound)
sets the ambient sound effect;
Definition: SavedBattleGame.cpp:1909
void initUtilities(Mod *mod)
Initialises the pathfinding and tileengine.
Definition: SavedBattleGame.cpp:529
void setMissionType(const std::string &missionType)
Sets the mission type.
Definition: SavedBattleGame.cpp:541
Node * getPatrolNode(bool scout, BattleUnit *unit, Node *fromNode)
Gets a patrol node.
Definition: SavedBattleGame.cpp:1212
BattleUnit * selectUnit(Position pos)
Selects the unit with position on map.
Definition: SavedBattleGame.cpp:739
BattleActionType getTUReserved() const
get the reserved fire mode.
Definition: SavedBattleGame.cpp:1790
Represents a single item in the battlescape.
Definition: BattleItem.h:36
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:1505
std::string & getMusic()
Get the name of the music track.
Definition: SavedBattleGame.cpp:1945
bool placeUnitNearPosition(BattleUnit *unit, const Position &entryPoint, bool largeFriend)
Attempts to place a unit on or near entryPoint.
Definition: SavedBattleGame.cpp:1712
void setChronoTrigger(ChronoTrigger trigger)
Sets the action that triggers when the timer runs out.
Definition: SavedBattleGame.cpp:2028
void setObjectiveCount(int counter)
Sets how many objectives need to be destroyed.
Definition: SavedBattleGame.cpp:1110
Pathfinding * getPathfinding() const
Gets the pathfinding object.
Definition: SavedBattleGame.cpp:784
BattleUnit * getHighestRankedXCom()
Gets the highest ranked, living XCom unit.
Definition: SavedBattleGame.cpp:1640
double getAmbientVolume() const
gets the ambient sound effect;
Definition: SavedBattleGame.cpp:1992
BattleUnit * selectNextPlayerUnit(bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
Selects the next soldier.
Definition: SavedBattleGame.cpp:662
void calculateModuleMap()
calculate the number of map modules remaining
Definition: SavedBattleGame.cpp:1839
int getMapSizeX() const
Gets terrain size x.
Definition: SavedBattleGame.cpp:577
void load(const YAML::Node &node, Mod *mod, SavedGame *savedGame)
Loads a saved battle game from YAML.
Definition: SavedBattleGame.cpp:117
std::vector< Node * > * getNodes()
Gets a pointer to the list of nodes.
Definition: SavedBattleGame.cpp:757
int getAmbientSound() const
gets the ambient sound effect;
Definition: SavedBattleGame.cpp:1918
~SavedBattleGame()
Cleans up the saved game.
Definition: SavedBattleGame.cpp:64
bool getDebugMode() const
Gets debug mode.
Definition: SavedBattleGame.cpp:928
bool isCheating() const
check if the AI has engaged cheat mode.
Definition: SavedBattleGame.cpp:1781
Tile ** getTiles() const
Gets a pointer to the tiles, a tile is the smallest component of battlescape.
Definition: SavedBattleGame.cpp:481
void getTileCoords(int index, int *x, int *y, int *z) const
Converts a tile index to its coordinates.
Definition: SavedBattleGame.cpp:616
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:1002
BattleUnit * selectPreviousPlayerUnit(bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
Selects the previous soldier.
Definition: SavedBattleGame.cpp:649
int getGlobalShade() const
Gets the global shade.
Definition: SavedBattleGame.cpp:568
bool getKneelReserved() const
get whether we are reserving TUs to kneel.
Definition: SavedBattleGame.cpp:1808
void setGlobalShade(int shade)
Sets the global shade.
Definition: SavedBattleGame.cpp:559
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:2010
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:2019
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:46
void addDestroyedObjective()
increments the objective counter.
Definition: SavedBattleGame.cpp:1119
void setCheatTurn(int turn)
Sets the turn to start the aliens cheating.
Definition: SavedBattleGame.cpp:2037
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:550
void setKneelReserved(bool reserved)
set whether we are reserving TUs to kneel.
Definition: SavedBattleGame.cpp:1817
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:937
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:129
SavedBattleGame()
Creates a new battle save, based on the current generic save.
Definition: SavedBattleGame.cpp:49
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:1445
Definition: BaseInfoState.cpp:40
const std::vector< Position > & getTileSearch() const
get an 11x11 grid of positions (-10 to +10) to check.
Definition: SavedBattleGame.cpp:1772
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:1570
std::list< BattleUnit * > * getFallingUnits()
Gets the vector of falling units.
Definition: SavedBattleGame.cpp:1613