Skip to content

Commit

Permalink
Further job assignment changes
Browse files Browse the repository at this point in the history
Haulers will now once again cut plants that are interferring with blueprint placement, but only if they're assigned to Plant Cutting. Otherwise, they will simply leave that blueprint untouched.
  • Loading branch information
DingoDjango committed Nov 24, 2017
1 parent f9f2576 commit 27b0034
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
Binary file modified Assemblies/Hand Me That Brick.dll
Binary file not shown.
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("2.7.18.0")]
[assembly: AssemblyFileVersion("2.7.18.0")]
[assembly: AssemblyVersion("2.8.18.0")]
[assembly: AssemblyFileVersion("2.8.18.0")]
41 changes: 25 additions & 16 deletions Source/Tools/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace HMTB
{
[StaticConstructorOnStartup]
public static class Utilities
{
private static WorkTypeDef PlantCutting = DefDatabase<WorkTypeDef>.GetNamed("PlantCutting");

public static bool AllowedHaulDistance(Pawn pawn, Thing t)
{
OpportunityDistance distance = Controller.OpportunisticMode.Value;
Expand Down Expand Up @@ -33,30 +36,36 @@ public static bool AllowedHaulDistance(Pawn pawn, Thing t)
return t.Position.DistanceTo(pawn.Position) <= maxSearchDistance;
}

/* RimWorld.GenConstruct.CanConstruct
* Tweaked vanilla code to disregard pawn skill */
public static bool CanDeliverResources(Thing t, Pawn p, Thing firstBlocking, bool forced = false)
/* RimWorld.GenConstruct.HandleBlockingThingJob
* Tweaked vanilla code to disregard construction and only cut plants if the hauler is a PlantCutter */
public static Job HandleBlockingThingJob(Thing firstBlocking, Pawn p, bool forced = false)
{
if (firstBlocking != null)
if (firstBlocking.def.category == ThingCategory.Plant)
{
return false;
if (p.workSettings.GetPriority(PlantCutting) > 0)
{
if (p.CanReserveAndReach(new LocalTargetInfo(firstBlocking), PathEndMode.ClosestTouch, p.NormalMaxDanger(), 1, -1, null, forced))
{
return new Job(JobDefOf.CutPlant, firstBlocking);
}
}
}

LocalTargetInfo target = t;

Danger maxDanger = !forced ? p.NormalMaxDanger() : Danger.Deadly;

if (!p.CanReserveAndReach(target, PathEndMode.Touch, maxDanger, 1, -1, null, forced))
else if (firstBlocking.def.category == ThingCategory.Item && firstBlocking.def.EverHaulable)
{
return false;
return HaulAIUtility.HaulAsideJobFor(p, firstBlocking);
}

if (t.IsBurning())
{
return false;
}
return null;
}

/* RimWorld.GenConstruct.CanConstruct
* Tweaked vanilla code to disregard pawn skill */
public static bool CanDeliverResources(Thing t, Pawn p, bool forced = false)
{
Danger maxDanger = !forced ? p.NormalMaxDanger() : Danger.Deadly;

return true;
return !t.IsBurning() && p.CanReserveAndReach(new LocalTargetInfo(t), PathEndMode.Touch, maxDanger, 1, -1, null, forced);
}
}
}
6 changes: 3 additions & 3 deletions Source/Work/WorkGiver_HaulDeliverResourcesToBlueprints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)

Thing firstBlockingThing = GenConstruct.FirstBlockingThing(blueprint, pawn);

if (firstBlockingThing != null && firstBlockingThing.def.category == ThingCategory.Item && firstBlockingThing.def.EverHaulable)
if (firstBlockingThing != null)
{
return HaulAIUtility.HaulAsideJobFor(pawn, firstBlockingThing);
return Utilities.HandleBlockingThingJob(firstBlockingThing, pawn, forced);
}

if (!Utilities.CanDeliverResources(blueprint, pawn, firstBlockingThing, forced))
if (!Utilities.CanDeliverResources(blueprint, pawn, forced))
{
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Work/WorkGiver_HaulDeliverResourcesToFrames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)

Thing firstBlockingThing = GenConstruct.FirstBlockingThing(frame, pawn);

if (firstBlockingThing != null && firstBlockingThing.def.category == ThingCategory.Item && firstBlockingThing.def.EverHaulable)
if (firstBlockingThing != null)
{
return HaulAIUtility.HaulAsideJobFor(pawn, firstBlockingThing);
return Utilities.HandleBlockingThingJob(firstBlockingThing, pawn, forced);
}

if (!Utilities.CanDeliverResources(frame, pawn, firstBlockingThing, forced))
if (!Utilities.CanDeliverResources(frame, pawn, forced))
{
return null;
}
Expand Down

0 comments on commit 27b0034

Please sign in to comment.