]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/overkill/okrpc.qc
Show the particle effect of the muzzle flash at the gun's actual muzzle position...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / okrpc.qc
index c06ca5b78cf3923816cf9950b4afb53172eb3967..db2803cee70e3d4975bfd372d426061fea0515ba 100644 (file)
@@ -2,12 +2,20 @@
 
 #ifdef SVQC
 
+.float m_chainsaw_damage; // accumulated damage of the missile as it passes trough enemies
+
 void W_OverkillRocketPropelledChainsaw_Explode(entity this, entity directhitentity)
 {
        this.event_damage = func_null;
        this.takedamage = DAMAGE_NO;
 
-       RadiusDamage(this, this.realowner, WEP_CVAR_PRI(okrpc, damage), WEP_CVAR_PRI(okrpc, edgedamage), WEP_CVAR_PRI(okrpc, radius), NULL, NULL, WEP_CVAR_PRI(okrpc, force), this.projectiledeathtype, this.weaponentity_fld, directhitentity);
+       float explosion_damage = RadiusDamage(this, this.realowner, WEP_CVAR_PRI(okrpc, damage), WEP_CVAR_PRI(okrpc, edgedamage), WEP_CVAR_PRI(okrpc, radius), NULL, NULL, WEP_CVAR_PRI(okrpc, force), this.projectiledeathtype, this.weaponentity_fld, directhitentity);
+       if (explosion_damage > 0 && this.m_chainsaw_damage > 0)
+       {
+               // if chainsaw hit something, it removed fired damage (so that direct hit is 100%)
+               // now that we also damaged something by explosion we'd go over 100% so let's add the fired damage back
+               accuracy_add(this.realowner, DEATH_WEAPONOF(this.projectiledeathtype), WEP_CVAR(okrpc, damage), 0);
+       }
 
        delete(this);
 }
@@ -28,15 +36,15 @@ void W_OverkillRocketPropelledChainsaw_Touch (entity this, entity toucher)
 
 void W_OverkillRocketPropelledChainsaw_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
 {
-       if (this.health <= 0)
+       if (GetResource(this, RES_HEALTH) <= 0)
                return;
 
        if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
                return; // g_projectiles_damage says to halt
 
-       this.health = this.health - damage;
+       TakeResource(this, RES_HEALTH, damage);
 
-       if (this.health <= 0)
+       if (GetResource(this, RES_HEALTH) <= 0)
                W_PrepareExplosionByDamage(this, attacker, W_OverkillRocketPropelledChainsaw_Explode_think);
 }
 
@@ -53,8 +61,22 @@ void W_OverkillRocketPropelledChainsaw_Think(entity this)
        vector mydir = normalize(this.velocity);
 
        tracebox(this.origin, this.mins, this.maxs, this.origin + mydir * (2 * myspeed_accel), MOVE_NORMAL, this);
-       if(IS_PLAYER(trace_ent))
+       if (IS_PLAYER(trace_ent))
+       {
+               if (accuracy_isgooddamage(this.realowner, trace_ent))
+               {
+                       if (this.m_chainsaw_damage == 0) // first hit
+                       {
+                               // The fired damage of the explosion is already counted in the statistics (when launching the chainsaw).
+                               // We remove it here so that a direct hit that passes through and doesn't damage anything by the explosion later is still 100%.
+                               float fired_damage = WEP_CVAR_PRI(okrpc, damage2) - WEP_CVAR_PRI(okrpc, damage);
+                               float hit_damage = WEP_CVAR_PRI(okrpc, damage2);
+                               accuracy_add(this.realowner, DEATH_WEAPONOF(this.projectiledeathtype), fired_damage, hit_damage);
+                       }
+                       this.m_chainsaw_damage += WEP_CVAR_PRI(okrpc, damage2);
+               }
                Damage(trace_ent, this, this.realowner, WEP_CVAR_PRI(okrpc, damage2), this.projectiledeathtype, this.weaponentity_fld, this.origin, normalize(this.origin - trace_ent.origin) * WEP_CVAR_PRI(okrpc, force));
+       }
 
        this.velocity = mydir * (myspeed + (WEP_CVAR_PRI(okrpc, speedaccel) * sys_frametime));
 
@@ -62,14 +84,14 @@ void W_OverkillRocketPropelledChainsaw_Think(entity this)
        this.nextthink = time;
 }
 
