From 4aca5e654007c25b2f03f1e85fe4d2964f5f321f Mon Sep 17 00:00:00 2001 From: Xylemon Date: Mon, 24 Apr 2023 22:05:17 -0700 Subject: [PATCH] Gamemodes: - Madness now fully reimplemented - Standard and Stealth hunting now finished - New gamemode Invasion, where scientists work together to kill off all players (WIP) Major thanks to @eukara for his help, time, and patienece --- src/server/gamerules.h | 13 +++++ src/server/gamerules.qc | 104 +++++++++++++++++++++++----------------- src/server/server.qc | 3 ++ 3 files changed, 76 insertions(+), 44 deletions(-) diff --git a/src/server/gamerules.h b/src/server/gamerules.h index 28cdb41..a4a7aa9 100644 --- a/src/server/gamerules.h +++ b/src/server/gamerules.h @@ -63,6 +63,7 @@ class SHTeamRules:HLGameRules class SHRules:HLGameRules { + void(void) SHRules; virtual void(void) RegisterSciDeath; }; @@ -124,5 +125,17 @@ typedef enum SHMODE_INVASION } shmode_e; +/* give our gamemode cvar a default */ var shmode_e autocvar_sh_realistic = SHMODE_SLAUGHTER; var shmode_e g_chosen_mode; + +/* limit the amount of scientists that can spawn by default */ +var int autocvar_sh_scimax = 5; + +var int autocvar_sh_scialert = FALSE; + +/* default speed for scientists */ +var int autocvar_sh_scispeed = 40; + +/* an override for sh_scimax */ +var int autocvarsh_scimax_override = 0; \ No newline at end of file diff --git a/src/server/gamerules.qc b/src/server/gamerules.qc index 52441c4..35d8014 100644 --- a/src/server/gamerules.qc +++ b/src/server/gamerules.qc @@ -81,6 +81,7 @@ HLGameRules::PlayerDeath(NSClientPlayer pl) pl.gflags &= ~GF_FLASHLIGHT; pl.gflags &= ~GF_EGONBEAM; pl.gflags &= ~GF_MADNESS; + pl.poisonTimer.StopTimer(); sh_pl.sh_insaneactive = 0.0f; @@ -372,6 +373,24 @@ HLGameRules::InitPostEnts(void) void HLGameRules::HLGameRules(void) { + /* HACK we'll set this here for now to ensure we don't + * have a race condition */ + forceinfokey(world, "sci_count", "0"); + + /* if the previous map set this value but the current doesn't + * then set the default */ + cvar_set("sh_scispeed","40"); + + /* just re-read this to prevent funny beahviour */ + readcmd(sprintf("exec maps/%s.cfg\n", mapname)); + + /* always broadcast how many max scientists the server has set + * but allow an override for server admins */ + if (cvar("sh_scimax_override") > 0) { + forceinfokey(world, "sv_scimax", cvar_string("sh_scimax_override")); + } else { + forceinfokey(world, "sv_scimax", cvar_string("sh_scimax")); + } } /* TEAMPLAY ONLY LOGIC */ @@ -393,6 +412,8 @@ SHTeamRules::PlayerSpawn(NSClientPlayer cl) if (cl.team != 0) return; + /* auto-balance + * TODO make this a command instead */ for (entity e = world; (e = find( e, ::classname, "player"));) { if (e == cl) continue; @@ -422,18 +443,6 @@ SHTeamRules::ScientistKill(NSClientPlayer cl, entity sci) AddTeam1Kill(); } -void -SHTeamRules::ScientistKillFear(NSClientPlayer cl, entity sci) -{ - super::ScientistKill(cl, sci); - - if (cl.team == 2) - RemoveTeam2Kill(); - else if (cl.team == 1) - AddTeam1Kill(); -} - - void SHTeamRules::AddTeam1Kill(void) { @@ -448,46 +457,31 @@ SHTeamRules::AddTeam2Kill(void) forceinfokey(world, "teamkills_2", sprintf("%i", m_iKillsTeam2)); } +/* teamplay scientist death tracking */ void -SHTeamRules::RemoveTeam1Kill(void) -{ - m_iKillsTeam1--; - forceinfokey(world, "teamkills_1", sprintf("%i", m_iKillsTeam1)); -} - -void -SHTeamRules::RemoveTeam2Kill(void) -{ - m_iKillsTeam2--; - forceinfokey(world, "teamkills_2", sprintf("%i", m_iKillsTeam2)); -} - -void -SHTeamRules::RegisterSciDeathHuntTeam(void) +SHTeamRules::RegisterSciDeath(void) { super::RegisterSciDeath(); + /* if no scientists are left then stop */ if (m_iScientistsAlive > 0) return; - switch (g_chosen_mode) { - case SHMODE_STANDARD: - if (m_iKillsTeam1 > m_iKillsTeam2) { - m_iScoreTeam1++; - env_message_broadcast("Red team has won!"); - } else if (m_iKillsTeam1 > m_iKillsTeam2) { - m_iScoreTeam2++; - env_message_broadcast("Blue team has won!"); - } else { - env_message_broadcast("Both teams are tied!"); - } - - forceinfokey(world, "teamscore_1", sprintf("%i", m_iScoreTeam1)); - forceinfokey(world, "teamscore_2", sprintf("%i", m_iScoreTeam2)); - think = RestartRound; - nextthink = time + 5.0f; - break; + /* award the kill to the appropiate team */ + if (m_iKillsTeam1 > m_iKillsTeam2) { + m_iScoreTeam1++; + env_message_broadcast("Red team has won!"); + } else if (m_iKillsTeam1 > m_iKillsTeam2) { + m_iScoreTeam2++; + env_message_broadcast("Blue team has won!"); + } else { + env_message_broadcast("Both teams are tied!"); } + + forceinfokey(world, "teamscore_1", sprintf("%i", m_iScoreTeam1)); + forceinfokey(world, "teamscore_2", sprintf("%i", m_iScoreTeam2)); + think = RestartRound; + nextthink = time + 5.0f; } void @@ -519,3 +513,25 @@ SHTeamRules::SHTeamRules(void) m_iKillsTeam1 = 0; m_iKillsTeam2 = 0; } + +/* invasion scientist death tracking */ +void +SHRules::RegisterSciDeath(void) +{ + super::RegisterSciDeath(); + + /* if no scientists are left then we win */ + if (m_iScientistsAlive > 0) + return; + + env_message_broadcast("You have survived!\nCan you do it again?"); + + think = RestartRound; + nextthink = time + 5.0f; +} + +void +SHRules::SHRules(void) +{ + +} diff --git a/src/server/server.qc b/src/server/server.qc index 492964b..40f59e5 100644 --- a/src/server/server.qc +++ b/src/server/server.qc @@ -35,6 +35,9 @@ Game_InitRules(void) case SHMODE_MADNESS: g_grMode = spawn(SHGameMadness); break; + case SHMODE_INVASION: + g_grMode = spawn(SHGameInvasion); + break; default: g_grMode = spawn(HLGameRules); }