]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_electro.qc
2 new features: Don't switch away from a weapon if one of its modes can still fire...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_electro.qc
index 711c44c8bf363a39bd8672e5c9908c6b2993f9db..9b1b96e56547abaf3d4bbff42c89a41bde6c781f 100644 (file)
@@ -9,14 +9,14 @@ void W_Plasma_Explode_Combo (void);
 
 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
 {
-       local entity e;
+       entity e;
        e = WarpZone_FindRadius(org, rad, TRUE);
        while (e)
        {
                if (e.classname == "plasma")
                {
                        // change owner to whoever caused the combo explosion
-                       e.owner = own;
+                       e.realowner = own;
                        e.takedamage = DAMAGE_NO;
                        e.classname = "plasma_chain";
                        e.think = W_Plasma_Explode_Combo;
@@ -30,21 +30,21 @@ void W_Plasma_Explode (void)
 {
        if(other.takedamage == DAMAGE_AIM)
                if(other.classname == "player")
-                       if(IsDifferentTeam(self.owner, other))
+                       if(IsDifferentTeam(self.realowner, other))
                                if(other.deadflag == DEAD_NO)
                                        if(IsFlying(other))
-                                               AnnounceTo(self.owner, "electrobitch");
+                                               AnnounceTo(self.realowner, "electrobitch");
 
        self.event_damage = SUB_Null;
        self.takedamage = DAMAGE_NO;
        if (self.movetype == MOVETYPE_BOUNCE)
        {
-               RadiusDamage (self, self.owner, autocvar_g_balance_electro_secondary_damage, autocvar_g_balance_electro_secondary_edgedamage, autocvar_g_balance_electro_secondary_radius, world, autocvar_g_balance_electro_secondary_force, self.projectiledeathtype, other);
+               RadiusDamage (self, self.realowner, autocvar_g_balance_electro_secondary_damage, autocvar_g_balance_electro_secondary_edgedamage, autocvar_g_balance_electro_secondary_radius, world, autocvar_g_balance_electro_secondary_force, self.projectiledeathtype, other);
        }
        else
        {
-               W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.owner);
-               RadiusDamage (self, self.owner, autocvar_g_balance_electro_primary_damage, autocvar_g_balance_electro_primary_edgedamage, autocvar_g_balance_electro_primary_radius, world, autocvar_g_balance_electro_primary_force, self.projectiledeathtype, other);
+               W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.realowner);
+               RadiusDamage (self, self.realowner, autocvar_g_balance_electro_primary_damage, autocvar_g_balance_electro_primary_edgedamage, autocvar_g_balance_electro_primary_radius, world, autocvar_g_balance_electro_primary_force, self.projectiledeathtype, other);
        }
 
        remove (self);
@@ -52,10 +52,10 @@ void W_Plasma_Explode (void)
 
 void W_Plasma_Explode_Combo (void)
 {
-       W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.owner);
+       W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.realowner);
 
        self.event_damage = SUB_Null;
-       RadiusDamage (self, self.owner, autocvar_g_balance_electro_combo_damage, autocvar_g_balance_electro_combo_edgedamage, autocvar_g_balance_electro_combo_radius, world, autocvar_g_balance_electro_combo_force, WEP_ELECTRO | HITTYPE_BOUNCE, world); // use THIS type for a combo because primary can't bounce
+       RadiusDamage (self, self.realowner, autocvar_g_balance_electro_combo_damage, autocvar_g_balance_electro_combo_edgedamage, autocvar_g_balance_electro_combo_radius, world, autocvar_g_balance_electro_combo_force, WEP_ELECTRO | HITTYPE_BOUNCE, world); // use THIS type for a combo because primary can't bounce
        remove (self);
 }
 
@@ -68,7 +68,7 @@ void W_Plasma_Touch (void)
                W_Plasma_Explode ();
        } else {
                //UpdateCSQCProjectile(self);
-               spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
+               spamsound (self, CH_SHOTS, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
                self.projectiledeathtype |= HITTYPE_BOUNCE;
        }
 }
