]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_common.qc
Merge branch 'master' into terencehill/ca_arena_freezetag_bugfixes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_common.qc
index 99df7041baf7196e83f4016123a2075ef6b30295..bbd9c647bcc8f578e6f5cd0a1e09652f281620ef 100644 (file)
@@ -6,7 +6,7 @@ void W_GiveWeapon (entity e, float wep, string name)
        if (!wep)
                return;
 
-       e.weapons = e.weapons | W_WeaponBit(wep);
+       WEPSET_OR_EW(e, wep);
 
        oldself = self;
        self = e;
@@ -23,11 +23,14 @@ void W_GiveWeapon (entity e, float wep, string name)
 }
 
 .float railgundistance;
+.vector railgunforce;
 void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, float mindist, float maxdist, float halflifedist, float forcehalflifedist, float deathtype)
 {
-       local vector hitloc, force, endpoint, dir;
-       local entity ent, endent;
-       local float endq3surfaceflags;
+       vector hitloc, force, endpoint, dir;
+       entity ent, endent;
+       float endq3surfaceflags;
+       float totaldmg;
+       entity o;
 
        float length;
        vector beampos;
@@ -35,7 +38,7 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
        entity pseudoprojectile;
        float f, ffs;
 
-       float hit;
+       pseudoprojectile = world;
 
        railgun_start = start;
        railgun_end = end;
@@ -47,15 +50,26 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
        // go a little bit into the wall because we need to hit this wall later
        end = end + dir;
 
+       totaldmg = 0;
+
        // trace multiple times until we hit a wall, each obstacle will be made
        // non-solid so we can hit the next, while doing this we spawn effects and
        // note down which entities were hit so we can damage them later
+       o = self;
        while (1)
        {
                if(self.antilag_debug)
-                       WarpZone_traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
+                       WarpZone_traceline_antilag (self, start, end, FALSE, o, self.antilag_debug);
                else
-                       WarpZone_traceline_antilag (self, start, end, FALSE, self, ANTILAG_LATENCY(self));
+                       WarpZone_traceline_antilag (self, start, end, FALSE, o, ANTILAG_LATENCY(self));
+               if(o && WarpZone_trace_firstzone)
+               {
+                       o = world;
+                       continue;
+               }
+
+               if(trace_ent.solid == SOLID_BSP || trace_ent.solid == SOLID_SLIDEBOX)
+                       Damage_DamageInfo(trace_endpos, bdamage, 0, 0, force, deathtype, trace_ent.species, self);
 
                // if it is world we can't hurt it so stop now
                if (trace_ent == world || trace_fraction == 1)
@@ -66,6 +80,7 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
                trace_ent.railgunhitloc = end;
                trace_ent.railgunhitsolidbackup = trace_ent.solid;
                trace_ent.railgundistance = vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - start);
+               trace_ent.railgunforce = WarpZone_TransformVelocity(WarpZone_trace_transform, force);
 
                // stop if this is a wall
                if (trace_ent.solid == SOLID_BSP)
@@ -107,7 +122,7 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
 
                        if(!pseudoprojectile)
                                pseudoprojectile = spawn(); // we need this so the sound uses the "entchannel4" volume
-                       soundtoat(MSG_ONE, pseudoprojectile, beampos, CHAN_PROJECTILE, snd, VOL_BASE * f, ATTN_NONE);
+                       soundtoat(MSG_ONE, pseudoprojectile, beampos, CH_SHOTS, snd, VOL_BASE * f, ATTN_NONE);
                }
 
                if(pseudoprojectile)
@@ -121,21 +136,15 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
                // get the details we need to call the damage function
                hitloc = ent.railgunhitloc;
 
-               //for stats so that team hit will count as a miss
-               if(ent.flags & FL_CLIENT)
-               if(ent.deadflag == DEAD_NO)
-                       hit = 1;
-
-               if(teams_matter)
-               if(ent.team == self.team)
-                       hit = 0;
-
                f = ExponentialFalloff(mindist, maxdist, halflifedist, ent.railgundistance);
                ffs = ExponentialFalloff(mindist, maxdist, forcehalflifedist, ent.railgundistance);
 
