Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Central Command #20

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Content.Client/LateJoin/LateJoinGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ private void RebuildUI()
if (!_gameTicker.DisallowedLateJoin && _gameTicker.StationNames.Count == 0)
Logger.Warning("No stations exist, nothing to display in late-join GUI");

foreach (var (id, name) in _gameTicker.StationNames)
foreach (var (id, name) in _gameTicker.StationNames
.OrderBy(x=> x.Value.Contains("Central Command") ? 1 : -1) // Corvax-Next-Centcomm
)
{
var jobList = new BoxContainer
{
Expand Down
51 changes: 51 additions & 0 deletions Content.Server/Objectives/Systems/KillPersonConditionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System.Linq; // Corvax-Next-Centcomm
using Content.Server.Objectives.Components;
using Content.Server.Revolutionary.Components;
using Content.Server.Shuttles.Systems;
using Content.Server.Station.Components; // Corvax-Next-Centcomm
using Content.Shared.CCVar;
using Content.Shared.Mind;
using Content.Shared.Objectives.Components;
using Content.Shared.Roles; // Corvax-Next-Centcomm
using Content.Shared.Roles.Jobs; // Corvax-Next-Centcomm
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes; // Corvax-Next-Centcomm
using Robust.Shared.Random;

namespace Content.Server.Objectives.Systems;
Expand All @@ -19,6 +24,10 @@ public sealed class KillPersonConditionSystem : EntitySystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
[Dependency] private readonly TargetObjectiveSystem _target = default!;
[Dependency] private readonly SharedRoleSystem _roleSystem = default!; // Corvax-Next-Centcomm
[Dependency] private readonly IPrototypeManager _prototype = default!; // Corvax-Next-Centcomm

private static readonly ProtoId<DepartmentPrototype> _ccDep = "CentralCommandCorvax"; // Corvax-Next-Centcomm

public override void Initialize()
{
Expand Down Expand Up @@ -60,9 +69,41 @@ private void OnPersonAssigned(EntityUid uid, PickRandomPersonComponent comp, ref
return;
}

// Corvax-Next-Centcomm-Start
FilterCentCom(allHumans);

if (allHumans.Count == 0)
{
args.Cancelled = true;
return;
}
// Corvax-Next-Centcomm-End

_target.SetTarget(uid, _random.Pick(allHumans), target);

}

// Corvax-Next-Centcomm-Start
private void FilterCentCom(List<EntityUid> minds)
{
var centcom = _prototype.Index(_ccDep);
foreach (var mindId in minds.ToArray())
{
if (!_roleSystem.MindHasRole<JobRoleComponent>(mindId, out var job) || job.Value.Comp1.JobPrototype == null)
{
continue;
}

if (!centcom.Roles.Contains(job.Value.Comp1.JobPrototype.Value))
{
continue;
}
Comment on lines +97 to +100

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В целях возможности использовать код повторно стоило добавить в прототип профессии поле на разрешение быть целью антагониста.

Тогда и сам метод желательно переименовать в что-то более общее, типо там FilterByJob(). Хотя не уверен в чём смысл вообще выделять эту часть кода в отдельный метод

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В целях возможности использовать код повторно стоило добавить в прототип профессии поле на разрешение быть целью антагониста.

Тогда и сам метод желательно переименовать в что-то более общее, типо там FilterByJob(). Хотя не уверен в чём смысл вообще выделять эту часть кода в отдельный метод

Не вижу смысла добавлять это кому-либо кроме ЦКшных


minds.Remove(mindId);
}
}
// Corvax-Next-Centcomm-End

private void OnHeadAssigned(EntityUid uid, PickRandomHeadComponent comp, ref ObjectiveAssignedEvent args)
{
// invalid prototype
Expand All @@ -84,6 +125,16 @@ private void OnHeadAssigned(EntityUid uid, PickRandomHeadComponent comp, ref Obj
return;
}

// Corvax-Next-Centcomm-Start
FilterCentCom(allHumans);

if (allHumans.Count == 0)
{
args.Cancelled = true;
return;
}
// Corvax-Next-Centcomm-End

var allHeads = new List<EntityUid>();
foreach (var person in allHumans)
{
Expand Down
103 changes: 21 additions & 82 deletions Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes; // Corvax-Next-Centcomm
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
Expand Down Expand Up @@ -69,6 +70,8 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly Content.Server._CorvaxNext.Arrivals.CentcommSystem _centcommSystem = default!; // Corvax-Next-Centcomm


private const float ShuttleSpawnBuffer = 1f;

Expand All @@ -86,7 +89,7 @@ public override void Initialize()
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundCleanup);
SubscribeLocalEvent<StationEmergencyShuttleComponent, StationPostInitEvent>(OnStationStartup);
SubscribeLocalEvent<StationCentcommComponent, ComponentShutdown>(OnCentcommShutdown);
//SubscribeLocalEvent<StationCentcommComponent, ComponentShutdown>(OnCentcommShutdown);// Corvax-Next-Centcomm
SubscribeLocalEvent<StationCentcommComponent, MapInitEvent>(OnStationInit);

SubscribeLocalEvent<EmergencyShuttleComponent, FTLStartedEvent>(OnEmergencyFTL);
Expand Down Expand Up @@ -396,6 +399,8 @@ public void AnnounceShuttleDock(ShuttleDockResult result, bool extended)

// TODO: Need filter extensions or something don't blame me.
_audio.PlayGlobal(audioFile, Filter.Broadcast(), true);

_centcommSystem.EnableFtl(_centcommSystem.CentComMapUid); // // Corvax-Next-Centcomm
}

private void OnStationInit(EntityUid uid, StationCentcommComponent component, MapInitEvent args)
Expand Down Expand Up @@ -495,90 +500,34 @@ private void SetupEmergencyShuttle()
}
}

