- moved the three remaining variables from PClassInventory to PClassActor so that PClassInventory can be removed.

This commit is contained in:
Christoph Oelckers 2017-02-08 18:11:23 +01:00
parent eebe09fb59
commit c77f6636f8
20 changed files with 89 additions and 109 deletions

View File

@ -699,7 +699,7 @@ public:
// Give an item to the actor and pick it up.
// Returns true if the item pickup succeeded.
bool GiveInventory (PClassInventory *type, int amount, bool givecheat = false);
bool GiveInventory (PClassActor *type, int amount, bool givecheat = false);
// Removes the item from the inventory list.
virtual void RemoveInventory (AInventory *item);
@ -736,7 +736,7 @@ public:
AInventory *FirstInv ();
// Tries to give the actor some ammo.
bool GiveAmmo (PClassInventory *type, int amount);
bool GiveAmmo (PClassActor *type, int amount);
// Destroys all the inventory the actor is holding.
void DestroyAllInventory ();

View File

@ -1658,7 +1658,7 @@ static int PatchWeapon (int weapNum)
{
val = 5;
}
info->AmmoType1 = (PClassInventory*)AmmoNames[val];
info->AmmoType1 = AmmoNames[val];
if (info->AmmoType1 != NULL)
{
info->AmmoGive1 = ((AInventory*)GetDefaultByType (info->AmmoType1))->Amount * 2;

View File

@ -110,9 +110,9 @@ public:
void TweakSpeeds (double &forwardmove, double &sidemove);
void MorphPlayerThink ();
void ActivateMorphWeapon ();
AWeapon *PickNewWeapon (PClassInventory *ammotype);
AWeapon *BestWeapon (PClassInventory *ammotype);
void CheckWeaponSwitch(PClassInventory *ammotype);
AWeapon *PickNewWeapon (PClassActor *ammotype);
AWeapon *BestWeapon (PClassActor *ammotype);
void CheckWeaponSwitch(PClassActor *ammotype);
void GiveDeathmatchInventory ();
void FilterCoopRespawnInventory (APlayerPawn *oldplayer);

View File

@ -93,7 +93,6 @@ enum
{
CLASSREG_PClass,
CLASSREG_PClassActor,
CLASSREG_PClassInventory,
CLASSREG_PClassPlayerPawn,
};

View File

@ -2955,7 +2955,6 @@ PClass *ClassReg::RegisterClass()
{
&PClass::RegistrationInfo,
&PClassActor::RegistrationInfo,
&PClassInventory::RegistrationInfo,
&PClassPlayerPawn::RegistrationInfo,
};

View File

@ -155,12 +155,9 @@ struct PalEntry
#endif
};
class PClassInventory;
class FTextureID
{
friend class FTextureManager;
friend FTextureID GetHUDIcon(PClassInventory *cls);
friend void R_InitSpriteDefs();
public:

View File

@ -340,7 +340,7 @@ inline int T_FindFirstSectorFromTag(int tagnum)
// Doom index is only supported for the 4 original ammo types
//
//==========================================================================
static PClassInventory * T_GetAmmo(const svalue_t &t)
static PClassActor * T_GetAmmo(const svalue_t &t)
{
const char * p;
@ -361,8 +361,8 @@ static PClassInventory * T_GetAmmo(const svalue_t &t)
}
p=DefAmmo[ammonum];
}
PClassInventory * am=dyn_cast<PClassInventory>(PClass::FindActor(p));
if (am == NULL)
auto am = PClass::FindActor(p);
if (am == NULL || !am->IsKindOf(PClass::FindClass(NAME_Ammo)))
{
script_error("unknown ammo type : %s", p);
return NULL;
@ -2434,8 +2434,8 @@ static void FS_GiveInventory (AActor *actor, const char * type, int amount)
{
type = "BasicArmorPickup";
}
PClassInventory * info = dyn_cast<PClassInventory>(PClass::FindActor (type));
if (info == NULL)
auto info = PClass::FindActor (type);
if (info == NULL || !info->IsKindOf(RUNTIME_CLASS(AInventory)))
{
Printf ("Unknown inventory item: %s\n", type);
return;
@ -2564,7 +2564,7 @@ void FParser::SF_PlayerKeys(void)
void FParser::SF_PlayerAmmo(void)
{
int playernum, amount;
PClassInventory * ammotype;
PClassActor * ammotype;
if (CheckArgs(2))
{
@ -2600,7 +2600,7 @@ void FParser::SF_PlayerAmmo(void)
void FParser::SF_MaxPlayerAmmo()
{
int playernum, amount;
PClassInventory * ammotype;
PClassActor * ammotype;
if (CheckArgs(2))
{

View File

@ -25,50 +25,6 @@
EXTERN_CVAR(Bool, sv_unlimited_pickup)
IMPLEMENT_CLASS(PClassInventory, false, false)
PClassInventory::PClassInventory()
{
}
void PClassInventory::DeriveData(PClass *newclass)
{
assert(newclass->IsKindOf(RUNTIME_CLASS(PClassInventory)));
Super::DeriveData(newclass);
PClassInventory *newc = static_cast<PClassInventory *>(newclass);
newc->PickupMsg = PickupMsg;
newc->ForbiddenToPlayerClass = ForbiddenToPlayerClass;
newc->RestrictedToPlayerClass = RestrictedToPlayerClass;
}
size_t PClassInventory::PointerSubstitution(DObject *oldclass, DObject *newclass)
{
size_t changed = Super::PointerSubstitution(oldclass, newclass);
AInventory *def = (AInventory*)Defaults;
if (def != NULL)
{
if (def->PickupFlash == oldclass) def->PickupFlash = static_cast<PClassActor *>(newclass);
for (unsigned i = 0; i < ForbiddenToPlayerClass.Size(); i++)
{
if (ForbiddenToPlayerClass[i] == oldclass)
{
ForbiddenToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
changed++;
}
}
for (unsigned i = 0; i < RestrictedToPlayerClass.Size(); i++)
{
if (RestrictedToPlayerClass[i] == oldclass)
{
RestrictedToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
changed++;
}
}
}
return changed;
}
void AInventory::Finalize(FStateDefinitions &statedef)
{
Super::Finalize(statedef);
@ -95,7 +51,7 @@ DEFINE_FIELD(AInventory, SpawnPointClass)
DEFINE_FIELD(AInventory, PickupFlash)
DEFINE_FIELD(AInventory, PickupSound)
DEFINE_FIELD(AInventory, GiveQuest)
DEFINE_FIELD(PClassInventory, PickupMsg)
DEFINE_FIELD(PClassActor, PickupMsg)
//===========================================================================
//
@ -545,7 +501,7 @@ DEFINE_ACTION_FUNCTION(AInventory, CanPickup)
if (!toucher)
ACTION_RETURN_BOOL(false);
PClassInventory *ai = self->GetClass();
auto ai = self->GetClass();
// Is the item restricted to certain player classes?
if (ai->RestrictedToPlayerClass.Size() != 0)
{

View File

@ -50,23 +50,9 @@ enum
};
class PClassInventory : public PClassActor
{
DECLARE_CLASS(PClassInventory, PClassActor)
public:
PClassInventory();
virtual void DeriveData(PClass *newclass);
virtual size_t PointerSubstitution(DObject *oldclass, DObject *newclass);
void Finalize(FStateDefinitions &statedef);
FString PickupMsg;
TArray<PClassPlayerPawn *> RestrictedToPlayerClass;
TArray<PClassPlayerPawn *> ForbiddenToPlayerClass;
};
class AInventory : public AActor
{
DECLARE_CLASS_WITH_META(AInventory, AActor, PClassInventory)
DECLARE_CLASS(AInventory, AActor)
HAS_OBJECT_POINTERS
public:

View File

@ -92,7 +92,7 @@ class AWeapon : public AStateProvider
HAS_OBJECT_POINTERS
public:
DWORD WeaponFlags;
PClassInventory *AmmoType1, *AmmoType2; // Types of ammo used by this weapon
PClassActor *AmmoType1, *AmmoType2; // Types of ammo used by this weapon
int AmmoGive1, AmmoGive2; // Amount of each ammo to get when picking up weapon
int MinAmmo1, MinAmmo2; // Minimum ammo needed to switch to this weapon
int AmmoUse1, AmmoUse2; // How much ammo to use with each shot

View File

@ -349,6 +349,11 @@ void PClassActor::DeriveData(PClass *newclass)
*newa->PainChances = *PainChances;
}
// Inventory stuff
newa->PickupMsg = PickupMsg;
newa->ForbiddenToPlayerClass = ForbiddenToPlayerClass;
newa->RestrictedToPlayerClass = RestrictedToPlayerClass;
}
//==========================================================================
@ -637,6 +642,29 @@ size_t PClassActor::PointerSubstitution(DObject *oldclass, DObject *newclass)
changed++;
}
}
for (unsigned i = 0; i < ForbiddenToPlayerClass.Size(); i++)
{
if (ForbiddenToPlayerClass[i] == oldclass)
{
ForbiddenToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
changed++;
}
}
for (unsigned i = 0; i < RestrictedToPlayerClass.Size(); i++)
{
if (RestrictedToPlayerClass[i] == oldclass)
{
RestrictedToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
changed++;
}
}
AInventory *def = dyn_cast<AInventory>((AActor*)Defaults);
if (def != NULL)
{
if (def->PickupFlash == oldclass) def->PickupFlash = static_cast<PClassActor *>(newclass);
}
return changed;
}

View File

@ -317,6 +317,11 @@ public:
FName MissileName;
double MissileHeight;
// These are only valid for inventory items.
FString PickupMsg;
TArray<PClassPlayerPawn *> RestrictedToPlayerClass;
TArray<PClassPlayerPawn *> ForbiddenToPlayerClass;
// For those times when being able to scan every kind of actor is convenient
static TArray<PClassActor *> AllActorClasses;
};

View File

@ -1193,12 +1193,12 @@ static void GiveInventory (AActor *activator, const char *type, int amount)
for (int i = 0; i < MAXPLAYERS; ++i)
{
if (playeringame[i])
players[i].mo->GiveInventory(static_cast<PClassInventory *>(info), amount);
players[i].mo->GiveInventory(info, amount);
}
}
else
{
activator->GiveInventory(static_cast<PClassInventory *>(info), amount);
activator->GiveInventory(info, amount);
}
}

