From d7162bed71bb9c04093d27bfb1ff66361d87747d Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sat, 8 Mar 2025 15:28:33 -0500 Subject: [PATCH] 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 --- src/k_kart.c | 22 ++++++++++++++++++++-- src/p_mobj.c | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 81a2bd4bc..63a2a6673 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -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; diff --git a/src/p_mobj.c b/src/p_mobj.c index ef02fc917..cc2ad1b8d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -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.