~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

Viewing changes to src/reward.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Copyright (C) 2007, 2008 Ben Asselstine
 
2
//
1
3
//  This program is free software; you can redistribute it and/or modify
2
4
//  it under the terms of the GNU General Public License as published by
3
5
//  the Free Software Foundation; either version 2 of the License, or
10
12
//
11
13
//  You should have received a copy of the GNU General Public License
12
14
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
 
 
15
 
#ifndef __REWARD_H
16
 
#define __REWARD_H
 
15
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
16
//  02110-1301, USA.
 
17
 
 
18
#ifndef REWARD_H
 
19
#define REWARD_H
 
20
 
17
21
#include <SDL_types.h>
18
22
#include "vector.h"
 
23
#include "ruinlist.h"
19
24
#include <string>
20
25
class Player;
21
26
class Army;
24
29
class XML_Helper;
25
30
class Ruin;
26
31
 
27
 
/** Base class for rewards
28
 
  *
29
 
  */
 
32
//! A little something nice for the Player.
 
33
/**
 
34
 * Reward objects are given to the Player upon completion of a difficult
 
35
 * task.  Rewards are awarded when a ruin is successfully searched, or when a
 
36
 * Hero completes a Quest, or visits a sage.
 
37
 *
 
38
 * Rewards come in 5 flavours (Reward::Type): an amount of gold pieces, a
 
39
 * number of powerful allies, a useful item, a map that exposes part of a
 
40
 * hidden map when playing with fog-of-war, and also a hidden ruin that only
 
41
 * that Player who is awarded the Reward can search.
 
42
 *
 
43
 * This is the base class for each of the different kinds of rewards.  It
 
44
 * holds the kind of reward and the name of the reward.
 
45
 *
 
46
 */
30
47
class Reward
31
48
{
32
49
    public:
33
50
 
34
 
        enum Type {GOLD = 1, ALLIES= 2, ITEM = 3, RUIN = 4, MAP = 5};
 
51
        //! The different kinds of Reward objects.
 
52
        enum Type {
 
53
          //! A number of gold pieces.
 
54
          GOLD = 1, 
 
55
          //! A number of powerful allies.
 
56
          ALLIES= 2, 
 
57
          //! A useful item.
 
58
          ITEM = 3, 
 
59
          //! A hidden ruin that only the rewarded Player can see.
 
60
          RUIN = 4, 
 
61
          //! A portion of the hidden map to expose to the rewarded player.
 
62
          MAP = 5
 
63
        };
35
64
 
36
 
        //! Standard constructor
 
65
        //! Default constructor.
 
66
        /**
 
67
         * Make a new constructor of the given type and name.
 
68
         *
 
69
         * @param type  The kind of reward.
 
70
         * @param name  The name of the reward.
 
71
         *
 
72
         * @note This constructor is only used in the constructors of other 
 
73
         *       Reward objects, and shouldn't be called directly.
 
74
         */
37
75
        Reward(Type type, std::string name = "");
38
 
        //! XML constructor
 
76
 
 
77
        //! Loading constructor.
 
78
        /**
 
79
         * Make a new Reward by reading it in from the opened saved-game file.
 
80
         *
 
81
         * @param helper  The opened saved-game file to read the Reward from.
 
82
         *
 
83
         * @note This constructor is only used within the constructors of
 
84
         *       other Reward objects, and shouldn't be called directly.
 
85
         *       It only loads the parts common to all Reward objects.
 
86
         */
39
87
        Reward(XML_Helper* helper);
40
 
        
 
88
 
 
89
        //! Copy constructor.
 
90
        /**
 
91
         * Make a new Reward by copying it from another Reward object.
 
92
         *
 
93
         * @param orig  The Reward object to copy it from.
 
94
         *
 
95
         * @note This constructor is only used within the constructors of
 
96
         *       other Reward objects, and shouldn't be called directly.
 
97
         *       It only copies the parts common to all Reward objects.
 
98
         */
 
99
        Reward (const Reward& orig);
 
100
 
 
101
        //! Destructor.
41
102
        virtual ~Reward();
42
103
 
43
 
        //! Get the type of the reward
 
104
        //! Get the type of the reward.
44
105
        Type getType() const { return d_type; }
45
106
 
46
 
        //! Returns the name of the reward
 
107
        //! Sets the name of the reward.
 
108
        void setName(std::string name) {d_name = name;}
 
109
 
 
110
        //! Returns the name of the reward.
47
111
        std::string getName() const {return d_name;}
48
112
 
49
 
        /** Saves the reward data
50
 
          * 
51
 
          * @note This function is called by the actual reward and only saves
52
 
          * the common data. It does NOT open/close tags etc. This has to be
53
 
          * done by the derived classes.
54
 
          */
 
113
        //! Generates a description of this reward.
 
114
        /**
 
115
         * This method inspects the underlying reward and generates an
 
116
         * appropriate description.
 
117
         */
 
118
        std::string getDescription();
 
119
 
 
120
        //! Saves the data elements common to all rewards.
 
121
        /**
 
122
         * @note This function is called by the actual reward and only saves
 
123
         * the common data. It does NOT open/close tags etc. This has to be
 
124
         * done by the derived classes.
 
125
         *
 
126
         * @param helper  The opened saved-game file to save the Reward object
 
127
         *                to.
 
128
         */
55
129
        virtual bool save(XML_Helper* helper) const;
56
130
 
57
 
        /** static load function (see XML_Helper)
58
 
          * 
59
 
          * Whenever an reward item is loaded, this function is called. It
60
 
          * examines the stored id and calls the constructor of the appropriate
61
 
          * reward class.
62
 
          *
63
 
          * @param helper       the XML_Helper instance for the savegame
64
 
          */
 
131
        //! Assist in the loading of Rewards of all kinds.
 
132
        /**
 
133
         * Whenever an reward item is loaded, this function is called. It
 
134
         * examines the stored id and calls the constructor of the appropriate
 
135
         * reward class.
 
136
         *
 
137
         * @param helper   The opened saved-game file to load the Reward from.
 
138
         */
65
139
        static Reward* handle_load(XML_Helper* helper);
66
140
 
67
141
    protected:
68
142
 
69
 
        //! Type of the reward
 
143
        //! Type of the reward.
70
144
        Type d_type;
 
145
 
 
146
        //! The name of the reward.
71
147
        std::string d_name;
72
148
 
73
149
};
74
150
 
 
151
//! A Reward of some gold pieces.
 
