25
30
#include "armyset.h"
28
/** List of all available armysets
30
* This class contains a list of all armysetsused in the game. Each armyset has
31
* a size, a name and a list of armies. The armysetlist shields all these from
32
* the evil rest of the program. Armysets are in general referenced by their
35
* @note Throughout this class, it is assumed that the standard armyset usable
36
* by all playes ha sthe index 1, the heroes armyset index 2. However, to avoid
37
* this assumption being spread over the whole code, we separate the access to
38
* these two armysets from the rest via special functions.
40
* Since several classes access this class, it is implemented as a singleton.
33
//! A list of all Armyset objects available to the game.
35
* This class contains a list of all armyset objects available to the game.
36
* Each armyset has a size, a name and a list of armies. The armysetlist
37
* shields all these from the rest of the program. Armysets are most often
38
* referenced by their id.
40
* The Armysetlist is populated with Armyset objects that are loaded from the
43
* Since several classes access this class, it is implemented as a singleton.
43
46
class Armysetlist : public std::list<Armyset*>, public sigc::trackable
46
//! return the singleton instance of this class
49
//! Return the singleton instance of this class.
47
50
static Armysetlist* getInstance();
49
52
//! Explicitly delete the singleton instance of this class
50
53
static void deleteInstance();
52
/** Returns an army prototype
54
* @param id the id of the armyset
55
* @param index the index of the army within the set
56
* @return the requested army or 0 on error
55
//! Returns an army prototype from a given armyset.
57
* @param id The Id of the armyset.
58
* @param index The index of the army within the set.
59
* This value becomes the Army object's type.
61
* @return The requested army or 0 on error.
58
63
Army* getArmy(Uint32 id, Uint32 index) const;
65
//! Get the unshaded ship image for the given Armyset.
60
66
SDL_Surface * getShipPic (Uint32 id);
68
//! Get the ship mask picture for the given Armyset.
61
69
SDL_Surface * getShipMask (Uint32 id);
71
//! Get the unshaded planted standard picture for the given Armyset.
62
72
SDL_Surface * getStandardPic (Uint32 id);
74
//! Get the planted standard mask for the given Armyset.
63
75
SDL_Surface * getStandardMask (Uint32 id);
64
76
Uint32 getTileSize(Uint32 id);
66
/** Returns the size of a specific armyset
68
* @param id the id of the armyset
69
* @return size of the armyset or 0 on error (an armyset should never
78
//! Returns the size of a specific armyset.
80
* @param id The id of the armyset to get the size of.
82
* @return The number of Army prototype objects in the Armyset.
72
85
Uint32 getSize(Uint32 id) const;
74
/** Returns the name of a specific armyset
76
* @param id the id of the armyset
77
* @return the name or an empty string on error
87
//! Return the name of a given armyset.
89
* @param id The id of the armyset to get the name of.
91
* @return The name of the Armyset or an empty string on error.
79
93
std::string getName(Uint32 id) const;
81
//! Returns the names of all armysets
95
//! Returns the names of all Armyset objects available to the game.
82
96
std::list<std::string> getNames();
84
98
/** Returns the Id of a specific armyset by name
89
103
Uint32 getArmysetId(std::string armyset) {return d_ids[armyset];}
91
/** Returns a list of all existing army sets
105
//! Returns a list of all Armyset objects available to the game.
93
106
std::vector<Uint32> getArmysets() const;
95
/* Reads in the pixmap and mask for every army of every armyset.
96
* This can only be done after SDL is initialized.
108
//! Load the pictures for all Armyset objects available to the game.
110
* Reads in the pixmap and mask for every army of every armyset.
111
* @note This can only be done after SDL is initialized.
98
113
void instantiatePixmaps();
101
//! Constructor; loads all armysets it can find
116
//! Default Constructor. Loads all armyset objects it can find.
118
* The army/ directory is scanned for armyset directories.
104
//! Destructor; mainly clears the lists
107
//! Callback for loading. See XML_Helper for details.
125
//! Callback for loading an armyset. See XML_Helper for details.
108
126
bool load(std::string tag, XML_Helper *helper);
110
//! Loads a specific armyset
128
//! Loads a specific armyset.
130
* Load the armyset from an armyset configuration file and add it to
131
* this list of armysets.
133
* @param name The subdirectory name that the Armyset resides in.
135
* @return True if the Armyset could be loaded. False otherwise.
111
137
bool loadArmyset (std::string name);
113
typedef std::map<Uint32, std::vector<Army*> > ArmyMap;
139
typedef std::map<Uint32, std::vector<Army*> > ArmyPrototypeMap;
114
140
typedef std::map<Uint32, std::string> NameMap;
115
141
typedef std::map<std::string, Uint32> IdMap;
143
//! A map that provides Army objects by their index.
144
ArmyPrototypeMap d_armies;
146
//! A map that provides Armyset::d_name by supplying a Armyset::d_id.
149
//! A map that provides Armyset:d_id by supplying a Armyset::d_name.
152
//! A static pointer for the singleton instance.
121
153
static Armysetlist* s_instance;