Okay so I went back to the first approach and tweaked it to check for defs and not for request groups.
Not elegant, probably slower than the previous solution. But at least it works!
Code Select
private Thing FindRockTarget(Pawn pawn)
{
Predicate<Thing> validator = delegate(Thing t)
{
Building building = t as Building;
if (!t.def.mineable)
{
return false;
}
return (building.Position.CanReach(pawn.Position, PathEndMode.Touch, TraverseMode.NoPassClosedDoors, Danger.Deadly) && HiveUtility.IsInHive(t));
};
Thing thingToReturn;
thingToReturn = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Sandstone")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
if (thingToReturn != null)
{
return GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Sandstone")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
}
thingToReturn = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Marble")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
if (thingToReturn != null)
{
return GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Marble")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
}
thingToReturn = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Granite")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
if (thingToReturn != null)
{
return GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Granite")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
}
thingToReturn = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Limestone")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
if (thingToReturn != null)
{
return GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Limestone")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
}
thingToReturn = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Slate")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
if (thingToReturn != null)
{
return GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Slate")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
}
thingToReturn = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(ThingDef.Named("Wall")), PathEndMode.Touch, TraverseParms.For(pawn), 30f, validator, null, -1);
return null;
}
Not elegant, probably slower than the previous solution. But at least it works!
![Grin ;D](https://ludeon.com/forums/Smileys/default/grin.gif)