$treeview $search $mathjax
Stratagus  2.2.6
$projectbrief
$projectbrief
$searchbox
-->
         _________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
           Stratagus - A free fantasy real time strategy game engine

src/include/pathfinder.h File Reference

Go to the source code of this file.


pathfinder.h - The path finder headerfile.

#define STDCALL
#define AstarDebugPrint(x)
#define NewResetPath(unit)   do { (unit).Data.Move.Fast = 1; (unit).Data.Move.Length = 0; } while (0)
enum  _move_return_ {
  PF_FAILED = -3, PF_UNREACHABLE = -2, PF_REACHED = -1, PF_WAIT = 0,
  PF_MOVE = 1
}
int AStarFixedUnitCrossingCost
 cost associated to move on a tile occupied by a fixed unit
int AStarMovingUnitCrossingCost
 cost associated to move on a tile occupied by a moving unit
bool AStarKnowUnseenTerrain
 Whether to have knowledge of terrain that we haven't visited yet.
int AStarUnknownTerrainCost
 Cost of using a square we haven't seen before.
const int Heading2X [9]
const int Heading2Y [9]
const int XY2Heading [3][3]
void InitPathfinder ()
 Init the pathfinder.
void FreePathfinder ()
 Free the pathfinder.
unsigned char * CreateMatrix ()
 Create a matrix for the old pathfinder.
unsigned char * MakeMatrix ()
 Allocate a new matrix and initialize.
int NewPath (CUnit &unit)
 Get next element of the way to goal.
int NextPathElement (CUnit &unit, short int *xdp, short int *ydp)
 Returns the next element of the path.
int UnitReachable (const CUnit &unit, const CUnit &dst, int range)
 Return distance to unit.
int PlaceReachable (const CUnit &src, int x, int y, int w, int h, int minrange, int maxrange)
 Can the unit 'src' reach the place x,y.
void SetAStarFixedUnitCrossingCost (int cost)
int GetAStarFixedUnitCrossingCost ()
void SetAStarMovingUnitCrossingCost (int cost)
int GetAStarMovingUnitCrossingCost ()
void SetAStarUnknownTerrainCost (int cost)
int GetAStarUnknownTerrainCost ()
void PathfinderCclRegister ()

Define Documentation

#define AstarDebugPrint (  ) 

#define NewResetPath ( unit   )     do { (unit).Data.Move.Fast = 1; (unit).Data.Move.Length = 0; } while (0)

To remove pathfinder internals. Called if path destination changed.

#define STDCALL


Enumeration Type Documentation

Result codes of the pathfinder.

Todo:
Another idea is SINT_MAX as reached, SINT_MIN as unreachable stop others how far to goal.
Enumerator:
PF_FAILED 
PF_UNREACHABLE  This Pathfinder failed, try another.
PF_REACHED  Unreachable stop.
PF_WAIT  Reached goal stop.
PF_MOVE  Wait, no time or blocked.


Function Documentation

unsigned char* CreateMatrix (  ) 

Create a matrix for the old pathfinder.

Create empty movement matrix.

void FreePathfinder (  ) 

Free the pathfinder.

Free the pathfinder

int GetAStarFixedUnitCrossingCost (  ) 

int GetAStarMovingUnitCrossingCost (  ) 

int GetAStarUnknownTerrainCost (  ) 

void InitPathfinder (  ) 

Init the pathfinder.

Init the pathfinder.

Init the pathfinder

unsigned char* MakeMatrix (  ) 

Allocate a new matrix and initialize.

Allocate a new matrix and initialize

int NewPath ( CUnit unit  ) 

Get next element of the way to goal.

Find new path.

The destination could be a unit or a field. Range gives how far we must reach the goal.

Note:
The destination could become negative coordinates!
Parameters:
unit Path for this unit.
Returns:
>0 remaining path length, 0 wait for path, -1 reached goal, -2 can't reach the goal.

int NextPathElement ( CUnit unit,
short int *  pxd,
short int *  pyd 
)

Returns the next element of the path.

Returns the next element of a path.

Parameters:
unit Unit that wants the path element.
pxd Pointer for the x direction.
pyd Pointer for the y direction.
Returns:
>0 remaining path length, 0 wait for path, -1 reached goal, -2 can't reach the goal.

void PathfinderCclRegister (  ) 

Register CCL features for pathfinder.

int PlaceReachable ( const CUnit src,
int  x,
int  y,
int  w,
int  h,
int  minrange,
int  range 
)

Can the unit 'src' reach the place x,y.

Can the unit 'src' reach the place x,y.

Parameters:
src Unit for the path.
x Map X tile position.
y Map Y tile position.
w Width of Goal
h Height of Goal
minrange min range to the tile
range Range to the tile.
Returns:
Distance to place.

void SetAStarFixedUnitCrossingCost ( int  cost  ) 

void SetAStarMovingUnitCrossingCost ( int  cost  ) 

void SetAStarUnknownTerrainCost ( int  cost  ) 

int UnitReachable ( const CUnit src,
const CUnit dst,
int  range 
)

Return distance to unit.

Can the unit 'src' reach the unit 'dst'.

Parameters:
src Unit for the path.
dst Unit to be reached.
range Range to unit.
Returns:
Distance to place.


Variable Documentation

cost associated to move on a tile occupied by a fixed unit

Whether to have knowledge of terrain that we haven't visited yet.

cost associated to move on a tile occupied by a moving unit

Cost of using a square we haven't seen before.

const int Heading2X[9]

const int Heading2Y[9]

const int XY2Heading[3][3]

(C) Copyright 1998-2011 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.