initial commit, lordsawar source, slightly modified
[lordsawar] / src / Backpack.h
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 #ifndef BACKPACK_H
19 #define BACKPACK_H
20
21 #include <list>
22 #include <string>
23 #include <gtkmm.h>
24
25 class XML_Helper;
26 class Item;
27 class Player;
28
29 //! An object that carries items.
30 /**
31  * Heroes have backpack objects that carry items.
32  */
33 class Backpack: public std::list<Item*>
34 {
35     public:
36         //! The xml tag of this object in a saved-game file.
37         static std::string d_tag; 
38
39         //! Standard constructor: create a backpack.
40         /**
41          */
42         Backpack();
43
44         //! Loading constructor.
45         /**
46          * Load the backpack from a file.
47          * Backpacks are stored in the saved-game file at:
48          * lordsawar.playerlist.player.stacklist.stack.hero.backpack.
49          *
50          * @param helper  The opened saved-game file to load the backpack from.
51          */
52         Backpack(XML_Helper* helper);
53
54         //! Copy constructor.
55         Backpack(const Backpack&);
56
57         //! Destructor.
58         ~Backpack();
59
60         //! Save a backpack.
61         /**
62          * @param helper  The opened saved-game file to save the backpack to.
63          *
64          * @return True if saving went well, false otherwise.
65          */
66         bool save(XML_Helper* helper) const;
67
68         //! Save the contents of a backpack.
69         /**
70          * @param helper  The opened saved-game file to save the contents of
71          *                the backpack to.
72          *
73          * @return True if saving went well, false otherwise.
74          */
75         bool saveData(XML_Helper* helper) const;
76
77         //! Remove an Item from the backpack of the hero.
78         /**
79          * Scan the hero's d_backpack for the Item, and remove it if it is
80          * found.
81          *
82          * @note This method removes the Item from the d_backpack, but does
83          *       not destroy the Item.
84          *
85          * @param item   The Item to look for.
86          *
87          * @return True if the Item was found and removed.
88          */
89         bool removeFromBackpack(Item* item);
90
91         //! Remove all items from the backpack.
92         void removeAllFromBackpack();
93
94         //! Add all of the items from the given backpack.
95         void add(Backpack *backpack);
96
97         //! Add an Item to the bottom of the hero's backpack. 
98         bool addToBackpack(Item* item);
99
100         //! Add an Item to the backpack of the Hero.
101         /**
102          * @param item      The Item to add to the d_backpack.
103          * @param position  How deep into the backpack the Item is stored.
104          *                  Subsequent Items get pushed down to make room.
105          *                  This value starts at 0.
106          *
107          * This method is usually used to add an Item to the top of the
108          * hero's backpack (e.g. position == 0).
109          *
110          * @return Always returns true.
111          */
112         bool addToBackpack(Item* item, int position);
113
114         //! Tally up the strength bonuses inferred by items in the backpack.
115         guint32 countStrengthBonuses();
116
117         //! Tally up the gold bonuses inferred by the items in the backpack.
118         guint32 countGoldBonuses();
119
120         //! Tally the stack strength bonuses inferred by items in the backpack.
121         guint32 countStackStrengthBonuses();
122
123         //! Count the number of items that double movement in the backpack.
124         guint32 countMovementDoublers();
125
126         //! Return the first plantable item that can be planted by player.
127         Item *getPlantableItem(Player *player);
128
129         //! Tally the plantable items in the backpack.
130         guint32 countPlantableItems();
131
132         //! Return the item with the given id.
133         Item *getItemById(guint32 id);
134
135         //! Tally the items that let stacks fly.
136         guint32 countStackFlightGivers();
137     private:
138
139         bool loadItem(std::string tag, XML_Helper* helper);
140 };
141
142 #endif
143
144 // End of file