From 3f05289328dfaeb67a344de0b553e31cbb11ea36 Mon Sep 17 00:00:00 2001 From: oy Date: Thu, 10 Feb 2011 12:05:55 +0100 Subject: [PATCH] fixed a possible problem with occupied spawn points and cleaned up spawn code a bit --- src/game/server/gamecontroller.cpp | 16 ++++++++++------ src/game/server/gamecontroller.h | 2 +- src/game/server/gameworld.cpp | 3 ++- src/game/server/player.cpp | 19 ++++++------------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index f4b6d33ce..d3de11e77 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -62,6 +62,10 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int T) // get spawn point for(int i = 0; i < m_aNumSpawnPoints[T]; i++) { + // check if the position is occupado + if(GameServer()->m_World.FindEntities(m_aaSpawnPoints[T][i], 64, 0, 1, CGameWorld::ENTTYPE_CHARACTER)) + continue; + vec2 P = m_aaSpawnPoints[T][i]; float S = EvaluateSpawnPos(pEval, P); if(!pEval->m_Got || pEval->m_Score > S) @@ -73,25 +77,25 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int T) } } -bool IGameController::CanSpawn(CPlayer *pPlayer, vec2 *pOutPos) +bool IGameController::CanSpawn(int Team, vec2 *pOutPos) { CSpawnEval Eval; // spectators can't spawn - if(pPlayer->GetTeam() == TEAM_SPECTATORS) + if(Team == TEAM_SPECTATORS) return false; if(IsTeamplay()) { - Eval.m_FriendlyTeam = pPlayer->GetTeam(); + Eval.m_FriendlyTeam = Team; - // try first try own team spawn, then normal spawn and then enemy - EvaluateSpawnType(&Eval, 1+(pPlayer->GetTeam()&1)); + // first try own team spawn, then normal spawn and then enemy + EvaluateSpawnType(&Eval, 1+(Team&1)); if(!Eval.m_Got) { EvaluateSpawnType(&Eval, 0); if(!Eval.m_Got) - EvaluateSpawnType(&Eval, 1+((pPlayer->GetTeam()+1)&1)); + EvaluateSpawnType(&Eval, 1+((Team+1)&1)); } } else diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index 2ff6acd3b..070cb0941 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -129,7 +129,7 @@ public: virtual void OnPlayerInfoChange(class CPlayer *pP); // - virtual bool CanSpawn(class CPlayer *pP, vec2 *pPos); + virtual bool CanSpawn(int Team, vec2 *pPos); /* diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 66da43699..8fffabc8c 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -48,7 +48,8 @@ int CGameWorld::FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, { if(distance(pEnt->m_Pos, Pos) < Radius+pEnt->m_ProximityRadius) { - ppEnts[Num] = pEnt; + if(ppEnts) + ppEnts[Num] = pEnt; Num++; if(Num == Max) break; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 3f32d6af1..5147cbfbd 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -201,20 +201,13 @@ void CPlayer::SetTeam(int Team) void CPlayer::TryRespawn() { - vec2 SpawnPos = vec2(100.0f, -60.0f); + vec2 SpawnPos; - if(!GameServer()->m_pController->CanSpawn(this, &SpawnPos)) + if(!GameServer()->m_pController->CanSpawn(m_Team, &SpawnPos)) return; - // check if the position is occupado - CEntity *apEnts[2] = {0}; - int NumEnts = GameServer()->m_World.FindEntities(SpawnPos, 64, apEnts, 2, CGameWorld::ENTTYPE_CHARACTER); - - if(NumEnts == 0) - { - m_Spawning = false; - Character = new(m_ClientID) CCharacter(&GameServer()->m_World); - Character->Spawn(this, SpawnPos); - GameServer()->CreatePlayerSpawn(SpawnPos); - } + m_Spawning = false; + Character = new(m_ClientID) CCharacter(&GameServer()->m_World); + Character->Spawn(this, SpawnPos); + GameServer()->CreatePlayerSpawn(SpawnPos); }