Skip to content

Commit

Permalink
Allow pawns to construct building if they only enclose themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
dhultgren committed Aug 25, 2020
1 parent 515376c commit 4186c45
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 30 deletions.
4 changes: 3 additions & 1 deletion Source/SmarterConstruction/Core/ClosedRegionDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public static EncloseThingsResult WouldEncloseThings(Thing target, Pawn ___pawn)
var enclosedPlayerPawns = enclosedThings.Where(t => t is Pawn && t.Faction != null && t.Faction.IsPlayer).ToList();

retValue.EnclosesRegion = true;
retValue.EnclosesThings = enclosedUnacceptable.Count > 0 || enclosedPlayerPawns.Count > 0;
retValue.EnclosesThings = enclosedUnacceptable.Count > 0 || enclosedPlayerPawns.Count(p => p != ___pawn) > 0;
retValue.EnclosesSelf = enclosedPlayerPawns.Any(p => p == ___pawn);
}
WouldEncloseThingsCache[target] = new CachedEncloseThingsResult
{
Expand Down Expand Up @@ -121,5 +122,6 @@ public class EncloseThingsResult
{
public bool EnclosesRegion { get; set; }
public bool EnclosesThings { get; set; }
public bool EnclosesSelf { get; set; }
}
}
2 changes: 1 addition & 1 deletion Source/SmarterConstruction/DebugUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void DebugLog(string text)

public static void VerboseLog(string text)
{
Log.Message(Find.TickManager.TicksGame + ": " + text, true);
//Log.Message(Find.TickManager.TicksGame + ": " + text, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ public static bool EndJobIfEnclosing(Frame target, Pawn pawn)
pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
return true;
}
//DebugUtils.VerboseLog(pawn.Label + " finished " + target.Label + " on coordinates " + target.Position);
DebugUtils.VerboseLog(pawn.Label + " finished " + target.Label + " on coordinates " + target.Position);

var pawnsAtLocation = target.Position.GetThingList(target.Map)
.Where(t => t is Pawn && t.Faction != null && t.Faction.IsPlayer)
.ToList();
if (wouldEnclose.EnclosesSelf) pawnsAtLocation.Add(pawn);
if (pawnsAtLocation.Count > 0 && wouldEnclose.EnclosesRegion)
{
// move pawn to a safe location to avoid random movement
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ public class WorkGiver_ConstructFinishFrames_JobOnThing
{
public static void Postfix(Pawn pawn, Thing t, ref Job __result, bool forced, WorkGiver_ConstructFinishFrames __instance)
{
if (t?.def?.entityDefToBuild?.passability == Traversability.Impassable
&& ClosedRegionDetector.WouldEncloseThings(t, pawn).EnclosesThings
&& !forced)
if (t?.def?.entityDefToBuild?.passability == Traversability.Impassable && !forced)
{
__result = null;
var encloseData = ClosedRegionDetector.WouldEncloseThings(t, pawn);
if (encloseData.EnclosesSelf)
{
DebugUtils.VerboseLog($"Allowing self enclosing job on {t.Position} for pawn {pawn.Label} expecting a teleport.");
}
if (encloseData.EnclosesThings)
{
__result = null;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/SmarterConstruction/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.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
1 change: 0 additions & 1 deletion Source/SmarterConstruction/SmarterConstruction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<ItemGroup>
<Compile Include="DebugUtils.cs" />
<Compile Include="Patches\Patch_JobDriver_MakeNewToils.cs" />
<Compile Include="Patches\Patch_WorkGiver_ConstructDeliverResources.cs" />
<Compile Include="Patches\Patch_WorkGiver_Scanner_GetPriority.cs" />
<Compile Include="Patches\Patch_WorkGiver_Scanner_Prioritized.cs" />
<Compile Include="Patches\WorkGiver_ConstructFinishFrames_JobOnThing.cs" />
Expand Down

0 comments on commit 4186c45

Please sign in to comment.