From 08a2f47ee8d3a44f5829fbd08b7cb5dc556ce147 Mon Sep 17 00:00:00 2001 From: GreYFoXGTi Date: Sun, 19 Dec 2010 05:48:16 +0200 Subject: [PATCH] Added Ability to Restart the race in a team after you have finished
Testers: Please check if this can be abused --- src/game/server/entities/character.cpp | 4 +- src/game/server/entities/character.h | 3 +- src/game/server/teams.cpp | 101 ++++++++++++++++++------- src/game/server/teams.h | 2 + 4 files changed, 81 insertions(+), 29 deletions(-) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index bde488c61..90dc8403f 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -658,7 +658,7 @@ void CCharacter::OnFinish() } - m_DDRaceState = DDRACE_NONE; + m_DDRaceState = DDRACE_FINISHED; // set player score if(!pData->m_CurrentTime || pData->m_CurrentTime > time) { @@ -969,7 +969,7 @@ void CCharacter::HandleTiles(int Index) Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID()); } } - if(((m_TileIndex == TILE_BEGIN) || (m_TileFIndex == TILE_BEGIN) || FTile1 == TILE_BEGIN || FTile2 == TILE_BEGIN || FTile3 == TILE_BEGIN || FTile4 == TILE_BEGIN || Tile1 == TILE_BEGIN || Tile2 == TILE_BEGIN || Tile3 == TILE_BEGIN || Tile4 == TILE_BEGIN) && (m_DDRaceState == DDRACE_NONE || (m_DDRaceState == DDRACE_STARTED && !Team()))) + if(((m_TileIndex == TILE_BEGIN) || (m_TileFIndex == TILE_BEGIN) || FTile1 == TILE_BEGIN || FTile2 == TILE_BEGIN || FTile3 == TILE_BEGIN || FTile4 == TILE_BEGIN || Tile1 == TILE_BEGIN || Tile2 == TILE_BEGIN || Tile3 == TILE_BEGIN || Tile4 == TILE_BEGIN) && (m_DDRaceState == DDRACE_NONE || m_DDRaceState == DDRACE_FINISHED || (m_DDRaceState == DDRACE_STARTED && !Team()))) { bool CanBegin = true; if(g_Config.m_SvTeam == 1 && (Team() == TEAM_FLOCK || Teams()->Count(Team()) <= 1) ) { diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 00194d2b0..a7dd67e36 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -21,7 +21,8 @@ enum { DDRACE_NONE = 0, DDRACE_STARTED, - DDRACE_CHEAT // no time and won't start again unless ordered by a mod or death + DDRACE_CHEAT, // no time and won't start again unless ordered by a mod or death + DDRACE_FINISHED }; class CCharacter : public CEntity diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index e13613ba0..106216467 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -11,28 +11,66 @@ void CGameTeams::Reset() { m_TeamState[i] = EMPTY; m_TeeFinished[i] = false; m_MembersCount[i] = 0; + m_LastChat[i] = 0; } } void CGameTeams::OnCharacterStart(int id) { int Tick = Server()->Tick(); - if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER) { - CCharacter* Char = Character(id); - if(!Char) return; // for some reason i had a crash here - Char->m_DDRaceState = DDRACE_STARTED; - Char->m_StartTime = Tick; - Char->m_RefreshTime = Tick; - } else { - if(m_TeamState[m_Core.Team(id)] <= CLOSED) { - ChangeTeamState(m_Core.Team(id), STARTED); - - for(int i = 0; i < MAX_CLIENTS; ++i) { - if(m_Core.Team(id) == m_Core.Team(i)) { - CCharacter* Char = Character(i); + CCharacter* StartingChar = Character(id); + if(!StartingChar) + return; + if(StartingChar->m_DDRaceState == DDRACE_FINISHED) + StartingChar->m_DDRaceState = DDRACE_NONE; + if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER) + { + StartingChar->m_DDRaceState = DDRACE_STARTED; + StartingChar->m_StartTime = Tick; + StartingChar->m_RefreshTime = Tick; + } + else + { + bool Waiting = false; + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(m_Core.Team(id) == m_Core.Team(i)) + { + CCharacter* Char = Character(i); + if(Char->m_DDRaceState == DDRACE_FINISHED) + { + Waiting = true; + if(m_LastChat[id] + Server()->TickSpeed() + g_Config.m_SvChatDelay < Tick) + { + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "%s has finished and didn't go through start yet, wait for him or join another team.", Server()->ClientName(i)); + GameServer()->SendChatTarget(id, aBuf); + m_LastChat[id] = Tick; + } + if(m_LastChat[i] + Server()->TickSpeed() + g_Config.m_SvChatDelay < Tick) + { + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "%s wants to start a new round, kill or walk to start.", Server()->ClientName(id)); + GameServer()->SendChatTarget(i, aBuf); + m_LastChat[i] = Tick; + } + } + } + } - Char->m_DDRaceState = DDRACE_STARTED; - Char->m_StartTime = Tick; - Char->m_RefreshTime = Tick; + if(m_TeamState[m_Core.Team(id)] <= CLOSED && !Waiting) + { + ChangeTeamState(m_Core.Team(id), STARTED); + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(m_Core.Team(id) == m_Core.Team(i)) + { + CCharacter* Char = Character(i); + if(Char) + { + Char->m_DDRaceState = DDRACE_STARTED; + Char->m_StartTime = Tick; + Char->m_RefreshTime = Tick; + } } } } @@ -40,21 +78,32 @@ void CGameTeams::OnCharacterStart(int id) { } void CGameTeams::OnCharacterFinish(int id) { - if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER) { + if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER) + { Character(id)->OnFinish(); - } else { + } + else + { m_TeeFinished[id] = true; - if(TeamFinished(m_Core.Team(id))) { - ChangeTeamState(m_Core.Team(id), FINISHED);//TODO: Make it better - for(int i = 0; i < MAX_CLIENTS; ++i) { - if(m_Core.Team(id) == m_Core.Team(i)) { + if(TeamFinished(m_Core.Team(id))) + { + //ChangeTeamState(m_Core.Team(id), FINISHED);//TODO: Make it better + ChangeTeamState(m_Core.Team(id), OPEN); + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(m_Core.Team(id) == m_Core.Team(i)) + { CCharacter * Char = Character(i); - if(Char != 0) { + if(Char != 0) + { Char->OnFinish(); m_TeeFinished[i] = false; - } //else { - // m_Core.Team(id) = 0; //i saw zomby =) - //} + } + /*else + *{ + * m_Core.Team(id) = 0; //i saw zomby =) + *} + */ } } diff --git a/src/game/server/teams.h b/src/game/server/teams.h index ec0fa6eeb..e820c745a 100644 --- a/src/game/server/teams.h +++ b/src/game/server/teams.h @@ -50,6 +50,8 @@ public: void Reset(); void SendTeamsState(int Cid); + + int m_LastChat[MAX_CLIENTS]; }; #endif