- some cleanup on the weapon slot interface.

This really shouldn't make any decisions from directly reading weapon class defaults.
This commit is contained in:
Christoph Oelckers 2018-11-25 07:21:02 +01:00
parent f218e95c4d
commit 8fa16b6c30
5 changed files with 34 additions and 28 deletions

View file

@ -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.

View file

@ -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;
}
if (LocateWeapon(cls, nullptr, nullptr)) // Do we already have it? Don't add it again.
{
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.
)
// Let the weapon decide for itself if it wants to get added to a slot.
IFVIRTUALPTR(weapdef, AWeapon, CheckAddToSlots)
{
int slot = weapdef->SlotNumber;
if ((unsigned)slot < NUM_WEAPON_SLOTS)
VMValue param = weapdef;
int slot = -1, slotpriority;
VMReturn rets[]{ &slot, &slotpriority };
VMCall(func, &param, 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);
}
}

View file

@ -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<AInventory*> 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)

View file

@ -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);
}
//==========================================================================
//
//==========================================================================

View file

@ -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
{
@ -75,6 +78,16 @@ class Weapon : StateProvider native
Stop;
}
virtual int, int CheckAddToSlots()
{
if (GetReplacement(GetClass()) == null && !bPowered_Up)
{
return SlotNumber, SlotPriority*65536;
}
return -1, 0;
}
virtual State GetReadyState ()
{
return FindState('Ready');