From 6aca7604eb37ba8e436261015603b4c9a2f1d311 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Thu, 21 Apr 2016 16:00:34 +0200 Subject: [PATCH] - Clean the code by using AActor::GiveInventory. This fixes also a bug in FraggleScript GiveInventory, which tried to access the 'SaveAmount' member of 'ABasicArmorBonus' with the wrong cast. --- src/fragglescript/t_func.cpp | 27 +------------------ src/m_cheat.cpp | 51 ++++-------------------------------- src/p_acs.cpp | 46 ++------------------------------ src/p_conversation.cpp | 2 -- 4 files changed, 8 insertions(+), 118 deletions(-) diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 4826a6ca4f..5d4320a4f9 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -2439,32 +2439,7 @@ static void FS_GiveInventory (AActor *actor, const char * type, int amount) return; } - AWeapon *savedPendingWeap = actor->player != NULL? actor->player->PendingWeapon : NULL; - bool hadweap = actor->player != NULL ? actor->player->ReadyWeapon != NULL : true; - - AInventory *item = static_cast(Spawn (info)); - - // This shouldn't count for the item statistics! - item->ClearCounters(); - if (info->IsDescendantOf (RUNTIME_CLASS(ABasicArmorPickup)) || - info->IsDescendantOf (RUNTIME_CLASS(ABasicArmorBonus))) - { - static_cast(item)->SaveAmount *= amount; - } - else - { - item->Amount = amount; - } - if (!item->CallTryPickup (actor)) - { - item->Destroy (); - } - // If the item was a weapon, don't bring it up automatically - // unless the player was not already using a weapon. - if (savedPendingWeap != NULL && hadweap) - { - actor->player->PendingWeapon = savedPendingWeap; - } + actor->GiveInventory(info, amount); } //============================================================================ diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index c9b4781616..d7622b3d47 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -575,47 +575,6 @@ const char *cht_Morph (player_t *player, PClassPlayerPawn *morphclass, bool quic return ""; } -void GiveSpawner (player_t *player, PClassInventory *type, int amount) -{ - if (player->mo == NULL || player->health <= 0) - { - return; - } - - AInventory *item = static_cast - (Spawn (type, player->mo->Pos(), NO_REPLACE)); - if (item != NULL) - { - if (amount > 0) - { - if (type->IsDescendantOf (RUNTIME_CLASS(ABasicArmorPickup))) - { - if (static_cast(item)->SaveAmount != 0) - { - static_cast(item)->SaveAmount *= amount; - } - else - { - static_cast(item)->SaveAmount *= amount; - } - } - else if (type->IsDescendantOf (RUNTIME_CLASS(ABasicArmorBonus))) - { - static_cast(item)->SaveAmount *= amount; - } - else - { - item->Amount = MIN (amount, item->MaxAmount); - } - } - item->ClearCounters(); - if (!item->CallTryPickup (player->mo)) - { - item->Destroy (); - } - } -} - void cht_Give (player_t *player, const char *name, int amount) { enum { ALL_NO, ALL_YES, ALL_YESYES } giveall; @@ -673,7 +632,7 @@ void cht_Give (player_t *player, const char *name, int amount) type = PClass::FindActor(gameinfo.backpacktype); if (type != NULL) { - GiveSpawner (player, static_cast(type), 1); + player->mo->GiveInventory(static_cast(type), 1, true); } if (!giveall) @@ -778,7 +737,7 @@ void cht_Give (player_t *player, const char *name, int amount) AWeapon *def = (AWeapon*)GetDefaultByType (type); if (giveall == ALL_YESYES || !(def->WeaponFlags & WIF_CHEATNOTWEAPON)) { - GiveSpawner (player, static_cast(type), 1); + player->mo->GiveInventory(static_cast(type), 1, true); } } } @@ -805,7 +764,7 @@ void cht_Give (player_t *player, const char *name, int amount) // Do not give replaced items unless using "give everything" if (giveall == ALL_YESYES || type->GetReplacement() == type) { - GiveSpawner (player, static_cast(type), amount <= 0 ? def->MaxAmount : amount); + player->mo->GiveInventory(static_cast(type), amount <= 0 ? def->MaxAmount : amount, true); } } } @@ -827,7 +786,7 @@ void cht_Give (player_t *player, const char *name, int amount) // Do not give replaced items unless using "give everything" if (giveall == ALL_YESYES || type->GetReplacement() == type) { - GiveSpawner (player, static_cast(type), amount <= 0 ? def->MaxAmount : amount); + player->mo->GiveInventory(static_cast(type), amount <= 0 ? def->MaxAmount : amount, true); } } } @@ -847,7 +806,7 @@ void cht_Give (player_t *player, const char *name, int amount) } else { - GiveSpawner (player, static_cast(type), amount); + player->mo->GiveInventory(static_cast(type), amount, true); } return; } diff --git a/src/p_acs.cpp b/src/p_acs.cpp index e56aeb5963..0437bc9f03 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1142,48 +1142,6 @@ static void ClearInventory (AActor *activator) } } -//============================================================================ -// -// DoGiveInv -// -// Gives an item to a single actor. -// -//============================================================================ - -static void DoGiveInv (AActor *actor, PClassActor *info, int amount) -{ - AWeapon *savedPendingWeap = actor->player != NULL - ? actor->player->PendingWeapon : NULL; - bool hadweap = actor->player != NULL ? actor->player->ReadyWeapon != NULL : true; - - AInventory *item = static_cast(Spawn (info)); - - // This shouldn't count for the item statistics! - item->ClearCounters(); - if (info->IsDescendantOf (RUNTIME_CLASS(ABasicArmorPickup))) - { - static_cast(item)->SaveAmount *= amount; - } - else if (info->IsDescendantOf (RUNTIME_CLASS(ABasicArmorBonus))) - { - static_cast(item)->SaveAmount *= amount; - } - else - { - item->Amount = amount; - } - if (!item->CallTryPickup (actor)) - { - item->Destroy (); - } - // If the item was a weapon, don't bring it up automatically - // unless the player was not already using a weapon. - if (savedPendingWeap != NULL && hadweap && actor->player != NULL) - { - actor->player->PendingWeapon = savedPendingWeap; - } -} - //============================================================================ // // GiveInventory @@ -1218,12 +1176,12 @@ static void GiveInventory (AActor *activator, const char *type, int amount) for (int i = 0; i < MAXPLAYERS; ++i) { if (playeringame[i]) - DoGiveInv (players[i].mo, info, amount); + players[i].mo->GiveInventory(static_cast(info), amount); } } else { - DoGiveInv (activator, info, amount); + activator->GiveInventory(static_cast(info), amount); } } diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index e8aaa6912c..64fe2cbab2 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -102,8 +102,6 @@ struct TeaserSpeech static FRandom pr_randomspeech("RandomSpeech"); -void GiveSpawner (player_t *player, PClassActor *type); - TArray StrifeDialogues; typedef TMap FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS)