]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_electro.qc
add some jitter to the beam length to make it look more electric :)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_electro.qc
index 45168cdacf66fcf60d685f5521ec16f64e2a25aa..32f85285c46edd1f7a4dbab41cf5b6003018a4df 100644 (file)
@@ -184,19 +184,66 @@ void W_Electro_Attack2()
        CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
 }
 
-// experimental lightning gun
-void W_Electro_Attack3 (void)
+void lgbeam_think()
 {
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-               self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_primary_ammo");
-       W_SetupShot (self, TRUE, 0, "weapons/crylink_fire2.wav", cvar("g_balance_electro_primary_damage"));
+    if (!self.owner.BUTTON_ATCK || self.owner.ammo_cells <= 0) // || (self.ammo_cells <= 0 && !(self.items & IT_UNLIMITED_WEAPON_AMMO)))
+    {
+        sound (self, CHAN_PROJECTILE, "sound/misc/null.wav", VOL_BASE, ATTN_NORM);
+        remove(self);
+        return;
+    }
+
+    if (time - self.shot_spread + random() * 0.2 > 0)
+    {
+        self.shot_spread = time + 2;
+        sound (self, CHAN_PROJECTILE, "turrets/phaser.wav", VOL_BASE, ATTN_NORM);
+    }
+
+    if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+       self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_primary_ammo");
+
+    self.nextthink = time + self.ticrate;
+
+    //w_deathtypestring = "was phased out of existence";
+
+    makevectors(self.owner.v_angle);
+    vector angle;
+    angle = v_forward;
+
+    vector force;
+    force = angle * cvar("g_balance_electro_primary_force");
+
+    traceline_antilag(self.owner, self.owner.origin, self.owner.origin + angle * cvar("g_balance_electro_primary_range"), FALSE, self.owner, ANTILAG_LATENCY(self.owner));
 
-       traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_electro_primary_radius"), FALSE, self, ANTILAG_LATENCY(self));
+    // apply the damage
+    if(trace_fraction < 1)
+    {
+       Damage (trace_ent, self.owner, self.owner, cvar("g_balance_electro_primary_damage"), WEP_ELECTRO, trace_endpos, force);
+       trace_ent.velocity = trace_ent.velocity * cvar("g_balance_electro_primary_velocityfactor") + '0 0 1' * cvar("g_balance_electro_primary_force_up");
+    }
 
-       te_lightning1(self, w_shotorg, trace_endpos);
+    self.scale = vlen(self.owner.origin - trace_endpos) / 256 * (0.75 + 0.75 * random());
+}
 
-       if (trace_fraction < 1)
-               Damage(trace_ent, self, self, cvar("g_balance_electro_primary_damage"), WEP_ELECTRO | HITTYPE_SECONDARY, trace_endpos, cvar("g_balance_electro_primary_force") * w_shotdir);
+// experimental lightning gun
+void W_Electro_Attack3 (void)
+{
+       entity beam;
+
+       beam = spawn();
+       beam.ticrate = autocvar_sys_ticrate;
+       setmodel(beam,"models/turrets/phaser_beam.md3");
+       beam.effects = EF_LOWPRECISION;
+       beam.solid = SOLID_NOT;
+       beam.think = lgbeam_think;
+       beam.shot_spread = 0;
+       beam.scale = cvar("g_balance_electro_primary_range") / 256;
+       beam.nextthink = time;
+       beam.owner = self;
+       beam.movetype = MOVETYPE_NONE;
+       beam.bot_dodge = TRUE;
+       beam.bot_dodgerating = cvar("g_balance_electro_primary_damage")/autocvar_sys_ticrate;
+       setattachment(beam, self.weaponentity, "shot");
 }
 
 void spawnfunc_weapon_electro (void)
@@ -220,6 +267,7 @@ void w_electro_checkattack()
 }
 
 .float bot_secondary_electromooth;
+.float BUTTON_ATCK_prev;
 float w_electro(float req)
 {
        if (req == WR_AIM)
@@ -251,12 +299,19 @@ float w_electro(float req)
                if (weapon_prepareattack(0, cvar("g_balance_electro_primary_refire")))
                {
                        if(cvar("g_balance_electro_lightning"))
-                               W_Electro_Attack3();
+                       {
+                               if (self.BUTTON_ATCK_prev == 0)
+                               {
+                                       W_Electro_Attack3();
+                               }
+                       }
                        else
+                       {
                                W_Electro_Attack();
+                       }
                        weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_electro_primary_animtime"), w_ready);
                }
-               if (self.BUTTON_ATCK2 && !cvar("g_balance_electro_lightning"))
+               if (self.BUTTON_ATCK2)
                if (time >= self.electro_secondarytime)
                if (weapon_prepareattack(1, cvar("g_balance_electro_secondary_refire")))
                {
@@ -285,36 +340,11 @@ float w_electro(float req)
                return self.ammo_cells >= cvar("g_balance_electro_primary_ammo");
        else if (req == WR_CHECKAMMO2)
                return self.ammo_cells >= cvar("g_balance_electro_secondary_ammo");
-       else if (req == WR_SUICIDEMESSAGE)
-       {
-               if(w_deathtype & HITTYPE_SECONDARY)
-                       w_deathtypestring = "could not remember where they put plasma";
-               else
-                       w_deathtypestring = "played with plasma";
-       }
-       else if (req == WR_KILLMESSAGE)
-       {
-               if(w_deathtype & HITTYPE_SECONDARY)
-               {
-                       if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
-                               w_deathtypestring = "just noticed #'s blue ball";
-                       else // unchecked: BOUNCE
-                               w_deathtypestring = "got in touch with #'s blue ball";
-               }
-               else
-               {
-                       if(w_deathtype & HITTYPE_BOUNCE) // combo
-                               w_deathtypestring = "felt the electrifying air of #'s combo";
-                       else if(w_deathtype & HITTYPE_SPLASH)
-                               w_deathtypestring = "got too close to #'s blue beam";
-                       else
-                               w_deathtypestring = "was blasted by #'s blue beam";
-               }
-       }
        else if (req == WR_RESETPLAYER)
        {
                self.electro_secondarytime = time;
        }
+       self.BUTTON_ATCK_prev = self.BUTTON_ATCK;
        return TRUE;
 };
 #endif
@@ -353,6 +383,32 @@ float w_electro(float req)
                precache_sound("weapons/electro_impact.wav");
                precache_sound("weapons/electro_impact_combo.wav");
        }
+       else if (req == WR_SUICIDEMESSAGE)
+       {
+               if(w_deathtype & HITTYPE_SECONDARY)
+                       w_deathtypestring = "could not remember where they put plasma";
+               else
+                       w_deathtypestring = "played with plasma";
+       }
+       else if (req == WR_KILLMESSAGE)
+       {
+               if(w_deathtype & HITTYPE_SECONDARY)
+               {
+                       if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
+                               w_deathtypestring = "just noticed #'s blue ball";
+                       else // unchecked: BOUNCE
+                               w_deathtypestring = "got in touch with #'s blue ball";
+               }
+               else
+               {
+                       if(w_deathtype & HITTYPE_BOUNCE) // combo
+                               w_deathtypestring = "felt the electrifying air of #'s combo";
+                       else if(w_deathtype & HITTYPE_SPLASH)
+                               w_deathtypestring = "got too close to #'s blue beam";
+                       else
+                               w_deathtypestring = "was blasted by #'s blue beam";
+               }
+       }
        return TRUE;
 }
 #endif