From 228a71d477d58f923000ac554a0db1d4dddcb733 Mon Sep 17 00:00:00 2001 From: MaxED Date: Fri, 13 May 2016 14:42:15 +0000 Subject: [PATCH] Added, Map Analysis mode: added "Check unknown actions and effects" check. --- Source/Core/Config/GameConfiguration.cs | 2 + .../Plugins/BuilderModes/BuilderModes.csproj | 4 + .../ErrorChecks/CheckUnknownActions.cs | 93 +++++++++++++++++++ .../ErrorChecks/ResultUnknownLinedefAction.cs | 86 +++++++++++++++++ .../ErrorChecks/ResultUnknownSectorEffect.cs | 84 +++++++++++++++++ .../ErrorChecks/ResultUnknownThingAction.cs | 84 +++++++++++++++++ 6 files changed, 353 insertions(+) create mode 100644 Source/Plugins/BuilderModes/ErrorChecks/CheckUnknownActions.cs create mode 100644 Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownLinedefAction.cs create mode 100644 Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownSectorEffect.cs create mode 100644 Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownThingAction.cs diff --git a/Source/Core/Config/GameConfiguration.cs b/Source/Core/Config/GameConfiguration.cs index f0806d9..5ed0670 100644 --- a/Source/Core/Config/GameConfiguration.cs +++ b/Source/Core/Config/GameConfiguration.cs @@ -1086,6 +1086,7 @@ namespace CodeImp.DoomBuilder.Config } //mxd + public static bool IsGeneralizedSectorEffect(int effect) { return IsGeneralizedSectorEffect(effect, General.Map.Config.GenEffectOptions); } public static bool IsGeneralizedSectorEffect(int effect, List options) { if(effect == 0) return false; @@ -1098,6 +1099,7 @@ namespace CodeImp.DoomBuilder.Config GeneralizedBit bit = options[i].Bits[j]; if(bit.Index > 0 && (cureffect & bit.Index) == bit.Index) return true; cureffect -= bit.Index; + if(cureffect < 1) return false; } } diff --git a/Source/Plugins/BuilderModes/BuilderModes.csproj b/Source/Plugins/BuilderModes/BuilderModes.csproj index 15fc2cb..2d60383 100644 --- a/Source/Plugins/BuilderModes/BuilderModes.csproj +++ b/Source/Plugins/BuilderModes/BuilderModes.csproj @@ -351,6 +351,7 @@ + @@ -369,8 +370,11 @@ + + + diff --git a/Source/Plugins/BuilderModes/ErrorChecks/CheckUnknownActions.cs b/Source/Plugins/BuilderModes/ErrorChecks/CheckUnknownActions.cs new file mode 100644 index 0000000..a4e40c8 --- /dev/null +++ b/Source/Plugins/BuilderModes/ErrorChecks/CheckUnknownActions.cs @@ -0,0 +1,93 @@ +using System.Threading; +using CodeImp.DoomBuilder.Config; +using CodeImp.DoomBuilder.Map; + +namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks +{ + [ErrorChecker("Check unknown actions/effects", true, 50)] + public class CheckUnknownActions : ErrorChecker + { + private const int PROGRESS_STEP = 1000; + + // Constructor + public CheckUnknownActions() + { + int count = General.Map.Map.Sectors.Count + General.Map.Map.Linedefs.Count; + if(General.Map.FormatInterface.HasThingAction) count += General.Map.Map.Things.Count; + + // Total progress is done when all relevant map elements are checked + SetTotalProgress(count / PROGRESS_STEP); + } + + // This runs the check + public override void Run() + { + int progress = 0; + int stepprogress = 0; + + // Go for all Linedefs + foreach(Linedef l in General.Map.Map.Linedefs) + { + // Check action... + if(l.Action != 0 && !General.Map.Config.LinedefActions.ContainsKey(l.Action) + && !GameConfiguration.IsGeneralized(l.Action)) + { + SubmitResult(new ResultUnknownLinedefAction(l)); + } + + // Handle thread interruption + try { Thread.Sleep(0); } catch(ThreadInterruptedException) { return; } + + // We are making progress! + if((++progress / PROGRESS_STEP) > stepprogress) + { + stepprogress = (progress / PROGRESS_STEP); + AddProgress(1); + } + } + + // Go for all Sectors + foreach(Sector s in General.Map.Map.Sectors) + { + // Check action... + if(s.Effect != 0 && !General.Map.Config.SectorEffects.ContainsKey(s.Effect) + && !GameConfiguration.IsGeneralizedSectorEffect(s.Effect)) + { + SubmitResult(new ResultUnknownSectorEffect(s)); + } + + // Handle thread interruption + try { Thread.Sleep(0); } catch(ThreadInterruptedException) { return; } + + // We are making progress! + if((++progress / PROGRESS_STEP) > stepprogress) + { + stepprogress = (progress / PROGRESS_STEP); + AddProgress(1); + } + } + + // Go for all things? + if(!General.Map.FormatInterface.HasThingAction) return; + foreach(Thing t in General.Map.Map.Things) + { + // Check action... + if(t.Action != 0 && !General.Map.Config.LinedefActions.ContainsKey(t.Action) + && !GameConfiguration.IsGeneralized(t.Action)) + { + SubmitResult(new ResultUnknownThingAction(t)); + } + + // Handle thread interruption + try { Thread.Sleep(0); } catch(ThreadInterruptedException) { return; } + + // We are making progress! + if((++progress / PROGRESS_STEP) > stepprogress) + { + stepprogress = (progress / PROGRESS_STEP); + AddProgress(1); + } + } + } + } +} diff --git a/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownLinedefAction.cs b/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownLinedefAction.cs new file mode 100644 index 0000000..71a3de3 --- /dev/null +++ b/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownLinedefAction.cs @@ -0,0 +1,86 @@ +#region ================== Namespaces + +using System; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + public class ResultUnknownLinedefAction : ErrorResult + { + #region ================== Variables + + private readonly Linedef line; + + #endregion + + #region ================== Properties + + public override int Buttons { get { return 2; } } + public override string Button1Text { get { return "Remove Action"; } } + public override string Button2Text { get { return "Browse Action..."; } } //mxd + + #endregion + + #region ================== Constructor / Destructor + + // Constructor + public ResultUnknownLinedefAction(Linedef l) + { + // Initialize + line = l; + viewobjects.Add(l); + hidden = l.IgnoredErrorChecks.Contains(this.GetType()); //mxd + description = "This linedef uses unknown action. This can potentially cause gameplay issues."; + } + + #endregion + + #region ================== Methods + + // This sets if this result is displayed in ErrorCheckForm (mxd) + internal override void Hide(bool hide) + { + hidden = hide; + Type t = this.GetType(); + if(hide) line.IgnoredErrorChecks.Add(t); + else if(line.IgnoredErrorChecks.Contains(t)) line.IgnoredErrorChecks.Remove(t); + } + + // This must return the string that is displayed in the listbox + public override string ToString() + { + return "Linedef " + line.Index + " uses unknown action " + line.Action; + } + + // Rendering + public override void PlotSelection(IRenderer2D renderer) + { + renderer.PlotLinedef(line, General.Colors.Selection); + renderer.PlotVertex(line.Start, ColorCollection.VERTICES); + renderer.PlotVertex(line.End, ColorCollection.VERTICES); + } + + // Fix by removing action + public override bool Button1Click(bool batchmode) + { + if(!batchmode) General.Map.UndoRedo.CreateUndo("Unknown linedef action removal"); + line.Action = 0; + General.Map.Map.Update(); + return true; + } + + // Fix by picking action + public override bool Button2Click(bool batchmode) + { + if(!batchmode) General.Map.UndoRedo.CreateUndo("Unknown linedef action correction"); + line.Action = General.Interface.BrowseLinedefActions(BuilderPlug.Me.ErrorCheckForm, line.Action); + General.Map.Map.Update(); + return true; + } + + #endregion + } +} diff --git a/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownSectorEffect.cs b/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownSectorEffect.cs new file mode 100644 index 0000000..7128cc4 --- /dev/null +++ b/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownSectorEffect.cs @@ -0,0 +1,84 @@ +#region ================== Namespaces + +using System; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + public class ResultUnknownSectorEffect : ErrorResult + { + #region ================== Variables + + private readonly Sector sector; + + #endregion + + #region ================== Properties + + public override int Buttons { get { return 2; } } + public override string Button1Text { get { return "Remove Effect"; } } + public override string Button2Text { get { return "Browse Effect..."; } } //mxd + + #endregion + + #region ================== Constructor + + // Constructor + public ResultUnknownSectorEffect(Sector s) + { + // Initialize + sector = s; + viewobjects.Add(s); + hidden = s.IgnoredErrorChecks.Contains(this.GetType()); //mxd + description = "This sector uses unknown effect. This can potentially cause gameplay issues."; + } + + #endregion + + #region ================== Methods + + // This sets if this result is displayed in ErrorCheckForm (mxd) + internal override void Hide(bool hide) + { + hidden = hide; + Type t = this.GetType(); + if(hide) sector.IgnoredErrorChecks.Add(t); + else if(sector.IgnoredErrorChecks.Contains(t)) sector.IgnoredErrorChecks.Remove(t); + } + + // This must return the string that is displayed in the listbox + public override string ToString() + { + return "Sector " + sector.Index + " uses unknown effect " + sector.Effect; + } + + // Rendering + public override void PlotSelection(IRenderer2D renderer) + { + renderer.PlotSector(sector, General.Colors.Selection); + } + + // Fix by removing effect + public override bool Button1Click(bool batchmode) + { + if(!batchmode) General.Map.UndoRedo.CreateUndo("Unknown sector effect removal"); + sector.Effect = 0; + General.Map.Map.Update(); + return true; + } + + // Fix by picking effect + public override bool Button2Click(bool batchmode) + { + if(!batchmode) General.Map.UndoRedo.CreateUndo("Unknown sector effect correction"); + sector.Effect = General.Interface.BrowseSectorEffect(BuilderPlug.Me.ErrorCheckForm, sector.Effect); + General.Map.Map.Update(); + return true; + } + + #endregion + } +} diff --git a/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownThingAction.cs b/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownThingAction.cs new file mode 100644 index 0000000..a26cc64 --- /dev/null +++ b/Source/Plugins/BuilderModes/ErrorChecks/ResultUnknownThingAction.cs @@ -0,0 +1,84 @@ +#region ================== Namespaces + +using System; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + public class ResultUnknownThingAction : ErrorResult + { + #region ================== Variables + + private readonly Thing thing; + + #endregion + + #region ================== Properties + + public override int Buttons { get { return 2; } } + public override string Button1Text { get { return "Remove Action"; } } + public override string Button2Text { get { return "Browse Action..."; } } //mxd + + #endregion + + #region ================== Constructor / Destructor + + // Constructor + public ResultUnknownThingAction(Thing t) + { + // Initialize + thing = t; + viewobjects.Add(t); + hidden = t.IgnoredErrorChecks.Contains(this.GetType()); //mxd + description = "This thing uses unknown action. This can potentially cause gameplay issues."; + } + + #endregion + + #region ================== Methods + + // This sets if this result is displayed in ErrorCheckForm (mxd) + internal override void Hide(bool hide) + { + hidden = hide; + Type t = this.GetType(); + if(hide) thing.IgnoredErrorChecks.Add(t); + else if(thing.IgnoredErrorChecks.Contains(t)) thing.IgnoredErrorChecks.Remove(t); + } + + // This must return the string that is displayed in the listbox + public override string ToString() + { + return "Thing " + thing.Index + " uses unknown action " + thing.Action; + } + + // Rendering + public override void RenderOverlaySelection(IRenderer2D renderer) + { + renderer.RenderThing(thing, General.Colors.Selection, General.Settings.ActiveThingsAlpha); + } + + // Fix by removing action + public override bool Button1Click(bool batchmode) + { + if(!batchmode) General.Map.UndoRedo.CreateUndo("Unknown thing action removal"); + thing.Action = 0; + General.Map.Map.Update(); + return true; + } + + // Fix by picking action + public override bool Button2Click(bool batchmode) + { + if(!batchmode) General.Map.UndoRedo.CreateUndo("Unknown thing action correction"); + thing.Action = General.Interface.BrowseLinedefActions(BuilderPlug.Me.ErrorCheckForm, thing.Action); + General.Map.Map.Update(); + return true; + } + + #endregion + } +}