Cloak fixes (#705)

## Bug fixes
- Fixed spawning inside cloaks. Fixes #671 
- Fixed default system override logging errors on load
- Fixed star size in shader params
- Fixed water inside of cloaks
This commit is contained in:
Nick 2023-08-23 13:55:13 -04:00 committed by GitHub
commit ac188d0946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 199 additions and 41 deletions

View File

@ -5,6 +5,9 @@ using NewHorizons.External.Modules.VariableSize;
using Tessellation; using Tessellation;
using NewHorizons.Utility.OWML; using NewHorizons.Utility.OWML;
using NewHorizons.Utility.OuterWilds; using NewHorizons.Utility.OuterWilds;
using NewHorizons.External.Configs;
using NewHorizons.Components.Volumes;
using System.Linq;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -41,10 +44,12 @@ namespace NewHorizons.Builder.Body
if (_oceanAmbientLight == null) _oceanAmbientLight = SearchUtilities.Find("Ocean_GD").GetComponent<OceanLODController>()._ambientLight.gameObject.InstantiateInactive().Rename("OceanAmbientLight").DontDestroyOnLoad(); if (_oceanAmbientLight == null) _oceanAmbientLight = SearchUtilities.Find("Ocean_GD").GetComponent<OceanLODController>()._ambientLight.gameObject.InstantiateInactive().Rename("OceanAmbientLight").DontDestroyOnLoad();
} }
public static RadialFluidVolume Make(GameObject planetGO, Sector sector, OWRigidbody rb, WaterModule module) public static RadialFluidVolume Make(GameObject planetGO, Sector sector, OWRigidbody rb, PlanetConfig config)
{ {
InitPrefabs(); InitPrefabs();
var module = config.Water;
var waterSize = module.size; var waterSize = module.size;
GameObject waterGO = new GameObject("Water"); GameObject waterGO = new GameObject("Water");
@ -154,6 +159,11 @@ namespace NewHorizons.Builder.Body
fogGO.GetComponent<MeshRenderer>().material.SetFloat("_Radius2", 0); fogGO.GetComponent<MeshRenderer>().material.SetFloat("_Radius2", 0);
} }
if (config.Cloak != null)
{
fluidVolume.gameObject.AddComponent<WaterCloakFixerVolume>().material = TSR.sharedMaterials.First(x => x.name == "Ocean_GD_Surface_mat");
}
// TODO: fix ruleset making the sand bubble pop up // TODO: fix ruleset making the sand bubble pop up
waterGO.transform.position = planetGO.transform.position; waterGO.transform.position = planetGO.transform.position;

View File

@ -61,15 +61,17 @@ namespace NewHorizons.Builder.Orbital
var fade = isMoon; var fade = isMoon;
/* if (config.Orbit.orbitLineFadeStartDistance >= 0)
if (config.Base.IsSatellite)
{ {
if (config.Orbit.Tint != null) color = new Color(0.4082f, 0.516f, 0.4469f, 1f);
fade = true; fade = true;
orbitLine._fadeEndDist = 5000; orbitLine._fadeStartDist = config.Orbit.orbitLineFadeStartDistance;
orbitLine._fadeStartDist = 3000; }
if (config.Orbit.orbitLineFadeEndDistance >= 0)
{
fade = true;
orbitLine._fadeEndDist = config.Orbit.orbitLineFadeEndDistance;
} }
*/
orbitLine._color = color; orbitLine._color = color;
lineRenderer.endColor = new Color(color.r, color.g, color.b, 0f); lineRenderer.endColor = new Color(color.r, color.g, color.b, 0f);

View File

@ -257,7 +257,9 @@ namespace NewHorizons.Builder.Props
// Seed fog works differently, so it doesn't need to be fixed // Seed fog works differently, so it doesn't need to be fixed
// (it's also located on a different child path, so the below FindChild calls wouldn't work) // (it's also located on a different child path, so the below FindChild calls wouldn't work)
// Default size is 70
var fog = brambleNode.FindChild("Effects/InnerWarpFogSphere"); var fog = brambleNode.FindChild("Effects/InnerWarpFogSphere");
fog.transform.localScale = Vector3.one * config.scale * 70f;
var fogMaterial = fog.GetComponent<MeshRenderer>().material; var fogMaterial = fog.GetComponent<MeshRenderer>().material;
fogMaterial.SetFloat("_Radius", fogMaterial.GetFloat("_Radius") * config.scale); fogMaterial.SetFloat("_Radius", fogMaterial.GetFloat("_Radius") * config.scale);
fogMaterial.SetFloat("_Density", fogMaterial.GetFloat("_Density") / config.scale); fogMaterial.SetFloat("_Density", fogMaterial.GetFloat("_Density") / config.scale);

