qzdoom-gpl/wadsrc/static/zscript/inventory/weaponpiece.txt

187 lines
4.1 KiB
Text
Raw Normal View History

class WeaponHolder : Inventory native
{
native int PieceMask;
native Class<Actor> PieceWeapon;
Default
{
+NOBLOCKMAP
+NOSECTOR
+INVENTORY.UNDROPPABLE
}
}
class WeaponPiece : Inventory native
{
Default
{
+WEAPONSPAWN;
}
native int PieceValue;
native Class<Weapon> WeaponClass;
native Weapon FullWeapon;
//==========================================================================
//
// TryPickupWeaponPiece
//
//==========================================================================
override bool TryPickupRestricted (in out Actor toucher)
{
// Wrong class, but try to pick up for ammo
if (ShouldStay())
{ // Can't pick up weapons for other classes in coop netplay
return false;
}
let Defaults = GetDefaultByType(WeaponClass);
bool gaveSome = !!(toucher.GiveAmmo (Defaults.AmmoType1, Defaults.AmmoGive1) +
toucher.GiveAmmo (Defaults.AmmoType2, Defaults.AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
//==========================================================================
//
// TryPickupWeaponPiece
//
//==========================================================================
override bool TryPickup (in out Actor toucher)
{
Inventory item;
WeaponHolder hold = NULL;
bool shouldStay = ShouldStay ();
int gaveAmmo;
let Defaults = GetDefaultByType(WeaponClass);
FullWeapon = NULL;
for(item=toucher.Inv; item; item=item.Inv)
{
hold = WeaponHolder(item);
if (hold != null)
{
if (hold.PieceWeapon == WeaponClass)
{
break;
}
hold = NULL;
}
}
if (!hold)
{
hold = WeaponHolder(Spawn("WeaponHolder"));
hold.BecomeItem();
hold.AttachToOwner(toucher);
hold.PieceMask = 0;
hold.PieceWeapon = WeaponClass;
}
if (shouldStay)
{
// Cooperative net-game
if (hold.PieceMask & PieceValue)
{
// Already has the piece
return false;
}
toucher.GiveAmmo (Defaults.AmmoType1, Defaults.AmmoGive1);
toucher.GiveAmmo (Defaults.AmmoType2, Defaults.AmmoGive2);
}
else
{ // Deathmatch or singleplayer game
gaveAmmo = toucher.GiveAmmo (Defaults.AmmoType1, Defaults.AmmoGive1) +
toucher.GiveAmmo (Defaults.AmmoType2, Defaults.AmmoGive2);
if (hold.PieceMask & PieceValue)
{
// Already has the piece, check if mana needed
if (!gaveAmmo) return false;
GoAwayAndDie();
return true;
}
}
hold.PieceMask |= PieceValue;
// Check if weapon assembled
if (hold.PieceMask == (1 << Defaults.health) - 1)
{
if (!toucher.FindInventory (WeaponClass))
{
FullWeapon= Weapon(Spawn(WeaponClass));
// The weapon itself should not give more ammo to the player.
FullWeapon.AmmoGive1 = 0;
FullWeapon.AmmoGive2 = 0;
FullWeapon.AttachToOwner(toucher);
FullWeapon.AmmoGive1 = Defaults.AmmoGive1;
FullWeapon.AmmoGive2 = Defaults.AmmoGive2;
}
}
GoAwayAndDie();
return true;
}
//===========================================================================
//
//
//
//===========================================================================
override bool ShouldStay ()
{
// We want a weapon piece to behave like a weapon, so follow the exact
// same logic as weapons when deciding whether or not to stay.
return (((multiplayer &&
(!deathmatch && !alwaysapplydmflags)) || sv_weaponstay) && !bDropped);
}
//===========================================================================
//
// PickupMessage
//
// Returns the message to print when this actor is picked up.
//
//===========================================================================
override String PickupMessage ()
{
if (FullWeapon)
{
return FullWeapon.PickupMessage();
}
else
{
return Super.PickupMessage();
}
}
//===========================================================================
//
// DoPlayPickupSound
//
// Plays a sound when this actor is picked up.
//
//===========================================================================
override void PlayPickupSound (Actor toucher)
{
if (FullWeapon)
{
FullWeapon.PlayPickupSound(toucher);
}
else
{
Super.PlayPickupSound(toucher);
}
}
}