]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_electro.qc
Merge remote-tracking branch 'origin/samual/no_dead_airshots'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_electro.qc
index a25d266312fa8c28e870201926234ccdc1339b8e..711c44c8bf363a39bd8672e5c9908c6b2993f9db 100644 (file)
@@ -1,5 +1,5 @@
 #ifdef REGISTER_WEAPON
-REGISTER_WEAPON(ELECTRO, w_electro, IT_CELLS, 5, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "electro", "electro", "Electro");
+REGISTER_WEAPON(ELECTRO, w_electro, IT_CELLS, 5, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "electro", "electro", _("Electro"));
 #else
 #ifdef SVQC
 .float electro_count;
@@ -110,6 +110,8 @@ void W_Electro_Attack()
 {
        local 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);
 
        pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
@@ -126,8 +128,6 @@ void W_Electro_Attack()
        proj.projectiledeathtype = WEP_ELECTRO;
        setorigin(proj, w_shotorg);
 
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-               self.ammo_cells = self.ammo_cells - autocvar_g_balance_electro_primary_ammo;
        proj.movetype = MOVETYPE_FLY;
        W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
        proj.angles = vectoangles(proj.velocity);
@@ -147,6 +147,8 @@ void W_Electro_Attack2()
 {
        local 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_shotdir = v_forward; // no TrueAim for grenades please
@@ -165,8 +167,6 @@ void W_Electro_Attack2()
        proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
        setorigin(proj, w_shotorg);
 
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-               self.ammo_cells = self.ammo_cells - autocvar_g_balance_electro_secondary_ammo;
        //proj.glow_size = 50;
        //proj.glow_color = 45;
        proj.movetype = MOVETYPE_BOUNCE;
@@ -193,7 +193,7 @@ void W_Electro_Attack2()
        CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
 
        other = proj; MUTATOR_CALLHOOK(EditProjectile);
-       }
+}
 
 .vector hook_start, hook_end;
 float lgbeam_send(entity to, float sf)
@@ -224,39 +224,64 @@ float lgbeam_send(entity to, float sf)
 }
 .entity lgbeam;
 .float prevlgfire;
+float lgbeam_checkammo()
+{
+       if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
+               return TRUE;
+       else if(autocvar_g_balance_electro_reload_ammo)
+               return self.owner.clip_load > 0;
+       else
+               return self.owner.ammo_cells > 0;
+}
+
 void lgbeam_think()
 {
-       self.owner.prevlgfire = time;
-       if (self != self.owner.lgbeam)
+       entity owner_player;
+       owner_player = self.owner;
+
+       owner_player.prevlgfire = time;
+       if (self != owner_player.lgbeam)
        {
                remove(self);
                return;
        }
-       if (self.owner.weaponentity.state != WS_INUSE || (self.owner.ammo_cells <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)) || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || (g_freezetag && self.owner.freezetag_frozen))
+
+       if (owner_player.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || owner_player.deadflag != DEAD_NO || !owner_player.BUTTON_ATCK || owner_player.freezetag_frozen)
        {
-               if(self == self.owner.lgbeam)
-                       self.owner.lgbeam = world;
+               if(self == owner_player.lgbeam)
+                       owner_player.lgbeam = world;
                remove(self);
                return;
        }
 
        self.nextthink = time;
 
-       makevectors(self.owner.v_angle);
+       makevectors(owner_player.v_angle);
 
        float dt, f;
        dt = frametime;
-       if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
+
+       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
+       if not(owner_player.items & IT_UNLIMITED_WEAPON_AMMO)
        {
                if(autocvar_g_balance_electro_primary_ammo)
                {
-                       dt = min(dt, self.owner.ammo_cells / autocvar_g_balance_electro_primary_ammo);
-                       self.owner.ammo_cells = max(0, self.owner.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
+                       if(autocvar_g_balance_electro_reload_ammo)
+                       {
+                               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;
+                       }
+                       else
+                       {
+                               dt = min(dt, owner_player.ammo_cells / autocvar_g_balance_electro_primary_ammo);
+                               owner_player.ammo_cells = max(0, owner_player.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
+                       }
                }
        }
 
-       W_SetupShot_Range(self.owner, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
-       WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
+       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));
 
        // apply the damage
        if(trace_ent)
@@ -266,11 +291,11 @@ void lgbeam_think()
 
                f = ExponentialFalloff(autocvar_g_balance_electro_primary_falloff_mindist, autocvar_g_balance_electro_primary_falloff_maxdist, autocvar_g_balance_electro_primary_falloff_halflifedist, vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg));
 
