From 2fcffd1fc17b50bdd6ce728217be840b8995a5d7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 18 Jan 2017 22:57:47 +0100 Subject: [PATCH] - removed the remaining native parts of ABasicArmor. - simplified some FindInventory calls using PClass::FindActor to call the variant taking a name directly. --- src/actor.h | 2 +- src/am_map.cpp | 2 +- src/ct_chat.cpp | 2 +- src/g_game.cpp | 6 ++-- src/g_inventory/a_armor.cpp | 36 ----------------------- src/g_inventory/a_armor.h | 19 ------------ src/g_shared/sbarinfo.cpp | 4 +-- src/g_shared/sbarinfo_commands.cpp | 16 +++++----- src/g_shared/shared_hud.cpp | 6 ++-- src/g_strife/strife_sbar.cpp | 6 ++-- src/m_cheat.cpp | 4 +-- src/namedef.h | 4 +++ src/p_acs.cpp | 22 +++++++------- src/p_lnspec.cpp | 2 +- src/p_mobj.cpp | 4 +-- src/p_pspr.cpp | 2 +- src/p_user.cpp | 8 ++--- wadsrc/static/zscript/inventory/armor.txt | 24 ++++++++++----- 18 files changed, 62 insertions(+), 107 deletions(-) diff --git a/src/actor.h b/src/actor.h index e1cc56290..9f6d00e02 100644 --- a/src/actor.h +++ b/src/actor.h @@ -721,7 +721,7 @@ public: // Finds the first item of a particular type. AInventory *FindInventory (PClassActor *type, bool subclass=false); - AInventory *FindInventory (FName type); + AInventory *FindInventory (FName type, bool subclass = false); template T *FindInventory () { return static_cast (FindInventory (RUNTIME_TEMPLATE_CLASS(T))); diff --git a/src/am_map.cpp b/src/am_map.cpp index b94840d66..a20998526 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -3048,7 +3048,7 @@ void AM_Drawer () return; bool allmap = (level.flags2 & LEVEL2_ALLMAP) != 0; - bool allthings = allmap && players[consoleplayer].mo->FindInventory(PClass::FindActor(NAME_PowerScanner), true) != nullptr; + bool allthings = allmap && players[consoleplayer].mo->FindInventory(NAME_PowerScanner, true) != nullptr; if (am_portaloverlay) { diff --git a/src/ct_chat.cpp b/src/ct_chat.cpp index 0a92a58b9..340378434 100644 --- a/src/ct_chat.cpp +++ b/src/ct_chat.cpp @@ -434,7 +434,7 @@ static bool DoSubstitution (FString &out, const char *in) { if (strnicmp(a, "armor", 5) == 0) { - AInventory *armor = player->mo->FindInventory(); + AInventory *armor = player->mo->FindInventory(NAME_BasicArmor); out.AppendFormat("%d", armor != NULL ? armor->Amount : 0); } } diff --git a/src/g_game.cpp b/src/g_game.cpp index c98eee244..936caea18 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -447,7 +447,7 @@ CCMD (use) { if (argv.argc() > 1 && who != NULL) { - SendItemUse = who->FindInventory(PClass::FindActor(argv[1])); + SendItemUse = who->FindInventory(argv[1]); } } @@ -468,7 +468,7 @@ CCMD (drop) { if (argv.argc() > 1 && who != NULL) { - SendItemDrop = who->FindInventory(PClass::FindActor(argv[1])); + SendItemDrop = who->FindInventory(argv[1]); } } @@ -513,7 +513,7 @@ CCMD (select) { if (argv.argc() > 1) { - AInventory *item = who->FindInventory(PClass::FindActor(argv[1])); + AInventory *item = who->FindInventory(argv[1]); if (item != NULL) { who->InvSel = item; diff --git a/src/g_inventory/a_armor.cpp b/src/g_inventory/a_armor.cpp index 816cf1620..74ebd52d6 100644 --- a/src/g_inventory/a_armor.cpp +++ b/src/g_inventory/a_armor.cpp @@ -46,44 +46,8 @@ #include "cmdlib.h" IMPLEMENT_CLASS(AArmor, false, false) -IMPLEMENT_CLASS(ABasicArmor, false, false) IMPLEMENT_CLASS(AHexenArmor, false, false) -//=========================================================================== -// -// -// BasicArmor -// -// -//=========================================================================== - -DEFINE_FIELD(ABasicArmor, AbsorbCount) -DEFINE_FIELD(ABasicArmor, SavePercent) -DEFINE_FIELD(ABasicArmor, MaxAbsorb) -DEFINE_FIELD(ABasicArmor, MaxFullAbsorb) -DEFINE_FIELD(ABasicArmor, BonusCount) -DEFINE_FIELD(ABasicArmor, ArmorType) -DEFINE_FIELD(ABasicArmor, ActualSaveAmount) - -//=========================================================================== -// -// ABasicArmor :: Serialize -// -//=========================================================================== - -void ABasicArmor::Serialize(FSerializer &arc) -{ - Super::Serialize (arc); - auto def = (ABasicArmor *)GetDefault(); - arc("savepercent", SavePercent, def->SavePercent) - ("bonuscount", BonusCount, def->BonusCount) - ("maxabsorb", MaxAbsorb, def->MaxAbsorb) - ("maxfullabsorb", MaxFullAbsorb, def->MaxFullAbsorb) - ("absorbcount", AbsorbCount, def->AbsorbCount) - ("armortype", ArmorType, def->ArmorType) - ("actualsaveamount", ActualSaveAmount, def->ActualSaveAmount); -} - //=========================================================================== // // diff --git a/src/g_inventory/a_armor.h b/src/g_inventory/a_armor.h index c09162f72..d208306a1 100644 --- a/src/g_inventory/a_armor.h +++ b/src/g_inventory/a_armor.h @@ -8,25 +8,6 @@ class AArmor : public AInventory DECLARE_CLASS (AArmor, AInventory) }; -// Basic armor absorbs a specific percent of the damage. You should -// never pickup a BasicArmor. Instead, you pickup a BasicArmorPickup -// or BasicArmorBonus and those gives you BasicArmor when it activates. -class ABasicArmor : public AArmor -{ - DECLARE_CLASS (ABasicArmor, AArmor) -public: - - virtual void Serialize(FSerializer &arc) override; - - int AbsorbCount; - double SavePercent; - int MaxAbsorb; - int MaxFullAbsorb; - int BonusCount; - FNameNoInit ArmorType; - int ActualSaveAmount; -}; - // Hexen armor consists of four separate armor types plus a conceptual armor // type (the player himself) that work together as a single armor. class AHexenArmor : public AArmor diff --git a/src/g_shared/sbarinfo.cpp b/src/g_shared/sbarinfo.cpp index 83fc19de1..f896faefe 100644 --- a/src/g_shared/sbarinfo.cpp +++ b/src/g_shared/sbarinfo.cpp @@ -1067,7 +1067,7 @@ public: //prepare ammo counts GetCurrentAmmo(ammo1, ammo2, ammocount1, ammocount2); - armor = CPlayer->mo->FindInventory(); + armor = CPlayer->mo->FindInventory(NAME_BasicArmor); if(state != HUD_AltHud) { @@ -1517,7 +1517,7 @@ public: AInventory *ammo1, *ammo2; int ammocount1, ammocount2; - ABasicArmor *armor; + AInventory *armor; FImageCollection Images; unsigned int invBarOffset; diff --git a/src/g_shared/sbarinfo_commands.cpp b/src/g_shared/sbarinfo_commands.cpp index 883b2a460..6bbbadc54 100644 --- a/src/g_shared/sbarinfo_commands.cpp +++ b/src/g_shared/sbarinfo_commands.cpp @@ -268,7 +268,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl } else if(type == SIGIL) { - auto item = statusBar->CPlayer->mo->FindInventory(PClass::FindActor(NAME_Sigil)); + auto item = statusBar->CPlayer->mo->FindInventory(NAME_Sigil); if (item != NULL) texture = TexMan(item->Icon); } @@ -592,11 +592,11 @@ class CommandDrawSwitchableImage : public CommandDrawImage } else if(condition == ARMORTYPE) { - ABasicArmor *armor = (ABasicArmor *) statusBar->CPlayer->mo->FindInventory(NAME_BasicArmor); + auto armor = statusBar->CPlayer->mo->FindInventory(NAME_BasicArmor); if(armor != NULL) { - bool matches1 = armor->ArmorType.GetIndex() == armorType[0] && EvaluateOperation(conditionalOperator[0], conditionalValue[0], armor->Amount); - bool matches2 = armor->ArmorType.GetIndex() == armorType[1] && EvaluateOperation(conditionalOperator[1], conditionalValue[1], armor->Amount); + bool matches1 = armor->NameVar(NAME_ArmorType).GetIndex() == armorType[0] && EvaluateOperation(conditionalOperator[0], conditionalValue[0], armor->Amount); + bool matches2 = armor->NameVar(NAME_ArmorType).GetIndex() == armorType[1] && EvaluateOperation(conditionalOperator[1], conditionalValue[1], armor->Amount); drawAlt = 1; if(conditionAnd) @@ -614,12 +614,12 @@ class CommandDrawSwitchableImage : public CommandDrawImage } else //check the inventory items and draw selected sprite { - AInventory* item = statusBar->CPlayer->mo->FindInventory(PClass::FindActor(inventoryItem[0])); + AInventory* item = statusBar->CPlayer->mo->FindInventory(inventoryItem[0]); if(item == NULL || !EvaluateOperation(conditionalOperator[0], conditionalValue[0], item->Amount)) drawAlt = 1; if(conditionAnd) { - item = statusBar->CPlayer->mo->FindInventory(PClass::FindActor(inventoryItem[1])); + item = statusBar->CPlayer->mo->FindInventory(inventoryItem[1]); bool secondCondition = item != NULL && EvaluateOperation(conditionalOperator[1], conditionalValue[1], item->Amount); if((item != NULL && secondCondition) && drawAlt == 0) //both { @@ -1418,7 +1418,7 @@ class CommandDrawNumber : public CommandDrawString //Hexen counts basic armor also so we should too. if(statusBar->armor != NULL) { - add += statusBar->armor->SavePercent * 100; + add += statusBar->armor->FloatVar(NAME_SavePercent) * 100; } if(value == ARMORCLASS) add /= 5; @@ -2851,7 +2851,7 @@ class CommandDrawBar : public SBarInfoCommand //Hexen counts basic armor also so we should too. if(statusBar->armor != NULL) { - add += statusBar->armor->SavePercent * 100; + add += statusBar->armor->FloatVar(NAME_SavePercent) * 100; } value = int(add); max = 100; diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index 118838f79..b6ee15602 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -297,7 +297,7 @@ static void DrawHealth(player_t *CPlayer, int x, int y) const bool haveBerserk = hud_berserk_health && nullptr != berserkpic - && nullptr != CPlayer->mo->FindInventory(PClass::FindActor(NAME_PowerStrength)); + && nullptr != CPlayer->mo->FindInventory(NAME_PowerStrength); DrawImageToBox(haveBerserk ? berserkpic : healthpic, x, y, 31, 17); DrawHudNumber(HudFont, fontcolor, health, x + 33, y + 17); @@ -310,7 +310,7 @@ static void DrawHealth(player_t *CPlayer, int x, int y) // //=========================================================================== -static void DrawArmor(ABasicArmor * barmor, AHexenArmor * harmor, int x, int y) +static void DrawArmor(AInventory * barmor, AHexenArmor * harmor, int x, int y) { int ap = 0; int bestslot = 4; @@ -1141,7 +1141,7 @@ void DrawHUD() DrawFrags(CPlayer, 5, hudheight-70); } DrawHealth(CPlayer, 5, hudheight-45); - DrawArmor(CPlayer->mo->FindInventory(), + DrawArmor(CPlayer->mo->FindInventory(NAME_BasicArmor), CPlayer->mo->FindInventory(), 5, hudheight-20); i=DrawKeys(CPlayer, hudwidth-4, hudheight-10); i=DrawAmmo(CPlayer, hudwidth-5, i); diff --git a/src/g_strife/strife_sbar.cpp b/src/g_strife/strife_sbar.cpp index cec529371..7fc64531f 100644 --- a/src/g_strife/strife_sbar.cpp +++ b/src/g_strife/strife_sbar.cpp @@ -408,7 +408,7 @@ private: DrawImage (&HealthBar, 49, 7); // Armor - item = CPlayer->mo->FindInventory(); + item = CPlayer->mo->FindInventory(NAME_BasicArmor); if (item != NULL && item->Amount > 0) { DrawImage (TexMan(item->Icon), 2, 9); @@ -436,7 +436,7 @@ private: } // Sigil - item = CPlayer->mo->FindInventory(PClass::FindActor(NAME_Sigil)); + item = CPlayer->mo->FindInventory(NAME_Sigil); if (item != NULL) { DrawImage (TexMan(item->Icon), 253, 7); @@ -473,7 +473,7 @@ private: TAG_DONE); // Draw armor - ABasicArmor *armor = CPlayer->mo->FindInventory(); + auto armor = CPlayer->mo->FindInventory(NAME_BasicArmor); if (armor != NULL && armor->Amount != 0) { DrINumberOuter (armor->Amount, 35, -10, false, 7); diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index 708bccf90..5510ec077 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -266,7 +266,7 @@ void cht_DoCheat (player_t *player, int cheat) } else if (player->mo != NULL && player->health >= 0) { - item = player->mo->FindInventory(PClass::FindActor(BeholdPowers[i])); + item = player->mo->FindInventory(BeholdPowers[i]); if (item == NULL) { if (i != 0) @@ -487,7 +487,7 @@ void cht_DoCheat (player_t *player, int cheat) int oldpieces = 1; ret.IntAt(&oldpieces); GlobalVMStack.Call(gsp, params, 1, &ret, 1, nullptr); - item = player->mo->FindInventory(PClass::FindActor(NAME_Sigil)); + item = player->mo->FindInventory(NAME_Sigil); if (item != NULL) { diff --git a/src/namedef.h b/src/namedef.h index e0ac61bf3..ff117df45 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -89,6 +89,10 @@ xx(SaveAmount) xx(SavePercent) xx(MaxAbsorb) xx(MaxFullAbsorb) +xx(MaxAmount) +xx(ActualSaveAmount) +xx(ArmorType) + xx(BulletPuff) xx(StrifePuff) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 5ebb0f640..09344cc76 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4955,8 +4955,8 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args) else { FName p(FBehavior::StaticLookupString(args[0])); - ABasicArmor * armor = (ABasicArmor *) players[args[1]].mo->FindInventory(NAME_BasicArmor); - if (armor && armor->ArmorType == p) return armor->Amount; + auto armor = players[args[1]].mo->FindInventory(NAME_BasicArmor); + if (armor && armor->NameVar(NAME_ArmorType) == p) return armor->Amount; } return 0; } @@ -4965,29 +4965,29 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args) { if (activator == NULL || activator->player == NULL) return 0; - ABasicArmor * equippedarmor = (ABasicArmor *) activator->FindInventory(NAME_BasicArmor); + auto equippedarmor = activator->FindInventory(NAME_BasicArmor); if (equippedarmor && equippedarmor->Amount != 0) { switch(args[0]) { case ARMORINFO_CLASSNAME: - return GlobalACSStrings.AddString(equippedarmor->ArmorType.GetChars()); + return GlobalACSStrings.AddString(equippedarmor->NameVar(NAME_ArmorType).GetChars()); case ARMORINFO_SAVEAMOUNT: - return equippedarmor->MaxAmount; + return equippedarmor->IntVar(NAME_MaxAmount); case ARMORINFO_SAVEPERCENT: - return DoubleToACS(equippedarmor->SavePercent); + return DoubleToACS(equippedarmor->FloatVar(NAME_SavePercent)); case ARMORINFO_MAXABSORB: - return equippedarmor->MaxAbsorb; + return equippedarmor->IntVar(NAME_MaxAbsorb); case ARMORINFO_MAXFULLABSORB: - return equippedarmor->MaxFullAbsorb; + return equippedarmor->IntVar(NAME_MaxFullAbsorb); case ARMORINFO_ACTUALSAVEAMOUNT: - return equippedarmor->ActualSaveAmount; + return equippedarmor->IntVar(NAME_ActualSaveAmount); default: return 0; @@ -8235,7 +8235,7 @@ scriptwait: case PCD_PLAYERARMORPOINTS: if (activator) { - ABasicArmor *armor = activator->FindInventory(); + auto armor = activator->FindInventory(NAME_BasicArmor); PushToStack (armor ? armor->Amount : 0); } else @@ -8682,7 +8682,7 @@ scriptwait: { AInventory *sigil; - if (activator == NULL || (sigil = activator->FindInventory(PClass::FindActor(NAME_Sigil))) == NULL) + if (activator == NULL || (sigil = activator->FindInventory(NAME_Sigil)) == NULL) { PushToStack (0); } diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index a09ad16cf..900f79497 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -2883,7 +2883,7 @@ FUNC(LS_SetPlayerProperty) { // Take power from activator if (power != 4) { - AInventory *item = it->FindInventory(PClass::FindActor(powers[power]), true); + AInventory *item = it->FindInventory(powers[power], true); if (item != NULL) { item->Destroy (); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 2a6caaae8..f45332b86 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1093,9 +1093,9 @@ AInventory *AActor::FindInventory (PClassActor *type, bool subclass) return item; } -AInventory *AActor::FindInventory (FName type) +AInventory *AActor::FindInventory (FName type, bool subclass) { - return FindInventory(PClass::FindActor(type)); + return FindInventory(PClass::FindActor(type), subclass); } DEFINE_ACTION_FUNCTION(AActor, FindInventory) diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 2e5201fa1..725744d37 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -233,7 +233,7 @@ DPSprite *player_t::GetPSprite(PSPLayers layer) { if (mo != nullptr) { - newcaller = mo->FindInventory(PClass::FindActor(NAME_PowerTargeter), true); + newcaller = mo->FindInventory(NAME_PowerTargeter, true); } } else if (layer == PSP_STRIFEHANDS) diff --git a/src/p_user.cpp b/src/p_user.cpp index 967890cf1..322353704 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -1148,9 +1148,9 @@ void APlayerPawn::FilterCoopRespawnInventory (APlayerPawn *oldplayer) { item->Destroy(); } - else if (item->IsKindOf(RUNTIME_CLASS(ABasicArmor))) + else if (item->IsKindOf(PClass::FindActor(NAME_BasicArmor))) { - static_cast(item)->SavePercent = static_cast(defitem)->SavePercent; + item->IntVar(NAME_SavePercent) = defitem->IntVar(NAME_SavePercent); item->Amount = defitem->Amount; } else if (item->IsKindOf(RUNTIME_CLASS(AHexenArmor))) @@ -1375,10 +1375,8 @@ void APlayerPawn::GiveDefaultInventory () // BasicArmor must come right after that. It should not affect any // other protection item as well but needs to process the damage // before the HexenArmor does. - ABasicArmor *barmor = Spawn (); + auto barmor = (AInventory*)Spawn(NAME_BasicArmor); barmor->BecomeItem (); - barmor->SavePercent = 0; - barmor->Amount = 0; AddInventory (barmor); // Now add the items from the DECORATE definition diff --git a/wadsrc/static/zscript/inventory/armor.txt b/wadsrc/static/zscript/inventory/armor.txt index 1d0f5fd9d..195de5f55 100644 --- a/wadsrc/static/zscript/inventory/armor.txt +++ b/wadsrc/static/zscript/inventory/armor.txt @@ -46,22 +46,27 @@ class Armor : Inventory native // // BasicArmor // +// Basic armor absorbs a specific percent of the damage. You should +// never pickup a BasicArmor. Instead, you pickup a BasicArmorPickup +// or BasicArmorBonus and those gives you BasicArmor when it activates. +// // //=========================================================================== -class BasicArmor : Armor native +class BasicArmor : Armor { - native int AbsorbCount; - native double SavePercent; - native int MaxAbsorb; - native int MaxFullAbsorb; - native int BonusCount; - native Name ArmorType; - native int ActualSaveAmount; + int AbsorbCount; + double SavePercent; + int MaxAbsorb; + int MaxFullAbsorb; + int BonusCount; + Name ArmorType; + int ActualSaveAmount; Default { + Inventory.Amount 0; +Inventory.KEEPDEPLETED } @@ -441,6 +446,9 @@ class BasicArmorPickup : Armor // // HexenArmor // +// Hexen armor consists of four separate armor types plus a conceptual armor +// type (the player himself) that work together as a single armor. +// // //===========================================================================