mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-10 14:51:46 +00:00
- scriptified ammo.
- moved inventory stuff into its own directory.
This commit is contained in:
parent
d91023ba0b
commit
a597979738
13 changed files with 157 additions and 135 deletions
|
@ -2623,7 +2623,7 @@ void FParser::SF_MaxPlayerAmmo()
|
|||
}
|
||||
else if(t_argc >= 3)
|
||||
{
|
||||
AAmmo * iammo = (AAmmo*)players[playernum].mo->FindInventory(ammotype);
|
||||
auto iammo = players[playernum].mo->FindInventory(ammotype);
|
||||
amount = intvalue(t_argv[2]);
|
||||
if(amount < 0) amount = 0;
|
||||
if (!iammo)
|
||||
|
@ -2644,7 +2644,7 @@ void FParser::SF_MaxPlayerAmmo()
|
|||
break;
|
||||
}
|
||||
}
|
||||
iammo->BackpackMaxAmount=amount;
|
||||
((AAmmo*)iammo)->BackpackMaxAmount=amount;
|
||||
}
|
||||
|
||||
t_return.type = svt_int;
|
||||
|
|
|
@ -84,117 +84,12 @@ PClassActor *AAmmo::GetParentAmmo () const
|
|||
return static_cast<PClassActor *>(type);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// AAmmo :: HandlePickup
|
||||
//
|
||||
//===========================================================================
|
||||
EXTERN_CVAR(Bool, sv_unlimited_pickup)
|
||||
|
||||
bool AAmmo::HandlePickup (AInventory *item)
|
||||
DEFINE_ACTION_FUNCTION(AAmmo, GetParentAmmo)
|
||||
{
|
||||
if (GetClass() == item->GetClass() ||
|
||||
(item->IsKindOf (RUNTIME_CLASS(AAmmo)) && static_cast<AAmmo*>(item)->GetParentAmmo() == GetClass()))
|
||||
{
|
||||
if (Amount < MaxAmount || sv_unlimited_pickup)
|
||||
{
|
||||
int receiving = item->Amount;
|
||||
|
||||
if (!(item->ItemFlags & IF_IGNORESKILL))
|
||||
{ // extra ammo in baby mode and nightmare mode
|
||||
receiving = int(receiving * G_SkillProperty(SKILLP_AmmoFactor));
|
||||
}
|
||||
int oldamount = Amount;
|
||||
|
||||
if (Amount > 0 && Amount + receiving < 0)
|
||||
{
|
||||
Amount = 0x7fffffff;
|
||||
}
|
||||
else
|
||||
{
|
||||
Amount += receiving;
|
||||
}
|
||||
if (Amount > MaxAmount && !sv_unlimited_pickup)
|
||||
{
|
||||
Amount = MaxAmount;
|
||||
}
|
||||
item->ItemFlags |= IF_PICKUPGOOD;
|
||||
|
||||
// If the player previously had this ammo but ran out, possibly switch
|
||||
// to a weapon that uses it, but only if the player doesn't already
|
||||
// have a weapon pending.
|
||||
|
||||
assert (Owner != NULL);
|
||||
|
||||
if (oldamount == 0 && Owner != NULL && Owner->player != NULL)
|
||||
{
|
||||
barrier_cast<APlayerPawn *>(Owner)->CheckWeaponSwitch(GetClass());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
PARAM_SELF_PROLOGUE(AAmmo);
|
||||
ACTION_RETURN_OBJECT(self->GetParentAmmo());
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// AAmmo :: CreateCopy
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
AInventory *AAmmo::CreateCopy (AActor *other)
|
||||
{
|
||||
AInventory *copy;
|
||||
int amount = Amount;
|
||||
|
||||
// extra ammo in baby mode and nightmare mode
|
||||
if (!(ItemFlags&IF_IGNORESKILL))
|
||||
{
|
||||
amount = int(amount * G_SkillProperty(SKILLP_AmmoFactor));
|
||||
}
|
||||
|
||||
if (GetClass()->ParentClass != RUNTIME_CLASS(AAmmo) && GetClass() != RUNTIME_CLASS(AAmmo))
|
||||
{
|
||||
PClassActor *type = GetParentAmmo();
|
||||
if (!GoAway ())
|
||||
{
|
||||
Destroy ();
|
||||
}
|
||||
|
||||
copy = static_cast<AInventory *>(Spawn (type));
|
||||
copy->Amount = amount;
|
||||
copy->BecomeItem ();
|
||||
}
|
||||
else
|
||||
{
|
||||
copy = Super::CreateCopy (other);
|
||||
copy->Amount = amount;
|
||||
}
|
||||
if (copy->Amount > copy->MaxAmount)
|
||||
{ // Don't pick up more ammo than you're supposed to be able to carry.
|
||||
copy->Amount = copy->MaxAmount;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// AAmmo :: CreateTossable
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
AInventory *AAmmo::CreateTossable()
|
||||
{
|
||||
AInventory *copy = Super::CreateTossable();
|
||||
if (copy != NULL)
|
||||
{ // Do not increase ammo by dropping it and picking it back up at
|
||||
// certain skill levels.
|
||||
copy->ItemFlags |= IF_IGNORESKILL;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
// Backpack -----------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CLASS(ABackpackItem, false, false)
|
||||
|
@ -214,6 +109,7 @@ void ABackpackItem::Serialize(FSerializer &arc)
|
|||
arc("bdepleted", bDepleted, def->bDepleted);
|
||||
}
|
||||
|
||||
EXTERN_CVAR(Bool, sv_unlimited_pickup)
|
||||
//===========================================================================
|
||||
//
|
||||
// ABackpackItem :: CreateCopy
|
||||
|
|
|
@ -7,9 +7,6 @@ class AAmmo : public AInventory
|
|||
public:
|
||||
|
||||
virtual void Serialize(FSerializer &arc) override;
|
||||
virtual AInventory *CreateCopy (AActor *other) override;
|
||||
virtual bool HandlePickup (AInventory *item) override;
|
||||
virtual AInventory *CreateTossable () override;
|
||||
PClassActor *GetParentAmmo () const;
|
||||
|
||||
int BackpackAmount, BackpackMaxAmount, DropAmount;
|
||||
|
|
|
@ -486,6 +486,12 @@ bool AInventory::GoAway ()
|
|||
return true;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AInventory, GoAway)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AInventory);
|
||||
ACTION_RETURN_BOOL(self->GoAway());
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// AInventory :: GoAwayAndDie
|
||||
|
|
|
@ -1048,6 +1048,13 @@ void APlayerPawn::CheckWeaponSwitch(PClassInventory *ammotype)
|
|||
}
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(APlayerPawn, CheckWeaponSwitch)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(APlayerPawn);
|
||||
PARAM_OBJECT(ammotype, PClassInventory);
|
||||
self->CheckWeaponSwitch(ammotype);
|
||||
return 0;
|
||||
}
|
||||
//===========================================================================
|
||||
//
|
||||
// APlayerPawn :: GiveDeathmatchInventory
|
||||
|
|
|
@ -6,11 +6,13 @@
|
|||
#include "zscript/actor.txt"
|
||||
#include "zscript/actor_checks.txt"
|
||||
|
||||
#include "zscript/shared/inventory.txt"
|
||||
#include "zscript/shared/inv_misc.txt"
|
||||
#include "zscript/shared/weapons.txt"
|
||||
#include "zscript/shared/armor.txt"
|
||||
#include "zscript/shared/powerups.txt"
|
||||
#include "zscript/inventory/inventory.txt"
|
||||
#include "zscript/inventory/inv_misc.txt"
|
||||
#include "zscript/inventory/weapons.txt"
|
||||
#include "zscript/inventory/armor.txt"
|
||||
#include "zscript/inventory/ammo.txt"
|
||||
#include "zscript/inventory/powerups.txt"
|
||||
|
||||
#include "zscript/shared/player.txt"
|
||||
#include "zscript/shared/morph.txt"
|
||||
#include "zscript/shared/botstuff.txt"
|
||||
|
|
129
wadsrc/static/zscript/inventory/ammo.txt
Normal file
129
wadsrc/static/zscript/inventory/ammo.txt
Normal file
|
@ -0,0 +1,129 @@
|
|||
|
||||
class Ammo : Inventory native
|
||||
{
|
||||
native int BackpackAmount;
|
||||
native int BackpackMaxAmount;
|
||||
|
||||
Default
|
||||
{
|
||||
+INVENTORY.KEEPDEPLETED
|
||||
Inventory.PickupSound "misc/ammo_pkup";
|
||||
}
|
||||
|
||||
native Class<Actor> GetParentAmmo ();
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// AAmmo :: HandlePickup
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
override bool HandlePickup (Inventory item)
|
||||
{
|
||||
let ammoitem = Ammo(item);
|
||||
if (ammoitem != null && ammoitem.GetParentAmmo() == GetClass())
|
||||
{
|
||||
if (Amount < MaxAmount || sv_unlimited_pickup)
|
||||
{
|
||||
int receiving = item.Amount;
|
||||
|
||||
if (!item.bIgnoreSkill)
|
||||
{ // extra ammo in baby mode and nightmare mode
|
||||
receiving = int(receiving * G_SkillPropertyFloat(SKILLP_AmmoFactor));
|
||||
}
|
||||
int oldamount = Amount;
|
||||
|
||||
if (Amount > 0 && Amount + receiving < 0)
|
||||
{
|
||||
Amount = 0x7fffffff;
|
||||
}
|
||||
else
|
||||
{
|
||||
Amount += receiving;
|
||||
}
|
||||
if (Amount > MaxAmount && !sv_unlimited_pickup)
|
||||
{
|
||||
Amount = MaxAmount;
|
||||
}
|
||||
item.bPickupGood = true;
|
||||
|
||||
// If the player previously had this ammo but ran out, possibly switch
|
||||
// to a weapon that uses it, but only if the player doesn't already
|
||||
// have a weapon pending.
|
||||
|
||||
if (oldamount == 0 && Owner != null && Owner.player != null)
|
||||
{
|
||||
PlayerPawn(Owner).CheckWeaponSwitch(GetClass());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// AAmmo :: CreateCopy
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
override Inventory CreateCopy (Actor other)
|
||||
{
|
||||
Inventory copy;
|
||||
int amount = Amount;
|
||||
|
||||
// extra ammo in baby mode and nightmare mode
|
||||
if (!bIgnoreSkill)
|
||||
{
|
||||
amount = int(amount * G_SkillPropertyFloat(SKILLP_AmmoFactor));
|
||||
}
|
||||
|
||||
let type = GetParentAmmo();
|
||||
if (GetClass() == type)
|
||||
{
|
||||
if (!GoAway ())
|
||||
{
|
||||
Destroy ();
|
||||
}
|
||||
|
||||
copy = Inventory(Spawn (type));
|
||||
copy.Amount = amount;
|
||||
copy.BecomeItem ();
|
||||
}
|
||||
else
|
||||
{
|
||||
copy = Super.CreateCopy (other);
|
||||
copy.Amount = amount;
|
||||
}
|
||||
if (copy.Amount > copy.MaxAmount)
|
||||
{ // Don't pick up more ammo than you're supposed to be able to carry.
|
||||
copy.Amount = copy.MaxAmount;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// AAmmo :: CreateTossable
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
override Inventory CreateTossable()
|
||||
{
|
||||
Inventory copy = Super.CreateTossable();
|
||||
if (copy != null)
|
||||
{ // Do not increase ammo by dropping it and picking it back up at
|
||||
// certain skill levels.
|
||||
copy.bIgnoreSkill = true;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class BackpackItem : Inventory native
|
||||
{
|
||||
native bool bDepleted;
|
||||
}
|
||||
|
|
@ -42,6 +42,7 @@ class Inventory : Actor native
|
|||
virtual bool GetNoTeleportFreeze() { return false; }
|
||||
virtual void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive) {}
|
||||
|
||||
native bool GoAway();
|
||||
native void GoAwayAndDie();
|
||||
native void BecomeItem();
|
||||
native void BecomePickup();
|
|
@ -125,20 +125,3 @@ class WeaponPiece : Inventory native
|
|||
}
|
||||
}
|
||||
|
||||
class Ammo : Inventory native
|
||||
{
|
||||
native int BackpackAmount;
|
||||
native int BackpackMaxAmount;
|
||||
|
||||
Default
|
||||
{
|
||||
+INVENTORY.KEEPDEPLETED
|
||||
Inventory.PickupSound "misc/ammo_pkup";
|
||||
}
|
||||
}
|
||||
|
||||
class BackpackItem : Inventory native
|
||||
{
|
||||
native bool bDepleted;
|
||||
}
|
||||
|
|
@ -105,6 +105,7 @@ class PlayerPawn : Actor native
|
|||
|
||||
native int GetMaxHealth();
|
||||
native bool ResetAirSupply (bool playgasp = false);
|
||||
native void CheckWeaponSwitch(class<Inventory> item);
|
||||
}
|
||||
|
||||
class PlayerChunk : PlayerPawn native
|
||||
|
|
Loading…
Reference in a new issue