Skip to content

Commit

Permalink
Allow eletric poles to not be planned at all
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Jan 15, 2024
1 parent c12413a commit a892aa0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/FactorioTools/OilField/OilFieldOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public static OilFieldOptions ForSubstation
/// </summary>
public bool OverlapBeacons { get; set; } = true;

/// <summary>
/// Whether or not to add electric poles around the pumpjacks and (optionally) beacons.
/// </summary>
public bool AddElectricPoles { get; set; } = true;

/// <summary>
/// The pipe planning strategies to attempt.
/// </summary>
Expand Down
35 changes: 19 additions & 16 deletions src/FactorioTools/OilField/Planner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,31 @@ private static (Context Context, OilFieldPlanSummary Summary) Execute(

// Visualizer.Show(context.Grid, Array.Empty<DelaunatorSharp.IPoint>(), Array.Empty<DelaunatorSharp.IEdge>());

if (!addElectricPolesFirst || context.Options.AddBeacons)
if (options.AddElectricPoles)
{
poles = AddElectricPoles.Execute(context, avoid: EmptyLocationSet.Instance, allowRetries: addElectricPolesFirst);
if (poles is null)
if (!addElectricPolesFirst || context.Options.AddBeacons)
{
if (addElectricPolesFirst)
{
// Visualizer.Show(context.Grid, Array.Empty<DelaunatorSharp.IPoint>(), Array.Empty<DelaunatorSharp.IEdge>());
throw new FactorioToolsException(
"No valid placement for the electric poles could be found, after adding electric poles first. " +
"Try removing some pumpjacks or using a different electric pole.",
badInput: true);
}
else
poles = AddElectricPoles.Execute(context, avoid: EmptyLocationSet.Instance, allowRetries: addElectricPolesFirst);
if (poles is null)
{
electricPolesAvoid = GetElectricPolesAvoid(context);
return Execute(options, blueprint, electricPolesAvoid, EletricPolesMode.AddFirstAndAvoidSpecificTerminals);
if (addElectricPolesFirst)
{
// Visualizer.Show(context.Grid, Array.Empty<DelaunatorSharp.IPoint>(), Array.Empty<DelaunatorSharp.IEdge>());
throw new FactorioToolsException(
"No valid placement for the electric poles could be found, after adding electric poles first. " +
"Try removing some pumpjacks or using a different electric pole.",
badInput: true);
}
else
{
electricPolesAvoid = GetElectricPolesAvoid(context);
return Execute(options, blueprint, electricPolesAvoid, EletricPolesMode.AddFirstAndAvoidSpecificTerminals);
}
}
}
}

Validate.AllEntitiesHavePower(context);
Validate.AllEntitiesHavePower(context);
}

var missingPumpjacks = initialPumpjackCount - context.CenterToTerminals.Count;
if (missingPumpjacks > 0)
Expand Down
10 changes: 10 additions & 0 deletions src/WebApp/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@
"description": "Whether or to allow beacon effects to overlap. For Factorio mods like Space Exploration, beacon effects cannot\r\noverlap otherwise pumpjacks will break down with a beacon overload. For vanilla Factorio, this should be true.",
"default": true
},
"addElectricPoles": {
"type": "boolean",
"description": "Whether or not to add electric poles around the pumpjacks and (optionally) beacons.",
"default": true
},
"pipeStrategies": {
"type": "array",
"items": {
Expand Down Expand Up @@ -411,6 +416,7 @@
"OilFieldPlanRequestResponse": {
"required": [
"addBeacons",
"addElectricPoles",
"addFbeOffset",
"beaconEntityName",
"beaconHeight",
Expand Down Expand Up @@ -451,6 +457,10 @@
"type": "boolean",
"description": "Whether or to allow beacon effects to overlap. For Factorio mods like Space Exploration, beacon effects cannot\r\noverlap otherwise pumpjacks will break down with a beacon overload. For vanilla Factorio, this should be true."
},
"addElectricPoles": {
"type": "boolean",
"description": "Whether or not to add electric poles around the pumpjacks and (optionally) beacons."
},
"pipeStrategies": {
"type": "array",
"items": {
Expand Down
44 changes: 42 additions & 2 deletions test/FactorioTools.Test/OilField/PlannerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void AllowsPumpjackWithDefaultDirection()
/// This blueprint found a bug in the SortedBatches class.
/// </summary>
[Fact]
public void PlansPowerPoles()
public void PlansElectricPoles()
{
// Arrange
var options = OilFieldOptions.ForSubstation;
Expand All @@ -63,7 +63,47 @@ public void PlansPowerPoles()
var blueprint = ParseBlueprint.Execute(blueprintString);

// Act
Planner.Execute(options, blueprint);
var (context, _) = Planner.Execute(options, blueprint);

// Assert
Assert.NotEmpty(context.Grid.GetEntities().OfType<ElectricPoleCenter>());
Assert.NotEmpty(context.Grid.GetEntities().OfType<ElectricPoleSide>());
}

[Fact]
public void AllowsElectricPolesToNotBePlanned()
{
// Arrange
var options = OilFieldOptions.ForBigElectricPole;
options.ValidateSolution = true;
options.AddElectricPoles = false;
var blueprintString = SmallListBlueprintStrings[0];
var blueprint = ParseBlueprint.Execute(blueprintString);

// Act
var (context, _) = Planner.Execute(options, blueprint);

// Assert
Assert.Empty(context.Grid.GetEntities().OfType<ElectricPoleCenter>());
Assert.Empty(context.Grid.GetEntities().OfType<ElectricPoleSide>());
}

[Fact]
public void AllowsBeaconsToNotBePlanned()
{
// Arrange
var options = OilFieldOptions.ForBigElectricPole;
options.ValidateSolution = true;
options.AddBeacons = false;
var blueprintString = SmallListBlueprintStrings[0];
var blueprint = ParseBlueprint.Execute(blueprintString);

// Act
var (context, _) = Planner.Execute(options, blueprint);

// Assert
Assert.Empty(context.Grid.GetEntities().OfType<BeaconCenter>());
Assert.Empty(context.Grid.GetEntities().OfType<BeaconSide>());
}

[Fact]
Expand Down

0 comments on commit a892aa0

Please sign in to comment.