From 6b80dd9caa16a0825b8bf0d0f7b956e58a1e3295 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Sun, 25 Jun 2017 23:39:31 +0300 Subject: [PATCH] Survival: Added ability to block spectating enemies. --- .../mutators/mutator/gamemode_survival.qc | 57 +++++++++++++++++++ survival.cfg | 1 + 2 files changed, 58 insertions(+) diff --git a/qcsrc/server/mutators/mutator/gamemode_survival.qc b/qcsrc/server/mutators/mutator/gamemode_survival.qc index 438d5ce57..9756ac2fe 100644 --- a/qcsrc/server/mutators/mutator/gamemode_survival.qc +++ b/qcsrc/server/mutators/mutator/gamemode_survival.qc @@ -64,6 +64,8 @@ int autocvar_g_surv_point_leadlimit; ///< Maximum lead of a single team. int autocvar_g_surv_team_size; /// \brief If set, defenders will not be shown on the radar. int autocvar_g_surv_stealth; +/// \brief Whether to allow spectating enemy players while dead. +bool autocvar_g_surv_spectate_enemies; /// \brief Whether to force overkill player models for attackers. int autocvar_g_surv_attacker_force_overkill_models; @@ -2137,6 +2139,61 @@ MUTATOR_HOOKFUNCTION(surv, GiveFragsForKill, CBC_ORDER_FIRST) return true; } +MUTATOR_HOOKFUNCTION(surv, SpectateSet) +{ + entity client = M_ARGV(0, entity); + entity targ = M_ARGV(1, entity); + + if (!autocvar_g_surv_spectate_enemies && + (client.surv_state == SURVIVAL_STATE_PLAYING) && + DIFF_TEAM(targ, client)) + { + return true; + } +} + +MUTATOR_HOOKFUNCTION(surv, SpectateNext) +{ + entity client = M_ARGV(0, entity); + + if (!autocvar_g_surv_spectate_enemies && + (client.surv_state == SURVIVAL_STATE_PLAYING)) + { + entity targ = M_ARGV(1, entity); + M_ARGV(1, entity) = CA_SpectateNext(client, targ); + return true; + } +} + +MUTATOR_HOOKFUNCTION(surv, SpectatePrev) +{ + entity client = M_ARGV(0, entity); + entity targ = M_ARGV(1, entity); + entity first = M_ARGV(2, entity); + + if (!autocvar_g_surv_spectate_enemies && + (client.surv_state == SURVIVAL_STATE_PLAYING)) + { + do + { + targ = targ.chain; + } + while (targ && DIFF_TEAM(targ, client)); + if (!targ) + { + for (targ = first; targ && DIFF_TEAM(targ, client); + targ = targ.chain); + + if (targ == client.enemy) + { + return MUT_SPECPREV_RETURN; + } + } + } + M_ARGV(1, entity) = targ; + return MUT_SPECPREV_FOUND; +} + /// \brief I'm not sure exactly what this function does but it is very /// important. Without it bots are completely broken. Is it a hack? Of course. MUTATOR_HOOKFUNCTION(surv, Bot_FixCount, CBC_ORDER_EXCLUSIVE) diff --git a/survival.cfg b/survival.cfg index 0e6fdbb62..b0deec629 100644 --- a/survival.cfg +++ b/survival.cfg @@ -20,6 +20,7 @@ seta g_surv_point_limit -1 "Survival point limit overriding the mapinfo specifie seta g_surv_point_leadlimit -1 "Survival point lead limit overriding the mapinfo specified one (use 0 to play without limit, and -1 to use the mapinfo's limit)" set g_surv_team_size 4 "How much players are allowed in teams (excluding cannon fodder)" set g_surv_stealth 0 "If set, defenders will not be shown on the radar" +set g_surv_spectate_enemies 0 "Whether to allow spectating enemy players while dead" set g_surv_attacker_force_overkill_models 0 "Whether to force overkill player models for attackers" set g_surv_defender_force_overkill_models 1 "Whether to force overkill player models for defenders" -- 2.39.5