]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/damage.qc
Send ent_DamageInfo for hitscan damage too. Why wasn't this done in the first place...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / damage.qc
index 03eb15f6ca871bc349039fc31f60896c6c881a2d..662c8fddb9ee7076a2609eb905aa6cfcf01bd458 100644 (file)
@@ -1,6 +1,7 @@
+void DamageEffect(float dmg, float type, float specnum1, float entnumber);
 void Ent_DamageInfo(float isNew)
 {
-       float dmg, rad, edge, thisdmg, forcemul;
+       float dmg, rad, edge, thisdmg, forcemul, species;
        vector force, thisforce;
        entity oldself;
 
@@ -18,6 +19,7 @@ void Ent_DamageInfo(float isNew)
        rad = ReadByte();
        edge = ReadByte();
        force = decompressShortVector(ReadShort());
+       species = ReadByte();
 
        if not(isNew)
                return;
@@ -67,6 +69,7 @@ void Ent_DamageInfo(float isNew)
                if(self.event_damage)
                        self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
        }
+       DamageEffect(dmg, w_deathtype, species, self.entnum);
 
        self = oldself;
        
@@ -145,6 +148,7 @@ 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;
@@ -157,20 +161,13 @@ void Ent_DamageInfo(float isNew)
            {   
              case DEATH_TURRET_EWHEEL:
                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
-                pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
+                pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
                 break;
              
              case DEATH_TURRET_FLAC:
-                vector org2;
-                org2 = w_org + w_backoff * 6;
-                pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
-                if (w_random<0.15)
-                    sound(self, CH_SHOTS, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
-                else if (w_random<0.7)
-                    sound(self, CH_SHOTS, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
-                else
-                    sound(self, CH_SHOTS, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
-                
+                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, ATTN_NORM);                
                 break;
                 
              case DEATH_TURRET_MLRS:
@@ -183,7 +180,6 @@ void Ent_DamageInfo(float isNew)
              
              case DEATH_TURRET_MACHINEGUN:
              case DEATH_TURRET_WALKER_GUN:
-                string _snd;
                 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
                 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
                 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
@@ -235,57 +231,72 @@ void DamageInfo_Precache()
                (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
 }
 
-.entity dmgeffect;
-.float partnum;
+// damage effect
+
+.entity dmgent;
+.float dmgpartnum, dmgtime;
+.float lifetime;
 
-void Ent_DamageEffect_Think()
+void DamageEffect_Think()
 {
        self.nextthink = time;
 
-       entity entcs;
-       entcs = entcs_receiver[self.team];
-       if(!entcs)
+       float foundgib;
+       vector org;
+
+       if(time >= self.lifetime)
+       {
+               remove(self);
+               self = world;
+               return;
+       }
+       if(self.dmgtime > time)
+               return;
+       org = getplayerorigin(self.team);
+       if(org == GETPLAYERORIGIN_ERROR)
                return;
 
-       // Scan the owner of all gibs in the world. If a gib owner is the same as the player we're applying the
-       // effect to, it means our player is gibbed. Therefore, apply the particles to the gibs as well.
-       if(autocvar_cl_damageeffect_gibs)
+       // Scan the owner of all gibs in the world. If a gib owner is the same as the player we're applying
+       // the effect to, it means our player is gibbed. Therefore, apply particles to the gibs instead.
+       entity head;
+       for(head = world; (head = find(head, classname, "gib")); )
        {
-               entity head;
-               for(head = world; (head = find(head, classname, "gib")); )
+               if(head.team == self.team)
                {
-                       if(head.team == self.team)
-                               pointparticles(self.partnum, head.origin, '0 0 0', 1);
+                       if(autocvar_cl_damageeffect_gibs)
+                       {
+                               if(autocvar_cl_damageeffect_gibs_randomize >= random())
+                                       pointparticles(self.dmgpartnum, head.origin, '0 0 0', 1);
+                               self.dmgtime = time + autocvar_cl_damageeffect_gibs;
+                       }
+                       foundgib = TRUE;
                }
        }
 
-       // if we aren't in third person mode, hide our own damage effect
+       if(foundgib || !autocvar_cl_damageeffect_player)
+               return; // don't show effects on the invisible dead body if gibs exist
        if(self.team == player_localentnum - 1 && !autocvar_chase_active)
-               return;
+               return; // if we aren't in third person mode, hide own damage effect
 
-       // Now apply the effect to the actual player.
-       pointparticles(self.partnum, entcs.origin, '0 0 0', 1);
+       // Now apply the effect to actual players
+       pointparticles(self.dmgpartnum, org, '0 0 0', 1);
+       self.dmgtime = time + autocvar_cl_damageeffect_player;
 }
 
-void Ent_DamageEffect()
+void DamageEffect(float dmg, float type, float specnum1, float entnumber)
 {
-       float dmg, type, specnum1, specnum2, entnumber;
-       vector org;
+       float specnum2, life;
        string specstr, effectnum;
        entity e;
 
-       dmg = ReadByte(); // damage amount
-       type = ReadByte(); // damage weapon
-       specnum1 = ReadByte(); // player species
-       entnumber = ReadByte(); // player entnum
-
-       if not(autocvar_cl_damageeffect)
+       if(!autocvar_cl_damageeffect_player && !autocvar_cl_damageeffect_gibs)
                return;
        if(autocvar_cl_gentle || autocvar_cl_gentle_damage)
                return;
 
        specnum2 = (specnum1 & 0x78) / 8; // blood type: using four bits (0..7, bit indexes 3,4,5)
        specstr = species_prefix(specnum2);
+       life = bound(0, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
 
        e = get_weaponinfo(type);
        effectnum = strcat("weapondamage_", e.netname);
@@ -298,22 +309,24 @@ void Ent_DamageEffect()
                effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species name
        }
 
-       // if the player already has a damage effect, replace it with the new one
+       // if the player already has a damage effect, update it instead of spawning a new one
        entity head;
-       for(head = world; (head = find(head, classname, "dmgeffect")); )
+       for(head = world; (head = find(head, classname, "damageeffect")); )
        {
                if(head.team == entnumber - 1)
                {
-                       remove(head);
-                       head = world;
+                       head.dmgpartnum = particleeffectnum(effectnum);
+                       head.lifetime += life;
+                       return;
                }
        }
 
        entity e;
        e = spawn();
-       e.classname = "dmgeffect";
+       e.classname = "damageeffect";
        e.team = entnumber - 1;
-       e.partnum = particleeffectnum(effectnum);
-       e.think = Ent_DamageEffect_Think;
+       e.dmgpartnum = particleeffectnum(effectnum);
+       e.lifetime = time + life;
+       e.think = DamageEffect_Think;
        e.nextthink = time;
 }