initial commit, lordsawar source, slightly modified
[lordsawar] / src / MapBackpack.cpp
1 //  Copyright (C) 2008, 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 #include "MapBackpack.h"
19 #include "Item.h"
20 #include "xmlhelper.h"
21
22 std::string MapBackpack::d_tag = "itemstack";
23
24 //#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<std::endl<<std::flush;}
25 #define debug(x)
26
27 MapBackpack::MapBackpack(Vector<int> pos)
28   :Backpack(), Immovable(pos), UniquelyIdentified((guint32)0)
29 {
30 }
31
32 MapBackpack::MapBackpack(const MapBackpack& object)
33   :Backpack(object), Immovable(object), UniquelyIdentified((guint32)0)
34 {
35 }
36
37 MapBackpack::MapBackpack(XML_Helper* helper)
38   :Backpack(helper), Immovable(helper), UniquelyIdentified((guint32)0)
39 {
40 }
41
42 MapBackpack::~MapBackpack()
43 {
44 }
45
46 bool MapBackpack::save(XML_Helper* helper) const
47 {
48   bool retval = true;
49
50   retval &= helper->openTag(Backpack::d_tag);
51   retval &= helper->saveData("x", getPos().x);
52   retval &= helper->saveData("y", getPos().y);
53   retval &= Backpack::saveData(helper);
54   retval &= helper->closeTag();
55
56   return retval;
57 }
58
59 Item *MapBackpack::getFirstPlantedItem()
60 {
61   for (MapBackpack::iterator it = begin(); it != end(); it++)
62     {
63       if ((*it)->getPlanted() == true)
64         return *it;
65     }
66   return NULL;
67 }
68
69 Item *MapBackpack::getPlantedItem(Player *player)
70 {
71   for (MapBackpack::iterator it = begin(); it != end(); it++)
72     {
73       if ((*it)->getPlanted() == true &&
74           (*it)->getPlantableOwner() == player)
75         return *it;
76     }
77   return NULL;
78 }