]> 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 c1cb49d0ebb896c4b50f3985e95bb7eeb704a38a..32f85285c46edd1f7a4dbab41cf5b6003018a4df 100644 (file)
@@ -1,6 +1,7 @@
 #ifdef REGISTER_WEAPON
 REGISTER_WEAPON(ELECTRO, w_electro, IT_CELLS, 5, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "electro", "electro", "Electro");
 #else
+#ifdef SVQC
 .float electro_count;
 .float electro_secondarytime;
 
@@ -51,7 +52,6 @@ void W_Plasma_Explode (void)
 
 void W_Plasma_Explode_Combo (void)
 {
-
        W_Plasma_TriggerCombo(self.origin, cvar("g_balance_electro_combo_comboradius"), self.owner);
 
        self.event_damage = SUB_Null;
@@ -98,7 +98,7 @@ void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float dea
                else
                {
                        self.use = W_Plasma_Explode;
-                       self.think = adaptor_think2use;
+                       self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
                }
        }
 }
@@ -117,7 +117,7 @@ void W_Electro_Attack()
        proj.bot_dodge = TRUE;
        proj.bot_dodgerating = cvar("g_balance_electro_primary_damage");
        proj.use = W_Plasma_Explode;
-       proj.think = adaptor_think2use;
+       proj.think = adaptor_think2use_hittype_splash;
        proj.nextthink = time + cvar("g_balance_electro_primary_lifetime");
        PROJECTILE_MAKETRIGGER(proj);
        proj.projectiledeathtype = WEP_ELECTRO;
@@ -151,7 +151,7 @@ void W_Electro_Attack2()
        proj.classname = "plasma";
        proj.owner = self;
        proj.use = W_Plasma_Explode;
-       proj.think = adaptor_think2use;
+       proj.think = adaptor_think2use_hittype_splash;
        proj.bot_dodge = TRUE;
        proj.bot_dodgerating = cvar("g_balance_electro_secondary_damage");
        proj.nextthink = time + cvar("g_balance_electro_secondary_lifetime");
@@ -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";
 
-       traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_electro_primary_radius"), FALSE, self, ANTILAG_LATENCY(self));
+    makevectors(self.owner.v_angle);
+    vector angle;
+    angle = v_forward;
 
-       te_lightning1(self, w_shotorg, trace_endpos);
+    vector force;
+    force = angle * cvar("g_balance_electro_primary_force");
 
-       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);
+    traceline_antilag(self.owner, self.owner.origin, self.owner.origin + angle * cvar("g_balance_electro_primary_range"), FALSE, self.owner, ANTILAG_LATENCY(self.owner));
+
+    // 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");
+    }
+
+    self.scale = vlen(self.owner.origin - trace_endpos) / 256 * (0.75 + 0.75 * random());
+}
+
+// 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,6 +340,49 @@ 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_RESETPLAYER)
+       {
+               self.electro_secondarytime = time;
+       }
+       self.BUTTON_ATCK_prev = self.BUTTON_ATCK;
+       return TRUE;
+};
+#endif
+#ifdef CSQC
+float w_electro(float req)
+{
+       if(req == WR_IMPACTEFFECT)
+       {
+               vector org2;
+               org2 = w_org + w_backoff * 6;
+               if(w_deathtype & HITTYPE_SECONDARY)
+               {
+                       pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
+                       if(!w_issilent)
+                               sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_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(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
+                               if(!w_issilent)
+                                       sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
+                       }
+                       else
+                       {
+                               pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
+                               if(!w_issilent)
+                                       sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
+                       }
+               }
+       }
+       else if(req == WR_PRECACHE)
+       {
+               precache_sound("weapons/electro_impact.wav");
+               precache_sound("weapons/electro_impact_combo.wav");
+       }
        else if (req == WR_SUICIDEMESSAGE)
        {
                if(w_deathtype & HITTYPE_SECONDARY)
@@ -311,10 +409,7 @@ float w_electro(float req)
                                w_deathtypestring = "was blasted by #'s blue beam";
                }
        }
-       else if (req == WR_RESETPLAYER)
-       {
-               self.electro_secondarytime = time;
-       }
        return TRUE;
-};
+}
+#endif
 #endif