+               if(accuracy_isgooddamage(self.realowner, ent))
+                       totaldmg += bdamage * f;
+
                // apply the damage
                if (ent.takedamage)
-                       Damage (ent, self, self, bdamage * f, deathtype, hitloc, force * ffs);
+                       Damage (ent, self, self, bdamage * f, deathtype, hitloc, ent.railgunforce * ffs);
 
                // create a small explosion to throw gibs around (if applicable)
                //setorigin (explosion, hitloc);
@@ -151,16 +160,7 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
        }
 
        // calculate hits and fired shots for hitscan
-       if not(inWarmupStage)
-       {
-               self.stats_fired[self.weapon - 1] += 1;
-               self.stat_fired = self.weapon + 64 * floor(self.stats_fired[self.weapon - 1]);
-
-               if(hit) {
-                       self.stats_hit[self.weapon - 1] += 1;
-                       self.stat_hit = self.weapon + 64 * floor(self.stats_hit[self.weapon - 1]);
-               }
-       }
+       accuracy_add(self, self.weapon, 0, min(bdamage, totaldmg));
 
        trace_endpos = endpoint;
        trace_ent = endent;
@@ -170,14 +170,16 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
 .float dmg_edge;
 .float dmg_force;
 .float dmg_radius;
+.float dmg_total;
 void W_BallisticBullet_Hit (void)
 {
-       float f;
+       float f, q, g;
 
        f = pow(bound(0, vlen(self.velocity) / vlen(self.oldvelocity), 1), 2); // energy multiplier
+       q = 1 + self.dmg_edge / self.dmg;
 
-       if(other.solid == SOLID_BSP)
-               Damage_DamageInfo(self.origin, self.dmg * f, 0, 0, max(1, self.dmg_force) * normalize(self.velocity) * f, self.projectiledeathtype, self);
+       if(other.solid == SOLID_BSP || other.solid == SOLID_SLIDEBOX)
+               Damage_DamageInfo(self.origin, self.dmg * f, 0, 0, max(1, self.dmg_force) * normalize(self.velocity) * f, self.projectiledeathtype, other.species, self);
 
        if(other && other != self.enemy)
        {
@@ -185,29 +187,30 @@ void W_BallisticBullet_Hit (void)
 
                headshot = 0;
                yoda = 0;
-               damage_headshotbonus = self.dmg_edge;
+               damage_headshotbonus = self.dmg_edge * f;
                railgun_start = self.origin - 2 * frametime * self.velocity;
                railgun_end = self.origin + 2 * frametime * self.velocity;
-
-               Damage(other, self, self.owner, self.dmg * f, self.projectiledeathtype, self.origin, self.dmg_force * normalize(self.velocity) * f);
+               g = accuracy_isgooddamage(self.realowner, other);
+               Damage(other, self, self.realowner, self.dmg * f, self.projectiledeathtype, self.origin, self.dmg_force * normalize(self.velocity) * f);
                damage_headshotbonus = 0;
 
-               if(self.dmg_edge != 0)
+               if(headshot)
+                       f *= q;
+               if(self.dmg_edge > 0)
                {
                        if(headshot)
-                               AnnounceTo(self.owner, "headshot");
+                               AnnounceTo(self.realowner, "headshot");
                        if(yoda)
-                               AnnounceTo(self.owner, "awesome");
+                               AnnounceTo(self.realowner, "awesome");
                }
 
                // calculate hits for ballistic weapons
-               if (other.flags & FL_CLIENT)  // is the player a client
-               if (other.deadflag == DEAD_NO)  // is the victim a corpse
-               if ((!(teamplay)) | (other.team != self.owner.team))  // not teamplay (ctf, kh, tdm etc) or the victim is in the same team
-               if not(inWarmupStage)  // not in warm up stage
+               if(g)
                {
-                       self.owner.stats_hit[self.owner.weapon - 1] += 1;
-                       self.owner.stat_hit = self.owner.weapon + 64 * floor(self.owner.stats_hit[self.owner.weapon - 1]);
+                       // do not exceed 100%
+                       q = min(self.dmg * q, self.dmg_total + f * self.dmg) - self.dmg_total;
+                       self.dmg_total += f * self.dmg;
+                       accuracy_add(self.realowner, self.realowner.weapon, 0, q);
                }
        }
 
@@ -226,7 +229,7 @@ void W_BallisticBullet_LeaveSolid_think()
 
        self.think = self.W_BallisticBullet_LeaveSolid_think_save;
        self.nextthink = max(time, self.W_BallisticBullet_LeaveSolid_nextthink_save);
-       self.W_BallisticBullet_LeaveSolid_think_save = SUB_Null;
+       self.W_BallisticBullet_LeaveSolid_think_save = func_null;
 
        self.flags &~= FL_ONGROUND;
 
@@ -234,43 +237,70 @@ void W_BallisticBullet_LeaveSolid_think()
        {
                float f;
                f = pow(bound(0, vlen(self.velocity) / vlen(self.oldvelocity), 1), 2); // energy multiplier
-               Damage_DamageInfo(self.origin, 0, 0, 0, max(1, self.dmg_force) * normalize(self.velocity) * -f, self.projectiledeathtype, self);
+               Damage_DamageInfo(self.origin, 0, 0, 0, max(1, self.dmg_force) * normalize(self.velocity) * -f, self.projectiledeathtype, 0, self);
        }
 
        UpdateCSQCProjectile(self);
 }
 
