From b4c80fa2d1073436bf9cf31ad3e6a14a86449b2a Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 22 Feb 2019 19:13:05 +0100 Subject: [PATCH] Refactor Item_GiveAmmoTo a little bit to reduce duplicated code --- qcsrc/common/t_items.qc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index bce35c7dd..c309ed35d 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -743,23 +743,16 @@ bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax) if (item.spawnshieldtime) { if ((player_amount >= ammomax) && (item.pickup_anyway <= 0)) - { return false; - } - if (amount < 0) - TakeResourceWithLimit(player, res_type, -amount, ammomax); - else - GiveResourceWithLimit(player, res_type, amount, ammomax); - return true; } - if (g_weapon_stay != 2) - { + else if (g_weapon_stay == 2) + ammomax = min(amount, ammomax); + else return false; - } if (amount < 0) - TakeResourceWithLimit(player, res_type, -amount, min(amount, ammomax)); + TakeResourceWithLimit(player, res_type, -amount, ammomax); else - GiveResourceWithLimit(player, res_type, amount, min(amount, ammomax)); + GiveResourceWithLimit(player, res_type, amount, ammomax); return true; } -- 2.39.2