Add TryGetPrimaryDepartment to jobs system (#23317)

* add primary departments

* make command and station specific secondary

* add a unit test

* fixy

* compile

* webedit ops

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2024-01-14 08:18:34 +00:00
committed by GitHub
parent 1346cc051d
commit d1d11d09c7
4 changed files with 81 additions and 0 deletions

View File

@@ -76,6 +76,30 @@ public abstract class SharedJobSystem : EntitySystem
return false;
}
/// <summary>
/// Like <see cref="TryGetDepartment"/> but ignores any non-primary departments.
/// For example, with CE it will return Engineering but with captain it will
/// not return anything, since Command is not a primary department.
/// </summary>
public bool TryGetPrimaryDepartment(string jobProto, [NotNullWhen(true)] out DepartmentPrototype? departmentPrototype)
{
// not sorting it since there should only be 1 primary department for a job.
// this is enforced by the job tests.
var departmentProtos = _protoManager.EnumeratePrototypes<DepartmentPrototype>();
foreach (var department in departmentProtos)
{
if (department.Primary && department.Roles.Contains(jobProto))
{
departmentPrototype = department;
return true;
}
}
departmentPrototype = null;
return false;
}
public bool MindHasJobWithId(EntityUid? mindId, string prototypeId)
{
return CompOrNull<JobComponent>(mindId)?.Prototype == prototypeId;