Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lung Rot fix #49

Open
wants to merge 1 commit into
base: 1.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
}