diff --git a/Source/FieldTending.cs b/Source/FieldTending.cs index d5f4962..763cbaa 100644 --- a/Source/FieldTending.cs +++ b/Source/FieldTending.cs @@ -43,7 +43,7 @@ static class GoodLayingStatusForTend_Patch public static void Postfix(Pawn patient, ref bool __result) { if (!__result) Log.Message($"StatusFor {patient} is {__result}"); - if (!__result && Settings.Get().FieldTendingActive(patient)) + if (!__result && Mod.settings.FieldTendingActive(patient)) __result = (patient.GetPosture() != PawnPosture.Standing) || (patient.Drafted && patient.jobs.curDriver is JobDriver_Wait //Tend while idle + drafted && !patient.stances.FullBodyBusy && !patient.stances.Staggered); @@ -104,7 +104,7 @@ public static class UseTempSleepSpot public static ThinkResult LayDownInPlace(Pawn pawn, JobGiver_PatientGoToBed giver) { - if (Settings.Get().FieldTendingActive(pawn)) + if (Mod.settings.FieldTendingActive(pawn)) { Building_Bed tempTendSpot = pawn.Position.GetThingList(pawn.Map).FirstOrDefault(t => t.def == TempSleepSpot) as Building_Bed; if (tempTendSpot == null && @@ -180,7 +180,7 @@ static class ShouldBeFed_Patch { public static bool InBed_Patch(Pawn pawn) { - return pawn.InBed() || Settings.Get().FieldTendingActive(pawn); + return pawn.InBed() || Mod.settings.FieldTendingActive(pawn); } public static IEnumerable Transpiler(IEnumerable instructions) { diff --git a/Source/InventorySurgery.cs b/Source/InventorySurgery.cs index bfce866..ab5cfee 100644 --- a/Source/InventorySurgery.cs +++ b/Source/InventorySurgery.cs @@ -50,7 +50,7 @@ public static void Postfix(Pawn pawn, Thing billGiver, List relevantThing } //Tiny addition to use minimal medicine for Anesthetize bill. TODO: Make this a def extension so any recipe could use it, though no one will so why really - int statAdjust = (Settings.Get().minimalMedicineForNonUrgent && HackityGetBill.bill.recipe == Anesthetize ? 1 : -1); + int statAdjust = (Mod.settings.minimalMedicineForNonUrgent && HackityGetBill.bill.recipe == Anesthetize ? 1 : -1); relevantThings.SortBy( (Thing x) => statAdjust * x.GetStatValue(StatDefOf.MedicalPotency), //Check if item is in inventory or spawned in map: inventory "distance" is 0 diff --git a/Source/MedicineGrabbing.cs b/Source/MedicineGrabbing.cs index a698f05..4b30f36 100644 --- a/Source/MedicineGrabbing.cs +++ b/Source/MedicineGrabbing.cs @@ -105,11 +105,11 @@ public static void FilterInjuriesForMedCount(List hediffs) }); } - if (Settings.Get().noMedicineForNonUrgent) + if (Mod.settings.noMedicineForNonUrgent) { hediffs.RemoveAll(h => !h.IsUrgent()); } - else if (Settings.Get().minimalMedicineForNonUrgent && __beep_beep_MinimalMedicineAvailable) + else if (Mod.settings.minimalMedicineForNonUrgent && __beep_beep_MinimalMedicineAvailable) { if (hediffs.Any(h => h.IsUrgent())) hediffs.RemoveAll(h => !h.IsUrgent()); @@ -342,7 +342,7 @@ public static List Find(Pawn healer, Pawn patient, out int totalCoun Log.Message($"{healer} is tending to {patient}"); float sufficientQuality = maxMedicineQuality + 1; // nothing is sufficient! - if (Settings.Get().minimalMedicineForNonUrgent) + if (Mod.settings.minimalMedicineForNonUrgent) { if (patient.health.hediffSet.hediffs.All(h => !h.TendableNow() || !h.IsUrgent())) { @@ -414,18 +414,18 @@ public static List Find(Pawn healer, Pawn patient, out int totalCoun List pawns = healer.Map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer).ListFullCopy(); - if (!Settings.Get().useDoctorMedicine) + if (!Mod.settings.useDoctorMedicine) pawns.Remove(healer); - if (!Settings.Get().usePatientMedicine) + if (!Mod.settings.usePatientMedicine) pawns.Remove(patient); - if (!Settings.Get().useColonistMedicine) + if (!Mod.settings.useColonistMedicine) pawns.RemoveAll(p => p.IsFreeColonist && p != healer && p != patient); - if (!Settings.Get().useAnimalMedicine) + if (!Mod.settings.useAnimalMedicine) pawns.RemoveAll(p => !p.IsColonist); int minDistance = DistanceTo(healer, patient); - if (!Settings.Get().useOtherEvenIfFar) - pawns.RemoveAll(p => DistanceTo(p, healer, patient) > minDistance + Settings.Get().distanceToUseFromOther * 2); //*2, there and back + if (!Mod.settings.useOtherEvenIfFar) + pawns.RemoveAll(p => DistanceTo(p, healer, patient) > minDistance + Mod.settings.distanceToUseFromOther * 2); //*2, there and back pawns.RemoveAll(p => !validatorHolder(p)); @@ -458,7 +458,7 @@ public static List Find(Pawn healer, Pawn patient, out int totalCoun if (bestMed.thing != null) { allMeds.RemoveLast(); - if (Settings.Get().useCloseMedicine && bestMed.pawn != null) + if (Mod.settings.useCloseMedicine && bestMed.pawn != null) { bestMed.DebugLog("Best: "); Log.Message($"checking nearby:"); @@ -467,7 +467,7 @@ public static List Find(Pawn healer, Pawn patient, out int totalCoun { MedicineEvaluator closeMed = equalMedicines.MinBy(eval => eval.distance); closeMed.DebugLog("Nearby med on the way there: "); - if (closeMed.distance <= minDistance + Settings.Get().distanceToUseEqualOnGround * 2) //*2, there and back + if (closeMed.distance <= minDistance + Mod.settings.distanceToUseEqualOnGround * 2) //*2, there and back bestMed = closeMed; } } diff --git a/Source/Settings.cs b/Source/Settings.cs index 4f50db7..54a6550 100644 --- a/Source/Settings.cs +++ b/Source/Settings.cs @@ -7,7 +7,7 @@ namespace SmartMedicine { - class Settings : ModSettings + public class Settings : ModSettings { //TODO: save per map public bool useDoctorMedicine = true; @@ -39,11 +39,6 @@ public bool FieldTendingActive(Pawn patient) (fieldTendingForLackOfBed && RestUtility.FindPatientBedFor(patient) == null)); } - public static Settings Get() - { - return LoadedModManager.GetMod().GetSettings(); - } - public void DoWindowContents(Rect wrect) { var options = new Listing_Standard(); diff --git a/Source/SmartMedicine.cs b/Source/SmartMedicine.cs index e30f9f6..7861d95 100644 --- a/Source/SmartMedicine.cs +++ b/Source/SmartMedicine.cs @@ -10,10 +10,11 @@ namespace SmartMedicine { public class Mod : Verse.Mod { + public static Settings settings; public Mod(ModContentPack content) : base(content) { // initialize settings - GetSettings(); + settings = GetSettings(); #if DEBUG Harmony.DEBUG = true; #endif @@ -26,7 +27,7 @@ public Mod(ModContentPack content) : base(content) public override void DoSettingsWindowContents(Rect inRect) { base.DoSettingsWindowContents(inRect); - GetSettings().DoWindowContents(inRect); + settings.DoWindowContents(inRect); } public override string SettingsCategory() diff --git a/Source/StockUp/StockUpGUI.cs b/Source/StockUp/StockUpGUI.cs index 3ba6b49..0f561c3 100644 --- a/Source/StockUp/StockUpGUI.cs +++ b/Source/StockUp/StockUpGUI.cs @@ -212,7 +212,7 @@ public static void DrawMissingThings(Pawn pawn, ref float y, Rect viewRect) { if (!pawn.IsFreeColonist || pawn.Dead) return; - if (!Settings.Get().stockUp) return; + if (!Mod.settings.stockUp) return; foreach (ThingDef def in pawn.StockingUpList().ToList()) if (pawn.StockUpMissing(def)) @@ -222,7 +222,7 @@ public static void DrawMissingThings(Pawn pawn, ref float y, Rect viewRect) public static void DrawStockUpButton(Pawn pawn, ref float y, float width) { - if (!Settings.Get().stockUp) return; + if (!Mod.settings.stockUp) return; GUI.color = ThingLabelColor; @@ -308,7 +308,7 @@ public static class InterfaceDrop_Patch public static PropertyInfo SelPawnForGearInfo = AccessTools.Property(typeof(ITab_Pawn_Gear), "SelPawnForGear"); public static void Postfix(Thing t, ITab_Pawn_Gear __instance) { - if (!Settings.Get().stockUp) return; + if (!Mod.settings.stockUp) return; Pawn pawn = (Pawn)SelPawnForGearInfo.GetValue(__instance, new object[] { }); diff --git a/Source/StockUp/StockUpUtility.cs b/Source/StockUp/StockUpUtility.cs index e61ff0b..7bca0d4 100644 --- a/Source/StockUp/StockUpUtility.cs +++ b/Source/StockUp/StockUpUtility.cs @@ -76,13 +76,13 @@ public static void StockUpClearSettings(this Pawn pawn) } public static bool StockingUpOnAnything(this Pawn pawn) { - if (!Settings.Get().stockUp || pawn.inventory == null) return false; + if (!Mod.settings.stockUp || pawn.inventory == null) return false; return pawn.StockUpSettings().Count > 0; } public static IEnumerable StockingUpList(this Pawn pawn) { - if (!Settings.Get().stockUp || pawn.inventory == null) return new List(); + if (!Mod.settings.stockUp || pawn.inventory == null) return new List(); return pawn.StockUpSettings().Keys; } @@ -91,7 +91,7 @@ public static IEnumerable StockingUpList(this Pawn pawn) public static bool StockingUpOn(this Pawn pawn, ThingDef thingDef) { - if (!Settings.Get().stockUp || pawn.inventory == null || pawn.inventory.UnloadEverything) return false; + if (!Mod.settings.stockUp || pawn.inventory == null || pawn.inventory.UnloadEverything) return false; return pawn.StockUpSettings().ContainsKey(thingDef); } @@ -121,7 +121,7 @@ public static int StockUpNeeds(this Pawn pawn, ThingDef thingDef) if (invCount > capacity) return capacity - invCount; if (!EnoughAvailable(thingDef, pawn.Map)) - return Settings.Get().stockUpReturn ? -invCount : 0; + return Mod.settings.stockUpReturn ? -invCount : 0; return capacity - invCount; } @@ -160,7 +160,7 @@ public static void StockUpStop(this Pawn pawn, ThingDef thingDef) public static Thing StockUpThingToReturn(this Pawn pawn) { - if (!Settings.Get().stockUp || pawn.inventory == null) return null; + if (!Mod.settings.stockUp || pawn.inventory == null) return null; ThingDef td = pawn.StockUpSettings().FirstOrDefault(kvp => pawn.StockUpNeeds(kvp.Key) < 0).Key; if (td == null) return null; @@ -170,7 +170,7 @@ public static Thing StockUpThingToReturn(this Pawn pawn) public static bool StockUpIsFull(this Pawn pawn) { - if (!Settings.Get().stockUp) return true; + if (!Mod.settings.stockUp) return true; return !pawn.StockUpSettings().Any(kvp => pawn.StockUpNeeds(kvp.Key) != 0); } @@ -178,7 +178,7 @@ public static bool StockUpIsFull(this Pawn pawn) public static bool EnoughAvailable(Thing thing) => EnoughAvailable(thing.def, thing.Map); public static bool EnoughAvailable(ThingDef thingDef, Map map) { - float enough = Settings.Get().stockUpEnough; + float enough = Mod.settings.stockUpEnough; if (enough == 0.0f) return true; float stockUpCount = 0; diff --git a/Source/SurgeryUnlimited/SurgeryUnlimited.cs b/Source/SurgeryUnlimited/SurgeryUnlimited.cs index cdf94b5..d8c32a7 100644 --- a/Source/SurgeryUnlimited/SurgeryUnlimited.cs +++ b/Source/SurgeryUnlimited/SurgeryUnlimited.cs @@ -18,7 +18,7 @@ public class SurgeryUnlimitedGameComponent : GameComponent public SurgeryUnlimitedGameComponent(Game game) { - surgeryUnlimitedDefault = Settings.Get().defaultUnlimitedSurgery; + surgeryUnlimitedDefault = Mod.settings.defaultUnlimitedSurgery; surgeryUnlimited = new HashSet(); } @@ -37,7 +37,7 @@ public void Set(Pawn pawn, bool val) public override void ExposeData() { - Scribe_Values.Look(ref surgeryUnlimitedDefault, "surgeryUnlimitedDefault", Settings.Get().defaultUnlimitedSurgery); + Scribe_Values.Look(ref surgeryUnlimitedDefault, "surgeryUnlimitedDefault", Mod.settings.defaultUnlimitedSurgery); Scribe_Collections.Look(ref surgeryUnlimited, "surgeryUnlimitedList", LookMode.Reference); } }