diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index cc03e52f..edfdb23e 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -47,12 +47,12 @@ namespace NewHorizons.Builder.Props { Logger.LogWarning($"Pairing missed for {dimensionName}"); if (!_unpairedNodes.ContainsKey(dimensionName)) return; - + Logger.LogWarning("proceeding"); foreach (var nodeWarpController in _unpairedNodes[dimensionName]) { Logger.LogWarning($"Pairing node {nodeWarpController.gameObject.name} links to {dimensionName}"); - PairEntrance(nodeWarpController, dimensionName, dimensionAO); + PairEntrance(nodeWarpController, dimensionName, dimensionAO); } _unpairedNodes.Remove(dimensionName); @@ -61,7 +61,7 @@ namespace NewHorizons.Builder.Props private static void RecordUnpairedNode(InnerFogWarpVolume warpVolume, string linksTo) { if (!_unpairedNodes.ContainsKey(linksTo)) _unpairedNodes[linksTo] = new(); - + Logger.LogWarning($"Recording node {warpVolume.gameObject.name} links to {linksTo}"); _unpairedNodes[linksTo].Add(warpVolume); @@ -81,7 +81,7 @@ namespace NewHorizons.Builder.Props // The purpose of this function is to determine which signals any given node should play, based on which dimension it links to // you know how the main dark bramble node, the one that forms the core of the planet, plays Feldspar's harmonica signal, even though Feldspar isn't in the dimension that the node links directly to? // that's what this function is for. it would determine that the main node should play Feldspar's signal - + // New Strategy (thanks Damian): // 1) Run Floyd-Warshall on the dimensions (where each dimension is a vertex and each node is an edge) // 2) For each dimension A, if it's possible to reach dimension B, add dimension B's signals to the list propogatedSignals[A] @@ -97,18 +97,18 @@ namespace NewHorizons.Builder.Props var dimensionNameToIndex = new Dictionary(); for (int dimensionIndex = 0; dimensionIndex < allDimensions.Count(); dimensionIndex++) dimensionNameToIndex[allDimensions[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 < allDimensions.Count(); dimensionIndex++) { var dimension = allDimensions[dimensionIndex]; if (dimension.Bramble.nodes == null) continue; foreach (var node in dimension.Bramble.nodes) { - var destinationDimensionIndex = dimensionNameToIndex[node.linksTo]; + var destinationDimensionIndex = dimensionNameToIndex[node.linksTo]; access[dimensionIndex, destinationDimensionIndex] = true; } - } + } // 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++) access[dimensionIndex, dimensionIndex] = true; @@ -117,7 +117,7 @@ namespace NewHorizons.Builder.Props for (int k = 0; k < allDimensions.Count(); k++) for (int i = 0; i < allDimensions.Count(); i++) for (int j = 0; j < allDimensions.Count(); j++) - if (access[i, k] && access[k, j]) + if (access[i, k] && access[k, j]) access[i, j] = true; // @@ -131,7 +131,7 @@ namespace NewHorizons.Builder.Props { _propogatedSignals[dimension.name] = new(); var dimensionIndex = dimensionNameToIndex[dimension.name]; - + foreach (var destinationDimension in allDimensions) { if (destinationDimension.Signal?.signals == null) continue; @@ -146,7 +146,7 @@ namespace NewHorizons.Builder.Props } private static bool PairEntrance(InnerFogWarpVolume nodeWarp, string destinationName, AstroObject dimensionAO = null) - { + { Logger.LogWarning($"Pairing node {nodeWarp.gameObject.name} to {destinationName}"); var destinationAO = dimensionAO ?? AstroObjectLocator.GetAstroObject(destinationName); // find child "Sector/OuterWarp" @@ -157,7 +157,7 @@ namespace NewHorizons.Builder.Props // link the node's warp volume to the destination's var destination = GetOuterFogWarpVolumeFromAstroObject(destinationAO.gameObject); if (destination == null) return false; - + Logger.LogWarning($"Proceeding with pairing node {nodeWarp.gameObject.name} to {destinationName}. Path to outer fog warp volume: {destination.transform.GetPath()}"); nodeWarp._linkedOuterWarpVolume = destination; @@ -175,7 +175,7 @@ namespace NewHorizons.Builder.Props public static void Make(GameObject go, Sector sector, BrambleNodeInfo[] configs, IModBehaviour mod) { - foreach(var config in configs) + foreach (var config in configs) { Make(go, sector, config, mod); } @@ -183,49 +183,43 @@ namespace NewHorizons.Builder.Props public static GameObject Make(GameObject go, Sector sector, BrambleNodeInfo config, IModBehaviour mod) { - // - // spawn the bramble node - // - + // Spawn the bramble node var brambleSeedPrefabPath = "DB_PioneerDimension_Body/Sector_PioneerDimension/Interactables_PioneerDimension/SeedWarp_ToPioneer (1)"; var brambleNodePrefabPath = "DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster"; - + var path = config.isSeed ? brambleSeedPrefabPath : brambleNodePrefabPath; - var brambleNode = DetailBuilder.MakeDetail(go, sector, path, config.position, config.rotation, 1, false, leaveInactive:true); - brambleNode.name = "Bramble Node to " + config.linksTo; + var brambleNode = SearchUtilities.Find(path).InstantiateInactive(); + brambleNode.transform.parent = sector.transform; + brambleNode.transform.position = go.transform.TransformPoint(config.position); + brambleNode.transform.rotation = go.transform.TransformRotation(Quaternion.Euler(config.rotation)); + brambleNode.name = "Bramble Node to " + config.linksTo; var warpController = brambleNode.GetComponent(); - // this node comes with Feldspar's signal, we don't want that though + // This node comes with Feldspar's signal, we don't want that though GameObject.Destroy(brambleNode.FindChild("Signal_Harmonica")); - - // // Fix some components - // - var fogLight = brambleNode.GetComponent(); fogLight._parentBody = go.GetComponent(); fogLight._sector = sector; fogLight._linkedFogLights.Clear(); fogLight._linkedLightData.Clear(); fogLight._linkedSector = null; - + sector.RegisterFogLight(fogLight); - // // Set the scale - // brambleNode.transform.localScale = Vector3.one * config.scale; warpController._warpRadius *= config.scale; warpController._exitRadius *= config.scale; - - // seed fog works differently, so it doesn't need to be fixed (it's also located on a different child path, so the below FindChild calls wouldn't work) + + // Seed fog works differently, so it doesn't need to be fixed (it's also located on a different child path, so the below FindChild calls wouldn't work) if (!config.isSeed) { var fog = brambleNode.FindChild("Effects").FindChild("InnerWarpFogSphere"); var fogMaterial = fog.GetComponent().sharedMaterial; fog.transform.localScale /= config.scale; - fogMaterial.SetFloat("_Radius", fogMaterial.GetFloat("_Radius") * config.scale); + fogMaterial.SetFloat("_Radius", fogMaterial.GetFloat("_Radius") * config.scale); fogMaterial.SetFloat("_Density", fogMaterial.GetFloat("_Density") / config.scale); } @@ -237,45 +231,32 @@ namespace NewHorizons.Builder.Props // found under FogWarpDetector.FixedUpdate() // FogWarpVolume fogWarpVolume = _warpVolumes[i]; - // float num2 = Mathf.Abs(fogWarpVolume.CheckWarpProximity(this)); - // float b = Mathf.Clamp01(1f - Mathf.Abs(num2) / fogWarpVolume.GetFogThickness()); - // _targetFogFraction = Mathf.Max(_targetFogFraction, b); + // float num2 = Mathf.Abs(fogWarpVolume.CheckWarpProximity(this)); + // float b = Mathf.Clamp01(1f - Mathf.Abs(num2) / fogWarpVolume.GetFogThickness()); + // _targetFogFraction = Mathf.Max(_targetFogFraction, b); // this means that either CheckWarpProximity() or GetFogThickness() is incorrect for the InnerWarpFogSpheres. // most likely it's CheckWarpProximity() - - // - // change the colors - // - + // Change the colors if (config.isSeed) SetSeedColors(brambleNode, config.fogTint?.ToColor(), config.lightTint?.ToColor()); - else SetNodeColors(brambleNode, config.fogTint?.ToColor(), config.lightTint?.ToColor()); - - // - // set up warps - // + else SetNodeColors(brambleNode, config.fogTint?.ToColor(), config.lightTint?.ToColor()); + // Set up warps warpController._sector = sector; warpController._attachedBody = go.GetComponent(); // I don't think this is necessary, it seems to be set correctly on its own warpController._containerWarpVolume = GetOuterFogWarpVolumeFromAstroObject(go); // the OuterFogWarpVolume of the dimension this node is inside of (null if this node is not inside of a bramble dimension (eg it's sitting on a planet or something)) var success = PairEntrance(warpController, config.linksTo); if (!success) RecordUnpairedNode(warpController, config.linksTo); - warpController.Awake(); // I can't spawn this game object disabled, but Awake needs to run after _sector is set. That means I need to call Awake myself - - // // Cleanup for dimension exits - // if (config.name != null) { NamedNodes[config.name] = warpController; BrambleDimensionBuilder.FinishPairingDimensionsForExitNode(config.name); } - // // Make signals - // if (_propogatedSignals == null) PropogateSignals(); foreach (var signalConfig in _propogatedSignals[config.linksTo]) { @@ -293,25 +274,25 @@ namespace NewHorizons.Builder.Props public static void SetNodeColors(GameObject brambleNode, Color? fogTint, Color? lightTint) { - if (fogTint != null) - { + if (fogTint != null) + { var fogRenderer = brambleNode.GetComponent(); - + fogRenderer._fogColor = fogTint.Value; fogRenderer._useFarFogColor = false; var fogBackdrop = brambleNode.FindChild("Terrain_DB_BrambleSphere_Inner_v2")?.FindChild("fogbackdrop_v2"); if (fogBackdrop != null) fogBackdrop.GetComponent().sharedMaterial.color = (Color)fogTint; - } + } if (lightTint != null) { var lightShafts = brambleNode.FindChild("Effects/DB_BrambleLightShafts"); - + var lightShaft1 = lightShafts.FindChild("BrambleLightShaft1"); var mat = lightShaft1.GetComponent().material; mat.color = lightTint.Value; - + for (int i = 1; i <= 6; i++) { var lightShaft = lightShafts.FindChild($"BrambleLightShaft{i}"); @@ -322,24 +303,24 @@ namespace NewHorizons.Builder.Props public static void SetSeedColors(GameObject brambleSeed, Color? fogTint, Color? lightTint) { - if (fogTint != null) - { + if (fogTint != null) + { var fogRenderer = brambleSeed.FindChild("VolumetricFogSphere (2)"); - + var fogMeshRenderer = fogRenderer.GetComponent(); var mat = fogMeshRenderer.material; mat.color = fogTint.Value; fogMeshRenderer.sharedMaterial = mat; - } - + } + if (lightTint != null) { var lightShafts = brambleSeed.FindChild("Terrain_DB_BrambleSphere_Seed_V2 (2)/DB_SeedLightShafts"); - + var lightShaft1 = lightShafts.FindChild("DB_SeedLightShafts1"); var mat = lightShaft1.GetComponent().material; mat.color = lightTint.Value; - + for (int i = 1; i <= 6; i++) { var lightShaft = lightShafts.FindChild($"DB_SeedLightShafts{i}"); diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 7fabe376..0d1c8c7a 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -94,14 +94,14 @@ namespace NewHorizons.Builder.Props detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO; } - public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal, bool leaveInactive=false) + public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal) { var prefab = SearchUtilities.Find(propToClone); if (prefab == null) Logger.LogError($"Couldn't find detail {propToClone}"); - return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal, leaveInactive); + return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal); } - public static GameObject MakeDetail(GameObject planetGO, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal, bool leaveInactive=false) + public static GameObject MakeDetail(GameObject planetGO, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal) { if (prefab == null) return null; @@ -271,7 +271,7 @@ namespace NewHorizons.Builder.Props prop.transform.localScale = scale != 0 ? Vector3.one * scale : prefab.transform.localScale; - if (!leaveInactive) prop.SetActive(true); + prop.SetActive(true); return prop; } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index e9c2e256..2429fc58 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -388,8 +388,15 @@ namespace NewHorizons.Handlers body.Object = go; - // Now that we're done move the planet into place - UpdatePosition(go, body.Config.Orbit, primaryBody, ao); + // Now that we're done move the planet into place + if (body.Config.Orbit?.staticPosition != null) + { + SetPositionFromVector(go, body.Config.Orbit.staticPosition); + } + else + { + UpdatePosition(go, body.Config.Orbit, primaryBody, ao); + } // Have to do this after setting position var initialMotion = InitialMotionBuilder.Make(go, primaryBody, ao, owRigidBody, body.Config.Orbit); @@ -410,11 +417,6 @@ namespace NewHorizons.Handlers { DetectorBuilder.Make(go, owRigidBody, primaryBody, ao, body.Config); } - else if (body.Config.Orbit.staticPosition != null) - { - // NH doesn't set the value of _centerOfTheUniverse for a few frames - ao.transform.position = body.Config.Orbit.staticPosition + Locator._centerOfTheUniverse._staticReferenceFrame._lastPosition; - } if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) { @@ -687,24 +689,29 @@ namespace NewHorizons.Handlers { Logger.LogVerbose($"Placing [{secondaryBody?.name}] around [{primaryBody?.name}]"); - go.transform.parent = Locator.GetRootTransform(); - if (primaryBody != null) { var primaryGravity = new Gravity(primaryBody.GetGravityVolume()); var secondaryGravity = new Gravity(secondaryBody.GetGravityVolume()); - go.transform.position = orbit.GetOrbitalParameters(primaryGravity, secondaryGravity).InitialPosition + primaryBody.transform.position; + var pos = orbit.GetOrbitalParameters(primaryGravity, secondaryGravity).InitialPosition + primaryBody.transform.position; + SetPositionFromVector(go, pos); } else - { - go.transform.position = Vector3.zero; + { + SetPositionFromVector(go, Vector3.zero); } - + } + + public static void SetPositionFromVector(GameObject go, Vector3 position) + { + go.transform.parent = Locator.GetRootTransform(); + go.transform.position = position; + if (go.transform.position.magnitude > Main.FurthestOrbit) { Main.FurthestOrbit = go.transform.position.magnitude + 30000f; - } + } } } }