// Corvax-Next-Centcomm-Start
private void AddCentcomm(EntityUid station, StationCentcommComponent component)
{
DebugTools.Assert(LifeStage(station) >= EntityLifeStage.MapInitialized);
var centcom = EntityManager.System<Content.Server._CorvaxNext.Arrivals.CentcommSystem>();
DebugTools.Assert(LifeStage(station)>= EntityLifeStage.MapInitialized);
if (component.MapEntity != null || component.Entity != null)
{
Log.Warning("Attempted to re-add an existing centcomm map.");
return;
}

// Check for existing centcomms and just point to that
var query = AllEntityQuery<StationCentcommComponent>();
while (query.MoveNext(out var otherComp))
{
if (otherComp == component)
continue;

if (!Exists(otherComp.MapEntity) || !Exists(otherComp.Entity))
{
Log.Error($"Discovered invalid centcomm component?");
ClearCentcomm(otherComp);
continue;
}

component.MapEntity = otherComp.MapEntity;
component.Entity = otherComp.Entity;
component.ShuttleIndex = otherComp.ShuttleIndex;
return;
}

if (string.IsNullOrEmpty(component.Map.ToString()))
{
Log.Warning("No CentComm map found, skipping setup.");
return;
}
centcom.EnsureCentcom(true);

var map = _mapSystem.CreateMap(out var mapId);
var grid = _map.LoadGrid(mapId, component.Map.ToString(), new MapLoadOptions()
{
LoadMap = false,
});

if (!Exists(map))
{
Log.Error($"Failed to set up centcomm map!");
QueueDel(grid);
return;
}

if (!Exists(grid))
{
Log.Error($"Failed to set up centcomm grid!");
QueueDel(map);
return;
}

var xform = Transform(grid.Value);
if (xform.ParentUid != map || xform.MapUid != map)
{
Log.Error($"Centcomm grid is not parented to its own map?");
QueueDel(map);
QueueDel(grid);
return;
}

component.MapEntity = map;
_metaData.SetEntityName(map, Loc.GetString("map-name-centcomm"));
component.Entity = grid;
_shuttle.TryAddFTLDestination(mapId, true, out _);
Log.Info($"Created centcomm grid {ToPrettyString(grid)} on map {ToPrettyString(map)} for station {ToPrettyString(station)}");
component.MapEntity = centcom.CentComMapUid;
component.Entity = centcom.CentComGrid;
component.ShuttleIndex = centcom.ShuttleIndex;
Log.Info($"Attached centcomm grid {ToPrettyString(centcom.CentComGrid)} on map {ToPrettyString(centcom.CentComMapUid)} for station {ToPrettyString(station)}");
}

public HashSet<EntityUid> GetCentcommMaps()
{
var query = AllEntityQuery<StationCentcommComponent>();
var maps = new HashSet<EntityUid>(Count<StationCentcommComponent>());
var maps = new HashSet<EntityUid>();

while (query.MoveNext(out var comp))
{
if (comp.MapEntity != null)
maps.Add(comp.MapEntity.Value);
}
if(_centcommSystem.CentComMapUid.IsValid())
maps.Add(_centcommSystem.CentComMapUid);

return maps;
}
// Corvax-Next-Centcomm-End

private void AddEmergencyShuttle(Entity<StationEmergencyShuttleComponent?, StationCentcommComponent?> ent)
{
Expand Down Expand Up @@ -611,7 +560,7 @@ private void AddEmergencyShuttle(Entity<StationEmergencyShuttleComponent?, Stati
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 + ent.Comp2.ShuttleIndex, 0f),
Offset = new Vector2(500f + _centcommSystem.ShuttleIndex, 0f), // Corvax-Next-Centcomm
// 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,
});
Expand All @@ -622,18 +571,8 @@ private void AddEmergencyShuttle(Entity<StationEmergencyShuttleComponent?, Stati
return;
}

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 == ent.Comp2 || comp.MapEntity != ent.Comp2.MapEntity)
continue;

comp.ShuttleIndex = ent.Comp2.ShuttleIndex;
}
_centcommSystem.ShuttleIndex += Comp<MapGridComponent>(shuttle.Value).LocalAABB.Width + ShuttleSpawnBuffer; // Corvax-Next-Centcomm
ent.Comp2.ShuttleIndex = _centcommSystem.ShuttleIndex; // Corvax-Next-Centcomm

ent.Comp1.EmergencyShuttle = shuttle;
EnsureComp<ProtectedGridComponent>(shuttle.Value);
Expand Down
Loading
Loading