~ubuntu-branches/ubuntu/saucy/lordsawar/saucy

« back to all changes in this revision

Viewing changes to src/city.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2008-12-20 13:52:12 UTC
  • mfrom: (1.1.6 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081220135212-noeb2w3y98ebo7o9
Tags: 0.1.4-1
[ Barry deFreese ]
* New upstream release.
* Move 0.0.8-2.1 changelog entry to correct point in changelog.
* Make lordsawar-data suggest lordsawar.
* Update my e-mail address.
* Add build-depends on intltool, uuid-dev, and libboost-dev.
* Don't install locales since there are no translations currently.
* Add simple man page for new lordsawar-pbm binary.
* Drop gcc4.3 patches as they have been fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include <list>
27
27
#include <string>
 
28
#include <vector>
28
29
#include "Location.h"
29
30
#include "Ownable.h"
30
31
#include "Renamable.h"
 
32
#include "prodslot.h"
 
33
#include "defs.h"
 
34
#include "prodslotlist.h"
31
35
 
32
36
class Player;
33
37
class Stack;
34
38
class Army;
 
39
class ArmyProdBase;
 
40
class ArmyProto;
35
41
class Hero;
36
42
 
37
43
#define DEFAULT_CITY_NAME "Noname"
57
63
 * city.  Conquering another player's capital city doesn't give any bonus
58
64
 * except for bragging rights.
59
65
 */
60
 
class City : public Ownable, public Location, public Renamable
 
66
class City : public Ownable, public Location, public Renamable, 
 
67
    public ProdSlotlist
61
68
{
62
69
    public:
 
70
 
 
71
        //! The xml tag of this object in a saved-game file.
 
72
        static std::string d_tag; 
 
73
 
63
74
        //! Default constructor.
64
75
        /** 
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.
70
82
          */
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.
74
87
        City(const City&);
75
88
        //! Loading constructor.
106
119
         */
107
120
        bool reduceDefense();
108
121
 
109
 
        //! Add an Army production base to a production slot.
110
 
        /**
111
 
         * @note This method overwrites the production slot if neccessary.
112
 
         * 
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.
118
 
         */
119
 
        void addProductionBase(int index, Army *army);
120
 
 
121
 
        //! Clears the basic production of a given slot.
122
 
        /**
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.
126
 
         */
127
 
        void removeProductionBase(int index);
128
 
        
129
122
        //! Changes the owner of the city and prepares it for takeover.
130
123
        /**
131
124
         * @param newowner  The pointer to the Player in Playerlist who is the
166
159
         */
167
160
        void nextTurn();
168
161
 
169
 
        //! Returns whether or not the city can produce a given army type.
170
 
        /**
171
 
         * This method scans the production slots of the city for the given 
172
 
         * army prototype.
173
 
         *
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
177
 
         *                  in this city.
178
 
         * @return True if the given army prototype is already a production
179
 
         *         base in the city.  Otherwise false.
180
 
         */
181
 
        bool hasProductionBase(int type, Uint32 armyset) const;
182
 
 
183
 
        //! Returns true if the city already has bought this production type.
184
 
        bool hasProductionBase(const Army * army);
185
 
 
186
 
        //! Return the first slot that doesn't have a production base.
187
 
        int getFreeBasicSlot();
188
 
 
189
162
        //! Return the defense level of the city.
190
163
        int getDefenseLevel() const {return d_defense_level;}
191
164
 
198
171
         */
199
172
        int getGoldNeededForUpgrade() const; 
200
173
        
201
 
        //! Returns the maximum number of production bases of the city.
202
 
        /**
203
 
         * The city has this many production slots in total.  This value 
204
 
         * should always return 4.
205
 
         *
206
 
         * @return The maximum number of Army production bases that this city
207
 
         *         can have.
208
 
         */
209
 
        int getMaxNoOfProductionBases() const {return d_numprodbase;};
210
 
 
211
 
        void setMaxNoOfProductionBases(int max) {d_numprodbase = max;};
212
 
 
213
 
        //! Return the number of basic productions of the city.
214
 
        /**
215
 
         * Scan the production slots and count how many are filled with an
216
 
         * Army production base.
217
 
         *
218
 
         * @return The current number of used slots that the city has.
219
 
         */
220
 
        int getNoOfProductionBases();
221
 
 
222
 
        //! Get the number of turns until current production base is finished.
223
 
        int getDuration() const {return d_duration;}
224
 
 
225
 
        //! Return the index of the active production slot.
226
 
        /**
227
 
         * @return The index of the active production slot, or -1 if the City
228
 
         *         isn't producing anything.
229
 
         */
230
 
        int getActiveProductionSlot() const {return d_active_production_slot;}
231
 
        
232
 
        //! Set the active production base of the city.
233
 
        /**
234
 
         * Make the Army production base in particular slot active, so that
235
 
         * the Army starts being produced.
236
 
         *
237
 
         * @param index  The index of the production slot to activate. 
238
 
         *               -1 means no production at all.   This must be a value
239
 
         *               between -1 and 3.
240
 
         */
241
 
        void setActiveProductionSlot(int index);
242
 
        
243
174
        //! Return the income of the city per turn.
244
175
        Uint32 getGold() const {return d_gold;}
245
176
 
246
 
        //! Return the index of the army in the given slot.
247
 
        /**
248
 
         * @param slot  The production slot to return the army type for.  This
249
 
         *              value ranges between 0 and 3.
250
 
         *
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.
253
 
         */
254
 
        int getArmytype(int slot) const;
255
 
 
256
 
        //! Return the army production base of the given slot.
257
 
        const Army* getProductionBase(int slot) const;
258
 
        
259
177
        //! Returns whether or not the city has been destroyed.
260
178
        bool isBurnt() const {return d_burnt;}
261
179
 
329
247
        //! Return how many armies are in the city.
330
248
        Uint32 countDefenders();
331
249
 
332
 
        Uint32 countCitiesVectoringToHere();
333
 
 
334
250
        //! This makes the army show up.  called when it's time.
335
251
        const Army *armyArrives();
336
252
 
 
253
        bool isUnnamed() {return getName() == getDefaultName() ? true : false;};
 
254
 
 
255
        static std::string getDefaultName() {return DEFAULT_CITY_NAME;};
 
256
 
337
257
    private:
338
258
 
 
259
        bool load(std::string tag, XML_Helper *helper);
 
260
 
339
261
        //! Produces the currently active Army production base.
340
262
        Army * produceArmy();
341
263
 
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.
350
272
         */
351
 
        void randomlyImproveOrDegradeArmy(Army *army);
 
273
        void randomlyImproveOrDegradeArmy(ArmyProdBase *army);
352
274
 
353
275
        //! Sort the Army production bases that this city produces by strength.
354
276
        /**
358
280
 
359
281
        // DATA
360
282
 
361
 
        //! The production slots for this city.
362
 
        /**
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 
365
 
         * set to NULL.
366
 
         */
367
 
        Army* d_prodbase[MAX_PRODUCTION_SLOTS_IN_A_CITY];
368
 
 
369
 
        //! The maximum number of slots.
370
 
        /**
371
 
         * Equal to MAX_PRODUCTION_SLOTS_IN_A_CITY.
372
 
         */
373
 
        int d_numprodbase;
374
 
 
375
 
        //! The active production slot.
376
 
        /**
377
 
         * The Army production base in this slot is the Army unit that the
378
 
         * city is currently busy creating.
379
 
         */
380
 
        int d_active_production_slot;
381
 
 
382
 
        //! Number of turns until the next Army is produced.
383
 
        /**
384
 
         *  Number of turns required to finish the current production.
385
 
         *  When this value hits 0, the new Army unit is created.
386
 
         */
387
 
        int d_duration;
388
 
 
389
283
        //! The City gives the Player this much gold per turn.
390
284
        Uint32 d_gold;
391
285