Skip to content

Commit 0d43272

Browse files
Boondorlmadame-rachelle
authored andcommitted
Allow for Basic and Hexen armor replacing
1 parent 5fa2202 commit 0d43272

21 files changed

+56
-34
lines changed

src/ct_chat.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static bool DoSubstitution (FString &out, const char *in)
436436
{
437437
if (strnicmp(a, "armor", 5) == 0)
438438
{
439-
auto armor = player->mo->FindInventory(NAME_BasicArmor);
439+
auto armor = player->mo->FindInventory(NAME_BasicArmor, true);
440440
out.AppendFormat("%d", armor != NULL ? armor->IntVar(NAME_Amount) : 0);
441441
}
442442
}

src/g_statusbar/sbarinfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ class DSBarInfo
10361036
ammocount2 = ammo2 != nullptr ? ammo2->IntVar(NAME_Amount) : 0;
10371037

10381038
//prepare ammo counts
1039-
armor = CPlayer->mo->FindInventory(NAME_BasicArmor);
1039+
armor = CPlayer->mo->FindInventory(NAME_BasicArmor, true);
10401040
}
10411041

10421042
void _Draw (EHudState state)

src/g_statusbar/sbarinfo_commands.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
276276
{
277277
int armorType = type - HEXENARMOR_ARMOR;
278278

279-
auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor);
279+
auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor, true);
280280
if (harmor != NULL)
281281
{
282282
double *Slots = (double*)harmor->ScriptVar(NAME_Slots, nullptr);
@@ -596,7 +596,7 @@ class CommandDrawSwitchableImage : public CommandDrawImage
596596
}
597597
else if(condition == ARMORTYPE)
598598
{
599-
auto armor = statusBar->CPlayer->mo->FindInventory(NAME_BasicArmor);
599+
auto armor = statusBar->CPlayer->mo->FindInventory(NAME_BasicArmor, true);
600600
if(armor != NULL)
601601
{
602602
auto n = armor->NameVar(NAME_ArmorType).GetIndex();
@@ -1413,7 +1413,7 @@ class CommandDrawNumber : public CommandDrawString
14131413
case SAVEPERCENT:
14141414
{
14151415
double add = 0;
1416-
auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor);
1416+
auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor, true);
14171417
if(harmor != NULL)
14181418
{
14191419
double *Slots = (double*)harmor->ScriptVar(NAME_Slots, nullptr);
@@ -2775,7 +2775,7 @@ class CommandDrawBar : public SBarInfoCommand
27752775
case SAVEPERCENT:
27762776
{
27772777
double add = 0;
2778-
auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor);
2778+
auto harmor = statusBar->CPlayer->mo->FindInventory(NAME_HexenArmor, true);
27792779
if (harmor != NULL)
27802780
{
27812781
double *Slots = (double*)harmor->ScriptVar(NAME_Slots, nullptr);

src/gamedata/gi.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, backpacktype)
5252
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, Armor2Percent)
5353
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, ArmorIcon1)
5454
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, ArmorIcon2)
55+
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, BasicArmorClass)
56+
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, HexenArmorClass)
5557
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, gametype)
5658
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, norandomplayerclass)
5759
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, infoPages)
@@ -392,6 +394,8 @@ void FMapInfoParser::ParseGameInfo()
392394
GAMEINFOKEY_SOUNDARRAY(PrecachedSounds, "precachesounds", 0, false)
393395
GAMEINFOKEY_STRINGARRAY(EventHandlers, "addeventhandlers", 0, false)
394396
GAMEINFOKEY_STRINGARRAY(EventHandlers, "eventhandlers", 0, false)
397+
GAMEINFOKEY_STRING(BasicArmorClass, "BasicArmorClass")
398+
GAMEINFOKEY_STRING(HexenArmorClass, "HexenArmorClass")
395399
GAMEINFOKEY_STRING(PauseSign, "pausesign")
396400
GAMEINFOKEY_STRING(quitSound, "quitSound")
397401
GAMEINFOKEY_STRING(BorderFlat, "borderFlat")

src/gamedata/gi.h

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ struct gameinfo_t
148148
FString SkyFlatName;
149149
FString ArmorIcon1;
150150
FString ArmorIcon2;
151+
FName BasicArmorClass;
152+
FName HexenArmorClass;
151153
FString PauseSign;
152154
FString Endoom;
153155
double Armor2Percent;

