____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
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"
Go to the source code of this file.
Defines | |
| #define | STDCALL |
| #define | AstarDebugPrint(x) |
| #define | NewResetPath(unit) do { unit->Data.Move.Fast = 1; unit->Data.Move.Length = 0; } while (0) |
Enumerations | |
| enum | _move_return_ { PF_FAILED = -3, PF_UNREACHABLE = -2, PF_REACHED = -1, PF_WAIT = 0, PF_MOVE = 1 } |
Functions | |
| void | InitPathfinder () |
| < Init the pathfinder | |
| void | FreePathfinder () |
| Create a matrix for the old pathfinder. | |
| unsigned char * | CreateMatrix (void) |
| Allocate a new matrix and initialize. | |
| unsigned char * | MakeMatrix (void) |
| Get next element of the way to goal. | |
| int | NewPath (CUnit *unit) |
| Returns the next element of the path. | |
| int | NextPathElement (CUnit *unit, int *xdp, int *ydp) |
| Return distance to unit. | |
| int | UnitReachable (const CUnit *unit, const CUnit *dst, int range) |
| Can the unit 'src' reach the place x,y. | |
| int | PlaceReachable (const CUnit *src, int x, int y, int w, int h, int minrange, int maxrange) |
| void | InitAStar (int mapWidth, int mapHeight, int(STDCALL *costMoveTo)(int x, int y, void *data)) |
| < Init the a* data structures | |
| void | FreeAStar (void) |
| Find and a* path for a unit. | |
| 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) |
| void | SetAStarFixedUnitCrossingCost (int cost) |
| int | GetAStarFixedUnitCrossingCost () |
| void | SetAStarMovingUnitCrossingCost (int cost) |
| int | GetAStarMovingUnitCrossingCost () |
| void | SetAStarUnknownTerrainCost (int cost) |
| int | GetAStarUnknownTerrainCost () |
Variables | |
| int | AStarFixedUnitCrossingCost |
| < cost associated to move on a tile occupied by a fixed unit | |
| int | AStarMovingUnitCrossingCost |
| Whether to have knowledge of terrain that we haven't visited yet. | |
| bool | AStarKnowUnseenTerrain |
| Cost of using a square we haven't seen before. | |
| int | AStarUnknownTerrainCost |
| const int | Heading2X [9] |
| const int | Heading2Y [9] |
| const int | XY2Heading [3][3] |
Definition in file pathfinder.h.
| #define AstarDebugPrint | ( | x | ) |
| #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.
Definition at line 69 of file pathfinder.h.
Referenced by AttackTarget(), CheckForDeadGoal(), CheckForTargetInRange(), HandleActionAttack(), HandleActionBoard(), HandleActionFollow(), HandleActionMove(), HandleActionPatrol(), HandleActionResource(), HandleActionSpellCast(), HandleActionUnload(), MoveToLocation(), MoveToTarget(), MoveToTransporter(), RepairUnit(), RestoreSavedOrder(), and SwapPatrolPoints().
| #define STDCALL |
Definition at line 36 of file pathfinder.h.
| enum _move_return_ |
Result codes of the pathfinder.
| PF_FAILED | This Pathfinder failed, try another. |
| PF_UNREACHABLE | Unreachable stop. |
| PF_REACHED | Reached goal stop. |
| PF_WAIT | Wait, no time or blocked. |
| PF_MOVE | On the way moving. |
Definition at line 58 of file pathfinder.h.
| 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 path.
Definition at line 823 of file astar.cpp.
References AStarAddNode(), AStarAddToClose(), AStarCleanUp(), AStarCosts, AstarDebugPrint, AStarFindMinimum, AStarFindNode(), AStarFindSimplePath(), AStarGoalX, AStarGoalY, AStarMapHeight, AStarMapWidth, AStarMarkGoal(), AStarRemoveMinimum(), AStarReplaceNode(), AStarSavePath(), CacheNotSet, CloseSetSize, Node::CostFromStart, CostMoveTo(), CostMoveToCache, Node::CostToGoal, Node::Direction, Heading2X, Heading2Y, int(), Open::O, OpenSetSize, PF_FAILED, PF_REACHED, PF_UNREACHABLE, ProfileBegin, ProfileEnd, Open::X, Open::Y, and y.
Referenced by NewPath(), and PlaceReachable().
| 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 FreeAStar | ( | void | ) |
Find and a* path for a unit.
Free A* data structure
Definition at line 329 of file astar.cpp.
References CloseSet, CloseSetSize, CostMoveToCache, OpenSetSize, ProfilePrint, VisionLookup, and VisionTable.
Referenced by FreePathfinder().
| 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().
| int GetAStarFixedUnitCrossingCost | ( | ) |
Definition at line 1075 of file astar.cpp.
References AStarFixedUnitCrossingCost.
Referenced by tolua_get_AStarFixedUnitCrossingCost().
| int GetAStarMovingUnitCrossingCost | ( | ) |
Definition at line 1085 of file astar.cpp.
References AStarMovingUnitCrossingCost.
Referenced by tolua_get_AStarMovingUnitCrossingCost().
| int GetAStarUnknownTerrainCost | ( | ) |
Definition at line 1097 of file astar.cpp.
References AStarUnknownTerrainCost.
Referenced by tolua_get_AStarUnknownTerrainCost().
< Init the a* data structures
free the a* data structures
Init A* data structures
Definition at line 301 of file astar.cpp.
References Assert, AStarMapHeight, AStarMapWidth, AStarMatrixSize, CloseSet, CostMoveToCache, InitVisionTable(), MAX_CLOSE_SET_RATIO, MAX_OPEN_SET_RATIO, OpenSetMaxSize, ProfileInit, and Threshold.
Referenced by InitPathfinder().
| void InitPathfinder | ( | ) |
< Init the pathfinder
Free 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().
| void SetAStarFixedUnitCrossingCost | ( | int | cost | ) |
| void SetAStarMovingUnitCrossingCost | ( | int | cost | ) |
| void SetAStarUnknownTerrainCost | ( | int | cost | ) |
Definition at line 1090 of file astar.cpp.
References AStarUnknownTerrainCost.
Referenced by tolua_set_AStarUnknownTerrainCost().
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().
< cost associated to move on a tile occupied by a fixed unit
cost associated to move on a tile occupied by a moving unit
Definition at line 86 of file astar.cpp.
Referenced by GetAStarFixedUnitCrossingCost().
Cost of using a square we haven't seen before.
Definition at line 88 of file astar.cpp.
Referenced by CostMoveTo(), tolua_get_AStarKnowUnseenTerrain(), and tolua_set_AStarKnowUnseenTerrain().
Whether to have knowledge of terrain that we haven't visited yet.
Definition at line 87 of file astar.cpp.
Referenced by CostMoveTo(), and GetAStarMovingUnitCrossingCost().
Definition at line 89 of file astar.cpp.
Referenced by CostMoveTo(), GetAStarUnknownTerrainCost(), and SetAStarUnknownTerrainCost().
| const int Heading2X[9] |
Definition at line 69 of file astar.cpp.
Referenced by AStarFindPath(), AStarSavePath(), DoActionMove(), and NextPathElement().
| const int Heading2Y[9] |
Definition at line 70 of file astar.cpp.
Referenced by AStarFindPath(), AStarSavePath(), DoActionMove(), and NextPathElement().
| const int XY2Heading[3][3] |
1.5.6