]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/electro.qc
Merge branch 'master' into Mario/electro_combo_over_time
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / electro.qc
index 4a6ee87d5cc16ac5bb008897ba88007994da9813..a68ad35bd9fcf203a3d093d3c119fa68bd993a45 100644 (file)
@@ -10,6 +10,13 @@ void W_Electro_TriggerCombo(vector org, float rad, entity own)
        {
                if(e.classname == "electro_orb")
                {
+                       // check if the ball we are exploding is not owned by an
+                       // independent player which is not the player who shot the ball
+                       if(IS_INDEPENDENT_PLAYER(e.realowner) && own != e.realowner)
+                       {
+                               e = e.chain;
+                               continue;
+                       }
                        // do we allow thruwall triggering?
                        if(WEP_CVAR(electro, combo_comboradius_thruwall))
                        {
@@ -44,6 +51,25 @@ void W_Electro_TriggerCombo(vector org, float rad, entity own)
        }
 }
 
+void W_Electro_ExplodeComboThink(entity this)
+{
+       float dt = time - this.teleport_time + this.dmg_interval;
+       float dmg_remaining_next = (bound(0, 1 - dt / this.dmg_duration, 1) ** this.dmg_power);
+
+       float f = this.dmg_last - dmg_remaining_next;
+       this.dmg_last = dmg_remaining_next;
+
+       float dmg_scale = ((this.dmg_linear) ? this.dmg_interval : f);
+
+       RadiusDamage(this, this.realowner, this.dmg * dmg_scale, this.dmg_edge * dmg_scale, this.dmg_radius, NULL, NULL, this.dmg_force * f, this.projectiledeathtype, this.weaponentity_fld, NULL);
+       this.projectiledeathtype |= HITTYPE_BOUNCE; // ensure it doesn't spam its effect
+
+       if(dt < this.dmg_duration)
+               this.nextthink = time + this.dmg_interval; // soon
+       else
+               delete(this);
+}
+
 void W_Electro_ExplodeCombo(entity this)
 {
        W_Electro_TriggerCombo(this.origin, WEP_CVAR(electro, combo_comboradius), this.realowner);
@@ -51,6 +77,29 @@ void W_Electro_ExplodeCombo(entity this)
        this.event_damage = func_null;
        this.velocity = this.movedir; // particle fx and decals need .velocity
 
+       if(WEP_CVAR(electro, combo_duration))
+       {
+               this.projectiledeathtype = WEP_ELECTRO.m_id | HITTYPE_SPLASH;
+               this.event_damage = func_null;
+               settouch(this, func_null);
+               this.effects |= EF_NODRAW;
+
+               setthink(this, W_Electro_ExplodeComboThink);
+               this.nextthink = time;
+               this.dmg = WEP_CVAR(electro, combo_damage);
+               this.dmg_edge = WEP_CVAR(electro, combo_edgedamage);
+               this.dmg_radius = WEP_CVAR(electro, combo_radius);
+               this.dmg_force = WEP_CVAR(electro, combo_force);
+               this.dmg_power = WEP_CVAR(electro, combo_power);
+               this.dmg_duration = WEP_CVAR(electro, combo_duration);
+               this.dmg_interval = WEP_CVAR(electro, combo_damage_interval);
+               this.dmg_linear = WEP_CVAR(electro, combo_damage_linear);
+               this.teleport_time = time;
+               this.dmg_last = 1;
+               set_movetype(this, MOVETYPE_NONE);
+               return;
+       }
+
        RadiusDamage(
                this,
                this.realowner,
@@ -151,6 +200,13 @@ void W_Electro_Bolt_Think(entity this)
                {
                        if(e.classname == "electro_orb")
                        {
+                               // check if the ball we are exploding is not owned by an
+                               // independent player which is not the player who shot the ball
+                               if(IS_INDEPENDENT_PLAYER(e.realowner) && this.realowner != e.realowner)
+                               {
+                                       e = e.chain;
+                                       continue;
+                               }
                                bool explode;
                                if (this.owner == e.owner)
                                {
@@ -312,7 +368,11 @@ void W_Electro_Orb_Stick(entity this, entity to)
        newproj.weaponentity_fld = this.weaponentity_fld;
 
        settouch(newproj, func_null);
-       newproj.death_time = this.death_time;
+       if(WEP_CVAR_SEC(electro, stick_lifetime) > 0){
+               newproj.death_time = time + WEP_CVAR_SEC(electro, stick_lifetime);
+       }else{
+               newproj.death_time = this.death_time;
+       }
        newproj.use = this.use;
        newproj.flags = this.flags;
        IL_PUSH(g_projectiles, newproj);
@@ -351,8 +411,13 @@ void W_Electro_Orb_Touch(entity this, entity toucher)
                spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
                this.projectiledeathtype |= HITTYPE_BOUNCE;
 
-               if(WEP_CVAR_SEC(electro, stick))
-                       W_Electro_Orb_Stick(this, toucher);
+               if(WEP_CVAR_SEC(electro, stick)){
+                       if(WEP_CVAR_SEC(electro, stick_lifetime) == 0){
+                               W_Electro_Explode(this, toucher);
+                       } else {
+                               W_Electro_Orb_Stick(this, toucher);
+                       }
+               }
        }
 }
 
@@ -468,10 +533,10 @@ void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, i
        {
                W_Electro_Attack_Orb(thiswep, actor, weaponentity);
                actor.(weaponentity).electro_count -= 1;
+               actor.(weaponentity).electro_secondarytime = time;
                weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
                return;
        }
-       // WEAPONTODO: when the player releases the button, cut down the length of refire2?
        w_ready(thiswep, actor, weaponentity, fire);
 }
 
@@ -524,21 +589,22 @@ METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentit
 
     if(fire & 1)
     {
+        if(time >= actor.(weaponentity).electro_secondarytime + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor))
         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
         {
-                W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
-                weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
+            W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
+            weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
         }
     }
     else if(fire & 2)
     {
-        if(time >= actor.(weaponentity).electro_secondarytime)
-        if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
+        if(time >= actor.(weaponentity).electro_secondarytime + WEP_CVAR_SEC(electro, refire) * W_WeaponRateFactor(actor))
+        if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
         {
             W_Electro_Attack_Orb(thiswep, actor, weaponentity);
             actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
+            actor.(weaponentity).electro_secondarytime = time;
             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
-            actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
         }
     }
 }
@@ -563,14 +629,6 @@ METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weapon
     }
     return ammo_amount;
 }
-METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
-{
-    for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
-    {
-       .entity weaponentity = weaponentities[slot];
-       actor.(weaponentity).electro_secondarytime = time;
-    }
-}
 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
 {
     W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
@@ -612,7 +670,17 @@ METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
     }
     else
     {
-        if(w_deathtype & HITTYPE_BOUNCE)
+       if(w_deathtype & HITTYPE_SPLASH)
+       {
+               org2 = w_org + w_backoff * 2;
+               if(particleeffectnum(EFFECT_ELECTRO_COMBO_LONG) >= 0)
+               pointparticles(EFFECT_ELECTRO_COMBO_LONG, org2, '0 0 0', 1);
+               else
+               pointparticles(EFFECT_HOOK_EXPLODE, org2, '0 0 0', 1);
+            if(!w_issilent)
+                sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
+       }
+        else if(w_deathtype & HITTYPE_BOUNCE)
         {
             // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
             pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);