mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
fixed a possible problem with occupied spawn points and cleaned up spawn code a bit
This commit is contained in:
parent
0698243c6b
commit
3f05289328
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
/*
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue