Merge branch 'waypoint-fixes' into 'master'

Big Waypoint Change

See merge request KartKrew/Kart!784
This commit is contained in:
Oni 2022-11-27 02:01:43 +00:00
commit db621c4538
7 changed files with 596 additions and 671 deletions

View file

@ -418,6 +418,7 @@ typedef struct player_s
UINT8 oldposition; // Used for taunting when you pass someone
UINT8 positiondelay; // Used for position number, so it can grow when passing
UINT32 distancetofinish;
waypoint_t *currentwaypoint;
waypoint_t *nextwaypoint;
respawnvars_t respawn; // Respawn info
tic_t airtime; // Keep track of how long you've been in the air

View file

@ -4663,7 +4663,8 @@ static void K_DrawWaypointDebugger(void)
if (stplyr != &players[displayplayers[0]]) // only for p1
return;
V_DrawString(8, 166, 0, va("'Best' Waypoint ID: %d", K_GetWaypointID(stplyr->nextwaypoint)));
V_DrawString(8, 156, 0, va("Current Waypoint ID: %d", K_GetWaypointID(stplyr->currentwaypoint)));
V_DrawString(8, 166, 0, va("Next Waypoint ID: %d", K_GetWaypointID(stplyr->nextwaypoint)));
V_DrawString(8, 176, 0, va("Finishline Distance: %d", stplyr->distancetofinish));
if (numstarposts > 0)

View file

