1 /*
2 * Copyright 2010-2014 OpenXcom Developers.
3 *
4 * This file is part of OpenXcom.
5 *
6 * OpenXcom is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OpenXcom is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "MapData.h"
20
21 namespace OpenXcom
22 {
23
24 /**
25 * Creates a new Map Data Object.
26 * @param dataset The dataset this object belongs to.
27 */
MapData(MapDataSet * dataset)28 MapData::MapData(MapDataSet *dataset) : _dataset(dataset), _specialType(TILE),
29 _isUfoDoor(false), _stopLOS(false), _isNoFloor(false), _isGravLift(false), _isDoor(false), _blockFire(false), _blockSmoke(false), _baseModule(false),
30 _yOffset(0), _TUWalk(0), _TUFly(0), _TUSlide(0), _terrainLevel(0), _footstepSound(0), _dieMCD(0), _altMCD(0), _objectType(0), _lightSource(0),
31 _armor(0), _flammable(0), _fuel(0), _explosive(0), _bigWall(0), _miniMapIndex(0)
32 {
33 std::fill_n(_sprite, 8, 0);
34 std::fill_n(_block, 6, 0);
35 std::fill_n(_loftID, 12, 0);
36 }
37
38 /**
39 * Destroys the object.
40 */
~MapData()41 MapData::~MapData()
42 {
43
44 }
45
46 /* Explicit storage for MapData constants. */
47 const int MapData::O_FLOOR = 0;
48 const int MapData::O_WESTWALL = 1;
49 const int MapData::O_NORTHWALL = 2;
50 const int MapData::O_OBJECT = 3;
51
52 /**
53 * Gets the dataset this object belongs to.
54 * @return Pointer to MapDataSet.
55 */
getDataset() const56 MapDataSet *MapData::getDataset() const
57 {
58 return _dataset;
59 }
60
61 /**
62 * Gets the sprite index.
63 * @param frameID Animation frame 0-7.
64 * @return The original sprite index.
65 */
getSprite(int frameID) const66 int MapData::getSprite(int frameID) const
67 {
68 return _sprite[frameID];
69 }
70
71 /**
72 * Sets the sprite index for a certain frame.
73 * @param frameID Animation frame
74 * @param value The sprite index in the surfaceset of the mapdataset.
75 */
setSprite(int frameID,int value)76 void MapData::setSprite(int frameID, int value)
77 {
78 _sprite[frameID] = value;
79 }
80
81 /**
82 * Gets whether this is an animated ufo door.
83 * @return True if this is an animated ufo door.
84 */
isUFODoor() const85 bool MapData::isUFODoor() const
86 {
87 return _isUfoDoor;
88 }
89
90 /**
91 * Gets whether this is a floor.
92 * @return True if this is a floor.
93 */
isNoFloor() const94 bool MapData::isNoFloor() const
95 {
96 return _isNoFloor;
97 }
98
99 /**
100 * Gets whether this is a big wall, which blocks all surrounding paths.
101 *
102 * Return value key:
103 * 0: not a bigWall
104 * 1: regular bigWall
105 * 2: allows movement in ne/sw direction
106 * 3: allows movement in nw/se direction
107 * 4: acts as a west wall
108 * 5: acts as a north wall
109 * 6: acts as an east wall
110 * 7: acts as a south wall
111 * 8: acts as a south and east wall.
112 * @return An integer representing what kind of bigwall this is.
113 */
getBigWall() const114 int MapData::getBigWall() const
115 {
116 if (_terrainLevel < 0) return 0; // this is a hack for eg. Skyranger Ramps
117 return _bigWall;
118 }
119
120 /**
121 * Gets whether this is a normal door.
122 * @return True if this is a normal door.
123 */
isDoor() const124 bool MapData::isDoor() const
125 {
126 return _isDoor;
127 }
128
129 /**
130 * Gets whether this is a grav lift.
131 * @return True if this is a grav lift.
132 */
isGravLift() const133 bool MapData::isGravLift() const
134 {
135 return _isGravLift;
136 }
137
138 /**
139 * Sets all kinds of flags.
140 * @param isUfoDoor True if this is a ufo door.
141 * @param stopLOS True if this stops line of sight.
142 * @param isNoFloor True if this is a floor.
143 * @param bigWall True if this is a bigWall.
144 * @param isGravLift True if this is a grav lift.
145 * @param isDoor True if this is a normal door.
146 * @param blockFire True if this blocks fire.
147 * @param blockSmoke True if this blocks smoke.
148 * @param baseModule True if this is a base module item.
149 */
setFlags(bool isUfoDoor,bool stopLOS,bool isNoFloor,int bigWall,bool isGravLift,bool isDoor,bool blockFire,bool blockSmoke,bool baseModule)150 void MapData::setFlags(bool isUfoDoor, bool stopLOS, bool isNoFloor, int bigWall, bool isGravLift, bool isDoor, bool blockFire, bool blockSmoke, bool baseModule)
151 {
152 _isUfoDoor = isUfoDoor;
153 _stopLOS = stopLOS;
154 _isNoFloor = isNoFloor;
155 _bigWall = bigWall;
156 _isGravLift = isGravLift;
157 _isDoor = isDoor;
158 _blockFire = blockFire;
159 _blockSmoke = blockSmoke;
160 _baseModule = baseModule;
161 }
162
163 /**
164 * Gets the amount of blockage of a certain type.
165 * @param type Type.
166 * @return The blockage (0-255).
167 */
getBlock(ItemDamageType type) const168 int MapData::getBlock(ItemDamageType type) const
169 {
170 switch (type)
171 {
172 case DT_NONE:
173 return _block[1];
174 case DT_SMOKE:
175 return _block[3];
176 case DT_HE:
177 case DT_IN:
178 case DT_STUN:
179 return _block[2];
180 default:
181 break;
182 }
183
184 return 0;
185 }
186
187 /**
188 * Sets the amount of blockage for all types.
189 * @param lightBlock The light blockage.
190 * @param visionBlock The vision blockage.
191 * @param HEBlock The high explosive blockage.
192 * @param smokeBlock The smoke blockage.
193 * @param fireBlock The fire blockage.
194 * @param gasBlock The gas blockage.
195 */
setBlockValue(int lightBlock,int visionBlock,int HEBlock,int smokeBlock,int fireBlock,int gasBlock)196 void MapData::setBlockValue(int lightBlock, int visionBlock, int HEBlock, int smokeBlock, int fireBlock, int gasBlock)
197 {
198 _block[0] = lightBlock; // not used...
199 _block[1] = visionBlock==1?255:0;
200 _block[2] = HEBlock;
201 _block[3] = smokeBlock==1?256:0;
202 _block[4] = fireBlock;
203 _block[5] = gasBlock;
204 }
205
206 /**
207 * Sets the amount of HE blockage.
208 * @param HEBlock The high explosive blockage.
209 */
setHEBlock(int HEBlock)210 void MapData::setHEBlock(int HEBlock)
211 {
212 _block[2] = HEBlock;
213 }
214
215 /**
216 * Gets the Y offset for drawing.
217 * @return The height in pixels.
218 */
getYOffset() const219 int MapData::getYOffset() const
220 {
221 return _yOffset;
222 }
223
224 /**
225 * Sets the offset on the Y axis for drawing this object.
226 * @param value The offset.
227 */
setYOffset(int value)228 void MapData::setYOffset(int value)
229 {
230 _yOffset = value;
231 }
232
233 /**
234 * Gets info about special tile types.
235 * @return The special tile type.
236 */
getSpecialType() const237 SpecialTileType MapData::getSpecialType() const
238 {
239 return _specialType;
240 }
241
242 /**
243 * Gets the type of object.
244 * @return The object type (0-3).
245 */
getObjectType() const246 int MapData::getObjectType() const
247 {
248 return _objectType;
249 }
250
251 /**
252 * Sets a special tile type and object type.
253 * @param value Special tile type.
254 * @param otype Object type.
255 */
setSpecialType(int value,int otype)256 void MapData::setSpecialType(int value, int otype)
257 {
258 _specialType = (SpecialTileType)value;
259 _objectType = otype;
260 }
261
262 /**
263 * Gets the TU cost to walk over the object.
264 * @param movementType The movement type.
265 * @return The TU cost.
266 */
getTUCost(MovementType movementType) const267 int MapData::getTUCost(MovementType movementType) const
268 {
269 switch (movementType)
270 {
271 case MT_WALK:
272 return _TUWalk;
273 break;
274 case MT_FLY:
275 return _TUFly;
276 break;
277 case MT_SLIDE:
278 return _TUSlide;
279 break;
280 }
281 return 0;
282 }
283
284 /**
285 * Sets the TU cost to move over the object.
286 * @param walk The walking TU cost.
287 * @param fly The flying TU cost.
288 * @param slide The sliding TU cost.
289 */
setTUCosts(int walk,int fly,int slide)290 void MapData::setTUCosts(int walk, int fly, int slide)
291 {
292 _TUWalk = walk;
293 _TUFly = fly;
294 _TUSlide = slide;
295 }
296
297 /**
298 * Adds this to the graphical Y offset of units or objects on this tile.
299 * @return The Y offset.
300 */
getTerrainLevel() const301 int MapData::getTerrainLevel() const
302 {
303 return _terrainLevel;
304 }
305
306 /**
307 * Sets the Y offset for units/objects on this tile.
308 * @param value The Y offset.
309 */
setTerrainLevel(int value)310 void MapData::setTerrainLevel(int value)
311 {
312 _terrainLevel = value;
313 }
314
315 /**
316 * Gets the index to the footstep sound.
317 * @return The sound ID.
318 */
getFootstepSound() const319 int MapData::getFootstepSound() const
320 {
321 return _footstepSound;
322 }
323
324 /**
325 * Sets the index to the footstep sound.
326 * @param value The sound ID.
327 */
setFootstepSound(int value)328 void MapData::setFootstepSound(int value)
329 {
330 _footstepSound = value;
331 }
332
333 /**
334 * Gets the alternative object ID.
335 * @return The alternative object ID.
336 */
getAltMCD() const337 int MapData::getAltMCD() const
338 {
339 return _altMCD;
340 }
341
342 /**
343 * Sets the alternative object ID.
344 * @param value The alternative object ID.
345 */
setAltMCD(int value)346 void MapData::setAltMCD(int value)
347 {
348 _altMCD = value;
349 }
350
351 /**
352 * Gets the dead object ID.
353 * @return The dead object ID.
354 */
getDieMCD() const355 int MapData::getDieMCD() const
356 {
357 return _dieMCD;
358 }
359
360 /**
361 * Sets the dead object ID.
362 * @param value The dead object ID.
363 */
setDieMCD(int value)364 void MapData::setDieMCD(int value)
365 {
366 _dieMCD = value;
367 }
368
369 /**
370 * Gets the amount of light the object is emitting.
371 * @return The amount of light emitted.
372 */
getLightSource() const373 int MapData::getLightSource() const
374 {
375 // lamp posts have 1, but they should emit more light
376 if (_lightSource == 1)
377 return 15;
378 else
379 return _lightSource - 1;
380 }
381
382 /**
383 * Sets the amount of light the object is emitting.
384 * @param value The amount of light emitted.
385 */
setLightSource(int value)386 void MapData::setLightSource(int value)
387 {
388 _lightSource = value;
389 }
390
391 /**
392 * Gets the amount of armor.
393 * @return The amount of armor.
394 */
getArmor() const395 int MapData::getArmor() const
396 {
397 return _armor;
398 }
399
400 /**
401 * Sets the amount of armor.
402 * @param value The amount of armor.
403 */
setArmor(int value)404 void MapData::setArmor(int value)
405 {
406 _armor = value;
407 }
408
409 /**
410 * Gets the amount of flammable (how flammable this object is).
411 * @return The amount of flammable.
412 */
getFlammable() const413 int MapData::getFlammable() const
414 {
415 return _flammable;
416 }
417
418 /**
419 * Sets the amount of flammable (how flammable this object is).
420 * @param value The amount of flammable.
421 */
setFlammable(int value)422 void MapData::setFlammable(int value)
423 {
424 _flammable = value;
425 }
426
427 /**
428 * Gets the amount of fuel.
429 * @return The amount of fuel.
430 */
getFuel() const431 int MapData::getFuel() const
432 {
433 return _fuel;
434 }
435
436 /**
437 * Sets the amount of fuel.
438 * @param value The amount of fuel.
439 */
setFuel(int value)440 void MapData::setFuel(int value)
441 {
442 _fuel = value;
443 }
444
445 /**
446 * Gets the loft index for a certain layer.
447 * @param layer The layer.
448 * @return The loft index.
449 */
getLoftID(int layer) const450 int MapData::getLoftID(int layer) const
451 {
452 return _loftID[layer];
453 }
454
455 /**
456 * Sets the loft index for a certain layer.
457 * @param loft The loft index.
458 * @param layer The layer.
459 */
setLoftID(int loft,int layer)460 void MapData::setLoftID(int loft, int layer)
461 {
462 _loftID[layer] = loft;
463 }
464
465 /**
466 * Gets the amount of explosive.
467 * @return The amount of explosive.
468 */
getExplosive() const469 int MapData::getExplosive() const
470 {
471 return _explosive;
472 }
473
474 /**
475 * Sets the amount of explosive.
476 * @param value The amount of explosive.
477 */
setExplosive(int value)478 void MapData::setExplosive(int value)
479 {
480 _explosive = value;
481 }
482
483 /**
484 * Sets the SCANG.DAT index for minimap.
485 * @param i The minimap index.
486 */
setMiniMapIndex(unsigned short i)487 void MapData::setMiniMapIndex(unsigned short i)
488 {
489 _miniMapIndex = i;
490 }
491
492 /**
493 * Gets the SCANG.DAT index for minimap.
494 * @return The minimap index.
495 */
getMiniMapIndex() const496 unsigned short MapData::getMiniMapIndex() const
497 {
498 return _miniMapIndex;
499 }
500
501 /**
502 * Sets the bigWall value.
503 * @param bigWall The new bigWall value.
504 */
setBigWall(const int bigWall)505 void MapData::setBigWall(const int bigWall)
506 {
507 _bigWall = bigWall;
508 }
509
510 /**
511 * Sets the TUWalk value.
512 * @param TUWalk The new TUWalk value.
513 */
setTUWalk(const int TUWalk)514 void MapData::setTUWalk(const int TUWalk)
515 {
516 _TUWalk = TUWalk;
517 }
518
519 /**
520 * Sets the TUFly value.
521 * @param TUFly The new TUFly value.
522 */
setTUFly(const int TUFly)523 void MapData::setTUFly(const int TUFly)
524 {
525 _TUFly = TUFly;
526 }
527
528 /**
529 * Sets the TUSlide value.
530 * @param TUSlide The new TUSlide value.
531 */
setTUSlide(const int TUSlide)532 void MapData::setTUSlide(const int TUSlide)
533 {
534 _TUSlide = TUSlide;
535 }
536
537 /**
538 * check if this is an xcom base object.
539 * @return if it is a base object.
540 */
isBaseModule()541 bool MapData::isBaseModule()
542 {
543 return _baseModule;
544 }
545
546 /**
547 * set the "no floor" flag.
548 * @param isNoFloor set the flag to THIS.
549 */
setNoFloor(bool isNoFloor)550 void MapData::setNoFloor(bool isNoFloor)
551 {
552 _isNoFloor = isNoFloor;
553 }
554 }
555