diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index a6b9ba5a9..a04ab2240 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -3095,7 +3095,7 @@ void FinishDehPatch () } else { - weap->WeaponFlags |= WIF_DEHAMMO; + weap->bDehAmmo = true; weap->AmmoUse1 = 0; // to allow proper checks in CheckAmmo we have to find the first attack pointer in the Fire sequence // and set its default ammo use as the weapon's AmmoUse1. diff --git a/src/g_inventory/a_weapons.cpp b/src/g_inventory/a_weapons.cpp index 0d18cbcc6..f9e635756 100644 --- a/src/g_inventory/a_weapons.cpp +++ b/src/g_inventory/a_weapons.cpp @@ -83,9 +83,8 @@ DEFINE_FIELD(AWeapon, FOVScale) DEFINE_FIELD(AWeapon, Crosshair) DEFINE_FIELD(AWeapon, GivenAsMorphWeapon) DEFINE_FIELD(AWeapon, bAltFire) -DEFINE_FIELD(AWeapon, SlotNumber) DEFINE_FIELD(AWeapon, WeaponFlags) -DEFINE_FIELD_BIT(AWeapon, WeaponFlags, bDehAmmo, WIF_DEHAMMO) +DEFINE_FIELD(AWeapon, bDehAmmo) //=========================================================================== // @@ -482,18 +481,23 @@ void FWeaponSlots::AddExtraWeapons() { continue; } - auto weapdef = ((AWeapon*)GetDefaultByType(cls)); - auto gf = cls->ActorInfo()->GameFilter; - if ((gf == GAME_Any || (gf & gameinfo.gametype)) && - cls->ActorInfo()->Replacement == nullptr && // Replaced weapons don't get slotted. - !(weapdef->WeaponFlags & WIF_POWERED_UP) && - !LocateWeapon(cls, nullptr, nullptr) // Don't duplicate it if it's already present. - ) + if (LocateWeapon(cls, nullptr, nullptr)) // Do we already have it? Don't add it again. { - int slot = weapdef->SlotNumber; - if ((unsigned)slot < NUM_WEAPON_SLOTS) + continue; + } + auto weapdef = ((AWeapon*)GetDefaultByType(cls)); + + // Let the weapon decide for itself if it wants to get added to a slot. + IFVIRTUALPTR(weapdef, AWeapon, CheckAddToSlots) + { + VMValue param = weapdef; + int slot = -1, slotpriority; + VMReturn rets[]{ &slot, &slotpriority }; + VMCall(func, ¶m, 1, rets, 2); + + if (slot >= 0 && slot < NUM_WEAPON_SLOTS) { - FWeaponSlot::WeaponInfo info = { cls, weapdef->SlotPriority }; + FWeaponSlot::WeaponInfo info = { cls, slotpriority }; Slots[slot].Weapons.Push(info); } } diff --git a/src/g_inventory/a_weapons.h b/src/g_inventory/a_weapons.h index 62097b633..1a7bfb0de 100644 --- a/src/g_inventory/a_weapons.h +++ b/src/g_inventory/a_weapons.h @@ -148,8 +148,6 @@ public: int BobStyle; // [XA] Bobbing style. Defines type of bobbing (e.g. Normal, Alpha) (visual only so no need to be a double) float BobSpeed; // [XA] Bobbing speed. Defines how quickly a weapon bobs. float BobRangeX, BobRangeY; // [XA] Bobbing range. Defines how far a weapon bobs in either direction. - int SlotNumber; - int SlotPriority; // In-inventory instance variables TObjPtr Ammo1, Ammo2; @@ -159,6 +157,7 @@ public: bool GivenAsMorphWeapon; // *** only accessed from ZScript. bool bAltFire; // *** only accessed from ZScript. Set when this weapon's alternate fire is used. + bool bDehAmmo; virtual void MarkPrecacheSounds() const; @@ -202,8 +201,7 @@ enum WIF_STAFF2_KICKBACK = 0x00002000, // the powered-up Heretic staff has special kickback WIF_NOAUTOAIM = 0x00004000, // this weapon never uses autoaim (useful for ballistic projectiles) WIF_MELEEWEAPON = 0x00008000, // melee weapon. Used by bots and monster AI. - WIF_DEHAMMO = 0x00010000, // Uses Doom's original amount of ammo for the respective attack functions so that old DEHACKED patches work as intended. - // AmmoUse1 will be set to the first attack's ammo use so that checking for empty weapons still works + //WIF_DEHAMMO = 0x00010000, WIF_NODEATHDESELECT = 0x00020000, // Don't jump to the Deselect state when the player dies WIF_NODEATHINPUT = 0x00040000, // The weapon cannot be fired/reloaded/whatever when the player is dead WIF_CHEATNOTWEAPON = 0x08000000, // Give cheat considers this not a weapon (used by Sigil) diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 522a569ee..8701f8f4e 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -1203,15 +1203,6 @@ DEFINE_CLASS_PROPERTY(bobstyle, S, Weapon) defaults->BobStyle = styles[match]; } -//========================================================================== -// -//========================================================================== -DEFINE_CLASS_PROPERTY(slotpriority, F, Weapon) -{ - PROP_DOUBLE_PARM(i, 0); - defaults->SlotPriority = int(i*65536); -} - //========================================================================== // //========================================================================== diff --git a/wadsrc/static/zscript/inventory/weapons.txt b/wadsrc/static/zscript/inventory/weapons.txt index d07239f4a..879063a63 100644 --- a/wadsrc/static/zscript/inventory/weapons.txt +++ b/wadsrc/static/zscript/inventory/weapons.txt @@ -31,8 +31,10 @@ class Weapon : StateProvider native native int Crosshair; // 0 to use player's crosshair native bool GivenAsMorphWeapon; native bool bAltFire; // Set when this weapon's alternate fire is used. - native readonly bool bDehAmmo; - native readonly int SlotNumber; + native readonly bool bDehAmmo; // Uses Doom's original amount of ammo for the respective attack functions so that old DEHACKED patches work as intended. + // AmmoUse1 will be set to the first attack's ammo use so that checking for empty weapons still works + meta int SlotNumber; + meta int SlotPriority; property AmmoGive: AmmoGive1; property AmmoGive1: AmmoGive1; @@ -55,6 +57,7 @@ class Weapon : StateProvider native property BobRangeX: BobRangeX; property BobRangeY: BobRangeY; property SlotNumber: SlotNumber; + property SlotPriority: SlotPriority; Default { @@ -74,6 +77,16 @@ class Weapon : StateProvider native SHTG E 0 A_Light0; Stop; } + + + virtual int, int CheckAddToSlots() + { + if (GetReplacement(GetClass()) == null && !bPowered_Up) + { + return SlotNumber, SlotPriority*65536; + } + return -1, 0; + } virtual State GetReadyState () {