- added Gez's submission for inventory restrictions but changed the added checks to be in the main CallTryPickup function.

SVN r3296 (trunk)
This commit is contained in:
Christoph Oelckers 2011-09-23 08:23:51 +00:00
parent a0bb1c2546
commit 3c47a30249
17 changed files with 158 additions and 199 deletions

View file

@ -25,44 +25,6 @@ static FRandom pr_wraithvergedrop ("WraithvergeDrop");
void SpawnSpiritTail (AActor *spirit);
//==========================================================================
class AClericWeaponPiece : public AWeaponPiece
{
DECLARE_CLASS (AClericWeaponPiece, AWeaponPiece)
protected:
bool TryPickup (AActor *&toucher);
};
IMPLEMENT_CLASS (AClericWeaponPiece)
bool AClericWeaponPiece::TryPickup (AActor *&toucher)
{
if (!toucher->IsKindOf (PClass::FindClass(NAME_MagePlayer)) &&
!toucher->IsKindOf (PClass::FindClass(NAME_FighterPlayer)))
{
return Super::TryPickup(toucher);
}
else
{ // Wrong class, but try to pick up for ammo
if (ShouldStay())
{
// Can't pick up weapons for other classes in coop netplay
return false;
}
AWeapon * Defaults=(AWeapon*)GetDefaultByType(WeaponClass);
bool gaveSome = !!(toucher->GiveAmmo (Defaults->AmmoType1, Defaults->AmmoGive1) +
toucher->GiveAmmo (Defaults->AmmoType2, Defaults->AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
}
// Cleric's Wraithverge (Holy Symbol?) --------------------------------------
class ACWeapWraithverge : public AClericWeapon

View file

@ -11,87 +11,10 @@
#include "thingdef/thingdef.h"
*/
// Fighter Weapon Base Class ------------------------------------------------
IMPLEMENT_CLASS (AFighterWeapon)
IMPLEMENT_CLASS (AClericWeapon)
IMPLEMENT_CLASS (AMageWeapon)
bool AFighterWeapon::TryPickup (AActor *&toucher)
{
// The Doom and Hexen players are not excluded from pickup in case
// somebody wants to use these weapons with either of those games.
if (toucher->IsKindOf (PClass::FindClass(NAME_ClericPlayer)) ||
toucher->IsKindOf (PClass::FindClass(NAME_MagePlayer)))
{ // Wrong class, but try to pick up for mana
if (ShouldStay())
{ // Can't pick up weapons for other classes in coop netplay
return false;
}
bool gaveSome = (NULL != AddAmmo (toucher, AmmoType1, AmmoGive1));
gaveSome |= (NULL != AddAmmo (toucher, AmmoType2, AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
return Super::TryPickup (toucher);
}
// Cleric Weapon Base Class -------------------------------------------------
bool AClericWeapon::TryPickup (AActor *&toucher)
{
// The Doom and Hexen players are not excluded from pickup in case
// somebody wants to use these weapons with either of those games.
if (toucher->IsKindOf (PClass::FindClass(NAME_FighterPlayer)) ||
toucher->IsKindOf (PClass::FindClass(NAME_MagePlayer)))
{ // Wrong class, but try to pick up for mana
if (ShouldStay())
{ // Can't pick up weapons for other classes in coop netplay
return false;
}
bool gaveSome = (NULL != AddAmmo (toucher, AmmoType1, AmmoGive1));
gaveSome |= (NULL != AddAmmo (toucher, AmmoType2, AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
return Super::TryPickup (toucher);
}
// Mage Weapon Base Class ---------------------------------------------------
bool AMageWeapon::TryPickup (AActor *&toucher)
{
// The Doom and Hexen players are not excluded from pickup in case
// somebody wants to use these weapons with either of those games.
if (toucher->IsKindOf (PClass::FindClass(NAME_FighterPlayer)) ||
toucher->IsKindOf (PClass::FindClass(NAME_ClericPlayer)))
{ // Wrong class, but try to pick up for mana
if (ShouldStay())
{ // Can't pick up weapons for other classes in coop netplay
return false;
}
bool gaveSome = (NULL != AddAmmo (toucher, AmmoType1, AmmoGive1));
gaveSome |= (NULL != AddAmmo (toucher, AmmoType2, AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
return Super::TryPickup (toucher);
}
static FRandom pr_fpatk ("FPunchAttack");
//============================================================================

View file

@ -18,43 +18,6 @@ static FRandom pr_fswordflame ("FSwordFlame");
//==========================================================================
class AFighterWeaponPiece : public AWeaponPiece
{
DECLARE_CLASS (AFighterWeaponPiece, AWeaponPiece)
protected:
bool TryPickup (AActor *&toucher);
};
IMPLEMENT_CLASS (AFighterWeaponPiece)
bool AFighterWeaponPiece::TryPickup (AActor *&toucher)
{
if (!toucher->IsKindOf (PClass::FindClass(NAME_ClericPlayer)) &&
!toucher->IsKindOf (PClass::FindClass(NAME_MagePlayer)))
{
return Super::TryPickup(toucher);
}
else
{ // Wrong class, but try to pick up for ammo
if (ShouldStay())
{
// Can't pick up weapons for other classes in coop netplay
return false;
}
AWeapon * Defaults=(AWeapon*)GetDefaultByType(WeaponClass);
bool gaveSome = !!(toucher->GiveAmmo (Defaults->AmmoType1, Defaults->AmmoGive1) +
toucher->GiveAmmo (Defaults->AmmoType2, Defaults->AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
}
//============================================================================
//
// A_DropQuietusPieces

View file

@ -15,21 +15,18 @@ class AFighterWeapon : public AWeapon
{
DECLARE_CLASS (AFighterWeapon, AWeapon);
public:
bool TryPickup (AActor *&toucher);
};
class AClericWeapon : public AWeapon
{
DECLARE_CLASS (AClericWeapon, AWeapon);
public:
bool TryPickup (AActor *&toucher);
};
class AMageWeapon : public AWeapon
{
DECLARE_CLASS (AMageWeapon, AWeapon);
public:
bool TryPickup (AActor *&toucher);
};
#endif //__A_HEXENGLOBAL_H__

View file

@ -23,44 +23,6 @@ static AActor *FrontBlockCheck (AActor *mo, int index, void *);
static divline_t BlockCheckLine;
//==========================================================================
class AMageWeaponPiece : public AWeaponPiece
{
DECLARE_CLASS (AMageWeaponPiece, AWeaponPiece)
protected:
bool TryPickup (AActor *&toucher);
};
IMPLEMENT_CLASS (AMageWeaponPiece)
bool AMageWeaponPiece::TryPickup (AActor *&toucher)
{
if (!toucher->IsKindOf (PClass::FindClass(NAME_ClericPlayer)) &&
!toucher->IsKindOf (PClass::FindClass(NAME_FighterPlayer)))
{
return Super::TryPickup(toucher);
}
else
{ // Wrong class, but try to pick up for ammo
if (ShouldStay())
{
// Can't pick up weapons for other classes in coop netplay
return false;
}
AWeapon * Defaults=(AWeapon*)GetDefaultByType(WeaponClass);
bool gaveSome = !!(toucher->GiveAmmo (Defaults->AmmoType1, Defaults->AmmoGive1) +
toucher->GiveAmmo (Defaults->AmmoType2, Defaults->AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
}
// The Mages's Staff (Bloodscourge) -----------------------------------------
class AMWeapBloodscourge : public AMageWeapon

View file

@ -1266,13 +1266,29 @@ bool AInventory::TryPickup (AActor *&toucher)
//===========================================================================
//
// AInventory :: TryPickup
// AInventory :: TryPickupRestricted
//
//===========================================================================
bool AInventory::TryPickupRestricted (AActor *&toucher)
{
return false;
}
//===========================================================================
//
// AInventory :: CallTryPickup
//
//===========================================================================
bool AInventory::CallTryPickup (AActor *toucher, AActor **toucher_return)
{
bool res = TryPickup(toucher);
bool res;
if (CanPickup(toucher))
res = TryPickup(toucher);
else
res = TryPickupRestricted(toucher); // let an item decide for itself how it will handle this
// Morph items can change the toucher so we need an option to return this info.
if (toucher_return != NULL) *toucher_return = toucher;
@ -1288,6 +1304,40 @@ bool AInventory::CallTryPickup (AActor *toucher, AActor **toucher_return)
}
//===========================================================================
//
// AInventory :: CanPickup
//
//===========================================================================
bool AInventory::CanPickup (AActor *toucher)
{
if (!toucher)
return false;
FActorInfo *ai = GetClass()->ActorInfo;
// Is the item restricted to certain player classes?
if (ai->RestrictedToPlayerClass.Size() != 0)
{
for (unsigned i = 0; i < ai->RestrictedToPlayerClass.Size(); ++i)
{
if (toucher->IsKindOf(ai->RestrictedToPlayerClass[i]))
return true;
}
return false;
}
// Or is it forbidden to certain other classes?
else
{
for (unsigned i = 0; i < ai->ForbiddenToPlayerClass.Size(); ++i)
{
if (toucher->IsKindOf(ai->ForbiddenToPlayerClass[i]))
return false;
}
}
return true;
}
//===========================================================================
//
// CCMD printinv

View file

@ -198,6 +198,8 @@ public:
protected:
virtual bool TryPickup (AActor *&toucher);
virtual bool TryPickupRestricted (AActor *&toucher);
bool CanPickup(AActor * toucher);
void GiveQuest(AActor * toucher);
private:
@ -277,6 +279,7 @@ public:
virtual AInventory *CreateCopy (AActor *other);
virtual AInventory *CreateTossable ();
virtual bool TryPickup (AActor *&toucher);
virtual bool TryPickupRestricted (AActor *&toucher);
virtual bool PickupForAmmo (AWeapon *ownedWeapon);
virtual bool Use (bool pickup);
virtual void Destroy();

View file

@ -23,6 +23,34 @@ void AWeaponPiece::Serialize (FArchive &arc)
arc << WeaponClass << FullWeapon << PieceValue;
}
//==========================================================================
//
// TryPickupWeaponPiece
//
//==========================================================================
bool AWeaponPiece::TryPickupRestricted (AActor *&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;
}
AWeapon * Defaults=(AWeapon*)GetDefaultByType(WeaponClass);
bool gaveSome = !!(toucher->GiveAmmo (Defaults->AmmoType1, Defaults->AmmoGive1) +
toucher->GiveAmmo (Defaults->AmmoType2, Defaults->AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
//==========================================================================
//
// TryPickupWeaponPiece

View file

@ -8,6 +8,7 @@ protected:
public:
void Serialize (FArchive &arc);
bool TryPickup (AActor *&toucher);
bool TryPickupRestricted (AActor *&toucher);
bool ShouldStay ();
virtual const char *PickupMessage ();
virtual void PlayPickupSound (AActor *toucher);

View file

@ -72,6 +72,30 @@ void AWeapon::Serialize (FArchive &arc)
//
//===========================================================================
bool AWeapon::TryPickupRestricted (AActor *&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;
}
bool gaveSome = (NULL != AddAmmo (toucher, AmmoType1, AmmoGive1));
gaveSome |= (NULL != AddAmmo (toucher, AmmoType2, AmmoGive2));
if (gaveSome)
{
GoAwayAndDie ();
}
return gaveSome;
}
//===========================================================================
//
// AWeapon :: TryPickup
//
//===========================================================================
bool AWeapon::TryPickup (AActor *&toucher)
{
FState * ReadyState = FindState(NAME_Ready);

View file

@ -211,6 +211,8 @@ struct FActorInfo
PainFlashList *PainFlashes;
FPlayerColorSetMap *ColorSets;
TArray<const PClass *> VisibleToPlayerClass;
TArray<const PClass *> RestrictedToPlayerClass;
TArray<const PClass *> ForbiddenToPlayerClass;
};
class FDoomEdMap

View file

@ -146,6 +146,11 @@ FActorInfo *CreateNewActor(const FScriptPosition &sc, FName typeName, FName pare
info = ti->ActorInfo;
}
// Copy class lists from parent
info->ForbiddenToPlayerClass = parent->ActorInfo->ForbiddenToPlayerClass;
info->RestrictedToPlayerClass = parent->ActorInfo->RestrictedToPlayerClass;
info->VisibleToPlayerClass = parent->ActorInfo->VisibleToPlayerClass;
if (parent->ActorInfo->DamageFactors != NULL)
{
// copy damage factors from parent

View file

@ -1248,9 +1248,11 @@ DEFINE_PROPERTY(visibletoteam, I, Actor)
//==========================================================================
DEFINE_PROPERTY(visibletoplayerclass, S_s, Actor)
{
info->VisibleToPlayerClass.Clear();
for(int i = 0;i < PROP_PARM_COUNT;++i)
{
PROP_STRING_PARM(n, i);
if (*n != 0)
info->VisibleToPlayerClass.Push(FindClassTentative(n, "PlayerPawn"));
}
}
@ -1261,6 +1263,34 @@ DEFINE_PROPERTY(visibletoplayerclass, S_s, Actor)
//
//==========================================================================
//==========================================================================
//
//==========================================================================
DEFINE_CLASS_PROPERTY(restrictedto, S_s, Inventory)
{
info->RestrictedToPlayerClass.Clear();
for(int i = 0;i < PROP_PARM_COUNT;++i)
{
PROP_STRING_PARM(n, i);
if (*n != 0)
info->RestrictedToPlayerClass.Push(FindClassTentative(n, "PlayerPawn"));
}
}
//==========================================================================
//
//==========================================================================
DEFINE_CLASS_PROPERTY(forbiddento, S_s, Inventory)
{
info->ForbiddenToPlayerClass.Clear();
for(int i = 0;i < PROP_PARM_COUNT;++i)
{
PROP_STRING_PARM(n, i);
if (*n != 0)
info->ForbiddenToPlayerClass.Push(FindClassTentative(n, "PlayerPawn"));
}
}
//==========================================================================
//
//==========================================================================

View file

@ -1,14 +1,20 @@
// The Doom and Heretic players are not excluded from pickup in case
// somebody wants to use these weapons with either of those games.
ACTOR FighterWeapon : Weapon native
{
Weapon.Kickback 150
Inventory.ForbiddenTo ClericPlayer, MagePlayer
}
ACTOR ClericWeapon : Weapon native
{
Weapon.Kickback 150
Inventory.ForbiddenTo FighterPlayer, MagePlayer
}
ACTOR MageWeapon : Weapon native
{
Weapon.Kickback 150
Inventory.ForbiddenTo FighterPlayer, ClericPlayer
}

View file

@ -1,10 +1,11 @@
// Cleric Weapon Piece ------------------------------------------------------
ACTOR ClericWeaponPiece : WeaponPiece native
ACTOR ClericWeaponPiece : WeaponPiece
{
Inventory.PickupSound "misc/w_pkup"
Inventory.PickupMessage "$TXT_WRAITHVERGE_PIECE"
Inventory.ForbiddenTo FighterPlayer, MagePlayer
WeaponPiece.Weapon CWeapWraithverge
+FLOATBOB
}

View file

@ -1,10 +1,11 @@
// Fighter Weapon Piece -----------------------------------------------------
ACTOR FighterWeaponPiece : WeaponPiece native
ACTOR FighterWeaponPiece : WeaponPiece
{
Inventory.PickupSound "misc/w_pkup"
Inventory.PickupMessage "$TXT_QUIETUS_PIECE"
Inventory.ForbiddenTo ClericPlayer, MagePlayer
WeaponPiece.Weapon FWeapQuietus
+FLOATBOB
}

View file

@ -1,10 +1,11 @@
// Mage Weapon Piece --------------------------------------------------------
ACTOR MageWeaponPiece : WeaponPiece native
ACTOR MageWeaponPiece : WeaponPiece
{
Inventory.PickupSound "misc/w_pkup"
Inventory.PickupMessage "$TXT_BLOODSCOURGE_PIECE"
Inventory.ForbiddenTo FighterPlayer, ClericPlayer
WeaponPiece.Weapon MWeapBloodscourge
+FLOATBOB
}