1 // Copyright (C) 2004, 2005 Ulf Lorenz
2 // Copyright (C) 2007, 2008 Ben Asselstine
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <sigc++/trackable.h>
25 #include "ItemProto.h"
27 //! A list of Item objects.
29 * The Itemlist holds all item templates (i.e. types of items) together.
31 * It is implemented as a singleton. Upon creation, it reads the item
32 * description file and initialises an internal list.
34 * For easier access, the Itemlist is derived from map. Given an item index,
35 * you can get the item belonging to the index by the []-operator using the
36 * item index as index.
38 class Itemlist : public std::map<guint32, ItemProto*>, public sigc::trackable
42 //! The xml tag of this object.
44 * @note This tag appears in the items configuration file, or in a
47 static std::string d_tag;
49 //! Returns the singleton instance.
50 static Itemlist* getInstance();
52 //! Reads in the itemlist from a file
53 static Itemlist* getInstance(XML_Helper *helper);
55 //! Creates a new singleton instance. Deletes an existing one.
56 //This list of items comes from loading the items.xml file.
57 static void createStandardInstance();
59 //! Explicitly deletes the singleton instance.
60 static void deleteInstance();
62 //! Save the item data. See XML_Helper for details.
63 bool save(XML_Helper* helper) const;
65 void remove(ItemProto *item);
68 //! Default constructor.
70 //! Loading constructor.
71 Itemlist(XML_Helper* helper);
77 //! Callback for loading an Item from an opened saved-game file.
78 bool loadItemProto(std::string tag, XML_Helper* helper);
80 //! Erases an Item from the list and frees the Item too.
81 void flErase(iterator it);
83 //! Clears the itemlist of all it's items.
86 static Itemlist* d_instance;