mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Messy Merge
This commit is contained in:
commit
c39906bbe7
@ -2,6 +2,7 @@
|
|||||||
using NewHorizons.OrbitalPhysics;
|
using NewHorizons.OrbitalPhysics;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using OWML.Common;
|
using OWML.Common;
|
||||||
|
using OWML.Utils;
|
||||||
using PacificEngine.OW_CommonResources.Game;
|
using PacificEngine.OW_CommonResources.Game;
|
||||||
using PacificEngine.OW_CommonResources.Game.Resource;
|
using PacificEngine.OW_CommonResources.Game.Resource;
|
||||||
using PacificEngine.OW_CommonResources.Game.State;
|
using PacificEngine.OW_CommonResources.Game.State;
|
||||||
@ -12,6 +13,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
|
|
||||||
namespace NewHorizons.Builder.General
|
namespace NewHorizons.Builder.General
|
||||||
{
|
{
|
||||||
@ -35,15 +37,43 @@ namespace NewHorizons.Builder.General
|
|||||||
{
|
{
|
||||||
hb = AddHeavenlyBody(config.Name);
|
hb = AddHeavenlyBody(config.Name);
|
||||||
}
|
}
|
||||||
var planetoid = new Planet.Plantoid(size, gravity, body.transform.rotation, initialMotion._initAngularSpeed, parent, orbit);
|
|
||||||
|
|
||||||
var mapping = Planet.defaultMapping;
|
if(!config.Orbit.IsStatic)
|
||||||
mapping[hb] = planetoid;
|
{
|
||||||
Planet.defaultMapping = mapping;
|
var planetoid = new Planet.Plantoid(size, gravity, body.transform.rotation, initialMotion._initAngularSpeed, parent, orbit);
|
||||||
|
|
||||||
|
var mapping = Planet.defaultMapping;
|
||||||
|
mapping[hb] = planetoid;
|
||||||
|
Planet.defaultMapping = mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix for binary focal points
|
||||||
|
var focalPoint = Position.AstroLookup[parent].Invoke()?.gameObject.GetComponent<BinaryFocalPoint>();
|
||||||
|
if (focalPoint != null && Planet.defaultMapping.ContainsKey(parent))
|
||||||
|
{
|
||||||
|
var primary = Position.getBody(GetBody(focalPoint.PrimaryName));
|
||||||
|
var secondary = Position.getBody(GetBody(focalPoint.SecondaryName));
|
||||||
|
|
||||||
|
if(primary != null && secondary != null)
|
||||||
|
{
|
||||||
|
Logger.Log($"Fixing BinaryFocalPoint HeavenlyBody gravity value for {parent.name}");
|
||||||
|
var exponent = ((primary?.GetAttachedGravityVolume()?._falloffExponent ?? 2f) + (secondary?.GetAttachedGravityVolume()?._falloffExponent ?? 2f)) / 2f;
|
||||||
|
var mass = ((primary?.GetAttachedGravityVolume()?._gravitationalMass ?? ((primary?.GetMass() ?? 0f) * 1000f)) + (secondary?.GetAttachedGravityVolume()?._gravitationalMass ?? ((secondary?.GetMass() ?? 0f) * 1000f))) / 4f;
|
||||||
|
|
||||||
|
var currentValue = Planet.mapping[parent];
|
||||||
|
var newValue = new Planet.Plantoid(currentValue.size, Gravity.of(exponent, mass), currentValue.state);
|
||||||
|
Planet.defaultMapping[parent] = newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Gravity getGravity(GravityVolume volume)
|
private static Gravity getGravity(GravityVolume volume)
|
||||||
{
|
{
|
||||||
|
if (volume == null)
|
||||||
|
{
|
||||||
|
return Gravity.of(2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
var exponent = volume._falloffType != GravityVolume.FalloffType.linear ? 2f : 1f;
|
var exponent = volume._falloffType != GravityVolume.FalloffType.linear ? 2f : 1f;
|
||||||
var mass = (volume._surfaceAcceleration * Mathf.Pow(volume._upperSurfaceRadius, exponent)) / GravityVolume.GRAVITATIONAL_CONSTANT;
|
var mass = (volume._surfaceAcceleration * Mathf.Pow(volume._upperSurfaceRadius, exponent)) / GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||||
|
|
||||||
|
|||||||
@ -89,33 +89,44 @@ namespace NewHorizons
|
|||||||
(b.Config.Orbit.IsMoon ? 2 : 1)
|
(b.Config.Orbit.IsMoon ? 2 : 1)
|
||||||
))).ToList();
|
))).ToList();
|
||||||
|
|
||||||
var flagNoneLoadedThisPass = true;
|
var count = 0;
|
||||||
while(toLoad.Count != 0)
|
while(toLoad.Count != 0)
|
||||||
{
|
{
|
||||||
|
Logger.Log($"Starting body loading pass #{++count}");
|
||||||
|
var flagNoneLoadedThisPass = true;
|
||||||
foreach (var body in toLoad)
|
foreach (var body in toLoad)
|
||||||
{
|
{
|
||||||
if (LoadBody(body))
|
if (LoadBody(body)) flagNoneLoadedThisPass = false;
|
||||||
flagNoneLoadedThisPass = false;
|
|
||||||
}
|
}
|
||||||
if (flagNoneLoadedThisPass)
|
if (flagNoneLoadedThisPass)
|
||||||
{
|
{
|
||||||
|
Logger.LogWarning("No objects were loaded this pass");
|
||||||
// Try again but default to sun
|
// Try again but default to sun
|
||||||
foreach(var body in toLoad)
|
foreach(var body in toLoad)
|
||||||
{
|
{
|
||||||
if (LoadBody(body, true))
|
if (LoadBody(body, true)) flagNoneLoadedThisPass = false;
|
||||||
flagNoneLoadedThisPass = false;
|
|
||||||
}
|
|
||||||
if(flagNoneLoadedThisPass)
|
|
||||||
{
|
|
||||||
// Give up
|
|
||||||
Logger.Log($"Couldn't finish adding bodies.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (flagNoneLoadedThisPass)
|
||||||
|
{
|
||||||
|
// Give up
|
||||||
|
Logger.Log($"Couldn't finish adding bodies.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
toLoad = NextPassBodies;
|
toLoad = NextPassBodies;
|
||||||
NextPassBodies = new List<NewHorizonsBody>();
|
NextPassBodies = new List<NewHorizonsBody>();
|
||||||
|
|
||||||
|
// Infinite loop failsafe
|
||||||
|
if (count > 10)
|
||||||
|
{
|
||||||
|
Logger.Log("Something went wrong");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.Log("Done loading bodies");
|
||||||
|
|
||||||
// I don't know what these do but they look really weird from a distance
|
// I don't know what these do but they look really weird from a distance
|
||||||
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones());
|
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,38 +1,38 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
using NewHorizons.External;
|
using NewHorizons.External;
|
||||||
using CRGravity = PacificEngine.OW_CommonResources.Geometry.Orbits.Gravity;
|
using CRGravity = PacificEngine.OW_CommonResources.Geometry.Orbits.Gravity;
|
||||||
using KeplerCoordinates = PacificEngine.OW_CommonResources.Geometry.Orbits.KeplerCoordinates;
|
using KeplerCoordinates = PacificEngine.OW_CommonResources.Geometry.Orbits.KeplerCoordinates;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wrapper class for OW_CommonResources.Geometry.Orbits functions
|
* Wrapper class for OW_CommonResources.Geometry.Orbits functions
|
||||||
*/
|
*/
|
||||||
namespace NewHorizons.OrbitalPhysics
|
namespace NewHorizons.OrbitalPhysics
|
||||||
{
|
{
|
||||||
public static class OrbitalHelper
|
public static class OrbitalHelper
|
||||||
{
|
{
|
||||||
public enum FalloffType
|
public enum FalloffType
|
||||||
{
|
{
|
||||||
inverseSquared,
|
inverseSquared,
|
||||||
linear,
|
linear,
|
||||||
none
|
none
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tuple<Vector3, Vector3> GetCartesian(Gravity gravity, OrbitModule orbit)
|
public static Tuple<Vector3, Vector3> GetCartesian(Gravity gravity, OrbitModule orbit)
|
||||||
{
|
{
|
||||||
if (orbit.SemiMajorAxis == 0)
|
if (orbit.SemiMajorAxis == 0)
|
||||||
{
|
{
|
||||||
return Tuple.Create(Vector3.zero, Vector3.zero);
|
return Tuple.Create(Vector3.zero, Vector3.zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, gravity.Exponent, gravity.Mass);
|
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, gravity.Exponent, gravity.Mass);
|
||||||
var kepler = KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
var kepler = KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
||||||
var cartesian = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler);
|
var cartesian = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler);
|
||||||
|
|
||||||
if (cartesian == null)
|
if (cartesian == null)
|
||||||
@ -44,15 +44,15 @@ namespace NewHorizons.OrbitalPhysics
|
|||||||
return cartesian;
|
return cartesian;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tuple<Vector3, Vector3> GetCartesian(Gravity gravity, ParameterizedAstroObject ao)
|
public static Tuple<Vector3, Vector3> GetCartesian(Gravity gravity, ParameterizedAstroObject ao)
|
||||||
{
|
{
|
||||||
if (ao.SemiMajorAxis == 0)
|
if (ao.SemiMajorAxis == 0)
|
||||||
{
|
{
|
||||||
return Tuple.Create(Vector3.zero, Vector3.zero);
|
return Tuple.Create(Vector3.zero, Vector3.zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, gravity.Exponent, gravity.Mass);
|
var crGravity = new CRGravity(GravityVolume.GRAVITATIONAL_CONSTANT, gravity.Exponent, gravity.Mass);
|
||||||
var kepler = KeplerCoordinates.fromTrueAnomaly(ao.Eccentricity, ao.SemiMajorAxis, ao.Inclination, ao.ArgumentOfPeriapsis, ao.LongitudeOfAscendingNode, ao.TrueAnomaly);
|
var kepler = KeplerCoordinates.fromTrueAnomaly(ao.Eccentricity, ao.SemiMajorAxis, ao.Inclination, ao.ArgumentOfPeriapsis, ao.LongitudeOfAscendingNode, ao.TrueAnomaly);
|
||||||
var cartesian = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler);
|
var cartesian = PacificEngine.OW_CommonResources.Geometry.Orbits.OrbitHelper.toCartesian(crGravity, 0f, kepler);
|
||||||
|
|
||||||
if (cartesian == null)
|
if (cartesian == null)
|
||||||
@ -64,27 +64,27 @@ namespace NewHorizons.OrbitalPhysics
|
|||||||
return cartesian;
|
return cartesian;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeplerCoordinates KeplerCoordinatesFromOrbitModule(OrbitModule orbit)
|
public static KeplerCoordinates KeplerCoordinatesFromOrbitModule(OrbitModule orbit)
|
||||||
{
|
{
|
||||||
return KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
return KeplerCoordinates.fromTrueAnomaly(orbit.Eccentricity, orbit.SemiMajorAxis, orbit.Inclination, orbit.ArgumentOfPeriapsis, orbit.LongitudeOfAscendingNode, orbit.TrueAnomaly);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Gravity
|
public class Gravity
|
||||||
{
|
{
|
||||||
public float Exponent { get; }
|
public float Exponent { get; }
|
||||||
public float Mass { get; }
|
public float Mass { get; }
|
||||||
|
|
||||||
public Gravity(float exponent, float mass)
|
public Gravity(float exponent, float mass)
|
||||||
{
|
{
|
||||||
Exponent = exponent;
|
Exponent = exponent;
|
||||||
Mass = mass;
|
Mass = mass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gravity(GravityVolume gv)
|
public Gravity(GravityVolume gv)
|
||||||
{
|
{
|
||||||
Exponent = gv.GetFalloffExponent();
|
Exponent = gv.GetFalloffExponent();
|
||||||
Mass = gv.GetStandardGravitationalParameter() / GravityVolume.GRAVITATIONAL_CONSTANT;
|
Mass = gv.GetStandardGravitationalParameter() / GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
using OWML.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UnityEngine;
|
|
||||||
using NewHorizons.Utility;
|
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
|
||||||
|
|
||||||
namespace NewHorizons.OrbitalPhysics
|
|
||||||
{
|
|
||||||
public class ParameterizedOrbitLine : EllipticOrbitLine
|
|
||||||
{
|
|
||||||
public ParameterizedAstroObject astroObject;
|
|
||||||
|
|
||||||
public override void Start()
|
|
||||||
{
|
|
||||||
base.Start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -30,7 +30,10 @@ namespace NewHorizons.Utility
|
|||||||
public static float GetFalloffExponent(this GravityVolume gv)
|
public static float GetFalloffExponent(this GravityVolume gv)
|
||||||
{
|
{
|
||||||
if (gv == null) return 0;
|
if (gv == null) return 0;
|
||||||
return (float)typeof(GravityVolume).GetField("_falloffExponent", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(gv);
|
if (gv._falloffType == GravityVolume.FalloffType.linear) return 1;
|
||||||
|
if (gv._falloffType == GravityVolume.FalloffType.inverseSquared) return 2;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToCamelCase(this string str)
|
public static string ToCamelCase(this string str)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user