View File

@ -369,7 +369,9 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, DWORD &prevSpeaker
node->ItemCheck.Resize(3);
for (j = 0; j < 3; ++j)
{
node->ItemCheck[j].Item = dyn_cast<PClassInventory>(GetStrifeType(speech.ItemCheck[j]));
auto inv = GetStrifeType(speech.ItemCheck[j]);
if (!inv->IsDescendantOf(RUNTIME_CLASS(AInventory))) inv = nullptr;
node->ItemCheck[j].Item = inv;
node->ItemCheck[j].Amount = -1;
}
node->ItemCheckNode = speech.Link;
@ -513,7 +515,9 @@ static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses)
reply->ItemCheck.Resize(3);
for (k = 0; k < 3; ++k)
{
reply->ItemCheck[k].Item = dyn_cast<PClassInventory>(GetStrifeType(rsp->Item[k]));
auto inv = GetStrifeType(rsp->Item[k]);
if (!inv->IsDescendantOf(RUNTIME_CLASS(AInventory))) inv = nullptr;
reply->ItemCheck[k].Item = inv;
reply->ItemCheck[k].Amount = rsp->Count[k];
}
reply->ItemCheckRequire.Clear();

View File

@ -12,7 +12,7 @@ struct FBrokenLines;
struct FStrifeDialogueItemCheck
{
PClassInventory *Item;
PClassActor *Item;
int Amount;
};

