]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
First step in a common reload system for all weapons. Move the campingrifle reload...
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Thu, 20 Jan 2011 21:54:07 +0000 (23:54 +0200)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Thu, 20 Jan 2011 21:54:07 +0000 (23:54 +0200)
qcsrc/server/cl_weaponsystem.qc
qcsrc/server/cl_weaponsystem.qh [new file with mode: 0644]
qcsrc/server/progs.src
qcsrc/server/w_sniperrifle.qc

index 057c5cb1dc767fde25d85b66a61ca8ee519cbf32..bd161253669311b8d5affb45bb53013b80adf69b 100644 (file)
@@ -1611,3 +1611,81 @@ void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread)
 
 #define W_SETUPPROJECTILEVELOCITY_UP(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), cvar(#s "_speed_up"), cvar(#s "_speed_z"), cvar(#s "_spread"), FALSE)
 #define W_SETUPPROJECTILEVELOCITY(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), 0, 0, cvar(#s "_spread"), FALSE)
+
+// ----------------------------------------------------------------
+// weapon reload code
+// ----------------------------------------------------------------
+
+float W_SniperRifle_CheckMaxBullets(float checkammo)
+{
+       float maxbulls;
+       maxbulls = autocvar_g_balance_sniperrifle_magazinecapacity;
+       if(!maxbulls)
+               maxbulls = 8; // match HUD
+       if(checkammo)
+               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+                       maxbulls = min(maxbulls, floor(self.ammo_nails / min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo)));
+       if(self.sniperrifle_bulletcounter > maxbulls || !autocvar_g_balance_sniperrifle_magazinecapacity)
+               self.sniperrifle_bulletcounter = maxbulls;
+       return (self.sniperrifle_bulletcounter == maxbulls);
+}
+
+void W_SniperRifle_ReloadedAndReady()
+{
+       float t;
+       self.sniperrifle_bulletcounter = autocvar_g_balance_sniperrifle_magazinecapacity;
+       W_SniperRifle_CheckMaxBullets(TRUE);
+       t = ATTACK_FINISHED(self) - autocvar_g_balance_sniperrifle_reloadtime - 1;
+       ATTACK_FINISHED(self) = t;
+       w_ready();
+}
+
+float W_SniperRifle_Reload()
+{
+       float t;
+
+       W_SniperRifle_CheckMaxBullets(TRUE);
+
+       if(self.ammo_nails < min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo)) // when we get here, bulletcounter must be 0 or -1
+       {
+               print("cannot reload... not enough bullets\n");
+               self.sniperrifle_bulletcounter = -1; // reload later
+               W_SwitchToOtherWeapon(self);
+               return 0;
+       }
+       
+       if (self.sniperrifle_bulletcounter >= autocvar_g_balance_sniperrifle_magazinecapacity)
+               return 0;
+
+       if (self.weaponentity)
+       {
+               if (self.weaponentity.wframe == WFRAME_RELOAD)
+                       return 0;
+
+               // allow to switch away while reloading, but this will cause a new reload!
+               self.weaponentity.state = WS_READY;
+       }
+
+       sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM);
+
+       t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_sniperrifle_reloadtime + 1;
+       ATTACK_FINISHED(self) = t;
+
+       weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_sniperrifle_reloadtime, W_SniperRifle_ReloadedAndReady);
+
+       self.sniperrifle_bulletcounter = -1;
+
+       return 1;
+}
+
+void W_SniperRifle_CheckReloadAndReady()
+{
+       w_ready();
+       if(self.sniperrifle_bulletcounter <= 0)
+               if(W_SniperRifle_Reload())
+                       return;
+}
+
+// ----------------------------------------------------------------
+// end of weapon reload code
+// ----------------------------------------------------------------
\ No newline at end of file
diff --git a/qcsrc/server/cl_weaponsystem.qh b/qcsrc/server/cl_weaponsystem.qh
new file mode 100644 (file)
index 0000000..6ba450a
--- /dev/null
@@ -0,0 +1 @@
+void W_SniperRifle_CheckReloadAndReady();
\ No newline at end of file
index c76395fdbc27df7bdd26371a491fe1da65064276..ad13a4f18cf83969770a27c02ed7b1740cbef56c 100644 (file)
@@ -38,6 +38,7 @@ campaign.qh
 accuracy.qh
 csqcprojectile.qh
 csqceffects.qc
+cl_weaponsystem.qh
 
 anticheat.qh
 cheats.qh
index 68dec352d91c8b90fe096ad8083c9fe354da6f65..102769aa5933554824cee48255a9d8c1500ec0d6 100644 (file)
@@ -8,76 +8,6 @@ REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_T
 
 .float sniperrifle_accumulator;
 
-float W_SniperRifle_CheckMaxBullets(float checkammo)
-{
-       float maxbulls;
-       maxbulls = autocvar_g_balance_sniperrifle_magazinecapacity;
-       if(!maxbulls)
-               maxbulls = 8; // match HUD
-       if(checkammo)
-               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-                       maxbulls = min(maxbulls, floor(self.ammo_nails / min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo)));
-       if(self.sniperrifle_bulletcounter > maxbulls || !autocvar_g_balance_sniperrifle_magazinecapacity)
-               self.sniperrifle_bulletcounter = maxbulls;
-       return (self.sniperrifle_bulletcounter == maxbulls);
-}
-
-void W_SniperRifle_ReloadedAndReady()
-{
-       float t;
-       self.sniperrifle_bulletcounter = autocvar_g_balance_sniperrifle_magazinecapacity;
-       W_SniperRifle_CheckMaxBullets(TRUE);
-       t = ATTACK_FINISHED(self) - autocvar_g_balance_sniperrifle_reloadtime - 1;
-       ATTACK_FINISHED(self) = t;
-       w_ready();
-}
-
-float W_SniperRifle_Reload()
-{
-       float t;
-
-       W_SniperRifle_CheckMaxBullets(TRUE);
-
-       if(self.ammo_nails < min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo)) // when we get here, bulletcounter must be 0 or -1
-       {
-               print("cannot reload... not enough bullets\n");
-               self.sniperrifle_bulletcounter = -1; // reload later
-               W_SwitchToOtherWeapon(self);
-               return 0;
-       }
-       
-       if (self.sniperrifle_bulletcounter >= autocvar_g_balance_sniperrifle_magazinecapacity)
-               return 0;
-
-       if (self.weaponentity)
-       {
-               if (self.weaponentity.wframe == WFRAME_RELOAD)
-                       return 0;
-
-               // allow to switch away while reloading, but this will cause a new reload!
-               self.weaponentity.state = WS_READY;
-       }
-
-       sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM);
-
-       t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_sniperrifle_reloadtime + 1;
-       ATTACK_FINISHED(self) = t;
-
-       weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_sniperrifle_reloadtime, W_SniperRifle_ReloadedAndReady);
-
-       self.sniperrifle_bulletcounter = -1;
-
-       return 1;
-}
-
-void W_SniperRifle_CheckReloadAndReady()
-{
-       w_ready();
-       if(self.sniperrifle_bulletcounter <= 0)
-               if(W_SniperRifle_Reload())
-                       return;
-}
-
 void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAddedDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant)
 {
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
@@ -106,7 +36,6 @@ void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAdded
                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);
        
        self.sniperrifle_bulletcounter = self.sniperrifle_bulletcounter - 1;
-       W_SniperRifle_CheckMaxBullets(TRUE);
 }
 
 void W_SniperRifle_Attack()