Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

AStar Class Reference

A 2dimensional path finding algorithm, from Amit J. Patel. More...

#include <astar2.h>

Inheritance diagram for AStar:

Inheritance graph
[legend]
List of all members.

Public Types

typedef vector< MapCoordinatePath
typedef std::vector< NodeContainer

Public Member Functions

 AStar (GameMap *actmap, Vehicle *veh)
int dist (HexCoord a, HexCoord b)
void get_first (Container &v, Node &n)
void findPath (HexCoord A, HexCoord B, Path &path)
 searches for a path from A to B and stores it in path
void findPath (Path &path, int x, int y)
 searches for a path from the units current position to dest and stores it in path
void findAllAccessibleFields (int maxDist=maxint)
 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
bool fieldVisited (int x, int y)
 checks weather the field fld was among the visited fields during the last search
virtual ~AStar ()

Public Attributes

greater< Nodecomp
Container visited

Protected Member Functions

virtual int getMoveCost (int x1, int y1, int x2, int y2, const Vehicle *vehicle)
 returns the movement cost for the unit to travel from x1/y1 to x2/y2

Protected Attributes

int MAXIMUM_PATH_LENGTH
GameMaptempsMarked
Path_path
Vehicle_veh
GameMap_actmap

Classes

struct  HexCoord
 A hexagonal Coordinate. This structure is used instead of MapCoordinate to reduce the amount of modifications to Amits path finding code. More...
struct  Node

Detailed Description

A 2dimensional path finding algorithm, from Amit J. Patel.

Definition at line 23 of file astar2.h.


Member Typedef Documentation

typedef std::vector<Node> AStar::Container
 

Definition at line 58 of file astar2.h.

typedef vector<MapCoordinate> AStar::Path
 

Definition at line 25 of file astar2.h.


Constructor & Destructor Documentation

AStar::AStar GameMap actmap,
Vehicle veh
 

Definition at line 63 of file astar2.cpp.

References _actmap, _path, _veh, MAXIMUM_PATH_LENGTH, maxint, and tempsMarked.

AStar::~AStar  )  [virtual]
 

Definition at line 72 of file astar2.cpp.

References GameMap::cleartemps(), and tempsMarked.


Member Function Documentation

int AStar::dist HexCoord  a,
HexCoord  b
 

Definition at line 78 of file astar2.cpp.

References beeline(), AStar::HexCoord::m, and AStar::HexCoord::n.

Referenced by findPath(), getDistance(), and getTravelTime().

bool AStar::fieldVisited int  x,
int  y
 

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

Definition at line 315 of file astar2.cpp.

References visited.

void AStar::findAllAccessibleFields int  maxDist = maxint  ) 
 

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.

Definition at line 325 of file astar2.cpp.

References _actmap, GameMap::cleartemps(), findPath(), GameMap::getField(), MAXIMUM_PATH_LENGTH, tempsMarked, visited, GameMap::xsize, and GameMap::ysize.

void AStar::findPath Path path,
int  x,
int  y
 

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

Definition at line 340 of file astar2.cpp.

References _veh, findPath(), Vehicle::xpos, and Vehicle::ypos.

void AStar::findPath HexCoord  A,
HexCoord  B,
Path path
 

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

Definition at line 139 of file astar2.cpp.

References _actmap, _path, _veh, actmap, Vehicle::canMove(), GameMap::cleartemps(), comp, DirNone, dist(), GameMap::field, fieldAccessible(), get_first(), getfield(), GameMap::getField(), getMoveCost(), getnextfield(), AStar::Node::gval, AStar::Node::h, AStar::Node::hval, AStar::HexCoord::m, MAXIMUM_PATH_LENGTH, Vehicle::maxMovement(), N, AStar::HexCoord::n, random(), ReverseDirection(), tfield::temp3, visited, GameMap::xsize, and GameMap::ysize.

Referenced by findAllAccessibleFields(), findPath(), and findPath().

void AStar::get_first Container v,
Node n
[inline]
 

Definition at line 125 of file astar2.cpp.

References comp.

Referenced by findPath().

int AStar::getDistance  ) 
 

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

Definition at line 291 of file astar2.cpp.

References _actmap, _path, _veh, dist(), GameMap::getField(), tfield::getmovemalus(), Vehicletype::movemalustyp, and Vehicle::typ.

Referenced by getTravelTime().

int AStar::getMoveCost int  x1,
int  y1,
int  x2,
int  y2,
const Vehicle vehicle
[protected, virtual]
 

returns the movement cost for the unit to travel from x1/y1 to x2/y2

Reimplemented in StratAStar, and HiddenAStar.

Definition at line 105 of file astar2.cpp.

References calcMoveMalus(), fieldAccessible(), getfield(), Vehicle::height, and MAXIMUM_PATH_LENGTH.

Referenced by findPath(), HiddenAStar::getMoveCost(), and StratAStar::getMoveCost().

int AStar::getTravelTime  ) 
 

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

Definition at line 306 of file astar2.cpp.

References _veh, dist(), getDistance(), Vehicle::height, log2(), Vehicletype::movement, and Vehicle::typ.


Member Data Documentation

GameMap* AStar::_actmap [protected]
 

Definition at line 32 of file astar2.h.

Referenced by AStar(), findAllAccessibleFields(), findPath(), and getDistance().

Path* AStar::_path [protected]
 

Definition at line 30 of file astar2.h.

Referenced by AStar(), findPath(), and getDistance().

Vehicle* AStar::_veh [protected]
 

Definition at line 31 of file astar2.h.

Referenced by AStar(), findPath(), getDistance(), and getTravelTime().

greater<Node> AStar::comp
 

Definition at line 59 of file astar2.h.

Referenced by findPath(), and get_first().

int AStar::MAXIMUM_PATH_LENGTH [protected]
 

Definition at line 28 of file astar2.h.

Referenced by AStar(), findAllAccessibleFields(), findPath(), and getMoveCost().

GameMap* AStar::tempsMarked [protected]
 

Definition at line 29 of file astar2.h.

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

Container AStar::visited
 

Definition at line 64 of file astar2.h.

Referenced by fieldVisited(), findAllAccessibleFields(), and findPath().


The documentation for this class was generated from the following files:
Generated on Tue Jun 24 02:16:14 2008 for Advanced Strategic Command by  doxygen 1.4.2