@ -8889,6 +8889,7 @@ void K_KartPlayerAfterThink(player_t *player)
--------------------------------------------------*/
static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
{
waypoint_t *finishline = K_GetFinishLineWaypoint();
waypoint_t *bestwaypoint = NULL;
if ((player != NULL) && (player->mo != NULL) && (P_MobjWasRemoved(player->mo) == false))
@ -8896,7 +8897,8 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
waypoint_t *waypoint = K_GetBestWaypointForMobj(player->mo);
boolean updaterespawn = false;
bestwaypoint = waypoint;
// Our current waypoint.
player->currentwaypoint = bestwaypoint = waypoint;
// check the waypoint's location in relation to the player
// If it's generally in front, it's fine, otherwise, use the best next/previous waypoint.
@ -8904,13 +8906,12 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
// Otherwise it breaks the distance calculations.
if (waypoint != NULL)
{
boolean finishlinehack = false;
angle_t playerangle = player->mo->angle;
angle_t momangle = K_MomentumAngle(player->mo);
angle_t angletowaypoint =
R_PointToAngle2(player->mo->x, player->mo->y, waypoint->mobj->x, waypoint->mobj->y);
angle_t angledelta = ANGLE_MAX;
angle_t momdelta = ANGLE_MAX;
angle_t angledelta = ANGLE_180;
angle_t momdelta = ANGLE_180;
angledelta = playerangle - angletowaypoint;
if (angledelta > ANGLE_180)
@ -8924,36 +8925,17 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
momdelta = InvAngle(momdelta);
}
if (bestwaypoint == K_GetFinishLineWaypoint())
{
waypoint_t *nextwaypoint = waypoint->nextwaypoints[0];
angle_t angletonextwaypoint =
R_PointToAngle2(waypoint->mobj->x, waypoint->mobj->y, nextwaypoint->mobj->x, nextwaypoint->mobj->y);
// facing towards the finishline
if (AngleDelta(angletonextwaypoint, angletowaypoint) <= ANGLE_90)
{
finishlinehack = true;
}
}
// We're using a lot of angle calculations here, because only using facing angle or only using momentum angle both have downsides.
// nextwaypoints will be picked if you're facing OR moving forward.
// prevwaypoints will be picked if you're facing AND moving backward.
if ((angledelta > ANGLE_45 || momdelta > ANGLE_45)
&& (finishlinehack == false))
#if 0
if (angledelta > ANGLE_45 || momdelta > ANGLE_45)
#endif
{
angle_t nextbestdelta = angledelta;
angle_t nextbestmomdelta = momdelta;
angle_t nextbestdelta = ANGLE_90;
angle_t nextbestmomdelta = ANGLE_90;
size_t i = 0U;
if (K_PlayerUsesBotMovement(player))
{
// Try to force bots to use a next waypoint
nextbestdelta = ANGLE_MAX;
nextbestmomdelta = ANGLE_MAX;
}
if ((waypoint->nextwaypoints != NULL) && (waypoint->numnextwaypoints > 0U))
{
for (i = 0U; i < waypoint->numnextwaypoints; i++)
@ -8995,10 +8977,19 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
if (angledelta < nextbestdelta || momdelta < nextbestmomdelta)
{
if (P_TraceBlockingLines(player->mo, waypoint->nextwaypoints[i]->mobj) == false)
// Wanted to use a next waypoint, so remove WRONG WAY flag.
// Done here instead of when set, because of finish line
// hacks meaning we might not actually use this one, but
// we still want to acknowledge we're facing the right way.
player->pflags &= ~PF_WRONGWAY;
if (waypoint->nextwaypoints[i] != finishline) // Allow finish line.
{
// Save sight checks when all of the other checks pass, so we only do it if we have to
continue;
if (P_TraceWaypointTraversal(player->mo, waypoint->nextwaypoints[i]->mobj) == false)
{
// Save sight checks when all of the other checks pass, so we only do it if we have to
continue;
}
}
bestwaypoint = waypoint->nextwaypoints[i];
@ -9012,8 +9003,6 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
nextbestmomdelta = momdelta;
}
// Remove wrong way flag if we're using nextwaypoints
player->pflags &= ~PF_WRONGWAY;
updaterespawn = true;
}
}
@ -9047,7 +9036,7 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
if (angledelta < nextbestdelta && momdelta < nextbestmomdelta)
{
if (P_TraceBlockingLines(player->mo, waypoint->prevwaypoints[i]->mobj) == false)
if (P_TraceWaypointTraversal(player->mo, waypoint->prevwaypoints[i]->mobj) == false)
{
// Save sight checks when all of the other checks pass, so we only do it if we have to
continue;
@ -9087,69 +9076,6 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
return bestwaypoint;
}
#if 0
static boolean K_PlayerCloserToNextWaypoints(waypoint_t *const waypoint, player_t *const player)
{
boolean nextiscloser = true;
if ((waypoint != NULL) && (player != NULL) && (player->mo != NULL))
{
size_t i = 0U;
waypoint_t *currentwpcheck = NULL;
angle_t angletoplayer = ANGLE_MAX;
angle_t currentanglecheck = ANGLE_MAX;
angle_t bestangle = ANGLE_MAX;
angletoplayer = R_PointToAngle2(waypoint->mobj->x, waypoint->mobj->y,
player->mo->x, player->mo->y);
for (i = 0U; i < waypoint->numnextwaypoints; i++)
{
currentwpcheck = waypoint->nextwaypoints[i];
currentanglecheck = R_PointToAngle2(
waypoint->mobj->x, waypoint->mobj->y, currentwpcheck->mobj->x, currentwpcheck->mobj->y);
// Get delta angle
currentanglecheck = currentanglecheck - angletoplayer;
if (currentanglecheck > ANGLE_180)
{
currentanglecheck = InvAngle(currentanglecheck);
}
if (currentanglecheck < bestangle)
{
bestangle = currentanglecheck;
}
}
for (i = 0U; i < waypoint->numprevwaypoints; i++)
{
currentwpcheck = waypoint->prevwaypoints[i];
currentanglecheck = R_PointToAngle2(
waypoint->mobj->x, waypoint->mobj->y, currentwpcheck->mobj->x, currentwpcheck->mobj->y);
// Get delta angle
currentanglecheck = currentanglecheck - angletoplayer;
if (currentanglecheck > ANGLE_180)
{
currentanglecheck = InvAngle(currentanglecheck);
}
if (currentanglecheck < bestangle)
{
bestangle = currentanglecheck;
nextiscloser = false;
break;
}
}
}
return nextiscloser;
}
#endif
/*--------------------------------------------------
void K_UpdateDistanceFromFinishLine(player_t *const player)
@ -9191,7 +9117,7 @@ void K_UpdateDistanceFromFinishLine(player_t *const player)
// Player has finished, we don't need to calculate this
player->distancetofinish = 0U;
}
else if ((player->nextwaypoint != NULL) && (finishline != NULL))
else if ((player->currentwaypoint != NULL) && (player->nextwaypoint != NULL) && (finishline != NULL))
{
const boolean useshortcuts = false;
const boolean huntbackwards = false;
@ -9205,17 +9131,139 @@ void K_UpdateDistanceFromFinishLine(player_t *const player)
// Using shortcuts won't find a path, so distance won't be updated until the player gets back on track
if (pathfindsuccess == true)
{
// Add euclidean distance to the next waypoint to the distancetofinish
UINT32 adddist;
fixed_t disttowaypoint =
const boolean pathBackwardsReverse = ((player->pflags & PF_WRONGWAY) == 0);
boolean pathBackwardsSuccess = false;
path_t pathBackwards = {0};
fixed_t disttonext = 0;
UINT32 traveldist = 0;
UINT32 adddist = 0;
disttonext =
P_AproxDistance(
(player->mo->x >> FRACBITS) - (player->nextwaypoint->mobj->x >> FRACBITS),
(player->mo->y >> FRACBITS) - (player->nextwaypoint->mobj->y >> FRACBITS));
disttowaypoint = P_AproxDistance(disttowaypoint, (player->mo->z >> FRACBITS) - (player->nextwaypoint->mobj->z >> FRACBITS));
disttonext = P_AproxDistance(disttonext, (player->mo->z >> FRACBITS) - (player->nextwaypoint->mobj->z >> FRACBITS));
adddist = (UINT32)disttowaypoint;
traveldist = ((UINT32)disttonext) * 2;
pathBackwardsSuccess =
K_PathfindThruCircuit(player->nextwaypoint, traveldist, &pathBackwards, false, pathBackwardsReverse);
player->distancetofinish = pathtofinish.totaldist + adddist;
if (pathBackwardsSuccess == true)
{
if (pathBackwards.numnodes > 1)
{
// Find the closest segment, and add the distance to reach it.
vector3_t point;
size_t i;
vector3_t best;
fixed_t bestPoint = INT32_MAX;
fixed_t bestDist = INT32_MAX;
UINT32 bestGScore = UINT32_MAX;
point.x = player->mo->x;
point.y = player->mo->y;
point.z = player->mo->z;
best.x = point.x;
best.y = point.y;
best.z = point.z;
for (i = 1; i < pathBackwards.numnodes; i++)
{
vector3_t line[2];
vector3_t result;
waypoint_t *pwp = (waypoint_t *)pathBackwards.array[i - 1].nodedata;
waypoint_t *wp = (waypoint_t *)pathBackwards.array[i].nodedata;
fixed_t pDist = 0;
UINT32 g = pathBackwards.array[i - 1].gscore;
line[0].x = pwp->mobj->x;
line[0].y = pwp->mobj->y;
line[0].z = pwp->mobj->z;
line[1].x = wp->mobj->x;
line[1].y = wp->mobj->y;
line[1].z = wp->mobj->z;
P_ClosestPointOnLine3D(&point, line, &result);
pDist = P_AproxDistance(point.x - result.x, point.y - result.y);
pDist = P_AproxDistance(pDist, point.z - result.z);
if (pDist < bestPoint)
{
FV3_Copy(&best, &result);
bestPoint = pDist;
bestDist =
P_AproxDistance(
(result.x >> FRACBITS) - (line[0].x >> FRACBITS),
(result.y >> FRACBITS) - (line[0].y >> FRACBITS));
bestDist = P_AproxDistance(bestDist, (result.z >> FRACBITS) - (line[0].z >> FRACBITS));
bestGScore = g + ((UINT32)bestDist);
}
}
#if 0
if (cv_kartdebugwaypoints.value)
{
mobj_t *debugmobj = P_SpawnMobj(best.x, best.y, best.z, MT_SPARK);
P_SetMobjState(debugmobj, S_WAYPOINTORB);
debugmobj->frame &= ~FF_TRANSMASK;
debugmobj->frame |= FF_FULLBRIGHT; //FF_TRANS20
debugmobj->tics = 1;
debugmobj->color = SKINCOLOR_BANANA;
}
#endif
adddist = bestGScore;
}
/*
else
{
// Only one point to work with, so just add your euclidean distance to that.
waypoint_t *wp = (waypoint_t *)pathBackwards.array[0].nodedata;
fixed_t disttowaypoint =
P_AproxDistance(
(player->mo->x >> FRACBITS) - (wp->mobj->x >> FRACBITS),
(player->mo->y >> FRACBITS) - (wp->mobj->y >> FRACBITS));
disttowaypoint = P_AproxDistance(disttowaypoint, (player->mo->z >> FRACBITS) - (wp->mobj->z >> FRACBITS));
adddist = (UINT32)disttowaypoint;
}
*/
}
/*
else
{
// Fallback to adding euclidean distance to the next waypoint to the distancetofinish
adddist = (UINT32)disttonext;
}
*/
if (pathBackwardsReverse == false)
{
if (pathtofinish.totaldist > adddist)
{
player->distancetofinish = pathtofinish.totaldist - adddist;
}
else
{
player->distancetofinish = 0;
}
}
else
{
player->distancetofinish = pathtofinish.totaldist + adddist;
}
Z_Free(pathtofinish.array);
// distancetofinish is currently a flat distance to the finish line, but in order to be fully
@ -9225,21 +9273,7 @@ void K_UpdateDistanceFromFinishLine(player_t *const player)
if ((mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) == 0U)
{
const UINT8 numfulllapsleft = ((UINT8)numlaps - player->laps);
player->distancetofinish += numfulllapsleft * K_GetCircuitLength();
#if 0
// An additional HACK, to fix looking backwards towards the finish line
// If the player's next waypoint is the finishline and the angle distance from player to
// connectin waypoints implies they're closer to a next waypoint, add a full track distance
if (player->nextwaypoint == finishline)
{
if (K_PlayerCloserToNextWaypoints(player->nextwaypoint, player) == true)
{
player->distancetofinish += K_GetCircuitLength();
}
}
#endif
}
}
}