View File

@ -454,6 +454,8 @@ namespace NewHorizons.Components.SizeControllers
public float GetSupernovaRadius() => supernova.GetSupernovaRadius(); public float GetSupernovaRadius() => supernova.GetSupernovaRadius();
public float GetSurfaceRadius() => transform.localScale.x;
public float GetMaxSupernovaRadius() => supernovaSize; public float GetMaxSupernovaRadius() => supernovaSize;
protected new void FixedUpdate() protected new void FixedUpdate()

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.Atmosphere; using NewHorizons.Builder.Atmosphere;
using NewHorizons.Components.SizeControllers;
using NewHorizons.Utility.OWML; using NewHorizons.Utility.OWML;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -17,7 +18,11 @@ namespace NewHorizons.Components.Stars
private readonly List<StarController> _stars = new(); private readonly List<StarController> _stars = new();
private readonly List<Light> _lights = new(); private readonly List<Light> _lights = new();
private StarController _activeStar; // SunController or StarEvolutionController
public StarEvolutionController ActiveStarEvolutionController { get; private set; }
public SunController ActiveSunController { get; private set; }
private StarController _activeStarController;
private SunLightController _sunLightController; private SunLightController _sunLightController;
private SunLightParamUpdater _sunLightParamUpdater; private SunLightParamUpdater _sunLightParamUpdater;
@ -54,7 +59,7 @@ namespace NewHorizons.Components.Stars
NHLogger.LogVerbose($"Removing star from list: {star?.gameObject?.name}"); NHLogger.LogVerbose($"Removing star from list: {star?.gameObject?.name}");
if (Instance._stars.Contains(star)) if (Instance._stars.Contains(star))
{ {
if (Instance._activeStar != null && Instance._activeStar.Equals(star)) if (Instance._activeStarController != null && Instance._activeStarController.Equals(star))
{ {
Instance._stars.Remove(star); Instance._stars.Remove(star);
if (Instance._stars.Count > 0) Instance.ChangeActiveStar(Instance._stars[0]); if (Instance._stars.Count > 0) Instance.ChangeActiveStar(Instance._stars[0]);
@ -121,11 +126,11 @@ namespace NewHorizons.Components.Stars
if (_stars.Count > 0) if (_stars.Count > 0)
{ {
if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) if (_activeStarController == null || !_activeStarController.gameObject.activeInHierarchy)
{ {
if (_stars.Contains(_activeStar)) if (_stars.Contains(_activeStarController))
{ {
_stars.Remove(_activeStar); _stars.Remove(_activeStarController);
} }
if (_stars.Count > 0) if (_stars.Count > 0)
@ -145,8 +150,8 @@ namespace NewHorizons.Components.Stars
// Update atmo shaders // Update atmo shaders
foreach (var (planet, material) in AtmosphereBuilder.Skys) foreach (var (planet, material) in AtmosphereBuilder.Skys)
{ {
var sqrDist = (planet.transform.position - _activeStar.transform.position).sqrMagnitude; var sqrDist = (planet.transform.position - _activeStarController.transform.position).sqrMagnitude;
var intensity = Mathf.Min(_activeStar.Intensity / (sqrDist / hearthSunDistanceSqr), 1f); var intensity = Mathf.Min(_activeStarController.Intensity / (sqrDist / hearthSunDistanceSqr), 1f);
material.SetFloat(SunIntensity, intensity); material.SetFloat(SunIntensity, intensity);
} }
@ -156,7 +161,7 @@ namespace NewHorizons.Components.Stars
if (star == null) continue; if (star == null) continue;
if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue;
if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStar.Intensity * (_activeStar.transform.position - origin).sqrMagnitude) if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStarController.Intensity * (_activeStarController.transform.position - origin).sqrMagnitude)
{ {
ChangeActiveStar(star); ChangeActiveStar(star);
break; break;
@ -170,11 +175,13 @@ namespace NewHorizons.Components.Stars
{ {
if (_sunLightController == null || _sunLightParamUpdater == null) return; if (_sunLightController == null || _sunLightParamUpdater == null) return;
if (_activeStar != null) _activeStar.Disable(); _activeStarController?.Disable();
NHLogger.LogVerbose($"Switching active star: {star.gameObject.name}"); NHLogger.LogVerbose($"Switching active star: {star.gameObject.name}");
_activeStar = star; _activeStarController = star;
ActiveStarEvolutionController = star.GetComponentInChildren<StarEvolutionController>();
ActiveSunController = star.GetComponent<SunController>();
star.Enable(); star.Enable();
@ -194,7 +201,8 @@ namespace NewHorizons.Components.Stars
transform.localPosition = Vector3.zero; transform.localPosition = Vector3.zero;
// Some effects use Locator.GetSunTransform so hopefully its fine to change it // Some effects use Locator.GetSunTransform so hopefully its fine to change it
Locator._sunTransform = transform; // Use the root transform of the star because that's the default behaviour, breaks SunProxy is not (potentially others)
Locator._sunTransform = star.transform;
// TODO?: maybe also turn off star controller stuff (mainly proxy light) since idk if that can handle more than 1 being on // TODO?: maybe also turn off star controller stuff (mainly proxy light) since idk if that can handle more than 1 being on
} }

View File

@ -0,0 +1,42 @@
using UnityEngine;
namespace NewHorizons.Components.Volumes
{
internal class WaterCloakFixerVolume : MonoBehaviour
{
public Material material;
private OWTriggerVolume _volume;
public void Start()
{
_volume = GetComponent<RadialFluidVolume>().GetOWTriggerVolume();
_volume.OnEntry += WaterCloakFixerVolume_OnEntry;
_volume.OnExit += WaterCloakFixerVolume_OnExit;
material.renderQueue = 3000;
}
public void OnDestroy()
{
_volume.OnEntry -= WaterCloakFixerVolume_OnEntry;
_volume.OnExit -= WaterCloakFixerVolume_OnExit;
}
private void WaterCloakFixerVolume_OnEntry(GameObject hitObj)
{
if (hitObj.CompareTag("PlayerDetector"))
{
material.renderQueue = 2990;
}
}
private void WaterCloakFixerVolume_OnExit(GameObject hitObj)
{
if (hitObj.CompareTag("PlayerDetector"))
{
material.renderQueue = 3000;
}
}
}
}

View File

@ -45,6 +45,12 @@ namespace NewHorizons.External.Modules
/// </summary> /// </summary>
public bool isTidallyLocked; public bool isTidallyLocked;
/// <summary>
/// Is the body meant to stay in one place without moving? If staticPosition is not set, the initial position
/// will be determined using its orbital parameters.
/// </summary>
public bool isStatic;
/// <summary> /// <summary>
/// If it is tidally locked, this direction will face towards the primary. Ex: Interloper uses `0, -1, 0`. Most planets /// If it is tidally locked, this direction will face towards the primary. Ex: Interloper uses `0, -1, 0`. Most planets
/// will want something like `-1, 0, 0`. /// will want something like `-1, 0, 0`.
@ -62,12 +68,6 @@ namespace NewHorizons.External.Modules
/// </summary> /// </summary>
public bool dottedOrbitLine; public bool dottedOrbitLine;
/// <summary>
/// Is the body meant to stay in one place without moving? If staticPosition is not set, the initial position
/// will be determined using its orbital parameters.
/// </summary>
public bool isStatic;
/// <summary> /// <summary>
/// Colour of the orbit-line in the map view. /// Colour of the orbit-line in the map view.
/// </summary> /// </summary>
@ -78,6 +78,16 @@ namespace NewHorizons.External.Modules
/// </summary> /// </summary>
public bool trackingOrbitLine; public bool trackingOrbitLine;
/// <summary>
/// If the camera is farther than this distance the orbit line will fade out. Leave empty to not have it fade out.
/// </summary>
public float orbitLineFadeEndDistance = -1f;
/// <summary>
/// If the camera is closer than this distance the orbit line will fade out. Leave empty to not have it fade out.
/// </summary>
public float orbitLineFadeStartDistance = -1f;
/// <summary> /// <summary>
/// The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius. /// The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.
/// </summary> /// </summary>

View File

@ -627,7 +627,7 @@ namespace NewHorizons.Handlers
if (body.Config.Water != null) if (body.Config.Water != null)
{ {
WaterBuilder.Make(go, sector, rb, body.Config.Water); WaterBuilder.Make(go, sector, rb, body.Config);
} }
if (body.Config.Sand != null) if (body.Config.Sand != null)

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using NewHorizons.Components;
namespace NewHorizons.Handlers namespace NewHorizons.Handlers
{ {
@ -66,17 +67,20 @@ namespace NewHorizons.Handlers
} }
} }
foreach (var proxyBody in GameObject.FindObjectsOfType<ProxyBody>())
{
toDisable.Add(proxyBody.gameObject);
}
Delay.FireInNUpdates(() => Delay.FireInNUpdates(() =>
{ {
foreach (var gameObject in toDisable) foreach (var gameObject in toDisable)
{ {
gameObject.SetActive(false); gameObject.SetActive(false);
} }
// Kill all non nh proxies
foreach (var proxy in GameObject.FindObjectsOfType<ProxyBody>())
{
if (proxy is not NHProxy)
{
proxy.gameObject.SetActive(false);
}
}
GameObject.FindObjectOfType<SunProxy>().gameObject.SetActive(false); GameObject.FindObjectOfType<SunProxy>().gameObject.SetActive(false);
// force call update here to make it switch to an active star. idk why we didnt have to do this before // force call update here to make it switch to an active star. idk why we didnt have to do this before

View File

@ -10,11 +10,11 @@ namespace NewHorizons.Handlers
{ {
public static void SetUpPlayerSpawn() public static void SetUpPlayerSpawn()
{ {
var spawnPoint = Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint; if (UsingCustomSpawn())
if (spawnPoint != null)
{ {
SearchUtilities.Find("Player_Body").GetComponent<MatchInitialMotion>().SetBodyToMatch(spawnPoint.GetAttachedOWRigidbody()); var spawn = GetDefaultSpawn();
GetPlayerSpawner().SetInitialSpawnPoint(spawnPoint); SearchUtilities.Find("Player_Body").GetComponent<MatchInitialMotion>().SetBodyToMatch(spawn.GetAttachedOWRigidbody());
GetPlayerSpawner().SetInitialSpawnPoint(spawn);
} }
else else
{ {
@ -44,6 +44,13 @@ namespace NewHorizons.Handlers
// Arbitrary number, depending on the machine some people die, some people fall through the floor, its very inconsistent // Arbitrary number, depending on the machine some people die, some people fall through the floor, its very inconsistent
Delay.StartCoroutine(SpawnCoroutine(30)); Delay.StartCoroutine(SpawnCoroutine(30));
} }
var cloak = GetDefaultSpawn()?.GetAttachedOWRigidbody()?.GetComponentInChildren<CloakFieldController>();
if (cloak != null)
{
// Ensures it has invoked everything and actually placed the player in the cloaking field
cloak._firstUpdate = true;
}
} }
public static void SpawnShip() public static void SpawnShip()

View File

@ -907,7 +907,8 @@ namespace NewHorizons
} }
else else
{ {
if (!string.IsNullOrEmpty(_defaultSystemOverride)) // Ignore first load because it doesn't even know what systems we have
if (!_firstLoad && !string.IsNullOrEmpty(_defaultSystemOverride))
{ {
NHLogger.LogError($"The given default system override {_defaultSystemOverride} is invalid - no system exists with that name"); NHLogger.LogError($"The given default system override {_defaultSystemOverride} is invalid - no system exists with that name");
} }

View File

@ -0,0 +1,19 @@
using HarmonyLib;
using NewHorizons.Utility;
namespace NewHorizons.Patches.ProxyPatches
{
[HarmonyPatch(typeof(SunProxy))]
public static class SunProxyPatches
{
[HarmonyPostfix]
[HarmonyPatch(nameof(SunProxy.Start))]
public static void SunProxy_Start(SunProxy __instance)
{
// We mess with the Locator.GetSunTransform() value to switch it to other relevant stars since it's used for some other effects
// However if it's set to a different star when the SunProxy starts it breaks, so we double check it here
__instance._sunTransform = SearchUtilities.Find("Sun_Body").transform;
__instance._realSunController = __instance._sunTransform.GetComponent<SunController>();
}
}
}

View File

@ -0,0 +1,30 @@
using HarmonyLib;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.Patches.ShipLogPatches
{
[HarmonyPatch(typeof(ShipLogEntryLocation))]
public static class ShipLogEntryLocationPatches
{
[HarmonyPrefix]
[HarmonyPatch(nameof(ShipLogEntryLocation.OnValidate))]
public static bool ShipLogEntryLocation_OnValidate(ShipLogEntryLocation __instance)
{
// This part is unchanged
if (!__instance._entryID.Equals(string.Empty) && !__instance.gameObject.name.Equals(__instance._entryID))
{
__instance.gameObject.name = __instance._entryID;
}
// Base method checks if its on the Ringworld to see if it can be cloaked, we wanna check for a cloak field controller instead
var cloak = __instance.GetComponentInChildren<CloakFieldController>();
__instance._isWithinCloakField = cloak != null;
return false;
}
}
}

View File

@ -1,4 +1,5 @@
using HarmonyLib; using HarmonyLib;
using NewHorizons.Components.Stars;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Patches.SunPatches namespace NewHorizons.Patches.SunPatches
{ {
@ -13,10 +14,20 @@ namespace NewHorizons.Patches.SunPatches
{ {
Vector3 position = __instance.transform.position; Vector3 position = __instance.transform.position;
float w = 2000f; float w = 2000f;
if (__instance._sunController != null)
var sunController = SunLightEffectsController.Instance.ActiveSunController;
var starEvolutionController = SunLightEffectsController.Instance.ActiveStarEvolutionController;
if (sunController != null)
{ {
w = __instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius(); w = sunController.HasSupernovaStarted() ? sunController.GetSupernovaRadius() : sunController.GetSurfaceRadius();
} }
// This is an addition in this patch, to work with our stars
else if (starEvolutionController != null)
{
w = starEvolutionController.HasSupernovaStarted() ? starEvolutionController.GetSupernovaRadius() : starEvolutionController.GetSurfaceRadius();
}
float range = __instance.sunLight.range; float range = __instance.sunLight.range;
Color color = __instance._sunLightController != null ? __instance._sunLightController.sunColor : __instance.sunLight.color; Color color = __instance._sunLightController != null ? __instance._sunLightController.sunColor : __instance.sunLight.color;
float w2 = __instance._sunLightController != null ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity; float w2 = __instance._sunLightController != null ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity;

View File

@ -1056,6 +1056,10 @@
"type": "boolean", "type": "boolean",
"description": "Should the body always have one side facing its primary?" "description": "Should the body always have one side facing its primary?"
}, },
"isStatic": {
"type": "boolean",
"description": "Is the body meant to stay in one place without moving? If staticPosition is not set, the initial position\nwill be determined using its orbital parameters."
},
"alignmentAxis": { "alignmentAxis": {
"description": "If it is tidally locked, this direction will face towards the primary. Ex: Interloper uses `0, -1, 0`. Most planets\nwill want something like `-1, 0, 0`.", "description": "If it is tidally locked, this direction will face towards the primary. Ex: Interloper uses `0, -1, 0`. Most planets\nwill want something like `-1, 0, 0`.",
"$ref": "#/definitions/MVector3" "$ref": "#/definitions/MVector3"
@ -1069,10 +1073,6 @@
"type": "boolean", "type": "boolean",
"description": "Should the orbit line be dotted?" "description": "Should the orbit line be dotted?"
}, },
"isStatic": {
"type": "boolean",
"description": "Is the body meant to stay in one place without moving? If staticPosition is not set, the initial position\nwill be determined using its orbital parameters."
},
"tint": { "tint": {
"description": "Colour of the orbit-line in the map view.", "description": "Colour of the orbit-line in the map view.",
"$ref": "#/definitions/MColor" "$ref": "#/definitions/MColor"
@ -1081,6 +1081,16 @@
"type": "boolean", "type": "boolean",
"description": "Should we just draw a line behind its orbit instead of the entire circle/ellipse?" "description": "Should we just draw a line behind its orbit instead of the entire circle/ellipse?"
}, },
"orbitLineFadeEndDistance": {
"type": "number",
"description": "If the camera is farther than this distance the orbit line will fade out. Leave empty to not have it fade out.",
"format": "float"
},
"orbitLineFadeStartDistance": {
"type": "number",
"description": "If the camera is closer than this distance the orbit line will fade out. Leave empty to not have it fade out.",
"format": "float"
},
"semiMajorAxis": { "semiMajorAxis": {
"type": "number", "type": "number",
"description": "The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.", "description": "The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.",