From 4538a9e53cba6419afa8ee4ca74bbc83ff954c44 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 14 Aug 2022 23:34:02 -0400 Subject: [PATCH 01/18] Better supernova scale --- NewHorizons/Builder/Body/StarBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 65d84c1f..3aa21546 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -288,7 +288,7 @@ namespace NewHorizons.Builder.Body var supernova = supernovaGO.GetComponent(); supernova._surface = starGO.GetComponentInChildren(); - supernova._supernovaScale = AnimationCurve.Linear(5, 0, 15, starModule.supernovaSize); + supernova._supernovaScale = new AnimationCurve(new Keyframe(0, 200, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(45, starModule.supernovaSize, 1758.508f, 1758.508f, 1f / 3f, 1f / 3f)); supernova._supernovaVolume = null; if (starModule.supernovaTint != null) From efebb13e85b6a484f901a17c07cecda37515eccb Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 06:14:03 -0400 Subject: [PATCH 02/18] Rename instantiated objects --- NewHorizons/Builder/Atmosphere/EffectsBuilder.cs | 1 + NewHorizons/Builder/Body/LavaBuilder.cs | 1 + NewHorizons/Builder/Body/SingularityBuilder.cs | 1 + NewHorizons/Builder/Body/StarBuilder.cs | 1 + NewHorizons/Builder/Props/TornadoBuilder.cs | 5 ++++- 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs index 0271e8ed..fb405705 100644 --- a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs @@ -23,6 +23,7 @@ namespace NewHorizons.Builder.Atmosphere if (config.Atmosphere.hasRain) { var rainGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain"), effectsGO.transform); + rainGO.name = "RainEmitter"; rainGO.transform.position = planetGO.transform.position; var pvc = rainGO.GetComponent(); diff --git a/NewHorizons/Builder/Body/LavaBuilder.cs b/NewHorizons/Builder/Body/LavaBuilder.cs index dc1d4d47..95878f9e 100644 --- a/NewHorizons/Builder/Body/LavaBuilder.cs +++ b/NewHorizons/Builder/Body/LavaBuilder.cs @@ -52,6 +52,7 @@ namespace NewHorizons.Builder.Body sectorProxy.SetSector(sector); var destructionVolume = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/DestructionVolume"), moltenCore.transform); + destructionVolume.name = "DestructionVolume"; destructionVolume.GetComponent().radius = 1; destructionVolume.SetActive(true); diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index a58a3595..1676879a 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -140,6 +140,7 @@ namespace NewHorizons.Builder.Body if (sizeController != null) sizeController.audioSource = blackHoleAudioSource; var blackHoleOneShot = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleEmissionOneShot"), blackHole.transform); + blackHoleOneShot.name = "BlackHoleEmissionOneShot"; var oneShotAudioSource = blackHoleOneShot.GetComponent(); oneShotAudioSource.maxDistance = size * 3f; oneShotAudioSource.minDistance = size * 0.4f; diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 3aa21546..f3ef4b15 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -283,6 +283,7 @@ namespace NewHorizons.Builder.Body private static SupernovaEffectController MakeSupernova(GameObject starGO, StarModule starModule) { var supernovaGO = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive(); + supernovaGO.name = "Supernova"; supernovaGO.transform.SetParent(starGO.transform); supernovaGO.transform.localPosition = Vector3.zero; diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 49b2f43a..e166bea0 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -36,7 +36,8 @@ namespace NewHorizons.Builder.Props } if (_hurricanePrefab == null) { - _hurricanePrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane/").InstantiateInactive(); + _hurricanePrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane").InstantiateInactive(); + _hurricanePrefab.name = "Hurricane_Prefab"; // For some reason they put the hurricane at the origin and offset all its children (450) // Increasing by 40 will keep the bottom above the ground foreach (Transform child in _hurricanePrefab.transform) @@ -84,6 +85,7 @@ namespace NewHorizons.Builder.Props private static void MakeTornado(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, Vector3 position, bool downwards) { var tornadoGO = downwards ? _downPrefab.InstantiateInactive() : _upPrefab.InstantiateInactive(); + tornadoGO.name = downwards ? "Tornado_Down" : "Tornado_Up"; tornadoGO.transform.parent = sector.transform; tornadoGO.transform.position = planetGO.transform.TransformPoint(position); tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized)); @@ -168,6 +170,7 @@ namespace NewHorizons.Builder.Props private static void MakeHurricane(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, Vector3 position, bool hasClouds) { var hurricaneGO = _hurricanePrefab.InstantiateInactive(); + hurricaneGO.name = "Hurricane"; hurricaneGO.transform.parent = sector.transform; hurricaneGO.transform.position = planetGO.transform.TransformPoint(position); hurricaneGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized)); From adc962f14e9c77b5100ab71236351199138446c1 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 06:17:40 -0400 Subject: [PATCH 03/18] Better locator --- NewHorizons/Patches/LocatorPatches.cs | 93 +++++++++++++++++++++++ NewHorizons/Utility/AstroObjectLocator.cs | 16 ++++ 2 files changed, 109 insertions(+) diff --git a/NewHorizons/Patches/LocatorPatches.cs b/NewHorizons/Patches/LocatorPatches.cs index 30c76cf2..1a95dfbb 100644 --- a/NewHorizons/Patches/LocatorPatches.cs +++ b/NewHorizons/Patches/LocatorPatches.cs @@ -1,9 +1,18 @@ using HarmonyLib; +using NewHorizons.Utility; + namespace NewHorizons.Patches { [HarmonyPatch] public static class LocatorPatches { + public static AstroObject _attlerock; + public static AstroObject _eye; + public static AstroObject _focal; + public static AstroObject _hollowsLantern; + public static AstroObject _mapSatellite; + public static AstroObject _sunStation; + [HarmonyPrefix] [HarmonyPatch(typeof(Locator), nameof(Locator.RegisterCloakFieldController))] public static bool Locator_RegisterCloakFieldController() @@ -31,5 +40,89 @@ namespace NewHorizons.Patches { __result = __result || Components.CloakSectorController.isShipInside; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(Locator), nameof(Locator.GetAstroObject))] + public static bool Locator_GetAstroObject(AstroObject.Name astroObjectName, ref AstroObject __result) + { + switch (astroObjectName) + { + case AstroObject.Name.Eye: + __result = _eye; + return false; + case AstroObject.Name.HourglassTwins: + __result = _focal; + return false; + case AstroObject.Name.MapSatellite: + __result = _mapSatellite; + return false; + case AstroObject.Name.SunStation: + __result = _sunStation; + return false; + case AstroObject.Name.TimberMoon: + __result = _attlerock; + return false; + case AstroObject.Name.VolcanicMoon: + __result = _hollowsLantern; + return false; + default: + break; + } + return true; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(Locator), nameof(Locator.RegisterAstroObject))] + public static bool Locator_RegisterAstroObject(AstroObject astroObject) + { + if (astroObject.GetAstroObjectName() == AstroObject.Name.None) return false; + if (!string.IsNullOrEmpty(astroObject._customName) && astroObject._customName.Equals("Sun Station")) + { + if (astroObject.gameObject.name == "SunStation_Body") + { + astroObject._name = AstroObject.Name.SunStation; + _sunStation = astroObject; + return false; + } + else if (astroObject.gameObject.name == "SS_Debris_Body") astroObject._customName = "Sun Station Debris"; + return true; + } + switch (astroObject.GetAstroObjectName()) + { + case AstroObject.Name.Eye: + _eye = astroObject; + return false; + case AstroObject.Name.HourglassTwins: + _focal = astroObject; + return false; + case AstroObject.Name.MapSatellite: + _mapSatellite = astroObject; + return false; + case AstroObject.Name.SunStation: + _sunStation = astroObject; + return false; + case AstroObject.Name.TimberMoon: + _attlerock = astroObject; + return false; + case AstroObject.Name.VolcanicMoon: + _hollowsLantern = astroObject; + return false; + default: + break; + } + return true; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(Locator), nameof(Locator.ClearReferences))] + public static void Locator_ClearReferences() + { + _attlerock = null; + _eye = null; + _focal = null; + _hollowsLantern = null; + _mapSatellite = null; + _sunStation = null; + } } } diff --git a/NewHorizons/Utility/AstroObjectLocator.cs b/NewHorizons/Utility/AstroObjectLocator.cs index d28b225e..bfe23bfe 100644 --- a/NewHorizons/Utility/AstroObjectLocator.cs +++ b/NewHorizons/Utility/AstroObjectLocator.cs @@ -89,6 +89,16 @@ namespace NewHorizons.Utility return _customAstroObjectDictionary.Values.Where(x => x._primaryBody == primary).Select(x => x.gameObject).ToArray(); } + public static AstroObject[] GetAncestors(AstroObject astroObject) + { + List ancestors = new List(); + for (AstroObject primaryBody = astroObject._primaryBody; primaryBody != null && !ancestors.Contains(primaryBody); primaryBody = primaryBody._primaryBody) + { + ancestors.Add(primaryBody); + } + return ancestors.ToArray(); + } + public static GameObject[] GetChildren(AstroObject primary) { if (primary == null) return new GameObject[0]; @@ -142,6 +152,12 @@ namespace NewHorizons.Utility otherChildren.Add(SearchUtilities.Find("DB_SmallNest_Body")); otherChildren.Add(SearchUtilities.Find("DB_Elsinore_Body")); break; + case AstroObject.Name.SunStation: + // there are multiple debris with the same name + otherChildren.AddRange(Object.FindObjectsOfType() + .Select(x => x.gameObject) + .Where(x => x.name == "SS_Debris_Body")); + break; // For some dumb reason the sun station doesn't use AstroObject.Name.SunStation case AstroObject.Name.CustomString: if (primary._customName.Equals("Sun Station")) From cc4194ccad030eee9429d8fc65c823f28b489901 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 06:20:00 -0400 Subject: [PATCH 04/18] Proxy atmosphere, fog, and lightning --- .../Builder/Atmosphere/AtmosphereBuilder.cs | 77 ++++++++++++++----- .../Builder/Atmosphere/CloudsBuilder.cs | 52 ++++++++----- NewHorizons/Builder/Atmosphere/FogBuilder.cs | 37 ++++++++- NewHorizons/Builder/Body/GeometryBuilder.cs | 4 +- NewHorizons/Builder/Body/HeightMapBuilder.cs | 6 +- NewHorizons/Builder/Body/ProcGenBuilder.cs | 3 +- NewHorizons/Builder/Body/ProxyBuilder.cs | 49 ++++++++++-- .../Builder/General/AmbientLightBuilder.cs | 4 +- NewHorizons/Components/NHProxy.cs | 20 ++++- NewHorizons/Patches/ProxyBodyPatches.cs | 74 +++++++++++++++++- 10 files changed, 269 insertions(+), 57 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs index 1a833182..ed4294c5 100644 --- a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs @@ -18,7 +18,7 @@ namespace NewHorizons.Builder.Atmosphere Skys.Clear(); } - public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmosphereModule, float surfaceSize) + public static GameObject Make(GameObject planetGO, Sector sector, AtmosphereModule atmosphereModule, float surfaceSize, bool proxy = false) { GameObject atmoGO = new GameObject("Atmosphere"); atmoGO.SetActive(false); @@ -26,36 +26,73 @@ namespace NewHorizons.Builder.Atmosphere if (atmosphereModule.useAtmosphereShader) { - GameObject atmo = GameObject.Instantiate(SearchUtilities.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"), atmoGO.transform, true); - atmo.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - atmo.transform.localScale = Vector3.one * atmosphereModule.size * 1.2f; - - var renderers = atmo.GetComponentsInChildren(); - var material = renderers[0].material; // makes a new material - foreach (var renderer in renderers) + if (proxy) { - renderer.sharedMaterial = material; - } - material.SetFloat(InnerRadius, atmosphereModule.clouds != null ? atmosphereModule.size : surfaceSize); - material.SetFloat(OuterRadius, atmosphereModule.size * 1.2f); - if (atmosphereModule.atmosphereTint != null) material.SetColor(SkyColor, atmosphereModule.atmosphereTint.ToColor()); + var distantProxy = (SearchUtilities.Find("TimberHearth_DistantProxy", false) ?? SearchUtilities.Find("TimberHearth_DistantProxy(Clone)", false))?.FindChild("Atmosphere_TH/Atmosphere_LOD3"); + if (distantProxy != null) + { + GameObject atmo = GameObject.Instantiate(distantProxy, atmoGO.transform, true); + atmo.name = "Atmosphere_LOD3"; + atmo.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + atmo.transform.localScale = Vector3.one * atmosphereModule.size * 1.2f * 2f; - atmo.SetActive(true); + var renderer = atmo.GetComponent(); + var material = renderer.material; // makes a new material + renderer.sharedMaterial = material; + material.SetFloat(InnerRadius, atmosphereModule.clouds != null ? atmosphereModule.size : surfaceSize); + material.SetFloat(OuterRadius, atmosphereModule.size * 1.2f); + if (atmosphereModule.atmosphereTint != null) material.SetColor(SkyColor, atmosphereModule.atmosphereTint.ToColor()); - if (atmosphereModule.atmosphereSunIntensity == 0) - { - // do it based on distance - Skys.Add((planetGO, material)); + atmo.SetActive(true); + + if (atmosphereModule.atmosphereSunIntensity == 0) + { + // do it based on distance + Skys.Add((planetGO, material)); + } + else + { + // use the override instead + material.SetFloat(SunIntensity, atmosphereModule.atmosphereSunIntensity); + } + } } else { - // use the override instead - material.SetFloat(SunIntensity, atmosphereModule.atmosphereSunIntensity); + GameObject atmo = GameObject.Instantiate(SearchUtilities.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"), atmoGO.transform, true); + atmo.name = "AtmoSphere"; + atmo.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + atmo.transform.localScale = Vector3.one * atmosphereModule.size * 1.2f; + + var renderers = atmo.GetComponentsInChildren(); + var material = renderers[0].material; // makes a new material + foreach (var renderer in renderers) + { + renderer.sharedMaterial = material; + } + material.SetFloat(InnerRadius, atmosphereModule.clouds != null ? atmosphereModule.size : surfaceSize); + material.SetFloat(OuterRadius, atmosphereModule.size * 1.2f); + if (atmosphereModule.atmosphereTint != null) material.SetColor(SkyColor, atmosphereModule.atmosphereTint.ToColor()); + + atmo.SetActive(true); + + if (atmosphereModule.atmosphereSunIntensity == 0) + { + // do it based on distance + Skys.Add((planetGO, material)); + } + else + { + // use the override instead + material.SetFloat(SunIntensity, atmosphereModule.atmosphereSunIntensity); + } } } atmoGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); atmoGO.SetActive(true); + + return atmoGO; } } } diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index ea439e0b..c18487ba 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -109,26 +109,7 @@ namespace NewHorizons.Builder.Atmosphere // Lightning if (atmo.clouds.hasLightning) { - var lightning = _lightningPrefab.InstantiateInactive(); - lightning.transform.parent = cloudsMainGO.transform; - lightning.transform.localPosition = Vector3.zero; - - var lightningGenerator = lightning.GetComponent(); - lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; - lightningGenerator._audioSector = sector; - if (atmo.clouds.lightningGradient != null) - { - var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; - - for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) - { - var pair = atmo.clouds.lightningGradient[i]; - gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); - } - - lightningGenerator._lightColor.colorKeys = gradient; - } - lightning.SetActive(true); + MakeLightning(cloudsMainGO, sector, atmo); } cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); @@ -140,6 +121,37 @@ namespace NewHorizons.Builder.Atmosphere cloudsMainGO.SetActive(true); } + public static CloudLightningGenerator MakeLightning(GameObject rootObject, Sector sector, AtmosphereModule atmo, bool noAudio = false) + { + var lightning = _lightningPrefab.InstantiateInactive(); + lightning.name = "LightningGenerator"; + lightning.transform.parent = rootObject.transform; + lightning.transform.localPosition = Vector3.zero; + + var lightningGenerator = lightning.GetComponent(); + lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; + if (noAudio) + { + lightningGenerator._audioPrefab = null; + lightningGenerator._audioSourcePool = null; + } + lightningGenerator._audioSector = sector; + if (atmo.clouds.lightningGradient != null) + { + var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; + + for (int i = 0; i < atmo.clouds.lightningGradient.Length; i++) + { + var pair = atmo.clouds.lightningGradient[i]; + gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); + } + + lightningGenerator._lightColor.colorKeys = gradient; + } + lightning.SetActive(true); + return lightningGenerator; + } + public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) { Color cloudTint = atmo.clouds.tint?.ToColor() ?? UnityEngine.Color.white; diff --git a/NewHorizons/Builder/Atmosphere/FogBuilder.cs b/NewHorizons/Builder/Atmosphere/FogBuilder.cs index 34d62f95..88ce4965 100644 --- a/NewHorizons/Builder/Atmosphere/FogBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/FogBuilder.cs @@ -14,7 +14,7 @@ namespace NewHorizons.Builder.Atmosphere private static readonly int DensityExponent = Shader.PropertyToID("_DensityExp"); private static readonly int ColorRampTexture = Shader.PropertyToID("_ColorRampTex"); - public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo) + public static PlanetaryFogController Make(GameObject planetGO, Sector sector, AtmosphereModule atmo) { if (_ramp == null) _ramp = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/FogColorRamp.png"); @@ -58,6 +58,41 @@ namespace NewHorizons.Builder.Atmosphere fogGO.transform.position = planetGO.transform.position; fogGO.SetActive(true); + return PFC; + } + + public static Renderer MakeProxy(GameObject proxyGO, AtmosphereModule atmo) + { + if (_ramp == null) _ramp = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/FogColorRamp.png"); + + GameObject fogGO = new GameObject("FogSphere"); + fogGO.SetActive(false); + fogGO.transform.parent = proxyGO.transform; + fogGO.transform.localScale = Vector3.one * atmo.fogSize; + + var fog = (SearchUtilities.Find("TimberHearth_DistantProxy", false) ?? SearchUtilities.Find("TimberHearth_DistantProxy(Clone)", false))?.FindChild("Atmosphere_TH/FogSphere"); + + MeshFilter MF = fogGO.AddComponent(); + MF.mesh = fog.GetComponent().mesh; + + MeshRenderer MR = fogGO.AddComponent(); + MR.materials = fog.GetComponent().materials; + MR.allowOcclusionWhenDynamic = true; + + var colorRampTexture = atmo.fogTint == null ? _ramp : ImageUtilities.TintImage(_ramp, atmo.fogTint.ToColor()); + if (atmo.fogTint != null) + { + MR.material.SetColor(Tint, atmo.fogTint.ToColor()); + } + MR.material.SetFloat(Radius, atmo.fogSize); + MR.material.SetFloat(Density, atmo.fogDensity); + MR.material.SetFloat(DensityExponent, 1); + MR.material.SetTexture(ColorRampTexture, colorRampTexture); + + fogGO.transform.position = proxyGO.transform.position; + + fogGO.SetActive(true); + return MR; } } } diff --git a/NewHorizons/Builder/Body/GeometryBuilder.cs b/NewHorizons/Builder/Body/GeometryBuilder.cs index 73c1cbcc..0d4bcce0 100644 --- a/NewHorizons/Builder/Body/GeometryBuilder.cs +++ b/NewHorizons/Builder/Body/GeometryBuilder.cs @@ -4,7 +4,7 @@ namespace NewHorizons.Builder.Body { public static class GeometryBuilder { - public static void Make(GameObject planetGO, Sector sector, float groundScale) + public static GameObject Make(GameObject planetGO, Sector sector, float groundScale) { GameObject groundGO = GameObject.CreatePrimitive(PrimitiveType.Sphere); groundGO.transform.name = "GroundSphere"; @@ -15,6 +15,8 @@ namespace NewHorizons.Builder.Body groundGO.GetComponent().mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; groundGO.GetComponent().radius = 1f; groundGO.SetActive(true); + + return groundGO; } } } diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index cf704eb7..3e8a06f5 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -14,7 +14,7 @@ namespace NewHorizons.Builder.Body { public static Shader PlanetShader; - public static void Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod, int resolution, bool useLOD = false) + public static GameObject Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod, int resolution, bool useLOD = false) { var deleteHeightmapFlag = false; @@ -60,7 +60,7 @@ namespace NewHorizons.Builder.Body catch (Exception e) { Logger.LogError($"Couldn't load HeightMap textures:\n{e}"); - return; + return null; } GameObject cubeSphere = new GameObject("CubeSphere"); @@ -111,6 +111,8 @@ namespace NewHorizons.Builder.Body // Now that we've made the mesh we can delete the heightmap texture if (deleteHeightmapFlag) ImageUtilities.DeleteTexture(mod, module.heightMap, heightMap); + + return cubeSphere; } public static MeshRenderer MakeLODTerrain(GameObject root, Texture2D heightMap, Texture2D textureMap, float minHeight, float maxHeight, int resolution, Vector3 stretch) diff --git a/NewHorizons/Builder/Body/ProcGenBuilder.cs b/NewHorizons/Builder/Body/ProcGenBuilder.cs index 5d696b1e..e168c678 100644 --- a/NewHorizons/Builder/Body/ProcGenBuilder.cs +++ b/NewHorizons/Builder/Body/ProcGenBuilder.cs @@ -9,7 +9,7 @@ namespace NewHorizons.Builder.Body private static Material quantumMaterial; private static Material iceMaterial; - public static void Make(GameObject planetGO, Sector sector, ProcGenModule module) + public static GameObject Make(GameObject planetGO, Sector sector, ProcGenModule module) { if (quantumMaterial == null) quantumMaterial = SearchUtilities.FindResourceOfTypeAndName("Rock_QM_EyeRock_mat"); if (iceMaterial == null) iceMaterial = SearchUtilities.FindResourceOfTypeAndName("Rock_BH_IceSpike_mat"); @@ -40,6 +40,7 @@ namespace NewHorizons.Builder.Body if (superGroup != null) icosphere.AddComponent()._superGroup = superGroup; icosphere.SetActive(true); + return icosphere; } } } diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 629e7570..15eb6635 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -34,43 +34,73 @@ namespace NewHorizons.Builder.Body var proxyName = $"{body.Config.name}_Proxy"; var newProxy = new GameObject(proxyName); + newProxy.SetActive(false); try { + var proxyController = newProxy.AddComponent(); + proxyController.astroName = body.Config.name; + // We want to take the largest size I think var realSize = body.Config.Base.surfaceSize; + GameObject heightMap = null; if (body.Config.HeightMap != null) { - HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20); + heightMap = HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20); if (realSize < body.Config.HeightMap.maxHeight) realSize = body.Config.HeightMap.maxHeight; } + if (body.Config.Base.groundSize != 0) { GeometryBuilder.Make(newProxy, null, body.Config.Base.groundSize); if (realSize < body.Config.Base.groundSize) realSize = body.Config.Base.groundSize; } - if (body.Config.Atmosphere?.clouds != null) + + if (body.Config.Atmosphere != null) { - CloudsBuilder.MakeTopClouds(newProxy, body.Config.Atmosphere, body.Mod); - if (realSize < body.Config.Atmosphere.size) realSize = body.Config.Atmosphere.size; + proxyController._atmosphere = AtmosphereBuilder.Make(newProxy, null, body.Config.Atmosphere, body.Config.Base.surfaceSize, true).GetComponentInChildren(); + proxyController._mieCurveMaxVal = 0.1f; + proxyController._mieCurve = AnimationCurve.EaseInOut(0.0011f, 1, 1, 0); + + if (body.Config.Atmosphere.fogSize != 0) + { + proxyController._fog = FogBuilder.MakeProxy(newProxy, body.Config.Atmosphere); + proxyController._fogCurveMaxVal = body.Config.Atmosphere.fogDensity; + proxyController._fogCurve = AnimationCurve.Linear(0, 1, 1, 0); + } + + if (body.Config.Atmosphere.clouds != null) + { + proxyController._mainBody = CloudsBuilder.MakeTopClouds(newProxy, body.Config.Atmosphere, body.Mod).GetComponent(); + if (body.Config.Atmosphere.clouds.hasLightning) + { + proxyController._lightningGenerator = CloudsBuilder.MakeLightning(newProxy, null, body.Config.Atmosphere, true); + } + if (realSize < body.Config.Atmosphere.size) realSize = body.Config.Atmosphere.size; + } } + if (body.Config.Ring != null) { RingBuilder.MakeRingGraphics(newProxy, null, body.Config.Ring, body.Mod); if (realSize < body.Config.Ring.outerRadius) realSize = body.Config.Ring.outerRadius; } + if (body.Config.Star != null) { var starGO = StarBuilder.MakeStarProxy(planetGO, newProxy, body.Config.Star, body.Mod); if (realSize < body.Config.Star.size) realSize = body.Config.Star.size; } + + GameObject procGen = null; if (body.Config.ProcGen != null) { - ProcGenBuilder.Make(newProxy, null, body.Config.ProcGen); + procGen = ProcGenBuilder.Make(newProxy, null, body.Config.ProcGen); if (realSize < body.Config.ProcGen.scale) realSize = body.Config.ProcGen.scale; } + if (body.Config.Lava != null) { var sphere = AddColouredSphere(newProxy, body.Config.Lava.size, body.Config.Lava.curve, Color.black); @@ -80,18 +110,21 @@ namespace NewHorizons.Builder.Body if (body.Config.Lava.tint != null) material.SetColor(EmissionColor, body.Config.Lava.tint.ToColor()); sphere.GetComponent().material = material; } + if (body.Config.Water != null) { var colour = body.Config.Water.tint?.ToColor() ?? Color.blue; AddColouredSphere(newProxy, body.Config.Water.size, body.Config.Water.curve, colour); if (realSize < body.Config.Water.size) realSize = body.Config.Water.size; } + if (body.Config.Sand != null) { var colour = body.Config.Sand.tint?.ToColor() ?? Color.yellow; AddColouredSphere(newProxy, body.Config.Sand.size, body.Config.Sand.curve, colour); if (realSize < body.Config.Sand.size) realSize = body.Config.Sand.size; } + // Could improve this to actually use the proper renders and materials if (body.Config.Props?.singularities != null) { @@ -109,10 +142,12 @@ namespace NewHorizons.Builder.Body if (realSize < singularity.size) realSize = singularity.size; } } + if (body.Config.Base.hasCometTail) { CometTailBuilder.Make(newProxy, null, body.Config); } + if (body.Config.Props?.proxyDetails != null) { foreach (var detailInfo in body.Config.Props.proxyDetails) @@ -138,8 +173,6 @@ namespace NewHorizons.Builder.Body tessellatedRenderer.enabled = true; } - var proxyController = newProxy.AddComponent(); - proxyController.astroName = body.Config.name; proxyController._realObjectDiameter = realSize; } catch (Exception ex) @@ -147,6 +180,8 @@ namespace NewHorizons.Builder.Body Logger.LogError($"Exception thrown when generating proxy for [{body.Config.name}]:\n{ex}"); GameObject.Destroy(newProxy); } + + newProxy.SetActive(true); } private static GameObject AddColouredSphere(GameObject rootObj, float size, VariableSizeModule.TimeValuePair[] curve, Color color) diff --git a/NewHorizons/Builder/General/AmbientLightBuilder.cs b/NewHorizons/Builder/General/AmbientLightBuilder.cs index c51f90c0..10a85002 100644 --- a/NewHorizons/Builder/General/AmbientLightBuilder.cs +++ b/NewHorizons/Builder/General/AmbientLightBuilder.cs @@ -4,7 +4,7 @@ namespace NewHorizons.Builder.General { public static class AmbientLightBuilder { - public static void Make(GameObject planetGO, Sector sector, float scale, float intensity) + public static Light Make(GameObject planetGO, Sector sector, float scale, float intensity) { GameObject lightGO = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/AmbientLight_BH_Surface"), sector?.transform ?? planetGO.transform); lightGO.transform.position = planetGO.transform.position; @@ -21,6 +21,8 @@ namespace NewHorizons.Builder.General light.color = new Color(0.0f, 0.0f, 0.8f, 0.0225f); light.range = scale; light.intensity = intensity; + + return light; } } } diff --git a/NewHorizons/Components/NHProxy.cs b/NewHorizons/Components/NHProxy.cs index f9a7e37d..d40c74bf 100644 --- a/NewHorizons/Components/NHProxy.cs +++ b/NewHorizons/Components/NHProxy.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components.SizeControllers; +using NewHorizons.Components.SizeControllers; using NewHorizons.Utility; using System.Collections.Generic; using UnityEngine; @@ -13,6 +13,8 @@ namespace NewHorizons.Components private TessellatedRenderer[] _starTessellatedRenderers; private ParticleSystemRenderer[] _starParticleRenderers; private SolarFlareEmitter _solarFlareEmitter; + public CloudLightningGenerator _lightningGenerator; + public MeshRenderer _mainBody; public override void Awake() { @@ -30,6 +32,8 @@ namespace NewHorizons.Components _solarFlareEmitter = _star.GetComponentInChildren(); } + if (_lightningGenerator == null) _lightningGenerator = GetComponentInChildren(); + // Start off _outOfRange = false; ToggleRendering(false); @@ -39,9 +43,9 @@ namespace NewHorizons.Components { AstroObject astroObject = AstroObjectLocator.GetAstroObject(astroName); _realObjectTransform = astroObject.transform; - _hasAtmosphere = _atmosphere != null; - if (_hasAtmosphere) + if (_atmosphere != null) { + _hasAtmosphere = true; _atmosphereMaterial = new Material(_atmosphere.sharedMaterial); _baseAtmoMatShellInnerRadius = _atmosphereMaterial.GetFloat(propID_AtmoInnerRadius); _baseAtmoMatShellOuterRadius = _atmosphereMaterial.GetFloat(propID_AtmoOuterRadius); @@ -73,6 +77,16 @@ namespace NewHorizons.Components _solarFlareEmitter.gameObject.SetActive(on); } + if (_mainBody != null) + { + _mainBody.enabled = on; + } + + if (_lightningGenerator != null) + { + _lightningGenerator.enabled = on; + } + foreach (var renderer in _starRenderers) { renderer.enabled = on; diff --git a/NewHorizons/Patches/ProxyBodyPatches.cs b/NewHorizons/Patches/ProxyBodyPatches.cs index ecc7ef7b..804c6682 100644 --- a/NewHorizons/Patches/ProxyBodyPatches.cs +++ b/NewHorizons/Patches/ProxyBodyPatches.cs @@ -1,4 +1,9 @@ -using HarmonyLib; +using HarmonyLib; +using NewHorizons.Utility; +using System; +using System.Runtime.CompilerServices; +using UnityEngine; + namespace NewHorizons.Patches { [HarmonyPatch] @@ -46,5 +51,72 @@ namespace NewHorizons.Patches GlobalMessenger.RemoveListener("EnterMapView", __instance.OnEnterMapView); GlobalMessenger.RemoveListener("ExitMapView", __instance.OnExitMapView); } + + [HarmonyReversePatch] + [HarmonyPatch(typeof(ProxyPlanet), nameof(ProxyPlanet.Initialize))] + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ProxyPlanet_Initialize(ProxyPlanet instance) { } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ProxyBrittleHollow), nameof(ProxyBrittleHollow.Initialize))] + public static bool ProxyBrittleHollow_Initialize(ProxyBrittleHollow __instance) + { + try + { + ProxyPlanet_Initialize(__instance); + __instance._moon.SetOriginalBodies(Locator.GetAstroObject(AstroObject.Name.VolcanicMoon).transform, Locator.GetAstroObject(AstroObject.Name.BrittleHollow).transform); + if (!__instance._fragmentsResolved) __instance.ResolveFragments(); + __instance._blackHoleMaterial = new Material(__instance._blackHoleRenderer.sharedMaterial); + __instance._blackHoleRenderer.sharedMaterial = __instance._blackHoleMaterial; + } + catch (NullReferenceException ex) + { + __instance.PrintInitializeFailMessage(ex); + UnityEngine.Object.Destroy(__instance._moon.gameObject); + UnityEngine.Object.Destroy(__instance.gameObject); + } + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ProxyTimberHearth), nameof(ProxyTimberHearth.Initialize))] + public static bool ProxyTimberHearth_Initialize(ProxyTimberHearth __instance) + { + try + { + ProxyPlanet_Initialize(__instance); + __instance._moon.SetOriginalBodies(Locator.GetAstroObject(AstroObject.Name.TimberMoon).transform, Locator.GetAstroObject(AstroObject.Name.TimberHearth).transform); + } + catch (NullReferenceException ex) + { + __instance.PrintInitializeFailMessage(ex); + UnityEngine.Object.Destroy(__instance._moon.gameObject); + UnityEngine.Object.Destroy(__instance.gameObject); + } + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ProxyAshTwin), nameof(ProxyAshTwin.Initialize))] + public static bool ProxyAshTwin_Initialize(ProxyAshTwin __instance) + { + try + { + ProxyPlanet_Initialize(__instance); + __instance._realSandTransform = Locator.GetAstroObject(AstroObject.Name.TowerTwin).GetSandLevelController().transform; + SandFunnelController sandFunnelController = SearchUtilities.Find("SandFunnel_Body", false)?.GetComponent(); + if (sandFunnelController != null) + { + __instance._realSandColumnRoot = sandFunnelController.scaleRoot; + __instance._realSandColumnRenderObject = sandFunnelController.sandGeoObjects[0]; + } + } + catch (NullReferenceException ex) + { + __instance.PrintInitializeFailMessage(ex); + UnityEngine.Object.Destroy(__instance.gameObject); + } + return false; + } } } From fb5b7b87c8ec444c2152e315086d89e0378c015c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 06:25:09 -0400 Subject: [PATCH 05/18] Scale planet destruction volume at the end --- .../SizeControllers/StarEvolutionController.cs | 10 +++++++++- NewHorizons/Components/TimeLoopController.cs | 5 ++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index f3491024..4120d873 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -39,7 +39,9 @@ namespace NewHorizons.Components.SizeControllers private float _collapseTimer; public float collapseTime = 10f; // seconds - public float supernovaTime = 45f; // seconds + public float supernovaScaleStart = 45f; // seconds + public float supernovaScaleEnd = 50f; // seconds + public float supernovaTime = 50f; // seconds public float lifespan = 22f; // minutes public float supernovaSize = 50000f; @@ -228,6 +230,12 @@ namespace NewHorizons.Components.SizeControllers if (_planetDestructionVolume != null) _planetDestructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * 0.9f; if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius(); + var t = Mathf.Clamp01((Time.time - (_supernovaStartTime + supernovaScaleStart)) / (supernovaScaleEnd - supernovaScaleStart)); + if (t > 0) + { + _planetDestructionVolume.GetComponent().radius = Mathf.Lerp(0.8f, 1, t); + } + if (Time.time > _supernovaStartTime + supernovaTime) { DisableStar(); diff --git a/NewHorizons/Components/TimeLoopController.cs b/NewHorizons/Components/TimeLoopController.cs index 2e739b2a..7110e6db 100644 --- a/NewHorizons/Components/TimeLoopController.cs +++ b/NewHorizons/Components/TimeLoopController.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; namespace NewHorizons.Components { public class TimeLoopController : MonoBehaviour @@ -14,8 +14,7 @@ namespace NewHorizons.Components public void Update() { // Stock gives like 33 seconds after the sun collapses - // Gonna assume it takes like 7 seconds to collapse after the supernova trigger - if (_supernovaHappened && Time.time > _supernovaTime + 40f) + if (_supernovaHappened && Time.time > _supernovaTime + 50f) { Locator.GetDeathManager().KillPlayer(DeathType.TimeLoop); } From dc14871cb4b3f9aba4ea4d44d94b17aed630a2c3 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 06:25:56 -0400 Subject: [PATCH 06/18] Colors --- .../Builder/Body/AsteroidBeltBuilder.cs | 2 +- NewHorizons/Utility/MColor.cs | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index b106ebb4..21b6e4eb 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -62,7 +62,7 @@ namespace NewHorizons.Builder.Body config.ProcGen = new ProcGenModule() { scale = size, - color = new MColor(126, 94, 73, 255) + color = new MColor(126, 94, 73) }; } else diff --git a/NewHorizons/Utility/MColor.cs b/NewHorizons/Utility/MColor.cs index 93d1781b..6ec161b7 100644 --- a/NewHorizons/Utility/MColor.cs +++ b/NewHorizons/Utility/MColor.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; using Newtonsoft.Json; using UnityEngine; namespace NewHorizons.Utility @@ -6,7 +6,7 @@ namespace NewHorizons.Utility [JsonObject] public class MColor { - public MColor(int r, int g, int b, int a) + public MColor(int r, int g, int b, int a = 255) { this.r = r; this.g = g; @@ -37,8 +37,30 @@ namespace NewHorizons.Utility /// [System.ComponentModel.DataAnnotations.Range(0, 255)] [DefaultValue(255)] - public int a; + public int a = 255; public Color ToColor() => new Color(r / 255f, g / 255f, b / 255f, a / 255f); + + public static MColor red => new MColor(255, 0, 0); + + public static MColor green => new MColor(0, 255, 0); + + public static MColor blue => new MColor(0, 0, 255); + + public static MColor white => new MColor(255, 255, 255); + + public static MColor black => new MColor(0, 0, 0); + + public static MColor yellow => new MColor(255, 235, 4); + + public static MColor cyan => new MColor(0, 255, 255); + + public static MColor magenta => new MColor(255, 0, 255); + + public static MColor gray => new MColor(127, 127, 127); + + public static MColor grey => new MColor(127, 127, 127); + + public static MColor clear => new MColor(0, 0, 0, 0); } } From ead3bef90ecb71f47427e7c999fd721c50dcbee2 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 06:27:05 -0400 Subject: [PATCH 07/18] Supernova Planet Effect --- NewHorizons/Builder/Body/ProxyBuilder.cs | 5 + NewHorizons/Builder/Body/StarBuilder.cs | 2 + .../Builder/Body/SupernovaEffectBuilder.cs | 172 +++++++++++++++ NewHorizons/Components/NHProxy.cs | 9 + .../NHSupernovaPlanetEffectController.cs | 195 ++++++++++++++++++ .../StarEvolutionController.cs | 33 +++ NewHorizons/External/Modules/BaseModule.cs | 5 + NewHorizons/Handlers/PlanetCreationHandler.cs | 26 ++- .../Handlers/SupernovaEffectHandler.cs | 90 ++++++++ NewHorizons/Main.cs | 8 + 10 files changed, 538 insertions(+), 7 deletions(-) create mode 100644 NewHorizons/Builder/Body/SupernovaEffectBuilder.cs create mode 100644 NewHorizons/Components/NHSupernovaPlanetEffectController.cs create mode 100644 NewHorizons/Handlers/SupernovaEffectHandler.cs diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 15eb6635..4ff3c84d 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -156,6 +156,11 @@ namespace NewHorizons.Builder.Body } } + if (body.Config.Base.hasSupernovaShockEffect && body.Config.Star == null && body.Config.name != "Sun" && body.Config.FocalPoint == null) + { + proxyController._supernovaPlanetEffectController = SupernovaEffectBuilder.Make(newProxy, null, body.Config, heightMap, procGen, null, null, null, proxyController._atmosphere, proxyController._fog); + } + // Remove all collisions if there are any foreach (var col in newProxy.GetComponentsInChildren()) { diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index f3ef4b15..ab76c9e2 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -142,6 +142,7 @@ namespace NewHorizons.Builder.Body controller.supernova = supernova; controller.StartColour = starModule.tint; controller.EndColour = starModule.endTint; + controller.SupernovaColour = starModule.supernovaTint; controller.WillExplode = starModule.goSupernova; controller.lifespan = starModule.lifespan; controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; @@ -192,6 +193,7 @@ namespace NewHorizons.Builder.Body controller.supernova = supernova; controller.StartColour = starModule.tint; controller.EndColour = starModule.endTint; + controller.SupernovaColour = starModule.supernovaTint; controller.WillExplode = starModule.goSupernova; controller.lifespan = starModule.lifespan; controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; diff --git a/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs b/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs new file mode 100644 index 00000000..746a976f --- /dev/null +++ b/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs @@ -0,0 +1,172 @@ +using UnityEngine; +using NewHorizons.Utility; +using NewHorizons.External.Configs; +using NewHorizons.Components; +using System.Linq; +using NewHorizons.Handlers; + +namespace NewHorizons.Builder.Body +{ + public static class SupernovaEffectBuilder + { + public static NHSupernovaPlanetEffectController Make(GameObject planetGO, Sector sector, PlanetConfig config, GameObject heightMap, GameObject procGen, Light ambientLight, PlanetaryFogController fog, LODGroup atmosphere, Renderer atmosphereRenderer, Renderer fogImpostor) + { + var vanillaController = planetGO.GetComponentInChildren(); + if (vanillaController != null) + { + ReplaceVanillaWithNH(vanillaController); + } + + var currentController = planetGO.GetComponentInChildren(); + if (currentController != null) + { + if (currentController._ambientLight == null && ambientLight != null) + { + currentController._ambientLight = ambientLight; + currentController._ambientLightOrigIntensity = config.Base.ambientLight; + } + + if (currentController._atmosphere == null && atmosphere != null) currentController._atmosphere = atmosphere; + + if (currentController._fog == null && fog != null) currentController._fog = fog; + + return currentController; + } + else + { + var supernovaController = new GameObject("SupernovaController"); + supernovaController.transform.SetParent(sector?.transform ?? planetGO.transform, false); + var supernovaEffectController = supernovaController.AddComponent(); + supernovaEffectController._ambientLight = ambientLight; + supernovaEffectController._ambientLightOrigIntensity = config.Base.ambientLight; + supernovaEffectController._atmosphere = atmosphere; + supernovaEffectController._atmosphereRenderer = atmosphereRenderer; + supernovaEffectController._fog = fog; + supernovaEffectController._fogImpostor = fogImpostor; + + var shockLayerGD = SearchUtilities.Find("GiantsDeep_Body/Shocklayer_GD"); + var shockLayer = new GameObject("ShockLayer"); + shockLayer.transform.SetParent(sector?.transform ?? planetGO.transform, false); + shockLayer.AddComponent().sharedMesh = shockLayerGD.GetComponent().sharedMesh; + + var shockLayerMaterial = new Material(shockLayerGD.GetComponent().sharedMaterial); + shockLayerMaterial.name = "ShockLayer_mat"; + + var shockLayerRenderer = shockLayer.AddComponent(); + shockLayerRenderer.sharedMaterial = shockLayerMaterial; + supernovaEffectController._shockLayer = shockLayerRenderer; + + var biggestSize = config.Base.surfaceSize; + var noMeshChange = false; + + if (config.Atmosphere != null) + { + if (config.Atmosphere.size > biggestSize) biggestSize = config.Atmosphere.size; + if (config.Atmosphere.fogSize > biggestSize) biggestSize = config.Atmosphere.fogSize; + if (config.Atmosphere.clouds != null) + { + noMeshChange = true; + if (config.Atmosphere.clouds.innerCloudRadius > biggestSize) biggestSize = config.Atmosphere.clouds.innerCloudRadius; + if (config.Atmosphere.clouds.outerCloudRadius > biggestSize) biggestSize = config.Atmosphere.clouds.outerCloudRadius; + } + } + + if (config.Base.groundSize > biggestSize) + { + noMeshChange = true; + biggestSize = config.Base.groundSize; + } + + if (config.HeightMap != null) + { + if (config.HeightMap.minHeight > biggestSize) biggestSize = config.HeightMap.minHeight; + if (config.HeightMap.maxHeight > biggestSize) biggestSize = config.HeightMap.maxHeight; + } + + if (config.ProcGen != null) + { + if (config.ProcGen.scale > biggestSize) biggestSize = config.ProcGen.scale; + } + + if (config.Lava != null) + { + noMeshChange = true; + var lavaSize = config.Lava.size; + if (config.Lava.curve != null) lavaSize *= config.Lava.curve.Max(tvp => tvp.value); + if (lavaSize > biggestSize) biggestSize = lavaSize; + } + + if (config.Water != null) + { + noMeshChange = true; + var waterSize = config.Water.size; + if (config.Water.curve != null) waterSize *= config.Water.curve.Max(tvp => tvp.value); + if (waterSize > biggestSize) biggestSize = waterSize; + } + + if (config.Sand != null) + { + noMeshChange = true; + var sandSize = config.Sand.size; + if (config.Sand.curve != null) sandSize *= config.Sand.curve.Max(tvp => tvp.value); + if (sandSize > biggestSize) biggestSize = sandSize; + } + + if (config.Props?.singularities != null) + { + noMeshChange = true; + foreach (var singularity in config.Props.singularities) + { + if (singularity.size > biggestSize) biggestSize = singularity.size; + } + } + + supernovaEffectController._shockLayerStartRadius = biggestSize; + supernovaEffectController._shockLayerFullRadius = biggestSize * 10f; + supernovaEffectController._shockLayerTrailFlare = 100; + supernovaEffectController._shockLayerTrailLength = biggestSize < 600 ? 300 : 600; + + shockLayer.transform.position = planetGO.transform.position; + shockLayer.transform.localScale = Vector3.one * biggestSize * 1.1f; + + if (!noMeshChange) + { + if (heightMap != null) + { + shockLayer.GetComponent().sharedMesh = heightMap.GetComponent().sharedMesh; + shockLayer.transform.localScale = Vector3.one * 1.1f; + shockLayer.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); + } + else if (procGen != null) + { + shockLayer.GetComponent().sharedMesh = procGen.GetComponent().sharedMesh; + shockLayer.transform.localScale = Vector3.one * 1.1f; + shockLayer.transform.rotation = Quaternion.Euler(90, 0, 0); + } + } + + return supernovaEffectController; + } + } + + public static void ReplaceVanillaWithNH(SupernovaPlanetEffectController vanillaController) + { + if (vanillaController._shockLayer != null) vanillaController._shockLayer.gameObject.SetActive(true); + var supernovaEffectController = vanillaController.gameObject.GetAddComponent(); + supernovaEffectController._atmosphere = vanillaController._atmosphere; + supernovaEffectController._ambientLight = vanillaController._ambientLight; + supernovaEffectController._ambientLightOrigIntensity = vanillaController._ambientLightOrigIntensity; + supernovaEffectController._atmosphere = vanillaController._atmosphere; + supernovaEffectController._fog = vanillaController._fog; + supernovaEffectController._fogOrigTint = vanillaController._fogOrigTint; + supernovaEffectController._shockLayer = vanillaController._shockLayer; + supernovaEffectController._shockLayerColor = vanillaController._shockLayerColor; + supernovaEffectController._shockLayerFullRadius = vanillaController._shockLayerFullRadius; + supernovaEffectController._shockLayerStartRadius = vanillaController._shockLayerStartRadius; + supernovaEffectController._shockLayerTrailFlare = vanillaController._shockLayerTrailFlare; + supernovaEffectController._shockLayerTrailLength = vanillaController._shockLayerTrailLength; + supernovaEffectController._sunController = SearchUtilities.Find("Sun_Body").GetComponent(); + Object.Destroy(vanillaController); + } + } +} diff --git a/NewHorizons/Components/NHProxy.cs b/NewHorizons/Components/NHProxy.cs index d40c74bf..f19f9ae9 100644 --- a/NewHorizons/Components/NHProxy.cs +++ b/NewHorizons/Components/NHProxy.cs @@ -15,6 +15,7 @@ namespace NewHorizons.Components private SolarFlareEmitter _solarFlareEmitter; public CloudLightningGenerator _lightningGenerator; public MeshRenderer _mainBody; + public NHSupernovaPlanetEffectController _supernovaPlanetEffectController; public override void Awake() { @@ -33,6 +34,8 @@ namespace NewHorizons.Components } if (_lightningGenerator == null) _lightningGenerator = GetComponentInChildren(); + + if (_supernovaPlanetEffectController == null) _supernovaPlanetEffectController = GetComponentInChildren(); // Start off _outOfRange = false; @@ -87,6 +90,12 @@ namespace NewHorizons.Components _lightningGenerator.enabled = on; } + if (_supernovaPlanetEffectController != null) + { + if (on) _supernovaPlanetEffectController.Enable(); + else _supernovaPlanetEffectController.Disable(); + } + foreach (var renderer in _starRenderers) { renderer.enabled = on; diff --git a/NewHorizons/Components/NHSupernovaPlanetEffectController.cs b/NewHorizons/Components/NHSupernovaPlanetEffectController.cs new file mode 100644 index 00000000..5f964a55 --- /dev/null +++ b/NewHorizons/Components/NHSupernovaPlanetEffectController.cs @@ -0,0 +1,195 @@ +using NewHorizons.Components.SizeControllers; +using NewHorizons.Handlers; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using static SupernovaPlanetEffectController; + +namespace NewHorizons.Components +{ + public class NHSupernovaPlanetEffectController : MonoBehaviour + { + public Light _ambientLight; + public float _ambientLightOrigIntensity; + public LODGroup _atmosphere; + public Renderer _atmosphereRenderer; + public PlanetaryFogController _fog; + public Renderer _fogImpostor; + public Color _fogOrigTint; + [Space] + public MeshRenderer _shockLayer; + [ColorUsage(true, true)] + public Color _shockLayerColor = new Color(0.3569f, 0.7843f, 1f, 1f); + public float _shockLayerStartRadius = 1000f; + public float _shockLayerFullRadius = 10000f; + public float _shockLayerTrailLength = 300f; + public float _shockLayerTrailFlare = 100f; + + private LOD[] _atmosphereLODs; + + public StarEvolutionController _starEvolutionController; + + public SunController _sunController; + + public void Awake() + { + if (s_matPropBlock_Atmosphere == null) + { + s_matPropBlock_Atmosphere = new MaterialPropertyBlock(); + s_propID_SunIntensity = Shader.PropertyToID("_SunIntensity"); + s_propID_Tint = Shader.PropertyToID("_Tint"); + s_matPropBlock_ShockLayer = new MaterialPropertyBlock(); + s_propID_Color = Shader.PropertyToID("_Color"); + s_propID_WorldToLocalShockMatrix = Shader.PropertyToID("_WorldToShockLocalMatrix"); + s_propID_Dir = Shader.PropertyToID("_Dir"); + s_propID_Length = Shader.PropertyToID("_Length"); + s_propID_Flare = Shader.PropertyToID("_Flare"); + s_propID_TrailFade = Shader.PropertyToID("_TrailFade"); + s_propID_GradientLerp = Shader.PropertyToID("_GradientLerp"); + s_propID_MainTex_ST = Shader.PropertyToID("_MainTex_ST"); + } + } + + public void Start() + { + SupernovaEffectHandler.RegisterPlanetEffect(this); + if (_atmosphere != null) _atmosphereLODs = _atmosphere.GetLODs(); + if (_fog != null) + { + _fogOrigTint = _fog.fogTint; + _fogImpostor = _fog.fogImpostor; + } + else if (_fogImpostor != null) + { + _fogOrigTint = _fogImpostor.material.GetColor(s_propID_Tint); + } + if (_shockLayer != null) _shockLayer.enabled = false; + } + + public void OnDestroy() + { + SupernovaEffectHandler.UnregisterPlanetEffect(this); + } + + public void Enable() + { + enabled = true; + } + + public void Disable() + { + enabled = false; + if (_shockLayer != null) _shockLayer.enabled = false; + } + + public void Update() + { + SupernovaEffectHandler.GetNearestStarSupernova(this); + if (_starEvolutionController != null) + { + if (_starEvolutionController.HasSupernovaStarted()) + { + if (_shockLayer != null) + { + if (!_shockLayer.enabled) _shockLayer.enabled = true; + Vector3 dir = Vector3.Normalize(transform.position - _starEvolutionController.transform.position); + s_matPropBlock_ShockLayer.SetColor(s_propID_Color, _starEvolutionController.SupernovaColour != null ? _starEvolutionController.SupernovaColour.ToColor() : new Color(0.3569f, 0.7843f, 1f, 1f)); + s_matPropBlock_ShockLayer.SetMatrix(s_propID_WorldToLocalShockMatrix, Matrix4x4.TRS(transform.position, Quaternion.LookRotation(dir, Vector3.up), Vector3.one).inverse); + s_matPropBlock_ShockLayer.SetVector(s_propID_Dir, dir); + s_matPropBlock_ShockLayer.SetFloat(s_propID_Length, _shockLayerTrailLength); + s_matPropBlock_ShockLayer.SetFloat(s_propID_Flare, _shockLayerTrailFlare); + s_matPropBlock_ShockLayer.SetFloat(s_propID_TrailFade, 1f - Mathf.InverseLerp(_shockLayerStartRadius, _shockLayerFullRadius, _starEvolutionController.GetSupernovaRadius())); + s_matPropBlock_ShockLayer.SetFloat(s_propID_GradientLerp, 0); + s_matPropBlock_ShockLayer.SetVector(s_propID_MainTex_ST, _shockLayer.sharedMaterial.GetVector(s_propID_MainTex_ST) with { w = -Time.timeSinceLevelLoad }); + _shockLayer.SetPropertyBlock(s_matPropBlock_ShockLayer); + } + } + if (_starEvolutionController.IsCollapsing()) + { + float collapseProgress = _starEvolutionController.GetCollapseProgress(); + + if (_ambientLight != null) _ambientLight.intensity = _ambientLightOrigIntensity * (1f - collapseProgress); + + if (_atmosphere != null) + { + s_matPropBlock_Atmosphere.SetFloat(s_propID_SunIntensity, 1f - collapseProgress); + + foreach (var lod in _atmosphereLODs) + foreach (var renderer in lod.renderers) + renderer.SetPropertyBlock(s_matPropBlock_Atmosphere); + } + + if (_atmosphereRenderer != null) + { + s_matPropBlock_Atmosphere.SetFloat(s_propID_SunIntensity, 1f - collapseProgress); + + _atmosphereRenderer.SetPropertyBlock(s_matPropBlock_Atmosphere); + } + + if (_fog != null) _fog.fogTint = Color.Lerp(_fogOrigTint, Color.black, collapseProgress); + + if (_fogImpostor != null) _fogImpostor.material.SetColor(s_propID_Tint, Color.Lerp(_fogOrigTint, Color.black, collapseProgress)); + } + else + { + if (_shockLayer != null) _shockLayer.enabled = false; + } + } + else if (_sunController != null) + { + if (_sunController.HasSupernovaStarted()) + { + if (_shockLayer != null) + { + if (!_shockLayer.enabled) _shockLayer.enabled = true; + Vector3 dir = Vector3.Normalize(transform.position - _sunController.transform.position); + s_matPropBlock_ShockLayer.SetColor(s_propID_Color, _shockLayerColor); + s_matPropBlock_ShockLayer.SetMatrix(s_propID_WorldToLocalShockMatrix, Matrix4x4.TRS(transform.position, Quaternion.LookRotation(dir, Vector3.up), Vector3.one).inverse); + s_matPropBlock_ShockLayer.SetVector(s_propID_Dir, dir); + s_matPropBlock_ShockLayer.SetFloat(s_propID_Length, _shockLayerTrailLength); + s_matPropBlock_ShockLayer.SetFloat(s_propID_Flare, _shockLayerTrailFlare); + s_matPropBlock_ShockLayer.SetFloat(s_propID_TrailFade, 1f - Mathf.InverseLerp(_shockLayerStartRadius, _shockLayerFullRadius, _sunController.GetSupernovaRadius())); + s_matPropBlock_ShockLayer.SetFloat(s_propID_GradientLerp, 0); + s_matPropBlock_ShockLayer.SetVector(s_propID_MainTex_ST, _shockLayer.sharedMaterial.GetVector(s_propID_MainTex_ST) with { w = -Time.timeSinceLevelLoad }); + _shockLayer.SetPropertyBlock(s_matPropBlock_ShockLayer); + } + } + else if (_sunController._collapseStarted) + { + float collapseProgress = _sunController.GetCollapseProgress(); + + if (_ambientLight != null) _ambientLight.intensity = _ambientLightOrigIntensity * (1f - collapseProgress); + + if (_atmosphere != null) + { + s_matPropBlock_Atmosphere.SetFloat(s_propID_SunIntensity, 1f - collapseProgress); + + foreach (var lod in _atmosphereLODs) + foreach (var renderer in lod.renderers) + renderer.SetPropertyBlock(s_matPropBlock_Atmosphere); + } + + if (_atmosphereRenderer != null) + { + s_matPropBlock_Atmosphere.SetFloat(s_propID_SunIntensity, 1f - collapseProgress); + + _atmosphereRenderer.SetPropertyBlock(s_matPropBlock_Atmosphere); + } + + if (_fog != null) _fog.fogTint = Color.Lerp(_fogOrigTint, Color.black, collapseProgress); + + if (_fogImpostor != null) _fogImpostor.material.SetColor(s_propID_Tint, Color.Lerp(_fogOrigTint, Color.black, collapseProgress)); + } + else + { + if (_shockLayer != null) _shockLayer.enabled = false; + } + } + else + { + if (_shockLayer != null) _shockLayer.enabled = false; + } + } + } +} diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 4120d873..2d66070c 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -1,4 +1,5 @@ using NewHorizons.Builder.Body; +using NewHorizons.Handlers; using NewHorizons.Utility; using System; using System.Collections.Generic; @@ -19,6 +20,7 @@ namespace NewHorizons.Components.SizeControllers public bool WillExplode { get; set; } public MColor StartColour { get; set; } public MColor EndColour { get; set; } + public MColor SupernovaColour { get; set; } public Texture normalRamp; public Texture collapseRamp; @@ -48,6 +50,8 @@ namespace NewHorizons.Components.SizeControllers private bool _isSupernova; private float _supernovaStartTime; + public bool _disabled; + private Material _collapseStartSurfaceMaterial; private Material _collapseEndSurfaceMaterial; private Material _startSurfaceMaterial; @@ -58,7 +62,10 @@ namespace NewHorizons.Components.SizeControllers private StarEvolutionController _proxy; + public UnityEvent CollapseStart = new UnityEvent(); + public UnityEvent CollapseStop = new UnityEvent(); public UnityEvent SupernovaStart = new UnityEvent(); + public UnityEvent SupernovaStop = new UnityEvent(); private float maxScale; private float minScale; @@ -148,6 +155,8 @@ namespace NewHorizons.Components.SizeControllers _flareEmitter = GetComponentInChildren(); _surfaceMaterial = supernova._surface._materials[0]; + SupernovaEffectHandler.RegisterStar(this); + var secondsElapsed = TimeLoop.GetSecondsElapsed(); var lifespanInSeconds = lifespan * 60; if (secondsElapsed >= lifespanInSeconds) @@ -164,6 +173,7 @@ namespace NewHorizons.Components.SizeControllers public void OnDestroy() { + SupernovaEffectHandler.UnregisterStar(this); } public void SetProxy(StarEvolutionController proxy) @@ -260,6 +270,8 @@ namespace NewHorizons.Components.SizeControllers if (controller != null) StarLightController.RemoveStar(controller); + _disabled = true; + // Just turn off the star entirely base.gameObject.SetActive(false); @@ -289,6 +301,7 @@ namespace NewHorizons.Components.SizeControllers Logger.LogVerbose($"{gameObject.transform.root.name} started collapse"); + CollapseStart.Invoke(); _isCollapsing = true; _collapseStartSize = CurrentScale; _collapseTimer = 0f; @@ -303,6 +316,7 @@ namespace NewHorizons.Components.SizeControllers Logger.LogVerbose($"{gameObject.transform.root.name} stopped collapse"); + CollapseStop.Invoke(); _isCollapsing = false; supernova._surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial); @@ -332,6 +346,7 @@ namespace NewHorizons.Components.SizeControllers Logger.LogVerbose($"{gameObject.transform.root.name} stopped supernova"); + SupernovaStop.Invoke(); supernova.enabled = false; _isSupernova = false; if (atmosphere != null) atmosphere.SetActive(true); @@ -354,6 +369,24 @@ namespace NewHorizons.Components.SizeControllers if (_proxy != null) _proxy.StopSupernova(); } + public bool IsCollapsing() => _isCollapsing; + + public float GetCollapseProgress() => _collapseTimer / collapseTime; + + public bool HasSupernovaStarted() => _isSupernova; + + public bool IsPointInsideSupernova(Vector3 worldPosition) => _isSupernova && (worldPosition - transform.position).sqrMagnitude < (supernova.GetSupernovaRadius() * supernova.GetSupernovaRadius()); + + public bool IsPointInsideMaxSupernova(Vector3 worldPosition) => (worldPosition - transform.position).sqrMagnitude < (supernovaSize * supernovaSize); + + public float GetDistanceToSupernova(Vector3 worldPosition) => Vector3.Distance(worldPosition, transform.position) - supernova.GetSupernovaRadius(); + + public float GetDistanceToMaxSupernova(Vector3 worldPosition) => Vector3.Distance(worldPosition, transform.position) - supernovaSize; + + public float GetSupernovaRadius() => supernova.GetSupernovaRadius(); + + public float GetMaxSupernovaRadius() => supernovaSize; + protected new void FixedUpdate() { // If we've gone supernova and its been 45 seconds that means it has faded out and is gone diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index 2d434f66..aad6549c 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -56,6 +56,11 @@ namespace NewHorizons.External.Modules /// public bool hasMapMarker; + /// + /// Does this planet have a shock effect when the nearest star goes supernova? + /// + [DefaultValue(true)] public bool hasSupernovaShockEffect = true; + /// /// Can this planet survive entering a star? /// diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index bffe3fea..61eb5d20 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -31,11 +31,12 @@ namespace NewHorizons.Handlers _existingBodyDict = new(); _customBodyDict = new(); - + // Set up stars // Need to manage this when there are multiple stars var sun = SearchUtilities.Find("Sun_Body"); var starController = sun.AddComponent(); + SupernovaEffectHandler.RegisterSun(sun.GetComponent()); starController.Light = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); starController.AmbientLight = SearchUtilities.Find("Sun_Body/AmbientLight_SUN").GetComponent(); starController.FaceActiveCamera = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); @@ -467,9 +468,10 @@ namespace NewHorizons.Handlers { var sphereOfInfluence = GetSphereOfInfluence(body); + Light ambientLight = null; if (body.Config.Base.ambientLight != 0) { - AmbientLightBuilder.Make(go, sector, sphereOfInfluence, body.Config.Base.ambientLight); + ambientLight = AmbientLightBuilder.Make(go, sector, sphereOfInfluence, body.Config.Base.ambientLight); } if (body.Config.Base.groundSize != 0) @@ -477,17 +479,19 @@ namespace NewHorizons.Handlers GeometryBuilder.Make(go, sector, body.Config.Base.groundSize); } + GameObject heightMap = null; if (body.Config.HeightMap != null) { // resolution = tris on edge per face // divide by 4 to account for all the way around the equator var res = body.Config.HeightMap.resolution / 4; - HeightMapBuilder.Make(go, sector, body.Config.HeightMap, body.Mod, res, true); + heightMap = HeightMapBuilder.Make(go, sector, body.Config.HeightMap, body.Mod, res, true); } + GameObject procGen = null; if (body.Config.ProcGen != null) { - ProcGenBuilder.Make(go, sector, body.Config.ProcGen); + procGen = ProcGenBuilder.Make(go, sector, body.Config.ProcGen); } if (body.Config.Star != null) @@ -539,7 +543,8 @@ namespace NewHorizons.Handlers } var willHaveCloak = body.Config.Cloak != null && body.Config.Cloak.radius != 0f; - + PlanetaryFogController fog = null; + LODGroup atmosphere = null; if (body.Config.Atmosphere != null) { var surfaceSize = body.Config.Base.surfaceSize; @@ -556,9 +561,11 @@ namespace NewHorizons.Handlers EffectsBuilder.Make(go, sector, body.Config, surfaceSize); if (body.Config.Atmosphere.fogSize != 0) - FogBuilder.Make(go, sector, body.Config.Atmosphere); + { + fog = FogBuilder.Make(go, sector, body.Config.Atmosphere); + } - AtmosphereBuilder.Make(go, sector, body.Config.Atmosphere, surfaceSize); + atmosphere = AtmosphereBuilder.Make(go, sector, body.Config.Atmosphere, surfaceSize).GetComponentInChildren(); } if (body.Config.Props != null) @@ -577,6 +584,11 @@ namespace NewHorizons.Handlers CloakBuilder.Make(go, sector, rb, body.Config.Cloak, !body.Config.ReferenceFrame.hideInMap, body.Mod); } + if (body.Config.Base.hasSupernovaShockEffect && body.Config.Star == null && body.Config.name != "Sun" && body.Config.FocalPoint == null) + { + SupernovaEffectBuilder.Make(go, sector, body.Config, heightMap, procGen, ambientLight, fog, atmosphere, null, fog?._fogImpostor); + } + return go; } diff --git a/NewHorizons/Handlers/SupernovaEffectHandler.cs b/NewHorizons/Handlers/SupernovaEffectHandler.cs new file mode 100644 index 00000000..760b99b3 --- /dev/null +++ b/NewHorizons/Handlers/SupernovaEffectHandler.cs @@ -0,0 +1,90 @@ +using NewHorizons.Components; +using NewHorizons.Components.SizeControllers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Handlers +{ + public class SupernovaEffectHandler + { + private static List _supernovaPlanetEffectControllers = new List(); + private static List _starEvolutionControllers = new List(); + private static SunController _sunController; + + public static void RegisterStar(StarEvolutionController starEvolutionController) + { + _starEvolutionControllers.SafeAdd(starEvolutionController); + } + + public static void UnregisterStar(StarEvolutionController starEvolutionController) + { + _starEvolutionControllers.Remove(starEvolutionController); + } + + public static void RegisterSun(SunController sunController) + { + _sunController = sunController; + } + + public static void UnregisterSun() + { + _sunController = null; + } + + public static void RegisterPlanetEffect(NHSupernovaPlanetEffectController supernovaPlanetEffectController) + { + _supernovaPlanetEffectControllers.SafeAdd(supernovaPlanetEffectController); + } + + public static void UnregisterPlanetEffect(NHSupernovaPlanetEffectController supernovaPlanetEffectController) + { + _supernovaPlanetEffectControllers.Remove(supernovaPlanetEffectController); + } + + public static void GetNearestStarSupernova(NHSupernovaPlanetEffectController supernovaPlanetEffectController) + { + if (supernovaPlanetEffectController == null) return; + + StarEvolutionController nearestStarEvolutionController = null; + float nearestDistance = float.MaxValue; + foreach (StarEvolutionController starEvolutionController in _starEvolutionControllers) + { + if (starEvolutionController == null) continue; + if (starEvolutionController._disabled) continue; + float distance = (supernovaPlanetEffectController.transform.position - starEvolutionController.transform.position).sqrMagnitude; + if (starEvolutionController.IsPointInsideMaxSupernova(supernovaPlanetEffectController.transform.position) && distance < nearestDistance) + { + nearestDistance = distance; + nearestStarEvolutionController = starEvolutionController; + } + } + + if (_sunController != null && _sunController.gameObject.activeSelf) + { + float distance = (supernovaPlanetEffectController.transform.position - _sunController.transform.position).sqrMagnitude; + if (InPointInsideSunSupernova(supernovaPlanetEffectController) && distance < nearestDistance) + { + supernovaPlanetEffectController._sunController = _sunController; + supernovaPlanetEffectController._starEvolutionController = null; + } + else + { + supernovaPlanetEffectController._sunController = null; + supernovaPlanetEffectController._starEvolutionController = nearestStarEvolutionController; + } + } + else + { + supernovaPlanetEffectController._sunController = null; + supernovaPlanetEffectController._starEvolutionController = nearestStarEvolutionController; + } + } + + public static SunController GetSunController() => _sunController; + + public static bool InPointInsideSunSupernova(NHSupernovaPlanetEffectController supernovaPlanetEffectController) => _sunController != null && (supernovaPlanetEffectController.transform.position - _sunController.transform.position).sqrMagnitude < 2500000000f;//(50000f*50000f); + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 7b51f660..1215468b 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -302,6 +302,14 @@ namespace NewHorizons AtmosphereBuilder.Init(); BrambleNodeBuilder.Init(BodyDict[CurrentStarSystem].Select(x => x.Config).Where(x => x.Bramble?.dimension != null).ToArray()); + if (isSolarSystem) + { + foreach (var supernovaPlanetEffectController in GameObject.FindObjectsOfType()) + { + SupernovaEffectBuilder.ReplaceVanillaWithNH(supernovaPlanetEffectController); + } + } + if (isSolarSystem) { PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]); From c7d8119b1db4e4f5c234f761cb82b04d423a66f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 15 Aug 2022 10:54:48 +0000 Subject: [PATCH 08/18] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 9a23d4df..d8d4db3c 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -450,6 +450,11 @@ "type": "boolean", "description": "If the body should have a marker on the map screen." }, + "hasSupernovaShockEffect": { + "type": "boolean", + "description": "Does this planet have a shock effect when the nearest star goes supernova?", + "default": true + }, "invulnerableToSun": { "type": "boolean", "description": "Can this planet survive entering a star?" From cd65a23e129f337fd916bc9e014098d100fd8e43 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 07:03:29 -0400 Subject: [PATCH 09/18] Simplify --- NewHorizons/Handlers/SupernovaEffectHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/SupernovaEffectHandler.cs b/NewHorizons/Handlers/SupernovaEffectHandler.cs index 760b99b3..cd27312a 100644 --- a/NewHorizons/Handlers/SupernovaEffectHandler.cs +++ b/NewHorizons/Handlers/SupernovaEffectHandler.cs @@ -55,7 +55,7 @@ namespace NewHorizons.Handlers if (starEvolutionController == null) continue; if (starEvolutionController._disabled) continue; float distance = (supernovaPlanetEffectController.transform.position - starEvolutionController.transform.position).sqrMagnitude; - if (starEvolutionController.IsPointInsideMaxSupernova(supernovaPlanetEffectController.transform.position) && distance < nearestDistance) + if (distance < (starEvolutionController.supernovaSize * starEvolutionController.supernovaSize) && distance < nearestDistance) { nearestDistance = distance; nearestStarEvolutionController = starEvolutionController; @@ -65,7 +65,7 @@ namespace NewHorizons.Handlers if (_sunController != null && _sunController.gameObject.activeSelf) { float distance = (supernovaPlanetEffectController.transform.position - _sunController.transform.position).sqrMagnitude; - if (InPointInsideSunSupernova(supernovaPlanetEffectController) && distance < nearestDistance) + if (distance < 2500000000f && distance < nearestDistance) { supernovaPlanetEffectController._sunController = _sunController; supernovaPlanetEffectController._starEvolutionController = null; From 14c39eb052fd3d4bd1c07fe7e6cbc9b5427a5bb4 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 09:22:54 -0400 Subject: [PATCH 10/18] Default shock layer color --- NewHorizons/Components/NHSupernovaPlanetEffectController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Components/NHSupernovaPlanetEffectController.cs b/NewHorizons/Components/NHSupernovaPlanetEffectController.cs index 5f964a55..c2c8b48d 100644 --- a/NewHorizons/Components/NHSupernovaPlanetEffectController.cs +++ b/NewHorizons/Components/NHSupernovaPlanetEffectController.cs @@ -19,8 +19,9 @@ namespace NewHorizons.Components public Color _fogOrigTint; [Space] public MeshRenderer _shockLayer; + public static readonly Color _shockLayerDefaultColor = new Color(0.3569f, 0.7843f, 1f, 1f); [ColorUsage(true, true)] - public Color _shockLayerColor = new Color(0.3569f, 0.7843f, 1f, 1f); + public Color _shockLayerColor = _shockLayerDefaultColor; public float _shockLayerStartRadius = 1000f; public float _shockLayerFullRadius = 10000f; public float _shockLayerTrailLength = 300f; @@ -94,7 +95,7 @@ namespace NewHorizons.Components { if (!_shockLayer.enabled) _shockLayer.enabled = true; Vector3 dir = Vector3.Normalize(transform.position - _starEvolutionController.transform.position); - s_matPropBlock_ShockLayer.SetColor(s_propID_Color, _starEvolutionController.SupernovaColour != null ? _starEvolutionController.SupernovaColour.ToColor() : new Color(0.3569f, 0.7843f, 1f, 1f)); + s_matPropBlock_ShockLayer.SetColor(s_propID_Color, _starEvolutionController.SupernovaColour != null ? _starEvolutionController.SupernovaColour.ToColor() : _shockLayerColor); s_matPropBlock_ShockLayer.SetMatrix(s_propID_WorldToLocalShockMatrix, Matrix4x4.TRS(transform.position, Quaternion.LookRotation(dir, Vector3.up), Vector3.one).inverse); s_matPropBlock_ShockLayer.SetVector(s_propID_Dir, dir); s_matPropBlock_ShockLayer.SetFloat(s_propID_Length, _shockLayerTrailLength); From 2cba81129f6304739c20345a855b1a3bb8fe5bca Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 09:24:50 -0400 Subject: [PATCH 11/18] Check if active --- NewHorizons/Handlers/SupernovaEffectHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Handlers/SupernovaEffectHandler.cs b/NewHorizons/Handlers/SupernovaEffectHandler.cs index cd27312a..af9dbee3 100644 --- a/NewHorizons/Handlers/SupernovaEffectHandler.cs +++ b/NewHorizons/Handlers/SupernovaEffectHandler.cs @@ -53,7 +53,7 @@ namespace NewHorizons.Handlers foreach (StarEvolutionController starEvolutionController in _starEvolutionControllers) { if (starEvolutionController == null) continue; - if (starEvolutionController._disabled) continue; + if (starEvolutionController._disabled || !(starEvolutionController.gameObject.activeSelf && starEvolutionController.gameObject.activeInHierarchy)) continue; float distance = (supernovaPlanetEffectController.transform.position - starEvolutionController.transform.position).sqrMagnitude; if (distance < (starEvolutionController.supernovaSize * starEvolutionController.supernovaSize) && distance < nearestDistance) { From c674d5c48a163382d014bf880c6f1a905fde1cc4 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 15 Aug 2022 21:08:48 -0400 Subject: [PATCH 12/18] Add splash effects --- .../Builder/General/DetectorBuilder.cs | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/General/DetectorBuilder.cs b/NewHorizons/Builder/General/DetectorBuilder.cs index 82671951..9f815d21 100644 --- a/NewHorizons/Builder/General/DetectorBuilder.cs +++ b/NewHorizons/Builder/General/DetectorBuilder.cs @@ -1,5 +1,7 @@ using NewHorizons.Components.Orbital; using NewHorizons.External.Configs; +using NewHorizons.Utility; +using System.Collections.Generic; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.General @@ -33,7 +35,58 @@ namespace NewHorizons.Builder.General OWRB.RegisterAttachedFluidDetector(fluidDetector); - // Could copy the splash from the interloper as well some day + var splashEffects = new List(); + + var cometDetector = SearchUtilities.Find("Comet_Body/Detector_CO")?.GetComponent(); + if (cometDetector != null) + { + foreach (var splashEffect in cometDetector._splashEffects) + { + splashEffects.Add(new SplashEffect + { + fluidType = splashEffect.fluidType, + ignoreSphereAligment = splashEffect.ignoreSphereAligment, + triggerEvent = splashEffect.triggerEvent, + minImpactSpeed = 15, + splashPrefab = splashEffect.splashPrefab + }); + } + } + + var islandDetector = SearchUtilities.Find("GabbroIsland_Body/Detector_GabbroIsland")?.GetComponent(); + if (islandDetector != null) + { + foreach (var splashEffect in islandDetector._splashEffects) + { + splashEffects.Add(new SplashEffect + { + fluidType = splashEffect.fluidType, + ignoreSphereAligment = splashEffect.ignoreSphereAligment, + triggerEvent = splashEffect.triggerEvent, + minImpactSpeed = 15, + splashPrefab = splashEffect.splashPrefab + }); + } + } + + var shipDetector = SearchUtilities.Find("Ship_Body/ShipDetector")?.GetComponent(); + if (shipDetector != null) + { + foreach (var splashEffect in shipDetector._splashEffects) + { + if (splashEffect.fluidType == FluidVolume.Type.SAND) + splashEffects.Add(new SplashEffect + { + fluidType = splashEffect.fluidType, + ignoreSphereAligment = splashEffect.ignoreSphereAligment, + triggerEvent = splashEffect.triggerEvent, + minImpactSpeed = 15, + splashPrefab = splashEffect.splashPrefab + }); + } + } + + fluidDetector._splashEffects = splashEffects.ToArray(); } SetDetector(primaryBody, astroObject, forceDetector); @@ -113,4 +166,4 @@ namespace NewHorizons.Builder.General secondaryCFD._inheritElement0 = false; } } -} +} \ No newline at end of file From 41622fb0a73193c5e958fb9ffda93eaa7c7cfcfd Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Tue, 16 Aug 2022 02:16:54 -0400 Subject: [PATCH 13/18] Clarify --- NewHorizons/Patches/LocatorPatches.cs | 7 +++++++ NewHorizons/Utility/AstroObjectLocator.cs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Patches/LocatorPatches.cs b/NewHorizons/Patches/LocatorPatches.cs index 1a95dfbb..91a32e93 100644 --- a/NewHorizons/Patches/LocatorPatches.cs +++ b/NewHorizons/Patches/LocatorPatches.cs @@ -41,6 +41,9 @@ namespace NewHorizons.Patches __result = __result || Components.CloakSectorController.isShipInside; } + // Locator Fixes + // Vanilla doesn't register these AstroObjects for some reason. So here is a fix. + [HarmonyPrefix] [HarmonyPatch(typeof(Locator), nameof(Locator.GetAstroObject))] public static bool Locator_GetAstroObject(AstroObject.Name astroObjectName, ref AstroObject __result) @@ -76,6 +79,8 @@ namespace NewHorizons.Patches public static bool Locator_RegisterAstroObject(AstroObject astroObject) { if (astroObject.GetAstroObjectName() == AstroObject.Name.None) return false; + + // Sun Station name change because for some dumb reason it doesn't use AstroObject.Name.SunStation if (!string.IsNullOrEmpty(astroObject._customName) && astroObject._customName.Equals("Sun Station")) { if (astroObject.gameObject.name == "SunStation_Body") @@ -84,9 +89,11 @@ namespace NewHorizons.Patches _sunStation = astroObject; return false; } + // Debris uses same custom name because morbius, so let us change that. else if (astroObject.gameObject.name == "SS_Debris_Body") astroObject._customName = "Sun Station Debris"; return true; } + switch (astroObject.GetAstroObjectName()) { case AstroObject.Name.Eye: diff --git a/NewHorizons/Utility/AstroObjectLocator.cs b/NewHorizons/Utility/AstroObjectLocator.cs index bfe23bfe..317ffc41 100644 --- a/NewHorizons/Utility/AstroObjectLocator.cs +++ b/NewHorizons/Utility/AstroObjectLocator.cs @@ -158,7 +158,7 @@ namespace NewHorizons.Utility .Select(x => x.gameObject) .Where(x => x.name == "SS_Debris_Body")); break; - // For some dumb reason the sun station doesn't use AstroObject.Name.SunStation + // Just in case GetChildren runs before sun station's name is changed case AstroObject.Name.CustomString: if (primary._customName.Equals("Sun Station")) { From c42318542e43ea97d7c9fbb4f18638d91fc12eee Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Tue, 16 Aug 2022 05:41:54 -0400 Subject: [PATCH 14/18] Add plasma effect from probe to player --- NewHorizons/Main.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 1215468b..048c9464 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -321,6 +321,7 @@ namespace NewHorizons LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this); StarChartHandler.Init(SystemDict.Values.ToArray()); + if (isSolarSystem) { // Warp drive @@ -406,7 +407,17 @@ namespace NewHorizons ssrLight.spotAngle = 179; ssrLight.range = Main.FurthestOrbit * (4f/3f); ssrLight.intensity = 0.001f; - + + var fluid = playerBody.FindChild("PlayerDetector").GetComponent(); + fluid._splashEffects = fluid._splashEffects.AddToArray(new SplashEffect + { + fluidType = FluidVolume.Type.PLASMA, + ignoreSphereAligment = false, + minImpactSpeed = 15, + splashPrefab = SearchUtilities.Find("Probe_Body/ProbeDetector").GetComponent()._splashEffects.FirstOrDefault(sfx => sfx.fluidType == FluidVolume.Type.PLASMA).splashPrefab, + triggerEvent = SplashEffect.TriggerEvent.OnEntry + }); + try { Logger.Log($"Star system finished loading [{Instance.CurrentStarSystem}]"); From 330a9d91e551efc378b96f521f80a95d24c2a198 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 17 Aug 2022 21:43:44 -0400 Subject: [PATCH 15/18] Don't use height map --- NewHorizons/Builder/Body/ProxyBuilder.cs | 5 ++--- .../Builder/Body/SupernovaEffectBuilder.cs | 19 +++++-------------- NewHorizons/Handlers/PlanetCreationHandler.cs | 5 ++--- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 4ff3c84d..49befd13 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -44,10 +44,9 @@ namespace NewHorizons.Builder.Body // We want to take the largest size I think var realSize = body.Config.Base.surfaceSize; - GameObject heightMap = null; if (body.Config.HeightMap != null) { - heightMap = HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20); + HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20); if (realSize < body.Config.HeightMap.maxHeight) realSize = body.Config.HeightMap.maxHeight; } @@ -158,7 +157,7 @@ namespace NewHorizons.Builder.Body if (body.Config.Base.hasSupernovaShockEffect && body.Config.Star == null && body.Config.name != "Sun" && body.Config.FocalPoint == null) { - proxyController._supernovaPlanetEffectController = SupernovaEffectBuilder.Make(newProxy, null, body.Config, heightMap, procGen, null, null, null, proxyController._atmosphere, proxyController._fog); + proxyController._supernovaPlanetEffectController = SupernovaEffectBuilder.Make(newProxy, null, body.Config, procGen, null, null, null, proxyController._atmosphere, proxyController._fog); } // Remove all collisions if there are any diff --git a/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs b/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs index 746a976f..80d6ea31 100644 --- a/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs +++ b/NewHorizons/Builder/Body/SupernovaEffectBuilder.cs @@ -9,7 +9,7 @@ namespace NewHorizons.Builder.Body { public static class SupernovaEffectBuilder { - public static NHSupernovaPlanetEffectController Make(GameObject planetGO, Sector sector, PlanetConfig config, GameObject heightMap, GameObject procGen, Light ambientLight, PlanetaryFogController fog, LODGroup atmosphere, Renderer atmosphereRenderer, Renderer fogImpostor) + public static NHSupernovaPlanetEffectController Make(GameObject planetGO, Sector sector, PlanetConfig config, GameObject procGen, Light ambientLight, PlanetaryFogController fog, LODGroup atmosphere, Renderer atmosphereRenderer, Renderer fogImpostor) { var vanillaController = planetGO.GetComponentInChildren(); if (vanillaController != null) @@ -129,20 +129,11 @@ namespace NewHorizons.Builder.Body shockLayer.transform.position = planetGO.transform.position; shockLayer.transform.localScale = Vector3.one * biggestSize * 1.1f; - if (!noMeshChange) + if (!noMeshChange && procGen != null) { - if (heightMap != null) - { - shockLayer.GetComponent().sharedMesh = heightMap.GetComponent().sharedMesh; - shockLayer.transform.localScale = Vector3.one * 1.1f; - shockLayer.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); - } - else if (procGen != null) - { - shockLayer.GetComponent().sharedMesh = procGen.GetComponent().sharedMesh; - shockLayer.transform.localScale = Vector3.one * 1.1f; - shockLayer.transform.rotation = Quaternion.Euler(90, 0, 0); - } + shockLayer.GetComponent().sharedMesh = procGen.GetComponent().sharedMesh; + shockLayer.transform.localScale = Vector3.one * 1.1f; + shockLayer.transform.rotation = Quaternion.Euler(90, 0, 0); } return supernovaEffectController; diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 5b6f1eb1..4beee488 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -476,13 +476,12 @@ namespace NewHorizons.Handlers GeometryBuilder.Make(go, sector, body.Config.Base.groundSize); } - GameObject heightMap = null; if (body.Config.HeightMap != null) { // resolution = tris on edge per face // divide by 4 to account for all the way around the equator var res = body.Config.HeightMap.resolution / 4; - heightMap = HeightMapBuilder.Make(go, sector, body.Config.HeightMap, body.Mod, res, true); + HeightMapBuilder.Make(go, sector, body.Config.HeightMap, body.Mod, res, true); } GameObject procGen = null; @@ -583,7 +582,7 @@ namespace NewHorizons.Handlers if (body.Config.Base.hasSupernovaShockEffect && body.Config.Star == null && body.Config.name != "Sun" && body.Config.FocalPoint == null) { - SupernovaEffectBuilder.Make(go, sector, body.Config, heightMap, procGen, ambientLight, fog, atmosphere, null, fog?._fogImpostor); + SupernovaEffectBuilder.Make(go, sector, body.Config, procGen, ambientLight, fog, atmosphere, null, fog?._fogImpostor); } return go; From 57771cae0ec8344ce55d854bc8c3fdc9922ea5ff Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 17 Aug 2022 21:56:28 -0400 Subject: [PATCH 16/18] Merge --- NewHorizons/Main.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 048c9464..4e7c8114 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -308,10 +308,7 @@ namespace NewHorizons { SupernovaEffectBuilder.ReplaceVanillaWithNH(supernovaPlanetEffectController); } - } - if (isSolarSystem) - { PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]); VesselWarpHandler.LoadVessel(); From 38dd12c8e6881b374d2ec5303c4429027fa3f97e Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 17 Aug 2022 22:04:36 -0400 Subject: [PATCH 17/18] Remove disabled --- .../Components/SizeControllers/StarEvolutionController.cs | 4 ---- NewHorizons/Handlers/SupernovaEffectHandler.cs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 2d66070c..0fa3a4d0 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -50,8 +50,6 @@ namespace NewHorizons.Components.SizeControllers private bool _isSupernova; private float _supernovaStartTime; - public bool _disabled; - private Material _collapseStartSurfaceMaterial; private Material _collapseEndSurfaceMaterial; private Material _startSurfaceMaterial; @@ -270,8 +268,6 @@ namespace NewHorizons.Components.SizeControllers if (controller != null) StarLightController.RemoveStar(controller); - _disabled = true; - // Just turn off the star entirely base.gameObject.SetActive(false); diff --git a/NewHorizons/Handlers/SupernovaEffectHandler.cs b/NewHorizons/Handlers/SupernovaEffectHandler.cs index af9dbee3..35df25e5 100644 --- a/NewHorizons/Handlers/SupernovaEffectHandler.cs +++ b/NewHorizons/Handlers/SupernovaEffectHandler.cs @@ -53,7 +53,7 @@ namespace NewHorizons.Handlers foreach (StarEvolutionController starEvolutionController in _starEvolutionControllers) { if (starEvolutionController == null) continue; - if (starEvolutionController._disabled || !(starEvolutionController.gameObject.activeSelf && starEvolutionController.gameObject.activeInHierarchy)) continue; + if (!(starEvolutionController.gameObject.activeSelf && starEvolutionController.gameObject.activeInHierarchy)) continue; float distance = (supernovaPlanetEffectController.transform.position - starEvolutionController.transform.position).sqrMagnitude; if (distance < (starEvolutionController.supernovaSize * starEvolutionController.supernovaSize) && distance < nearestDistance) { From 6a6a090948441204e1e1fc62c2b2856ea7e7e875 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 17 Aug 2022 22:32:06 -0400 Subject: [PATCH 18/18] Disable fluid volume on supernova --- NewHorizons/Builder/Body/StarBuilder.cs | 2 ++ .../Components/SizeControllers/StarEvolutionController.cs | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index ab76c9e2..10b27ba1 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -148,6 +148,8 @@ namespace NewHorizons.Builder.Body controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; controller._destructionVolume = deathVolume.GetComponent(); controller._planetDestructionVolume = planetDestructionVolume.GetComponent(); + controller._destructionFluidVolume = planetDestructionVolume.GetComponent(); + controller._planetDestructionFluidVolume = planetDestructionVolume.GetComponent(); if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture)) { controller.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture); diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 0fa3a4d0..afb81949 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -32,6 +32,8 @@ namespace NewHorizons.Components.SizeControllers private HeatHazardVolume _heatVolume; public DestructionVolume _destructionVolume; public DestructionVolume _planetDestructionVolume; + public SimpleFluidVolume _destructionFluidVolume; + public SimpleFluidVolume _planetDestructionFluidVolume; private SolarFlareEmitter _flareEmitter; private MapMarker _mapMarker; private OWRigidbody _rigidbody; @@ -129,7 +131,7 @@ namespace NewHorizons.Components.SizeControllers } _heatVolume = GetComponentInChildren(); - if (_destructionVolume != null) _destructionVolume = GetComponentInChildren(); + if (_destructionVolume == null) _destructionVolume = GetComponentInChildren(); if (atmosphere != null) { @@ -332,6 +334,8 @@ namespace NewHorizons.Components.SizeControllers if (atmosphere != null) atmosphere.SetActive(false); if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova; if (_planetDestructionVolume != null) _planetDestructionVolume._deathType = DeathType.Supernova; + if (_destructionFluidVolume != null) _destructionFluidVolume.enabled = false; + if (_planetDestructionFluidVolume != null) _planetDestructionFluidVolume.enabled = false; if (_proxy != null) _proxy.StartSupernova(); } @@ -356,6 +360,8 @@ namespace NewHorizons.Components.SizeControllers _planetDestructionVolume._deathType = DeathType.Energy; _planetDestructionVolume.transform.localScale = Vector3.one; } + if (_destructionFluidVolume != null) _destructionFluidVolume.enabled = true; + if (_planetDestructionFluidVolume != null) _planetDestructionFluidVolume.enabled = true; if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one; gameObject.SetActive(true); transform.localScale = Vector3.one;