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 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 2 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(Uint32 numslots = MAX_PRODUCTION_SLOTS_IN_A_CITY);
56
ProdSlotlist(const ProdSlotlist&);
57
//! Loading constructor.
59
* Make a new set of production slots by reading it from a saved-game
62
* @param helper The opened saved-game file to load the set of
63
* production slots from.
65
ProdSlotlist(XML_Helper* helper);
69
//! Save the set of production slots to an opened saved-game file.
70
bool save(XML_Helper* helper) const;
72
//! Add an Army production base to a production slot.
74
* This method is called when a new army production base has been
77
* @note This method overwrites the production slot if neccessary.
79
* @param index The index of the production slot; if set to -1,
80
* the object will try to find a free production
81
* slot. This must be a value between -1 and 3.
82
* @param army The Army production base to add. Look at the
83
* Army class to find out what a production base is.
85
void addProductionBase(int index, ArmyProdBase *army);
87
//! Clears the basic production of a given slot.
89
* @param index The slot to remove the Army production base from.
90
* This method deletes the Army production base object.
91
* This parameter must be a a value between 0 and 3.
93
void removeProductionBase(int index);
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, Uint32 armyset) const;
109
//! Returns true if the list already contains this production type.
110
bool hasProductionBase(const ArmyProto * army);
112
//! Return the first slot that doesn't have a production base.
113
int getFreeBasicSlot();
115
//! Returns the maximum number of production bases in the list.
117
* The list has this many production slots in total. This value
118
* should always return 4 (defs.h:MAX_PRODUCTION_SLOTS_IN_A_CITY)
120
* @return The maximum number of Army production bases that this list
123
Uint32 getMaxNoOfProductionBases() const {return size();};
125
//! Return the number of production bases in the list.
127
* Scan the production slots and count how many are filled with an
128
* Army production base.
130
* @return The current number of used slots that the list has.
132
Uint32 getNoOfProductionBases();
134
//! Get the number of turns until current production base is finished.
135
int getDuration() const {return d_duration;}
137
//! Return the index of the active production slot.
139
* @return The index of the active production slot, or -1 if the list
140
* does not have an active production slot.
142
int getActiveProductionSlot() const {return d_active_production_slot;}
144
//! Set the active production base of the list.
146
* Make the Army production base in particular slot active, so that
147
* the Army starts being produced.
149
* @param index The index of the production slot to activate.
150
* -1 means no production at all. This must be a value
153
void setActiveProductionSlot(int index);
155
//! Return the index of the army in the given slot.
157
* @param slot The production slot to return the army type for. This
158
* value ranges between 0 and 3.
160
* @return The index of the Army prototype unit within it's Armyset,
161
* or -1 if no production base is allocated to that slot.
163
int getArmytype(int slot) const;
165
//! Return the army production base of the given slot.
166
const ArmyProdBase * getProductionBase(int slot) const;
168
//! Scan the list for an army production base of the given type.
169
const ArmyProdBase * getProductionBaseBelongingTo(const Army *army);
171
//! Return the army production base this list is producing.
172
const ArmyProdBase *getActiveProductionBase() const;
176
bool load(std::string tag, XML_Helper *helper);
180
//! The active production slot.
182
* The Army production base in this slot is the Army unit that the
183
* list is currently busy creating.
185
int d_active_production_slot;
187
//! Number of turns until the next Army is produced.
189
* Number of turns required to finish the current production.
190
* When this value hits 0, the new Army unit is created.
196
#endif // PRODSLOTLIST_H