Prune a ton of dead code from path-finding.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2828 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
61a216a6d8
commit
e37197da6c
638
src/astar.c
638
src/astar.c
|
@ -35,14 +35,9 @@
|
|||
|
||||
#include "astar.h"
|
||||
|
||||
// open list storage methods :
|
||||
// binary tree - 0
|
||||
// ordered list - 1
|
||||
// unordered list - 2
|
||||
#define OPEN_LIST 2
|
||||
|
||||
SDWORD firstHit, secondHit;
|
||||
SDWORD astarInner,astarOuter, astarRemove;
|
||||
static SDWORD astarOuter, astarRemove;
|
||||
SDWORD astarInner;
|
||||
static UWORD seed = 1234; // random seed
|
||||
|
||||
// The structure to store a node of the route
|
||||
typedef struct _fp_node
|
||||
|
@ -50,14 +45,8 @@ typedef struct _fp_node
|
|||
SWORD x,y; // map coords
|
||||
SWORD dist, est; // distance so far and estimate to end
|
||||
SWORD type; // open or closed node
|
||||
|
||||
#if OPEN_LIST == 0
|
||||
struct _fp_node *psLeft, *psRight; // Open list pointer
|
||||
#else
|
||||
struct _fp_node *psOpen;
|
||||
#endif
|
||||
struct _fp_node *psRoute; // Previous point in the route
|
||||
|
||||
struct _fp_node *psNext;
|
||||
} FP_NODE;
|
||||
|
||||
|
@ -72,28 +61,11 @@ FP_NODE *psOpen;
|
|||
//#define FPATH_TABLESIZE 20671
|
||||
#define FPATH_TABLESIZE 4091
|
||||
|
||||
#if OPEN_LIST == 2
|
||||
// Hash table for closed nodes
|
||||
FP_NODE **apsNodes=NULL;
|
||||
#else
|
||||
// Hash table for closed nodes
|
||||
FP_NODE **apsClosed;
|
||||
// Hash table for open nodes
|
||||
FP_NODE **apsOpen;
|
||||
#endif
|
||||
|
||||
/*#define NUM_DIR 4
|
||||
// Convert a direction into an offset
|
||||
// dir 0 => x = 0, y = -1
|
||||
static POINT aDirOffset[NUM_DIR] =
|
||||
{
|
||||
0, 1,
|
||||
-1, 0,
|
||||
0,-1,
|
||||
1, 0,
|
||||
};*/
|
||||
|
||||
#define NUM_DIR 8
|
||||
|
||||
// Convert a direction into an offset
|
||||
// dir 0 => x = 0, y = -1
|
||||
static Vector2i aDirOffset[NUM_DIR] =
|
||||
|
@ -108,7 +80,6 @@ static Vector2i aDirOffset[NUM_DIR] =
|
|||
{ 1, 1},
|
||||
};
|
||||
|
||||
|
||||
// reset the astar counters
|
||||
void astarResetCounters(void)
|
||||
{
|
||||
|
@ -126,45 +97,21 @@ static void ClearAstarNodes(void)
|
|||
// Initialise the findpath routine
|
||||
BOOL astarInitialise(void)
|
||||
{
|
||||
#if OPEN_LIST == 2
|
||||
apsNodes = (FP_NODE**)malloc(sizeof(FP_NODE *) * FPATH_TABLESIZE);
|
||||
if (!apsNodes)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
ClearAstarNodes();
|
||||
#else
|
||||
// Create the two hash tables
|
||||
apsOpen = malloc(sizeof(FP_NODE *) * FPATH_TABLESIZE);
|
||||
if (!apsOpen)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
memset(apsOpen, 0, sizeof(FP_NODE *) * FPATH_TABLESIZE);
|
||||
apsClosed = malloc(sizeof(FP_NODE *) * FPATH_TABLESIZE);
|
||||
if (!apsClosed)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
memset(apsClosed, 0, sizeof(FP_NODE *) * FPATH_TABLESIZE);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Shutdown the findpath routine
|
||||
void fpathShutDown(void)
|
||||
{
|
||||
#if OPEN_LIST == 2
|
||||
free(apsNodes);
|
||||
apsNodes = NULL;
|
||||
#else
|
||||
free(apsOpen);
|
||||
free(apsClosed);
|
||||
apsOpen = NULL;
|
||||
apsClosed = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
// calculate a hash table index
|
||||
|
@ -230,7 +177,6 @@ static void fpathHashAdd(FP_NODE *apsTable[], FP_NODE *psNode)
|
|||
apsTable[index] = psNode;
|
||||
}
|
||||
|
||||
|
||||
// See if a node is in the hash table
|
||||
static FP_NODE *fpathHashPresent(FP_NODE *apsTable[], SDWORD x, SDWORD y)
|
||||
{
|
||||
|
@ -247,81 +193,6 @@ static FP_NODE *fpathHashPresent(FP_NODE *apsTable[], SDWORD x, SDWORD y)
|
|||
return psFound;
|
||||
}
|
||||
|
||||
#if OPEN_LIST == 0 || OPEN_LIST == 1
|
||||
// Remove a node from the hash table
|
||||
static FP_NODE *fpathHashRemove(FP_NODE *apsTable[], SDWORD x, SDWORD y)
|
||||
{
|
||||
SDWORD index;
|
||||
FP_NODE *psPrev, *psFound;
|
||||
|
||||
index = fpathHashFunc(x,y);
|
||||
if (apsTable[index] &&
|
||||
apsTable[index]->x == x && apsTable[index]->y == y)
|
||||
{
|
||||
psFound = apsTable[index];
|
||||
apsTable[index] = apsTable[index]->psNext;
|
||||
}
|
||||
else
|
||||
{
|
||||
psPrev = NULL;
|
||||
for(psFound = apsTable[index]; psFound; psFound = psFound->psNext)
|
||||
{
|
||||
if (psFound->x == x && psFound->y == y)
|
||||
{
|
||||
break;
|
||||
}
|
||||
psPrev = psFound;
|
||||
}
|
||||
if (psFound)
|
||||
{
|
||||
psPrev->psNext = psFound->psNext;
|
||||
}
|
||||
}
|
||||
|
||||
return psFound;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPEN_LIST == 0 || OPEN_LIST == 1
|
||||
// Remove a node from the hash table
|
||||
static FP_NODE *fpathHashCondRemove(FP_NODE *apsTable[], SDWORD x, SDWORD y, SDWORD dist)
|
||||
{
|
||||
SDWORD index;
|
||||
FP_NODE *psPrev, *psFound;
|
||||
|
||||
index = fpathHashFunc(x,y);
|
||||
if (apsTable[index] &&
|
||||
apsTable[index]->x == x && apsTable[index]->y == y)
|
||||
{
|
||||
psFound = apsTable[index];
|
||||
if (psFound->dist > dist)
|
||||
{
|
||||
apsTable[index] = apsTable[index]->psNext;
|
||||
}
|
||||
firstHit ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
psPrev = NULL;
|
||||
for(psFound = apsTable[index]; psFound; psFound = psFound->psNext)
|
||||
{
|
||||
if (psFound->x == x && psFound->y == y)
|
||||
{
|
||||
break;
|
||||
}
|
||||
psPrev = psFound;
|
||||
}
|
||||
if (psFound && psFound->dist > dist)
|
||||
{
|
||||
psPrev->psNext = psFound->psNext;
|
||||
}
|
||||
secondHit ++;
|
||||
}
|
||||
|
||||
return psFound;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Reset the hash tables
|
||||
static void fpathHashReset(void)
|
||||
{
|
||||
|
@ -330,31 +201,15 @@ static void fpathHashReset(void)
|
|||
|
||||
for(i=0; i<FPATH_TABLESIZE; i++)
|
||||
{
|
||||
#if OPEN_LIST == 2
|
||||
while (apsNodes[i])
|
||||
{
|
||||
psNext = apsNodes[i]->psNext;
|
||||
free(apsNodes[i]);
|
||||
apsNodes[i] = psNext;
|
||||
}
|
||||
#else
|
||||
while (apsOpen[i])
|
||||
{
|
||||
psNext = apsOpen[i]->psNext;
|
||||
free(apsOpen[i]);
|
||||
apsOpen[i] = psNext;
|
||||
}
|
||||
while (apsClosed[i])
|
||||
{
|
||||
psNext = apsClosed[i]->psNext;
|
||||
free(apsClosed[i]);
|
||||
apsClosed[i] = psNext;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Compare two nodes
|
||||
static inline SDWORD fpathCompare(FP_NODE *psFirst, FP_NODE *psSecond)
|
||||
{
|
||||
|
@ -385,9 +240,7 @@ static inline SDWORD fpathCompare(FP_NODE *psFirst, FP_NODE *psSecond)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// make a 50/50 random choice
|
||||
static UWORD seed = 1234;
|
||||
static BOOL fpathRandChoice(void)
|
||||
{
|
||||
UDWORD val;
|
||||
|
@ -398,243 +251,6 @@ static BOOL fpathRandChoice(void)
|
|||
return val & 1;
|
||||
}
|
||||
|
||||
#if OPEN_LIST == 0
|
||||
|
||||
// Add a node to the open list
|
||||
static void fpathOpenAdd(FP_NODE *psNode)
|
||||
{
|
||||
FP_NODE *psCurr, *psPrev;
|
||||
SDWORD comp;
|
||||
|
||||
psNode->psLeft = NULL;
|
||||
psNode->psRight = NULL;
|
||||
|
||||
if (psOpen == NULL)
|
||||
{
|
||||
// Nothing in the open set, add at root
|
||||
psOpen = psNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Search the tree for the insertion point
|
||||
psCurr = psOpen;
|
||||
while (psCurr != NULL)
|
||||
{
|
||||
psPrev = psCurr;
|
||||
comp = fpathCompare(psNode, psCurr);
|
||||
if (comp < 0)
|
||||
{
|
||||
psCurr = psCurr->psLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
psCurr = psCurr->psRight;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the node to the tree
|
||||
if (comp < 0)
|
||||
{
|
||||
psPrev->psLeft = psNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
psPrev->psRight = psNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove a node from the open list
|
||||
static void fpathOpenRemove(FP_NODE *psNode)
|
||||
{
|
||||
FP_NODE *psCurr, *psParent, *psSubParent, *psInsert;
|
||||
SDWORD comp;
|
||||
|
||||
if (psNode == psOpen)
|
||||
{
|
||||
// deleting the root
|
||||
psParent = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// find the parent of the node to delete
|
||||
psCurr = psOpen;
|
||||
while (psCurr && psCurr != psNode)
|
||||
{
|
||||
psParent = psCurr;
|
||||
comp = fpathCompare(psNode, psCurr);
|
||||
if (comp < 0)
|
||||
{
|
||||
psCurr = psCurr->psLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
psCurr = psCurr->psRight;
|
||||
}
|
||||
}
|
||||
ASSERT( psCurr != NULL,
|
||||
"fpathOpenRemove: couldn't find node" );
|
||||
}
|
||||
|
||||
// Find the node to take the deleted nodes place in the tree
|
||||
if (psNode->psLeft == NULL)
|
||||
{
|
||||
// simple case only right subtree
|
||||
psInsert = psNode->psRight;
|
||||
}
|
||||
else if (psNode->psRight == NULL)
|
||||
{
|
||||
// simple case only left subtree
|
||||
psInsert = psNode->psLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
// both subtrees present - find a node to replace this one in the tree
|
||||
psInsert = psNode->psRight;
|
||||
if (psInsert->psLeft == NULL)
|
||||
{
|
||||
psInsert->psLeft = psNode->psLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (psInsert->psLeft != NULL)
|
||||
{
|
||||
psSubParent = psInsert;
|
||||
psInsert=psInsert->psLeft;
|
||||
}
|
||||
psSubParent->psLeft = psInsert->psRight;
|
||||
psInsert->psLeft = psNode->psLeft;
|
||||
psInsert->psRight = psNode->psRight;
|
||||
}
|
||||
}
|
||||
|
||||
// replace the deleted node in the tree
|
||||
if (psParent == NULL)
|
||||
{
|
||||
psOpen = psInsert;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (comp < 0)
|
||||
{
|
||||
psParent->psLeft = psInsert;
|
||||
}
|
||||
else
|
||||
{
|
||||
psParent->psRight = psInsert;
|
||||
}
|
||||
}
|
||||
|
||||
psNode->psLeft = NULL;
|
||||
psNode->psRight = NULL;
|
||||
}
|
||||
|
||||
// Get the nearest entry in the open list
|
||||
static FP_NODE *fpathOpenGet(void)
|
||||
{
|
||||
FP_NODE *psNode, *psPrev;
|
||||
|
||||
if (psOpen == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
psPrev = NULL;
|
||||
for(psNode = psOpen; psNode->psLeft != NULL; psNode = psNode->psLeft)
|
||||
{
|
||||
psPrev = psNode;
|
||||
}
|
||||
|
||||
if (psPrev == NULL)
|
||||
{
|
||||
psOpen = psNode->psRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
psPrev->psLeft = psNode->psRight;
|
||||
}
|
||||
|
||||
return psNode;
|
||||
}
|
||||
|
||||
|
||||
// Check the binary tree is valid
|
||||
BOOL fpathValidateTree(FP_NODE *psNode)
|
||||
{
|
||||
BOOL left, right;
|
||||
|
||||
left = TRUE;
|
||||
if (psNode->psLeft)
|
||||
{
|
||||
if (fpathCompare(psNode->psLeft, psNode) >= 0)
|
||||
{
|
||||
left = FALSE;
|
||||
}
|
||||
if (left)
|
||||
{
|
||||
left = fpathValidateTree(psNode->psLeft);
|
||||
}
|
||||
}
|
||||
right = TRUE;
|
||||
if (psNode->psRight)
|
||||
{
|
||||
if (fpathCompare(psNode->psRight, psNode) < 0)
|
||||
{
|
||||
right = FALSE;
|
||||
}
|
||||
if (right)
|
||||
{
|
||||
right = fpathValidateTree(psNode->psRight);
|
||||
}
|
||||
}
|
||||
|
||||
return left && right;
|
||||
}
|
||||
|
||||
#elif OPEN_LIST == 1
|
||||
|
||||
// Add a node to the open list
|
||||
static void fpathOpenAdd(FP_NODE *psNode)
|
||||
{
|
||||
FP_NODE *psCurr,*psPrev;
|
||||
|
||||
if (psOpen == NULL || fpathCompare(psNode, psOpen) < 0)
|
||||
{
|
||||
// Add to start
|
||||
psNode->psOpen = psOpen;
|
||||
psOpen = psNode;
|
||||
debug( LOG_NEVER, "OpenAdd: start\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add in the middle
|
||||
psPrev = NULL;
|
||||
for(psCurr = psOpen; psCurr && fpathCompare(psNode, psCurr) >= 0;
|
||||
psCurr = psCurr->psOpen)
|
||||
{
|
||||
psPrev = psCurr;
|
||||
}
|
||||
psNode->psOpen = psCurr;
|
||||
psPrev->psOpen = psNode;
|
||||
debug( LOG_MOVEMENT, ("OpenAdd: after %d,%d dist %d\n",
|
||||
psPrev->x,psPrev->y, psPrev->dist));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get the nearest entry in the open list
|
||||
static FP_NODE *fpathOpenGet(void)
|
||||
{
|
||||
FP_NODE *psNode;
|
||||
|
||||
psNode = psOpen;
|
||||
psOpen = psOpen->psOpen;
|
||||
|
||||
return psNode;
|
||||
}
|
||||
|
||||
#elif OPEN_LIST == 2
|
||||
|
||||
// Add a node to the open list
|
||||
static void fpathOpenAdd(FP_NODE *psNode)
|
||||
{
|
||||
|
@ -681,47 +297,6 @@ static FP_NODE *fpathOpenGet(void)
|
|||
return psNode;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if OPEN_LIST == 0 || OPEN_LIST == 1
|
||||
// Remove a node from the open list
|
||||
static void fpathOpenRemove(FP_NODE *psNode)
|
||||
{
|
||||
FP_NODE *psCurr,*psPrev;
|
||||
|
||||
if (psOpen == NULL)
|
||||
{
|
||||
ASSERT(!"empty/NULL list", "fpathOpenRemove: NULL list");
|
||||
return;
|
||||
}
|
||||
else if (psNode == psOpen)
|
||||
{
|
||||
// Remove from start
|
||||
psOpen = psOpen->psOpen;
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove from the middle
|
||||
psPrev = NULL;
|
||||
for(psCurr = psOpen; psCurr && psCurr != psNode;
|
||||
psCurr = psCurr->psOpen)
|
||||
{
|
||||
psPrev = psCurr;
|
||||
}
|
||||
if (psCurr)
|
||||
{
|
||||
psPrev->psOpen = psCurr->psOpen;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(!"unable to find node", "fpathOpenRemove: failed to find node");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// estimate the distance to the target point
|
||||
static SDWORD fpathEstimate(SDWORD x, SDWORD y, SDWORD fx, SDWORD fy)
|
||||
{
|
||||
|
@ -736,7 +311,6 @@ static SDWORD fpathEstimate(SDWORD x, SDWORD y, SDWORD fx, SDWORD fy)
|
|||
return xdiff > ydiff ? xdiff + ydiff/2 : xdiff/2 + ydiff;
|
||||
}
|
||||
|
||||
|
||||
// Generate a new node
|
||||
static FP_NODE *fpathNewNode(SDWORD x, SDWORD y, SDWORD dist, FP_NODE *psRoute)
|
||||
{
|
||||
|
@ -757,7 +331,6 @@ static FP_NODE *fpathNewNode(SDWORD x, SDWORD y, SDWORD dist, FP_NODE *psRoute)
|
|||
return psNode;
|
||||
}
|
||||
|
||||
|
||||
// Variables for the callback
|
||||
static SDWORD finalX,finalY, vectorX,vectorY;
|
||||
static BOOL obstruction;
|
||||
|
@ -787,7 +360,6 @@ static BOOL fpathVisCallback(SDWORD x, SDWORD y, SDWORD dist)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Check los between two tiles
|
||||
BOOL fpathTileLOS(SDWORD x1,SDWORD y1, SDWORD x2,SDWORD y2)
|
||||
{
|
||||
|
@ -810,7 +382,6 @@ BOOL fpathTileLOS(SDWORD x1,SDWORD y1, SDWORD x2,SDWORD y2)
|
|||
return !obstruction;
|
||||
}
|
||||
|
||||
|
||||
// Optimise the route
|
||||
static void fpathOptimise(FP_NODE *psRoute)
|
||||
{
|
||||
|
@ -846,197 +417,6 @@ static void fpathOptimise(FP_NODE *psRoute)
|
|||
} while (psCurr);
|
||||
}
|
||||
|
||||
#if OPEN_LIST == 0 || OPEN_LIST == 1
|
||||
// A* findpath
|
||||
BOOL fpathAStarRoute(ASTAR_ROUTE *psRoutePoints,
|
||||
SDWORD sx, SDWORD sy, SDWORD fx, SDWORD fy)
|
||||
{
|
||||
FP_NODE *psCurr, *psNew, *psRoute;
|
||||
FP_NODE *psCFound, *psOFound;
|
||||
SDWORD tileSX,tileSY,tileFX,tileFY;
|
||||
SDWORD dir, x,y, currDist;
|
||||
SDWORD index;
|
||||
SDWORD numPoints;
|
||||
|
||||
/* firstHit=0;
|
||||
secondHit=0;
|
||||
astarInner=0;
|
||||
astarOuter=0;
|
||||
astarRemove=0;*/
|
||||
|
||||
tileSX = map_coord(sx);
|
||||
tileSY = map_coord(sy);
|
||||
|
||||
tileFX = map_coord(fx);
|
||||
tileFY = map_coord(fy);
|
||||
|
||||
// Add the start point to the open list
|
||||
psCurr = fpathNewNode(tileSX,tileSY, 0, NULL);
|
||||
if (!psCurr)
|
||||
{
|
||||
goto exit_error;
|
||||
}
|
||||
psCurr->est = fpathEstimate(psCurr->x, psCurr->y, tileFX, tileFY);
|
||||
psOpen = NULL;
|
||||
fpathOpenAdd(psCurr);
|
||||
fpathHashAdd(apsOpen, psCurr);
|
||||
|
||||
// search for a route
|
||||
psRoute = NULL;
|
||||
while (psOpen != NULL)
|
||||
{
|
||||
psCurr = fpathOpenGet();
|
||||
// debug( LOG_NEVER, "\nStart : %3d,%3d (%d,%d) = %d\n", psCurr->x,psCurr->y, psCurr->dist, psCurr->est, psCurr->dist + psCurr->est );
|
||||
|
||||
if (psCurr->x == tileFX && psCurr->y == tileFY)
|
||||
{
|
||||
// reached the target
|
||||
psRoute = psCurr;
|
||||
break;
|
||||
}
|
||||
|
||||
astarOuter += 1;
|
||||
|
||||
for(dir=0; dir<NUM_DIR; dir+=1)
|
||||
{
|
||||
if (dir % 2 == 0)
|
||||
{
|
||||
currDist = psCurr->dist + 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
currDist = psCurr->dist + 14;
|
||||
}
|
||||
|
||||
// Try a new location
|
||||
x = psCurr->x + aDirOffset[dir].x;
|
||||
y = psCurr->y + aDirOffset[dir].y;
|
||||
if (fpathBlockingTile(x,y))
|
||||
{
|
||||
// tile is blocked, skip it
|
||||
// debug( LOG_NEVER, "blocked : %3d, %3d\n", x, y );
|
||||
continue;
|
||||
}
|
||||
|
||||
// See if this is already in the open list
|
||||
psOFound = fpathHashCondRemove(apsOpen, x,y, currDist);
|
||||
if (psOFound && psOFound->dist <= currDist)
|
||||
{
|
||||
// already in the open list by a shorter route
|
||||
// debug( LOG_NEVER, "blocked open : %3d, %3d dist %d\n", x, y, currDist );
|
||||
continue;
|
||||
}
|
||||
|
||||
// See if this is in the closed list
|
||||
psCFound = fpathHashCondRemove(apsClosed, x,y, currDist);
|
||||
ASSERT( !(psOFound && psCFound),
|
||||
"fpathAStarRoute: found point in open and closed lists" );
|
||||
if (psCFound && psCFound->dist <= currDist)
|
||||
{
|
||||
// already in the closed list by a shorter route
|
||||
// debug( LOG_NEVER, "blocked closed : %3d, %3d dist %d\n", x, y, currDist );
|
||||
continue;
|
||||
}
|
||||
|
||||
astarInner += 1;
|
||||
|
||||
// Now insert the point into the appropriate list
|
||||
if (!psOFound && !psCFound)
|
||||
{
|
||||
// Not in open or closed lists - add to the open list
|
||||
psNew = fpathNewNode(x,y, currDist, psCurr);
|
||||
psNew->est = fpathEstimate(x,y, tileFX, tileFY);
|
||||
fpathOpenAdd(psNew);
|
||||
fpathHashAdd(apsOpen, psNew);
|
||||
// debug( LOG_NEVER, "new : %3d, %3d (%d,%d) = %d\n", x, y, currDist, psNew->est, currDist + psNew->est );
|
||||
}
|
||||
else if (psOFound && !psCFound)
|
||||
{
|
||||
astarRemove += 1;
|
||||
|
||||
// already in the open list but this is shorter
|
||||
fpathOpenRemove(psOFound);
|
||||
psOFound->dist = currDist;
|
||||
psOFound->psRoute = psCurr;
|
||||
fpathOpenAdd(psOFound);
|
||||
fpathHashAdd(apsOpen, psOFound);
|
||||
// debug( LOG_NEVER, "replace open : %3d, %3d dist %d\n", x, y, currDist, psOFound->est, currDist + psOFound->est );
|
||||
}
|
||||
else if (!psOFound && psCFound)
|
||||
{
|
||||
// already in the closed list but this is shorter
|
||||
psCFound->dist = currDist;
|
||||
psCFound->psRoute = psCurr;
|
||||
fpathOpenAdd(psCFound);
|
||||
fpathHashAdd(apsOpen, psCFound);
|
||||
// debug( _LOG_NEVER, "replace closed : %3d, %3d dist %d\n", x, y, currDist, psCFound->est, currDist + psCFound->est );
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(!"the open and closed lists are fried/wrong", "fpathAStarRoute: the open and closed lists are f***ed");
|
||||
}
|
||||
}
|
||||
|
||||
// ASSERT( fpathValidateTree(psOpen),
|
||||
// "fpathAStarRoute: Invalid open tree" );
|
||||
|
||||
// add the current point to the closed nodes
|
||||
fpathHashRemove(apsOpen, psCurr->x, psCurr->y);
|
||||
fpathHashAdd(apsClosed, psCurr);
|
||||
// debug( LOG_NEVER, "HashAdd - closed : %3d,%3d (%d,%d) = %d\n", psCurr->x, psCurr->y, psCurr->dist, psCurr->est, psCurr->dist+psCurr->est );
|
||||
}
|
||||
|
||||
// optimise the route if one was found
|
||||
if (psRoute)
|
||||
{
|
||||
fpathOptimise(psRoute);
|
||||
|
||||
numPoints = 0;
|
||||
for(psCurr = psRoute; psCurr; psCurr=psCurr->psRoute)
|
||||
{
|
||||
numPoints ++;
|
||||
}
|
||||
index = numPoints -1;
|
||||
if (numPoints >= TRAVELSIZE)
|
||||
{
|
||||
numPoints = TRAVELSIZE -1;
|
||||
}
|
||||
psCurr = psRoute;
|
||||
while (psCurr)
|
||||
{
|
||||
if (index < numPoints)
|
||||
{
|
||||
psMoveCntl->MovementList[index].XCoordinate =
|
||||
world_coord(psCurr->x) + TILE_UNITS/2;
|
||||
psMoveCntl->MovementList[index].YCoordinate =
|
||||
world_coord(psCurr->y) + TILE_UNITS/2;
|
||||
}
|
||||
index -= 1;
|
||||
psCurr = psCurr->psRoute;
|
||||
}
|
||||
psMoveCntl->MovementList[numPoints].XCoordinate = -1;
|
||||
psMoveCntl->MovementList[numPoints].YCoordinate = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
psMoveCntl->MovementList[0].XCoordinate = -1;
|
||||
psMoveCntl->MovementList[0].YCoordinate = -1;
|
||||
}
|
||||
|
||||
fpathHashReset();
|
||||
// fpathOpenReset();
|
||||
|
||||
|
||||
return TRUE;
|
||||
|
||||
exit_error:
|
||||
fpathHashReset();
|
||||
// fpathOpenReset();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#elif OPEN_LIST == 2
|
||||
|
||||
// A* findpath
|
||||
SDWORD fpathAStarRoute(SDWORD routeMode, ASTAR_ROUTE *psRoutePoints,
|
||||
SDWORD sx, SDWORD sy, SDWORD fx, SDWORD fy)
|
||||
|
@ -1048,12 +428,6 @@ static FP_NODE *psNearest, *psRoute;
|
|||
SDWORD index;
|
||||
SDWORD retval;
|
||||
|
||||
/* firstHit=0;
|
||||
secondHit=0;
|
||||
astarInner=0;
|
||||
astarOuter=0;
|
||||
astarRemove=0;*/
|
||||
|
||||
tileSX = map_coord(sx);
|
||||
tileSY = map_coord(sy);
|
||||
|
||||
|
@ -1088,7 +462,6 @@ static FP_NODE *psNearest, *psRoute;
|
|||
}
|
||||
|
||||
psCurr = fpathOpenGet();
|
||||
// debug( LOG_NEVER, "\nStart : %3d,%3d (%d,%d) = %d\n", psCurr->x, psCurr->y, psCurr->dist, psCurr->est, psCurr->dist + psCurr->est );
|
||||
|
||||
if (psCurr->x == tileFX && psCurr->y == tileFY)
|
||||
{
|
||||
|
@ -1256,6 +629,3 @@ exit_error:
|
|||
// fpathOpenReset();
|
||||
return ASR_FAILED;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,10 +35,9 @@ typedef struct _astar_route
|
|||
|
||||
// Sizes for the node heap
|
||||
#define FPATH_NODEINIT 600
|
||||
#define FPATH_NODEEXT 0
|
||||
|
||||
// counters for a-star
|
||||
extern SDWORD astarInner,astarOuter, astarRemove;
|
||||
extern SDWORD astarInner;
|
||||
|
||||
// reset the astar counters
|
||||
extern void astarResetCounters(void);
|
||||
|
|
|
@ -588,8 +588,6 @@ BOOL saveConfig(void)
|
|||
setWarzoneKeyNumeric("sequences",(SDWORD)(war_GetSeqMode())); // sequences
|
||||
setWarzoneKeyNumeric("subtitles",(SDWORD)(seq_GetSubtitles())); // subtitles
|
||||
setWarzoneKeyNumeric("reopenBuild",(SDWORD)(intGetReopenBuild())); // build menu
|
||||
// setWarzoneKeyNumeric("maxRoute",(SDWORD)(fpathGetMaxRoute())); // maximum routing
|
||||
|
||||
setWarzoneKeyNumeric("radarObjectMode",(SDWORD)bEnemyAllyRadarColor); // enemy/allies radar view
|
||||
setWarzoneKeyNumeric("radarTerrainMode",(SDWORD)radarDrawMode);
|
||||
|
||||
|
|
336
src/fpath.c
336
src/fpath.c
|
@ -24,13 +24,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// route success printf's
|
||||
//#define DEBUG_GROUP0
|
||||
// way point printf's
|
||||
//#define DEBUG_GROUP1
|
||||
// gateway route printf's
|
||||
//#define DEBUG_GROUP2
|
||||
|
||||
#include "lib/framework/frame.h"
|
||||
|
||||
#include "objects.h"
|
||||
|
@ -40,9 +33,6 @@
|
|||
#include "hci.h"
|
||||
#include "order.h"
|
||||
|
||||
#ifdef TEST_BED
|
||||
#include "main.h"
|
||||
#endif
|
||||
#include "astar.h"
|
||||
#include "gateway.h"
|
||||
#include "gatewayroute.h"
|
||||
|
@ -88,11 +78,7 @@ static SDWORD partialSX,partialSY, partialTX,partialTY;
|
|||
// the last frame on which the partial route was calculatated
|
||||
static SDWORD lastPartialFrame;
|
||||
|
||||
|
||||
// the maximum amount of routing to do per frame
|
||||
SDWORD astarMaxRoute = FPATH_MAX_ROUTE_INIT;
|
||||
|
||||
BOOL fpathFindRoute(DROID *psDroid, SDWORD sX,SDWORD sY, SDWORD tX,SDWORD tY);
|
||||
static BOOL fpathFindRoute(DROID *psDroid, SDWORD sX,SDWORD sY, SDWORD tX,SDWORD tY);
|
||||
|
||||
// initialise the findpath module
|
||||
BOOL fpathInitialise(void)
|
||||
|
@ -115,37 +101,14 @@ void fpathUpdate(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// access functions for the loop limit
|
||||
void fpathSetMaxRoute(SDWORD max)
|
||||
{
|
||||
astarMaxRoute = max;
|
||||
}
|
||||
SDWORD fpathGetMaxRoute(void)
|
||||
{
|
||||
return astarMaxRoute;
|
||||
}
|
||||
|
||||
#define VTOL_MAP_EDGE_TILES 1
|
||||
|
||||
// Check if the map tile at a location blocks a droid
|
||||
BOOL fpathGroundBlockingTile(SDWORD x, SDWORD y)
|
||||
{
|
||||
MAPTILE *psTile;
|
||||
// FEATURE *psFeat;
|
||||
|
||||
//doesn't look like we need this - pickATile wasn't working with it! - AB 8/2/99
|
||||
/* check VTOL limits if not routing */
|
||||
/*if ( g_psObjRoute == NULL )
|
||||
{
|
||||
if ( x < VTOL_MAP_EDGE_TILES || y < VTOL_MAP_EDGE_TILES ||
|
||||
x >= (SDWORD)mapWidth-VTOL_MAP_EDGE_TILES || y >= (SDWORD)mapHeight-VTOL_MAP_EDGE_TILES)
|
||||
{
|
||||
// coords off map - auto blocking tile
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else*/
|
||||
{
|
||||
if (x < scrollMinX+1 || y < scrollMinY+1 ||
|
||||
x >= scrollMaxX-1 || y >= scrollMaxY-1)
|
||||
|
@ -159,42 +122,17 @@ BOOL fpathGroundBlockingTile(SDWORD x, SDWORD y)
|
|||
"fpathBlockingTile: off map" );
|
||||
|
||||
psTile = mapTile((UDWORD)x, (UDWORD)y);
|
||||
/*
|
||||
// THIS CAN'T BE HERE - TESTING ONLY FIXME
|
||||
if( (TILE_HAS_STRUCTURE(psTile)) &&
|
||||
(getTileStructure(x,y)->pStructureType->type == REF_BLASTDOOR) && // slow bit
|
||||
(getTileStructure(x,y)->player==selectedPlayer) )
|
||||
{
|
||||
return(FALSE);
|
||||
}
|
||||
*/
|
||||
|
||||
/* This god awful hack RIP - John 15.2.99
|
||||
if(TILE_HAS_FEATURE(psTile))
|
||||
{
|
||||
psFeat = getTileFeature(x,y);
|
||||
if ((psFeat != NULL) &&
|
||||
(psFeat->psStats->subType == FEAT_GEN_ARTE || psFeat->psStats->subType == FEAT_OIL_DRUM))
|
||||
{
|
||||
return(FALSE);
|
||||
}
|
||||
}*/
|
||||
|
||||
#ifndef TEST_BED
|
||||
if ((psTile->tileInfoBits & BITS_FPATHBLOCK) ||
|
||||
(TILE_OCCUPIED(psTile) && !TILE_IS_NOTBLOCKING(psTile)) ||
|
||||
(terrainType(psTile) == TER_CLIFFFACE) ||
|
||||
(terrainType(psTile) == TER_WATER))
|
||||
#else
|
||||
if (psTile->tileInfoBits & BLOCKED)
|
||||
#endif
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef TEST_BED
|
||||
// Check if the map tile at a location blocks a droid
|
||||
BOOL fpathHoverBlockingTile(SDWORD x, SDWORD y)
|
||||
{
|
||||
|
@ -326,7 +264,6 @@ BOOL fpathLiftSlideBlockingTile(SDWORD x, SDWORD y)
|
|||
return FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Calculate the distance to a tile from a point
|
||||
static SDWORD fpathDistToTile(SDWORD tileX,SDWORD tileY, SDWORD pointX, SDWORD pointY)
|
||||
|
@ -766,203 +703,6 @@ static void fpathGatewayCoords(GATEWAY *psGate, SDWORD *px, SDWORD *py)
|
|||
*py = (y * TILE_UNITS) + TILE_UNITS/2;
|
||||
}
|
||||
|
||||
// create a final route from a gateway route
|
||||
#if 0
|
||||
SDWORD fpathGatewayRouteOld(BASE_OBJECT *psObj, SDWORD routeMode, SDWORD GWTerrain,
|
||||
SDWORD sx, SDWORD sy, SDWORD fx, SDWORD fy,
|
||||
MOVE_CONTROL *psMoveCntl)
|
||||
{
|
||||
static SDWORD linkx,linky, gwx,gwy, asret, routex,routey;
|
||||
ASTAR_ROUTE sAStarRoute;
|
||||
SDWORD retval = FPR_OK, gwRet;
|
||||
static GATEWAY *psCurrRoute, *psGWRoute, *psLastGW;
|
||||
BOOL bRouting = TRUE;
|
||||
BOOL firstRoute = TRUE;
|
||||
|
||||
// keep trying gateway routes until out of options
|
||||
while (bRouting)
|
||||
{
|
||||
|
||||
if (routeMode == ASR_NEWROUTE)
|
||||
{
|
||||
firstRoute = FALSE;
|
||||
|
||||
debug( LOG_MOVEMENT, "Gateway route - droid %d\n", psObj->id);
|
||||
gwRet = gwrAStarRoute(psObj->player, GWTerrain,
|
||||
sx,sy, fx,fy, &psGWRoute);
|
||||
switch (gwRet)
|
||||
{
|
||||
case GWR_OK:
|
||||
// initialise the move control structure
|
||||
psMoveCntl->numPoints = 0;
|
||||
break;
|
||||
case GWR_NEAREST:
|
||||
if (firstRoute)
|
||||
{
|
||||
// first time a route has been generated
|
||||
// initialise the move control structure
|
||||
psMoveCntl->numPoints = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( LOG_MOVEMENT, " GW route returned GWR_NEAREST for second route\n");
|
||||
// can't find a better route than the last one
|
||||
if (psMoveCntl->numPoints > 0)
|
||||
{
|
||||
// return the last route as it got as near as you can
|
||||
retval = FPR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( LOG_MOVEMENT, " no points - route failed\n");
|
||||
retval = FPR_FAILED;
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
break;
|
||||
case GWR_NOZONE:
|
||||
case GWR_SAMEZONE:
|
||||
// no zone information - try a normal route
|
||||
psGWRoute = NULL;
|
||||
break;
|
||||
case GWR_FAILED:
|
||||
debug( LOG_MOVEMENT, " Gateway route failed\n");
|
||||
retval = FPR_FAILED;
|
||||
goto exit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// stop routing through any gateways which are not in the route
|
||||
fpathSetGatewayBlock();
|
||||
|
||||
if (routeMode == ASR_NEWROUTE)
|
||||
{
|
||||
// if the start of the route is on the first gateway, skip it
|
||||
if ((psGWRoute != NULL) && fpathPointInGateway(sx,sy, psGWRoute))
|
||||
{
|
||||
psGWRoute = psGWRoute->psRoute;
|
||||
}
|
||||
|
||||
linkx = sx;
|
||||
linky = sy;
|
||||
psCurrRoute = psGWRoute;
|
||||
psLastGW = NULL;
|
||||
}
|
||||
|
||||
// now generate the route
|
||||
bRouting = FALSE;
|
||||
while (psCurrRoute != NULL)
|
||||
{
|
||||
// if the end of the route is on the last gateway, skip it
|
||||
if ((psCurrRoute->psRoute == NULL) && fpathPointInGateway(fx,fy, psCurrRoute))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* gwx = (psCurrRoute->x1 + psCurrRoute->x2)/2;
|
||||
gwy = (psCurrRoute->y1 + psCurrRoute->y2)/2;
|
||||
|
||||
gwx = gwx * TILE_UNITS + TILE_UNITS/2;
|
||||
gwy = gwy * TILE_UNITS + TILE_UNITS/2;*/
|
||||
fpathGatewayCoords(psCurrRoute, &gwx, &gwy);
|
||||
|
||||
debug( LOG_MOVEMENT, " astar route : (%d,%d) -> (%d,%d)n",
|
||||
map_coord(linkx), map_coord(linky),
|
||||
map_coord(gwx), map_coord(gwy));
|
||||
asret = fpathAStarRoute(routeMode, &sAStarRoute, linkx,linky, gwx,gwy);
|
||||
routeMode = ASR_NEWROUTE;
|
||||
if ((asret == ASR_NEAREST) &&
|
||||
actionRouteBlockingPos((DROID *)psObj, sAStarRoute.finalX,sAStarRoute.finalY))
|
||||
{
|
||||
// found a blocking wall - route to that
|
||||
fpathAppendRoute(psMoveCntl, &sAStarRoute);
|
||||
retval = FPR_OK;
|
||||
goto exit;
|
||||
}
|
||||
else if ((asret == ASR_FAILED) ||
|
||||
(asret == ASR_NEAREST))
|
||||
{
|
||||
// no route found - try ditching this gateway
|
||||
// and trying a new gateway route
|
||||
debug( LOG_MOVEMENT, " Route failed - trying new gatway route\n");
|
||||
psCurrRoute->flags |= GWR_IGNORE;
|
||||
bRouting = TRUE;
|
||||
fpathClearGatewayBlock();
|
||||
break;
|
||||
}
|
||||
else if (asret == ASR_PARTIAL)
|
||||
{
|
||||
// routing hasn't finished yet
|
||||
debug( LOG_MOVEMENT, " Reschedule\n");
|
||||
retval = FPR_WAIT;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fpathAppendRoute(psMoveCntl, &sAStarRoute);
|
||||
|
||||
linkx = gwx;
|
||||
linky = gwy;
|
||||
|
||||
psLastGW = psCurrRoute;
|
||||
psCurrRoute = psCurrRoute->psRoute;
|
||||
}
|
||||
|
||||
// only finish off if no new gateway route is going to be generated
|
||||
if (!bRouting)
|
||||
{
|
||||
asret = fpathAStarRoute(routeMode,&sAStarRoute, linkx,linky, fx,fy);
|
||||
routeMode = ASR_NEWROUTE;
|
||||
if ((asret == ASR_NEAREST) &&
|
||||
actionRouteBlockingPos((DROID *)psObj, sAStarRoute.finalX,sAStarRoute.finalY))
|
||||
{
|
||||
// found a blocking wall - route to that
|
||||
fpathAppendRoute(psMoveCntl, &sAStarRoute);
|
||||
retval = FPR_OK;
|
||||
goto exit;
|
||||
}
|
||||
else if ((psLastGW != NULL) &&
|
||||
((asret == ASR_FAILED) ||
|
||||
(asret == ASR_NEAREST)))
|
||||
{
|
||||
// no route found - try ditching the last gateway
|
||||
// and trying a new gateway route
|
||||
debug( LOG_MOVEMENT, " Route failed - trying new gatway route\n");
|
||||
psLastGW->flags |= GWR_IGNORE;
|
||||
bRouting = TRUE;
|
||||
fpathClearGatewayBlock();
|
||||
}
|
||||
else if (asret == ASR_FAILED)
|
||||
{
|
||||
debug( LOG_MOVEMENT, " Final route failed\n");
|
||||
retval = FPR_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
else if (asret == ASR_PARTIAL)
|
||||
{
|
||||
// routing hasn't finished yet
|
||||
debug( LOG_MOVEMENT, " Reschedule\n");
|
||||
retval = FPR_WAIT;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fpathAppendRoute(psMoveCntl, &sAStarRoute);
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
// reset the routing block flags
|
||||
fpathClearGatewayBlock();
|
||||
if (retval != FPR_WAIT)
|
||||
{
|
||||
fpathClearIgnore();
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void fpathBlockGatewayLink(GATEWAY *psLast, GATEWAY *psCurr)
|
||||
{
|
||||
SDWORD link, numLinks;
|
||||
|
@ -983,7 +723,6 @@ static void fpathBlockGatewayLink(GATEWAY *psLast, GATEWAY *psCurr)
|
|||
numLinks = psLast->zone1Links + psLast->zone2Links;
|
||||
for(link = 0; link < numLinks; link += 1)
|
||||
{
|
||||
// if (psLast->psLinks[link].psGateway == psCurr)
|
||||
if (psLast->psLinks[link].flags & GWRL_CHILD)
|
||||
{
|
||||
debug( LOG_MOVEMENT, " last link %d", link);
|
||||
|
@ -993,7 +732,6 @@ static void fpathBlockGatewayLink(GATEWAY *psLast, GATEWAY *psCurr)
|
|||
numLinks = psCurr->zone1Links + psCurr->zone2Links;
|
||||
for(link = 0; link < numLinks; link += 1)
|
||||
{
|
||||
// if (psCurr->psLinks[link].psGateway == psLast)
|
||||
if (psCurr->psLinks[link].flags & GWRL_PARENT)
|
||||
{
|
||||
debug( LOG_MOVEMENT, " curr link %d", link);
|
||||
|
@ -1155,11 +893,7 @@ static FPATH_RETVAL fpathGatewayRoute(BASE_OBJECT *psObj, SDWORD routeMode, SDWO
|
|||
}
|
||||
|
||||
// only route between the gateways if it wasn't done on a previous route
|
||||
// if (!fpathCheckRouteMatch(psMoveCntl, &matchPoints, gwx,gwy))
|
||||
// if (1)
|
||||
{
|
||||
// psMoveCntl->numPoints = (UBYTE)matchPoints;
|
||||
|
||||
debug( LOG_MOVEMENT, " astar route : (%d,%d) -> (%d,%d) zone %d\n",
|
||||
map_coord(linkx), map_coord(linky),
|
||||
map_coord(gwx), map_coord(gwy), zone);
|
||||
|
@ -1173,11 +907,6 @@ static FPATH_RETVAL fpathGatewayRoute(BASE_OBJECT *psObj, SDWORD routeMode, SDWO
|
|||
retval = FPR_WAIT;
|
||||
goto exit;
|
||||
}
|
||||
/* else if (asret != ASR_FAILED)
|
||||
{
|
||||
fpathAppendRoute(psMoveCntl, &sAStarRoute);
|
||||
matchPoints = psMoveCntl->numPoints;
|
||||
}*/
|
||||
routeMode = ASR_NEWROUTE;
|
||||
|
||||
if ((asret == ASR_NEAREST) &&
|
||||
|
@ -1223,14 +952,6 @@ static FPATH_RETVAL fpathGatewayRoute(BASE_OBJECT *psObj, SDWORD routeMode, SDWO
|
|||
break;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_GROUP2
|
||||
/* else
|
||||
{
|
||||
debug( LOG_MOVEMENT, " matched previous route : (%d,%d) -> (%d,%d)n",
|
||||
map_coord(linkx), map_coord(linky),
|
||||
map_coord(gwx), map_coord(gwy)));
|
||||
}*/
|
||||
#endif
|
||||
|
||||
linkx = gwx;
|
||||
linky = gwy;
|
||||
|
@ -1272,7 +993,6 @@ void fpathSetCurrentObject( BASE_OBJECT *psObj )
|
|||
// set the correct blocking tile function
|
||||
void fpathSetBlockingTile( UBYTE ubPropulsionType )
|
||||
{
|
||||
#ifndef TEST_BED
|
||||
switch ( ubPropulsionType )
|
||||
{
|
||||
case HOVER:
|
||||
|
@ -1284,12 +1004,8 @@ void fpathSetBlockingTile( UBYTE ubPropulsionType )
|
|||
default:
|
||||
fpathBlockingTile = fpathGroundBlockingTile;
|
||||
}
|
||||
#else
|
||||
fpathBlockingTile = fpathGroundBlockingTile;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Find a route for an object to a location
|
||||
FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
|
||||
SDWORD tX, SDWORD tY)
|
||||
|
@ -1298,12 +1014,10 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
|
|||
SDWORD x,y;
|
||||
SDWORD dir, nearestDir, minDist, tileDist;
|
||||
FPATH_RETVAL retVal = FPR_OK;
|
||||
// DROID *psCurr;
|
||||
DROID *psDroid = NULL;
|
||||
PROPULSION_STATS *psPropStats;
|
||||
UDWORD GWTerrain;
|
||||
|
||||
|
||||
/* set global pointer for object being routed - GJ hack */
|
||||
fpathSetCurrentObject( psObj );
|
||||
|
||||
|
@ -1374,20 +1088,6 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
|
|||
GWTerrain = GWR_TER_LAND;
|
||||
}
|
||||
|
||||
#ifndef TEST_BED
|
||||
// set all the flags for stationary droids
|
||||
/* for(psCurr = apsDroidLists[psObj->player]; psCurr; psCurr = psCurr->psNext)
|
||||
{
|
||||
if (psCurr != (DROID *)psObj &&
|
||||
!psCurr->selected &&
|
||||
psCurr->sMove.Status == MOVEINACTIVE)
|
||||
{
|
||||
psTile = mapTile(map_coord(psCurr->x), map_coord(psCurr->y));
|
||||
psTile->tileInfoBits |= BITS_FPATHBLOCK;
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
|
||||
if ((psPartialRouteObj == NULL) ||
|
||||
(psPartialRouteObj != psObj))
|
||||
{
|
||||
|
@ -1544,25 +1244,13 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
|
|||
|
||||
exit:
|
||||
|
||||
#ifndef TEST_BED
|
||||
// reset all the droid flags
|
||||
/* for(psCurr = apsDroidLists[psObj->player]; psCurr; psCurr = psCurr->psNext)
|
||||
{
|
||||
if (psCurr->sMove.Status == MOVEINACTIVE)
|
||||
{
|
||||
psTile = mapTile(map_coord(psCurr->x), map_coord(psCurr->y));
|
||||
psTile->tileInfoBits &= ~BITS_FPATHBLOCK;
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
|
||||
// reset the blocking tile function
|
||||
fpathBlockingTile = fpathGroundBlockingTile;
|
||||
|
||||
/* reset global pointer for object being routed */
|
||||
fpathSetCurrentObject( NULL );
|
||||
|
||||
#if defined(JOHN) && defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
{
|
||||
MAPTILE *psTile;
|
||||
|
||||
|
@ -1578,26 +1266,9 @@ exit:
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_GROUP1
|
||||
{
|
||||
SDWORD pos;
|
||||
|
||||
debug( LOG_MOVEMENT, "Waypoints:");
|
||||
|
||||
for(pos = 0; pos < psMoveCntl->numPoints; pos += 1)
|
||||
{
|
||||
debug( LOG_MOVEMENT, " (%d,%d)",
|
||||
psMoveCntl->asPath[pos].x,
|
||||
psMoveCntl->asPath[pos].y);
|
||||
}
|
||||
debug( LOG_MOVEMENT, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
// find the first point on the route which has both droids on the same side of it
|
||||
static BOOL fpathFindFirstRoutePoint(MOVE_CONTROL *psMove, SDWORD *pIndex, SDWORD x1,SDWORD y1, SDWORD x2,SDWORD y2)
|
||||
{
|
||||
|
@ -1621,7 +1292,7 @@ static BOOL fpathFindFirstRoutePoint(MOVE_CONTROL *psMove, SDWORD *pIndex, SDWOR
|
|||
}
|
||||
|
||||
// See if there is another unit on your side that has a route this unit can use
|
||||
BOOL fpathFindRoute(DROID *psDroid, SDWORD sX,SDWORD sY, SDWORD tX,SDWORD tY)
|
||||
static BOOL fpathFindRoute(DROID *psDroid, SDWORD sX,SDWORD sY, SDWORD tX,SDWORD tY)
|
||||
{
|
||||
FORMATION *psFormation;
|
||||
DROID *psCurr;
|
||||
|
@ -1677,6 +1348,5 @@ BOOL fpathFindRoute(DROID *psDroid, SDWORD sX,SDWORD sY, SDWORD tX,SDWORD tY)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
52
src/fpath.h
52
src/fpath.h
|
@ -27,16 +27,8 @@
|
|||
#define _fpath_h
|
||||
|
||||
// limit the number of iterations for astar
|
||||
#define FPATH_MAX_ROUTE_INIT 600 //was 400
|
||||
|
||||
extern SDWORD astarMaxRoute;
|
||||
# ifdef DEBUG
|
||||
# define FPATH_LOOP_LIMIT (astarMaxRoute / 2)
|
||||
# else
|
||||
# define FPATH_LOOP_LIMIT astarMaxRoute
|
||||
# endif
|
||||
|
||||
|
||||
#define FPATH_MAX_ROUTE_INIT 600
|
||||
#define FPATH_LOOP_LIMIT FPATH_MAX_ROUTE_INIT
|
||||
|
||||
// return values for routing
|
||||
typedef enum _fpath_retval
|
||||
|
@ -49,7 +41,6 @@ typedef enum _fpath_retval
|
|||
// spent routing this frame
|
||||
} FPATH_RETVAL;
|
||||
|
||||
|
||||
// initialise the findpath module
|
||||
extern BOOL fpathInitialise(void);
|
||||
|
||||
|
@ -58,7 +49,6 @@ extern void fpathUpdate(void);
|
|||
|
||||
// access functions for the loop limit
|
||||
extern void fpathSetMaxRoute(SDWORD max);
|
||||
extern SDWORD fpathGetMaxRoute(void);
|
||||
|
||||
// Find a route for an object to a location
|
||||
extern FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
|
||||
|
@ -82,42 +72,4 @@ extern void fpathSetCurrentObject( BASE_OBJECT *psDroid );
|
|||
extern void fpathSetDirectRoute( BASE_OBJECT *psObj,
|
||||
SDWORD targetX, SDWORD targetY );
|
||||
|
||||
/*
|
||||
// Check if the map tile at a location blocks a droid
|
||||
static inline BOOL fpathBlockingTile(SDWORD x, SDWORD y)
|
||||
{
|
||||
MAPTILE *psTile;
|
||||
|
||||
if (x < scrollMinX+1 || y < scrollMinY+1 ||
|
||||
x >= scrollMaxX-1 || y >= scrollMaxY-1)
|
||||
{
|
||||
// coords off map - auto blocking tile
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ASSERT( !(x <1 || y < 1 || x >= (SDWORD)mapWidth-1 || y >= (SDWORD)mapHeight-1),
|
||||
"fpathBlockingTile: off map" );
|
||||
|
||||
psTile = mapTile((UDWORD)x, (UDWORD)y);
|
||||
|
||||
#ifndef TEST_BED
|
||||
if ((psTile->tileInfoBits & BITS_FPATHBLOCK) ||
|
||||
TILE_OCCUPIED(psTile) ||
|
||||
TERRAIN_TYPE(psTile) == TER_CLIFFFACE)
|
||||
#else
|
||||
if (psTile->tileInfoBits & BLOCKED)
|
||||
#endif
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
typedef struct _path_point
|
||||
{
|
||||
// SDWORD XCoordinate,YCoordinate;
|
||||
UBYTE x,y;
|
||||
} PATH_POINT;
|
||||
|
||||
|
|
Loading…
Reference in New Issue