@@ -83,16 +83,22 @@ void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float dea
 {
        if(self.health <= 0)
                return;
+
        // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
+       float is_combo = (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim");
+       
+       if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, (is_combo ? 1 : -1)))
+               return; // g_projectiles_damage says to halt    
+       
        self.health = self.health - damage;
        if (self.health <= 0)
        {
                self.takedamage = DAMAGE_NO;
                self.nextthink = time;
-               if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
+               if (is_combo)
                {
                        // change owner to whoever caused the combo explosion
-                       self.owner = inflictor.owner;
+                       self.realowner = inflictor.realowner;
                        self.classname = "plasma_chain";
                        self.think = W_Plasma_Explode_Combo;
                        self.nextthink = time + min(autocvar_g_balance_electro_combo_radius, vlen(self.origin - inflictor.origin)) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
@@ -108,17 +114,17 @@ void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float dea
 
 void W_Electro_Attack()
 {
-       local entity proj;
+       entity proj;
 
        W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_reload_ammo);
 
-       W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
+       W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CH_WEAPON_A, autocvar_g_balance_electro_primary_damage);
 
        pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
 
        proj = spawn ();
        proj.classname = "plasma_prim";
-       proj.owner = self;
+       proj.owner = proj.realowner = self;
        proj.bot_dodge = TRUE;
        proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
        proj.use = W_Plasma_Explode;
@@ -135,9 +141,6 @@ void W_Electro_Attack()
        setsize(proj, '0 0 -3', '0 0 -3');
        proj.flags = FL_PROJECTILE;
 
-       //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
-       //sounds bad
-
        CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
 
        other = proj; MUTATOR_CALLHOOK(EditProjectile);
@@ -145,11 +148,11 @@ void W_Electro_Attack()
 
 void W_Electro_Attack2()
 {
-       local entity proj;
+       entity proj;
 
        W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_secondary_ammo, autocvar_g_balance_electro_reload_ammo);
 
-       W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
+       W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CH_WEAPON_A, autocvar_g_balance_electro_secondary_damage);
 
        w_shotdir = v_forward; // no TrueAim for grenades please
 
@@ -157,7 +160,7 @@ void W_Electro_Attack2()
 
        proj = spawn ();
        proj.classname = "plasma";
-       proj.owner = self;
+       proj.owner = proj.realowner = self;
        proj.use = W_Plasma_Explode;
        proj.think = adaptor_think2use_hittype_splash;
        proj.bot_dodge = TRUE;
@@ -178,6 +181,7 @@ void W_Electro_Attack2()
        proj.health = autocvar_g_balance_electro_secondary_health;
        proj.event_damage = W_Plasma_Damage;
        proj.flags = FL_PROJECTILE;
+       proj.damagedbycontents = (autocvar_g_balance_electro_secondary_damagedbycontents);
 
        proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
        proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
