OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SavedGame.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_SAVEDGAME_H
20 #define OPENXCOM_SAVEDGAME_H
21 
22 #include <map>
23 #include <vector>
24 #include <string>
25 #include <time.h>
26 
27 namespace OpenXcom
28 {
29 
30 class Ruleset;
31 class GameTime;
32 class Country;
33 class Base;
34 class Region;
35 class Ufo;
36 class Waypoint;
37 class SavedBattleGame;
38 class TextList;
39 class Language;
40 class RuleResearch;
41 class ResearchProject;
42 class Soldier;
43 class RuleManufacture;
44 class TerrorSite;
45 class AlienBase;
46 class AlienStrategy;
47 class AlienMission;
48 class Target;
49 class Soldier;
50 
54 enum GameDifficulty { DIFF_BEGINNER = 0, DIFF_EXPERIENCED, DIFF_VETERAN, DIFF_GENIUS, DIFF_SUPERHUMAN };
55 
59 enum SaveType { SAVE_DEFAULT, SAVE_QUICK, SAVE_AUTO_GEOSCAPE, SAVE_AUTO_BATTLESCAPE, SAVE_IRONMAN, SAVE_IRONMAN_END };
60 
64 struct SaveInfo
65 {
66  std::string fileName;
67  std::wstring displayName;
68  time_t timestamp;
69  std::wstring isoDate, isoTime;
70  std::wstring details;
71  std::vector<std::string> rulesets;
72  bool reserved;
73 };
74 
80 class SavedGame
81 {
82 private:
83  std::wstring _name;
84  GameDifficulty _difficulty;
85  bool _ironman;
86  GameTime *_time;
87  std::vector<int> _funds, _maintenance, _researchScores, _incomes, _expenditures;
88  double _globeLon, _globeLat;
89  int _globeZoom;
90  std::map<std::string, int> _ids;
91  std::vector<Country*> _countries;
92  std::vector<Region*> _regions;
93  std::vector<Base*> _bases;
94  std::vector<Ufo*> _ufos;
95  std::vector<Waypoint*> _waypoints;
96  std::vector<TerrorSite*> _terrorSites;
97  std::vector<AlienBase*> _alienBases;
98  AlienStrategy *_alienStrategy;
99  SavedBattleGame *_battleGame;
100  std::vector<const RuleResearch *> _discovered;
101  std::vector<AlienMission*> _activeMissions;
102  bool _debug, _warned;
103  int _monthsPassed;
104  std::string _graphRegionToggles;
105  std::string _graphCountryToggles;
106  std::string _graphFinanceToggles;
107  std::vector<const RuleResearch *> _poppedResearch;
108  std::vector<Soldier*> _deadSoldiers;
109  size_t _selectedBase;
110 
111  void getDependableResearchBasic (std::vector<RuleResearch *> & dependables, const RuleResearch *research, const Ruleset * ruleset, Base * base) const;
112  static SaveInfo getSaveInfo(const std::string &file, Language *lang);
113 public:
114  static const std::string AUTOSAVE_GEOSCAPE, AUTOSAVE_BATTLESCAPE, QUICKSAVE;
115 
117  SavedGame();
119  ~SavedGame();
121  static std::vector<SaveInfo> getList(Language *lang, bool autoquick);
123  void load(const std::string &filename, Ruleset *rule);
125  void save(const std::string &filename) const;
127  std::wstring getName() const;
129  void setName(const std::wstring &name);
133  void setDifficulty(GameDifficulty difficulty);
135  bool isIronman() const;
137  void setIronman(bool ironman);
139  int getFunds() const;
141  const std::vector<int> &getFundsList() const;
143  void setFunds(int funds);
145  double getGlobeLongitude() const;
147  void setGlobeLongitude(double lon);
149  double getGlobeLatitude() const;
151  void setGlobeLatitude(double lat);
153  int getGlobeZoom() const;
155  void setGlobeZoom(int zoom);
157  void monthlyFunding();
159  GameTime *getTime() const;
161  void setTime(GameTime time);
163  int getId(const std::string &name);
165  std::vector<Country*> *getCountries();
167  int getCountryFunding() const;
169  std::vector<Region*> *getRegions();
171  std::vector<Base*> *getBases();
173  const std::vector<Base*> *getBases() const;
175  int getBaseMaintenance() const;
177  std::vector<Ufo*> *getUfos();
179  std::vector<Waypoint*> *getWaypoints();
181  std::vector<TerrorSite*> *getTerrorSites();
185  void setBattleGame(SavedBattleGame *battleGame);
187  void addFinishedResearch (const RuleResearch * r, const Ruleset * ruleset = NULL);
189  const std::vector<const RuleResearch *> & getDiscoveredResearch() const;
191  void getAvailableResearchProjects (std::vector<RuleResearch *> & projects, const Ruleset * ruleset, Base * base) const;
193  void getAvailableProductions (std::vector<RuleManufacture *> & productions, const Ruleset * ruleset, Base * base) const;
195  void getDependableResearch (std::vector<RuleResearch *> & dependables, const RuleResearch *research, const Ruleset * ruleset, Base * base) const;
197  void getDependableManufacture (std::vector<RuleManufacture *> & dependables, const RuleResearch *research, const Ruleset * ruleset, Base * base) const;
199  bool isResearchAvailable (RuleResearch * r, const std::vector<const RuleResearch *> & unlocked, const Ruleset * ruleset) const;
201  bool isResearched(const std::string &research) const;
203  bool isResearched(const std::vector<std::string> &research) const;
205  Soldier *getSoldier(int id) const;
207  bool handlePromotions(std::vector<Soldier*> &participants);
209  void inspectSoldiers(Soldier **highestRanked, size_t *total, int rank);
211  std::vector<AlienBase*> *getAlienBases();
213  void setDebugMode();
215  bool getDebugMode() const;
217  std::vector<int> getMaintenances();
219  void addResearchScore(int score);
221  std::vector<int> &getResearchScores();
223  std::vector<int> getIncomes();
225  std::vector<int> getExpenditures();
227  bool getWarned() const;
229  void setWarned(bool warned);
231  AlienStrategy &getAlienStrategy() { return *_alienStrategy; }
233  const AlienStrategy &getAlienStrategy() const { return *_alienStrategy; }
235  std::vector<AlienMission*> &getAlienMissions() { return _activeMissions; }
237  const std::vector<AlienMission*> &getAlienMissions() const { return _activeMissions; }
239  AlienMission *getAlienMission(const std::string &region, const std::string &type) const;
241  Region *locateRegion(double lon, double lat) const;
243  Region *locateRegion(const Target &target) const;
245  int getMonthsPassed() const;
247  const std::string &getGraphRegionToggles() const;
249  const std::string &getGraphCountryToggles() const;
251  const std::string &getGraphFinanceToggles() const;
253  void setGraphRegionToggles(const std::string &value);
255  void setGraphCountryToggles(const std::string &value);
257  void setGraphFinanceToggles(const std::string &value);
259  void addMonth();
261  void addPoppedResearch(const RuleResearch* research);
263  bool wasResearchPopped(const RuleResearch* research);
265  void removePoppedResearch(const RuleResearch* research);
267  std::vector<Soldier*> *getDeadSoldiers();
271  void setSelectedBase(size_t base);
273  int getSoldierScore(Soldier *soldier);
274 };
275 
276 }
277 
278 #endif
SaveType
Enumerator for the various save types.
Definition: SavedGame.h:59
std::vector< int > & getResearchScores()
gets the list of research scores
Definition: SavedGame.cpp:1481
void save(const std::string &filename) const
Saves a saved game to YAML.
Definition: SavedGame.cpp:449
std::vector< Base * > * getBases()
Gets the list of bases.
Definition: SavedGame.cpp:796
Stores the information about alien strategy.
Definition: AlienStrategy.h:32
const std::string & getGraphRegionToggles() const
Return the GraphRegionToggles.
Definition: SavedGame.cpp:1573
bool handlePromotions(std::vector< Soldier * > &participants)
Handles the higher promotions.
Definition: SavedGame.cpp:1282
void addFinishedResearch(const RuleResearch *r, const Ruleset *ruleset=NULL)
Add a finished ResearchProject.
Definition: SavedGame.cpp:901
void setDifficulty(GameDifficulty difficulty)
Sets the game difficulty.
Definition: SavedGame.cpp:582
void setGlobeZoom(int zoom)
Sets the new globe zoom.
Definition: SavedGame.cpp:691
void load(const std::string &filename, Ruleset *rule)
Loads a saved game from YAML.
Definition: SavedGame.cpp:289
double getGlobeLongitude() const
Gets the current globe longitude.
Definition: SavedGame.cpp:646
Represents an ongoing alien mission.
Definition: AlienMission.h:45
std::vector< Waypoint * > * getWaypoints()
Gets the list of waypoints.
Definition: SavedGame.cpp:863
void setGraphRegionToggles(const std::string &value)
Sets the GraphRegionToggles.
Definition: SavedGame.cpp:1598
bool isResearchAvailable(RuleResearch *r, const std::vector< const RuleResearch * > &unlocked, const Ruleset *ruleset) const
Check whether a ResearchProject can be researched.
Definition: SavedGame.cpp:1085
void setDebugMode()
Sets debug mode.
Definition: SavedGame.cpp:1412
void getDependableResearch(std::vector< RuleResearch * > &dependables, const RuleResearch *research, const Ruleset *ruleset, Base *base) const
Get the list of newly available research projects once a research has been completed.
Definition: SavedGame.cpp:1151
int getCountryFunding() const
Gets the total country funding.
Definition: SavedGame.cpp:773
std::vector< int > getExpenditures()
gets the list of expenditures.
Definition: SavedGame.cpp:1499
SavedGame()
Creates a new saved game.
Definition: SavedGame.cpp:98
void setBattleGame(SavedBattleGame *battleGame)
Sets the current battle game.
Definition: SavedGame.cpp:890
The game data that gets written to disk when the game is saved.
Definition: SavedGame.h:80
void getAvailableResearchProjects(std::vector< RuleResearch * > &projects, const Ruleset *ruleset, Base *base) const
Get the list of ResearchProject which can be researched in a Base.
Definition: SavedGame.cpp:954
void setSelectedBase(size_t base)
Set the last selected player base.
Definition: SavedGame.cpp:822
const std::string & getGraphFinanceToggles() const
Return the GraphFinanceToggles.
Definition: SavedGame.cpp:1589
AlienStrategy & getAlienStrategy()
Full access to the alien strategy data.
Definition: SavedGame.h:231
bool isResearched(const std::string &research) const
Gets if a research has been unlocked.
Definition: SavedGame.cpp:1217
double getGlobeLatitude() const
Gets the current globe latitude.
Definition: SavedGame.cpp:664
GameDifficulty getDifficulty() const
Gets the game difficulty.
Definition: SavedGame.cpp:573
Soldier * getSoldier(int id) const
Gets the soldier matching this ID.
Definition: SavedGame.cpp:1262
int getSoldierScore(Soldier *soldier)
Evaluate the score of a soldier based on all of his stats, missions and kills.
Definition: SavedGame.cpp:1390
int getMonthsPassed() const
Return the month counter.
Definition: SavedGame.cpp:1565
int getId(const std::string &name)
Gets the current ID for an object.
Definition: SavedGame.cpp:746
void setTime(GameTime time)
Sets the current game time.
Definition: SavedGame.cpp:735
bool wasResearchPopped(const RuleResearch *research)
check if a research is on the "popped up" array
Definition: SavedGame.cpp:1644
std::vector< Soldier * > * getDeadSoldiers()
Gets the list of dead soldiers.
Definition: SavedGame.cpp:1666
std::wstring getName() const
Gets the game name.
Definition: SavedGame.cpp:555
void setGraphFinanceToggles(const std::string &value)
Sets the GraphFinanceToggles.
Definition: SavedGame.cpp:1616
GameDifficulty
Enumerator containing all the possible game difficulties.
Definition: SavedGame.h:54
Contains strings used throughout the game for localization.
Definition: Language.h:42
Base * getSelectedBase()
Gets the last selected player base.
Definition: SavedGame.cpp:805
void addPoppedResearch(const RuleResearch *research)
add a research to the "popped up" array
Definition: SavedGame.cpp:1633
void monthlyFunding()
Handles monthly funding.
Definition: SavedGame.cpp:700
std::vector< int > getMaintenances()
return a list of maintenance costs
Definition: SavedGame.cpp:1463
SavedBattleGame * getSavedBattle()
Gets the current battle game.
Definition: SavedGame.cpp:881
int getFunds() const
Gets the current funds.
Definition: SavedGame.cpp:611
~SavedGame()
Cleans up the saved game.
Definition: SavedGame.cpp:112
const std::vector< int > & getFundsList() const
Gets the list of funds from previous months.
Definition: SavedGame.cpp:620
Set of rules and stats for a game.
Definition: Ruleset.h:69
std::vector< Region * > * getRegions()
Gets the list of regions.
Definition: SavedGame.cpp:787
static std::vector< SaveInfo > getList(Language *lang, bool autoquick)
Gets list of saves in the user directory.
Definition: SavedGame.cpp:161
void setWarned(bool warned)
sets whether or not the player has been warned
Definition: SavedGame.cpp:1517
int getBaseMaintenance() const
Gets the total base maintenance.
Definition: SavedGame.cpp:840
void setFunds(int funds)
Sets new funds.
Definition: SavedGame.cpp:629
void setName(const std::wstring &name)
Sets the game name.
Definition: SavedGame.cpp:564
std::vector< int > getIncomes()
gets the list of incomes.
Definition: SavedGame.cpp:1490
const std::vector< const RuleResearch * > & getDiscoveredResearch() const
Get the list of already discovered research projects.
Definition: SavedGame.cpp:943
Stores the current ingame time/date according to GMT.
Definition: GameTime.h:40
Represents a soldier hired by the player.
Definition: Soldier.h:49
bool isIronman() const
Gets if the game is in ironman mode.
Definition: SavedGame.cpp:592
void setGlobeLatitude(double lat)
Sets the new globe latitude.
Definition: SavedGame.cpp:673
std::vector< AlienBase * > * getAlienBases()
Returns the list of alien bases.
Definition: SavedGame.cpp:1404
Represents a player base on the globe.
Definition: Base.h:47
bool getWarned() const
gets whether or not the player has been warned
Definition: SavedGame.cpp:1508
void addMonth()
Increment the month counter.
Definition: SavedGame.cpp:1624
int getGlobeZoom() const
Gets the current globe zoom.
Definition: SavedGame.cpp:682
const std::string & getGraphCountryToggles() const
Return the GraphCountryToggles.
Definition: SavedGame.cpp:1581
Represents one research project.
Definition: RuleResearch.h:40
GameTime * getTime() const
Gets the current game time.
Definition: SavedGame.cpp:726
bool getDebugMode() const
Gets debug mode.
Definition: SavedGame.cpp:1421
void removePoppedResearch(const RuleResearch *research)
remove a research from the "popped up" array
Definition: SavedGame.cpp:1653
std::vector< AlienMission * > & getAlienMissions()
Full access to the current alien missions.
Definition: SavedGame.h:235
void setGraphCountryToggles(const std::string &value)
Sets the GraphCountryToggles.
Definition: SavedGame.cpp:1607
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:50
void getAvailableProductions(std::vector< RuleManufacture * > &productions, const Ruleset *ruleset, Base *base) const
Get the list of Productions which can be manufactured in a Base.
Definition: SavedGame.cpp:1056
Represents a region of the world.
Definition: Region.h:35
std::vector< Ufo * > * getUfos()
Gets the list of UFOs.
Definition: SavedGame.cpp:854
const AlienStrategy & getAlienStrategy() const
Read-only access to the alien strategy data.
Definition: SavedGame.h:233
void setGlobeLongitude(double lon)
Sets the new globe longitude.
Definition: SavedGame.cpp:655
void inspectSoldiers(Soldier **highestRanked, size_t *total, int rank)
Checks how many soldiers of a rank exist and which one has the highest score.
Definition: SavedGame.cpp:1349
Region * locateRegion(double lon, double lat) const
Locate a region containing a position.
Definition: SavedGame.cpp:1542
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:1472
std::vector< Country * > * getCountries()
Gets the list of countries.
Definition: SavedGame.cpp:764
void getDependableManufacture(std::vector< RuleManufacture * > &dependables, const RuleResearch *research, const Ruleset *ruleset, Base *base) const
Get the list of newly available manufacture projects once a research has been completed.
Definition: SavedGame.cpp:1198
std::vector< TerrorSite * > * getTerrorSites()
Gets the list of terror sites.
Definition: SavedGame.cpp:872
Container for savegame info displayed on listings.
Definition: SavedGame.h:64
const std::vector< AlienMission * > & getAlienMissions() const
Read-only access to the current alien missions.
Definition: SavedGame.h:237
void setIronman(bool ironman)
Sets if the game is in ironman mode.
Definition: SavedGame.cpp:602
AlienMission * getAlienMission(const std::string &region, const std::string &type) const
Gets a mission matching region and type.
Definition: SavedGame.cpp:1451