]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/tracing.qc
Merge branch 'terencehill/menu_optimization' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / tracing.qc
index eec32a3e51ac0339bf9c764d992b15aa3b942b90..facf13f2028be61a41a13e39bae5fd2ba9a3a08c 100644 (file)
@@ -1,20 +1,20 @@
 #include "tracing.qh"
-#include "../_all.qh"
 
 #include "accuracy.qh"
 #include "common.qh"
 #include "hitplot.qh"
+#include "weaponsystem.qh"
 
 #include "../g_damage.qh"
 #include "../g_subs.qh"
 #include "../antilag.qh"
 
-#include "../../common/constants.qh"
-#include "../../common/util.qh"
+#include <common/constants.qh>
+#include <common/util.qh>
 
-#include "../../common/weapons/all.qh"
+#include <common/weapons/all.qh>
 
-#include "../../warpzonelib/common.qh"
+#include <lib/warpzone/common.qh>
 
 // this function calculates w_shotorg and w_shotdir based on the weapon model
 // offset, trueaim and antilag, and won't put w_shotorg inside a wall.
@@ -25,7 +25,7 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m
        float oldsolid;
        vector vecs, dv;
        oldsolid = ent.dphitcontentsmask;
-       if(ent.weapon == WEP_RIFLE.m_id)
+       if (IS_PLAYER(ent) && PS(ent).m_weapon == WEP_RIFLE)
                ent.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_CORPSE;
        else
                ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
@@ -46,17 +46,20 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m
        v_up = vu;
 
        // un-adjust trueaim if shotend is too close
-       if(vlen(w_shotend - (ent.origin + ent.view_ofs)) < autocvar_g_trueaim_minrange)
+       if(vdist(w_shotend - (ent.origin + ent.view_ofs), <, autocvar_g_trueaim_minrange))
                w_shotend = ent.origin + ent.view_ofs + s_forward * autocvar_g_trueaim_minrange;
 
        // track max damage
-       if(accuracy_canbegooddamage(ent))
-               accuracy_add(ent, ent.weapon, maxdamage, 0);
+       if (IS_PLAYER(ent) && accuracy_canbegooddamage(ent))
+               accuracy_add(ent, PS(ent).m_weapon.m_id, maxdamage, 0);
 
-       W_HitPlotAnalysis(ent, v_forward, v_right, v_up);
+       if(IS_PLAYER(ent))
+               W_HitPlotAnalysis(ent, v_forward, v_right, v_up);
 
-       if(ent.weaponentity.movedir.x > 0)
-               vecs = ent.weaponentity.movedir;
+       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+       vector md = ent.(weaponentity).movedir;
+       if(md.x > 0)
+               vecs = md;
        else
                vecs = '0 0 0';
 
@@ -131,7 +134,7 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m
 
        if (snd != "")
        {
-               sound (ent, chan, snd, VOL_BASE, ATTN_NORM);
+               _sound (ent, chan, snd, VOL_BASE, ATTN_NORM);
                W_PlayStrengthSound(ent);
        }
 
@@ -194,7 +197,7 @@ void W_SetupProjVelocity_Explicit(entity proj, vector dir, vector upDir, float p
 // ====================
 
 void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, float mindist, float maxdist, float halflifedist, float forcehalflifedist, int deathtype)