-void W_OverkillRocketPropelledChainsaw_Attack (Weapon thiswep, entity actor, .entity weaponentity)
+void W_OverkillRocketPropelledChainsaw_Attack(Weapon thiswep, entity actor, .entity weaponentity)
 {
        entity missile = spawn(); //WarpZone_RefSys_SpawnSameRefSys(actor);
        entity flash = spawn ();
 
        W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(okrpc, ammo), weaponentity);
-       W_SetupShot_ProjectileSize(actor, weaponentity, '-3 -3 -3', '3 3 3', false, 5, SND_ROCKET_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(okrpc, damage), WEP_OVERKILL_RPC.m_id);
-       Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
+       W_SetupShot_ProjectileSize(actor, weaponentity, '-3 -3 -3', '3 3 3', false, 5, SND_ROCKET_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(okrpc, damage), thiswep.m_id);
+       W_MuzzleFlash(actor, weaponentity, EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000);
        PROJECTILE_MAKETRIGGER(missile);
 
        missile.owner = missile.realowner = actor;
@@ -78,13 +100,13 @@ void W_OverkillRocketPropelledChainsaw_Attack (Weapon thiswep, entity actor, .en
 
        missile.takedamage = DAMAGE_YES;
        missile.damageforcescale = WEP_CVAR_PRI(okrpc, damageforcescale);
-       missile.health = WEP_CVAR_PRI(okrpc, health);
+       SetResourceExplicit(missile, RES_HEALTH, WEP_CVAR_PRI(okrpc, health));
        missile.event_damage = W_OverkillRocketPropelledChainsaw_Damage;
        missile.damagedbycontents = true;
        IL_PUSH(g_damagedbycontents, missile);
        set_movetype(missile, MOVETYPE_FLY);
 
-       missile.projectiledeathtype = WEP_OVERKILL_RPC.m_id;
+       missile.projectiledeathtype = thiswep.m_id;
        missile.weaponentity_fld = weaponentity;
        setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
 
@@ -102,10 +124,12 @@ void W_OverkillRocketPropelledChainsaw_Attack (Weapon thiswep, entity actor, .en
 
        CSQCProjectile(missile, true, PROJECTILE_RPC, false);
 
+       // TODO: move to client
        setmodel(flash, MDL_RPC_MUZZLEFLASH); // precision set below
        SUB_SetFade (flash, time, 0.1);
        flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
        W_AttachToShotorg(actor, weaponentity, flash, '5 0 0');
+       missile.m_chainsaw_damage = 0;
 
        MUTATOR_CALLHOOK(EditProjectile, actor, missile);
 }
@@ -126,14 +150,11 @@ METHOD(OverkillRocketPropelledChainsaw, wr_think, void(entity thiswep, entity ac
                        (actor.(weaponentity).wframe == WFRAME_FIRE2))
                {
                        // Set secondary fire animation.
-                       vector a = '0 0 0';
                        actor.(weaponentity).wframe = WFRAME_FIRE2;
-                       a = actor.(weaponentity).anim_fire2;
-                       a.z *= g_weaponratefactor;
                        FOREACH_CLIENT(true, LAMBDA(
                                if (it == actor || (IS_SPEC(it) && it.enemy == actor))
                                {
-                                       wframe_send(it, actor.(weaponentity), a, true);
+                                       wframe_send(it, actor.(weaponentity), WFRAME_FIRE2, g_weaponratefactor, true);
                                }
                        ));
                        animdecide_setaction(actor, ANIMACTION_SHOOT, true);
@@ -168,15 +189,15 @@ METHOD(OverkillRocketPropelledChainsaw, wr_think, void(entity thiswep, entity ac
 
 METHOD(OverkillRocketPropelledChainsaw, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
 {
-       float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(okrpc, ammo);
-       ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_RPC.m_id]) >= WEP_CVAR_PRI(okrpc, ammo);
+       float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(okrpc, ammo);
+       ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(okrpc, ammo);
        return ammo_amount;
 }
 
 METHOD(OverkillRocketPropelledChainsaw, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
 {
-       float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(okrpc, ammo);
-       ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_RPC.m_id]) >= WEP_CVAR_SEC(okrpc, ammo);
+       float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(okrpc, ammo);
+       ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(okrpc, ammo);
        return ammo_amount;
 }