From 0d43272c8fdb6bd2d0fc8cc94564efcdffe3948e Mon Sep 17 00:00:00 2001 From: Boondorl Date: Fri, 29 Mar 2024 19:49:16 -0400 Subject: [PATCH] Allow for Basic and Hexen armor replacing --- src/ct_chat.cpp | 2 +- src/g_statusbar/sbarinfo.cpp | 2 +- src/g_statusbar/sbarinfo_commands.cpp | 8 ++++---- src/gamedata/gi.cpp | 4 ++++ src/gamedata/gi.h | 2 ++ src/playsim/p_acs.cpp | 6 +++--- wadsrc/static/zscript/actors/checks.zs | 2 +- wadsrc/static/zscript/actors/hexen/boostarmor.zs | 2 +- .../static/zscript/actors/hexen/healingradius.zs | 2 +- wadsrc/static/zscript/actors/inventory/armor.zs | 14 +++++++------- wadsrc/static/zscript/actors/inventory_util.zs | 14 ++++++++++++++ wadsrc/static/zscript/actors/player/player.zs | 6 +++--- .../static/zscript/actors/player/player_cheat.zs | 2 +- .../static/zscript/actors/player/player_morph.zs | 2 +- wadsrc/static/zscript/doombase.zs | 2 ++ wadsrc/static/zscript/scriptutil/scriptutil.zs | 2 +- wadsrc/static/zscript/ui/statusbar/alt_hud.zs | 2 +- wadsrc/static/zscript/ui/statusbar/doom_sbar.zs | 2 +- wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs | 2 +- wadsrc/static/zscript/ui/statusbar/statusbar.zs | 8 ++++---- wadsrc/static/zscript/ui/statusbar/strife_sbar.zs | 4 ++-- 21 files changed, 56 insertions(+), 34 deletions(-) diff --git a/src/ct_chat.cpp b/src/ct_chat.cpp index e5368f83e1..a12bb9f205 100644 --- a/src/ct_chat.cpp +++ b/src/ct_chat.cpp @@ -436,7 +436,7 @@ static bool DoSubstitution (FString &out, const char *in) { if (strnicmp(a, "armor", 5) == 0) { - auto armor = player->mo->FindInventory(NAME_BasicArmor); + auto armor = player->mo->FindInventory(NAME_BasicArmor, true); out.AppendFormat("%d", armor != NULL ? armor->IntVar(NAME_Amount) : 0); } } diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index 1d855cc232..6bb27d1798 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1036,7 +1036,7 @@ public: ammocount2 = ammo2 != nullptr ? ammo2->IntVar(NAME_Amount) : 0; //prepare ammo counts - armor = CPlayer->mo->FindInventory(NAME_BasicArmor); + armor = CPlayer->mo->FindInventory(NAME_BasicArmor, true); } void _Draw (EHudState state) diff --git a/src/g_statusbar/sbarinfo_commands.cpp b/src/g_statusbar/sbarinfo_commands.cpp index 73462f384d..749294adc2 100644 --- a/src/g_statusbar/sbarinfo_commands.cpp +++ b/src/g_statusbar/sbarinfo_commands.cpp @@ -276,7 +276,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl { int armorType = type - HEXENARMOR_ARMOR; - auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor); + auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor, true); if (harmor != NULL) { double *Slots = (double*)harmor->ScriptVar(NAME_Slots, nullptr); @@ -596,7 +596,7 @@ class CommandDrawSwitchableImage : public CommandDrawImage } else if(condition == ARMORTYPE) { - auto armor = statusBar->CPlayer->mo->FindInventory(NAME_BasicArmor); + auto armor = statusBar->CPlayer->mo->FindInventory(NAME_BasicArmor, true); if(armor != NULL) { auto n = armor->NameVar(NAME_ArmorType).GetIndex(); @@ -1413,7 +1413,7 @@ class CommandDrawNumber : public CommandDrawString case SAVEPERCENT: { double add = 0; - auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor); + auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor, true); if(harmor != NULL) { double *Slots = (double*)harmor->ScriptVar(NAME_Slots, nullptr); @@ -2775,7 +2775,7 @@ class CommandDrawBar : public SBarInfoCommand case SAVEPERCENT: { double add = 0; - auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor); + auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor, true); if (harmor != NULL) { double *Slots = (double*)harmor->ScriptVar(NAME_Slots, nullptr); diff --git a/src/gamedata/gi.cpp b/src/gamedata/gi.cpp index e907722e97..ed9b0bfa96 100644 --- a/src/gamedata/gi.cpp +++ b/src/gamedata/gi.cpp @@ -52,6 +52,8 @@ DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, backpacktype) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, Armor2Percent) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, ArmorIcon1) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, ArmorIcon2) +DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, BasicArmorClass) +DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, HexenArmorClass) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, gametype) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, norandomplayerclass) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, infoPages) @@ -392,6 +394,8 @@ void FMapInfoParser::ParseGameInfo() GAMEINFOKEY_SOUNDARRAY(PrecachedSounds, "precachesounds", 0, false) GAMEINFOKEY_STRINGARRAY(EventHandlers, "addeventhandlers", 0, false) GAMEINFOKEY_STRINGARRAY(EventHandlers, "eventhandlers", 0, false) + GAMEINFOKEY_STRING(BasicArmorClass, "BasicArmorClass") + GAMEINFOKEY_STRING(HexenArmorClass, "HexenArmorClass") GAMEINFOKEY_STRING(PauseSign, "pausesign") GAMEINFOKEY_STRING(quitSound, "quitSound") GAMEINFOKEY_STRING(BorderFlat, "borderFlat") diff --git a/src/gamedata/gi.h b/src/gamedata/gi.h index 5e713628d3..a8d4fa66ca 100644 --- a/src/gamedata/gi.h +++ b/src/gamedata/gi.h @@ -148,6 +148,8 @@ struct gameinfo_t FString SkyFlatName; FString ArmorIcon1; FString ArmorIcon2; + FName BasicArmorClass; + FName HexenArmorClass; FString PauseSign; FString Endoom; double Armor2Percent; diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index 1d4e90d1e8..d05f5dae3b 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -5506,7 +5506,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args, int & else { FName p(Level->Behaviors.LookupString(args[0])); - auto armor = Level->Players[args[1]]->mo->FindInventory(NAME_BasicArmor); + auto armor = Level->Players[args[1]]->mo->FindInventory(NAME_BasicArmor, true); if (armor && armor->NameVar(NAME_ArmorType) == p) return armor->IntVar(NAME_Amount); } return 0; @@ -5517,7 +5517,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args, int & { if (activator == NULL || activator->player == NULL) return 0; - auto equippedarmor = activator->FindInventory(NAME_BasicArmor); + auto equippedarmor = activator->FindInventory(NAME_BasicArmor, true); if (equippedarmor && equippedarmor->IntVar(NAME_Amount) != 0) { @@ -8898,7 +8898,7 @@ scriptwait: case PCD_PLAYERARMORPOINTS: if (activator) { - auto armor = activator->FindInventory(NAME_BasicArmor); + auto armor = activator->FindInventory(NAME_BasicArmor, true); PushToStack (armor ? armor->IntVar(NAME_Amount) : 0); } else diff --git a/wadsrc/static/zscript/actors/checks.zs b/wadsrc/static/zscript/actors/checks.zs index 280abf4fe2..018f2b5529 100644 --- a/wadsrc/static/zscript/actors/checks.zs +++ b/wadsrc/static/zscript/actors/checks.zs @@ -110,7 +110,7 @@ extend class Actor bool CheckArmorType(name Type, int amount = 1) { - let myarmor = BasicArmor(FindInventory("BasicArmor")); + let myarmor = BasicArmor(FindInventory("BasicArmor", true)); return myarmor != null && myarmor.ArmorType == type && myarmor.Amount >= amount; } diff --git a/wadsrc/static/zscript/actors/hexen/boostarmor.zs b/wadsrc/static/zscript/actors/hexen/boostarmor.zs index 4ed7c7f808..0592a4e2d8 100644 --- a/wadsrc/static/zscript/actors/hexen/boostarmor.zs +++ b/wadsrc/static/zscript/actors/hexen/boostarmor.zs @@ -32,7 +32,7 @@ class ArtiBoostArmor : Inventory for (int i = 0; i < 4; ++i) { - armor = HexenArmor(Spawn("HexenArmor")); + armor = HexenArmor(Spawn(GetHexenArmorClass())); armor.bDropped = true; armor.health = i; armor.Amount = 1; diff --git a/wadsrc/static/zscript/actors/hexen/healingradius.zs b/wadsrc/static/zscript/actors/hexen/healingradius.zs index 852bd642ac..508595a30c 100644 --- a/wadsrc/static/zscript/actors/hexen/healingradius.zs +++ b/wadsrc/static/zscript/actors/hexen/healingradius.zs @@ -51,7 +51,7 @@ class ArtiHealingRadius : Inventory case 'Armor': for (int j = 0; j < 4; ++j) { - HexenArmor armor = HexenArmor(Spawn("HexenArmor")); + HexenArmor armor = HexenArmor(Spawn(GetHexenArmorClass())); armor.health = j; armor.Amount = 1; if (!armor.CallTryPickup (mo)) diff --git a/wadsrc/static/zscript/actors/inventory/armor.zs b/wadsrc/static/zscript/actors/inventory/armor.zs index bc764fc2c5..8509c5bf23 100644 --- a/wadsrc/static/zscript/actors/inventory/armor.zs +++ b/wadsrc/static/zscript/actors/inventory/armor.zs @@ -106,7 +106,7 @@ class BasicArmor : Armor { // BasicArmor that is in use is stored in the inventory as BasicArmor. // BasicArmor that is in reserve is not. - let copy = BasicArmor(Spawn("BasicArmor")); + let copy = BasicArmor(Spawn(GetBasicArmorClass())); copy.SavePercent = SavePercent != 0 ? SavePercent : 0.33335; // slightly more than 1/3 to avoid roundoff errors. copy.Amount = Amount; copy.MaxAmount = MaxAmount; @@ -127,7 +127,7 @@ class BasicArmor : Armor override bool HandlePickup (Inventory item) { - if (item.GetClass() == "BasicArmor") + if (item is "BasicArmor") { // You shouldn't be picking up BasicArmor anyway. return true; @@ -271,13 +271,13 @@ class BasicArmorBonus : Armor override bool Use (bool pickup) { - let armor = BasicArmor(Owner.FindInventory("BasicArmor")); + let armor = BasicArmor(Owner.FindInventory("BasicArmor", true)); bool result = false; // This should really never happen but let's be prepared for a broken inventory. if (armor == null) { - armor = BasicArmor(Spawn("BasicArmor")); + armor = BasicArmor(Spawn(GetBasicArmorClass())); armor.BecomeItem (); armor.Amount = 0; armor.MaxAmount = MaxSaveAmount; @@ -391,12 +391,12 @@ class BasicArmorPickup : Armor override bool Use (bool pickup) { int SaveAmount = GetSaveAmount(); - let armor = BasicArmor(Owner.FindInventory("BasicArmor")); + let armor = BasicArmor(Owner.FindInventory("BasicArmor", true)); // This should really never happen but let's be prepared for a broken inventory. if (armor == null) { - armor = BasicArmor(Spawn("BasicArmor")); + armor = BasicArmor(Spawn(GetBasicArmorClass())); armor.BecomeItem (); Owner.AddInventory (armor); } @@ -471,7 +471,7 @@ class HexenArmor : Armor // Like BasicArmor, HexenArmor is used in the inventory but not the map. // health is the slot this armor occupies. // Amount is the quantity to give (0 = normal max). - let copy = HexenArmor(Spawn("HexenArmor")); + let copy = HexenArmor(Spawn(GetHexenArmorClass())); copy.AddArmorToSlot (health, Amount); GoAwayAndDie (); return copy; diff --git a/wadsrc/static/zscript/actors/inventory_util.zs b/wadsrc/static/zscript/actors/inventory_util.zs index 1bb9be5126..011ca134f4 100644 --- a/wadsrc/static/zscript/actors/inventory_util.zs +++ b/wadsrc/static/zscript/actors/inventory_util.zs @@ -855,8 +855,22 @@ extend class Actor } } + clearscope static class GetBasicArmorClass() + { + class cls = (class)(GameInfo.BasicArmorClass); + if (cls) + return cls; + return "BasicArmor"; + } + clearscope static class GetHexenArmorClass() + { + class cls = (class)(GameInfo.HexenArmorClass); + if (cls) + return cls; + return "HexenArmor"; + } } diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index b2252c16e1..69e534b70f 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -1906,8 +1906,8 @@ class PlayerPawn : Actor // it provides player class based protection that should not affect // any other protection item. let myclass = GetClass(); - GiveInventoryType('HexenArmor'); - let harmor = HexenArmor(FindInventory('HexenArmor')); + GiveInventoryType(GetHexenArmorClass()); + let harmor = HexenArmor(FindInventory('HexenArmor', true)); harmor.Slots[4] = self.HexenArmor[0]; for (int i = 0; i < 4; ++i) @@ -1918,7 +1918,7 @@ class PlayerPawn : Actor // 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. - GiveInventoryType('BasicArmor'); + GiveInventoryType(GetBasicArmorClass()); // Now add the items from the DECORATE definition let di = GetDropItems(); diff --git a/wadsrc/static/zscript/actors/player/player_cheat.zs b/wadsrc/static/zscript/actors/player/player_cheat.zs index c89832dca6..3fbb5f30b6 100644 --- a/wadsrc/static/zscript/actors/player/player_cheat.zs +++ b/wadsrc/static/zscript/actors/player/player_cheat.zs @@ -139,7 +139,7 @@ extend class PlayerPawn { for (i = 0; i < 4; ++i) { - let armoritem = Inventory(Spawn("HexenArmor")); + let armoritem = Inventory(Spawn(GetHexenArmorClass())); armoritem.health = i; armoritem.Amount = 0; if (!armoritem.CallTryPickup (self)) diff --git a/wadsrc/static/zscript/actors/player/player_morph.zs b/wadsrc/static/zscript/actors/player/player_morph.zs index 435d61cdf2..85d21d2509 100644 --- a/wadsrc/static/zscript/actors/player/player_morph.zs +++ b/wadsrc/static/zscript/actors/player/player_morph.zs @@ -347,7 +347,7 @@ extend class PlayerPawn } // Reset the base AC of the player's Hexen armor back to its default. - let hexArmor = HexenArmor(alt.FindInventory("HexenArmor")); + let hexArmor = HexenArmor(alt.FindInventory("HexenArmor", true)); if (hexArmor) hexArmor.Slots[4] = alt.HexenArmor[0]; diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 829e752707..54c44f8219 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -89,6 +89,8 @@ extend struct GameInfoStruct native double Armor2Percent; native String ArmorIcon1; native String ArmorIcon2; + native Name BasicArmorClass; + native Name HexenArmorClass; native bool norandomplayerclass; native Array infoPages; native GIFont mStatscreenMapNameFont; diff --git a/wadsrc/static/zscript/scriptutil/scriptutil.zs b/wadsrc/static/zscript/scriptutil/scriptutil.zs index 26f1a2b9de..b9d13e7b5e 100644 --- a/wadsrc/static/zscript/scriptutil/scriptutil.zs +++ b/wadsrc/static/zscript/scriptutil/scriptutil.zs @@ -61,7 +61,7 @@ class ScriptUtil play } if (type == 'Armor') { - type = "BasicArmor"; + type = Actor.GetBasicArmorClass().GetClassName(); } if (amount <= 0) { diff --git a/wadsrc/static/zscript/ui/statusbar/alt_hud.zs b/wadsrc/static/zscript/ui/statusbar/alt_hud.zs index 203d55ec41..c1c6e72888 100644 --- a/wadsrc/static/zscript/ui/statusbar/alt_hud.zs +++ b/wadsrc/static/zscript/ui/statusbar/alt_hud.zs @@ -930,7 +930,7 @@ class AltHud ui int armory = hud_swaphealtharmor ? hudheight-45 : hudheight-20; int healthy = hud_swaphealtharmor ? hudheight-20 : hudheight-45; DrawHealth(CPlayer, 5, healthy); - DrawArmor(BasicArmor(CPlayer.mo.FindInventory('BasicArmor')), HexenArmor(CPlayer.mo.FindInventory('HexenArmor')), 5, armory); + DrawArmor(BasicArmor(CPlayer.mo.FindInventory('BasicArmor', true)), HexenArmor(CPlayer.mo.FindInventory('HexenArmor', true)), 5, armory); int y = DrawKeys(CPlayer, hudwidth-4, hudheight-10); y = DrawAmmo(CPlayer, hudwidth-5, y); diff --git a/wadsrc/static/zscript/ui/statusbar/doom_sbar.zs b/wadsrc/static/zscript/ui/statusbar/doom_sbar.zs index 39cad7adb9..7e7496a414 100644 --- a/wadsrc/static/zscript/ui/statusbar/doom_sbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/doom_sbar.zs @@ -146,7 +146,7 @@ class DoomStatusBar : BaseStatusBar DrawImage(berserk? "PSTRA0" : "MEDIA0", (20, -2)); DrawString(mHUDFont, FormatNumber(CPlayer.health, 3), (44, -20)); - let armor = CPlayer.mo.FindInventory("BasicArmor"); + let armor = CPlayer.mo.FindInventory("BasicArmor", true); if (armor != null && armor.Amount > 0) { DrawInventoryIcon(armor, (20, -22)); diff --git a/wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs b/wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs index 5c29e176f5..62cc27efa4 100644 --- a/wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs @@ -148,7 +148,7 @@ class HereticStatusBar : BaseStatusBar DrawString(mBigFont, FormatNumber(mHealthInterpolator.GetValue()), (41, -21), DI_TEXT_ALIGN_RIGHT); //armor - let armor = CPlayer.mo.FindInventory("BasicArmor"); + let armor = CPlayer.mo.FindInventory("BasicArmor", true); if (armor != null && armor.Amount > 0) { DrawInventoryIcon(armor, (58, -24)); diff --git a/wadsrc/static/zscript/ui/statusbar/statusbar.zs b/wadsrc/static/zscript/ui/statusbar/statusbar.zs index 58f2ecc3af..1cbaeae871 100644 --- a/wadsrc/static/zscript/ui/statusbar/statusbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/statusbar.zs @@ -430,7 +430,7 @@ class BaseStatusBar : StatusBarCore native int GetArmorAmount() { - let armor = CPlayer.mo.FindInventory("BasicArmor"); + let armor = CPlayer.mo.FindInventory("BasicArmor", true); return armor? armor.Amount : 0; } @@ -451,13 +451,13 @@ class BaseStatusBar : StatusBarCore native int GetArmorSavePercent() { double add = 0; - let harmor = HexenArmor(CPlayer.mo.FindInventory("HexenArmor")); + let harmor = HexenArmor(CPlayer.mo.FindInventory("HexenArmor", true)); if(harmor != NULL) { add = harmor.Slots[0] + harmor.Slots[1] + harmor.Slots[2] + harmor.Slots[3] + harmor.Slots[4]; } //Hexen counts basic armor also so we should too. - let armor = BasicArmor(CPlayer.mo.FindInventory("BasicArmor")); + let armor = BasicArmor(CPlayer.mo.FindInventory("BasicArmor", true)); if(armor != NULL && armor.Amount > 0) { add += armor.SavePercent * 100; @@ -771,7 +771,7 @@ class BaseStatusBar : StatusBarCore native void DrawHexenArmor(int armortype, String image, Vector2 pos, int flags = 0, double alpha = 1.0, Vector2 boxsize = (-1, -1), Vector2 scale = (1.,1.)) { - let harmor = HexenArmor(statusBar.CPlayer.mo.FindInventory("HexenArmor")); + let harmor = HexenArmor(statusBar.CPlayer.mo.FindInventory("HexenArmor", true)); if (harmor != NULL) { let slotval = harmor.Slots[armorType]; diff --git a/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs b/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs index f52195be42..7186d46d4b 100644 --- a/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs @@ -287,7 +287,7 @@ class StrifeStatusBar : BaseStatusBar DrawHealthBar (points, 49, 175); // Armor - item = CPlayer.mo.FindInventory('BasicArmor'); + item = CPlayer.mo.FindInventory('BasicArmor', true); if (item != NULL && item.Amount > 0) { DrawInventoryIcon(item, (2, 177), DI_ITEM_OFFSETS); @@ -333,7 +333,7 @@ class StrifeStatusBar : BaseStatusBar DrawImage("I_MDKT", (14, -17)); // Draw armor - let armor = CPlayer.mo.FindInventory('BasicArmor'); + let armor = CPlayer.mo.FindInventory('BasicArmor', true); if (armor != NULL && armor.Amount != 0) { DrawString(mYelFont, FormatNumber(armor.Amount, 3), (35, -10));