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, 2014, 2015 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 #pragma once
24 #ifndef PRODSLOTLIST_H
25 #define PRODSLOTLIST_H
26 
27 #include <gtkmm.h>
28 #include <list>
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 	 * @return True if the given army prototype is already a production
102 	 *         base in the list.  Otherwise false.
103 	 */
104         bool hasProductionBase(int type) const;
105 
106         //! Returns the maximum number of production bases in the list.
107 	/**
108 	 * The list has this many production slots in total.  This value
109 	 * should always return 4 (defs.h:MAX_PRODUCTION_SLOTS_IN_A_CITY)
110 	 *
111 	 * @return The maximum number of Army production bases that this list
112 	 *         can have.
113 	 */
getMaxNoOfProductionBases()114         guint32 getMaxNoOfProductionBases() const {return size();};
115 
116 
117         //! Returns true if the list already contains this production type.
118         bool hasProductionBase(const ArmyProto * army) const;
119 
120         //! Return the first slot that doesn't have a production base.
121 	int getFreeSlot() const;
122 
123         //! Return the number of production bases in the list.
124 	/**
125 	 * Scan the production slots and count how many are filled with an
126 	 * Army production base.
127 	 *
128 	 * @return The current number of used slots that the list has.
129 	 */
130         guint32 getNoOfProductionBases() const;
131 
132         //! Get the number of turns until current production base is finished.
getDuration()133         int getDuration() const {return d_duration;}
134 
135         //! Return the index of the active production slot.
136 	/**
137 	 * @return The index of the active production slot, or -1 if the list
138 	 *         does not have an active production slot.
139 	 */
getActiveProductionSlot()140         int getActiveProductionSlot() const {return d_active_production_slot;}
141 
142         //! Return the index of the army in the given slot.
143 	/**
144 	 * @param slot  The production slot to return the army type for.  This
145 	 *              value ranges between 0 and 3.
146 	 *
147 	 * @return The index of the Army prototype unit within it's Armyset,
148 	 *         or -1 if no production base is allocated to that slot.
149 	 */
150         int getArmytype(int slot) const;
151 
152         //! Return the army production base of the given slot.
153         const ArmyProdBase * getProductionBase(int slot) const;
154 
155 	//! Return the army production base this list is producing.
156 	const ArmyProdBase *getActiveProductionBase() const;
157 
158 	//! Scan the list for an army production base of the given type.
159 	const ArmyProdBase * getProductionBaseBelongingTo(const Army *army) const;
160 
161 
162 	// Methods that operate on the class data and modify the class.
163 
164 	//! Add an Army production base to a production slot.
165         /**
166 	 * This method is called when a new army production base has been
167 	 * purchased/bought.
168 	 *
169          * @note This method overwrites the production slot if neccessary.
170          *
171          * @param index        The index of the production slot; if set to -1,
172          *                     the object will try to find a free production
173 	 *                     slot. This must be a value between -1 and 3.
174 	 * @param army         The Army production base to add.  Look at the
175 	 *                     Army class to find out what a production base is.
176          */
177         void addProductionBase(int index, ArmyProdBase *army);
178 
179         //! Clears the basic production of a given slot.
180 	/**
181 	 * @param index  The slot to remove the Army production base from.
182 	 *               This method deletes the Army production base object.
183 	 *               This parameter must be a a value between 0 and 3.
184 	 */
185         void removeProductionBase(int index);
186 
187         //! axe any army types that are no longer in the armyset.
188         bool removeArmyProdBasesWithoutAType(guint32 armyset);
189 
190     protected:
191 
192 	//! Callback method to help in loading the armyprodbases into the list.
193 	bool load(Glib::ustring tag, XML_Helper *helper);
194 
195         // DATA
196 
197 	//! The active production slot.
198 	/**
199 	 * The Army production base in this slot is the Army unit that the
200 	 * list is currently busy creating.
201 	 */
202         int d_active_production_slot;
203 
204 	//! Number of turns until the next Army is produced.
205 	/**
206 	 *  Number of turns required to finish the current production.
207 	 *  When this value hits 0, the new Army unit is created.
208 	 */
209         int d_duration;
210 
211 };
212 
213 #endif // PRODSLOTLIST_H
214