Skip to content

Commit

Permalink
RWP 1.4.1
Browse files Browse the repository at this point in the history
Fixed custom haul work givers to prioritise correctly (thanks Zhentar!).

Separated all custom work givers in the menu to be individually togglable.
  • Loading branch information
DingoDjango authored Nov 7, 2016
1 parent 1f3ed27 commit f415372
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 43 deletions.
Binary file modified Assemblies/RefactoredWorkPriorities.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions Defs/UpdateFeatureDefs/UpdateFeatures.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
<content>RWP uses some custom priorities that do not exist in vanilla RimWorld to make colonists behave more logically.\n\nYou can toggle the use of these custom priorities and read more about them in the menu (via tooltips).\n\nTo access the mod's menu, go to Menu &gt; Options &gt; Mod Settings.</content>
</HugsLib.UpdateFeatureDef>

<HugsLib.UpdateFeatureDef ParentName="HMTBUpdateFeatures">
<defName>RWP_1_4_1</defName>
<assemblyVersion>1.4.1</assemblyVersion>
<content>\n- All custom work orders are now individually togglable in the mod's menu.\n\n- Fixed Haul Rottables. Haulers will prioritise the fastest rotting items.\n\n- Fixed Haul Deterioratables. Haulers will prioritise the fastest deteriorating items.\n\nTo access the mod's menu, go to Mod Settings in RimWorld's Options menu.</content>
</HugsLib.UpdateFeatureDef>

</Defs>
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
81 changes: 44 additions & 37 deletions Source/RWPMenu.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
using HugsLib;
using RimWorld;

[DefOf]
public static class RWPDefs
namespace RWP
{
public static WorkGiverDef DoctorRescueHumanColonist;
public static WorkGiverDef DoctorTreatHumanColonist;
public static WorkGiverDef HaulRottable;
public static WorkGiverDef HaulDeteriorating;
}
[DefOf]
public static class RWPDefs
{
public static WorkGiverDef DoctorRescueHumanColonist;
public static WorkGiverDef DoctorTreatHumanColonist;
public static WorkGiverDef HaulRottable;
public static WorkGiverDef HaulDeteriorating;
}

