]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Port reload code over to the UZI
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Fri, 21 Jan 2011 18:40:30 +0000 (20:40 +0200)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Fri, 21 Jan 2011 18:40:30 +0000 (20:40 +0200)
balanceXonotic.cfg
qcsrc/server/autocvars.qh
qcsrc/server/cl_client.qc
qcsrc/server/w_shotgun.qc
qcsrc/server/w_sniperrifle.qc
qcsrc/server/w_uzi.qc

index 284ae42f3a3adc554bafe8c06b746ee7171302c4..01836ee7916027ee004afb2c09167dbc17b34782 100644 (file)
@@ -296,6 +296,9 @@ set g_balance_uzi_sustained_ammo 1
 
 set g_balance_uzi_speed 18000
 set g_balance_uzi_bulletconstant 115 // 13.1qu
+
+set g_balance_uzi_reload_ammo 30
+set g_balance_uzi_reload_time 2
 // }}}
 // {{{ mortar
 set g_balance_grenadelauncher_primary_type 0
index 4a9476bb576e7db85e9f3e5e4e545206774aaa76..684a81be9c4b81899df298848a1280ccbad2d673 100644 (file)
@@ -646,6 +646,8 @@ float autocvar_g_balance_uzi_sustained_damage;
 float autocvar_g_balance_uzi_sustained_force;
 float autocvar_g_balance_uzi_sustained_refire;
 float autocvar_g_balance_uzi_sustained_spread;
+float autocvar_g_balance_uzi_reload_ammo;
+float autocvar_g_balance_uzi_reload_time;
 float autocvar_g_balance_weaponswitchdelay;
 float autocvar_g_ballistics_density_corpse;
 float autocvar_g_ballistics_density_player;
index 5522eb805eb01d28e7dd569610b041361a35988b..a1133cd2a1b79bcd2a9bc8ca02780ad34810e70d 100644 (file)
@@ -892,6 +892,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.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;
 
                if(inWarmupStage)
                {
index 4cfd5b4bd336af6d953dd28bdc21bb7036448801..54043a9b430d8b92130fb58ed496b184821f25ab 100644 (file)
@@ -103,13 +103,13 @@ void W_Shotgun_Attack (void)
        // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
        {
-               if(!autocvar_g_balance_shotgun_reload_ammo)
-                       self.ammo_shells -= ammoamount;
-               else
+               if(autocvar_g_balance_shotgun_reload_ammo)
                {
                        self.clip_load -= ammoamount;
                        self.shotgun_load = self.clip_load;
                }
+               else
+                       self.ammo_shells -= ammoamount;
        }
 }
 
index 502fd3a53817e1a81d5dd132b5563fce87f36507..22da48052d8be028f46cb2f40a0a9bca84e18676 100644 (file)
@@ -88,13 +88,13 @@ void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAdded
        // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
        {
-               if(!autocvar_g_balance_sniperrifle_reload_ammo)
-                       self.ammo_nails -= pAmmo;
-               else
+               if(autocvar_g_balance_sniperrifle_reload_ammo)
                {
                        self.clip_load -= pAmmo;
                        self.sniperrifle_load = self.clip_load;
                }
+               else
+                       self.ammo_nails -= pAmmo;
        }
 }
 
