Star lifespan fixes (#256)

Star lifespans are fully implemented.
This commit is contained in:
Noah 2022-08-10 19:38:25 -04:00 committed by GitHub
commit 7e020b2537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 17 deletions

View File

@ -144,6 +144,8 @@ namespace NewHorizons.Builder.Body
controller.WillExplode = starModule.goSupernova; controller.WillExplode = starModule.goSupernova;
controller.lifespan = starModule.lifespan; controller.lifespan = starModule.lifespan;
controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp;
controller._destructionVolume = deathVolume.GetComponent<DestructionVolume>();
controller._planetDestructionVolume = planetDestructionVolume.GetComponent<DestructionVolume>();
if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture)) if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture))
{ {
controller.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture); controller.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture);
@ -185,6 +187,7 @@ namespace NewHorizons.Builder.Body
var controller = starGO.AddComponent<StarEvolutionController>(); var controller = starGO.AddComponent<StarEvolutionController>();
if (starModule.curve != null) controller.SetScaleCurve(starModule.curve); if (starModule.curve != null) controller.SetScaleCurve(starModule.curve);
controller.size = starModule.size; controller.size = starModule.size;
controller.supernovaSize = starModule.supernovaSize;
controller.supernova = supernova; controller.supernova = supernova;
controller.StartColour = starModule.tint; controller.StartColour = starModule.tint;
controller.EndColour = starModule.endTint; controller.EndColour = starModule.endTint;
@ -198,7 +201,7 @@ namespace NewHorizons.Builder.Body
controller.enabled = true; controller.enabled = true;
starGO.SetActive(true); starGO.SetActive(true);
planet.GetComponentInChildren<StarEvolutionController>().SetProxy(controller); planet.GetComponentInChildren<StarEvolutionController>(true).SetProxy(controller);
return proxyGO; return proxyGO;
} }
@ -284,6 +287,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 = AnimationCurve.Linear(5, 0, 15, starModule.supernovaSize);
supernova._supernovaVolume = null; supernova._supernovaVolume = null;
if (starModule.supernovaTint != null) if (starModule.supernovaTint != null)

View File

