diff --git a/Assemblies/Pharmacist.dll b/Assemblies/Pharmacist.dll index decb1fe..d9f8f28 100644 Binary files a/Assemblies/Pharmacist.dll and b/Assemblies/Pharmacist.dll differ diff --git a/Source/PharmacistUtility.cs b/Source/PharmacistUtility.cs index 62215d4..e72fea8 100644 --- a/Source/PharmacistUtility.cs +++ b/Source/PharmacistUtility.cs @@ -6,42 +6,55 @@ using RimWorld; using Verse; -namespace Pharmacist { - public enum InjurySeverity { +namespace Pharmacist +{ + + public enum InjurySeverity + { Minor, Major, LifeThreathening, Operation } - public enum Population { + public enum Population + { Colonist, Prisoner, Guest, Animal } - public static class PharmacistUtility { - public static InjurySeverity GetTendSeverity(this Pawn patient) { + public static class PharmacistUtility + { + public static InjurySeverity GetTendSeverity(this Pawn patient) + { if (!HealthAIUtility.ShouldBeTendedNowByPlayer(patient)) // .ShouldBeTendedNow( patient ) ) -{ + { return InjurySeverity.Minor; } System.Collections.Generic.List hediffs = patient.health.hediffSet.hediffs; - int ticksToDeathDueToBloodLoss = HealthUtility.TicksUntilDeathDueToBloodLoss( patient ); + int ticksToDeathDueToBloodLoss = HealthUtility.TicksUntilDeathDueToBloodLoss(patient); // going to die in <6 hours, or any tendable is life threathening if (ticksToDeathDueToBloodLoss <= GenDate.TicksPerHour * 6 || hediffs.Any(h => h.CurStage?.lifeThreatening ?? false) || - hediffs.Any(NearLethalDisease)) { + hediffs.Any(NearLethalDisease) || + hediffs.Any(h => IsBloodRot(h) && h.Severity > PharmacistSettings.medicalCare.DiseaseThreshold) + ) + { return InjurySeverity.LifeThreathening; } // going to die in <12 hours, or any immunity < severity and can be fatal, or death by a thousand cuts imminent if (ticksToDeathDueToBloodLoss <= GenDate.TicksPerHour * 12 || hediffs.Any(PotentiallyLethalDisease) || - DeathByAThousandCuts(patient)) { + DeathByAThousandCuts(patient) || + hediffs.Any(IsBloodRot) || + hediffs.Any(IsLungRot) + ) + { return InjurySeverity.Major; } @@ -49,12 +62,15 @@ public static InjurySeverity GetTendSeverity(this Pawn patient) { return InjurySeverity.Minor; } - private static bool PotentiallyLethalDisease(Hediff h) { - if (!h.TendableNow()) { + private static bool PotentiallyLethalDisease(Hediff h) + { + if (!h.TendableNow()) + { return false; } - if (h.def.lethalSeverity <= 0f) { + if (h.def.lethalSeverity <= 0f) + { return false; } @@ -62,7 +78,8 @@ private static bool PotentiallyLethalDisease(Hediff h) { return compImmunizable != null; } - private static bool NearLethalDisease(Hediff h) { + private static bool NearLethalDisease(Hediff h) + { HediffComp_Immunizable compImmunizable = h.TryGetComp(); return PotentiallyLethalDisease(h) && !compImmunizable.FullyImmune && @@ -70,34 +87,51 @@ private static bool NearLethalDisease(Hediff h) { compImmunizable.Immunity < PharmacistSettings.medicalCare.DiseaseMargin + h.Severity; } - private static bool DeathByAThousandCuts(Pawn patient) { + private static bool IsBloodRot(Hediff h) + { + return h.def.defName == "BloodRot"; + } + + private static bool IsLungRot(Hediff h) + { + return h.def.defName == "LungRot"; + } + + private static bool DeathByAThousandCuts(Pawn patient) + { // number of bleeding wounds > threshold return patient.health.hediffSet.hediffs.Count(hediff => hediff.Bleeding) > PharmacistSettings.medicalCare.MinorWoundsThreshold; } - public static Population GetPopulation(this Pawn patient) { - if (patient.RaceProps.Animal) { + public static Population GetPopulation(this Pawn patient) + { + if (patient.RaceProps.Animal) + { return Population.Animal; } - if (patient.IsColonist) { + if (patient.IsColonist) + { return Population.Colonist; } - if (patient.IsPrisonerOfColony) { + if (patient.IsPrisonerOfColony) + { return Population.Prisoner; } return Population.Guest; } - public static MedicalCareCategory TendAdvice(Pawn patient) { + public static MedicalCareCategory TendAdvice(Pawn patient) + { InjurySeverity severity = patient.GetTendSeverity(); return TendAdvice(patient, severity); } - public static MedicalCareCategory TendAdvice(Pawn patient, InjurySeverity severity) { + public static MedicalCareCategory TendAdvice(Pawn patient, InjurySeverity severity) + { Population population = patient.GetPopulation(); MedicalCareCategory pharmacist = PharmacistSettings.medicalCare[population][severity]; @@ -106,19 +140,22 @@ public static MedicalCareCategory TendAdvice(Pawn patient, InjurySeverity severi #if DEBUG Log.Message( "Pharmacist :: Advice" + - $"\n\tpatient: {patient?.LabelShort}" + - $"\n\tpopulation: {population}" + - $"\n\tseverity: {severity}" + - $"\n\tplayerSettings: {playerSetting}" + - $"\n\tpharmacist: {pharmacist}"); + $"\tpatient: {patient?.LabelShort}" + + $"\tpopulation: {population}" + + $"\tbloodRot: {patient.health.hediffSet.hediffs.Exists(IsBloodRot)}" + + $"\tlungRot: {patient.health.hediffSet.hediffs.Exists(IsLungRot)}" + + $"\tseverity: {severity}" + + $"\tplayerSettings: {playerSetting}" + + $"\tpharmacist: {pharmacist}"); #endif // return lowest - if (pharmacist < playerSetting) { + if (pharmacist < playerSetting) + { return pharmacist; } return playerSetting; } } -} +} \ No newline at end of file