]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Very well... add reloading to the Laser too. Uses no ammo of course
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Sat, 22 Jan 2011 16:13:12 +0000 (18:13 +0200)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Sat, 22 Jan 2011 16:13:12 +0000 (18:13 +0200)
balanceXonotic.cfg
qcsrc/server/autocvars.qh
qcsrc/server/cl_client.qc
qcsrc/server/w_laser.qc

index 02604b66e8c102eb818cede79c56c591878f3848..7e5327c335d490d03050d7c0f442a2b56892f419 100644 (file)
@@ -243,6 +243,8 @@ set g_balance_laser_secondary_gauntlet 1
 set g_balance_laser_secondary_force_zscale 1.25
 set g_balance_laser_secondary_force_velocitybias 0
 set g_balance_laser_secondary_force_other_scale 0
+set g_balance_laser_reload_count 5
+set g_balance_laser_reload_time 2
 // }}}
 // {{{ shotgun
 set g_balance_shotgun_primary_bullets 18
index 5d5377aef5b3cf3e8f190b82327615951dda9673..308635f05aaa37167b097202b586f8fe6c9ba5c7 100644 (file)
@@ -422,6 +422,8 @@ float autocvar_g_balance_laser_secondary_force_zscale;
 float autocvar_g_balance_laser_secondary_lifetime;
 float autocvar_g_balance_laser_secondary_radius;
 float autocvar_g_balance_laser_secondary_speed;
+float autocvar_g_balance_laser_reload_count;
+float autocvar_g_balance_laser_reload_time;
 float autocvar_g_balance_minelayer_ammo;
 float autocvar_g_balance_minelayer_animtime;
 float autocvar_g_balance_minelayer_damage;
index c4b5220b9bdee134555ff5dc85c9271f8b5a31bc..183f31fe6b5668e25eb8f3170b536c5834cb7c09 100644 (file)
@@ -890,6 +890,7 @@ void PutClientInServer (void)
                }
 
                // all weapons must be fully loaded the first time we pick them up, so set their load to maximum at respawn
+               self.laser_load = autocvar_g_balance_laser_reload_count;
                self.shotgun_load = autocvar_g_balance_shotgun_reload_ammo;
                self.sniperrifle_load = autocvar_g_balance_sniperrifle_reload_ammo;
                self.uzi_load = autocvar_g_balance_uzi_reload_ammo;
index 736c7a8dbd19a19539b02622319a422e2235065e..0dde022e8ac82fd7e26800a3405259b7cae154b4 100644 (file)
@@ -4,6 +4,53 @@ REGISTER_WEAPON(LASER, w_laser, 0, 1, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_
 #ifdef SVQC
 void(float imp) W_SwitchWeapon;
 
+.float laser_load;
+
+void W_Laser_SetAmmoCounter()
+{
+       // set clip_load to the weapon we have switched to, if the gun uses reloading
+       if(!autocvar_g_balance_laser_reload_count)
+               self.clip_load = 0; // also keeps crosshair ammo from displaying
+       else
+       {
+               self.clip_load = self.laser_load;
+               self.clip_size = autocvar_g_balance_laser_reload_count; // for the crosshair ammo display
+       }
+}
+
+void W_Laser_ReloadedAndReady()
+{
+       float t;
+
+       self.clip_load = autocvar_g_balance_laser_reload_count; // maximum load since this weapon uses no ammo
+       self.laser_load = self.clip_load;
+
+       t = ATTACK_FINISHED(self) - autocvar_g_balance_laser_reload_time - 1;
+       ATTACK_FINISHED(self) = t;
+       w_ready();
+}
+
+void W_Laser_Reload()
+{
+       // return if reloading is disabled for this weapon
+       if(!autocvar_g_balance_laser_reload_count)
+               return;
+
+       if(!W_ReloadCheck(1, 0))
+               return;
+
+       float t;
+
+       sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
+
+       t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_laser_reload_time + 1;
+       ATTACK_FINISHED(self) = t;
+
+       weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_laser_reload_time, W_Laser_ReloadedAndReady);
+
+       self.clip_load = -1;
+}
+
 void W_Laser_Touch (void)
 {
        PROJECTILE_TOUCH;
@@ -226,16 +273,40 @@ float w_laser(float req)
        }
        else if (req == WR_THINK)
        {
-               if (self.BUTTON_ATCK)
-               if (weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
+               if(autocvar_g_balance_laser_reload_count && self.clip_load < 1) // forced reload
+                       W_Laser_Reload();
+               else if (self.BUTTON_ATCK)
                {
-                       W_Laser_Attack(0);
-                       weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
+                       if (weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
+                       {
+                               // if this weapon is reloadable, decrease its load
+                               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+                               {
+                                       if(autocvar_g_balance_laser_reload_count)
+                                       {
+                                               self.clip_load -= 1;
+                                               self.laser_load = self.clip_load;
+                                       }
+                               }
+
+                               W_Laser_Attack(0);
+                               weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
+                       }
                }
-               if (self.BUTTON_ATCK2)
+               else if (self.BUTTON_ATCK2)
                {
                        if(autocvar_g_balance_laser_secondary)
                        {
+                               // if this weapon is reloadable, decrease its load
+                               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+                               {
+                                       if(autocvar_g_balance_laser_reload_count)
+                                       {
+                                               self.clip_load -= 1;
+                                               self.laser_load = self.clip_load;
+                                       }
+                               }
+
                                if (weapon_prepareattack(0, 0))
                                {
                                        W_Laser_Attack2();
@@ -248,6 +319,17 @@ float w_laser(float req)
                                        W_SwitchWeapon (self.cnt);
                        }
                }
+        if(self.wish_reload)
+        {
+            if(self.switchweapon == self.weapon)
+            {
+                if(self.weaponentity.state == WS_READY)
+                {
+                    self.wish_reload = 0;
+                    W_Laser_Reload();
+                }
+            }
+        }
        }
        else if (req == WR_PRECACHE)
        {
@@ -258,11 +340,16 @@ float w_laser(float req)
                precache_sound ("weapons/gauntlet_fire.wav");
        }
        else if (req == WR_SETUP)
+       {
                weapon_setup(WEP_LASER);
+               W_Laser_SetAmmoCounter();
+       }
        else if (req == WR_CHECKAMMO1)
                return TRUE;
        else if (req == WR_CHECKAMMO2)
                return TRUE;
+       else if (req == WR_RELOAD)
+               W_Laser_Reload();
        return TRUE;
 };
 #endif