mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Put circumbinary gravity directly on focalpoint (remove fake barycenter)
Fixes #221
This commit is contained in:
parent
a6b3911e93
commit
6b5b12dbde
@ -44,15 +44,9 @@ namespace NewHorizons.Builder.General
|
|||||||
|
|
||||||
public static void SetDetector(AstroObject primaryBody, AstroObject astroObject, ConstantForceDetector forceDetector)
|
public static void SetDetector(AstroObject primaryBody, AstroObject astroObject, ConstantForceDetector forceDetector)
|
||||||
{
|
{
|
||||||
GravityVolume parentGravityVolume = primaryBody?.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
|
|
||||||
if (parentGravityVolume != null)
|
|
||||||
{
|
|
||||||
forceDetector._detectableFields = new ForceVolume[] { parentGravityVolume };
|
|
||||||
}
|
|
||||||
else if (astroObject != null)
|
|
||||||
{
|
|
||||||
// It's probably a focal point (or its just broken)
|
|
||||||
var binaryFocalPoint = primaryBody?.gameObject?.GetComponent<BinaryFocalPoint>();
|
var binaryFocalPoint = primaryBody?.gameObject?.GetComponent<BinaryFocalPoint>();
|
||||||
|
var parentGravityVolume = primaryBody?.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
|
||||||
|
|
||||||
if (binaryFocalPoint != null)
|
if (binaryFocalPoint != null)
|
||||||
{
|
{
|
||||||
if (astroObject.GetCustomName().Equals(binaryFocalPoint.PrimaryName))
|
if (astroObject.GetCustomName().Equals(binaryFocalPoint.PrimaryName))
|
||||||
@ -78,11 +72,13 @@ namespace NewHorizons.Builder.General
|
|||||||
// It's a planet
|
// It's a planet
|
||||||
if (binaryFocalPoint.Primary != null && binaryFocalPoint.Secondary != null)
|
if (binaryFocalPoint.Primary != null && binaryFocalPoint.Secondary != null)
|
||||||
{
|
{
|
||||||
var fakeBarycenterGravityVolume = binaryFocalPoint.FakeMassBody.GetComponent<AstroObject>().GetGravityVolume();
|
forceDetector._detectableFields = new ForceVolume[] { parentGravityVolume };
|
||||||
forceDetector._detectableFields = new ForceVolume[] { fakeBarycenterGravityVolume };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
forceDetector._detectableFields = new ForceVolume[] { parentGravityVolume };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using NewHorizons.External.Modules;
|
|||||||
using NewHorizons.Handlers;
|
using NewHorizons.Handlers;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using OWML.Common;
|
using OWML.Common;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
namespace NewHorizons.Builder.Orbital
|
namespace NewHorizons.Builder.Orbital
|
||||||
@ -18,12 +19,10 @@ namespace NewHorizons.Builder.Orbital
|
|||||||
binary.PrimaryName = module.primary;
|
binary.PrimaryName = module.primary;
|
||||||
binary.SecondaryName = module.secondary;
|
binary.SecondaryName = module.secondary;
|
||||||
|
|
||||||
// Below is the stupid fix for making circumbinary planets or wtv
|
|
||||||
|
|
||||||
// Grab the bodies from the main dictionary
|
// Grab the bodies from the main dictionary
|
||||||
NewHorizonsBody primary = null;
|
NewHorizonsBody primary = null;
|
||||||
NewHorizonsBody secondary = null;
|
NewHorizonsBody secondary = null;
|
||||||
foreach (var body in Main.BodyDict[Main.Instance.CurrentStarSystem])
|
foreach (var body in Main.BodyDict[config.starSystem])
|
||||||
{
|
{
|
||||||
if (body.Config.name == module.primary)
|
if (body.Config.name == module.primary)
|
||||||
{
|
{
|
||||||
@ -44,28 +43,26 @@ namespace NewHorizons.Builder.Orbital
|
|||||||
Logger.LogError($"Couldn't make focal point between [{module.primary} = {primary}] and [{module.secondary} = {secondary}]");
|
Logger.LogError($"Couldn't make focal point between [{module.primary} = {primary}] and [{module.secondary} = {secondary}]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ValidateConfig(PlanetConfig config)
|
||||||
|
{
|
||||||
|
var primary = Main.BodyDict[config.starSystem].Where(x => x.Config.name == config.FocalPoint.primary).FirstOrDefault();
|
||||||
|
var secondary = Main.BodyDict[config.starSystem].Where(x => x.Config.name == config.FocalPoint.secondary).FirstOrDefault();
|
||||||
|
|
||||||
var gravitationalMass = GetGravitationalMass(primary.Config) + GetGravitationalMass(secondary.Config);
|
var gravitationalMass = GetGravitationalMass(primary.Config) + GetGravitationalMass(secondary.Config);
|
||||||
|
|
||||||
// Copying it because I don't want to modify the actual config
|
|
||||||
var fakeMassConfig = new PlanetConfig();
|
|
||||||
|
|
||||||
// Now need to fake the 3 values to make it return this mass
|
// Now need to fake the 3 values to make it return this mass
|
||||||
fakeMassConfig.Base.surfaceSize = 1;
|
config.Base.surfaceSize = 1;
|
||||||
fakeMassConfig.Base.surfaceGravity = gravitationalMass * GravityVolume.GRAVITATIONAL_CONSTANT;
|
config.Base.surfaceGravity = gravitationalMass * GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||||
fakeMassConfig.Base.gravityFallOff = primary.Config.Base.gravityFallOff;
|
config.Base.gravityFallOff = primary.Config.Base.gravityFallOff;
|
||||||
|
|
||||||
// Other stuff to make the fake barycenter not interact with anything in any way
|
// Other stuff to make the barycenter not interact with anything in any way
|
||||||
fakeMassConfig.name = config.name + "_FakeBarycenterMass";
|
config.Base.soiOverride = 0;
|
||||||
fakeMassConfig.Base.soiOverride = 0;
|
|
||||||
fakeMassConfig.Base.hasMapMarker = false;
|
|
||||||
fakeMassConfig.ReferenceFrame.enabled = false;
|
|
||||||
fakeMassConfig.ReferenceFrame.hideInMap = true;
|
|
||||||
|
|
||||||
fakeMassConfig.Orbit = new OrbitModule();
|
var separation = primary.Config.Orbit.semiMajorAxis + secondary.Config.Orbit.semiMajorAxis;
|
||||||
fakeMassConfig.Orbit.CopyPropertiesFrom(config.Orbit);
|
config.ReferenceFrame.bracketRadius = separation;
|
||||||
|
config.ReferenceFrame.targetColliderRadius = separation;
|
||||||
binary.FakeMassBody = PlanetCreationHandler.GenerateBody(new NewHorizonsBody(fakeMassConfig, mod));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float GetGravitationalMass(PlanetConfig config)
|
private static float GetGravitationalMass(PlanetConfig config)
|
||||||
|
|||||||
@ -70,8 +70,8 @@ namespace NewHorizons.Builder.Orbital
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// It's a circumbinary moon/planet
|
// It's a circumbinary moon/planet
|
||||||
var fakePrimaryBody = focalPoint.FakeMassBody.GetComponent<AstroObject>();
|
var focalPointAO = focalPoint.GetComponent<AstroObject>();
|
||||||
SetMotionFromPrimary(fakePrimaryBody, secondaryBody, secondaryBody as NHAstroObject, initialMotion);
|
SetMotionFromPrimary(focalPointAO, secondaryBody, secondaryBody as NHAstroObject, initialMotion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (primaryBody.GetGravityVolume())
|
else if (primaryBody.GetGravityVolume())
|
||||||
@ -107,11 +107,11 @@ namespace NewHorizons.Builder.Orbital
|
|||||||
// Might make binaries with binaries with binaries work
|
// Might make binaries with binaries with binaries work
|
||||||
if (primaryBody.GetGravityVolume() == null)
|
if (primaryBody.GetGravityVolume() == null)
|
||||||
{
|
{
|
||||||
primaryGravity = new Gravity(primaryBody.GetComponent<BinaryFocalPoint>()?.FakeMassBody?.GetComponent<AstroObject>()?.GetGravityVolume());
|
primaryGravity = new Gravity(primaryBody.GetGravityVolume());
|
||||||
}
|
}
|
||||||
if (secondaryBody.GetGravityVolume() == null)
|
if (secondaryBody.GetGravityVolume() == null)
|
||||||
{
|
{
|
||||||
secondaryGravity = new Gravity(secondaryBody.GetComponent<BinaryFocalPoint>()?.FakeMassBody?.GetComponent<AstroObject>()?.GetGravityVolume());
|
secondaryGravity = new Gravity(secondaryBody.GetGravityVolume());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the positions
|
// Update the positions
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
namespace NewHorizons.Components.Orbital
|
namespace NewHorizons.Components.Orbital
|
||||||
{
|
{
|
||||||
public class BinaryFocalPoint : MonoBehaviour
|
public class BinaryFocalPoint : MonoBehaviour
|
||||||
@ -9,14 +9,6 @@ namespace NewHorizons.Components.Orbital
|
|||||||
public AstroObject Primary { get; set; }
|
public AstroObject Primary { get; set; }
|
||||||
public AstroObject Secondary { get; set; }
|
public AstroObject Secondary { get; set; }
|
||||||
|
|
||||||
public GameObject FakeMassBody { get; set; }
|
|
||||||
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
// Make sure its active but maybe it hasn't been set yet
|
|
||||||
if (FakeMassBody) FakeMassBody.SetActive(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (Primary == null || Secondary == null)
|
if (Primary == null || Secondary == null)
|
||||||
@ -48,8 +40,6 @@ namespace NewHorizons.Components.Orbital
|
|||||||
{
|
{
|
||||||
component2.DisableMarker();
|
component2.DisableMarker();
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeMassBody.SetActive(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
NewHorizons/External/Configs/PlanetConfig.cs
vendored
1
NewHorizons/External/Configs/PlanetConfig.cs
vendored
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using NewHorizons.Builder.Orbital;
|
||||||
using NewHorizons.External.Modules;
|
using NewHorizons.External.Modules;
|
||||||
using NewHorizons.External.Modules.VariableSize;
|
using NewHorizons.External.Modules.VariableSize;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|||||||
@ -267,6 +267,9 @@ namespace NewHorizons.Handlers
|
|||||||
// Only called when making new planets
|
// Only called when making new planets
|
||||||
public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
|
public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
|
||||||
{
|
{
|
||||||
|
// Focal points are weird
|
||||||
|
if (body.Config.FocalPoint != null) FocalPointBuilder.ValidateConfig(body.Config);
|
||||||
|
|
||||||
AstroObject primaryBody;
|
AstroObject primaryBody;
|
||||||
if (body.Config.Orbit.primaryBody != null)
|
if (body.Config.Orbit.primaryBody != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user