From f63d2620d2bbf6946ed257f297332a743f977a7c Mon Sep 17 00:00:00 2001
From: TimePath <andrew.hardaker1995@gmail.com>
Date: Thu, 5 Nov 2015 22:32:42 +1100
Subject: [PATCH] Gibs: move to qc effects

---
 qcsrc/client/damage.qc                      | 16 ++++-
 qcsrc/client/gibs.qh                        | 24 -------
 qcsrc/client/main.qc                        |  1 -
 qcsrc/client/progs.inc                      |  4 +-
 qcsrc/common/effects/qc/all.inc             |  1 +
 qcsrc/{client => common/effects/qc}/gibs.qc | 80 ++++++++++++++++-----
 qcsrc/server/cl_player.qc                   |  1 -
 qcsrc/server/g_violence.qc                  | 52 --------------
 qcsrc/server/g_violence.qh                  | 10 ---
 qcsrc/server/progs.inc                      |  4 +-
 10 files changed, 83 insertions(+), 110 deletions(-)
 delete mode 100644 qcsrc/client/gibs.qh
 rename qcsrc/{client => common/effects/qc}/gibs.qc (80%)
 delete mode 100644 qcsrc/server/g_violence.qc
 delete mode 100644 qcsrc/server/g_violence.qh

diff --git a/qcsrc/client/damage.qc b/qcsrc/client/damage.qc
index a0c1696107..fe99d507b7 100644
--- a/qcsrc/client/damage.qc
+++ b/qcsrc/client/damage.qc
@@ -1,6 +1,5 @@
 #include "damage.qh"
 
-#include "gibs.qh"
 #include "../common/deathtypes/all.qh"
 #include "../common/movetypes/movetypes.qh"
 #include "../common/vehicles/all.qh"
@@ -45,6 +44,21 @@ void DamageEffect_Think()
 	__pointparticles(self.team, org, '0 0 0', 1);
 }
 
+string species_prefix(int specnum)
+{
+	switch(specnum)
+	{
+		case SPECIES_HUMAN:       return "";
+		case SPECIES_ALIEN:       return "alien_";
+		case SPECIES_ROBOT_SHINY: return "robot_";
+		case SPECIES_ROBOT_RUSTY: return "robot_"; // use the same effects, only different gibs
+		case SPECIES_ROBOT_SOLID: return "robot_"; // use the same effects, only different gibs
+		case SPECIES_ANIMAL:      return "animal_";
+		case SPECIES_RESERVED:    return "reserved_";
+		default:         return "";
+	}
+}
+
 void DamageEffect(vector hitorg, float thedamage, int type, int specnum)
 {SELFPARAM();
 	// particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
diff --git a/qcsrc/client/gibs.qh b/qcsrc/client/gibs.qh
deleted file mode 100644
index 69058f6c46..0000000000
--- a/qcsrc/client/gibs.qh
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef CLIENT_GIBS_H
-#define CLIENT_GIBS_H
-
-.vector colormod;
-
-.bool silent;
-
-void Gib_Delete();
-
-string species_prefix(int specnum);
-
-void Gib_setmodel(entity gib, string mdlname, int specnum);
-
-void new_te_bloodshower (int ef, vector org, float explosionspeed, int howmany);
-
-void SUB_RemoveOnNoImpact();
-
-void Gib_Touch();
-
-void Gib_Draw(entity this);
-
-void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, int specnum, bool destroyontouch, bool issilent);
-
-#endif
diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc
index bb522b4adc..d205284c7d 100644
--- a/qcsrc/client/main.qc
+++ b/qcsrc/client/main.qc
@@ -2,7 +2,6 @@
 
 #include "damage.qh"
 #include "../common/effects/qc/all.qh"
-#include "gibs.qh"
 #include "hook.qh"
 #include "hud/all.qh"
 #include "mapvoting.qh"
diff --git a/qcsrc/client/progs.inc b/qcsrc/client/progs.inc
index a4eee1c73d..84e596c947 100644
--- a/qcsrc/client/progs.inc
+++ b/qcsrc/client/progs.inc
@@ -1,12 +1,12 @@
 #include "../lib/_all.inc"
 #include "_all.qh"
 
+#include "../common/effects/qc/all.qc"
+
 #include "announcer.qc"
 #include "bgmscript.qc"
 #include "csqcmodel_hooks.qc"
 #include "damage.qc"
-#include "../common/effects/qc/all.qc"
-#include "gibs.qc"
 #include "hook.qc"
 #include "hud/all.qc"
 #include "main.qc"
