More path-finding cleanup and documentation

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3452 4a71c877-e1ca-e34f-864e-861f7616d084
master
Per Inge Mathisen 2008-01-13 16:57:06 +00:00
parent 546abc300e
commit c0d220e335
3 changed files with 46 additions and 207 deletions

View File

@ -952,6 +952,7 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
(((DROID *)psObj)->sMove.DestinationX != tX ||
((DROID *)psObj)->sMove.DestinationX != tX))
{
// we have a partial route, but changed destination, so need to recalculate
psPartialRouteObj = NULL;
targetX = tX;
targetY = tY;
@ -980,8 +981,7 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
psDroid = (DROID *)psObj;
psPropStats = asPropulsionStats + psDroid->asBits[COMP_PROPULSION].nStat;
ASSERT( psPropStats != NULL,
"fpathRoute: invalid propulsion stats pointer" );
ASSERT(psPropStats != NULL, "fpathRoute: invalid propulsion stats pointer");
fpathSetBlockingTile( psPropStats->propulsionType );
@ -1006,8 +1006,7 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
GWTerrain = GWR_TER_LAND;
}
if ((psPartialRouteObj == NULL) ||
(psPartialRouteObj != psObj))
if (psPartialRouteObj == NULL || psPartialRouteObj != psObj)
{
// check whether the start point of the route
// is a blocking tile and find an alternative if it is
@ -1080,17 +1079,24 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
if (fpathBlockingTile(map_coord(targetX), map_coord(targetY)))
{
// route to the last clear tile found by the raycast
// Does this code work? - Per
targetX = clearX;
targetY = clearY;
objTrace(LOG_MOVEMENT, psObj->id, "Unit %d: end point is blocked, going to (%d, %d) instead",
(int)psObj->id, (int)clearX, (int)clearY);
}
// see if there is another unit with a usable route
if (fpathFindRoute((DROID *)psDroid, startX,startY, targetX,targetY))
{
objTrace(LOG_MOVEMENT, psObj->id, "fpathRoute droid %d: found route", (int)psObj->id);
if (psPartialRouteObj != NULL)
{
objTrace(LOG_MOVEMENT, psObj->id, "fpathRoute droid %d: found route during multi-frame route", (int)psObj->id);
objTrace(LOG_MOVEMENT, psObj->id, "fpathRoute droid %d: found existing route during multi-frame path",
(int)psObj->id);
}
else
{
objTrace(LOG_MOVEMENT, psObj->id, "fpathRoute droid %d: found existing route", (int)psObj->id);
}
goto exit;
}
@ -1109,6 +1115,7 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
if (astarInner > FPATH_LOOP_LIMIT)
{
// Time out
if (psPartialRouteObj == psObj)
{
retVal = FPR_WAIT;
@ -1121,16 +1128,15 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
goto exit;
}
}
else if ( ((psPartialRouteObj != NULL) &&
(psPartialRouteObj != psObj)) ||
((psPartialRouteObj != psObj) &&
(psNextRouteDroid != NULL) &&
(psNextRouteDroid != (DROID *)psObj)) )
else if ((psPartialRouteObj != NULL && psPartialRouteObj != psObj)
|| (psPartialRouteObj != psObj && psNextRouteDroid != NULL && psNextRouteDroid != (DROID *)psObj))
{
// Not our turn
retVal = FPR_RESCHEDULE;
goto exit;
}
// Now actually create a route
if (psPartialRouteObj == NULL)
{
retVal = fpathGatewayRoute(psObj, ASR_NEWROUTE, GWTerrain,
@ -1152,8 +1158,7 @@ FPATH_RETVAL fpathRoute(BASE_OBJECT *psObj, MOVE_CONTROL *psMoveCntl,
partialTX = targetX;
partialTY = targetY;
}
else if ((retVal == FPR_FAILED) &&
(psObj->type == OBJ_DROID) && vtolDroid((DROID *)psObj))
else if (retVal == FPR_FAILED && psObj->type == OBJ_DROID && vtolDroid((DROID *)psObj))
{
fpathSetDirectRoute( psObj, targetX, targetY );
retVal = FPR_OK;

View File

@ -22,15 +22,8 @@
*
*/
// print out the gateways examined while generating the route
//#define DEBUG_GROUP0
// print out the final route
//#define DEBUG_GROUP1
#include "lib/framework/frame.h"
BOOL gwrDoMessage;
#include "map.h"
#include "gateway.h"
#include "gatewayroute.h"
@ -412,8 +405,3 @@ SDWORD gwrAStarRoute(SDWORD player, UDWORD terrain,
return retval;
}

View File

@ -62,10 +62,6 @@
#include "drive.h"
//#define DEBUG_DRIVE_SPEED
/* system definitions */
/* max and min vtol heights above terrain */
#define VTOL_HEIGHT_MIN 250
#define VTOL_HEIGHT_LEVEL 300
@ -143,10 +139,6 @@
// distance from final way point to start slowing
#define END_SPEED_RANGE (3 * TILE_UNITS)
// times for rerouting
#define REROUTE_BASETIME 200
#define REROUTE_RNDTIME 400
// how long to pause after firing a FOM_NO weapon
#define FOM_MOVEPAUSE 1500
@ -240,8 +232,6 @@ static void moveCalcBoundary(DROID *psDroid);
/* Turn a vector into an angle - returns a float (!) */
static float vectorToAngle(float vx, float vy);
extern UDWORD selectedPlayer;
static BOOL g_bFormationSpeedLimitingOn = TRUE;
/* Return the difference in directions */
@ -380,9 +370,6 @@ static BOOL moveDroidToBase(DROID *psDroid, UDWORD x, UDWORD y, BOOL bFormation)
/* check formations */
if ( retVal == FPR_OK )
{
objTrace(LOG_MOVEMENT, psDroid->id, "unit(%u): base Speed %u, speed %f", psDroid->id,
psDroid->baseSpeed, psDroid->sMove.speed);
// bit of a hack this - john
// if astar doesn't have a complete route, it returns a route to the nearest clear tile.
// the location of the clear tile is in DestinationX,DestinationY.
@ -390,6 +377,9 @@ static BOOL moveDroidToBase(DROID *psDroid, UDWORD x, UDWORD y, BOOL bFormation)
x = psDroid->sMove.DestinationX;
y = psDroid->sMove.DestinationY;
objTrace(LOG_MOVEMENT, psDroid->id, "unit %d: path ok - base Speed %u, speed %f, target(%d, %d)",
(int)psDroid->id, psDroid->baseSpeed, psDroid->sMove.speed, (int)x, (int)y);
psDroid->sMove.Status = MOVENAVIGATE;
psDroid->sMove.Position=0;
psDroid->sMove.fx = psDroid->pos.x;
@ -404,8 +394,6 @@ static BOOL moveDroidToBase(DROID *psDroid, UDWORD x, UDWORD y, BOOL bFormation)
psNextRouteDroid = NULL;
}
// DBPRINTF(("moveDroidTo: form %p id %d\n",psDroid->sMove.psFormation, psDroid->id));
// leave any old formation
if (psDroid->sMove.psFormation)
{
@ -448,12 +436,10 @@ static BOOL moveDroidToBase(DROID *psDroid, UDWORD x, UDWORD y, BOOL bFormation)
}
}
}
// DBPRINTF(("moveDroidTo: form %p id %d end\n",psDroid->sMove.psFormation, psDroid->id));
}
else if (retVal == FPR_RESCHEDULE)
{
objTrace(LOG_MOVEMENT, psDroid->id, "moveDroidToBase: reroute: id %d", (int)psDroid->id);
objTrace(LOG_MOVEMENT, psDroid->id, "moveDroidToBase(%d): out of time, not our turn; rescheduled", (int)psDroid->id);
// maxed out routing time this frame - do it next time
psDroid->sMove.DestinationX = x;
@ -462,15 +448,13 @@ static BOOL moveDroidToBase(DROID *psDroid, UDWORD x, UDWORD y, BOOL bFormation)
if ((psDroid->sMove.Status != MOVEROUTE) &&
(psDroid->sMove.Status != MOVEROUTESHUFFLE))
{
objTrace(LOG_MOVEMENT, psDroid->id, "moveDroidToBase: Unit %d (player %d) started waiting at %d",
(int)psDroid->id, (int)psDroid->player, (int)gameTime);
objTrace(LOG_MOVEMENT, psDroid->id, "moveDroidToBase(%d): started waiting at %d",
(int)psDroid->id, (int)gameTime);
psDroid->sMove.Status = MOVEROUTE;
// note when the unit first tried to route
psDroid->sMove.bumpTime = gameTime;
// psDroid->sMove.bumpTime = gameTime + REROUTE_BASETIME + REROUTE_RNDTIME - (rand()%REROUTE_RNDTIME);
}
}
else if (retVal == FPR_WAIT)
@ -478,10 +462,15 @@ static BOOL moveDroidToBase(DROID *psDroid, UDWORD x, UDWORD y, BOOL bFormation)
// reset the next route droid
if (psDroid == psNextRouteDroid)
{
objTrace(LOG_MOVEMENT, psDroid->id, "Waiting droid %d (player %d) got route", (int)psDroid->id,
(int)psDroid->player);
objTrace(LOG_MOVEMENT, psDroid->id, "moveDroidToBase(%d): out of time, waiting for next frame (we are next)",
(int)psDroid->id);
psNextRouteDroid = NULL;
}
else
{
objTrace(LOG_MOVEMENT, psDroid->id, "moveDroidToBase(%d): out of time, waiting for next frame (we are not next)",
(int)psDroid->id);
}
// the route will be calculated over a number of frames
psDroid->sMove.Status = MOVEWAITROUTE;
@ -490,6 +479,7 @@ static BOOL moveDroidToBase(DROID *psDroid, UDWORD x, UDWORD y, BOOL bFormation)
}
else // if (retVal == FPR_FAILED)
{
objTrace(LOG_MOVEMENT, psDroid->id, "Path to (%d, %d) failed for droid %d", (int)x, (int)y, (int)psDroid->id);
psDroid->sMove.Status = MOVEINACTIVE;
actionDroid(psDroid, DACTION_SULK);
return(FALSE);
@ -596,10 +586,6 @@ static void moveShuffleDroid(DROID *psDroid, UDWORD shuffleStart, SDWORD sx, SDW
}
shuffleMove = SHUFFLE_MOVE;
/* if (vtolDroid(psDroid))
{
shuffleMove /= 4;
}*/
// calculate the possible movement vectors
lvx = -sy * shuffleMove / shuffleMag;
@ -690,20 +676,13 @@ static void moveShuffleDroid(DROID *psDroid, UDWORD shuffleStart, SDWORD sx, SDW
{
psDroid->sMove.Status = MOVESHUFFLE;
}
// psDroid->sMove.shuffleX = (SWORD)sx;
// psDroid->sMove.shuffleY = (SWORD)sy;
psDroid->sMove.shuffleStart = shuffleStart;
psDroid->sMove.srcX = (SDWORD)psDroid->pos.x;
psDroid->sMove.srcY = (SDWORD)psDroid->pos.y;
// psDroid->sMove.targetX = (SDWORD)psDroid->pos.x + mx;
// psDroid->sMove.targetY = (SDWORD)psDroid->pos.y + my;
psDroid->sMove.targetX = tarX;
psDroid->sMove.targetY = tarY;
// setting the Destination could overwrite a MOVEROUTE's destination
// it is not actually needed for a shuffle anyway
// psDroid->sMove.DestinationX = psDroid->sMove.targetX;
// psDroid->sMove.DestinationY = psDroid->sMove.targetY;
// psDroid->sMove.bumpTime = 0;
psDroid->sMove.numPoints = 0;
psDroid->sMove.Position = 0;
psDroid->sMove.fx = psDroid->pos.x;
@ -817,16 +796,6 @@ void updateDroidOrientation(DROID *psDroid)
roll = cos(direction) * dx - sin(direction) * dy;
roll = atan(roll);
psDroid->roll = (UWORD)((roll * 180) / M_PI);
//turret
/* direction = (PI * psDroid->turretDirection) / 180.0;
pitch = sin(direction) * dx + cos(direction) * dy;
pitch = atan(pitch);
psDroid->turretPitch = (UDWORD)((pitch * 180) / M_PI);
roll = cos(direction) * dx - sin(direction) * dy;
roll = atan(roll);
psDroid->turretRoll = (UDWORD)((roll * 180) / M_PI);
*/
return;
}
@ -2097,12 +2066,6 @@ SDWORD moveCalcDroidSpeed(DROID *psDroid)
speed = (SDWORD) calcDroidSpeed(psDroid->baseSpeed, terrainType(mapTile(mapX,mapY)),
psDroid->asBits[COMP_PROPULSION].nStat);
/* if ( vtolDroid(psDroid) &&
((asBodyStats + psDroid->asBits[COMP_BODY].nStat)->size == SIZE_HEAVY) )
{
speed /= 2;
}*/
pitch = psDroid->pitch;
if (pitch > MAX_SPEED_PITCH)
{
@ -2123,8 +2086,6 @@ SDWORD moveCalcDroidSpeed(DROID *psDroid)
}
// stop droids that have just fired a no fire while moving weapon
//if (psDroid->numWeaps > 0 && psDroid->asWeaps[0].lastFired + FOM_MOVEPAUSE > gameTime)
//Watermelon:I dont think droid with no weapon should do this check...
if (psDroid->numWeaps > 0)
{
if (psDroid->asWeaps[0].nStat > 0 && psDroid->asWeaps[0].lastFired + FOM_MOVEPAUSE > gameTime)
@ -2157,20 +2118,6 @@ SDWORD moveCalcDroidSpeed(DROID *psDroid)
speed = MIN_END_SPEED;
}
// /* adjust speed for formation */
// if ( moveFormationSpeedLimitingOn() &&
// psDroid->sMove.psFormation &&
// speed > (SDWORD)psDroid->sMove.psFormation->iSpeed )
// {
// speed = psDroid->sMove.psFormation->iSpeed;
// }
//#if(1)
// if(psDroid->selected) {
// printf("%d : %d : %d\n",driveGetSpeed(),psDroid->baseSpeed,speed);
// }
//#endif
return speed;
}
@ -2478,43 +2425,15 @@ static void moveUpdateGroundModel(DROID *psDroid, SDWORD speed, SDWORD direction
// update the naybors list
droidGetNaybors(psDroid);
#ifdef DEBUG_DRIVE_SPEED
if(psDroid == driveGetDriven()) debug( LOG_NEVER, "%d ", speed );
#endif
moveCheckFinalWaypoint( psDroid, &speed );
#ifdef DEBUG_DRIVE_SPEED
if(psDroid == driveGetDriven()) debug( LOG_NEVER, "%d ", speed );
#endif
// moveUpdateDroidDirection( psDroid, &speed, direction, TRACKED_SPIN_ANGLE,
// TRACKED_SPIN_SPEED, TRACKED_TURN_SPEED, &iDroidDir, &fSpeed );
moveUpdateDroidDirection( psDroid, &speed, direction, TRACKED_SPIN_ANGLE,
spinSpeed, turnSpeed, &iDroidDir, &fSpeed );
#ifdef DEBUG_DRIVE_SPEED
if(psDroid == driveGetDriven()) debug( LOG_NEVER, "%d ", speed );
#endif
fNormalSpeed = moveCalcNormalSpeed( psDroid, fSpeed, iDroidDir,
TRACKED_ACCEL, TRACKED_DECEL );
fNormalSpeed = moveCalcNormalSpeed(psDroid, fSpeed, iDroidDir, TRACKED_ACCEL, TRACKED_DECEL);
fPerpSpeed = moveCalcPerpSpeed( psDroid, iDroidDir, skidDecel );
moveCombineNormalAndPerpSpeeds( psDroid, fNormalSpeed,
fPerpSpeed, iDroidDir );
#ifdef DEBUG_DRIVE_SPEED
if(psDroid == driveGetDriven()) debug( LOG_NEVER, "%d\n", speed );
#endif
// if (psDroid->direction != psDroid->sMove.dir)
/* if (fPerpSpeed > 0)
{
DBPRINTF(("droid %d direction %d total dir %d perpspeed %f\n",
psDroid->id, psDroid->direction, psDroid->sMove.dir, fPerpSpeed));
}*/
moveCombineNormalAndPerpSpeeds(psDroid, fNormalSpeed, fPerpSpeed, iDroidDir);
moveGetDroidPosDiffs( psDroid, &dx, &dy );
moveCheckSquished(psDroid, dx,dy);
@ -2542,7 +2461,6 @@ static void moveUpdatePersonModel(DROID *psDroid, SDWORD speed, SDWORD direction
float fPerpSpeed, fNormalSpeed, dx, dy, fSpeed;
float iDroidDir;
SDWORD slideDir;
// BASE_OBJECT *psObst;
BOOL bRet;
// nothing to do if the droid is stopped
@ -2599,11 +2517,6 @@ static void moveUpdatePersonModel(DROID *psDroid, SDWORD speed, SDWORD direction
moveGetDroidPosDiffs( psDroid, &dx, &dy );
/* if (moveFindObstacle(psDroid, dx,dy, &psObst))
{
moveCalcSlideVector(psDroid, (SDWORD)psObst->pos.x, (SDWORD)psObst->pos.y, &dx, &dy);
}*/
moveCalcDroidSlide(psDroid, &dx,&dy);
moveCalcBlockingSlide(psDroid, &dx,&dy, direction, &slideDir);
@ -2656,7 +2569,6 @@ static void moveUpdatePersonModel(DROID *psDroid, SDWORD speed, SDWORD direction
}
}
//#define VTOL_VERTICAL_SPEED ((SDWORD)psDroid->baseSpeed / 4)
#define VTOL_VERTICAL_SPEED ((((SDWORD)psDroid->baseSpeed / 4) > 60) ? ((SDWORD)psDroid->baseSpeed / 4) : 60)
/* primitive 'bang-bang' vtol height controller */
@ -2788,49 +2700,6 @@ static void moveUpdateVtolModel(DROID *psDroid, SDWORD speed, SDWORD direction)
moveAdjustVtolHeight( psDroid, iMapZ );
}
#ifdef DEBUG
WZ_DECL_UNUSED static void moveGetStatusStr( UBYTE status, char *szStr )
{
switch ( status )
{
case MOVEINACTIVE:
strcpy( szStr, "MOVEINACTIVE" );
break;
case MOVENAVIGATE:
strcpy( szStr, "MOVENAVIGATE" );
break;
case MOVETURN:
strcpy( szStr, "MOVETURN" );
break;
case MOVEPAUSE:
strcpy( szStr, "MOVEPAUSE" );
break;
case MOVEPOINTTOPOINT:
strcpy( szStr, "MOVEPOINTTOPOINT" );
break;
case MOVETURNSTOP:
strcpy( szStr, "MOVETURNSTOP" );
break;
case MOVETURNTOTARGET:
strcpy( szStr, "MOVETURNTOTARGET" );
break;
case MOVEROUTE:
strcpy( szStr, "MOVEROUTE" );
break;
case MOVEHOVER:
strcpy( szStr, "MOVEHOVER" );
break;
case MOVEDRIVE:
strcpy( szStr, "MOVEDRIVE" );
break;
default:
strcpy( szStr, "" );
break;
}
}
#endif
#define CYBORG_VERTICAL_SPEED ((SDWORD)psDroid->baseSpeed/2)
static void
@ -2960,28 +2829,19 @@ moveUpdateCyborgModel( DROID *psDroid, SDWORD moveSpeed, SDWORD moveDir, UBYTE o
// Only add the animation if the droid is on screen, saves memory and time.
if(clipXY(psDroid->pos.x,psDroid->pos.y))
{
//DBPRINTF(("Added cyborg run anim\n"));
//What about my new cyborg droids?????!!!!!!!
/*if ( psDroid->droidType == DROID_CYBORG )
if ( psDroid->droidType == DROID_CYBORG_SUPER )
{
psDroid->psCurAnim = animObj_Add( psObj, ID_ANIM_SUPERCYBORG_RUN, 0, 0 );
}
else if (cyborgDroid(psDroid))
{
psDroid->psCurAnim = animObj_Add( psObj, ID_ANIM_CYBORG_RUN, 0, 0 );
}
else if ( psDroid->droidType == DROID_CYBORG_SUPER )
{
psDroid->psCurAnim = animObj_Add( psObj, ID_ANIM_SUPERCYBORG_RUN, 0, 0 );
}*/
if ( psDroid->droidType == DROID_CYBORG_SUPER )
{
psDroid->psCurAnim = animObj_Add( psObj, ID_ANIM_SUPERCYBORG_RUN, 0, 0 );
}
else if (cyborgDroid(psDroid))
{
psDroid->psCurAnim = animObj_Add( psObj, ID_ANIM_CYBORG_RUN, 0, 0 );
}
}
} else {
// If the droid went off screen then remove the animation, saves memory and time.
if(!clipXY(psDroid->pos.x,psDroid->pos.y)) {
if(!clipXY(psDroid->pos.x,psDroid->pos.y))
{
bRet = animObj_Remove( &psDroid->psCurAnim, psDroid->psCurAnim->psAnim->uwID );
ASSERT( bRet == TRUE, "moveUpdateCyborgModel : animObj_Remove failed" );
psDroid->psCurAnim = NULL;
@ -3108,12 +2968,11 @@ static void movePlayDroidMoveAudio( DROID *psDroid )
{
iAudioID = ID_SOUND_TREAD;
}
else if ( psDroid->droidType == DROID_TRANSPORTER )
else if (psDroid->droidType == DROID_TRANSPORTER)
{
iAudioID = ID_SOUND_BLIMP_FLIGHT;
}
//else if ( iPropType == LEGGED && psDroid->droidType == DROID_CYBORG )
else if ( iPropType == LEGGED && cyborgDroid(psDroid))
else if (iPropType == LEGGED && cyborgDroid(psDroid))
{
iAudioID = ID_SOUND_CYBORG_MOVE;
}
@ -3150,7 +3009,6 @@ static BOOL moveDroidStartCallback( void *psObj )
}
static void movePlayAudio( DROID *psDroid, BOOL bStarted, BOOL bStoppedBefore, SDWORD iMoveSpeed )
{
UBYTE propType;
@ -3173,8 +3031,8 @@ static void movePlayAudio( DROID *psDroid, BOOL bStarted, BOOL bStoppedBefore, S
if ( bStarted )
{
/* play start audio */
if ( (propType == WHEELED && psDroid->droidType != DROID_CONSTRUCT) ||
(psPropType->startID == NO_SOUND) )
if ((propType == WHEELED && psDroid->droidType != DROID_CONSTRUCT)
|| psPropType->startID == NO_SOUND)
{
movePlayDroidMoveAudio( psDroid );
return;
@ -3203,8 +3061,7 @@ static void movePlayAudio( DROID *psDroid, BOOL bStarted, BOOL bStoppedBefore, S
iAudioID = psPropType->shutDownID;
}
}
else if ( (!bStoppedBefore && !bStoppedNow) &&
(psDroid->iAudioID == NO_SOUND) )
else if (!bStoppedBefore && !bStoppedNow && psDroid->iAudioID == NO_SOUND)
{
/* play move audio */
movePlayDroidMoveAudio( psDroid );
@ -3220,17 +3077,6 @@ static void movePlayAudio( DROID *psDroid, BOOL bStarted, BOOL bStoppedBefore, S
psDroid->iAudioID = iAudioID;
}
}
#if 0
if ( oldStatus != newStatus )
{
char szOldStatus[100], szNewStatus[100];
moveGetStatusStr( oldStatus, szOldStatus );
moveGetStatusStr( newStatus, szNewStatus );
debug( LOG_NEVER, "oldStatus = %s newStatus = %s\n", szOldStatus, szNewStatus );
}
#endif
}