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
24 #include <sigc++/trackable.h>
26 #include "xmlhelper.h"
30 //! A list of all Cityset objects available to the game.
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.
35 * Cityset objects are usually referenced by the name of the subdirectory
36 * in which they reside on disk (inside the citysets/ directory).
38 class Citysetlist : public std::list<Cityset*>, public sigc::trackable
41 //! Return the singleton instance of this class.
42 static Citysetlist* getInstance();
44 //! Explicitly delete the singleton instance of this class.
45 static void deleteInstance();
47 //! Returns the names of all citysets available to the game.
48 std::list<std::string> getNames();
50 //! Returns the names of citysets that have the given tile size.
51 std::list<std::string> getNames(guint32 tilesize);
53 //! Returns the different tilesizes present in the citysetlist.
54 void getSizes(std::list<guint32> &sizes);
56 //! Return the name of the subdirectory for a given cityset.
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.
61 * @return The name of the directory that holds the cityset. See
62 * Cityset::d_dir for more information about the nature of
65 std::string getCitysetDir(std::string name, guint32 tilesize);
67 //! Return the Cityset object by the name of the subdir.
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.
73 Cityset *getCityset(std::string dir);
75 //! Return the Cityset object by the id.
77 * @param id A unique numeric identifier that identifies the cityset
78 * among all tilesets in the citysetlist.
80 Cityset *getCityset(guint32 id);
82 void add(Cityset *cityset);
83 void instantiateImages();
84 void uninstantiateImages();
86 bool addToPersonalCollection(Cityset *cityset, std::string &new_subdir, guint32 &new_id);
88 static int getNextAvailableId(int after = 0);
90 //! Default constructor. Loads all citysets it can find.
92 * The citysets/ directory is scanned for Cityset directories.
99 //! Loads a specific Cityset.
101 * Load the Cityset from an cityset configuration file and add it to
102 * this list of Cityset objects.
104 * @param name The name of the subdirectory that the Cityset resides
107 * @return the Cityset. NULL otherwise.
109 Cityset* loadCityset (std::string name);
110 void loadCitysets (std::list<std::string> name);
112 typedef std::map<std::string, std::string> DirMap;
113 typedef std::map<std::string, Cityset*> CitysetMap;
114 typedef std::map<guint32, Cityset*> CitysetIdMap;
116 //! A map that provides a subdirectory when supplying a Cityset name.
118 * the key for this map is actually the city name, a space, and then
119 * the tile size. e.g. "Default 80".
123 //! A map that provides a Cityset when supplying a subdirectory name.
124 CitysetMap d_citysets;
126 //! A map that provides a Cityset when supplying a cityset id.
127 CitysetIdMap d_citysetids;
129 //! A static pointer for the singleton instance.
130 static Citysetlist* s_instance;
133 #endif // CITYSETLIST_H