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  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::vector<SaveInfo> getList(Language *lang, bool autoquick);
144  void load(const std::string &filename, Mod *mod);
146  void save(const std::string &filename) const;
148  std::wstring getName() const;
150  void setName(const std::wstring &name);
152  GameDifficulty getDifficulty() const;
154  void setDifficulty(GameDifficulty difficulty);
156  int getDifficultyCoefficient() const;
158  GameEnding getEnding() const;
160  void setEnding(GameEnding end);
162  bool isIronman() const;
164  void setIronman(bool ironman);
166  int64_t getFunds() const;
168  std::vector<int64_t> &getFundsList();
170  void setFunds(int64_t funds);
172  double getGlobeLongitude() const;
174  void setGlobeLongitude(double lon);
176  double getGlobeLatitude() const;
178  void setGlobeLatitude(double lat);
180  int getGlobeZoom() const;
182  void setGlobeZoom(int zoom);
184  void monthlyFunding();
186  GameTime *getTime() const;
188  void setTime(const GameTime& time);
190  int getId(const std::string &name);
192  const std::map<std::string, int> &getAllIds() const;
194  void setAllIds(const std::map<std::string, int> &ids);
196  std::vector<Country*> *getCountries();
198  int getCountryFunding() const;
200  std::vector<Region*> *getRegions();
202  std::vector<Base*> *getBases();
204  const std::vector<Base*> *getBases() const;
206  int getBaseMaintenance() const;
208  std::vector<Ufo*> *getUfos();
210  std::vector<Waypoint*> *getWaypoints();
212  std::vector<MissionSite*> *getMissionSites();
214  SavedBattleGame *getSavedBattle();
216  void setBattleGame(SavedBattleGame *battleGame);
218  void addFinishedResearchSimple(const RuleResearch *research);
220  void addFinishedResearch(const RuleResearch *research, const Mod *mod, Base *base, bool score = true);
222  const std::vector<const RuleResearch*> & getDiscoveredResearch() const;
224  void getAvailableResearchProjects(std::vector<RuleResearch*> & projects, const Mod *mod, Base *base, bool considerDebugMode = false) const;
226  void getNewlyAvailableResearchProjects(std::vector<RuleResearch*> & before, std::vector<RuleResearch*> & after, std::vector<RuleResearch*> & diff) const;
228  void getAvailableProductions(std::vector<RuleManufacture*> & productions, const Mod *mod, Base *base) const;
230  void getDependableManufacture(std::vector<RuleManufacture*> & dependables, const RuleResearch *research, const Mod *mod, Base *base) const;
232  bool hasUndiscoveredProtectedUnlock(const RuleResearch * r, const Mod * mod) const;
234  bool isResearched(const std::string &research, bool considerDebugMode = true) const;
236  bool isResearched(const std::vector<std::string> &research, bool considerDebugMode = true) const;
238  Soldier *getSoldier(int id) const;
240  bool handlePromotions(std::vector<Soldier*> &participants);
242  void processSoldier(Soldier *soldier, PromotionInfo &soldierData);
244  Soldier *inspectSoldiers(std::vector<Soldier*> &soldiers, std::vector<Soldier*> &participants, int rank);
246  std::vector<AlienBase*> *getAlienBases();
248  void setDebugMode();
250  bool getDebugMode() const;
252  std::vector<int64_t> &getMaintenances();
254  void addResearchScore(int score);
256  std::vector<int> &getResearchScores();
258  std::vector<int64_t> &getIncomes();
260  std::vector<int64_t> &getExpenditures();
262  bool getWarned() const;
264  void setWarned(bool warned);
266  AlienStrategy &getAlienStrategy() { return *_alienStrategy; }
268  const AlienStrategy &getAlienStrategy() const { return *_alienStrategy; }
270  std::vector<AlienMission*> &getAlienMissions() { return _activeMissions; }
272  const std::vector<AlienMission*> &getAlienMissions() const { return _activeMissions; }
274  AlienMission *findAlienMission(const std::string &region, MissionObjective objective) const;
276  Region *locateRegion(double lon, double lat) const;
278  Region *locateRegion(const Target &target) const;
280  int getMonthsPassed() const;
282  const std::string &getGraphRegionToggles() const;
284  const std::string &getGraphCountryToggles() const;
286  const std::string &getGraphFinanceToggles() const;
288  void setGraphRegionToggles(const std::string &value);
290  void setGraphCountryToggles(const std::string &value);
292  void setGraphFinanceToggles(const std::string &value);
294  void addMonth();
296  void addPoppedResearch(const RuleResearch* research);
298  bool wasResearchPopped(const RuleResearch* research);
300  void removePoppedResearch(const RuleResearch* research);
302  std::vector<Soldier*> *getDeadSoldiers();
304  Base *getSelectedBase();
306  void setSelectedBase(size_t base);
308  int getSoldierScore(Soldier *soldier);
310  void setLastSelectedArmor(const std::string &value);
312  std::string getLastSelectedArmor() const;
314  Craft *findCraftByUniqueId(const CraftId& craftId) const;
316  std::vector<MissionStatistics*> *getMissionStatistics();
318  std::vector<Soldier*>::iterator killSoldier(Soldier *soldier, BattleUnitKills *cause = 0);
319 };
320 
321 }
Represents a craft stored in a base.
Definition: Craft.h:45
Stores the information about alien strategy.
Definition: AlienStrategy.h:31
Represents an ongoing alien mission.
Definition: AlienMission.h:46
const std::vector< AlienMission * > & getAlienMissions() const
Read-only access to the current alien missions.
Definition: SavedGame.h:272
The game data that gets written to disk when the game is saved.
Definition: SavedGame.h:99
AlienStrategy & getAlienStrategy()
Full access to the alien strategy data.
Definition: SavedGame.h:266
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:268
Container for battle unit kills statistics.
Definition: BattleUnitStatistics.h:31
Contains strings used throughout the game for localization.
Definition: Language.h:39
Definition: SavedGame.h:85
Stores the current ingame time/date according to GMT.
Definition: GameTime.h:38
Represents a soldier hired by the player.
Definition: Soldier.h:48
Represents a player base on the globe.
Definition: Base.h:45
Represents one research project.
Definition: RuleResearch.h:38
std::vector< AlienMission * > & getAlienMissions()
Full access to the current alien missions.
Definition: SavedGame.h:270
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:47
Represents a region of the world.
Definition: Region.h:33
Base class for targets on the globe with a set of radian coordinates.
Definition: Target.h:33
Container for savegame info displayed on listings.
Definition: SavedGame.h:74
Definition: BaseInfoState.cpp:40