152
/**
 
153
 * Gold pieces are added to the Player's treasury.
 
154
 */
75
155
class Reward_Gold : public Reward
76
156
{
77
157
    public:
 
158
        //! Default constructor. 
 
159
        /**
 
160
         * @param gold  The number of gold pieces to award the Player.
 
161
         */
78
162
        Reward_Gold(Uint32 gold);
 
163
        //! Loading constructor.
79
164
        Reward_Gold(XML_Helper *helper);
 
165
        //! Copy constructor.
 
166
        Reward_Gold(const Reward_Gold& orig);
 
167
        //! Destructor.
80
168
        ~Reward_Gold();
81
169
 
 
170
        //! Return a random number of gold pieces.
 
171
        /**
 
172
         * This method provides a random number of gold pieces suitable for a
 
173
         * reward in the game.
 
174
         */
 
175
        static Uint32 getRandomGoldPieces();
 
176
 
 
177
        //! Save the gold reward to the opened saved-game file.
82
178
        bool save(XML_Helper* helper) const;
 
179
 
 
180
        //! Return the number of gold pieces associated with this reward.
83
181
        Uint32 getGold() const {return d_gold;}
84
182
 
85
183
    private:
 
184
        //! The number of gold pieces to award the player.
86
185
        Uint32 d_gold;
87
186
};
88
187
 
 
188
//! A number of powerful allies.
 
189
/**
 
190
 * Up to 8 allies are awarded to the Player's stack being given the Reward.
 
191
 * Allies are Army prototypes that have `Awardable' ability set.
 
192
 */
89
193
class Reward_Allies: public Reward
90
194
{
91
195
    public:
 
196
        //! Default constructor.  Make a new reward of allies.
 
197
        /**
 
198
         * @param army  The Army prototype to create allies from.
 
199
         * @param count The number of Army units to create from the prototype.
 
200
         */
92
201
        Reward_Allies(const Army *army, Uint32 count);
 
202
 
 
203
        //! Secondary constructor.  Make a new reward of allies.
 
204
        /**
 
205
         * @param army_type  The Id of the Army prototype to create allies from.
 
206
         * @param army_set   The Id of the Armyset that the type belongs to.
 
207
         * @param count      The number of Armies to create from the prototype.
 
208
         */
93
209
        Reward_Allies(Uint32 army_type, Uint32 army_set, Uint32 count);
 
210
 
 
211
        //! Make a new reward of allies from another one.
 
212
        Reward_Allies(const Reward_Allies& orig);
 
213
 
 
214
        //! Loading constructor.  Load the allies reward from a saved-game file.
94
215
        Reward_Allies(XML_Helper *helper);
 
216
 
 
217
        //! Destructor.
95
218
        ~Reward_Allies();
96
219
 
 
220
        //! Save the allies reward to the opened saved-game file.
97
221
        bool save(XML_Helper* helper) const;
 
222
 
 
223
        //! Return the army prototype of the allies associated with this reward.
98
224
        const Army * getArmy() const {return d_army;}
 
225
 
 
226
        //! Return the number allies that this reward will create.
99
227
        Uint32 getNoOfAllies() const {return d_count;}
 
228
 
 
229
        //! A static method that returns a random awardable Army prototype.
100
230
        static const Army* randomArmyAlly();
 
231
 
 
232
        //! A static method that returns a number of allies between 1 and 8.
 
233
        static const Uint32 getRandomAmountOfAllies();
 
234
 
 
235
        //! A static method for adding allies to the game map.
 
236
        /**
 
237
         * Place the given number of the given allies onto the map at the given
 
238
         * position.
 
239
         *
 
240
         * @param p           The player to make the new stack for, if the 
 
241
         *                    stack can't take all of the allies.
 
242
         * @param pos         The place on the map to add the allies.
 
243
         * @param army        The Army prototype that defines the allies.
 
244
         * @param alliesCount The number of allies to add.
 
245
         *
 
246
         * @return True if the armies could successfully be added to the game
 
247
         *         map.  Returns false otherwise.
 
248
         */
101
249
        static bool addAllies(Player *p, Vector<int> pos, const Army *army, Uint32 alliesCount);
 
250
 
 
251
        //! A static method for adding allies to the game map.
 
252
        /**
 
253
         * Place the given number of the given allies onto the map at the given
 
254
         * location.
 
255
         *
 
256
         * @param p           The player to make the new stack for, if the 
 
257
         *                    stack can't take all of the allies.
 
258
         * @param loc         The place on the map to add the allies.
 
259
         * @param army        The Army prototype that defines the allies.
 
260
         * @param alliesCount The number of allies to add.
 
261
         *
 
262
         * @note This method tries to add the armies to the various tiles of
 
263
         *       the location first, before placing it outside of the location.
 
264
         *
 
265
         * @return True if the armies could successfully be added to the game
 
266
         *         map.  Returns false otherwise.
 
267
         */
102
268
        static bool addAllies(Player *p, Location *l, const Army *army, Uint32 alliesCount);
103
269
 
104
270
    private:
 
271
        //! The Army prototype that represents the allies to give the Player.
105
272
        const Army *d_army;
 
273
        //! The army type of the given prototype.
106
274
        Uint32 d_army_type;
 
275
        //! The army set of the given prototype.
107
276
        Uint32 d_army_set;
 
277
        //! The number of allies to give the Player.
108
278
        Uint32 d_count;
109
279
};
110
280
 
 
281
//! A useful item to be awarded to a Hero.
 
282
/**
 
283
 * Item objects are given to a Hero who has completed a Quest or searched a 
 
284
 * Ruin object.
 
285
 */
