From 1f6877e1e75806c99c3dcaa5bd7bf0175ee7d2dc Mon Sep 17 00:00:00 2001 From: Sryder13 Date: Sat, 11 Nov 2017 03:28:20 +0000 Subject: [PATCH] Don't allow the player to respawn on a mapthing if it will collide them with another player Mainly effects battle where match starts are used, race will be effected at the beginning of races though --- src/g_game.c | 3 +++ src/k_kart.c | 22 ++++++++++++++++++++++ src/k_kart.h | 1 + 3 files changed, 26 insertions(+) diff --git a/src/g_game.c b/src/g_game.c index 7fbba1664..bdcf88857 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2411,6 +2411,9 @@ static boolean G_CheckSpot(INT32 playernum, mapthing_t *mthing) if (!P_CheckPosition(players[playernum].mo, x, y)) return false; + if (!K_CheckPlayersRespawnColliding(playernum, x, y)) + return false; + return true; } diff --git a/src/k_kart.c b/src/k_kart.c index e3d703dc4..a952d70d4 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -2475,6 +2475,28 @@ void K_DoBouncePad(player_t *player, fixed_t vertispeed) S_StartSound(player->mo, sfx_boing); } +// Returns false if this player being placed here causes them to collide with any other player +// Used in g_game.c for match etc. respawning +// This does not check along the z because the z is not correctly set for the spawnee at this point +boolean K_CheckPlayersRespawnColliding(INT32 playernum, fixed_t x, fixed_t y) +{ + INT32 i; + fixed_t p1radius = players[playernum].mo->radius; + for (i = 0; i < MAXPLAYERS; i++) + { + if (playernum == i || !playeringame[i] || players[i].spectator || !players[i].mo || players[i].mo->health <= 0 + || players[i].playerstate != PST_LIVE || (players[i].mo->flags & MF_NOCLIP) || (players[i].mo->flags & MF_NOCLIPTHING)) + continue; + + if (abs(x - players[i].mo->x) < (p1radius + players[i].mo->radius) + && abs(y - players[i].mo->y) < (p1radius + players[i].mo->radius)) + { + return false; + } + } + return true; +} + // countersteer is how strong the controls are telling us we are turning // turndir is the direction the controls are telling us to turn, -1 if turning right and 1 if turning left static INT16 K_GetKartDriftValue(player_t *player, fixed_t countersteer) diff --git a/src/k_kart.h b/src/k_kart.h index 36c8c0b99..187cbd9c9 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -27,6 +27,7 @@ void K_SpawnKartExplosion(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 void K_SpawnDriftTrail(player_t *player); void K_DoMushroom(player_t *player, boolean doPFlag, boolean startboost); void K_DoBouncePad(player_t *player, fixed_t vertispeed); +boolean K_CheckPlayersRespawnColliding(INT32 playernum, fixed_t x, fixed_t y); INT16 K_GetKartTurnValue(player_t *player, INT16 turnvalue); void K_MomentumToFacing(player_t *player); fixed_t K_GetKartSpeed(player_t *player, boolean doboostpower);