initial commit, lordsawar source, slightly modified
[lordsawar] / src / Item.h
1 // Copyright (C) 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2004 Andrea Paternesi
3 // Copyright (C) 2007, 2008 Ben Asselstine
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Library General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
18 //  02110-1301, USA.
19
20 #ifndef ITEM_H
21 #define ITEM_H
22
23 #include <string>
24 #include <gtkmm.h>
25 #include "xmlhelper.h"
26 #include "army.h"
27
28 #include "player.h"
29 #include "playerlist.h"
30 #include "UniquelyIdentified.h"
31
32 #include "ItemProto.h"
33
34 //! A carryable thing that confers special properties on it's holder.
35 /** 
36  * This class describes an item.  Items are carried by heroes in a backpack.
37  * When Items are carried they give special abilities to that hero, and 
38  * perhaps the stack it is included in.
39  * Items can be dropped onto the ground, and picked up from the ground.
40  * When a hero dies, all of that hero's items get dropped onto the ground.
41  *
42  * There are "plantable items", that a hero can stick into the ground.  This
43  * gives the ability to vector Army units to that location.  Every player
44  * gets a plantable item, and the item is branded to be usable only by the
45  * player that it belongs to.
46  * 
47  */
48
49
50 class Item: public ItemProto, public UniquelyIdentified
51 {
52     public:
53         //! The xml tag of this object in a saved-game file.
54         static std::string d_tag; 
55
56         //! Loading constructor.
57         Item(XML_Helper* helper);
58
59         //! Copy constructor.
60         Item(const Item& orig);
61
62         //! Copy constructor.  make an item from a prototype.
63         Item(const ItemProto &proto);
64
65         //! Creates a new Item from scratch.
66         Item(std::string name, bool plantable, Player *plantable_owner);
67
68         static Item* createNonUniqueItem(std::string name, bool plantable,
69                                          Player *plantable_owner);
70         //! Destructor.
71         ~Item();
72         
73         //! Emitted when an item is destroyed.
74         sigc::signal<void, Item*> sdying;
75
76         //! Save the item to the opened saved-game file.
77         bool save(XML_Helper* helper) const;
78
79         //! Return whether or not the Item is of a kind that can be vectored to.
80         bool isPlantable() const {return d_plantable;}
81
82         //! Set the planted status of the Item.
83         void setPlanted(bool planted) {d_planted = planted;}
84
85         //! Get the planted status of the Item.
86         bool getPlanted() const {return d_planted;}
87
88         //! Return the Player who can plant this particular Item.
89         Player *getPlantableOwner() const 
90           {return Playerlist::getInstance()->getPlayer(d_plantable_owner_id);}
91
92         //! Return the type of this item.
93         guint32 getType() const {return d_type;};
94
95     private:
96
97         //! non-default constructor to make an item with a particular id.
98         Item(std::string name, bool plantable, Player *plantable_owner,
99              guint32 id);
100
101         /**
102          * This value indicates if the type of this Item can potentially be
103          * planted into the ground on the GameMap, and subsequently have 
104          * Army units vectored to that position.
105          */
106         bool d_plantable;
107
108         /**
109          * If the Item is plantable, this value is used to determine if the
110          * correct Player is attempting to plant the Item into the ground.
111          * For example, the red player cannot plant the flag belonging to the
112          * yellow player.
113          */
114         //! The Id of the Player who can plant this Item.
115         guint32 d_plantable_owner_id;
116
117         /**
118          * When the Item is planted, the player can vector Army units to 
119          * this item's position on the GameMap.
120          */
121         //! Whether or not this Item is currently planted.
122         bool d_planted;
123
124         //! The item was instantiated from the item prototype that has this id.
125         guint32 d_type;
126 };
127
128 #endif //ITEM_H