implement safe guards for softlock respawns in New Waypoints

if you fail to respawn properly (die while respawning) you get placed at the next waypoint. Code was also adjusted so the next waypoint can't be the same as your current one if you are detected as going backwards, helps on turns that sometimes face you towards the previous waypoint. Respawning angle for both respawn fallbacks now gets the angle by comparing x and y of the current waypoint and next waypoint to guarntee you are facing the correct direction
This commit is contained in:
NepDisk 2025-03-08 15:28:33 -05:00
parent dfab6cc945
commit d7162bed71
2 changed files with 42 additions and 2 deletions

View file

@ -7891,7 +7891,23 @@ static boolean K_SetPlayerNextWaypoint(player_t *player)
continue;
}
bestwaypoint = waypoint->prevwaypoints[i];
if ((waypoint->nextwaypoints != NULL) && (waypoint->numnextwaypoints > 0U))
{
for (size_t j = 0U; j < waypoint->numnextwaypoints; j++)
{
if (!K_GetWaypointIsEnabled(waypoint->nextwaypoints[j]))
{
continue;
}
if (waypoint->nextwaypoints[j] == waypoint)\
{
continue;
}
bestwaypoint = waypoint->nextwaypoints[j];
}
}
nextbestdelta = angledelta;
nextbestmomdelta = momdelta;
@ -8207,12 +8223,14 @@ static void K_UpdatePlayerWaypoints(player_t *const player)
}
else
{
mobj_t *currentwaypoint = player->currentwaypoint->mobj;
mobj_t *safewaypoint = player->nextwaypoint->mobj;
angle_t respawnangle = R_PointToAngle2(currentwaypoint->x, currentwaypoint->y, safewaypoint->x, safewaypoint->y);
player->starposttime = player->realtime;
player->starpostz = safewaypoint->spawnpoint->z >> FRACBITS;
player->starpostflip = (safewaypoint->flags2 & MF2_OBJECTFLIP);
player->starpostangle = safewaypoint->spawnpoint ? FixedAngle(safewaypoint->spawnpoint->angle * FRACUNIT) : player->mo->angle;
player->starpostangle = respawnangle;
// Then do x and y
player->starpostx = safewaypoint->x >> FRACBITS;

View file

@ -6322,6 +6322,28 @@ static boolean P_MobjDeadThink(mobj_t *mobj)
{
case MT_PLAYER:
/// \todo Have the player's dead body completely finish its animation even if they've already respawned.
if (mobj->player)
{
// Set players next respawn point to the next waypoint
// If they die while still in respawn state for extra safety.
if (mobj->player->nextwaypoint && mobj->player->respawn > 0)
{
mobj_t *currentwaypoint = mobj->player->currentwaypoint->mobj;
mobj_t *safewaypoint = mobj->player->nextwaypoint->mobj;
angle_t respawnangle = R_PointToAngle2(currentwaypoint->x, currentwaypoint->y, safewaypoint->x, safewaypoint->y);
mobj->player->starposttime = mobj->player->realtime;
mobj->player->starpostz = safewaypoint->spawnpoint->z >> FRACBITS;
mobj->player->starpostflip = (safewaypoint->flags2 & MF2_OBJECTFLIP);
mobj->player->starpostangle = respawnangle;
// Then do x and y
mobj->player->starpostx = safewaypoint->x >> FRACBITS;
mobj->player->starposty = safewaypoint->y >> FRACBITS;
}
}
if (!mobj->fuse)
{ // Go away.
/// \todo Actually go ahead and remove mobj completely, and fix any bugs and crashes doing this creates. Chasecam should stop moving, and F12 should never return to it.