using HSchool.Content; using HSchool.People; namespace HSchool.Simulation; /// /// Worn insulation in °C-equivalent points, summed from apparel currently on the body. /// Tests that need a bare frost set on the entity explicitly. /// public readonly record struct PersonInsulation(float Value) { public static PersonInsulation Naked { get; } = new(0f); public static PersonInsulation FromWorn(DefCatalog catalog, params string[] defNames) { ArgumentNullException.ThrowIfNull(catalog); var sum = 0f; foreach (var name in defNames) { if (catalog.Things.TryGetValue(name, out var thing) && thing.Layers.Count > 0) { sum += thing.Insulation; } } return new PersonInsulation(sum); } public static PersonInsulation FromPerson(Person person, DefCatalog? catalog) { ArgumentNullException.ThrowIfNull(person); if (catalog is null) { return Naked; } var worn = new List(); foreach (var item in person.Items) { if (item.Location.Equals(ItemLocations.Worn, StringComparison.Ordinal)) { worn.Add(item.Def); } } return worn.Count == 0 ? Naked : FromWorn(catalog, [.. worn]); } }