]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move ClientKill code into its own file
authorterencehill <piuntn@gmail.com>
Tue, 14 Aug 2018 17:39:57 +0000 (19:39 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 14 Aug 2018 17:39:57 +0000 (19:39 +0200)
12 files changed:
qcsrc/server/_mod.inc
qcsrc/server/_mod.qh
qcsrc/server/cheats.qc
qcsrc/server/client.qc
qcsrc/server/client.qh
qcsrc/server/clientkill.qc [new file with mode: 0644]
qcsrc/server/clientkill.qh [new file with mode: 0644]
qcsrc/server/command/cmd.qc
qcsrc/server/defs.qh
qcsrc/server/impulse.qc
qcsrc/server/player.qc
qcsrc/server/player.qh

index a4cb8bd5e1c5779b2274a01448ceeb39a689c867..429117ad00cf42f7d73aa7e78a22b737dc17f122 100644 (file)
@@ -4,6 +4,7 @@
 #include <server/campaign.qc>
 #include <server/cheats.qc>
 #include <server/client.qc>
+#include <server/clientkill.qc>
 #include <server/g_damage.qc>
 #include <server/g_hook.qc>
 #include <server/g_world.qc>
index 0a00d680786fa51c84701339d0b9f82fe01000aa..2bbfb7204df508065c4279227c3ebb92ecf248c1 100644 (file)
@@ -4,6 +4,7 @@
 #include <server/campaign.qh>
 #include <server/cheats.qh>
 #include <server/client.qh>
+#include <server/clientkill.qh>
 #include <server/g_damage.qh>
 #include <server/g_hook.qh>
 #include <server/g_world.qh>
index 04172b5eb2b59d74de854c3c1d440ad4c5f7827a..978b3fcb74ecc84721967e95b7ac5e3302facd6b 100644 (file)
@@ -6,6 +6,7 @@
 #include <server/resources.qh>
 
 #include "g_damage.qh"
+#include "clientkill.qh"
 #include "player.qh"
 #include "race.qh"
 #include "../common/mapobjects/teleporters.qh"
index 909e89768b866bad6e8516c50ba7e66946301064..85514bdf9e0b02c553e3def6a750ad84b5043e49 100644 (file)
@@ -17,6 +17,7 @@
 #include "g_hook.qh"
 #include "command/common.qh"
 #include "command/vote.qh"
+#include "clientkill.qh"
 #include "cheats.qh"
 #include "g_world.qh"
 #include "race.qh"
@@ -900,204 +901,6 @@ void DecodeLevelParms(entity this)
        MUTATOR_CALLHOOK(DecodeLevelParms);
 }
 
