Skip to content

Commit

Permalink
Version 3.3.17
Browse files Browse the repository at this point in the history
- Changed preview image.

- Fixed users not being able to force repair when right clicking a building.

- Added a Repair designator:
* Used to flag buildings that will not be automatically repaired due to the current Repair Threshold setting.
* Flagged buildings will ignore the threshold.
* The designator will be removed when the building's current HP reaches its Maximum HP.

- Added a Repair keybinding to the Architect section of the keybindings menu.

- Repair icon courtesy of mrofa (credits can be found in the Steam Workshop page or Ludeon forums thread).

- Minor code consistency changes.
  • Loading branch information
DingoDjango committed Jun 12, 2017
1 parent 9a7c735 commit b274d59
Show file tree
Hide file tree
Showing 19 changed files with 264 additions and 59 deletions.
Binary file modified About/Preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assemblies/RefactoredWorkPriorities.dll
Binary file not shown.
11 changes: 11 additions & 0 deletions Defs/Designations/Designations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<DesignationDefs>

<DesignationDef>
<defName>RWP_ForcedRepair</defName>
<texturePath>Designations/ForcedRepair</texturePath>
<targetType>Thing</targetType>
<removeIfBuildingDespawned>true</removeIfBuildingDespawned>
</DesignationDef>

</DesignationDefs>
12 changes: 12 additions & 0 deletions Defs/KeyBindings/KeyBindings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<KeyBindingDefs>

<!-- Repair designator keybinding -->

<KeyBindingDef ParentName="ArchitectBase">
<defName>DesignatorForcedRepair</defName>
<label>Repair &lt;b&gt;&lt;color=orange&gt;[Refactored Work Priorities]&lt;/color&gt;&lt;/b&gt;</label>
<category>Architect</category>
</KeyBindingDef>

</KeyBindingDefs>
3 changes: 3 additions & 0 deletions Languages/ChineseSimplified/Keyed/ChineseSimplified.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
<RWP_setting_haulDeterioratables_HealthThresholdInt>&lt;b&gt;[Haul]&lt;/b&gt; Deterioratable HP threshold percentage: &lt;b&gt;&lt;color=orange&gt;{0}%&lt;/color&gt;&lt;/b&gt;</RWP_setting_haulDeterioratables_HealthThresholdInt>
<RWP_setting_haulDeterioratables_HealthThresholdInt_desc>If "Prioritise hauling deterioratables" is enabled, skip items if their current health falls below this percentage.</RWP_setting_haulDeterioratables_HealthThresholdInt_desc>

<Designator_ForcedRepair>Repair (Ignore Threshold)</Designator_ForcedRepair>
<Designator_ForcedRepairDesc>Instruct colonists to repair the designated buildings even if their HP is above the assigned Repair Threshold.</Designator_ForcedRepairDesc>

</LanguageData>
3 changes: 3 additions & 0 deletions Languages/English/Keyed/English.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
<RWP_setting_haulDeterioratables_HealthThresholdInt>&lt;b&gt;[Haul]&lt;/b&gt; Deterioratable HP threshold percentage: &lt;b&gt;&lt;color=orange&gt;{0}%&lt;/color&gt;&lt;/b&gt;</RWP_setting_haulDeterioratables_HealthThresholdInt>
<RWP_setting_haulDeterioratables_HealthThresholdInt_desc>If "Prioritise hauling deterioratables" is enabled, skip items if their current health falls below this percentage.</RWP_setting_haulDeterioratables_HealthThresholdInt_desc>

<Designator_ForcedRepair>Repair (Ignore Threshold)</Designator_ForcedRepair>
<Designator_ForcedRepairDesc>Instruct colonists to repair the designated buildings even if their HP is above the assigned Repair Threshold.</Designator_ForcedRepairDesc>

</LanguageData>
11 changes: 11 additions & 0 deletions Patches/Designations/DesignationCategories.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>

<Operation Class="PatchOperationAdd">
<xpath>/Defs/DesignationCategoryDef[defName = "Orders"]/specialDesignatorClasses</xpath>
<value>
<li>RWP.Designator_ForcedRepair</li>
</value>
</Operation>

