initial commit, lordsawar source, slightly modified
[lordsawar] / src / citysetlist.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 CITYSETLIST_H
19 #define CITYSETLIST_H
20
21 #include <string>
22 #include <map>
23 #include <vector>
24 #include <sigc++/trackable.h>
25
26 #include "xmlhelper.h"
27 #include "cityset.h"
28
29
30 //! A list of all Cityset objects available to the game.
31 /**
32  * This class contains a list of all Cityset objects available to the game. 
33  * Since several classes access this class, it is implemented as a singleton.
34  *
35  * Cityset objects are usually referenced by the name of the subdirectory
36  * in which they reside on disk (inside the citysets/ directory).
37  */
38 class Citysetlist : public std::list<Cityset*>, public sigc::trackable
39 {
40     public:
41         //! Return the singleton instance of this class.
42         static Citysetlist* getInstance();
43
44         //! Explicitly delete the singleton instance of this class.
45         static void deleteInstance();
46
47         //! Returns the names of all citysets available to the game.
48         std::list<std::string> getNames();
49
50         //! Returns the names of citysets that have the given tile size.
51         std::list<std::string> getNames(guint32 tilesize);
52
53         //! Returns the different tilesizes present in the citysetlist.
54         void getSizes(std::list<guint32> &sizes);
55
56         //! Return the name of the subdirectory for a given cityset.
57         /** 
58          * @param name          The name of the cityset to get the subdir of.
59          * @param tilesize      The size of the cityset to get the subdir of.
60          *
61          * @return The name of the directory that holds the cityset.  See 
62          *         Cityset::d_dir for more information about the nature of 
63          *         the return value.
64          */
65         std::string getCitysetDir(std::string name, guint32 tilesize);
66
67         //! Return the Cityset object by the name of the subdir.
68         /**
69          * @param dir  The directory where the Cityset resides on disk.
70          *             This value does not contain any slashes, and is
71          *             presumed to be found inside the citysets/ directory.
72          */
73         Cityset *getCityset(std::string dir);
74
75         //! Return the Cityset object by the id.
76         /**
77          * @param id   A unique numeric identifier that identifies the cityset
78          *             among all tilesets in the citysetlist.
79          */
80         Cityset *getCityset(guint32 id);
81
82         void add(Cityset *cityset);
83         void instantiateImages();
84         void uninstantiateImages();
85
86         bool addToPersonalCollection(Cityset *cityset, std::string &new_subdir, guint32 &new_id);
87
88         static int getNextAvailableId(int after = 0);
89     private:
90         //! Default constructor.  Loads all citysets it can find.
91         /**
92          * The citysets/ directory is scanned for Cityset directories.
93          */
94         Citysetlist();
95         
96         //! Destructor.
97         ~Citysetlist();
98
99         //! Loads a specific Cityset.
100         /**
101          * Load the Cityset from an cityset configuration file and add it to 
102          * this list of Cityset objects.
103          *
104          * @param name  The name of the subdirectory that the Cityset resides 
105          *              in.
106          *
107          * @return the Cityset.  NULL otherwise.
108          */
109         Cityset* loadCityset (std::string name);
110         void loadCitysets (std::list<std::string> name);
111         
112         typedef std::map<std::string, std::string> DirMap;
113         typedef std::map<std::string, Cityset*> CitysetMap;
114         typedef std::map<guint32, Cityset*> CitysetIdMap;
115
116         //! A map that provides a subdirectory when supplying a Cityset name.
117         /**
118          * the key for this map is actually the city name, a space, and then
119          * the tile size.  e.g. "Default 80".
120          */
121         DirMap d_dirs;
122
123         //! A map that provides a Cityset when supplying a subdirectory name.
124         CitysetMap d_citysets;
125
126         //! A map that provides a Cityset when supplying a cityset id.
127         CitysetIdMap d_citysetids;
128
129         //! A static pointer for the singleton instance.
130         static Citysetlist* s_instance;
131 };
132
133 #endif // CITYSETLIST_H
134