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