]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/damage.qc
Merge branch 'master' into terencehill/tooltips_cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / damage.qc
index 39c422e1cca700cabe13953c50af3c7234bcbc40..4f25aef13ef2d25bd6c9a1cdf81637f8a104e60c 100644 (file)
@@ -2,13 +2,13 @@
 #include "_all.qh"
 
 #include "gibs.qh"
-#include "movetypes.qh"
-#include "prandom.qh"
 
-#include "vehicles/all.qh"
+#include "../common/vehicles/all.qh"
 
 #include "../common/constants.qh"
 #include "../common/deathtypes.qh"
+#include "../common/effects/effects.qh"
+#include "../common/movetypes/movetypes.qh"
 #include "../common/util.qh"
 
 #include "../common/weapons/all.qh"
@@ -20,7 +20,7 @@
 .bool isplayermodel;
 
 void DamageEffect_Think()
-{
+{SELFPARAM();
        // if particle distribution is enabled, slow ticrate by total number of damages
        if(autocvar_cl_damageeffect_distribute)
                self.nextthink = time + autocvar_cl_damageeffect_ticrate * self.owner.total_damages;
@@ -52,8 +52,8 @@ void DamageEffect_Think()
        pointparticles(self.team, org, '0 0 0', 1);
 }
 
-void DamageEffect(vector hitorg, float dmg, int type, int specnum)
-{
+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)
 
        int nearestbone = 0;
@@ -97,7 +97,7 @@ void DamageEffect(vector hitorg, float dmg, int type, int specnum)
                        return; // allow a single damage on non-skeletal models
        }
 
-       life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
+       life = bound(autocvar_cl_damageeffect_lifetime_min, thedamage * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
 
        effectname = get_weaponinfo(DEATH_WEAPONOF(type)).netname;
 
@@ -113,26 +113,23 @@ void DamageEffect(vector hitorg, float dmg, int type, int specnum)
        }
 
        e = spawn();
-       setmodel(e, "null"); // necessary to attach and read origin
+       setmodel(e, MDL_Null); // necessary to attach and read origin
        setattachment(e, self, gettaginfo_name); // attach to the given bone
        e.classname = "damage";
        e.owner = self;
        e.cnt = time + life;
-       e.team = particleeffectnum(effectname);
+       e.team = _particleeffectnum(effectname);
        e.think = DamageEffect_Think;
        e.nextthink = time;
        self.total_damages += 1;
 }
 
 void Ent_DamageInfo(float isNew)
-{
-       float dmg, rad, edge, thisdmg;
+{SELFPARAM();
+       float thedamage, rad, edge, thisdmg;
        bool hitplayer = false;
        int species, forcemul;
        vector force, thisforce;
-       entity oldself;
-
-       oldself = self;
 
        w_deathtype = ReadShort();
        w_issilent = (w_deathtype & 0x8000);
@@ -142,7 +139,7 @@ void Ent_DamageInfo(float isNew)
        w_org.y = ReadCoord();
        w_org.z = ReadCoord();
 
-       dmg = ReadByte();
+       thedamage = ReadByte();
        rad = ReadByte();
        edge = ReadByte();
        force = decompressShortVector(ReadShort());
@@ -159,8 +156,9 @@ void Ent_DamageInfo(float isNew)
        else
                forcemul = 1;
 
-       for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
+       for(entity e = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); e; e = e.chain)
        {
+               setself(e);
                // attached ents suck
                if(self.tag_entity)
                        continue;
@@ -173,10 +171,10 @@ void Ent_DamageInfo(float isNew)
                                continue;
                        if(thisdmg < 0)
                                thisdmg = 0;
-                       if(dmg)
+                       if(thedamage)
                        {
-                               thisdmg = dmg + (edge - dmg) * thisdmg;
-                               thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
+                               thisdmg = thedamage + (edge - thedamage) * thisdmg;
+                               thisforce = forcemul * vlen(force) * (thisdmg / thedamage) * normalize(self.origin - w_org);
                        }
                        else
                        {
@@ -189,7 +187,7 @@ void Ent_DamageInfo(float isNew)
                        if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
                                continue;
 
-                       thisdmg = dmg;
+                       thisdmg = thedamage;
                        thisforce = forcemul * force;
                }
 
@@ -211,8 +209,7 @@ void Ent_DamageInfo(float isNew)
                if(self.isplayermodel)
                        hitplayer = true; // this impact damaged a player
        }
-
-       self = oldself;
+       setself(this);
 
        if(DEATH_ISVEHICLE(w_deathtype))
        {
@@ -231,36 +228,34 @@ void Ent_DamageInfo(float isNew)
 
                        // spiderbot
                        case DEATH_VH_SPID_MINIGUN:
-                               string _snd;
-                               _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
-                               sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_SPIDERBOT_MINIGUN_IMPACT), self.origin, w_backoff * 1000, 1);
                                break;
                        case DEATH_VH_SPID_ROCKET:
