initial commit, lordsawar source, slightly modified
[lordsawar] / src / ItemProto.h
1 // Copyright (C) 2008, 2009 Ben Asselstine
2 //
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.
7 //
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.
12 //
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 
16 //  02110-1301, USA.
17
18 #ifndef ITEM_PROTO_H
19 #define ITEM_PROTO_H
20
21 #include <string>
22 #include <gtkmm.h>
23 #include "xmlhelper.h"
24 #include "army.h"
25
26 #include "Renamable.h"
27
28 //! A carryable type of thing that confers special properties on it's holder.
29 /** 
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.
36  * 
37  */
38
39 class ItemProto: public Renamable
40 {
41     public:
42
43         //! The xml tag of this object in an itemlist configuration file.
44         /**
45          * @note This tag appears in the item configuration file, and in
46          * saved-game files.
47          */
48         static std::string d_tag;
49
50         // The item can confer these special properties.
51         enum Bonus {
52
53           //! Add 1 to the strength of the wearer.
54           ADD1STR         = 0x00000001,
55           //! Add 2 to the strength of the wearer.
56           ADD2STR         = 0x00000002,
57           //! Add 3 to the strength of the wearer.
58           ADD3STR         = 0x00000004,
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, 
77
78         };
79         static guint32 bonusFlagsFromString(const std::string str);
80         static std::string bonusFlagsToString(const guint32 bonus);
81         
82         //! Loading constructor.
83         ItemProto(XML_Helper* helper);
84
85         //! Copy constructor.
86         ItemProto(const ItemProto& orig);
87
88         //! Creates a new Item Prototype from scratch.
89         ItemProto(std::string name, guint32 id);
90
91         //! Destructor.
92         virtual ~ItemProto();
93         
94         //! Save the item to the opened saved-game file.
95         bool save(XML_Helper* helper) const;
96
97         //! Returns whether or not the Item has a particular special bonus.
98         guint32 getBonus() const {return d_bonus;};
99
100         //! Returns whether or not the Item has a particular special bonus.
101         bool getBonus(ItemProto::Bonus bonus) const;
102
103         //! Add a bonus to the Item.
104         void addBonus(ItemProto::Bonus bonus);
105
106         //! Remove a bonus from the Item.
107         void removeBonus(ItemProto::Bonus bonus);
108         
109         //! Return the Id of the Item prototype.
110         guint32 getTypeId() const {return d_type_id;};
111
112         //! Set the id of the item prototype.
113         void setTypeId(guint32 id) {d_type_id = id;};
114
115         //! Return some text describing the item's special abilities.
116         std::string getBonusDescription() const;
117
118     protected:
119         //! The item's bonus.
120         /**
121          * This value is a bitwise OR-ing of the values in ItemProto::Bonus.
122          */
123         guint32 d_bonus;
124         
125
126     private:
127
128         //! The Id of the Item.
129         /**
130          * This value is a unique Id among all other game objects.
131          * This value does not change during gameplay.
132          */
133         guint32 d_type_id;
134
135         static std::string bonusFlagToString(ItemProto::Bonus type);
136         static ItemProto::Bonus bonusFlagFromString(std::string str);
137
138
139 };
140
141 #endif //ITEM_PROTOTYPE_H