Merge branch 'phase/43-whisper'
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -250,7 +250,7 @@ public static class DecisionPlanner
|
||||
OccupiedCount occupied,
|
||||
ActionDef action)
|
||||
{
|
||||
if (action.Abstract || action.Weight <= 0 || !RoleFits(action, state))
|
||||
if (action.Abstract || !RoleFits(action, state))
|
||||
{
|
||||
return Intent.None;
|
||||
}
|
||||
@@ -260,6 +260,32 @@ public static class DecisionPlanner
|
||||
return Intent.None;
|
||||
}
|
||||
|
||||
if (TalkActions.IsTeacherTalk(action.DefName))
|
||||
{
|
||||
if (state.BoundToLesson)
|
||||
{
|
||||
return Intent.None;
|
||||
}
|
||||
|
||||
var teacherWeight = catalog.BehaviorRules?.TeacherAfterLessonWeight ?? 0f;
|
||||
if (teacherWeight <= 0)
|
||||
{
|
||||
return Intent.None;
|
||||
}
|
||||
|
||||
if (RoomFor(catalog, map, walks, state, occupied, action) is null)
|
||||
{
|
||||
return Intent.None;
|
||||
}
|
||||
|
||||
return new Intent(GoalKind.Leisure, action.DefName, teacherWeight, action.DefName);
|
||||
}
|
||||
|
||||
if (action.Weight <= 0)
|
||||
{
|
||||
return Intent.None;
|
||||
}
|
||||
|
||||
if (action.DefName.Equals(TalkActions.PhoneChat, StringComparison.Ordinal) && !state.Talk.HasPhone)
|
||||
{
|
||||
return Intent.None;
|
||||
@@ -371,7 +397,8 @@ public static class DecisionPlanner
|
||||
{
|
||||
if (action.Abstract
|
||||
|| !need.Equals(action.Need, StringComparison.Ordinal)
|
||||
|| !RoleFits(action, state))
|
||||
|| !RoleFits(action, state)
|
||||
|| (state.BoundToLesson && TalkCircles.BlocksOnLesson(action.DefName)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ public readonly record struct TalkPlannerContext(
|
||||
/// </summary>
|
||||
public static class TalkCircles
|
||||
{
|
||||
public static bool BlocksOnLesson(string actionId) => TalkActions.IsTalk(actionId);
|
||||
public static bool BlocksOnLesson(string actionId) =>
|
||||
TalkActions.IsTalk(actionId) && !TalkActions.IsWhisper(actionId);
|
||||
|
||||
public static int MaxSize(string actionId, BehaviorDef? rules, IReadOnlyList<string> traitIds, DefCatalog catalog)
|
||||
{
|
||||
@@ -27,6 +28,12 @@ public static class TalkCircles
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (actionId.Equals(TalkActions.TeacherTalk, StringComparison.Ordinal))
|
||||
{
|
||||
// Teacher plus 2–4 pupils; the live-circle cap of 4 is the pupil side.
|
||||
return 1 + Math.Clamp(rules?.TalkCircleMax ?? 4, 2, 4);
|
||||
}
|
||||
|
||||
var max = rules?.TalkCircleMax ?? 4;
|
||||
foreach (var traitId in traitIds)
|
||||
{
|
||||
@@ -182,14 +189,16 @@ public static class TalkCircles
|
||||
DefCatalog catalog,
|
||||
Person picker,
|
||||
int age,
|
||||
int seed)
|
||||
int seed,
|
||||
bool whisperOnLesson = false)
|
||||
{
|
||||
var candidates = new List<(TopicDef Topic, float Weight)>();
|
||||
foreach (var topic in catalog.Topics.Values)
|
||||
{
|
||||
if (topic.Abstract
|
||||
|| !RoleFitsTopic(topic, picker.IsStudent, picker.IsStaff, picker.IsParent)
|
||||
|| !AgeFits(topic, age))
|
||||
|| !AgeFits(topic, age)
|
||||
|| (whisperOnLesson && !topic.WhisperOnLesson))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -368,6 +377,102 @@ public static class TalkCircles
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>0…1 from a mixed seed. Same seed, same roll — never <c>string.GetHashCode</c>.</summary>
|
||||
public static float Roll01(int seed)
|
||||
{
|
||||
var unit = (seed & int.MaxValue) / (float)int.MaxValue;
|
||||
return Math.Clamp(unit, 0f, 1f);
|
||||
}
|
||||
|
||||
/// <summary>Traits multiply: quiet dampens, outgoing raises, missing stays 1.</summary>
|
||||
public static float WhisperCatchMultiplier(IReadOnlyList<string> traitIds, DefCatalog catalog)
|
||||
{
|
||||
var factor = 1f;
|
||||
foreach (var traitId in traitIds)
|
||||
{
|
||||
if (catalog.Traits.TryGetValue(traitId, out var trait) && trait.WhisperCatchMultiplier > 0f)
|
||||
{
|
||||
factor *= trait.WhisperCatchMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
return factor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True when this roll catches a whisper. <paramref name="catchMax"/> keeps it below 100 %
|
||||
/// even with loud traits.
|
||||
/// </summary>
|
||||
public static bool WhisperCaught(float roll, float baseChance, float catchMax, float traitMultiplier)
|
||||
{
|
||||
var ceiling = Math.Clamp(catchMax, 0f, 0.99f);
|
||||
var chance = Math.Clamp(baseChance * Math.Max(0f, traitMultiplier), 0f, ceiling);
|
||||
return chance > 0f && roll < chance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pupil → teacher opinion after talk. Pedagogy 50 is identity; a strong teacher after praise
|
||||
/// pluses more, a weak reprimand angers more.
|
||||
/// </summary>
|
||||
public static int ScaleByPedagogy(int delta, float pedagogy, BehaviorDef? rules)
|
||||
{
|
||||
if (delta == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var t = (Math.Clamp(pedagogy, 0f, 100f) - 50f) / 50f;
|
||||
var k = rules?.TalkPedagogyOpinionScale ?? 0.4f;
|
||||
var scale = delta > 0 ? 1f + (t * k) : 1f - (t * k);
|
||||
var scaled = (int)Math.Round(delta * Math.Max(0.1f, scale), MidpointRounding.AwayFromZero);
|
||||
if (delta > 0)
|
||||
{
|
||||
return Math.Max(1, scaled);
|
||||
}
|
||||
|
||||
return Math.Min(-1, scaled);
|
||||
}
|
||||
|
||||
public static string? PickTeacherTopic(DefCatalog catalog, BehaviorDef? rules, int seed)
|
||||
{
|
||||
var options = new (string Id, float Weight)[]
|
||||
{
|
||||
(TeacherTopics.Question, rules?.TeacherQuestionWeight ?? 2f),
|
||||
(TeacherTopics.Praise, rules?.TeacherPraiseWeight ?? 2f),
|
||||
(TeacherTopics.Discipline, rules?.TeacherReprimandWeight ?? 1f),
|
||||
};
|
||||
var available = new List<(string Id, float Weight)>();
|
||||
foreach (var option in options)
|
||||
{
|
||||
if (option.Weight > 0f && catalog.Topics.ContainsKey(option.Id))
|
||||
{
|
||||
available.Add(option);
|
||||
}
|
||||
}
|
||||
|
||||
if (available.Count == 0)
|
||||
{
|
||||
return catalog.Topics.Values.FirstOrDefault(topic => !topic.Abstract)?.DefName;
|
||||
}
|
||||
|
||||
var total = available.Sum(pair => pair.Weight);
|
||||
var roll = Roll01(seed) * total;
|
||||
var cursor = 0f;
|
||||
foreach (var (id, weight) in available.OrderBy(pair => pair.Id, StringComparer.Ordinal))
|
||||
{
|
||||
cursor += weight;
|
||||
if (roll <= cursor)
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
return available[^1].Id;
|
||||
}
|
||||
|
||||
public static float LessonWhisperFactor(string? actionId, BehaviorDef? rules) =>
|
||||
TalkActions.IsWhisper(actionId) ? rules?.LessonWhisperSkillFactor ?? 0.4f : 1f;
|
||||
|
||||
public readonly record struct Candidate(
|
||||
string Id,
|
||||
string? ClassId,
|
||||
|
||||
@@ -261,6 +261,11 @@ internal static class PeopleDefValidator
|
||||
throw new ContentLoadException($"TraitDef '{trait.DefName}' skill modifier references unknown SkillDef '{modifier.Skill}'.");
|
||||
}
|
||||
}
|
||||
|
||||
if (trait.WhisperCatchMultiplier < 0f)
|
||||
{
|
||||
throw new ContentLoadException($"TraitDef '{trait.DefName}' whisperCatchMultiplier cannot be negative.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateNeed(NeedDef need)
|
||||
@@ -574,6 +579,39 @@ internal static class PeopleDefValidator
|
||||
throw new ContentLoadException(
|
||||
$"BehaviorDef '{behavior.DefName}' talk circle size must be at least 2 with max ≥ min.");
|
||||
}
|
||||
|
||||
if (behavior.LessonWhisperSkillFactor is < 0f or > 1f)
|
||||
{
|
||||
throw new ContentLoadException($"BehaviorDef '{behavior.DefName}' lessonWhisperSkillFactor must be 0–1.");
|
||||
}
|
||||
|
||||
if (behavior.WhisperCatchChance is < 0f or > 1f)
|
||||
{
|
||||
throw new ContentLoadException($"BehaviorDef '{behavior.DefName}' whisperCatchChance must be 0–1.");
|
||||
}
|
||||
|
||||
if (behavior.WhisperCatchMax is < 0f or > 1f)
|
||||
{
|
||||
throw new ContentLoadException($"BehaviorDef '{behavior.DefName}' whisperCatchMax must be 0–1.");
|
||||
}
|
||||
|
||||
if (behavior.WhisperStartChance is < 0f or > 1f)
|
||||
{
|
||||
throw new ContentLoadException($"BehaviorDef '{behavior.DefName}' whisperStartChance must be 0–1.");
|
||||
}
|
||||
|
||||
if (behavior.TalkPedagogyOpinionScale < 0f)
|
||||
{
|
||||
throw new ContentLoadException($"BehaviorDef '{behavior.DefName}' talkPedagogyOpinionScale cannot be negative.");
|
||||
}
|
||||
|
||||
if (behavior.TeacherAfterLessonWeight < 0f
|
||||
|| behavior.TeacherQuestionWeight < 0f
|
||||
|| behavior.TeacherPraiseWeight < 0f
|
||||
|| behavior.TeacherReprimandWeight < 0f)
|
||||
{
|
||||
throw new ContentLoadException($"BehaviorDef '{behavior.DefName}' teacher-talk weights cannot be negative.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateTopic(TopicDef topic, DefCatalog catalog)
|
||||
@@ -611,10 +649,7 @@ internal static class PeopleDefValidator
|
||||
private static void RequireTalkTopics(DefCatalog catalog)
|
||||
{
|
||||
var hasTalkAction = catalog.Actions.Values.Any(action =>
|
||||
!action.Abstract
|
||||
&& (action.DefName.Equals(TalkActions.Chat, StringComparison.Ordinal)
|
||||
|| action.DefName.Equals(TalkActions.StaffChat, StringComparison.Ordinal)
|
||||
|| action.DefName.Equals(TalkActions.PhoneChat, StringComparison.Ordinal)));
|
||||
!action.Abstract && TalkActions.IsTalk(action.DefName));
|
||||
if (!hasTalkAction)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -210,6 +210,11 @@ public sealed class TraitDef : Def
|
||||
|
||||
/// <summary>Pull toward topics carrying these tags when this person picks the subject.</summary>
|
||||
public IReadOnlyList<TopicTagWeight> TalkTagWeights { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the chance a whisper is caught. Quiet below 1, outgoing above. Missing is 1.
|
||||
/// </summary>
|
||||
public float WhisperCatchMultiplier { get; init; } = 1f;
|
||||
}
|
||||
|
||||
/// <summary>Conversation subject. Tags gate appropriateness; language is optional skill help.</summary>
|
||||
@@ -415,6 +420,37 @@ public sealed class BehaviorDef : Def
|
||||
/// <summary>Opinion at or below — enemy; never invited, lunch nodes avoided.</summary>
|
||||
public int TalkEnemyThreshold { get; init; } = -40;
|
||||
|
||||
/// <summary>
|
||||
/// Lesson skill multiplier while the pupil is in a whisper circle. Missing keeps a cut, not
|
||||
/// a skipped lesson — whispering is costly, not a free skip.
|
||||
/// </summary>
|
||||
public float LessonWhisperSkillFactor { get; init; } = 0.4f;
|
||||
|
||||
/// <summary>Base chance the teacher notices one whisper circle. Traits scale it; never 1.</summary>
|
||||
public float WhisperCatchChance { get; init; } = 0.4f;
|
||||
|
||||
/// <summary>Ceiling after traits. A pack cannot make every whisper a sure catch.</summary>
|
||||
public float WhisperCatchMax { get; init; } = 0.85f;
|
||||
|
||||
/// <summary>
|
||||
/// How far pedagogy 0…100 bends a pupil's opinion of the teacher. 50 is identity; above it
|
||||
/// praise grows and reprimand softens, below it the reverse.
|
||||
/// </summary>
|
||||
public float TalkPedagogyOpinionScale { get; init; } = 0.4f;
|
||||
|
||||
/// <summary>Leisure weight for a teacher taking pupils after the bell. Below lesson, above chat.</summary>
|
||||
public float TeacherAfterLessonWeight { get; init; } = 4f;
|
||||
|
||||
/// <summary>Relative weights when the teacher picks question / praise / reprimand.</summary>
|
||||
public float TeacherQuestionWeight { get; init; } = 2f;
|
||||
|
||||
public float TeacherPraiseWeight { get; init; } = 2f;
|
||||
|
||||
public float TeacherReprimandWeight { get; init; } = 1f;
|
||||
|
||||
/// <summary>Per-decision chance a pupil in class tries to start a whisper, before initiative.</summary>
|
||||
public float WhisperStartChance { get; init; } = 0.12f;
|
||||
|
||||
public static IReadOnlyList<OpinionBand> DefaultOpinionBands { get; } =
|
||||
[
|
||||
new() { Min = 70, Id = "OpinionCloseFriend" },
|
||||
|
||||
@@ -6,12 +6,22 @@ public static class TalkActions
|
||||
public const string Chat = "Chat";
|
||||
public const string StaffChat = "StaffChat";
|
||||
public const string PhoneChat = "PhoneChat";
|
||||
public const string Whisper = "Whisper";
|
||||
public const string TeacherTalk = "TeacherTalk";
|
||||
|
||||
public static bool IsTalk(string? actionId) =>
|
||||
actionId is not null
|
||||
&& (actionId.Equals(Chat, StringComparison.Ordinal)
|
||||
|| actionId.Equals(StaffChat, StringComparison.Ordinal)
|
||||
|| actionId.Equals(PhoneChat, StringComparison.Ordinal));
|
||||
|| actionId.Equals(PhoneChat, StringComparison.Ordinal)
|
||||
|| actionId.Equals(Whisper, StringComparison.Ordinal)
|
||||
|| actionId.Equals(TeacherTalk, StringComparison.Ordinal));
|
||||
|
||||
public static bool IsWhisper(string? actionId) =>
|
||||
actionId is not null && actionId.Equals(Whisper, StringComparison.Ordinal);
|
||||
|
||||
public static bool IsTeacherTalk(string? actionId) =>
|
||||
actionId is not null && actionId.Equals(TeacherTalk, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>Vanilla topic tags from the social slice design doc.</summary>
|
||||
@@ -26,3 +36,11 @@ public static class TopicTags
|
||||
public const string Rude = "rude";
|
||||
public const string Appearance = "appearance";
|
||||
}
|
||||
|
||||
/// <summary>Teacher-after-lesson and reprimand topics in core. Names match TopicDef ids.</summary>
|
||||
public static class TeacherTopics
|
||||
{
|
||||
public const string Question = "TopicQuestion";
|
||||
public const string Praise = "TopicPraise";
|
||||
public const string Discipline = "TopicDiscipline";
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public static class Seed
|
||||
public const int NativeLanguageSalt = 9;
|
||||
public const int ClimatePresetSalt = 10;
|
||||
public const int ApparelSalt = 11;
|
||||
public const int WhisperSalt = 12;
|
||||
|
||||
/// <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);
|
||||
|
||||
@@ -54,6 +54,24 @@
|
||||
"roles": ["student"],
|
||||
"weight": 2,
|
||||
},
|
||||
{
|
||||
"defName": "Whisper",
|
||||
"room": "Classroom",
|
||||
"minutes": 6,
|
||||
"need": "Social",
|
||||
"needGain": 0.15,
|
||||
"roles": ["student"],
|
||||
"weight": 2,
|
||||
},
|
||||
{
|
||||
"defName": "TeacherTalk",
|
||||
"room": "Classroom",
|
||||
"minutes": 8,
|
||||
"need": "Social",
|
||||
"needGain": 0.3,
|
||||
"roles": ["staff"],
|
||||
"weight": 0,
|
||||
},
|
||||
{
|
||||
"defName": "WalkCorridor",
|
||||
"room": "Corridor",
|
||||
|
||||
@@ -74,8 +74,18 @@
|
||||
"talkNoLanguageOpinionMultiplier": 0.15,
|
||||
"talkPhoneOpinionMultiplier": 0.5,
|
||||
"talkCommunicationOpinionScale": 0.5,
|
||||
"talkCircleMin": 2,
|
||||
"talkCircleMax": 4,
|
||||
"talkFriendThreshold": 40,
|
||||
"talkEnemyThreshold": -40,
|
||||
"talkCircleMin": 2,
|
||||
"talkCircleMax": 4,
|
||||
"talkFriendThreshold": 40,
|
||||
"talkEnemyThreshold": -40,
|
||||
// Whisper on lesson (slice 9 phase 43). Catch chance is not 1 even with loud traits.
|
||||
"lessonWhisperSkillFactor": 0.4,
|
||||
"whisperCatchChance": 0.4,
|
||||
"whisperCatchMax": 0.85,
|
||||
"whisperStartChance": 0.12,
|
||||
"talkPedagogyOpinionScale": 0.4,
|
||||
"teacherAfterLessonWeight": 4,
|
||||
"teacherQuestionWeight": 2,
|
||||
"teacherPraiseWeight": 2,
|
||||
"teacherReprimandWeight": 1,
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"defName": "TopicStudy",
|
||||
"tags": ["study"],
|
||||
"roles": ["student", "staff"],
|
||||
"whisperOnLesson": true,
|
||||
"opinionShift": 2,
|
||||
},
|
||||
{
|
||||
@@ -10,12 +11,14 @@
|
||||
"tags": ["games"],
|
||||
"roles": ["student"],
|
||||
"age": { "min": 7, "max": 18 },
|
||||
"whisperOnLesson": true,
|
||||
"opinionShift": 3,
|
||||
},
|
||||
{
|
||||
"defName": "TopicFood",
|
||||
"tags": ["food"],
|
||||
"roles": ["student", "staff"],
|
||||
"whisperOnLesson": true,
|
||||
"opinionShift": 2,
|
||||
},
|
||||
{
|
||||
@@ -28,12 +31,14 @@
|
||||
"defName": "TopicSport",
|
||||
"tags": ["sport"],
|
||||
"roles": ["student", "staff"],
|
||||
"whisperOnLesson": true,
|
||||
"opinionShift": 3,
|
||||
},
|
||||
{
|
||||
"defName": "TopicGossip",
|
||||
"tags": ["gossip"],
|
||||
"roles": ["student", "staff"],
|
||||
"whisperOnLesson": true,
|
||||
"opinionShift": 1,
|
||||
},
|
||||
{
|
||||
@@ -47,6 +52,25 @@
|
||||
"tags": ["appearance"],
|
||||
"roles": ["student"],
|
||||
"age": { "min": 11, "max": 18 },
|
||||
"whisperOnLesson": true,
|
||||
"opinionShift": 1,
|
||||
},
|
||||
{
|
||||
"defName": "TopicQuestion",
|
||||
"tags": ["study"],
|
||||
"roles": ["student", "staff"],
|
||||
"opinionShift": 2,
|
||||
},
|
||||
{
|
||||
"defName": "TopicPraise",
|
||||
"tags": ["study"],
|
||||
"roles": ["student", "staff"],
|
||||
"opinionShift": 4,
|
||||
},
|
||||
{
|
||||
"defName": "TopicDiscipline",
|
||||
"tags": ["study"],
|
||||
"roles": ["student", "staff"],
|
||||
"opinionShift": -6,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
"incompatible": ["Leader", "Bully"],
|
||||
"wageAsk": -8,
|
||||
"talkInitiative": 0.45,
|
||||
"whisperCatchMultiplier": 0.55,
|
||||
},
|
||||
{
|
||||
"defName": "Leader",
|
||||
@@ -42,6 +43,7 @@
|
||||
"incompatible": ["Quiet"],
|
||||
"wageAsk": 10,
|
||||
"talkInitiative": 1.6,
|
||||
"whisperCatchMultiplier": 1.25,
|
||||
"skillModifiers": [
|
||||
{ "skill": "History", "offset": 4 },
|
||||
],
|
||||
@@ -107,5 +109,6 @@
|
||||
"incompatible": ["Quiet"],
|
||||
"talkInitiative": 1.4,
|
||||
"talkCircleBonus": 1,
|
||||
"whisperCatchMultiplier": 1.4,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
"Chat": "Chat",
|
||||
"StaffChat": "Staff chat",
|
||||
"PhoneChat": "Phone chat",
|
||||
"Whisper": "Whisper",
|
||||
"TeacherTalk": "Teacher talk",
|
||||
"WalkCorridor": "Walk the corridor",
|
||||
"WalkYard": "Walk the yard",
|
||||
"Behavior": "Behavior rules",
|
||||
@@ -194,6 +196,8 @@
|
||||
"ActionStarted": "started: {0}",
|
||||
"ActionEnded": "finished: {0}",
|
||||
"TalkEnded": "talked about {0}",
|
||||
"Whispered": "whispered",
|
||||
"TeacherInterrupted": "the teacher cut them off",
|
||||
"TopicStudy": "schoolwork",
|
||||
"TopicGames": "games",
|
||||
"TopicFood": "food",
|
||||
@@ -202,6 +206,9 @@
|
||||
"TopicGossip": "gossip",
|
||||
"TopicRude": "rough talk",
|
||||
"TopicAppearance": "looks",
|
||||
"TopicQuestion": "a subject question",
|
||||
"TopicPraise": "praise",
|
||||
"TopicDiscipline": "discipline",
|
||||
"ApparelReplaced": "got a new {0}",
|
||||
"ApparelChanged": "changed clothes: {0}",
|
||||
"LessonNoTeacher": "lesson without a teacher: {0}",
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
"Chat": "Разговор",
|
||||
"StaffChat": "Разговор в учительской",
|
||||
"PhoneChat": "Разговор по телефону",
|
||||
"Whisper": "Шёпот",
|
||||
"TeacherTalk": "Разговор учителя",
|
||||
"WalkCorridor": "Прогулка по коридору",
|
||||
"WalkYard": "Прогулка во дворе",
|
||||
"Behavior": "Правила поведения",
|
||||
@@ -194,6 +196,8 @@
|
||||
"ActionStarted": "начал: {0}",
|
||||
"ActionEnded": "закончил: {0}",
|
||||
"TalkEnded": "говорил о {0}",
|
||||
"Whispered": "шептались",
|
||||
"TeacherInterrupted": "учитель оборвал",
|
||||
"TopicStudy": "учёбе",
|
||||
"TopicGames": "играх",
|
||||
"TopicFood": "еде",
|
||||
@@ -202,6 +206,9 @@
|
||||
"TopicGossip": "сплетнях",
|
||||
"TopicRude": "грубом",
|
||||
"TopicAppearance": "внешности",
|
||||
"TopicQuestion": "вопросе по предмету",
|
||||
"TopicPraise": "похвале",
|
||||
"TopicDiscipline": "дисциплине",
|
||||
"ApparelReplaced": "получил новую {0}",
|
||||
"ApparelChanged": "переоделся: {0}",
|
||||
"LessonNoTeacher": "урок без учителя: {0}",
|
||||
|
||||
@@ -57,7 +57,12 @@ internal static class LessonLearningSystem
|
||||
in People,
|
||||
(ref PersonIdentity identity, ref PersonSkills skills, ref PersonTraits traits, ref PersonNeeds needs, ref PersonRoles roles, ref Presence presence, ref PersonActivity activity) =>
|
||||
{
|
||||
if (activity.IsActive || !IsStanding(presence))
|
||||
if (!IsStanding(presence))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (activity.IsActive && !TalkActions.IsWhisper(activity.ActionId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -98,6 +103,8 @@ internal static class LessonLearningSystem
|
||||
school.TryLogLessonOnce(personId, PersonLogTypes.LessonNoTextbook, lesson.Subject);
|
||||
}
|
||||
|
||||
textbookFactor *= TalkCircles.LessonWhisperFactor(activity.ActionId, rules);
|
||||
|
||||
IReadOnlyDictionary<string, float> taught = teacherSkills.TryGetValue(lesson.TeacherId, out var found)
|
||||
? found
|
||||
: new Dictionary<string, float>(StringComparer.Ordinal);
|
||||
|
||||
@@ -13,6 +13,8 @@ public static class PersonLogTypes
|
||||
public const string ActionStarted = "action-started";
|
||||
public const string ActionEnded = "action-ended";
|
||||
public const string TalkEnded = "talk-ended";
|
||||
public const string Whispered = "whispered";
|
||||
public const string TeacherInterrupted = "teacher-interrupted";
|
||||
public const string ApparelReplaced = "apparel-replaced";
|
||||
public const string ApparelChanged = "apparel-changed";
|
||||
public const string LessonNoTeacher = "lesson-no-teacher";
|
||||
@@ -29,6 +31,16 @@ public sealed record PersonLogEvent(string PersonId, DateTime Time, string Type,
|
||||
public string Caption(DefCatalog catalog, string locale)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(catalog);
|
||||
if (Type.Equals(PersonLogTypes.Whispered, StringComparison.Ordinal))
|
||||
{
|
||||
return catalog.Text(locale, "Whispered");
|
||||
}
|
||||
|
||||
if (Type.Equals(PersonLogTypes.TeacherInterrupted, StringComparison.Ordinal))
|
||||
{
|
||||
return catalog.Text(locale, "TeacherInterrupted");
|
||||
}
|
||||
|
||||
if (ThingDef is null)
|
||||
{
|
||||
return Type;
|
||||
|
||||
@@ -333,7 +333,7 @@ internal static class PresenceSystem
|
||||
: slot.Kind == DaySlotKind.Lesson && lessons.Any(lesson => lesson.Period == slot.Index);
|
||||
if (activity.IsActive && TalkActions.IsTalk(activity.ActionId))
|
||||
{
|
||||
if (!bound)
|
||||
if (!bound || TalkActions.IsWhisper(activity.ActionId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -432,7 +432,48 @@ internal static class PresenceSystem
|
||||
presence = PresenceStepper.StartWalk(presence, walks, decision.WalkTo, headingHome: false);
|
||||
}
|
||||
|
||||
return decision.StartAction is not null && !activity.IsActive ? decision.StartAction : null;
|
||||
if (decision.StartAction is not null && !activity.IsActive)
|
||||
{
|
||||
return decision.StartAction;
|
||||
}
|
||||
|
||||
if (!activity.IsActive
|
||||
&& decision.WalkTo is null
|
||||
&& ShouldStartWhisper(school, person, state))
|
||||
{
|
||||
return TalkActions.Whisper;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool ShouldStartWhisper(School school, Person person, ActorState state)
|
||||
{
|
||||
if (!state.BoundToLesson
|
||||
|| !person.IsStudent
|
||||
|| state.IsWalking
|
||||
|| state.NodeId is null
|
||||
|| state.DutyRoom is null
|
||||
|| !state.NodeId.Equals(state.DutyRoom, StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var location = school.Map?.NodeDef(state.NodeId);
|
||||
if (location is null || !location.Equals("Classroom", StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var rules = school.Catalog?.BehaviorRules;
|
||||
var chance = (rules?.WhisperStartChance ?? 0.12f) * TalkCircles.Initiative(person.Traits, school.Catalog!);
|
||||
var roll = TalkCircles.Roll01(
|
||||
Seed.Mix(
|
||||
school.PeopleSeed,
|
||||
person.Id,
|
||||
DateOnly.FromDateTime(school.Clock.Time).DayNumber,
|
||||
Seed.WhisperSalt + (school.Clock.Time.Minute / 2)));
|
||||
return TalkCircles.WhisperCaught(roll, chance, 0.5f, 1f);
|
||||
}
|
||||
|
||||
private static Dictionary<(string Node, string Thing), int> SnapshotOccupied(School school, string exceptId)
|
||||
|
||||
@@ -18,6 +18,9 @@ internal sealed class ActiveTalkCircle
|
||||
public required List<string> Members { get; init; }
|
||||
|
||||
public float RemainingMinutes { get; set; }
|
||||
|
||||
/// <summary>Set once a teacher in the room has rolled to notice this whisper.</summary>
|
||||
public bool CatchChecked { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Forms 2–4 person talk circles, applies outcomes, writes topic log lines.</summary>
|
||||
@@ -59,7 +62,7 @@ internal static class TalkCircleSystem
|
||||
}
|
||||
|
||||
var person = school.Roster.People.FirstOrDefault(row => row.Id.Equals(personId, StringComparison.Ordinal));
|
||||
if (person is null)
|
||||
if (person is null || !RoleFits(action, person))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -115,6 +118,11 @@ internal static class TalkCircleSystem
|
||||
{
|
||||
circle.RemainingMinutes -= minutes;
|
||||
SyncActivity(school, circle);
|
||||
if (TalkActions.IsWhisper(circle.ActionId) && TryCatchWhisper(school, circle))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (circle.RemainingMinutes > 0)
|
||||
{
|
||||
continue;
|
||||
@@ -173,7 +181,8 @@ internal static class TalkCircleSystem
|
||||
{
|
||||
var rules = school.Catalog!.BehaviorRules;
|
||||
var max = TalkCircles.MaxSize(action.DefName, rules, initiator.Traits, school.Catalog);
|
||||
var candidates = GatherCandidates(school, initiator.Id, nodeId, requirePhone: false);
|
||||
var studentsOnly = TalkActions.IsWhisper(action.DefName) || TalkActions.IsTeacherTalk(action.DefName);
|
||||
var candidates = GatherCandidates(school, initiator.Id, nodeId, requirePhone: false, studentsOnly);
|
||||
var ranked = TalkCircles.RankInvitees(initiator, candidates, rules);
|
||||
var members = new List<string> { initiator.Id };
|
||||
foreach (var id in ranked)
|
||||
@@ -186,7 +195,7 @@ internal static class TalkCircleSystem
|
||||
members.Add(id);
|
||||
}
|
||||
|
||||
var min = rules?.TalkCircleMin ?? 2;
|
||||
var min = TalkActions.IsTeacherTalk(action.DefName) ? 3 : rules?.TalkCircleMin ?? 2;
|
||||
if (members.Count < min)
|
||||
{
|
||||
return false;
|
||||
@@ -196,8 +205,17 @@ internal static class TalkCircleSystem
|
||||
school.Catalog,
|
||||
initiator,
|
||||
initiator.AgeOn(school.Clock.Time),
|
||||
Seed.Mix(school.PeopleSeed, initiator.Id, DateOnly.FromDateTime(school.Clock.Time).DayNumber, Seed.ApparelSalt + 21))
|
||||
?? school.Catalog.Topics.Values.First(topic => !topic.Abstract).DefName;
|
||||
Seed.Mix(school.PeopleSeed, initiator.Id, DateOnly.FromDateTime(school.Clock.Time).DayNumber, Seed.ApparelSalt + 21),
|
||||
whisperOnLesson: TalkActions.IsWhisper(action.DefName));
|
||||
if (TalkActions.IsTeacherTalk(action.DefName))
|
||||
{
|
||||
topicId = TalkCircles.PickTeacherTopic(
|
||||
school.Catalog,
|
||||
rules,
|
||||
Seed.Mix(school.PeopleSeed, initiator.Id, DateOnly.FromDateTime(school.Clock.Time).DayNumber, Seed.WhisperSalt));
|
||||
}
|
||||
|
||||
topicId ??= school.Catalog.Topics.Values.First(topic => !topic.Abstract).DefName;
|
||||
|
||||
var circle = new ActiveTalkCircle
|
||||
{
|
||||
@@ -216,6 +234,11 @@ internal static class TalkCircleSystem
|
||||
{
|
||||
var rules = school.Catalog!.BehaviorRules;
|
||||
var person = school.Roster!.People.First(row => row.Id.Equals(personId, StringComparison.Ordinal));
|
||||
if ((TalkActions.IsWhisper(action.DefName) || TalkActions.IsTeacherTalk(action.DefName)) && !person.IsStudent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var max = TalkCircles.MaxSize(action.DefName, rules, person.Traits, school.Catalog);
|
||||
if (circle.Members.Count >= max || circle.Members.Contains(personId))
|
||||
{
|
||||
@@ -238,7 +261,7 @@ internal static class TalkCircleSystem
|
||||
&& circle.RemainingMinutes > 0)
|
||||
{
|
||||
var rules = school.Catalog!.BehaviorRules;
|
||||
var max = rules?.TalkCircleMax ?? 4;
|
||||
var max = TalkCircles.MaxSize(actionId, rules, [], school.Catalog);
|
||||
if (circle.Members.Count < max)
|
||||
{
|
||||
return circle;
|
||||
@@ -253,7 +276,8 @@ internal static class TalkCircleSystem
|
||||
School school,
|
||||
string exceptId,
|
||||
string nodeId,
|
||||
bool requirePhone)
|
||||
bool requirePhone,
|
||||
bool studentsOnly = false)
|
||||
{
|
||||
var roster = school.Roster!.People.ToDictionary(person => person.Id, StringComparer.Ordinal);
|
||||
var list = new List<TalkCircles.Candidate>();
|
||||
@@ -268,6 +292,11 @@ internal static class TalkCircleSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (studentsOnly && !roles.IsStudent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!roster.TryGetValue(identity.Id, out var person))
|
||||
{
|
||||
return;
|
||||
@@ -296,6 +325,14 @@ internal static class TalkCircleSystem
|
||||
{
|
||||
school.TalkCircleByPerson[member] = circle.Id;
|
||||
SetActivity(school, member, action.DefName, circle.TopicId, circle.RemainingMinutes);
|
||||
if (TalkActions.IsWhisper(action.DefName))
|
||||
{
|
||||
school.AppendDayLog(new PersonLogEvent(
|
||||
member,
|
||||
school.Clock.Time,
|
||||
PersonLogTypes.Whispered,
|
||||
circle.TopicId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,6 +429,11 @@ internal static class TalkCircleSystem
|
||||
appearance,
|
||||
rules,
|
||||
catalog);
|
||||
if (person.IsStudent && other.IsStaff)
|
||||
{
|
||||
delta = TalkCircles.ScaleByPedagogy(delta, SkillOf(school, other.Id, "Pedagogy"), rules);
|
||||
}
|
||||
|
||||
if (delta == 0)
|
||||
{
|
||||
continue;
|
||||
@@ -417,6 +459,150 @@ internal static class TalkCircleSystem
|
||||
school.TalkCirclesById.Remove(circle.Id);
|
||||
}
|
||||
|
||||
private static bool TryCatchWhisper(School school, ActiveTalkCircle circle)
|
||||
{
|
||||
if (circle.CatchChecked)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var teacherId = StaffStandingIn(school, circle.NodeId);
|
||||
if (teacherId is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
circle.CatchChecked = true;
|
||||
var rules = school.Catalog!.BehaviorRules;
|
||||
var traits = new List<string>();
|
||||
foreach (var memberId in circle.Members)
|
||||
{
|
||||
var member = school.Roster!.People.FirstOrDefault(person => person.Id.Equals(memberId, StringComparison.Ordinal));
|
||||
if (member is not null)
|
||||
{
|
||||
traits.AddRange(member.Traits);
|
||||
}
|
||||
}
|
||||
|
||||
var roll = TalkCircles.Roll01(
|
||||
Seed.Mix(school.PeopleSeed, circle.Id, DateOnly.FromDateTime(school.Clock.Time).DayNumber, Seed.WhisperSalt));
|
||||
var multiplier = TalkCircles.WhisperCatchMultiplier(traits, school.Catalog);
|
||||
if (!TalkCircles.WhisperCaught(
|
||||
roll,
|
||||
rules?.WhisperCatchChance ?? 0.4f,
|
||||
rules?.WhisperCatchMax ?? 0.85f,
|
||||
multiplier))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ConvertToReprimand(school, circle, teacherId);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void ConvertToReprimand(School school, ActiveTalkCircle circle, string teacherId)
|
||||
{
|
||||
var pupils = circle.Members.ToArray();
|
||||
foreach (var member in pupils)
|
||||
{
|
||||
school.AppendDayLog(new PersonLogEvent(
|
||||
member,
|
||||
school.Clock.Time,
|
||||
PersonLogTypes.TeacherInterrupted,
|
||||
circle.TopicId));
|
||||
school.TalkCircleByPerson.Remove(member);
|
||||
ClearActivity(school, member);
|
||||
}
|
||||
|
||||
school.TalkCirclesById.Remove(circle.Id);
|
||||
if (!school.Catalog!.Actions.TryGetValue(TalkActions.TeacherTalk, out var action))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var members = new List<string> { teacherId };
|
||||
var max = TalkCircles.MaxSize(TalkActions.TeacherTalk, school.Catalog.BehaviorRules, [], school.Catalog);
|
||||
foreach (var id in pupils.OrderBy(value => value, StringComparer.Ordinal))
|
||||
{
|
||||
if (members.Count >= max)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!members.Contains(id, StringComparer.Ordinal))
|
||||
{
|
||||
members.Add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (members.Count < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var reprimand = new ActiveTalkCircle
|
||||
{
|
||||
Id = $"reprimand-{teacherId}-{circle.NodeId}-{school.Clock.Time.Ticks}",
|
||||
ActionId = TalkActions.TeacherTalk,
|
||||
TopicId = TeacherTopics.Discipline,
|
||||
NodeId = circle.NodeId,
|
||||
Members = members,
|
||||
RemainingMinutes = action.Minutes,
|
||||
CatchChecked = true,
|
||||
};
|
||||
Register(school, reprimand, action);
|
||||
}
|
||||
|
||||
private static string? StaffStandingIn(School school, string nodeId)
|
||||
{
|
||||
string? found = null;
|
||||
school.World.Query(
|
||||
in People,
|
||||
(ref PersonIdentity identity, ref PersonRoles roles, ref Presence presence, ref PersonActivity activity) =>
|
||||
{
|
||||
if (found is not null
|
||||
|| !roles.IsStaff
|
||||
|| presence.NodeId is null
|
||||
|| !presence.NodeId.Equals(nodeId, StringComparison.Ordinal)
|
||||
|| presence.Path.Length > 0
|
||||
|| presence.RemainingMinutes > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
found = identity.Id;
|
||||
});
|
||||
return found;
|
||||
}
|
||||
|
||||
private static bool RoleFits(ActionDef action, Person person)
|
||||
{
|
||||
if (action.Roles.Count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var role in action.Roles)
|
||||
{
|
||||
if (role.Equals(HSchool.Content.PersonRoles.Student, StringComparison.OrdinalIgnoreCase) && person.IsStudent)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (role.Equals(HSchool.Content.PersonRoles.Staff, StringComparison.OrdinalIgnoreCase) && person.IsStaff)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (role.Equals(HSchool.Content.PersonRoles.Parent, StringComparison.OrdinalIgnoreCase) && person.IsParent)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ApparelIssue AppearanceOf(School school, Person person)
|
||||
{
|
||||
var schoolClass = person.ClassId is { } classId
|
||||
|
||||
Reference in New Issue
Block a user