Added AStar pathfinding.

It can be removed easily by undefing USE_ASTAR_PATHS.
See AStar thread in mod discussion forum for changes.

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1331 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
AalaarDB
2007-09-08 03:18:32 +00:00
parent 10208ca5af
commit c099151b37
3 changed files with 1699 additions and 1 deletions
+24 -1
View File
@@ -19,7 +19,30 @@
#define WORLD_BASE_HEIGHT 0
#define WORLD_CLIFF_HEIGHT 80
//ADB I'm tired of seeing a 5 digit number when looking at something's gridno.
//I need to see an x and y. I created this class for the AStar,
//but moved it here as you can convert a regular INT16 gridno to a GridNode then print it out for debugging.
//Don't switch between the 2 types too often, IntToGridNode is especially slow
class GridNode
{
public:
GridNode () {x = -1; y = -1;};
GridNode (INT16 const loc) {this->x = loc % WORLD_COLS; this->y = loc / WORLD_COLS;};
GridNode (int x, int y) {GridNode::x = x; GridNode::y = y;};
GridNode operator + (const GridNode& point) const {return GridNode(this->x + point.x, this->y + point.y);};
bool operator == (const GridNode& point) const {return this->x == point.x && this->y == point.y;};
bool operator != (const GridNode& point) const {return !(*this == point);};
INT16 GridNodeToInt() {return (this->x + this->y * WORLD_COLS);};
void IntToGridNode(INT16 const loc) {this->x = loc % WORLD_COLS; this->y = loc / WORLD_COLS;};
bool isInWorld() {return (this->x < WORLD_COLS && this->x >= 0 &&
this->y < WORLD_ROWS && this->y >= 0);};
int x;
int y;
};
//A macro that actually memcpy's over data and increments the pointer automatically
//based on the size. Works like a FileRead except with a buffer instead of a file pointer.
//Used by LoadWorld() and child functions.