mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 13:11:33 +00:00
- 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.
This commit is contained in:
parent
7b35f32f3d
commit
6aca7604eb
4 changed files with 8 additions and 118 deletions
|
@ -2439,32 +2439,7 @@ static void FS_GiveInventory (AActor *actor, const char * type, int amount)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AWeapon *savedPendingWeap = actor->player != NULL? actor->player->PendingWeapon : NULL;
|
actor->GiveInventory(info, amount);
|
||||||
bool hadweap = actor->player != NULL ? actor->player->ReadyWeapon != NULL : true;
|
|
||||||
|
|
||||||
AInventory *item = static_cast<AInventory *>(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<ABasicArmorPickup*>(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
|
@ -575,47 +575,6 @@ const char *cht_Morph (player_t *player, PClassPlayerPawn *morphclass, bool quic
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void GiveSpawner (player_t *player, PClassInventory *type, int amount)
|
|
||||||
{
|
|
||||||
if (player->mo == NULL || player->health <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AInventory *item = static_cast<AInventory *>
|
|
||||||
(Spawn (type, player->mo->Pos(), NO_REPLACE));
|
|
||||||
if (item != NULL)
|
|
||||||
{
|
|
||||||
if (amount > 0)
|
|
||||||
{
|
|
||||||
if (type->IsDescendantOf (RUNTIME_CLASS(ABasicArmorPickup)))
|
|
||||||
{
|
|
||||||
if (static_cast<ABasicArmorPickup*>(item)->SaveAmount != 0)
|
|
||||||
{
|
|
||||||
static_cast<ABasicArmorPickup*>(item)->SaveAmount *= amount;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
static_cast<ABasicArmorPickup*>(item)->SaveAmount *= amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type->IsDescendantOf (RUNTIME_CLASS(ABasicArmorBonus)))
|
|
||||||
{
|
|
||||||
static_cast<ABasicArmorBonus*>(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)
|
void cht_Give (player_t *player, const char *name, int amount)
|
||||||
{
|
{
|
||||||
enum { ALL_NO, ALL_YES, ALL_YESYES } giveall;
|
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);
|
type = PClass::FindActor(gameinfo.backpacktype);
|
||||||
if (type != NULL)
|
if (type != NULL)
|
||||||
{
|
{
|
||||||
GiveSpawner (player, static_cast<PClassInventory *>(type), 1);
|
player->mo->GiveInventory(static_cast<PClassInventory *>(type), 1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!giveall)
|
if (!giveall)
|
||||||
|
@ -778,7 +737,7 @@ void cht_Give (player_t *player, const char *name, int amount)
|
||||||
AWeapon *def = (AWeapon*)GetDefaultByType (type);
|
AWeapon *def = (AWeapon*)GetDefaultByType (type);
|
||||||
if (giveall == ALL_YESYES || !(def->WeaponFlags & WIF_CHEATNOTWEAPON))
|
if (giveall == ALL_YESYES || !(def->WeaponFlags & WIF_CHEATNOTWEAPON))
|
||||||
{
|
{
|
||||||
GiveSpawner (player, static_cast<PClassInventory *>(type), 1);
|
player->mo->GiveInventory(static_cast<PClassInventory *>(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"
|
// Do not give replaced items unless using "give everything"
|
||||||
if (giveall == ALL_YESYES || type->GetReplacement() == type)
|
if (giveall == ALL_YESYES || type->GetReplacement() == type)
|
||||||
{
|
{
|
||||||
GiveSpawner (player, static_cast<PClassInventory *>(type), amount <= 0 ? def->MaxAmount : amount);
|
player->mo->GiveInventory(static_cast<PClassInventory *>(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"
|
// Do not give replaced items unless using "give everything"
|
||||||
if (giveall == ALL_YESYES || type->GetReplacement() == type)
|
if (giveall == ALL_YESYES || type->GetReplacement() == type)
|
||||||
{
|
{
|
||||||
GiveSpawner (player, static_cast<PClassInventory *>(type), amount <= 0 ? def->MaxAmount : amount);
|
player->mo->GiveInventory(static_cast<PClassInventory *>(type), amount <= 0 ? def->MaxAmount : amount, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -847,7 +806,7 @@ void cht_Give (player_t *player, const char *name, int amount)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GiveSpawner (player, static_cast<PClassInventory *>(type), amount);
|
player->mo->GiveInventory(static_cast<PClassInventory *>(type), amount, true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<AInventory *>(Spawn (info));
|
|
||||||
|
|
||||||
// This shouldn't count for the item statistics!
|
|
||||||
item->ClearCounters();
|
|
||||||
if (info->IsDescendantOf (RUNTIME_CLASS(ABasicArmorPickup)))
|
|
||||||
{
|
|
||||||
static_cast<ABasicArmorPickup*>(item)->SaveAmount *= amount;
|
|
||||||
}
|
|
||||||
else if (info->IsDescendantOf (RUNTIME_CLASS(ABasicArmorBonus)))
|
|
||||||
{
|
|
||||||
static_cast<ABasicArmorBonus*>(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
|
// GiveInventory
|
||||||
|
@ -1218,12 +1176,12 @@ static void GiveInventory (AActor *activator, const char *type, int amount)
|
||||||
for (int i = 0; i < MAXPLAYERS; ++i)
|
for (int i = 0; i < MAXPLAYERS; ++i)
|
||||||
{
|
{
|
||||||
if (playeringame[i])
|
if (playeringame[i])
|
||||||
DoGiveInv (players[i].mo, info, amount);
|
players[i].mo->GiveInventory(static_cast<PClassInventory *>(info), amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DoGiveInv (activator, info, amount);
|
activator->GiveInventory(static_cast<PClassInventory *>(info), amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,8 +102,6 @@ struct TeaserSpeech
|
||||||
|
|
||||||
static FRandom pr_randomspeech("RandomSpeech");
|
static FRandom pr_randomspeech("RandomSpeech");
|
||||||
|
|
||||||
void GiveSpawner (player_t *player, PClassActor *type);
|
|
||||||
|
|
||||||
TArray<FStrifeDialogueNode *> StrifeDialogues;
|
TArray<FStrifeDialogueNode *> StrifeDialogues;
|
||||||
|
|
||||||
typedef TMap<int, int> FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS)
|
typedef TMap<int, int> FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS)
|
||||||
|
|
Loading…
Reference in a new issue