1 /***************************************************************************
2  *      Mechanized Assault and Exploration Reloaded Projectfile            *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19 
20 #include <algorithm>
21 
22 #include "game/data/units/unitdata.h"
23 
24 //------------------------------------------------------------------------------
sUnitData()25 sUnitData::sUnitData()
26 {
27 	version = 0;
28 	muzzleType = MUZZLE_TYPE_NONE;
29 
30 	ammoMax = 0;
31 	ammoCur = 0;
32 	shotsMax = 0;
33 	shotsCur = 0;
34 	range = 0;
35 	damage = 0;
36 	canAttack = 0;
37 	canDriveAndFire = false;
38 
39 	buildCosts = 0;
40 	maxBuildFactor = 0;
41 
42 	canBuildPath = false;
43 	canBuildRepeat = false;
44 
45 	// Movement
46 	speedMax = 0;
47 	speedCur = 0;
48 
49 	factorGround = 0.0f;
50 	factorSea = 0.0f;
51 	factorAir = 0.0f;
52 	factorCoast = 0.0f;
53 
54 	// Abilities
55 	isBig = false;
56 	connectsToBase = false;
57 	armor = 0;
58 	hitpointsMax = 0;
59 	hitpointsCur = 0;
60 	scan = 0;
61 	modifiesSpeed = 0.0f;
62 	canClearArea = false;
63 	canBeCaptured = false;
64 	canBeDisabled = false;
65 	canCapture = false;
66 	canDisable = false;
67 	canRepair = false;
68 	canRearm = false;
69 	canResearch = false;
70 	canPlaceMines = false;
71 	canSurvey = false;
72 	doesSelfRepair = false;
73 	convertsGold = 0;
74 	canSelfDestroy = false;
75 	canScore = false;
76 
77 	canMineMaxRes = 0;
78 	needsMetal = 0;
79 	needsOil = 0;
80 	needsEnergy = 0;
81 	needsHumans = 0;
82 	produceEnergy = 0;
83 	produceHumans = 0;
84 
85 	isStealthOn = 0;
86 	canDetectStealthOn = 0;
87 
88 	surfacePosition = SURFACE_POS_BENEATH_SEA;
89 	canBeOverbuild = OVERBUILD_TYPE_NO;
90 
91 	canBeLandedOn = false;
92 	canWork = false;
93 	explodesOnContact = false;
94 	isHuman = false;
95 
96 	// Storage
97 	storageResMax = 0;
98 	storageResCur = 0;
99 	storeResType = STORE_RES_NONE;
100 	storageUnitsMax = 0;
101 	storageUnitsCur = 0;
102 	storeUnitsImageType = STORE_UNIT_IMG_NONE;
103 
104 	// Graphic
105 	hasClanLogos = false;
106 	hasCorpse = false;
107 	hasDamageEffect = false;
108 	hasBetonUnderground = false;
109 	hasPlayerColor = false;
110 	hasOverlay = false;
111 
112 	buildUpGraphic = false;
113 	animationMovement = false;
114 	powerOnGraphic = false;
115 	isAnimated = false;
116 	makeTracks = false;
117 
118 	isConnectorGraphic = false;
119 	hasFrames = 0;
120 }
121 
122 //------------------------------------------------------------------------------
sUnitData(const sUnitData & other)123 sUnitData::sUnitData (const sUnitData& other)
124 {
125 	(*this) = other;
126 }
127 
128 //------------------------------------------------------------------------------
operator =(const sUnitData & other)129 sUnitData& sUnitData::operator= (const sUnitData& other)
130 {
131 	ID = other.ID;
132 	name = other.name;
133 	description = other.description;
134 	version = other.version;
135 	muzzleType = other.muzzleType;
136 	ammoMax = other.getAmmoMax();
137 	shotsMax = other.getShotsMax();
138 	range = other.range;
139 	damage = other.damage;
140 	canAttack = other.canAttack;
141 	canDriveAndFire = other.canDriveAndFire;
142 	buildCosts = other.buildCosts;
143 	canBuild = other.canBuild;
144 	buildAs = other.buildAs;
145 	maxBuildFactor = other.maxBuildFactor;
146 	canBuildPath = other.canBuildPath;
147 	canBuildRepeat = other.canBuildRepeat;
148 	speedMax = other.getSpeedMax();
149 	speedCur = other.getSpeed();
150 	factorGround = other.factorGround;
151 	factorSea = other.factorSea;
152 	factorAir = other.factorAir;
153 	factorCoast = other.factorCoast;
154 	isBig = other.isBig;
155 	connectsToBase = other.connectsToBase;
156 	armor = other.armor;
157 	hitpointsMax = other.getHitpointsMax();
158 	scan = other.scan;
159 	modifiesSpeed = other.modifiesSpeed;
160 	canClearArea = other.canClearArea;
161 	canBeCaptured = other.canBeCaptured;
162 	canBeDisabled = other.canBeDisabled;
163 	canCapture = other.canCapture;
164 	canDisable = other.canDisable;
165 	canRepair = other.canRepair;
166 	canRearm = other.canRearm;
167 	canResearch = other.canResearch;
168 	canPlaceMines = other.canPlaceMines;
169 	canSurvey = other.canSurvey;
170 	doesSelfRepair = other.doesSelfRepair;
171 	convertsGold = other.convertsGold;
172 	canSelfDestroy = other.canSelfDestroy;
173 	canScore = other.canScore;
174 	canMineMaxRes = other.canMineMaxRes;
175 	needsMetal = other.needsMetal;
176 	needsOil = other.needsOil;
177 	needsEnergy = other.needsEnergy;
178 	needsHumans = other.needsHumans;
179 	produceEnergy = other.produceEnergy;
180 	produceHumans = other.produceHumans;
181 	isStealthOn = other.isStealthOn;
182 	canDetectStealthOn = other.canDetectStealthOn;
183 	surfacePosition = other.surfacePosition;
184 	canBeOverbuild = other.canBeOverbuild;
185 	canBeLandedOn = other.canBeLandedOn;
186 	canWork = other.canWork;
187 	explodesOnContact = other.explodesOnContact;
188 	isHuman = other.isHuman;
189 	storageResMax = other.storageResMax;
190 	storageResCur = other.storageResCur;
191 	storeResType = other.storeResType;
192 	storageUnitsMax = other.storageUnitsMax;
193 	storageUnitsCur = other.storageUnitsCur;
194 	storeUnitsImageType = other.storeUnitsImageType;
195 	storeUnitsTypes = other.storeUnitsTypes;
196 	isStorageType = other.isStorageType;
197 	hasClanLogos = other.hasClanLogos;
198 	hasCorpse = other.hasCorpse;
199 	hasDamageEffect = other.hasDamageEffect;
200 	hasBetonUnderground = other.hasBetonUnderground;
201 	hasPlayerColor = other.hasPlayerColor;
202 	hasOverlay = other.hasOverlay;
203 	buildUpGraphic = other.buildUpGraphic;
204 	animationMovement = other.animationMovement;
205 	powerOnGraphic = other.powerOnGraphic;
206 	isAnimated = other.isAnimated;
207 	makeTracks = other.makeTracks;
208 	isConnectorGraphic = other.isConnectorGraphic;
209 	hasFrames = other.hasFrames;
210 	hitpointsCur = other.hitpointsCur;
211 	shotsCur = other.shotsCur;
212 	ammoCur = other.ammoCur;
213 
214 	return *this;
215 }
216 
217 //------------------------------------------------------------------------------
getVersion() const218 int sUnitData::getVersion() const
219 {
220 	return version;
221 }
222 
223 //------------------------------------------------------------------------------
setVersion(int value)224 void sUnitData::setVersion (int value)
225 {
226 	std::swap (version, value);
227 	if (version != value) versionChanged();
228 }
229 
230 //------------------------------------------------------------------------------
getSpeed() const231 int sUnitData::getSpeed() const
232 {
233 	return speedCur;
234 }
235 
236 //------------------------------------------------------------------------------
setSpeed(int value)237 void sUnitData::setSpeed (int value)
238 {
239 	std::swap (speedCur, value);
240 	if (speedCur != value) speedChanged();
241 }
242 
243 //------------------------------------------------------------------------------
getSpeedMax() const244 int sUnitData::getSpeedMax() const
245 {
246 	return speedMax;
247 }
248 
249 //------------------------------------------------------------------------------
setSpeedMax(int value)250 void sUnitData::setSpeedMax (int value)
251 {
252 	std::swap (speedMax, value);
253 	if (speedMax != value) speedMaxChanged();
254 }
255 
256 //------------------------------------------------------------------------------
getHitpoints() const257 int sUnitData::getHitpoints() const
258 {
259 	return hitpointsCur;
260 }
261 
262 //------------------------------------------------------------------------------
setHitpoints(int value)263 void sUnitData::setHitpoints (int value)
264 {
265 	std::swap (hitpointsCur, value);
266 	if (hitpointsCur != value) hitpointsChanged();
267 }
268 
269 //------------------------------------------------------------------------------
getHitpointsMax() const270 int sUnitData::getHitpointsMax() const
271 {
272 	return hitpointsMax;
273 }
274 
275 //------------------------------------------------------------------------------
setHitpointsMax(int value)276 void sUnitData::setHitpointsMax (int value)
277 {
278 	std::swap (hitpointsMax, value);
279 	if (hitpointsMax != value) hitpointsMaxChanged();
280 }
281 
282 //------------------------------------------------------------------------------
getScan() const283 int sUnitData::getScan() const
284 {
285 	return scan;
286 }
287 
288 //------------------------------------------------------------------------------
setScan(int value)289 void sUnitData::setScan (int value)
290 {
291 	std::swap (scan, value);
292 	if (scan != value) scanChanged();
293 }
294 
295 //------------------------------------------------------------------------------
getRange() const296 int sUnitData::getRange() const
297 {
298 	return range;
299 }
300 
301 //------------------------------------------------------------------------------
setRange(int value)302 void sUnitData::setRange (int value)
303 {
304 	std::swap (range, value);
305 	if (range != value) rangeChanged();
306 }
307 
308 //------------------------------------------------------------------------------
getShots() const309 int sUnitData::getShots() const
310 {
311 	return shotsCur;
312 }
313 
314 //------------------------------------------------------------------------------
setShots(int value)315 void sUnitData::setShots (int value)
316 {
317 	std::swap (shotsCur, value);
318 	if (shotsCur != value) shotsChanged();
319 }
320 
321 //------------------------------------------------------------------------------
getShotsMax() const322 int sUnitData::getShotsMax() const
323 {
324 	return shotsMax;
325 }
326 
327 //------------------------------------------------------------------------------
setShotsMax(int value)328 void sUnitData::setShotsMax (int value)
329 {
330 	std::swap (shotsMax, value);
331 	if (shotsMax != value) shotsMaxChanged();
332 }
333 
334 //------------------------------------------------------------------------------
getAmmo() const335 int sUnitData::getAmmo() const
336 {
337 	return ammoCur;
338 }
339 
340 //------------------------------------------------------------------------------
setAmmo(int value)341 void sUnitData::setAmmo (int value)
342 {
343 	std::swap (ammoCur, value);
344 	if (ammoCur != value) ammoChanged();
345 }
346 
347 //------------------------------------------------------------------------------
getAmmoMax() const348 int sUnitData::getAmmoMax() const
349 {
350 	return ammoMax;
351 }
352 
353 //------------------------------------------------------------------------------
setAmmoMax(int value)354 void sUnitData::setAmmoMax (int value)
355 {
356 	std::swap (ammoMax, value);
357 	if (ammoMax != value) ammoMaxChanged();
358 }
359 
360 //------------------------------------------------------------------------------
getDamage() const361 int sUnitData::getDamage() const
362 {
363 	return damage;
364 }
365 
366 //------------------------------------------------------------------------------
setDamage(int value)367 void sUnitData::setDamage (int value)
368 {
369 	std::swap (damage, value);
370 	if (damage != value) damageChanged();
371 }
372 
373 //------------------------------------------------------------------------------
getArmor() const374 int sUnitData::getArmor() const
375 {
376 	return armor;
377 }
378 
379 //------------------------------------------------------------------------------
setArmor(int value)380 void sUnitData::setArmor (int value)
381 {
382 	std::swap (armor, value);
383 	if (armor != value) armorChanged();
384 }
385 
386 //------------------------------------------------------------------------------
getStoredResources() const387 int sUnitData::getStoredResources() const
388 {
389 	return storageResCur;
390 }
391 
392 //------------------------------------------------------------------------------
setStoredResources(int value)393 void sUnitData::setStoredResources (int value)
394 {
395 	value = std::max (std::min (value, storageResMax), 0);
396 	std::swap (storageResCur, value);
397 	if (storageResCur != value) storedResourcesChanged();
398 }
399 
400 //------------------------------------------------------------------------------
getStoredUnits() const401 int sUnitData::getStoredUnits() const
402 {
403 	return storageUnitsCur;
404 }
405 
406 //------------------------------------------------------------------------------
setStoredUnits(int value)407 void sUnitData::setStoredUnits (int value)
408 {
409 	value = std::max (std::min (value, storageUnitsMax), 0);
410 	std::swap (storageUnitsCur, value);
411 	if (storageUnitsCur != value) storedUnitsChanged();
412 }
413