Skip to content

Commit

Permalink
Allow more turns if needed for FBE
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Dec 9, 2023
1 parent 55e2182 commit facd11d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/FactorioTools/OilField/Steps/AddPipeEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static void Execute(
SharedInstances sharedInstances,
IReadOnlyDictionary<Location, List<TerminalLocation>> centerToTerminals,
HashSet<Location> pipes,
Dictionary<Location, Direction>? undergroundPipes)
Dictionary<Location, Direction>? undergroundPipes = null,
bool allowMultipleTerminals = false)
{
#if USE_SHARED_INSTANCES
var addedPipes = sharedInstances.LocationSetA;
Expand All @@ -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.");
}
Expand Down
41 changes: 27 additions & 14 deletions src/FactorioTools/OilField/Steps/AddPipes.1.FBE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,37 @@ private static (List<TerminalLocation> Terminals, HashSet<Location> Pipes) Delau
.Select(t => new Group(new List<TerminalLocation> { t }, new List<List<Location>> { new List<Location> { 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<DelaunatorSharp.IPoint>(), Array.Empty<DelaunatorSharp.IEdge>());
*/
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<IPoint>(), Array.Empty<IEdge>());
*/

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();
Expand Down
3 changes: 3 additions & 0 deletions test/FactorioTools.Test/OilField/blueprints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=

0 comments on commit facd11d

Please sign in to comment.