diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs
index bce32058..c04cf8cf 100644
--- a/NewHorizons/Builder/General/SpawnPointBuilder.cs
+++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs
@@ -13,9 +13,22 @@ namespace NewHorizons.Builder.General
public static class SpawnPointBuilder
{
private static bool suitUpQueued = false;
+
+ // Ship
+ public static SpawnModule.ShipSpawnPoint ShipSpawnInfo { get; private set; }
public static SpawnPoint ShipSpawn { get; private set; }
public static Vector3 ShipSpawnOffset { get; private set; }
+ // Player
+ public static SpawnModule.PlayerSpawnPoint PlayerSpawnInfo { get; private set; }
+ public static SpawnPoint PlayerSpawn { get; private set; }
+
+ public static void OverridePlayerSpawn(SpawnPoint newSpawn)
+ {
+ PlayerSpawn = newSpawn;
+ PlayerSpawnInfo = null;
+ }
+
public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbody owRigidBody)
{
SpawnPoint playerSpawn = null;
@@ -34,6 +47,12 @@ namespace NewHorizons.Builder.General
// This was a stupid hack to stop players getting stuck in the ground and now we have to keep it forever
spawnGO.transform.position += spawnGO.transform.TransformDirection(module.playerSpawn.offset ?? Vector3.up * 4f);
+
+ if (PlayerSpawn == null || module.playerSpawn.GetPriority() > PlayerSpawnInfo.GetPriority())
+ {
+ PlayerSpawn = playerSpawn;
+ PlayerSpawnInfo = module.playerSpawn;
+ }
}
if (module.shipSpawn != null)
@@ -52,10 +71,11 @@ namespace NewHorizons.Builder.General
var shipSpawnOffset = module.shipSpawn.offset ?? (module.shipSpawn.alignRadial.GetValueOrDefault() ? Vector3.up * 4 : Vector3.zero);
- if (ShipSpawn == null || module.shipSpawn.IsDefault())
+ if (ShipSpawn == null || module.shipSpawn.GetPriority() > ShipSpawnInfo.GetPriority())
{
ShipSpawn = shipSpawn;
ShipSpawnOffset = shipSpawnOffset;
+ ShipSpawnInfo = module.shipSpawn;
}
spawnGO.SetActive(true);
diff --git a/NewHorizons/External/Modules/SpawnModule.cs b/NewHorizons/External/Modules/SpawnModule.cs
index 8b70bb3c..1105ca06 100644
--- a/NewHorizons/External/Modules/SpawnModule.cs
+++ b/NewHorizons/External/Modules/SpawnModule.cs
@@ -35,34 +35,41 @@ namespace NewHorizons.External.Modules
///
/// Whether this planet's spawn point is the one the player/ship will initially spawn at, if multiple spawn points exist.
/// Do not use at the same time as makeDefaultIfFactRevealed or makeDefaultIfPersistentCondition
+ /// Spawns unlocked with this have lowest priority
///
public bool isDefault;
///
/// If the given ship log fact is revealed, this spawn point will be used
/// Do not use at the same time as isDefault or makeDefaultIfPersistentCondition
+ /// Spawns unlocked with this have highest priority
///
public string makeDefaultIfFactRevealed;
///
/// If the given persistent condition is true, this spawn point will be used
/// Do not use at the same time as isDefault or makeDefaultIfFactRevealed
+ /// Spawns unlocked with this have second highest priority
///
public string makeDefaultIfPersistentCondition;
- public bool IsDefault()
+ public int GetPriority()
{
if (!string.IsNullOrEmpty(makeDefaultIfFactRevealed) && ShipLogHandler.KnowsFact(makeDefaultIfFactRevealed))
{
- return true;
+ return 2;
}
if (!string.IsNullOrEmpty(makeDefaultIfPersistentCondition) && PlayerData.GetPersistentCondition(makeDefaultIfPersistentCondition))
{
- return true;
+ return 1;
+ }
+ if (isDefault)
+ {
+ return 0;
}
else
{
- return isDefault;
+ return -1;
}
}
}
diff --git a/NewHorizons/External/NewHorizonsSystem.cs b/NewHorizons/External/NewHorizonsSystem.cs
index 07f1ba08..f4928f17 100644
--- a/NewHorizons/External/NewHorizonsSystem.cs
+++ b/NewHorizons/External/NewHorizonsSystem.cs
@@ -1,5 +1,4 @@
using NewHorizons.External.Configs;
-using NewHorizons.External.Modules;
using OWML.Common;
using System.Linq;
@@ -9,10 +8,9 @@ namespace NewHorizons.External
{
public string UniqueID;
public string RelativePath;
- public SpawnModule Spawn = null;
- public SpawnPoint SpawnPoint = null;
public StarSystemConfig Config;
public IModBehaviour Mod;
+ public bool HasShipSpawn;
public NewHorizonsSystem(string uniqueID, StarSystemConfig config, string relativePath, IModBehaviour mod)
{
diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs
index fe68519f..44d083c4 100644
--- a/NewHorizons/Handlers/PlanetCreationHandler.cs
+++ b/NewHorizons/Handlers/PlanetCreationHandler.cs
@@ -502,13 +502,6 @@ namespace NewHorizons.Handlers
{
NHLogger.LogVerbose($"Making spawn point on {body.Config.name}");
var spawnPoint = SpawnPointBuilder.Make(go, body.Config.Spawn, owRigidBody);
- var isVanillaSystem = body.Config.starSystem == "SolarSystem" || body.Config.starSystem == "EyeOfTheUniverse";
- var needsSpawnPoint = Main.SystemDict[body.Config.starSystem].SpawnPoint == null || isVanillaSystem;
- var isDefaultSpawn = body.Config.Spawn.playerSpawn?.IsDefault() ?? true; // Backwards compat
- if (needsSpawnPoint || isDefaultSpawn)
- {
- Main.SystemDict[body.Config.starSystem].SpawnPoint = spawnPoint;
- }
}
if (body.Config.Orbit.showOrbitLine && !body.Config.Orbit.isStatic)
diff --git a/NewHorizons/Handlers/PlayerSpawnHandler.cs b/NewHorizons/Handlers/PlayerSpawnHandler.cs
index dd4f4f27..af78874a 100644
--- a/NewHorizons/Handlers/PlayerSpawnHandler.cs
+++ b/NewHorizons/Handlers/PlayerSpawnHandler.cs
@@ -200,8 +200,8 @@ namespace NewHorizons.Handlers
return vector;
}
- public static bool UsingCustomSpawn() => Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint != null;
+ public static bool UsingCustomSpawn() => SpawnPointBuilder.PlayerSpawn != null;
public static PlayerSpawner GetPlayerSpawner() => GameObject.FindObjectOfType();
- public static SpawnPoint GetDefaultSpawn() => Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint ?? GetPlayerSpawner().GetSpawnPoint(SpawnLocation.TimberHearth);
+ public static SpawnPoint GetDefaultSpawn() => SpawnPointBuilder.PlayerSpawn ?? GetPlayerSpawner().GetSpawnPoint(SpawnLocation.TimberHearth);
}
}
diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs
index d063abcc..3435fd19 100644
--- a/NewHorizons/Handlers/StarChartHandler.cs
+++ b/NewHorizons/Handlers/StarChartHandler.cs
@@ -130,7 +130,7 @@ namespace NewHorizons.Handlers
var canWarpTo = false;
if (system.Equals("SolarSystem")) canWarpTo = true;
else if (system.Equals("EyeOfTheUniverse")) canWarpTo = false;
- else if (config.Spawn?.shipSpawn != null) canWarpTo = true;
+ else if (config.HasShipSpawn) canWarpTo = true;
var canEnterViaWarpDrive = Main.SystemDict[system].Config.canEnterViaWarpDrive || system == "SolarSystem";
diff --git a/NewHorizons/Handlers/VesselWarpHandler.cs b/NewHorizons/Handlers/VesselWarpHandler.cs
index 26195e5c..bac8fdf7 100644
--- a/NewHorizons/Handlers/VesselWarpHandler.cs
+++ b/NewHorizons/Handlers/VesselWarpHandler.cs
@@ -1,3 +1,4 @@
+using NewHorizons.Builder.General;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.Components.EyeOfTheUniverse;
@@ -240,7 +241,7 @@ namespace NewHorizons.Handlers
VesselSpawnPoint spawnPoint = vesselObject.GetComponentInChildren(true);
if (ShouldSpawnAtVessel())
{
- system.SpawnPoint = spawnPoint;
+ SpawnPointBuilder.OverridePlayerSpawn(spawnPoint);
}
vesselObject.SetActive(true);
diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs
index f8f18718..0eb502ab 100644
--- a/NewHorizons/Main.cs
+++ b/NewHorizons/Main.cs
@@ -789,9 +789,6 @@ namespace NewHorizons
if (body != null)
{
- // Wanna track the spawn point of each system
- if (body.Config.Spawn != null) SystemDict[body.Config.starSystem].Spawn = body.Config.Spawn;
-
// Add the new planet to the planet dictionary
if (!BodyDict.ContainsKey(body.Config.starSystem)) BodyDict[body.Config.starSystem] = new List();
BodyDict[body.Config.starSystem].Add(body);
@@ -924,6 +921,12 @@ namespace NewHorizons
config.Validate();
config.Migrate();
+ // Check if this system can be warped to
+ if (config.Spawn?.shipSpawn != null)
+ {
+ SystemDict[config.starSystem].HasShipSpawn = true;
+ }
+
return new NewHorizonsBody(config, mod, relativePath);
}