Phase 33: technician climate control and locker assignment.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using HSchool.Content;
|
||||
|
||||
namespace HSchool.People;
|
||||
|
||||
/// <summary>
|
||||
/// Hands out personal locker slots from each gendered changing room. Senior years first, then id.
|
||||
/// Staff never receive a slot; graduates lose theirs on the next assignment pass.
|
||||
/// </summary>
|
||||
public static class LockerAssigner
|
||||
{
|
||||
public static Roster Apply(DefCatalog catalog, MapLayout map, Roster roster)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(catalog);
|
||||
ArgumentNullException.ThrowIfNull(map);
|
||||
ArgumentNullException.ThrowIfNull(roster);
|
||||
|
||||
var classes = roster.Classes.ToDictionary(schoolClass => schoolClass.Id, StringComparer.Ordinal);
|
||||
var people = roster.People.ToDictionary(person => person.Id, StringComparer.Ordinal);
|
||||
foreach (var id in people.Keys.ToArray())
|
||||
{
|
||||
people[id] = people[id] with { LockerRoomId = null };
|
||||
}
|
||||
|
||||
foreach (var room in map.Rooms)
|
||||
{
|
||||
if (!catalog.Rooms.TryGetValue(room.Def, out var def) || def.LockerSex is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var female = def.LockerSex.Equals("female", StringComparison.OrdinalIgnoreCase);
|
||||
if (!female && !def.LockerSex.Equals("male", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var lockerCount = RoomOccupancy.ThingCount(catalog, map, room.Id, "Locker");
|
||||
if (lockerCount <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var winners = people.Values
|
||||
.Where(person => person.IsStudent && person.Female == female)
|
||||
.Select(person =>
|
||||
{
|
||||
var year = 0;
|
||||
if (person.ClassId is { } classId && classes.TryGetValue(classId, out var schoolClass))
|
||||
{
|
||||
year = schoolClass.Year;
|
||||
}
|
||||
|
||||
return (Person: person, Year: year);
|
||||
})
|
||||
.OrderByDescending(entry => entry.Year)
|
||||
.ThenBy(entry => entry.Person.Id, StringComparer.Ordinal)
|
||||
.Take(lockerCount)
|
||||
.Select(entry => entry.Person.Id)
|
||||
.ToArray();
|
||||
|
||||
foreach (var id in winners)
|
||||
{
|
||||
people[id] = people[id] with { LockerRoomId = room.Id };
|
||||
}
|
||||
}
|
||||
|
||||
return new Roster([.. people.Values], roster.Families, roster.Classes);
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,9 @@ public sealed record Person
|
||||
/// <summary>Worn, bag, locker and home. Empty on rosters written before clothes existed.</summary>
|
||||
public IReadOnlyList<InventoryItem> Items { get; init; } = [];
|
||||
|
||||
/// <summary>Changing-room node when this pupil won a locker slot. Null for staff and the rest.</summary>
|
||||
public string? LockerRoomId { get; init; }
|
||||
|
||||
public int AgeOn(DateTime asOf) => SchoolYears.AgeYears(BirthDate, asOf);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public static class RosterGenerator
|
||||
}
|
||||
|
||||
var classes = FillClasses(demand.Classes, people);
|
||||
return new Roster(people, families, classes);
|
||||
return LockerAssigner.Apply(catalog, map, new Roster(people, families, classes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user