-float W_BallisticBullet_LeaveSolid(entity e, vector vel, float constant)
+float W_BallisticBullet_LeaveSolid(float eff)
 {
        // move the entity along its velocity until it's out of solid, then let it resume
-
+       vector vel = self.velocity;
        float dt, dst, velfactor, v0, vs;
        float maxdist;
        float E0_m, Es_m;
+       float constant = self.dmg_radius * (other.ballistics_density ? other.ballistics_density : 1);
 
        // outside the world? forget it
        if(self.origin_x > world.maxs_x || self.origin_y > world.maxs_y || self.origin_z > world.maxs_z || self.origin_x < world.mins_x || self.origin_y < world.mins_y || self.origin_z < world.mins_z)
                return 0;
 
+       // special case for zero density and zero bullet constant: 
+
+       if(self.dmg_radius == 0)
+       {
+               if(other.ballistics_density < 0)
+                       constant = 0; // infinite travel distance
+               else
+                       return 0; // no penetration
+       }
+       else
+       {
+               if(other.ballistics_density < 0)
+                       constant = 0; // infinite travel distance
+               else if(other.ballistics_density == 0)
+                       constant = self.dmg_radius;
+               else
+                       constant = self.dmg_radius * other.ballistics_density;
+       }
+
        // E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
        v0 = vlen(vel);
 
        E0_m = 0.5 * v0 * v0;
-       maxdist = E0_m / constant;
-       // maxdist = 0.5 * v0 * v0 / constant
-       // dprint("max dist = ", ftos(maxdist), "\n");
 
-       if(maxdist <= cvar("g_ballistics_mindistance"))
-               return 0;
+       if(constant)
+       {
+               maxdist = E0_m / constant;
+               // maxdist = 0.5 * v0 * v0 / constant
+               // dprint("max dist = ", ftos(maxdist), "\n");
 
-       traceline_inverted (self.origin, self.origin + normalize(vel) * maxdist, MOVE_NORMAL, self);
+               if(maxdist <= autocvar_g_ballistics_mindistance)
+                       return 0;
+       }
+       else
+       {
+               maxdist = vlen(other.maxs - other.mins) + 1; // any distance, as long as we leave the entity
+       }
 
+       traceline_inverted (self.origin, self.origin + normalize(vel) * maxdist, MOVE_NORMAL, self, TRUE);
        if(trace_fraction == 1) // 1: we never got out of solid
                return 0;
 
        self.W_BallisticBullet_LeaveSolid_origin = trace_endpos;
 
-       dst = max(cvar("g_ballistics_mindistance"), vlen(trace_endpos - self.origin));
+       dst = max(autocvar_g_ballistics_mindistance, vlen(trace_endpos - self.origin));
        // E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
        Es_m = E0_m - constant * dst;
        if(Es_m <= 0)
@@ -297,12 +327,19 @@ float W_BallisticBullet_LeaveSolid(entity e, vector vel, float constant)
        self.flags |= FL_ONGROUND; // prevent moving
        self.W_BallisticBullet_LeaveSolid_velocity = vel;
 
+       if(eff >= 0)
+               if(vlen(trace_endpos - self.origin) > 4)
+               {
+                       endzcurveparticles();
+                       trailparticles(self, eff, self.origin, trace_endpos);
+               }
+
        return 1;
 }
 
 void W_BallisticBullet_Touch (void)
 {
-       float density;
+       //float density;
 
        if(self.think == W_BallisticBullet_LeaveSolid_think) // skip this!
                return;
@@ -310,12 +347,34 @@ void W_BallisticBullet_Touch (void)
        PROJECTILE_TOUCH;
        W_BallisticBullet_Hit ();
 
-       density = other.ballistics_density;
-       if(density == 0)
-               density = 1;
+       if(self.dmg_radius < 0) // these NEVER penetrate solid
+       {
+               remove(self);
+               return;
+       }
+
+       // if we hit "weapclip", bail out
+       //
+       // rationale of this check:
+       //
+       // any shader that is solid, nodraw AND trans is meant to clip weapon
+       // shots and players, but has no other effect!
+       //
+       // if it is not trans, it is caulk and should not have this side effect
+       //
+       // matching shaders:
+       //   common/weapclip (intended)
+       //   common/noimpact (is supposed to eat projectiles, but is erased farther above)
+       if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
+       if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID)
+       if not(trace_dphitcontents & DPCONTENTS_OPAQUE)
+       {
+               remove(self);
+               return;
+       }
 
        // go through solid!
