diff options
| author | oy <Tom_Adams@web.de> | 2011-06-15 01:03:14 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-06-15 01:03:14 +0200 |
| commit | 4dc79a9ec1209d9ec6265408b4fa419d052716ed (patch) | |
| tree | 9f54e72a5b926fa045cb88e8080d594c539ba7c7 /src/game/server | |
| parent | d5b38048041788b3a7627b729974a7a3c96843f0 (diff) | |
| download | zcatch-4dc79a9ec1209d9ec6265408b4fa419d052716ed.tar.gz zcatch-4dc79a9ec1209d9ec6265408b4fa419d052716ed.zip | |
fixed spawn bug. Closes #634
Diffstat (limited to 'src/game/server')
| -rw-r--r-- | src/game/server/gamecontroller.cpp | 84 | ||||
| -rw-r--r-- | src/game/server/gamecontroller.h | 1 |
2 files changed, 18 insertions, 67 deletions
diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 6685bba3..e687a17f 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -63,10 +63,25 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type) for(int i = 0; i < m_aNumSpawnPoints[Type]; i++) { // check if the position is occupado - if(GameServer()->m_World.FindEntities(m_aaSpawnPoints[Type][i], 64, 0, 1, CGameWorld::ENTTYPE_CHARACTER)) - continue; + CCharacter *aEnts[MAX_CLIENTS]; + int Num = GameServer()->m_World.FindEntities(m_aaSpawnPoints[Type][i], 64, (CEntity**)aEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); + vec2 Positions[5] = { vec2(0.0f, 0.0f), vec2(-32.0f, 0.0f), vec2(0.0f, -32.0f), vec2(32.0f, 0.0f), vec2(0.0f, 32.0f) }; // start, left, up, right, down + int Result = -1; + for(int Index = 0; Index < 5 && Result == -1; ++Index) + { + Result = Index; + for(int c = 0; c < Num; ++c) + if(GameServer()->Collision()->CheckPoint(m_aaSpawnPoints[Type][i]+Positions[Index]) || + distance(aEnts[c]->m_Pos, m_aaSpawnPoints[Type][i]+Positions[Index]) <= aEnts[c]->m_ProximityRadius) + { + Result = -1; + break; + } + } + if(Result == -1) + continue; // try next spawn point - vec2 P = m_aaSpawnPoints[Type][i]; + vec2 P = m_aaSpawnPoints[Type][i]+Positions[Result]; float S = EvaluateSpawnPos(pEval, P); if(!pEval->m_Got || pEval->m_Score > S) { @@ -77,47 +92,6 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type) } } -void IGameController::FindFreeSpawn(CSpawnEval *pEval, int Type) -{ - // pick the spawn point that is least occupied and has free space for spawning around it - for(int i = 0; i < m_aNumSpawnPoints[Type]; i++) - { - - CCharacter *aEnts[MAX_CLIENTS]; - int Num = GameServer()->m_World.FindEntities(m_aaSpawnPoints[Type][i], 64, (CEntity**)aEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); - float Score = 0.0f; - for(int c = 0; c < Num; ++c) - Score += 96.0f - distance(aEnts[c]->m_Pos, m_aaSpawnPoints[Type][i]); - - if(!pEval->m_Got || pEval->m_Score > Score) - { - // start, left, up, right, down - vec2 Positions[5] = { vec2(0.0f, 0.0f), vec2(-32.0f, 0.0f), vec2(0.0f, -32.0f), vec2(32.0f, 0.0f), vec2(0.0f, 32.0f) }; - - // check for free space - int Result = -1; - for(int Index = 0; Index < 5 && Result == -1; ++Index) - { - Result = Index; - for(int c = 0; c < Num; ++c) - if(GameServer()->Collision()->CheckPoint(m_aaSpawnPoints[Type][i]+Positions[Index]) || - distance(aEnts[c]->m_Pos, m_aaSpawnPoints[Type][i]+Positions[Index]) <= aEnts[c]->m_ProximityRadius) - { - Result = -1; - break; - } - } - - if(Result == -1) - continue; // try next spawn point - - pEval->m_Got = true; - pEval->m_Score = Score; - pEval->m_Pos = m_aaSpawnPoints[Type][i]+Positions[Result]; - } - } -} - bool IGameController::CanSpawn(int Team, vec2 *pOutPos) { CSpawnEval Eval; @@ -146,28 +120,6 @@ bool IGameController::CanSpawn(int Team, vec2 *pOutPos) EvaluateSpawnType(&Eval, 2); } - // handle crappy maps - if(!Eval.m_Got) - { - if(IsTeamplay()) - { - // first try own team spawn, then normal spawn and then enemy - FindFreeSpawn(&Eval, 1+(Team&1)); - if(!Eval.m_Got) - { - FindFreeSpawn(&Eval, 0); - if(!Eval.m_Got) - FindFreeSpawn(&Eval, 1+((Team+1)&1)); - } - } - else - { - FindFreeSpawn(&Eval, 0); - FindFreeSpawn(&Eval, 1); - FindFreeSpawn(&Eval, 2); - } - } - *pOutPos = Eval.m_Pos; return Eval.m_Got; } diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index 6ccfe977..9fc689bf 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -39,7 +39,6 @@ protected: float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos); void EvaluateSpawnType(CSpawnEval *pEval, int Type); - void FindFreeSpawn(CSpawnEval *pEval, int Type); bool EvaluateSpawn(class CPlayer *pP, vec2 *pPos); void CycleMap(); |