27
/** Base class for rewards
32
//! A little something nice for the Player.
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.
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.
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.
34
enum Type {GOLD = 1, ALLIES= 2, ITEM = 3, RUIN = 4, MAP = 5};
51
//! The different kinds of Reward objects.
53
//! A number of gold pieces.
55
//! A number of powerful allies.
59
//! A hidden ruin that only the rewarded Player can see.
61
//! A portion of the hidden map to expose to the rewarded player.
36
//! Standard constructor
65
//! Default constructor.
67
* Make a new constructor of the given type and name.
69
* @param type The kind of reward.
70
* @param name The name of the reward.
72
* @note This constructor is only used in the constructors of other
73
* Reward objects, and shouldn't be called directly.
37
75
Reward(Type type, std::string name = "");
77
//! Loading constructor.
79
* Make a new Reward by reading it in from the opened saved-game file.
81
* @param helper The opened saved-game file to read the Reward from.
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.
39
87
Reward(XML_Helper* helper);
91
* Make a new Reward by copying it from another Reward object.
93
* @param orig The Reward object to copy it from.
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.
99
Reward (const Reward& orig);
41
102
virtual ~Reward();
43
//! Get the type of the reward
104
//! Get the type of the reward.
44
105
Type getType() const { return d_type; }
46
//! Returns the name of the reward
107
//! Sets the name of the reward.
108
void setName(std::string name) {d_name = name;}
110
//! Returns the name of the reward.
47
111
std::string getName() const {return d_name;}
49
/** Saves the reward data
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.
113
//! Generates a description of this reward.
115
* This method inspects the underlying reward and generates an
116
* appropriate description.
118
std::string getDescription();
120
//! Saves the data elements common to all rewards.
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.
126
* @param helper The opened saved-game file to save the Reward object
55
129
virtual bool save(XML_Helper* helper) const;
57
/** static load function (see XML_Helper)
59
* Whenever an reward item is loaded, this function is called. It
60
* examines the stored id and calls the constructor of the appropriate
63
* @param helper the XML_Helper instance for the savegame
131
//! Assist in the loading of Rewards of all kinds.
133
* Whenever an reward item is loaded, this function is called. It
134
* examines the stored id and calls the constructor of the appropriate
137
* @param helper The opened saved-game file to load the Reward from.
65
139
static Reward* handle_load(XML_Helper* helper);
69
//! Type of the reward
143
//! Type of the reward.
146
//! The name of the reward.
71
147
std::string d_name;
151
//! A Reward of some gold pieces.
153
* Gold pieces are added to the Player's treasury.
75
155
class Reward_Gold : public Reward
158
//! Default constructor.
160
* @param gold The number of gold pieces to award the Player.
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);
170
//! Return a random number of gold pieces.
172
* This method provides a random number of gold pieces suitable for a
173
* reward in the game.
175
static Uint32 getRandomGoldPieces();
177
//! Save the gold reward to the opened saved-game file.
82
178
bool save(XML_Helper* helper) const;
180
//! Return the number of gold pieces associated with this reward.
83
181
Uint32 getGold() const {return d_gold;}
184
//! The number of gold pieces to award the player.
188
//! A number of powerful allies.
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.
89
193
class Reward_Allies: public Reward
196
//! Default constructor. Make a new reward of allies.
198
* @param army The Army prototype to create allies from.
199
* @param count The number of Army units to create from the prototype.
92
201
Reward_Allies(const Army *army, Uint32 count);
203
//! Secondary constructor. Make a new reward of allies.
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.
93
209
Reward_Allies(Uint32 army_type, Uint32 army_set, Uint32 count);
211
//! Make a new reward of allies from another one.
212
Reward_Allies(const Reward_Allies& orig);
214
//! Loading constructor. Load the allies reward from a saved-game file.
94
215
Reward_Allies(XML_Helper *helper);
220
//! Save the allies reward to the opened saved-game file.
97
221
bool save(XML_Helper* helper) const;
223
//! Return the army prototype of the allies associated with this reward.
98
224
const Army * getArmy() const {return d_army;}
226
//! Return the number allies that this reward will create.
99
227
Uint32 getNoOfAllies() const {return d_count;}
229
//! A static method that returns a random awardable Army prototype.
100
230
static const Army* randomArmyAlly();
232
//! A static method that returns a number of allies between 1 and 8.
233
static const Uint32 getRandomAmountOfAllies();
235
//! A static method for adding allies to the game map.
237
* Place the given number of the given allies onto the map at the given
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.
246
* @return True if the armies could successfully be added to the game
247
* map. Returns false otherwise.
101
249
static bool addAllies(Player *p, Vector<int> pos, const Army *army, Uint32 alliesCount);
251
//! A static method for adding allies to the game map.
253
* Place the given number of the given allies onto the map at the given
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.
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.
265
* @return True if the armies could successfully be added to the game
266
* map. Returns false otherwise.
102
268
static bool addAllies(Player *p, Location *l, const Army *army, Uint32 alliesCount);
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.
281
//! A useful item to be awarded to a Hero.
283
* Item objects are given to a Hero who has completed a Quest or searched a
111
286
class Reward_Item: public Reward
289
//! Default constructor.
291
* @param item A pointer to the item to give to the Hero.
114
293
Reward_Item (Item *item);
295
//! Loading constructor.
297
* Make a new reward item by loading it from an opened saved-game file.
299
* @param helper The opened saved-game file to load the item reward
115
302
Reward_Item(XML_Helper *helper);
304
//! Copy constructor.
306
* Make a new reward item by copying it from another one.
308
* @param orig The reward item to copy from.
310
Reward_Item(const Reward_Item& orig);
315
//! Return a random Item object.
317
* @note This method does not return an Reward_Item object.
319
* @note This method does not remove the Item object from the Itemlist.
321
* @return A pointer to a random Item object in the Itemlist.
323
static Item *getRandomItem();
325
//! Save the reward item to a file.
327
* @param helper The opened saved-game file to save the reward item to.
118
329
bool save(XML_Helper* helper) const;
331
//! Get the Item object associated with this reward.
119
332
Item *getItem() const {return d_item;}
335
//! Callback to load the Item object in the Reward_Item object.
122
336
bool loadItem(std::string tag, XML_Helper* helper);
338
//! A pointer to the Item object associated with this Reward_Item.
342
//! A hidden ruin to be awarded to a Player.
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.
126
348
class Reward_Ruin: public Reward
351
//! Default constructor.
353
* Make a new Reward_Ruin.
355
* @param ruin A pointer to the hidden Ruin object to present to the
129
358
Reward_Ruin(Ruin *ruin);
360
//! Loading constructor.
362
* Make a new Reward_Ruin by loading it from an opened saved-game file.
364
* @param helper The opened saved-game file to load the reward ruin
130
367
Reward_Ruin(XML_Helper *helper);
369
//! Copy constructor.
371
* Make a new reward ruin by copying it from another one.
373
* @param orig The reward ruin to copy from.
375
Reward_Ruin(const Reward_Ruin& orig);
380
//! Go get a random hidden ruin to give to the Player.
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
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
393
static Ruin *getRandomHiddenRuin();
395
//! Save the reward ruin to an opened saved-game file.
397
* @param helper The opened saved-game file to write the ruin reward
133
400
bool save(XML_Helper* helper) const;
134
Ruin* getRuin() const {return d_ruin;}
402
//! Return the Ruin object associated with this Reward_Ruin.
403
Ruin* getRuin() const
404
{return Ruinlist::getInstance()->getObjectAt(d_ruin_pos);}
407
//! The position of the Ruin object associated with this reward.
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.
415
//FIXME: verify that the ruin's position has to be used here.
416
Vector<int> d_ruin_pos;
140
class Reward_Map: public Reward
419
//! A portion of a hidden map to reveal to a Player.
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
424
* The map has a position (from the derived Location class), and as well as a
425
* height and a width.
427
class Reward_Map: public Reward, public Location
143
Reward_Map(Location *l, Uint32 height, Uint32 width);
430
//! Default constructor.
432
* Make a new Reward_Map from the given parameters.
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.
439
Reward_Map(Vector<int> pos, std::string name,
440
Uint32 height, Uint32 width);
442
//! Loading constructor.
444
* Make a new Reward_Map by loading it from an opened saved-game file.
446
* @param helper The opened saved-game file to load the reward map
144
449
Reward_Map(XML_Helper *helper);
451
//! Copy constructor.
453
* Make a new reward map by copying it from another one.
455
* @param orig The reward map to copy from.
457
Reward_Map(const Reward_Map& orig);
462
//! Save the reward map to an opened saved-game file.
464
* @param helper The opened saved-game file to write the ruin map to.
147
466
bool save(XML_Helper* helper) const;
148
Location* getLocation() const {return d_loc;}
468
//! Get the height of the revealed portion of the game map.
149
469
Uint32 getHeight() const {return d_height;}
471
//! Get the width of the revealed portion of the game map.
150
472
Uint32 getWidth() const {return d_width;}
474
//! Return a description of a random map.
476
* @note This will produce random maps that overlap each other.
477
* @note x,y defines the top-left-most tile of the map.
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.
486
static void getRandomMap(int *x, int *y, int *width, int *height);
153
bool loadLocation(std::string tag, XML_Helper* helper);
489
//! The height of the revealed portion of the map (in tiles).
491
* @note d_height + getPos().x must not exceed the height of the game
496
//! The width of the revealed portion of the map (in tiles).
498
* @note d_width + getPos().y must not exceed the width of the game