src/playsim/p_acs.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5506,7 +5506,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args, int &
55065506
else
55075507
{
55085508
FName p(Level->Behaviors.LookupString(args[0]));
5509-
auto armor = Level->Players[args[1]]->mo->FindInventory(NAME_BasicArmor);
5509+
auto armor = Level->Players[args[1]]->mo->FindInventory(NAME_BasicArmor, true);
55105510
if (armor && armor->NameVar(NAME_ArmorType) == p) return armor->IntVar(NAME_Amount);
55115511
}
55125512
return 0;
@@ -5517,7 +5517,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args, int &
55175517
{
55185518
if (activator == NULL || activator->player == NULL) return 0;
55195519

5520-
auto equippedarmor = activator->FindInventory(NAME_BasicArmor);
5520+
auto equippedarmor = activator->FindInventory(NAME_BasicArmor, true);
55215521

55225522
if (equippedarmor && equippedarmor->IntVar(NAME_Amount) != 0)
55235523
{
@@ -8898,7 +8898,7 @@ int DLevelScript::RunScript()
88988898
case PCD_PLAYERARMORPOINTS:
88998899
if (activator)
89008900
{
8901-
auto armor = activator->FindInventory(NAME_BasicArmor);
8901+
auto armor = activator->FindInventory(NAME_BasicArmor, true);
89028902
PushToStack (armor ? armor->IntVar(NAME_Amount) : 0);
89038903
}
89048904
else

wadsrc/static/zscript/actors/checks.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extend class Actor
110110

111111
bool CheckArmorType(name Type, int amount = 1)
112112
{
113-
let myarmor = BasicArmor(FindInventory("BasicArmor"));
113+
let myarmor = BasicArmor(FindInventory("BasicArmor", true));
114114
return myarmor != null && myarmor.ArmorType == type && myarmor.Amount >= amount;
115115
}
116116

wadsrc/static/zscript/actors/hexen/boostarmor.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ArtiBoostArmor : Inventory
3232

3333
for (int i = 0; i < 4; ++i)
3434
{
35-
armor = HexenArmor(Spawn("HexenArmor"));
35+
armor = HexenArmor(Spawn(GetHexenArmorClass()));
3636
armor.bDropped = true;
3737
armor.health = i;
3838
armor.Amount = 1;

wadsrc/static/zscript/actors/hexen/healingradius.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ArtiHealingRadius : Inventory
5151
case 'Armor':
5252
for (int j = 0; j < 4; ++j)
5353
{
54-
HexenArmor armor = HexenArmor(Spawn("HexenArmor"));
54+
HexenArmor armor = HexenArmor(Spawn(GetHexenArmorClass()));
5555
armor.health = j;
5656
armor.Amount = 1;
5757
if (!armor.CallTryPickup (mo))

wadsrc/static/zscript/actors/inventory/armor.zs

+7-7
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class BasicArmor : Armor
106106
{
107107
// BasicArmor that is in use is stored in the inventory as BasicArmor.
108108
// BasicArmor that is in reserve is not.
109-
let copy = BasicArmor(Spawn("BasicArmor"));
109+
let copy = BasicArmor(Spawn(GetBasicArmorClass()));
110110
copy.SavePercent = SavePercent != 0 ? SavePercent : 0.33335; // slightly more than 1/3 to avoid roundoff errors.
111111
copy.Amount = Amount;
112112
copy.MaxAmount = MaxAmount;
@@ -127,7 +127,7 @@ class BasicArmor : Armor
127127

128128
override bool HandlePickup (Inventory item)
129129
{
130-
if (item.GetClass() == "BasicArmor")
130+
if (item is "BasicArmor")
131131
{
132132
// You shouldn't be picking up BasicArmor anyway.
133133
return true;
@@ -271,13 +271,13 @@ class BasicArmorBonus : Armor
271271

272272
override bool Use (bool pickup)
273273
{
274-
let armor = BasicArmor(Owner.FindInventory("BasicArmor"));
274+
let armor = BasicArmor(Owner.FindInventory("BasicArmor", true));
275275
bool result = false;
276276

277277
// This should really never happen but let's be prepared for a broken inventory.
278278
if (armor == null)
279279
{
280-
armor = BasicArmor(Spawn("BasicArmor"));
280+
armor = BasicArmor(Spawn(GetBasicArmorClass()));
281281
armor.BecomeItem ();
282282
armor.Amount = 0;
283283
armor.MaxAmount = MaxSaveAmount;
@@ -391,12 +391,12 @@ class BasicArmorPickup : Armor
391391
override bool Use (bool pickup)
392392
{
393393
int SaveAmount = GetSaveAmount();
394-
let armor = BasicArmor(Owner.FindInventory("BasicArmor"));
394+
let armor = BasicArmor(Owner.FindInventory("BasicArmor", true));
395395

396396
// This should really never happen but let's be prepared for a broken inventory.
397397
if (armor == null)
398398
{
399-
armor = BasicArmor(Spawn("BasicArmor"));
399+
armor = BasicArmor(Spawn(GetBasicArmorClass()));
400400
armor.BecomeItem ();
401401
Owner.AddInventory (armor);
402402
}
@@ -471,7 +471,7 @@ class HexenArmor : Armor
471471
// Like BasicArmor, HexenArmor is used in the inventory but not the map.
472472
// health is the slot this armor occupies.
473473
// Amount is the quantity to give (0 = normal max).
474-
let copy = HexenArmor(Spawn("HexenArmor"));
474+
let copy = HexenArmor(Spawn(GetHexenArmorClass()));
475475
copy.AddArmorToSlot (health, Amount);
476476
GoAwayAndDie ();
477477
return copy;

wadsrc/static/zscript/actors/inventory_util.zs

+14
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,22 @@ extend class Actor
855855
}
856856
}
857857

858+
clearscope static class<BasicArmor> GetBasicArmorClass()
859+
{
860+
class<BasicArmor> cls = (class<BasicArmor>)(GameInfo.BasicArmorClass);
861+
if (cls)
862+
return cls;
858863

864+
return "BasicArmor";
865+
}
859866

867+
clearscope static class<HexenArmor> GetHexenArmorClass()
868+
{
869+
class<HexenArmor> cls = (class<HexenArmor>)(GameInfo.HexenArmorClass);
870+
if (cls)
871+
return cls;
860872

873+
return "HexenArmor";
874+
}
861875

862876
}

wadsrc/static/zscript/actors/player/player.zs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1906,8 +1906,8 @@ class PlayerPawn : Actor
19061906
// it provides player class based protection that should not affect
19071907
// any other protection item.
19081908
let myclass = GetClass();
1909-
GiveInventoryType('HexenArmor');
1910-
let harmor = HexenArmor(FindInventory('HexenArmor'));
1909+
GiveInventoryType(GetHexenArmorClass());
1910+
let harmor = HexenArmor(FindInventory('HexenArmor', true));
19111911

19121912
harmor.Slots[4] = self.HexenArmor[0];
19131913
for (int i = 0; i < 4; ++i)
@@ -1918,7 +1918,7 @@ class PlayerPawn : Actor
19181918
// BasicArmor must come right after that. It should not affect any
19191919
// other protection item as well but needs to process the damage
19201920
// before the HexenArmor does.
1921-
GiveInventoryType('BasicArmor');
1921+
GiveInventoryType(GetBasicArmorClass());
19221922

19231923
// Now add the items from the DECORATE definition
19241924
let di = GetDropItems();

wadsrc/static/zscript/actors/player/player_cheat.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ extend class PlayerPawn
139139
{
140140
for (i = 0; i < 4; ++i)
141141
{
142-
let armoritem = Inventory(Spawn("HexenArmor"));
142+
let armoritem = Inventory(Spawn(GetHexenArmorClass()));
143143
armoritem.health = i;
144144
armoritem.Amount = 0;
145145
if (!armoritem.CallTryPickup (self))

wadsrc/static/zscript/actors/player/player_morph.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ extend class PlayerPawn
347347
}
348348

349349
// Reset the base AC of the player's Hexen armor back to its default.
350-
let hexArmor = HexenArmor(alt.FindInventory("HexenArmor"));
350+
let hexArmor = HexenArmor(alt.FindInventory("HexenArmor", true));
351351
if (hexArmor)
352352
hexArmor.Slots[4] = alt.HexenArmor[0];
353353

wadsrc/static/zscript/doombase.zs

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ extend struct GameInfoStruct
8989
native double Armor2Percent;
9090
native String ArmorIcon1;
9191
native String ArmorIcon2;
92+
native Name BasicArmorClass;
93+
native Name HexenArmorClass;
9294
native bool norandomplayerclass;
9395
native Array<Name> infoPages;
9496
native GIFont mStatscreenMapNameFont;

wadsrc/static/zscript/scriptutil/scriptutil.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ScriptUtil play
6161
}
6262
if (type == 'Armor')
6363
{
64-
type = "BasicArmor";
64+
type = Actor.GetBasicArmorClass().GetClassName();
6565
}
6666
if (amount <= 0)
6767
{

wadsrc/static/zscript/ui/statusbar/alt_hud.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ class AltHud ui
930930
int armory = hud_swaphealtharmor ? hudheight-45 : hudheight-20;
931931
int healthy = hud_swaphealtharmor ? hudheight-20 : hudheight-45;
932932
DrawHealth(CPlayer, 5, healthy);
933-
DrawArmor(BasicArmor(CPlayer.mo.FindInventory('BasicArmor')), HexenArmor(CPlayer.mo.FindInventory('HexenArmor')), 5, armory);
933+
DrawArmor(BasicArmor(CPlayer.mo.FindInventory('BasicArmor', true)), HexenArmor(CPlayer.mo.FindInventory('HexenArmor', true)), 5, armory);
934934

935935
int y = DrawKeys(CPlayer, hudwidth-4, hudheight-10);
936936
y = DrawAmmo(CPlayer, hudwidth-5, y);

wadsrc/static/zscript/ui/statusbar/doom_sbar.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class DoomStatusBar : BaseStatusBar
146146
DrawImage(berserk? "PSTRA0" : "MEDIA0", (20, -2));
147147
DrawString(mHUDFont, FormatNumber(CPlayer.health, 3), (44, -20));
148148

149-
let armor = CPlayer.mo.FindInventory("BasicArmor");
149+
let armor = CPlayer.mo.FindInventory("BasicArmor", true);
150150
if (armor != null && armor.Amount > 0)
151151
{
152152
DrawInventoryIcon(armor, (20, -22));

wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class HereticStatusBar : BaseStatusBar
148148
DrawString(mBigFont, FormatNumber(mHealthInterpolator.GetValue()), (41, -21), DI_TEXT_ALIGN_RIGHT);
149149

150150
//armor
151-
let armor = CPlayer.mo.FindInventory("BasicArmor");
151+
let armor = CPlayer.mo.FindInventory("BasicArmor", true);
152152
if (armor != null && armor.Amount > 0)
153153
{
154154
DrawInventoryIcon(armor, (58, -24));

wadsrc/static/zscript/ui/statusbar/statusbar.zs

+4-4
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class BaseStatusBar : StatusBarCore native
430430

431431
int GetArmorAmount()
432432
{
433-
let armor = CPlayer.mo.FindInventory("BasicArmor");
433+
let armor = CPlayer.mo.FindInventory("BasicArmor", true);
434434
return armor? armor.Amount : 0;
435435
}
436436

@@ -451,13 +451,13 @@ class BaseStatusBar : StatusBarCore native
451451
int GetArmorSavePercent()
452452
{
453453
double add = 0;
454-
let harmor = HexenArmor(CPlayer.mo.FindInventory("HexenArmor"));
454+
let harmor = HexenArmor(CPlayer.mo.FindInventory("HexenArmor", true));
455455
if(harmor != NULL)
456456
{
457457
add = harmor.Slots[0] + harmor.Slots[1] + harmor.Slots[2] + harmor.Slots[3] + harmor.Slots[4];
458458
}
459459
//Hexen counts basic armor also so we should too.
460-
let armor = BasicArmor(CPlayer.mo.FindInventory("BasicArmor"));
460+
let armor = BasicArmor(CPlayer.mo.FindInventory("BasicArmor", true));
461461
if(armor != NULL && armor.Amount > 0)
462462
{
463463
add += armor.SavePercent * 100;
@@ -771,7 +771,7 @@ class BaseStatusBar : StatusBarCore native
771771

772772
void DrawHexenArmor(int armortype, String image, Vector2 pos, int flags = 0, double alpha = 1.0, Vector2 boxsize = (-1, -1), Vector2 scale = (1.,1.))
773773
{
774-
let harmor = HexenArmor(statusBar.CPlayer.mo.FindInventory("HexenArmor"));
774+
let harmor = HexenArmor(statusBar.CPlayer.mo.FindInventory("HexenArmor", true));
775775
if (harmor != NULL)
776776
{
777777
let slotval = harmor.Slots[armorType];

wadsrc/static/zscript/ui/statusbar/strife_sbar.zs

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class StrifeStatusBar : BaseStatusBar
287287
DrawHealthBar (points, 49, 175);
288288

289289
// Armor
290-
item = CPlayer.mo.FindInventory('BasicArmor');
290+
item = CPlayer.mo.FindInventory('BasicArmor', true);
291291
if (item != NULL && item.Amount > 0)
292292
{
293293
DrawInventoryIcon(item, (2, 177), DI_ITEM_OFFSETS);
@@ -333,7 +333,7 @@ class StrifeStatusBar : BaseStatusBar
333333
DrawImage("I_MDKT", (14, -17));
334334

335335
// Draw armor
336-
let armor = CPlayer.mo.FindInventory('BasicArmor');
336+
let armor = CPlayer.mo.FindInventory('BasicArmor', true);
337337
if (armor != NULL && armor.Amount != 0)
338338
{
339339
DrawString(mYelFont, FormatNumber(armor.Amount, 3), (35, -10));

0 commit comments

Comments
 (0)