| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name pathfinder.h - The path finder headerfile. */ |
| 11 |
// |
| 12 |
// (c) Copyright 1998-2007 by Lutz Sammer, Russell Smith |
| 13 |
// |
| 14 |
// This program is free software; you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation; only version 2 of the License. |
| 17 |
// |
| 18 |
// This program is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program; if not, write to the Free Software |
| 25 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
// 02111-1307, USA. |
| 27 |
|
| 28 |
#ifndef __PATHFINDER_H__ |
| 29 |
#define __PATHFINDER_H__ |
| 30 |
|
| 31 |
//@{ |
| 32 |
|
| 33 |
#ifdef _MSC_VER |
| 34 |
#define STDCALL __stdcall |
| 35 |
#else |
| 36 |
#ifndef STDCALL |
| 37 |
#define STDCALL |
| 38 |
#endif |
| 39 |
#endif |
| 40 |
|
| 41 |
#if defined(DEBUG_ASTAR) |
| 42 |
#define AstarDebugPrint(x) DebugPrint(x) |
| 43 |
#else |
| 44 |
#define AstarDebugPrint(x) |
| 45 |
#endif |
| 46 |
|
| 47 |
/*---------------------------------------------------------------------------- |
| 48 |
-- Declarations |
| 49 |
----------------------------------------------------------------------------*/ |
| 50 |
|
| 51 |
class CUnit; |
| 52 |
|
| 53 |
/** |
| 54 |
** Result codes of the pathfinder. |
| 55 |
** |
| 56 |
** @todo |
| 57 |
** Another idea is SINT_MAX as reached, SINT_MIN as unreachable |
| 58 |
** stop others how far to goal. |
| 59 |
*/ |
| 60 |
enum _move_return_ { |
| 61 |
PF_FAILED = -3, /// This Pathfinder failed, try another |
| 62 |
PF_UNREACHABLE = -2, /// Unreachable stop |
| 63 |
PF_REACHED = -1, /// Reached goal stop |
| 64 |
PF_WAIT = 0, /// Wait, no time or blocked |
| 65 |
PF_MOVE = 1, /// On the way moving |
| 66 |
}; |
| 67 |
|
| 68 |
/** |
| 69 |
** To remove pathfinder internals. Called if path destination changed. |
| 70 |
*/ |
| 71 |
#define NewResetPath(unit) \ |
| 72 |
do { unit->Data.Move.Fast = 1; unit->Data.Move.Length = 0; } while (0) |
| 73 |
|
| 74 |
/*---------------------------------------------------------------------------- |
| 75 |
-- Variables |
| 76 |
----------------------------------------------------------------------------*/ |
| 77 |
|
| 78 |
/// cost associated to move on a tile occupied by a fixed unit |
| 79 |
extern int AStarFixedUnitCrossingCost; |
| 80 |
/// cost associated to move on a tile occupied by a moving unit |
| 81 |
extern int AStarMovingUnitCrossingCost; |
| 82 |
/// Whether to have knowledge of terrain that we haven't visited yet |
| 83 |
extern bool AStarKnowUnseenTerrain; |
| 84 |
/// Cost of using a square we haven't seen before. |
| 85 |
extern int AStarUnknownTerrainCost; |
| 86 |
|
| 87 |
// |
| 88 |
// Convert heading into direction. |
| 89 |
// N NE E SE S SW W NW |
| 90 |
extern const int Heading2X[9]; |
| 91 |
extern const int Heading2Y[9]; |
| 92 |
extern const int XY2Heading[3][3]; |
| 93 |
|
| 94 |
/*---------------------------------------------------------------------------- |
| 95 |
-- Functions |
| 96 |
----------------------------------------------------------------------------*/ |
| 97 |
|
| 98 |
/// Init the pathfinder |
| 99 |
extern void InitPathfinder(); |
| 100 |
/// Free the pathfinder |
| 101 |
extern void FreePathfinder(); |
| 102 |
|
| 103 |
/// Create a matrix for the old pathfinder |
| 104 |
extern unsigned char *CreateMatrix(void); |
| 105 |
/// Allocate a new matrix and initialize |
| 106 |
extern unsigned char *MakeMatrix(void); |
| 107 |
/// Get next element of the way to goal. |
| 108 |
extern int NewPath(CUnit *unit); |
| 109 |
/// Returns the next element of the path |
| 110 |
extern int NextPathElement(CUnit *unit, int *xdp, int *ydp); |
| 111 |
/// Return distance to unit. |
| 112 |
extern int UnitReachable(const CUnit *unit, const CUnit *dst, int range); |
| 113 |
/// Can the unit 'src' reach the place x,y |
| 114 |
extern int PlaceReachable(const CUnit *src, int x, int y, int w, int h, |
| 115 |
int minrange, int maxrange); |
| 116 |
|
| 117 |
// |
| 118 |
// in astar.cpp |
| 119 |
// |
| 120 |
/// Init the a* data structures |
| 121 |
extern void InitAStar(int mapWidth, int mapHeight, int (STDCALL *costMoveTo)(int x, int y, void *data)); |
| 122 |
|
| 123 |
/// free the a* data structures |
| 124 |
extern void FreeAStar(void); |
| 125 |
|
| 126 |
/// Find and a* path for a unit |
| 127 |
extern int AStarFindPath(int sx, int sy, int gx, int gy, int gw, int gh, |
| 128 |
int tilesizex, int tilesizey, int minrange, int maxrange, char *path, int pathlen, void *data); |
| 129 |
|
| 130 |
extern void SetAStarFixedUnitCrossingCost(int cost); |
| 131 |
extern int GetAStarFixedUnitCrossingCost(); |
| 132 |
|
| 133 |
extern void SetAStarMovingUnitCrossingCost(int cost); |
| 134 |
extern int GetAStarMovingUnitCrossingCost(); |
| 135 |
|
| 136 |
extern void SetAStarUnknownTerrainCost(int cost); |
| 137 |
extern int GetAStarUnknownTerrainCost(); |
| 138 |
|
| 139 |
//@} |
| 140 |
|
| 141 |
#endif // !__PATHFINDER_H__ |