@@ -200,12 +204,12 @@ float lgbeam_send(entity to, float sf)
 {
        WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
        sf = sf & 0x7F;
-       if(sound_allowed(MSG_BROADCAST, self.owner))
+       if(sound_allowed(MSG_BROADCAST, self.realowner))
                sf |= 0x80;
        WriteByte(MSG_ENTITY, sf);
        if(sf & 1)
        {
-               WriteByte(MSG_ENTITY, num_for_edict(self.owner));
+               WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
                WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
        }
        if(sf & 2)
@@ -226,18 +230,19 @@ float lgbeam_send(entity to, float sf)
 .float prevlgfire;
 float lgbeam_checkammo()
 {
-       if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
+       if(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO)
                return TRUE;
        else if(autocvar_g_balance_electro_reload_ammo)
-               return self.owner.clip_load > 0;
+               return self.realowner.clip_load > 0;
        else
-               return self.owner.ammo_cells > 0;
+               return self.realowner.ammo_cells > 0;
 }
 
+entity lgbeam_owner_ent;
 void lgbeam_think()
 {
        entity owner_player;
-       owner_player = self.owner;
+       owner_player = self.realowner;
 
        owner_player.prevlgfire = time;
        if (self != owner_player.lgbeam)
@@ -270,7 +275,7 @@ void lgbeam_think()
                        {
                                dt = min(dt, owner_player.clip_load / autocvar_g_balance_electro_primary_ammo);
                                owner_player.clip_load = max(0, owner_player.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
-                               owner_player.weapon_load[WEP_ELECTRO] = owner_player.clip_load;
+                               owner_player.(weapon_load[WEP_ELECTRO]) = owner_player.clip_load;
                        }
                        else
                        {
@@ -281,7 +286,12 @@ void lgbeam_think()
        }
 
        W_SetupShot_Range(owner_player, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
-       WarpZone_traceline_antilag(owner_player, w_shotorg, w_shotend, MOVE_NORMAL, owner_player, ANTILAG_LATENCY(owner_player));
+       if(!lgbeam_owner_ent)
+       {
+               lgbeam_owner_ent = spawn();
+               lgbeam_owner_ent.classname = "lgbeam_owner_ent";
+       }
+       WarpZone_traceline_antilag(lgbeam_owner_ent, w_shotorg, w_shotend, MOVE_NORMAL, lgbeam_owner_ent, ANTILAG_LATENCY(owner_player));
 
        // apply the damage
        if(trace_ent)
@@ -315,7 +325,7 @@ void W_Electro_Attack3 (void)
 {
        // only play fire sound if 0.5 sec has passed since player let go the fire button
        if(time - self.prevlgfire > 0.5)
-               sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
+               sound (self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
 
        entity beam, oldself;
 
@@ -323,7 +333,7 @@ void W_Electro_Attack3 (void)
        beam.classname = "lgbeam";
        beam.solid = SOLID_NOT;
        beam.think = lgbeam_think;
-       beam.owner = self;
+       beam.owner = beam.realowner = self;
        beam.movetype = MOVETYPE_NONE;
        beam.shot_spread = 0;
        beam.bot_dodge = TRUE;
@@ -504,19 +514,27 @@ float w_electro(float req)
                                ammo_amount = 1;
                        else
                                ammo_amount = self.ammo_cells > 0;
-                       ammo_amount += self.weapon_load[WEP_ELECTRO] > 0;
+                       ammo_amount += self.(weapon_load[WEP_ELECTRO]) > 0;
                }
                else
                {
                        ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
-                       ammo_amount += self.weapon_load[WEP_ELECTRO] >= autocvar_g_balance_electro_primary_ammo;
+                       ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_primary_ammo;
                }
                return ammo_amount;
        }
        else if (req == WR_CHECKAMMO2)
        {
-               ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
-               ammo_amount += self.weapon_load[WEP_ELECTRO] >= autocvar_g_balance_electro_secondary_ammo;
+               if(autocvar_g_balance_electro_combo_safeammocheck) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
+               {
+                       ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo + autocvar_g_balance_electro_primary_ammo;
+                       ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_secondary_ammo + autocvar_g_balance_electro_primary_ammo;
+               }
+               else
+               {
+                       ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
+                       ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_secondary_ammo;
+               }
                return ammo_amount;
        }
        else if (req == WR_RESETPLAYER)
@@ -528,7 +546,7 @@ float w_electro(float req)
                W_Reload(min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo), autocvar_g_balance_electro_reload_ammo, autocvar_g_balance_electro_reload_time, "weapons/reload.wav");
        }
        return TRUE;
-};
+}
 #endif
 #ifdef CSQC
 float w_electro(float req)
@@ -541,7 +559,7 @@ float w_electro(float req)
                {
                        pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
                        if(!w_issilent)
-                               sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
+                               sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
                }
                else
                {
@@ -550,13 +568,13 @@ float w_electro(float req)
                                // 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);
+                                       sound(self, CH_SHOTS, "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);
+                                       sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
                        }
                }
        }
@@ -568,27 +586,27 @@ float w_electro(float req)
        else if (req == WR_SUICIDEMESSAGE)
        {
                if(w_deathtype & HITTYPE_SECONDARY)
-                       w_deathtypestring = _("%s could not remember where they put plasma");
+                       w_deathtypestring = _("%s could not remember where they put their electro plasma");
                else
-                       w_deathtypestring = _("%s played with plasma");
+                       w_deathtypestring = _("%s played with electro plasma");
        }
        else if (req == WR_KILLMESSAGE)
        {
                if(w_deathtype & HITTYPE_SECONDARY)
                {
                        if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
-                               w_deathtypestring = _("%s just noticed %s's blue ball");
+                               w_deathtypestring = _("%s just noticed %s's electro plasma");
                        else // unchecked: BOUNCE
-                               w_deathtypestring = _("%s got in touch with %s's blue ball");
+                               w_deathtypestring = _("%s got in touch with %s's electro plasma");
                }
                else
                {
                        if(w_deathtype & HITTYPE_BOUNCE) // combo
-                               w_deathtypestring = _("%s felt the electrifying air of %s's combo");
+                               w_deathtypestring = _("%s felt the electrifying air of %s's electro combo");
                        else if(w_deathtype & HITTYPE_SPLASH)
-                               w_deathtypestring = _("%s got too close to %s's blue beam");
+                               w_deathtypestring = _("%s got too close to %s's blue electro bolt");
                        else
-                               w_deathtypestring = _("%s was blasted by %s's blue beam");
+                               w_deathtypestring = _("%s was blasted by %s's blue electro bolt");
                }
        }
        return TRUE;