Fix the what bug again (#723)

## Bug fixes
- Log an error when trying to orbit a body that doesn't have a gravity
volume.
This commit is contained in:
Will Corby 2023-08-31 20:33:49 -07:00 committed by GitHub
commit f082d2de81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 13 deletions

View File

@ -143,13 +143,15 @@ namespace NewHorizons.Builder.General
// It's a planet
if (binaryFocalPoint.Primary != null && binaryFocalPoint.Secondary != null)
{
forceDetector._detectableFields = new ForceVolume[] { parentGravityVolume };
if (!parentGravityVolume) NHLogger.LogError($"{astroObject?.name} trying to orbit {primaryBody?.name}, which has no gravity volume!");
forceDetector._detectableFields = parentGravityVolume ? new ForceVolume[] { parentGravityVolume } : new ForceVolume[0];
}
}
}
else
{
forceDetector._detectableFields = new ForceVolume[] { parentGravityVolume };
if (!parentGravityVolume) NHLogger.LogError($"{astroObject?.name} trying to orbit {primaryBody?.name}, which has no gravity volume!");
forceDetector._detectableFields = parentGravityVolume ? new ForceVolume[] { parentGravityVolume } : new ForceVolume[0];
}
}
@ -164,7 +166,7 @@ namespace NewHorizons.Builder.General
var primaryGV = primary.GetGravityVolume();
var secondaryGV = secondary.GetGravityVolume();
if (primaryGV._falloffType != secondaryGV._falloffType)
if (primaryGV && secondaryGV && primaryGV._falloffType != secondaryGV._falloffType)
{
NHLogger.LogError($"Binaries must have the same gravity falloff! {primaryGV._falloffType} != {secondaryGV._falloffType}");
return;
@ -173,15 +175,17 @@ namespace NewHorizons.Builder.General
var pointForceDetector = point.GetAttachedOWRigidbody().GetAttachedForceDetector();
// Set detectable fields
primaryCFD._detectableFields = new ForceVolume[] { secondaryGV };
if (!secondaryGV) NHLogger.LogError($"{point.PrimaryName} trying to orbit {point.SecondaryName}, which has no gravity volume!");
primaryCFD._detectableFields = secondaryGV ? new ForceVolume[] { secondaryGV } : new ForceVolume[0];
primaryCFD._inheritDetector = pointForceDetector;
primaryCFD._activeInheritedDetector = pointForceDetector;
primaryCFD._inheritElement0 = false;
secondaryCFD._detectableFields = new ForceVolume[] { primaryGV };
if (!primaryGV) NHLogger.LogError($"{point.SecondaryName} trying to orbit {point.PrimaryName}, which has no gravity volume!");
secondaryCFD._detectableFields = primaryGV ? new ForceVolume[] { primaryGV } : new ForceVolume[0];
secondaryCFD._inheritDetector = pointForceDetector;
secondaryCFD._activeInheritedDetector = pointForceDetector;
secondaryCFD._inheritElement0 = false;
}
}
}
}

View File

@ -382,8 +382,9 @@ namespace NewHorizons.Builder.Props
else if (component is NomaiInterfaceOrb orb)
{
// detect planet gravity
// somehow Intervention has GetAttachedOWRigidbody as null sometimes, idk why
var gravityVolume = planetGO.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
orb.GetComponent<ConstantForceDetector>()._detectableFields = gravityVolume ? new ForceVolume[] { gravityVolume } : new ForceVolume[] { };
orb.GetComponent<ConstantForceDetector>()._detectableFields = gravityVolume ? new ForceVolume[] { gravityVolume } : new ForceVolume[0];
}
else if (component is VisionTorchItem torchItem)

View File

@ -137,7 +137,10 @@ namespace NewHorizons.Builder.Props
orbBody._lastVelocity = velocity;
orbBody._currentVelocity = velocity;
orb.GetComponent<ConstantForceDetector>()._detectableFields = new ForceVolume[] { planetGO.GetComponentInChildren<GravityVolume>() };
// detect planet gravity
// somehow Intervention has GetAttachedOWRigidbody as null sometimes, idk why
var gravityVolume = planetGO.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
orb.GetComponent<ConstantForceDetector>()._detectableFields = gravityVolume ? new ForceVolume[] { gravityVolume } : new ForceVolume[0];
Delay.RunWhenAndInNUpdates(() =>
{

View File

@ -15,9 +15,8 @@
<DebugType>none</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HarmonyX" Version="2.10.1" />
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.457" />
<PackageReference Include="OWML" Version="2.9.3" />
<PackageReference Include="OWML" Version="2.9.7" />
<Reference Include="../Lib/System.ComponentModel.Annotations.dll" />
</ItemGroup>
<ItemGroup>

View File

@ -1,7 +1,7 @@
using HarmonyLib;
using NewHorizons.Utility.OWML;
namespace NewHorizons.Patches.PlayerPatches
namespace NewHorizons.Patches.DetectorPatches
{
[HarmonyPatch(typeof(HazardDetector))]
public static class PlayerHazardDetectorPatches

View File

@ -4,8 +4,8 @@
"author": "xen, Bwc9876, clay, MegaPiggy, John, Trifid, Hawkbar, Book",
"name": "New Horizons",
"uniqueName": "xen.NewHorizons",
"version": "1.16.3",
"owmlVersion": "2.9.3",
"version": "1.16.4",
"owmlVersion": "2.9.7",
"dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ],
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],
"pathsToPreserve": [ "planets", "systems", "translations" ]