From f0eba13f77d633a4bd987de3626c026853799b52 Mon Sep 17 00:00:00 2001 From: Mircea Kitsune Date: Fri, 21 Jan 2011 01:43:56 +0200 Subject: [PATCH] Make the reload code use the proper type of ammo --- qcsrc/server/cl_weaponsystem.qc | 46 +++++++++++++++++++++++++-------- qcsrc/server/w_shotgun.qc | 13 ++++++++-- qcsrc/server/w_sniperrifle.qc | 10 ++++++- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/qcsrc/server/cl_weaponsystem.qc b/qcsrc/server/cl_weaponsystem.qc index bd1612536..8c510bba7 100644 --- a/qcsrc/server/cl_weaponsystem.qc +++ b/qcsrc/server/cl_weaponsystem.qc @@ -1616,6 +1616,37 @@ void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread) // weapon reload code // ---------------------------------------------------------------- +float ammo_amount; +void W_SniperRifle_Ammo(string ammo_string, float ammo_reduce) +{ + // sets ammo_amount to our current ammo level, and can optionally reduce ammo + switch(ammo_string) + { + case "shells": + ammo_amount = self.ammo_shells; + self.ammo_shells -= ammo_reduce; + return; + case "nails": + ammo_amount = self.ammo_nails; + self.ammo_nails -= ammo_reduce; + return; + case "cells": + ammo_amount = self.ammo_cells; + self.ammo_cells -= ammo_reduce; + return; + case "rockets": + ammo_amount = self.ammo_rockets; + self.ammo_rockets -= ammo_reduce; + return; + case "fuel": + ammo_amount = self.ammo_fuel; + self.ammo_fuel -= ammo_reduce; + return; + default: + return; + } +} + float W_SniperRifle_CheckMaxBullets(float checkammo) { float maxbulls; @@ -1624,7 +1655,7 @@ float W_SniperRifle_CheckMaxBullets(float checkammo) 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))); + maxbulls = min(maxbulls, floor(ammo_amount / 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); @@ -1640,13 +1671,14 @@ void W_SniperRifle_ReloadedAndReady() w_ready(); } -float W_SniperRifle_Reload() +float W_SniperRifle_Reload(string ammo_type) { 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 + W_SniperRifle_Ammo(ammo_type, 0); // set ammo_amount to the ammo type specified + if(ammo_amount < 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 @@ -1678,14 +1710,6 @@ float W_SniperRifle_Reload() 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/w_shotgun.qc b/qcsrc/server/w_shotgun.qc index 9b914794c..470acac34 100644 --- a/qcsrc/server/w_shotgun.qc +++ b/qcsrc/server/w_shotgun.qc @@ -2,6 +2,15 @@ REGISTER_WEAPON(SHOTGUN, w_shotgun, IT_SHELLS, 2, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_LOW, "shotgun", "shotgun", _("Shotgun")) #else #ifdef SVQC + +void W_Shotgun_CheckReloadAndReady() +{ + w_ready(); + if(self.sniperrifle_bulletcounter <= 0) + if(W_SniperRifle_Reload("shells")) + return; +} + void W_Shotgun_Attack (void) { float sc; @@ -14,7 +23,7 @@ void W_Shotgun_Attack (void) float bulletconstant; local entity flash; - W_SniperRifle_CheckReloadAndReady(); + W_Shotgun_CheckReloadAndReady(); if(self.sniperrifle_bulletcounter < 0) return; // reloading, so we are done @@ -144,7 +153,7 @@ float w_shotgun(float req) if(self.weaponentity.state == WS_READY) { self.wish_reload = 0; - W_SniperRifle_Reload(); + W_SniperRifle_Reload("shells"); } } } diff --git a/qcsrc/server/w_sniperrifle.qc b/qcsrc/server/w_sniperrifle.qc index 102769aa5..655c1204a 100644 --- a/qcsrc/server/w_sniperrifle.qc +++ b/qcsrc/server/w_sniperrifle.qc @@ -8,6 +8,14 @@ REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_T .float sniperrifle_accumulator; +void W_SniperRifle_CheckReloadAndReady() +{ + w_ready(); + if(self.sniperrifle_bulletcounter <= 0) + if(W_SniperRifle_Reload("nails")) + 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) @@ -180,7 +188,7 @@ float w_sniperrifle(float req) if(self.weaponentity.state == WS_READY) { self.wish_reload = 0; - W_SniperRifle_Reload(); + W_SniperRifle_Reload("nails"); } } } -- 2.39.2