Should actually work now with priorities

This commit is contained in:
xen-42 2024-10-04 12:47:22 -04:00
parent 3f92573c4c
commit 25aceb676d
8 changed files with 44 additions and 22 deletions

View File

@ -13,9 +13,22 @@ namespace NewHorizons.Builder.General
public static class SpawnPointBuilder public static class SpawnPointBuilder
{ {
private static bool suitUpQueued = false; private static bool suitUpQueued = false;
// Ship
public static SpawnModule.ShipSpawnPoint ShipSpawnInfo { get; private set; }
public static SpawnPoint ShipSpawn { get; private set; } public static SpawnPoint ShipSpawn { get; private set; }
public static Vector3 ShipSpawnOffset { 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) public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbody owRigidBody)
{ {
SpawnPoint playerSpawn = null; 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 // 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); 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) 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); 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; ShipSpawn = shipSpawn;
ShipSpawnOffset = shipSpawnOffset; ShipSpawnOffset = shipSpawnOffset;
ShipSpawnInfo = module.shipSpawn;
} }
spawnGO.SetActive(true); spawnGO.SetActive(true);

View File

@ -35,34 +35,41 @@ namespace NewHorizons.External.Modules
/// <summary> /// <summary>
/// Whether this planet's spawn point is the one the player/ship will initially spawn at, if multiple spawn points exist. /// 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 /// Do not use at the same time as makeDefaultIfFactRevealed or makeDefaultIfPersistentCondition
/// Spawns unlocked with this have lowest priority
/// </summary> /// </summary>
public bool isDefault; public bool isDefault;
/// <summary> /// <summary>
/// If the given ship log fact is revealed, this spawn point will be used /// 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 /// Do not use at the same time as isDefault or makeDefaultIfPersistentCondition
/// Spawns unlocked with this have highest priority
/// </summary> /// </summary>
public string makeDefaultIfFactRevealed; public string makeDefaultIfFactRevealed;
/// <summary> /// <summary>
/// If the given persistent condition is true, this spawn point will be used /// If the given persistent condition is true, this spawn point will be used
/// Do not use at the same time as isDefault or makeDefaultIfFactRevealed /// Do not use at the same time as isDefault or makeDefaultIfFactRevealed
/// Spawns unlocked with this have second highest priority
/// </summary> /// </summary>
public string makeDefaultIfPersistentCondition; public string makeDefaultIfPersistentCondition;
public bool IsDefault() public int GetPriority()
{ {
if (!string.IsNullOrEmpty(makeDefaultIfFactRevealed) && ShipLogHandler.KnowsFact(makeDefaultIfFactRevealed)) if (!string.IsNullOrEmpty(makeDefaultIfFactRevealed) && ShipLogHandler.KnowsFact(makeDefaultIfFactRevealed))
{ {
return true; return 2;
} }
if (!string.IsNullOrEmpty(makeDefaultIfPersistentCondition) && PlayerData.GetPersistentCondition(makeDefaultIfPersistentCondition)) if (!string.IsNullOrEmpty(makeDefaultIfPersistentCondition) && PlayerData.GetPersistentCondition(makeDefaultIfPersistentCondition))
{ {
return true; return 1;
}
if (isDefault)
{
return 0;
} }
else else
{ {
return isDefault; return -1;
} }
} }
} }

View File

@ -1,5 +1,4 @@
using NewHorizons.External.Configs; using NewHorizons.External.Configs;
using NewHorizons.External.Modules;
using OWML.Common; using OWML.Common;
using System.Linq; using System.Linq;
@ -9,10 +8,9 @@ namespace NewHorizons.External
{ {
public string UniqueID; public string UniqueID;
public string RelativePath; public string RelativePath;
public SpawnModule Spawn = null;
public SpawnPoint SpawnPoint = null;
public StarSystemConfig Config; public StarSystemConfig Config;
public IModBehaviour Mod; public IModBehaviour Mod;
public bool HasShipSpawn;
public NewHorizonsSystem(string uniqueID, StarSystemConfig config, string relativePath, IModBehaviour mod) public NewHorizonsSystem(string uniqueID, StarSystemConfig config, string relativePath, IModBehaviour mod)
{ {

View File

@ -502,13 +502,6 @@ namespace NewHorizons.Handlers
{ {
NHLogger.LogVerbose($"Making spawn point on {body.Config.name}"); NHLogger.LogVerbose($"Making spawn point on {body.Config.name}");
var spawnPoint = SpawnPointBuilder.Make(go, body.Config.Spawn, owRigidBody); 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) if (body.Config.Orbit.showOrbitLine && !body.Config.Orbit.isStatic)

View File

@ -200,8 +200,8 @@ namespace NewHorizons.Handlers
return vector; 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<PlayerSpawner>(); public static PlayerSpawner GetPlayerSpawner() => GameObject.FindObjectOfType<PlayerSpawner>();
public static SpawnPoint GetDefaultSpawn() => Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint ?? GetPlayerSpawner().GetSpawnPoint(SpawnLocation.TimberHearth); public static SpawnPoint GetDefaultSpawn() => SpawnPointBuilder.PlayerSpawn ?? GetPlayerSpawner().GetSpawnPoint(SpawnLocation.TimberHearth);
} }
} }

View File

@ -130,7 +130,7 @@ namespace NewHorizons.Handlers
var canWarpTo = false; var canWarpTo = false;
if (system.Equals("SolarSystem")) canWarpTo = true; if (system.Equals("SolarSystem")) canWarpTo = true;
else if (system.Equals("EyeOfTheUniverse")) canWarpTo = false; 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"; var canEnterViaWarpDrive = Main.SystemDict[system].Config.canEnterViaWarpDrive || system == "SolarSystem";

View File

@ -1,3 +1,4 @@
using NewHorizons.Builder.General;
using NewHorizons.Builder.Props; using NewHorizons.Builder.Props;
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.Components.EyeOfTheUniverse; using NewHorizons.Components.EyeOfTheUniverse;
@ -240,7 +241,7 @@ namespace NewHorizons.Handlers
VesselSpawnPoint spawnPoint = vesselObject.GetComponentInChildren<VesselSpawnPoint>(true); VesselSpawnPoint spawnPoint = vesselObject.GetComponentInChildren<VesselSpawnPoint>(true);
if (ShouldSpawnAtVessel()) if (ShouldSpawnAtVessel())
{ {
system.SpawnPoint = spawnPoint; SpawnPointBuilder.OverridePlayerSpawn(spawnPoint);
} }
vesselObject.SetActive(true); vesselObject.SetActive(true);

View File

@ -789,9 +789,6 @@ namespace NewHorizons
if (body != null) 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 // Add the new planet to the planet dictionary
if (!BodyDict.ContainsKey(body.Config.starSystem)) BodyDict[body.Config.starSystem] = new List<NewHorizonsBody>(); if (!BodyDict.ContainsKey(body.Config.starSystem)) BodyDict[body.Config.starSystem] = new List<NewHorizonsBody>();
BodyDict[body.Config.starSystem].Add(body); BodyDict[body.Config.starSystem].Add(body);
@ -924,6 +921,12 @@ namespace NewHorizons
config.Validate(); config.Validate();
config.Migrate(); 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); return new NewHorizonsBody(config, mod, relativePath);
} }