-{
+{SELFPARAM();
        vector hitloc, force, endpoint, dir;
        entity ent, endent;
        float endq3surfaceflags;
@@ -275,24 +278,25 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
        // Find all non-hit players the beam passed close by
        if(deathtype == WEP_VAPORIZER.m_id || deathtype == WEP_VORTEX.m_id)
        {
-               FOR_EACH_REALCLIENT(msg_entity)
-               if(msg_entity != self)
-               if(!msg_entity.railgunhit)
-               if(!(IS_SPEC(msg_entity) && msg_entity.enemy == self)) // we use realclient, so spectators can hear the whoosh too
-               {
-                       // nearest point on the beam
-                       beampos = start + dir * bound(0, (msg_entity.origin - start) * dir, length);
+               FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != self, LAMBDA(
+                       if(!it.railgunhit)
+                       if(!(IS_SPEC(it) && it.enemy == self))
+                       {
+                               msg_entity = it;
+                               // nearest point on the beam
+                               beampos = start + dir * bound(0, (msg_entity.origin - start) * dir, length);
 
-                       f = bound(0, 1 - vlen(beampos - msg_entity.origin) / 512, 1);
-                       if(f <= 0)
-                               continue;
+                               f = bound(0, 1 - vlen(beampos - msg_entity.origin) / 512, 1);
+                               if(f <= 0)
+                                       continue;
 
-                       snd = W_Sound(strcat("nexwhoosh", ftos(floor(random() * 3) + 1)));
+                               snd = SND(NEXWHOOSH_RANDOM());
 
-                       if(!pseudoprojectile)
-                               pseudoprojectile = spawn(); // we need this so the sound uses the "entchannel4" volume
-                       soundtoat(MSG_ONE, pseudoprojectile, beampos, CH_SHOTS, snd, VOL_BASE * f, ATTEN_NONE);
-               }
+                               if(!pseudoprojectile)
+                                       pseudoprojectile = spawn(); // we need this so the sound uses the "entchannel4" volume
+                               soundtoat(MSG_ONE, pseudoprojectile, beampos, CH_SHOTS, snd, VOL_BASE * f, ATTEN_NONE);
+                       }
+               ));
 
                if(pseudoprojectile)
                        remove(pseudoprojectile);
@@ -329,7 +333,7 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
        }
 
        // calculate hits and fired shots for hitscan
-       accuracy_add(self, self.weapon, 0, min(bdamage, totaldmg));
+       accuracy_add(self, PS(self).m_weapon.m_id, 0, min(bdamage, totaldmg));
 
        trace_endpos = endpoint;
        trace_ent = endent;
@@ -338,30 +342,29 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
 
 void fireBullet_trace_callback(vector start, vector hit, vector end)
 {
-       if(vlen(hit - start) > 16)
+       if(vdist(hit - start, >, 16))
                trailparticles(world, fireBullet_trace_callback_eff, start, hit);
        WarpZone_trace_forent = world;
        fireBullet_last_hit = world;
 }
 
 void fireBullet(vector start, vector dir, float spread, float max_solid_penetration, float damage, float force, float dtype, int tracereffects)
-{
+{SELFPARAM();
        vector  end;
 
        dir = normalize(dir + randomvec() * spread);
        end = start + dir * MAX_SHOT_DISTANCE;
 
-       entity pl;
        fireBullet_last_hit = world;
        float solid_penetration_left = 1;
        float total_damage = 0;
 
        if(tracereffects & EF_RED)
-               fireBullet_trace_callback_eff = particleeffectnum(EFFECT_RIFLE);
+               fireBullet_trace_callback_eff = EFFECT_RIFLE;
        else if(tracereffects & EF_BLUE)
-               fireBullet_trace_callback_eff = particleeffectnum(EFFECT_RIFLE_WEAK);
+               fireBullet_trace_callback_eff = EFFECT_RIFLE_WEAK;
        else
-               fireBullet_trace_callback_eff = particleeffectnum(EFFECT_BULLET);
+               fireBullet_trace_callback_eff = EFFECT_BULLET;
 
        float lag = ANTILAG_LATENCY(self);
        if(lag < 0.001)
@@ -372,11 +375,11 @@ void fireBullet(vector start, vector dir, float spread, float max_solid_penetrat
                lag = 0; // only do hitscan, but no antilag
        if(lag)
        {
-               FOR_EACH_PLAYER(pl)
-                       if(pl != self)
-                               antilag_takeback(pl, time - lag);
-               FOR_EACH_MONSTER(pl)
-                       antilag_takeback(pl, time - lag);
+               FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(antilag_takeback(it, time - lag)));
+               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+                       if(it != self)
+                               antilag_takeback(it, time - lag);
+               ));
        }
 
        WarpZone_trace_forent = self;
@@ -432,7 +435,7 @@ void fireBullet(vector start, vector dir, float spread, float max_solid_penetrat
                                // do not exceed 100%
                                float added_damage = min(damage - total_damage, damage * solid_penetration_left);
                                total_damage += damage * solid_penetration_left;
-                               accuracy_add(self, self.weapon, 0, added_damage);
+                               accuracy_add(self, PS(self).m_weapon.m_id, 0, added_damage);
                        }
                }
 
@@ -470,7 +473,7 @@ void fireBullet(vector start, vector dir, float spread, float max_solid_penetrat
 
                // Only show effect when going through a player (invisible otherwise)
                if (hit && (hit.solid != SOLID_BSP))
-                       if(vlen(trace_endpos - start) > 4)
+                       if(vdist(trace_endpos - start, >, 4))
                                trailparticles(self, fireBullet_trace_callback_eff, start, trace_endpos);
 
                start = trace_endpos;
@@ -481,10 +484,10 @@ void fireBullet(vector start, vector dir, float spread, float max_solid_penetrat
 
        if(lag)
        {
-               FOR_EACH_PLAYER(pl)
-                       if(pl != self)
-                               antilag_restore(pl);
-               FOR_EACH_MONSTER(pl)
-                       antilag_restore(pl);
+               FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(antilag_restore(it)));
+               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+                       if(it != self)
+                               antilag_restore(it);
+               ));
        }
 }