Ship spawn (#711)

## Bug fixes
- Allow setting ship spawns in main solar system / separately from the
player spawn. Implements #677
This commit is contained in:
Nick 2023-08-25 22:23:43 -04:00 committed by GitHub
commit 72e984f531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 25 deletions

View File

@ -259,7 +259,7 @@ namespace NewHorizons.Components.ShipLog
if (!name.Equals(uniqueID)) return name;
// Else we return a default name
if (uniqueID.Equals("SolarSystem")) return "Hearthian System";
if (uniqueID.Equals("SolarSystem")) return "The Outer Wilds";
var splitString = uniqueID.Split('.');
if (splitString.Length > 1) splitString = splitString.Skip(1).ToArray();

View File

@ -391,7 +391,8 @@ namespace NewHorizons.Handlers
if (defaultPrimaryToSun)
{
NHLogger.LogError($"Couldn't find {body.Config.Orbit.primaryBody}, defaulting to center of solar system");
primaryBody = Locator.GetCenterOfTheUniverse().GetAttachedOWRigidbody().GetComponent<AstroObject>();
// TODO: Make this work in other systems. We tried using Locator.GetCenterOfUniverse before but that doesn't work since its too early now
primaryBody = SearchUtilities.Find("Sun_Body")?.GetComponent<AstroObject>();
}
else
{

View File

@ -51,24 +51,38 @@ namespace NewHorizons.Handlers
// Ensures it has invoked everything and actually placed the player in the cloaking field #671
cloak._firstUpdate = true;
}
// Spawn ship
Delay.FireInNUpdates(SpawnShip, 30);
}
public static void SpawnShip()
{
var ship = SearchUtilities.Find("Ship_Body");
if (ship != null)
if (SpawnPointBuilder.ShipSpawn != null)
{
ship.SetActive(true);
NHLogger.Log("Spawning player ship");
var pos = SpawnPointBuilder.ShipSpawn.transform.position;
// Move it up a bit more when aligning to surface
if (SpawnPointBuilder.ShipSpawnOffset != null)
if (ship != null)
{
pos += SpawnPointBuilder.ShipSpawn.transform.TransformDirection(SpawnPointBuilder.ShipSpawnOffset);
}
ship.SetActive(true);
SpawnBody(ship.GetAttachedOWRigidbody(), SpawnPointBuilder.ShipSpawn, pos);
var pos = SpawnPointBuilder.ShipSpawn.transform.position;
// Move it up a bit more when aligning to surface
if (SpawnPointBuilder.ShipSpawnOffset != null)
{
pos += SpawnPointBuilder.ShipSpawn.transform.TransformDirection(SpawnPointBuilder.ShipSpawnOffset);
}
SpawnBody(ship.GetAttachedOWRigidbody(), SpawnPointBuilder.ShipSpawn, pos);
}
}
else if (Main.Instance.CurrentStarSystem != "SolarSystem" && !Main.Instance.IsWarpingFromShip)
{
NHLogger.Log("System has no ship spawn. Deactivating it.");
ship?.SetActive(false);
}
}
@ -81,20 +95,6 @@ namespace NewHorizons.Handlers
}
InvulnerabilityHandler.MakeInvulnerable(false);
if (!Main.Instance.IsWarpingFromShip)
{
if (SpawnPointBuilder.ShipSpawn != null)
{
NHLogger.Log("Spawning player ship");
SpawnShip();
}
else
{
NHLogger.Log("System has no ship spawn. Deactivating it.");
SearchUtilities.Find("Ship_Body")?.SetActive(false);
}
}
}
private static void FixPlayerVelocity()