From 05a160b53336be58faaad753f50895c0f5808d4f Mon Sep 17 00:00:00 2001 From: ZZYZX <zzyzx@virtual> Date: Tue, 17 Jan 2017 07:13:28 +0200 Subject: [PATCH] ZScript: moved actor inheritance code to separate step; ZScript: ported game configuration inheritance code from DECORATE --- Source/Core/Properties/AssemblyInfo.cs | 4 +- Source/Core/ZDoom/ZScriptActorStructure.cs | 4 +- Source/Core/ZDoom/ZScriptParser.cs | 48 +++++++++++++++++++ .../BuilderModes/Properties/AssemblyInfo.cs | 2 +- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Source/Core/Properties/AssemblyInfo.cs b/Source/Core/Properties/AssemblyInfo.cs index b4f6c608c..73f92c5d0 100755 --- a/Source/Core/Properties/AssemblyInfo.cs +++ b/Source/Core/Properties/AssemblyInfo.cs @@ -30,6 +30,6 @@ using CodeImp.DoomBuilder; // Build Number // Revision // -[assembly: AssemblyVersion("2.3.0.2824")] +[assembly: AssemblyVersion("2.3.0.2826")] [assembly: NeutralResourcesLanguageAttribute("en")] -[assembly: AssemblyHash("3bdfadc")] +[assembly: AssemblyHash("8fa63ca")] diff --git a/Source/Core/ZDoom/ZScriptActorStructure.cs b/Source/Core/ZDoom/ZScriptActorStructure.cs index 4b205c4ac..1f20f94d3 100755 --- a/Source/Core/ZDoom/ZScriptActorStructure.cs +++ b/Source/Core/ZDoom/ZScriptActorStructure.cs @@ -269,7 +269,7 @@ namespace CodeImp.DoomBuilder.ZDoom classname = _classname; replaceclass = _replacesname; - baseclass = parser.GetArchivedActorByName(_parentname); + //baseclass = parser.GetArchivedActorByName(_parentname); // this is not guaranteed to work here ZScriptToken cls_open = tokenizer.ExpectToken(ZScriptTokenType.OpenCurly); if (cls_open == null || !cls_open.IsValid) @@ -348,7 +348,7 @@ namespace CodeImp.DoomBuilder.ZDoom List<string> names = new List<string>(); List<int> arraylens = new List<int>(); List<ZScriptToken> args = null; // this is for the future - List<ZScriptToken> body = null; + //List<ZScriptToken> body = null; while (true) { diff --git a/Source/Core/ZDoom/ZScriptParser.cs b/Source/Core/ZDoom/ZScriptParser.cs index 3eb88e89b..a3bb7b816 100755 --- a/Source/Core/ZDoom/ZScriptParser.cs +++ b/Source/Core/ZDoom/ZScriptParser.cs @@ -821,12 +821,60 @@ namespace CodeImp.DoomBuilder.ZDoom { ClearError(); + // parse class data foreach (ZScriptClassStructure cls in allclasseslist) { if (!cls.Process()) return false; } + // inject superclasses, since everything is parsed by now + foreach (ZScriptClassStructure cls in allclasseslist) + { + ActorStructure actor = cls.Actor; + if (actor != null && cls.ParentName != null) + { + actor.baseclass = GetArchivedActorByName(cls.ParentName); + string inheritclass = cls.ParentName; + if (actor.baseclass == null) + { + //check if this class inherits from a class defined in game configuration + Dictionary<int, ThingTypeInfo> things = General.Map.Config.GetThingTypes(); + string inheritclasscheck = inheritclass.ToLowerInvariant(); + + bool thingfound = false; + foreach (KeyValuePair<int, ThingTypeInfo> ti in things) + { + if (!string.IsNullOrEmpty(ti.Value.ClassName) && ti.Value.ClassName.ToLowerInvariant() == inheritclasscheck) + { + //states + if (actor.states.Count == 0 && !string.IsNullOrEmpty(ti.Value.Sprite)) + actor.states.Add("spawn", new StateStructure(ti.Value.Sprite.Substring(0, 5))); + + //flags + if (ti.Value.Hangs && !actor.flags.ContainsKey("spawnceiling")) + actor.flags["spawnceiling"] = true; + + if (ti.Value.Blocking > 0 && !actor.flags.ContainsKey("solid")) + actor.flags["solid"] = true; + + //properties + if (!actor.props.ContainsKey("height")) + actor.props["height"] = new List<string> { ti.Value.Height.ToString() }; + + if (!actor.props.ContainsKey("radius")) + actor.props["radius"] = new List<string> { ti.Value.Radius.ToString() }; + + thingfound = true; + break; + } + } + + if (!thingfound) LogWarning("Unable to find \"" + inheritclass + "\" class to inherit from, while parsing \"" + cls.ClassName + "\""); + } + } + } + return true; } diff --git a/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs b/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs index 063d478d0..e30188bb8 100755 --- a/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs +++ b/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Resources; // Build Number // Revision // -[assembly: AssemblyVersion("2.3.0.2824")] +[assembly: AssemblyVersion("2.3.0.2826")] [assembly: NeutralResourcesLanguageAttribute("en")] -- GitLab