-/*
-=============
-ClientKill
-
-Called when a client types 'kill' in the console
-=============
-*/
-
-.float clientkill_nexttime;
-void ClientKill_Now_TeamChange(entity this)
-{
-       if(this.killindicator_teamchange == -1)
-       {
-               TeamBalance_JoinBestTeam(this);
-       }
-       else if(this.killindicator_teamchange == -2)
-       {
-               if(blockSpectators)
-                       Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
-               PutObserverInServer(this);
-       }
-       else
-               SV_ChangeTeam(this, this.killindicator_teamchange - 1);
-       this.killindicator_teamchange = 0;
-}
-
-void ClientKill_Now(entity this)
-{
-       if(this.vehicle)
-       {
-           vehicles_exit(this.vehicle, VHEF_RELEASE);
-           if(!this.killindicator_teamchange)
-           {
-            this.vehicle_health = -1;
-            Damage(this, this, this, 1 , DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
-           }
-       }
-
-       if(this.killindicator && !wasfreed(this.killindicator))
-               delete(this.killindicator);
-
-       this.killindicator = NULL;
-
-       if(this.killindicator_teamchange)
-               ClientKill_Now_TeamChange(this);
-
-       if (!IS_SPEC(this) && !IS_OBSERVER(this) && MUTATOR_CALLHOOK(ClientKill_Now, this) == false)
-       {
-               Damage(this, this, this, 100000, DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
-       }
-
-       // now I am sure the player IS dead
-}
-void KillIndicator_Think(entity this)
-{
-       if (game_stopped)
-       {
-               this.owner.killindicator = NULL;
-               delete(this);
-               return;
-       }
-
-       if (this.owner.alpha < 0 && !this.owner.vehicle)
-       {
-               this.owner.killindicator = NULL;
-               delete(this);
-               return;
-       }
-
-       if(this.cnt <= 0)
-       {
-               ClientKill_Now(this.owner);
-               return;
-       }
-    else if(this.count == 1) // count == 1 means that it's silent
-    {
-        this.nextthink = time + 1;
-        this.cnt -= 1;
-    }
-       else
-       {
-               if(this.cnt <= 10)
-                       setmodel(this, MDL_NUM(this.cnt));
-               if(IS_REAL_CLIENT(this.owner))
-               {
-                       if(this.cnt <= 10)
-                               { Send_Notification(NOTIF_ONE, this.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, this.cnt)); }
-               }
-               this.nextthink = time + 1;
-               this.cnt -= 1;
-       }
-}
-
-float clientkilltime;
-void ClientKill_TeamChange (entity this, float targetteam) // 0 = don't change, -1 = auto, -2 = spec
-{
-       float killtime;
-       float starttime;
-
-       if (game_stopped)
-               return;
-
-       killtime = autocvar_g_balance_kill_delay;
-
-    if(MUTATOR_CALLHOOK(ClientKill, this, killtime))
-       return;
-    killtime = M_ARGV(1, float);
-
-       this.killindicator_teamchange = targetteam;
-
-    if(!this.killindicator)
-       {
-               if(!IS_DEAD(this))
-               {
-                       killtime = max(killtime, this.clientkill_nexttime - time);
-                       this.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
-               }
-
-               if(killtime <= 0 || !IS_PLAYER(this) || IS_DEAD(this))
-               {
-                       ClientKill_Now(this);
-               }
-               else
-               {
-                       starttime = max(time, clientkilltime);
-
-                       this.killindicator = spawn();
-                       this.killindicator.owner = this;
-                       this.killindicator.scale = 0.5;
-                       setattachment(this.killindicator, this, "");
-                       setorigin(this.killindicator, '0 0 52');
-                       setthink(this.killindicator, KillIndicator_Think);
-                       this.killindicator.nextthink = starttime + (this.lip) * 0.05;
-                       clientkilltime = max(clientkilltime, this.killindicator.nextthink + 0.05);
-                       this.killindicator.cnt = ceil(killtime);
-                       this.killindicator.count = bound(0, ceil(killtime), 10);
-                       //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
-
-                       IL_EACH(g_clones, it.enemy == this && !(it.effects & CSQCMODEL_EF_RESPAWNGHOST),
-                       {
-                               it.killindicator = spawn();
-                               it.killindicator.owner = it;
-                               it.killindicator.scale = 0.5;
-                               setattachment(it.killindicator, it, "");
-                               setorigin(it.killindicator, '0 0 52');
-                               setthink(it.killindicator, KillIndicator_Think);
-                               it.killindicator.nextthink = starttime + (it.lip) * 0.05;
-                               //clientkilltime = max(clientkilltime, it.killindicator.nextthink + 0.05);
-                               it.killindicator.cnt = ceil(killtime);
-                       });
-                       this.lip = 0;
-               }
-       }
-       if(this.killindicator)
-       {
-               if(targetteam == 0) // just die
-               {
-                       this.killindicator.colormod = '0 0 0';
-                       if(IS_REAL_CLIENT(this))
-                       if(this.killindicator.cnt > 0)
-                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, this.killindicator.cnt);
-               }
-               else if(targetteam == -1) // auto
-               {
-                       this.killindicator.colormod = '0 1 0';
-                       if(IS_REAL_CLIENT(this))
-                       if(this.killindicator.cnt > 0)
-                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, this.killindicator.cnt);
-               }
-               else if(targetteam == -2) // spectate
-               {
-                       this.killindicator.colormod = '0.5 0.5 0.5';
-                       if(IS_REAL_CLIENT(this))
-                       if(this.killindicator.cnt > 0)
-                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, this.killindicator.cnt);
-               }
-               else
-               {
-                       this.killindicator.colormod = Team_ColorRGB(targetteam);
-                       if(IS_REAL_CLIENT(this))
-                       if(this.killindicator.cnt > 0)
-                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE), this.killindicator.cnt);
-               }
-       }
-
-}
-
-void ClientKill (entity this)
-{
-       // TODO: once .health is removed, will need to check it here for the "already dead" message!
-
-       if(game_stopped) return;
-       if(this.player_blocked) return;
-       if(STAT(FROZEN, this)) return;
-
-       ClientKill_TeamChange(this, 0);
-}
-
 void FixClientCvars(entity e)
 {
        // send prediction settings to the client
index 2d3a099b3988bc715589d9f5018fd310be1fc7f6..efb61a436d8db7021028b58c8b60424b6bdfb67a 100644 (file)
@@ -274,8 +274,6 @@ void FixPlayermodel(entity player);
 
 void ClientInit_misc(entity this);
 
-void ClientKill_TeamChange(entity this, float targetteam);  // 0 = don't change, -1 = auto, -2 = spec
-
 bool joinAllowed(entity this);
 void Join(entity this);
 
diff --git a/qcsrc/server/clientkill.qc b/qcsrc/server/clientkill.qc
new file mode 100644 (file)
index 0000000..aec5387
--- /dev/null
@@ -0,0 +1,198 @@
+#include "clientkill.qh"
+
+#include <server/defs.qh>
+
+#include "g_damage.qh"
+#include "teamplay.qh"
+
+#include <common/vehicles/sv_vehicles.qh>
+#include <common/notifications/all.qh>
+#include <common/stats.qh>
+
+void ClientKill_Now_TeamChange(entity this)
+{
+       if (this.killindicator_teamchange == -1)
+       {
+               TeamBalance_JoinBestTeam(this);
+       }
+       else if (this.killindicator_teamchange == -2)
+       {
+               if (blockSpectators)
+                       Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
+               PutObserverInServer(this);
+       }
+       else
+               SV_ChangeTeam(this, this.killindicator_teamchange - 1);
+       this.killindicator_teamchange = 0;
+}
+
+void ClientKill_Now(entity this)
+{
+       if (this.vehicle)
+       {
+               vehicles_exit(this.vehicle, VHEF_RELEASE);
+               if (!this.killindicator_teamchange)
+               {
+                       this.vehicle_health = -1;
+                       Damage(this, this, this, 1 , DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
+               }
+       }
+
+       if (this.killindicator && !wasfreed(this.killindicator))
+               delete(this.killindicator);
+
+       this.killindicator = NULL;
+
+       if (this.killindicator_teamchange)
+               ClientKill_Now_TeamChange(this);
+
+       if (!IS_SPEC(this) && !IS_OBSERVER(this) && MUTATOR_CALLHOOK(ClientKill_Now, this) == false)
+       {
+               Damage(this, this, this, 100000, DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
+       }
+
+       // now I am sure the player IS dead
+}
+void KillIndicator_Think(entity this)
+{
+       if (game_stopped)
+       {
+               this.owner.killindicator = NULL;
+               delete(this);
+               return;
+       }
+
+       if (this.owner.alpha < 0 && !this.owner.vehicle)
+       {
+               this.owner.killindicator = NULL;
+               delete(this);
+               return;
+       }
+
+       if (this.cnt <= 0)
+       {
+               ClientKill_Now(this.owner);
+               return;
+       }
+       else if (this.count == 1) // count == 1 means that it's silent
+       {
+               this.nextthink = time + 1;
+               this.cnt -= 1;
+       }
+       else
+       {
+               if (this.cnt <= 10)
+                       setmodel(this, MDL_NUM(this.cnt));
+               if (IS_REAL_CLIENT(this.owner))
+               {
+                       if (this.cnt <= 10)
+                               Send_Notification(NOTIF_ONE, this.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, this.cnt));
+               }
+               this.nextthink = time + 1;
+               this.cnt -= 1;
+       }
+}
+
+.float lip;
+float clientkilltime;
+.float clientkill_nexttime;
+void ClientKill_TeamChange(entity this, float targetteam) // 0 = don't change, -1 = auto, -2 = spec
+{
+       if (game_stopped)
+               return;
+
+       float killtime = autocvar_g_balance_kill_delay;
+
+       if (MUTATOR_CALLHOOK(ClientKill, this, killtime))
+               return;
+       killtime = M_ARGV(1, float);
+
+       this.killindicator_teamchange = targetteam;
+
+       if (!this.killindicator)
+       {
+               if (!IS_DEAD(this))
+               {
+                       killtime = max(killtime, this.clientkill_nexttime - time);
+                       this.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
+               }
+
+               if (killtime <= 0 || !IS_PLAYER(this) || IS_DEAD(this))
+               {
+                       ClientKill_Now(this);
+               }
+               else
+               {
+                       float starttime = max(time, clientkilltime);
+
+                       this.killindicator = spawn();
+                       this.killindicator.owner = this;
+                       this.killindicator.scale = 0.5;
+                       setattachment(this.killindicator, this, "");
+                       setorigin(this.killindicator, '0 0 52');
+                       setthink(this.killindicator, KillIndicator_Think);
+                       this.killindicator.nextthink = starttime + (this.lip) * 0.05;
+                       clientkilltime = max(clientkilltime, this.killindicator.nextthink + 0.05);
+                       this.killindicator.cnt = ceil(killtime);
+                       this.killindicator.count = bound(0, ceil(killtime), 10);
+                       //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
+
+                       IL_EACH(g_clones, it.enemy == this && !(it.effects & CSQCMODEL_EF_RESPAWNGHOST),
+                       {
+                               it.killindicator = spawn();
+                               it.killindicator.owner = it;
+                               it.killindicator.scale = 0.5;
+                               setattachment(it.killindicator, it, "");
+                               setorigin(it.killindicator, '0 0 52');
+                               setthink(it.killindicator, KillIndicator_Think);
+                               it.killindicator.nextthink = starttime + (it.lip) * 0.05;
+                               //clientkilltime = max(clientkilltime, it.killindicator.nextthink + 0.05);
+                               it.killindicator.cnt = ceil(killtime);
+                       });
+                       this.lip = 0;
+               }
+       }
+       if (this.killindicator)
+       {
+               if (targetteam == 0) // just die
+               {
+                       this.killindicator.colormod = '0 0 0';
+                       if(IS_REAL_CLIENT(this))
+                       if(this.killindicator.cnt > 0)
+                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, this.killindicator.cnt);
+               }
+               else if (targetteam == -1) // auto
+               {
+                       this.killindicator.colormod = '0 1 0';
+                       if(IS_REAL_CLIENT(this))
+                       if(this.killindicator.cnt > 0)
+                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, this.killindicator.cnt);
+               }
+               else if (targetteam == -2) // spectate
+               {
+                       this.killindicator.colormod = '0.5 0.5 0.5';
+                       if(IS_REAL_CLIENT(this))
+                       if(this.killindicator.cnt > 0)
+                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, this.killindicator.cnt);
+               }
+               else
+               {
+                       this.killindicator.colormod = Team_ColorRGB(targetteam);
+                       if(IS_REAL_CLIENT(this))
+                       if(this.killindicator.cnt > 0)
+                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE), this.killindicator.cnt);
+               }
+       }
+
+}
+
+// Called when a client types 'kill' in the console
+void ClientKill(entity this)
+{
+       // TODO: once .health is removed, will need to check it here for the "already dead" message!
+
+       if (game_stopped || this.player_blocked || STAT(FROZEN, this))
+               return;
+
+       ClientKill_TeamChange(this, 0);
+}
diff --git a/qcsrc/server/clientkill.qh b/qcsrc/server/clientkill.qh
new file mode 100644 (file)
index 0000000..33c4adb
--- /dev/null
@@ -0,0 +1,10 @@
+
+// set when showing a kill countdown
+.entity killindicator;
+.int killindicator_teamchange;
+
+void ClientKill_Now_TeamChange(entity this);
+void ClientKill_Now(entity this);
+void KillIndicator_Think(entity this);
+void ClientKill_TeamChange(entity this, float targetteam);  // 0 = don't change, -1 = auto, -2 = spec
+void ClientKill(entity this);
index 04fb79d38ce6be8ad1d82911321424f0949aba56..9743dc5c4815f56c0ef3212f52e661fe5bdc85d6 100644 (file)
@@ -11,6 +11,7 @@
 #include "../campaign.qh"
 #include "../cheats.qh"
 #include "../client.qh"
