AStar3D Class Reference

A 3D path finding algorithm, based on the 2D algorithm by Amit J. Patel. More...

#include <astar2.h>

Inheritance diagram for AStar3D:

Inheritance graph
[legend]
List of all members.

Public Types

typedef float DistanceType
typedef vector< PathPointPath

Public Member Functions

 AStar3D (GameMap *actmap, Vehicle *veh, bool markTemps_=true, int maxDistance=maxint)
void registerOperationLimiter (OperationLimiter *ol)
 the search can be restricted to certain operations
void findPath (const MapCoordinate3D &A, const vector< MapCoordinate3D > &B, Path &path)
 searches for a path from A to B and stores it in path
void findPath (Path &path, const MapCoordinate3D &dest)
 searches for a path from the unit's current position to dest and stores it in path
void findPath (Path &path, const vector< MapCoordinate3D > &dest)
 searches for a path from the units current position to one of the dest fields and stores it in path
void findAllAccessibleFields (vector< MapCoordinate3D > *path=NULL)
 searches for all fields that are within the range of maxDist and marks them.
int getDistance ()
 returns the distance of the last found path, or -1 on any error
int getTravelTime ()
 returns the number of turns that the unit will need to travel along the last found path
const NodefieldVisited (const MapCoordinate3D &fld)
 checks weather the field fld was among the visited fields during the last search
int & getFieldAccess (int x, int y)
int & getFieldAccess (const MapCoordinate &mc)
virtual ~AStar3D ()

Public Attributes

Container visited
 the reachable fields

Static Public Attributes

static const DistanceType longestPath

Protected Member Functions

virtual DistanceType getMoveCost (const MapCoordinate3D &start, const MapCoordinate3D &dest, const Vehicle *vehicle, bool &canStop, bool &hasAttacked)
HexDirectiongetPosDir (const MapCoordinate3D &pos)
int & getPosHHop (const MapCoordinate3D &pos)
DistanceType dist (const MapCoordinate3D &a, const MapCoordinate3D &b)
DistanceType dist (const MapCoordinate3D &a, const vector< MapCoordinate3D > &b)
bool get_first (Container &v, Node &n)
void nodeVisited (const Node &n, HexDirection direc, Container &open, int prevHeight=-10, int heightChangeDist=0)

Protected Attributes

OperationLimiteroperationLimiter
int MAXIMUM_PATH_LENGTH
GameMaptempsMarked
Path_path
Vehicleveh
GameMapactmap
float vehicleSpeedFactor [8]
float maxVehicleSpeedFactor
bool markTemps
WindMovementwind
HexDirectionposDirs
int * posHHops
int * fieldAccess

Classes

class  Container
struct  Node
class  OperationLimiter
class  PathPoint

Detailed Description

A 3D path finding algorithm, based on the 2D algorithm by Amit J. Patel.

Definition at line 98 of file astar2.h.


Member Typedef Documentation

typedef float AStar3D::DistanceType

Definition at line 100 of file astar2.h.

typedef vector<PathPoint> AStar3D::Path

Definition at line 127 of file astar2.h.


Constructor & Destructor Documentation

AStar3D::AStar3D ( GameMap actmap,
Vehicle veh,
bool  markTemps_ = true,
int  maxDistance = maxint 
)

Definition at line 429 of file astar2.cpp.

References _path, actmap, chfliegend, chhochfliegend, chtieffliegend, DirNone, fieldAccess, MapCoordinate3D::getNumericalHeight(), Vehicle::getPosition(), ContainerBaseType::height, longestPath, markTemps, max(), MAXIMUM_PATH_LENGTH, Vehicle::maxMovement(), maxVehicleSpeedFactor, VehicleType::movement, posDirs, posHHops, tempsMarked, Vehicle::typ, veh, vehicleSpeedFactor, GameMap::weather, wind, GameMap::Weather::windSpeed, GameMap::xsize, and GameMap::ysize.

AStar3D::~AStar3D (  )  [virtual]

Definition at line 483 of file astar2.cpp.

References GameMap::cleartemps(), fieldAccess, posDirs, posHHops, tempsMarked, and wind.


Member Function Documentation

AStar3D::DistanceType AStar3D::getMoveCost ( const MapCoordinate3D start,
const MapCoordinate3D dest,
const Vehicle vehicle,
bool &  canStop,
bool &  hasAttacked 
) [protected, virtual]

Reimplemented in StratAStar3D, AntiMineAStar3D, and HiddenAStar3D.

Definition at line 529 of file astar2.cpp.

References actmap, calcMoveMalus(), fieldAccessible(), MapCoordinate3D::getBitmappedHeight(), GameMap::getField(), MapCoordinate3D::getNumericalHeight(), longestPath, VehicleType::movement, Vehicle::typ, veh, vehicleSpeedFactor, and wind.