index 01d76821bb85a4835084728f716a01a1d791dd47..cda7d52348bb3f9325af5ed44a566548aa99dc8d 100644 (file)
@@ -3,6 +3,60 @@ REGISTER_WEAPON(UZI, w_uzi, IT_NAILS, 3, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT
 #else
 #ifdef SVQC
 
+.float uzi_load;
+
+void W_Uzi_SetAmmoCounter()
+{
+       // set clip_load to the weapon we have switched to, if the gun uses reloading
+       if(!autocvar_g_balance_uzi_reload_ammo)
+               self.clip_load = 0; // also keeps crosshair ammo from displaying
+       else
+       {
+               self.clip_load = self.uzi_load;
+               self.clip_size = autocvar_g_balance_uzi_reload_ammo; // for the crosshair ammo display
+       }
+}
+
+void W_Uzi_ReloadedAndReady()
+{
+       float t;
+
+       // now do the ammo transfer
+       self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
+       while(self.clip_load < autocvar_g_balance_uzi_reload_ammo && self.ammo_nails) // make sure we don't add more ammo than we have
+       {
+               self.clip_load += 1;
+               self.ammo_nails -= 1;
+       }
+       self.uzi_load = self.clip_load;
+
+       t = ATTACK_FINISHED(self) - autocvar_g_balance_uzi_reload_time - 1;
+       ATTACK_FINISHED(self) = t;
+       w_ready();
+}
+
+void W_Uzi_Reload()
+{
+       // return if reloading is disabled for this weapon
+       if(!autocvar_g_balance_uzi_reload_ammo)
+               return;
+
+       if(!W_ReloadCheck(self.ammo_nails))
+               return;
+
+       float t;
+
+       sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
+
+       t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_uzi_reload_time + 1;
+       ATTACK_FINISHED(self) = t;
+
+       weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_uzi_reload_time, W_Uzi_ReloadedAndReady);
+
+       self.old_clip_load = self.clip_load;
+       self.clip_load = -1;
+}
+
 // leilei's fancy muzzleflash stuff
 void Uzi_Flash_Go() 
 {      
@@ -41,13 +95,9 @@ void UziFlash()
 
 void W_Uzi_Attack (float deathtype)
 {
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-       {
-               if (self.misc_bulletcounter == 1)
-                       self.ammo_nails = self.ammo_nails - autocvar_g_balance_uzi_first_ammo;
-               else
-                       self.ammo_nails = self.ammo_nails - autocvar_g_balance_uzi_sustained_ammo;
-       }
+       if(autocvar_g_balance_uzi_reload_ammo && self.clip_load <= 0)
+               return; // reloading, so we are done
+
        W_SetupShot (self, autocvar_g_antilag_bullets && autocvar_g_balance_uzi_speed >= autocvar_g_antilag_bullets, 0, "weapons/uzi_fire.wav", CHAN_WEAPON, ((self.misc_bulletcounter == 1) ? autocvar_g_balance_uzi_first_damage : autocvar_g_balance_uzi_sustained_damage));
        if (!g_norecoil)
        {
@@ -72,6 +122,26 @@ void W_Uzi_Attack (float deathtype)
        // casing code
        if (autocvar_g_casings >= 2)
                SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
+
+       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
+       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+       {
+               if(autocvar_g_balance_uzi_reload_ammo)
+               {
+                       if (self.misc_bulletcounter == 1)
+                               self.clip_load -= autocvar_g_balance_uzi_first_ammo;
+                       else
+                               self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
+                       self.uzi_load = self.clip_load;
+               }
+               else
+               {
+                       if (self.misc_bulletcounter == 1)
+                               self.ammo_nails -= autocvar_g_balance_uzi_first_ammo;
+                       else
+                               self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
+               }
+       }
 }
 
 // weapon frames
@@ -139,10 +209,18 @@ void uzi_mode1_fire_auto()
        
        if (autocvar_g_casings >= 2) // casing code
                SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
-       
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)   
-               self.ammo_nails = self.ammo_nails - autocvar_g_balance_uzi_sustained_ammo;
-       
+
+       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
+       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+       {
+               if(autocvar_g_balance_uzi_reload_ammo)
+               {
+                       self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
+                       self.uzi_load = self.clip_load;
+               }
+               else
+                       self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
+       }
 }
 
 void uzi_mode1_fire_burst()
@@ -192,7 +270,9 @@ float w_uzi(float req)
                }
        else if (req == WR_THINK)
        {
-               if(autocvar_g_balance_uzi_mode == 1)
+               if(autocvar_g_balance_uzi_reload_ammo && self.clip_load <= 0) // forced reload
+                       W_Uzi_Reload();
+               else if(autocvar_g_balance_uzi_mode == 1)
                {
                        if (self.BUTTON_ATCK)
                        if (weapon_prepareattack(0, 0))
@@ -210,9 +290,18 @@ float w_uzi(float req)
                                        w_ready();
                                        return FALSE;
                                }
-                               
-                               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)   
-                                       self.ammo_nails = self.ammo_nails - autocvar_g_balance_uzi_burst_ammo;
+
+                               // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
+                               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+                               {
+                                       if(autocvar_g_balance_uzi_reload_ammo)
+                                       {
+                                               self.clip_load -= autocvar_g_balance_uzi_burst_ammo;
+                                               self.uzi_load = self.clip_load;
+                                       }
+                                       else
+                                               self.ammo_nails -= autocvar_g_balance_uzi_burst_ammo;
+                               }
 
                                self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
                                uzi_mode1_fire_burst();
@@ -237,6 +326,17 @@ float w_uzi(float req)
                                weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
                        }
                }
+        if(self.wish_reload)
+        {
+            if(self.switchweapon == self.weapon)
+            {
+                if(self.weaponentity.state == WS_READY)
+                {
+                    self.wish_reload = 0;
+                    W_Uzi_Reload();
+                }
+            }
+        }
        }
        else if (req == WR_PRECACHE)
        {
@@ -247,17 +347,28 @@ float w_uzi(float req)
                precache_sound ("weapons/uzi_fire.wav");
        }
        else if (req == WR_SETUP)
+       {
                weapon_setup(WEP_UZI);
+               W_Uzi_SetAmmoCounter();
+       }
        else if (req == WR_CHECKAMMO1)
+       {
                if(autocvar_g_balance_uzi_mode == 1)
                        return self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
                else
                        return self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
+       }
        else if (req == WR_CHECKAMMO2)
+       {
                if(autocvar_g_balance_uzi_mode == 1)
                        return self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
                else
                        return self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
+       }
+       else if (req == WR_RELOAD)
+       {
+               W_Uzi_Reload();
+       }
        return TRUE;
 };
 #endif