- cleaned up the class data organization:

* moved RestrictedToPlayerClass and ForbiddenToPlayerClass arrays to AInventory.
 * moved all copy-from-parent code into DeriveData functions.
This commit is contained in:
Christoph Oelckers 2016-02-10 00:46:51 +01:00
parent 6ce0c9f78e
commit 3358181f18
6 changed files with 33 additions and 34 deletions

View file

@ -50,6 +50,16 @@ void PClassInventory::ReplaceClassRef(PClass *oldclass, PClass *newclass)
if (def != NULL) if (def != NULL)
{ {
if (def->PickupFlash == oldclass) def->PickupFlash = static_cast<PClassActor *>(newclass); 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);
}
for (unsigned i = 0; i < RestrictedToPlayerClass.Size(); i++)
{
if (RestrictedToPlayerClass[i] == oldclass)
RestrictedToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
}
} }
} }
@ -1536,7 +1546,7 @@ bool AInventory::CanPickup (AActor *toucher)
if (!toucher) if (!toucher)
return false; return false;
PClassActor *ai = GetClass(); PClassInventory *ai = GetClass();
// Is the item restricted to certain player classes? // Is the item restricted to certain player classes?
if (ai->RestrictedToPlayerClass.Size() != 0) if (ai->RestrictedToPlayerClass.Size() != 0)
{ {

View file

@ -143,6 +143,8 @@ public:
FString PickupMessage; FString PickupMessage;
int GiveQuest; // Optionally give one of the quest items. int GiveQuest; // Optionally give one of the quest items.
FTextureID AltHUDIcon; FTextureID AltHUDIcon;
TArray<PClassPlayerPawn *> RestrictedToPlayerClass;
TArray<PClassPlayerPawn *> ForbiddenToPlayerClass;
}; };
class AInventory : public AActor class AInventory : public AActor

View file

@ -275,6 +275,22 @@ void PClassActor::DeriveData(PClass *newclass)
newa->MeleeSound = MeleeSound; newa->MeleeSound = MeleeSound;
newa->MissileName = MissileName; newa->MissileName = MissileName;
newa->MissileHeight = MissileHeight; newa->MissileHeight = MissileHeight;
newa->VisibleToPlayerClass = VisibleToPlayerClass;
if (DamageFactors != NULL)
{
// copy damage factors from parent
newa->DamageFactors = new DmgFactors;
*newa->DamageFactors = *DamageFactors;
}
if (PainChances != NULL)
{
// copy pain chances from parent
newa->PainChances = new PainChanceList;
*newa->PainChances = *PainChances;
}
} }
//========================================================================== //==========================================================================
@ -529,16 +545,6 @@ void PClassActor::ReplaceClassRef(PClass *oldclass, PClass *newclass)
if (VisibleToPlayerClass[i] == oldclass) if (VisibleToPlayerClass[i] == oldclass)
VisibleToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass); VisibleToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
} }
for (unsigned i = 0; i < ForbiddenToPlayerClass.Size(); i++)
{
if (ForbiddenToPlayerClass[i] == oldclass)
ForbiddenToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
}
for (unsigned i = 0; i < RestrictedToPlayerClass.Size(); i++)
{
if (RestrictedToPlayerClass[i] == oldclass)
RestrictedToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
}
AActor *def = (AActor*)Defaults; AActor *def = (AActor*)Defaults;
if (def != NULL) if (def != NULL)
{ {

View file

@ -237,8 +237,6 @@ public:
PainChanceList *PainChances; PainChanceList *PainChances;
TArray<PClassPlayerPawn *> VisibleToPlayerClass; TArray<PClassPlayerPawn *> VisibleToPlayerClass;
TArray<PClassPlayerPawn *> RestrictedToPlayerClass;
TArray<PClassPlayerPawn *> ForbiddenToPlayerClass;
FString Obituary; // Player was killed by this actor FString Obituary; // Player was killed by this actor
FString HitObituary; // Player was killed by this actor in melee FString HitObituary; // Player was killed by this actor in melee

View file

@ -145,23 +145,6 @@ PClassActor *CreateNewActor(const FScriptPosition &sc, FName typeName, FName par
ti = static_cast<PClassActor *>(parent->CreateDerivedClass (typeName, parent->Size)); ti = static_cast<PClassActor *>(parent->CreateDerivedClass (typeName, parent->Size));
} }
// Copy class lists from parent
ti->ForbiddenToPlayerClass = parent->ForbiddenToPlayerClass;
ti->RestrictedToPlayerClass = parent->RestrictedToPlayerClass;
ti->VisibleToPlayerClass = parent->VisibleToPlayerClass;
if (parent->DamageFactors != NULL)
{
// copy damage factors from parent
ti->DamageFactors = new DmgFactors;
*ti->DamageFactors = *parent->DamageFactors;
}
if (parent->PainChances != NULL)
{
// copy pain chances from parent
ti->PainChances = new PainChanceList;
*ti->PainChances = *parent->PainChances;
}
ti->Replacee = ti->Replacement = NULL; ti->Replacee = ti->Replacement = NULL;
ti->DoomEdNum = -1; ti->DoomEdNum = -1;
return ti; return ti;

View file

@ -1534,12 +1534,12 @@ DEFINE_PROPERTY(riplevelmax, I, Actor)
//========================================================================== //==========================================================================
DEFINE_CLASS_PROPERTY(restrictedto, Ssssssssssssssssssss, Inventory) DEFINE_CLASS_PROPERTY(restrictedto, Ssssssssssssssssssss, Inventory)
{ {
info->RestrictedToPlayerClass.Clear(); static_cast<PClassInventory*>(info)->RestrictedToPlayerClass.Clear();
for(int i = 0;i < PROP_PARM_COUNT;++i) for(int i = 0;i < PROP_PARM_COUNT;++i)
{ {
PROP_STRING_PARM(n, i); PROP_STRING_PARM(n, i);
if (*n != 0) if (*n != 0)
info->RestrictedToPlayerClass.Push(FindClassTentativePlayerPawn(n)); static_cast<PClassInventory*>(info)->RestrictedToPlayerClass.Push(FindClassTentativePlayerPawn(n));
} }
} }
@ -1548,12 +1548,12 @@ DEFINE_CLASS_PROPERTY(restrictedto, Ssssssssssssssssssss, Inventory)
//========================================================================== //==========================================================================
DEFINE_CLASS_PROPERTY(forbiddento, Ssssssssssssssssssss, Inventory) DEFINE_CLASS_PROPERTY(forbiddento, Ssssssssssssssssssss, Inventory)
{ {
info->ForbiddenToPlayerClass.Clear(); static_cast<PClassInventory*>(info)->ForbiddenToPlayerClass.Clear();
for(int i = 0;i < PROP_PARM_COUNT;++i) for(int i = 0;i < PROP_PARM_COUNT;++i)
{ {
PROP_STRING_PARM(n, i); PROP_STRING_PARM(n, i);
if (*n != 0) if (*n != 0)
info->ForbiddenToPlayerClass.Push(FindClassTentativePlayerPawn(n)); static_cast<PClassInventory*>(info)->ForbiddenToPlayerClass.Push(FindClassTentativePlayerPawn(n));
} }
} }