111
286
class Reward_Item: public Reward
112
287
{
113
288
    public:
 
289
        //! Default constructor.
 
290
        /**
 
291
         * @param item  A pointer to the item to give to the Hero.
 
292
         */
114
293
        Reward_Item (Item *item);
 
294
 
 
295
        //! Loading constructor.
 
296
        /**
 
297
         * Make a new reward item by loading it from an opened saved-game file.
 
298
         *
 
299
         * @param helper  The opened saved-game file to load the item reward 
 
300
         *                from.
 
301
         */
115
302
        Reward_Item(XML_Helper *helper);
 
303
 
 
304
        //! Copy constructor.
 
305
        /**
 
306
         * Make a new reward item by copying it from another one.
 
307
         *
 
308
         * @param orig  The reward item to copy from.
 
309
         */
 
310
        Reward_Item(const Reward_Item& orig);
 
311
 
 
312
        //! Destructor.
116
313
        ~Reward_Item();
117
314
 
 
315
        //! Return a random Item object.
 
316
        /**
 
317
         * @note This method does not return an Reward_Item object.
 
318
         *
 
319
         * @note This method does not remove the Item object from the Itemlist.
 
320
         *
 
321
         * @return A pointer to a random Item object in the Itemlist.
 
322
         */
 
323
        static Item *getRandomItem();
 
324
 
 
325
        //! Save the reward item to a file.
 
326
        /**
 
327
         * @param helper  The opened saved-game file to save the reward item to.
 
328
         */
118
329
        bool save(XML_Helper* helper) const;
 
330
 
 
331
        //! Get the Item object associated with this reward.
119
332
        Item *getItem() const {return d_item;}
120
333
 
121
334
    private:
 
335
        //! Callback to load the Item object in the Reward_Item object.
122
336
        bool loadItem(std::string tag, XML_Helper* helper);
 
337
 
 
338
        //! A pointer to the Item object associated with this Reward_Item.
123
339
        Item *d_item;
124
340
};
125
341
 
 
342
//! A hidden ruin to be awarded to a Player.
 
343
/**
 
344
 * Hidden Ruin objects are only visitable by a single Player.
 
345
 * Hidden ruins are not given out as a reward when a Hero searched it and is
 
346
 * successful.  Hidden ruins are given out as a reward for a completed Quest.
 
347
 */
126
348
class Reward_Ruin: public Reward
127
349
{
128
350
    public:
 
351
        //! Default constructor.
 
352
        /**
 
353
         * Make a new Reward_Ruin.
 
354
         *
 
355
         * @param ruin  A pointer to the hidden Ruin object to present to the
 
356
         *              Player.
 
357
         */
129
358
        Reward_Ruin(Ruin *ruin);
 
359
 
 
360
        //! Loading constructor.
 
361
        /**
 
362
         * Make a new Reward_Ruin by loading it from an opened saved-game file.
 
363
         *
 
364
         * @param helper  The opened saved-game file to load the reward ruin 
 
365
         *                from.
 
366
         */
130
367
        Reward_Ruin(XML_Helper *helper);
 
368
 
 
369
        //! Copy constructor.
 
370
        /**
 
371
         * Make a new reward ruin by copying it from another one.
 
372
         *
 
373
         * @param orig  The reward ruin to copy from.
 
374
         */
 
375
        Reward_Ruin(const Reward_Ruin& orig);
 
376
 
 
377
        //! Destructor.
131
378
        ~Reward_Ruin();
132
379
 
 
380
        //! Go get a random hidden ruin to give to the Player.
 
381
        /**
 
382
         * Scan all of the Ruin objects in the game and find one that is
 
383
         * hidden but only visible by Neutral.  Pick a random Ruin object
 
384
         * out of the ones that qualify.
 
385
         * It is up to the caller to change the owner of the hidden Ruin 
 
386
         * object..
 
387
         *
 
388
         * @return A pointer to a Ruin object in the Ruinlist that is a hidden
 
389
         *         ruin and is owned by the neutral Player.  This method will
 
390
         *         return NULL if there are no more Ruin objects that meet 
 
391
         *         that criteria.
 
392
         */
 
393
        static Ruin *getRandomHiddenRuin();
 
394
 
 
395
        //! Save the reward ruin to an opened saved-game file.
 
396
        /**
 
397
         * @param helper  The opened saved-game file to write the ruin reward 
 
398
         *                to.
 
399
         */
133
400
        bool save(XML_Helper* helper) const;
134
 
        Ruin* getRuin() const {return d_ruin;}
 
401
 
 
402
        //! Return the Ruin object associated with this Reward_Ruin.
 
403
        Ruin* getRuin() const 
 
404
          {return Ruinlist::getInstance()->getObjectAt(d_ruin_pos);}
135
405
 
136
406
    private:
137
 
        Ruin *d_ruin;
 
407
        //! The position of the Ruin object associated with this reward.
 
408
        /**
 
409
         * The ruin is saved as a position for a good reason, but I don't know
 
410
         * what that reason is.  Perhaps the Ruinlist was loaded after the
 
411
         * Rewardlist at one time (but isn't any longer).
 
412
         * Maybe it is because a Ruin can reference a Reward_Ruin which can
 
413
         * reference a (hidden) Ruin.
 
414
         */
 
415
        //FIXME: verify that the ruin's position has to be used here.
 
416
        Vector<int> d_ruin_pos;
138
417
};
139
418
 