+#include "../clientkill.qh"
 #include "../player.qh"
 #include "../ipban.qh"
 #include "../mapvoting.qh"
index d2a695aeb988c274df6e478527ae09cfbee8f753..5114ae2f428ac0bc7aebebdcae3fadc58f660735 100644 (file)
@@ -219,9 +219,6 @@ bool some_spawn_has_been_used;
 int have_team_spawns; // 0 = no team spawns requested, -1 = team spawns requested but none found, 1 = team spawns requested and found
 int have_team_spawns_forteams; // if Xth bit is 1 then team X has spawns else it has no spawns; team 0 is the "no-team"
 
-// set when showing a kill countdown
-.entity killindicator;
-
 .bool canteamdamage;
 
 void Damage (entity targ, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force);
@@ -367,8 +364,6 @@ const float ACTIVE_TOGGLE   = 3;
 .entity muzzle_flash;
 .float misc_bulletcounter;     // replaces uzi & hlac bullet counter.
 
-.int killindicator_teamchange;
-
 void PlayerUseKey(entity this);
 
 USING(spawn_evalfunc_t, vector(entity this, entity player, entity spot, vector current));
index 5010d283711ff0e795ed3f146bb097b56cfbcd10..5d71b95afa829d84ba7885516b458a92d40a3dd2 100644 (file)
@@ -6,6 +6,7 @@
 #include "weapons/throwing.qh"
 #include "command/common.qh"
 #include "cheats.qh"
+#include "clientkill.qh"
 #include "weapons/selection.qh"
 #include "weapons/tracing.qh"
 #include "weapons/weaponsystem.qh"
index 3755da96386ed98e6b10f9a754185a7f6b487951..5d69c0aa1a4b88dde931bd63ec6f967dd525cdad 100644 (file)
@@ -3,6 +3,7 @@
 #include <common/effects/all.qh>
 #include "bot/api.qh"
 #include "cheats.qh"
+#include "clientkill.qh"
 #include "g_damage.qh"
 #include "handicap.qh"
 #include "miscfunctions.qh"
index 1c38a9fbebf3012b1d87029e26659457d7548a1c..c386473d95f9fe60d4f8483abe8099876c1f4bf2 100644 (file)
@@ -28,8 +28,6 @@ void PlayerCorpseDamage(entity this, entity inflictor, entity attacker, float da
 
 void calculate_player_respawn_time(entity this);
 
-void ClientKill_Now_TeamChange(entity this);
-
 void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force);
 
 bool PlayerHeal(entity targ, entity inflictor, float amount, float limit);