-       if(!W_BallisticBullet_LeaveSolid(self, self.velocity, self.dmg_radius * density))
+       if(!W_BallisticBullet_LeaveSolid(-1))
        {
                remove(self);
                return;
@@ -335,17 +394,22 @@ void fireBallisticBullet_trace_callback(vector start, vector hit, vector end)
 {
        if(vlen(trace_endpos - fireBallisticBullet_trace_callback_ent.origin) > 16)
                zcurveparticles_from_tracetoss(fireBallisticBullet_trace_callback_eff, fireBallisticBullet_trace_callback_ent.origin, trace_endpos, fireBallisticBullet_trace_callback_ent.velocity);
+       WarpZone_trace_forent = world;
+       self.owner = world;
 }
 
 void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, float lifetime, float damage, float headshotbonus, float force, float dtype, float tracereffects, float gravityfactor, float bulletconstant)
 {
-       float lag, dt, savetime, density;
+       float lag, dt, savetime; //, density;
        entity pl, oldself;
+       float antilagging;
+
+       antilagging = (autocvar_g_antilag_bullets && (pSpeed >= autocvar_g_antilag_bullets));
 
        entity proj;
        proj = spawn();
        proj.classname = "bullet";
-       proj.owner = self;
+       proj.owner = proj.realowner = self;
        PROJECTILE_MAKETRIGGER(proj);
        if(gravityfactor > 0)
        {
@@ -356,9 +420,14 @@ void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, f
                proj.movetype = MOVETYPE_FLY;
        proj.think = SUB_Remove;
        proj.nextthink = time + lifetime; // min(pLifetime, vlen(world.maxs - world.mins) / pSpeed);
-       W_SetupProjectileVelocityEx(proj, dir, v_up, pSpeed, 0, 0, spread);
+       W_SetupProjectileVelocityEx(proj, dir, v_up, pSpeed, 0, 0, spread, antilagging);
        proj.angles = vectoangles(proj.velocity);
-       proj.dmg_radius = cvar("g_ballistics_materialconstant") / bulletconstant;
+       if(bulletconstant > 0)
+               proj.dmg_radius = autocvar_g_ballistics_materialconstant / bulletconstant;
+       else if(bulletconstant == 0)
+               proj.dmg_radius = 0;
+       else
+               proj.dmg_radius = -1;
        // so: bulletconstant = bullet mass / area of bullet circle
        setorigin(proj, start);
        proj.flags = FL_PROJECTILE;
@@ -371,13 +440,16 @@ void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, f
 
        proj.oldvelocity = proj.velocity;
 
-       if(cvar("g_antilag_bullets"))
-       if(pSpeed >= cvar("g_antilag_bullets"))
+       other = proj; MUTATOR_CALLHOOK(EditProjectile);
+
+       if(antilagging)
        {
                float eff;
 
                if(tracereffects & EF_RED)
                        eff = particleeffectnum("tr_rifle");
+               else if(tracereffects & EF_BLUE)
+                       eff = particleeffectnum("tr_rifle_weak");
                else
                        eff = particleeffectnum("tr_bullet");
 
@@ -387,12 +459,13 @@ void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, f
                        lag = 0;
                if(clienttype(self) != CLIENTTYPE_REAL)
                        lag = 0;
-               if(cvar("g_antilag") == 0 || self.cvar_cl_noantilag)
+               if(autocvar_g_antilag == 0 || self.cvar_cl_noantilag)
                        lag = 0; // only do hitscan, but no antilag
 
                if(lag)
                        FOR_EACH_PLAYER(pl)
-                               antilag_takeback(pl, time - lag);
+                               if(pl != self)
+                                       antilag_takeback(pl, time - lag);
 
                oldself = self;
                self = proj;
@@ -400,13 +473,6 @@ void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, f
                savetime = frametime;
                frametime = 0.05;
 
-               // update the accuracy stats - increase shots fired by 1
-               if not(inWarmupStage)
-               {
-                       oldself.stats_fired[oldself.weapon - 1] += 1;
-                       oldself.stat_fired = oldself.weapon + 64 * floor(oldself.stats_fired[oldself.weapon - 1]);
-               }
-
                for(;;)
                {
                        // DP tracetoss is stupid and always traces in 0.05s
@@ -421,7 +487,7 @@ void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, f
                        trace_fraction = 0;
                        fireBallisticBullet_trace_callback_ent = self;
                        fireBallisticBullet_trace_callback_eff = eff;
-                       WarpZone_TraceToss_ThroughZone(self, oldself, world, fireBallisticBullet_trace_callback);
+                       WarpZone_TraceToss_ThroughZone(self, self.owner, world, fireBallisticBullet_trace_callback);
                        self.velocity = v0;
                        self.gravity = g0;
 
@@ -445,35 +511,47 @@ void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, f
                                W_BallisticBullet_Hit();
                        }
 
-                       density = other.ballistics_density;
-                       if(density == 0)
-                               density = 1;
+                       if(proj.dmg_radius < 0) // these NEVER penetrate solid
+                               break;
+
+                       // if we hit "weapclip", bail out
+                       //
+                       // rationale of this check:
+                       //
+                       // any shader that is solid, nodraw AND trans is meant to clip weapon
+                       // shots and players, but has no other effect!
+                       //
+                       // if it is not trans, it is caulk and should not have this side effect
+                       //
+                       // matching shaders:
+                       //   common/weapclip (intended)
+                       //   common/noimpact (is supposed to eat projectiles, but is erased farther above)
+                       if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
+                       if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID)
+                       if not(trace_dphitcontents & DPCONTENTS_OPAQUE)
+                               break;
 
                        // go through solid!
-                       if(!W_BallisticBullet_LeaveSolid(self, self.velocity, self.dmg_radius * density))
+                       if(!W_BallisticBullet_LeaveSolid((other && (other.solid != SOLID_BSP)) ? eff : -1))
                                break;
 
                        W_BallisticBullet_LeaveSolid_think();
+
+                       self.projectiledeathtype |= HITTYPE_BOUNCE;
                }
                frametime = savetime;
                self = oldself;
 
                if(lag)
                        FOR_EACH_PLAYER(pl)
-                               antilag_restore(pl);
+                               if(pl != self)
+                                       antilag_restore(pl);
 
                remove(proj);
 
                return;
        }
 
