- use an inventory flag to decide what items are slipped by DF_NO_HEALTH and DF_NO_ARMOR. With all the changes over the last 10 years this had become too spotty.

- use an enum type for ItemFlags, just like it was done for actor flags. Since the flag word is almost full it may soon be necessary to add a second one and then this kind of security check may become necessary.
This commit is contained in:
Christoph Oelckers 2017-02-28 21:45:47 +01:00
parent dc6c91042b
commit 12915b5f6e
7 changed files with 34 additions and 24 deletions

View File

@ -17,7 +17,7 @@ struct visstyle_t;
// A pickup is anything the player can pickup (i.e. weapons, ammo, powerups, etc)
enum
enum ItemFlag
{
IF_ACTIVATABLE = 1<<0, // can be activated
IF_ACTIVATED = 1<<1, // is currently activated
@ -46,8 +46,14 @@ enum
IF_TRANSFER = 1<<24, // All inventory items that the inventory item contains is also transfered to the pickuper
IF_NOTELEPORTFREEZE = 1<<25, // does not 'freeze' the player right after teleporting.
IF_NOSCREENBLINK = 1<<26, // Does not blink the screen overlay when expiring.
IF_ISHEALTH = 1<<27, // for the DM flag so that it can recognize items that are not obviously health givers.
IF_ISARMOR = 1<<28, // for the DM flag so that it can recognize items that are not obviously armor givers.
};
typedef TFlags<ItemFlag> InvFlags;
//typedef TFlags<ItemFlag2> ItemFlags2;
DEFINE_TFLAGS_OPERATORS(InvFlags)
//DEFINE_TFLAGS_OPERATORS(ItemFlags2)
class AInventory : public AActor
{
@ -89,7 +95,7 @@ public:
PClassActor *SpawnPointClass; // For respawning like Heretic's mace
FTextureID AltHUDIcon;
DWORD ItemFlags;
InvFlags ItemFlags;
PClassActor *PickupFlash; // actor to spawn as pickup flash
FSoundIDNoInit PickupSound;

View File

@ -3217,13 +3217,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_ActiveSound)
//---------------------------------------------------------------------------
void ModifyDropAmount(AInventory *inv, int dropamount)
{
int flagmask = IF_IGNORESKILL;
auto flagmask = IF_IGNORESKILL;
double dropammofactor = G_SkillProperty(SKILLP_DropAmmoFactor);
// Default drop amount is half of regular amount * regular ammo multiplication
if (dropammofactor == -1)
{
dropammofactor = 0.5;
flagmask = 0;
flagmask = ItemFlag(0);
}
if (dropamount > 0)

View File

@ -5821,27 +5821,23 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position)
// [RH] Other things that shouldn't be spawned depending on dmflags
if (deathmatch || alwaysapplydmflags)
{
// Fixme: This needs to be done differently, it's quite broken.
if (dmflags & DF_NO_HEALTH)
if (i->IsDescendantOf(RUNTIME_CLASS(AInventory)))
{
if (i->IsDescendantOf (PClass::FindActor(NAME_Health)))
return NULL;
if (i->TypeName == NAME_Berserk)
return NULL;
if (i->TypeName == NAME_Megasphere)
return NULL;
}
if (dmflags & DF_NO_ITEMS)
{
// if (i->IsDescendantOf (RUNTIME_CLASS(AArtifact)))
// return;
}
if (dmflags & DF_NO_ARMOR)
{
if (i->IsDescendantOf (PClass::FindActor(NAME_Armor)))
return NULL;
if (i->TypeName == NAME_Megasphere)
return NULL;
auto it = static_cast<AInventory*>(GetDefaultByType(i));
if (dmflags & DF_NO_HEALTH)
{
if (it->ItemFlags & IF_ISHEALTH) return nullptr;
}
if (dmflags & DF_NO_ITEMS)
{
// if (i->IsDescendantOf (RUNTIME_CLASS(AArtifact)))
// return;
}
if (dmflags & DF_NO_ARMOR)
{
if (it->ItemFlags & IF_ISARMOR) return nullptr;
}
}
}

View File

@ -430,6 +430,8 @@ static FFlagDef InventoryFlagDefs[] =
DEFINE_FLAG(IF, TRANSFER, AInventory, ItemFlags),
DEFINE_FLAG(IF, NOTELEPORTFREEZE, AInventory, ItemFlags),
DEFINE_FLAG(IF, NOSCREENBLINK, AInventory, ItemFlags),
DEFINE_FLAG(IF, ISARMOR, AInventory, ItemFlags),
DEFINE_FLAG(IF, ISHEALTH, AInventory, ItemFlags),
DEFINE_DUMMY_FLAG(FORCERESPAWNINSURVIVAL, false),

View File

@ -72,6 +72,8 @@ class Megasphere : CustomInventory
{
+COUNTITEM
+INVENTORY.ALWAYSPICKUP
+INVENTORY.ISHEALTH
+INVENTORY.ISARMOR
Inventory.PickupMessage "$GOTMSPHERE";
Inventory.PickupSound "misc/p_pkup";
}
@ -183,6 +185,7 @@ class Berserk : CustomInventory
{
+COUNTITEM
+INVENTORY.ALWAYSPICKUP
+INVENTORY.ISHEALTH
Inventory.PickupMessage "$GOTBERSERK";
Inventory.PickupSound "misc/p_pkup";
}

View File

@ -38,6 +38,7 @@ class Armor : Inventory
Default
{
Inventory.PickupSound "misc/armor_pkup";
+INVENTORY.ISARMOR
}
}

View File

@ -43,6 +43,7 @@ class Health : Inventory
Default
{
+INVENTORY.ISHEALTH
Inventory.Amount 1;
Inventory.MaxAmount 0;
Inventory.PickupSound "misc/health_pkup";
@ -99,6 +100,7 @@ class HealthPickup : Inventory
{
Inventory.DefMaxAmount;
+INVENTORY.INVBAR
+INVENTORY.ISHEALTH
}
//===========================================================================