mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add visibility tracker to quantum planets
This commit is contained in:
parent
923cd149fe
commit
c648fbe428
@ -18,6 +18,7 @@ namespace NewHorizons.Components
|
|||||||
public class QuantumPlanet : QuantumObject
|
public class QuantumPlanet : QuantumObject
|
||||||
{
|
{
|
||||||
public List<State> states = new List<State>();
|
public List<State> states = new List<State>();
|
||||||
|
public State groundState;
|
||||||
|
|
||||||
private int _currentIndex;
|
private int _currentIndex;
|
||||||
private NHAstroObject _astroObject;
|
private NHAstroObject _astroObject;
|
||||||
@ -33,6 +34,8 @@ namespace NewHorizons.Components
|
|||||||
_detector = GetComponentInChildren<ConstantForceDetector>();
|
_detector = GetComponentInChildren<ConstantForceDetector>();
|
||||||
_alignment = GetComponent<AlignWithTargetBody>();
|
_alignment = GetComponent<AlignWithTargetBody>();
|
||||||
_rb = GetComponent<OWRigidbody>();
|
_rb = GetComponent<OWRigidbody>();
|
||||||
|
|
||||||
|
GlobalMessenger.AddListener("PlayerBlink", new Callback(OnPlayerBlink));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Start()
|
public override void Start()
|
||||||
@ -62,8 +65,8 @@ namespace NewHorizons.Components
|
|||||||
var oldState = states[_currentIndex];
|
var oldState = states[_currentIndex];
|
||||||
var newState = states[newIndex];
|
var newState = states[newIndex];
|
||||||
|
|
||||||
if (newState.sector != null) SetNewSector(oldState, newState);
|
if (newState.sector != null && newState.sector != oldState.sector) SetNewSector(oldState, newState);
|
||||||
if(newState.orbit != null) SetNewOrbit(newState);
|
if (newState.orbit != null && newState.orbit != oldState.orbit) SetNewOrbit(newState);
|
||||||
|
|
||||||
_currentIndex = newIndex;
|
_currentIndex = newIndex;
|
||||||
|
|
||||||
@ -94,6 +97,19 @@ namespace NewHorizons.Components
|
|||||||
_rb.SetVelocity(currentOrbit.GetOrbitalParameters(primaryGravity, secondaryGravity).InitialVelocity);
|
_rb.SetVelocity(currentOrbit.GetOrbitalParameters(primaryGravity, secondaryGravity).InitialVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPlayerBlink()
|
||||||
|
{
|
||||||
|
if (base.IsVisible())
|
||||||
|
{
|
||||||
|
base.Collapse(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsPlayerEntangled()
|
||||||
|
{
|
||||||
|
return states[_currentIndex].sector.ContainsAnyOccupants(DynamicOccupant.Player);
|
||||||
|
}
|
||||||
|
|
||||||
public class State
|
public class State
|
||||||
{
|
{
|
||||||
public Sector sector { get; set; }
|
public Sector sector { get; set; }
|
||||||
|
|||||||
@ -166,7 +166,16 @@ namespace NewHorizons.Handlers
|
|||||||
var rootSector = quantumPlanet.GetComponentInChildren<Sector>();
|
var rootSector = quantumPlanet.GetComponentInChildren<Sector>();
|
||||||
var groundOrbit = _dict[ao].Config.Orbit;
|
var groundOrbit = _dict[ao].Config.Orbit;
|
||||||
|
|
||||||
quantumPlanet.states.Add(new QuantumPlanet.State(rootSector, groundOrbit));
|
quantumPlanet.groundState = new QuantumPlanet.State(rootSector, groundOrbit);
|
||||||
|
quantumPlanet.states.Add(quantumPlanet.groundState);
|
||||||
|
|
||||||
|
var visibilityTracker = new GameObject("VisibilityTracker_Sphere");
|
||||||
|
visibilityTracker.transform.parent = existingPlanet.transform;
|
||||||
|
visibilityTracker.transform.localPosition = Vector3.zero;
|
||||||
|
var sphere = visibilityTracker.AddComponent<SphereShape>();
|
||||||
|
sphere.radius = GetSphereOfInfluence(_dict[ao]);
|
||||||
|
var tracker = visibilityTracker.AddComponent<ShapeVisibilityTracker>();
|
||||||
|
quantumPlanet._visibilityTrackers = new VisibilityTracker[] { tracker };
|
||||||
}
|
}
|
||||||
|
|
||||||
var rb = existingPlanet.GetComponent<OWRigidbody>();
|
var rb = existingPlanet.GetComponent<OWRigidbody>();
|
||||||
@ -177,10 +186,10 @@ namespace NewHorizons.Handlers
|
|||||||
SharedGenerateBody(body, existingPlanet, sector, rb);
|
SharedGenerateBody(body, existingPlanet, sector, rb);
|
||||||
|
|
||||||
// If nothing was generated then forget the sector
|
// If nothing was generated then forget the sector
|
||||||
if (sector.transform.childCount == 0) sector = null;
|
if (sector.transform.childCount == 0) sector = quantumPlanet.groundState.sector;
|
||||||
|
|
||||||
// If semimajor axis is 0 then forget the orbit
|
// If semimajor axis is 0 then forget the orbit
|
||||||
var orbit = body.Config.Orbit.SemiMajorAxis == 0 ? null : body.Config.Orbit;
|
var orbit = body.Config.Orbit.SemiMajorAxis == 0 ? quantumPlanet.groundState.orbit : body.Config.Orbit;
|
||||||
|
|
||||||
quantumPlanet.states.Add(new QuantumPlanet.State(sector, orbit));
|
quantumPlanet.states.Add(new QuantumPlanet.State(sector, orbit));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user