140
 
class Reward_Map: public Reward
 
419
//! A portion of a hidden map to reveal to a Player.
 
420
/**
 
421
 * When playing on a hidden map, the Player can receive a map that uncovers a
 
422
 * portion of the game map.  It only reveals a portion of the map for one 
 
423
 * Player.
 
424
 * The map has a position (from the derived Location class), and as well as a
 
425
 * height and a width.
 
426
 */
 
427
class Reward_Map: public Reward, public Location
141
428
{
142
429
    public:
143
 
        Reward_Map(Location *l, Uint32 height, Uint32 width);
 
430
        //! Default constructor.
 
431
        /**
 
432
         * Make a new Reward_Map from the given parameters.
 
433
         *
 
434
         * @param pos     The position of the top left corner tile of the map.
 
435
         * @param name    The name of this map.
 
436
         * @param height  The height of the revealed portion of the game map.
 
437
         * @param width   The width of the revealed portion of the game map.
 
438
         */
 
439
        Reward_Map(Vector<int> pos, std::string name, 
 
440
                   Uint32 height, Uint32 width);
 
441
 
 
442
        //! Loading constructor.
 
443
        /**
 
444
         * Make a new Reward_Map by loading it from an opened saved-game file.
 
445
         *
 
446
         * @param helper  The opened saved-game file to load the reward map
 
447
         *                from.
 
448
         */
144
449
        Reward_Map(XML_Helper *helper);
 
450
 
 
451
        //! Copy constructor.
 
452
        /**
 
453
         * Make a new reward map by copying it from another one.
 
454
         *
 
455
         * @param orig  The reward map to copy from.
 
456
         */
 
457
        Reward_Map(const Reward_Map& orig);
 
458
 
 
459
        //! Destructor.
145
460
        ~Reward_Map();
146
461
 
 
462
        //! Save the reward map to an opened saved-game file.
 
463
        /**
 
464
         * @param helper  The opened saved-game file to write the ruin map to.
 
465
         */
147
466
        bool save(XML_Helper* helper) const;
148
 
        Location* getLocation() const {return d_loc;}
 
467
 
 
468
        //! Get the height of the revealed portion of the game map.
149
469
        Uint32 getHeight() const {return d_height;}
 
470
 
 
471
        //! Get the width of the revealed portion of the game map.
150
472
        Uint32 getWidth() const {return d_width;}
151
473
 
 
474
        //! Return a description of a random map.
 
475
        /**
 
476
         * @note This will produce random maps that overlap each other.
 
477
         * @note x,y defines the top-left-most tile of the map.
 
478
         *
 
479
         * @param x       The number of tiles down in the vertical axis from the
 
480
         *                topmost edge of the map.
 
481
         * @param y       The number of tiles right in the horizontal axis from
 
482
         *                the leftmost edge of the map.
 
483
         * @param width   The width of the revealed portion of the game map.
 
484
         * @param height  The height of the revealed portion of the game map.
 
485
         */
 
486
        static void getRandomMap(int *x, int *y, int *width, int *height);
 
487
 
152
488
    private:
153
 
        bool loadLocation(std::string tag, XML_Helper* helper);
154
 
        Location *d_loc;
 
489
        //! The height of the revealed portion of the map (in tiles).
 
490
        /**
 
491
         * @note d_height + getPos().x must not exceed the height of the game
 
492
         *       map.
 
493
         */
155
494
        Uint32 d_height;
 
495
 
 
496
        //! The width of the revealed portion of the map (in tiles).
 
497
        /**
 
498
         * @note d_width + getPos().y must not exceed the width of the game
 
499
         *       map.
 
500
         */
156
501
        Uint32 d_width;
157
502
};
158
503