</Patch>
13 changes: 13 additions & 0 deletions Patches/JobDefs/Jobs_Work.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>

<!-- Replace Repair driverClass -->

<Operation Class="PatchOperationReplace">
<xpath>/Defs/JobDef[defName = "Repair"]/driverClass</xpath>
<value>
<driverClass>RWP.JobDriver_RepairCustom</driverClass>
</value>
</Operation>

</Patch>
88 changes: 44 additions & 44 deletions Patches/WorkGivers.xml → Patches/WorkGiverDefs/WorkGivers.xml
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>

<!-- Remove feeding sick animals from doctors, given to handlers -->

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "DoctorFeedAnimals"]/workType</xpath>
<value>
<workType>Handling</workType>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "DoctorFeedAnimals"]/priorityInType</xpath>
<value>
<priorityInType>110</priorityInType>
</value>
</Operation>

<!-- Replace Repair giverClass -->

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "Repair"]/giverClass</xpath>
<value>
<giverClass>RWP.WorkGiver_RepairCustom</giverClass>
</value>
</Operation>

<!-- Prioritise roof removal over building roofs -->

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "RemoveRoofs"]/priorityInType</xpath>
<value>
<priorityInType>70</priorityInType>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "BuildRoofs"]/priorityInType</xpath>
<value>
<priorityInType>60</priorityInType>
</value>
</Operation>

<?xml version="1.0" encoding="utf-8" ?>
<Patch>

<!-- Remove feeding sick animals from doctors, given to handlers -->

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "DoctorFeedAnimals"]/workType</xpath>
<value>
<workType>Handling</workType>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "DoctorFeedAnimals"]/priorityInType</xpath>
<value>
<priorityInType>110</priorityInType>
</value>
</Operation>

<!-- Replace Repair giverClass -->

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "Repair"]/giverClass</xpath>
<value>
<giverClass>RWP.WorkGiver_RepairCustom</giverClass>
</value>
</Operation>

<!-- Prioritise roof removal over building roofs -->

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "RemoveRoofs"]/priorityInType</xpath>
<value>
<priorityInType>70</priorityInType>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>/WorkGivers/WorkGiverDef[defName = "BuildRoofs"]/priorityInType</xpath>
<value>
<priorityInType>60</priorityInType>
</value>
</Operation>

</Patch>
9 changes: 5 additions & 4 deletions Source/Controller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using UnityEngine;
using RimWorld;
using RimWorld;
using UnityEngine;
using Verse;

namespace RWP
Expand All @@ -11,8 +11,9 @@ public Controller(ModContentPack content) : base(content)
GetSettings<Settings>();
}

public WorkGiverDef DefOf_HaulRottable => DefDatabase<WorkGiverDef>.GetNamed("HaulRottable");
public WorkGiverDef DefOf_HaulDeteriorating => DefDatabase<WorkGiverDef>.GetNamed("HaulDeteriorating");
public static WorkGiverDef DefOf_HaulRottable => DefDatabase<WorkGiverDef>.GetNamed("HaulRottable");
public static WorkGiverDef DefOf_HaulDeteriorating => DefDatabase<WorkGiverDef>.GetNamed("HaulDeteriorating");
public static DesignationDef DefOf_RWP_ForcedRepair => DefDatabase<DesignationDef>.GetNamed("RWP_ForcedRepair");

