diff --git a/src/FactorioTools/OilField/Steps/AddPipeEntities.cs b/src/FactorioTools/OilField/Steps/AddPipeEntities.cs index 803e827f..a31fa31d 100644 --- a/src/FactorioTools/OilField/Steps/AddPipeEntities.cs +++ b/src/FactorioTools/OilField/Steps/AddPipeEntities.cs @@ -20,7 +20,8 @@ public static void Execute( SharedInstances sharedInstances, IReadOnlyDictionary> centerToTerminals, HashSet pipes, - Dictionary? undergroundPipes) + Dictionary? undergroundPipes = null, + bool allowMultipleTerminals = false) { #if USE_SHARED_INSTANCES var addedPipes = sharedInstances.LocationSetA; @@ -42,7 +43,7 @@ public static void Execute( foreach (var terminals in centerToTerminals.Values) { - if (terminals.Count != 1) + if (terminals.Count != 1 && !allowMultipleTerminals) { throw new FactorioToolsException("Every pumpjack should have a single terminal selected."); } diff --git a/src/FactorioTools/OilField/Steps/AddPipes.1.FBE.cs b/src/FactorioTools/OilField/Steps/AddPipes.1.FBE.cs index 4dab6f02..6fd31551 100644 --- a/src/FactorioTools/OilField/Steps/AddPipes.1.FBE.cs +++ b/src/FactorioTools/OilField/Steps/AddPipes.1.FBE.cs @@ -214,24 +214,37 @@ private static (List Terminals, HashSet Pipes) Delau .Select(t => new Group(new List { t }, new List> { new List { t.Terminal } })) .ToList(); - var connection = GetPathBetweenGroups( - context, - terminalGroups, - finalGroup); - - if (connection is null) + var maxTurns = 2; + while (true) { - /* - var clone = new PipeGrid(context.Grid); - AddPipeEntities.Execute(clone, context.CenterToTerminals, finalGroup.Paths.SelectMany(l => l).ToHashSet()); - Visualizer.Show(clone, Array.Empty(), Array.Empty()); - */ + var connection = GetPathBetweenGroups( + context, + terminalGroups, + finalGroup, + maxTurns); + + if (connection is null) + { + if (maxTurns > 4) + { + /* + var clone = new PipeGrid(context.Grid); + AddPipeEntities.Execute(clone, context.SharedInstances, context.CenterToTerminals, finalGroup.Paths.SelectMany(l => l).ToHashSet(), undergroundPipes: null, allowMultipleTerminals: true); + Visualizer.Show(clone, Array.Empty(), Array.Empty()); + */ + + throw new FactorioToolsException("There should be at least one connection between a leftover pumpjack and the final group. Max turns: " + maxTurns); + } + + maxTurns++; + continue; + } - throw new FactorioToolsException("There should be at least one connection between a leftover pumpjack and the final group."); + finalGroup.Add(connection.FirstGroup.Entities.Single()); + finalGroup.Paths.Add(connection.Lines[0]); + break; } - finalGroup.Add(connection.FirstGroup.Entities.Single()); - finalGroup.Paths.Add(connection.Lines[0]); } var terminals = finalGroup.Entities.ToList(); diff --git a/test/FactorioTools.Test/OilField/blueprints.txt b/test/FactorioTools.Test/OilField/blueprints.txt index 5e2c9297..bb1fd9dc 100644 --- a/test/FactorioTools.Test/OilField/blueprints.txt +++ b/test/FactorioTools.Test/OilField/blueprints.txt @@ -81,3 +81,6 @@ # 59: produces a trunk with no neighbors, which caused a LINQ exception 0eJyM0MEKwjAMBuB3+c896AZO+ioiMrcg0TUrbSeO0Xe33TyICu5Ukvz9SjPh3A1kHUuAnsBNLx76MMHzReou96Q2BA07GHutmxsUwmhzhwMZRAWWlh7Q23hUIAkcmBZjLsaTDOZMLgXUD8v2Pl3oJb+UkZ3CmI4yuS07apbZJqovrljDVQtX/efKNVwKJa7Yf3Lp5/M29Ns6Fe7k/CsQnwAAAP//AwCxtHgS + +# 60: caused FBE planner bug, mitigated by allowing more turns, bug: https://github.com/teoxoy/factorio-blueprint-editor/issues/253 +0eJyM1ctuhCAUBuB3OWsWAt5fpWkmjkMa2hGNl6bG+O4VzyzaGRL+pYgfB+GHja73xQyjdTPVG9m2dxPVbxtN9sM1d9/mms5QTcPSDZ9N+0WC5nXwLXY2He2CrLuZH6rl/i7IuNnO1rBxPqwXt3RXMx4dRMAa+un4oHd+pAPRStB6dNWHe7OjafldsosXTgGczJnL45wGOFUwV8a5FOFS5qo4lyGTrU5OJXEuR5aCq1MyzhXIZHlllfrPqQBXIlwV5ELVVci/K5nT8epkgngZe1m8PCnxrQJ5SDBUwh4QDIkkQ0v2CsBDouEH9V4JrAeSDfXwgKj5MyPulbhX4PtFA2HzWxWdr36KRxrykHwoPkifvdB6+K2FeulLfI875LxX6j8Xk6BvM06PDvsvAAAA//8DANANMhY=