OpenXcom  1.0
Open-source clone of the original X-Com
SavedGame.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 <map>
21 #include <vector>
22 #include <string>
23 #include <time.h>
24 #include <stdint.h>
25 #include "GameTime.h"
26 #include "../Mod/RuleAlienMission.h"
27 #include "../Savegame/Craft.h"
28 
29 namespace OpenXcom
30 {
31 
32 class Mod;
33 class GameTime;
34 class Country;
35 class Base;
36 class Region;
37 class Ufo;
38 class Waypoint;
39 class SavedBattleGame;
40 class TextList;
41 class Language;
42 class RuleResearch;
43 class ResearchProject;
44 class Soldier;
45 class RuleManufacture;
46 class MissionSite;
47 class AlienBase;
48 class AlienStrategy;
49 class AlienMission;
50 class Target;
51 class Soldier;
52 class Craft;
53 struct MissionStatistics;
54 struct BattleUnitKills;
55 
59 enum GameDifficulty { DIFF_BEGINNER = 0, DIFF_EXPERIENCED, DIFF_VETERAN, DIFF_GENIUS, DIFF_SUPERHUMAN };
60 
64 enum SaveType { SAVE_DEFAULT, SAVE_QUICK, SAVE_AUTO_GEOSCAPE, SAVE_AUTO_BATTLESCAPE, SAVE_IRONMAN, SAVE_IRONMAN_END };
65 
69 enum GameEnding { END_NONE, END_WIN, END_LOSE };
70 
74 struct SaveInfo
75 {
76  std::string fileName;
77  std::string displayName;
78  time_t timestamp;
79  std::string isoDate, isoTime;
80  std::string details;
81  std::vector<std::string> mods;
82  bool reserved;
83 };
84 
86 {
87  int totalCommanders;
88  int totalColonels;
89  int totalCaptains;
90  int totalSergeants;
91  PromotionInfo(): totalCommanders(0), totalColonels(0), totalCaptains(0), totalSergeants(0){}
92 };
93 
99 class SavedGame
100 {
101 private:
102  std::string _name;
103  GameDifficulty _difficulty;
104  GameEnding _end;
105  bool _ironman;
106  GameTime *_time;
107  std::vector<int> _researchScores;
108  std::vector<int64_t> _funds, _maintenance, _incomes, _expenditures;
109  double _globeLon, _globeLat;
110  int _globeZoom;
111  std::map<std::string, int> _ids;
112  std::vector<Country*> _countries;
113  std::vector<Region*> _regions;
114  std::vector<Base*> _bases;
115  std::vector<Ufo*> _ufos;
116  std::vector<Waypoint*> _waypoints;
117  std::vector<MissionSite*> _missionSites;
118  std::vector<AlienBase*> _alienBases;
119  AlienStrategy *_alienStrategy;
120  SavedBattleGame *_battleGame;
121  std::vector<const RuleResearch*> _discovered;
122  std::vector<AlienMission*> _activeMissions;
123  bool _debug, _warned;
124  int _monthsPassed;
125  std::string _graphRegionToggles;
126  std::string _graphCountryToggles;
127  std::string _graphFinanceToggles;
128  std::vector<const RuleResearch*> _poppedResearch;
129  std::vector<Soldier*> _deadSoldiers;
130  size_t _selectedBase;
131  std::string _lastselectedArmor; //contains the last selected armour
132  std::vector<MissionStatistics*> _missionStatistics;
133 
134  static SaveInfo getSaveInfo(const std::string &file, Language *lang);
135 public:
136  static const std::string AUTOSAVE_GEOSCAPE, AUTOSAVE_BATTLESCAPE, QUICKSAVE;
138  SavedGame();
140  ~SavedGame();
142  static std::string sanitizeModName(const std::string &name);
144  static std::vector<SaveInfo> getList(Language *lang, bool autoquick);
146  void load(const std::string &filename, Mod *mod);
148  void save(const std::string &filename) const;
150  std::string getName() const;
152  void setName(const std::string &name);
154  GameDifficulty getDifficulty() const;
156  void setDifficulty(GameDifficulty difficulty);
158  int getDifficultyCoefficient() const;
160  GameEnding getEnding() const;
162  void setEnding(GameEnding end);
164  bool isIronman() const;
166  void setIronman(bool ironman);
168  int64_t getFunds() const;
170  std::vector<int64_t> &getFundsList();
172  void setFunds(int64_t funds);
174  double getGlobeLongitude() const;
176  void setGlobeLongitude(double lon);
178  double getGlobeLatitude() const;
180  void setGlobeLatitude(double lat);
182  int getGlobeZoom() const;
184  void setGlobeZoom(int zoom);
186  void monthlyFunding();
188  GameTime *getTime() const;
190  void setTime(const GameTime& time);
192  int getId(const std::string &name);
194  const std::map<std::string, int> &getAllIds() const;
196  void setAllIds(const std::map<std::string, int> &ids);
198  std::vector<Country*> *getCountries();
200  int getCountryFunding() const;
202  std::vector<Region*> *getRegions();
204  std::vector<Base*> *getBases();
206  const std::vector<Base*> *getBases() const;
208  int getBaseMaintenance() const;
210  std::vector<Ufo*> *getUfos();
212  std::vector<Waypoint*> *getWaypoints();
214  std::vector<MissionSite*> *getMissionSites();
218  void setBattleGame(SavedBattleGame *battleGame);
220  void addFinishedResearchSimple(const RuleResearch *research);
222  void addFinishedResearch(const RuleResearch *research, const Mod *mod, Base *base, bool score = true);
224  const std::vector<const RuleResearch*> & getDiscoveredResearch() const;
226  void getAvailableResearchProjects(std::vector<RuleResearch*> & projects, const Mod *mod, Base *base, bool considerDebugMode = false) const;
228  void getNewlyAvailableResearchProjects(std::vector<RuleResearch*> & before, std::vector<RuleResearch*> & after, std::vector<RuleResearch*> & diff) const;
230  void getAvailableProductions(std::vector<RuleManufacture*> & productions, const Mod *mod, Base *base) const;
232  void getDependableManufacture(std::vector<RuleManufacture*> & dependables, const RuleResearch *research, const Mod *mod, Base *base) const;
234  bool hasUndiscoveredProtectedUnlock(const RuleResearch * r, const Mod * mod) const;
236  bool isResearched(const std::string &research, bool considerDebugMode = true) const;
238  bool isResearched(const std::vector<std::string> &research, bool considerDebugMode = true) const;
240  Soldier *getSoldier(int id) const;
242  bool handlePromotions(std::vector<Soldier*> &participants);
244  void processSoldier(Soldier *soldier, PromotionInfo &soldierData);
246  Soldier *inspectSoldiers(std::vector<Soldier*> &soldiers, std::vector<Soldier*> &participants, int rank);
248  std::vector<AlienBase*> *getAlienBases();
250  void setDebugMode();
252  bool getDebugMode() const;
254  std::vector<int64_t> &getMaintenances();
256  void addResearchScore(int score);
258  std::vector<int> &getResearchScores();
260  std::vector<int64_t> &getIncomes();
262  std::vector<int64_t> &getExpenditures();
264  bool getWarned() const;
266  void setWarned(bool warned);
268  AlienStrategy &getAlienStrategy() { return *_alienStrategy; }
270  const AlienStrategy &getAlienStrategy() const { return *_alienStrategy; }
272  std::vector<AlienMission*> &getAlienMissions() { return _activeMissions; }
274  const std::vector<AlienMission*> &getAlienMissions() const { return _activeMissions; }
276  AlienMission *findAlienMission(const std::string &region, MissionObjective objective) const;
278  Region *locateRegion(double lon, double lat) const;
280  Region *locateRegion(const Target &target) const;
282  int getMonthsPassed() const;
284  const std::string &getGraphRegionToggles() const;
286  const std::string &getGraphCountryToggles() const;
288  const std::string &getGraphFinanceToggles() const;
290  void setGraphRegionToggles(const std::string &value);
292  void setGraphCountryToggles(const std::string &value);
294  void setGraphFinanceToggles(const std::string &value);
296  void addMonth();
298  void addPoppedResearch(const RuleResearch* research);
300  bool wasResearchPopped(const RuleResearch* research);
302  void removePoppedResearch(const RuleResearch* research);
304  std::vector<Soldier*> *getDeadSoldiers();
308  void setSelectedBase(size_t base);
310  int getSoldierScore(Soldier *soldier);
312  void setLastSelectedArmor(const std::string &value);
314  std::string getLastSelectedArmor() const;
316  Craft *findCraftByUniqueId(const CraftId& craftId) const;
318  std::vector<MissionStatistics*> *getMissionStatistics();
320  std::vector<Soldier*>::iterator killSoldier(Soldier *soldier, BattleUnitKills *cause = 0);
321 };
322 
323 }
std::vector< int > & getResearchScores()
gets the list of research scores
Definition: SavedGame.cpp:1734
Represents a craft stored in a base.
Definition: Craft.h:45
std::vector< Base * > * getBases()
Gets the list of bases.
Definition: SavedGame.cpp:980
Stores the information about alien strategy.
Definition: AlienStrategy.h:31
void setLastSelectedArmor(const std::string &value)
Sets the last selected armour.
Definition: SavedGame.cpp:1930
int getBaseMaintenance() const
Gets the total base maintenance.
Definition: SavedGame.cpp:1024
void setDifficulty(GameDifficulty difficulty)
Sets the game difficulty.
Definition: SavedGame.cpp:720
void setGlobeZoom(int zoom)
Sets the new globe zoom.
Definition: SavedGame.cpp:857
void getAvailableProductions(std::vector< RuleManufacture *> &productions, const Mod *mod, Base *base) const
Get the list of Productions which can be manufactured in a Base.
Definition: SavedGame.cpp:1337
void getDependableManufacture(std::vector< RuleManufacture *> &dependables, const RuleResearch *research, const Mod *mod, Base *base) const
Get the list of newly available manufacture projects once a research has been completed.
Definition: SavedGame.cpp:1366
void getAvailableResearchProjects(std::vector< RuleResearch *> &projects, const Mod *mod, Base *base, bool considerDebugMode=false) const
Get the list of ResearchProject which can be researched in a Base.
Definition: SavedGame.cpp:1219
Represents an ongoing alien mission.
Definition: AlienMission.h:46
std::vector< Waypoint * > * getWaypoints()
Gets the list of waypoints.
Definition: SavedGame.cpp:1047
const std::vector< const RuleResearch * > & getDiscoveredResearch() const
Get the list of already discovered research projects.
Definition: SavedGame.cpp:1207
void setGraphRegionToggles(const std::string &value)
Sets the GraphRegionToggles.
Definition: SavedGame.cpp:1852
std::vector< int64_t > & getExpenditures()
gets the list of expenditures.
Definition: SavedGame.cpp:1752
const std::vector< AlienMission * > & getAlienMissions() const
Read-only access to the current alien missions.
Definition: SavedGame.h:274
double getGlobeLongitude() const
Gets the current globe longitude.
Definition: SavedGame.cpp:812
void setDebugMode()
Sets debug mode.
Definition: SavedGame.cpp:1665
void addFinishedResearchSimple(const RuleResearch *research)
Add a finished ResearchProject.
Definition: SavedGame.cpp:1084
const std::string & getGraphRegionToggles() const
Return the GraphRegionToggles.
Definition: SavedGame.cpp:1827
std::string getLastSelectedArmor() const
Gets the last selected armour.
Definition: SavedGame.cpp:1939
void setEnding(GameEnding end)
Sets the game ending.
Definition: SavedGame.cpp:748
SavedGame()
Creates a new saved game.
Definition: SavedGame.cpp:101
double getGlobeLatitude() const
Gets the current globe latitude.
Definition: SavedGame.cpp:830
void setBattleGame(SavedBattleGame *battleGame)
Sets the current battle game.
Definition: SavedGame.cpp:1074
The game data that gets written to disk when the game is saved.
Definition: SavedGame.h:99
void setSelectedBase(size_t base)
Set the last selected player base.
Definition: SavedGame.cpp:1006
AlienStrategy & getAlienStrategy()
Full access to the alien strategy data.
Definition: SavedGame.h:268
void save(const std::string &filename) const
Saves a saved game to YAML.
Definition: SavedGame.cpp:562
Contains all the game-specific static data that never changes throughout the game, like rulesets and resources.
Definition: Mod.h:87
const AlienStrategy & getAlienStrategy() const
Read-only access to the alien strategy data.
Definition: SavedGame.h:270
void setFunds(int64_t funds)
Sets new funds.
Definition: SavedGame.cpp:795
GameEnding getEnding() const
Gets the game ending.
Definition: SavedGame.cpp:739
int getSoldierScore(Soldier *soldier)
Evaluate the score of a soldier based on all of his stats, missions and kills.
Definition: SavedGame.cpp:1643
std::vector< int64_t > & getMaintenances()
return a list of maintenance costs
Definition: SavedGame.cpp:1716
bool getDebugMode() const
Gets debug mode.
Definition: SavedGame.cpp:1674
int getId(const std::string &name)
Gets the current ID for an object.
Definition: SavedGame.cpp:912
static std::string sanitizeModName(const std::string &name)
Sanitizies a mod name in a save.
Definition: SavedGame.cpp:169
Container for battle unit kills statistics.
Definition: BattleUnitStatistics.h:32
Craft * findCraftByUniqueId(const CraftId &craftId) const
Returns the craft corresponding to the specified unique id.
Definition: SavedGame.cpp:1949
void processSoldier(Soldier *soldier, PromotionInfo &soldierData)
Processes a soldier&#39;s promotion.
Definition: SavedGame.cpp:1591
bool wasResearchPopped(const RuleResearch *research)
check if a research is on the "popped up" array
Definition: SavedGame.cpp:1898
GameTime * getTime() const
Gets the current game time.
Definition: SavedGame.cpp:892
Soldier * inspectSoldiers(std::vector< Soldier *> &soldiers, std::vector< Soldier *> &participants, int rank)
Checks how many soldiers of a rank exist and which one has the highest score.
Definition: SavedGame.cpp:1619
int getDifficultyCoefficient() const
Gets the game difficulty coefficient.
Definition: SavedGame.cpp:730
const std::string & getGraphFinanceToggles() const
Return the GraphFinanceToggles.
Definition: SavedGame.cpp:1843
std::vector< int64_t > & getIncomes()
gets the list of incomes.
Definition: SavedGame.cpp:1743
std::vector< Soldier * > * getDeadSoldiers()
Gets the list of dead soldiers.
Definition: SavedGame.cpp:1920
void setGraphFinanceToggles(const std::string &value)
Sets the GraphFinanceToggles.
Definition: SavedGame.cpp:1870
Soldier * getSoldier(int id) const
Gets the soldier matching this ID.
Definition: SavedGame.cpp:1459
Contains strings used throughout the game for localization.
Definition: Language.h:39
Base * getSelectedBase()
Gets the last selected player base.
Definition: SavedGame.cpp:989
void addPoppedResearch(const RuleResearch *research)
add a research to the "popped up" array
Definition: SavedGame.cpp:1887
void monthlyFunding()
Handles monthly funding.
Definition: SavedGame.cpp:866
int getGlobeZoom() const
Gets the current globe zoom.
Definition: SavedGame.cpp:848
SavedBattleGame * getSavedBattle()
Gets the current battle game.
Definition: SavedGame.cpp:1065
~SavedGame()
Cleans up the saved game.
Definition: SavedGame.cpp:116
Definition: SavedGame.h:85
std::vector< Region * > * getRegions()
Gets the list of regions.
Definition: SavedGame.cpp:971
static std::vector< SaveInfo > getList(Language *lang, bool autoquick)
Gets list of saves in the user directory.
Definition: SavedGame.cpp:218
void setWarned(bool warned)
sets whether or not the player has been warned
Definition: SavedGame.cpp:1771
void setName(const std::string &name)
Sets the game name.
Definition: SavedGame.cpp:702
int getCountryFunding() const
Gets the total country funding.
Definition: SavedGame.cpp:957
Stores the current ingame time/date according to GMT.
Definition: GameTime.h:38
Represents a soldier hired by the player.
Definition: Soldier.h:48
void setTime(const GameTime &time)
Sets the current game time.
Definition: SavedGame.cpp:901
std::vector< Soldier * >::iterator killSoldier(Soldier *soldier, BattleUnitKills *cause=0)
Handles a soldier&#39;s death.
Definition: SavedGame.cpp:1977
void setGlobeLatitude(double lat)
Sets the new globe latitude.
Definition: SavedGame.cpp:839
std::vector< AlienBase * > * getAlienBases()
Returns the list of alien bases.
Definition: SavedGame.cpp:1657
Represents a player base on the globe.
Definition: Base.h:45
void addMonth()
Increment the month counter.
Definition: SavedGame.cpp:1878
Represents one research project.
Definition: RuleResearch.h:38
void getNewlyAvailableResearchProjects(std::vector< RuleResearch *> &before, std::vector< RuleResearch *> &after, std::vector< RuleResearch *> &diff) const
Get the list of newly available research projects once a research has been completed.
Definition: SavedGame.cpp:1314
void removePoppedResearch(const RuleResearch *research)
remove a research from the "popped up" array
Definition: SavedGame.cpp:1907
Region * locateRegion(double lon, double lat) const
Locate a region containing a position.
Definition: SavedGame.cpp:1796
std::vector< AlienMission * > & getAlienMissions()
Full access to the current alien missions.
Definition: SavedGame.h:272
bool hasUndiscoveredProtectedUnlock(const RuleResearch *r, const Mod *mod) const
Gets if a research still has undiscovered "protected unlocks".
Definition: SavedGame.cpp:1386
const std::string & getGraphCountryToggles() const
Return the GraphCountryToggles.
Definition: SavedGame.cpp:1835
AlienMission * findAlienMission(const std::string &region, MissionObjective objective) const
Finds a mission by region and objective.
Definition: SavedGame.cpp:1704
bool handlePromotions(std::vector< Soldier *> &participants)
Handles the higher promotions.
Definition: SavedGame.cpp:1486
void addFinishedResearch(const RuleResearch *research, const Mod *mod, Base *base, bool score=true)
Add a finished ResearchProject.
Definition: SavedGame.cpp:1096
std::vector< int64_t > & getFundsList()
Gets the list of funds from previous months.
Definition: SavedGame.cpp:786
std::vector< MissionStatistics * > * getMissionStatistics()
Gets the list of missions statistics.
Definition: SavedGame.cpp:1967
void setGraphCountryToggles(const std::string &value)
Sets the GraphCountryToggles.
Definition: SavedGame.cpp:1861
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:47
bool isIronman() const
Gets if the game is in ironman mode.
Definition: SavedGame.cpp:758
GameDifficulty getDifficulty() const
Gets the game difficulty.
Definition: SavedGame.cpp:711
Represents a region of the world.
Definition: Region.h:33
std::vector< Ufo * > * getUfos()
Gets the list of UFOs.
Definition: SavedGame.cpp:1038
void setAllIds(const std::map< std::string, int > &ids)
Resets the list of object IDs.
Definition: SavedGame.cpp:939
std::string getName() const
Gets the game name.
Definition: SavedGame.cpp:693
void setGlobeLongitude(double lon)
Sets the new globe longitude.
Definition: SavedGame.cpp:821
void load(const std::string &filename, Mod *mod)
Loads a saved game from YAML.
Definition: SavedGame.cpp:331
std::vector< MissionSite * > * getMissionSites()
Gets the list of mission sites.
Definition: SavedGame.cpp:1056
Base class for targets on the globe with a set of radian coordinates.
Definition: Target.h:35
void addResearchScore(int score)
sets the research score for the month
Definition: SavedGame.cpp:1725
std::vector< Country * > * getCountries()
Gets the list of countries.
Definition: SavedGame.cpp:948
bool isResearched(const std::string &research, bool considerDebugMode=true) const
Gets if a certain research has been completed.
Definition: SavedGame.cpp:1409
int getMonthsPassed() const
Return the month counter.
Definition: SavedGame.cpp:1819
const std::map< std::string, int > & getAllIds() const
Resets the list of object IDs.
Definition: SavedGame.cpp:930
int64_t getFunds() const
Gets the current funds.
Definition: SavedGame.cpp:777
bool getWarned() const
gets whether or not the player has been warned
Definition: SavedGame.cpp:1762
Container for savegame info displayed on listings.
Definition: SavedGame.h:74
Definition: BaseInfoState.cpp:40
void setIronman(bool ironman)
Sets if the game is in ironman mode.
Definition: SavedGame.cpp:768