Skip to content

Commit

Permalink
Allow easier piece weapon replacing
Browse files Browse the repository at this point in the history
Checks for replacements on weapons instead of using the given weapon class as is (also verifies said replacement is a weapon).
  • Loading branch information
Boondorl authored and RicardoLuis0 committed Nov 16, 2024
1 parent 268dad1 commit ab9b632
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions wadsrc/static/zscript/actors/inventory/weaponpiece.zs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class WeaponPiece : Inventory

property number: PieceValue;
property weapon: WeaponClass;

// Account for weapon replacers, but make sure it's still a Weapon
clearscope class<Weapon> GetWeaponClass() const
{
class<Weapon> type = WeaponClass ? (class<Weapon>)(GetReplacement(WeaponClass)) : null;
return type ? type : WeaponClass;
}

//==========================================================================
//
Expand All @@ -74,7 +81,11 @@ class WeaponPiece : Inventory
return false;
}

let Defaults = GetDefaultByType(WeaponClass);
class<Weapon> type = GetWeaponClass();
if (!type)
return false;

let Defaults = GetDefaultByType(type);

bool gaveSome = !!(toucher.GiveAmmo (Defaults.AmmoType1, Defaults.AmmoGive1) +
toucher.GiveAmmo (Defaults.AmmoType2, Defaults.AmmoGive2));
Expand All @@ -94,18 +105,23 @@ class WeaponPiece : Inventory

override bool TryPickup (in out Actor toucher)
{
class<Weapon> type = GetWeaponClass();
if (!type)
return false;

Inventory item;
WeaponHolder hold = NULL;
bool shouldStay = ShouldStay ();
int gaveAmmo;
let Defaults = GetDefaultByType(WeaponClass);
let Defaults = GetDefaultByType(type);

FullWeapon = NULL;
for(item=toucher.Inv; item; item=item.Inv)
{
hold = WeaponHolder(item);
if (hold != null)
{
// Intentionally check against the unreplaced class
if (hold.PieceWeapon == WeaponClass)
{
break;
Expand Down Expand Up @@ -153,9 +169,9 @@ class WeaponPiece : Inventory
// Check if weapon assembled
if (hold.PieceMask == (1 << Defaults.health) - 1)
{
if (!toucher.FindInventory (WeaponClass))
if (!toucher.FindInventory (type))
{
FullWeapon= Weapon(Spawn(WeaponClass));
FullWeapon= Weapon(Spawn(type));

// The weapon itself should not give more ammo to the player.
FullWeapon.AmmoGive1 = 0;
Expand Down

0 comments on commit ab9b632

Please sign in to comment.