Vastly simplify fpathGatewayRoute
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4885 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
ff89c2e63f
commit
76110b6156
55
src/fpath.c
55
src/fpath.c
|
@ -412,51 +412,19 @@ static BOOL fpathRouteCloser(MOVE_CONTROL *psMoveCntl, ASTAR_ROUTE *psAStarRoute
|
||||||
static FPATH_RETVAL fpathGatewayRoute(DROID* psDroid, SDWORD routeMode, SDWORD sx, SDWORD sy,
|
static FPATH_RETVAL fpathGatewayRoute(DROID* psDroid, SDWORD routeMode, SDWORD sx, SDWORD sy,
|
||||||
SDWORD fx, SDWORD fy, MOVE_CONTROL *psMoveCntl)
|
SDWORD fx, SDWORD fy, MOVE_CONTROL *psMoveCntl)
|
||||||
{
|
{
|
||||||
static SDWORD linkx, linky, gwx, gwy, asret, matchPoints;
|
|
||||||
static ASTAR_ROUTE sAStarRoute;
|
static ASTAR_ROUTE sAStarRoute;
|
||||||
FPATH_RETVAL retval = FPR_OK;
|
int asret;
|
||||||
BOOL bRouting, bFinished;
|
|
||||||
static BOOL bFirstRoute;
|
|
||||||
|
|
||||||
if (routeMode == ASR_NEWROUTE)
|
if (routeMode == ASR_NEWROUTE)
|
||||||
{
|
{
|
||||||
// initialise the move control structures
|
// initialise the move control structures
|
||||||
psMoveCntl->numPoints = 0;
|
psMoveCntl->numPoints = 0;
|
||||||
sAStarRoute.numPoints = 0;
|
sAStarRoute.numPoints = 0;
|
||||||
bFirstRoute = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep trying gateway routes until out of options
|
|
||||||
bRouting = true;
|
|
||||||
while (bRouting)
|
|
||||||
{
|
|
||||||
if (routeMode == ASR_NEWROUTE)
|
|
||||||
{
|
|
||||||
// reset matchPoints so that routing between gateways generated
|
|
||||||
// by the previous gateway route can be reused
|
|
||||||
matchPoints = 0;
|
|
||||||
sAStarRoute.numPoints = 0;
|
|
||||||
}
|
|
||||||
bFirstRoute = false;
|
|
||||||
|
|
||||||
if (routeMode == ASR_NEWROUTE)
|
|
||||||
{
|
|
||||||
linkx = sx;
|
|
||||||
linky = sy;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now generate the route
|
|
||||||
bRouting = false;
|
|
||||||
bFinished = false;
|
|
||||||
while (!bFinished)
|
|
||||||
{
|
|
||||||
gwx = fx;
|
|
||||||
gwy = fy;
|
|
||||||
|
|
||||||
objTrace(LOG_MOVEMENT, psDroid->id, "fpathGatewayRoute: astar route : (%d,%d) -> (%d,%d)",
|
objTrace(LOG_MOVEMENT, psDroid->id, "fpathGatewayRoute: astar route : (%d,%d) -> (%d,%d)",
|
||||||
map_coord(linkx), map_coord(linky),
|
map_coord(sx), map_coord(sy), map_coord(fx), map_coord(fy));
|
||||||
map_coord(gwx), map_coord(gwy));
|
asret = fpathAStarRoute(routeMode, &sAStarRoute, sx, sy, fx,fy);
|
||||||
asret = fpathAStarRoute(routeMode, &sAStarRoute, linkx,linky, gwx,gwy);
|
|
||||||
if (asret == ASR_PARTIAL)
|
if (asret == ASR_PARTIAL)
|
||||||
{
|
{
|
||||||
// routing hasn't finished yet
|
// routing hasn't finished yet
|
||||||
|
@ -465,8 +433,7 @@ static FPATH_RETVAL fpathGatewayRoute(DROID* psDroid, SDWORD routeMode, SDWORD s
|
||||||
}
|
}
|
||||||
routeMode = ASR_NEWROUTE;
|
routeMode = ASR_NEWROUTE;
|
||||||
|
|
||||||
if ((asret == ASR_NEAREST) &&
|
if (asret == ASR_NEAREST && actionRouteBlockingPos(psDroid, sAStarRoute.finalX,sAStarRoute.finalY))
|
||||||
actionRouteBlockingPos(psDroid, sAStarRoute.finalX,sAStarRoute.finalY))
|
|
||||||
{
|
{
|
||||||
// found a blocking wall - route to that
|
// found a blocking wall - route to that
|
||||||
objTrace(LOG_MOVEMENT, psDroid->id, "fpathGatewayRoute: Got blocking wall");
|
objTrace(LOG_MOVEMENT, psDroid->id, "fpathGatewayRoute: Got blocking wall");
|
||||||
|
@ -489,21 +456,15 @@ static FPATH_RETVAL fpathGatewayRoute(DROID* psDroid, SDWORD routeMode, SDWORD s
|
||||||
objTrace(LOG_MOVEMENT, psDroid->id, "fpathGatewayRoute: Failed route in same zone");
|
objTrace(LOG_MOVEMENT, psDroid->id, "fpathGatewayRoute: Failed route in same zone");
|
||||||
return FPR_FAILED;
|
return FPR_FAILED;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
linkx = gwx;
|
{
|
||||||
linky = gwy;
|
|
||||||
|
|
||||||
bFinished = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fpathRouteCloser(psMoveCntl, &sAStarRoute, fx,fy))
|
if (fpathRouteCloser(psMoveCntl, &sAStarRoute, fx,fy))
|
||||||
{
|
{
|
||||||
psMoveCntl->numPoints = 0;
|
psMoveCntl->numPoints = 0;
|
||||||
fpathAppendRoute(psMoveCntl, &sAStarRoute);
|
fpathAppendRoute(psMoveCntl, &sAStarRoute);
|
||||||
}
|
}
|
||||||
|
return FPR_OK;
|
||||||
return retval;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fpathSetCurrentDroid(DROID* psDroid)
|
void fpathSetCurrentDroid(DROID* psDroid)
|
||||||
|
|
Loading…
Reference in New Issue