]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Refactor edgedamage calculation to be clearer and fix a bug where projectiles with...
authorterencehill <piuntn@gmail.com>
Fri, 18 Mar 2022 21:43:01 +0000 (22:43 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 18 Mar 2022 21:43:01 +0000 (22:43 +0100)
qcsrc/server/damage.qc

index ce2dd04b3ea139bcbf985b2b34229ab9c254571b..d0b3a288fb3011d5472d1d5df49a2d58ea217399 100644 (file)
@@ -881,6 +881,8 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in
                return 0;
        }
 
+       if (rad < 0) rad = 0;
+
        RadiusDamage_running = 1;
 
        tfloordmg = autocvar_g_throughfloor_damage;
@@ -912,32 +914,25 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in
                if (((cantbe != targ) && !mustbe) || (mustbe == targ))
                if (targ.takedamage)
                {
-                       vector nearest;
-                       vector diff;
-                       float power;
-
                        // measure distance from nearest point on target (not origin)
                        // to nearest point on inflictor (not origin)
-                       nearest = targ.WarpZone_findradius_nearest;
+                       vector nearest = targ.WarpZone_findradius_nearest;
                        vector inflictornearest = NearestPointOnBoundingBox(
                                inflictororigin - (inflictor.maxs - inflictor.mins) * 0.5,
                                inflictororigin + (inflictor.maxs - inflictor.mins) * 0.5,
                                nearest);
-                       diff = inflictornearest - nearest;
+                       vector diff = inflictornearest - nearest;
 
                        // round up a little on the damage to ensure full damage on impacts
                        // and turn the distance into a fraction of the radius
-                       power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
-                       //bprint(" ");
-                       //bprint(ftos(power));
-                       //if (targ == attacker)
-                       //      print(ftos(power), "\n");
-                       if (power > 0)
+                       float dist = max(0, vlen(diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS));
+                       if (dist <= rad)
                        {
-                               float finaldmg;
-                               if (power > 1)
-                                       power = 1;
-                               finaldmg = coredamage * power + edgedamage * (1 - power);
+                               float power = 1;
+                               if (rad > 0)
+                                       power -= (dist / rad);
+                               // at this point power can't be < 0 or > 1
+                               float finaldmg = coredamage * power + edgedamage * (1 - power);
                                if (finaldmg > 0)
                                {
                                        float a;