]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/damage.qc
Attempt to move the repeater of the damage effect client side, using entcs to get...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / damage.qc
index 9e90bee2240161c7293450712830d826fac63b53..fe2e8b67b0488a28d7f759bad87c435715ff7216 100644 (file)
@@ -1,22 +1,18 @@
-.float silent;
-
 void Ent_DamageInfo(float isNew)
 {
-       float hittype, dmg, rad, edge, thisdmg, forcemul;
-       float issilent;
-       vector force, org, thisforce;
+       float dmg, rad, edge, thisdmg, forcemul;
+       vector force, thisforce;
        entity oldself;
 
        oldself = self;
 
-       hittype = ReadShort();
-
-       issilent = (hittype & 0x8000);
-       hittype = (hittype & 0x7FFF);
+       w_deathtype = ReadShort();
+       w_issilent = (w_deathtype & 0x8000);
+       w_deathtype = (w_deathtype & 0x7FFF);
 
-       org_x = ReadCoord();
-       org_y = ReadCoord();
-       org_z = ReadCoord();
+       w_org_x = ReadCoord();
+       w_org_y = ReadCoord();
+       w_org_z = ReadCoord();
 
        dmg = ReadByte();
        rad = ReadByte();
@@ -34,22 +30,22 @@ void Ent_DamageInfo(float isNew)
        else
                forcemul = 1;
        
-       for(self = findradius(org, rad); self; self = self.chain)
+       for(self = findradius(w_org, rad); self; self = self.chain)
        {
                if(rad)
                {
-                       thisdmg = vlen(self.origin - org) / rad;
+                       thisdmg = vlen(self.origin - w_org) / rad;
                        if(thisdmg >= 1)
                                continue;
                        if(dmg)
                        {
                                thisdmg = dmg + (edge - dmg) * thisdmg;
-                               thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - org);
+                               thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
                        }
                        else
                        {
                                thisdmg = 0;
-                               thisforce = forcemul * vlen(force) * normalize(self.origin - org);
+                               thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
                        }
                }
                else
@@ -58,287 +54,269 @@ void Ent_DamageInfo(float isNew)
                        thisforce = forcemul * force;
                }
 
-               //print("check ", ftos(num_for_edict(self)), " ", self.classname, "\n");
-               //print(ftos(self.damageforcescale), "\n");
-               //print(vtos(thisforce), "\n");
                if(self.damageforcescale)
                        if(vlen(thisforce))
                        {
-                               self.move_velocity = self.move_velocity + self.damageforcescale * thisforce;
+                               self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
                                self.move_flags &~= FL_ONGROUND;
-                               //print("pushed ", ftos(num_for_edict(self)), " loose\n");
                        }
 
-               if(issilent)
+               if(w_issilent)
                        self.silent = 1;
 
                if(self.event_damage)
-                       self.event_damage(thisdmg, hittype, org, thisforce);
+                       self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
        }
 
        self = oldself;
+       
+       if(DEATH_ISVEHICLE(w_deathtype))
+       {
+           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;
+        else
+            w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
+           
+           setorigin(self, w_org + w_backoff * 2); // for sound() calls
+           
+           switch(w_deathtype)
+           {            
+            case DEATH_VHCRUSH:
+                break;
+                
+            case DEATH_SBMINIGUN:
+                string _snd;
+                _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
+                sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
+                pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
+                break;
+            case DEATH_SBROCKET:
+                sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
+                pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
+                break;
+            case DEATH_SBBLOWUP:
+                sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
+                pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
+                break;
+                
+            case DEATH_WAKIGUN:
+                sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
+                pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
+                break;
+            case DEATH_WAKIROCKET:
+                sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
+                pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
+                break;
+            case DEATH_WAKIBLOWUP:
+                sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
+                pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
+                break;
+                
+            case DEATH_RAPTOR_CANNON:
+                sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
+                pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
+                break;
+            case DEATH_RAPTOR_BOMB_SPLIT:
+                float i;
+                vector ang, vel;
+                for(i = 1; i < 4; ++i)
+                {
+                    vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
+                    ang = vectoangles(vel);
+                    RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
+                }
+                    
+                
+                sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
+                pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
+                break;
+            case DEATH_RAPTOR_BOMB:
+                sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
+                pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
+                break;
+            case DEATH_RAPTOR_DEATH:
+                sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
+                pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
+                break;
+           }
+       }
+       
+       
+       if(DEATH_ISTURRET(w_deathtype))
+       {           
+           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;
+        else
+            w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
+           
+           setorigin(self, w_org + w_backoff * 2); // for sound() calls
+           
+           switch(w_deathtype)
+           {   
+             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);
+                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);
+                
+                break;
+                
+             case DEATH_TURRET_MLRS:
+             case DEATH_TURRET_HK:
+             case DEATH_TURRET_WALKER_ROCKET:
+             case DEATH_TURRET_HELLION:
+                sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
+                pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
+                break;
+             
+             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);
+                break;
+                          
+             case DEATH_TURRET_PLASMA:
+                sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
+                pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
+                break;
+                          
+             case DEATH_TURRET_WALKER_MEELE:
+                sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
+                pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
+                break;
+
+             case DEATH_TURRET_PHASER:
+                break;
+                
+             case DEATH_TURRET_TESLA:
+                te_smallflash(self.origin);
+                break;
 
