Seperate and reorder functions for easier rebasing of Per's threaded pathfinding
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5268 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
364c32afea
commit
bdf986c0e5
45
src/fpath.c
45
src/fpath.c
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include "fpath.h"
|
||||
|
||||
|
||||
/* Beware: Enabling this will cause significant slow-down. */
|
||||
#undef DEBUG_MAP
|
||||
|
||||
|
@ -48,6 +49,8 @@
|
|||
#define LIFT_BLOCK_HEIGHT_HEAVYBODY 350
|
||||
|
||||
#define NUM_DIR 8
|
||||
|
||||
|
||||
// Convert a direction into an offset
|
||||
// dir 0 => x = 0, y = -1
|
||||
static const Vector2i aDirOffset[NUM_DIR] =
|
||||
|
@ -72,6 +75,7 @@ static SDWORD partialSX,partialSY, partialTX,partialTY;
|
|||
// the last frame on which the partial route was calculatated
|
||||
static SDWORD lastPartialFrame;
|
||||
|
||||
|
||||
// initialise the findpath module
|
||||
BOOL fpathInitialise(void)
|
||||
{
|
||||
|
@ -80,11 +84,13 @@ BOOL fpathInitialise(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
void fpathShutdown()
|
||||
{
|
||||
fpathHardTableReset();
|
||||
}
|
||||
|
||||
|
||||
/** Updates the pathfinding system.
|
||||
* @post Pathfinding jobs for DROID's that died, aren't waiting for a route
|
||||
* anymore, or the currently calculated route is outdated for, are
|
||||
|
@ -103,6 +109,7 @@ void fpathUpdate(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Check if the map tile at a location blocks a droid
|
||||
BOOL fpathBlockingTile(SDWORD x, SDWORD y, PROPULSION_TYPE propulsion)
|
||||
{
|
||||
|
@ -142,6 +149,7 @@ BOOL fpathBlockingTile(SDWORD x, SDWORD y, PROPULSION_TYPE propulsion)
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** Calculate the distance to a tile from a point
|
||||
*
|
||||
* @ingroup pathfinding
|
||||
|
@ -157,11 +165,31 @@ static inline int fpathDistToTile(int tileX, int tileY, int pointX, int pointY)
|
|||
return trigIntSqrt(xdiff * xdiff + ydiff * ydiff);
|
||||
}
|
||||
|
||||
|
||||
void fpathSetDirectRoute(DROID* psDroid, SDWORD targetX, SDWORD targetY)
|
||||
{
|
||||
MOVE_CONTROL *psMoveCntl;
|
||||
|
||||
ASSERT(psDroid != NULL, "fpathSetDirectRoute: invalid droid pointer");
|
||||
ASSERT(psDroid->type == OBJ_DROID, "We got passed a DROID that isn't a DROID!");
|
||||
|
||||
psMoveCntl = &psDroid->sMove;
|
||||
|
||||
psMoveCntl->asPath = realloc(psMoveCntl->asPath, sizeof(*psMoveCntl->asPath));
|
||||
psMoveCntl->DestinationX = targetX;
|
||||
psMoveCntl->DestinationY = targetY;
|
||||
psMoveCntl->numPoints = 1;
|
||||
psMoveCntl->asPath[0].x = map_coord(targetX);
|
||||
psMoveCntl->asPath[0].y = map_coord(targetY);
|
||||
}
|
||||
|
||||
|
||||
// Variables for the callback
|
||||
static SDWORD finalX,finalY, vectorX,vectorY;
|
||||
static SDWORD clearX,clearY;
|
||||
static BOOL obstruction;
|
||||
|
||||
|
||||
/** Callback to find the first clear tile before an obstructed target
|
||||
*
|
||||
* @ingroup pathfinding
|
||||
|
@ -191,22 +219,6 @@ static bool fpathEndPointCallback(Vector3i pos, int dist, void* data)
|
|||
return true;
|
||||
}
|
||||
|
||||
void fpathSetDirectRoute(DROID* psDroid, SDWORD targetX, SDWORD targetY)
|
||||
{
|
||||
MOVE_CONTROL *psMoveCntl;
|
||||
|
||||
ASSERT(psDroid != NULL, "fpathSetDirectRoute: invalid droid pointer");
|
||||
ASSERT(psDroid->type == OBJ_DROID, "We got passed a DROID that isn't a DROID!");
|
||||
|
||||
psMoveCntl = &psDroid->sMove;
|
||||
|
||||
psMoveCntl->asPath = realloc(psMoveCntl->asPath, sizeof(*psMoveCntl->asPath));
|
||||
psMoveCntl->DestinationX = targetX;
|
||||
psMoveCntl->DestinationY = targetY;
|
||||
psMoveCntl->numPoints = 1;
|
||||
psMoveCntl->asPath[0].x = map_coord(targetX);
|
||||
psMoveCntl->asPath[0].y = map_coord(targetY);
|
||||
}
|
||||
|
||||
/** Create a final route from a gateway route
|
||||
*
|
||||
|
@ -247,6 +259,7 @@ static FPATH_RETVAL fpathGatewayRoute(DROID* psDroid, SDWORD routeMode, SDWORD s
|
|||
return FPR_OK;
|
||||
}
|
||||
|
||||
|
||||
// Find a route for an DROID to a location
|
||||
FPATH_RETVAL fpathRoute(DROID* psDroid, SDWORD tX, SDWORD tY)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue