]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_common.qc
cvar cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_common.qc
index 3780fc71384d987160f8e56c3063166fdbcc1bb3..fa119c7b7527ea340fe9aa5d0d5abe5af196ce92 100644 (file)
@@ -1,23 +1,18 @@
 
-void W_GiveWeapon (entity e, float wep, string name)
+void W_GiveWeapon (entity e, float wep)
 {
        entity oldself;
 
        if (!wep)
                return;
 
-       WEPSET_OR_EW(e, wep);
+       e.weapons |= WepSet_FromWeapon(wep);
 
        oldself = self;
        self = e;
 
-       if not(g_minstagib)
-       if (other.classname == "player")
-       {
-               sprint (other, "You got the ^2");
-               sprint (other, name);
-               sprint (other, "\n");
-       }
+       if(IS_PLAYER(other))
+               { Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_WEAPON_GOT, wep); }
 
        self = oldself;
 }
@@ -40,9 +35,6 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
 
        pseudoprojectile = world;
 
-       railgun_start = start;
-       railgun_end = end;
-
        dir = normalize(end - start);
        length = vlen(end - start);
        force = dir * bforce;
@@ -109,7 +101,10 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
        // Find all non-hit players the beam passed close by
        if(deathtype == WEP_MINSTANEX || deathtype == WEP_NEX)
        {
-               FOR_EACH_REALCLIENT(msg_entity) if(msg_entity != self) if(!msg_entity.railgunhit) if not(msg_entity.classname == "spectator" && msg_entity.enemy == self) // we use realclient, so spectators can hear the whoosh too
+               FOR_EACH_REALCLIENT(msg_entity)
+               if(msg_entity != self)
+               if(!msg_entity.railgunhit)
+               if(!(IS_SPEC(msg_entity) && msg_entity.enemy == self)) // we use realclient, so spectators can hear the whoosh too
                {
                        // nearest point on the beam
                        beampos = start + dir * bound(0, (msg_entity.origin - start) * dir, length);
@@ -122,7 +117,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, CH_SHOTS, snd, VOL_BASE * f, ATTN_NONE);
+                       soundtoat(MSG_ONE, pseudoprojectile, beampos, CH_SHOTS, snd, VOL_BASE * f, ATTEN_NONE);
                }
 
                if(pseudoprojectile)
@@ -167,420 +162,151 @@ void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, f
        trace_dphitq3surfaceflags = endq3surfaceflags;
 }
 
-.float dmg_edge;
-.float dmg_force;
-.float dmg_radius;
-.float dmg_total;
-void W_BallisticBullet_Hit (void)
-{
-       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 || 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)
-       {
-               endzcurveparticles();
-
-               headshot = 0;
-               yoda = 0;
-               damage_headshotbonus = self.dmg_edge * f;
-               railgun_start = self.origin - 2 * frametime * self.velocity;
-               railgun_end = self.origin + 2 * frametime * self.velocity;
-               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(headshot)
-                       f *= q;
-               if(self.dmg_edge > 0)
-               {
-                       if(headshot)
-                               AnnounceTo(self.realowner, "headshot");
-                       if(yoda)
-                               AnnounceTo(self.realowner, "awesome");
-               }
-
-               // calculate hits for ballistic weapons
-               if(g)
-               {
-                       // 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);
-               }
-       }
-
-       self.enemy = other; // don't hit the same player twice with the same bullet
-}
-
-.void(void) W_BallisticBullet_LeaveSolid_think_save;
-.float W_BallisticBullet_LeaveSolid_nextthink_save;
-.vector W_BallisticBullet_LeaveSolid_origin;
-.vector W_BallisticBullet_LeaveSolid_velocity;
-
-void W_BallisticBullet_LeaveSolid_think()
+float fireBullet_trace_callback_eff;
+void fireBullet_trace_callback(vector start, vector hit, vector end)
 {
-       setorigin(self, self.W_BallisticBullet_LeaveSolid_origin);
-       self.velocity = self.W_BallisticBullet_LeaveSolid_velocity;
-
-       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.flags &~= FL_ONGROUND;
-
-       if(self.enemy.solid == SOLID_BSP)
-       {
-               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, 0, self);
-       }
-
-       UpdateCSQCProjectile(self);
+       if(vlen(hit - start) > 16)
+               trailparticles(world, fireBullet_trace_callback_eff, start, hit);
+       WarpZone_trace_forent = world;
 }
 
-float W_BallisticBullet_LeaveSolid(float eff)
+void fireBullet(vector start, vector dir, float spread, float max_solid_penetration, float damage, float force, float dtype, float tracereffects)
 {
-       // 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);
+       // TODO antilag takeback
+       vector  end;
 
-       E0_m = 0.5 * v0 * v0;
+       dir = normalize(dir + randomvec() * spread);
+       end = start + dir * MAX_SHOT_DISTANCE;
 
-       if(constant)
-       {
-               maxdist = E0_m / constant;
-               // maxdist = 0.5 * v0 * v0 / constant
-               // dprint("max dist = ", ftos(maxdist), "\n");
+       entity pl;
+       entity last_hit = world;
+       float solid_penetration_left = 1;
+       float total_damage = 0;
 
-               if(maxdist <= autocvar_g_ballistics_mindistance)
-                       return 0;
-       }
+       if(tracereffects & EF_RED)
+               fireBullet_trace_callback_eff = particleeffectnum("tr_rifle");
+       else if(tracereffects & EF_BLUE)
+               fireBullet_trace_callback_eff = particleeffectnum("tr_rifle_weak");
        else
+               fireBullet_trace_callback_eff = particleeffectnum("tr_bullet");
+
+       float lag = ANTILAG_LATENCY(self);
+       if(lag < 0.001)
+               lag = 0;
+       if (!IS_REAL_CLIENT(self))
+               lag = 0;
+       if(autocvar_g_antilag == 0 || self.cvar_cl_noantilag)
+               lag = 0; // only do hitscan, but no antilag
+       if(lag)
+               FOR_EACH_PLAYER(pl)
+                       if(pl != self)
+                               antilag_takeback(pl, time - lag);
+
+       for (;;)
        {
-               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(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)
-       {
-               // roundoff errors got us
-               return 0;
-       }
-       vs = sqrt(2 * Es_m);
-       velfactor = vs / v0;
-
-       dt = dst / (0.5 * (v0 + vs));
-       // this is not correct, but the differential equations have no analytic
-       // solution - and these times are very small anyway
-       //print("dt = ", ftos(dt), "\n");
-
-       self.W_BallisticBullet_LeaveSolid_think_save = self.think;
-       self.W_BallisticBullet_LeaveSolid_nextthink_save = self.nextthink;
-       self.think = W_BallisticBullet_LeaveSolid_think;
-       self.nextthink = time + dt;
-
-       vel = vel * velfactor;
+               // TODO also show effect while tracing
+               WarpZone_TraceBox_ThroughZone(start, '0 0 0', '0 0 0', end, FALSE, self, world, fireBullet_trace_callback);
+               dir = WarpZone_TransformVelocity(WarpZone_trace_transform, dir);
+               end = WarpZone_TransformOrigin(WarpZone_trace_transform, end);
+               start = trace_endpos;
+               entity hit = trace_ent;
+
+               // When hitting sky, stop.
+               if (pointcontents(start) == CONTENT_SKY)
+                       break;
 
-       self.velocity = '0 0 0';
-       self.flags |= FL_ONGROUND; // prevent moving
-       self.W_BallisticBullet_LeaveSolid_velocity = vel;
+               if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
+                       break;
 
-       if(eff >= 0)
-               if(vlen(trace_endpos - self.origin) > 4)
+               // 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 anyway)
+               float is_weapclip = 0;
+               if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
+               if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
+               if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
+                       is_weapclip = 1;
+
+               // Avoid self-damage // FIXME can this happen?
+               if (hit != self)
                {
-                       endzcurveparticles();
-                       trailparticles(self, eff, self.origin, trace_endpos);
-               }
+                       if(hit.solid == SOLID_BSP || hit.solid == SOLID_SLIDEBOX)
+                               Damage_DamageInfo(self.origin, damage * solid_penetration_left, 0, 0, max(1, force) * dir * solid_penetration_left, dtype, hit.species, self);
 
-       return 1;
-}
-
-void W_BallisticBullet_Touch (void)
-{
-       //float density;
-
-       if(self.think == W_BallisticBullet_LeaveSolid_think) // skip this!
-               return;
-
-       PROJECTILE_TOUCH;
-       W_BallisticBullet_Hit ();
-
-       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(-1))
-       {
-               remove(self);
-               return;
-       }
-
-       self.projectiledeathtype |= HITTYPE_BOUNCE;
-}
-
-void endFireBallisticBullet()
-{
-       endzcurveparticles();
-}
-
-entity fireBallisticBullet_trace_callback_ent;
-float fireBallisticBullet_trace_callback_eff;
-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;
-       entity pl, oldself;
-       float antilagging;
-
-       antilagging = (autocvar_g_antilag_bullets && (pSpeed >= autocvar_g_antilag_bullets));
-
-       entity proj;
-       proj = spawn();
-       proj.classname = "bullet";
-       proj.owner = proj.realowner = self;
-       PROJECTILE_MAKETRIGGER(proj);
-       if(gravityfactor > 0)
-       {
-               proj.movetype = MOVETYPE_TOSS;
-               proj.gravity = gravityfactor;
-       }
-       else
-               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, antilagging);
-       proj.angles = vectoangles(proj.velocity);
-       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;
-
-       proj.touch = W_BallisticBullet_Touch;
-       proj.dmg = damage;
-       proj.dmg_edge = headshotbonus;
-       proj.dmg_force = force;
-       proj.projectiledeathtype = dtype;
-
-       proj.oldvelocity = proj.velocity;
-
-       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");
-
-               // NOTE: this may severely throw off weapon balance
-               lag = ANTILAG_LATENCY(self);
-               if(lag < 0.001)
-                       lag = 0;
-               if(clienttype(self) != CLIENTTYPE_REAL)
-                       lag = 0;
-               if(autocvar_g_antilag == 0 || self.cvar_cl_noantilag)
-                       lag = 0; // only do hitscan, but no antilag
-
-               if(lag)
-                       FOR_EACH_PLAYER(pl)
-                               if(pl != self)
-                                       antilag_takeback(pl, time - lag);
-
-               oldself = self;
-               self = proj;
-
-               savetime = frametime;
-               frametime = 0.05;
-
-               for(;;)
-               {
-                       // DP tracetoss is stupid and always traces in 0.05s
-                       // ticks. This makes it trace in 0.05*0.125s ticks
-                       // instead.
-                       vector v0;
-                       float g0;
-                       v0 = self.velocity;
-                       g0 = self.gravity;
-                       self.velocity = self.velocity * 0.125;
-                       self.gravity *= 0.125 * 0.125;
-                       trace_fraction = 0;
-                       fireBallisticBullet_trace_callback_ent = self;
-                       fireBallisticBullet_trace_callback_eff = eff;
-                       WarpZone_TraceToss_ThroughZone(self, self.owner, world, fireBallisticBullet_trace_callback);
-                       self.velocity = v0;
-                       self.gravity = g0;
-
-                       if(trace_fraction == 1)
-                               break;
-                               // won't hit anything anytime soon (DP's
-                               // tracetoss does 200 tics of, here,
-                               // 0.05*0.125s, that is, 1.25 seconds
-
-                       other = trace_ent;
-                       dt = WarpZone_tracetoss_time * 0.125; // this is only approximate!
-                       setorigin(self, trace_endpos);
-                       self.velocity = WarpZone_tracetoss_velocity * (1 / 0.125);
-
-                       if(!SUB_OwnerCheck())
+                       if(hit && hit != last_hit)
                        {
-                               if(SUB_NoImpactCheck())
-                                       break;
-
-                               // hit the player
-                               W_BallisticBullet_Hit();
+                               yoda = 0;
+                               float g = accuracy_isgooddamage(self, hit);
+                               // FIXME preserve trace stuff
+                               Damage(hit, self, self, damage * solid_penetration_left, dtype, self.origin, force * dir * solid_penetration_left);
+                               // calculate hits for ballistic weapons
+                               if(g)
+                               {
+                                       // do not exceed 100%
+                                       float added_damage = min(damage - total_damage, damage * solid_penetration_left);
+                                       total_damage += damage * solid_penetration_left;
+                                       accuracy_add(self, self.weapon, 0, added_damage);
+                               }
                        }
 
-                       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((other && (other.solid != SOLID_BSP)) ? eff : -1))
-                               break;
-
-                       W_BallisticBullet_LeaveSolid_think();
-
-                       self.projectiledeathtype |= HITTYPE_BOUNCE;
+                       last_hit = hit; // don't hit the same player twice with the same bullet
                }
-               frametime = savetime;
-               self = oldself;
 
-               if(lag)
-                       FOR_EACH_PLAYER(pl)
-                               if(pl != self)
-                                       antilag_restore(pl);
+               if (is_weapclip)
+                       break;
 
-               remove(proj);
+               // go through solid!
+               // outside the world? forget it
+               if(end_x > world.maxs_x || end_y > world.maxs_y || end_z > world.maxs_z || end_x < world.mins_x || end_y < world.mins_y || end_z < world.mins_z)
+                       break;
 
-               return;
-       }
+               float maxdist;
+               if(max_solid_penetration < 0)
+                       break;
+               else if(hit.ballistics_density < -1)
+                       break; // -2: no solid penetration, ever
+               else if(hit.ballistics_density < 0)
+                       maxdist = vlen(hit.maxs - hit.mins) + 1; // -1: infinite travel distance
+               else if(hit.ballistics_density == 0)
+                       maxdist = max_solid_penetration * solid_penetration_left;
+               else
+                       maxdist = max_solid_penetration * solid_penetration_left * hit.ballistics_density;
 
-       if(tracereffects & EF_RED)
-               CSQCProjectile(proj, TRUE, PROJECTILE_BULLET_GLOWING_TRACER, TRUE);
-       else if(tracereffects & EF_BLUE)
-               CSQCProjectile(proj, TRUE, PROJECTILE_BULLET_GLOWING, TRUE);
-       else
-               CSQCProjectile(proj, TRUE, PROJECTILE_BULLET, TRUE);
-}
+               if(maxdist <= autocvar_g_ballistics_mindistance)
+                       break;
 
-void fireBullet (vector start, vector dir, float spread, float damage, float force, float dtype, float tracer)
-{
-       vector  end;
+               // move the entity along its velocity until it's out of solid, then let it resume
+               traceline_inverted (start, self.origin + dir * maxdist, MOVE_NORMAL, self, TRUE);
+               if(trace_fraction == 1) // 1: we never got out of solid
+                       break;
 
-       dir = normalize(dir + randomvec() * spread);
-       end = start + dir * MAX_SHOT_DISTANCE;
-       if(self.antilag_debug)
-               traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
-       else
-               traceline_antilag (self, start, end, FALSE, self, ANTILAG_LATENCY(self));
+               float dist_taken = max(autocvar_g_ballistics_mindistance, vlen(trace_endpos - start));
+               solid_penetration_left *= (dist_taken / maxdist);
 
-       end = trace_endpos;
+               // Only show effect when going through a player (invisible otherwise)
+               if (hit && (hit.solid != SOLID_BSP))
+                       if(vlen(trace_endpos - start) > 4)
+                               trailparticles(self, fireBullet_trace_callback_eff, start, trace_endpos);
 
-       if (pointcontents (trace_endpos) != CONTENT_SKY)
-       {
-               if not (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
-                       Damage_DamageInfo(trace_endpos, damage, 0, 0, dir * max(1, force), dtype, trace_ent.species, self);                    
+               start = trace_endpos;
 
-               Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * force);
+               if(hit.solid == SOLID_BSP)
+                       Damage_DamageInfo(start, 0, 0, 0, max(1, force) * normalize(dir) * -solid_penetration_left, dtype, 0, self);
        }
-       trace_endpos = end;
+
+       if(lag)
+               FOR_EACH_PLAYER(pl)
+                       if(pl != self)
+                               antilag_restore(pl);
 }
 
 float W_CheckProjectileDamage(entity inflictor, entity projowner, float deathtype, float exception)
@@ -588,7 +314,7 @@ float W_CheckProjectileDamage(entity inflictor, entity projowner, float deathtyp
        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)
@@ -606,14 +332,14 @@ float W_CheckProjectileDamage(entity inflictor, entity projowner, float deathtyp
        {
                if(is_from_exception)
                        return (exception); // if exception is detected, allow it to override
-               else if not(is_from_contents)
+               else if (!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)
+               else if (!(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
@@ -628,14 +354,14 @@ float W_CheckProjectileDamage(entity inflictor, entity projowner, float deathtyp
 void W_PrepareExplosionByDamage(entity attacker, void() explode)
 {
        self.takedamage = DAMAGE_NO;
-       self.event_damage = SUB_Null;
-       
-       if((attacker.flags & FL_CLIENT) && !autocvar_g_projectiles_keep_owner)
+       self.event_damage = func_null;
+
+       if(IS_CLIENT(attacker) && !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;