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
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.
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.
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
23 #ifndef PRODSLOTLIST_H
24 #define PRODSLOTLIST_H
37 //! A set of production slots.
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.
44 class ProdSlotlist: public std::vector<ProdSlot*>
48 //! Default constructor.
50 * Make a new set of production slots.
52 * @param numslots The number of production slots in the list.
54 ProdSlotlist(guint32 numslots = MAX_PRODUCTION_SLOTS_IN_A_CITY);
57 ProdSlotlist(const ProdSlotlist&);
59 //! Loading constructor.
61 * Make a new set of production slots by reading it from a saved-game
64 * @param helper The opened saved-game file to load the set of
65 * production slots from.
67 ProdSlotlist(XML_Helper* helper);
75 //! Set the active production base of the list.
77 * Make the Army production base in particular slot active, so that
78 * the Army starts being produced.
80 * @param index The index of the production slot to activate.
81 * -1 means no production at all. This must be a value
84 void setActiveProductionSlot(int index);
90 // Methods that operate on the class data but do not modify the class.
92 //! Save the set of production slots to an opened saved-game file.
93 bool save(XML_Helper* helper) const;
95 //! Returns whether or not the given army type is in the list.
97 * This method scans the production slots for the given army
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
104 * @return True if the given army prototype is already a production
105 * base in the list. Otherwise false.
107 bool hasProductionBase(int type, guint32 armyset) const;
109 //! Returns the maximum number of production bases in the list.
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)
114 * @return The maximum number of Army production bases that this list
117 guint32 getMaxNoOfProductionBases() const {return size();};
120 //! Returns true if the list already contains this production type.
121 bool hasProductionBase(const ArmyProto * army) const;
123 //! Return the first slot that doesn't have a production base.
124 int getFreeSlot() const;
126 //! Return the number of production bases in the list.
128 * Scan the production slots and count how many are filled with an
129 * Army production base.
131 * @return The current number of used slots that the list has.
133 guint32 getNoOfProductionBases() const;
135 //! Get the number of turns until current production base is finished.
136 int getDuration() const {return d_duration;}
138 //! Return the index of the active production slot.
140 * @return The index of the active production slot, or -1 if the list
141 * does not have an active production slot.
143 int getActiveProductionSlot() const {return d_active_production_slot;}
145 //! Return the index of the army in the given slot.
147 * @param slot The production slot to return the army type for. This
148 * value ranges between 0 and 3.
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.
153 int getArmytype(int slot) const;
155 //! Return the army production base of the given slot.
156 const ArmyProdBase * getProductionBase(int slot) const;
158 //! Return the army production base this list is producing.
159 const ArmyProdBase *getActiveProductionBase() const;
161 //! Scan the list for an army production base of the given type.
162 const ArmyProdBase * getProductionBaseBelongingTo(const Army *army) const;
165 // Methods that operate on the class data and modify the class.
167 //! Add an Army production base to a production slot.
169 * This method is called when a new army production base has been
172 * @note This method overwrites the production slot if neccessary.
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.
180 void addProductionBase(int index, ArmyProdBase *army);
182 //! Clears the basic production of a given slot.
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.
188 void removeProductionBase(int index);
193 //! Callback method to help in loading the armyprodbases into the list.
194 bool load(std::string tag, XML_Helper *helper);
198 //! The active production slot.
200 * The Army production base in this slot is the Army unit that the
201 * list is currently busy creating.
203 int d_active_production_slot;
205 //! Number of turns until the next Army is produced.
207 * Number of turns required to finish the current production.
208 * When this value hits 0, the new Army unit is created.
214 #endif // PRODSLOTLIST_H