1
0

EvacShuttleTest.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.Linq;
  2. using Content.Server.GameTicking;
  3. using Content.Server.Shuttles.Components;
  4. using Content.Server.Shuttles.Systems;
  5. using Content.Server.Station.Components;
  6. using Content.Shared.CCVar;
  7. using Content.Shared.Shuttles.Components;
  8. using Robust.Shared.GameObjects;
  9. using Robust.Shared.Map.Components;
  10. namespace Content.IntegrationTests.Tests.Station;
  11. [TestFixture]
  12. [TestOf(typeof(EmergencyShuttleSystem))]
  13. public sealed class EvacShuttleTest
  14. {
  15. /// <summary>
  16. /// Ensure that the emergency shuttle can be called, and that it will travel to centcomm
  17. /// </summary>
  18. [Test]
  19. public async Task EmergencyEvacTest()
  20. {
  21. await using var pair = await PoolManager.GetServerClient(new PoolSettings { DummyTicker = true, Dirty = true });
  22. var server = pair.Server;
  23. var entMan = server.EntMan;
  24. var ticker = server.System<GameTicker>();
  25. // Dummy ticker tests should not have centcomm
  26. Assert.That(entMan.Count<StationCentcommComponent>(), Is.Zero);
  27. Assert.That(pair.Server.CfgMan.GetCVar(CCVars.GridFill), Is.False);
  28. pair.Server.CfgMan.SetCVar(CCVars.EmergencyShuttleEnabled, true);
  29. pair.Server.CfgMan.SetCVar(CCVars.GameDummyTicker, false);
  30. var gameMap = pair.Server.CfgMan.GetCVar(CCVars.GameMap);
  31. pair.Server.CfgMan.SetCVar(CCVars.GameMap, "Saltern");
  32. await server.WaitPost(() => ticker.RestartRound());
  33. await pair.RunTicksSync(25);
  34. Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.InRound));
  35. // Find the station, centcomm, and shuttle, and ftl map.
  36. Assert.That(entMan.Count<StationCentcommComponent>(), Is.EqualTo(1));
  37. Assert.That(entMan.Count<StationEmergencyShuttleComponent>(), Is.EqualTo(1));
  38. Assert.That(entMan.Count<StationDataComponent>(), Is.EqualTo(1));
  39. Assert.That(entMan.Count<EmergencyShuttleComponent>(), Is.EqualTo(1));
  40. Assert.That(entMan.Count<FTLMapComponent>(), Is.EqualTo(0));
  41. var station = (Entity<StationCentcommComponent>) entMan.AllComponentsList<StationCentcommComponent>().Single();
  42. var data = entMan.GetComponent<StationDataComponent>(station);
  43. var shuttleData = entMan.GetComponent<StationEmergencyShuttleComponent>(station);
  44. var saltern = data.Grids.Single();
  45. Assert.That(entMan.HasComponent<MapGridComponent>(saltern));
  46. var shuttle = shuttleData.EmergencyShuttle!.Value;
  47. Assert.That(entMan.HasComponent<EmergencyShuttleComponent>(shuttle));
  48. Assert.That(entMan.HasComponent<MapGridComponent>(shuttle));
  49. var centcomm = station.Comp.Entity!.Value;
  50. Assert.That(entMan.HasComponent<MapGridComponent>(centcomm));
  51. var centcommMap = station.Comp.MapEntity!.Value;
  52. Assert.That(entMan.HasComponent<MapComponent>(centcommMap));
  53. Assert.That(server.Transform(centcomm).MapUid, Is.EqualTo(centcommMap));
  54. var salternXform = server.Transform(saltern);
  55. Assert.That(salternXform.MapUid, Is.Not.Null);
  56. Assert.That(salternXform.MapUid, Is.Not.EqualTo(centcommMap));
  57. var shuttleXform = server.Transform(shuttle);
  58. Assert.That(shuttleXform.MapUid, Is.Not.Null);
  59. Assert.That(shuttleXform.MapUid, Is.EqualTo(centcommMap));
  60. // All of these should have been map-initialized.
  61. var mapSys = entMan.System<SharedMapSystem>();
  62. Assert.That(mapSys.IsInitialized(centcommMap), Is.True);
  63. Assert.That(mapSys.IsInitialized(salternXform.MapUid), Is.True);
  64. Assert.That(mapSys.IsPaused(centcommMap), Is.False);
  65. Assert.That(mapSys.IsPaused(salternXform.MapUid!.Value), Is.False);
  66. EntityLifeStage LifeStage(EntityUid uid) => entMan.GetComponent<MetaDataComponent>(uid).EntityLifeStage;
  67. Assert.That(LifeStage(saltern), Is.EqualTo(EntityLifeStage.MapInitialized));
  68. Assert.That(LifeStage(shuttle), Is.EqualTo(EntityLifeStage.MapInitialized));
  69. Assert.That(LifeStage(centcomm), Is.EqualTo(EntityLifeStage.MapInitialized));
  70. Assert.That(LifeStage(centcommMap), Is.EqualTo(EntityLifeStage.MapInitialized));
  71. Assert.That(LifeStage(salternXform.MapUid.Value), Is.EqualTo(EntityLifeStage.MapInitialized));
  72. // Set up shuttle timing
  73. var shuttleSys = server.System<ShuttleSystem>();
  74. var evacSys = server.System<EmergencyShuttleSystem>();
  75. evacSys.TransitTime = shuttleSys.DefaultTravelTime; // Absolute minimum transit time, so the test has to run for at least this long
  76. // TODO SHUTTLE fix spaghetti
  77. var dockTime = server.CfgMan.GetCVar(CCVars.EmergencyShuttleDockTime);
  78. server.CfgMan.SetCVar(CCVars.EmergencyShuttleDockTime, 2);
  79. // Call evac shuttle.
  80. await pair.WaitCommand("callshuttle 0:02");
  81. await pair.RunSeconds(3);
  82. // Shuttle should have arrived on the station
  83. Assert.That(shuttleXform.MapUid, Is.EqualTo(salternXform.MapUid));
  84. await pair.RunSeconds(2);
  85. // Shuttle should be FTLing back to centcomm
  86. Assert.That(entMan.Count<FTLMapComponent>(), Is.EqualTo(1));
  87. var ftl = (Entity<FTLMapComponent>) entMan.AllComponentsList<FTLMapComponent>().Single();
  88. Assert.That(entMan.HasComponent<MapComponent>(ftl));
  89. Assert.That(ftl.Owner, Is.Not.EqualTo(centcommMap));
  90. Assert.That(ftl.Owner, Is.Not.EqualTo(salternXform.MapUid));
  91. Assert.That(shuttleXform.MapUid, Is.EqualTo(ftl.Owner));
  92. // Shuttle should have arrived at centcomm
  93. await pair.RunSeconds(shuttleSys.DefaultTravelTime);
  94. Assert.That(shuttleXform.MapUid, Is.EqualTo(centcommMap));
  95. // Round should be ending now
  96. Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PostRound));
  97. server.CfgMan.SetCVar(CCVars.EmergencyShuttleDockTime, dockTime);
  98. pair.Server.CfgMan.SetCVar(CCVars.EmergencyShuttleEnabled, false);
  99. pair.Server.CfgMan.SetCVar(CCVars.GameMap, gameMap);
  100. await pair.CleanReturnAsync();
  101. }
  102. }