-       // TODO spawn particle effects and sounds based on hittype
+        }        
+       }
        
-       if(!DEATH_ISSPECIAL(hittype))
+       // TODO spawn particle effects and sounds based on w_deathtype
+       if(!DEATH_ISSPECIAL(w_deathtype))
        {
-               float hitwep, secondary, bounce, headshot;
-               vector org2, backoff;
-               float r;
+               float hitwep;
 
-               hitwep = DEATH_WEAPONOFWEAPONDEATH(hittype);
-               secondary = hittype & HITTYPE_SECONDARY;
-               bounce = hittype & HITTYPE_BOUNCE;
-               headshot = hittype & HITTYPE_HEADSHOT;
-               r = prandom();
+               hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
+               w_random = prandom();
 
-               traceline(org - normalize(force) * 16, org + normalize(force) * 16, MOVE_NOMONSTERS, world);
+               traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
                if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
-                       backoff = trace_plane_normal;
+                       w_backoff = trace_plane_normal;
                else
-                       backoff = -1 * normalize(force);
+                       w_backoff = -1 * normalize(force);
+               setorigin(self, w_org + w_backoff * 2); // for sound() calls
+
+               (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
+       }
+}
+
+void DamageInfo_Precache()
+{
+       float i;
+       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+               (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
+}
+
+.entity dmgeffect;
+.string dmgparticles;
 
-               setorigin(self, org + backoff * 2); // for sound() calls
+void Ent_DamageEffect_Think()
+{
+       self.nextthink = time;
+
+       entity entcs;
+       entcs = entcs_receiver[self.team];
+       if(!entcs)
+               return;
 
-               switch(hitwep)
+       // 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)
+       {
+               entity head;
+               for(head = world; (head = find(head, classname, "gib")); )
                {
-                       case WEP_LASER:
-                               org2 = org + backoff * 6;
-                               pointparticles(particleeffectnum("laser_impact"), org2, backoff * 1000, 1);
-                               if(!issilent)
-                                       sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
-                               break;
-                       case WEP_SHOTGUN:
-                               org2 = org + backoff * 2;
-                               pointparticles(particleeffectnum("shotgun_impact"), org2, backoff * 1000, 1);
-                               if(!issilent)
-                               {
-                                       if(r < 0.05)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
-                                       else if(r < 0.1)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
-                                       else if(r < 0.2)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
-                               }
-                               break;
-                       case WEP_UZI:
-                               org2 = org + backoff * 2;
-                               pointparticles(particleeffectnum("machinegun_impact"), org2, backoff * 1000, 1);
-                               if(!issilent)
-                                       if(r < 0.05)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
-                                       else if(r < 0.1)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
-                                       else if(r < 0.2)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
-                               break;
-                       case WEP_GRENADE_LAUNCHER:
-                               org2 = org + backoff * 12;
-                               pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
-                               if(!issilent)
-                                       sound(self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
-                               break;
-                       case WEP_ELECTRO:
-                               org2 = org + backoff * 6;
-                               if(secondary)
-                               {
-                                       pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
-                                       if(!issilent)
-                                               sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
-                               }
-                               else
-                               {
-                                       if(bounce)
-                                       {
-                                               // this is sent as "primary bounce" to distinguish it from secondary bounced balls
-                                               pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
-                                               if(!issilent)
-                                                       sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
-                                       }
-                                       else
-                                       {
-                                               pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
-                                               if(!issilent)
-                                                       sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
-                                       }
-                               }
-                               break;
-                       case WEP_CRYLINK:
-                               org2 = org + backoff * 2;
-                               if(secondary)
-                               {
-                                       pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
-                                       if(!issilent)
-                                               sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
-                               }
-                               else
-                               {
-                                       pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
-                                       if(!issilent)
-                                               sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
-                               }
-                               break;
-                       case WEP_NEX:
-                               org2 = org + backoff * 6;
-                               pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
-                               if(!issilent)
-                                       sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
-                               break;
-                       case WEP_HAGAR:
-                               org2 = org + backoff * 6;
-                               pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
-                               if(!issilent)
-                               {
-                                       if (r<0.15)
-                                               sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
-                                       else if (r<0.7)
-                                               sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
-                                       else
-                                               sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
-                               }
-                               break;
-                       case WEP_ROCKET_LAUNCHER:
-                               org2 = org + backoff * 12;
-                               pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
-                               if(!issilent)
-                                       sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
-                               break;
-                       case WEP_PORTO:
-                               print("Since when does Porto send DamageInfo?\n");
-                               break;
-                       case WEP_MINSTANEX:
-                               org2 = org + backoff * 6;
-                               pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
-                               if(!issilent)
-                                       sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
-                               break;
-                       case WEP_HOOK:
-                               org2 = org + backoff * 2;
-                               pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
-                               if(!issilent)
-                                       sound(self, CHAN_PROJECTILE, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
-                               break;
-                       case WEP_SEEKER:
-                               org2 = org + backoff * 6;
-                               if(secondary)
-                               {
-                                       pointparticles(particleeffectnum("flac_explode"), org2, '0 0 0', 1);
-                                       if(!issilent)
-                                       {
-                                               if (r<0.15)
-                                                       sound(self, CHAN_PROJECTILE, "weapons/flacexp1.wav", 1, ATTN_NORM);
-                                               else if (r<0.7)
-                                                       sound(self, CHAN_PROJECTILE, "weapons/flacexp2.wav", 1, ATTN_NORM);
-                                               else
-                                                       sound(self, CHAN_PROJECTILE, "weapons/flacexp3.wav", 1, ATTN_NORM);
-                                       }
-                               }
-                               else
-                               {
-                                       if(bounce)
-                                       {
-                                               pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
-                                               if(!issilent)
-                                               {
-                                                       if (r<0.15)
-                                                               sound(self, CHAN_PROJECTILE, "weapons/tagexp1.wav", 1, ATTN_NORM);
-                                                       else if (r<0.7)
-                                                               sound(self, CHAN_PROJECTILE, "weapons/tagexp2.wav", 1, ATTN_NORM);
-                                                       else
-                                                               sound(self, CHAN_PROJECTILE, "weapons/tagexp3.wav", 1, ATTN_NORM);
-                                               }
-                                       }
-                                       else if(headshot)
-                                       {
-                                               if(!issilent)
-                                                       sound(self, CHAN_PROJECTILE, "weapons/tag_impact.wav", 1, ATTN_NORM);
-                                       }
-                                       else
-                                       {
-                                               pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
-                                               if(!issilent)
-                                               {
-                                                       if (r<0.15)
-                                                               sound(self, CHAN_PROJECTILE, "weapons/seekerexp1.wav", 1, ATTN_NORM);
-                                                       else if (r<0.7)
-                                                               sound(self, CHAN_PROJECTILE, "weapons/seekerexp2.wav", 1, ATTN_NORM);
-                                                       else
-                                                               sound(self, CHAN_PROJECTILE, "weapons/seekerexp3.wav", 1, ATTN_NORM);
-                                               }
-                                       }
-                               }
-                               break;
-                       case WEP_HLAC:
-                               org2 = org + backoff * 6;
-                               pointparticles(particleeffectnum("laser_impact"), org2, backoff * 1000, 1);
-                               if(!issilent)
-                                       sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
-                               break;
-                       case WEP_CAMPINGRIFLE:
-                               org2 = org + backoff * 2;
-                               pointparticles(particleeffectnum("machinegun_impact"), org2, backoff * 1000, 1);
-                               if(!issilent)
-                               {
-                                       if(r < 0.2)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
-                                       else if(r < 0.4)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
-                                       else if(r < 0.5)
-                                               sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
-                               }
-                               break;
-                       case WEP_TUBA:
-                               break;
-                       case WEP_FIREBALL:
-                               if(secondary)
-                               {
-                                       // firemine goes out silently
-                               }
-                               else
-                               {
-                                       org2 = org + backoff * 16;
-                                       pointparticles(particleeffectnum("fireball_explode"), org2, '0 0 0', 1);
-                                       if(!issilent)
-                                               sound(self, CHAN_PROJECTILE, "weapons/fireball_impact2.wav", VOL_BASE, ATTN_NORM * 0.25); // long range boom
-                               }
-                               break;
-                       default:
-                               dprint("Unhandled damage of weapon ", ftos(hitwep), "\n");
-                               break;
+                       if(head.team == self.team)
+                       if(random() < autocvar_cl_damageeffect_gibs)
+                               pointparticles(particleeffectnum(self.dmgparticles), head.origin, '0 0 0', 1);
                }
        }
+
+       // if we aren't in third person mode, hide our own damage effect
+       if(self.team == player_localentnum)
+       if(!autocvar_chase_active)
+               return;
+
+       // Now apply the effect to the actual player.
+       if(random() < autocvar_cl_damageeffect)
+               pointparticles(particleeffectnum(self.dmgparticles), entcs.origin, '0 0 0', 1);
 }
 
-void DamageInfo_Precache()
+void Ent_DamageEffect()
 {
-       precache_sound("weapons/crylink_impact2.wav");
-       precache_sound("weapons/crylink_impact.wav");
-       precache_sound("weapons/electro_impact.wav");
-       precache_sound("weapons/electro_impact_combo.wav");
-       precache_sound("weapons/flacexp1.wav");
-       precache_sound("weapons/flacexp2.wav");
-       precache_sound("weapons/flacexp3.wav");
-       precache_sound("weapons/grenade_impact.wav");
-       precache_sound("weapons/hagexp1.wav");
-       precache_sound("weapons/hagexp2.wav");
-       precache_sound("weapons/hagexp3.wav");
-       precache_sound("weapons/flacexp1.wav");
-       precache_sound("weapons/flacexp2.wav");
-       precache_sound("weapons/flacexp3.wav");
-       precache_sound("weapons/hookbomb_impact.wav");
-       precache_sound("weapons/laserimpact.wav");
-       precache_sound("weapons/neximpact.wav");
-       precache_sound("weapons/ric1.wav");
-       precache_sound("weapons/ric2.wav");
-       precache_sound("weapons/ric3.wav");
-       precache_sound("weapons/rocket_impact.wav");
-       precache_sound("weapons/fireball_impact.wav");
-       precache_sound("weapons/fireball_impact2.wav");
-       precache_sound("weapons/seekerexp1.wav");
-       precache_sound("weapons/seekerexp2.wav");
-       precache_sound("weapons/seekerexp3.wav");
-       precache_sound("weapons/tagexp1.wav");
-       precache_sound("weapons/tagexp2.wav");
-       precache_sound("weapons/tagexp3.wav");
-       precache_sound("weapons/tag_impact.wav");
+       float dmg, type, specnum1, specnum2, entnumber;
+       vector org;
+       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)
+               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);
+
+       e = get_weaponinfo(type);
+       effectnum = strcat("weapondamage_", e.netname);
+       // If the weapon is a bullet weapon, its damage effect is blood.
+       // Since blood is species dependent, we make this effect per-species.
+       if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
+       if(specstr != "")
+       {
+               effectnum = strcat(effectnum, "_", specstr);
+               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
+       entity head;
+       for(head = world; (head = find(head, classname, "dmgeffect")); )
+       {
+               if(head.team == entnumber)
+               {
+                       remove(head);
+                       head = world;
+               }
+       }
+
+       entity e;
+       e = spawn();
+       e.classname = "dmgeffect";
+       e.team = entnumber;
+       e.dmgparticles = effectnum;
+       e.think = Ent_DamageEffect_Think;
+       e.nextthink = time;
 }