1 // Copyright (C) 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2003, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2014, 2020 Ben Asselstine
4 //
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.
9 //
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.
14 //
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
18 //  02110-1301, USA.
19 
20 #pragma once
21 #ifndef ARMYSETLIST_H
22 #define ARMYSETLIST_H
23 
24 #include <gtkmm.h>
25 #include <map>
26 #include <vector>
27 #include <sigc++/trackable.h>
28 
29 #include "armyproto.h"
30 #include "armyset.h"
31 #include "setlist.h"
32 
33 class Tar_Helper;
34 
35 //! A list of all Armyset objects available to the game.
36 /**
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.
41  *
42  * The Armysetlist is populated with Armyset objects that are loaded from the
43  * army/ directory.
44  *
45  * Since several classes access this class, it is implemented as a singleton.
46  */
47 
48 class Armysetlist : public SetList<Armyset>, public sigc::trackable
49 {
50     public:
51         //! Return the singleton instance of this class.
52         static Armysetlist* getInstance();
53 
54         //! Explicitly delete the singleton instance of this class
55         static void deleteInstance();
56 
57 	//! Returns an army prototype from a given armyset.
58         /**
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.
62 	 *
63          * @return The requested army or 0 on error.
64          */
65         ArmyProto* getArmy(guint32 id, guint32 index) const;
66 
67 	//! Returns army prototype of the weakest/quickest from a given armyset.
68         /**
69          * @param id       The Id of the armyset.
70 	 *
71          * @return The requested weakest quickest army prototype or 0 on error.
72          */
73         ArmyProto* lookupWeakestQuickestArmy(guint32 id) const;
74 
75 	//! Get the unshaded ship image for the given Armyset.
76 	PixMask* getShipPic (guint32 id);
77 
78 	//! Get the ship mask picture for the given Armyset.
79 	PixMask* getShipMask (guint32 id);
80 
81 	//! Get the unshaded planted standard picture for the given Armyset.
82 	PixMask* getStandardPic (guint32 id);
83 
84 	//! Get the bag of oitems picture for the given Armyset.
85 	PixMask* getBagPic (guint32 id);
86 
87 	//! Get the planted standard mask for the given Armyset.
88 	PixMask* getStandardMask (guint32 id);
89         guint32 getTileSize(guint32 id);
90 
91 	void instantiateImages(bool &broken);
92 	void uninstantiateImages();
93 
94     private:
95         //! Default Constructor.  Loads all armyset objects it can find.
96 	/**
97 	 * The army/ directory is scanned for armyset directories.
98 	 */
99         Armysetlist();
100 
101         //! Destructor.
102         ~Armysetlist();
103 
104         void on_armyset_added(Armyset *armyset);
105         void on_armyset_reloaded(Armyset *armyset);
106 
107         typedef std::map<guint32, ArmyProto*> IdArmyPrototypeMap;
108         typedef std::map<guint32, IdArmyPrototypeMap> ArmyPrototypeMap;
109 
110 	//! A map that provides Army objects by their index.
111         ArmyPrototypeMap d_armies;
112 
113         //! A static pointer for the singleton instance.
114         static Armysetlist* s_instance;
115 };
116 
117 #endif // ARMYSETLIST_H
118 
119