From 841f4087b65d9bf8b2654c445eec0efff1d13efc Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 13 Jan 2016 22:28:16 +0100 Subject: [PATCH] Special Z position handling for NiGHTS path items and hoops --- Source/Core/IO/DoomMapSetIO.cs | 1 + Source/Core/IO/HexenMapSetIO.cs | 1 + Source/Core/IO/IMapSetIO.cs | 1 + Source/Core/IO/MapSetIO.cs | 1 + Source/Core/IO/SRB2MapSetIO.cs | 1 + Source/Core/IO/UniversalMapSetIO.cs | 1 + Source/Core/Map/Thing.cs | 54 ++++++++++++------- .../VisualModes/BaseVisualThing.cs | 54 +++++++++++++++---- 8 files changed, 87 insertions(+), 27 deletions(-) diff --git a/Source/Core/IO/DoomMapSetIO.cs b/Source/Core/IO/DoomMapSetIO.cs index 169ddf9..83719dd 100644 --- a/Source/Core/IO/DoomMapSetIO.cs +++ b/Source/Core/IO/DoomMapSetIO.cs @@ -104,6 +104,7 @@ namespace CodeImp.DoomBuilder.IO public override int ColormapType { get { return -1; } } public override int FlatAlignmentType { get { return -1; } } public override int AxisType { get { return -1; } } + public override int AxisTransferType { get { return -1; } } public override int AxisTransferLineType { get { return -1; } } #endregion diff --git a/Source/Core/IO/HexenMapSetIO.cs b/Source/Core/IO/HexenMapSetIO.cs index 0d0a61f..77ad6ae 100644 --- a/Source/Core/IO/HexenMapSetIO.cs +++ b/Source/Core/IO/HexenMapSetIO.cs @@ -104,6 +104,7 @@ namespace CodeImp.DoomBuilder.IO public override int ColormapType { get { return -1; } } public override int FlatAlignmentType { get { return -1; } } public override int AxisType { get { return -1; } } + public override int AxisTransferType { get { return -1; } } public override int AxisTransferLineType { get { return -1; } } #endregion diff --git a/Source/Core/IO/IMapSetIO.cs b/Source/Core/IO/IMapSetIO.cs index 9490ffc..30337ef 100644 --- a/Source/Core/IO/IMapSetIO.cs +++ b/Source/Core/IO/IMapSetIO.cs @@ -80,6 +80,7 @@ namespace CodeImp.DoomBuilder.IO int ColormapType { get; } int FlatAlignmentType { get; } int AxisType { get; } + int AxisTransferType { get; } int AxisTransferLineType { get; } List UnflippableTypes { get; } List StartTypes { get; } diff --git a/Source/Core/IO/MapSetIO.cs b/Source/Core/IO/MapSetIO.cs index fc5d78a..c6984c6 100644 --- a/Source/Core/IO/MapSetIO.cs +++ b/Source/Core/IO/MapSetIO.cs @@ -110,6 +110,7 @@ namespace CodeImp.DoomBuilder.IO public abstract int ColormapType { get; } public abstract int FlatAlignmentType { get; } public abstract int AxisType { get; } + public abstract int AxisTransferType { get; } public abstract int AxisTransferLineType { get; } public List UnflippableTypes { get { return unflippableTypes; } } public List StartTypes { get { return startTypes; } } diff --git a/Source/Core/IO/SRB2MapSetIO.cs b/Source/Core/IO/SRB2MapSetIO.cs index 19a20af..44b8176 100644 --- a/Source/Core/IO/SRB2MapSetIO.cs +++ b/Source/Core/IO/SRB2MapSetIO.cs @@ -165,6 +165,7 @@ namespace CodeImp.DoomBuilder.IO public override int ColormapType { get { return 606; } } public override int FlatAlignmentType { get { return 7; } } public override int AxisType { get { return 1700; } } + public override int AxisTransferType { get { return 1701; } } public override int AxisTransferLineType { get { return 1702; } } #endregion diff --git a/Source/Core/IO/UniversalMapSetIO.cs b/Source/Core/IO/UniversalMapSetIO.cs index 5de3393..447e427 100644 --- a/Source/Core/IO/UniversalMapSetIO.cs +++ b/Source/Core/IO/UniversalMapSetIO.cs @@ -155,6 +155,7 @@ namespace CodeImp.DoomBuilder.IO public override int ColormapType { get { return -1; } } public override int FlatAlignmentType { get { return -1; } } public override int AxisType { get { return -1; } } + public override int AxisTransferType { get { return -1; } } public override int AxisTransferLineType { get { return -1; } } #endregion diff --git a/Source/Core/Map/Thing.cs b/Source/Core/Map/Thing.cs index 7364453..19a2498 100644 --- a/Source/Core/Map/Thing.cs +++ b/Source/Core/Map/Thing.cs @@ -132,6 +132,11 @@ namespace CodeImp.DoomBuilder.Map public bool Unflippable { get { return General.Map.FormatInterface.UnflippableTypes.Contains(Type); } } public bool IsFloatable { get { return General.Map.FormatInterface.FloatableTypes.Contains(Type); } } public bool CenterHitbox { get { return General.Map.FormatInterface.CenterHitboxTypes.Contains(Type); } } + public bool IsNiGHTSPathItem { get { return General.Map.FormatInterface.AxisType == Type + || General.Map.FormatInterface.AxisTransferType == Type + || General.Map.FormatInterface.AxisTransferLineType == Type; + } + } #endregion #region ================== Constructor / Disposer @@ -393,22 +398,6 @@ namespace CodeImp.DoomBuilder.Map if(selecteditem.List != null) selecteditem.List.Remove(selecteditem); selecteditem = null; } - - public int GetFlagsValue() - { - int flags = 0; - foreach (KeyValuePair f in Flags) - { - int fnum; - if (f.Value && int.TryParse(f.Key, out fnum)) flags |= fnum; - } - - //SRB2 stores Z position in upper 12 bits of flags. Add Z position to flags. - if (General.Map.SRB2) flags |= (UInt16)Position.z << 4; - - return flags; - - } #endregion #region ================== Changes @@ -636,8 +625,37 @@ namespace CodeImp.DoomBuilder.Map return new Dictionary(flags); } - // This clears all flags - public void ClearFlags() + public int GetFlagsValue() + { + int flags = 0; + foreach (KeyValuePair f in Flags) + { + int fnum; + if (f.Value && int.TryParse(f.Key, out fnum)) flags |= fnum; + } + + //SRB2 stores Z position in upper 12 bits of flags. Add Z position to flags. + if (General.Map.SRB2) flags |= (UInt16)Position.z << 4; + + return flags; + } + + public void SetFlagsValue(int value) + { + Dictionary newflags = new Dictionary(flags); + foreach (KeyValuePair f in flags) + { + int fnum; + if (int.TryParse(f.Key, out fnum)) newflags[f.Key] = ((value & fnum) == fnum); + } + flags = newflags; + + //SRB2 stores Z position in upper 12 bits of flags. Get Z position to flags. + if (General.Map.SRB2) pos.z = value >> 4; + } + + // This clears all flags + public void ClearFlags() { BeforePropsChange(); diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs index c8f6aa7..454b089 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs @@ -421,15 +421,35 @@ namespace CodeImp.DoomBuilder.BuilderModes } else if (General.Map.SRB2 && Thing.IsSlopeVertex) { - if (Thing.Sector != null) //mxd + if (Thing.Sector != null) { // This is a special thing that needs special positioning SectorData sd = mode.GetSectorData(Thing.Sector); pos.z = sd.Floor.sector.FloorHeight + Thing.Position.z - Thing.Height/2; } } + else if (Thing.IsNiGHTSPathItem) + { + //Z position is always 0. + if (Thing.Sector != null) + { + SectorData sd = mode.GetSectorData(Thing.Sector); + pos.z = sd.Floor.sector.FloorHeight; + } + else pos.z = 0; + } + else if (General.Map.SRB2 && Thing.Type == 1705) + { + //Use the flags value instead of the Z position for the Z position. SRB2 is really stupid sometimes. + pos.z = Thing.GetFlagsValue(); + if (Thing.Sector != null) + { + SectorData sd = mode.GetSectorData(Thing.Sector); + pos.z += sd.Floor.sector.FloorHeight; + } + } - else if(info.AbsoluteZ) + else if (info.AbsoluteZ) { // Absolute Z position pos.z = Thing.Position.z; @@ -808,20 +828,36 @@ namespace CodeImp.DoomBuilder.BuilderModes // Raise/lower thing public void OnChangeTargetHeight(int amount) { + if (Thing.IsNiGHTSPathItem) return; //NiGHTS path items have no height. + if(General.Map.FormatInterface.HasThingHeight) { if((General.Map.UndoRedo.NextUndo == null) || (General.Map.UndoRedo.NextUndo.TicketID != undoticket)) undoticket = mode.CreateUndo("Change thing height"); - Vector3D newPosition = Thing.Position + new Vector3D(0.0f, 0.0f, (Thing.IsFlipped ? -amount : amount)); - newPosition.z = General.Clamp(newPosition.z, General.Map.FormatInterface.MinThingHeight, General.Map.FormatInterface.MaxThingHeight); + if (General.Map.SRB2 && Thing.Type == 1705) + { + int newZ = General.Clamp(Thing.GetFlagsValue() + amount,0,0xFFFF); + Thing.SetFlagsValue(newZ); - Thing.Move(newPosition); + int actualZ = newZ >> 4; + Vector3D newPosition = new Vector3D(Thing.Position.x, Thing.Position.y, actualZ); + Thing.Move(newPosition); - mode.SetActionResult("Changed thing height to " + Thing.Position.z + "."); - - // Update what must be updated - ThingData td = mode.GetThingData(this.Thing); + mode.SetActionResult("Changed thing height to " + newZ + "."); + } + else + { + Vector3D newPosition = Thing.Position + new Vector3D(0.0f, 0.0f, (Thing.IsFlipped ? -amount : amount)); + newPosition.z = General.Clamp(newPosition.z, General.Map.FormatInterface.MinThingHeight, General.Map.FormatInterface.MaxThingHeight); + + Thing.Move(newPosition); + + mode.SetActionResult("Changed thing height to " + Thing.Position.z + "."); + } + + // Update what must be updated + ThingData td = mode.GetThingData(this.Thing); foreach(KeyValuePair s in td.UpdateAlso) { if(mode.VisualSectorExists(s.Key))