]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/effects/qc/damageeffects.qc
Use gender-neutral pronouns when referring to the player
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / damageeffects.qc
index c85d66eeb6686cee70d27d77482757baf0336550..1d8b6c53c57052976304ca25589232004bc1d63b 100644 (file)
@@ -6,20 +6,19 @@ REGISTER_NET_LINKED(ENT_CLIENT_DAMAGEINFO)
 
 bool Damage_DamageInfo_SendEntity(entity this, entity to, int sf)
 {
+       vector org = vec3(floor(this.origin.x), floor(this.origin.y), floor(this.origin.z));
        WriteHeader(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
        WriteShort(MSG_ENTITY, this.projectiledeathtype);
-       WriteCoord(MSG_ENTITY, floor(this.origin.x));
-       WriteCoord(MSG_ENTITY, floor(this.origin.y));
-       WriteCoord(MSG_ENTITY, floor(this.origin.z));
+       WriteVector(MSG_ENTITY, org);
        WriteByte(MSG_ENTITY, bound(1, this.dmg, 255));
        WriteByte(MSG_ENTITY, bound(0, this.dmg_radius, 255));
        WriteByte(MSG_ENTITY, bound(1, this.dmg_edge, 255));
-       WriteShort(MSG_ENTITY, this.oldorigin.x);
+       WriteVector(MSG_ENTITY, this.velocity);
        WriteByte(MSG_ENTITY, this.species);
        return true;
 }
 
-void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner)
+void Damage_DamageInfo(vector org, bool is_solid_hit, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner)
 {
        // 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?
@@ -29,16 +28,19 @@ void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad
        if(!sound_allowed(MSG_BROADCAST, dmgowner))
                deathtype |= 0x8000;
 
-       e = new(damageinfo);
-       setorigin(e, org);
+       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;
        e.dmg_radius = rad;
        e.dmg_force = vlen(force);
        e.velocity = force;
-       e.oldorigin_x = compressShortVector(e.velocity);
        e.species = bloodtype;
+       if(is_solid_hit)
+               e.species |= 0x80;
 
        Net_LinkEntity(e, false, 0.2, Damage_DamageInfo_SendEntity);
 }
@@ -54,7 +56,8 @@ void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad
 
 .float cnt;
 .int state;
-.bool isplayermodel;
+
+.bool silent;
 
 void DamageEffect_Think(entity this)
 {
@@ -73,19 +76,18 @@ void DamageEffect_Think(entity this)
        }
        if(this.state && !this.owner.csqcmodel_isdead)
        {
-               // if the player was dead but is now alive, it means he respawned
-               // if so, clear his damage effects, or damages from his dead body will be copied back
+               // if the player was dead but is now alive, it means they respawned
+               // if so, clear their damage effects, or damages from their dead body will be copied back
                this.owner.total_damages = max(0, this.owner.total_damages - 1);
                delete(this);
                return;
        }
        this.state = this.owner.csqcmodel_isdead;
-       if(this.owner.isplayermodel && (this.owner.entnum == player_localentnum) && !autocvar_chase_active)
+       if((this.owner.isplayermodel & ISPLAYER_LOCAL) && !autocvar_chase_active)
                return; // if we aren't using a third person camera, hide our own effects
 
        // now generate the particles
-       vector org;
-       org = gettaginfo(this, 0); // origin at attached location
+       vector org = gettaginfo(this, 0); // origin at attached location
        __pointparticles(this.team, org, '0 0 0', 1);
 }
 
