Phase 33: technician climate control and locker assignment.
This commit is contained in:
@@ -154,6 +154,11 @@ public sealed class RoomDef : Def
|
||||
/// the street by the climate preset's wall offset.
|
||||
/// </summary>
|
||||
public bool Outdoor { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// When set, pupil lockers in this room go to students of that sex (<c>male</c> / <c>female</c>).
|
||||
/// </summary>
|
||||
public string? LockerSex { get; init; }
|
||||
}
|
||||
|
||||
public sealed class BuildingDef : Def;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -86,7 +86,8 @@ internal static class PersonCardReader
|
||||
Carried(person, catalog, locale),
|
||||
catalog is null ? 0f : CarryMass.Held(catalog, person.Items),
|
||||
Capacity(person, skills, catalog),
|
||||
person.Items.Any(item => item.Location.Equals(ItemLocations.Locker, StringComparison.Ordinal)),
|
||||
person.LockerRoomId is not null
|
||||
|| person.Items.Any(item => item.Location.Equals(ItemLocations.Locker, StringComparison.Ordinal)),
|
||||
person.Items.Count(item => item.Location.Equals(ItemLocations.Home, StringComparison.Ordinal)));
|
||||
}
|
||||
|
||||
|
||||
@@ -945,6 +945,8 @@ internal sealed class SchoolWorker
|
||||
generated = true;
|
||||
}
|
||||
|
||||
roster = LockerAssigner.Apply(catalog, map, roster);
|
||||
|
||||
if (!RosterFit.Matches(roster, demand))
|
||||
{
|
||||
throw new SchoolContentUnavailableException(
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
{ "defName": "Librarian" },
|
||||
{ "defName": "Nurse" },
|
||||
{ "defName": "CafeteriaCook" },
|
||||
{ "defName": "Technician" },
|
||||
]
|
||||
|
||||
@@ -42,7 +42,26 @@
|
||||
"travelMinutes": 0.5,
|
||||
},
|
||||
{
|
||||
"defName": "ChangingRoom",
|
||||
"defName": "UtilityRoom",
|
||||
"slots": [
|
||||
{ "key": "desk", "thing": "Desk" },
|
||||
{ "key": "chair", "thing": "Chair" },
|
||||
],
|
||||
"positions": ["Technician"],
|
||||
"works": ["ClimateDuty"],
|
||||
"travelMinutes": 0.5,
|
||||
},
|
||||
{
|
||||
"defName": "MaleChangingRoom",
|
||||
"lockerSex": "male",
|
||||
"slots": [
|
||||
{ "key": "lockers", "thing": "Locker", "count": 12 },
|
||||
],
|
||||
"travelMinutes": 0.5,
|
||||
},
|
||||
{
|
||||
"defName": "FemaleChangingRoom",
|
||||
"lockerSex": "female",
|
||||
"slots": [
|
||||
{ "key": "lockers", "thing": "Locker", "count": 12 },
|
||||
],
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
{ "defName": "OfficeWork" },
|
||||
{ "defName": "LibraryWork" },
|
||||
{ "defName": "MedicalDuty" },
|
||||
{ "defName": "ClimateDuty" },
|
||||
{ "defName": "PELesson" },
|
||||
{ "defName": "ServeLunch" },
|
||||
]
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
"Teacher": "Teacher",
|
||||
"Librarian": "Librarian",
|
||||
"Nurse": "Nurse",
|
||||
"Technician": "Technician",
|
||||
"CafeteriaCook": "Cook",
|
||||
"PrimarySchool": "Primary",
|
||||
"PrincipalOfficeWork": "Principal's work",
|
||||
@@ -71,6 +72,7 @@
|
||||
"OfficeWork": "Office work",
|
||||
"LibraryWork": "Library work",
|
||||
"MedicalDuty": "Nurse's duty",
|
||||
"ClimateDuty": "Climate control",
|
||||
"PELesson": "PE lesson",
|
||||
"ServeLunch": "Serve lunch",
|
||||
"SchoolYard": "Yard",
|
||||
@@ -90,7 +92,9 @@
|
||||
"Library": "Library",
|
||||
"ComputerLab": "Computer lab",
|
||||
"GymHall": "Gym",
|
||||
"ChangingRoom": "Changing room",
|
||||
"UtilityRoom": "Utility room",
|
||||
"MaleChangingRoom": "Boys' changing room",
|
||||
"FemaleChangingRoom": "Girls' changing room",
|
||||
"Mathematics": "Mathematics",
|
||||
"RussianLanguage": "Russian",
|
||||
"Literature": "Literature",
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
"Teacher": "Учитель",
|
||||
"Librarian": "Библиотекарь",
|
||||
"Nurse": "Медсестра",
|
||||
"Technician": "Техник",
|
||||
"CafeteriaCook": "Повар",
|
||||
"PrimarySchool": "Начальные классы",
|
||||
"PrincipalOfficeWork": "Работа директора",
|
||||
@@ -71,6 +72,7 @@
|
||||
"OfficeWork": "Канцелярия",
|
||||
"LibraryWork": "Работа в библиотеке",
|
||||
"MedicalDuty": "Медпункт",
|
||||
"ClimateDuty": "Климат",
|
||||
"PELesson": "Урок физкультуры",
|
||||
"ServeLunch": "Раздача обеда",
|
||||
"SchoolYard": "Двор",
|
||||
@@ -90,7 +92,9 @@
|
||||
"Library": "Библиотека",
|
||||
"ComputerLab": "Компьютерный класс",
|
||||
"GymHall": "Спортивный зал",
|
||||
"ChangingRoom": "Раздевалка",
|
||||
"UtilityRoom": "Теплоузел",
|
||||
"MaleChangingRoom": "Мужская раздевалка",
|
||||
"FemaleChangingRoom": "Женская раздевалка",
|
||||
"Mathematics": "Математика",
|
||||
"RussianLanguage": "Русский язык",
|
||||
"Literature": "Литература",
|
||||
|
||||
@@ -99,6 +99,16 @@
|
||||
{ "key": "desk", "thing": "Desk" },
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "utility-room",
|
||||
"def": "UtilityRoom",
|
||||
"building": "main",
|
||||
"floor": "floor-1",
|
||||
"slots": [
|
||||
{ "key": "desk", "thing": "Desk" },
|
||||
{ "key": "chair", "thing": "Chair" },
|
||||
],
|
||||
},
|
||||
{ "id": "corridor-2", "def": "Corridor", "building": "main", "floor": "floor-2", "label": "2" },
|
||||
{ "id": "stairs-2", "def": "Stairwell", "building": "main", "floor": "floor-2", "label": "2" },
|
||||
{
|
||||
@@ -189,8 +199,17 @@
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "changing-room",
|
||||
"def": "ChangingRoom",
|
||||
"id": "boys-changing-room",
|
||||
"def": "MaleChangingRoom",
|
||||
"building": "gym",
|
||||
"floor": "gym-floor",
|
||||
"slots": [
|
||||
{ "key": "lockers", "thing": "Locker", "count": 12 },
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "girls-changing-room",
|
||||
"def": "FemaleChangingRoom",
|
||||
"building": "gym",
|
||||
"floor": "gym-floor",
|
||||
"slots": [
|
||||
@@ -212,6 +231,7 @@
|
||||
{ "a": "corridor-1", "b": "cafeteria" },
|
||||
{ "a": "corridor-1", "b": "restroom-1" },
|
||||
{ "a": "corridor-1", "b": "medical-office" },
|
||||
{ "a": "corridor-1", "b": "utility-room" },
|
||||
{ "a": "stairs-1", "b": "stairs-2" },
|
||||
{ "a": "stairs-2", "b": "corridor-2" },
|
||||
{ "a": "corridor-2", "b": "classroom-201" },
|
||||
@@ -225,6 +245,7 @@
|
||||
{ "a": "corridor-2", "b": "computer-lab" },
|
||||
{ "a": "corridor-2", "b": "restroom-2" },
|
||||
{ "a": "yard", "b": "gym-hall" },
|
||||
{ "a": "gym-hall", "b": "changing-room" },
|
||||
{ "a": "gym-hall", "b": "boys-changing-room" },
|
||||
{ "a": "gym-hall", "b": "girls-changing-room" },
|
||||
],
|
||||
}
|
||||
|
||||
@@ -45,13 +45,36 @@ public static class PlaceClimate
|
||||
}
|
||||
|
||||
var offset = 8f;
|
||||
ClimatePresetDef? climate = null;
|
||||
if (school.ClimatePresetId is { } presetId
|
||||
&& catalog.ClimatePresets.TryGetValue(presetId, out var preset)
|
||||
&& !preset.Abstract)
|
||||
{
|
||||
offset = preset.IndoorOffset;
|
||||
climate = preset;
|
||||
}
|
||||
|
||||
return outdoor + offset;
|
||||
var indoor = outdoor + offset;
|
||||
if (HasTechnician(school) && climate is not null)
|
||||
{
|
||||
var min = climate.ComfortC - climate.ComfortHalfWidthC;
|
||||
var max = climate.ComfortC + climate.ComfortHalfWidthC;
|
||||
if (indoor < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
|
||||
if (indoor > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
return indoor;
|
||||
}
|
||||
|
||||
public static bool HasTechnician(School school) =>
|
||||
school.Roster?.People.Any(person =>
|
||||
person.IsStaff && person.Position is { } position
|
||||
&& position.Equals("Technician", StringComparison.Ordinal)) == true;
|
||||
}
|
||||
|
||||
@@ -367,6 +367,11 @@ public sealed class School : IDisposable
|
||||
foreach (var date in YearlyIntake.DatesBetween(before, after))
|
||||
{
|
||||
Roster = YearlyIntake.Apply(Catalog, Roster, PeopleSeed, CountryId, date, NativeLanguage);
|
||||
if (Map is not null)
|
||||
{
|
||||
Roster = LockerAssigner.Apply(Catalog, Map, Roster);
|
||||
}
|
||||
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user