]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/damage.qc
Merge remote branch 'origin/master' into tzork/csqc-items
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / damage.qc
index f7bdee24d5595a92b4437e3a8c24a080916bb2f9..fc8b83b5b6c8666a11efe0961ebe8af011cfcbfb 100644 (file)
@@ -9,7 +9,7 @@ void DamageEffect_Think()
        if(time >= self.cnt || !self.owner || !self.owner.modelindex || !self.owner.drawmask)
        {
                // time is up or the player got gibbed / disconnected
-               self.owner.total_damages -= 1;
+               self.owner.total_damages = max(0, self.owner.total_damages - 1);
                remove(self);
                return;
        }
@@ -17,12 +17,16 @@ void DamageEffect_Think()
        {
                // if the player was dead but is now alive, it means he respawned
                // if so, clear his damage effects, or damages from his dead body will be copied back
-               self.owner.total_damages -= 1;
+               self.owner.total_damages = max(0, self.owner.total_damages - 1);
                remove(self);
                return;
        }
        self.state = self.owner.csqcmodel_isdead;
+#ifdef COMPAT_XON050_ENGINE
        if(self.owner.isplayermodel && (self.owner.entnum == player_localentnum || self.owner.entnum == spectatee_status) && !autocvar_chase_active)
+#else
+       if(self.owner.isplayermodel && (self.owner.entnum == player_localentnum) && !autocvar_chase_active)
+#endif
                return; // if we aren't using a third person camera, hide our own effects
 
        // now generate the particles
@@ -36,7 +40,7 @@ void DamageEffect(vector hitorg, float dmg, float type, float specnum)
        // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
 
        float life, nearestbone;
-       string specstr, effectnum;
+       string specstr, effectname;
        entity e;
 
        if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
@@ -63,6 +67,7 @@ void DamageEffect(vector hitorg, float dmg, float type, float specnum)
        gettaginfo(self, nearestbone); // set gettaginfo_name
 
        // return if we reached our damage effect limit or damages are disabled
+       // TODO: When the limit is reached, it would be better if the oldest damage was removed instead of not adding a new one
        if(nearestbone)
        {
                if(self.total_damages >= autocvar_cl_damageeffect_bones)
@@ -79,7 +84,7 @@ void DamageEffect(vector hitorg, float dmg, float type, float specnum)
        type = DEATH_WEAPONOF(type);
        e = get_weaponinfo(type);
 
-       effectnum = strcat("damage_", e.netname);
+       effectname = strcat("damage_", e.netname);
        
        // if damage was dealt with a bullet weapon, our effect is blood
        // since blood is species dependent, include the species tag
@@ -87,8 +92,8 @@ void DamageEffect(vector hitorg, float dmg, float type, float specnum)
        {
                if(self.isplayermodel)
                {
-                       effectnum = strcat(effectnum, "_", specstr);
-                       effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species tag
+                       effectname = strcat(effectname, "_", specstr);
+                       effectname = substring(effectname, 0, strlen(effectname) - 1); // remove the _ symbol at the end of the species tag
                }
                else
                        return; // objects don't bleed
@@ -100,7 +105,7 @@ void DamageEffect(vector hitorg, float dmg, float type, float specnum)
        e.classname = "damage";
        e.owner = self;
        e.cnt = time + life;
-       e.team = particleeffectnum(effectnum);
+       e.team = particleeffectnum(effectname);
        e.think = DamageEffect_Think;
        e.nextthink = time;
        self.total_damages += 1;
@@ -108,7 +113,7 @@ void DamageEffect(vector hitorg, float dmg, float type, float specnum)
 
 void Ent_DamageInfo(float isNew)
 {
-       float dmg, rad, edge, thisdmg, forcemul, species;
+       float dmg, rad, edge, thisdmg, forcemul, species, hitplayer;
        vector force, thisforce;
        entity oldself;
 
@@ -141,6 +146,10 @@ void Ent_DamageInfo(float isNew)
        
        for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
        {
+               // attached ents suck
+               if(self.tag_entity)
+                       continue;
+
                vector nearest = NearestPointOnBox(self, w_org);
                if(rad)
                {
@@ -183,6 +192,9 @@ void Ent_DamageInfo(float isNew)
                        self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
 
                DamageEffect(w_org, thisdmg, w_deathtype, species);
+
+               if(self.isplayermodel)
+                       hitplayer = TRUE; // this impact damaged a player
        }
 
        self = oldself;
@@ -320,6 +332,7 @@ void Ent_DamageInfo(float isNew)
        
        // TODO spawn particle effects and sounds based on w_deathtype
        if(!DEATH_ISSPECIAL(w_deathtype))
+       if not(hitplayer && !rad) // don't show ground impacts for hitscan weapons if a player was hit
        {
                float hitwep;