1 // Copyright (C) 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2003, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Library General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #include <sigc++/trackable.h>
29 #include "xmlhelper.h"
30 #include "armyproto.h"
35 //! A list of all Armyset objects available to the game.
37 * This class contains a list of all armyset objects available to the game.
38 * Each armyset has a size, a name and a list of armies. The armysetlist
39 * shields all these from the rest of the program. Armysets are most often
40 * referenced by their id.
42 * The Armysetlist is populated with Armyset objects that are loaded from the
45 * Since several classes access this class, it is implemented as a singleton.
48 class Armysetlist : public std::list<Armyset*>, public sigc::trackable
51 //! Return the singleton instance of this class.
52 static Armysetlist* getInstance();
54 //! Explicitly delete the singleton instance of this class
55 static void deleteInstance();
57 //! Returns an army prototype from a given armyset.
59 * @param id The Id of the armyset.
60 * @param index The index of the army within the set.
61 * This value becomes the Army object's type.
63 * @return The requested army or 0 on error.
65 ArmyProto* getArmy(guint32 id, guint32 index) const;
67 //! Returns an army prototype of a scout from a given armyset.
69 * @param id The Id of the armyset.
71 * @return The requested scout or 0 on error.
73 ArmyProto* getScout(guint32 id) const;
75 //! Get the unshaded ship image for the given Armyset.
76 PixMask* getShipPic (guint32 id);
78 //! Get the ship mask picture for the given Armyset.
79 PixMask* getShipMask (guint32 id);
81 //! Get the unshaded planted standard picture for the given Armyset.
82 PixMask* getStandardPic (guint32 id);
84 //! Get the bag of oitems picture for the given Armyset.
85 PixMask* getBagPic (guint32 id);
87 //! Get the planted standard mask for the given Armyset.
88 PixMask* getStandardMask (guint32 id);
89 guint32 getTileSize(guint32 id);
91 //! Returns the size of a specific armyset.
93 * @param id The id of the armyset to get the size of.
95 * @return The number of Army prototype objects in the Armyset.
98 guint32 getSize(guint32 id) const;
100 //! Return the name of a given armyset.
102 * @param id The id of the armyset to get the name of.
104 * @return The name of the Armyset or an empty string on error.
106 std::string getName(guint32 id) const;
108 //! Returns the different tilesizes present in the armysetlist.
109 void getSizes(std::list<guint32> &sizes);
111 //! Returns the names of all Armyset objects available to the game.
112 std::list<std::string> getNames();
114 //! Returns the names of armysets that have the given tile size.
115 std::list<std::string> getNames(guint32 tilesize);
117 /** Returns the Id of a specific armyset by name
119 * @param armyset the name of the armyset
120 * @param tilesize the height and width of tiles in the armyset.
122 * @return the id of the armyset (0 on error)
124 guint32 getArmysetId(std::string armyset, guint32 tilesize);
125 Armyset *getArmyset(guint32 id);
127 //! Return the Armyset object by the name of the subdir.
129 * @param dir The directory where the Armyset resides on disk.
130 * This value does not contain any slashes, and is
131 * presumed to be found inside the army/ directory.
133 Armyset *getArmyset(std::string dir);
135 //! Return the name of the subdirectory for a given armyset.
137 * @param name The name of the Armyset to get the subdir of.
138 * @param tilesize The size of the Armyset to get the subdir of.
140 * @return The name of the directory that holds the cityset. See
141 * Armyset::d_dir for more information about the nature of
144 std::string getArmysetDir(std::string name, guint32 tilesize);
147 //! Return an unused armyset number.
148 static int getNextAvailableId(int after = 0);
150 void add(Armyset *arymset);
152 void instantiateImages();
153 void uninstantiateImages();
156 Armyset *import(Tar_Helper *t, std::string f, bool &broken);
158 bool addToPersonalCollection(Armyset *armyset, std::string &new_subdir, guint32 &new_id);
159 //! Default Constructor. Loads all armyset objects it can find.
161 * The army/ directory is scanned for armyset directories.
168 //! Loads a specific armyset.
170 * Load the armyset from an armyset configuration file and add it to
171 * this list of armysets.
173 * @param name The subdirectory name that the Armyset resides in.
175 * @return the Armyset. NULL otherwise.
177 Armyset* loadArmyset(std::string name);
179 //! Loads a bunch of armysets.
181 * Load a list of armysets from the system armyset directory, or the
182 * user's personal collection.
184 void loadArmysets(std::list<std::string> armysets);
186 typedef std::map<guint32, std::vector<ArmyProto*> > ArmyPrototypeMap;
187 typedef std::map<guint32, std::string> NameMap;
188 typedef std::map<std::string, guint32> IdMap;
189 typedef std::map<std::string, Armyset*> ArmysetMap;
190 typedef std::map<guint32, Armyset*> ArmysetIdMap;
192 //! A map that provides Army objects by their index.
193 ArmyPrototypeMap d_armies;
195 //! A map that provides Armyset::d_name by supplying a Armyset::d_id.
198 //! A map that provides Armyset:d_id by supplying a Armyset::d_name.
201 //! A map that provides an Armyset when supplying a subdirectory name.
202 ArmysetMap d_armysets;
204 //! A map that provides an Armyset when supplying a subdirectory name.
205 ArmysetIdMap d_armysetids;
207 //! A static pointer for the singleton instance.
208 static Armysetlist* s_instance;
211 #endif // ARMYSETLIST_H