- fixed generic class type properties to handle "" and "none" as 'no class'.

This commit is contained in:
Christoph Oelckers 2017-03-19 12:02:17 +01:00
parent 2c789a2d75
commit ac95cba848
4 changed files with 36 additions and 61 deletions

View file

@ -883,18 +883,25 @@ static void DispatchScriptProperty(FScanner &sc, PProperty *prop, AActor *defaul
else if (f->Type->IsKindOf(RUNTIME_CLASS(PClassPointer)))
{
sc.MustGetString();
auto cls = PClass::FindClass(sc.String);
*(PClass**)addr = cls;
if (cls == nullptr)
if (*sc.String == 0 || !stricmp(sc.String, "none"))
{
cls = static_cast<PClassPointer*>(f->Type)->ClassRestriction->FindClassTentative(sc.String);
*(PClass**)addr = nullptr;
}
else if (!cls->IsDescendantOf(static_cast<PClassPointer*>(f->Type)->ClassRestriction))
else
{
sc.ScriptMessage("class %s is not compatible with property type %s", sc.String, static_cast<PClassPointer*>(f->Type)->ClassRestriction->TypeName.GetChars());
FScriptPosition::ErrorCounter++;
auto cls = PClass::FindClass(sc.String);
if (cls == nullptr)
{
cls = static_cast<PClassPointer*>(f->Type)->ClassRestriction->FindClassTentative(sc.String);
}
else if (!cls->IsDescendantOf(static_cast<PClassPointer*>(f->Type)->ClassRestriction))
{
sc.ScriptMessage("class %s is not compatible with property type %s", sc.String, static_cast<PClassPointer*>(f->Type)->ClassRestriction->TypeName.GetChars());
FScriptPosition::ErrorCounter++;
}
*(PClass**)addr = cls;
}
*(PClass**)addr = cls;
}
else
{

View file

@ -96,18 +96,6 @@ static PClassActor *FindClassTentative(const char *name, PClass *ancestor, bool
}
return static_cast<PClassActor *>(cls);
}
static AInventory::MetaClass *FindClassTentativeAmmo(const char *name, bool optional = false)
{
return static_cast<AInventory::MetaClass *>(FindClassTentative(name, PClass::FindActor(NAME_Ammo), optional));
}
static AWeapon::MetaClass *FindClassTentativeWeapon(const char *name, bool optional = false)
{
return static_cast<AWeapon::MetaClass *>(FindClassTentative(name, RUNTIME_CLASS(AWeapon), optional));
}
static APlayerPawn::MetaClass *FindClassTentativePlayerPawn(const char *name, bool optional = false)
{
return static_cast<APlayerPawn::MetaClass *>(FindClassTentative(name, RUNTIME_CLASS(APlayerPawn), optional));
}
//==========================================================================
//
@ -1065,7 +1053,7 @@ DEFINE_PROPERTY(visibletoplayerclass, Ssssssssssssssssssss, Actor)
{
PROP_STRING_PARM(n, i);
if (*n != 0)
info->VisibleToPlayerClass.Push(FindClassTentativePlayerPawn(n));
info->VisibleToPlayerClass.Push(FindClassTentative(n, RUNTIME_CLASS(APlayerPawn)));
}
}
@ -1107,7 +1095,7 @@ DEFINE_CLASS_PROPERTY(restrictedto, Ssssssssssssssssssss, Inventory)
{
PROP_STRING_PARM(n, i);
if (*n != 0)
static_cast<PClassActor*>(info)->RestrictedToPlayerClass.Push(FindClassTentativePlayerPawn(n));
static_cast<PClassActor*>(info)->RestrictedToPlayerClass.Push(FindClassTentative(n, RUNTIME_CLASS(APlayerPawn)));
}
}
@ -1121,7 +1109,7 @@ DEFINE_CLASS_PROPERTY(forbiddento, Ssssssssssssssssssss, Inventory)
{
PROP_STRING_PARM(n, i);
if (*n != 0)
static_cast<PClassActor*>(info)->ForbiddenToPlayerClass.Push(FindClassTentativePlayerPawn(n));
static_cast<PClassActor*>(info)->ForbiddenToPlayerClass.Push(FindClassTentative(n, RUNTIME_CLASS(APlayerPawn)));
}
}
@ -1184,36 +1172,6 @@ DEFINE_CLASS_PROPERTY(pickupannouncerentry, S, Inventory)
{
}
//==========================================================================
//
//==========================================================================
DEFINE_CLASS_PROPERTY(ammotype, S, Weapon)
{
PROP_STRING_PARM(str, 0);
if (!stricmp(str, "none") || *str == 0) defaults->AmmoType1 = NULL;
else defaults->AmmoType1 = FindClassTentativeAmmo(str);
}
//==========================================================================
//
//==========================================================================
DEFINE_CLASS_PROPERTY(ammotype1, S, Weapon)
{
PROP_STRING_PARM(str, 0);
if (!stricmp(str, "none") || *str == 0) defaults->AmmoType1 = NULL;
else defaults->AmmoType1 = FindClassTentativeAmmo(str);
}
//==========================================================================
//
//==========================================================================
DEFINE_CLASS_PROPERTY(ammotype2, S, Weapon)
{
PROP_STRING_PARM(str, 0);
if (!stricmp(str, "none") || *str == 0) defaults->AmmoType1 = NULL;
else defaults->AmmoType2 = FindClassTentativeAmmo(str);
}
//==========================================================================
//
//==========================================================================
@ -1779,7 +1737,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, viewbob, F, PlayerPawn)
DEFINE_SCRIPTED_PROPERTY(playerclass, S, MorphProjectile)
{
PROP_STRING_PARM(str, 0);
defaults->PointerVar<PClassActor>(NAME_PlayerClass) = FindClassTentativePlayerPawn(str, bag.fromDecorate);
defaults->PointerVar<PClassActor>(NAME_PlayerClass) = FindClassTentative(str, RUNTIME_CLASS(APlayerPawn), bag.fromDecorate);
}
//==========================================================================
@ -1833,7 +1791,7 @@ DEFINE_SCRIPTED_PROPERTY(unmorphflash, S, MorphProjectile)
DEFINE_SCRIPTED_PROPERTY(playerclass, S, PowerMorph)
{
PROP_STRING_PARM(str, 0);
defaults->PointerVar<PClassActor>(NAME_PlayerClass) = FindClassTentativePlayerPawn(str, bag.fromDecorate);
defaults->PointerVar<PClassActor>(NAME_PlayerClass) = FindClassTentative(str, RUNTIME_CLASS(APlayerPawn), bag.fromDecorate);
}
//==========================================================================