View file

@ -361,7 +361,7 @@ waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
// remember: huge radius
if (closestdist <= rad && checkdist <= rad && finishline != NULL)
{
if (!P_TraceBlockingLines(mobj, checkwaypoint->mobj))
if (!P_TraceBlockingLines(mobj, checkwaypoint->mobj)) // Intentionally not P_TraceWaypointTraversal
{
// Save sight checks when all of the other checks pass, so we only do it if we have to
continue;
@ -379,7 +379,7 @@ waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
}
else if (checkdist < closestdist && bestfindist == INT32_MAX)
{
if (!P_TraceBlockingLines(mobj, checkwaypoint->mobj))
if (!P_TraceBlockingLines(mobj, checkwaypoint->mobj)) // Intentionally not P_TraceWaypointTraversal
{
// Save sight checks when all of the other checks pass, so we only do it if we have to
continue;

View file

@ -456,6 +456,7 @@ void P_BounceMove(mobj_t *mo, TryMoveResult_t *result);
boolean P_CheckSight(mobj_t *t1, mobj_t *t2);
boolean P_TraceBlockingLines(mobj_t *t1, mobj_t *t2);
boolean P_TraceBotTraversal(mobj_t *t1, mobj_t *t2);
boolean P_TraceWaypointTraversal(mobj_t *t1, mobj_t *t2);
void P_CheckHoopPosition(mobj_t *hoopthing, fixed_t x, fixed_t y, fixed_t z, fixed_t radius);
boolean P_CheckSector(sector_t *sector, boolean crunch);

View file

@ -251,6 +251,7 @@ static void P_NetArchivePlayers(void)
WRITEUINT8(save_p, players[i].oldposition);
WRITEUINT8(save_p, players[i].positiondelay);
WRITEUINT32(save_p, players[i].distancetofinish);
WRITEUINT32(save_p, K_GetWaypointHeapIndex(players[i].currentwaypoint));
WRITEUINT32(save_p, K_GetWaypointHeapIndex(players[i].nextwaypoint));
WRITEUINT32(save_p, players[i].airtime);
WRITEUINT8(save_p, players[i].startboost);
@ -552,6 +553,7 @@ static void P_NetUnArchivePlayers(void)
players[i].oldposition = READUINT8(save_p);
players[i].positiondelay = READUINT8(save_p);
players[i].distancetofinish = READUINT32(save_p);
players[i].currentwaypoint = (waypoint_t *)(size_t)READUINT32(save_p);
players[i].nextwaypoint = (waypoint_t *)(size_t)READUINT32(save_p);
players[i].airtime = READUINT32(save_p);
players[i].startboost = READUINT8(save_p);
@ -4426,6 +4428,15 @@ static void P_RelinkPointers(void)
if (!P_SetTarget(&mobj->player->follower, P_FindNewPosition(temp)))
CONS_Debug(DBG_GAMELOGIC, "follower not found on %d\n", mobj->type);
}
if (mobj->player->currentwaypoint)
{
temp = (UINT32)(size_t)mobj->player->currentwaypoint;
mobj->player->currentwaypoint = K_GetWaypointFromIndex(temp);
if (mobj->player->currentwaypoint == NULL)
{
CONS_Debug(DBG_GAMELOGIC, "currentwaypoint not found on %d\n", mobj->type);
}
}
if (mobj->player->nextwaypoint)
{
temp = (UINT32)(size_t)mobj->player->nextwaypoint;

File diff suppressed because it is too large Load diff