Referenced by findPath(), HiddenAStar3D::getMoveCost(), AntiMineAStar3D::getMoveCost(), and StratAStar3D::getMoveCost().

HexDirection& AStar3D::getPosDir ( const MapCoordinate3D pos  )  [inline, protected]

Definition at line 158 of file astar2.h.

References actmap, MapCoordinate3D::getNumericalHeight(), posDirs, MapCoordinate::x, GameMap::xsize, and MapCoordinate::y.

Referenced by findPath(), and nodeVisited().

int& AStar3D::getPosHHop ( const MapCoordinate3D pos  )  [inline, protected]

Definition at line 159 of file astar2.h.

References actmap, MapCoordinate3D::getNumericalHeight(), posHHops, MapCoordinate::x, GameMap::xsize, and MapCoordinate::y.

Referenced by findPath(), and nodeVisited().

AStar3D::DistanceType AStar3D::dist ( const MapCoordinate3D a,
const MapCoordinate3D b 
) [protected]

Definition at line 498 of file astar2.cpp.

References beeline(), chfliegend, chhochfliegend, chtieffliegend, MapCoordinate3D::getBitmappedHeight(), MapCoordinate3D::getNumericalHeight(), longestPath, minmalq, MapCoordinate::valid(), wind, and windbeeline().

Referenced by dist(), and findPath().

AStar3D::DistanceType AStar3D::dist ( const MapCoordinate3D a,
const vector< MapCoordinate3D > &  b 
) [protected]

Definition at line 515 of file astar2.cpp.

References dist(), longestPath, and maxVehicleSpeedFactor.

bool AStar3D::get_first ( Container v,
Node n 
) [protected]

void AStar3D::nodeVisited ( const Node n,
HexDirection  direc,
Container open,
int  prevHeight = -10,
int  heightChangeDist = 0 
) [protected]

Definition at line 570 of file astar2.cpp.

References AStar3D::Container::add(), DirNone, getPosDir(), getPosHHop(), AStar3D::Node::gval, AStar3D::Node::h, longestPath, MAXIMUM_PATH_LENGTH, ReverseDirection(), and AStar3D::Container::update().

Referenced by findPath().

void AStar3D::registerOperationLimiter ( OperationLimiter ol  )  [inline]

the search can be restricted to certain operations

Definition at line 201 of file astar2.h.

References operationLimiter.

void AStar3D::findPath ( const MapCoordinate3D A,
const vector< MapCoordinate3D > &  B,
Path path 
)

searches for a path from A to B and stores it in path

Definition at line 619 of file astar2.cpp.

References _path, actmap, AStar3D::Container::add(), AStar3D::OperationLimiter::allowDocking(), AStar3D::OperationLimiter::allowHeightChange(), AStar3D::OperationLimiter::allowLeavingContainer(), AStar3D::OperationLimiter::allowMovement(), MapField::building, AStar3D::Node::canStop, cbbuildingentry, cgp_movefrominvalidfields, ContainerBaseType::TransportationIO::disableAttack, dist(), AStar3D::Container::empty(), AStar3D::Node::enterHeight, fatalError(), fieldAccessible(), fieldVisited(), MapCoordinate3D::getBitmappedHeight(), MapField::getContainer(), getDirectionOrder(), GameMap::getField(), AStar3D::Container::getFirst(), GameMap::getgameparameter(), getMoveCost(), getNeighbouringFieldCoordinate(), getnextfield(), MapCoordinate3D::getNumericalHeight(), ContainerBase::getOwner(), getPosDir(), getPosHHop(), getTerrainBitType(), AStar3D::Node::gval, AStar3D::Node::h, AStar3D::Node::hasAttacked, AStar3D::Node::hval, longestPath, MAXIMUM_PATH_LENGTH, maxmalq, N, nodeVisited(), ContainerBaseType::OnlyMoveToAndFromTransports, operationLimiter, MapCoordinate3D::setnum(), MapField::unitHere(), veh, MapField::vehicle, ContainerBase::vehicleDocking(), ContainerBase::vehicleUnloadable(), ContainerBase::vehicleUnloadSystem(), visited, MapCoordinate::x, GameMap::xsize, MapCoordinate::y, and GameMap::ysize.

Referenced by MoveUnitCommand::calcPath(), findAllAccessibleFields(), findPath(), PathFinder::getMovementFields(), and MoveUnitCommand::isFieldReachable3D().

void AStar3D::findPath ( Path path,
const MapCoordinate3D dest 
)

searches for a path from the unit's current position to dest and stores it in path

Definition at line 899 of file astar2.cpp.

References findPath(), Vehicle::getPosition3D(), and veh.