-                               sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_SPIDERBOT_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
                                break;
                        case DEATH_VH_SPID_DEATH:
-                               sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
-                               pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_MIN);
+                               pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
                                break;
 
                        case DEATH_VH_WAKI_GUN:
-                               sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_RACER_IMPACT), self.origin, w_backoff * 1000, 1);
                                break;
                        case DEATH_VH_WAKI_ROCKET:
-                               sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_RACER_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
                                break;
                        case DEATH_VH_WAKI_DEATH:
-                               sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
-                               pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_MIN);
+                               pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
                                break;
 
                        case DEATH_VH_RAPT_CANNON:
-                               sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_RAPTOR_CANNON_IMPACT), self.origin, w_backoff * 1000, 1);
                                break;
                        case DEATH_VH_RAPT_FRAGMENT:
                                float i;
@@ -271,20 +266,20 @@ void Ent_DamageInfo(float isNew)
                                        ang = vectoangles(vel);
                                        RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
                                }
-                               sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_RAPTOR_BOMB_SPREAD), self.origin, w_backoff * 1000, 1);
                                break;
                        case DEATH_VH_RAPT_BOMB:
-                               sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_RAPTOR_BOMB_IMPACT), self.origin, w_backoff * 1000, 1);
                                break;
                        case DEATH_VH_RAPT_DEATH:
-                               sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_MIN);
-                               pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_MIN);
+                               pointparticles(particleeffectnum(EFFECT_EXPLOSION_BIG), self.origin, w_backoff * 1000, 1);
                                break;
                        case DEATH_VH_BUMB_GUN:
-                               sound(self, CH_SHOTS, "weapons/fireball_impact2.wav", VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("bigplasma_impact"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_BIGPLASMA_IMPACT), self.origin, w_backoff * 1000, 1);
                                break;
                }
        }
@@ -292,7 +287,6 @@ void Ent_DamageInfo(float isNew)
 
        if(DEATH_ISTURRET(w_deathtype))
        {
-               string _snd;
                traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
                if(trace_plane_normal != '0 0 0')
                        w_backoff = trace_plane_normal;
@@ -304,39 +298,37 @@ void Ent_DamageInfo(float isNew)
                switch(w_deathtype)
                {
                         case DEATH_TURRET_EWHEEL:
-                               sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_MIN);
-                               pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_MIN);
+                               pointparticles(particleeffectnum(EFFECT_BLASTER_IMPACT), self.origin, w_backoff * 1000, 1);
                                break;
 
                         case DEATH_TURRET_FLAC:
-                               pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
-                               _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
-                               sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_HAGAR_EXPLODE), w_org, '0 0 0', 1);
+                               sound(self, CH_SHOTS, SND_HAGEXP_RANDOM(), VOL_BASE, ATTEN_NORM);
                                break;
 
                         case DEATH_TURRET_MLRS:
                         case DEATH_TURRET_HK:
                         case DEATH_TURRET_WALK_ROCKET:
                         case DEATH_TURRET_HELLION:
-                               sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
-                               pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_MIN);
+                               pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), self.origin, w_backoff * 1000, 1);
                                break;
 
                         case DEATH_TURRET_MACHINEGUN:
                         case DEATH_TURRET_WALK_GUN:
-                               _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
-                               sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
-                               pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
+                               pointparticles(particleeffectnum(EFFECT_MACHINEGUN_IMPACT), self.origin, w_backoff * 1000, 1);
                                break;
 
                         case DEATH_TURRET_PLASMA:
-                               sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_MIN);
-                               pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
+                               sound(self, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_MIN);
+                               pointparticles(particleeffectnum(EFFECT_ELECTRO_IMPACT), self.origin, w_backoff * 1000, 1);
                                break;
 
-                        case DEATH_TURRET_WALK_MEELE:
-                               sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_MIN);
-                               pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
+                        case DEATH_TURRET_WALK_MELEE:
+                               sound(self, CH_SHOTS, SND_RIC1, VOL_BASE, ATTEN_MIN);
+                               pointparticles(particleeffectnum(EFFECT_TE_SPARK), self.origin, w_backoff * 1000, 1);
                                break;
 
                         case DEATH_TURRET_PHASER:
@@ -357,7 +349,7 @@ void Ent_DamageInfo(float isNew)
                w_random = prandom();
 
                traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
-               if(trace_fraction < 1 && hitwep != WEP_VORTEX && hitwep != WEP_VAPORIZER)
+               if(trace_fraction < 1 && hitwep != WEP_VORTEX.m_id && hitwep != WEP_VAPORIZER.m_id)
                        w_backoff = trace_plane_normal;
                else
                        w_backoff = -1 * normalize(force);