- removed all direct access to AInventory's members.

We are getting closer to make class Inventory fully scripted.
This commit is contained in:
Christoph Oelckers 2018-12-04 00:22:26 +01:00
parent e333a886e9
commit a573c63f60
11 changed files with 64 additions and 56 deletions

View file

@ -371,8 +371,8 @@ void DBot::WhatToGet (AActor *item)
return;
auto ammo1 = heldWeapon->PointerVar<AInventory>(NAME_Ammo1);
auto ammo2 = heldWeapon->PointerVar<AInventory>(NAME_Ammo2);
if ((ammo1 == NULL || ammo1->IntVar(NAME_Amount) >= ammo1->MaxAmount) &&
(ammo2 == NULL || ammo2->IntVar(NAME_Amount) >= ammo2->MaxAmount))
if ((ammo1 == NULL || ammo1->IntVar(NAME_Amount) >= ammo1->IntVar(NAME_MaxAmount)) &&
(ammo2 == NULL || ammo2->IntVar(NAME_Amount) >= ammo2->IntVar(NAME_MaxAmount)))
{
return;
}
@ -384,7 +384,7 @@ void DBot::WhatToGet (AActor *item)
auto parent = item->GetClass();
while (parent->ParentClass != ac) parent = static_cast<PClassActor*>(parent->ParentClass);
AInventory *holdingammo = player->mo->FindInventory(parent);
if (holdingammo != NULL && holdingammo->IntVar(NAME_Amount) >= holdingammo->MaxAmount)
if (holdingammo != NULL && holdingammo->IntVar(NAME_Amount) >= holdingammo->IntVar(NAME_MaxAmount))
{
return;
}

View file

@ -76,7 +76,7 @@ void C_PrintInv(AActor *target)
{
Printf (" %s #%u (%d/%d)\n", item->GetClass()->TypeName.GetChars(),
item->InventoryID,
item->IntVar(NAME_Amount), item->MaxAmount);
item->IntVar(NAME_Amount), item->IntVar(NAME_MaxAmount));
count++;
}
Printf (" List count: %d\n", count);

View file

@ -1548,7 +1548,7 @@ static int PatchAmmo (int ammoNum)
defaultAmmo = (AInventory*)GetDefaultByType (ammoType);
if (defaultAmmo != NULL)
{
max = &defaultAmmo->MaxAmount;
max = &defaultAmmo->IntVar(NAME_MaxAmount);
per = &defaultAmmo->IntVar(NAME_Amount);
}
}
@ -1571,7 +1571,7 @@ static int PatchAmmo (int ammoNum)
// Calculate the new backpack-given amounts for this ammo.
if (ammoType != NULL)
{
defaultAmmo->IntVar("BackpackMaxAmount") = defaultAmmo->MaxAmount * 2;
defaultAmmo->IntVar("BackpackMaxAmount") = defaultAmmo->IntVar(NAME_MaxAmount) * 2;
defaultAmmo->IntVar("BackpackAmount") = defaultAmmo->IntVar(NAME_Amount);
}
@ -1588,7 +1588,7 @@ static int PatchAmmo (int ammoNum)
if (type->IsDescendantOf (ammoType))
{
defaultAmmo = (AInventory *)GetDefaultByType (type);
defaultAmmo->MaxAmount = *max;
defaultAmmo->IntVar(NAME_MaxAmount) = *max;
defaultAmmo->IntVar(NAME_Amount) = Scale (defaultAmmo->IntVar(NAME_Amount), *per, oldclip);
}
else if (type->IsDescendantOf (NAME_Weapon))
@ -1981,20 +1981,20 @@ static int PatchMisc (int dummy)
health = static_cast<AInventory *> (GetDefaultByName ("HealthBonus"));
if (health!=NULL)
{
health->MaxAmount = 2 * deh.MaxHealth;
health->IntVar(NAME_MaxAmount) = 2 * deh.MaxHealth;
}
health = static_cast<AInventory *> (GetDefaultByName ("Soulsphere"));
if (health!=NULL)
{
health->IntVar(NAME_Amount) = deh.SoulsphereHealth;
health->MaxAmount = deh.MaxSoulsphere;
health->IntVar(NAME_MaxAmount) = deh.MaxSoulsphere;
}
health = static_cast<AInventory *> (GetDefaultByName ("MegasphereHealth"));
if (health!=NULL)
{
health->IntVar(NAME_Amount) = health->MaxAmount = deh.MegasphereHealth;
health->IntVar(NAME_Amount) = health->IntVar(NAME_MaxAmount) = deh.MegasphereHealth;
}
APlayerPawn *player = static_cast<APlayerPawn *> (GetDefaultByName ("DoomPlayer"));

