~ubuntu-branches/ubuntu/saucy/lordsawar/saucy

« back to all changes in this revision

Viewing changes to src/prodslotlist.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2008-12-20 13:52:12 UTC
  • mfrom: (1.1.6 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081220135212-noeb2w3y98ebo7o9
Tags: 0.1.4-1
[ Barry deFreese ]
* New upstream release.
* Move 0.0.8-2.1 changelog entry to correct point in changelog.
* Make lordsawar-data suggest lordsawar.
* Update my e-mail address.
* Add build-depends on intltool, uuid-dev, and libboost-dev.
* Don't install locales since there are no translations currently.
* Add simple man page for new lordsawar-pbm binary.
* Drop gcc4.3 patches as they have been fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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 2 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 <SDL.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(Uint32 numslots = MAX_PRODUCTION_SLOTS_IN_A_CITY);
 
55
        //! Copy constructor.
 
56
        ProdSlotlist(const ProdSlotlist&);
 
57
        //! Loading constructor.
 
58
        /**
 
59
         * Make a new set of production slots by reading it from a saved-game 
 
60
         * file.
 
61
         *
 
62
         * @param helper The opened saved-game file to load the set of 
 
63
         *               production slots from.
 
64
         */
 
65
        ProdSlotlist(XML_Helper* helper);
 
66
        //! Destructor.
 
67
        ~ProdSlotlist();
 
68
 
 
69
        //! Save the set of production slots to an opened saved-game file.
 
70
        bool save(XML_Helper* helper) const;
 
71
        
 
72
        //! Add an Army production base to a production slot.
 
73
        /**
 
74
         * This method is called when a new army production base has been
 
75
         * purchased/bought.
 
76
         *
 
77
         * @note This method overwrites the production slot if neccessary.
 
78
         * 
 
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.
 
84
         */
 
85
        void addProductionBase(int index, ArmyProdBase *army);
 
86
 
 
87
        //! Clears the basic production of a given slot.
 
88
        /**
 
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.
 
92
         */
 
93
        void removeProductionBase(int index);
 
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, Uint32 armyset) const;
 
108
 
 
109
        //! Returns true if the list already contains this production type.
 
110
        bool hasProductionBase(const ArmyProto * army);
 
111
 
 
112
        //! Return the first slot that doesn't have a production base.
 
113
        int getFreeBasicSlot();
 
114
 
 
115
        //! Returns the maximum number of production bases in the list.
 
116
        /**
 
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)
 
119
         *
 
120
         * @return The maximum number of Army production bases that this list
 
121
         *         can have.
 
122
         */
 
123
        Uint32 getMaxNoOfProductionBases() const {return size();};
 
124
 
 
125
        //! Return the number of production bases in the list.
 
126
        /**
 
127
         * Scan the production slots and count how many are filled with an
 
128
         * Army production base.
 
129
         *
 
130
         * @return The current number of used slots that the list has.
 
131
         */
 
132
        Uint32 getNoOfProductionBases();
 
133
 
 
134
        //! Get the number of turns until current production base is finished.
 
135
        int getDuration() const {return d_duration;}
 
136
 
 
137
        //! Return the index of the active production slot.
 
138
        /**
 
139
         * @return The index of the active production slot, or -1 if the list 
 
140
         *         does not have an active production slot.
 
141
         */
 
142
        int getActiveProductionSlot() const {return d_active_production_slot;}
 
143
        
 
144
        //! Set the active production base of the list.
 
145
        /**
 
146
         * Make the Army production base in particular slot active, so that
 
147
         * the Army starts being produced.
 
148
         *
 
149
         * @param index  The index of the production slot to activate. 
 
150
         *               -1 means no production at all.   This must be a value
 
151
         *               between -1 and 3.
 
152
         */
 
153
        void setActiveProductionSlot(int index);
 
154
        
 
155
        //! Return the index of the army in the given slot.
 
156
        /**
 
157
         * @param slot  The production slot to return the army type for.  This
 
158
         *              value ranges between 0 and 3.
 
159
         *
 
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.
 
162
         */
 
163
        int getArmytype(int slot) const;
 
164
 
 
165
        //! Return the army production base of the given slot.
 
166
        const ArmyProdBase * getProductionBase(int slot) const;
 
167
 
 
168
        //! Scan the list for an army production base of the given type.
 
169
        const ArmyProdBase * getProductionBaseBelongingTo(const Army *army);
 
170
        
 
171
        //! Return the army production base this list is producing.
 
172
        const ArmyProdBase *getActiveProductionBase() const;
 
173
 
 
174
    protected:
 
175
 
 
176
        bool load(std::string tag, XML_Helper *helper);
 
177
 
 
178
        // DATA
 
179
 
 
180
        //! The active production slot.
 
181
        /**
 
182
         * The Army production base in this slot is the Army unit that the
 
183
         * list is currently busy creating.
 
184
         */
 
185
        int d_active_production_slot;
 
186
 
 
187
        //! Number of turns until the next Army is produced.
 
188
        /**
 
189
         *  Number of turns required to finish the current production.
 
190
         *  When this value hits 0, the new Army unit is created.
 
191
         */
 
192
        int d_duration;
 
193
 
 
194
};
 
195
 
 
196
#endif // PRODSLOTLIST_H