Adonthell  0.4
path Class Reference

A* pathfinding algorithm implementation class. More...

#include <path.h>

Collaboration diagram for path:

Classes

struct  area_coord
 (x, y) coordinates of a point on a submap. More...
 

Public Member Functions

void clear ()
 Totally clears the path. More...
 
bool calculate ()
 Tries to find the shortest path possible between the start point and the goal point. More...
 
u_int16 nbr_moves () const
 Returns the number of moves between start and goal. More...
 
u_int16 get_move (u_int16 nbr) const
 Returns the move to perform when at position nbr. More...
 
s_int8 get_state (igzstream &file)
 Restore the path's state from an opened file. More...
 
s_int8 put_state (ogzstream &file) const
 Saves the path's state into an opened file. More...
 

Public Attributes

landmaprefmap
 Landmap where the pathfinding will occur. More...
 
u_int16 submap
 Submap where the pathfinding will occur. More...
 
u_int16 dir
 Direction to face once the goal is reached. More...
 
area_coord start
 Start point. More...
 
area_coord goal
 Goal point. More...
 

Detailed Description

A* pathfinding algorithm implementation class.

This class calculates the shortest way from a begin point to a goal point on a landmap using the A* algorithm. It stores a list of directions that when followed lead from the start to the goal.

This class is particularly well designed for mapcharacters, who will often need to walk from one point to another.

Definition at line 52 of file path.h.

Member Function Documentation

void path::clear ( )
inline

Totally clears the path.

Definition at line 119 of file path.h.

bool path::calculate ( )

Tries to find the shortest path possible between the start point and the goal point.

Returns
true if a path was found, false otherwise.

Definition at line 47 of file path.cc.

u_int16 path::nbr_moves ( ) const
inline

Returns the number of moves between start and goal.

Returns
Number of moves between start and goal.

Definition at line 138 of file path.h.

u_int16 path::get_move ( u_int16  nbr) const
inline

Returns the move to perform when at position nbr.

Parameters
nbrIndex of the move to get.
Returns
Direction (move) at index nbr.

Definition at line 150 of file path.h.

s_int8 path::get_state ( igzstream file)

Restore the path's state from an opened file.

Parameters
filethe opened file from which to load the state.
Returns
0 in case of success, error code otherwise.
Bug:
the landmap this path belongs to must be restored manually!

Definition at line 265 of file path.cc.

s_int8 path::put_state ( ogzstream file) const

Saves the path's state into an opened file.

Parameters
filethe opened file where to the state.
Returns
0 in case of success, error code otherwise.
Bug:
the landmap this path belongs to can't be saved (as it's a pointer)!

Definition at line 289 of file path.cc.

Member Data Documentation

landmap* path::refmap

Landmap where the pathfinding will occur.

Definition at line 88 of file path.h.

u_int16 path::submap

Submap where the pathfinding will occur.

Definition at line 94 of file path.h.

u_int16 path::dir

Direction to face once the goal is reached.

Definition at line 100 of file path.h.

area_coord path::start

Start point.

Definition at line 106 of file path.h.

area_coord path::goal

Goal point.

Definition at line 112 of file path.h.


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