Add wet condition and disease aftereffect (phase 84).
This commit is contained in:
@@ -15,6 +15,8 @@ public class DiseaseDefTests
|
||||
Assert.True(catalog.Diseases.ContainsKey("Influenza"));
|
||||
Assert.True(catalog.Diseases.ContainsKey("StomachBug"));
|
||||
Assert.True(catalog.Diseases.ContainsKey("Otitis"));
|
||||
Assert.True(catalog.Diseases.ContainsKey(DiseaseFamilies.WetDefName));
|
||||
Assert.True(catalog.Diseases.ContainsKey(DiseaseFamilies.AftereffectDefName));
|
||||
|
||||
var cold = catalog.Diseases["CommonCold"];
|
||||
Assert.Equal(DiseaseFamilies.Respiratory, cold.Family);
|
||||
@@ -22,6 +24,9 @@ public class DiseaseDefTests
|
||||
Assert.True(cold.Stages.Count >= 2);
|
||||
Assert.Equal(0.5f, cold.IncubationDays);
|
||||
Assert.Equal(14f, cold.ImmunityDays);
|
||||
Assert.Equal(0.07f, cold.WetChancePerDay);
|
||||
Assert.Equal(0.55f, catalog.Diseases["Influenza"].AftereffectMinSeverity);
|
||||
Assert.Equal(DiseaseFamilies.Condition, catalog.Diseases[DiseaseFamilies.WetDefName].Family);
|
||||
Assert.Equal(0.55f, cold.NodeContagionChancePerDay);
|
||||
Assert.Equal(0.25f, cold.ClassContagionChancePerDay);
|
||||
Assert.True(cold.ContagiousDuringIncubation);
|
||||
@@ -30,7 +35,11 @@ public class DiseaseDefTests
|
||||
|
||||
Assert.Equal("ОРВИ", catalog.Label("ru", cold));
|
||||
Assert.Equal("Common cold", catalog.Label("en", cold));
|
||||
Assert.Equal("Мокрый", catalog.Label("ru", catalog.Diseases[DiseaseFamilies.WetDefName]));
|
||||
Assert.Equal("Wet", catalog.Label("en", catalog.Diseases[DiseaseFamilies.WetDefName]));
|
||||
Assert.Equal(1f, catalog.BehaviorRules!.DiseaseVectorScale);
|
||||
Assert.Equal(0.75f, catalog.BehaviorRules.WetRainChance);
|
||||
Assert.Equal(0.85f, catalog.BehaviorRules.WetSnowChance);
|
||||
Assert.Equal(3, catalog.BehaviorRules.DiseaseOutbreakMinNewCases);
|
||||
Assert.True(catalog.Events.ContainsKey("DiseaseOutbreak"));
|
||||
Assert.Equal(EventTriggers.DiseaseOutbreak, catalog.Events["DiseaseOutbreak"].Trigger);
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
using HSchool.Content;
|
||||
|
||||
namespace HSchool.People.Tests;
|
||||
|
||||
public class WetAftereffectTests
|
||||
{
|
||||
[Fact]
|
||||
public void HeavyDisease_LeavesAftereffectThatClears()
|
||||
{
|
||||
var catalog = LoadVanilla();
|
||||
var started = new DateTime(2012, 4, 3, 8, 0, 0, DateTimeKind.Utc);
|
||||
var person = Blank("p1");
|
||||
HealthConditions.Add(
|
||||
person,
|
||||
new HealthCondition
|
||||
{
|
||||
DefName = "Influenza",
|
||||
Severity = 0.85f,
|
||||
Progress = 0.99f,
|
||||
Source = "cold",
|
||||
StartedAt = started,
|
||||
});
|
||||
|
||||
Assert.True(HealthConditions.Tick(
|
||||
person,
|
||||
peopleSeed: 3,
|
||||
dayNumber: 50,
|
||||
gameMinutes: 24 * 60,
|
||||
catalog,
|
||||
started.AddDays(3)));
|
||||
|
||||
Assert.NotNull(person.Conditions);
|
||||
Assert.Contains(person.Conditions!, row => row.DefName == DiseaseFamilies.AftereffectDefName);
|
||||
Assert.DoesNotContain(person.Conditions!, row => row.DefName == "Influenza");
|
||||
Assert.True(DiseaseImmunities.IsImmune(person, "Influenza", started.AddDays(4)));
|
||||
|
||||
// Aftereffect clears on its stage curve within a few game days — not a year-long chronicle.
|
||||
for (var day = 0; day < 14 && person.Conditions is { Count: > 0 }; day++)
|
||||
{
|
||||
HealthConditions.Tick(
|
||||
person,
|
||||
peopleSeed: 3,
|
||||
dayNumber: 51 + day,
|
||||
gameMinutes: 24 * 60,
|
||||
catalog,
|
||||
started.AddDays(4 + day));
|
||||
}
|
||||
|
||||
Assert.True(
|
||||
person.Conditions is null
|
||||
|| person.Conditions.All(row => row.DefName != DiseaseFamilies.AftereffectDefName));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RosterJson_RoundTripsWetAndAftereffect()
|
||||
{
|
||||
var roster = Fixtures.Generate(Fixtures.Classrooms(4));
|
||||
var pupil = roster.People.First(person => person.IsStudent && !person.IsParent);
|
||||
var started = new DateTime(2012, 4, 3, 9, 0, 0, DateTimeKind.Utc);
|
||||
HealthConditions.Add(
|
||||
pupil,
|
||||
new HealthCondition
|
||||
{
|
||||
DefName = DiseaseFamilies.WetDefName,
|
||||
Severity = 0.6f,
|
||||
Progress = 0.1f,
|
||||
Source = "rain",
|
||||
StartedAt = started,
|
||||
});
|
||||
HealthConditions.Add(
|
||||
pupil,
|
||||
new HealthCondition
|
||||
{
|
||||
DefName = DiseaseFamilies.AftereffectDefName,
|
||||
Severity = 0.4f,
|
||||
Progress = 0.2f,
|
||||
Source = "Influenza",
|
||||
StartedAt = started.AddDays(-1),
|
||||
});
|
||||
|
||||
var json = RosterJson.Serialize(RosterDocument.From(1, roster));
|
||||
Assert.Contains($"\"defName\": \"{DiseaseFamilies.WetDefName}\"", json, StringComparison.Ordinal);
|
||||
Assert.Contains($"\"defName\": \"{DiseaseFamilies.AftereffectDefName}\"", json, StringComparison.Ordinal);
|
||||
|
||||
var loaded = RosterJson.Parse(json).ToRoster();
|
||||
var loadedPupil = loaded.People.First(person => person.Id.Equals(pupil.Id, StringComparison.Ordinal));
|
||||
Assert.NotNull(loadedPupil.Conditions);
|
||||
Assert.Equal(2, loadedPupil.Conditions!.Count);
|
||||
Assert.Contains(loadedPupil.Conditions, row => row.DefName == DiseaseFamilies.WetDefName && row.Source == "rain");
|
||||
Assert.Contains(
|
||||
loadedPupil.Conditions,
|
||||
row => row.DefName == DiseaseFamilies.AftereffectDefName && row.Source == "Influenza");
|
||||
}
|
||||
|
||||
private static DefCatalog LoadVanilla()
|
||||
{
|
||||
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
||||
return new CatalogLoader().Load(
|
||||
[CatalogLoader.CorePackId],
|
||||
PackDocuments.FromDirectory(CatalogLoader.CorePackId, root));
|
||||
}
|
||||
|
||||
private static Person Blank(string id)
|
||||
{
|
||||
var cases = new CaseTable
|
||||
{
|
||||
Nom = id,
|
||||
Gen = id,
|
||||
Dat = id,
|
||||
Acc = id,
|
||||
Ins = id,
|
||||
Pre = id,
|
||||
};
|
||||
return new Person
|
||||
{
|
||||
Id = id,
|
||||
FamilyId = "f",
|
||||
Female = false,
|
||||
BirthDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
Name = new PersonName(id, id, id, cases, cases, cases),
|
||||
IsStudent = true,
|
||||
IsStaff = false,
|
||||
IsParent = false,
|
||||
Numbers = new Dictionary<string, int>(StringComparer.Ordinal),
|
||||
Choices = new Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Skills = new Dictionary<string, int>(StringComparer.Ordinal),
|
||||
Traits = [],
|
||||
Needs = new Dictionary<string, float>(StringComparer.Ordinal),
|
||||
Opinions = new Dictionary<string, int>(StringComparer.Ordinal),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using HSchool.Ai;
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
|
||||
namespace HSchool.Simulation.Tests;
|
||||
|
||||
public class WetAftereffectTests
|
||||
{
|
||||
private static readonly DateTime TuesdayMorning = new(2012, 4, 3, 6, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
[Fact]
|
||||
public void RainArrival_AssignsWetMoreThanClear()
|
||||
{
|
||||
using var rainSchool = OpenStaffed(seed: 42);
|
||||
using var clearSchool = OpenStaffed(seed: 42);
|
||||
rainSchool.ForceWeather(new OutdoorWeather(12f, Precipitation.Rain));
|
||||
clearSchool.ForceWeather(new OutdoorWeather(12f, Precipitation.None));
|
||||
|
||||
var rainWet = CountWet(rainSchool);
|
||||
var clearWet = CountWet(clearSchool);
|
||||
|
||||
Assert.True(rainWet > clearWet);
|
||||
Assert.True(rainWet > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Wet_RaisesRespiratoryOnsetVsDryControl()
|
||||
{
|
||||
using var wetSchool = OpenStaffed(seed: 7);
|
||||
using var drySchool = OpenStaffed(seed: 7);
|
||||
wetSchool.ForceWeather(new OutdoorWeather(14f, Precipitation.None));
|
||||
drySchool.ForceWeather(new OutdoorWeather(14f, Precipitation.None));
|
||||
|
||||
foreach (var person in wetSchool.Roster!.People.Where(row => row.IsStudent || row.IsStaff))
|
||||
{
|
||||
HealthConditions.Add(
|
||||
person,
|
||||
new HealthCondition
|
||||
{
|
||||
DefName = DiseaseFamilies.WetDefName,
|
||||
Severity = 0.7f,
|
||||
Progress = 0f,
|
||||
Source = "rain",
|
||||
StartedAt = TuesdayMorning,
|
||||
});
|
||||
}
|
||||
|
||||
var wetHits = CountRespiratoryOnset(wetSchool);
|
||||
var dryHits = CountRespiratoryOnset(drySchool);
|
||||
|
||||
Assert.True(wetHits > dryHits);
|
||||
Assert.True(wetHits > 0);
|
||||
}
|
||||
|
||||
private static int CountWet(School school)
|
||||
{
|
||||
school.LastDiseaseDay = int.MinValue;
|
||||
DiseaseSystem.Apply(school, gameMinutes: 0);
|
||||
return school.Roster!.People.Count(person =>
|
||||
person.Conditions is not null
|
||||
&& person.Conditions.Any(row => row.DefName == DiseaseFamilies.WetDefName));
|
||||
}
|
||||
|
||||
private static int CountRespiratoryOnset(School school)
|
||||
{
|
||||
school.LastDiseaseDay = int.MinValue;
|
||||
DiseaseSystem.Apply(school, gameMinutes: 0);
|
||||
return school.Roster!.People.Count(person =>
|
||||
person.Conditions is not null
|
||||
&& person.Conditions.Any(row =>
|
||||
row.DefName is "CommonCold" or "Influenza" or "Otitis"));
|
||||
}
|
||||
|
||||
private static School OpenStaffed(int seed)
|
||||
{
|
||||
var (catalog, map) = Vanilla();
|
||||
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: seed, "Russia", TuesdayMorning);
|
||||
var pool = ApplicantPool.Create(catalog, roster, schoolSeed: seed, "Russia", TuesdayMorning);
|
||||
var school = School.Create(1, "Мокрый", TuesdayMorning, catalog, map);
|
||||
school.InstallPeople(roster, seed: seed, "Russia", pool);
|
||||
school.ConfigurePresence(weekDays: 5, maxDecisionsPerTick: 10_000);
|
||||
return school;
|
||||
}
|
||||
|
||||
private static (DefCatalog Catalog, MapLayout Map) Vanilla()
|
||||
{
|
||||
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
||||
var documents = new List<ContentDocument>();
|
||||
foreach (var path in Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories))
|
||||
{
|
||||
if (!path.EndsWith(".jsonc", StringComparison.OrdinalIgnoreCase)
|
||||
&& !path.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var relative = Path.GetRelativePath(root, path).Replace('\\', '/');
|
||||
documents.Add(new ContentDocument(
|
||||
CatalogLoader.CorePackId,
|
||||
relative,
|
||||
File.ReadAllText(path)));
|
||||
}
|
||||
|
||||
var catalog = new CatalogLoader().Load([CatalogLoader.CorePackId], documents);
|
||||
var map = CatalogLoader.LastDefaultMap([CatalogLoader.CorePackId], documents);
|
||||
Assert.NotNull(map);
|
||||
return (catalog, map);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user