initial commit, lordsawar source, slightly modified
[lordsawar] / src / GameScenario.h
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
6 //
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.
11 //
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.
16 //
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 
20 //  02110-1301, USA.
21
22 #ifndef GAME_SCENARIO_H
23 #define GAME_SCENARIO_H
24
25 #include <string>
26 #include <list>
27 #include <sigc++/trackable.h>
28 #include "game-parameters.h"
29 #include "GameScenarioOptions.h"
30 #include "xmlhelper.h"
31
32 #include "armysetlist.h"
33 #include "armyset.h"
34 #include "GameMap.h"
35 #include "Configuration.h"
36
37 class XML_Helper;
38 class Tar_Helper;
39
40 //! A class to hold several scenario options.
41 /** 
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.
50  */
51
52 class GameScenario: public GameScenarioOptions
53 {
54     public:
55
56         //! The xml tag of this object in a saved-game file.
57         static std::string d_tag;
58
59         enum PlayMode 
60           {
61             HOTSEAT = 0, 
62             NETWORKED = 1,
63             PLAY_BY_MAIL = 2,
64           };
65
66         static std::string playModeToString(const GameScenario::PlayMode mode);
67         static GameScenario::PlayMode playModeFromString(const std::string str);
68
69         /** Initializes an "empty" scenario
70           * 
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)
74           */
75         GameScenario(std::string name, std::string comment, bool turnmode,
76                      GameScenario::PlayMode playmode = GameScenario::HOTSEAT);
77         
78         /** Load the game scenario using a specified save game
79           * 
80           * @param savegame     the full name of the saved-game to load
81           * @param broken       set to true if something goes wrong
82           */
83         GameScenario(std::string savegame, bool& broken);
84
85         GameScenario(XML_Helper &helper, bool &broken);
86
87         ~GameScenario();
88
89         //! Returns the number of the current turn.
90         unsigned int getRound() const {return s_round;}
91
92         //! Returns the turn mode. See NextTurn for a description.
93         bool getTurnmode() const {return d_turnmode;}
94         
95         std::string getId() const {return d_id;};
96
97         void setNewRandomId();
98
99         //! Returns the name of the scenario.
100         std::string getName(bool translate = true) const;
101
102         //! Returns the comment for the scenario.
103         std::string getComment(bool translate = true) const;
104
105         //! Returns the copyright for the scenario.
106         std::string getCopyright() const {return d_copyright; };
107
108         //! Returns the license of the scenario.
109         std::string getLicense() const {return d_license;};
110
111         //! Increments the turn number and does an autosave. Called by NextTurn
112         //! via a signal.
113         void nextRound();
114
115         //! Sets the name of the scenario.
116         void setName(std::string name) {d_name = name;}
117
118         //! Sets the description of the scenario.
119         void setComment(std::string comment) {d_comment = comment;}
120         
121         //! Sets the copyright of the scenario.
122         void setCopyright(std::string copy) {d_copyright = copy;}
123         
124         //! Sets the license of the scenario.
125         void setLicense(std::string license) {d_license = license;}
126         
127         /** Saves the game. See XML_Helper for further explanations.
128           * 
129           * @param filename     the full name of the save game file
130           * @return true if all went well, false otherwise
131           */
132         bool saveGame(std::string filename, std::string extension = "sav") const;
133         bool loadWithHelper(XML_Helper &helper);
134         bool saveWithHelper(XML_Helper &helper) const;
135
136         
137         guint32 getPlayMode() const {return d_playmode;};
138         void setPlayMode(GameScenario::PlayMode mode) {d_playmode = mode;};
139
140         bool validate(std::list<std::string> &errors, std::list<std::string> &warnings);
141
142         void initialize(GameParameters g);
143
144         static GameParameters loadGameParameters(std::string filename, bool &broken);
145
146         static PlayMode loadPlayMode(std::string filename, bool &broken);
147
148         static void loadDetails(std::string filename, bool &broken, guint32 &player_count, guint32 &city_count, std::string &name, std::string &comment);
149
150         void inhibitAutosaveRemoval(bool i) {inhibit_autosave_removal = i;}
151     private:
152           /** Callback function for loading a game. See XML_Helper for details.
153            *
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.
157            */
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);
169           bool autoSave();
170
171           bool loadArmysets(Tar_Helper *t);
172           bool loadTilesets(Tar_Helper *t);
173           bool loadCitysets(Tar_Helper *t);
174           bool loadShieldsets(Tar_Helper *t);
175
176           // DATA
177           std::string d_name;
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
182           guint32 d_playmode;
183           std::string d_id; //globally unique id identifying the scenario
184           bool inhibit_autosave_removal;
185 };
186
187 #endif // GAME_SCENARIO_H
188
189 // End of file