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