OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SavedBattleGame.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_SAVEDBATTLEGAME_H
20 #define OPENXCOM_SAVEDBATTLEGAME_H
21 
22 #include <iostream>
23 #include <algorithm>
24 #include <vector>
25 #include <string>
26 #include <SDL.h>
27 #include <yaml-cpp/yaml.h>
28 #include "BattleUnit.h"
29 
30 namespace OpenXcom
31 {
32 
33 class Tile;
34 class SavedGame;
35 class MapDataSet;
36 class Node;
37 class Game;
38 class BattlescapeState;
39 class Position;
40 class Pathfinding;
41 class TileEngine;
42 class BattleItem;
43 class Ruleset;
44 
51 {
52 private:
53  BattlescapeState *_battleState;
54  int _mapsize_x, _mapsize_y, _mapsize_z;
55  std::vector<MapDataSet*> _mapDataSets;
56  Tile **_tiles;
57  BattleUnit *_selectedUnit, *_lastSelectedUnit;
58  std::vector<Node*> _nodes;
59  std::vector<BattleUnit*> _units;
60  std::vector<BattleItem*> _items, _deleted;
61  Pathfinding *_pathfinding;
62  TileEngine *_tileEngine;
63  std::string _missionType;
64  int _globalShade;
65  UnitFaction _side;
66  int _turn;
67  bool _debugMode;
68  bool _aborted;
69  int _itemId;
70  bool _objectiveDestroyed;
71  std::vector<BattleUnit*> _exposedUnits;
72  std::list<BattleUnit*> _fallingUnits;
73  bool _unitsFalling, _cheating;
74  std::vector<Position> _tileSearch, _storageSpace;
75  BattleActionType _tuReserved;
76  bool _kneelReserved;
77  std::vector< std::vector<std::pair<int, int> > > _baseModules;
79  BattleUnit *selectPlayerUnit(int dir, bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
80 public:
86  void load(const YAML::Node& node, Ruleset *rule, SavedGame* savedGame);
88  YAML::Node save() const;
90  void initMap(int mapsize_x, int mapsize_y, int mapsize_z);
92  void initUtilities(ResourcePack *res);
94  std::vector<MapDataSet*> *getMapDataSets();
96  void setMissionType(const std::string &missionType);
98  std::string getMissionType() const;
100  void setGlobalShade(int shade);
102  int getGlobalShade() const;
104  Tile **getTiles() const;
106  std::vector<Node*> *getNodes();
108  std::vector<BattleItem*> *getItems();
110  std::vector<BattleUnit*> *getUnits();
112  int getMapSizeX() const;
114  int getMapSizeY() const;
116  int getMapSizeZ() const;
118  int getMapSizeXYZ() const;
119 
126  inline int getTileIndex(const Position& pos) const
127  {
128  return pos.z * _mapsize_y * _mapsize_x + pos.y * _mapsize_x + pos.x;
129  }
130 
132  void getTileCoords(int index, int *x, int *y, int *z) const;
133 
141  inline Tile *getTile(const Position& pos) const
142  {
143  if (pos.x < 0 || pos.y < 0 || pos.z < 0
144  || pos.x >= _mapsize_x || pos.y >= _mapsize_y || pos.z >= _mapsize_z)
145  return 0;
146 
147  return _tiles[getTileIndex(pos)];
148  }
149 
151  BattleUnit *getSelectedUnit() const;
153  void setSelectedUnit(BattleUnit *unit);
155  BattleUnit *selectPreviousPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
157  BattleUnit *selectNextPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
159  BattleUnit *selectUnit(const Position& pos);
161  Pathfinding *getPathfinding() const;
163  TileEngine *getTileEngine() const;
165  UnitFaction getSide() const;
167  int getTurn() const;
169  void endTurn();
171  void setDebugMode();
173  bool getDebugMode() const;
175  void loadMapResources(Game *game);
177  void resetUnitTiles();
179  void removeItem(BattleItem *item);
181  void setAborted(bool flag);
183  bool isAborted() const;
185  void setObjectiveDestroyed(bool flag);
187  bool isObjectiveDestroyed();
189  int *getCurrentItemId();
191  Node *getSpawnNode(int nodeRank, BattleUnit *unit);
193  Node *getPatrolNode(bool scout, BattleUnit *unit, Node *fromNode);
195  void prepareNewTurn();
197  void reviveUnconsciousUnits();
201  bool setUnitPosition(BattleUnit *bu, const Position &position, bool testOnly = false);
203  bool addFallingUnit(BattleUnit* unit);
205  std::list<BattleUnit*> *getFallingUnits();
207  void setUnitsFalling(bool fall);
209  bool getUnitsFalling() const;
219  int getMoraleModifier(BattleUnit* unit = 0);
221  bool eyesOnTarget(UnitFaction faction, BattleUnit* unit);
223  bool placeUnitNearPosition(BattleUnit *unit, Position entryPoint);
225  void resetTurnCounter();
227  void resetTiles();
229  const std::vector<Position> getTileSearch();
231  bool isCheating();
233  BattleActionType getTUReserved() const;
235  void setTUReserved(BattleActionType reserved);
237  bool getKneelReserved() const;
239  void setKneelReserved(bool reserved);
241  std::vector<Position> &getStorageSpace();
243  void randomizeItemLocations(Tile *t);
245  std::vector< std::vector<std::pair<int, int> > > &getModuleMap();
247  void calculateModuleMap();
250 
251 };
252 
253 }
254 
255 #endif
void setTUReserved(BattleActionType reserved)
set the reserved fire mode.
Definition: SavedBattleGame.cpp:1699
void setDebugMode()
Sets debug mode.
Definition: SavedBattleGame.cpp:867
A utility class that modifies tile properties on a battlescape map.
Definition: TileEngine.h:40
bool getUnitsFalling() const
Checks the status of the switch that says "there are units falling".
Definition: SavedBattleGame.cpp:1537
bool addFallingUnit(BattleUnit *unit)
Adds this unit to the vector of falling units.
Definition: SavedBattleGame.cpp:1496
void endTurn()
Ends the turn.
Definition: SavedBattleGame.cpp:781
void setUnitsFalling(bool fall)
Toggles the switch that says "there are units falling, start the fall state".
Definition: SavedBattleGame.cpp:1528
BattleUnit * selectUnit(const Position &pos)
Selects the unit with position on map.
Definition: SavedBattleGame.cpp:692
std::vector< BattleUnit * > * getUnits()
Gets a pointer to the list of units.
Definition: SavedBattleGame.cpp:719
std::vector< MapDataSet * > * getMapDataSets()
Gets the game's mapdatafiles.
Definition: SavedBattleGame.cpp:755
void initMap(int mapsize_x, int mapsize_y, int mapsize_z)
Sets the dimensions of the map and initializes it.
Definition: SavedBattleGame.cpp:448
BattlescapeGame * getBattleGame()
Gets a pointer to the BattlescapeGame.
Definition: SavedBattleGame.cpp:899
void setBattleState(BattlescapeState *bs)
Sets the pointer to the BattlescapeState.
Definition: SavedBattleGame.cpp:908
bool isAborted() const
Checks if the mission was aborted.
Definition: SavedBattleGame.cpp:1053
void resetUnitTiles()
Resets tiles units are standing on.
Definition: SavedBattleGame.cpp:916
Pathfinding * getPathfinding() const
Gets the pathfinding object.
Definition: SavedBattleGame.cpp:737
Tile ** getTiles() const
Gets a pointer to the tiles, a tile is the smallest component of battlescape.
Definition: SavedBattleGame.cpp:437
int * getCurrentItemId()
Gets the current item ID.
Definition: SavedBattleGame.cpp:1086
The game data that gets written to disk when the game is saved.
Definition: SavedGame.h:80
void resetTurnCounter()
Resets the turn counter.
Definition: SavedBattleGame.cpp:1651
int getTurn() const
Gets the turn number.
Definition: SavedBattleGame.cpp:773
std::vector< BattleItem * > * getItems()
Gets a pointer to the list of items.
Definition: SavedBattleGame.cpp:728
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.
Definition: SavedBattleGame.cpp:1422
void prepareNewTurn()
Carries out new turn preparations.
Definition: SavedBattleGame.cpp:1207
bool getKneelReserved() const
get whether we are reserving TUs to kneel.
Definition: SavedBattleGame.cpp:1708
void removeUnconsciousBodyItem(BattleUnit *bu)
Removes the body item that corresponds to the unit.
Definition: SavedBattleGame.cpp:1401
void resetTiles()
Resets the visibility of all tiles on the map.
Definition: SavedBattleGame.cpp:1659
void randomizeItemLocations(Tile *t)
move all the leftover items to random locations in the storage tiles vector.
Definition: SavedBattleGame.cpp:963
void setSelectedUnit(BattleUnit *unit)
Sets the currently selected unit.
Definition: SavedBattleGame.cpp:589
void setAborted(bool flag)
Sets whether the mission was aborted.
Definition: SavedBattleGame.cpp:1044
int getTileIndex(const Position &pos) const
Converts coordinates into a unique index.
Definition: SavedBattleGame.h:126
std::vector< std::vector< std::pair< int, int > > > & getModuleMap()
get a reference to the baseModules map.
Definition: SavedBattleGame.cpp:1729
TileEngine * getTileEngine() const
Gets a pointer to the tileengine.
Definition: SavedBattleGame.cpp:746
SavedGame * getGeoscapeSave()
a shortcut to the geoscape save.
Definition: SavedBattleGame.cpp:1760
Node * getSpawnNode(int nodeRank, BattleUnit *unit)
Gets a spawn node.
Definition: SavedBattleGame.cpp:1097
void removeItem(BattleItem *item)
Removes an item from the game.
Definition: SavedBattleGame.cpp:985
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:1569
void setMissionType(const std::string &missionType)
Sets the mission type.
Definition: SavedBattleGame.cpp:494
Tile * getTile(const Position &pos) const
Gets the Tile at a given position on the map.
Definition: SavedBattleGame.h:141
bool placeUnitNearPosition(BattleUnit *unit, Position entryPoint)
Attempts to place a unit on or near entryPoint.
Definition: SavedBattleGame.cpp:1618
Node * getPatrolNode(bool scout, BattleUnit *unit, Node *fromNode)
Gets a patrol node.
Definition: SavedBattleGame.cpp:1138
int getMapSizeX() const
Gets terrain size x.
Definition: SavedBattleGame.cpp:530
int getGlobalShade() const
Gets the global shade.
Definition: SavedBattleGame.cpp:521
UnitFaction getSide() const
Gets the playing side.
Definition: SavedBattleGame.cpp:764
Represents a single item in the battlescape.
Definition: BattleItem.h:39
Set of rules and stats for a game.
Definition: Ruleset.h:69
int getMapSizeY() const
Gets terrain size y.
Definition: SavedBattleGame.cpp:539
BattleUnit * getHighestRankedXCom()
Gets the highest ranked, living XCom unit.
Definition: SavedBattleGame.cpp:1546
YAML::Node save() const
Saves a saved battle game to YAML.
Definition: SavedBattleGame.cpp:355
std::string getMissionType() const
Gets the mission type.
Definition: SavedBattleGame.cpp:503
BattleUnit * selectNextPlayerUnit(bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
Selects the next soldier.
Definition: SavedBattleGame.cpp:615
void calculateModuleMap()
calculate the number of map modules remaining
Definition: SavedBattleGame.cpp:1738
std::vector< Node * > * getNodes()
Gets a pointer to the list of nodes.
Definition: SavedBattleGame.cpp:710
~SavedBattleGame()
Cleans up the saved game.
Definition: SavedBattleGame.cpp:75
bool isCheating()
check if the AI has engaged cheat mode.
Definition: SavedBattleGame.cpp:1681
void setObjectiveDestroyed(bool flag)
Sets whether the objective is destroyed.
Definition: SavedBattleGame.cpp:1062
Basic element of which a battle map is build.
Definition: Tile.h:43
void load(const YAML::Node &node, Ruleset *rule, SavedGame *savedGame)
Loads a saved battle game from YAML.
Definition: SavedBattleGame.cpp:117
void getTileCoords(int index, int *x, int *y, int *z) const
Converts a tile index to its coordinates.
Definition: SavedBattleGame.cpp:569
std::vector< Position > & getStorageSpace()
give me access to the storage tiles vector.
Definition: SavedBattleGame.cpp:954
Packs of external game media.
Definition: ResourcePack.h:50
BattleUnit * selectPreviousPlayerUnit(bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
Selects the previous soldier.
Definition: SavedBattleGame.cpp:602
void loadMapResources(Game *game)
Load map resources.
Definition: SavedBattleGame.cpp:318
BattleUnit * getSelectedUnit() const
Gets the currently selected unit.
Definition: SavedBattleGame.cpp:580
bool getDebugMode() const
Gets debug mode.
Definition: SavedBattleGame.cpp:881
void setGlobalShade(int shade)
Sets the global shade.
Definition: SavedBattleGame.cpp:512
Battlescape game - the core game engine of the battlescape game.
Definition: BattlescapeGame.h:70
A utility class that calculates the shortest path between two points on the battlescape map...
Definition: Pathfinding.h:37
int getMapSizeXYZ() const
Gets terrain x*y*z.
Definition: SavedBattleGame.cpp:557
const std::vector< Position > getTileSearch()
get an 11x11 grid of positions (-10 to +10) to check.
Definition: SavedBattleGame.cpp:1672
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:50
int getMapSizeZ() const
Gets terrain size z.
Definition: SavedBattleGame.cpp:548
The core of the game engine, manages the game's entire contents and structure.
Definition: Game.h:44
Represents a node/spawnpoint in the battlescape, loaded from RMP files.
Definition: Node.h:34
BattleActionType getTUReserved() const
get the reserved fire mode.
Definition: SavedBattleGame.cpp:1690
void setKneelReserved(bool reserved)
set whether we are reserving TUs to kneel.
Definition: SavedBattleGame.cpp:1717
bool isObjectiveDestroyed()
Checks if the objective is detroyed.
Definition: SavedBattleGame.cpp:1077
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
BattlescapeState * getBattleState()
Gets a pointer to the BattlescapeState.
Definition: SavedBattleGame.cpp:890
Battlescape screen which shows the tactical battle.
Definition: BattlescapeState.h:48
SavedBattleGame()
Creates a new battle save, based on the current generic save.
Definition: SavedBattleGame.cpp:54
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:58
void reviveUnconsciousUnits()
Revives unconscious units (healthcheck).
Definition: SavedBattleGame.cpp:1363
void initUtilities(ResourcePack *res)
Initialises the pathfinding and tileengine.
Definition: SavedBattleGame.cpp:484
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:1476
std::list< BattleUnit * > * getFallingUnits()
Gets the vector of falling units.
Definition: SavedBattleGame.cpp:1519