Mark phase 84 wet-aftereffect in progress.
This commit is contained in:
@@ -18,6 +18,7 @@ internal static class EventDefValidator
|
||||
EventTriggers.ParentMeeting,
|
||||
EventTriggers.DiseaseOutbreak,
|
||||
EventTriggers.LessonNoTeacher,
|
||||
EventTriggers.PoorGradeTrail,
|
||||
};
|
||||
|
||||
private static readonly HashSet<string> Actions = new(StringComparer.Ordinal)
|
||||
|
||||
@@ -16,6 +16,9 @@ public static class EventTriggers
|
||||
public const string ParentMeeting = "parentMeeting";
|
||||
public const string DiseaseOutbreak = "diseaseOutbreak";
|
||||
public const string LessonNoTeacher = "lessonNoTeacher";
|
||||
|
||||
/// <summary>Bad recent marks and/or truancy trail (slice 13 phase 76).</summary>
|
||||
public const string PoorGradeTrail = "poorGradeTrail";
|
||||
}
|
||||
|
||||
public static class EventActions
|
||||
|
||||
@@ -752,6 +752,36 @@ internal static class PeopleDefValidator
|
||||
$"BehaviorDef '{behavior.DefName}' lessonLateMinutes cannot be negative.");
|
||||
}
|
||||
|
||||
if (behavior.LessonDressMarkFactor is < 0f or > 1f)
|
||||
{
|
||||
throw new ContentLoadException(
|
||||
$"BehaviorDef '{behavior.DefName}' lessonDressMarkFactor must be 0–1.");
|
||||
}
|
||||
|
||||
if (behavior.PoorMarkTrailMaxAverage is < 0f or > 5f)
|
||||
{
|
||||
throw new ContentLoadException(
|
||||
$"BehaviorDef '{behavior.DefName}' poorMarkTrailMaxAverage must be 0–5.");
|
||||
}
|
||||
|
||||
if (behavior.PoorMarkTrailMinMarks < 0)
|
||||
{
|
||||
throw new ContentLoadException(
|
||||
$"BehaviorDef '{behavior.DefName}' poorMarkTrailMinMarks cannot be negative.");
|
||||
}
|
||||
|
||||
if (behavior.TruancyTrailMinCount < 0)
|
||||
{
|
||||
throw new ContentLoadException(
|
||||
$"BehaviorDef '{behavior.DefName}' truancyTrailMinCount cannot be negative.");
|
||||
}
|
||||
|
||||
if (behavior.GradeTrailSummonChance is < 0f or > 1f)
|
||||
{
|
||||
throw new ContentLoadException(
|
||||
$"BehaviorDef '{behavior.DefName}' gradeTrailSummonChance must be 0–1.");
|
||||
}
|
||||
|
||||
if (behavior.DiseaseVectorScale < 0f)
|
||||
{
|
||||
throw new ContentLoadException(
|
||||
|
||||
@@ -619,6 +619,7 @@ public sealed class BehaviorDef : Def
|
||||
"quarrel",
|
||||
"fight",
|
||||
"reprimand",
|
||||
"truancy",
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
@@ -655,6 +656,33 @@ public sealed class BehaviorDef : Def
|
||||
/// </summary>
|
||||
public bool LessonMarkWhenLate { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Multiplier on lesson quality when worn dress fails Appropriateness for this lesson.
|
||||
/// 1 = log only (no mark hit). Vanilla is a light penalty.
|
||||
/// </summary>
|
||||
public float LessonDressMarkFactor { get; init; } = 0.95f;
|
||||
|
||||
/// <summary>
|
||||
/// Mean of recent marks at or below this (and at least <see cref="PoorMarkTrailMinMarks"/>)
|
||||
/// raises a poor-grade-trail notice. Zero disables the mark half of the trail.
|
||||
/// </summary>
|
||||
public float PoorMarkTrailMaxAverage { get; init; } = 2.5f;
|
||||
|
||||
/// <summary>How many recent marks are required before the average trail can fire. Zero disables.</summary>
|
||||
public int PoorMarkTrailMinMarks { get; init; } = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Recent unexcused absences (truancy) at or above this raise the trail notice.
|
||||
/// Zero disables the truancy half.
|
||||
/// </summary>
|
||||
public int TruancyTrailMinCount { get; init; } = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Chance to auto-enqueue a director summons when a poor trail first fires today.
|
||||
/// Slice 12 must be able to start (principal + office); 0 skips the roll.
|
||||
/// </summary>
|
||||
public float GradeTrailSummonChance { get; init; } = 0.35f;
|
||||
|
||||
/// <summary>
|
||||
/// Scales DiseaseDef weather/base onset chances. 0 disables natural onset; missing keeps 1.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
using HSchool.Content;
|
||||
|
||||
namespace HSchool.People;
|
||||
|
||||
/// <summary>
|
||||
/// Pure trail checks over recent marks and attendance. Simulation decides when to notice or summon.
|
||||
/// </summary>
|
||||
public static class GradeTrail
|
||||
{
|
||||
public static float? AverageMark(Person person)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(person);
|
||||
var list = person.LessonMarks;
|
||||
if (list is null || list.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var total = 0;
|
||||
foreach (var row in list)
|
||||
{
|
||||
total += row.Value;
|
||||
}
|
||||
|
||||
return total / (float)list.Count;
|
||||
}
|
||||
|
||||
public static int TruancyCount(Person person)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(person);
|
||||
var list = person.Attendance;
|
||||
if (list is null || list.Count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
foreach (var row in list)
|
||||
{
|
||||
if (row.Status == AttendanceStatuses.Absent
|
||||
&& (row.AbsenceReason is null
|
||||
|| row.AbsenceReason.Equals(AbsenceReasons.Truancy, StringComparison.Ordinal)))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public static bool HasPoorMarks(Person person, BehaviorDef rules)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(person);
|
||||
ArgumentNullException.ThrowIfNull(rules);
|
||||
if (rules.PoorMarkTrailMinMarks <= 0 || rules.PoorMarkTrailMaxAverage <= 0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var list = person.LessonMarks;
|
||||
if (list is null || list.Count < rules.PoorMarkTrailMinMarks)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return AverageMark(person) is { } average && average <= rules.PoorMarkTrailMaxAverage;
|
||||
}
|
||||
|
||||
public static bool HasTruancyTrail(Person person, BehaviorDef rules)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(person);
|
||||
ArgumentNullException.ThrowIfNull(rules);
|
||||
if (rules.TruancyTrailMinCount <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return TruancyCount(person) >= rules.TruancyTrailMinCount;
|
||||
}
|
||||
|
||||
public static bool IsPoor(Person person, BehaviorDef rules) =>
|
||||
HasPoorMarks(person, rules) || HasTruancyTrail(person, rules);
|
||||
|
||||
/// <summary>
|
||||
/// Illness absences are excused for summons / offense memory. Truancy and unknown reasons are not.
|
||||
/// </summary>
|
||||
public static bool CountsAsSummonOffense(string? absenceReason) =>
|
||||
absenceReason is null
|
||||
|| absenceReason.Equals(AbsenceReasons.Truancy, StringComparison.Ordinal);
|
||||
}
|
||||
@@ -12,11 +12,15 @@ public static class OffenseKinds
|
||||
|
||||
public const string Reprimand = "reprimand";
|
||||
|
||||
/// <summary>Unexcused lesson absence (slice 13). Illness does not use this kind.</summary>
|
||||
public const string Truancy = "truancy";
|
||||
|
||||
public static string LocaleKey(string kind) => kind switch
|
||||
{
|
||||
Quarrel => "OffenseQuarrel",
|
||||
Fight => "OffenseFight",
|
||||
Reprimand => "OffenseReprimand",
|
||||
Truancy => "OffenseTruancy",
|
||||
_ => "Offense" + char.ToUpperInvariant(kind[0]) + kind[1..],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public static class Seed
|
||||
public const int MeetingAttendSalt = 19;
|
||||
public const int DiseaseSalt = 20;
|
||||
public const int ContagionSalt = 21;
|
||||
public const int GradeTrailSalt = 22;
|
||||
|
||||
/// <summary>A stream that belongs to the school rather than to one family.</summary>
|
||||
public static int ForSchool(int schoolSeed, int salt) => Mix(schoolSeed, familyIndex: -1, salt);
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
"defendOpinionMin": 40,
|
||||
// Short misconduct list on the person (slice 12 phase 69). Not a 0…100 score.
|
||||
"offenseMemoryMax": 5,
|
||||
"offenseMemoryKinds": ["quarrel", "fight", "reprimand"],
|
||||
"offenseMemoryKinds": ["quarrel", "fight", "reprimand", "truancy"],
|
||||
// Auto director summons (slice 12 phase 70). Fight-break always; reprimand rarer.
|
||||
"directorSummonFightBreakChance": 1,
|
||||
"directorSummonReprimandChance": 0.35,
|
||||
@@ -121,6 +121,13 @@
|
||||
"lessonLateMinutes": 5,
|
||||
// Late still gets a mark when standing (stage A). False would skip the mark for late arrivals.
|
||||
"lessonMarkWhenLate": true,
|
||||
// Dress fails Appropriateness on this lesson: light mark penalty (1 = log only).
|
||||
"lessonDressMarkFactor": 0.95,
|
||||
// Poor recent average / truancy trail → info toast + optional auto summons (slice 13 phase 76).
|
||||
"poorMarkTrailMaxAverage": 2.5,
|
||||
"poorMarkTrailMinMarks": 3,
|
||||
"truancyTrailMinCount": 2,
|
||||
"gradeTrailSummonChance": 0.35,
|
||||
// Scales DiseaseDef onset from weather/base (slice 14 phase 78). 0 disables natural onset.
|
||||
"diseaseVectorScale": 1,
|
||||
// Contagion cases in one day at or above this raise diseaseOutbreak (slice 14 phase 79).
|
||||
|
||||
@@ -55,4 +55,12 @@
|
||||
"trigger": "lessonNoTeacher",
|
||||
"action": "none",
|
||||
},
|
||||
{
|
||||
"defName": "PoorGradeTrail",
|
||||
"severity": "info",
|
||||
"pause": false,
|
||||
"ttlMs": 8000,
|
||||
"trigger": "poorGradeTrail",
|
||||
"action": "none",
|
||||
},
|
||||
]
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"OffenseQuarrel": "quarrel",
|
||||
"OffenseFight": "fight",
|
||||
"OffenseReprimand": "reprimand",
|
||||
"OffenseTruancy": "truancy",
|
||||
"AttendancePresent": "present",
|
||||
"AttendanceLate": "late",
|
||||
"AttendanceAbsent": "absent",
|
||||
@@ -231,6 +232,9 @@
|
||||
"LessonNoTeacher": "lesson without a teacher: {0}",
|
||||
"LessonCold": "too cold in class: {0}",
|
||||
"LessonNoTextbook": "no textbook: {0}",
|
||||
"LessonDress": "dress code issue: {0}",
|
||||
"ClassTeacherGradeNote": "the class teacher noted a weak trail",
|
||||
"PoorGradeTrail": "A pupil has a weak grade trail",
|
||||
"DayStarted": "The day has started",
|
||||
"LessonStarted": "A lesson has started",
|
||||
"GenerationFailed": "Portrait generation failed",
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"OffenseQuarrel": "ссора",
|
||||
"OffenseFight": "драка",
|
||||
"OffenseReprimand": "выговор",
|
||||
"OffenseTruancy": "прогул",
|
||||
"AttendancePresent": "был",
|
||||
"AttendanceLate": "опоздал",
|
||||
"AttendanceAbsent": "отсутствовал",
|
||||
@@ -231,6 +232,9 @@
|
||||
"LessonNoTeacher": "урок без учителя: {0}",
|
||||
"LessonCold": "замёрз на уроке: {0}",
|
||||
"LessonNoTextbook": "нет учебника: {0}",
|
||||
"LessonDress": "форма не по правилам: {0}",
|
||||
"ClassTeacherGradeNote": "классный отметил слабый след",
|
||||
"PoorGradeTrail": "Слабый учебный след у ученика",
|
||||
"DayStarted": "Начало дня",
|
||||
"LessonStarted": "Начало урока",
|
||||
"GenerationFailed": "Не удалось нарисовать портрет",
|
||||
|
||||
@@ -136,6 +136,7 @@ internal static class AttendanceSystem
|
||||
reason))
|
||||
{
|
||||
school.RosterTalkDirty = true;
|
||||
GradeTrailSystem.AfterAbsent(school, person, reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
|
||||
namespace HSchool.Simulation;
|
||||
|
||||
/// <summary>
|
||||
/// After marks or absences: info toast, class-teacher log, and optional auto summons weight.
|
||||
/// Illness absences do not become summons offenses.
|
||||
/// </summary>
|
||||
internal static class GradeTrailSystem
|
||||
{
|
||||
public static void AfterMark(School school, Person person)
|
||||
{
|
||||
if (school.Catalog?.BehaviorRules is not { } rules)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TryReact(school, person, rules);
|
||||
}
|
||||
|
||||
public static void AfterAbsent(School school, Person person, string? absenceReason)
|
||||
{
|
||||
if (school.Catalog?.BehaviorRules is not { } rules)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (GradeTrail.CountsAsSummonOffense(absenceReason)
|
||||
&& OffenseMemory.Record(person, OffenseKinds.Truancy, school.Clock.Time, otherPersonId: null, rules))
|
||||
{
|
||||
school.RosterTalkDirty = true;
|
||||
}
|
||||
|
||||
TryReact(school, person, rules);
|
||||
}
|
||||
|
||||
private static void TryReact(School school, Person person, BehaviorDef rules)
|
||||
{
|
||||
if (!GradeTrail.IsPoor(person, rules))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!school.TryClaimGradeTrailNotice(person.Id, school.Clock.Time.Date))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
school.RaiseWorldEvent(new WorldEvent(EventTriggers.PoorGradeTrail, person.Id));
|
||||
|
||||
var schoolClass = ClassOf(school, person);
|
||||
if (schoolClass?.ClassTeacherId is { } teacherId)
|
||||
{
|
||||
school.AppendDayLog(new PersonLogEvent(
|
||||
person.Id,
|
||||
school.Clock.Time,
|
||||
PersonLogTypes.ClassTeacherGradeNote,
|
||||
teacherId));
|
||||
}
|
||||
|
||||
if (rules.GradeTrailSummonChance > 0f)
|
||||
{
|
||||
DirectorSummonSystem.TryEnqueue(school, person.Id, rules.GradeTrailSummonChance);
|
||||
}
|
||||
}
|
||||
|
||||
private static SchoolClass? ClassOf(School school, Person person)
|
||||
{
|
||||
if (person.ClassId is null || school.Roster is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return school.Roster.Classes.FirstOrDefault(row =>
|
||||
row.Id.Equals(person.ClassId, StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,13 @@ internal static class LessonLearningSystem
|
||||
textbookFactor *= TalkCircles.LessonWhisperFactor(activity.ActionId, rules);
|
||||
textbookFactor *= DiseaseEffects.LessonLearningFactor(person, catalog, school.Clock.Time);
|
||||
|
||||
var mode = ApparelDresser.ModeForLesson(lesson.Subject);
|
||||
if (ApparelDresser.CurrentIssues(school, person, mode) != ApparelIssue.None)
|
||||
{
|
||||
school.TryLogLessonOnce(personId, PersonLogTypes.LessonDress, lesson.Subject);
|
||||
textbookFactor *= rules.LessonDressMarkFactor;
|
||||
}
|
||||
|
||||
IReadOnlyDictionary<string, float> taught = teacherSkills.TryGetValue(lesson.TeacherId, out var found)
|
||||
? found
|
||||
: new Dictionary<string, float>(StringComparer.Ordinal);
|
||||
@@ -167,6 +174,7 @@ internal static class LessonLearningSystem
|
||||
if (LessonMarkMemory.Record(person, lesson.Subject, mark, school.Clock.Time, lesson.Period, rules))
|
||||
{
|
||||
school.RosterTalkDirty = true;
|
||||
GradeTrailSystem.AfterMark(school, person);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +204,7 @@ internal static class LessonLearningSystem
|
||||
if (LessonMarkMemory.Record(person, lesson.Subject, mark, school.Clock.Time, lesson.Period, rules))
|
||||
{
|
||||
school.RosterTalkDirty = true;
|
||||
GradeTrailSystem.AfterMark(school, person);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ public static class PersonLogTypes
|
||||
public const string LessonNoTeacher = "lesson-no-teacher";
|
||||
public const string LessonCold = "lesson-cold";
|
||||
public const string LessonNoTextbook = "lesson-no-textbook";
|
||||
public const string LessonDress = "lesson-dress";
|
||||
public const string ClassTeacherGradeNote = "class-teacher-grade-note";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,7 +104,8 @@ public sealed record PersonLogEvent(string PersonId, DateTime Time, string Type,
|
||||
|
||||
if (Type.Equals(PersonLogTypes.LessonNoTeacher, StringComparison.Ordinal)
|
||||
|| Type.Equals(PersonLogTypes.LessonCold, StringComparison.Ordinal)
|
||||
|| Type.Equals(PersonLogTypes.LessonNoTextbook, StringComparison.Ordinal))
|
||||
|| Type.Equals(PersonLogTypes.LessonNoTextbook, StringComparison.Ordinal)
|
||||
|| Type.Equals(PersonLogTypes.LessonDress, StringComparison.Ordinal))
|
||||
{
|
||||
var name = catalog.Subjects.TryGetValue(ThingDef, out var subject)
|
||||
? catalog.Label(locale, subject)
|
||||
@@ -111,10 +114,17 @@ public sealed record PersonLogEvent(string PersonId, DateTime Time, string Type,
|
||||
? "LessonCold"
|
||||
: Type.Equals(PersonLogTypes.LessonNoTextbook, StringComparison.Ordinal)
|
||||
? "LessonNoTextbook"
|
||||
: "LessonNoTeacher";
|
||||
: Type.Equals(PersonLogTypes.LessonDress, StringComparison.Ordinal)
|
||||
? "LessonDress"
|
||||
: "LessonNoTeacher";
|
||||
return string.Format(CultureInfo.InvariantCulture, catalog.Text(locale, key), name);
|
||||
}
|
||||
|
||||
if (Type.Equals(PersonLogTypes.ClassTeacherGradeNote, StringComparison.Ordinal))
|
||||
{
|
||||
return catalog.Text(locale, "ClassTeacherGradeNote");
|
||||
}
|
||||
|
||||
if (Type.Equals(PersonLogTypes.TalkEnded, StringComparison.Ordinal)
|
||||
|| Type.Equals(PersonLogTypes.HomeTalk, StringComparison.Ordinal))
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ public sealed class School : IDisposable
|
||||
private readonly HashSet<string> _lessonLogOnce = new(StringComparer.Ordinal);
|
||||
private readonly HashSet<string> _lessonMarkOnce = new(StringComparer.Ordinal);
|
||||
private readonly HashSet<string> _lessonNoTeacherEventOnce = new(StringComparer.Ordinal);
|
||||
private readonly HashSet<string> _gradeTrailOnce = new(StringComparer.Ordinal);
|
||||
private readonly List<WorldEvent> _worldEvents = [];
|
||||
|
||||
internal School(int id, string name, DateTime startDate, DefCatalog? catalog, MapLayout? map)
|
||||
@@ -178,6 +179,7 @@ public sealed class School : IDisposable
|
||||
_lessonLogOnce.Clear();
|
||||
_lessonMarkOnce.Clear();
|
||||
_lessonNoTeacherEventOnce.Clear();
|
||||
_gradeTrailOnce.Clear();
|
||||
LastAttendanceSlot = null;
|
||||
}
|
||||
|
||||
@@ -216,6 +218,15 @@ public sealed class School : IDisposable
|
||||
return _lessonNoTeacherEventOnce.Add(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One poor-grade-trail notice per person per calendar day (toast + class-teacher note + summon roll).
|
||||
/// </summary>
|
||||
internal bool TryClaimGradeTrailNotice(string personId, DateTime day)
|
||||
{
|
||||
var key = string.Concat(personId, "\0", day.ToString("yyyy-MM-dd"));
|
||||
return _gradeTrailOnce.Add(key);
|
||||
}
|
||||
|
||||
public void QueueDecision(string personId)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
Reference in New Issue
Block a user