From 4544b91d2fe891283003188a11b07ae0f4ade728 Mon Sep 17 00:00:00 2001 From: btd Date: Mon, 30 Aug 2010 23:25:04 +0400 Subject: [PATCH] Teams collision a works fine... But i broke collision with tiles --- src/game/client/gameclient.cpp | 5 +- src/game/client/gameclient.h | 3 + src/game/gamecore.cpp | 12 ++-- src/game/teams.cpp | 103 --------------------------------- src/game/teams.h | 47 --------------- src/game/teamscore.cpp | 2 +- 6 files changed, 15 insertions(+), 157 deletions(-) delete mode 100644 src/game/teams.cpp delete mode 100644 src/game/teams.h diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index ec41eec83..fd657a7bd 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -445,8 +445,9 @@ static void Evolve(CNetObj_Character *pCharacter, int Tick) { CWorldCore TempWorld; CCharacterCore TempCore; + CTeamsCore TempTeams; mem_zero(&TempCore, sizeof(TempCore)); - TempCore.Init(&TempWorld, g_GameClient.Collision()); + TempCore.Init(&TempWorld, g_GameClient.Collision(), &TempTeams);//???? TempCore.Read(pCharacter); while(pCharacter->m_Tick < Tick) @@ -943,7 +944,7 @@ void CGameClient::OnPredict() if(!m_Snap.m_aCharacters[i].m_Active) continue; - g_GameClient.m_aClients[i].m_Predicted.Init(&World, Collision()); + g_GameClient.m_aClients[i].m_Predicted.Init(&World, Collision(), &m_Teams); World.m_apCharacters[i] = &g_GameClient.m_aClients[i].m_Predicted; g_GameClient.m_aClients[i].m_Predicted.Read(&m_Snap.m_aCharacters[i].m_Cur); } diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 36c2330af..2bedf744e 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -6,6 +6,8 @@ #include #include #include +#include + #include "render.h" const CColor m_PredefinedColors[MAX_CLIENTS] = { @@ -61,6 +63,7 @@ class CGameClient : public IGameClient CLayers m_Layers; class CCollision m_Collision; + class CTeamsCore m_Teams; CUI m_UI; void DispatchInput(); diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index afd39d914..ed3483419 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -218,7 +218,7 @@ void CCharacterCore::Tick(bool UseInput) GoingToHitGround = true; m_pReset = true; } - + // Check against other players first if(m_pWorld && m_pWorld->m_Tuning.m_PlayerHooking) { @@ -226,9 +226,13 @@ void CCharacterCore::Tick(bool UseInput) for(int i = 0; i < MAX_CLIENTS; i++) { CCharacterCore *p = m_pWorld->m_apCharacters[i]; + + if(!p || p == this || !m_pTeams->SameTeam(i, ThisId)) continue; - + //char aBuf[512]; + //str_format(aBuf, sizeof(aBuf), "ThisId = %d Id = %d TheSameTeam? = %d", ThisId, i, m_pTeams->SameTeam(i, ThisId)); + //dbg_msg("GameCore", aBuf); vec2 ClosestPoint = closest_point_on_line(m_HookPos, NewPos, p->m_Pos); if(distance(p->m_Pos, ClosestPoint) < PhysSize+2.0f) { @@ -328,13 +332,13 @@ void CCharacterCore::Tick(bool UseInput) continue; //player *p = (player*)ent; - if(p == this) { // || !(p->flags&FLAG_ALIVE) + if(p == this || (ThisId != -1 && !m_pTeams->SameTeam(ThisId, i))) { // || !(p->flags&FLAG_ALIVE) continue; // make sure that we don't nudge our self } // handle player <-> player collision float d = distance(m_Pos, p->m_Pos); vec2 Dir = normalize(m_Pos - p->m_Pos); - if (m_pWorld->m_Tuning.m_PlayerCollision && ThisId != -1 && m_pTeams->SameTeam(ThisId, i)) { + if (m_pWorld->m_Tuning.m_PlayerCollision) { if(d < PhysSize*1.25f && d > 1.0f) { diff --git a/src/game/teams.cpp b/src/game/teams.cpp deleted file mode 100644 index ebdf21d57..000000000 --- a/src/game/teams.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "teams.h" - - -CTeams::CTeams(CGameContext *pGameContext) : m_pGameContext(pGameContext) { - for(int i = 0; i < MAX_CLIENTS; ++i) { - m_Team[i] = 0; - m_TeamState[i] = EMPTY; - m_TeeFinished[i] = false; - } -} - -void CTeams::OnCharacterStart(int id) { - int Tick = Server()->Tick(); - if(m_Team[id] == 0) { - CCharacter* Char = Character(id); - Char->m_RaceState = RACE_STARTED; - Char->m_StartTime = Tick; - Char->m_RefreshTime = Tick; - } else { - if(m_TeamState[m_Team[id]] <= CLOSED) { - ChangeTeamState(m_Team[id], STARTED); - - for(int i = 0; i < MAX_CLIENTS; ++i) { - if(m_Team[i] == m_Team[id]) { - CCharacter* Char = Character(i); - - Char->m_RaceState = RACE_STARTED; - Char->m_StartTime = Tick; - Char->m_RefreshTime = Tick; - } - } - } - } -} - -void CTeams::OnCharacterFinish(int id) { - if(m_Team[id] == 0) { - Character(id)->OnFinish(); - } else { - m_TeeFinished[id] = true; - if(TeamFinished(m_Team[id])) { - ChangeTeamState(m_Team[id], FINISHED);//TODO: Make it better - for(int i = 0; i < MAX_CLIENTS; ++i) { - if(SameTeam(i, id)) { - CCharacter * Char = Character(i); - if(Char != 0) { - Char->OnFinish(); - m_TeeFinished[i] = false; - } //else { - // m_Team[id] = 0; //i saw zomby =) - //} - } - } - - } - } -} - -bool CTeams::SetCharacterTeam(int id, int Team) { - //TODO: Send error message - if(id < 0 || id >= MAX_CLIENTS || Team < 0 || Team >= MAX_CLIENTS) { - return false; - } - if(m_TeamState[Team] >= CLOSED) { - return false; - } - if(m_Team[id] != 0 && m_TeamState[m_Team[id]] != EMPTY) { - bool NoOneInOldTeam = true; - for(int i = 0; i < MAX_CLIENTS; ++i) { - if(SameTeam(i, id)) { - NoOneInOldTeam = false;//all good exists someone in old team - break; - } - } - if(NoOneInOldTeam) { - m_TeamState[m_Team[id]] = EMPTY; - } - } - m_Team[id] = Team; - if(m_TeamState[Team] == EMPTY) { - ChangeTeamState(Team, OPEN); - } - return true; -} - -void CTeams::ChangeTeamState(int Team, int State) { - m_TeamState[Team] = State; -} - - - -bool CTeams::TeamFinished(int Team) { - for(int i = 0; i < MAX_CLIENTS; ++i) { - if(m_Team[i] == Team && !m_TeeFinished[i]) { - return false; - } - } - return true; -} - -bool CTeams::SameTeam(int Cid1, int Cid2) { - return m_Team[Cid1] = m_Team[Cid2]; -} diff --git a/src/game/teams.h b/src/game/teams.h deleted file mode 100644 index e3d0f86dd..000000000 --- a/src/game/teams.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef GAME_SERVER_TEAMS_H -#define GAME_SERVER_TEAMS_H - -#include -#include - -class CTeams { - int m_Team[MAX_CLIENTS]; - int m_TeamState[MAX_CLIENTS]; - bool m_TeeFinished[MAX_CLIENTS]; - - class CGameContext * m_pGameContext; - -public: - enum { - EMPTY, - OPEN, - CLOSED, - STARTED, - FINISHED - }; - - CTeams(CGameContext *pGameContext); - - //helper methods - CCharacter* Character(int id) { return GameServer()->GetPlayerChar(id); } - - class CGameContext *GameServer() { return m_pGameContext; } - class IServer *Server() { return m_pGameContext->Server(); } - - void OnCharacterStart(int id); - void OnCharacterFinish(int id); - - bool SetCharacterTeam(int id, int Team); - - void ChangeTeamState(int Team, int State); - - bool TeamFinished(int Team); - - bool SameTeam(int Cid1, int Cid2); - - int GetTeam(int Cid) { - return m_Team[Cid]; - } -}; - -#endif \ No newline at end of file diff --git a/src/game/teamscore.cpp b/src/game/teamscore.cpp index c0ae6e9af..52de3ef35 100644 --- a/src/game/teamscore.cpp +++ b/src/game/teamscore.cpp @@ -7,7 +7,7 @@ CTeamsCore::CTeamsCore() { } bool CTeamsCore::SameTeam(int Cid1, int Cid2) { - return m_Team[Cid1] = m_Team[Cid2]; + return m_Team[Cid1] == m_Team[Cid2]; } int CTeamsCore::Team(int Cid) {