Skip to content

Commit

Permalink
add LungRot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DomBarber committed May 28, 2024
1 parent ebb52f6 commit 27abf82
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 27 deletions.
Binary file modified Assemblies/Pharmacist.dll
Binary file not shown.
91 changes: 64 additions & 27 deletions Source/PharmacistUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,98 +6,132 @@
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<Hediff> 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;
}

// otherwise
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;
}

HediffComp_Immunizable compImmunizable = h.TryGetComp<HediffComp_Immunizable>();
return compImmunizable != null;
}

private static bool NearLethalDisease(Hediff h) {
private static bool NearLethalDisease(Hediff h)
{
HediffComp_Immunizable compImmunizable = h.TryGetComp<HediffComp_Immunizable>();
return PotentiallyLethalDisease(h) &&
!compImmunizable.FullyImmune &&
h.Severity > PharmacistSettings.medicalCare.DiseaseThreshold &&
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];
Expand All @@ -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;
}
}
}
}

0 comments on commit 27abf82

Please sign in to comment.