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 (const 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 (const Position ¢er, int power, ItemDamageType type, BattleUnit *unit) |
Handles bullet/weapon hits. More... | |
void | explode (const Position ¢er, 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 (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. More... | |
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. 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 (const Position &pos1, const Position &pos2) const |
Checks the distance between two positions. More... | |
int | distanceSq (const Position &pos1, const Position &pos2, bool considerZ=true) const |
Checks the distance squared between two positions. More... | |
int | horizontalBlockage (Tile *startTile, Tile *endTile, ItemDamageType type) |
Checks the horizontal blockage of a tile. More... | |
int | verticalBlockage (Tile *startTile, Tile *endTile, ItemDamageType type) |
Checks the vertical blockage of a tile. More... | |
bool | psiAttack (BattleAction *action) |
Attempts a panic or mind control action. 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 (Position pos, int direction, BattleUnit *attacker, BattleUnit *target, Position *dest) |
Returns validity of a melee attack from a given position. More... | |
int | faceWindow (const 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, BattleUnit *potentialUnit=0) |
Checks validity for targetting a unit. More... | |
bool | canTargetTile (Position *originVoxel, Tile *tile, int part, Position *scanVoxel, BattleUnit *excludeUnit) |
Check validity for targetting a tile. More... | |
int | castedShade (const Position &voxel) |
Calculates the z voxel for shadows. More... | |
bool | isVoxelVisible (const Position &voxel) |
Checks the visibility of a given voxel. More... | |
int | voxelCheck (const Position &voxel, BattleUnit *excludeUnit, bool excludeAllUnits=false, bool onlyVisible=false, BattleUnit *excludeAllBut=0) |
Checks what type of voxel occupies this space. More... | |
bool | detonate (Tile *tile) |
Blows this tile up. More... | |
bool | validateThrow (BattleAction &action, Position originVoxel, Position targetVoxel, double *curve=0, int *voxelType=0) |
Validates a throwing action. More... | |
void | checkAdjacentDoors (Position pos, int part) |
Opens any doors this door is connected to. More... | |
std::vector< BattleUnit * > | getSpottingUnits (BattleUnit *unit) |
Creates a vector of units that can spot this unit. More... | |
BattleUnit * | getReactor (std::vector< BattleUnit * > spotters, BattleUnit *unit) |
Given a vector of spotters, and a unit, picks the spotter with the highest reaction score. More... | |
bool | canMakeSnap (BattleUnit *unit, BattleUnit *target) |
Checks validity of a snap shot to this position. More... | |
bool | tryReactionSnap (BattleUnit *unit, BattleUnit *target) |
Tries to perform a reaction snap shot to this location. More... | |
void | recalculateFOV () |
Recalculates FOV of all units in-game. | |
int | getDirectionTo (const Position &origin, const 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 (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 | ( | const Position & | position | ) |
int OpenXcom::TileEngine::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.
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 | ( | const Position & | origin, |
const 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 | Orign 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.
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::canMakeSnap | ( | 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::canTargetTile | ( | Position * | originVoxel, |
Tile * | tile, | ||
int | part, | ||
Position * | scanVoxel, | ||
BattleUnit * | excludeUnit | ||
) |
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). |
bool OpenXcom::TileEngine::canTargetUnit | ( | Position * | originVoxel, |
Tile * | tile, | ||
Position * | scanVoxel, | ||
BattleUnit * | excludeUnit, | ||
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). |
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 | ( | const 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 | ( | Position | pos, |
int | 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.
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 7 objects (6 box sides and the object inside).
tile | Tile affected. |
int OpenXcom::TileEngine::distanceSq | ( | const Position & | pos1, |
const Position & | pos2, | ||
bool | considerZ = true |
||
) | const |
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 | ( | const 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 | ( | const 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< BattleUnit * > | spotters, |
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< BattleUnit * > 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 | ( | const 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 | ||
) |
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 | ( | const Position & | voxel | ) |
Checks the visibility of a given voxel.
Traces voxel visibility.
voxel | Voxel coordinates. |
bool OpenXcom::TileEngine::psiAttack | ( | BattleAction * | action | ) |
Attempts a panic or mind control action.
action | Pointer to an action. |
void OpenXcom::TileEngine::setDangerZone | ( | 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::tryReactionSnap | ( | BattleUnit * | unit, |
BattleUnit * | target | ||
) |
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 |
||
) |
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 | ( | Position | pos, |
int | direction, | ||
BattleUnit * | attacker, | ||
BattleUnit * | target, | ||
Position * | dest | ||
) |
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 | ||
) |
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.
Can cross more than one level. Only floor tiles are taken into account.
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 |
int OpenXcom::TileEngine::voxelCheck | ( | const 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. |