OpenXcom
1.0
Open-source clone of the original X-Com
|
A utility class that calculates the shortest path between two points on the battlescape map. More...
#include <Pathfinding.h>
Public Member Functions | |
bool | isOnStairs (const Position &startPosition, const Position &endPosition) |
Determines whether the unit is going up a stairs. More... | |
bool | isBlocked (Tile *startTile, Tile *endTile, const int direction, BattleUnit *missileTarget) |
Determines whether or not movement between starttile and endtile is possible in the direction. More... | |
Pathfinding (SavedBattleGame *save) | |
Creates a new Pathfinding class. More... | |
~Pathfinding () | |
Cleans up the Pathfinding. More... | |
void | calculate (BattleUnit *unit, Position endPosition, BattleUnit *missileTarget=0, int maxTUCost=1000) |
Calculates the shortest path. More... | |
int | getStartDirection () |
Checks whether a path is ready and gives the first direction. More... | |
int | dequeuePath () |
Dequeues a direction. More... | |
int | getTUCost (const Position &startPosition, const int direction, Position *endPosition, BattleUnit *unit, BattleUnit *target, bool missile) |
Gets the TU cost to move from 1 tile to the other. More... | |
void | abortPath () |
Aborts the current path. More... | |
bool | getStrafeMove () const |
Gets the strafe move setting. More... | |
bool | validateUpDown (BattleUnit *bu, Position startPosition, const int direction) |
Checks, for the up/down button, if the movement is valid. More... | |
bool | previewPath (bool bRemove=false) |
Previews the path. More... | |
bool | removePreview () |
Removes the path preview. More... | |
void | setUnit (BattleUnit *unit) |
Sets _unit in order to abuse low-level pathfinding functions from outside the class. More... | |
std::vector< int > | findReachable (BattleUnit *unit, int tuMax) |
Gets all reachable tiles, based on cost. More... | |
int | getTotalTUCost () const |
Gets _totalTUCost; finds out whether we can hike somewhere in this turn or not. | |
bool | isPathPreviewed () const |
Gets the path preview setting. More... | |
bool | isModifierUsed () const |
Gets the modifier setting. More... | |
const std::vector< int > & | getPath () |
Gets a reference to the path. More... | |
std::vector< int > | copyPath () const |
Makes a copy to the path. More... | |
Static Public Member Functions | |
static void | directionToVector (const int direction, Position *vector) |
Converts direction to a vector. More... | |
static void | vectorToDirection (const Position &vector, int &dir) |
Converts a vector to a direction. More... | |
A utility class that calculates the shortest path between two points on the battlescape map.
OpenXcom::Pathfinding::Pathfinding | ( | SavedBattleGame * | save | ) |
Creates a new Pathfinding class.
Sets up a Pathfinding.
save | pointer to SavedBattleGame object. |
OpenXcom::Pathfinding::~Pathfinding | ( | ) |
Cleans up the Pathfinding.
Deletes the Pathfinding.
void OpenXcom::Pathfinding::abortPath | ( | ) |
Aborts the current path.
Clears the path vector.
void OpenXcom::Pathfinding::calculate | ( | BattleUnit * | unit, |
Position | endPosition, | ||
BattleUnit * | target = 0 , |
||
int | maxTUCost = 1000 |
||
) |
std::vector< int > OpenXcom::Pathfinding::copyPath | ( | ) | const |
Makes a copy to the path.
Makes a copy of the current path.
int OpenXcom::Pathfinding::dequeuePath | ( | ) |
Dequeues a direction.
Dequeues the next path direction.
Ie returns the direction and removes it from queue.
|
static |
Converts direction to a vector.
Direction starts north = 0 and goes clockwise.
direction | Source direction. |
vector | Pointer to a position (which acts as a vector). |
std::vector< int > OpenXcom::Pathfinding::findReachable | ( | BattleUnit * | unit, |
int | tuMax | ||
) |
Gets all reachable tiles, based on cost.
Locates all tiles reachable to *unit with a TU cost no more than tuMax.
Uses Dijkstra's algorithm.
unit | Pointer to the unit. |
tuMax | The maximum cost of the path to each tile. |
const std::vector< int > & OpenXcom::Pathfinding::getPath | ( | ) |
Gets a reference to the path.
Gets a reference to the current path.
int OpenXcom::Pathfinding::getStartDirection | ( | ) |
Checks whether a path is ready and gives the first direction.
bool OpenXcom::Pathfinding::getStrafeMove | ( | ) | const |
Gets the strafe move setting.
int OpenXcom::Pathfinding::getTUCost | ( | const Position & | startPosition, |
const int | direction, | ||
Position * | endPosition, | ||
BattleUnit * | unit, | ||
BattleUnit * | target, | ||
bool | missile | ||
) |
Gets the TU cost to move from 1 tile to the other.
Gets the TU cost to move from 1 tile to the other (ONE STEP ONLY).
But also updates the endPosition, because it is possible the unit goes upstairs or falls down while walking.
startPosition | The position to start from. |
direction | The direction we are facing. |
endPosition | The position we want to reach. |
unit | The unit moving. |
target | The target unit. |
missile | Is this a guided missile? |
bool OpenXcom::Pathfinding::isBlocked | ( | Tile * | startTile, |
Tile * | endTile, | ||
const int | direction, | ||
BattleUnit * | missileTarget | ||
) |
Determines whether or not movement between starttile and endtile is possible in the direction.
Determines whether going from one tile to another blocks movement.
startTile | The tile to start from. |
endTile | The tile we want to reach. |
direction | The direction we are facing. |
missileTarget | Target for a missile. |
bool OpenXcom::Pathfinding::isModifierUsed | ( | ) | const |
Gets the modifier setting.
Checks whether a modifier key was used to enable strafing or running.
bool OpenXcom::Pathfinding::isOnStairs | ( | const Position & | startPosition, |
const Position & | endPosition | ||
) |
Determines whether the unit is going up a stairs.
startPosition | The position to start from. |
endPosition | The position we wanna reach. |
bool OpenXcom::Pathfinding::isPathPreviewed | ( | ) | const |
Gets the path preview setting.
bool OpenXcom::Pathfinding::previewPath | ( | bool | bRemove = false | ) |
Previews the path.
Marks tiles for the path preview.
bRemove | Remove preview? |
bool OpenXcom::Pathfinding::removePreview | ( | ) |
Removes the path preview.
Unmarks the tiles used for the path preview.
void OpenXcom::Pathfinding::setUnit | ( | BattleUnit * | unit | ) |
Sets _unit in order to abuse low-level pathfinding functions from outside the class.
unit | Unit taking the path. |
bool OpenXcom::Pathfinding::validateUpDown | ( | BattleUnit * | bu, |
Position | startPosition, | ||
const int | direction | ||
) |
Checks, for the up/down button, if the movement is valid.
Either there is a grav lift or the unit can fly and there are no obstructions.
bu | Pointer to unit. |
startPosition | Unit starting position. |
direction | Up or Down |
|
static |
Converts a vector to a direction.
Converts direction to a vector.
Direction starts north = 0 and goes clockwise.
vector | Pointer to a position (which acts as a vector). |
dir | Resulting direction. |