Fully implement stellar remnants

This commit is contained in:
Noah Pilarski 2022-08-18 11:03:12 -04:00
parent 135794fa29
commit 6ade2171cf
6 changed files with 186 additions and 64 deletions

View File

@ -21,7 +21,7 @@ namespace NewHorizons.Builder.Body
private static readonly int InnerRadius = Shader.PropertyToID("_InnerRadius"); private static readonly int InnerRadius = Shader.PropertyToID("_InnerRadius");
private static readonly int OuterRadius = Shader.PropertyToID("_OuterRadius"); private static readonly int OuterRadius = Shader.PropertyToID("_OuterRadius");
public static StarController Make(GameObject planetGO, Sector sector, StarModule starModule, IModBehaviour mod) public static StarController Make(GameObject planetGO, Sector sector, StarModule starModule, IModBehaviour mod, bool isStellarRemnant)
{ {
var starGO = MakeStarGraphics(planetGO, sector, starModule, mod); var starGO = MakeStarGraphics(planetGO, sector, starModule, mod);
var ramp = starGO.GetComponentInChildren<TessellatedSphereRenderer>().sharedMaterial.GetTexture(ColorRamp); var ramp = starGO.GetComponentInChildren<TessellatedSphereRenderer>().sharedMaterial.GetTexture(ColorRamp);
@ -32,6 +32,7 @@ namespace NewHorizons.Builder.Body
sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent<AudioSource>().maxDistance = starModule.size * 2f; sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent<AudioSource>().maxDistance = starModule.size * 2f;
var sunSurfaceAudio = sunAudio.GetComponentInChildren<SunSurfaceAudioController>(); var sunSurfaceAudio = sunAudio.GetComponentInChildren<SunSurfaceAudioController>();
var surfaceAudio = sunSurfaceAudio.gameObject.AddComponent<StarSurfaceAudioController>(); var surfaceAudio = sunSurfaceAudio.gameObject.AddComponent<StarSurfaceAudioController>();
surfaceAudio._size = starModule.size;
GameObject.Destroy(sunSurfaceAudio); GameObject.Destroy(sunSurfaceAudio);
surfaceAudio.SetSector(sector); surfaceAudio.SetSector(sector);
@ -143,8 +144,11 @@ namespace NewHorizons.Builder.Body
starController.ProxyShadowLight = proxyShadowLight; starController.ProxyShadowLight = proxyShadowLight;
starController.Intensity = starModule.solarLuminosity; starController.Intensity = starModule.solarLuminosity;
starController.SunColor = lightColour; starController.SunColor = lightColour;
starController.IsStellarRemnant = isStellarRemnant;
} }
if (!isStellarRemnant)
{
var supernova = MakeSupernova(starGO, starModule); var supernova = MakeSupernova(starGO, starModule);
starGO.SetActive(false); starGO.SetActive(false);
@ -181,6 +185,7 @@ namespace NewHorizons.Builder.Body
sphere.isTrigger = true; sphere.isTrigger = true;
supernovaVolume.AddComponent<OWCollider>(); supernovaVolume.AddComponent<OWCollider>();
supernova._supernovaVolume = supernovaVolume.AddComponent<SupernovaDestructionVolume>(); supernova._supernovaVolume = supernovaVolume.AddComponent<SupernovaDestructionVolume>();
}
var shockLayerRuleset = sector.gameObject.AddComponent<ShockLayerRuleset>(); var shockLayerRuleset = sector.gameObject.AddComponent<ShockLayerRuleset>();
shockLayerRuleset._type = ShockLayerRuleset.ShockType.Radial; shockLayerRuleset._type = ShockLayerRuleset.ShockType.Radial;
@ -309,7 +314,7 @@ namespace NewHorizons.Builder.Body
var supernova = supernovaGO.GetComponent<SupernovaEffectController>(); var supernova = supernovaGO.GetComponent<SupernovaEffectController>();
supernova._surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>(); supernova._surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>();
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._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._supernovaAlpha = new AnimationCurve(new Keyframe(5, 1, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(15, 1.0002f, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(50, 0, -0.0578f, 1 / 3f, -0.0578f, 1 / 3f) ); supernova._supernovaAlpha = new AnimationCurve(new Keyframe(5, 1, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(15, 1.0002f, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(50, 0, -0.0578f, 1 / 3f, -0.0578f, 1 / 3f));
supernova._supernovaVolume = null; supernova._supernovaVolume = null;
if (starModule.supernovaTint != null) if (starModule.supernovaTint != null)

View File

@ -247,6 +247,8 @@ namespace NewHorizons.Components.SizeControllers
_planetDestructionVolume.GetComponent<SphereCollider>().radius = Mathf.Lerp(0.8f, 1, t); _planetDestructionVolume.GetComponent<SphereCollider>().radius = Mathf.Lerp(0.8f, 1, t);
} }
if (_stellarRemnantController != null && Time.time > _supernovaStartTime + 15) _stellarRemnantController.PartiallyActivate();
if (Time.time > _supernovaStartTime + supernovaTime) if (Time.time > _supernovaStartTime + supernovaTime)
{ {
if (_destructionVolume != null && _destructionVolume._shrinkingBodies.Count > 0) return; if (_destructionVolume != null && _destructionVolume._shrinkingBodies.Count > 0) return;
@ -260,9 +262,9 @@ namespace NewHorizons.Components.SizeControllers
if (controller != null) StarLightController.RemoveStar(controller); if (controller != null) StarLightController.RemoveStar(controller);
// Just turn off the star entirely // Just turn off the star entirely
base.gameObject.SetActive(false); transform.parent.gameObject.SetActive(false);
if (_stellarRemnantController != null) _stellarRemnantController.gameObject.SetActive(true); if (_stellarRemnantController != null) _stellarRemnantController.FullyActivate();
if (start && _planetDestructionVolume != null) if (start && _planetDestructionVolume != null)
{ {

View File

@ -10,6 +10,7 @@ namespace NewHorizons.Components
public ProxyShadowLight ProxyShadowLight; public ProxyShadowLight ProxyShadowLight;
public float Intensity; public float Intensity;
public Color SunColor; public Color SunColor;
public bool IsStellarRemnant;
public void Awake() public void Awake()
{ {

View File

@ -10,6 +10,7 @@ namespace NewHorizons.Components
private StarEvolutionController _starEvolutionController; private StarEvolutionController _starEvolutionController;
private OWAudioSource _audioSource; private OWAudioSource _audioSource;
private float _fade; private float _fade;
public float _size;
public void Start() public void Start()
{ {
@ -33,7 +34,7 @@ namespace NewHorizons.Components
public void Update() public void Update()
{ {
_fade = Mathf.MoveTowards(_fade, 1, Time.deltaTime * 0.2f); _fade = Mathf.MoveTowards(_fade, 1, Time.deltaTime * 0.2f);
float value = Mathf.Max(0.0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, this.transform.position) - _starEvolutionController.CurrentScale); float value = Mathf.Max(0.0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, this.transform.position) - (_starEvolutionController != null ? _starEvolutionController.CurrentScale : _size));
float num = Mathf.InverseLerp(1600f, 100f, value); float num = Mathf.InverseLerp(1600f, 100f, value);
_audioSource.SetLocalVolume(num * num * _fade); _audioSource.SetLocalVolume(num * num * _fade);
} }

View File

@ -8,12 +8,65 @@ namespace NewHorizons.Components
{ {
public class StellarRemnantController : MonoBehaviour public class StellarRemnantController : MonoBehaviour
{ {
private RemnantType _type = RemnantType.None;
private StarEvolutionController _starEvolutionController; private StarEvolutionController _starEvolutionController;
private StellarRemnantController _proxy; private StellarRemnantController _proxy;
private StarController _starController;
private float _surfaceGravity = 0;
private float _surfaceSize = 0;
private float _sphereOfInfluence = 0;
private float _alignmentRadius = 0;
public RemnantType GetRemnantType() => _type;
public void SetRemnantType(RemnantType type) => _type = type;
public void SetSurfaceGravity(float surfaceGravity) => _surfaceGravity = surfaceGravity;
public void SetSurfaceSize(float surfaceSize) => _surfaceSize = surfaceSize;
public void SetAlignmentRadius(float alignmentRadius) => _alignmentRadius = alignmentRadius;
public void SetSphereOfInfluence(float sphereOfInfluence) => _sphereOfInfluence = sphereOfInfluence;
public void SetStarController(StarController starController) => _starController = starController;
public void SetProxy(StellarRemnantController proxy) => _proxy = proxy; public void SetProxy(StellarRemnantController proxy) => _proxy = proxy;
public void SetStarEvolutionController(StarEvolutionController controller) => _starEvolutionController = controller; public void SetStarEvolutionController(StarEvolutionController controller) => _starEvolutionController = controller;
public void PartiallyActivate()
{
if (!gameObject.activeSelf) gameObject.SetActive(true);
}
public void FullyActivate()
{
if (!gameObject.activeSelf) gameObject.SetActive(true);
var gravityVolume = this.GetAttachedOWRigidbody().GetAttachedGravityVolume();
if (gravityVolume != null)
{
gravityVolume._alignmentRadius = _alignmentRadius;
gravityVolume._upperSurfaceRadius = _surfaceSize;
gravityVolume._surfaceAcceleration = _surfaceGravity;
}
var referenceFrameVolume = this.GetAttachedOWRigidbody()._attachedRFVolume;
if (referenceFrameVolume != null)
{
referenceFrameVolume.GetComponent<SphereCollider>().radius = _sphereOfInfluence * 2;
referenceFrameVolume._maxColliderRadius = _sphereOfInfluence * 2;
}
if (_starController != null) StarLightController.AddStar(_starController);
}
public enum RemnantType
{
None,
BlackHole,
NeutronStar,
WhiteDwarf,
Custom
}
} }
} }

View File

@ -202,28 +202,7 @@ namespace NewHorizons.Handlers
} }
else if (body.Config.isStellarRemnant) else if (body.Config.isStellarRemnant)
{ {
Logger.Log($"Creating stellar remnant for [{body.Config.name}]"); //Skip
try
{
var rb = existingPlanet.GetComponent<OWRigidbody>();
var sector = SectorBuilder.Make(existingPlanet, rb, GetSphereOfInfluence(body));
sector.name = $"StellarRemnant";
var stellarRemnantController = sector.gameObject.AddComponent<StellarRemnantController>();
var starEvolutionController = existingPlanet.GetComponentInChildren<StarEvolutionController>(true);
stellarRemnantController.SetStarEvolutionController(starEvolutionController);
starEvolutionController.SetStellarRemnantController(stellarRemnantController);
sector.gameObject.SetActive(false);
SharedGenerateBody(body, existingPlanet, sector, rb);
}
catch (Exception ex)
{
Logger.LogError($"Couldn't make stellar remnant for [{body.Config.name}]:\n{ex}");
return false;
}
} }
else else
{ {
@ -245,8 +224,7 @@ namespace NewHorizons.Handlers
} }
else if (body.Config.isStellarRemnant) else if (body.Config.isStellarRemnant)
{ {
// If the star object isn't made yet do it later //Skip
_nextPassBodies.Add(body);
} }
else else
{ {
@ -523,7 +501,89 @@ namespace NewHorizons.Handlers
if (body.Config.Star != null) if (body.Config.Star != null)
{ {
StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star, body.Mod)); StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star, body.Mod, body.Config.isStellarRemnant));
if (!body.Config.isStellarRemnant)
{
Logger.Log($"Creating stellar remnant for [{body.Config.name}]");
try
{
var size = body.Config.Star.size;
var srBody = Main.BodyDict[body.Config.starSystem].Where(x => x.Config.name == body.Config.name && body.Config.isStellarRemnant).FirstOrDefault();
var srSector = SectorBuilder.Make(go, rb, GetSphereOfInfluence(body));
srSector.name = "StellarRemnant";
var ss = srSector.GetComponent<SphereShape>();
var stellarRemnantController = srSector.gameObject.AddComponent<StellarRemnantController>();
var starEvolutionController = go.GetComponentInChildren<StarEvolutionController>(true);
stellarRemnantController.SetStarEvolutionController(starEvolutionController);
starEvolutionController.SetStellarRemnantController(stellarRemnantController);
srSector.gameObject.SetActive(false);
if (srBody != null)
{
stellarRemnantController.SetRemnantType(StellarRemnantController.RemnantType.Custom);
stellarRemnantController.SetSurfaceSize(srBody.Config.Base.surfaceSize);
stellarRemnantController.SetSurfaceGravity(srBody.Config.Base.surfaceGravity);
var srSphereOfInfluence = GetSphereOfInfluence(srBody);
stellarRemnantController.SetSphereOfInfluence(srSphereOfInfluence);
ss.radius = srSphereOfInfluence + 10;
var alignmentRadius = srBody.Config.Atmosphere?.clouds?.outerCloudRadius ?? 1.5f * srBody.Config.Base.surfaceSize;
if (srBody.Config.Base.surfaceGravity == 0) alignmentRadius = 0;
stellarRemnantController.SetAlignmentRadius(alignmentRadius);
SharedGenerateBody(srBody, go, srSector, rb);
}
// Black Hole
else if (size > 4000)
{
stellarRemnantController.SetRemnantType(StellarRemnantController.RemnantType.BlackHole);
var bhSurfaceSize = size * 0.015f;
stellarRemnantController.SetSurfaceSize(bhSurfaceSize);
stellarRemnantController.SetSurfaceGravity(body.Config.Base.surfaceGravity * 4);
stellarRemnantController.SetSphereOfInfluence(bhSurfaceSize * 2);
ss.radius = (bhSurfaceSize * 2) + 10;
stellarRemnantController.SetAlignmentRadius(bhSurfaceSize * 1.5f);
SingularityBuilder.MakeBlackHole(go, srSector, Vector3.zero, bhSurfaceSize, true, string.Empty, new External.Modules.VariableSize.VariableSizeModule.TimeValuePair[0]);
}
// Neutron Star
else if (2000 < size && size < 3000)
{
stellarRemnantController.SetRemnantType(StellarRemnantController.RemnantType.NeutronStar);
var nsSurfaceSize = size * 0.03f;
stellarRemnantController.SetSurfaceSize(nsSurfaceSize);
stellarRemnantController.SetSurfaceGravity(body.Config.Base.surfaceGravity * 2);
stellarRemnantController.SetSphereOfInfluence(nsSurfaceSize * 2);
ss.radius = (nsSurfaceSize * 2) + 10;
stellarRemnantController.SetAlignmentRadius(nsSurfaceSize * 1.5f);
stellarRemnantController.SetStarController(StarBuilder.Make(go, srSector, new External.Modules.VariableSize.StarModule
{
size = nsSurfaceSize,
tint = MColor.white
}, body.Mod, true));
}
// White Dwarf
else
{
stellarRemnantController.SetRemnantType(StellarRemnantController.RemnantType.WhiteDwarf);
var wdSurfaceSize = size * 0.15f;
stellarRemnantController.SetSurfaceSize(wdSurfaceSize);
stellarRemnantController.SetSurfaceGravity(body.Config.Base.surfaceGravity * 1.4f);
stellarRemnantController.SetSphereOfInfluence(wdSurfaceSize * 2);
ss.radius = (wdSurfaceSize * 2) + 10;
stellarRemnantController.SetAlignmentRadius(wdSurfaceSize * 1.5f);
stellarRemnantController.SetStarController(StarBuilder.Make(go, srSector, new External.Modules.VariableSize.StarModule
{
size = wdSurfaceSize,
tint = MColor.white,
endTint = MColor.black
}, body.Mod, true));
}
}
catch (Exception ex)
{
Logger.LogError($"Couldn't make stellar remnant for [{body.Config.name}]:\n{ex}");
}
}
} }
if (body.Config?.Bramble != null) if (body.Config?.Bramble != null)