1 // Copyright (C) 2008, 2009 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include "xmlhelper.h"
26 #include "Renamable.h"
28 //! A carryable type of thing that confers special properties on it's holder.
30 * This class describes an item prototype. Items are carried by heroes in a
31 * backpack, and each item has a "kind". The item prototype is this kind.
32 * When Items are carried they give special abilities to that hero, and
33 * perhaps the stack it is included in.
34 * Items can be dropped onto the ground, and picked up from the ground.
35 * When a hero dies, all of that hero's items get dropped onto the ground.
39 class ItemProto: public Renamable
43 //! The xml tag of this object in an itemlist configuration file.
45 * @note This tag appears in the item configuration file, and in
48 static std::string d_tag;
50 // The item can confer these special properties.
53 //! Add 1 to the strength of the wearer.
55 //! Add 2 to the strength of the wearer.
57 //! Add 3 to the strength of the wearer.
59 //! Add 1 to the strength of the Stack.
60 ADD1STACK = 0x00000008,
61 //! Add 2 to the strength of the Stack.
62 ADD2STACK = 0x00000010,
63 //! Add 3 to the strength of the Stack.
64 ADD3STACK = 0x00000020,
65 //! Provides the gift of flight to the Stack.
66 FLYSTACK = 0x00000040,
67 //! Makes the stack go two times as far.
68 DOUBLEMOVESTACK = 0x00000080,
69 //! Add 2 gold to the Player's treasury per City it holds.
70 ADD2GOLDPERCITY = 0x00000100,
71 //! Add 3 gold to the Player's treasury per City it holds.
72 ADD3GOLDPERCITY = 0x00000200,
73 //! Add 4 gold to the Player's treasury per City it holds.
74 ADD4GOLDPERCITY = 0x00000400,
75 //! Add 5 gold to the Player's treasury per City it holds.
76 ADD5GOLDPERCITY = 0x00000800,
79 static guint32 bonusFlagsFromString(const std::string str);
80 static std::string bonusFlagsToString(const guint32 bonus);
82 //! Loading constructor.
83 ItemProto(XML_Helper* helper);
86 ItemProto(const ItemProto& orig);
88 //! Creates a new Item Prototype from scratch.
89 ItemProto(std::string name, guint32 id);
94 //! Save the item to the opened saved-game file.
95 bool save(XML_Helper* helper) const;
97 //! Returns whether or not the Item has a particular special bonus.
98 guint32 getBonus() const {return d_bonus;};
100 //! Returns whether or not the Item has a particular special bonus.
101 bool getBonus(ItemProto::Bonus bonus) const;
103 //! Add a bonus to the Item.
104 void addBonus(ItemProto::Bonus bonus);
106 //! Remove a bonus from the Item.
107 void removeBonus(ItemProto::Bonus bonus);
109 //! Return the Id of the Item prototype.
110 guint32 getTypeId() const {return d_type_id;};
112 //! Set the id of the item prototype.
113 void setTypeId(guint32 id) {d_type_id = id;};
115 //! Return some text describing the item's special abilities.
116 std::string getBonusDescription() const;
119 //! The item's bonus.
121 * This value is a bitwise OR-ing of the values in ItemProto::Bonus.
128 //! The Id of the Item.
130 * This value is a unique Id among all other game objects.
131 * This value does not change during gameplay.
135 static std::string bonusFlagToString(ItemProto::Bonus type);
136 static ItemProto::Bonus bonusFlagFromString(std::string str);
141 #endif //ITEM_PROTOTYPE_H