-               if(accuracy_isgooddamage(self.owner, trace_ent))
-                       accuracy_add(self.owner, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
-               Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
+               if(accuracy_isgooddamage(owner_player, trace_ent))
+                       accuracy_add(owner_player, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
+               Damage (trace_ent, owner_player, owner_player, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
        }
-       W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, self.owner);
+       W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, owner_player);
 
        // draw effect
        if(w_shotorg != self.hook_start)
@@ -344,6 +369,7 @@ void w_electro_checkattack()
 .float BUTTON_ATCK_prev;
 float w_electro(float req)
 {
+       float ammo_amount;
        if (req == WR_AIM)
        {
                self.BUTTON_ATCK=FALSE;
@@ -376,8 +402,35 @@ float w_electro(float req)
        }
        else if (req == WR_THINK)
        {
+               if(autocvar_g_balance_electro_reload_ammo) // forced reload
+               {
+                       if(autocvar_g_balance_electro_lightning)
+                       {
+                               if(self.clip_load > 0)
+                                       ammo_amount = 1;
+                       }
+                       else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
+                               ammo_amount = 1;
+                       if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
+                               ammo_amount += 1;
+
+                       if(!ammo_amount)
+                       {
+                               weapon_action(self.weapon, WR_RELOAD);
+                               return FALSE;
+                       }
+               }
                if (self.BUTTON_ATCK)
                {
+                       if(autocvar_g_balance_electro_lightning)
+                               if(self.BUTTON_ATCK_prev)
+                               {
+                                       // prolong the animtime while the gun is being fired
+                                       if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
+                                               weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
+                                       else
+                                               weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
+                               }
                        if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
                        {
                                if(autocvar_g_balance_electro_lightning)
@@ -386,33 +439,40 @@ float w_electro(float req)
                                        {
                                                W_Electro_Attack3();
                                        }
-                                       self.BUTTON_ATCK_prev = 1;
+                                       if(!self.BUTTON_ATCK_prev)
+                                       {
+                                               weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
+                                               self.BUTTON_ATCK_prev = 1;
+                                       }
                                }
                                else
                                {
                                        W_Electro_Attack();
+                                       weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
                                }
-                               weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
                        }
                } else {
                        if(autocvar_g_balance_electro_lightning)
                        {
                                if (self.BUTTON_ATCK_prev != 0)
                                {
+                                       weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
                                        ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
                                }
                                self.BUTTON_ATCK_prev = 0;
                        }
-               }
 
-               if (self.BUTTON_ATCK2)
-               if (time >= self.electro_secondarytime)
-               if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
-               {
-                       W_Electro_Attack2();
-                       self.electro_count = autocvar_g_balance_electro_secondary_count;
-                       weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
-                       self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2;
+                       if (self.BUTTON_ATCK2)
+                       {
+                               if (time >= self.electro_secondarytime)
+                               if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
+                               {
+                                       W_Electro_Attack2();
+                                       self.electro_count = autocvar_g_balance_electro_secondary_count;
+                                       weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
+                                       self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
+                               }
+                       }
                }
        }
        else if (req == WR_PRECACHE)
@@ -425,26 +485,48 @@ float w_electro(float req)
                precache_sound ("weapons/electro_fire2.wav");
                precache_sound ("weapons/electro_impact.wav");
                precache_sound ("weapons/electro_impact_combo.wav");
+               //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
                if(autocvar_g_balance_electro_lightning)
                {
                        precache_sound ("weapons/lgbeam_fire.wav");
                }
        }
        else if (req == WR_SETUP)
+       {
                weapon_setup(WEP_ELECTRO);
+               self.current_ammo = ammo_cells;
+       }
        else if (req == WR_CHECKAMMO1)
        {
                if(autocvar_g_balance_electro_lightning)
-                       return !autocvar_g_balance_electro_primary_ammo || (self.ammo_cells > 0);
+               {
+                       if(!autocvar_g_balance_electro_primary_ammo)
+                               ammo_amount = 1;
+                       else
+                               ammo_amount = self.ammo_cells > 0;
+                       ammo_amount += self.weapon_load[WEP_ELECTRO] > 0;
+               }
                else
-                       return self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
+               {
+                       ammo_amount = self.ammo_cells >= 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)
-               return self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
+       {
+               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)
        {
                self.electro_secondarytime = time;
        }
+       else if (req == WR_RELOAD)
+       {
+               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
@@ -486,27 +568,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 plasma");
                else
-                       w_deathtypestring = "%s played with plasma";
+                       w_deathtypestring = _("%s played with 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 blue ball");
                        else // unchecked: BOUNCE
-                               w_deathtypestring = "%s got in touch with %s's blue ball";
+                               w_deathtypestring = _("%s got in touch with %s's blue ball");
                }
                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 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 beam");
                        else
-                               w_deathtypestring = "%s was blasted by %s's blue beam";
+                               w_deathtypestring = _("%s was blasted by %s's blue beam");
                }
        }
        return TRUE;