From 4f4a0bdf58698c3be4bbf8af6fe4e29c998c6dbb Mon Sep 17 00:00:00 2001 From: biwa Date: Tue, 16 Apr 2019 18:05:21 +0200 Subject: [PATCH] - Test map from current mouse position now works properly in Hexen/UDMF maps with multiple player starts. Also works in maps without a valid player start now. Fixes #263. --- Source/Core/Editing/ClassicMode.cs | 60 +++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/Source/Core/Editing/ClassicMode.cs b/Source/Core/Editing/ClassicMode.cs index 0b3a53d..dd0a751 100644 --- a/Source/Core/Editing/ClassicMode.cs +++ b/Source/Core/Editing/ClassicMode.cs @@ -82,6 +82,7 @@ namespace CodeImp.DoomBuilder.Editing //mxd. used in "Play From Here" Action private Thing playerStart; private Vector3D playerStartPosition; + private bool playerStartIsTempThing; #endregion @@ -696,12 +697,28 @@ namespace CodeImp.DoomBuilder.Editing { if(testFromCurrentPosition) { - if(!mouseinside) + if (!mouseinside) { General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: mouse is outside editing vindow!"); return false; } - + + //now check if cursor is located inside a sector + Sector s = General.Map.Map.GetSectorByCoordinates(mousemappos); + + if (s == null) + { + General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: mouse cursor must be inside a sector!"); + return false; + } + + //41 = player's height in Doom. Is that so in all other games as well? + if (s.CeilHeight - s.FloorHeight < 41) + { + General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: sector is too low!"); + return false; + } + //find Single Player Start. Should be type 1 in all games Thing start = null; @@ -709,6 +726,11 @@ namespace CodeImp.DoomBuilder.Editing { if(t.Type == 1) { + // biwa. In Hexen format and UDMF a map can have multiple valid player starts because of + // hubs. The player by default stats at the player start withe arg0 set to 0 + if ((General.Map.HEXEN || General.Map.UDMF) && t.Args[0] != 0) + continue; + //store thing and position if(start == null) { @@ -724,24 +746,22 @@ namespace CodeImp.DoomBuilder.Editing if(start == null) { - General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: no Player 1 start found!"); - return false; - } + // biwa. If there's no existing valid player start create one + playerStartIsTempThing = true; + start = General.Map.Map.CreateThing(); - //now check if cursor is located inside a sector - Sector s = General.Map.Map.GetSectorByCoordinates(mousemappos); - - if(s == null) + if (start != null) + { + General.Settings.ApplyDefaultThingSettings(start); + start.Type = 1; + } else + { + General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: couldn't create player start!"); + return false; + } + } else { - General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: mouse cursor must be inside a sector!"); - return false; - } - - //41 = player's height in Doom. Is that so in all other games as well? - if(s.CeilHeight - s.FloorHeight < 41) - { - General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: sector is too low!"); - return false; + playerStartIsTempThing = false; } //store initial position @@ -761,6 +781,10 @@ namespace CodeImp.DoomBuilder.Editing { //restore position playerStart.Move(playerStartPosition); + + if (playerStartIsTempThing) // biwa + General.Map.Map.RemoveThing(playerStart.Index); + playerStart = null; } }