diff --git a/qcsrc/common/effects/qc/all.inc b/qcsrc/common/effects/qc/all.inc
index 7b0639610b..33aa1ccb86 100644
--- a/qcsrc/common/effects/qc/all.inc
+++ b/qcsrc/common/effects/qc/all.inc
@@ -1,2 +1,3 @@
 #include "casings.qc"
+#include "gibs.qc"
 #include "lightningarc.qc"
diff --git a/qcsrc/client/gibs.qc b/qcsrc/common/effects/qc/gibs.qc
similarity index 80%
rename from qcsrc/client/gibs.qc
rename to qcsrc/common/effects/qc/gibs.qc
index 675cd40c5e..ab8dbb8ccf 100644
--- a/qcsrc/client/gibs.qc
+++ b/qcsrc/common/effects/qc/gibs.qc
@@ -1,4 +1,62 @@
-#include "gibs.qh"
+#ifdef IMPLEMENTATION
+REGISTER_NET_TEMP(net_gibsplash)
+
+#ifdef SVQC
+
+.int state;
+
+bool Violence_GibSplash_SendEntity(entity this, entity to, int sf)
+{
+	int channel = MSG_ONE;
+	msg_entity = to;
+	WriteHeader(channel, net_gibsplash);
+	WriteByte(channel, this.state); // actually type
+	WriteByte(channel, bound(1, this.cnt * 16, 255)); // gibbage amount multiplier
+	WriteShort(channel, floor(this.origin.x / 4)); // not using a coord here, as gibs don't need this accuracy
+	WriteShort(channel, floor(this.origin.y / 4)); // not using a coord here, as gibs don't need this accuracy
+	WriteShort(channel, floor(this.origin.z / 4)); // not using a coord here, as gibs don't need this accuracy
+	WriteShort(channel, this.oldorigin.x); // acrually compressed velocity
+	return true;
+}
+
+void Violence_GibSplash_At(vector org, vector dir, float type, float amount, entity gibowner, entity attacker)
+{SELFPARAM();
+	if(g_cts) // no gibs in CTS
+		return;
+
+	entity e = new(gibsplash);
+	e.cnt = amount;
+	e.state = type; // should stay smaller than 15
+	if(!sound_allowed(MSG_BROADCAST, gibowner) || !sound_allowed(MSG_BROADCAST, attacker))
+		e.state |= 0x40; // "silence" bit
+	e.state |= 8 * self.species; // gib type, ranges from 0 to 15
+
+	// if this is a copied dead body, send the num of its player instead
+	// TODO: remove this field, read from model txt files
+	if(self.classname == "body")
+		e.team = num_for_edict(self.enemy);
+	else
+		e.team = num_for_edict(self);
+
+	setorigin(e, org);
+	e.velocity = dir;
+
+	e.oldorigin_x = compressShortVector(e.velocity);
+
+	entity cl; FOR_EACH_REALCLIENT(cl) Violence_GibSplash_SendEntity(e, cl, 0);
+	remove(e);
+}
+
+void Violence_GibSplash(entity source, float type, float amount, entity attacker)
+{
+	Violence_GibSplash_At(source.origin + source.view_ofs, source.velocity, type, amount, source, attacker);
+}
+#endif
+
+#ifdef CSQC
+
+.vector colormod;
+.bool silent;
 
 #include "rubble.qh"
 #include "../common/movetypes/movetypes.qh"
@@ -13,20 +71,7 @@ void Gib_Delete()
 	remove(self);
 }
 
-string species_prefix(int specnum)
-{
-	switch(specnum)
-	{
-		case SPECIES_HUMAN:       return "";
-		case SPECIES_ALIEN:       return "alien_";
-		case SPECIES_ROBOT_SHINY: return "robot_";
-		case SPECIES_ROBOT_RUSTY: return "robot_"; // use the same effects, only different gibs
-		case SPECIES_ROBOT_SOLID: return "robot_"; // use the same effects, only different gibs
-		case SPECIES_ANIMAL:      return "animal_";
-		case SPECIES_RESERVED:    return "reserved_";
-		default:         return "";
-	}
-}
+string species_prefix(int specnum);
 
 void Gib_setmodel(entity gib, string mdlname, int specnum)
 {
@@ -158,8 +203,6 @@ void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector
 	RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
 }
 
-REGISTER_NET_TEMP(net_gibsplash)
-
 NET_HANDLE(net_gibsplash, bool isNew)
 {
 	Net_Accept(net_gibsplash);
@@ -268,3 +311,6 @@ NET_HANDLE(net_gibsplash, bool isNew)
 	}
 	remove(this);
 }