public override void WriteSettings()
{
Expand Down
103 changes: 103 additions & 0 deletions Source/Designator_ForcedRepair.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System.Linq;
using RimWorld;
using UnityEngine;
using Verse;

namespace RWP
{
public class Designator_ForcedRepair : Designator
{
public Designator_ForcedRepair()
{
this.defaultLabel = "Designator_ForcedRepair".Translate();
this.defaultDesc = "Designator_ForcedRepairDesc".Translate();
this.icon = ContentFinder<Texture2D>.Get("Designations/ForcedRepair", true);
this.soundDragSustain = SoundDefOf.DesignateDragStandard;
this.soundDragChanged = SoundDefOf.DesignateDragStandardChanged;
this.useMouseIcon = true;
this.soundSucceeded = SoundDefOf.DesignateHaul; //???
this.hotKey = KeyBindingDef.Named("DesignatorForcedRepair");
}

public override AcceptanceReport CanDesignateCell(IntVec3 c)
{
if (!c.InBounds(base.Map))
{
return false;
}

if (c.Fogged(base.Map))
{
return false;
}

var thingList = base.Map.thingGrid.ThingsAt(c);

if (!(thingList.Any(t => CanDesignateThing(t).Accepted)))
{
return false;
}

return true;
}

public override void DesignateSingleCell(IntVec3 loc)
{
foreach (Thing building in base.Map.thingGrid.ThingsAt(loc))
{
if (this.CanDesignateThing(building).Accepted)
{
this.DesignateThing(building);
}
}
}

public override void DesignateThing(Thing t)
{
base.Map.designationManager.AddDesignation(new Designation(t, Controller.DefOf_RWP_ForcedRepair));
}

public override AcceptanceReport CanDesignateThing(Thing t)
{
if (!(base.Map.listerBuildingsRepairable.RepairableBuildings(Faction.OfPlayer).Contains(t)))
{
return false;
}

if (!(t.HitPoints < t.MaxHitPoints))
{
return false;
}

if (base.Map.designationManager.DesignationOn(t, DesignationDefOf.Deconstruct) != null)
{
return false;
}

if (base.Map.designationManager.DesignationOn(t, DesignationDefOf.Uninstall) != null)
{
return false;
}

if (base.Map.designationManager.DesignationOn(t, Controller.DefOf_RWP_ForcedRepair) != null)
{
return false;
}

return true;
}

public override int DraggableDimensions
{
get
{
return 2;
}
}

public override void SelectedUpdate()
{
GenUI.RenderMouseoverBracket();
}
}
}
38 changes: 38 additions & 0 deletions Source/JobDriver_RepairCustom.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using RimWorld;
using Verse;
using Verse.AI;

namespace RWP
{
public class JobDriver_RepairCustom : JobDriver_Repair
{
[DebuggerHidden]
protected override IEnumerable<Toil> MakeNewToils()
{
/* The final "repair" Toil ends the current job after it's done.
This means that we have to somehow intervene with our designator removal.
To do this we add a designator removal action to the cleanup FinishActions list. */

Action RemoveRepairDesignator = delegate
{
Pawn pawn = this.GetActor();
Job job = pawn.jobs.curJob;

if (job.targetA.Thing.HitPoints == job.targetA.Thing.MaxHitPoints)
{
pawn.Map.designationManager.RemoveAllDesignationsOn(job.targetA.Thing, false);
}
};

this.AddFinishAction(RemoveRepairDesignator);

foreach (Toil toil in base.MakeNewToils())
{
yield return toil;
}
}
}
}
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("3.2.17.0")]
[assembly: AssemblyFileVersion("3.2.17.0")]
[assembly: AssemblyVersion("3.3.17.0")]
[assembly: AssemblyFileVersion("3.3.17.0")]
2 changes: 2 additions & 0 deletions Source/RefactoredWorkPriorities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="JobDriver_RepairCustom.cs" />
<Compile Include="Designator_ForcedRepair.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Controller.cs" />
<Compile Include="WorkGiver_RepairCustom.cs" />
Expand Down
6 changes: 3 additions & 3 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ public class Settings : ModSettings
{
public static int RepairThreshold = 100;

public static bool PrioritizeRottable = true;
public static bool PrioritizeRottable = true;

public static bool PrioritizeDeteriorating = true;
public static bool PrioritizeDeteriorating = true;

public static int DeterioratableMinHealthPercent = 35;
public static int DeterioratableMinHealthPercent = 35;

public override void ExposeData()
{
Expand Down
3 changes: 1 addition & 2 deletions Source/WorkGiver_HaulDeteriorating.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using RimWorld;
using System.Collections.Generic;
using UnityEngine;
using RimWorld;
using Verse;

namespace RWP
Expand Down
2 changes: 1 addition & 1 deletion Source/WorkGiver_HaulRottable.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RimWorld;
using System.Collections.Generic;
using RimWorld;
using Verse;

namespace RWP
Expand Down
Loading

0 comments on commit b274d59

Please sign in to comment.