Skip to content

Commit

Permalink
Use CentersXY everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Jan 10, 2024
1 parent b4b117b commit 9f68791
Show file tree
Hide file tree
Showing 853 changed files with 13,380 additions and 13,395 deletions.
3 changes: 1 addition & 2 deletions src/FactorioTools/OilField/Models/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class Context
public required OilFieldOptions Options { get; set; }
public required Blueprint InputBlueprint { get; set; }
public required SquareGrid Grid { get; set; }
public required List<Location> CentersXY { get; set; }
public required List<Location> CentersYX { get; set; }
public required List<Location> Centers { get; set; }
public required ILocationDictionary<List<TerminalLocation>> CenterToTerminals { get; set; }
public required ILocationDictionary<Direction> CenterToOriginalDirection { get; set; }
public required ILocationDictionary<List<TerminalLocation>> LocationToTerminals { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions src/FactorioTools/OilField/Steps/AddPipes.1.FBE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static (ILocationSet Pipes, PipeStrategy FinalStrategy) ExecuteWithFbe(Co
private static (List<TerminalLocation> Terminals, ILocationSet Pipes, PipeStrategy FinalStrategy) DelaunayTriangulation(Context context, Location middle, PipeStrategy strategy)
{
// GENERATE LINES
var lines = PointsToLines(context.CentersXY, sort: false)
var lines = PointsToLines(context.Centers, sort: false)
.Select(line =>
{
var connections = context.CenterToTerminals[line.A]
Expand Down Expand Up @@ -107,7 +107,7 @@ private static (List<TerminalLocation> Terminals, ILocationSet Pipes, PipeStrate
// this will only happen when only a few pumpjacks need to be connected
if (groups.Count == 0)
{
var connection = PointsToLines(context.CentersXY, sort: false)
var connection = PointsToLines(context.Centers, sort: false)
.Select(line =>
{
return context.CenterToTerminals[line.A]
Expand Down Expand Up @@ -201,7 +201,7 @@ private static (List<TerminalLocation> Terminals, ILocationSet Pipes, PipeStrate
}

var leftoverPumpjacks = context
.CentersXY
.Centers
.Except(addedPumpjacks.Select(x => x.Center), context)
.OrderBy(l => l.GetManhattanDistance(true ? middle : context.Grid.Middle));

Expand Down
10 changes: 5 additions & 5 deletions src/FactorioTools/OilField/Steps/AddPipes.2.ConnectedCenters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static partial class AddPipes

private static ILocationDictionary<ILocationSet> GetConnectedPumpjacks(Context context, PipeStrategy strategy)
{
var centers = context.CentersXY;
var centers = context.Centers;

if (centers.Count == 2)
{
Expand Down Expand Up @@ -407,7 +407,7 @@ private static List<Trunk> FindTrunks(Context context, ILocationDictionary<ILoca
private static PumpjackGroup ConnectTwoClosestPumpjacks(Context context, ILocationDictionary<ILocationSet> centerToConnectedCenters, ILocationSet allIncludedCenters)
{
var bestConnection = context
.CentersYX
.Centers
.Select(center =>
{
return context
Expand Down Expand Up @@ -495,17 +495,17 @@ private static ILocationSet GetChildCenters(
private static List<Trunk> GetTrunkCandidates(Context context, ILocationDictionary<ILocationSet> centerToConnectedCenters)
{
var centerToMaxX = context
.CentersXY
.Centers
.ToDictionary(context, c => c, c => centerToConnectedCenters[c].EnumerateItems().Max(c => context.CenterToTerminals[c].Max(t => t.Terminal.X)));
var centerToMaxY = context
.CentersXY
.Centers
.ToDictionary(context, c => c, c => centerToConnectedCenters[c].EnumerateItems().Max(c => context.CenterToTerminals[c].Max(t => t.Terminal.Y)));

// Find paths that connect the most terminals of neighboring pumpjacks.
var trunkCandidates = new List<Trunk>();
foreach (var translation in Translations)
{
foreach (var startingCenter in context.CentersYX)
foreach (var startingCenter in context.Centers)
{
foreach (var terminal in context.CenterToTerminals[startingCenter])
{
Expand Down
2 changes: 1 addition & 1 deletion src/FactorioTools/OilField/Steps/CleanBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static Blueprint Execute(Blueprint blueprint)

var entities = new List<Entity>();

foreach (var center in context.CentersYX)
foreach (var center in context.Centers)
{
// Pumpjacks are given a direction that doesn't overlap with another pumpjack, preferring the direction
// starting at the top then proceeding clockwise.
Expand Down
24 changes: 5 additions & 19 deletions src/FactorioTools/OilField/Steps/InitializeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,9 @@ private static Context Execute(OilFieldOptions options, Blueprint blueprint, int

var grid = InitializeGrid(centerAndOriginalDirections, marginX, marginY);

var centersXY = new List<Location>(centerAndOriginalDirections.Count);
PopulateCenters(centerAndOriginalDirections, centersXY);
centersXY.Sort((a, b) =>
{
var c = a.X.CompareTo(b.X);
if (c != 0)
{
return c;
}

return a.Y.CompareTo(b.Y);
});

var centersYX = new List<Location>(centerAndOriginalDirections.Count);
PopulateCenters(centerAndOriginalDirections, centersYX);
centersYX.Sort((a, b) =>
var centers = new List<Location>(centerAndOriginalDirections.Count);
PopulateCenters(centerAndOriginalDirections, centers);
centers.Sort((a, b) =>
{
var c = a.Y.CompareTo(b.Y);
if (c != 0)
Expand All @@ -92,16 +79,15 @@ private static Context Execute(OilFieldOptions options, Blueprint blueprint, int
#endif

PopulateCenterToOriginalDirection(centerAndOriginalDirections, centerToOriginalDirection);
PopulateCenterToTerminals(centerToTerminals, grid, centersXY);
PopulateCenterToTerminals(centerToTerminals, grid, centers);
PopulateLocationToTerminals(locationToTerminals, centerToTerminals);

return new Context
{
Options = options,
InputBlueprint = blueprint,
Grid = grid,
CentersXY = centersXY,
CentersYX = centersYX,
Centers = centers,
CenterToTerminals = centerToTerminals,
CenterToOriginalDirection = centerToOriginalDirection,
LocationToTerminals = locationToTerminals,
Expand Down
2 changes: 1 addition & 1 deletion src/FactorioTools/OilField/Steps/PlanBeacons.1.FBE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private static List<Location[]> GetPossibleBeaconAreas(Context context, ILocatio

var area = new Location[context.Options.BeaconWidth * context.Options.BeaconHeight];

foreach (var center in context.CentersXY)
foreach (var center in context.Centers)
{
var supplyMinX = Math.Max(gridMinX, center.X - supplyLeft);
var supplyMinY = Math.Max(gridMinY, center.Y - supplyUp);
Expand Down
2 changes: 1 addition & 1 deletion src/FactorioTools/OilField/Steps/PlanBeacons.2.Snug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static partial class PlanBeacons
private static (List<Location> Beacons, int Effects) AddBeaconsSnug(Context context)
{
var poweredEntities = new List<ProviderRecipient>(context.CenterToTerminals.Count);
foreach (var center in context.CentersXY)
foreach (var center in context.Centers)
{
poweredEntities.Add(new ProviderRecipient(center, PumpjackWidth, PumpjackHeight));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ S FBE* -> FBE* (effects: 169, beacons: 127, pipes: 64)
CC-DT-MST -> FBE (effects: 158, beacons: 120, pipes: 69)
CC-DT-MST -> FBE* (effects: 156, beacons: 118, pipes: 69)
CC-DT-MST -> snug (effects: 154, beacons: 120, pipes: 69)
CC-DT-MST -> optimize -> FBE (effects: 163, beacons: 122, pipes: 65)
CC-DT-MST -> optimize -> FBE* (effects: 163, beacons: 122, pipes: 65)
CC-DT-MST -> optimize -> snug (effects: 159, beacons: 120, pipes: 65)
CC-DT-MST -> optimize -> FBE (effects: 161, beacons: 121, pipes: 72)
CC-DT-MST -> optimize -> FBE* (effects: 160, beacons: 120, pipes: 72)
CC-DT-MST -> optimize -> snug (effects: 155, beacons: 118, pipes: 72)
CC-FLUTE -> FBE (effects: 161, beacons: 121, pipes: 69)
CC-FLUTE -> FBE* (effects: 161, beacons: 121, pipes: 69)
CC-FLUTE -> snug (effects: 158, beacons: 120, pipes: 69)
Expand Down
Loading

0 comments on commit 9f68791

Please sign in to comment.