+#endif
+
+#endif
diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc
index d6aa84ea1a..84e905e85f 100644
--- a/qcsrc/server/cl_player.qc
+++ b/qcsrc/server/cl_player.qc
@@ -4,7 +4,6 @@
 #include "cheats.qh"
 #include "g_damage.qh"
 #include "g_subs.qh"
-#include "g_violence.qh"
 #include "miscfunctions.qh"
 #include "portals.qh"
 #include "teamplay.qh"
diff --git a/qcsrc/server/g_violence.qc b/qcsrc/server/g_violence.qc
deleted file mode 100644
index 688fa1d197..0000000000
--- a/qcsrc/server/g_violence.qc
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "g_violence.qh"
-
-.int state;
-
-REGISTER_NET_TEMP(net_gibsplash)
-
-bool Violence_GibSplash_SendEntity(entity this, entity to, int sf)
-{
-	int channel = MSG_ONE;
-	msg_entity = to;
-	WriteHeader(channel, net_gibsplash);
-	WriteByte(channel, this.state); // actually type
-	WriteByte(channel, bound(1, this.cnt * 16, 255)); // gibbage amount multiplier
-	WriteShort(channel, floor(this.origin.x / 4)); // not using a coord here, as gibs don't need this accuracy
-	WriteShort(channel, floor(this.origin.y / 4)); // not using a coord here, as gibs don't need this accuracy
-	WriteShort(channel, floor(this.origin.z / 4)); // not using a coord here, as gibs don't need this accuracy
-	WriteShort(channel, this.oldorigin.x); // acrually compressed velocity
-	return true;
-}
-
-void Violence_GibSplash_At(vector org, vector dir, float type, float amount, entity gibowner, entity attacker)
-{SELFPARAM();
-	if(g_cts) // no gibs in CTS
-		return;
-
-	entity e = new(gibsplash);
-	e.cnt = amount;
-	e.state = type; // should stay smaller than 15
-	if(!sound_allowed(MSG_BROADCAST, gibowner) || !sound_allowed(MSG_BROADCAST, attacker))
-		e.state |= 0x40; // "silence" bit
-	e.state |= 8 * self.species; // gib type, ranges from 0 to 15
-
-	// if this is a copied dead body, send the num of its player instead
-	// TODO: remove this field, read from model txt files
-	if(self.classname == "body")
-		e.team = num_for_edict(self.enemy);
-	else
-		e.team = num_for_edict(self);
-
-	setorigin(e, org);
-	e.velocity = dir;
-
-	e.oldorigin_x = compressShortVector(e.velocity);
-
-	entity cl; FOR_EACH_REALCLIENT(cl) Violence_GibSplash_SendEntity(e, cl, 0);
-	remove(e);
-}
-
-void Violence_GibSplash(entity source, float type, float amount, entity attacker)
-{
-	Violence_GibSplash_At(source.origin + source.view_ofs, source.velocity, type, amount, source, attacker);
-}
diff --git a/qcsrc/server/g_violence.qh b/qcsrc/server/g_violence.qh
deleted file mode 100644
index 6a33ac4418..0000000000
--- a/qcsrc/server/g_violence.qh
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef G_VIOLENCE_H
-#define G_VIOLENCE_H
-
-bool Violence_GibSplash_SendEntity(entity this, entity to, int sf);
-
-// TODO maybe convert this to a TE?
-void Violence_GibSplash_At(vector org, vector dir, float type, float amount, entity gibowner, entity attacker);
-
-void Violence_GibSplash(entity source, float type, float amount, entity attacker);
-#endif
diff --git a/qcsrc/server/progs.inc b/qcsrc/server/progs.inc
index 6fd58e7076..6ab895f21f 100644
--- a/qcsrc/server/progs.inc
+++ b/qcsrc/server/progs.inc
@@ -1,6 +1,8 @@
 #include "../lib/_all.inc"
 #include "_all.qh"
 
+#include "../common/effects/qc/all.qc"
+
 #include "anticheat.qc"
 #include "antilag.qc"
 #include "campaign.qc"
@@ -8,14 +10,12 @@
 #include "cl_client.qc"
 #include "cl_impulse.qc"
 #include "cl_player.qc"
-#include "../common/effects/qc/all.qc"
 #include "ent_cs.qc"
 #include "g_damage.qc"
 #include "g_hook.qc"
 // #include "g_lights.qc" // TODO: was never used
 #include "g_models.qc"
 #include "g_subs.qc"
-#include "g_violence.qc"
 #include "g_world.qc"
 #include "ipban.qc"
 #include "item_key.qc"
-- 
2.39.5