@@ -110,8 +112,8 @@ void DamageEffect(entity this, vector hitorg, float thedamage, int type, int spe
 
        int nearestbone = 0;
        float life;
-       string specstr, effectname;
-       entity e;
+       string effectname;
+       entity e, wep;
 
        if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
                return;
@@ -151,15 +153,15 @@ void DamageEffect(entity this, vector hitorg, float thedamage, int type, int spe
 
        life = bound(autocvar_cl_damageeffect_lifetime_min, thedamage * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
 
-       effectname = DEATH_WEAPONOF(type).netname;
-
-       if(substring(effectname, strlen(effectname) - 5, 5) == "BLOOD")
+       wep = DEATH_WEAPONOF(type);
+       effectname = strcat("damage_", wep.netname);
+       if((wep.spawnflags & WEP_FLAG_BLEED))
        {
-               if(this.isplayermodel)
+               // if this weapon induces bleeding, use the effect name with the proper species prefix (blood type)
+               if((this.isplayermodel & ISPLAYER_MODEL))
                {
-                       specstr = species_prefix(specnum);
-                       specstr = substring(specstr, 0, strlen(specstr) - 1);
-                       effectname = strreplace("BLOOD", specstr, effectname);
+                       string specstr = species_prefix(specnum);
+                       effectname = strcat(specstr, effectname);
                }
                else { return; } // objects don't bleed
        }
@@ -177,7 +179,6 @@ void DamageEffect(entity this, vector hitorg, float thedamage, int type, int spe
 
 NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
 {
-       const float ATTEN_LOW = 0.2;
        float thedamage, rad, edge, thisdmg;
        bool hitplayer = false;
        int species, forcemul;
@@ -187,15 +188,15 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
        w_issilent = (w_deathtype & 0x8000);
        w_deathtype = (w_deathtype & 0x7FFF);
 
-       w_org.x = ReadCoord();
-       w_org.y = ReadCoord();
-       w_org.z = ReadCoord();
+       w_org = ReadVector();
 
        thedamage = ReadByte();
        rad = ReadByte();
        edge = ReadByte();
-       force = decompressShortVector(ReadShort());
+       force = ReadVector();
        species = ReadByte();
+       bool is_solid_hit = (species & 0x80);
+       species = (species & 0x7F);
 
        return = true;
 
@@ -210,11 +211,11 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
        else
                forcemul = 1;
 
-    FOREACH_ENTITY_RADIUS(w_org, rad + MAX_DAMAGEEXTRARADIUS, !it.tag_entity, {
+       FOREACH_ENTITY_RADIUS(w_org, rad + MAX_DAMAGEEXTRARADIUS, !it.tag_entity, {
                vector nearest = NearestPointOnBox(it, w_org);
                if (rad)
                {
-                       thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, it.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
+                       thisdmg = ((vlen(nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, it.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
                        if(thisdmg >= 1)
                                continue;
                        if(thisdmg < 0)
@@ -254,17 +255,18 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
 
                DamageEffect(it, w_org, thisdmg, w_deathtype, species);
 
-               if(it.isplayermodel)
+               if((it.isplayermodel & ISPLAYER_MODEL))
                        hitplayer = true; // this impact damaged a player
        });
 
        if(DEATH_ISVEHICLE(w_deathtype))
        {
-               traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, NULL);
+               vector force_dir = normalize(force);
+               traceline(w_org - force_dir * 16, w_org + force_dir * 16, MOVE_NOMONSTERS, NULL);
                if(trace_plane_normal != '0 0 0')
                        w_backoff = trace_plane_normal;
                else
-                       w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
+                       w_backoff = -1 * normalize(w_org - (w_org + force_dir * 16));
 
                setorigin(this, w_org + w_backoff * 2); // for sound() calls
 
@@ -309,7 +311,7 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
                                vector ang, vel;
                                for(i = 1; i < 4; ++i)
                                {
-                                       vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
+                                       vel = normalize(w_org - (w_org + force_dir * 16)) + randomvec() * 128;
                                        ang = vectoangles(vel);
                                        RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
                                }
@@ -334,57 +336,57 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
 
        if(DEATH_ISTURRET(w_deathtype))
        {
-               traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, NULL);
+               vector force_dir = normalize(force);
+               traceline(w_org - force_dir * 16, w_org + force_dir * 16, MOVE_NOMONSTERS, NULL);
                if(trace_plane_normal != '0 0 0')
                        w_backoff = trace_plane_normal;
                else
-                       w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
+                       w_backoff = -1 * normalize(w_org - (w_org + force_dir * 16));
 
                setorigin(this, w_org + w_backoff * 2); // for sound() calls
 
                switch(DEATH_ENT(w_deathtype))
                {
-                        case DEATH_TURRET_EWHEEL:
+                       case DEATH_TURRET_EWHEEL:
                                sound(this, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTEN_LOW);
                                pointparticles(EFFECT_BLASTER_IMPACT, this.origin, w_backoff * 1000, 1);
                                break;
 
-                        case DEATH_TURRET_FLAC:
+                       case DEATH_TURRET_FLAC:
                                pointparticles(EFFECT_HAGAR_EXPLODE, w_org, '0 0 0', 1);
                                sound(this, CH_SHOTS, SND_HAGEXP_RANDOM(), VOL_BASE, ATTEN_NORM);
                                break;
 
-                        case DEATH_TURRET_MLRS:
-                        case DEATH_TURRET_HK:
-                        case DEATH_TURRET_WALK_ROCKET:
-                        case DEATH_TURRET_HELLION:
+                       case DEATH_TURRET_MLRS:
+                       case DEATH_TURRET_HK:
+                       case DEATH_TURRET_WALK_ROCKET:
+                       case DEATH_TURRET_HELLION:
                                sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_LOW);
                                pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, w_backoff * 1000, 1);
                                break;
 
-                        case DEATH_TURRET_MACHINEGUN:
-                        case DEATH_TURRET_WALK_GUN:
+                       case DEATH_TURRET_MACHINEGUN:
+                       case DEATH_TURRET_WALK_GUN:
                                sound(this, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
                                pointparticles(EFFECT_MACHINEGUN_IMPACT, this.origin, w_backoff * 1000, 1);
                                break;
 
-                        case DEATH_TURRET_PLASMA:
+                       case DEATH_TURRET_PLASMA:
                                sound(this, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_LOW);
                                pointparticles(EFFECT_ELECTRO_IMPACT, this.origin, w_backoff * 1000, 1);
                                break;
 
-                        case DEATH_TURRET_WALK_MELEE:
+                       case DEATH_TURRET_WALK_MELEE:
                                sound(this, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_LOW);
                                pointparticles(EFFECT_TE_SPARK, this.origin, w_backoff * 1000, 1);
                                break;
 
-                        case DEATH_TURRET_PHASER:
+                       case DEATH_TURRET_PHASER:
                                break;
 
-                        case DEATH_TURRET_TESLA:
+                       case DEATH_TURRET_TESLA:
                                te_smallflash(this.origin);
                                break;
-
                }
        }
 
@@ -397,11 +399,17 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
                Weapon hitwep = DEATH_WEAPONOF(w_deathtype);
                w_random = prandom();
 
-               traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, NULL);
-               if(trace_fraction < 1 && hitwep != WEP_VORTEX && hitwep != WEP_VAPORIZER)
-                       w_backoff = trace_plane_normal;
+               vector force_dir = normalize(force);
+               if (is_solid_hit) // traceline not needed
+                       w_backoff = -force_dir;
                else
-                       w_backoff = -1 * normalize(force);
+               {
+                       traceline(w_org - force_dir * 16, w_org + force_dir * 16, MOVE_NOMONSTERS, NULL);
+                       if(trace_fraction < 1 && !(hitwep.spawnflags & WEP_TYPE_HITSCAN))
+                               w_backoff = trace_plane_normal;
+                       else
+                               w_backoff = -force_dir;
+               }
                setorigin(this, w_org + w_backoff * 2); // for sound() calls
 
                if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))