From 980b2be5843d1bdd20307b0d8fc5901de450067c Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 5 Jul 2017 05:38:05 +0000 Subject: [PATCH] Move addammo into own function. git-svn-id: https://svn.eduke32.com/eduke32@6321 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gameexec.cpp | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index 77860e668..f1778c924 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -889,12 +889,12 @@ static void P_AddWeaponAmmoCommon(DukePlayer_t * const pPlayer, int const weapon P_AddWeaponMaybeSwitch(pPlayer, weaponNum); } -static int VM_AddWeapon(DukePlayer_t * const pPlayer, int const weaponNum, int const nAmount) +static void VM_AddWeapon(DukePlayer_t * const pPlayer, int const weaponNum, int const nAmount) { if (EDUKE32_PREDICT_FALSE((unsigned)weaponNum >= MAX_WEAPONS)) { CON_ERRPRINTF("Invalid weapon ID %d\n", weaponNum); - return 1; + return; } if ((pPlayer->gotweapon & (1 << weaponNum)) == 0) @@ -904,12 +904,27 @@ static int VM_AddWeapon(DukePlayer_t * const pPlayer, int const weaponNum, int c else if (pPlayer->ammo_amount[weaponNum] >= pPlayer->max_ammo_amount[weaponNum]) { vm.flags |= VM_NOEXECUTE; - return 2; + return; } P_AddWeaponAmmoCommon(pPlayer, weaponNum, nAmount); +} - return 0; +static void VM_AddAmmo(DukePlayer_t * const pPlayer, int const weaponNum, int const nAmount) +{ + if (EDUKE32_PREDICT_FALSE((unsigned)weaponNum >= MAX_WEAPONS)) + { + CON_ERRPRINTF("Invalid weapon ID %d\n", weaponNum); + return; + } + + if (pPlayer->ammo_amount[weaponNum] >= pPlayer->max_ammo_amount[weaponNum]) + { + vm.flags |= VM_NOEXECUTE; + return; + } + + P_AddWeaponAmmoCommon(pPlayer, weaponNum, nAmount); } static void VM_AddInventory(DukePlayer_t * const pPlayer, int const itemNum, int const nAmount) @@ -1732,19 +1747,7 @@ skip_check: int const weaponNum = *insptr++; int const addAmount = *insptr++; - if (EDUKE32_PREDICT_FALSE((unsigned)weaponNum >= MAX_WEAPONS)) - { - CON_ERRPRINTF("Invalid weapon ID %d\n", weaponNum); - break; - } - - if (pPlayer->ammo_amount[weaponNum] >= pPlayer->max_ammo_amount[weaponNum]) - { - vm.flags |= VM_NOEXECUTE; - return; - } - - P_AddWeaponAmmoCommon(pPlayer, weaponNum, addAmount); + VM_AddAmmo(pPlayer, weaponNum, addAmount); continue; }