diff --git a/wadsrc/static/zscript/inventory/ammo.txt b/wadsrc/static/zscript/inventory/ammo.txt index cc97611e0..52b3d8f22 100644 --- a/wadsrc/static/zscript/inventory/ammo.txt +++ b/wadsrc/static/zscript/inventory/ammo.txt @@ -249,11 +249,10 @@ class BackpackItem : Inventory uint end = AllActorClasses.Size(); for (uint i = 0; i < end; ++i) { - let type = AllActorClasses[i]; + let ammotype = (class)(AllActorClasses[i]); - if (type.GetParentClass() == 'Ammo') + if (ammotype && GetDefaultByType(ammotype).GetParentAmmo() == ammotype) { - let ammotype = (class)(type); let ammoitem = Ammo(other.FindInventory(ammotype)); int amount = GetDefaultByType(ammotype).BackpackAmount; // extra ammo in baby mode and nightmare mode @@ -314,20 +313,22 @@ class BackpackItem : Inventory { for (let probe = Owner.Inv; probe != NULL; probe = probe.Inv) { - if (probe.GetParentClass() == 'Ammo') + let ammoitem = Ammo(probe); + + if (ammoitem && ammoitem.GetParentAmmo() == ammoitem.GetClass()) { - if (probe.Amount < probe.MaxAmount || sv_unlimited_pickup) + if (ammoitem.Amount < ammoitem.MaxAmount || sv_unlimited_pickup) { - int amount = Ammo(probe).Default.BackpackAmount; + int amount = ammoitem.Default.BackpackAmount; // extra ammo in baby mode and nightmare mode if (!bIgnoreSkill) { amount = int(amount * G_SkillPropertyFloat(SKILLP_AmmoFactor)); } - probe.Amount += amount; - if (probe.Amount > probe.MaxAmount && !sv_unlimited_pickup) + ammoitem.Amount += amount; + if (ammoitem.Amount > ammoitem.MaxAmount && !sv_unlimited_pickup) { - probe.Amount = probe.MaxAmount; + ammoitem.Amount = ammoitem.MaxAmount; } } } diff --git a/wadsrc/static/zscript/shared/player_cheat.txt b/wadsrc/static/zscript/shared/player_cheat.txt index 8bd9d34c2..506a60480 100644 --- a/wadsrc/static/zscript/shared/player_cheat.txt +++ b/wadsrc/static/zscript/shared/player_cheat.txt @@ -99,14 +99,14 @@ extend class PlayerPawn // he doesn't have it already, and set each to its maximum. for (i = 0; i < AllActorClasses.Size(); ++i) { - type = (class)(AllActorClasses[i]); + let ammotype = (class)(AllActorClasses[i]); - if (type != null && type.GetParentClass() == "Ammo") + if (ammotype && GetDefaultByType(ammotype).GetParentAmmo() == ammotype) { - let ammoitem = FindInventory(type); + let ammoitem = FindInventory(ammotype); if (ammoitem == NULL) { - ammoitem = Inventory(Spawn (type)); + ammoitem = Inventory(Spawn (ammotype)); ammoitem.AttachToOwner (self); ammoitem.Amount = ammoitem.MaxAmount; }