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

pathfinder.cpp File Reference
#include "stratagus.h"
#include "pathfinder.h"
#include "actions.h"
#include "map.h"
#include "unittype.h"
#include "unit.h"

Functions

pathfinder.cpp - The path finder routines.
void InitAStar (int mapWidth, int mapHeight)
 Init the a* data structures. More...
 
void FreeAStar ()
 free the a* data structures More...
 
int AStarFindPath (const Vec2i &startPos, const Vec2i &goalPos, int gw, int gh, int tilesizex, int tilesizey, int minrange, int maxrange, char *path, int pathlen, const CUnit &unit)
 Find and a* path for a unit. More...
 
void InitPathfinder ()
 Init the pathfinder. More...
 
void FreePathfinder ()
 Free the pathfinder. More...
 
int PlaceReachable (const CUnit &src, const Vec2i &goalPos, int w, int h, int minrange, int range, bool from_outside_container)
 Can the unit 'src' reach the place x,y. More...
 
int UnitReachable (const CUnit &src, const CUnit &dst, int range, bool from_outside_container)
 Return path length to unit 'dst'. More...
 
int CalcPathLengthToUnit (const CUnit &src, const CUnit &dst, const int minrange, const int range)
 Return path length to unit 'dst' or error code. More...
 
static int NewPath (PathFinderInput &input, PathFinderOutput &output)
 
int NextPathElement (CUnit &unit, short int *pxd, short int *pyd)
 Returns the next element of the path. More...
 

Function Documentation

◆ AStarFindPath()

int AStarFindPath ( const Vec2i startPos,
const Vec2i goalPos,
int  gw,
int  gh,
int  tilesizex,
int  tilesizey,
int  minrange,
int  maxrange,
char *  path,
int  pathlen,
const CUnit unit 
)

Find and a* path for a unit.

Find path.

◆ CalcPathLengthToUnit()

int CalcPathLengthToUnit ( const CUnit src,
const CUnit dst,
const int  minrange,
const int  range 
)

Return path length to unit 'dst' or error code.

Calc path length for the unit 'src' to reach the unit 'dst'.

Parameters
srcUnit for the path.
dstUnit to be reached.
minrangemin range to the tile
rangeRange to the tile.
Returns
path length to dst or error code

change Path Finder setting to don't count tiles with enemy units as passable

restore Path Finder setting

◆ FreeAStar()

void FreeAStar ( )

free the a* data structures

Free A* data structure

◆ FreePathfinder()

void FreePathfinder ( )

Free the pathfinder.

Free the pathfinder

◆ InitAStar()

void InitAStar ( int  mapWidth,
int  mapHeight 
)

Init the a* data structures.

Init A* data structures

◆ InitPathfinder()

void InitPathfinder ( )

Init the pathfinder.

Init the pathfinder

◆ NewPath()

static int NewPath ( PathFinderInput input,
PathFinderOutput output 
)
static

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
unitPath for this unit.
Returns
>0 remaining path length, 0 wait for path, -1 reached goal, -2 can't reach the goal.

◆ NextPathElement()

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
unitUnit that wants the path element.
pxdPointer for the x direction.
pydPointer for the y direction.
Returns
>0 remaining path length, 0 wait for path, -1 reached goal, -2 can't reach the goal.

◆ PlaceReachable()

int PlaceReachable ( const CUnit src,
const Vec2i goalPos,
int  w,
int  h,
int  minrange,
int  range,
bool  from_outside_container 
)

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

Can the unit 'src' reach the place goalPos.

Parameters
srcUnit for the path.
goalPosMap tile position.
wWidth of Goal
hHeight of Goal
minrangemin range to the tile
rangeRange to the tile.
Returns
Distance to place.

change Path Finder setting to don't count tiles with enemy units as passable

restore Path Finder setting

◆ UnitReachable()

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

Return path length to unit 'dst'.

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

Parameters
srcUnit for the path.
dstUnit to be reached.
rangeRange to unit.
Returns
Distance to place.
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.