diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index 7ccc0b7d7..0bf96e441 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -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(f->Type)->ClassRestriction->FindClassTentative(sc.String); + *(PClass**)addr = nullptr; } - else if (!cls->IsDescendantOf(static_cast(f->Type)->ClassRestriction)) + else { - sc.ScriptMessage("class %s is not compatible with property type %s", sc.String, static_cast(f->Type)->ClassRestriction->TypeName.GetChars()); - FScriptPosition::ErrorCounter++; + auto cls = PClass::FindClass(sc.String); + if (cls == nullptr) + { + cls = static_cast(f->Type)->ClassRestriction->FindClassTentative(sc.String); + } + else if (!cls->IsDescendantOf(static_cast(f->Type)->ClassRestriction)) + { + sc.ScriptMessage("class %s is not compatible with property type %s", sc.String, static_cast(f->Type)->ClassRestriction->TypeName.GetChars()); + FScriptPosition::ErrorCounter++; + } + *(PClass**)addr = cls; } - *(PClass**)addr = cls; } else { diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 1094098fb..03fe4128a 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -96,18 +96,6 @@ static PClassActor *FindClassTentative(const char *name, PClass *ancestor, bool } return static_cast(cls); } -static AInventory::MetaClass *FindClassTentativeAmmo(const char *name, bool optional = false) -{ - return static_cast(FindClassTentative(name, PClass::FindActor(NAME_Ammo), optional)); -} -static AWeapon::MetaClass *FindClassTentativeWeapon(const char *name, bool optional = false) -{ - return static_cast(FindClassTentative(name, RUNTIME_CLASS(AWeapon), optional)); -} -static APlayerPawn::MetaClass *FindClassTentativePlayerPawn(const char *name, bool optional = false) -{ - return static_cast(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(info)->RestrictedToPlayerClass.Push(FindClassTentativePlayerPawn(n)); + static_cast(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(info)->ForbiddenToPlayerClass.Push(FindClassTentativePlayerPawn(n)); + static_cast(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(NAME_PlayerClass) = FindClassTentativePlayerPawn(str, bag.fromDecorate); + defaults->PointerVar(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(NAME_PlayerClass) = FindClassTentativePlayerPawn(str, bag.fromDecorate); + defaults->PointerVar(NAME_PlayerClass) = FindClassTentative(str, RUNTIME_CLASS(APlayerPawn), bag.fromDecorate); } //========================================================================== diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index e36e59df3..8d8277a6d 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -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(f->Type)->ClassRestriction->FindClassTentative(clsname); + *(PClass**)addr = nullptr; } - else if (!cls->IsDescendantOf(static_cast(f->Type)->ClassRestriction)) + else { - Error(property, "class %s is not compatible with property type %s", clsname, static_cast(f->Type)->ClassRestriction->TypeName.GetChars()); + auto cls = PClass::FindClass(clsname); + if (cls == nullptr) + { + cls = static_cast(f->Type)->ClassRestriction->FindClassTentative(clsname); + } + else if (!cls->IsDescendantOf(static_cast(f->Type)->ClassRestriction)) + { + Error(property, "class %s is not compatible with property type %s", clsname, static_cast(f->Type)->ClassRestriction->TypeName.GetChars()); + } + *(PClass**)addr = cls; } - *(PClass**)addr = cls; } else { diff --git a/wadsrc/static/zscript/inventory/weapons.txt b/wadsrc/static/zscript/inventory/weapons.txt index 97f4142e6..03b34b947 100644 --- a/wadsrc/static/zscript/inventory/weapons.txt +++ b/wadsrc/static/zscript/inventory/weapons.txt @@ -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;