]> ruin.nu Git - hbs.git/blob - bs/unittype.cpp
36bd4ed7c333c80bc063a8384980222f06b1a431
[hbs.git] / bs / unittype.cpp
1 /***************************************************************************
2                           unittype.cpp  -  description
3                              -------------------
4     begin                : Tue Jan 22 2002
5     copyright            : (C) 2002 by Michael Andreen
6     email                : whale@linux.nu
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "unittype.h"
19 #include <iostream>
20 using namespace std;
21
22 //////////////////////////////////////////////////////////////////////////
23 //
24
25 UnitType::UnitType()
26 {
27 }
28 //////////////////////////////////////////////////////////////////////////
29 //
30 UnitType::~UnitType(){
31 }
32
33
34 //////////////////////////////////////////////////////////////////////////
35 //
36 void UnitType::setName(string sName)
37 {
38         m_sName = sName;
39 }
40
41 //////////////////////////////////////////////////////////////////////////
42 //
43 string UnitType::Name() const
44 {
45         return m_sName;
46 }
47
48 //////////////////////////////////////////////////////////////////////////
49 //
50 void UnitType::setRace(int iRace)
51 {
52         m_iRace = iRace;
53 }
54
55 //////////////////////////////////////////////////////////////////////////
56 //
57 int UnitType::race() const
58 {
59         return m_iRace;
60 }
61
62 //////////////////////////////////////////////////////////////////////////
63 //
64 void UnitType::setUnitClass(string sClass)
65 {
66         m_sClass = sClass;
67 }
68
69 //////////////////////////////////////////////////////////////////////////
70 //
71 string UnitType::unitClass() const
72 {
73         return m_sClass;
74 }
75
76 //////////////////////////////////////////////////////////////////////////
77 //
78 void UnitType::setTarget(vector<string> Target)
79 {
80         m_vTarget = Target;
81 }
82
83 //////////////////////////////////////////////////////////////////////////
84 //
85 void UnitType::addTarget(string target)
86 {
87         m_vTarget.push_back(target);
88 }
89
90 //////////////////////////////////////////////////////////////////////////
91 //
92 /** This function iterates through the list until it finds the right positition.
93  * If it finds the position it inserts the target there, if it reaches the end 
94  * before it finds the correct possition it adds the target to the end. 
95  */
96 void UnitType::insTarget(string target, int index = 0)
97 {
98
99         vector<string>::iterator i = m_vTarget.begin(); 
100
101         for (int j = 0; j < index; j++, i++)
102         {
103                 if (i == m_vTarget.end())
104                 {
105                         m_vTarget.push_back(target);
106                         return;
107                 }
108         }
109
110         m_vTarget.insert(i, target);
111 }
112
113 //////////////////////////////////////////////////////////////////////////
114 //
115 vector<string> UnitType::target() const
116 {
117         return m_vTarget;
118 }
119
120 //////////////////////////////////////////////////////////////////////////
121 //
122 string UnitType::target(int index) const
123 {
124         return m_vTarget[index];
125 }
126
127 //////////////////////////////////////////////////////////////////////////
128 //
129 void UnitType::setInitiative(int iInit)
130 {
131         m_iInitiative = iInit;
132 }
133
134 //////////////////////////////////////////////////////////////////////////
135 //
136 int      UnitType::initiative() const
137 {
138         return m_iInitiative;
139 }
140
141 //////////////////////////////////////////////////////////////////////////
142 //
143 void UnitType::setAgility (int iAgil)
144 {
145         m_iAgility = iAgil;
146 }
147
148 //////////////////////////////////////////////////////////////////////////
149 //
150 int  UnitType::agility() const
151 {
152         return m_iAgility;
153 }
154
155 //////////////////////////////////////////////////////////////////////////
156 //
157 void UnitType::setWeaponSpeed(int iWPSP)
158 {
159         m_iWeaponSpeed = iWPSP;
160 }
161
162 //////////////////////////////////////////////////////////////////////////
163 //
164 int  UnitType::weaponSpeed() const
165 {
166         return m_iWeaponSpeed;
167 }
168
169 //////////////////////////////////////////////////////////////////////////
170 //
171 void UnitType::setGuns(int iGuns)
172 {
173         m_iGuns = iGuns;
174 }
175
176 //////////////////////////////////////////////////////////////////////////
177 //
178 int UnitType::guns() const
179 {
180         return m_iGuns;
181 }
182
183 //////////////////////////////////////////////////////////////////////////
184 //
185 void UnitType::setPower(int iPower)
186 {
187         m_iPower = iPower;
188 }
189
190 //////////////////////////////////////////////////////////////////////////
191 //
192 int  UnitType::power() const
193 {
194         return m_iPower;
195 }
196
197 //////////////////////////////////////////////////////////////////////////
198 //
199 void UnitType::setArmor(int iArmor)
200 {
201         m_iArmor = iArmor;
202 }
203
204 //////////////////////////////////////////////////////////////////////////
205 //
206 int  UnitType::armor() const
207 {
208         return m_iArmor;
209 }
210
211 //////////////////////////////////////////////////////////////////////////
212 //
213 void UnitType::setEMP(int iEMP)
214 {
215         m_iEMP = iEMP;
216 }
217
218 //////////////////////////////////////////////////////////////////////////
219 //
220 int  UnitType::EMP() const
221 {
222         return m_iEMP;
223 }
224
225 //////////////////////////////////////////////////////////////////////////
226 //
227 void UnitType::setResources(std::string type, int i)
228 {
229         m_Resources[type] = i;
230 }
231
232 //////////////////////////////////////////////////////////////////////////
233 //
234 void UnitType::setResources(map<std::string, int> res)
235 {
236         m_Resources = res;
237 }
238
239 //////////////////////////////////////////////////////////////////////////
240 //
241 std::map<std::string, int> UnitType::resources()
242 {
243         return m_Resources;
244 }
245
246 //////////////////////////////////////////////////////////////////////////
247 //
248 int UnitType::totRes() const
249 {
250         int totres = 0;
251         for (map<string, int>::const_iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
252                 totres += i->second;
253         return totres;
254 }
255
256 //////////////////////////////////////////////////////////////////////////
257 //
258 void UnitType::setFuel(int iFuel)
259 {
260         m_iFuel = iFuel;
261 }
262
263 //////////////////////////////////////////////////////////////////////////
264 //
265 int  UnitType::fuel() const
266 {
267         return m_iFuel;
268 }
269
270 //////////////////////////////////////////////////////////////////////////
271 //
272 void UnitType::setETA(int iETA)
273 {
274         m_iETA = iETA;
275 }
276
277 //////////////////////////////////////////////////////////////////////////
278 //
279 int  UnitType::ETA() const
280 {
281         return m_iETA;
282 }
283
284 //////////////////////////////////////////////////////////////////////////
285 //
286 void UnitType::setType(string type)
287 {
288         m_sType = type;
289 }
290
291 //////////////////////////////////////////////////////////////////////////
292 //
293 string  UnitType::type() const
294 {
295         return m_sType;
296 }
297