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
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.
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.
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
21 #ifndef CREATE_SCENARIO_H
22 #define CREATE_SCENARIO_H
28 #include <sigc++/signal.h>
29 #include "CreateScenarioRandomize.h"
30 #include "game-parameters.h"
38 /** \brief Creates and dumps (i.e. saves) a scenario.
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.
48 class CreateScenario : public CreateScenarioRandomize
51 //! This represents the class of the map (hills, islands etc.).
52 enum MapType { NORMAL };
56 * @param width the width of the map in the new scenario
57 * @param height the heightof the map in the new scenario
59 CreateScenario(int width = 112, int height = 156);
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);
68 //! Set the tileset of the map
69 void setMapTiles(std::string tilesname);
71 //! Set the shieldset for the map
72 void setShieldset(std::string shieldsname);
74 //! Set the cityset for the map
75 void setCityset(std::string citysetname);
77 //! Set the number of cities on the map
78 void setNoCities(int number);
80 //! Set the number of ruins on the map
81 void setNoRuins(int number);
83 //! Set the number of signposts on the map
84 void setNoSignposts(int number);
86 //! Set the number of temples
87 void setNoTemples(int number);
89 //! Set the width of the map
90 void setWidth(int width);
92 //! Set the height of the map
93 void setHeight(int height);
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.
103 void setTurnmode(bool turnmode) {d_turnmode=turnmode;}
105 /** Add a player to the scenario
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
113 Player* addPlayer(std::string name, guint32 armyset, Gdk::Color color,
116 /** Almost the same as addPlayer, but performs some additional checks
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
124 bool addNeutral(std::string name, guint32 armyset, Gdk::Color color,
128 //! Get the number of players already added
129 int getNoPlayers() const;
131 //! Get the n-th player
132 Player* getPlayer(int number) const;
134 //! Get the type of the map
135 MapType getMaptype() const {return NORMAL;};
137 //! Get the number of cities of the map
138 int getNoCities() const;
140 //! Get the number of ruins on the map
141 int getNoRuins() const;
143 //! Get the number of signposts on the map
144 int getNoSignposts() const;
146 //! Get the number of temples
147 int getNoTemples() const;
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
156 bool create(const GameParameters &g);
158 /** Dumps (Saves) the map
160 * @param filename the full name of the save file
162 * This will do the same as GameScenario::save() does (in fact it calls
163 * GameScenario::save)
165 bool dump(std::string filename) const;
167 MapGenerator *getGenerator() const {return d_generator;};
168 static int calculateRoadType (Vector<int> t);
170 //! Emitted when the generator generates something
171 sigc::signal<void> progress;
173 static int calculateNumberOfSignposts(int width, int height, int grass);
175 //! Creates the map and distributes cities, temples and ruins
178 void createCapitalCity(Player *player, City *city);
179 bool tooNearToOtherCapitalCities(City *c, std::list<City*> capitals, guint32 distance);
181 //! Distributes the players over the map
182 bool distributePlayers();
184 //! Setup city names and production
185 bool setupCities(bool cities_can_produce_allies,
186 int number_of_armies_factor);
188 //! Setup temple names
191 //! Set up ruin names and keepers
192 bool setupRuins(bool strongholds_invisible, int sage_factor,
193 int no_guardian_factor, int stronghold_factor);
196 //! Set up the standard set of items
200 //! @param ratio - how many signposts reference nearby cities vs
201 // signposts that don't.
202 bool setupSignposts(int ratio);
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);
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);
219 //! Given the difficulty, and whether we're doing a hidden map,
220 //see how many signposts should point to cities vs how many
222 void getSignpostDifficulty (int difficulty, bool hidden_map,
223 int *signpost_ratio);
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);
230 void on_progress(double percent, std::string description);
234 GameScenario* d_scenario;
235 MapGenerator* d_generator;
236 std::string d_tilesname;
237 std::string d_shieldsname;
238 std::string d_citysetname;
244 #endif //CREATE_SCENARIO_H