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::wstring displayName;
78  time_t timestamp;
79  std::wstring isoDate, isoTime;
80  std::wstring 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::wstring _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  void getDependableResearchBasic (std::vector<RuleResearch*> & dependables, const RuleResearch *research, const Mod *mod, Base *base) const;
135  static SaveInfo getSaveInfo(const std::string &file, Language *lang);
136 public:
137  static const std::string AUTOSAVE_GEOSCAPE, AUTOSAVE_BATTLESCAPE, QUICKSAVE;
139  SavedGame();
141  ~SavedGame();
143  static std::vector<SaveInfo> getList(Language *lang, bool autoquick);
145  void load(const std::string &filename, Mod *mod);
147  void save(const std::string &filename) const;
149  std::wstring getName() const;
151  void setName(const std::wstring &name);
153  GameDifficulty getDifficulty() const;
155  void setDifficulty(GameDifficulty difficulty);
157  int getDifficultyCoefficient() const;
159  GameEnding getEnding() const;
161  void setEnding(GameEnding end);
163  bool isIronman() const;
165  void setIronman(bool ironman);
167  int64_t getFunds() const;
169  std::vector<int64_t> &getFundsList();
171  void setFunds(int64_t funds);
173  double getGlobeLongitude() const;
175  void setGlobeLongitude(double lon);
177  double getGlobeLatitude() const;
179  void setGlobeLatitude(double lat);
181  int getGlobeZoom() const;
183  void setGlobeZoom(int zoom);
185  void monthlyFunding();
187  GameTime *getTime() const;
189  void setTime(const GameTime& time);
191  int getId(const std::string &name);
193  const std::map<std::string, int> &getAllIds() const;
195  void setAllIds(const std::map<std::string, int> &ids);
197  std::vector<Country*> *getCountries();
199  int getCountryFunding() const;
201  std::vector<Region*> *getRegions();
203  std::vector<Base*> *getBases();
205  const std::vector<Base*> *getBases() const;
207  int getBaseMaintenance() const;
209  std::vector<Ufo*> *getUfos();
211  std::vector<Waypoint*> *getWaypoints();
213  std::vector<MissionSite*> *getMissionSites();
217  void setBattleGame(SavedBattleGame *battleGame);
219  void addFinishedResearch(const RuleResearch *r, const Mod *mod = 0, bool score = true);
221  const std::vector<const RuleResearch*> & getDiscoveredResearch() const;
223  void getAvailableResearchProjects(std::vector<RuleResearch*> & projects, const Mod *mod, Base *base) const;
225  void getAvailableProductions(std::vector<RuleManufacture*> & productions, const Mod *mod, Base *base) const;
227  void getDependableResearch(std::vector<RuleResearch*> & dependables, const RuleResearch *research, const Mod *mod, Base *base) const;
229  void getDependableManufacture(std::vector<RuleManufacture*> & dependables, const RuleResearch *research, const Mod *mod, Base *base) const;
231  bool isResearchAvailable(RuleResearch *r, const std::vector<const RuleResearch*> & unlocked, const Mod *mod) const;
233  bool isResearched(const std::string &research) const;
235  bool isResearched(const std::vector<std::string> &research) const;
237  Soldier *getSoldier(int id) const;
239  bool handlePromotions(std::vector<Soldier*> &participants);
241  void processSoldier(Soldier *soldier, PromotionInfo &soldierData);
243  Soldier *inspectSoldiers(std::vector<Soldier*> &soldiers, std::vector<Soldier*> &participants, int rank);
245  std::vector<AlienBase*> *getAlienBases();
247  void setDebugMode();
249  bool getDebugMode() const;
251  std::vector<int64_t> &getMaintenances();
253  void addResearchScore(int score);
255  std::vector<int> &getResearchScores();
257  std::vector<int64_t> &getIncomes();
259  std::vector<int64_t> &getExpenditures();
261  bool getWarned() const;
263  void setWarned(bool warned);
265  AlienStrategy &getAlienStrategy() { return *_alienStrategy; }
267  const AlienStrategy &getAlienStrategy() const { return *_alienStrategy; }
269  std::vector<AlienMission*> &getAlienMissions() { return _activeMissions; }
271  const std::vector<AlienMission*> &getAlienMissions() const { return _activeMissions; }
273  AlienMission *findAlienMission(const std::string &region, MissionObjective objective) const;
275  Region *locateRegion(double lon, double lat) const;
277  Region *locateRegion(const Target &target) const;
279  int getMonthsPassed() const;
281  const std::string &getGraphRegionToggles() const;
283  const std::string &getGraphCountryToggles() const;
285  const std::string &getGraphFinanceToggles() const;
287  void setGraphRegionToggles(const std::string &value);
289  void setGraphCountryToggles(const std::string &value);
291  void setGraphFinanceToggles(const std::string &value);
293  void addMonth();
295  void addPoppedResearch(const RuleResearch* research);
297  bool wasResearchPopped(const RuleResearch* research);
299  void removePoppedResearch(const RuleResearch* research);
301  std::vector<Soldier*> *getDeadSoldiers();
305  void setSelectedBase(size_t base);
307  int getSoldierScore(Soldier *soldier);
309  void setLastSelectedArmor(const std::string &value);
311  std::string getLastSelectedArmor() const;
313  Craft *findCraftByUniqueId(const CraftId& craftId) const;
315  std::vector<MissionStatistics*> *getMissionStatistics();
317  std::vector<Soldier*>::iterator killSoldier(Soldier *soldier, BattleUnitKills *cause = 0);
318 };
319 
320 }
std::vector< int > & getResearchScores()
gets the list of research scores
Definition: SavedGame.cpp:1719
Represents a craft stored in a base.
Definition: Craft.h:45
std::vector< Base * > * getBases()
Gets the list of bases.
Definition: SavedGame.cpp:975
Stores the information about alien strategy.
Definition: AlienStrategy.h:31
void setLastSelectedArmor(const std::string &value)
Sets the last selected armour.
Definition: SavedGame.cpp:1915
int getBaseMaintenance() const
Gets the total base maintenance.
Definition: SavedGame.cpp:1019
void setDifficulty(GameDifficulty difficulty)
Sets the game difficulty.
Definition: SavedGame.cpp:715
void setGlobeZoom(int zoom)
Sets the new globe zoom.
Definition: SavedGame.cpp:852
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:1238
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:1380
Represents an ongoing alien mission.
Definition: AlienMission.h:46
std::vector< Waypoint * > * getWaypoints()
Gets the list of waypoints.
Definition: SavedGame.cpp:1042
const std::vector< const RuleResearch * > & getDiscoveredResearch() const
Get the list of already discovered research projects.
Definition: SavedGame.cpp:1125
void setGraphRegionToggles(const std::string &value)
Sets the GraphRegionToggles.
Definition: SavedGame.cpp:1837
std::vector< int64_t > & getExpenditures()
gets the list of expenditures.
Definition: SavedGame.cpp:1737
const std::vector< AlienMission * > & getAlienMissions() const
Read-only access to the current alien missions.
Definition: SavedGame.h:271
double getGlobeLongitude() const
Gets the current globe longitude.
Definition: SavedGame.cpp:807
void setDebugMode()
Sets debug mode.
Definition: SavedGame.cpp:1650
const std::string & getGraphRegionToggles() const
Return the GraphRegionToggles.
Definition: SavedGame.cpp:1812
std::string getLastSelectedArmor() const
Gets the last selected armour.
Definition: SavedGame.cpp:1924
void setEnding(GameEnding end)
Sets the game ending.
Definition: SavedGame.cpp:743
SavedGame()
Creates a new saved game.
Definition: SavedGame.cpp:101
double getGlobeLatitude() const
Gets the current globe latitude.
Definition: SavedGame.cpp:825
void setBattleGame(SavedBattleGame *battleGame)
Sets the current battle game.
Definition: SavedGame.cpp:1069
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:1001
AlienStrategy & getAlienStrategy()
Full access to the alien strategy data.
Definition: SavedGame.h:265
void getAvailableResearchProjects(std::vector< RuleResearch *> &projects, const Mod *mod, Base *base) const
Get the list of ResearchProject which can be researched in a Base.
Definition: SavedGame.cpp:1136
void save(const std::string &filename) const
Saves a saved game to YAML.
Definition: SavedGame.cpp:549
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:267
void setFunds(int64_t funds)
Sets new funds.
Definition: SavedGame.cpp:790
GameEnding getEnding() const
Gets the game ending.
Definition: SavedGame.cpp:734
bool isResearched(const std::string &research) const
Gets if a research has been unlocked.
Definition: SavedGame.cpp:1399
int getSoldierScore(Soldier *soldier)
Evaluate the score of a soldier based on all of his stats, missions and kills.
Definition: SavedGame.cpp:1628
std::vector< int64_t > & getMaintenances()
return a list of maintenance costs
Definition: SavedGame.cpp:1701
bool getDebugMode() const
Gets debug mode.
Definition: SavedGame.cpp:1659
int getId(const std::string &name)
Gets the current ID for an object.
Definition: SavedGame.cpp:907
Container for battle unit kills statistics.
Definition: BattleUnitStatistics.h:31
Craft * findCraftByUniqueId(const CraftId &craftId) const
Returns the craft corresponding to the specified unique id.
Definition: SavedGame.cpp:1934
void processSoldier(Soldier *soldier, PromotionInfo &soldierData)
Processes a soldier&#39;s promotion.
Definition: SavedGame.cpp:1576
bool wasResearchPopped(const RuleResearch *research)
check if a research is on the "popped up" array
Definition: SavedGame.cpp:1883
GameTime * getTime() const
Gets the current game time.
Definition: SavedGame.cpp:887
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:1604
int getDifficultyCoefficient() const
Gets the game difficulty coefficient.
Definition: SavedGame.cpp:725
const std::string & getGraphFinanceToggles() const
Return the GraphFinanceToggles.
Definition: SavedGame.cpp:1828
std::vector< int64_t > & getIncomes()
gets the list of incomes.
Definition: SavedGame.cpp:1728
std::vector< Soldier * > * getDeadSoldiers()
Gets the list of dead soldiers.
Definition: SavedGame.cpp:1905
void setGraphFinanceToggles(const std::string &value)
Sets the GraphFinanceToggles.
Definition: SavedGame.cpp:1855
void addFinishedResearch(const RuleResearch *r, const Mod *mod=0, bool score=true)
Add a finished ResearchProject.
Definition: SavedGame.cpp:1080
Soldier * getSoldier(int id) const
Gets the soldier matching this ID.
Definition: SavedGame.cpp:1444
Contains strings used throughout the game for localization.
Definition: Language.h:39
Base * getSelectedBase()
Gets the last selected player base.
Definition: SavedGame.cpp:984
void addPoppedResearch(const RuleResearch *research)
add a research to the "popped up" array
Definition: SavedGame.cpp:1872
void monthlyFunding()
Handles monthly funding.
Definition: SavedGame.cpp:861
int getGlobeZoom() const
Gets the current globe zoom.
Definition: SavedGame.cpp:843
SavedBattleGame * getSavedBattle()
Gets the current battle game.
Definition: SavedGame.cpp:1060
~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:966
static std::vector< SaveInfo > getList(Language *lang, bool autoquick)
Gets list of saves in the user directory.
Definition: SavedGame.cpp:198
void setWarned(bool warned)
sets whether or not the player has been warned
Definition: SavedGame.cpp:1756
void setName(const std::wstring &name)
Sets the game name.
Definition: SavedGame.cpp:697
int getCountryFunding() const
Gets the total country funding.
Definition: SavedGame.cpp:952
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:896
std::vector< Soldier * >::iterator killSoldier(Soldier *soldier, BattleUnitKills *cause=0)
Handles a soldier&#39;s death.
Definition: SavedGame.cpp:1962
void setGlobeLatitude(double lat)
Sets the new globe latitude.
Definition: SavedGame.cpp:834
std::vector< AlienBase * > * getAlienBases()
Returns the list of alien bases.
Definition: SavedGame.cpp:1642
Represents a player base on the globe.
Definition: Base.h:45
void addMonth()
Increment the month counter.
Definition: SavedGame.cpp:1863
Represents one research project.
Definition: RuleResearch.h:38
std::wstring getName() const
Gets the game name.
Definition: SavedGame.cpp:688
void removePoppedResearch(const RuleResearch *research)
remove a research from the "popped up" array
Definition: SavedGame.cpp:1892
Region * locateRegion(double lon, double lat) const
Locate a region containing a position.
Definition: SavedGame.cpp:1781
std::vector< AlienMission * > & getAlienMissions()
Full access to the current alien missions.
Definition: SavedGame.h:269
const std::string & getGraphCountryToggles() const
Return the GraphCountryToggles.
Definition: SavedGame.cpp:1820
AlienMission * findAlienMission(const std::string &region, MissionObjective objective) const
Finds a mission by region and objective.
Definition: SavedGame.cpp:1689
bool handlePromotions(std::vector< Soldier *> &participants)
Handles the higher promotions.
Definition: SavedGame.cpp:1471
std::vector< int64_t > & getFundsList()
Gets the list of funds from previous months.
Definition: SavedGame.cpp:781
std::vector< MissionStatistics * > * getMissionStatistics()
Gets the list of missions statistics.
Definition: SavedGame.cpp:1952
void setGraphCountryToggles(const std::string &value)
Sets the GraphCountryToggles.
Definition: SavedGame.cpp:1846
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:46
bool isIronman() const
Gets if the game is in ironman mode.
Definition: SavedGame.cpp:753
GameDifficulty getDifficulty() const
Gets the game difficulty.
Definition: SavedGame.cpp:706
Represents a region of the world.
Definition: Region.h:33
std::vector< Ufo * > * getUfos()
Gets the list of UFOs.
Definition: SavedGame.cpp:1033
void setAllIds(const std::map< std::string, int > &ids)
Resets the list of object IDs.
Definition: SavedGame.cpp:934
void setGlobeLongitude(double lon)
Sets the new globe longitude.
Definition: SavedGame.cpp:816
bool isResearchAvailable(RuleResearch *r, const std::vector< const RuleResearch *> &unlocked, const Mod *mod) const
Check whether a ResearchProject can be researched.
Definition: SavedGame.cpp:1267
void getDependableResearch(std::vector< RuleResearch *> &dependables, const RuleResearch *research, const Mod *mod, Base *base) const
Get the list of newly available research projects once a research has been completed.
Definition: SavedGame.cpp:1333
void load(const std::string &filename, Mod *mod)
Loads a saved game from YAML.
Definition: SavedGame.cpp:311
std::vector< MissionSite * > * getMissionSites()
Gets the list of mission sites.
Definition: SavedGame.cpp:1051
Base class for targets on the globe with a set of radian coordinates.
Definition: Target.h:33
void addResearchScore(int score)
sets the research score for the month
Definition: SavedGame.cpp:1710
std::vector< Country * > * getCountries()
Gets the list of countries.
Definition: SavedGame.cpp:943
int getMonthsPassed() const
Return the month counter.
Definition: SavedGame.cpp:1804
const std::map< std::string, int > & getAllIds() const
Resets the list of object IDs.
Definition: SavedGame.cpp:925
int64_t getFunds() const
Gets the current funds.
Definition: SavedGame.cpp:772
bool getWarned() const
gets whether or not the player has been warned
Definition: SavedGame.cpp:1747
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:763