Skip to content

Commit

Permalink
Settings for overriding rescue chance and search radius
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainMuscles committed Feb 20, 2021
1 parent 1b565df commit 1e1245f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
4 changes: 1 addition & 3 deletions About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>CaptainMuscles.NoPawnLeftBehind</identifier>
<version>1.0.0</version>
<version>1.0.1</version>
<dependencies>
<li>Ludeon.RimWorld</li>
<li>brrainz.harmony</li>
</dependencies>
<loadAfter>
<li>Ludeon.RimWorld</li>
<li>brrainz.harmony</li>
</loadAfter>
<showCrossPromotions>true</showCrossPromotions>
<downloadUri>https://github.com/CaptainMuscles/CM_No_Pawn_Left_Behind/releases</downloadUri>
Expand Down
Binary file modified Assemblies/CM_No_Pawn_Left_Behind.dll
Binary file not shown.
9 changes: 9 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [1.0.1] - 2021-02-19

### Added
- Settings for overriding rescue chance and search radius

### Changed
- Clamped market value factor for priority calculation between 200 and 3000


## [1.0.0] - 2021-02-19

### Added
Expand Down
8 changes: 8 additions & 0 deletions Languages/English/Keyed/CM_No_Pawn_Left_Behind.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
<LanguageData>

<CM_No_Pawn_Left_Behind_Settings_Log_Priorities_Label>Log priority calculations in dev mode</CM_No_Pawn_Left_Behind_Settings_Log_Priorities_Label>

<CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Override_Label>Override rescue chance</CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Override_Label>
<CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Override_Description>When enabled, will override rescue chance for all situations</CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Override_Description>
<CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Label>Rescue chance</CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Label>

<CM_No_Pawn_Left_Behind_Settings_Search_Radius_Override_Label>Override rescue search radius</CM_No_Pawn_Left_Behind_Settings_Search_Radius_Override_Label>
<CM_No_Pawn_Left_Behind_Settings_Search_Radius_Override_Description>When enabled, will override search radius for all situations</CM_No_Pawn_Left_Behind_Settings_Search_Radius_Override_Description>
<CM_No_Pawn_Left_Behind_Settings_Search_Radius_Label>Rescue search radius</CM_No_Pawn_Left_Behind_Settings_Search_Radius_Label>

</LanguageData>
21 changes: 16 additions & 5 deletions Source/CM_No_Pawn_Left_Behind/JobGiver_Rescue.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;

using UnityEngine;
using RimWorld;
using Verse;
using Verse.AI;
Expand Down Expand Up @@ -34,10 +35,14 @@ protected override Job TryGiveJob(Pawn pawn)
{
float random = Rand.Value;

float finalRescueChance = rescueChance;
if (RescueMod.settings.rescueChanceOverride)
finalRescueChance = RescueMod.settings.rescueChance;

if (Prefs.DevMode && RescueMod.settings.logPriorities)
Log.Message(String.Format("{0} - checking rescue chance {1}/{2}", pawn, random, rescueChance));
Log.Message(String.Format("{0} - checking rescue chance {1}/{2}", pawn, random, finalRescueChance));

if (random > rescueChance)
if (random > finalRescueChance)
return null;

if (pawn.AnimalOrWildMan() || pawn.Faction == Faction.OfPlayer || !RCellFinder.TryFindBestExitSpot(pawn, out var exitSpot))
Expand All @@ -62,9 +67,10 @@ private bool TryFindRescuableAlly(Pawn rescuer, out Pawn ally, List<Thing> disal
return false;
}


// Multiply search radius by health
// Multiply search radius by health to make wounded people a little less bold in the face of danger
float maxDist = searchRadius;
if (RescueMod.settings.searchRadiusOverride)
maxDist = RescueMod.settings.searchRadius;
if (healthSearchDistanceWeight > 0.0f)
maxDist *= (healthSearchDistanceWeight * rescuer.health.summaryHealth.SummaryHealthPercent);

Expand Down Expand Up @@ -97,8 +103,13 @@ private bool TryFindRescuableAlly(Pawn rescuer, out Pawn ally, List<Thing> disal

priority *= (opinionPriorityWeight * opinionValue);
}

if (marketValuePriorityWeight > 0.0f)
priority *= (marketValuePriorityWeight * pawn.MarketValue);
{
float marketValue = Mathf.Clamp(pawn.MarketValue, 200.0f, 3000.0f);
priority *= (marketValuePriorityWeight * marketValue);
}

if (distancePriorityWeight > 0.0f)
priority /= (distancePriorityWeight * (rescuer.Position.DistanceTo(pawn.Position) + 1.0f));

Expand Down
22 changes: 22 additions & 0 deletions Source/CM_No_Pawn_Left_Behind/RescueModSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ public class RescueModSettings : ModSettings
{
public bool logPriorities = false;

public bool rescueChanceOverride = false;
public float rescueChance = 1.0f;

public bool searchRadiusOverride = false;
public float searchRadius = 1.0f;

public override void ExposeData()
{
base.ExposeData();

Scribe_Values.Look(ref logPriorities, "logPriorities", false);

Scribe_Values.Look(ref rescueChanceOverride, "rescueChanceOverride", false);
Scribe_Values.Look(ref rescueChance, "rescueChance", 0.5f);

Scribe_Values.Look(ref searchRadiusOverride, "searchRadiusOverride", false);
Scribe_Values.Look(ref searchRadius, "searchRadius", 10.0f);
}

public void DoSettingsWindowContents(Rect inRect)
Expand All @@ -24,6 +36,16 @@ public void DoSettingsWindowContents(Rect inRect)

listing_Standard.CheckboxLabeled("CM_No_Pawn_Left_Behind_Settings_Log_Priorities_Label".Translate(), ref logPriorities);

listing_Standard.CheckboxLabeled("CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Override_Label".Translate(), ref rescueChanceOverride, "CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Override_Description".Translate());
listing_Standard.Label("CM_No_Pawn_Left_Behind_Settings_Rescue_Chance_Label".Translate());
listing_Standard.Label(rescueChance.ToString("P0"));
rescueChance = listing_Standard.Slider(rescueChance, 0.0f, 2.0f);

listing_Standard.CheckboxLabeled("CM_No_Pawn_Left_Behind_Settings_Search_Radius_Override_Label".Translate(), ref searchRadiusOverride, "CM_No_Pawn_Left_Behind_Settings_Search_Radius_Override_Description".Translate());
listing_Standard.Label("CM_No_Pawn_Left_Behind_Settings_Search_Radius_Label".Translate());
listing_Standard.Label(searchRadius.ToString("F0"));
searchRadius = listing_Standard.Slider(searchRadius, 1.0f, 100.0f);

listing_Standard.End();
}

Expand Down

0 comments on commit 1e1245f

Please sign in to comment.