-       // update the accuracy stats
-       if not(inWarmupStage)
-       {
-               self.stats_fired[self.weapon - 1] += 1;
-               self.stat_fired = self.weapon + 64 * floor(self.stats_fired[self.weapon - 1]);
-       }
-
        if(tracereffects & EF_RED)
                CSQCProjectile(proj, TRUE, PROJECTILE_BULLET_GLOWING_TRACER, TRUE);
        else if(tracereffects & EF_BLUE)
@@ -495,24 +573,69 @@ void fireBullet (vector start, vector dir, float spread, float damage, float for
 
        end = trace_endpos;
 
-       if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
+       if (pointcontents (trace_endpos) != CONTENT_SKY)
        {
-               pointparticles(particleeffectnum("TE_KNIGHTSPIKE"),end,trace_plane_normal * 2500,1);
-               if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
-                       Damage_DamageInfo(trace_endpos, damage, 0, 0, dir * max(1, force), dtype, self);
+               if not (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
+                       Damage_DamageInfo(trace_endpos, damage, 0, 0, dir * max(1, force), dtype, trace_ent.species, self);                    
+
                Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * force);
-               //void(float effectnum, vector org, vector vel, float howmany) pointparticles = #337; // same as in CSQC
        }
        trace_endpos = end;
 }
 