View file

@ -2018,16 +2018,23 @@ void ZCCCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *prop
else if (f->Type->IsKindOf(RUNTIME_CLASS(PClassPointer)))
{
auto clsname = GetStringConst(ex, ctx);
auto cls = PClass::FindClass(clsname);
if (cls == nullptr)
if (*clsname == 0 || !stricmp(clsname, "none"))
{
cls = static_cast<PClassPointer*>(f->Type)->ClassRestriction->FindClassTentative(clsname);
*(PClass**)addr = nullptr;
}
else if (!cls->IsDescendantOf(static_cast<PClassPointer*>(f->Type)->ClassRestriction))
else
{
Error(property, "class %s is not compatible with property type %s", clsname, static_cast<PClassPointer*>(f->Type)->ClassRestriction->TypeName.GetChars());
auto cls = PClass::FindClass(clsname);
if (cls == nullptr)
{
cls = static_cast<PClassPointer*>(f->Type)->ClassRestriction->FindClassTentative(clsname);
}
else if (!cls->IsDescendantOf(static_cast<PClassPointer*>(f->Type)->ClassRestriction))
{
Error(property, "class %s is not compatible with property type %s", clsname, static_cast<PClassPointer*>(f->Type)->ClassRestriction->TypeName.GetChars());
}
*(PClass**)addr = cls;
}
*(PClass**)addr = cls;
}
else
{

View file

@ -43,6 +43,9 @@ class Weapon : StateProvider native
property AmmoUse: AmmoUse1;
property AmmoUse1: AmmoUse1;
property AmmoUse2: AmmoUse2;
property AmmoType: AmmoType1;
property AmmoType1: AmmoType1;
property AmmoType2: AmmoType2;
property Kickback: Kickback;
property ReadySound: ReadySound;
property SelectionOrder: SelectionOrder;