Skip to content

Commit

Permalink
Respect null pawns in patch to FindPath; comment out dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Sep 21, 2019
1 parent aee778c commit e70be58
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
Binary file modified Assemblies/ZombieLand.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Source/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ public static class PathFinder_FindPath_Patch
// by returning 0 - currently disabled because it does cost too much
static int GetZombieCosts(Pawn pawn, int idx)
{
if (pawn == null) return 0;
if (Tools.ShouldAvoidZombies(pawn) == false) return 0;

var map = pawn.Map;
Expand Down
40 changes: 14 additions & 26 deletions Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Xml;
using UnityEngine;
using Verse;
using Verse.AI;
using Verse.Sound;

namespace ZombieLand
Expand Down Expand Up @@ -280,7 +279,15 @@ public static bool CanDoctor(this Pawn pawn, bool rightNow = false)
return pawn.workSettings.WorkIsActive(WorkTypeDefOf.Doctor) && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);
}

public static List<Zombie> NearByZombiesSorted(Pawn pawn, IntVec3 center, int radius, bool ignoreDowned, bool sortByDistance, bool usePathing)
/*public static bool CanPathTo(this Zombie zombie, IntVec3 cell)
{
var path = zombie.Map.pathFinder.FindPath(zombie.Position, cell, zombie, PathEndMode.InteractionCell);
var result = path != PawnPath.NotFound;
path.ReleaseToPool();
return result;
}*/

/*public static List<Zombie> NearByZombiesSorted(Pawn pawn, IntVec3 center, int radius, bool ignoreDowned, bool sortByDistance, bool usePathing)
{
var maxDistance = radius * radius;
var map = pawn.Map;
Expand All @@ -295,22 +302,7 @@ bool regionValidator(Region from, Region to)
{
if (to.Allows(tp, false) == false)
return false;

return true;

/*if (to.CellCount == 1)
return true;
var minX = to.extentsClose.minX;
var minZ = to.extentsClose.minZ;
var maxX = to.extentsClose.maxX;
var maxZ = to.extentsClose.maxZ;
if (distanceSquared(minX, minZ) <= maxDistance) return true;
if (distanceSquared(maxX, minZ) <= maxDistance) return true;
if (distanceSquared(minX, maxZ) <= maxDistance) return true;
if (distanceSquared(maxX, maxZ) <= maxDistance) return true;
return false;*/
}
bool regionProcessor(Region r)
Expand All @@ -331,20 +323,16 @@ bool regionProcessor(Region r)
zombies.Sort(new DistanceComparer(center));
if (usePathing)
{
var pather = map.pathFinder;
_ = zombies.RemoveAll(zombie => pather.FindPath(zombie.Position, center, zombie, PathEndMode.InteractionCell) == PawnPath.NotFound);
}
_ = zombies.RemoveAll(zombie => zombie.CanPathTo(center) == false);
return zombies;
}
}*/

public static Zombie NearestZombie(Pawn pawn, IntVec3 cell, int radius, bool ignoreDowned = false)
/*public static Zombie NearestZombie(Pawn pawn, IntVec3 cell, int radius, bool ignoreDowned = false)
{
var zombies = NearByZombiesSorted(pawn, cell, radius, ignoreDowned, true, false);
var pather = pawn.Map.pathFinder;
return zombies.FirstOrDefault(zombie => pather.FindPath(zombie.Position, cell, zombie, PathEndMode.InteractionCell) != PawnPath.NotFound);
}
return zombies.FirstOrDefault(zombie => zombie.CanPathTo(cell);
}*/

/*public static IntVec3 ZombiesNearby(Pawn pawn, IntVec3 destination, bool ignoreDowned = false)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/WorkGivers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
var avoidGrid = tickManager.avoidGrid;
var path = pawn.Map.pathFinder.FindPath(pawn.Position, t, pawn, PathEndMode.ClosestTouch);
var shouldAvoid = path.NodesReversed.Any(cell => avoidGrid.ShouldAvoid(map, cell));
path.Dispose();
path.ReleaseToPool();
if (shouldAvoid)
return false;
}
Expand Down

0 comments on commit e70be58

Please sign in to comment.