From fb337a80b101c569ec02d55c1aa027b1d1e92c1e Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 5 Jul 2017 05:38:02 +0000 Subject: [PATCH] Move addinventory command code into its own function. git-svn-id: https://svn.eduke32.com/eduke32@6320 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gameexec.cpp | 83 ++++++++++++++++++---------------- source/duke3d/src/inv.h | 6 +-- source/duke3d/src/player.cpp | 7 +++ 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index c14aba868..77860e668 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -911,6 +911,49 @@ static int VM_AddWeapon(DukePlayer_t * const pPlayer, int const weaponNum, int c return 0; } + +static void VM_AddInventory(DukePlayer_t * const pPlayer, int const itemNum, int const nAmount) +{ + switch (itemNum) + { + case GET_STEROIDS: + case GET_SCUBA: + case GET_HOLODUKE: + case GET_JETPACK: + case GET_HEATS: + case GET_FIRSTAID: + case GET_BOOTS: + pPlayer->inven_icon = inv_to_icon[itemNum]; + pPlayer->inv_amount[itemNum] = nAmount; + break; + + case GET_SHIELD: + { + int16_t & shield_amount = pPlayer->inv_amount[GET_SHIELD]; + shield_amount = min(shield_amount + nAmount, pPlayer->max_shield_amount); + break; + } + + case GET_ACCESS: + switch (vm.pSprite->pal) + { + case 0: + pPlayer->got_access |= 1; + break; + case 21: + pPlayer->got_access |= 2; + break; + case 23: + pPlayer->got_access |= 4; + break; + } + break; + + default: + CON_ERRPRINTF("Invalid inventory ID %d\n", itemNum); + break; + } +} #endif static int32_t A_GetVerticalVel(actor_t const * const pActor) @@ -3563,50 +3606,12 @@ nullquote: continue; case CON_ADDINVENTORY: - { insptr += 2; - int const item = *(insptr-1); + VM_AddInventory(pPlayer, *(insptr-1), *insptr); - switch (item) - { - case GET_STEROIDS: - case GET_SCUBA: - case GET_HOLODUKE: - case GET_JETPACK: - case GET_HEATS: - case GET_FIRSTAID: - case GET_BOOTS: - pPlayer->inven_icon = inv_to_icon[item]; - pPlayer->inv_amount[item] = *insptr; - break; - - case GET_SHIELD: - pPlayer->inv_amount[GET_SHIELD] = min(pPlayer->inv_amount[GET_SHIELD] + *insptr, pPlayer->max_shield_amount); - break; - - case GET_ACCESS: - switch (vm.pSprite->pal) - { - case 0: - pPlayer->got_access |= 1; - break; - case 21: - pPlayer->got_access |= 2; - break; - case 23: - pPlayer->got_access |= 4; - break; - } - break; - - default: - CON_ERRPRINTF("Invalid inventory ID %d\n", item); - break; - } insptr++; continue; - } case CON_HITRADIUSVAR: insptr++; diff --git a/source/duke3d/src/inv.h b/source/duke3d/src/inv.h index db1741d56..0a9e563b5 100644 --- a/source/duke3d/src/inv.h +++ b/source/duke3d/src/inv.h @@ -52,11 +52,9 @@ enum dukeinvicon_t ICON_MAX }; -static int const icon_to_inv[ICON_MAX] = { GET_FIRSTAID, GET_FIRSTAID, GET_STEROIDS, GET_HOLODUKE, - GET_JETPACK, GET_HEATS, GET_SCUBA, GET_BOOTS }; +extern int const icon_to_inv[ICON_MAX]; -static int const inv_to_icon[GET_MAX] = { ICON_STEROIDS, ICON_NONE, ICON_SCUBA, ICON_HOLODUKE, ICON_JETPACK, ICON_NONE, - ICON_NONE, ICON_HEATS, ICON_NONE, ICON_FIRSTAID, ICON_BOOTS }; +extern int const inv_to_icon[GET_MAX]; enum dukeweapon_t { diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index 26d54c2b9..953f39229 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -40,6 +40,13 @@ extern int32_t g_levelTextTime, ticrandomseed; int32_t g_numObituaries = 0; int32_t g_numSelfObituaries = 0; + +int const icon_to_inv[ICON_MAX] = { GET_FIRSTAID, GET_FIRSTAID, GET_STEROIDS, GET_HOLODUKE, + GET_JETPACK, GET_HEATS, GET_SCUBA, GET_BOOTS }; + +int const inv_to_icon[GET_MAX] = { ICON_STEROIDS, ICON_NONE, ICON_SCUBA, ICON_HOLODUKE, ICON_JETPACK, ICON_NONE, + ICON_NONE, ICON_HEATS, ICON_NONE, ICON_FIRSTAID, ICON_BOOTS }; + void P_AddKills(DukePlayer_t * const pPlayer, uint16_t kills) { pPlayer->actors_killed += kills;