mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Allow changing stock planet orbit (except for primary body)
This commit is contained in:
parent
90cff5bfc2
commit
3699c3a9b7
@ -21,10 +21,15 @@ namespace NewHorizons.Builder.Orbital
|
|||||||
return Update(initialMotion, body, primaryBody, OWRB, orbit);
|
return Update(initialMotion, body, primaryBody, OWRB, orbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float SiderealPeriodToAngularSpeed(float siderealPeriod)
|
||||||
|
{
|
||||||
|
return siderealPeriod == 0 ? 0f : 2f * Mathf.PI / (siderealPeriod * 60f);
|
||||||
|
}
|
||||||
|
|
||||||
public static InitialMotion Update(InitialMotion initialMotion, GameObject body, AstroObject primaryBody, OWRigidbody OWRB, OrbitModule orbit)
|
public static InitialMotion Update(InitialMotion initialMotion, GameObject body, AstroObject primaryBody, OWRigidbody OWRB, OrbitModule orbit)
|
||||||
{
|
{
|
||||||
// Rotation
|
// Rotation
|
||||||
initialMotion.SetValue("_initAngularSpeed", orbit.SiderealPeriod == 0 ? 0f : 2f * Mathf.PI / (orbit.SiderealPeriod * 60f));
|
initialMotion.SetValue("_initAngularSpeed", SiderealPeriodToAngularSpeed(orbit.SiderealPeriod));
|
||||||
|
|
||||||
var rotationAxis = Quaternion.AngleAxis(orbit.AxialTilt + 90f, Vector3.right) * Vector3.up;
|
var rotationAxis = Quaternion.AngleAxis(orbit.AxialTilt + 90f, Vector3.right) * Vector3.up;
|
||||||
body.transform.rotation = Quaternion.FromToRotation(Vector3.up, rotationAxis);
|
body.transform.rotation = Quaternion.FromToRotation(Vector3.up, rotationAxis);
|
||||||
|
|||||||
2
NewHorizons/External/OrbitModule.cs
vendored
2
NewHorizons/External/OrbitModule.cs
vendored
@ -9,7 +9,7 @@ namespace NewHorizons.External
|
|||||||
{
|
{
|
||||||
public class OrbitModule : Module
|
public class OrbitModule : Module
|
||||||
{
|
{
|
||||||
public int SemiMajorAxis { get; set; } = 5000;
|
public int SemiMajorAxis { get; set; }
|
||||||
public float Inclination { get; set; }
|
public float Inclination { get; set; }
|
||||||
public string PrimaryBody { get; set; }
|
public string PrimaryBody { get; set; }
|
||||||
public bool IsMoon { get; set; }
|
public bool IsMoon { get; set; }
|
||||||
|
|||||||
2
NewHorizons/External/PlanetConfig.cs
vendored
2
NewHorizons/External/PlanetConfig.cs
vendored
@ -33,7 +33,7 @@ namespace NewHorizons.External
|
|||||||
|
|
||||||
public PlanetConfig(Dictionary<string, object> dict)
|
public PlanetConfig(Dictionary<string, object> dict)
|
||||||
{
|
{
|
||||||
// Always have to have a base module and orbit module
|
// Always have to have a base module
|
||||||
Base = new BaseModule();
|
Base = new BaseModule();
|
||||||
Orbit = new OrbitModule();
|
Orbit = new OrbitModule();
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,8 @@ using OWML.Common;
|
|||||||
using OWML.ModHelper;
|
using OWML.ModHelper;
|
||||||
using OWML.Utils;
|
using OWML.Utils;
|
||||||
using PacificEngine.OW_CommonResources.Game.Player;
|
using PacificEngine.OW_CommonResources.Game.Player;
|
||||||
|
using PacificEngine.OW_CommonResources.Game.Resource;
|
||||||
|
using PacificEngine.OW_CommonResources.Game.State;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -421,7 +423,64 @@ namespace NewHorizons
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do stuff that's shared between generating new planets and updating old ones
|
// Do stuff that's shared between generating new planets and updating old ones
|
||||||
return SharedGenerateBody(body, go, sector, rb);
|
go = SharedGenerateBody(body, go, sector, rb);
|
||||||
|
|
||||||
|
// Update a position using CommonResources
|
||||||
|
// Since orbits are always there just check if they set a semi major axis
|
||||||
|
if (body.Config.Orbit != null && body.Config.Orbit.SemiMajorAxis != 0f)
|
||||||
|
{
|
||||||
|
var mapping = Planet.defaultMapping;
|
||||||
|
var heavenlyBody = CommonResourcesUtilities.HeavenlyBodyFromAstroObject(AstroObjectLocator.GetAstroObject(body.Config.Name));
|
||||||
|
|
||||||
|
Logger.Log($"Updating position of {body.Config.Name} -> {heavenlyBody}");
|
||||||
|
|
||||||
|
if (heavenlyBody != PacificEngine.OW_CommonResources.Game.Resource.HeavenlyBody.None)
|
||||||
|
{
|
||||||
|
var original = mapping[heavenlyBody];
|
||||||
|
|
||||||
|
var targetScale = original.state.orbit.scale;
|
||||||
|
var coords = OrbitalHelper.KeplerCoordinatesFromOrbitModule(body.Config.Orbit);
|
||||||
|
var orientation = original.state.orbit.orientation;
|
||||||
|
|
||||||
|
var parent = original.state.parent;
|
||||||
|
if (body.Config.Orbit.PrimaryBody != null)
|
||||||
|
{
|
||||||
|
var parentAO = AstroObjectLocator.GetAstroObject(body.Config.Orbit.PrimaryBody);
|
||||||
|
var newParent = CommonResourcesUtilities.HeavenlyBodyFromAstroObject(parentAO);
|
||||||
|
if (newParent != HeavenlyBody.None)
|
||||||
|
{
|
||||||
|
parent = newParent;
|
||||||
|
// Have to change the gravity stuff
|
||||||
|
go.GetComponentInChildren<ConstantForceDetector>()._detectableFields = new ForceVolume[] { parentAO.GetGravityVolume() };
|
||||||
|
go.GetComponent<AstroObject>()._primaryBody = parentAO;
|
||||||
|
Logger.Log($"WHO???? {body.Config.Name}, {parentAO.name}");
|
||||||
|
//Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => UpdatePosition(go, body, parentAO));
|
||||||
|
}
|
||||||
|
else Logger.LogError($"Couldn't find new parent {body.Config.Orbit.PrimaryBody}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Log($"{body.Config.Name} has parent {parent}");
|
||||||
|
var planetoid = new Planet.Plantoid(
|
||||||
|
original.size,
|
||||||
|
original.gravity,
|
||||||
|
go.transform.rotation,
|
||||||
|
InitialMotionBuilder.SiderealPeriodToAngularSpeed(body.Config.Orbit.SiderealPeriod),
|
||||||
|
parent,
|
||||||
|
coords
|
||||||
|
);
|
||||||
|
|
||||||
|
mapping[heavenlyBody] = planetoid;
|
||||||
|
|
||||||
|
Planet.defaultMapping = mapping;
|
||||||
|
Planet.mapping = mapping;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.LogError($"Couldn't find heavenlyBody for {body.Config.Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Load
|
#endregion Load
|
||||||
@ -504,13 +563,7 @@ namespace NewHorizons
|
|||||||
body.Object = go;
|
body.Object = go;
|
||||||
|
|
||||||
// Now that we're done move the planet into place
|
// Now that we're done move the planet into place
|
||||||
go.transform.parent = Locator.GetRootTransform();
|
UpdatePosition(go, body, primaryBody);
|
||||||
go.transform.position = OrbitalHelper.GetCartesian(new OrbitalHelper.Gravity(1, 100), body.Config.Orbit).Item1 + (primaryBody == null ? Vector3.zero : primaryBody.transform.position);
|
|
||||||
|
|
||||||
if (go.transform.position.magnitude > FurthestOrbit)
|
|
||||||
{
|
|
||||||
FurthestOrbit = go.transform.position.magnitude + 30000f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Have to do this after setting position
|
// Have to do this after setting position
|
||||||
var initialMotion = InitialMotionBuilder.Make(go, primaryBody, owRigidBody, body.Config.Orbit);
|
var initialMotion = InitialMotionBuilder.Make(go, primaryBody, owRigidBody, body.Config.Orbit);
|
||||||
@ -603,6 +656,17 @@ namespace NewHorizons
|
|||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdatePosition(GameObject go, NewHorizonsBody body, AstroObject primaryBody)
|
||||||
|
{
|
||||||
|
go.transform.parent = Locator.GetRootTransform();
|
||||||
|
go.transform.position = OrbitalHelper.GetCartesian(new OrbitalHelper.Gravity(1, 100), body.Config.Orbit).Item1 + (primaryBody == null ? Vector3.zero : primaryBody.transform.position);
|
||||||
|
|
||||||
|
if (go.transform.position.magnitude > FurthestOrbit)
|
||||||
|
{
|
||||||
|
FurthestOrbit = go.transform.position.magnitude + 30000f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Body generation
|
#endregion Body generation
|
||||||
|
|
||||||
#region Change star system
|
#region Change star system
|
||||||
|
|||||||
61
NewHorizons/Utility/CommonResourcesUtilities.cs
Normal file
61
NewHorizons/Utility/CommonResourcesUtilities.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using PacificEngine.OW_CommonResources.Game.Resource;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewHorizons.Utility
|
||||||
|
{
|
||||||
|
public static class CommonResourcesUtilities
|
||||||
|
{
|
||||||
|
public static HeavenlyBody HeavenlyBodyFromAstroObject(AstroObject obj)
|
||||||
|
{
|
||||||
|
switch (obj.GetAstroObjectName())
|
||||||
|
{
|
||||||
|
case AstroObject.Name.CustomString:
|
||||||
|
return HeavenlyBody.FromString(obj.GetCustomName());
|
||||||
|
case AstroObject.Name.BrittleHollow:
|
||||||
|
return HeavenlyBodies.BrittleHollow;
|
||||||
|
case AstroObject.Name.CaveTwin:
|
||||||
|
return HeavenlyBodies.EmberTwin;
|
||||||
|
case AstroObject.Name.Comet:
|
||||||
|
return HeavenlyBodies.Interloper;
|
||||||
|
case AstroObject.Name.DarkBramble:
|
||||||
|
return HeavenlyBodies.DarkBramble;
|
||||||
|
case AstroObject.Name.DreamWorld:
|
||||||
|
return HeavenlyBodies.DreamWorld;
|
||||||
|
case AstroObject.Name.GiantsDeep:
|
||||||
|
return HeavenlyBodies.GiantsDeep;
|
||||||
|
case AstroObject.Name.HourglassTwins:
|
||||||
|
return HeavenlyBodies.HourglassTwins;
|
||||||
|
case AstroObject.Name.MapSatellite:
|
||||||
|
return HeavenlyBodies.SatiliteMapping;
|
||||||
|
case AstroObject.Name.ProbeCannon:
|
||||||
|
return HeavenlyBodies.ProbeCannon;
|
||||||
|
case AstroObject.Name.QuantumMoon:
|
||||||
|
return HeavenlyBodies.QuantumMoon;
|
||||||
|
case AstroObject.Name.RingWorld:
|
||||||
|
return HeavenlyBodies.Stranger;
|
||||||
|
case AstroObject.Name.Sun:
|
||||||
|
return HeavenlyBodies.Sun;
|
||||||
|
case AstroObject.Name.SunStation:
|
||||||
|
return HeavenlyBodies.SunStation;
|
||||||
|
case AstroObject.Name.TimberHearth:
|
||||||
|
return HeavenlyBodies.TimberHearth;
|
||||||
|
case AstroObject.Name.TimberMoon:
|
||||||
|
return HeavenlyBodies.Attlerock;
|
||||||
|
case AstroObject.Name.TowerTwin:
|
||||||
|
return HeavenlyBodies.AshTwin;
|
||||||
|
case AstroObject.Name.VolcanicMoon:
|
||||||
|
return HeavenlyBodies.HollowLantern;
|
||||||
|
case AstroObject.Name.WhiteHole:
|
||||||
|
return HeavenlyBodies.WhiteHole;
|
||||||
|
case AstroObject.Name.WhiteHoleTarget:
|
||||||
|
return HeavenlyBodies.WhiteHoleStation;
|
||||||
|
default:
|
||||||
|
return HeavenlyBodies.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -99,60 +99,67 @@ namespace NewHorizons.Utility
|
|||||||
|
|
||||||
public static GameObject Find(string path)
|
public static GameObject Find(string path)
|
||||||
{
|
{
|
||||||
var go = GameObject.Find(path);
|
try
|
||||||
|
|
||||||
var names = path.Split(new char[] { '\\', '/' });
|
|
||||||
if (go == null)
|
|
||||||
{
|
{
|
||||||
|
var go = GameObject.Find(path);
|
||||||
|
|
||||||
// Get the root object and hope its the right one
|
var names = path.Split(new char[] { '\\', '/' });
|
||||||
var root = GameObject.Find(names[0]);
|
if (go == null)
|
||||||
if (root == null) root = FindObjectOfTypeAndName<GameObject>(names[0]);
|
|
||||||
|
|
||||||
var t = root?.transform;
|
|
||||||
if (t == null)
|
|
||||||
{
|
{
|
||||||
Logger.LogWarning($"Couldn't find root object in path ({names[0]})");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 1; i < names.Length; i++)
|
// Get the root object and hope its the right one
|
||||||
{
|
var root = GameObject.Find(names[0]);
|
||||||
var child = t.transform.Find(names[i]);
|
if (root == null) root = FindObjectOfTypeAndName<GameObject>(names[0]);
|
||||||
|
|
||||||
if(child == null)
|
var t = root?.transform;
|
||||||
|
if (t == null)
|
||||||
{
|
{
|
||||||
foreach(Transform c in t.GetComponentsInChildren<Transform>(true))
|
Logger.LogWarning($"Couldn't find root object in path ({names[0]})");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i < names.Length; i++)
|
||||||
|
{
|
||||||
|
var child = t.transform.Find(names[i]);
|
||||||
|
|
||||||
|
if (child == null)
|
||||||
{
|
{
|
||||||
if(t.name.Equals(names[i]))
|
foreach (Transform c in t.GetComponentsInChildren<Transform>(true))
|
||||||
{
|
{
|
||||||
child = c;
|
if (t.name.Equals(names[i]))
|
||||||
break;
|
{
|
||||||
|
child = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (child == null)
|
||||||
|
{
|
||||||
|
Logger.LogWarning($"Couldn't find object in path ({names[i]})");
|
||||||
|
t = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
t = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child == null)
|
go = t?.gameObject;
|
||||||
{
|
|
||||||
Logger.LogWarning($"Couldn't find object in path ({names[i]})");
|
|
||||||
t = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
t = child;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
go = t?.gameObject;
|
if (go == null)
|
||||||
}
|
{
|
||||||
|
var name = names.Last();
|
||||||
|
Logger.LogWarning($"Couldn't find object {path}, will look for potential matches for name {name}");
|
||||||
|
go = FindObjectOfTypeAndName<GameObject>(name);
|
||||||
|
}
|
||||||
|
|
||||||
if(go == null)
|
return go;
|
||||||
|
}
|
||||||
|
catch(Exception)
|
||||||
{
|
{
|
||||||
var name = names.Last();
|
return null;
|
||||||
Logger.LogWarning($"Couldn't find object {path}, will look for potential matches for name {name}");
|
|
||||||
go = FindObjectOfTypeAndName<GameObject>(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return go;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user