]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/effects/qc/casings.qc
Merge branch 'master' into Mario/csqc_muzzleflash
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / casings.qc
index 60f9633027eb2125d0278bd6abaaa2cb9ed1505a..68eccb461227c1e7797adab66a7985b320ee1c31 100644 (file)
@@ -9,33 +9,44 @@
 
 REGISTER_NET_TEMP(casings)
 
+#if defined(SVQC)
+.bool cvar_cl_casings;
+#elif defined(CSQC)
+bool cvar_cl_casings;
+#endif
+REPLICATE(cvar_cl_casings, bool, "cl_casings");
+
 #ifdef SVQC
 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
 {
-    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);
+       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;
+
+       FOREACH_CLIENT(true, {
+               if (!(CS(it).cvar_cl_casings))
+                       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)
 {
@@ -51,10 +62,6 @@ void Casing_Draw(entity this)
         //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);
 
@@ -62,20 +69,25 @@ 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, entity toucher)
@@ -123,10 +135,7 @@ void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector t
 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;
@@ -134,8 +143,6 @@ NET_HANDLE(casings, bool isNew)
     ang_z = ReadByte() * 360 / 256;
     return = true;
 
-    if (!autocvar_cl_casings) return;
-
     Casing casing = RubbleNew("casing");
     casing.silent = (_state & 0x80);
     casing.state = (_state & 0x7F);
@@ -150,6 +157,7 @@ NET_HANDLE(casings, bool isNew)
     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;