]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Properly network negative radius in the damage effects code, it fixes a bug where...
authorterencehill <piuntn@gmail.com>
Thu, 4 May 2023 15:02:09 +0000 (17:02 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 4 May 2023 15:02:46 +0000 (17:02 +0200)
qcsrc/common/effects/qc/damageeffects.qc

index d716672b28063a6cff0ca1443b22196ad15de9d6..dbc8e637ef88207670ce5b8ecf14d3be8244d284 100644 (file)
@@ -28,22 +28,30 @@ void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad
        // TODO maybe call this from non-edgedamage too?
        // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
 
-       entity e;
-
        if(!sound_allowed(MSG_BROADCAST, dmgowner))
                deathtype |= 0x8000;
 
-       e = new_pure(damageinfo);
+       entity e = new_pure(damageinfo);
        // origin is just data to be sent
        //setorigin(e, org);
        e.origin = org;
        e.projectiledeathtype = deathtype;
        e.dmg = coredamage;
        e.dmg_edge = edgedamage;
+       bool rad_negative = false;
+       if(rad < 0)
+       {
+               // make it positive (unsigned) so it can be sent as byte
+               rad_negative = true;
+               rad = -rad;
+       }
        e.dmg_radius = rad;
        e.dmg_force = vlen(force);
        e.velocity = force;
-       e.species = bloodtype;
+
+       e.species = bloodtype & BITS(4); // it only uses bits from 0 to 3, see SPECIES_* constants
+       if(rad_negative)
+               e.species |= BIT(7);
 
        Net_LinkEntity(e, false, 0.2, Damage_DamageInfo_SendEntity);
 }
@@ -201,19 +209,15 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
        force.z = ReadShort() * 4 + 2;
 
        species = ReadByte();
+       bool rad_negative = (species & BIT(7));
+       species = (species & BITS(4));
 
        return = true;
 
        if (!isNew)
                return;
 
-       if(rad < 0)
-       {
-               rad = -rad;
-               forcemul = -1;
-       }
-       else
-               forcemul = 1;
+       forcemul = (rad_negative ? -1 : 1);
 
        FOREACH_ENTITY_RADIUS(w_org, rad + MAX_DAMAGEEXTRARADIUS, !it.tag_entity, {
                vector nearest = NearestPointOnBox(it, w_org);