____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"
#include "stratagus.h"
#include "map.h"
#include "unittype.h"
#include "unit.h"
#include "pathfinder.h"
Go to the source code of this file.
Functions | |
| static int STDCALL | CostMoveTo (int x, int y, void *data) |
| void | InitPathfinder () |
| < Init the pathfinder | |
| void | FreePathfinder () |
| Create a matrix for the old pathfinder. | |
| static void | InitMatrix (unsigned char *matrix) |
| unsigned char * | CreateMatrix (void) |
| Allocate a new matrix and initialize. | |
| unsigned char * | MakeMatrix (void) |
| Get next element of the way to goal. | |
| int | PlaceReachable (const CUnit *src, int x, int y, int w, int h, int minrange, int range) |
| int | UnitReachable (const CUnit *src, const CUnit *dst, int range) |
| Can the unit 'src' reach the place x,y. | |
| int | NewPath (CUnit *unit) |
| Returns the next element of the path. | |
| int | NextPathElement (CUnit *unit, int *pxd, int *pyd) |
| Return distance to unit. | |
Variables | |
| static unsigned char | Matrix [(MaxMapWidth+2)*(MaxMapHeight+3)+2] |
| Path matrix. | |
Definition in file pathfinder.cpp.
| static int STDCALL CostMoveTo | ( | int | x, | |
| int | y, | |||
| void * | data | |||
| ) | [static] |
Compute the cost of crossing tile (dx,dy)
| data | user data. | |
| x | X tile where to move. | |
| y | Y tile where to move. |
Definition at line 210 of file pathfinder.cpp.
References Assert, AStarKnowUnseenTerrain, AStarMovingUnitCrossingCost, AStarUnknownTerrainCost, CMapField::Cost, CMap::Field(), CMapField::Flags, CMap::IsFieldExplored(), Map, MapFieldAirUnit, MapFieldLandUnit, MapFieldSeaUnit, CUnitType::MovementMask, CUnit::Moving, CUnit::Player, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitOnMapTile(), CUnitType::UnitType, CUnit::X, and CUnit::Y.
| unsigned char* CreateMatrix | ( | void | ) |
Allocate a new matrix and initialize.
Create empty movement matrix.
Definition at line 115 of file pathfinder.cpp.
References InitMatrix(), and Matrix.
Referenced by AiFindBuildingPlace2(), AiPlanAttack(), and UnitFindResource().
| void FreePathfinder | ( | ) |
Create a matrix for the old pathfinder.
Free the pathfinder
Definition at line 74 of file pathfinder.cpp.
References FreeAStar().
Referenced by CleanGame(), and CleanModules().
| static void InitMatrix | ( | unsigned char * | matrix | ) | [static] |
Initialize a matrix
Definition at line 90 of file pathfinder.cpp.
References CMap::Info, Map, CMapInfo::MapHeight, and CMapInfo::MapWidth.
Referenced by CreateMatrix(), and MakeMatrix().
| void InitPathfinder | ( | ) |
< Init the pathfinder
Init the pathfinder
Definition at line 66 of file pathfinder.cpp.
References CostMoveTo(), CMap::Info, InitAStar(), Map, CMapInfo::MapHeight, and CMapInfo::MapWidth.
Referenced by CreateGame(), and LoadModules().
| unsigned char* MakeMatrix | ( | void | ) |
Get next element of the way to goal.
Allocate a new matrix and initialize
Definition at line 124 of file pathfinder.cpp.
References CMap::Info, InitMatrix(), Map, CMapInfo::MapHeight, and CMapInfo::MapWidth.
| int NewPath | ( | CUnit * | unit | ) |
Returns the next element of the path.
Find new path.
The destination could be a unit or a field. Range gives how far we must reach the goal.
| unit | Path for this unit. |
Definition at line 282 of file pathfinder.cpp.
References AStarFindPath(), CUnit::Data, CMap::Info, CUnit::_order_data_::_order_move_::Length, Map, CMapInfo::MapHeight, CMapInfo::MapWidth, MAX_PATH_LENGTH, CUnit::_order_data_::Move, CUnit::Orders, CUnit::_order_data_::_order_move_::Path, PF_FAILED, PF_UNREACHABLE, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CUnit::X, and CUnit::Y.
Referenced by NextPathElement().
| int NextPathElement | ( | CUnit * | unit, | |
| int * | pxd, | |||
| int * | pyd | |||
| ) |
Return distance to unit.
Returns the next element of a path.
| unit | Unit that wants the path element. | |
| pxd | Pointer for the x direction. | |
| pyd | Pointer for the y direction. |
Definition at line 351 of file pathfinder.cpp.
References _C_, AstarDebugPrint, CUnit::Data, CUnit::_order_data_::_order_move_::Fast, CUnit::Goal, Heading2X, Heading2Y, int(), CUnit::_order_data_::_order_move_::Length, CUnit::_order_data_::Move, NewPath(), CUnit::Orders, CUnit::_order_data_::_order_move_::Path, PF_REACHED, PF_UNREACHABLE, PF_WAIT, UnitCanBeAt(), CUnit::X, and CUnit::Y.
Referenced by DoActionMove().
| 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.
| 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. |
Definition at line 151 of file pathfinder.cpp.
References Assert, AStarFindPath(), PF_FAILED, PF_MOVE, PF_REACHED, PF_UNREACHABLE, PF_WAIT, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CUnit::X, and CUnit::Y.
Referenced by AiCanNotMove(), and UnitReachable().
Can the unit 'src' reach the place x,y.
Can the unit 'src' reach the unit 'dst'.
| src | Unit for the path. | |
| dst | Unit to be reached. | |
| range | Range to unit. |
Definition at line 184 of file pathfinder.cpp.
References PlaceReachable(), CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CUnit::X, and CUnit::Y.
Referenced by AiRepairBuilding(), AttackUnitsInDistance(), and FindRangeAttack().
unsigned char Matrix[(MaxMapWidth+2)*(MaxMapHeight+3)+2] [static] |
Path matrix.
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.
Definition at line 55 of file pathfinder.cpp.
Referenced by CreateMatrix().
1.5.6