1 // Copyright (C) 2008 Ben Asselstine
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.
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.
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
29 //! An object that carries items.
31 * Heroes have backpack objects that carry items.
33 class Backpack: public std::list<Item*>
36 //! The xml tag of this object in a saved-game file.
37 static std::string d_tag;
39 //! Standard constructor: create a backpack.
44 //! Loading constructor.
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.
50 * @param helper The opened saved-game file to load the backpack from.
52 Backpack(XML_Helper* helper);
55 Backpack(const Backpack&);
62 * @param helper The opened saved-game file to save the backpack to.
64 * @return True if saving went well, false otherwise.
66 bool save(XML_Helper* helper) const;
68 //! Save the contents of a backpack.
70 * @param helper The opened saved-game file to save the contents of
73 * @return True if saving went well, false otherwise.
75 bool saveData(XML_Helper* helper) const;
77 //! Remove an Item from the backpack of the hero.
79 * Scan the hero's d_backpack for the Item, and remove it if it is
82 * @note This method removes the Item from the d_backpack, but does
83 * not destroy the Item.
85 * @param item The Item to look for.
87 * @return True if the Item was found and removed.
89 bool removeFromBackpack(Item* item);
91 //! Remove all items from the backpack.
92 void removeAllFromBackpack();
94 //! Add all of the items from the given backpack.
95 void add(Backpack *backpack);
97 //! Add an Item to the bottom of the hero's backpack.
98 bool addToBackpack(Item* item);
100 //! Add an Item to the backpack of the Hero.
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.
107 * This method is usually used to add an Item to the top of the
108 * hero's backpack (e.g. position == 0).
110 * @return Always returns true.
112 bool addToBackpack(Item* item, int position);
114 //! Tally up the strength bonuses inferred by items in the backpack.
115 guint32 countStrengthBonuses();
117 //! Tally up the gold bonuses inferred by the items in the backpack.
118 guint32 countGoldBonuses();
120 //! Tally the stack strength bonuses inferred by items in the backpack.
121 guint32 countStackStrengthBonuses();
123 //! Count the number of items that double movement in the backpack.
124 guint32 countMovementDoublers();
126 //! Return the first plantable item that can be planted by player.
127 Item *getPlantableItem(Player *player);
129 //! Tally the plantable items in the backpack.
130 guint32 countPlantableItems();
132 //! Return the item with the given id.
133 Item *getItemById(guint32 id);
135 //! Tally the items that let stacks fly.
136 guint32 countStackFlightGivers();
139 bool loadItem(std::string tag, XML_Helper* helper);