@ -28,7 +28,8 @@ namespace NewHorizons.Components.SizeControllers
private PlanetaryFogController _fog; private PlanetaryFogController _fog;
private MeshRenderer[] _atmosphereRenderers; private MeshRenderer[] _atmosphereRenderers;
private HeatHazardVolume _heatVolume; private HeatHazardVolume _heatVolume;
private DestructionVolume _destructionVolume; public DestructionVolume _destructionVolume;
public DestructionVolume _planetDestructionVolume;
private SolarFlareEmitter _flareEmitter; private SolarFlareEmitter _flareEmitter;
private MapMarker _mapMarker; private MapMarker _mapMarker;
private OWRigidbody _rigidbody; private OWRigidbody _rigidbody;
@ -39,6 +40,7 @@ namespace NewHorizons.Components.SizeControllers
public float collapseTime = 10f; // seconds public float collapseTime = 10f; // seconds
public float lifespan = 22f; // minutes public float lifespan = 22f; // minutes
public float supernovaSize = 50000f;
private bool _isSupernova; private bool _isSupernova;
private float _supernovaStartTime; private float _supernovaStartTime;
@ -119,7 +121,7 @@ namespace NewHorizons.Components.SizeControllers
} }
_heatVolume = GetComponentInChildren<HeatHazardVolume>(); _heatVolume = GetComponentInChildren<HeatHazardVolume>();
_destructionVolume = GetComponentInChildren<DestructionVolume>(); if (_destructionVolume != null) _destructionVolume = GetComponentInChildren<DestructionVolume>();
if (atmosphere != null) if (atmosphere != null)
{ {
@ -142,6 +144,19 @@ namespace NewHorizons.Components.SizeControllers
_flareEmitter = GetComponentInChildren<SolarFlareEmitter>(); _flareEmitter = GetComponentInChildren<SolarFlareEmitter>();
_surfaceMaterial = supernova._surface._materials[0]; _surfaceMaterial = supernova._surface._materials[0];
var secondsElapsed = TimeLoop.GetSecondsElapsed();
var lifespanInSeconds = lifespan * 60;
if (secondsElapsed >= lifespanInSeconds)
{
var timeAfter = secondsElapsed - lifespanInSeconds;
if (timeAfter <= collapseTime)
Delay.RunWhen(() => Main.IsSystemReady, StartCollapse);
else if (timeAfter <= collapseTime + 45)
Delay.RunWhen(() => Main.IsSystemReady, StartSupernova);
else
Delay.RunWhen(() => Main.IsSystemReady, () => Delay.FireOnNextUpdate(() => DisableStar(true)));
}
} }
public void OnDestroy() public void OnDestroy()
@ -209,28 +224,53 @@ namespace NewHorizons.Components.SizeControllers
// Make the destruction volume scale slightly smaller so you really have to be in the supernova to die // Make the destruction volume scale slightly smaller so you really have to be in the supernova to die
if (_destructionVolume != null) _destructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * 0.9f; if (_destructionVolume != null) _destructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * 0.9f;
if (_planetDestructionVolume != null) _planetDestructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * 0.9f;
if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius(); if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius();
if (Time.time > _supernovaStartTime + 45f) if (Time.time > _supernovaStartTime + 45f)
{ {
if (_rigidbody != null) DisableStar();
}
}
private void DisableStar(bool start = false)
{
if (_rigidbody != null)
{
ReferenceFrameTracker referenceFrameTracker = Locator.GetPlayerBody().GetComponent<ReferenceFrameTracker>();
if (referenceFrameTracker.GetReferenceFrame() != null && referenceFrameTracker.GetReferenceFrame().GetOWRigidBody() == _rigidbody) referenceFrameTracker.UntargetReferenceFrame();
_rigidbody._isTargetable = false;
if (_rigidbody._attachedRFVolume != null)
{ {
ReferenceFrameTracker referenceFrameTracker = Locator.GetPlayerBody().GetComponent<ReferenceFrameTracker>(); _rigidbody._attachedRFVolume._minColliderRadius = 0;
if (referenceFrameTracker.GetReferenceFrame() != null && referenceFrameTracker.GetReferenceFrame().GetOWRigidBody() == _rigidbody) referenceFrameTracker.UntargetReferenceFrame(); _rigidbody._attachedRFVolume._maxColliderRadius = 0;
_rigidbody._isTargetable = false; }
if (_rigidbody._attachedRFVolume != null) }
if (_mapMarker != null) _mapMarker.DisableMarker();
if (controller != null) StarLightController.RemoveStar(controller);
// Just turn off the star entirely
base.gameObject.SetActive(false);
if (start && _planetDestructionVolume != null)
{
foreach (var collider in Physics.OverlapSphere(_planetDestructionVolume.transform.position, _planetDestructionVolume.GetComponent<SphereCollider>().radius * supernovaSize * 0.9f))
{
if (collider.attachedRigidbody != null)
{ {
_rigidbody._attachedRFVolume._minColliderRadius = 0; var body = collider.attachedRigidbody.GetComponent<OWRigidbody>();
_rigidbody._attachedRFVolume._maxColliderRadius = 0; if (body != null && body != _rigidbody)
{
// Vanish anything that is not a player-related object
if (!(collider.attachedRigidbody.CompareTag("Player") || collider.attachedRigidbody.CompareTag("Ship") || collider.attachedRigidbody.CompareTag("ShipCockpit") || collider.attachedRigidbody.CompareTag("Probe")))
{
_planetDestructionVolume.Vanish(body, new RelativeLocationData(body, _rigidbody, _planetDestructionVolume.transform));
}
}
} }
} }
if (_mapMarker != null) _mapMarker.DisableMarker();
if (controller != null) StarLightController.RemoveStar(controller);
// Just turn off the star entirely
base.gameObject.SetActive(false);
} }
} }
@ -272,6 +312,7 @@ namespace NewHorizons.Components.SizeControllers
_supernovaStartTime = Time.time; _supernovaStartTime = Time.time;
if (atmosphere != null) atmosphere.SetActive(false); if (atmosphere != null) atmosphere.SetActive(false);
if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova; if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova;
if (_planetDestructionVolume != null) _planetDestructionVolume._deathType = DeathType.Supernova;
if (_proxy != null) _proxy.StartSupernova(); if (_proxy != null) _proxy.StartSupernova();
} }
@ -290,6 +331,11 @@ namespace NewHorizons.Components.SizeControllers
_destructionVolume._deathType = DeathType.Energy; _destructionVolume._deathType = DeathType.Energy;
_destructionVolume.transform.localScale = Vector3.one; _destructionVolume.transform.localScale = Vector3.one;
} }
if (_planetDestructionVolume != null)
{
_planetDestructionVolume._deathType = DeathType.Energy;
_planetDestructionVolume.transform.localScale = Vector3.one;
}
if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one; if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one;
gameObject.SetActive(true); gameObject.SetActive(true);
transform.localScale = Vector3.one; transform.localScale = Vector3.one;

View File

@ -52,6 +52,13 @@ namespace NewHorizons.External.Modules.VariableSize
[DefaultValue(1f)] [Range(0f, double.MaxValue)] [DefaultValue(1f)] [Range(0f, double.MaxValue)]
public float solarLuminosity = 1f; public float solarLuminosity = 1f;
/// <summary>
/// Radius of the supernova.
/// </summary>
[DefaultValue(50000f)]
[Range(0f, double.MaxValue)]
public float supernovaSize = 50000f;
/// <summary> /// <summary>
/// The tint of the supernova this star creates when it dies. /// The tint of the supernova this star creates when it dies.
/// </summary> /// </summary>

View File

@ -381,6 +381,14 @@ namespace NewHorizons
remoteViewer._visualSector = northPoleSurface; remoteViewer._visualSector = northPoleSurface;
} }
//Stop starfield from disappearing when there is no lights
var playerBody = SearchUtilities.Find("Player_Body");
var playerLight = playerBody.AddComponent<Light>();
playerLight.innerSpotAngle = 0;
playerLight.spotAngle = 179;
playerLight.range = 0.5f;
playerLight.intensity = 0.001f;
try try
{ {
Logger.Log($"Star system finished loading [{Instance.CurrentStarSystem}]"); Logger.Log($"Star system finished loading [{Instance.CurrentStarSystem}]");

View File

@ -2333,6 +2333,13 @@
"default": 1.0, "default": 1.0,
"minimum": 0.0 "minimum": 0.0
}, },
"supernovaSize": {
"type": "number",
"description": "Radius of the supernova.",
"format": "float",
"default": 50000.0,
"minimum": 0.0
},
"supernovaTint": { "supernovaTint": {
"description": "The tint of the supernova this star creates when it dies.", "description": "The tint of the supernova this star creates when it dies.",
"$ref": "#/definitions/MColor" "$ref": "#/definitions/MColor"