- removed the remaining native parts of ABasicArmor.

- simplified some FindInventory calls using PClass::FindActor to call the variant taking a name directly.
This commit is contained in:
Christoph Oelckers 2017-01-18 22:57:47 +01:00
parent 3148496f57
commit 2fcffd1fc1
18 changed files with 62 additions and 107 deletions

View file

@ -721,7 +721,7 @@ public:
// Finds the first item of a particular type. // Finds the first item of a particular type.
AInventory *FindInventory (PClassActor *type, bool subclass=false); AInventory *FindInventory (PClassActor *type, bool subclass=false);
AInventory *FindInventory (FName type); AInventory *FindInventory (FName type, bool subclass = false);
template<class T> T *FindInventory () template<class T> T *FindInventory ()
{ {
return static_cast<T *> (FindInventory (RUNTIME_TEMPLATE_CLASS(T))); return static_cast<T *> (FindInventory (RUNTIME_TEMPLATE_CLASS(T)));

View file

@ -3048,7 +3048,7 @@ void AM_Drawer ()
return; return;
bool allmap = (level.flags2 & LEVEL2_ALLMAP) != 0; bool allmap = (level.flags2 & LEVEL2_ALLMAP) != 0;
bool allthings = allmap && players[consoleplayer].mo->FindInventory(PClass::FindActor(NAME_PowerScanner), true) != nullptr; bool allthings = allmap && players[consoleplayer].mo->FindInventory(NAME_PowerScanner, true) != nullptr;
if (am_portaloverlay) if (am_portaloverlay)
{ {

View file

@ -434,7 +434,7 @@ static bool DoSubstitution (FString &out, const char *in)
{ {
if (strnicmp(a, "armor", 5) == 0) if (strnicmp(a, "armor", 5) == 0)
{ {
AInventory *armor = player->mo->FindInventory<ABasicArmor>(); AInventory *armor = player->mo->FindInventory(NAME_BasicArmor);
out.AppendFormat("%d", armor != NULL ? armor->Amount : 0); out.AppendFormat("%d", armor != NULL ? armor->Amount : 0);
} }
} }

View file

@ -447,7 +447,7 @@ CCMD (use)
{ {
if (argv.argc() > 1 && who != NULL) if (argv.argc() > 1 && who != NULL)
{ {
SendItemUse = who->FindInventory(PClass::FindActor(argv[1])); SendItemUse = who->FindInventory(argv[1]);
} }
} }
@ -468,7 +468,7 @@ CCMD (drop)
{ {
if (argv.argc() > 1 && who != NULL) if (argv.argc() > 1 && who != NULL)
{ {
SendItemDrop = who->FindInventory(PClass::FindActor(argv[1])); SendItemDrop = who->FindInventory(argv[1]);
} }
} }
@ -513,7 +513,7 @@ CCMD (select)
{ {
if (argv.argc() > 1) if (argv.argc() > 1)
{ {
AInventory *item = who->FindInventory(PClass::FindActor(argv[1])); AInventory *item = who->FindInventory(argv[1]);
if (item != NULL) if (item != NULL)
{ {
who->InvSel = item; who->InvSel = item;

View file

@ -46,44 +46,8 @@
#include "cmdlib.h" #include "cmdlib.h"
IMPLEMENT_CLASS(AArmor, false, false) IMPLEMENT_CLASS(AArmor, false, false)
IMPLEMENT_CLASS(ABasicArmor, false, false)
IMPLEMENT_CLASS(AHexenArmor, false, false) IMPLEMENT_CLASS(AHexenArmor, false, false)
//===========================================================================
//
//
// BasicArmor
//
//
//===========================================================================
DEFINE_FIELD(ABasicArmor, AbsorbCount)
DEFINE_FIELD(ABasicArmor, SavePercent)
DEFINE_FIELD(ABasicArmor, MaxAbsorb)
DEFINE_FIELD(ABasicArmor, MaxFullAbsorb)
DEFINE_FIELD(ABasicArmor, BonusCount)
DEFINE_FIELD(ABasicArmor, ArmorType)
DEFINE_FIELD(ABasicArmor, ActualSaveAmount)
//===========================================================================
//
// ABasicArmor :: Serialize
//
//===========================================================================
void ABasicArmor::Serialize(FSerializer &arc)
{
Super::Serialize (arc);
auto def = (ABasicArmor *)GetDefault();
arc("savepercent", SavePercent, def->SavePercent)
("bonuscount", BonusCount, def->BonusCount)
("maxabsorb", MaxAbsorb, def->MaxAbsorb)
("maxfullabsorb", MaxFullAbsorb, def->MaxFullAbsorb)
("absorbcount", AbsorbCount, def->AbsorbCount)
("armortype", ArmorType, def->ArmorType)
("actualsaveamount", ActualSaveAmount, def->ActualSaveAmount);
}
//=========================================================================== //===========================================================================
// //
// //

View file

@ -8,25 +8,6 @@ class AArmor : public AInventory
DECLARE_CLASS (AArmor, AInventory) DECLARE_CLASS (AArmor, AInventory)
}; };
// Basic armor absorbs a specific percent of the damage. You should
// never pickup a BasicArmor. Instead, you pickup a BasicArmorPickup
// or BasicArmorBonus and those gives you BasicArmor when it activates.
class ABasicArmor : public AArmor
{
DECLARE_CLASS (ABasicArmor, AArmor)
public:
virtual void Serialize(FSerializer &arc) override;
int AbsorbCount;
double SavePercent;
int MaxAbsorb;
int MaxFullAbsorb;
int BonusCount;
FNameNoInit ArmorType;
int ActualSaveAmount;
};
// Hexen armor consists of four separate armor types plus a conceptual armor // Hexen armor consists of four separate armor types plus a conceptual armor
// type (the player himself) that work together as a single armor. // type (the player himself) that work together as a single armor.
class AHexenArmor : public AArmor class AHexenArmor : public AArmor

View file

@ -1067,7 +1067,7 @@ public:
//prepare ammo counts //prepare ammo counts
GetCurrentAmmo(ammo1, ammo2, ammocount1, ammocount2); GetCurrentAmmo(ammo1, ammo2, ammocount1, ammocount2);
armor = CPlayer->mo->FindInventory<ABasicArmor>(); armor = CPlayer->mo->FindInventory(NAME_BasicArmor);
if(state != HUD_AltHud) if(state != HUD_AltHud)
{ {
@ -1517,7 +1517,7 @@ public:
AInventory *ammo1, *ammo2; AInventory *ammo1, *ammo2;
int ammocount1, ammocount2; int ammocount1, ammocount2;
ABasicArmor *armor; AInventory *armor;
FImageCollection Images; FImageCollection Images;
unsigned int invBarOffset; unsigned int invBarOffset;

View file

@ -268,7 +268,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
} }
else if(type == SIGIL) else if(type == SIGIL)
{ {
auto item = statusBar->CPlayer->mo->FindInventory(PClass::FindActor(NAME_Sigil)); auto item = statusBar->CPlayer->mo->FindInventory(NAME_Sigil);
if (item != NULL) if (item != NULL)
texture = TexMan(item->Icon); texture = TexMan(item->Icon);
} }
@ -592,11 +592,11 @@ class CommandDrawSwitchableImage : public CommandDrawImage
} }
else if(condition == ARMORTYPE) else if(condition == ARMORTYPE)
{ {
ABasicArmor *armor = (ABasicArmor *) statusBar->CPlayer->mo->FindInventory(NAME_BasicArmor); auto armor = statusBar->CPlayer->mo->FindInventory(NAME_BasicArmor);
if(armor != NULL) if(armor != NULL)
{ {
bool matches1 = armor->ArmorType.GetIndex() == armorType[0] && EvaluateOperation(conditionalOperator[0], conditionalValue[0], armor->Amount); bool matches1 = armor->NameVar(NAME_ArmorType).GetIndex() == armorType[0] && EvaluateOperation(conditionalOperator[0], conditionalValue[0], armor->Amount);
bool matches2 = armor->ArmorType.GetIndex() == armorType[1] && EvaluateOperation(conditionalOperator[1], conditionalValue[1], armor->Amount); bool matches2 = armor->NameVar(NAME_ArmorType).GetIndex() == armorType[1] && EvaluateOperation(conditionalOperator[1], conditionalValue[1], armor->Amount);
drawAlt = 1; drawAlt = 1;
if(conditionAnd) if(conditionAnd)
@ -614,12 +614,12 @@ class CommandDrawSwitchableImage : public CommandDrawImage
} }
else //check the inventory items and draw selected sprite else //check the inventory items and draw selected sprite
{ {
AInventory* item = statusBar->CPlayer->mo->FindInventory(PClass::FindActor(inventoryItem[0])); AInventory* item = statusBar->CPlayer->mo->FindInventory(inventoryItem[0]);
if(item == NULL || !EvaluateOperation(conditionalOperator[0], conditionalValue[0], item->Amount)) if(item == NULL || !EvaluateOperation(conditionalOperator[0], conditionalValue[0], item->Amount))
drawAlt = 1; drawAlt = 1;
if(conditionAnd) if(conditionAnd)
{ {
item = statusBar->CPlayer->mo->FindInventory(PClass::FindActor(inventoryItem[1])); item = statusBar->CPlayer->mo->FindInventory(inventoryItem[1]);
bool secondCondition = item != NULL && EvaluateOperation(conditionalOperator[1], conditionalValue[1], item->Amount); bool secondCondition = item != NULL && EvaluateOperation(conditionalOperator[1], conditionalValue[1], item->Amount);
if((item != NULL && secondCondition) && drawAlt == 0) //both if((item != NULL && secondCondition) && drawAlt == 0) //both
{ {
@ -1418,7 +1418,7 @@ class CommandDrawNumber : public CommandDrawString
//Hexen counts basic armor also so we should too. //Hexen counts basic armor also so we should too.
if(statusBar->armor != NULL) if(statusBar->armor != NULL)
{ {
add += statusBar->armor->SavePercent * 100; add += statusBar->armor->FloatVar(NAME_SavePercent) * 100;
} }
if(value == ARMORCLASS) if(value == ARMORCLASS)
add /= 5; add /= 5;
@ -2851,7 +2851,7 @@ class CommandDrawBar : public SBarInfoCommand
//Hexen counts basic armor also so we should too. //Hexen counts basic armor also so we should too.
if(statusBar->armor != NULL) if(statusBar->armor != NULL)
{ {
add += statusBar->armor->SavePercent * 100; add += statusBar->armor->FloatVar(NAME_SavePercent) * 100;
} }
value = int(add); value = int(add);
max = 100; max = 100;

View file

@ -297,7 +297,7 @@ static void DrawHealth(player_t *CPlayer, int x, int y)
const bool haveBerserk = hud_berserk_health const bool haveBerserk = hud_berserk_health
&& nullptr != berserkpic && nullptr != berserkpic
&& nullptr != CPlayer->mo->FindInventory(PClass::FindActor(NAME_PowerStrength)); && nullptr != CPlayer->mo->FindInventory(NAME_PowerStrength);
DrawImageToBox(haveBerserk ? berserkpic : healthpic, x, y, 31, 17); DrawImageToBox(haveBerserk ? berserkpic : healthpic, x, y, 31, 17);
DrawHudNumber(HudFont, fontcolor, health, x + 33, y + 17); DrawHudNumber(HudFont, fontcolor, health, x + 33, y + 17);
@ -310,7 +310,7 @@ static void DrawHealth(player_t *CPlayer, int x, int y)
// //
//=========================================================================== //===========================================================================
static void DrawArmor(ABasicArmor * barmor, AHexenArmor * harmor, int x, int y) static void DrawArmor(AInventory * barmor, AHexenArmor * harmor, int x, int y)
{ {
int ap = 0; int ap = 0;
int bestslot = 4; int bestslot = 4;
@ -1141,7 +1141,7 @@ void DrawHUD()
DrawFrags(CPlayer, 5, hudheight-70); DrawFrags(CPlayer, 5, hudheight-70);
} }
DrawHealth(CPlayer, 5, hudheight-45); DrawHealth(CPlayer, 5, hudheight-45);
DrawArmor(CPlayer->mo->FindInventory<ABasicArmor>(), DrawArmor(CPlayer->mo->FindInventory(NAME_BasicArmor),
CPlayer->mo->FindInventory<AHexenArmor>(), 5, hudheight-20); CPlayer->mo->FindInventory<AHexenArmor>(), 5, hudheight-20);
i=DrawKeys(CPlayer, hudwidth-4, hudheight-10); i=DrawKeys(CPlayer, hudwidth-4, hudheight-10);
i=DrawAmmo(CPlayer, hudwidth-5, i); i=DrawAmmo(CPlayer, hudwidth-5, i);

View file

@ -408,7 +408,7 @@ private:
DrawImage (&HealthBar, 49, 7); DrawImage (&HealthBar, 49, 7);
// Armor // Armor
item = CPlayer->mo->FindInventory<ABasicArmor>(); item = CPlayer->mo->FindInventory(NAME_BasicArmor);
if (item != NULL && item->Amount > 0) if (item != NULL && item->Amount > 0)
{ {
DrawImage (TexMan(item->Icon), 2, 9); DrawImage (TexMan(item->Icon), 2, 9);
@ -436,7 +436,7 @@ private:
} }
// Sigil // Sigil
item = CPlayer->mo->FindInventory(PClass::FindActor(NAME_Sigil)); item = CPlayer->mo->FindInventory(NAME_Sigil);
if (item != NULL) if (item != NULL)
{ {
DrawImage (TexMan(item->Icon), 253, 7); DrawImage (TexMan(item->Icon), 253, 7);
@ -473,7 +473,7 @@ private:
TAG_DONE); TAG_DONE);
// Draw armor // Draw armor
ABasicArmor *armor = CPlayer->mo->FindInventory<ABasicArmor>(); auto armor = CPlayer->mo->FindInventory(NAME_BasicArmor);
if (armor != NULL && armor->Amount != 0) if (armor != NULL && armor->Amount != 0)
{ {
DrINumberOuter (armor->Amount, 35, -10, false, 7); DrINumberOuter (armor->Amount, 35, -10, false, 7);

View file

@ -266,7 +266,7 @@ void cht_DoCheat (player_t *player, int cheat)
} }
else if (player->mo != NULL && player->health >= 0) else if (player->mo != NULL && player->health >= 0)
{ {
item = player->mo->FindInventory(PClass::FindActor(BeholdPowers[i])); item = player->mo->FindInventory(BeholdPowers[i]);
if (item == NULL) if (item == NULL)
{ {
if (i != 0) if (i != 0)
@ -487,7 +487,7 @@ void cht_DoCheat (player_t *player, int cheat)
int oldpieces = 1; int oldpieces = 1;
ret.IntAt(&oldpieces); ret.IntAt(&oldpieces);
GlobalVMStack.Call(gsp, params, 1, &ret, 1, nullptr); GlobalVMStack.Call(gsp, params, 1, &ret, 1, nullptr);
item = player->mo->FindInventory(PClass::FindActor(NAME_Sigil)); item = player->mo->FindInventory(NAME_Sigil);
if (item != NULL) if (item != NULL)
{ {

View file

@ -89,6 +89,10 @@ xx(SaveAmount)
xx(SavePercent) xx(SavePercent)
xx(MaxAbsorb) xx(MaxAbsorb)
xx(MaxFullAbsorb) xx(MaxFullAbsorb)
xx(MaxAmount)
xx(ActualSaveAmount)
xx(ArmorType)
xx(BulletPuff) xx(BulletPuff)
xx(StrifePuff) xx(StrifePuff)

View file

@ -4955,8 +4955,8 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args)
else else
{ {
FName p(FBehavior::StaticLookupString(args[0])); FName p(FBehavior::StaticLookupString(args[0]));
ABasicArmor * armor = (ABasicArmor *) players[args[1]].mo->FindInventory(NAME_BasicArmor); auto armor = players[args[1]].mo->FindInventory(NAME_BasicArmor);
if (armor && armor->ArmorType == p) return armor->Amount; if (armor && armor->NameVar(NAME_ArmorType) == p) return armor->Amount;
} }
return 0; return 0;
} }
@ -4965,29 +4965,29 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args)
{ {
if (activator == NULL || activator->player == NULL) return 0; if (activator == NULL || activator->player == NULL) return 0;
ABasicArmor * equippedarmor = (ABasicArmor *) activator->FindInventory(NAME_BasicArmor); auto equippedarmor = activator->FindInventory(NAME_BasicArmor);
if (equippedarmor && equippedarmor->Amount != 0) if (equippedarmor && equippedarmor->Amount != 0)
{ {
switch(args[0]) switch(args[0])
{ {
case ARMORINFO_CLASSNAME: case ARMORINFO_CLASSNAME:
return GlobalACSStrings.AddString(equippedarmor->ArmorType.GetChars()); return GlobalACSStrings.AddString(equippedarmor->NameVar(NAME_ArmorType).GetChars());
case ARMORINFO_SAVEAMOUNT: case ARMORINFO_SAVEAMOUNT:
return equippedarmor->MaxAmount; return equippedarmor->IntVar(NAME_MaxAmount);
case ARMORINFO_SAVEPERCENT: case ARMORINFO_SAVEPERCENT:
return DoubleToACS(equippedarmor->SavePercent); return DoubleToACS(equippedarmor->FloatVar(NAME_SavePercent));
case ARMORINFO_MAXABSORB: case ARMORINFO_MAXABSORB:
return equippedarmor->MaxAbsorb; return equippedarmor->IntVar(NAME_MaxAbsorb);
case ARMORINFO_MAXFULLABSORB: case ARMORINFO_MAXFULLABSORB:
return equippedarmor->MaxFullAbsorb; return equippedarmor->IntVar(NAME_MaxFullAbsorb);
case ARMORINFO_ACTUALSAVEAMOUNT: case ARMORINFO_ACTUALSAVEAMOUNT:
return equippedarmor->ActualSaveAmount; return equippedarmor->IntVar(NAME_ActualSaveAmount);
default: default:
return 0; return 0;
@ -8235,7 +8235,7 @@ scriptwait:
case PCD_PLAYERARMORPOINTS: case PCD_PLAYERARMORPOINTS:
if (activator) if (activator)
{ {
ABasicArmor *armor = activator->FindInventory<ABasicArmor>(); auto armor = activator->FindInventory(NAME_BasicArmor);
PushToStack (armor ? armor->Amount : 0); PushToStack (armor ? armor->Amount : 0);
} }
else else
@ -8682,7 +8682,7 @@ scriptwait:
{ {
AInventory *sigil; AInventory *sigil;
if (activator == NULL || (sigil = activator->FindInventory(PClass::FindActor(NAME_Sigil))) == NULL) if (activator == NULL || (sigil = activator->FindInventory(NAME_Sigil)) == NULL)
{ {
PushToStack (0); PushToStack (0);
} }

View file

@ -2883,7 +2883,7 @@ FUNC(LS_SetPlayerProperty)
{ // Take power from activator { // Take power from activator
if (power != 4) if (power != 4)
{ {
AInventory *item = it->FindInventory(PClass::FindActor(powers[power]), true); AInventory *item = it->FindInventory(powers[power], true);
if (item != NULL) if (item != NULL)
{ {
item->Destroy (); item->Destroy ();

View file

@ -1093,9 +1093,9 @@ AInventory *AActor::FindInventory (PClassActor *type, bool subclass)
return item; return item;
} }
AInventory *AActor::FindInventory (FName type) AInventory *AActor::FindInventory (FName type, bool subclass)
{ {
return FindInventory(PClass::FindActor(type)); return FindInventory(PClass::FindActor(type), subclass);
} }
DEFINE_ACTION_FUNCTION(AActor, FindInventory) DEFINE_ACTION_FUNCTION(AActor, FindInventory)

View file

@ -233,7 +233,7 @@ DPSprite *player_t::GetPSprite(PSPLayers layer)
{ {
if (mo != nullptr) if (mo != nullptr)
{ {
newcaller = mo->FindInventory(PClass::FindActor(NAME_PowerTargeter), true); newcaller = mo->FindInventory(NAME_PowerTargeter, true);
} }
} }
else if (layer == PSP_STRIFEHANDS) else if (layer == PSP_STRIFEHANDS)

View file

@ -1148,9 +1148,9 @@ void APlayerPawn::FilterCoopRespawnInventory (APlayerPawn *oldplayer)
{ {
item->Destroy(); item->Destroy();
} }
else if (item->IsKindOf(RUNTIME_CLASS(ABasicArmor))) else if (item->IsKindOf(PClass::FindActor(NAME_BasicArmor)))
{ {
static_cast<ABasicArmor*>(item)->SavePercent = static_cast<ABasicArmor*>(defitem)->SavePercent; item->IntVar(NAME_SavePercent) = defitem->IntVar(NAME_SavePercent);
item->Amount = defitem->Amount; item->Amount = defitem->Amount;
} }
else if (item->IsKindOf(RUNTIME_CLASS(AHexenArmor))) else if (item->IsKindOf(RUNTIME_CLASS(AHexenArmor)))
@ -1375,10 +1375,8 @@ void APlayerPawn::GiveDefaultInventory ()
// BasicArmor must come right after that. It should not affect any // BasicArmor must come right after that. It should not affect any
// other protection item as well but needs to process the damage // other protection item as well but needs to process the damage
// before the HexenArmor does. // before the HexenArmor does.
ABasicArmor *barmor = Spawn<ABasicArmor> (); auto barmor = (AInventory*)Spawn(NAME_BasicArmor);
barmor->BecomeItem (); barmor->BecomeItem ();
barmor->SavePercent = 0;
barmor->Amount = 0;
AddInventory (barmor); AddInventory (barmor);
// Now add the items from the DECORATE definition // Now add the items from the DECORATE definition

View file

@ -46,22 +46,27 @@ class Armor : Inventory native
// //
// BasicArmor // BasicArmor
// //
// Basic armor absorbs a specific percent of the damage. You should
// never pickup a BasicArmor. Instead, you pickup a BasicArmorPickup
// or BasicArmorBonus and those gives you BasicArmor when it activates.
//
// //
//=========================================================================== //===========================================================================
class BasicArmor : Armor native class BasicArmor : Armor
{ {
native int AbsorbCount; int AbsorbCount;
native double SavePercent; double SavePercent;
native int MaxAbsorb; int MaxAbsorb;
native int MaxFullAbsorb; int MaxFullAbsorb;
native int BonusCount; int BonusCount;
native Name ArmorType; Name ArmorType;
native int ActualSaveAmount; int ActualSaveAmount;
Default Default
{ {
Inventory.Amount 0;
+Inventory.KEEPDEPLETED +Inventory.KEEPDEPLETED
} }
@ -441,6 +446,9 @@ class BasicArmorPickup : Armor
// //
// HexenArmor // HexenArmor
// //
// Hexen armor consists of four separate armor types plus a conceptual armor
// type (the player himself) that work together as a single armor.
//
// //
//=========================================================================== //===========================================================================