SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundCleanup);
- SubscribeLocalEvent<StationEmergencyShuttleComponent, ComponentStartup>(OnStationStartup);
+ SubscribeLocalEvent<StationEmergencyShuttleComponent, StationPostInitEvent>(OnStationStartup);
SubscribeLocalEvent<StationCentcommComponent, ComponentShutdown>(OnCentcommShutdown);
- SubscribeLocalEvent<StationCentcommComponent, StationPostInitEvent>(OnStationPostInit);
+ SubscribeLocalEvent<StationCentcommComponent, MapInitEvent>(OnStationInit);
SubscribeLocalEvent<EmergencyShuttleComponent, FTLStartedEvent>(OnEmergencyFTL);
SubscribeLocalEvent<EmergencyShuttleComponent, FTLCompletedEvent>(OnEmergencyFTLComplete);
}
}
- private void OnStationPostInit(EntityUid uid, StationCentcommComponent component, ref StationPostInitEvent args)
+ private void OnStationInit(EntityUid uid, StationCentcommComponent component, MapInitEvent args)
{
+ // This is handled on map-init, so that centcomm has finished initializing by the time the StationPostInitEvent
+ // gets raised
if (!_emergencyShuttleEnabled)
return;
return;
}
- AddCentcomm(component);
+ AddCentcomm(uid, component);
}
- private void OnStationStartup(EntityUid uid, StationEmergencyShuttleComponent component, ComponentStartup args)
+ private void OnStationStartup(Entity<StationEmergencyShuttleComponent> ent, ref StationPostInitEvent args)
{
- AddEmergencyShuttle(uid, component);
+ AddEmergencyShuttle((ent, ent));
}
/// <summary>
var centcommQuery = AllEntityQuery<StationCentcommComponent>();
- while (centcommQuery.MoveNext(out var centcomm))
+ while (centcommQuery.MoveNext(out var uid, out var centcomm))
{
- AddCentcomm(centcomm);
+ AddCentcomm(uid, centcomm);
}
var query = AllEntityQuery<StationEmergencyShuttleComponent>();
while (query.MoveNext(out var uid, out var comp))
- AddEmergencyShuttle(uid, comp);
+ {
+ AddEmergencyShuttle((uid, comp));
+ }
}
- private void AddCentcomm(StationCentcommComponent component)
+ private void AddCentcomm(EntityUid station, StationCentcommComponent component)
{
+ DebugTools.Assert(LifeStage(station)>= EntityLifeStage.MapInitialized);
if (component.MapEntity != null || component.Entity != null)
{
Log.Warning("Attempted to re-add an existing centcomm map.");
if (!Exists(otherComp.MapEntity) || !Exists(otherComp.Entity))
{
- Log.Error($"Disconvered invalid centcomm component?");
+ Log.Error($"Discovered invalid centcomm component?");
ClearCentcomm(otherComp);
continue;
}
component.MapEntity = map;
component.Entity = grid;
_shuttle.TryAddFTLDestination(mapId, false, out _);
+ Log.Info($"Created centcomm grid {ToPrettyString(grid)} on map {ToPrettyString(map)} for station {ToPrettyString(station)}");
}
public HashSet<EntityUid> GetCentcommMaps()
return maps;
}
- private void AddEmergencyShuttle(EntityUid uid, StationEmergencyShuttleComponent component)
+ private void AddEmergencyShuttle(Entity<StationEmergencyShuttleComponent?, StationCentcommComponent?> ent)
{
- if (!_emergencyShuttleEnabled
- || component.EmergencyShuttle != null ||
- !TryComp<StationCentcommComponent>(uid, out var centcomm)
- || !TryComp(centcomm.MapEntity, out MapComponent? map))
+ if (!Resolve(ent.Owner, ref ent.Comp1, ref ent.Comp2))
+ return;
+
+ if (!_emergencyShuttleEnabled)
+ return;
+
+ if (ent.Comp1.EmergencyShuttle != null )
{
+ if (Exists(ent.Comp1.EmergencyShuttle))
+ {
+ Log.Error($"Attempted to add an emergency shuttle to {ToPrettyString(ent)}, despite a shuttle already existing?");
+ return;
+ }
+
+ Log.Error($"Encountered deleted emergency shuttle during initialization of {ToPrettyString(ent)}");
+ ent.Comp1.EmergencyShuttle = null;
+ }
+
+ if (!TryComp(ent.Comp2.MapEntity, out MapComponent? map))
+ {
+ Log.Error($"Failed to add emergency shuttle - centcomm has not been initialized? {ToPrettyString(ent)}");
return;
}
// Load escape shuttle
- var shuttlePath = component.EmergencyShuttlePath;
+ var shuttlePath = ent.Comp1.EmergencyShuttlePath;
var shuttle = _map.LoadGrid(map.MapId, shuttlePath.ToString(), new MapLoadOptions()
{
// Should be far enough... right? I'm too lazy to bounds check CentCom rn.
- Offset = new Vector2(500f + centcomm.ShuttleIndex, 0f),
+ Offset = new Vector2(500f + ent.Comp2.ShuttleIndex, 0f),
// fun fact: if you just fucking yeet centcomm into nullspace anytime you try to spawn the shuttle, then any distance is far enough. so lets not do that
LoadMap = false,
});
if (shuttle == null)
{
- Log.Error($"Unable to spawn emergency shuttle {shuttlePath} for {ToPrettyString(uid)}");
+ Log.Error($"Unable to spawn emergency shuttle {shuttlePath} for {ToPrettyString(ent)}");
return;
}
- centcomm.ShuttleIndex += Comp<MapGridComponent>(shuttle.Value).LocalAABB.Width + ShuttleSpawnBuffer;
+ ent.Comp2.ShuttleIndex += Comp<MapGridComponent>(shuttle.Value).LocalAABB.Width + ShuttleSpawnBuffer;
// Update indices for all centcomm comps pointing to same map
var query = AllEntityQuery<StationCentcommComponent>();
while (query.MoveNext(out var comp))
{
- if (comp == centcomm || comp.MapEntity != centcomm.MapEntity)
+ if (comp == ent.Comp2 || comp.MapEntity != ent.Comp2.MapEntity)
continue;
- comp.ShuttleIndex = centcomm.ShuttleIndex;
+ comp.ShuttleIndex = ent.Comp2.ShuttleIndex;
}
- component.EmergencyShuttle = shuttle;
+ ent.Comp1.EmergencyShuttle = shuttle;
EnsureComp<ProtectedGridComponent>(shuttle.Value);
EnsureComp<PreventPilotComponent>(shuttle.Value);
EnsureComp<EmergencyShuttleComponent>(shuttle.Value);
+
+ Log.Info($"Added emergency shuttle {ToPrettyString(shuttle)} for station {ToPrettyString(ent)} and centcomm {ToPrettyString(ent.Comp2.Entity)}");
}
/// <summary>