Move addinventory command code into its own function.

git-svn-id: https://svn.eduke32.com/eduke32@6320 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2017-07-05 05:38:02 +00:00
parent 57a7802f6c
commit fb337a80b1
3 changed files with 53 additions and 43 deletions

View file

@ -911,6 +911,49 @@ static int VM_AddWeapon(DukePlayer_t * const pPlayer, int const weaponNum, int c
return 0; 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 #endif
static int32_t A_GetVerticalVel(actor_t const * const pActor) static int32_t A_GetVerticalVel(actor_t const * const pActor)
@ -3563,50 +3606,12 @@ nullquote:
continue; continue;
case CON_ADDINVENTORY: case CON_ADDINVENTORY:
{
insptr += 2; 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++; insptr++;
continue; continue;
}
case CON_HITRADIUSVAR: case CON_HITRADIUSVAR:
insptr++; insptr++;

View file

@ -52,11 +52,9 @@ enum dukeinvicon_t
ICON_MAX ICON_MAX
}; };
static int const icon_to_inv[ICON_MAX] = { GET_FIRSTAID, GET_FIRSTAID, GET_STEROIDS, GET_HOLODUKE, extern int const icon_to_inv[ICON_MAX];
GET_JETPACK, GET_HEATS, GET_SCUBA, GET_BOOTS };
static int const inv_to_icon[GET_MAX] = { ICON_STEROIDS, ICON_NONE, ICON_SCUBA, ICON_HOLODUKE, ICON_JETPACK, ICON_NONE, extern int const inv_to_icon[GET_MAX];
ICON_NONE, ICON_HEATS, ICON_NONE, ICON_FIRSTAID, ICON_BOOTS };
enum dukeweapon_t enum dukeweapon_t
{ {

View file

@ -40,6 +40,13 @@ extern int32_t g_levelTextTime, ticrandomseed;
int32_t g_numObituaries = 0; int32_t g_numObituaries = 0;
int32_t g_numSelfObituaries = 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) void P_AddKills(DukePlayer_t * const pPlayer, uint16_t kills)
{ {
pPlayer->actors_killed += kills; pPlayer->actors_killed += kills;