View file

@ -244,6 +244,7 @@ public:
// Add other types as needed.
inline bool &BoolVar(FName field);
inline int &IntVar(FName field);
inline FTextureID &TextureIDVar(FName field);
inline FSoundID &SoundVar(FName field);
inline PalEntry &ColorVar(FName field);
inline FName &NameVar(FName field);
@ -443,6 +444,11 @@ inline int &DObject::IntVar(FName field)
return *(int*)ScriptVar(field, nullptr);
}
inline FTextureID &DObject::TextureIDVar(FName field)
{
return *(FTextureID*)ScriptVar(field, nullptr);
}
inline FSoundID &DObject::SoundVar(FName field)
{
return *(FSoundID*)ScriptVar(field, nullptr);

View file

@ -154,7 +154,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
}
else
{
sprite = ((AInventory *)GetDefaultByType(item))->Icon;
sprite = ((AInventory *)GetDefaultByType(item))->TextureIDVar(NAME_Icon);
}
image = -1;
}
@ -270,7 +270,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
{
auto item = statusBar->CPlayer->mo->FindInventory(NAME_Sigil);
if (item != NULL)
texture = TexMan(item->Icon);
texture = TexMan(item->TextureIDVar(NAME_Icon));
}
else if(type == HEXENARMOR_ARMOR || type == HEXENARMOR_SHIELD || type == HEXENARMOR_HELM || type == HEXENARMOR_AMULET)
{
@ -294,7 +294,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
else if(type == INVENTORYICON)
texture = TexMan(sprite);
else if(type == SELECTEDINVENTORYICON && statusBar->CPlayer->mo->InvSel != NULL)
texture = TexMan(statusBar->CPlayer->mo->InvSel->Icon);
texture = TexMan(statusBar->CPlayer->mo->InvSel->TextureIDVar(NAME_Icon));
else if(image >= 0)
texture = statusBar->Images[image];
@ -1365,7 +1365,7 @@ class CommandDrawNumber : public CommandDrawString
return;
}
else
num = statusBar->ammo1->MaxAmount;
num = statusBar->ammo1->IntVar(NAME_MaxAmount);
break;
case AMMO2CAPACITY:
if(statusBar->ammo2 == NULL) //no ammo, do not draw
@ -1374,15 +1374,15 @@ class CommandDrawNumber : public CommandDrawString
return;
}
else
num = statusBar->ammo2->MaxAmount;
num = statusBar->ammo2->IntVar(NAME_MaxAmount);
break;
case AMMOCAPACITY:
{
AInventory* item = statusBar->CPlayer->mo->FindInventory(inventoryItem);
if(item != NULL)
num = item->MaxAmount;
num = item->IntVar(NAME_MaxAmount);
else
num = ((AInventory *)GetDefaultByType(inventoryItem))->MaxAmount;
num = ((AInventory *)GetDefaultByType(inventoryItem))->IntVar(NAME_MaxAmount);
break;
}
case FRAGS:
@ -2131,7 +2131,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand
statusBar->DrawGraphic(statusBar->Images[statusBar->invBarOffset + imgARTIBOX], rx, ry, block->XOffset(), block->YOffset(), bgalpha, block->FullScreenOffsets());
if(style != STYLE_Strife) //Strife draws the cursor before the icons
statusBar->DrawGraphic(TexMan(item->Icon), rx - (style == STYLE_HexenStrict ? 2 : 0), ry - (style == STYLE_HexenStrict ? 1 : 0), block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0);
statusBar->DrawGraphic(TexMan(item->TextureIDVar(NAME_Icon)), rx - (style == STYLE_HexenStrict ? 2 : 0), ry - (style == STYLE_HexenStrict ? 1 : 0), block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0);
if(item == statusBar->CPlayer->mo->InvSel)
{
if(style == STYLE_Heretic)
@ -2146,7 +2146,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand
statusBar->DrawGraphic(statusBar->Images[statusBar->invBarOffset + imgSELECTBOX], rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets());
}
if(style == STYLE_Strife)
statusBar->DrawGraphic(TexMan(item->Icon), rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0);
statusBar->DrawGraphic(TexMan(item->TextureIDVar(NAME_Icon)), rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0);
if(counters != NULL && (alwaysShowCounter || item->IntVar(NAME_Amount) != 1))
{
counters[i]->valueArgument = item->IntVar(NAME_Amount);
@ -2359,7 +2359,7 @@ class CommandDrawKeyBar : public SBarInfoCommand
int rowWidth = 0;
for(unsigned int i = 0;i < number+keyOffset;i++)
{
while(!item->Icon.isValid() || !item->IsKindOf(NAME_Key))
while(!item->TextureIDVar(NAME_Icon).isValid() || !item->IsKindOf(NAME_Key))
{
item = item->Inventory;
if(item == NULL)
@ -2369,22 +2369,22 @@ class CommandDrawKeyBar : public SBarInfoCommand
{
if(!vertical)
{
statusBar->DrawGraphic(TexMan(item->Icon), x+slotOffset, y+rowOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets());
rowWidth = rowIconSize == -1 ? TexMan(item->Icon)->GetScaledHeight()+2 : rowIconSize;
statusBar->DrawGraphic(TexMan(item->TextureIDVar(NAME_Icon)), x+slotOffset, y+rowOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets());
rowWidth = rowIconSize == -1 ? TexMan(item->TextureIDVar(NAME_Icon))->GetScaledHeight()+2 : rowIconSize;
}
else
{
statusBar->DrawGraphic(TexMan(item->Icon), x+rowOffset, y+slotOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets());
rowWidth = rowIconSize == -1 ? TexMan(item->Icon)->GetScaledWidth()+2 : rowIconSize;
statusBar->DrawGraphic(TexMan(item->TextureIDVar(NAME_Icon)), x+rowOffset, y+slotOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets());
rowWidth = rowIconSize == -1 ? TexMan(item->TextureIDVar(NAME_Icon))->GetScaledWidth()+2 : rowIconSize;
}
// If cmd.special is -1 then the slot size is auto detected
if(iconSize == -1)
{
if(!vertical)
slotOffset += (reverse ? -1 : 1) * (TexMan(item->Icon)->GetScaledWidth() + 2);
slotOffset += (reverse ? -1 : 1) * (TexMan(item->TextureIDVar(NAME_Icon))->GetScaledWidth() + 2);
else
slotOffset += (reverse ? -1 : 1) * (TexMan(item->Icon)->GetScaledHeight() + 2);
slotOffset += (reverse ? -1 : 1) * (TexMan(item->TextureIDVar(NAME_Icon))->GetScaledHeight() + 2);
}
else
slotOffset += (reverse ? -iconSize : iconSize);
@ -2697,7 +2697,7 @@ class CommandDrawBar : public SBarInfoCommand
max = 1;
}
else
max = statusBar->ammo1->MaxAmount;
max = statusBar->ammo1->IntVar(NAME_MaxAmount);
break;
case AMMO2:
value = statusBar->ammocount2;
@ -2707,7 +2707,7 @@ class CommandDrawBar : public SBarInfoCommand
max = 1;
}
else
max = statusBar->ammo2->MaxAmount;
max = statusBar->ammo2->IntVar(NAME_MaxAmount);
break;
case AMMO:
{
@ -2715,7 +2715,7 @@ class CommandDrawBar : public SBarInfoCommand
if(item != NULL)
{
value = item->IntVar(NAME_Amount);
max = item->MaxAmount;
max = item->IntVar(NAME_MaxAmount);
}
else
value = 0;
@ -2743,7 +2743,7 @@ class CommandDrawBar : public SBarInfoCommand
if(item != NULL)
{
value = item->IntVar(NAME_Amount);
max = item->MaxAmount;
max = item->IntVar(NAME_MaxAmount);
}
else
value = 0;

View file

@ -1765,9 +1765,9 @@ int GetInventoryIcon(AInventory *item, uint32_t flags, int *applyscale)
*applyscale = false;
}
if (item == nullptr) return FNullTextureID().GetIndex();
if (item == nullptr) return 0;
FTextureID picnum, Icon = item->Icon, AltIcon = item->AltHUDIcon;
FTextureID picnum, Icon = item->TextureIDVar(NAME_Icon), AltIcon = item->TextureIDVar(NAME_AltHUDIcon);
FState * state = NULL, *ReadyState;
picnum.SetNull();
@ -1780,7 +1780,7 @@ int GetInventoryIcon(AInventory *item, uint32_t flags, int *applyscale)
}
else
{
if (!(flags & DI_SKIPICON) && item->Icon.isValid())
if (!(flags & DI_SKIPICON) && Icon.isValid())
picnum = Icon;
else if (!(flags & DI_SKIPALTICON))
picnum = AltIcon;

View file

@ -361,7 +361,7 @@ static void LoadAltHudStuff()
}
else tex.SetInvalid();
if (ti) ((AInventory*)GetDefaultByType(ti))->AltHUDIcon = tex;
if (ti) GetDefaultByType(ti)->TextureIDVar(NAME_AltHUDIcon) = tex;
}
}
}

