1 // Copyright (C) 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2004 Andrea Paternesi
3 // Copyright (C) 2007, 2008 Ben Asselstine
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.
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.
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
25 #include "xmlhelper.h"
29 #include "playerlist.h"
30 #include "UniquelyIdentified.h"
32 #include "ItemProto.h"
34 //! A carryable thing that confers special properties on it's holder.
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.
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.
50 class Item: public ItemProto, public UniquelyIdentified
53 //! The xml tag of this object in a saved-game file.
54 static std::string d_tag;
56 //! Loading constructor.
57 Item(XML_Helper* helper);
60 Item(const Item& orig);
62 //! Copy constructor. make an item from a prototype.
63 Item(const ItemProto &proto);
65 //! Creates a new Item from scratch.
66 Item(std::string name, bool plantable, Player *plantable_owner);
68 static Item* createNonUniqueItem(std::string name, bool plantable,
69 Player *plantable_owner);
73 //! Emitted when an item is destroyed.
74 sigc::signal<void, Item*> sdying;
76 //! Save the item to the opened saved-game file.
77 bool save(XML_Helper* helper) const;
79 //! Return whether or not the Item is of a kind that can be vectored to.
80 bool isPlantable() const {return d_plantable;}
82 //! Set the planted status of the Item.
83 void setPlanted(bool planted) {d_planted = planted;}
85 //! Get the planted status of the Item.
86 bool getPlanted() const {return d_planted;}
88 //! Return the Player who can plant this particular Item.
89 Player *getPlantableOwner() const
90 {return Playerlist::getInstance()->getPlayer(d_plantable_owner_id);}
92 //! Return the type of this item.
93 guint32 getType() const {return d_type;};
97 //! non-default constructor to make an item with a particular id.
98 Item(std::string name, bool plantable, Player *plantable_owner,
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.
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
114 //! The Id of the Player who can plant this Item.
115 guint32 d_plantable_owner_id;
118 * When the Item is planted, the player can vector Army units to
119 * this item's position on the GameMap.
121 //! Whether or not this Item is currently planted.
124 //! The item was instantiated from the item prototype that has this id.