initial commit, lordsawar source, slightly modified
[lordsawar] / src / rewardlist.h
1 //  Copyright (C) 2007, 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 REWARDLIST_H
19 #define REWARDLIST_H
20
21 #include <list>
22 #include <sigc++/trackable.h>
23 #include <gtkmm.h>
24 #include "reward.h"
25
26 class XML_Helper;
27
28 /** List of unique rewards in the game.
29   * Some rewards like gold, and allies can be created whenever they're needed,
30   * but other rewards are unique in nature.  This list is for those unique
31   * rewards -- namely item rewards, and hidden ruins.
32   *
33   */
34
35 class Rewardlist : public std::list<Reward*>, public sigc::trackable
36 {
37     public:
38         //! The xml tag of this object in a saved-game file.
39         static std::string d_tag; 
40
41
42         // Methods that operate on the class data and modify the class.
43
44         //! deletes a reward from the list
45         void deleteReward(Reward* s);
46
47         //! remove one item reward from the list and return it
48         Reward *popRandomItemReward();
49
50         //! remove one ruin reward from the list and return it
51         Reward *popRandomRuinReward();
52
53         //! remove one ruin reward from the list and return it
54         Reward *popRandomMapReward();
55
56         //! Behaves like std::list::clear(), but frees pointers as well
57         void flClear();
58
59         //! Behaves like std::list::erase(), but frees pointers as well
60         iterator flErase(iterator object);
61
62         //! Behaves like std::list::remove(), but frees pointers as well
63         bool flRemove(Reward* object);
64
65
66         // Methods that operate on the class data and do not modify the class.
67
68         //! Save the data. See XML_Helper for details
69         bool save(XML_Helper* helper) const;
70
71
72         // Static Methods
73
74         //! Returns the singleton instance. Creates a new one if required.
75         static Rewardlist* getInstance();
76
77         //! Loads the singleton instance with a savegame.
78         static Rewardlist* getInstance(XML_Helper* helper);
79
80         //! Explicitely deletes the singleton instance.
81         static void deleteInstance();
82         
83     protected:    
84
85         // Constructor.
86         Rewardlist();
87
88         //! Copy constructor.
89         Rewardlist(Rewardlist *rewardlist);
90
91         //! Loading constructor.
92         Rewardlist(XML_Helper* helper);
93
94         //! Destructor.
95         ~Rewardlist();
96
97     private:
98         //! Callback function for loading rewards.
99         bool load(std::string tag, XML_Helper* helper);
100
101         //! Return a random reward from the list of the given type.
102         Reward *popRandomReward(Reward::Type type);
103
104         // DATA
105
106         static Rewardlist* s_instance;
107 };
108
109 #endif // REWARDLIST_H
110
111 // End of file