diff --git a/src/g_inventory/a_weapons.cpp b/src/g_inventory/a_weapons.cpp index 1b7745979..823915aea 100644 --- a/src/g_inventory/a_weapons.cpp +++ b/src/g_inventory/a_weapons.cpp @@ -936,65 +936,6 @@ FState *AWeapon::GetStateForButtonName (FName button) } -/* Weapon giver ***********************************************************/ - -IMPLEMENT_CLASS(AWeaponGiver, false, false) - -DEFINE_FIELD(AWeaponGiver, DropAmmoFactor); - -void AWeaponGiver::Serialize(FSerializer &arc) -{ - Super::Serialize(arc); - auto def = (AWeaponGiver *)GetDefault(); - arc("dropammofactor", DropAmmoFactor, def->DropAmmoFactor); -} - -bool AWeaponGiver::TryPickup(AActor *&toucher) -{ - DDropItem *di = GetDropItems(); - AWeapon *weap; - - if (di != NULL) - { - PClassWeapon *ti = dyn_cast(PClass::FindClass(di->Name)); - if (ti != NULL) - { - if (master == NULL) - { - master = weap = static_cast(Spawn(di->Name)); - if (weap != NULL) - { - weap->ItemFlags &= ~IF_ALWAYSPICKUP; // use the flag of this item only. - weap->flags = (weap->flags & ~MF_DROPPED) | (this->flags & MF_DROPPED); - - // If our ammo gives are non-negative, transfer them to the real weapon. - if (AmmoGive1 >= 0) weap->AmmoGive1 = AmmoGive1; - if (AmmoGive2 >= 0) weap->AmmoGive2 = AmmoGive2; - - // If DropAmmoFactor is non-negative, modify the given ammo amounts. - if (DropAmmoFactor > 0) - { - weap->AmmoGive1 = int(weap->AmmoGive1 * DropAmmoFactor); - weap->AmmoGive2 = int(weap->AmmoGive2 * DropAmmoFactor); - } - weap->BecomeItem(); - } - else return false; - } - - weap = barrier_cast(master); - bool res = weap->CallTryPickup(toucher); - if (res) - { - GoAwayAndDie(); - master = NULL; - } - return res; - } - } - return false; -} - /* Weapon slots ***********************************************************/ //=========================================================================== @@ -2079,48 +2020,3 @@ PClassWeapon *Net_ReadWeapon(BYTE **stream) return Weapons_ntoh[index]; } -//=========================================================================== -// -// A_ZoomFactor -// -//=========================================================================== - -DEFINE_ACTION_FUNCTION(AWeapon, A_ZoomFactor) -{ - PARAM_ACTION_PROLOGUE(AActor); - PARAM_FLOAT_DEF(zoom); - PARAM_INT_DEF(flags); - - if (self->player != NULL && self->player->ReadyWeapon != NULL) - { - zoom = 1 / clamp(zoom, 0.1, 50.0); - if (flags & 1) - { // Make the zoom instant. - self->player->FOV = float(self->player->DesiredFOV * zoom); - } - if (flags & 2) - { // Disable pitch/yaw scaling. - zoom = -zoom; - } - self->player->ReadyWeapon->FOVScale = float(zoom); - } - return 0; -} - -//=========================================================================== -// -// A_SetCrosshair -// -//=========================================================================== - -DEFINE_ACTION_FUNCTION(AWeapon, A_SetCrosshair) -{ - PARAM_ACTION_PROLOGUE(AActor); - PARAM_INT(xhair); - - if (self->player != NULL && self->player->ReadyWeapon != NULL) - { - self->player->ReadyWeapon->Crosshair = xhair; - } - return 0; -} diff --git a/src/g_inventory/a_weapons.h b/src/g_inventory/a_weapons.h index ed18df421..504529805 100644 --- a/src/g_inventory/a_weapons.h +++ b/src/g_inventory/a_weapons.h @@ -217,14 +217,3 @@ enum WIF_BOT_BFG = 1<<28, // this is a BFG }; -class AWeaponGiver : public AWeapon -{ - DECLARE_CLASS (AWeaponGiver, AWeapon) - -public: - virtual bool TryPickup(AActor *&toucher) override; - virtual void Serialize(FSerializer &arc) override; - - double DropAmmoFactor; -}; - diff --git a/src/namedef.h b/src/namedef.h index b730e93aa..20953a8fe 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -185,6 +185,7 @@ xx(PuzzleItemNumber) xx(HealthPickup) xx(autousemode) xx(Ammo) +xx(WeaponGiver) xx(PowerTargeter) xx(PowerInvulnerable) xx(PowerStrength) diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index e4a902b44..bb90e976f 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -3248,9 +3248,9 @@ void ModifyDropAmount(AInventory *inv, int dropamount) inv->Amount = amount; inv->ItemFlags |= flagmask; } - else if (inv->IsKindOf (RUNTIME_CLASS(AWeaponGiver))) + else if (inv->IsKindOf (PClass::FindActor(NAME_WeaponGiver))) { - static_cast(inv)->DropAmmoFactor = dropammofactor; + inv->FloatVar("AmmoFactor") = dropammofactor; inv->ItemFlags |= flagmask; } else if (inv->IsKindOf (RUNTIME_CLASS(AWeapon))) diff --git a/wadsrc/static/zscript/inventory/weapons.txt b/wadsrc/static/zscript/inventory/weapons.txt index bf514b70a..cd558308d 100644 --- a/wadsrc/static/zscript/inventory/weapons.txt +++ b/wadsrc/static/zscript/inventory/weapons.txt @@ -7,6 +7,9 @@ class Weapon : StateProvider native EitherFire }; + const ZOOM_INSTANT = 1; + const ZOOM_NOSCALETURNING = 2; + native uint WeaponFlags; native class AmmoType1, AmmoType2; // Types of ammo used by this weapon native int AmmoGive1, AmmoGive2; // Amount of each ammo to get when picking up weapon @@ -206,25 +209,108 @@ class Weapon : StateProvider native player.ReadyWeapon.CheckAmmo (player.ReadyWeapon.bAltFire ? Weapon.AltFire : Weapon.PrimaryFire, true); } } - - - native action void A_ZoomFactor(double scale = 1, int flags = 0); - native action void A_SetCrosshair(int xhair); - const ZOOM_INSTANT = 1; - const ZOOM_NOSCALETURNING = 2; - + + //=========================================================================== + // + // A_ZoomFactor + // + //=========================================================================== + + action void A_ZoomFactor(double zoom = 1, int flags = 0) + { + let player = self.player; + if (player != NULL && player.ReadyWeapon != NULL) + { + zoom = 1 / clamp(zoom, 0.1, 50.0); + if (flags & 1) + { // Make the zoom instant. + self.player.FOV = self.player.DesiredFOV * zoom; + } + if (flags & 2) + { // Disable pitch/yaw scaling. + zoom = -zoom; + } + self.player.ReadyWeapon.FOVScale = zoom; + } + } + + //=========================================================================== + // + // A_SetCrosshair + // + //=========================================================================== + + action void A_SetCrosshair(int xhair) + { + let player = self.player; + if (player != NULL && player.ReadyWeapon != NULL) + { + player.ReadyWeapon.Crosshair = xhair; + } + } } -class WeaponGiver : Weapon native +class WeaponGiver : Weapon { - - native double DropAmmoFactor; + double AmmoFactor; Default { Weapon.AmmoGive1 -1; Weapon.AmmoGive2 -1; } + + override bool TryPickup(in out Actor toucher) + { + DropItem di = GetDropItems(); + Weapon weap; + + if (di != NULL) + { + Class ti = di.Name; + if (ti != NULL) + { + if (master == NULL) + { + // save the spawned weapon in 'master' to avoid constant respawning if it cannot be picked up. + master = weap = Weapon(Spawn(di.Name)); + if (weap != NULL) + { + weap.bAlwaysPickup = false; // use the flag of this item only. + weap.bDropped = bDropped; + + // If our ammo gives are non-negative, transfer them to the real weapon. + if (AmmoGive1 >= 0) weap.AmmoGive1 = AmmoGive1; + if (AmmoGive2 >= 0) weap.AmmoGive2 = AmmoGive2; + + // If AmmoFactor is non-negative, modify the given ammo amounts. + if (AmmoFactor > 0) + { + weap.AmmoGive1 = int(weap.AmmoGive1 * AmmoFactor); + weap.AmmoGive2 = int(weap.AmmoGive2 * AmmoFactor); + } + weap.BecomeItem(); + } + else return false; + } + + weap = Weapon(master); + bool res = false; + if (weap != null) + { + res = weap.CallTryPickup(toucher); + if (res) + { + GoAwayAndDie(); + master = NULL; + } + } + return res; + } + } + return false; + } + } struct WeaponSlots native diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index b9feb6cd0..e90f85a78 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -212,7 +212,7 @@ struct PlayerInfo native // this is what internally is known as player_t native uint original_oldbuttons; native readonly Class cls; native float DesiredFOV; - native readonly float FOV; + native float FOV; native double viewz; native double viewheight; native double deltaviewheight;