1 // Copyright (C) 2000, 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2004, 2006 Andrea Paternesi
4 // Copyright (C) 2007, 2008 Ben Asselstine
5 // Copyright (C) 2007 Ole Laursen
7 // This program 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.
12 // This program 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 Library General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #ifndef GAME_SCENARIO_H
23 #define GAME_SCENARIO_H
27 #include <sigc++/trackable.h>
28 #include "game-parameters.h"
29 #include "GameScenarioOptions.h"
30 #include "xmlhelper.h"
32 #include "armysetlist.h"
35 #include "Configuration.h"
40 //! A class to hold several scenario options.
42 * This class has two functions. On the one hand side, it holds some data
43 * about the current scenario being played (such as the name), on the other
44 * hand it has a kind of supervisor function. Loading and saving works in
45 * a hierarchical way with superior objects (such as the playerlist) saving
46 * their data and then telling inferior objects (such as players) to save
47 * their data as well. GameScenario is kind of the root of the saving or
48 * loading process. For more information about the saving procedure, have
49 * a look at XML_Helper.
52 class GameScenario: public GameScenarioOptions
56 //! The xml tag of this object in a saved-game file.
57 static std::string d_tag;
66 static std::string playModeToString(const GameScenario::PlayMode mode);
67 static GameScenario::PlayMode playModeFromString(const std::string str);
69 /** Initializes an "empty" scenario
71 * @param name the name of the scenario
72 * @param comment the comment for the scenario
73 * @param turnmode the turnmode (see NextTurn for description)
75 GameScenario(std::string name, std::string comment, bool turnmode,
76 GameScenario::PlayMode playmode = GameScenario::HOTSEAT);
78 /** Load the game scenario using a specified save game
80 * @param savegame the full name of the saved-game to load
81 * @param broken set to true if something goes wrong
83 GameScenario(std::string savegame, bool& broken);
85 GameScenario(XML_Helper &helper, bool &broken);
89 //! Returns the number of the current turn.
90 unsigned int getRound() const {return s_round;}
92 //! Returns the turn mode. See NextTurn for a description.
93 bool getTurnmode() const {return d_turnmode;}
95 std::string getId() const {return d_id;};
97 void setNewRandomId();
99 //! Returns the name of the scenario.
100 std::string getName(bool translate = true) const;
102 //! Returns the comment for the scenario.
103 std::string getComment(bool translate = true) const;
105 //! Returns the copyright for the scenario.
106 std::string getCopyright() const {return d_copyright; };
108 //! Returns the license of the scenario.
109 std::string getLicense() const {return d_license;};
111 //! Increments the turn number and does an autosave. Called by NextTurn
115 //! Sets the name of the scenario.
116 void setName(std::string name) {d_name = name;}
118 //! Sets the description of the scenario.
119 void setComment(std::string comment) {d_comment = comment;}
121 //! Sets the copyright of the scenario.
122 void setCopyright(std::string copy) {d_copyright = copy;}
124 //! Sets the license of the scenario.
125 void setLicense(std::string license) {d_license = license;}
127 /** Saves the game. See XML_Helper for further explanations.
129 * @param filename the full name of the save game file
130 * @return true if all went well, false otherwise
132 bool saveGame(std::string filename, std::string extension = "sav") const;
133 bool loadWithHelper(XML_Helper &helper);
134 bool saveWithHelper(XML_Helper &helper) const;
137 guint32 getPlayMode() const {return d_playmode;};
138 void setPlayMode(GameScenario::PlayMode mode) {d_playmode = mode;};
140 bool validate(std::list<std::string> &errors, std::list<std::string> &warnings);
142 void initialize(GameParameters g);
144 static GameParameters loadGameParameters(std::string filename, bool &broken);
146 static PlayMode loadPlayMode(std::string filename, bool &broken);
148 static void loadDetails(std::string filename, bool &broken, guint32 &player_count, guint32 &city_count, std::string &name, std::string &comment);
150 void inhibitAutosaveRemoval(bool i) {inhibit_autosave_removal = i;}
152 /** Callback function for loading a game. See XML_Helper for details.
154 * @param tag the tag name
155 * @param helper the helper for parsing the save game file
156 * @return true if all went well, false otherwise.
158 bool load(std::string tag, XML_Helper* helper);
159 void quickStartEvenlyDivided();
160 void quickStartAIHeadStart();
161 bool setupFog(bool hidden_map);
162 bool setupCities(GameParameters::QuickStartPolicy quick_start);
163 bool setupRewards(bool hidden_map);
164 bool setupMapRewards();
165 bool setupRuinRewards();
166 bool setupItemRewards();
167 bool setupStacks(bool hidden_map);
168 void setupDiplomacy(bool diplomacy);
171 bool loadArmysets(Tar_Helper *t);
172 bool loadTilesets(Tar_Helper *t);
173 bool loadCitysets(Tar_Helper *t);
174 bool loadShieldsets(Tar_Helper *t);
178 std::string d_comment;
179 std::string d_copyright;
180 std::string d_license;
181 bool d_turnmode; //see NextTurn for a description of this option
183 std::string d_id; //globally unique id identifying the scenario
184 bool inhibit_autosave_removal;
187 #endif // GAME_SCENARIO_H