public static Thing FindThingToHaul(Pawn p, Lord lord) { GatherItemsForShipCaravanUtility.neededItems.Clear(); List <TransferableOneWay> transferables = ((LordJob_FormAndSendCaravanShip)lord.LordJob).transferables; for (int i = 0; i < transferables.Count; i++) { TransferableOneWay transferableOneWay = transferables[i]; if (GatherItemsForShipCaravanUtility.CountLeftToTransfer(p, transferableOneWay, lord) > 0) { for (int j = 0; j < transferableOneWay.things.Count; j++) { GatherItemsForShipCaravanUtility.neededItems.Add(transferableOneWay.things[j]); } } } if (!GatherItemsForShipCaravanUtility.neededItems.Any <Thing>()) { return(null); } Thing result = GenClosest.ClosestThingReachable(p.Position, p.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.Touch, TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing x) => GatherItemsForShipCaravanUtility.neededItems.Contains(x) && p.CanReserve(x, 1, -1, null, false), null, 0, -1, false, RegionType.Set_Passable, false); GatherItemsForShipCaravanUtility.neededItems.Clear(); return(result); }
public static int CountLeftToTransfer(Pawn pawn, TransferableOneWay transferable, Lord lord) { if (transferable.CountToTransfer <= 0 || !transferable.HasAnyThing) { return(0); } int x = Mathf.Max(transferable.CountToTransfer - GatherItemsForShipCaravanUtility.TransferableCountHauledByOthers(pawn, transferable, lord), 0); return(x); }