1 // Copyright (C) 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2004 Andrea Paternesi
3 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 // Copyright (C) 2008 Ole Laursen
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Library General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "ItemProto.h"
26 #include "playerlist.h"
27 #include "ucompose.hpp"
29 std::string Item::d_tag = "item";
32 Item::Item(XML_Helper* helper)
33 : ItemProto(helper), UniquelyIdentified(helper)
36 helper->getData(d_plantable, "plantable");
39 helper->getData(d_plantable_owner_id, "plantable_owner");
40 helper->getData(d_planted, "planted");
44 d_plantable_owner_id = MAX_PLAYERS;
48 helper->getData(d_type, "type");
52 Item::Item(std::string name, bool plantable, Player *plantable_owner)
53 : ItemProto(name, 0), UniquelyIdentified()
57 d_plantable = plantable;
59 d_plantable_owner_id = plantable_owner->getId();
61 d_plantable_owner_id = MAX_PLAYERS;
63 //std::cerr << "item created with id " << d_id << std::endl;
66 Item::Item(std::string name, bool plantable, Player *plantable_owner, guint32 id)
67 : ItemProto(name, 0), UniquelyIdentified(id)
71 d_plantable = plantable;
73 d_plantable_owner_id = plantable_owner->getId();
75 d_plantable_owner_id = MAX_PLAYERS;
77 //std::cerr << "item created with id " << d_id << std::endl;
80 Item::Item(const Item& orig)
81 :ItemProto(orig), UniquelyIdentified(orig),
82 d_plantable(orig.d_plantable),
83 d_plantable_owner_id(orig.d_plantable_owner_id), d_planted(orig.d_planted),
88 Item::Item(const ItemProto &proto)
89 :ItemProto(proto), UniquelyIdentified()
91 d_type = proto.getTypeId();
93 d_plantable_owner_id = MAX_PLAYERS;
103 bool Item::save(XML_Helper* helper) const
107 // A template is never saved, so we assume this class is a real-life item
108 retval &= helper->openTag(Item::d_tag);
109 retval &= helper->saveData("name", getName(false));
110 retval &= helper->saveData("plantable", d_plantable);
113 retval &= helper->saveData("plantable_owner", d_plantable_owner_id);
114 retval &= helper->saveData("planted", d_planted);
116 retval &= helper->saveData("id", d_id);
117 retval &= helper->saveData("type", d_type);
119 std::string bonus_str = ItemProto::bonusFlagsToString(d_bonus);
120 retval &= helper->saveData("bonus", bonus_str);
122 retval &= helper->closeTag();
127 Item* Item::createNonUniqueItem(std::string name, bool plantable,
128 Player *plantable_owner)
130 return new Item(name, plantable, plantable_owner, 0);