OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TileEngine.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_TILEENGINE_H
20 #define OPENXCOM_TILEENGINE_H
21 
22 #include <vector>
23 #include "Position.h"
24 #include "../Ruleset/RuleItem.h"
25 #include <SDL.h>
26 
27 namespace OpenXcom
28 {
29 
30 class SavedBattleGame;
31 class BattleUnit;
32 class BattleItem;
33 class Tile;
34 struct BattleAction;
35 
41 {
42 private:
43  static const int MAX_VIEW_DISTANCE = 20;
44  static const int MAX_VOXEL_VIEW_DISTANCE = MAX_VIEW_DISTANCE * 16;
45  static const int MAX_DARKNESS_TO_SEE_UNITS = 9;
46  SavedBattleGame *_save;
47  std::vector<Uint16> *_voxelData;
48  static const int heightFromCenter[11];
49  void addLight(const Position &center, int power, int layer);
50  int blockage(Tile *tile, const int part, ItemDamageType type, int direction = -1, bool checkingFromOrigin = false);
51  bool _personalLighting;
52 public:
54  TileEngine(SavedBattleGame *save, std::vector<Uint16> *voxelData);
56  ~TileEngine();
58  void calculateSunShading();
60  void calculateSunShading(Tile *tile);
62  bool calculateFOV(BattleUnit *unit);
64  void calculateFOV(const Position &position);
66  bool checkReactionFire(BattleUnit *unit);
70  void calculateUnitLighting();
72  BattleUnit *hit(const Position &center, int power, ItemDamageType type, BattleUnit *unit);
74  void explode(const Position &center, int power, ItemDamageType type, int maxRadius, BattleUnit *unit = 0);
78  int unitOpensDoor(BattleUnit *unit, bool rClick = false, int dir = -1);
80  int closeUfoDoors();
82  int calculateLine(const Position& origin, const Position& target, bool storeTrajectory, std::vector<Position> *trajectory, BattleUnit *excludeUnit, bool doVoxelCheck = true, bool onlyVisible = false, BattleUnit *excludeAllBut = 0);
84  int calculateParabola(const Position& origin, const Position& target, bool storeTrajectory, std::vector<Position> *trajectory, BattleUnit *excludeUnit, double curvature, const Position delta);
88  bool visible(BattleUnit *currentUnit, Tile *tile);
92  int distance(const Position &pos1, const Position &pos2) const;
94  int distanceSq(const Position &pos1, const Position &pos2, bool considerZ = true) const;
96  int horizontalBlockage(Tile *startTile, Tile *endTile, ItemDamageType type);
98  int verticalBlockage(Tile *startTile, Tile *endTile, ItemDamageType type);
100  bool psiAttack(BattleAction *action);
102  Tile *applyGravity(Tile *t);
104  bool validMeleeRange(BattleUnit *attacker, BattleUnit *target, int dir);
106  bool validMeleeRange(Position pos, int direction, BattleUnit *attacker, BattleUnit *target, Position *dest);
108  int faceWindow(const Position &position);
110  int checkVoxelExposure(Position *originVoxel, Tile *tile, BattleUnit *excludeUnit, BattleUnit *excludeAllBut);
112  bool canTargetUnit(Position *originVoxel, Tile *tile, Position *scanVoxel, BattleUnit *excludeUnit, BattleUnit *potentialUnit = 0);
114  bool canTargetTile(Position *originVoxel, Tile *tile, int part, Position *scanVoxel, BattleUnit *excludeUnit);
116  int castedShade(const Position& voxel);
118  bool isVoxelVisible(const Position& voxel);
120  int voxelCheck(const Position& voxel, BattleUnit *excludeUnit, bool excludeAllUnits = false, bool onlyVisible = false, BattleUnit *excludeAllBut = 0);
122  bool detonate(Tile* tile);
124  bool validateThrow(BattleAction &action, Position originVoxel, Position targetVoxel, double *curve = 0, int *voxelType = 0);
126  void checkAdjacentDoors(Position pos, int part);
128  std::vector<BattleUnit *> getSpottingUnits(BattleUnit* unit);
130  BattleUnit* getReactor(std::vector<BattleUnit *> spotters, BattleUnit *unit);
132  bool canMakeSnap(BattleUnit *unit, BattleUnit *target);
134  bool tryReactionSnap(BattleUnit *unit, BattleUnit *target);
136  void recalculateFOV();
138  int getDirectionTo(const Position &origin, const Position &target) const;
140  Position getOriginVoxel(BattleAction &action, Tile *tile);
142  void setDangerZone(Position pos, int radius, BattleUnit *unit);
143 
144 };
145 
146 }
147 
148 #endif
bool canTargetUnit(Position *originVoxel, Tile *tile, Position *scanVoxel, BattleUnit *excludeUnit, BattleUnit *potentialUnit=0)
Checks validity for targetting a unit.
Definition: TileEngine.cpp:532
A utility class that modifies tile properties on a battlescape map.
Definition: TileEngine.h:40
int castedShade(const Position &voxel)
Calculates the z voxel for shadows.
Definition: TileEngine.cpp:2245
void togglePersonalLighting()
Turn XCom soldier's personal lighting on or off.
Definition: TileEngine.cpp:2381
bool canMakeSnap(BattleUnit *unit, BattleUnit *target)
Checks validity of a snap shot to this position.
Definition: TileEngine.cpp:909
int calculateLine(const Position &origin, const Position &target, bool storeTrajectory, std::vector< Position > *trajectory, BattleUnit *excludeUnit, bool doVoxelCheck=true, bool onlyVisible=false, BattleUnit *excludeAllBut=0)
Calculates a line trajectory.
Definition: TileEngine.cpp:2020
void explode(const Position &center, int power, ItemDamageType type, int maxRadius, BattleUnit *unit=0)
Handles explosions.
Definition: TileEngine.cpp:1105
bool psiAttack(BattleAction *action)
Attempts a panic or mind control action.
Definition: TileEngine.cpp:2420
Definition: BattlescapeGame.h:45
int closeUfoDoors()
Closes ufo doors.
Definition: TileEngine.cpp:1983
bool isVoxelVisible(const Position &voxel)
Checks the visibility of a given voxel.
Definition: TileEngine.cpp:2274
int verticalBlockage(Tile *startTile, Tile *endTile, ItemDamageType type)
Checks the vertical blockage of a tile.
Definition: TileEngine.cpp:1446
BattleUnit * hit(const Position &center, int power, ItemDamageType type, BattleUnit *unit)
Handles bullet/weapon hits.
Definition: TileEngine.cpp:1000
int unitOpensDoor(BattleUnit *unit, bool rClick=false, int dir=-1)
Unit opens door?
Definition: TileEngine.cpp:1797
void recalculateFOV()
Recalculates FOV of all units in-game.
Definition: TileEngine.cpp:2730
TileEngine(SavedBattleGame *save, std::vector< Uint16 > *voxelData)
Creates a new TileEngine class.
Definition: TileEngine.cpp:64
Position getOriginVoxel(BattleAction &action, Tile *tile)
determine the origin voxel of a given action.
Definition: TileEngine.cpp:2797
bool visible(BattleUnit *currentUnit, Tile *tile)
Checks visibility of a unit on this tile.
Definition: TileEngine.cpp:388
int getDirectionTo(const Position &origin, const Position &target) const
Get direction to a certain point.
Definition: TileEngine.cpp:2747
int faceWindow(const Position &position)
Gets the AI to look through a window.
Definition: TileEngine.cpp:2651
std::vector< BattleUnit * > getSpottingUnits(BattleUnit *unit)
Creates a vector of units that can spot this unit.
Definition: TileEngine.cpp:823
bool tryReactionSnap(BattleUnit *unit, BattleUnit *target)
Tries to perform a reaction snap shot to this location.
Definition: TileEngine.cpp:937
Tile * applyGravity(Tile *t)
Applies gravity to anything that occupy this tile.
Definition: TileEngine.cpp:2480
Tile * checkForTerrainExplosions()
Checks if a destroyed tile starts an explosion.
Definition: TileEngine.cpp:1426
bool validMeleeRange(BattleUnit *attacker, BattleUnit *target, int dir)
Returns melee validity between two units.
Definition: TileEngine.cpp:2581
bool checkReactionFire(BattleUnit *unit)
Checks reaction fire.
Definition: TileEngine.cpp:775
BattleUnit * getReactor(std::vector< BattleUnit * > spotters, BattleUnit *unit)
Given a vector of spotters, and a unit, picks the spotter with the highest reaction score...
Definition: TileEngine.cpp:875
void calculateSunShading()
Calculates sun shading of the whole map.
Definition: TileEngine.cpp:79
bool detonate(Tile *tile)
Blows this tile up.
Definition: TileEngine.cpp:1343
void checkAdjacentDoors(Position pos, int part)
Opens any doors this door is connected to.
Definition: TileEngine.cpp:1953
int voxelCheck(const Position &voxel, BattleUnit *excludeUnit, bool excludeAllUnits=false, bool onlyVisible=false, BattleUnit *excludeAllBut=0)
Checks what type of voxel occupies this space.
Definition: TileEngine.cpp:2303
void calculateTerrainLighting()
Recalculates lighting of the battlescape for terrain.
Definition: TileEngine.cpp:115
int distanceSq(const Position &pos1, const Position &pos2, bool considerZ=true) const
Checks the distance squared between two positions.
Definition: TileEngine.cpp:2407
Basic element of which a battle map is build.
Definition: Tile.h:43
Position getSightOriginVoxel(BattleUnit *currentUnit)
Gets the origin voxel of a unit's eyesight.
Definition: TileEngine.cpp:357
int calculateParabola(const Position &origin, const Position &target, bool storeTrajectory, std::vector< Position > *trajectory, BattleUnit *excludeUnit, double curvature, const Position delta)
Calculates a parabola trajectory.
Definition: TileEngine.cpp:2186
void setDangerZone(Position pos, int radius, BattleUnit *unit)
mark a region of the map as "dangerous" for a turn.
Definition: TileEngine.cpp:2872
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:50
void calculateUnitLighting()
Recalculates lighting of the battlescape for units.
Definition: TileEngine.cpp:162
int checkVoxelExposure(Position *originVoxel, Tile *tile, BattleUnit *excludeUnit, BattleUnit *excludeAllBut)
Checks a unit's % exposure on a tile.
Definition: TileEngine.cpp:454
bool validateThrow(BattleAction &action, Position originVoxel, Position targetVoxel, double *curve=0, int *voxelType=0)
Validates a throwing action.
Definition: TileEngine.cpp:2677
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
int horizontalBlockage(Tile *startTile, Tile *endTile, ItemDamageType type)
Checks the horizontal blockage of a tile.
Definition: TileEngine.cpp:1510
bool canTargetTile(Position *originVoxel, Tile *tile, int part, Position *scanVoxel, BattleUnit *excludeUnit)
Check validity for targetting a tile.
Definition: TileEngine.cpp:630
~TileEngine()
Cleans up the TileEngine.
Definition: TileEngine.cpp:71
int distance(const Position &pos1, const Position &pos2) const
Checks the distance between two positions.
Definition: TileEngine.cpp:2393
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:58
bool calculateFOV(BattleUnit *unit)
Calculates the field of view from a units view point.
Definition: TileEngine.cpp:227