From 45ed3fa7cc58ae556ea59aceb5973fcbc21cd4f6 Mon Sep 17 00:00:00 2001
From: Mario <mario@smbclan.net>
Date: Thu, 1 Feb 2018 23:50:24 +1000
Subject: [PATCH] Add cvars to control the minimum and maximum speed multiplier
 while spectating

---
 defaultServer.cfg               | 2 ++
 qcsrc/ecs/systems/sv_physics.qc | 4 ++--
 qcsrc/server/autocvars.qh       | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/defaultServer.cfg b/defaultServer.cfg
index 7397462677..4cabc2246a 100644
--- a/defaultServer.cfg
+++ b/defaultServer.cfg
@@ -83,6 +83,8 @@ set sv_precacheplayermodels 1
 set sv_precacheweapons 0
 set sv_precacheitems 0
 set sv_spectator_speed_multiplier 1.5
+set sv_spectator_speed_multiplier_min 1
+set sv_spectator_speed_multiplier_max 5
 set sv_spectate 1 "if set to 1, new clients are allowed to spectate or observe the game, if set to 0 joining clients spawn as players immediately (no spectating)"
 set sv_defaultcharacter 0 "master switch, if set to 1 the further configuration for replacing all player models, skins and colors is taken from the sv_defaultplayermodel, sv_defaultplayerskin and sv_defaultplayercolors variables"
 set sv_defaultcharacterskin 0 "if set to 1 the further configuration for replacing all skins is taken from the sv_defaultplayerskin variables"
diff --git a/qcsrc/ecs/systems/sv_physics.qc b/qcsrc/ecs/systems/sv_physics.qc
index 6731bdf943..ac939740b6 100644
--- a/qcsrc/ecs/systems/sv_physics.qc
+++ b/qcsrc/ecs/systems/sv_physics.qc
@@ -65,7 +65,7 @@ void sys_phys_spectator_control(entity this)
 			    || CS(this).impulse == 18
 			    || (CS(this).impulse >= 200 && CS(this).impulse <= 209)
 			   ) {
-				this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
+				this.spectatorspeed = bound(autocvar_sv_spectator_speed_multiplier_min, this.spectatorspeed + 0.5, autocvar_sv_spectator_speed_multiplier_max);
 			} else if (CS(this).impulse == 11) {
 				this.spectatorspeed = maxspeed_mod;
 			} else if (CS(this).impulse == 12
@@ -86,7 +86,7 @@ void sys_phys_fixspeed(entity this, float maxspeed_mod)
 {
 	float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
 	if (this.speed != spd) {
-		this.speed = spd;
+		this.speed = spd; // TODO: send this as a stat and set the below cvars on the client?
 		string temps = ftos(spd);
 		stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
 		stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh
index 4b3745dc00..80da3f403a 100644
--- a/qcsrc/server/autocvars.qh
+++ b/qcsrc/server/autocvars.qh
@@ -330,6 +330,8 @@ bool autocvar_sv_ready_restart_repeatable;
 bool autocvar_sv_servermodelsonly;
 int autocvar_sv_spectate;
 float autocvar_sv_spectator_speed_multiplier;
+float autocvar_sv_spectator_speed_multiplier_min = 1;
+float autocvar_sv_spectator_speed_multiplier_max = 5;
 bool autocvar_sv_status_privacy;
 float autocvar_sv_stepheight;
 float autocvar_sv_strengthsound_antispam_refire_threshold;
-- 
2.39.5