]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/effects/qc/casings.qc
Merge branch 'master' into develop
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / casings.qc
index 8cb4a2aa18ff6dcfff9065b62ad01c2b656919af..c0c7f5ac98d41bc95cb90948d4234f84c007f6dc 100644 (file)
@@ -1,9 +1,6 @@
-#ifdef SVQC
-void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner);
-#endif
-
-#ifdef IMPLEMENTATION
+#include "casings.qh"
 
+#include <common/replicate.qh>
 #include <common/util.qh>
 
 #ifdef CSQC
@@ -13,53 +10,57 @@ void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float ran
 
 REGISTER_NET_TEMP(casings)
 
+REPLICATE(cvar_cl_casings, bool, "cl_casings");
+REPLICATE(cvar_r_drawviewmodel, int, "r_drawviewmodel");
+
 #ifdef SVQC
-void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner)
+void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
 {
-    .entity weaponentity = weaponentities[0]; // TODO: parameter
-    entity wep = casingowner.(weaponentity);
-    vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up;
-
-    if (!sound_allowed(MSG_BROADCAST, casingowner))
-        casingtype |= 0x80;
-
-    WriteHeader(MSG_ALL, casings);
-    WriteByte(MSG_ALL, casingtype);
-    WriteCoord(MSG_ALL, org.x);
-    WriteCoord(MSG_ALL, org.y);
-    WriteCoord(MSG_ALL, org.z);
-    WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity
-    WriteByte(MSG_ALL, ang.x * 256 / 360);
-    WriteByte(MSG_ALL, ang.y * 256 / 360);
-    WriteByte(MSG_ALL, ang.z * 256 / 360);
+       vector org = casingowner.(weaponentity).spawnorigin;
+       org = casingowner.origin + casingowner.view_ofs + org.x * v_forward - org.y * v_right + org.z * v_up;
+
+       FOREACH_CLIENT(true, {
+               if (!(CS_CVAR(it).cvar_cl_casings))
+                       continue;
+               if (it == casingowner && !(CS_CVAR(it).cvar_r_drawviewmodel))
+                       continue;
+
+               msg_entity = it;
+               if (!sound_allowed(MSG_ONE, it))
+                       casingtype |= 0x80; // silent
+
+               WriteHeader(MSG_ONE, casings);
+               WriteByte(MSG_ONE, casingtype);
+               WriteVector(MSG_ONE, org);
+               WriteShort(MSG_ONE, compressShortVector(vel)); // actually compressed velocity
+               WriteByte(MSG_ONE, ang.x * 256 / 360);
+               WriteByte(MSG_ONE, ang.y * 256 / 360);
+               WriteByte(MSG_ONE, ang.z * 256 / 360);
+       });
 }
 #endif
 
 #ifdef CSQC
 entityclass(Casing);
-class(Casing) .float alpha;
-class(Casing) .bool silent;
-class(Casing) .int state;
-class(Casing) .float cnt;
+classfield(Casing) .float alpha;
+classfield(Casing) .bool silent;
+classfield(Casing) .int state;
+classfield(Casing) .float cnt;
 
 void Casing_Delete(entity this)
 {
-    remove(this);
+    delete(this);
 }
 
 void Casing_Draw(entity this)
 {
-    if (this.move_flags & FL_ONGROUND)
+    if (IS_ONGROUND(this))
     {
-        this.move_angles_x = 0;
-        this.move_angles_z = 0;
-        UNSET_ONGROUND(this);
+        this.angles_x = 0;
+        this.angles_z = 0;
+        //UNSET_ONGROUND(this);
     }
 
-    Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
-    if (wasfreed(this))
-        return; // deleted by touch function
-
     this.renderflags = 0;
     this.alpha = bound(0, this.cnt - time, 1);
 
@@ -67,39 +68,44 @@ void Casing_Draw(entity this)
     {
         Casing_Delete(this);
         this.drawmask = 0;
+        return;
     }
+
+    Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
+    //if (wasfreed(this))
+    //    return; // deleted by touch function
 }
 
 SOUND(BRASS1, W_Sound("brass1"));
 SOUND(BRASS2, W_Sound("brass2"));
 SOUND(BRASS3, W_Sound("brass3"));
 Sound SND_BRASS_RANDOM() {
-    return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3));
+    return REGISTRY_GET(Sounds, SND_BRASS1.m_id + floor(prandom() * 3));
 }
 SOUND(CASINGS1, W_Sound("casings1"));
 SOUND(CASINGS2, W_Sound("casings2"));
 SOUND(CASINGS3, W_Sound("casings3"));
 Sound SND_CASINGS_RANDOM() {
-    return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3));
+    return REGISTRY_GET(Sounds, SND_CASINGS1.m_id + floor(prandom() * 3));
 }
 
