$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/pathfinder/pathfinder.cpp File Reference

#include "stratagus.h"
#include "map.h"
#include "unittype.h"
#include "unit.h"
#include "pathfinder.h"

pathfinder.cpp - The path finder routines.

static unsigned char Matrix [(MaxMapWidth+2)*(MaxMapHeight+3)+2]
void InitAStar (int mapWidth, int mapHeight, int(STDCALL *costMoveTo)(unsigned int index, void *data))
 Init the a* data structures.
void FreeAStar ()
 free the a* data structures
int AStarFindPath (int sx, int sy, int gx, int gy, int gw, int gh, int tilesizex, int tilesizey, int minrange, int maxrange, char *path, int pathlen, void *data)
 Find and a* path for a unit.
void InitPathfinder ()
 Path matrix.
void FreePathfinder ()
 Free the pathfinder.
static void InitMatrix (unsigned char *matrix)
unsigned char * CreateMatrix ()
 Create a matrix for the old pathfinder.
unsigned char * MakeMatrix ()
 Allocate a new matrix and initialize.
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.
int UnitReachable (const CUnit &src, const CUnit &dst, int range)
 Return distance to unit.
int NewPath (CUnit &unit)
 Get next element of the way to goal.
int NextPathElement (CUnit &unit, short int *pxd, short int *pyd)
 Returns the next element of the path.

Function Documentation

int AStarFindPath ( int  sx,
int  sy,
int  gx,
int  gy,
int  gw,
int  gh,
int  tilesizex,
int  tilesizey,
int  minrange,
int  maxrange,
char *  path,
int  pathlen,
void *  data 
)

Find and a* path for a unit.

Find path.

unsigned char* CreateMatrix (  ) 

Create a matrix for the old pathfinder.

Create empty movement matrix.

void FreeAStar (  ) 

free the a* data structures

Free A* data structure

void FreePathfinder (  ) 

Free the pathfinder.

Free the pathfinder

void InitAStar ( int  mapWidth,
int  mapHeight,
int(STDCALL *costMoveTo)(unsigned int index, void *data  
)

Init the a* data structures.

Init A* data structures

static void InitMatrix ( unsigned char *  matrix  )  [static]

Initialize a matrix

Note:
Double border for ships/flyers.
98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98

void InitPathfinder (  ) 

Path matrix.

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.

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.

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

unsigned char Matrix[(MaxMapWidth+2)*(MaxMapHeight+3)+2] [static]

The matrix is used to generated the paths.

0: Nothing must check if usable. 1-8: Field on the path 1->2->3->4->5... 88: Marks the possible goal fields. 98: Marks map border, for faster limits checks.

(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.