View File

@ -767,10 +767,12 @@ DEFINE_ACTION_FUNCTION(AActor, AddInventory)
//
//============================================================================
bool AActor::GiveInventory(PClassInventory *type, int amount, bool givecheat)
bool AActor::GiveInventory(PClassActor *type, int amount, bool givecheat)
{
bool result = true;
if (type != nullptr || !type->IsDescendantOf(RUNTIME_CLASS(AInventory))) return false;
AWeapon *savedPendingWeap = player != NULL ? player->PendingWeapon : NULL;
bool hadweap = player != NULL ? player->ReadyWeapon != NULL : true;
@ -789,7 +791,7 @@ bool AActor::GiveInventory(PClassInventory *type, int amount, bool givecheat)
item->ClearCounters();
if (!givecheat || amount > 0)
{
if (type->IsDescendantOf (NAME_BasicArmorPickup) || type->IsDescendantOf(NAME_BasicArmorBonus))
if (type->IsDescendantOf (PClass::FindActor(NAME_BasicArmorPickup)) || type->IsDescendantOf(PClass::FindActor(NAME_BasicArmorBonus)))
{
item->IntVar(NAME_SaveAmount) *= amount;
}
@ -1146,10 +1148,12 @@ DEFINE_ACTION_FUNCTION(AActor, GiveInventoryType)
//
//============================================================================
bool AActor::GiveAmmo (PClassInventory *type, int amount)
bool AActor::GiveAmmo (PClassActor *type, int amount)
{
if (type != NULL)
{
if (!type->IsDescendantOf(RUNTIME_CLASS(AInventory))) return false;
AInventory *item = static_cast<AInventory *>(Spawn (type));
if (item)
{
@ -1542,7 +1546,7 @@ bool AActor::IsVisibleToPlayer() const
bool visible = false;
for(unsigned int i = 0;i < GetClass()->VisibleToPlayerClass.Size();++i)
{
PClassPlayerPawn *cls = GetClass()->VisibleToPlayerClass[i];
auto cls = GetClass()->VisibleToPlayerClass[i];
if (cls && pPlayer->mo->GetClass()->IsDescendantOf(cls))
{
visible = true;

View File

@ -57,21 +57,23 @@ class USDFParser : public UDMFParserBase
PClassActor *CheckActorType(const char *key)
{
PClassActor *type = nullptr;
if (namespace_bits == St)
{
return GetStrifeType(CheckInt(key));
type = GetStrifeType(CheckInt(key));
}
else if (namespace_bits == Zd)
{
PClassActor *cls = PClass::FindActor(CheckString(key));
if (cls == NULL)
if (cls == nullptr)
{
sc.ScriptMessage("Unknown actor class '%s'", key);
return NULL;
return nullptr;
}
return cls;
type = cls;
}
return NULL;
if (type && type->IsDescendantOf(RUNTIME_CLASS(AInventory))) return type;
return nullptr;
}
//===========================================================================
@ -92,7 +94,7 @@ class USDFParser : public UDMFParserBase
switch(key)
{
case NAME_Item:
check.Item = dyn_cast<PClassInventory>(CheckActorType(key));
check.Item = CheckActorType(key);
break;
case NAME_Amount:
@ -266,7 +268,7 @@ class USDFParser : public UDMFParserBase
switch(key)
{
case NAME_Item:
check.Item = dyn_cast<PClassInventory>(CheckActorType(key));
check.Item = CheckActorType(key);
break;
case NAME_Count:

View File

@ -931,7 +931,7 @@ bool APlayerPawn::UseInventory (AInventory *item)
//
//===========================================================================
AWeapon *APlayerPawn::BestWeapon(PClassInventory *ammotype)
AWeapon *APlayerPawn::BestWeapon(PClassActor *ammotype)
{
AWeapon *bestMatch = NULL;
int bestOrder = INT_MAX;
@ -993,7 +993,7 @@ AWeapon *APlayerPawn::BestWeapon(PClassInventory *ammotype)
//
//===========================================================================
AWeapon *APlayerPawn::PickNewWeapon(PClassInventory *ammotype)
AWeapon *APlayerPawn::PickNewWeapon(PClassActor *ammotype)
{
AWeapon *best = BestWeapon (ammotype);
@ -1021,7 +1021,7 @@ AWeapon *APlayerPawn::PickNewWeapon(PClassInventory *ammotype)
//
//===========================================================================
void APlayerPawn::CheckWeaponSwitch(PClassInventory *ammotype)
void APlayerPawn::CheckWeaponSwitch(PClassActor *ammotype)
{
if (!player->userinfo.GetNeverSwitch() &&
player->PendingWeapon == WP_NOCHANGE &&
@ -1040,7 +1040,7 @@ void APlayerPawn::CheckWeaponSwitch(PClassInventory *ammotype)
DEFINE_ACTION_FUNCTION(APlayerPawn, CheckWeaponSwitch)
{
PARAM_SELF_PROLOGUE(APlayerPawn);
PARAM_OBJECT(ammotype, PClassInventory);
PARAM_OBJECT(ammotype, PClassActor);
self->CheckWeaponSwitch(ammotype);
return 0;
}
@ -1346,7 +1346,7 @@ void APlayerPawn::GiveDefaultInventory ()
// HexenArmor must always be the first item in the inventory because
// it provides player class based protection that should not affect
// any other protection item.
PClassPlayerPawn *myclass = GetClass();
auto myclass = GetClass();
GiveInventoryType(PClass::FindActor(NAME_HexenArmor));
auto harmor = FindInventory(NAME_HexenArmor);

View File

@ -541,7 +541,7 @@ static void ParseInsideDecoration (Baggage &bag, AActor *defaults,
else if (def == DEF_Pickup && sc.Compare ("PickupMessage"))
{
sc.MustGetString ();
static_cast<PClassInventory *>(bag.Info)->PickupMsg = sc.String;
bag.Info->PickupMsg = sc.String;
}
else if (def == DEF_Pickup && sc.Compare ("Respawns"))
{

View File

@ -97,7 +97,7 @@ static PClassActor *FindClassTentative(const char *name, PClass *ancestor, bool
}
static AInventory::MetaClass *FindClassTentativeAmmo(const char *name, bool optional = false)
{
return static_cast<PClassInventory *>(FindClassTentative(name, PClass::FindActor(NAME_Ammo), optional));
return static_cast<AInventory::MetaClass *>(FindClassTentative(name, PClass::FindActor(NAME_Ammo), optional));
}
static AWeapon::MetaClass *FindClassTentativeWeapon(const char *name, bool optional = false)
{
@ -1699,12 +1699,12 @@ DEFINE_PROPERTY(distancecheck, S, Actor)
//==========================================================================
DEFINE_CLASS_PROPERTY(restrictedto, Ssssssssssssssssssss, Inventory)
{
static_cast<PClassInventory*>(info)->RestrictedToPlayerClass.Clear();
static_cast<PClassActor*>(info)->RestrictedToPlayerClass.Clear();
for(int i = 0;i < PROP_PARM_COUNT;++i)
{
PROP_STRING_PARM(n, i);
if (*n != 0)
static_cast<PClassInventory*>(info)->RestrictedToPlayerClass.Push(FindClassTentativePlayerPawn(n));
static_cast<PClassActor*>(info)->RestrictedToPlayerClass.Push(FindClassTentativePlayerPawn(n));
}
}
@ -1713,12 +1713,12 @@ DEFINE_CLASS_PROPERTY(restrictedto, Ssssssssssssssssssss, Inventory)
//==========================================================================
DEFINE_CLASS_PROPERTY(forbiddento, Ssssssssssssssssssss, Inventory)
{
static_cast<PClassInventory*>(info)->ForbiddenToPlayerClass.Clear();
static_cast<PClassActor*>(info)->ForbiddenToPlayerClass.Clear();
for(int i = 0;i < PROP_PARM_COUNT;++i)
{
PROP_STRING_PARM(n, i);
if (*n != 0)
static_cast<PClassInventory*>(info)->ForbiddenToPlayerClass.Push(FindClassTentativePlayerPawn(n));
static_cast<PClassActor*>(info)->ForbiddenToPlayerClass.Push(FindClassTentativePlayerPawn(n));
}
}
@ -1817,8 +1817,8 @@ DEFINE_CLASS_PROPERTY(pickupflash, S, Inventory)
DEFINE_CLASS_PROPERTY(pickupmessage, T, Inventory)
{
PROP_STRING_PARM(str, 0);
assert(info->IsKindOf(RUNTIME_CLASS(PClassInventory)));
static_cast<PClassInventory *>(info)->PickupMsg = str;
assert(info->IsKindOf(RUNTIME_CLASS(PClassActor)));
static_cast<PClassActor *>(info)->PickupMsg = str;
}
//==========================================================================