void AStar3D::findPath ( Path path,
const vector< MapCoordinate3D > &  dest 
)

searches for a path from the units current position to one of the dest fields and stores it in path

Definition at line 906 of file astar2.cpp.

References findPath(), Vehicle::getPosition3D(), and veh.

void AStar3D::findAllAccessibleFields ( vector< MapCoordinate3D > *  path = NULL  ) 

searches for all fields that are within the range of maxDist and marks them.

On each field one bit for each level of height will be set. The Destructor removes all marks.

Parameters:
path if non-null, all fields will be stored there

Definition at line 912 of file astar2.cpp.

References MapField::a, actmap, AStar3D::Container::begin(), GameMap::cleartemps(), AStar3D::Container::end(), findPath(), GameMap::getField(), getFieldAccess(), Vehicle::height, markTemps, tempsMarked, veh, visited, GameMap::xsize, and GameMap::ysize.

int AStar3D::getDistance (  ) 

returns the distance of the last found path, or -1 on any error

int AStar3D::getTravelTime (  ) 

returns the number of turns that the unit will need to travel along the last found path

const AStar3D::Node * AStar3D::fieldVisited ( const MapCoordinate3D fld  ) 

checks weather the field fld was among the visited fields during the last search

Definition at line 935 of file astar2.cpp.

References AStar3D::Container::end(), AStar3D::Container::find(), and visited.

Referenced by findPath().

int & AStar3D::getFieldAccess ( int  x,
int  y 
)

Definition at line 945 of file astar2.cpp.

References actmap, fieldAccess, and GameMap::xsize.

Referenced by findAllAccessibleFields().

int & AStar3D::getFieldAccess ( const MapCoordinate mc  ) 

Definition at line 950 of file astar2.cpp.

References actmap, fieldAccess, MapCoordinate::x, GameMap::xsize, and MapCoordinate::y.


Member Data Documentation

const AStar3D::DistanceType AStar3D::longestPath [static]

Definition at line 101 of file astar2.h.

Referenced by AStar3D(), dist(), findPath(), getMoveCost(), nodeVisited(), AStar3D::Node::operator<(), and operator>().

OperationLimiter* AStar3D::operationLimiter [protected]

Definition at line 141 of file astar2.h.

Referenced by findPath(), and registerOperationLimiter().

int AStar3D::MAXIMUM_PATH_LENGTH [protected]

Definition at line 142 of file astar2.h.

Referenced by AStar3D(), findPath(), and nodeVisited().

GameMap* AStar3D::tempsMarked [protected]

Definition at line 143 of file astar2.h.

Referenced by AStar3D(), findAllAccessibleFields(), and ~AStar3D().

Path* AStar3D::_path [protected]

Definition at line 144 of file astar2.h.

Referenced by AStar3D(), and findPath().

Vehicle* AStar3D::veh [protected]

Definition at line 145 of file astar2.h.

Referenced by AStar3D(), findAllAccessibleFields(), findPath(), getMoveCost(), and PathFinder::getMovementFields().

GameMap* AStar3D::actmap [protected]

Definition at line 146 of file astar2.h.

Referenced by AStar3D(), findAllAccessibleFields(), findPath(), getFieldAccess(), getMoveCost(), getPosDir(), and getPosHHop().

float AStar3D::vehicleSpeedFactor[8] [protected]

Definition at line 147 of file astar2.h.

Referenced by AStar3D(), and getMoveCost().

float AStar3D::maxVehicleSpeedFactor [protected]

Definition at line 148 of file astar2.h.

Referenced by AStar3D(), and dist().

bool AStar3D::markTemps [protected]

Definition at line 149 of file astar2.h.

Referenced by AStar3D(), and findAllAccessibleFields().

WindMovement* AStar3D::wind [protected]

Definition at line 150 of file astar2.h.

Referenced by AStar3D(), dist(), getMoveCost(), and ~AStar3D().

HexDirection* AStar3D::posDirs [protected]

Definition at line 154 of file astar2.h.

Referenced by AStar3D(), getPosDir(), and ~AStar3D().

int* AStar3D::posHHops [protected]

Definition at line 155 of file astar2.h.

Referenced by AStar3D(), getPosHHop(), and ~AStar3D().

int* AStar3D::fieldAccess [protected]

Definition at line 156 of file astar2.h.

Referenced by AStar3D(), getFieldAccess(), and ~AStar3D().

Container AStar3D::visited

the reachable fields

Definition at line 186 of file astar2.h.

Referenced by fieldVisited(), findAllAccessibleFields(), findPath(), and PathFinder::getMovementFields().


The documentation for this class was generated from the following files:
Generated on Mon May 21 01:46:20 2012 for Advanced Strategic Command by  doxygen 1.5.1