initial commit, lordsawar source, slightly modified
[lordsawar] / src / CreateScenario.h
1 // Copyright (C) 2003, 2004, 2005 Ulf Lorenz
2 // Copyright (C) 2003 Michael Bartl
3 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
4 // Copyright (C) 2007 Ole Laursen
5 //
6 //  This program 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 //  This program 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 Library General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
19 //  02110-1301, USA.
20
21 #ifndef CREATE_SCENARIO_H
22 #define CREATE_SCENARIO_H
23
24 #include <string>
25 #include <vector>
26 #include <list>
27 #include <gtkmm.h>
28 #include <sigc++/signal.h>
29 #include "CreateScenarioRandomize.h"
30 #include "game-parameters.h"
31 #include "vector.h"
32
33 class MapGenerator;
34 class GameScenario;
35 class Player;
36 class City;
37
38 /** \brief Creates and dumps (i.e. saves) a scenario.
39   * 
40   * The purpose of this class is to create a new scenario which can then be
41   * "loaded" by the game scenario class. The advantage is that the scenario
42   * creation can be concentrated in one specific class instead of being scattered
43   * over different classes and all objects (city, player, stack...) only need
44   * one "loading" constructor. The disavantage is that all significant changes
45   * e.g. to the player class have to be reflected here, too.
46   */
47
48 class CreateScenario : public CreateScenarioRandomize
49 {
50     public:
51         //! This represents the class of the map (hills, islands etc.).
52         enum MapType { NORMAL };
53     
54         /** The Constructor
55           * 
56           * @param width    the width of the map in the new scenario
57           * @param height   the heightof the map in the new scenario
58           */
59         CreateScenario(int width = 112, int height = 156);
60         ~CreateScenario();
61
62         // setters
63
64         //! Set the terrain distribution; differences to 100% are grass; sum may exceed 100%
65         void setPercentages(int pgrass, int pwater, int pforest, int pswamp,
66                             int phills, int pmountains);
67
68         //! Set the tileset of the map
69         void setMapTiles(std::string tilesname);
70
71         //! Set the shieldset for the map
72         void setShieldset(std::string shieldsname);
73
74         //! Set the cityset for the map
75         void setCityset(std::string citysetname);
76
77         //! Set the number of cities on the map
78         void setNoCities(int number);
79
80         //! Set the number of ruins on the map
81         void setNoRuins(int number);
82
83         //! Set the number of signposts on the map
84         void setNoSignposts(int number);
85
86         //! Set the number of temples
87         void setNoTemples(int number);
88
89         //! Set the width of the map
90         void setWidth(int width);
91
92         //! Set the height of the map
93         void setHeight(int height);
94
95         /** Set the turn mode
96           * 
97           * @param turnmode     if set to true, several actions (healing armies
98           *                     and producng armies, respectively) take part at
99           *                     the beginning of the correpsonding player's turn,
100           *                     else they are done when all players have
101           *                     finished their round.
102           */
103         void setTurnmode(bool turnmode) {d_turnmode=turnmode;}
104       
105         /** Add a player to the scenario
106           * 
107           * @param name     the name of the player
108           * @param armyset  the name of the player's armyset
109           * @param color    the color of the player
110           * @param type     the type of the player (see class player for more info)
111           * @return a pointer to the created player
112           */
113         Player* addPlayer(std::string name, guint32 armyset, Gdk::Color color,
114                           int type);
115
116         /** Almost the same as addPlayer, but performs some additional checks
117           * 
118           * @param name     the name of the player
119           * @param armyset  the name of the player's armyset
120           * @param color    the color of the player
121           * @param type     the type of the player (see class player for more info)
122           * @return false if a neutral player already exists, true otherwise
123           */
124         bool addNeutral(std::string name, guint32 armyset, Gdk::Color color,
125                         int type);
126
127         
128         //! Get the number of players already added
129         int getNoPlayers() const;
130
131         //! Get the n-th player
132         Player* getPlayer(int number) const;
133
134         //! Get the type of the map
135         MapType getMaptype() const {return NORMAL;};
136
137         //! Get the number of cities of the map
138         int getNoCities() const;
139
140         //! Get the number of ruins on the map
141         int getNoRuins() const;
142
143         //! Get the number of signposts on the map
144         int getNoSignposts() const;
145
146         //! Get the number of temples
147         int getNoTemples() const;
148
149         /** Creates a map
150           * 
151           * Calling this function will initiate the creation process itself. The
152           * result is a saved map with several distributed players. The created
153           * map can be either saved or used further (all lists etc. have already
154           * been filled)
155           */
156         bool create(const GameParameters &g);
157
158         /** Dumps (Saves) the map
159           * 
160           * @param filename     the full name of the save file
161           * 
162           * This will do the same as GameScenario::save() does (in fact it calls
163           * GameScenario::save)
164           */
165         bool dump(std::string filename) const;
166
167         MapGenerator *getGenerator() const {return d_generator;};
168         static int calculateRoadType (Vector<int> t);
169         
170         //! Emitted when the generator generates something
171         sigc::signal<void> progress;
172
173         static int calculateNumberOfSignposts(int width, int height, int grass);
174     private:
175         //! Creates the map and distributes cities, temples and ruins
176         bool createMap();
177
178         void createCapitalCity(Player *player, City *city);
179         bool tooNearToOtherCapitalCities(City *c, std::list<City*> capitals, guint32 distance);
180
181         //! Distributes the players over the map
182         bool distributePlayers();
183
184         //! Setup city names and production
185         bool setupCities(bool cities_can_produce_allies, 
186                          int number_of_armies_factor);
187
188         //! Setup temple names
189         bool setupTemples();
190         
191         //! Set up ruin names and keepers
192         bool setupRuins(bool strongholds_invisible, int sage_factor, 
193                         int no_guardian_factor, int stronghold_factor);
194
195
196         //! Set up the standard set of items
197         bool setupItems();
198
199         //! Set up signposts
200         //! @param ratio - how many signposts reference nearby cities vs
201         //                 signposts that don't.
202         bool setupSignposts(int ratio);
203
204         //! Do some setup concerning the players (give them money)
205         //! If we're playing with diplomacy then we start out at peace,
206         //! and if we're not playing with diplomacy we start out at war.
207         bool setupPlayers(bool random_turns, int base_gold);
208
209         bool setupRoads();
210         bool setupBridges();
211
212         void quickStart();
213
214         //! Given the difficulty, get some characteristics of ruins
215         void getRuinDifficulty (int difficulty, int *sage_factor, 
216                                 int *no_guardian_factor, 
217                                 int *stronghold_factor);
218
219         //! Given the difficulty, and whether we're doing a hidden map,
220         //see how many signposts should point to cities vs how many
221         //do not.
222         void getSignpostDifficulty (int difficulty, bool hidden_map, 
223                                     int *signpost_ratio);
224
225         //! Given the difficulty, see how many army units every city
226         //produces by default.  it is thought that more is easier because
227         //players do not have to pay for more armies.
228         void getCityDifficulty (int difficulty, int *number_of_armies_factor);
229
230         void on_progress(double percent, std::string description);
231
232         //data
233         //for map creation
234         GameScenario* d_scenario;
235         MapGenerator* d_generator;
236         std::string d_tilesname;
237         std::string d_shieldsname;
238         std::string d_citysetname;
239         int d_width;
240         int d_height;
241         bool d_turnmode;
242 };
243
244 #endif  //CREATE_SCENARIO_H