OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tile.h
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 #ifndef OPENXCOM_TILE_H
20 #define OPENXCOM_TILE_H
21 
22 #include <string>
23 #include <vector>
24 #include "../Battlescape/Position.h"
25 #include "../Ruleset/MapData.h"
26 #include "BattleUnit.h"
27 
28 #include <SDL_types.h> // for Uint8
29 
30 namespace OpenXcom
31 {
32 
33 class Surface;
34 class MapData;
35 class BattleUnit;
36 class BattleItem;
37 class RuleInventory;
38 
43 class Tile
44 {
45 public:
46  static struct SerializationKey
47  {
48  // how many bytes to store for each variable or each member of array of the same name
49  Uint8 index; // for indexing the actual tile array
50  Uint8 _mapDataSetID;
51  Uint8 _mapDataID;
52  Uint8 _smoke;
53  Uint8 _fire;
54  Uint8 boolFields;
55  Uint32 totalBytes; // per structure, including any data not mentioned here and accounting for all array members!
57 
58  static const int NOT_CALCULATED = -1;
59 
60 protected:
61  static const int LIGHTLAYERS = 3;
62  MapData *_objects[4];
63  int _mapDataID[4];
64  int _mapDataSetID[4];
65  int _currentFrame[4];
66  bool _discovered[3];
67  int _light[LIGHTLAYERS], _lastLight[LIGHTLAYERS];
68  int _smoke;
69  int _fire;
70  int _explosive;
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 public:
83  Tile(const Position& pos);
85  ~Tile();
87  void load(const YAML::Node &node);
89  void loadBinary(Uint8 *buffer, Tile::SerializationKey& serializationKey);
91  YAML::Node save() const;
93  void saveBinary(Uint8** buffer) const;
94 
100  MapData *getMapData(int part) const
101  {
102  if (0 > part || 3 < part)
103  {
104  return NULL;
105  }
106  return _objects[part];
107  }
108 
110  void setMapData(MapData *dat, int mapDataID, int mapDataSetID, int part);
112  void getMapData(int *mapDataID, int *mapDataSetID, int part) const;
114  bool isVoid() const;
116  int getTUCost(int part, MovementType movementType) const;
118  bool hasNoFloor(Tile *tileBelow) const;
120  bool isBigWall() const;
122  int getTerrainLevel() const;
123 
128  const Position& getPosition() const
129  {
130  return _pos;
131  }
132 
134  int getFootstepSound(Tile *tileBelow) const;
136  int openDoor(int part, BattleUnit *Unit = 0, BattleActionType reserve = BA_NONE);
137 
144  bool isUfoDoorOpen(int part) const
145  {
146  return (_objects[part] && _objects[part]->isUFODoor() && _currentFrame[part] != 0);
147  }
148 
150  int closeUfoDoor();
152  void setDiscovered(bool flag, int part);
154  bool isDiscovered(int part) const;
156  void resetLight(int layer);
158  void addLight(int light, int layer);
160  int getShade() const;
162  bool destroy(int part);
164  bool damage(int part, int power);
166  void setExplosive(int power, bool force = false);
168  int getExplosive() const;
170  void animate();
172  Surface *getSprite(int part) const;
174  void setUnit(BattleUnit *unit, Tile *tileBelow = 0);
180  {
181  return _unit;
182  }
184  void setFire(int fire);
186  int getFire() const;
188  void addSmoke(int smoke);
190  void setSmoke(int smoke);
192  int getSmoke() const;
194  int getFlammability() const;
196  int getFuel() const;
198  void ignite(int power);
200  int getAnimationOffset() const;
202  void addItem(BattleItem *item, RuleInventory *ground);
204  void removeItem(BattleItem *item);
206  int getTopItemSprite();
208  void prepareNewTurn();
210  std::vector<BattleItem *> *getInventory();
212  void setMarkerColor(int color);
214  int getMarkerColor();
216  void setVisible(int visibility);
218  int getVisible();
220  void setPreview(int dir);
222  int getPreview() const;
224  void setTUMarker(int tu);
226  int getTUMarker() const;
228  int getOverlaps() const;
230  void addOverlap();
232  void setDangerous();
234  bool getDangerous();
235 
236 };
237 
238 }
239 
240 #endif
int getFlammability() const
Get flammability.
Definition: Tile.cpp:516
int getShade() const
Get the shade amount.
Definition: Tile.cpp:424
const Position & getPosition() const
Gets the tile's position.
Definition: Tile.h:128
static struct OpenXcom::Tile::SerializationKey serializationKey
How many bytes various fields use in a serialized tile. See header.
Definition: Tile.cpp:36
bool isUfoDoorOpen(int part) const
Check if the ufo door is open or opening.
Definition: Tile.h:144
Tile(const Position &pos)
Creates a tile.
Definition: Tile.cpp:50
int getTerrainLevel() const
Get terrain level.
Definition: Tile.cpp:280
int getFuel() const
Get turns to burn.
Definition: Tile.cpp:536
int getOverlaps() const
how many times has this tile been overlapped with smoke/fire (runtime only)
Definition: Tile.cpp:893
int getExplosive() const
Get explosive power of this tile.
Definition: Tile.cpp:507
bool isVoid() const
Gets whether this tile has no objects.
Definition: Tile.cpp:224
YAML::Node save() const
Saves the tile to yaml.
Definition: Tile.cpp:138
void saveBinary(Uint8 **buffer) const
Saves the tile to binary.
Definition: Tile.cpp:173
void setDangerous()
set the danger flag on this tile (so the AI will avoid it).
Definition: Tile.cpp:909
MapData * getMapData(int part) const
Get the MapData pointer of a part of the tile.
Definition: Tile.h:100
int getFire() const
Get fire.
Definition: Tile.cpp:648
int getTUCost(int part, MovementType movementType) const
Get the TU cost to walk over a certain part of the tile.
Definition: Tile.cpp:235
void load(const YAML::Node &node)
Load the tile from yaml.
Definition: Tile.cpp:82
bool destroy(int part)
Destroy a tile part.
Definition: Tile.cpp:444
int getSmoke() const
Get smoke.
Definition: Tile.cpp:689
void setUnit(BattleUnit *unit, Tile *tileBelow=0)
Set a unit on this tile.
Definition: Tile.cpp:625
void addLight(int light, int layer)
Add light to this tile.
Definition: Tile.cpp:413
bool hasNoFloor(Tile *tileBelow) const
Checks if this tile has a floor.
Definition: Tile.cpp:254
bool damage(int part, int power)
Damage a tile part.
Definition: Tile.cpp:480
void addOverlap()
increment the overlap value on this tile.
Definition: Tile.cpp:901
Surface * getSprite(int part) const
Get object sprites.
Definition: Tile.cpp:612
void setMapData(MapData *dat, int mapDataID, int mapDataSetID, int part)
Sets the pointer to the mapdata for a specific part of the tile.
Definition: Tile.cpp:200
int getAnimationOffset() const
Get fire and smoke animation offset.
Definition: Tile.cpp:699
int getTopItemSprite()
Get top-most item.
Definition: Tile.cpp:737
void removeItem(BattleItem *item)
Remove item.
Definition: Tile.cpp:720
int openDoor(int 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:319
Represents a single item in the battlescape.
Definition: BattleItem.h:39
~Tile()
Cleans up a tile.
Definition: Tile.cpp:73
int getVisible()
Get the tile visible flag.
Definition: Tile.cpp:848
MapData is the smallest piece of a Battlescape terrain, holding info about a certain object...
Definition: MapData.h:52
BattleUnit * getUnit() const
Get the (alive) unit on this tile.
Definition: Tile.h:179
std::vector< BattleItem * > * getInventory()
Get inventory on this tile.
Definition: Tile.cpp:811
Basic element of which a battle map is build.
Definition: Tile.h:43
void ignite(int power)
attempt to set the tile on fire, sets overlaps to one if successful.
Definition: Tile.cpp:555
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
void animate()
Animated the tile parts.
Definition: Tile.cpp:582
void setMarkerColor(int color)
Set the tile marker color.
Definition: Tile.cpp:821
void addSmoke(int smoke)
Add smoke, increments overlap.
Definition: Tile.cpp:657
bool isBigWall() const
Checks if this tile is a big wall.
Definition: Tile.cpp:268
void setFire(int fire)
Set fire, does not increment overlaps.
Definition: Tile.cpp:638
void setVisible(int visibility)
Set the tile visible flag.
Definition: Tile.cpp:839
void setTUMarker(int tu)
set the number to be displayed for pathfinding preview.
Definition: Tile.cpp:875
int getTUMarker() const
get the number to be displayed for pathfinding preview.
Definition: Tile.cpp:884
int getFootstepSound(Tile *tileBelow) const
Gets the floor object footstep sound.
Definition: Tile.cpp:297
bool getDangerous()
check the danger flag on this tile.
Definition: Tile.cpp:918
void setExplosive(int power, bool force=false)
Set a "virtual" explosive on this tile, to detonate later.
Definition: Tile.cpp:495
bool isDiscovered(int part) const
Gets the black fog of war status of this tile.
Definition: Tile.cpp:392
int closeUfoDoor()
Close ufo door.
Definition: Tile.cpp:348
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
void loadBinary(Uint8 *buffer, Tile::SerializationKey &serializationKey)
Load the tile from binary buffer in memory.
Definition: Tile.cpp:111
void setDiscovered(bool flag, int part)
Sets the black fog of war status of this tile.
Definition: Tile.cpp:369
void setPreview(int dir)
set the direction (used for path previewing)
Definition: Tile.cpp:857
int getMarkerColor()
Get the tile marker color.
Definition: Tile.cpp:830
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:58
void addItem(BattleItem *item, RuleInventory *ground)
Add item.
Definition: Tile.cpp:709
Represents the static data for a unit that is generated on the battlescape, this includes: HWPs...
Definition: Unit.h:50
void setSmoke(int smoke)
Set smoke, does not increment overlaps.
Definition: Tile.cpp:678
void prepareNewTurn()
New turn preparations.
Definition: Tile.cpp:757
Represents a specific section of the inventory, containing information like available slots and scree...
Definition: RuleInventory.h:44
int getPreview() const
retrieve the direction stored by the pathfinding.
Definition: Tile.cpp:866
void resetLight(int layer)
Reset light to zero for this tile.
Definition: Tile.cpp:402