23
29
#include "player.h"
24
30
#include "playerlist.h"
26
/** This class describes an item.
28
* Items are defined by three values. They have a type, which determines where
29
* they may be worn (Weapon, Shield, Accessoire etc.), a bonus which determines
30
* what goods they bring to their wielder (strength, defense, army bonus etc.)
31
* and a value which tells how much the stat is raised or what boni the user
34
* @note Items occur on two places. First, there is an itemlist which holds
35
* templates of all available items. They can be identified by an id of 0.
36
* Second, there are items in the actual game, which are gained by cloning an
37
* item from the itemlist.
39
* @note Items should have not more than three boni. If they give an army or
40
* movement bonus, just count each of the boni as one bonus.
31
#include "Renamable.h"
33
//! A carryable thing that confers special properties on it's holder.
35
* This class describes an item. Items are carried by heroes in a backpack.
36
* When Items are carried they give special abilities to that hero, and
37
* perhaps the stack it is included in.
38
* Items can be dropped onto the ground, and picked up from the ground.
39
* When a hero dies, all of that hero's items get dropped onto the ground.
41
* There are "plantable items", that a hero can stick into the ground. This
42
* gives the ability to vector Army units to that location. Every player
43
* gets a plantable item, and the item is branded to be usable only by the
44
* player that it belongs to.
48
class Item: public Renamable
52
// The item can confer these special properties.
49
ADD1STR = 0x00000001, //+1 battle
50
ADD2STR = 0x00000002, //+2 battle
51
ADD3STR = 0x00000004, //+3 battle
52
ADD1STACK = 0x00000008, //+1 command
53
ADD2STACK = 0x00000010, //+2 command
54
ADD3STACK = 0x00000020, //+3 command
55
FLYSTACK = 0x00000040, // add flight to stack
56
DOUBLEMOVESTACK = 0x00000080, // double movement
57
ADD2GOLDPERCITY = 0x00000100, // +2 gold per city
58
ADD3GOLDPERCITY = 0x00000200, // +3 gold per city
59
ADD4GOLDPERCITY = 0x00000400, // +4 gold per city
60
ADD5GOLDPERCITY = 0x00000800, // +5 gold per city
55
//! Add 1 to the strength of the wearer.
57
//! Add 2 to the strength of the wearer.
59
//! Add 3 to the strength of the wearer.
61
//! Add 1 to the strength of the Stack.
62
ADD1STACK = 0x00000008,
63
//! Add 2 to the strength of the Stack.
64
ADD2STACK = 0x00000010,
65
//! Add 3 to the strength of the Stack.
66
ADD3STACK = 0x00000020,
67
//! Provides the gift of flight to the Stack.
68
FLYSTACK = 0x00000040,
69
//! Makes the stack go two times as far.
70
DOUBLEMOVESTACK = 0x00000080,
71
//! Add 2 gold to the Player's treasury per City it holds.
72
ADD2GOLDPERCITY = 0x00000100,
73
//! Add 3 gold to the Player's treasury per City it holds.
74
ADD3GOLDPERCITY = 0x00000200,
75
//! Add 4 gold to the Player's treasury per City it holds.
76
ADD4GOLDPERCITY = 0x00000400,
77
//! Add 5 gold to the Player's treasury per City it holds.
78
ADD5GOLDPERCITY = 0x00000800,
64
/** There are only three useful constructors. This is the loading
65
* constructor which loads an item description from a savegame or
66
* from an item description file
82
//! Loading constructor.
68
83
Item(XML_Helper* helper);
70
/** This constructor clones an item from a template for actual use in
73
86
Item(const Item& orig);
75
/** This constructor creates an item for actual use in the game.
76
* No template is used.
88
//! Creates a new Item from scratch.
78
89
Item(std::string name, bool plantable, Player *plantable_owner);
80
//! In opposition to other classes, item actually needs its destructor.
84
//! Saves the item data
94
//! Save the item to the opened saved-game file.
85
95
bool save(XML_Helper* helper) const;
87
//! Returns whether the item has a special bonus
97
//! Returns whether or not the Item has a particular special bonus.
88
98
bool getBonus(Item::Bonus bonus) const;
90
//! Add a bonus to the item
91
void setBonus(Item::Bonus bonus);
100
//! Add a bonus to the Item.
101
void addBonus(Item::Bonus bonus);
103
//! Remove a bonus from the Item.
104
void removeBonus(Item::Bonus bonus);
93
//! Return the name of the item
94
std::string getName() const {return __(d_name);}
96
//! Return the id of the item. 0 means the item is a template.
106
//! Return the Id of the Item. 0 means the item is a prototype.
97
107
Uint32 getId() const {return d_id;}
99
//! Return whether or not the item is plantable and able to be
109
//! Return whether or not the Item is of a kind that can be vectored to.
101
110
bool isPlantable() const {return d_plantable;}
103
//!Set the item as planted or not.
112
//! Set the planted status of the Item.
104
113
void setPlanted(bool planted) {d_planted = planted;}
106
//!Set the item as planted or not.
115
//! Get the planted status of the Item.
107
116
bool getPlanted() const {return d_planted;}
109
//! Return the player that can plant this item.
118
//! Return the Player who can plant this particular Item.
110
119
Player *getPlantableOwner() const
111
120
{return Playerlist::getInstance()->getPlayer(d_plantable_owner_id);}
113
//! Return some text describing the item's abilities
114
std::string getBonusDescription();
122
//! Return some text describing the item's special abilities.
123
std::string getBonusDescription() const;
126
//! The item's bonus.
128
* This value is a bitwise OR-ing of the valuesi in Item::Bonus.
132
//! The Id of the Item.
134
* This value is a unique Id among all other game objects.
135
* This value does not change during gameplay.
140
* This value indicates if the type of this Item can potentially be
141
* planted into the ground on the GameMap, and subsequently have
142
* Army units vectored to that position.
121
144
bool d_plantable;
147
* If the Item is plantable, this value is used to determine if the
148
* correct Player is attempting to plant the Item into the ground.
149
* For example, the red player cannot plant the flag belonging to the
152
//! The Id of the Player who can plant this Item.
122
153
Uint32 d_plantable_owner_id;
156
* When the Item is planted, the player can vector Army units to
157
* this item's position on the GameMap.
159
//! Whether or not this Item is currently planted.