OpenXcom  1.0
Open-source clone of the original X-Com
Tile.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <list>
21 #include <vector>
22 #include "../Battlescape/Position.h"
23 #include "../Mod/MapData.h"
24 #include "BattleUnit.h"
25 
26 #include <SDL_types.h> // for Uint8
27 
28 namespace OpenXcom
29 {
30 
31 class Surface;
32 class MapData;
33 class BattleUnit;
34 class BattleItem;
35 class RuleInventory;
36 class Particle;
37 
42 class Tile
43 {
44 public:
45  static struct SerializationKey
46  {
47  // how many bytes to store for each variable or each member of array of the same name
48  Uint8 index; // for indexing the actual tile array
49  Uint8 _mapDataSetID;
50  Uint8 _mapDataID;
51  Uint8 _smoke;
52  Uint8 _fire;
53  Uint8 boolFields;
54  Uint32 totalBytes; // per structure, including any data not mentioned here and accounting for all array members!
56 
57  static const int NOT_CALCULATED = -1;
58 
59 protected:
60  static const int LIGHTLAYERS = 3;
61  MapData *_objects[4];
62  int _mapDataID[4];
63  int _mapDataSetID[4];
64  int _currentFrame[4];
65  bool _discovered[3];
66  int _light[LIGHTLAYERS], _lastLight[LIGHTLAYERS];
67  int _smoke;
68  int _fire;
69  int _explosive;
70  int _explosiveType;
71  Position _pos;
72  BattleUnit *_unit;
73  std::vector<BattleItem *> _inventory;
74  int _animationOffset;
75  int _markerColor;
76  int _visible;
77  int _preview;
78  int _TUMarker;
79  int _overlaps;
80  bool _danger;
81  std::list<Particle*> _particles;
82  int _obstacle;
83 public:
85  Tile(Position pos);
87  ~Tile();
89  void load(const YAML::Node &node);
91  void loadBinary(Uint8 *buffer, Tile::SerializationKey& serializationKey);
93  YAML::Node save() const;
95  void saveBinary(Uint8** buffer) const;
96 
102  MapData *getMapData(TilePart part) const
103  {
104  return _objects[part];
105  }
106 
108  void setMapData(MapData *dat, int mapDataID, int mapDataSetID, TilePart part);
110  void getMapData(int *mapDataID, int *mapDataSetID, TilePart part) const;
112  bool isVoid() const;
114  int getTUCost(int part, MovementType movementType) const;
116  bool hasNoFloor(Tile *tileBelow) const;
118  bool isBigWall() const;
120  int getTerrainLevel() const;
121 
127  {
128  return _pos;
129  }
130 
132  int getFootstepSound(Tile *tileBelow) const;
134  int openDoor(TilePart part, BattleUnit *Unit = 0, BattleActionType reserve = BA_NONE);
135 
142  bool isUfoDoorOpen(TilePart tp) const
143  {
144  int part = (int)tp;
145  return (_objects[part] && _objects[part]->isUFODoor() && _currentFrame[part] != 0);
146  }
147 
149  int closeUfoDoor();
151  void setDiscovered(bool flag, int part);
153  bool isDiscovered(int part) const;
155  void resetLight(int layer);
157  void addLight(int light, int layer);
159  int getShade() const;
161  bool destroy(TilePart part, SpecialTileType type);
163  bool damage(TilePart part, int power, SpecialTileType type);
165  void setExplosive(int power, int damageType, bool force = false);
167  int getExplosive() const;
169  int getExplosiveType() const;
171  void animate();
173  Surface *getSprite(int part) const;
175  void setUnit(BattleUnit *unit, Tile *tileBelow = 0);
181  {
182  return _unit;
183  }
185  void setFire(int fire);
187  int getFire() const;
189  void addSmoke(int smoke);
191  void setSmoke(int smoke);
193  int getSmoke() const;
195  int getFlammability() const;
197  int getFuel() const;
199  int getFlammability(TilePart part) const;
201  int getFuel(TilePart part) const;
203  void ignite(int power);
205  int getAnimationOffset() const;
207  void addItem(BattleItem *item, RuleInventory *ground);
209  void removeItem(BattleItem *item);
211  int getTopItemSprite();
213  void prepareNewTurn(bool smokeDamage);
215  std::vector<BattleItem *> *getInventory();
217  void setMarkerColor(int color);
219  int getMarkerColor() const;
221  void setVisible(int visibility);
223  int getVisible() const;
225  void setPreview(int dir);
227  int getPreview() const;
229  void setTUMarker(int tu);
231  int getTUMarker() const;
233  int getOverlaps() const;
235  void addOverlap();
237  void setDangerous(bool danger);
239  bool getDangerous() const;
241  void addParticle(Particle *particle);
243  std::list<Particle *> *getParticleCloud();
244 
246  void setObstacle(int part);
248  bool getObstacle(int part) const
249  {
250  return _obstacle & (1 << part);
251  }
253  bool isObstacle(void) const
254  {
255  return _obstacle != 0;
256  }
258  void resetObstacle(void);
259 };
260 
261 }
void setObstacle(int part)
sets single obstacle flag.
Definition: Tile.cpp:998
void addParticle(Particle *particle)
adds a particle to this tile&#39;s array.
Definition: Tile.cpp:981
Definition: Particle.h:26
int getExplosive() const
Get explosive power of this tile.
Definition: Tile.cpp:530
static struct OpenXcom::Tile::SerializationKey serializationKey
How many bytes various fields use in a serialized tile. See header.
Definition: Tile.cpp:38
Surface * getSprite(int part) const
Get object sprites.
Definition: Tile.cpp:666
Tile(Position pos)
Creates a tile.
Definition: Tile.cpp:52
int getFlammability() const
Get flammability.
Definition: Tile.cpp:548
int openDoor(TilePart part, BattleUnit *Unit=0, BattleActionType reserve=BA_NONE)
Open a door, returns the ID, 0(normal), 1(ufo) or -1 if no door opened.
Definition: Tile.cpp:338
void setDangerous(bool danger)
set the danger flag on this tile (so the AI will avoid it).
Definition: Tile.cpp:963
void resetObstacle(void)
reset obstacle flags
Definition: Tile.cpp:1006
int getMarkerColor() const
Get the tile marker color.
Definition: Tile.cpp:884
int getTerrainLevel() const
Get terrain level.
Definition: Tile.cpp:298
void load(const YAML::Node &node)
Load the tile from yaml.
Definition: Tile.cpp:89
void setUnit(BattleUnit *unit, Tile *tileBelow=0)
Set a unit on this tile.
Definition: Tile.cpp:679
int getFire() const
Get fire.
Definition: Tile.cpp:702
void addLight(int light, int layer)
Add light to this tile.
Definition: Tile.cpp:432
void addOverlap()
increment the overlap value on this tile.
Definition: Tile.cpp:955
int getTopItemSprite()
Get top-most item.
Definition: Tile.cpp:791
void removeItem(BattleItem *item)
Remove item.
Definition: Tile.cpp:774
int getOverlaps() const
how many times has this tile been overlapped with smoke/fire (runtime only)
Definition: Tile.cpp:947
bool isObstacle(void) const
does the tile have obstacle flag set for at least one part?
Definition: Tile.h:253
Represents a single item in the battlescape.
Definition: BattleItem.h:37
bool getDangerous() const
check the danger flag on this tile.
Definition: Tile.cpp:972
~Tile()
Cleans up a tile.
Definition: Tile.cpp:75
bool damage(TilePart part, int power, SpecialTileType type)
Damage a tile part.
Definition: Tile.cpp:501
int getAnimationOffset() const
Get fire and smoke animation offset.
Definition: Tile.cpp:753
int getFootstepSound(Tile *tileBelow) const
Gets the floor object footstep sound.
Definition: Tile.cpp:316
bool getObstacle(int part) const
gets single obstacle flag.
Definition: Tile.h:248
bool isBigWall() const
Checks if this tile is a big wall.
Definition: Tile.cpp:286
MapData is the smallest piece of a Battlescape terrain, holding info about a certain object...
Definition: MapData.h:51
int getShade() const
Get the shade amount.
Definition: Tile.cpp:443
void setExplosive(int power, int damageType, bool force=false)
Set a "virtual" explosive on this tile, to detonate later.
Definition: Tile.cpp:517
std::vector< BattleItem * > * getInventory()
Get inventory on this tile.
Definition: Tile.cpp:865
Basic element of which a battle map is build.
Definition: Tile.h:42
void ignite(int power)
attempt to set the tile on fire, sets overlaps to one if successful.
Definition: Tile.cpp:597
bool isUfoDoorOpen(TilePart tp) const
Check if the ufo door is open or opening.
Definition: Tile.h:142
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
int getTUMarker() const
get the number to be displayed for pathfinding preview.
Definition: Tile.cpp:938
void animate()
Animated the tile parts.
Definition: Tile.cpp:624
void setMarkerColor(int color)
Set the tile marker color.
Definition: Tile.cpp:875
bool isDiscovered(int part) const
Gets the black fog of war status of this tile.
Definition: Tile.cpp:411
void addSmoke(int smoke)
Add smoke, increments overlap.
Definition: Tile.cpp:711
void setFire(int fire)
Set fire, does not increment overlaps.
Definition: Tile.cpp:692
void setVisible(int visibility)
Set the tile visible flag.
Definition: Tile.cpp:893
void setTUMarker(int tu)
set the number to be displayed for pathfinding preview.
Definition: Tile.cpp:929
YAML::Node save() const
Saves the tile to yaml.
Definition: Tile.cpp:156
int getSmoke() const
Get smoke.
Definition: Tile.cpp:743
MapData * getMapData(TilePart part) const
Get the MapData pointer of a part of the tile.
Definition: Tile.h:102
int closeUfoDoor()
Close ufo door.
Definition: Tile.cpp:367
int getFuel() const
Get turns to burn.
Definition: Tile.cpp:563
int getPreview() const
retrieve the direction stored by the pathfinding.
Definition: Tile.cpp:920
Easy handling of X-Y-Z coordinates.
Definition: Position.h:28
void prepareNewTurn(bool smokeDamage)
New turn preparations.
Definition: Tile.cpp:811
void loadBinary(Uint8 *buffer, Tile::SerializationKey &serializationKey)
Load the tile from binary buffer in memory.
Definition: Tile.cpp:125
BattleUnit * getUnit() const
Get the (alive) unit on this tile.
Definition: Tile.h:180
void setDiscovered(bool flag, int part)
Sets the black fog of war status of this tile.
Definition: Tile.cpp:388
bool hasNoFloor(Tile *tileBelow) const
Checks if this tile has a floor.
Definition: Tile.cpp:272
bool destroy(TilePart part, SpecialTileType type)
Destroy a tile part.
Definition: Tile.cpp:464
int getExplosiveType() const
Get explosive power of this tile.
Definition: Tile.cpp:539
void saveBinary(Uint8 **buffer) const
Saves the tile to binary.
Definition: Tile.cpp:191
void setMapData(MapData *dat, int mapDataID, int mapDataSetID, TilePart part)
Sets the pointer to the mapdata for a specific part of the tile.
Definition: Tile.cpp:218
void setPreview(int dir)
set the direction (used for path previewing)
Definition: Tile.cpp:911
bool isVoid() const
Gets whether this tile has no objects.
Definition: Tile.cpp:242
int getTUCost(int part, MovementType movementType) const
Get the TU cost to walk over a certain part of the tile.
Definition: Tile.cpp:253
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:59
Position getPosition() const
Gets the tile&#39;s position.
Definition: Tile.h:126
Definition: BaseInfoState.cpp:40
void addItem(BattleItem *item, RuleInventory *ground)
Add item.
Definition: Tile.cpp:763
Represents the static data for a unit that is generated on the battlescape, this includes: HWPs...
Definition: Unit.h:57
void setSmoke(int smoke)
Set smoke, does not increment overlaps.
Definition: Tile.cpp:732
Represents a specific section of the inventory, containing information like available slots and scree...
Definition: RuleInventory.h:42
std::list< Particle * > * getParticleCloud()
gets a pointer to this tile&#39;s particle array.
Definition: Tile.cpp:990
int getVisible() const
Get the tile visible flag.
Definition: Tile.cpp:902
void resetLight(int layer)
Reset light to zero for this tile.
Definition: Tile.cpp:421