View file

@ -98,7 +98,10 @@ xx(ArmorType)
xx(HexenArmor)
xx(Slots)
xx(SlotsIncrement)
xx(InterHubAmount)
xx(Icon)
xx(AltHUDIcon)
xx(PickupFlash)
xx(BulletPuff)
xx(StrifePuff)

View file

@ -1843,11 +1843,11 @@ int CheckInventory (AActor *activator, const char *type, bool max)
{
if (item)
{
return item->MaxAmount;
return item->IntVar(NAME_MaxAmount);
}
else if (info != nullptr && info->IsDescendantOf(NAME_Inventory))
{
return ((AInventory *)GetDefaultByType(info))->MaxAmount;
return ((AInventory *)GetDefaultByType(info))->IntVar(NAME_MaxAmount);
}
}
return item ? item->IntVar(NAME_Amount) : 0;
@ -9353,11 +9353,11 @@ scriptwait:
item = activator->FindInventory (static_cast<PClassActor *>(type));
if (item != NULL)
{
STACK(1) = item->MaxAmount;
STACK(1) = item->IntVar(NAME_MaxAmount);
}
else
{
STACK(1) = ((AInventory *)GetDefaultByType (type))->MaxAmount;
STACK(1) = ((AInventory *)GetDefaultByType (type))->IntVar(NAME_MaxAmount);
}
}
else
@ -9382,14 +9382,14 @@ scriptwait:
item = activator->FindInventory (type);
if (item != NULL)
{
item->MaxAmount = STACK(1);
item->IntVar(NAME_MaxAmount) = STACK(1);
}
else
{
item = activator->GiveInventoryType (type);
if (item != NULL)
{
item->MaxAmount = STACK(1);
item->IntVar(NAME_MaxAmount) = STACK(1);
item->IntVar(NAME_Amount) = 0;
}
}

