From d96f354b283aa2e97f05fdd8d42b45f419379fd4 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 6 Feb 2022 00:01:47 +0100 Subject: [PATCH] Make spawn position independent of players in other teams As suggested by Rockus, should help speedrunners who get followed by other players --- src/game/server/entities/character.cpp | 4 ++-- src/game/server/gamecontroller.cpp | 23 +++++++++++------------ src/game/server/gamecontroller.h | 6 +++--- src/game/server/player.cpp | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 102d56dde..e726c755b 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1929,7 +1929,7 @@ void CCharacter::HandleTiles(int Index) } // if no checkpointout have been found (or if there no recorded checkpoint), teleport to start vec2 SpawnPos; - if(GameServer()->m_pController->CanSpawn(m_pPlayer->GetTeam(), &SpawnPos)) + if(GameServer()->m_pController->CanSpawn(m_pPlayer->GetTeam(), &SpawnPos, GameServer()->GetDDRaceTeam(GetPlayer()->GetCID()))) { m_Core.m_Pos = SpawnPos; m_Core.m_Vel = vec2(0, 0); @@ -1964,7 +1964,7 @@ void CCharacter::HandleTiles(int Index) } // if no checkpointout have been found (or if there no recorded checkpoint), teleport to start vec2 SpawnPos; - if(GameServer()->m_pController->CanSpawn(m_pPlayer->GetTeam(), &SpawnPos)) + if(GameServer()->m_pController->CanSpawn(m_pPlayer->GetTeam(), &SpawnPos, GameServer()->GetDDRaceTeam(GetPlayer()->GetCID()))) { m_Core.m_Pos = SpawnPos; diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 19fbb12b1..c6ec9f789 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -99,25 +99,24 @@ void IGameController::DoActivityCheck() } } -float IGameController::EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos) +float IGameController::EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos, int DDTeam) { float Score = 0.0f; CCharacter *pC = static_cast(GameServer()->m_World.FindFirst(CGameWorld::ENTTYPE_CHARACTER)); for(; pC; pC = (CCharacter *)pC->TypeNext()) { - // team mates are not as dangerous as enemies - float Scoremod = 1.0f; - if(pEval->m_FriendlyTeam != -1 && pC->GetPlayer()->GetTeam() == pEval->m_FriendlyTeam) - Scoremod = 0.5f; + // ignore players in other teams + if(GameServer()->GetDDRaceTeam(pC->GetPlayer()->GetCID()) != DDTeam) + continue; float d = distance(Pos, pC->m_Pos); - Score += Scoremod * (d == 0 ? 1000000000.0f : 1.0f / d); + Score += d == 0 ? 1000000000.0f : 1.0f / d; } return Score; } -void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type) +void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type, int DDTeam) { // j == 0: Find an empty slot, j == 1: Take any slot if no empty one found for(int j = 0; j < 2 && !pEval->m_Got; j++) @@ -153,7 +152,7 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type) P += Positions[Result]; } - float S = EvaluateSpawnPos(pEval, P); + float S = EvaluateSpawnPos(pEval, P, DDTeam); if(!pEval->m_Got || (j == 0 && pEval->m_Score > S)) { pEval->m_Got = true; @@ -164,7 +163,7 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type) } } -bool IGameController::CanSpawn(int Team, vec2 *pOutPos) +bool IGameController::CanSpawn(int Team, vec2 *pOutPos, int DDTeam) { CSpawnEval Eval; @@ -172,9 +171,9 @@ bool IGameController::CanSpawn(int Team, vec2 *pOutPos) if(Team == TEAM_SPECTATORS) return false; - EvaluateSpawnType(&Eval, 0); - EvaluateSpawnType(&Eval, 1); - EvaluateSpawnType(&Eval, 2); + EvaluateSpawnType(&Eval, 0, DDTeam); + EvaluateSpawnType(&Eval, 1, DDTeam); + EvaluateSpawnType(&Eval, 2, DDTeam); *pOutPos = Eval.m_Pos; return Eval.m_Got; diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index aa09bf55e..f3a2cf6ed 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -44,8 +44,8 @@ protected: float m_Score; }; - float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos); - void EvaluateSpawnType(CSpawnEval *pEval, int Type); + float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos, int DDTeam); + void EvaluateSpawnType(CSpawnEval *pEval, int Type, int DDTeam); void ResetGame(); @@ -131,7 +131,7 @@ public: virtual void Snap(int SnappingClient); //spawn - virtual bool CanSpawn(int Team, vec2 *pOutPos); + virtual bool CanSpawn(int Team, vec2 *pOutPos, int DDTeam); virtual void DoTeamChange(class CPlayer *pPlayer, int Team, bool DoChatMsg = true); /* diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index c94eaca45..6f834d254 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -692,7 +692,7 @@ void CPlayer::TryRespawn() { vec2 SpawnPos; - if(!GameServer()->m_pController->CanSpawn(m_Team, &SpawnPos)) + if(!GameServer()->m_pController->CanSpawn(m_Team, &SpawnPos, GameServer()->GetDDRaceTeam(m_ClientID))) return; m_WeakHookSpawn = false;