From 007ff3fa1b2e41753ed2aa7d69e76069653d2afc Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 21 Jul 2022 22:25:46 -0400 Subject: [PATCH] Broke signal propagation before, fixed it --- .../Builder/Props/BrambleNodeBuilder.cs | 31 +++++++++---------- NewHorizons/Handlers/PlanetCreationHandler.cs | 4 --- NewHorizons/Main.cs | 4 +-- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index d41e42c1..db15d3c4 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -1,5 +1,6 @@ using NewHorizons.Builder.Body; using NewHorizons.Components; +using NewHorizons.External.Configs; using NewHorizons.Handlers; using NewHorizons.Utility; using OWML.Common; @@ -30,14 +31,14 @@ namespace NewHorizons.Builder.Props private static string _brambleSeedPrefabPath = "DB_PioneerDimension_Body/Sector_PioneerDimension/Interactables_PioneerDimension/SeedWarp_ToPioneer (1)"; private static string _brambleNodePrefabPath = "DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster"; - public static void Init() + public static void Init(PlanetConfig[] dimensionConfigs) { _unpairedNodes.Clear(); _propagatedSignals.Clear(); namedNodes.Clear(); builtBrambleNodes.Clear(); - PropagateSignals(); + PropagateSignals(dimensionConfigs); } public static void FinishPairingNodesForDimension(string dimensionName, AstroObject dimensionAO = null) @@ -75,23 +76,21 @@ namespace NewHorizons.Builder.Props // Makes signals inside dimensions appear on the nodes as well // Runs Floyd-Warshall algorithm on dimensions and nodes. - private static void PropagateSignals() + private static void PropagateSignals(PlanetConfig[] dimensionConfigs) { - var allDimensions = PlanetCreationHandler.Bodies.Where(body => body?.Config?.Bramble?.dimension != null).Select(body => body.Config).ToList(); - // Access will be our final answer - if access[i, j], then nodes linking to dimension i should display all of dimension j's signals - var access = new bool[allDimensions.Count(), allDimensions.Count()]; + var access = new bool[dimensionConfigs.Count(), dimensionConfigs.Count()]; var dimensionNameToIndex = new Dictionary(); - for (int dimensionIndex = 0; dimensionIndex < allDimensions.Count(); dimensionIndex++) + for (int dimensionIndex = 0; dimensionIndex < dimensionConfigs.Count(); dimensionIndex++) { - dimensionNameToIndex[allDimensions[dimensionIndex].name] = dimensionIndex; + dimensionNameToIndex[dimensionConfigs[dimensionIndex].name] = dimensionIndex; } // Set up the direct links (ie, if dimension 0 contains a node that links to dimension 3, set access[0, 3] = true) - for (int dimensionIndex = 0; dimensionIndex < allDimensions.Count(); dimensionIndex++) + for (int dimensionIndex = 0; dimensionIndex < dimensionConfigs.Count(); dimensionIndex++) { - var dimension = allDimensions[dimensionIndex]; + var dimension = dimensionConfigs[dimensionIndex]; if (dimension.Bramble.nodes == null) continue; foreach (var node in dimension.Bramble.nodes) { @@ -102,27 +101,27 @@ namespace NewHorizons.Builder.Props // A node that links to dimension A should display all of dimension A's signals, so for the purposes of our function, // we need to say that dimension A links to dimension A - for (int dimensionIndex = 0; dimensionIndex < allDimensions.Count(); dimensionIndex++) + for (int dimensionIndex = 0; dimensionIndex < dimensionConfigs.Count(); dimensionIndex++) { access[dimensionIndex, dimensionIndex] = true; } // The actual Floyd-Warshall - determine whether each pair of dimensions link indirectly (eg if A->B->C, // then after this step, access[A, C] = true) - for (int k = 0; k < allDimensions.Count(); k++) - for (int i = 0; i < allDimensions.Count(); i++) - for (int j = 0; j < allDimensions.Count(); j++) + for (int k = 0; k < dimensionConfigs.Count(); k++) + for (int i = 0; i < dimensionConfigs.Count(); i++) + for (int j = 0; j < dimensionConfigs.Count(); j++) if (access[i, k] && access[k, j]) access[i, j] = true; // This dictionary lists all the signals a given node should have, depending on the dimension it links to // ie, if a node links to "dimension1", then that node should spawn all of the signals in the list propagatedSignals["dimension1"] - foreach (var dimension in allDimensions) + foreach (var dimension in dimensionConfigs) { _propagatedSignals[dimension.name] = new(); var dimensionIndex = dimensionNameToIndex[dimension.name]; - foreach (var destinationDimension in allDimensions) + foreach (var destinationDimension in dimensionConfigs) { if (destinationDimension.Props?.signals == null) continue; diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 10a62bf1..f572b75f 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -17,8 +17,6 @@ namespace NewHorizons.Handlers { public static class PlanetCreationHandler { - public static List Bodies { get; private set; } - private static List _nextPassBodies = new List(); // Stock bodies being updated @@ -34,8 +32,6 @@ namespace NewHorizons.Handlers _existingBodyDict = new(); _customBodyDict = new(); - Bodies = bodies; - // Set up stars // Need to manage this when there are multiple stars var sun = SearchUtilities.Find("Sun_Body"); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index e77ddbf7..44980880 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -273,12 +273,10 @@ namespace NewHorizons AstroObjectLocator.Init(); StreamingHandler.Init(); AudioTypeHandler.Init(); + BrambleNodeBuilder.Init(BodyDict[CurrentStarSystem].Select(x => x.Config).Where(x => x.Bramble?.dimension != null).ToArray()); PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]); - // Relies on the list of bodies from PlanetCreationHandler so it must run after - BrambleNodeBuilder.Init(); - VesselWarpHandler.LoadVessel(); SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]); LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this);