]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Survival: Added ability to block spectating enemies.
authorLyberta <lyberta@lyberta.net>
Sun, 25 Jun 2017 20:39:31 +0000 (23:39 +0300)
committerLyberta <lyberta@lyberta.net>
Sun, 25 Jun 2017 20:39:31 +0000 (23:39 +0300)
qcsrc/server/mutators/mutator/gamemode_survival.qc
survival.cfg

index 438d5ce57f5b2ffa8a3227e0336ef5f2cb6e1360..9756ac2fe44f14f18dd90f9713ae93be71cda2f3 100644 (file)
@@ -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)
index 0e6fdbb62a9490bddee41ca1e7ede2299600aff2..b0deec62937d5bd7d4f30e028be9cac4a23e9dfd 100644 (file)
@@ -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"