initial commit, lordsawar source, slightly modified
[lordsawar] / src / prodslotlist.h
1 // Copyright (C) 2000, 2001, 2003 Michael Bartl
2 // Copyright (C) 2002 Mark L. Amidon
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
4 // Copyright (C) 2005, 2006 Andrea Paternesi
5 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
6 // Copyright (C) 2008 Ole Laursen
7 //
8 //  This program is free software; you can redistribute it and/or modify
9 //  it under the terms of the GNU General Public License as published by
10 //  the Free Software Foundation; either version 3 of the License, or
11 //  (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU Library General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
21 //  02110-1301, USA.
22
23 #ifndef PRODSLOTLIST_H
24 #define PRODSLOTLIST_H
25
26 #include <gtkmm.h>
27 #include <list>
28 #include <string>
29 #include <vector>
30 #include "prodslot.h"
31 #include "defs.h"
32
33 class ArmyProdBase;
34 class ArmyProto;
35 class Army;
36
37 //! A set of production slots.
38 /**
39  * This object is the set of production slots that may or may not hold
40  * army production base objects.
41  * This object remembers which slot is "active", and how far along the unit
42  * is to being completed.
43  */
44 class ProdSlotlist: public std::vector<ProdSlot*>
45 {
46     public:
47
48         //! Default constructor.
49         /** 
50           * Make a new set of production slots.
51           *
52           * @param numslots  The number of production slots in the list.
53           */
54         ProdSlotlist(guint32 numslots = MAX_PRODUCTION_SLOTS_IN_A_CITY);
55
56         //! Copy constructor.
57         ProdSlotlist(const ProdSlotlist&);
58
59         //! Loading constructor.
60         /**
61          * Make a new set of production slots by reading it from a saved-game 
62          * file.
63          *
64          * @param helper The opened saved-game file to load the set of 
65          *               production slots from.
66          */
67         ProdSlotlist(XML_Helper* helper);
68
69         //! Destructor.
70         ~ProdSlotlist();
71
72         
73         // Set Methods
74
75         //! Set the active production base of the list.
76         /**
77          * Make the Army production base in particular slot active, so that
78          * the Army starts being produced.
79          *
80          * @param index  The index of the production slot to activate. 
81          *               -1 means no production at all.   This must be a value
82          *               between -1 and 3.
83          */
84         void setActiveProductionSlot(int index);
85
86
87         // Get Methods
88
89
90         // Methods that operate on the class data but do not modify the class.
91
92         //! Save the set of production slots to an opened saved-game file.
93         bool save(XML_Helper* helper) const;
94         
95         //! Returns whether or not the given army type is in the list.
96         /**
97          * This method scans the production slots for the given army 
98          * prototype.
99          *
100          * @param type      The index of the Army prototype in the Armyset.
101          * @param armyset   The unique Id of the armyset for which to check
102          *                  if the given type is already a production base
103          *                  in this list.
104          * @return True if the given army prototype is already a production
105          *         base in the list.  Otherwise false.
106          */
107         bool hasProductionBase(int type, guint32 armyset) const;
108
109         //! Returns the maximum number of production bases in the list.
110         /**
111          * The list has this many production slots in total.  This value 
112          * should always return 4 (defs.h:MAX_PRODUCTION_SLOTS_IN_A_CITY)
113          *
114          * @return The maximum number of Army production bases that this list
115          *         can have.
116          */
117         guint32 getMaxNoOfProductionBases() const {return size();};
118
119
120         //! Returns true if the list already contains this production type.
121         bool hasProductionBase(const ArmyProto * army) const;
122
123         //! Return the first slot that doesn't have a production base.
124         int getFreeSlot() const;
125
126         //! Return the number of production bases in the list.
127         /**
128          * Scan the production slots and count how many are filled with an
129          * Army production base.
130          *
131          * @return The current number of used slots that the list has.
132          */
133         guint32 getNoOfProductionBases() const;
134
135         //! Get the number of turns until current production base is finished.
136         int getDuration() const {return d_duration;}
137         
138         //! Return the index of the active production slot.
139         /**
140          * @return The index of the active production slot, or -1 if the list 
141          *         does not have an active production slot.
142          */
143         int getActiveProductionSlot() const {return d_active_production_slot;}
144         
145         //! Return the index of the army in the given slot.
146         /**
147          * @param slot  The production slot to return the army type for.  This
148          *              value ranges between 0 and 3.
149          *
150          * @return The index of the Army prototype unit within it's Armyset,
151          *         or -1 if no production base is allocated to that slot.
152          */
153         int getArmytype(int slot) const;
154
155         //! Return the army production base of the given slot.
156         const ArmyProdBase * getProductionBase(int slot) const;
157
158         //! Return the army production base this list is producing.
159         const ArmyProdBase *getActiveProductionBase() const;
160
161         //! Scan the list for an army production base of the given type.
162         const ArmyProdBase * getProductionBaseBelongingTo(const Army *army) const;
163         
164
165         // Methods that operate on the class data and modify the class.
166
167         //! Add an Army production base to a production slot.
168         /**
169          * This method is called when a new army production base has been
170          * purchased/bought.
171          *
172          * @note This method overwrites the production slot if neccessary.
173          * 
174          * @param index        The index of the production slot; if set to -1,
175          *                     the object will try to find a free production 
176          *                     slot. This must be a value between -1 and 3.
177          * @param army         The Army production base to add.  Look at the
178          *                     Army class to find out what a production base is.
179          */
180         void addProductionBase(int index, ArmyProdBase *army);
181
182         //! Clears the basic production of a given slot.
183         /**
184          * @param index  The slot to remove the Army production base from.
185          *               This method deletes the Army production base object.  
186          *               This parameter must be a a value between 0 and 3.
187          */
188         void removeProductionBase(int index);
189
190
191     protected:
192
193         //! Callback method to help in loading the armyprodbases into the list.
194         bool load(std::string tag, XML_Helper *helper);
195
196         // DATA
197
198         //! The active production slot.
199         /**
200          * The Army production base in this slot is the Army unit that the
201          * list is currently busy creating.
202          */
203         int d_active_production_slot;
204
205         //! Number of turns until the next Army is produced.
206         /**
207          *  Number of turns required to finish the current production.
208          *  When this value hits 0, the new Army unit is created.
209          */
210         int d_duration;
211
212 };
213
214 #endif // PRODSLOTLIST_H