public class RWPMenu : ModBase
{
public override string ModIdentifier
{
get
{
return "RefactoredWorkPriorities";
}
}

public override void DefsLoaded()
{
UpdateDefs();
}

public override void SettingsChanged()
{
UpdateDefs();
}

private void UpdateDefs()
{
var customDoctor = Settings.GetHandle<bool>("CustomDoctorPriorities", "Custom Doctor priorities", "Doctors will rescue and treat colonists before animals or outsiders.", true);
RWPDefs.DoctorRescueHumanColonist.scanThings = customDoctor.Value;
RWPDefs.DoctorTreatHumanColonist.scanThings = customDoctor.Value;

var customHaul = Settings.GetHandle<bool>("CustomHaulPriorities", "Custom Haul priorities", "Haulers will haul rottable items (corn, meals etc.) and items which deteriorate over time (weapons, wood etc.) before generic things.", true);
RWPDefs.HaulRottable.scanThings = customHaul.Value;
RWPDefs.HaulDeteriorating.scanThings = customHaul.Value;
}
public class RWPMenu : ModBase
{
public override string ModIdentifier
{
get
{
return "RefactoredWorkPriorities";
}
}

public override void DefsLoaded()
{
UpdateDefs();
}

public override void SettingsChanged()
{
UpdateDefs();
}

private void UpdateDefs()
{
var doctorRescueColonist = Settings.GetHandle<bool>("DoctorRescueColonist", "[Doctor] Prioritise rescuing colonists", "Doctors will rescue allied colonists before rescuing animals or outsiders.", true);
RWPDefs.DoctorRescueHumanColonist.scanThings = doctorRescueColonist.Value;

var doctorTreatColonist = Settings.GetHandle<bool>("DoctorTreatColonist", "[Doctor] Prioritise treating colonists", "Doctors will treat colonist injuries before treating animals or outsiders.", true);
RWPDefs.DoctorTreatHumanColonist.scanThings = doctorTreatColonist.Value;

var haulRottables = Settings.GetHandle<bool>("HaulRottables", "[Haul] Prioritise hauling rottables", "Haulers will haul rottable items (corn, meals etc.) before generic things.", true);
RWPDefs.HaulRottable.scanThings = haulRottables.Value;

var haulDeterioratables = Settings.GetHandle<bool>("HaulDeterioratables", "[Haul] Prioritise hauling deterioratables", "Haulers will haul items which deteriorate over time (weapons, wood etc.) before generic things.", true);
RWPDefs.HaulDeteriorating.scanThings = haulDeterioratables.Value;
}
}
}
23 changes: 21 additions & 2 deletions Source/WorkGiver_HaulDeteriorating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ namespace RWP
{
public class WorkGiver_HaulDeteriorating : WorkGiver_Scanner
{
public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn) //Lists all deteriorating items that aren't under a roof and sorts by highest DeteriorationRate to lowest
public override bool Prioritized
{
return ListerHaulables.ThingsPotentiallyNeedingHauling().Where(t => t.Position.GetRoof() == null && t.GetStatValue(StatDefOf.DeteriorationRate, true) > 0f).OrderByDescending(t => t.GetStatValue(StatDefOf.DeteriorationRate, true));
get
{
return true;
}
}

public override bool ShouldSkip(Pawn pawn)
{
return ListerHaulables.ThingsPotentiallyNeedingHauling().Count == 0;
}

public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn) //Lists all items with DeteriorationRate above 0 that aren't under a roof
{
return ListerHaulables.ThingsPotentiallyNeedingHauling().Where(t => t.Position.GetRoof() == null && t.GetStatValue(StatDefOf.DeteriorationRate, true) > 0f);
}

public override Job JobOnThing(Pawn pawn, Thing t)
Expand All @@ -22,5 +35,11 @@ public override Job JobOnThing(Pawn pawn, Thing t)

return HaulAIUtility.HaulToStorageJob(pawn, t);
}

public override float GetPriority(Pawn pawn, TargetInfo t)
{
Thing thing = t.Thing;
return thing.GetStatValue(StatDefOf.DeteriorationRate, true);
}
}
}
24 changes: 22 additions & 2 deletions Source/WorkGiver_HaulRottable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ namespace RWP
{
public class WorkGiver_HaulRottable : WorkGiver_Scanner
{
public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn) //Lists all items with the rottable comp and sorts by fastest rotting to slowest
public override bool Prioritized
{
return ListerHaulables.ThingsPotentiallyNeedingHauling().Where(t => t.def.comps.Exists(tc => tc.compClass == typeof(CompRottable))).OrderBy(t => t.def.GetCompProperties<CompProperties_Rottable>().daysToRotStart);
get
{
return true;
}
}

public override bool ShouldSkip(Pawn pawn)
{
return ListerHaulables.ThingsPotentiallyNeedingHauling().Count == 0;
}

public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn) //Lists all items which need hauling and have CompProperties_Rottable
{
return ListerHaulables.ThingsPotentiallyNeedingHauling().Where(t => t.def.comps.Exists(tc => tc.compClass == typeof(CompRottable)));
}

public override Job JobOnThing(Pawn pawn, Thing t)
Expand All @@ -22,5 +35,12 @@ public override Job JobOnThing(Pawn pawn, Thing t)

return HaulAIUtility.HaulToStorageJob(pawn, t);
}

public override float GetPriority(Pawn pawn, TargetInfo t)
{
Thing thing = t.Thing;
var rottability = thing.def.GetCompProperties<CompProperties_Rottable>().daysToRotStart;
return (1f) / (rottability);
}
}
}

0 comments on commit f415372

Please sign in to comment.