OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
OpenXcom::TileEngine Class Reference

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...
 
BattleUnithit (const Position &center, int power, ItemDamageType type, BattleUnit *unit)
 Handles bullet/weapon hits. More...
 
void explode (const Position &center, int power, ItemDamageType type, int maxRadius, BattleUnit *unit=0)
 Handles explosions. More...
 
TilecheckForTerrainExplosions ()
 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...
 
TileapplyGravity (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...
 
BattleUnitgetReactor (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

OpenXcom::TileEngine::TileEngine ( SavedBattleGame save,
std::vector< Uint16 > *  voxelData 
)

Creates a new TileEngine class.

Sets up a TileEngine.

Parameters
savePointer to SavedBattleGame object.
voxelDataList of voxel data.
OpenXcom::TileEngine::~TileEngine ( )

Cleans up the TileEngine.

Deletes the TileEngine.

Member Function Documentation

Tile * OpenXcom::TileEngine::applyGravity ( Tile t)

Applies gravity to anything that occupy this tile.

Applies gravity to a tile.

Causes items and units to drop.

Parameters
tTile.
Returns
Tile where the items end up in eventually.
bool OpenXcom::TileEngine::calculateFOV ( BattleUnit unit)

Calculates the field of view from a units view point.

Calculates line of sight of a soldier.

Parameters
unitUnit to check line of sight of.
Returns
True when new aliens are spotted.
void OpenXcom::TileEngine::calculateFOV ( const Position position)

Calculates the field of view within range of a certain position.

Calculates line of sight of a soldiers within range of the Position (used when terrain has changed, which can reveal new parts of terrain or units).

Parameters
positionPosition of the changed terrain.
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.

Parameters
originOrigin (voxel??).
targetTarget (also voxel??).
storeTrajectoryTrue will store the whole trajectory - otherwise it just stores the last position.
trajectoryA vector of positions in which the trajectory is stored.
excludeUnitExcludes this unit in the collision detection.
doVoxelCheckCheck against voxel or tile blocking? (first one for units visibility and line of fire, second one for terrain visibility).
onlyVisibleSkip invisible units? used in FPS view.
excludeAllBut[Optional] The only unit to be considered for ray hits.
Returns
the objectnumber(0-3) or unit(4) or out of map (5) or -1(hit nothing).
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.

Parameters
originOrign in voxelspace.
targetTarget in voxelspace.
storeTrajectoryTrue will store the whole trajectory - otherwise it just stores the last position.
trajectoryA vector of positions in which the trajectory is stored.
excludeUnitMakes sure the trajectory does not hit the shooter itself.
curvatureHow high the parabola goes: 1.0 is almost straight throw, 3.0 is a very high throw, to throw over a fence for example.
deltaIs the deviation of the angles it should take into account, 0,0,0 is perfection.
Returns
The objectnumber(0-3) or unit(4) or out of map (5) or -1(hit nothing).
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.

Parameters
tileThe 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.

Parameters
unitThe unit to check sight from.
targetThe unit to check sight TO.
Returns
True if the target is valid.
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.

Parameters
originVoxelVoxel of trace origin (gun's barrel).
tileThe tile to check for.
partTile part to check for.
scanVoxelIs returned coordinate of hit.
excludeUnitIs self (not to hit self).
Returns
True if the tile can be targetted.
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.

Parameters
originVoxelVoxel of trace origin (eye or gun's barrel).
tileThe tile to check for.
scanVoxelis returned coordinate of hit.
excludeUnitis self (not to hit self).
potentialUnitis a hypothetical unit to draw a virtual line of fire for AI. if left blank, this function behaves normally.
Returns
True if the unit can be targetted.
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).

Parameters
voxelThe voxel to trace down.
Returns
z coord of "ground".
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.

Parameters
posThe starting position
partThe 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.

Returns
tile on which a explosion occurred
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.

Parameters
unitThe unit to check reaction fire upon.
Returns
True if reaction fire took place.
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.

Parameters
originVoxelVoxel of trace origin (eye or gun's barrel).
tileThe tile to check for.
excludeUnitIs self (not to hit self).
excludeAllBut[Optional] is unit which is the only one to be considered for ray hits.
Returns
Degree of exposure (as percent).
int OpenXcom::TileEngine::closeUfoDoors ( )

Closes ufo doors.

Returns
Whether doors are closed.
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).

Parameters
tileTile affected.
Returns
True if the objective was destroyed.
int OpenXcom::TileEngine::distance ( const Position pos1,
const Position pos2 
) const

Checks the distance between two positions.

Calculates the distance between 2 points.

Rounded up to first INT.

Parameters
pos1Position of first square.
pos2Position of second square.
Returns
Distance.
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.

Parameters
pos1Position of first square.
pos2Position of second square.
considerZWhether to consider the z coordinate.
Returns
Distance.
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.

Parameters
centerCenter of the explosion in voxelspace.
powerPower of the explosion.
typeThe damage type of the explosion.
maxRadiusThe maximum radius othe explosion.
unitThe unit that caused the explosion.
int OpenXcom::TileEngine::faceWindow ( const Position position)

Gets the AI to look through a window.

Parameters
positionCurrent position.
Returns
Direction or -1 when no window found.
int OpenXcom::TileEngine::getDirectionTo ( const Position origin,
const Position target 
) const

Get direction to a certain point.

Returns the direction from origin to target.

Parameters
originThe origin point of the action.
targetThe target point of the action.
Returns
direction.
Position OpenXcom::TileEngine::getOriginVoxel ( BattleAction action,
Tile tile 
)

determine the origin voxel of a given action.

Gets the origin voxel of a certain action.

Parameters
actionBattle action.
tilePointer to the action tile.
Returns
origin position.
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.

Parameters
spottersThe vector of spotting units.
unitThe unit to check scores against.
Returns
The unit with the highest reactions.
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??

Parameters
currentUnitThe watcher.
Returns
Approximately an eyeball voxel.
std::vector< BattleUnit * > OpenXcom::TileEngine::getSpottingUnits ( BattleUnit unit)

Creates a vector of units that can spot this unit.

Parameters
unitThe unit to check for spotters of.
Returns
A vector of units that can see this unit.
BattleUnit * OpenXcom::TileEngine::hit ( const Position center,
int  power,
ItemDamageType  type,
BattleUnit unit 
)

Handles bullet/weapon hits.

A bullet/weapon hits a voxel.

Parameters
centerCenter of the explosion in voxelspace.
powerPower of the explosion.
typeThe damage type of the explosion.
unitThe unit that caused the explosion.
Returns
The Unit that got hit.
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.

Parameters
startTileThe tile where the power starts.
endTileThe adjacent tile where the power ends.
typeThe type of power/damage.
Returns
Amount of blockage.
bool OpenXcom::TileEngine::isVoxelVisible ( const Position voxel)

Checks the visibility of a given voxel.

Traces voxel visibility.

Parameters
voxelVoxel coordinates.
Returns
True if visible.
bool OpenXcom::TileEngine::psiAttack ( BattleAction action)

Attempts a panic or mind control action.

Parameters
actionPointer to an action.
Returns
Whether it failed or succeeded.
void OpenXcom::TileEngine::setDangerZone ( Position  pos,
int  radius,
BattleUnit unit 
)

mark a region of the map as "dangerous" for a turn.

Parameters
posis the epicenter of the explosion.
radiushow far to spread out.
unitthe 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.

Parameters
unitThe unit to check sight from.
targetThe unit to check sight TO.
Returns
True if the action should (theoretically) succeed.
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.

Parameters
unitUnit.
rClickWhether the player right clicked.
dirDirection.
Returns
-1 there is no door, you can walk through; 0 normal door opened, make a squeaky sound and you can walk through; 1 ufo door is starting to open, make a whoosh sound, don't walk through; 3 ufo door is still opening, don't walk through it yet. (have patience, futuristic technology...) 4 not enough TUs 5 would contravene fire reserve
bool OpenXcom::TileEngine::validateThrow ( BattleAction action,
Position  originVoxel,
Position  targetVoxel,
double *  curve = 0,
int *  voxelType = 0 
)

Validates a throwing action.

Validates a throw action.

Parameters
actionThe action to validate.
originVoxelThe origin point of the action.
targetVoxelThe target point of the action.
curveThe curvature of the throw.
voxelTypeThe type of voxel at which this parabola terminates.
Returns
Validity of action.
bool OpenXcom::TileEngine::validMeleeRange ( BattleUnit attacker,
BattleUnit target,
int  dir 
)

Returns melee validity between two units.

Validates the melee range between two units.

Parameters
attackerThe attacking unit.
targetThe unit we want to attack.
dirDirection to check.
Returns
True when the range is valid.
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.

Parameters
posPosition to check from.
directionDirection to check.
attackerThe attacking unit.
targetThe unit we want to attack, 0 for any unit.
destDestination position.
Returns
True when the range is valid.
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.

Parameters
startTileThe tile where the power starts.
endTileThe adjacent tile where the power ends.
typeThe type of power/damage.
Returns
Amount of blockage of this power.
bool OpenXcom::TileEngine::visible ( BattleUnit currentUnit,
Tile tile 
)

Checks visibility of a unit on this tile.

Checks for an opposing unit on this tile.

Parameters
currentUnitThe watcher.
tileThe tile to check for
Returns
True if visible.
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.

Parameters
voxelThe voxel to check.
excludeUnitDon't do checks on this unit.
excludeAllUnitsDon't do checks on any unit.
onlyVisibleWhether to consider only visible units.
excludeAllButIf set, the only unit to be considered for ray hits.
Returns
The objectnumber(0-3) or unit(4) or out of map (5) or -1 (hit nothing).

The documentation for this class was generated from the following files: