57
63
* city. Conquering another player's capital city doesn't give any bonus
58
64
* except for bragging rights.
60
class City : public Ownable, public Location, public Renamable
66
class City : public Ownable, public Location, public Renamable,
71
//! The xml tag of this object in a saved-game file.
72
static std::string d_tag;
63
74
//! Default constructor.
65
76
* Make a new city object.
67
78
* @param pos The location of the city on the game map.
68
79
* @param name The name of the city.
69
80
* @param gold The amount of gold the city produces each turn.
81
* @param numslots The number of production slots for this city.
71
83
City(Vector<int> pos, std::string name = DEFAULT_CITY_NAME,
72
Uint32 gold = DEFAULT_CITY_INCOME);
84
Uint32 gold = DEFAULT_CITY_INCOME,
85
Uint32 numslots = MAX_PRODUCTION_SLOTS_IN_A_CITY);
73
86
//! Copy constructor.
75
88
//! Loading constructor.
107
120
bool reduceDefense();
109
//! Add an Army production base to a production slot.
111
* @note This method overwrites the production slot if neccessary.
113
* @param index The index of the production slot; if set to -1,
114
* the city will try to find a free production slot.
115
* This must be a value between -1 and 3.
116
* @param army The Army production base to add. Look at the
117
* Army class to find out what a production base is.
119
void addProductionBase(int index, Army *army);
121
//! Clears the basic production of a given slot.
123
* @param index The slot to remove the Army production base from.
124
* This method deletes the Army production base object.
125
* This parameter must be a a value between 0 and 3.
127
void removeProductionBase(int index);
129
122
//! Changes the owner of the city and prepares it for takeover.
131
124
* @param newowner The pointer to the Player in Playerlist who is the
169
//! Returns whether or not the city can produce a given army type.
171
* This method scans the production slots of the city for the given
174
* @param type The index of the Army prototype in the Armyset.
175
* @param armyset The unique Id of the armyset for which to check
176
* if the given type is already a production base
178
* @return True if the given army prototype is already a production
179
* base in the city. Otherwise false.
181
bool hasProductionBase(int type, Uint32 armyset) const;
183
//! Returns true if the city already has bought this production type.
184
bool hasProductionBase(const Army * army);
186
//! Return the first slot that doesn't have a production base.
187
int getFreeBasicSlot();
189
162
//! Return the defense level of the city.
190
163
int getDefenseLevel() const {return d_defense_level;}
199
172
int getGoldNeededForUpgrade() const;
201
//! Returns the maximum number of production bases of the city.
203
* The city has this many production slots in total. This value
204
* should always return 4.
206
* @return The maximum number of Army production bases that this city
209
int getMaxNoOfProductionBases() const {return d_numprodbase;};
211
void setMaxNoOfProductionBases(int max) {d_numprodbase = max;};
213
//! Return the number of basic productions of the city.
215
* Scan the production slots and count how many are filled with an
216
* Army production base.
218
* @return The current number of used slots that the city has.
220
int getNoOfProductionBases();
222
//! Get the number of turns until current production base is finished.
223
int getDuration() const {return d_duration;}
225
//! Return the index of the active production slot.
227
* @return The index of the active production slot, or -1 if the City
228
* isn't producing anything.
230
int getActiveProductionSlot() const {return d_active_production_slot;}
232
//! Set the active production base of the city.
234
* Make the Army production base in particular slot active, so that
235
* the Army starts being produced.
237
* @param index The index of the production slot to activate.
238
* -1 means no production at all. This must be a value
241
void setActiveProductionSlot(int index);
243
174
//! Return the income of the city per turn.
244
175
Uint32 getGold() const {return d_gold;}
246
//! Return the index of the army in the given slot.
248
* @param slot The production slot to return the army type for. This
249
* value ranges between 0 and 3.
251
* @return The index of the Army prototype unit within it's Armyset,
252
* or -1 if no production base is allocated to that slot.
254
int getArmytype(int slot) const;
256
//! Return the army production base of the given slot.
257
const Army* getProductionBase(int slot) const;
259
177
//! Returns whether or not the city has been destroyed.
260
178
bool isBurnt() const {return d_burnt;}
329
247
//! Return how many armies are in the city.
330
248
Uint32 countDefenders();
332
Uint32 countCitiesVectoringToHere();
334
250
//! This makes the army show up. called when it's time.
335
251
const Army *armyArrives();
253
bool isUnnamed() {return getName() == getDefaultName() ? true : false;};
255
static std::string getDefaultName() {return DEFAULT_CITY_NAME;};
259
bool load(std::string tag, XML_Helper *helper);
339
261
//! Produces the currently active Army production base.
340
262
Army * produceArmy();
348
270
* It also works the other way. Elephants can be altered to take 5
349
271
* turns instead of 4 turns, or have their strength decreased to 7.
351
void randomlyImproveOrDegradeArmy(Army *army);
273
void randomlyImproveOrDegradeArmy(ArmyProdBase *army);
353
275
//! Sort the Army production bases that this city produces by strength.
361
//! The production slots for this city.
363
* Each slot holds an Army production base that the City can
364
* potentially produce Army units from. When a slot is empty, it is
367
Army* d_prodbase[MAX_PRODUCTION_SLOTS_IN_A_CITY];
369
//! The maximum number of slots.
371
* Equal to MAX_PRODUCTION_SLOTS_IN_A_CITY.
375
//! The active production slot.
377
* The Army production base in this slot is the Army unit that the
378
* city is currently busy creating.
380
int d_active_production_slot;
382
//! Number of turns until the next Army is produced.
384
* Number of turns required to finish the current production.
385
* When this value hits 0, the new Army unit is created.
389
283
//! The City gives the Player this much gold per turn.