diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index cc7feddf..bce32058 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -42,15 +42,21 @@ namespace NewHorizons.Builder.General spawnGO.SetActive(false); spawnGO.layer = Layer.PlayerSafetyCollider; - ShipSpawn = spawnGO.AddComponent(); - ShipSpawn._isShipSpawn = true; - ShipSpawn._attachedBody = owRigidBody; - ShipSpawn._spawnLocation = SpawnLocation.None; + var shipSpawn = spawnGO.AddComponent(); + shipSpawn._isShipSpawn = true; + shipSpawn._attachedBody = owRigidBody; + shipSpawn._spawnLocation = SpawnLocation.None; // #601 we need to actually set the right trigger volumes here - ShipSpawn._triggerVolumes = new OWTriggerVolume[0]; + shipSpawn._triggerVolumes = new OWTriggerVolume[0]; - 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()) + { + ShipSpawn = shipSpawn; + ShipSpawnOffset = shipSpawnOffset; + } spawnGO.SetActive(true); } diff --git a/NewHorizons/External/Modules/SpawnModule.cs b/NewHorizons/External/Modules/SpawnModule.cs index f8af3fa1..8b70bb3c 100644 --- a/NewHorizons/External/Modules/SpawnModule.cs +++ b/NewHorizons/External/Modules/SpawnModule.cs @@ -1,4 +1,5 @@ using NewHorizons.External.SerializableData; +using NewHorizons.Handlers; using Newtonsoft.Json; using System; @@ -30,6 +31,40 @@ namespace NewHorizons.External.Modules /// Offsets the player/ship by this local vector when spawning. Used to prevent spawning in the floor. Optional: defaults to (0, 4, 0). /// public MVector3 offset; + + /// + /// 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 + /// + 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 + /// + 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 + /// + public string makeDefaultIfPersistentCondition; + + public bool IsDefault() + { + if (!string.IsNullOrEmpty(makeDefaultIfFactRevealed) && ShipLogHandler.KnowsFact(makeDefaultIfFactRevealed)) + { + return true; + } + if (!string.IsNullOrEmpty(makeDefaultIfPersistentCondition) && PlayerData.GetPersistentCondition(makeDefaultIfPersistentCondition)) + { + return true; + } + else + { + return isDefault; + } + } } [JsonObject] @@ -39,12 +74,6 @@ namespace NewHorizons.External.Modules /// If you spawn on a planet with no oxygen, you probably want to set this to true ;;) /// public bool startWithSuit; - /// - /// Whether this planet's spawn point is the one the player will initially spawn at, if multiple spawn points exist. - /// - public bool isDefault; - - } [JsonObject] diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index fda247e7..fe68519f 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -504,7 +504,7 @@ namespace NewHorizons.Handlers 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 + var isDefaultSpawn = body.Config.Spawn.playerSpawn?.IsDefault() ?? true; // Backwards compat if (needsSpawnPoint || isDefaultSpawn) { Main.SystemDict[body.Config.starSystem].SpawnPoint = spawnPoint;