From b0bf7115c9c51e10dbbd58578c3be3d7c52d959a Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 15 Feb 2012 01:40:34 +0100 Subject: [PATCH] added lms gametype, updated standard gametype check and made players keep their score between rounds --- src/engine/client/serverbrowser.cpp | 19 +----- src/game/client/components/controls.cpp | 2 +- src/game/client/components/hud.cpp | 2 + src/game/client/components/menus_browser.cpp | 4 +- src/game/client/gameclient.cpp | 3 +- src/game/server/gamecontext.cpp | 8 ++- src/game/server/gamecontroller.cpp | 11 ++- src/game/server/gamecontroller.h | 1 + src/game/server/gamemodes/lms.cpp | 70 ++++++++++++++++++++ src/game/server/gamemodes/lms.h | 19 ++++++ src/game/server/gamemodes/sur.cpp | 2 +- src/game/variables.h | 2 +- 12 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 src/game/server/gamemodes/lms.cpp create mode 100644 src/game/server/gamemodes/lms.h diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 4dda9da98..f06cd7f1d 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -154,7 +154,9 @@ void CServerBrowser::Filter() else if(g_Config.m_BrFilterPure && (str_comp(m_ppServerlist[i]->m_Info.m_aGameType, "DM") != 0 && str_comp(m_ppServerlist[i]->m_Info.m_aGameType, "TDM") != 0 && - str_comp(m_ppServerlist[i]->m_Info.m_aGameType, "CTF") != 0)) + str_comp(m_ppServerlist[i]->m_Info.m_aGameType, "CTF") != 0 && + str_comp(m_ppServerlist[i]->m_Info.m_aGameType, "SUR") != 0 && + str_comp(m_ppServerlist[i]->m_Info.m_aGameType, "LMS") != 0)) { Filtered = 1; } @@ -354,21 +356,6 @@ void CServerBrowser::SetInfo(CServerEntry *pEntry, const CServerInfo &Info) pEntry->m_Info = Info; pEntry->m_Info.m_Favorite = Fav; pEntry->m_Info.m_NetAddr = pEntry->m_Addr; - - // all these are just for nice compability - if(pEntry->m_Info.m_aGameType[0] == '0' && pEntry->m_Info.m_aGameType[1] == 0) - str_copy(pEntry->m_Info.m_aGameType, "DM", sizeof(pEntry->m_Info.m_aGameType)); - else if(pEntry->m_Info.m_aGameType[0] == '1' && pEntry->m_Info.m_aGameType[1] == 0) - str_copy(pEntry->m_Info.m_aGameType, "TDM", sizeof(pEntry->m_Info.m_aGameType)); - else if(pEntry->m_Info.m_aGameType[0] == '2' && pEntry->m_Info.m_aGameType[1] == 0) - str_copy(pEntry->m_Info.m_aGameType, "CTF", sizeof(pEntry->m_Info.m_aGameType)); - - /*if(!request) - { - pEntry->m_Info.latency = (time_get()-pEntry->request_time)*1000/time_freq(); - RemoveRequest(pEntry); - }*/ - pEntry->m_GotInfo = 1; } diff --git a/src/game/client/components/controls.cpp b/src/game/client/components/controls.cpp index 396ecf830..17ba98769 100644 --- a/src/game/client/components/controls.cpp +++ b/src/game/client/components/controls.cpp @@ -207,7 +207,7 @@ void CControls::OnRender() bool CControls::OnMouseMove(float x, float y) { - if((m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED) || + if((m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&(GAMESTATEFLAG_PAUSED|GAMESTATEFLAG_ROUNDOVER|GAMESTATEFLAG_GAMEOVER)) || (m_pClient->m_Snap.m_SpecInfo.m_Active && m_pClient->m_pChat->IsActive())) return false; diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 2e656fbe2..b6e31d23d 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -274,6 +274,8 @@ void CHud::RenderScoreHud() float ScoreWidthMax = max(max(aScoreWidth[0], aScoreWidth[1]), TextRender()->TextWidth(0, 14.0f, "10", -1)); float Split = 3.0f, ImageSize = 16.0f, PosSize = 16.0f; + // todo: add core hud for LMS + for(int t = 0; t < 2; t++) { // draw box diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index a9c434b38..507b5180b 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -314,7 +314,9 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) { if( str_comp(pItem->m_aGameType, "DM") == 0 || str_comp(pItem->m_aGameType, "TDM") == 0 || - str_comp(pItem->m_aGameType, "CTF") == 0) + str_comp(pItem->m_aGameType, "CTF") == 0 || + str_comp(pItem->m_aGameType, "LMS") == 0 || + str_comp(pItem->m_aGameType, "SUR") == 0) { // pure server } diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index e048a6845..708289c55 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -887,7 +887,8 @@ void CGameClient::OnNewSnapshot() Client()->GetServerInfo(&CurrentServerInfo); if(CurrentServerInfo.m_aGameType[0] != '0') { - if(str_comp(CurrentServerInfo.m_aGameType, "DM") != 0 && str_comp(CurrentServerInfo.m_aGameType, "TDM") != 0 && str_comp(CurrentServerInfo.m_aGameType, "CTF") != 0) + if(str_comp(CurrentServerInfo.m_aGameType, "DM") != 0 && str_comp(CurrentServerInfo.m_aGameType, "TDM") != 0 && str_comp(CurrentServerInfo.m_aGameType, "CTF") != 0 && + str_comp(CurrentServerInfo.m_aGameType, "LMS") != 0 && str_comp(CurrentServerInfo.m_aGameType, "SUR") != 0) m_ServerMode = SERVERMODE_MOD; else if(mem_comp(&StandardTuning, &m_Tuning, sizeof(CTuningParams)) == 0) m_ServerMode = SERVERMODE_PURE; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index fa407d161..10c3d70ad 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -13,6 +13,7 @@ #include "entities/character.h" #include "gamemodes/ctf.h" #include "gamemodes/dm.h" +#include "gamemodes/lms.h" #include "gamemodes/mod.h" #include "gamemodes/sur.h" #include "gamemodes/tdm.h" @@ -371,8 +372,9 @@ void CGameContext::CheckPureTuning() if( str_comp(m_pController->GetGameType(), "DM")==0 || str_comp(m_pController->GetGameType(), "TDM")==0 || - str_comp(m_pController->GetGameType(), "SUR")==0 || - str_comp(m_pController->GetGameType(), "CTF")==0) + str_comp(m_pController->GetGameType(), "CTF")==0 || + str_comp(m_pController->GetGameType(), "LMS")==0 || + str_comp(m_pController->GetGameType(), "SUR")==0) { CTuningParams p; if(mem_comp(&p, &m_Tuning, sizeof(p)) != 0) @@ -1446,6 +1448,8 @@ void CGameContext::OnInit() m_pController = new CGameControllerMOD(this); else if(str_comp(g_Config.m_SvGametype, "ctf") == 0) m_pController = new CGameControllerCTF(this); + else if(str_comp(g_Config.m_SvGametype, "lms") == 0) + m_pController = new CGameControllerLMS(this); else if(str_comp(g_Config.m_SvGametype, "sur") == 0) m_pController = new CGameControllerSUR(this); else if(str_comp(g_Config.m_SvGametype, "tdm") == 0) diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 42860365e..09f657d1f 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -26,6 +26,7 @@ IGameController::IGameController(CGameContext *pGameServer) m_GameStateTimer = TIMER_INFINITE; m_GameStartTick = Server()->Tick(); m_MatchCount = 0; + m_RoundCount = 0; m_SuddenDeath = 0; m_aTeamscore[TEAM_RED] = 0; m_aTeamscore[TEAM_BLUE] = 0; @@ -388,8 +389,11 @@ void IGameController::OnReset() GameServer()->m_apPlayers[i]->m_RespawnDisabled = false; GameServer()->m_apPlayers[i]->Respawn(); GameServer()->m_apPlayers[i]->m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2; - GameServer()->m_apPlayers[i]->m_Score = 0; - GameServer()->m_apPlayers[i]->m_ScoreStartTick = Server()->Tick(); + if(m_RoundCount == 0) + { + GameServer()->m_apPlayers[i]->m_Score = 0; + GameServer()->m_apPlayers[i]->m_ScoreStartTick = Server()->Tick(); + } GameServer()->m_apPlayers[i]->m_IsReadyToPlay = true; } } @@ -584,6 +588,7 @@ void IGameController::StartMatch() { ResetGame(); + m_RoundCount = 0; m_aTeamscore[TEAM_RED] = 0; m_aTeamscore[TEAM_BLUE] = 0; @@ -603,6 +608,8 @@ void IGameController::StartRound() { ResetGame(); + ++m_RoundCount; + // start countdown if there're enough players, otherwise abort to warmup if(HasEnoughPlayers()) SetGameState(IGS_START_COUNTDOWN); diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index 7c270ddc2..7a3d3712d 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -97,6 +97,7 @@ protected: // game int m_GameStartTick; int m_MatchCount; + int m_RoundCount; int m_SuddenDeath; int m_aTeamscore[NUM_TEAMS]; diff --git a/src/game/server/gamemodes/lms.cpp b/src/game/server/gamemodes/lms.cpp new file mode 100644 index 000000000..fe6211ac2 --- /dev/null +++ b/src/game/server/gamemodes/lms.cpp @@ -0,0 +1,70 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include + +#include +#include +#include +#include "lms.h" + +CGameControllerLMS::CGameControllerLMS(CGameContext *pGameServer) : IGameController(pGameServer) +{ + m_pGameType = "LMS"; + m_GameFlags = GAMEFLAG_SURVIVAL; +} + +// event +int CGameControllerLMS::OnCharacterDeath(CCharacter *pVictim, CPlayer *pKiller, int Weapon) +{ + // update spectator modes for dead players in survival + if(m_GameFlags&GAMEFLAG_SURVIVAL) + { + for(int i = 0; i < MAX_CLIENTS; ++i) + if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->m_DeadSpecMode) + GameServer()->m_apPlayers[i]->UpdateDeadSpecMode(); + } + + return 0; +} + +// game +void CGameControllerLMS::DoWincheckRound() +{ + // check for time based win + if(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_GameStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60) + { + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && + (!GameServer()->m_apPlayers[i]->m_RespawnDisabled || + (GameServer()->m_apPlayers[i]->GetCharacter() && GameServer()->m_apPlayers[i]->GetCharacter()->IsAlive()))) + GameServer()->m_apPlayers[i]->m_Score++; + } + + EndRound(); + } + else + { + // check for survival win + CPlayer *pAlivePlayer = 0; + int AlivePlayerCount = 0; + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && + (!GameServer()->m_apPlayers[i]->m_RespawnDisabled || + (GameServer()->m_apPlayers[i]->GetCharacter() && GameServer()->m_apPlayers[i]->GetCharacter()->IsAlive()))) + { + ++AlivePlayerCount; + pAlivePlayer = GameServer()->m_apPlayers[i]; + } + } + + if(AlivePlayerCount == 0) // no winner + EndRound(); + else if(AlivePlayerCount == 1) // 1 winner + { + pAlivePlayer->m_Score++; + EndRound(); + } + } +} diff --git a/src/game/server/gamemodes/lms.h b/src/game/server/gamemodes/lms.h new file mode 100644 index 000000000..a4e8e7149 --- /dev/null +++ b/src/game/server/gamemodes/lms.h @@ -0,0 +1,19 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#ifndef GAME_SERVER_GAMEMODES_LMS_H +#define GAME_SERVER_GAMEMODES_LMS_H +#include + +class CGameControllerLMS : public IGameController +{ +public: + CGameControllerLMS(class CGameContext *pGameServer); + + // event + virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon); + + // game + virtual void DoWincheckRound(); +}; + +#endif diff --git a/src/game/server/gamemodes/sur.cpp b/src/game/server/gamemodes/sur.cpp index 3c6bb9bcc..3921c5a22 100644 --- a/src/game/server/gamemodes/sur.cpp +++ b/src/game/server/gamemodes/sur.cpp @@ -7,7 +7,7 @@ #include #include "sur.h" -CGameControllerSUR::CGameControllerSUR(class CGameContext *pGameServer) : IGameController(pGameServer) +CGameControllerSUR::CGameControllerSUR(CGameContext *pGameServer) : IGameController(pGameServer) { m_pGameType = "SUR"; m_GameFlags = GAMEFLAG_TEAMS|GAMEFLAG_SURVIVAL; diff --git a/src/game/variables.h b/src/game/variables.h index 9fd1f8e62..6e9e8f27f 100644 --- a/src/game/variables.h +++ b/src/game/variables.h @@ -65,7 +65,7 @@ MACRO_CONFIG_INT(SvMatchSwap, sv_match_swap, 1, 0, 1, CFGFLAG_SERVER, "Swap team MACRO_CONFIG_INT(SvPowerups, sv_powerups, 1, 0, 1, CFGFLAG_SERVER, "Allow powerups like ninja") MACRO_CONFIG_INT(SvScorelimit, sv_scorelimit, 20, 0, 1000, CFGFLAG_SERVER, "Score limit (0 disables)") MACRO_CONFIG_INT(SvTimelimit, sv_timelimit, 0, 0, 1000, CFGFLAG_SERVER, "Time limit in minutes (0 disables)") -MACRO_CONFIG_STR(SvGametype, sv_gametype, 32, "dm", CFGFLAG_SERVER, "Game type (dm, tdm, sur, ctf)") +MACRO_CONFIG_STR(SvGametype, sv_gametype, 32, "dm", CFGFLAG_SERVER, "Game type (dm, tdm, ctf, lms, sur)") MACRO_CONFIG_INT(SvTournamentMode, sv_tournament_mode, 0, 0, 1, CFGFLAG_SERVER, "Tournament mode. When enabled, players joins the server as spectator") MACRO_CONFIG_INT(SvPlayerReadyMode, sv_player_ready_mode, 0, 0, 1, CFGFLAG_SERVER, "When enabled, players can pause/unpause the game and start the game on warmup via their ready state") MACRO_CONFIG_INT(SvSpamprotection, sv_spamprotection, 1, 0, 1, CFGFLAG_SERVER, "Spam protection")