+float W_CheckProjectileDamage(entity inflictor, entity projowner, float deathtype, float exception)
+{
+       float is_from_contents = (deathtype == DEATH_SLIME || deathtype == DEATH_LAVA);
+       float is_from_owner = (inflictor == projowner);
+       float is_from_exception = (exception != -1);
+       
+       //dprint(strcat("W_CheckProjectileDamage: from_contents ", ftos(is_from_contents), " : from_owner ", ftos(is_from_owner), " : exception ", strcat(ftos(is_from_exception), " (", ftos(exception), "). \n")));
+
+       if(autocvar_g_projectiles_damage <= -2)
+       {
+               return FALSE; // no damage to projectiles at all, not even with the exceptions
+       }
+       else if(autocvar_g_projectiles_damage == -1)
+       {
+               if(is_from_exception)
+                       return (exception); // if exception is detected, allow it to override
+               else
+                       return FALSE; // otherwise, no other damage is allowed
+       }
+       else if(autocvar_g_projectiles_damage == 0)
+       {
+               if(is_from_exception)
+                       return (exception); // if exception is detected, allow it to override
+               else if not(is_from_contents)
+                       return FALSE; // otherwise, only allow damage from contents
+       }       
+       else if(autocvar_g_projectiles_damage == 1)
+       {
+               if(is_from_exception)
+                       return (exception); // if exception is detected, allow it to override
+               else if not(is_from_contents || is_from_owner)
+                       return FALSE; // otherwise, only allow self damage and damage from contents
+       }
+       else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions
+       {
+               if(is_from_exception)
+                       return (exception); // if exception is detected, allow it to override
+       }
+
+       return TRUE; // if none of these return, then allow damage anyway.
+}
+
 void W_PrepareExplosionByDamage(entity attacker, void() explode)
 {
        self.takedamage = DAMAGE_NO;
-       self.event_damage = SUB_Null;
-       self.owner = attacker;
-       self.realowner = attacker;
-
+       self.event_damage = func_null;
+       
+       if((attacker.flags & FL_CLIENT) && !autocvar_g_projectiles_keep_owner)
+       {
+               self.owner = attacker;
+               self.realowner = attacker;
+       }
+       
        // do not explode NOW but in the NEXT FRAME!
        // because recursive calls to RadiusDamage are not allowed
        self.nextthink = time;