Smooth docking traversal (#10822)

This commit is contained in:
metalgearsloth
2022-08-29 15:05:53 +10:00
committed by GitHub
parent 0ebc733b3a
commit 5b42861539
14 changed files with 515 additions and 204 deletions

View File

@@ -25,9 +25,6 @@ namespace Content.Server.GameTicking
{
private const string ObserverPrototypeName = "MobObserver";
[ViewVariables(VVAccess.ReadWrite), Obsolete("Due for removal when observer spawning is refactored.")] // See also: MindComponent's OnShutdown shitcode
private EntityCoordinates _spawnPoint;
/// <summary>
/// How many players have joined the round through normal methods.
/// Useful for game rules to look at. Doesn't count observers, people in lobby, etc.
@@ -280,24 +277,72 @@ namespace Content.Server.GameTicking
#region Spawn Points
public EntityCoordinates GetObserverSpawnPoint()
{
// TODO rename this to TryGetObserverSpawnPoint to make it clear that the result might be invalid. Or at
// least try try more fallback values, like randomly spawning them in any available map or just creating a
// "we fucked up" map. Its better than dumping them into the void.
var location = _spawnPoint.IsValid(EntityManager) ? _spawnPoint : EntityCoordinates.Invalid;
_possiblePositions.Clear();
foreach (var (point, transform) in EntityManager.EntityQuery<SpawnPointComponent, TransformComponent>(true))
{
if (point.SpawnType == SpawnPointType.Observer)
_possiblePositions.Add(transform.Coordinates);
if (point.SpawnType != SpawnPointType.Observer)
continue;
_possiblePositions.Add(transform.Coordinates);
}
var metaQuery = GetEntityQuery<MetaDataComponent>();
// Fallback to a random grid.
if (_possiblePositions.Count == 0)
{
foreach (var grid in _mapManager.GetAllGrids())
{
if (!metaQuery.TryGetComponent(grid.GridEntityId, out var meta) ||
meta.EntityPaused)
{
continue;
}
_possiblePositions.Add(new EntityCoordinates(grid.GridEntityId, Vector2.Zero));
}
}
if (_possiblePositions.Count != 0)
location = _robustRandom.Pick(_possiblePositions);
{
// TODO: This is just here for the eye lerping.
// Ideally engine would just spawn them on grid directly I guess? Right now grid traversal is handling it during
// update which means we need to add a hack somewhere around it.
var spawn = _robustRandom.Pick(_possiblePositions);
var toMap = spawn.ToMap(EntityManager);
return location;
if (_mapManager.TryFindGridAt(toMap, out var foundGrid))
{
return new EntityCoordinates(foundGrid.GridEntityId,
foundGrid.InvWorldMatrix.Transform(toMap.Position));
}
return spawn;
}
if (_mapManager.MapExists(DefaultMap))
{
return new EntityCoordinates(_mapManager.GetMapEntityId(DefaultMap), Vector2.Zero);
}
// Just pick a point at this point I guess.
foreach (var map in _mapManager.GetAllMapIds())
{
var mapUid = _mapManager.GetMapEntityId(map);
if (!metaQuery.TryGetComponent(mapUid, out var meta) ||
meta.EntityPaused)
{
continue;
}
return new EntityCoordinates(mapUid, Vector2.Zero);
}
// AAAAAAAAAAAAA
_sawmill.Error("Found no observer spawn points!");
return EntityCoordinates.Invalid;
}
#endregion
}