diff --git a/Installer/Changes.txt b/Installer/Changes.txt index 837bf0913..999e7ae29 100644 --- a/Installer/Changes.txt +++ b/Installer/Changes.txt @@ -7,6 +7,7 @@ Tomb Editor: * Added Flyby Timeline control to edit and preview flyby sequences. * Added "Preview flyby sequence" and "Preview camera" context menus for cameras. * Added On Pickup, On Vehicle Enter and On Vehicle Exit global events in the global event set editor. + * Added support for mine cart floor data in TRX. WadTool: * Added missing TR2 henchman death sound (ID 838) and appropriate TR2 -> TEN conversion. diff --git a/TombEditor/Command.cs b/TombEditor/Command.cs index 05f67389a..c4e0df22d 100644 --- a/TombEditor/Command.cs +++ b/TombEditor/Command.cs @@ -2076,20 +2076,20 @@ static CommandHandler() EditorActions.SetDiagonalWall(args.Editor.SelectedRoom, args.Editor.SelectedSectors.Area); }); - AddCommand("SetBeetleCheckpoint", "Set beetle checkpoint / minecart right (TR3)", CommandType.Sectors, delegate (CommandArgs args) + AddCommand("SetBeetleCheckpoint", "Set beetle checkpoint / minecart right (TR3/TRX)", CommandType.Sectors, delegate (CommandArgs args) { if (!EditorActions.CheckForRoomAndSectorSelection(args.Window)) return; - if (!EditorActions.VersionCheck(args.Editor.Level.Settings.GameVersion.Native() >= TRVersion.Game.TR3, "This flag")) + if (!EditorActions.VersionCheck(args.Editor.Level.Settings.GameVersion >= TRVersion.Game.TR3, "This flag")) return; EditorActions.ToggleSectorFlag(args.Editor.SelectedRoom, args.Editor.SelectedSectors.Area, SectorFlags.Beetle); }); - AddCommand("SetTriggerTriggerer", "Set trigger triggerer / minecart left (TR3)", CommandType.Sectors, delegate (CommandArgs args) + AddCommand("SetTriggerTriggerer", "Set trigger triggerer / minecart left (TR3/TRX)", CommandType.Sectors, delegate (CommandArgs args) { if (!EditorActions.CheckForRoomAndSectorSelection(args.Window)) return; - if (!EditorActions.VersionCheck(args.Editor.Level.Settings.GameVersion.Native() >= TRVersion.Game.TR3, "This flag")) + if (!EditorActions.VersionCheck(args.Editor.Level.Settings.GameVersion >= TRVersion.Game.TR3, "This flag")) return; EditorActions.ToggleSectorFlag(args.Editor.SelectedRoom, args.Editor.SelectedSectors.Area, SectorFlags.TriggerTriggerer); }); diff --git a/TombEditor/ToolWindows/SectorOptions.cs b/TombEditor/ToolWindows/SectorOptions.cs index 0682cc1d7..79788cebc 100644 --- a/TombEditor/ToolWindows/SectorOptions.cs +++ b/TombEditor/ToolWindows/SectorOptions.cs @@ -74,15 +74,15 @@ obj is Editor.GameVersionChangedEvent || obj is Editor.LevelChangedEvent) { bool climbingSupported = _editor.Level.Settings.GameVersion.SupportsClimbing(); - bool isTR345 = _editor.Level.Settings.GameVersion.Native() >= TRVersion.Game.TR3; + bool beetleTrigMineSupported = _editor.Level.Settings.GameVersion >= TRVersion.Game.TR3; butClimbNegativeX.Enabled = climbingSupported; butClimbNegativeZ.Enabled = climbingSupported; butClimbPositiveX.Enabled = climbingSupported; butClimbPositiveZ.Enabled = climbingSupported; butMonkey.Enabled = _editor.Level.Settings.GameVersion.SupportsMonkeySwing(); - butFlagBeetle.Enabled = isTR345; - butFlagTriggerTriggerer.Enabled = isTR345; + butFlagBeetle.Enabled = beetleTrigMineSupported; + butFlagTriggerTriggerer.Enabled = beetleTrigMineSupported; if (_editor.Level.Settings.GameVersion.Native() >= TRVersion.Game.TR4) { diff --git a/TombLib/TombLib/LevelData/Compilers/Trx.cs b/TombLib/TombLib/LevelData/Compilers/Trx.cs index 11a367ee3..84234809f 100644 --- a/TombLib/TombLib/LevelData/Compilers/Trx.cs +++ b/TombLib/TombLib/LevelData/Compilers/Trx.cs @@ -56,6 +56,10 @@ private IEnumerable GenerateTrxSectorEdits() { yield return climbEdit; } + if (GetMineCartEntry(teRoom, x, z) is TrxSectorEdit mineCartEdit) + { + yield return mineCartEdit; + } if (GetTriangulation(teRoom, x, z) is TrxSectorEdit triangulationEdit) { yield return triangulationEdit; @@ -118,6 +122,33 @@ private TrxClimbEntry GetClimbEntry(Room teRoom, ushort x, ushort z) }; } + private TrxMineCartEntry GetMineCartEntry(Room teRoom, ushort x, ushort z) + { + var teSector = teRoom.Sectors[x, z]; + var left = (teSector.Flags & SectorFlags.TriggerTriggerer) != 0; + var right = (teSector.Flags & SectorFlags.Beetle) != 0; + + var type = (left, right) switch + { + (true, true) => TrxMineCartType.Stop, + (true, false) => TrxMineCartType.Left, + (false, true) => TrxMineCartType.Right, + _ => TrxMineCartType.None, + }; + if (type == TrxMineCartType.None) + { + return null; + } + + return new() + { + RoomIndex = (short)_roomRemapping[teRoom], + X = x, + Z = z, + Type = type, + }; + } + private TrxTriangulationEntry GetTriangulation(Room teRoom, ushort x, ushort z) { var teSector = teRoom.Sectors[x, z]; diff --git a/TombLib/TombLib/LevelData/Compilers/Util/TrxInjector.cs b/TombLib/TombLib/LevelData/Compilers/Util/TrxInjector.cs index 7a27a0eb2..be4049726 100644 --- a/TombLib/TombLib/LevelData/Compilers/Util/TrxInjector.cs +++ b/TombLib/TombLib/LevelData/Compilers/Util/TrxInjector.cs @@ -209,6 +209,26 @@ protected override void SerializeImpl(BinaryWriterEx writer) } } +public enum TrxMineCartType +{ + None, + Left, + Right, + Stop, +} + +public class TrxMineCartEntry : TrxSectorEdit +{ + public override int Command => 14; + + public TrxMineCartType Type { get; set; } + + protected override void SerializeImpl(BinaryWriterEx writer) + { + writer.Write((int)Type); + } +} + public class TrxTriangulationEntry : TrxSectorEdit { public override int Command => 13;