![]() |
OpenXcom
1.0
Open-source clone of the original X-Com
|
A utility class that modifies tile properties on a battlescape map. More...
#include <TileEngine.h>
Public Member Functions | |
TileEngine (SavedBattleGame *save, std::vector< Uint16 > *voxelData) | |
Creates a new TileEngine class. More... | |
~TileEngine () | |
Cleans up the TileEngine. More... | |
void | calculateSunShading () |
Calculates sun shading of the whole map. More... | |
void | calculateSunShading (Tile *tile) |
Calculates sun shading of a single tile. More... | |
bool | calculateFOV (BattleUnit *unit) |
Calculates the field of view from a units view point. More... | |
void | calculateFOV (Position position) |
Calculates the field of view within range of a certain position. More... | |
bool | checkReactionFire (BattleUnit *unit) |
Checks reaction fire. More... | |
void | calculateTerrainLighting () |
Recalculates lighting of the battlescape for terrain. More... | |
void | calculateUnitLighting () |
Recalculates lighting of the battlescape for units. More... | |
BattleUnit * | hit (Position center, int power, ItemDamageType type, BattleUnit *unit) |
Handles bullet/weapon hits. More... | |
void | explode (Position center, int power, ItemDamageType type, int maxRadius, BattleUnit *unit=0) |
Handles explosions. More... | |
Tile * | checkForTerrainExplosions () |
Checks if a destroyed tile starts an explosion. More... | |
int | unitOpensDoor (BattleUnit *unit, bool rClick=false, int dir=-1) |
Unit opens door? More... | |
int | closeUfoDoors () |
Closes ufo doors. More... | |
int | calculateLine (Position origin, Position target, bool storeTrajectory, std::vector< Position > *trajectory, BattleUnit *excludeUnit, bool doVoxelCheck=true, bool onlyVisible=false, BattleUnit *excludeAllBut=0) |
Calculates a line trajectory. More... | |
int | calculateParabola (Position origin, Position target, bool storeTrajectory, std::vector< Position > *trajectory, BattleUnit *excludeUnit, double curvature, const Position delta) |
Calculates a parabola trajectory. More... | |
Position | getSightOriginVoxel (BattleUnit *currentUnit) |
Gets the origin voxel of a unit's eyesight. More... | |
bool | visible (BattleUnit *currentUnit, Tile *tile) |
Checks visibility of a unit on this tile. More... | |
void | togglePersonalLighting () |
Turn XCom soldier's personal lighting on or off. More... | |
int | distance (Position pos1, Position pos2) const |
Checks the distance between two positions. More... | |
int | distanceSq (Position pos1, Position pos2, bool considerZ=true) const |
Checks the distance squared between two positions. More... | |
int | horizontalBlockage (Tile *startTile, Tile *endTile, ItemDamageType type, bool skipObject=false) |
Checks the horizontal blockage of a tile. More... | |
int | verticalBlockage (Tile *startTile, Tile *endTile, ItemDamageType type, bool skipObject=false) |
Checks the vertical blockage of a tile. More... | |
Tile * | applyGravity (Tile *t) |
Applies gravity to anything that occupy this tile. More... | |
bool | validMeleeRange (BattleUnit *attacker, BattleUnit *target, int dir) |
Returns melee validity between two units. More... | |
bool | validMeleeRange (const Position &pos, int direction, BattleUnit *attacker, BattleUnit *target, Position *dest, bool preferEnemy=true) |
Returns validity of a melee attack from a given position. More... | |
int | faceWindow (Position position) |
Gets the AI to look through a window. More... | |
int | checkVoxelExposure (Position *originVoxel, Tile *tile, BattleUnit *excludeUnit, BattleUnit *excludeAllBut) |
Checks a unit's % exposure on a tile. More... | |
bool | canTargetUnit (Position *originVoxel, Tile *tile, Position *scanVoxel, BattleUnit *excludeUnit, bool rememberObstacles, BattleUnit *potentialUnit=0) |
Checks validity for targetting a unit. More... | |
bool | canTargetTile (Position *originVoxel, Tile *tile, int part, Position *scanVoxel, BattleUnit *excludeUnit, bool rememberObstacles) |
Check validity for targetting a tile. More... | |
int | castedShade (Position voxel) |
Calculates the z voxel for shadows. More... | |
bool | isVoxelVisible (Position voxel) |
Checks the visibility of a given voxel. More... | |
VoxelType | voxelCheck (Position voxel, BattleUnit *excludeUnit, bool excludeAllUnits=false, bool onlyVisible=false, BattleUnit *excludeAllBut=0) |
Checks what type of voxel occupies this space. More... | |
void | voxelCheckFlush () |
Flushes cache of voxel check. | |
bool | detonate (Tile *tile) |
Blows this tile up. More... | |
bool | validateThrow (BattleAction &action, Position originVoxel, Position targetVoxel, double *curve=0, int *voxelType=0, bool forced=false) |
Validates a throwing action. More... | |
void | checkAdjacentDoors (const Position &pos, TilePart part) |
Opens any doors this door is connected to. More... | |
std::vector< std::pair< BattleUnit *, int > > | getSpottingUnits (BattleUnit *unit) |
Creates a vector of units that can spot this unit. More... | |
BattleUnit * | getReactor (std::vector< std::pair< BattleUnit *, int > > spotters, int &attackType, BattleUnit *unit) |
Given a vector of spotters, and a unit, picks the spotter with the highest reaction score. More... | |
int | determineReactionType (BattleUnit *unit, BattleUnit *target) |
Checks validity of a snap shot to this position. More... | |
bool | tryReaction (BattleUnit *unit, BattleUnit *target, int attackType) |
Tries to perform a reaction snap shot to this location. More... | |
void | recalculateFOV () |
Recalculates FOV of all units in-game. | |
int | getDirectionTo (Position origin, Position target) const |
Get direction to a certain point. More... | |
Position | getOriginVoxel (BattleAction &action, Tile *tile) |
determine the origin voxel of a given action. More... | |
void | setDangerZone (const Position &pos, int radius, BattleUnit *unit) |
mark a region of the map as "dangerous" for a turn. More... | |
A utility class that modifies tile properties on a battlescape map.
This includes lighting, destruction, smoke, fire, fog of war. Note that this function does not handle any sounds or animations.
OpenXcom::TileEngine::TileEngine | ( | SavedBattleGame * | save, |
std::vector< Uint16 > * | voxelData | ||
) |
Creates a new TileEngine class.
Sets up a TileEngine.
save | Pointer to SavedBattleGame object. |
voxelData | List of voxel data. |
OpenXcom::TileEngine::~TileEngine | ( | ) |
Cleans up the TileEngine.
Deletes the TileEngine.
bool OpenXcom::TileEngine::calculateFOV | ( | BattleUnit * | unit | ) |
Calculates the field of view from a units view point.
Calculates line of sight of a soldier.
unit | Unit to check line of sight of. |
void OpenXcom::TileEngine::calculateFOV | ( | Position | position | ) |
int OpenXcom::TileEngine::calculateLine | ( | Position | origin, |
Position | target, | ||
bool | storeTrajectory, | ||
std::vector< Position > * | trajectory, | ||
BattleUnit * | excludeUnit, | ||
bool | doVoxelCheck = true , |
||
bool | onlyVisible = false , |
||
BattleUnit * | excludeAllBut = 0 |
||
) |
Calculates a line trajectory.
Calculates a line trajectory, using bresenham algorithm in 3D.
origin | Origin (voxel??). |
target | Target (also voxel??). |
storeTrajectory | True will store the whole trajectory - otherwise it just stores the last position. |
trajectory | A vector of positions in which the trajectory is stored. |
excludeUnit | Excludes this unit in the collision detection. |
doVoxelCheck | Check against voxel or tile blocking? (first one for units visibility and line of fire, second one for terrain visibility). |
onlyVisible | Skip invisible units? used in FPS view. |
excludeAllBut | [Optional] The only unit to be considered for ray hits. |
int OpenXcom::TileEngine::calculateParabola | ( | Position | origin, |
Position | target, | ||
bool | storeTrajectory, | ||
std::vector< Position > * | trajectory, | ||
BattleUnit * | excludeUnit, | ||
double | curvature, | ||
const Position | delta | ||
) |
Calculates a parabola trajectory.
Calculates a parabola trajectory, used for throwing items.
origin | Origin in voxelspace. |
target | Target in voxelspace. |
storeTrajectory | True will store the whole trajectory - otherwise it just stores the last position. |
trajectory | A vector of positions in which the trajectory is stored. |
excludeUnit | Makes sure the trajectory does not hit the shooter itself. |
curvature | How high the parabola goes: 1.0 is almost straight throw, 3.0 is a very high throw, to throw over a fence for example. |
delta | Is the deviation of the angles it should take into account, 0,0,0 is perfection. |
void OpenXcom::TileEngine::calculateSunShading | ( | ) |
Calculates sun shading of the whole map.
Calculates sun shading for the whole terrain.
void OpenXcom::TileEngine::calculateSunShading | ( | Tile * | tile | ) |
Calculates sun shading of a single tile.
Calculates sun shading for 1 tile.
Sun comes from above and is blocked by floors or objects. TODO: angle the shadow according to the time? - link to Options::globeSeasons (or whatever the realistic lighting one is)
tile | The tile to calculate sun shading for. |
void OpenXcom::TileEngine::calculateTerrainLighting | ( | ) |
Recalculates lighting of the battlescape for terrain.
Recalculates lighting for the terrain: objects,items,fire.
void OpenXcom::TileEngine::calculateUnitLighting | ( | ) |
Recalculates lighting of the battlescape for units.
Recalculates lighting for the units.
bool OpenXcom::TileEngine::canTargetTile | ( | Position * | originVoxel, |
Tile * | tile, | ||
int | part, | ||
Position * | scanVoxel, | ||
BattleUnit * | excludeUnit, | ||
bool | rememberObstacles | ||
) |
Check validity for targetting a tile.
Checks for a tile part available for targeting and what particular voxel.
originVoxel | Voxel of trace origin (gun's barrel). |
tile | The tile to check for. |
part | Tile part to check for. |
scanVoxel | Is returned coordinate of hit. |
excludeUnit | Is self (not to hit self). |
rememberObstacles | Remember obstacles for no LOF indicator? |
bool OpenXcom::TileEngine::canTargetUnit | ( | Position * | originVoxel, |
Tile * | tile, | ||
Position * | scanVoxel, | ||
BattleUnit * | excludeUnit, | ||
bool | rememberObstacles, | ||
BattleUnit * | potentialUnit = 0 |
||
) |
Checks validity for targetting a unit.
Checks for another unit available for targeting and what particular voxel.
originVoxel | Voxel of trace origin (eye or gun's barrel). |
tile | The tile to check for. |
scanVoxel | is returned coordinate of hit. |
excludeUnit | is self (not to hit self). |
rememberObstacles | Remember obstacles for no LOF indicator? |
potentialUnit | is a hypothetical unit to draw a virtual line of fire for AI. if left blank, this function behaves normally. |
int OpenXcom::TileEngine::castedShade | ( | Position | voxel | ) |
Calculates the z voxel for shadows.
Calculates z "grounded" value for a particular voxel (used for projectile shadow).
voxel | The voxel to trace down. |
void OpenXcom::TileEngine::checkAdjacentDoors | ( | const Position & | pos, |
TilePart | part | ||
) |
Opens any doors this door is connected to.
Opens any doors connected to this part at this position, Keeps processing til it hits a non-ufo-door.
pos | The starting position |
part | The part to open, defines which direction to check. |
Tile * OpenXcom::TileEngine::checkForTerrainExplosions | ( | ) |
Checks if a destroyed tile starts an explosion.
Checks for chained explosions.
Chained explosions are explosions which occur after an explosive map object is destroyed. May be due a direct hit, other explosion or fire.
bool OpenXcom::TileEngine::checkReactionFire | ( | BattleUnit * | unit | ) |
Checks reaction fire.
Checks if a sniper from the opposing faction sees this unit.
The unit with the highest reaction score will be compared with the current unit's reaction score. If it's higher, a shot is fired when enough time units, a weapon and ammo are available.
unit | The unit to check reaction fire upon. |
int OpenXcom::TileEngine::checkVoxelExposure | ( | Position * | originVoxel, |
Tile * | tile, | ||
BattleUnit * | excludeUnit, | ||
BattleUnit * | excludeAllBut | ||
) |
Checks a unit's % exposure on a tile.
Checks for how exposed unit is for another unit.
originVoxel | Voxel of trace origin (eye or gun's barrel). |
tile | The tile to check for. |
excludeUnit | Is self (not to hit self). |
excludeAllBut | [Optional] is unit which is the only one to be considered for ray hits. |
int OpenXcom::TileEngine::closeUfoDoors | ( | ) |
Closes ufo doors.
int OpenXcom::TileEngine::determineReactionType | ( | BattleUnit * | unit, |
BattleUnit * | target | ||
) |
Checks validity of a snap shot to this position.
Checks the validity of a snap shot performed here.
unit | The unit to check sight from. |
target | The unit to check sight TO. |
bool OpenXcom::TileEngine::detonate | ( | Tile * | tile | ) |
Blows this tile up.
Applies the explosive power to the tile parts.
This is where the actual destruction takes place. Must affect 9 objects (6 box sides and the object inside plus 2 outer walls).
tile | Tile affected. |
Checks the distance squared between two positions.
Calculates the distance squared between 2 points.
No sqrt(), not floating point math, and sometimes it's all you need.
pos1 | Position of first square. |
pos2 | Position of second square. |
considerZ | Whether to consider the z coordinate. |
void OpenXcom::TileEngine::explode | ( | Position | center, |
int | power, | ||
ItemDamageType | type, | ||
int | maxRadius, | ||
BattleUnit * | unit = 0 |
||
) |
Handles explosions.
HE, smoke and fire explodes in a circular pattern on 1 level only. HE however damages floor tiles of the above level. Not the units on it. HE destroys an object if its armor is lower than the explosive power, then it's HE blockage is applied for further propagation. See http://www.ufopaedia.org/index.php?title=Explosions for more info.
center | Center of the explosion in voxelspace. |
power | Power of the explosion. |
type | The damage type of the explosion. |
maxRadius | The maximum radius othe explosion. |
unit | The unit that caused the explosion. |
int OpenXcom::TileEngine::faceWindow | ( | Position | position | ) |
Gets the AI to look through a window.
position | Current position. |
Get direction to a certain point.
Returns the direction from origin to target.
origin | The origin point of the action. |
target | The target point of the action. |
Position OpenXcom::TileEngine::getOriginVoxel | ( | BattleAction & | action, |
Tile * | tile | ||
) |
determine the origin voxel of a given action.
Gets the origin voxel of a certain action.
action | Battle action. |
tile | Pointer to the action tile. |
BattleUnit * OpenXcom::TileEngine::getReactor | ( | std::vector< std::pair< BattleUnit *, int > > | spotters, |
int & | attackType, | ||
BattleUnit * | unit | ||
) |
Given a vector of spotters, and a unit, picks the spotter with the highest reaction score.
Gets the unit with the highest reaction score from the spotter vector.
spotters | The vector of spotting units. |
unit | The unit to check scores against. |
Position OpenXcom::TileEngine::getSightOriginVoxel | ( | BattleUnit * | currentUnit | ) |
Gets the origin voxel of a unit's eyesight.
Gets the origin voxel of a unit's eyesight (from just one eye or something? Why is it x+7??
currentUnit | The watcher. |
std::vector< std::pair< BattleUnit *, int > > OpenXcom::TileEngine::getSpottingUnits | ( | BattleUnit * | unit | ) |
Creates a vector of units that can spot this unit.
unit | The unit to check for spotters of. |
BattleUnit * OpenXcom::TileEngine::hit | ( | Position | center, |
int | power, | ||
ItemDamageType | type, | ||
BattleUnit * | unit | ||
) |
Handles bullet/weapon hits.
A bullet/weapon hits a voxel.
center | Center of the explosion in voxelspace. |
power | Power of the explosion. |
type | The damage type of the explosion. |
unit | The unit that caused the explosion. |
int OpenXcom::TileEngine::horizontalBlockage | ( | Tile * | startTile, |
Tile * | endTile, | ||
ItemDamageType | type, | ||
bool | skipObject = false |
||
) |
Checks the horizontal blockage of a tile.
Calculates the amount of power that is blocked going from one tile to another on the same level.
startTile | The tile where the power starts. |
endTile | The adjacent tile where the power ends. |
type | The type of power/damage. |
bool OpenXcom::TileEngine::isVoxelVisible | ( | Position | voxel | ) |
Checks the visibility of a given voxel.
Traces voxel visibility.
voxel | Voxel coordinates. |
void OpenXcom::TileEngine::setDangerZone | ( | const Position & | pos, |
int | radius, | ||
BattleUnit * | unit | ||
) |
mark a region of the map as "dangerous" for a turn.
pos | is the epicenter of the explosion. |
radius | how far to spread out. |
unit | the unit that is triggering this action. |
void OpenXcom::TileEngine::togglePersonalLighting | ( | ) |
Turn XCom soldier's personal lighting on or off.
Toggles personal lighting on / off.
bool OpenXcom::TileEngine::tryReaction | ( | BattleUnit * | unit, |
BattleUnit * | target, | ||
int | attackType | ||
) |
Tries to perform a reaction snap shot to this location.
Attempts to perform a reaction snap shot.
unit | The unit to check sight from. |
target | The unit to check sight TO. |
int OpenXcom::TileEngine::unitOpensDoor | ( | BattleUnit * | unit, |
bool | rClick = false , |
||
int | dir = -1 |
||
) |
Unit opens door?
Opens a door (if any) by rightclick, or by walking through it.
The unit has to face in the right direction.
unit | Unit. |
rClick | Whether the player right clicked. |
dir | Direction. |
bool OpenXcom::TileEngine::validateThrow | ( | BattleAction & | action, |
Position | originVoxel, | ||
Position | targetVoxel, | ||
double * | curve = 0 , |
||
int * | voxelType = 0 , |
||
bool | forced = false |
||
) |
Validates a throwing action.
Validates a throw action.
action | The action to validate. |
originVoxel | The origin point of the action. |
targetVoxel | The target point of the action. |
curve | The curvature of the throw. |
voxelType | The type of voxel at which this parabola terminates. |
bool OpenXcom::TileEngine::validMeleeRange | ( | BattleUnit * | attacker, |
BattleUnit * | target, | ||
int | dir | ||
) |
Returns melee validity between two units.
Validates the melee range between two units.
attacker | The attacking unit. |
target | The unit we want to attack. |
dir | Direction to check. |
bool OpenXcom::TileEngine::validMeleeRange | ( | const Position & | pos, |
int | direction, | ||
BattleUnit * | attacker, | ||
BattleUnit * | target, | ||
Position * | dest, | ||
bool | preferEnemy = true |
||
) |
Returns validity of a melee attack from a given position.
Validates the melee range between a tile and a unit.
pos | Position to check from. |
direction | Direction to check. |
attacker | The attacking unit. |
target | The unit we want to attack, 0 for any unit. |
dest | Destination position. |
int OpenXcom::TileEngine::verticalBlockage | ( | Tile * | startTile, |
Tile * | endTile, | ||
ItemDamageType | type, | ||
bool | skipObject = false |
||
) |
Checks the vertical blockage of a tile.
Calculates the amount of power that is blocked going from one tile to another on a different level.
startTile | The tile where the power starts. |
endTile | The adjacent tile where the power ends. |
type | The type of power/damage. |
bool OpenXcom::TileEngine::visible | ( | BattleUnit * | currentUnit, |
Tile * | tile | ||
) |
Checks visibility of a unit on this tile.
Checks for an opposing unit on this tile.
currentUnit | The watcher. |
tile | The tile to check for |
VoxelType OpenXcom::TileEngine::voxelCheck | ( | Position | voxel, |
BattleUnit * | excludeUnit, | ||
bool | excludeAllUnits = false , |
||
bool | onlyVisible = false , |
||
BattleUnit * | excludeAllBut = 0 |
||
) |
Checks what type of voxel occupies this space.
Checks if we hit a voxel.
voxel | The voxel to check. |
excludeUnit | Don't do checks on this unit. |
excludeAllUnits | Don't do checks on any unit. |
onlyVisible | Whether to consider only visible units. |
excludeAllBut | If set, the only unit to be considered for ray hits. |