View file

@ -71,12 +71,12 @@ struct FFlagDef
void FinalizeClass(PClass *cls, FStateDefinitions &statedef);
FFlagDef *FindFlag (const PClass *type, const char *part1, const char *part2, bool strict = false);
void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int index);
bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index);
bool CheckDeprecatedFlags(AActor *actor, PClassActor *info, int index);
const char *GetFlagName(unsigned int flagnum, int flagoffset);
void ModActorFlag(AActor *actor, FFlagDef *fd, bool set);
bool ModActorFlag(AActor *actor, const FString &flagname, bool set, bool printerror = true);
INTBOOL CheckActorFlag(const AActor *actor, FFlagDef *fd);
INTBOOL CheckActorFlag(const AActor *owner, const char *flagname, bool printerror = true);
INTBOOL CheckActorFlag(AActor *actor, FFlagDef *fd);
INTBOOL CheckActorFlag(AActor *owner, const char *flagname, bool printerror = true);
#define FLAG_NAME(flagnum, flagvar) GetFlagName(flagnum, myoffsetof(AActor, flagvar))

View file

@ -206,7 +206,7 @@ bool ModActorFlag(AActor *actor, const FString &flagname, bool set, bool printer
//
//==========================================================================
INTBOOL CheckActorFlag(const AActor *owner, FFlagDef *fd)
INTBOOL CheckActorFlag(AActor *owner, FFlagDef *fd)
{
if (fd->structoffset == -1)
{
@ -232,7 +232,7 @@ INTBOOL CheckActorFlag(const AActor *owner, FFlagDef *fd)
#endif
}
INTBOOL CheckActorFlag(const AActor *owner, const char *flagname, bool printerror)
INTBOOL CheckActorFlag(AActor *owner, const char *flagname, bool printerror)
{
const char *dot = strchr (flagname, '.');
FFlagDef *fd;
@ -310,15 +310,15 @@ void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int in
case DEPF_PICKUPFLASH:
if (set)
{
static_cast<AInventory*>(defaults)->PickupFlash = FindClassTentative("PickupFlash", RUNTIME_CLASS(AActor));
defaults->PointerVar<PClass>(NAME_PickupFlash) = FindClassTentative("PickupFlash", RUNTIME_CLASS(AActor));
}
else
{
static_cast<AInventory*>(defaults)->PickupFlash = NULL;
defaults->PointerVar<PClass>(NAME_PickupFlash) = nullptr;
}
break;
case DEPF_INTERHUBSTRIP: // Old system was 0 or 1, so if the flag is cleared, assume 1.
static_cast<AInventory*>(defaults)->InterHubAmount = set ? 0 : 1;
defaults->IntVar(NAME_InterHubAmount) = set ? 0 : 1;
break;
case DEPF_NOTRAIL:
{
@ -351,7 +351,7 @@ void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int in
//
//===========================================================================
bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index)
bool CheckDeprecatedFlags(AActor *actor, PClassActor *info, int index)
{
// A deprecated flag is false if
// a) it hasn't been added here
@ -391,11 +391,10 @@ bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index)
return (actor->BounceFlags & (BOUNCE_TypeMask|BOUNCE_UseSeeSound)) == BOUNCE_DoomCompat;
case DEPF_PICKUPFLASH:
return static_cast<const AInventory*>(actor)->PickupFlash == PClass::FindClass("PickupFlash");
// A pure name lookup may or may not be more efficient, but I know no static identifier for PickupFlash.
return actor->PointerVar<PClass>(NAME_PickupFlash) == PClass::FindClass(NAME_PickupFlash);
case DEPF_INTERHUBSTRIP:
return !(static_cast<const AInventory*>(actor)->InterHubAmount);
return !(actor->IntVar(NAME_InterHubAmount));
}
return false; // Any entirely unknown flag is not set
@ -1151,7 +1150,7 @@ static void SetIcon(FTextureID &icon, Baggage &bag, const char *i)
DEFINE_CLASS_PROPERTY(icon, S, Inventory)
{
PROP_STRING_PARM(i, 0);
SetIcon(defaults->Icon, bag, i);
SetIcon(defaults->TextureIDVar(NAME_Icon), bag, i);
}
//==========================================================================
@ -1160,7 +1159,7 @@ DEFINE_CLASS_PROPERTY(icon, S, Inventory)
DEFINE_CLASS_PROPERTY(althudicon, S, Inventory)
{
PROP_STRING_PARM(i, 0);
SetIcon(defaults->AltHUDIcon, bag, i);
SetIcon(defaults->TextureIDVar(NAME_AltHUDIcon), bag, i);
}
//==========================================================================
@ -1168,7 +1167,7 @@ DEFINE_CLASS_PROPERTY(althudicon, S, Inventory)
//==========================================================================
DEFINE_CLASS_PROPERTY(defmaxamount, 0, Inventory)
{
defaults->MaxAmount = gameinfo.definventorymaxamount;
defaults->IntVar(NAME_MaxAmount) = gameinfo.definventorymaxamount;
}
//==========================================================================