mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
- scriptified the WeaponGiver.
This commit is contained in:
parent
42f3ccc602
commit
6d3b26f94c
6 changed files with 100 additions and 128 deletions
|
@ -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<PClassWeapon>(PClass::FindClass(di->Name));
|
||||
if (ti != NULL)
|
||||
{
|
||||
if (master == NULL)
|
||||
{
|
||||
master = weap = static_cast<AWeapon*>(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<AWeapon*>(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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -185,6 +185,7 @@ xx(PuzzleItemNumber)
|
|||
xx(HealthPickup)
|
||||
xx(autousemode)
|
||||
xx(Ammo)
|
||||
xx(WeaponGiver)
|
||||
xx(PowerTargeter)
|
||||
xx(PowerInvulnerable)
|
||||
xx(PowerStrength)
|
||||
|
|
|
@ -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<AWeaponGiver *>(inv)->DropAmmoFactor = dropammofactor;
|
||||
inv->FloatVar("AmmoFactor") = dropammofactor;
|
||||
inv->ItemFlags |= flagmask;
|
||||
}
|
||||
else if (inv->IsKindOf (RUNTIME_CLASS(AWeapon)))
|
||||
|
|
|
@ -7,6 +7,9 @@ class Weapon : StateProvider native
|
|||
EitherFire
|
||||
};
|
||||
|
||||
const ZOOM_INSTANT = 1;
|
||||
const ZOOM_NOSCALETURNING = 2;
|
||||
|
||||
native uint WeaponFlags;
|
||||
native class<Ammo> 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<Weapon> 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
|
||||
|
|
|
@ -212,7 +212,7 @@ struct PlayerInfo native // this is what internally is known as player_t
|
|||
native uint original_oldbuttons;
|
||||
native readonly Class<PlayerPawn> cls;
|
||||
native float DesiredFOV;
|
||||
native readonly float FOV;
|
||||
native float FOV;
|
||||
native double viewz;
|
||||
native double viewheight;
|
||||
native double deltaviewheight;
|
||||
|
|
Loading…
Reference in a new issue