-void Casing_Touch(entity this)
+void Casing_Touch(entity this, entity toucher)
 {
     if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
     {
-        Casing_Delete(self);
+        Casing_Delete(this);
         return;
     }
 
-    if (!self.silent)
+    if (!this.silent)
     if (!trace_ent || trace_ent.solid == SOLID_BSP)
     {
-        if(vdist(self.velocity, >, 50))
+        if(vdist(this.velocity, >, 50))
         {
-            if (time >= self.nextthink)
+            if (time >= this.nextthink)
             {
                 Sound s;
-                switch (self.state)
+                switch (this.state)
                 {
                     case 1:
                         s = SND_CASINGS_RANDOM();
@@ -109,29 +115,26 @@ void Casing_Touch(entity this)
                         break;
                 }
 
-                sound (self, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
+                sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
             }
         }
     }
 
-    self.nextthink = time + 0.2;
+    this.nextthink = time + 0.2;
 }
 
 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
 {
     if (thisforce.z < 0)
         thisforce.z = 0;
-    this.move_velocity = this.move_velocity + thisforce + '0 0 100';
-    this.move_flags &= ~FL_ONGROUND;
+    this.velocity = this.velocity + thisforce + '0 0 100';
+    UNSET_ONGROUND(this);
 }
 
 NET_HANDLE(casings, bool isNew)
 {
     int _state = ReadByte();
-    vector org;
-    org_x = ReadCoord();
-    org_y = ReadCoord();
-    org_z = ReadCoord();
+    vector org = ReadVector();
     vector vel = decompressShortVector(ReadShort());
     vector ang;
     ang_x = ReadByte() * 360 / 256;
@@ -139,9 +142,7 @@ NET_HANDLE(casings, bool isNew)
     ang_z = ReadByte() * 360 / 256;
     return = true;
 
-    if (!autocvar_cl_casings) return;
-
-    Casing casing = RubbleNew("casing");
+    Casing casing = ListNewChildRubble(CasingsNGibs, new(casing));
     casing.silent = (_state & 0x80);
     casing.state = (_state & 0x7F);
     casing.origin = org;
@@ -151,11 +152,11 @@ NET_HANDLE(casings, bool isNew)
     casing.drawmask = MASK_NORMAL;
 
     casing.draw = Casing_Draw;
-    casing.move_origin = casing.origin;
-    casing.move_velocity = casing.velocity + 2 * prandomvec();
-    casing.move_angles = casing.angles;
-    casing.move_avelocity = '0 250 0' + 100 * prandomvec();
-    casing.move_movetype = MOVETYPE_BOUNCE;
+    if (isNew) IL_PUSH(g_drawables, casing);
+    casing.velocity = casing.velocity + 2 * prandomvec();
+    casing.avelocity = '0 250 0' + 100 * prandomvec();
+    set_movetype(casing, MOVETYPE_BOUNCE);
+    casing.bouncefactor = 0.25;
     settouch(casing, Casing_Touch);
     casing.move_time = time;
     casing.event_damage = Casing_Damage;
@@ -175,8 +176,7 @@ NET_HANDLE(casings, bool isNew)
 
     setsize(casing, '0 0 -1', '0 0 -1');
 
-    RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);
+    LimitedChildrenRubble(CasingsNGibs, "casing", autocvar_cl_casings_maxcount, Casing_Delete, NULL);
 }
 
 #endif
-#endif