From 05a8dcb37440aa1f010e418de05ecc153340956f Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 27 Apr 2020 01:10:33 +0300 Subject: [PATCH] game: clean up TPlayer.GetRespawnPoint() now players can spawn even when there's a single point of any type --- src/game/g_map.pas | 9 +++ src/game/g_player.pas | 149 +++++++++--------------------------------- 2 files changed, 41 insertions(+), 117 deletions(-) diff --git a/src/game/g_map.pas b/src/game/g_map.pas index e99d47b..20bfa3b 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -89,6 +89,7 @@ function g_Map_IsSpecialTexture(Texture: String): Boolean; function g_Map_GetPoint(PointType: Byte; var RespawnPoint: TRespawnPoint): Boolean; function g_Map_GetPointCount(PointType: Byte): Word; +function g_Map_GetRandomPointType(): Byte; function g_Map_HaveFlagPoints(): Boolean; @@ -3122,6 +3123,14 @@ begin Result := Result + 1; end; +function g_Map_GetRandomPointType(): Byte; +begin + if RespawnPoints = nil then + Result := 255 + else + Result := RespawnPoints[Random(Length(RespawnPoints))].PointType; +end; + function g_Map_HaveFlagPoints(): Boolean; begin Result := (FlagPoints[FLAG_RED] <> nil) and (FlagPoints[FLAG_BLUE] <> nil); diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 0b72fc9..64e6166 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -4472,143 +4472,58 @@ begin // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then begin - if (Self = gPlayer1) or (Self = gPlayer2) then + if Self = gPlayer1 then begin - // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà - if Self = gPlayer1 then - c := RESPAWNPOINT_PLAYER1 - else - c := RESPAWNPOINT_PLAYER2; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; - - // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà - if Self = gPlayer1 then - c := RESPAWNPOINT_PLAYER2 - else - c := RESPAWNPOINT_PLAYER1; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; - end else + // player 1 should try to spawn on the player 1 point + if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then + Exit(RESPAWNPOINT_PLAYER1) + else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then + Exit(RESPAWNPOINT_PLAYER2); + end + else if Self = gPlayer2 then begin - // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà) - if Random(2) = 0 then - c := RESPAWNPOINT_PLAYER1 - else - c := RESPAWNPOINT_PLAYER2; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; - end; - - // Òî÷êà ëþáîé èç êîìàíä - if Random(2) = 0 then - c := RESPAWNPOINT_RED + // player 2 should try to spawn on the player 2 point + if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then + Exit(RESPAWNPOINT_PLAYER2) + else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then + Exit(RESPAWNPOINT_PLAYER1); + end else - c := RESPAWNPOINT_BLUE; - if g_Map_GetPointCount(c) > 0 then begin - Result := c; - Exit; - end; - - // Òî÷êà DM - c := RESPAWNPOINT_DM; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; + // other players randomly pick either the first or the second point + c := IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1, RESPAWNPOINT_PLAYER2); + if g_Map_GetPointCount(c) > 0 then + Exit(c); + // try the other one + c := IfThen((c = RESPAWNPOINT_PLAYER1), RESPAWNPOINT_PLAYER2, RESPAWNPOINT_PLAYER1); + if g_Map_GetPointCount(c) > 0 then + Exit(c); end; end; // Ìÿñîïîâàë if gGameSettings.GameMode = GM_DM then begin - // Òî÷êà DM - c := RESPAWNPOINT_DM; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; - - // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà - if Random(2) = 0 then - c := RESPAWNPOINT_PLAYER1 - else - c := RESPAWNPOINT_PLAYER2; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; - - // Òî÷êà ëþáîé èç êîìàíä - if Random(2) = 0 then - c := RESPAWNPOINT_RED - else - c := RESPAWNPOINT_BLUE; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; + // try DM points first + if g_Map_GetPointCount(RESPAWNPOINT_DM) > 0 then + Exit(RESPAWNPOINT_DM); end; // Êîìàíäíûå if gGameSettings.GameMode in [GM_TDM, GM_CTF] then begin - // Òî÷êà ñâîåé êîìàíäû - c := RESPAWNPOINT_DM; - if FTeam = TEAM_RED then - c := RESPAWNPOINT_RED; - if FTeam = TEAM_BLUE then - c := RESPAWNPOINT_BLUE; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; - - // Òî÷êà DM - c := RESPAWNPOINT_DM; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; - - // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà - if Random(2) = 0 then - c := RESPAWNPOINT_PLAYER1 - else - c := RESPAWNPOINT_PLAYER2; - if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; - - // Òî÷êà äðóãîé êîìàíäû + // try team points first c := RESPAWNPOINT_DM; if FTeam = TEAM_RED then + c := RESPAWNPOINT_RED + else if FTeam = TEAM_BLUE then c := RESPAWNPOINT_BLUE; - if FTeam = TEAM_BLUE then - c := RESPAWNPOINT_RED; if g_Map_GetPointCount(c) > 0 then - begin - Result := c; - Exit; - end; + Exit(c); end; + + // still haven't found a spawnpoint, try random shit + Result := g_Map_GetRandomPointType(); end; procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False); -- 2.29.2