Example #1
0
        public static Job HaulToCellStorageJob(Pawn p, Thing t, IntVec3 storeCell, bool fitInStoreCell)
        {
            Job       job       = new Job(JobDefOf.HaulToCell, t, storeCell);
            SlotGroup slotGroup = p.Map.haulDestinationManager.SlotGroupAt(storeCell);

            if (slotGroup != null)
            {
                Thing thing = p.Map.thingGrid.ThingAt(storeCell, t.def);
                if (thing != null)
                {
                    job.count = t.def.stackLimit;
                    if (fitInStoreCell)
                    {
                        job.count -= thing.stackCount;
                    }
                }
                else
                {
                    job.count = 99999;
                }
                int            num       = 0;
                float          statValue = p.GetStatValue(StatDefOf.CarryingCapacity, true);
                List <IntVec3> cellsList = slotGroup.CellsList;
                for (int i = 0; i < cellsList.Count; i++)
                {
                    if (StoreUtility.IsGoodStoreCell(cellsList[i], p.Map, t, p, p.Faction))
                    {
                        Thing thing2 = p.Map.thingGrid.ThingAt(cellsList[i], t.def);
                        if (thing2 != null && thing2 != t)
                        {
                            num += Mathf.Max(t.def.stackLimit - thing2.stackCount, 0);
                        }
                        else
                        {
                            num += t.def.stackLimit;
                        }
                        if (num >= job.count || (float)num >= statValue)
                        {
                            break;
                        }
                    }
                }
                job.count = Mathf.Min(job.count, num);
            }
            else
            {
                job.count = 99999;
            }
            job.haulOpportunisticDuplicates = true;
            job.haulMode = HaulMode.ToCellStorage;
            return(job);
        }
Example #2
0
        //See if closestSlot already contains Thing, if not double check the whole storage cell to see if there's an existing stack we want to force our Thing onto
        static void TryFindBestBetterStoreCellForWorker_Postfix(Thing t, Pawn carrier, Map map, Faction faction, SlotGroup slotGroup, ref IntVec3 closestSlot)
        {
            if (slotGroup == null || !slotGroup.parent.Accepts(t))
            {
                //So I don't think I needed this check in 1.0 but clearly this is needed in 1.1
                //HaulToStack.Instance.Logger.Message("slotgroup is null or doesn't accept item");
                return;
            }
            if (!closestSlot.InBounds(map))
            {
                //HaulToStack.Instance.Logger.Message("The original location picked to place item is out of bounds for an unknown reason");
                //HaulToStack.Instance.Logger.Message($"Thing {t.def.defName} Pawn: {carrier.Name}");
                //HaulToStack.Instance.Logger.Message($"Pawn: {carrier.Name}");
                return;
            }

            List <Thing> thingList = closestSlot.GetThingList(map);

            if (thingList.Exists(item => item.def.defName == t.def.defName))
            {
                return;
            }
            else
            {
                //HaulToStack.Instance.Logger.Trace("THE PLACE WE WERE GOING TO HAUL TO DOESN'T HAVE: " + t.def.defName);
                List <IntVec3> cellsList = slotGroup.CellsList;
                foreach (IntVec3 cell in cellsList)
                {
                    if (cell.InBounds(map))
                    {
                        //HaulToStack.Instance.Logger.Message("cell in the provided slotGroup is in bounds");
                        //return;
                        if (cell.GetThingList(map).Exists(item => item.def.defName == t.def.defName))
                        {
                            if (StoreUtility.IsGoodStoreCell(cell, map, t, carrier, faction))
                            {
                                //HaulToStack.Instance.Logger.Trace("FOUND AN EXISTING TILE WITH " + t.def.defName);
                                closestSlot = cell;
                                return;
                            }
                        }
                    }
                    //HaulToStack.Instance.Logger.Message("cell in the provided slotGroup is out of bounds");
                }

                //HaulToStack.Instance.Logger.Trace("TILE WITH EXISTING STACK OF " + t.def.defName + " DOES NOT EXIST, USING PREDETERMINED STACK LOCATION");
                //HaulToStack.Instance.Logger.Trace("----------------------------------------------------------------------------------------------------");
            }
        }
 private static bool CanBeStackTarget(Thing target, Thing thing, Pawn pawn = null)
 {
     return(thing != target &&
            target != null && thing != null &&
            target.CanStackWith(thing)
            // only move stuff to larger stacks
            // should stop situation with stacksize mods
            // where pawns keep going back and forth between stacks
            && target.stackCount >= thing.stackCount &&
            target.stackCount < target.def.stackLimit
            // is a good storage cell (no blockers, can be reserved, reachable, no fires, etc)
            && StoreUtility.IsGoodStoreCell(target.Position, target.Map, thing, pawn,
                                            pawn?.Faction ?? Faction.OfPlayer)
            // is going to stay around for a while
            && target.IsInValidBestStorage());
 }
Example #4
0
        public IntVec3 GetNextTrashCellFor(Thing thing, Pawn carrier = null)
        {
            if (thing != null && ShouldHaulTrash)
            {
                foreach (var cell in TrashCells())
                {
                    if (StoreUtility.IsGoodStoreCell(cell, map, thing, carrier, currentLord.faction))
                    {
                        return(cell);
                    }
                }
            }


            Log.Error("Found no spot to put trash. Jobs will be ended. Did the trash area overflow, or was trash cell calculation bad?");
            //this.trashCentre = IntVec3.Invalid;
            return(trashCentre);
        }
Example #5
0
        public bool TryFindBestStoreCellFor(Thing t, Pawn carrier, Map map, Faction faction, out IntVec3 foundCell)
        {
            List <Thing> facilities = facilityComp.LinkedFacilitiesListForReading;

            for (int f = 0; f < facilities.Count; f++)
            {
                foreach (IntVec3 c in GenAdj.CellsOccupiedBy(facilities[f]))
                {
                    if (StoreUtility.IsGoodStoreCell(c, map, t, carrier, faction))
                    {
                        foundCell = c;
                        return(true);
                    }
                }
            }
            foundCell = IntVec3.Invalid;
            return(false);
        }
Example #6
0
        public bool TryFindBestPlatformCell(Thing t, Pawn carrier, Map map, Faction faction, out IntVec3 foundCell)
        {
            List <Thing> facilities = facilityComp.LinkedFacilitiesListForReading;

            for (int f = 0; f < facilities.Count; f++)
            {
                if (facilities[f].GetSlotGroup() == null || !facilities[f].GetSlotGroup().Settings.AllowedToAccept(t))
                {
                    continue;
                }
                foreach (IntVec3 c in GenAdj.CellsOccupiedBy(facilities[f]))
                {
                    if (StoreUtility.IsGoodStoreCell(c, map, t, carrier, faction))
                    {
                        foundCell = c;
                        return(true);
                    }
                }
            }
            foundCell = IntVec3.Invalid;
            return(false);
        }
        public bool CanHaul(Pawn pawn, Thing target, Thing destination = null, bool logValues = false)
        {
            // check if target thing isn't already reserved and can be hauled
            var canHaulTarget = HaulAIUtility.PawnCanAutomaticallyHaul(pawn, target);

            if (!canHaulTarget)
            {
                return(false);
            }

            // default to true if no destination specified
            var canHaulToDestination = true;

            if (destination != null)
            {
                // check destination cell to make sure it's not blocked or reserved
                canHaulToDestination = StoreUtility.IsGoodStoreCell(destination.Position, pawn.Map, target, pawn,
                                                                    pawn.Faction);
            }

            LogMessage(() => $"Pawn {pawn} can haul {target}={canHaulTarget} to {destination}={canHaulToDestination}: {canHaulTarget && canHaulToDestination}");

            return(canHaulTarget && canHaulToDestination);
        }
Example #8
0
        private static void TryFindBestBetterStoreCellForWorker(
            Thing t,
            Pawn carrier,
            Map map,
            Faction faction,
            SlotGroup slotGroup,
            bool needAccurateResult,
            ref IntVec3 closestSlot,
            ref float closestDistSquared,
            ref StoragePriority foundPriority)
        {
            if (slotGroup == null || !slotGroup.parent.Accepts(t))
            {
                return;
            }
            IntVec3        intVec3   = t.PositionHeld;    //changed
            List <IntVec3> cellsList = slotGroup.CellsList;
            int            count     = cellsList.Count;
            int            num       = !needAccurateResult ? 0 : Mathf.FloorToInt((float)count * Rand.Range(0.005f, 0.018f));

            for (int index = 0; index < count; ++index)
            {
                IntVec3 c = cellsList[index];
                float   horizontalSquared = (float)(intVec3 - c).LengthHorizontalSquared;
                if ((double)horizontalSquared <= (double)closestDistSquared && StoreUtility.IsGoodStoreCell(c, map, t, carrier, faction))
                {
                    closestSlot        = c;
                    closestDistSquared = horizontalSquared;
                    foundPriority      = slotGroup.Settings.Priority;
                    if (index >= num)
                    {
                        break;
                    }
                }
            }
        }
        static void Postfix(ref Job __result, Pawn p, Thing t, IntVec3 storeCell, bool fitInStoreCell)
        {
            var temp = t.stackCount - AdditionalStorageSettings.CalculateStackLimit(t);

            if (temp > 0)
            {
                __result.count = temp;
                __result.haulOpportunisticDuplicates = false;
                Utilities.Debug($"clamp down hauling job count due to overlimit,job={__result},pawn={p},thing={t},count={__result.count}");
                return;
            }
            var slotGroup = p.Map.haulDestinationManager.SlotGroupAt(storeCell);

            if (slotGroup != null && AdditionalStorageSettings.TryGetLimit(slotGroup, out int limit))
            {
                limit = Mathf.Min(limit, t.def.stackLimit);
                int count     = 0;
                var statValue = p.GetStatValue(StatDefOf.CarryingCapacity, true);
                foreach (var cell in slotGroup.CellsList)
                {
                    if (StoreUtility.IsGoodStoreCell(cell, p.Map, t, p, p.Faction))
                    {
                        Thing thing2 = p.Map.thingGrid.ThingAt(cell, t.def);
                        count += thing2 != null?Mathf.Max(limit, -thing2.stackCount, 0) : limit;

                        if (count >= statValue)
                        {
                            count = (int)statValue;
                            break;
                        }
                    }
                }
                __result.count = limit;
                Utilities.Debug($"destination has a limit,recalculating job count,job={__result},pawn={p},thing={t},count={__result.count}");
            }
        }
Example #10
0
        public static bool TryFindBetterStoreCellInRange(Thing t, Pawn carrier, Map map, int range, StoragePriority currentPriority, Faction faction, out IntVec3 foundCell, bool needAccurateResult = true)
        {
            List <SlotGroup> allGroupsListInPriorityOrder = map.haulDestinationManager.AllGroupsListInPriorityOrder;

            if (allGroupsListInPriorityOrder.Count == 0)
            {
                foundCell = IntVec3.Invalid;
                return(false);
            }
            IntVec3         a = (t.MapHeld == null) ? carrier.PositionHeld : t.PositionHeld;
            StoragePriority storagePriority = currentPriority;
            float           num             = Mathf.Pow(range, 2);
            IntVec3         intVec          = default(IntVec3);
            bool            flag            = false;
            int             count           = allGroupsListInPriorityOrder.Count;

            for (int i = 0; i < count; i++)
            {
                SlotGroup       slotGroup = allGroupsListInPriorityOrder[i];
                StoragePriority priority  = slotGroup.Settings.Priority;
                if (priority < storagePriority || priority <= currentPriority)
                {
                    break;
                }
                if (slotGroup.Settings.AllowedToAccept(t))
                {
                    List <IntVec3> cellsList = slotGroup.CellsList;
                    int            count2    = cellsList.Count;
                    int            num2;
                    if (needAccurateResult)
                    {
                        num2 = Mathf.FloorToInt(count2 * Rand.Range(0.005f, 0.018f));
                    }
                    else
                    {
                        num2 = 0;
                    }
                    for (int j = 0; j < count2; j++)
                    {
                        IntVec3 intVec2 = cellsList[j];
                        float   lengthHorizontalSquared = (a - intVec2).LengthHorizontalSquared;
                        if (lengthHorizontalSquared <= num)
                        {
                            if (StoreUtility.IsGoodStoreCell(intVec2, map, t, carrier, faction))
                            {
                                flag            = true;
                                intVec          = intVec2;
                                num             = lengthHorizontalSquared;
                                storagePriority = priority;
                                if (j >= num2)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (!flag)
            {
                foundCell = IntVec3.Invalid;
                return(false);
            }
            foundCell = intVec;
            return(true);
        }
Example #11
0
        //  It might be possible to do this via Transpiler, but it's harder, so we do it this way.
        //      static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
        public static bool Prefix(out Job __result, Pawn p, Thing t, IntVec3 storeCell, bool fitInStoreCell)
        {
            Utils.Err(HaulToCellStorageJob, "Job request for " + t.stackCount + t.ToString() + " by pawn " + p.ToString() +
                      " to " + storeCell.ToString());
            SlotGroup slotGroup = p.Map.haulDestinationManager.SlotGroupAt(storeCell);

            if (slotGroup == null || !(slotGroup?.parent is ThingWithComps) ||
                (slotGroup.parent as ThingWithComps).TryGetComp <CompDeepStorage>() == null)
            {
                // Not going to Deep Storage
                __result = null;
                return(true); // HaulToCellStorageJob will handle it
            }
            // Create our own job for hauling to Deep_Storage units...
            // Another opportunity to put our own JobDef here:
            //   new Job(DefDatabase<JobDef>.GetNamed("LWM_HaulToDeepStorage"), t, storeCell, map);, etc
            Job job = new Job(JobDefOf.HaulToCell, t, storeCell);

            job.haulOpportunisticDuplicates = true;
            job.haulMode = HaulMode.ToCellStorage;

            __result = job;

            if (t.def.stackLimit <= 1)
            {
                job.count = 1;
                Utils.Err(HaulToCellStorageJob, "haulMaxNumToCellJob: " + t.ToString() + ": stackLimit<=1 so job.count=1");
                return(false);
            }
            // we have to count :p
            // Really???  statValue is the carrying capacity of the Pawn
            float statValue = p.GetStatValue(StatDefOf.CarryingCapacity, true);

            job.count = 0;

            var maxStacks = ((ThingWithComps)slotGroup.parent).GetComp <CompDeepStorage>().maxNumberStacks;

            Utils.Err(HaulToCellStorageJob, p.ToString() + " taking " + t.ToString() + ", count: " + t.stackCount);
            var howManyStacks = 0;
            //fill job.count with space in the direct storeCell:
            List <Thing> stuffHere = p.Map.thingGrid.ThingsListAt(storeCell);

            for (int i = 0; i < stuffHere.Count; i++) // thing list at storeCell
            {
                Thing thing2 = stuffHere[i];
                // We look thru for stacks of storeable things; if they match our thing t,
                //   we see how many we can carry there!
                if (thing2.def.EverStorable(false))
                {
                    Utils.Warn(HaulToCellStorageJob, "... already have a stack here of " + thing2.stackCount + " of " + thing2.ToString());
                    howManyStacks++;
                    if (thing2.def == t.def)
                    {
                        job.count += thing2.def.stackLimit - thing2.stackCount;
                        Utils.Warn(HaulToCellStorageJob, "... count is now " + job.count);
                        if ((float)job.count >= statValue || job.count >= t.def.stackLimit)
                        {
                            job.count = Math.Min(t.def.stackLimit, job.count);
                            Utils.Warn(HaulToCellStorageJob, "Final count: " + job.count + " (can carry: " + statValue + ")");
                            return(false);
                        }
                    }
                } // if storeable
            }     // thing list at storeCell

            if (howManyStacks < maxStacks || job.count >= t.def.stackLimit)
            {
                // There's room for a whole stack right here!
                job.count = t.def.stackLimit;
                Utils.Warn(HaulToCellStorageJob, "Room for whole stack! " + howManyStacks + "/" + maxStacks);
                return(false);
            }
            if (fitInStoreCell)   // don't look if pawn can put stuff anywhere else
            {
                return(false);
            }
            //  If !fitInStoreCell, we look in the other cells of the storagearea to see if we can put some there:
            //     (personally, I'd be okay if my pawns also tried NEARBY storage areas,
            //      but that's getting really complicted.)
            Utils.Warn(HaulToCellStorageJob, "Continuing to search for space in nearby cells...");
            List <IntVec3> cellsList = slotGroup.CellsList;

            for (int i = 0; i < cellsList.Count; i++)
            {
                IntVec3 c = cellsList[i];
                if (c == storeCell)
                {
                    continue;
                }
                if (!StoreUtility.IsGoodStoreCell(c, p.Map, t, p, p.Faction))
                {
                    continue;
                }
                //repeat above counting of space in the current store cell:
                stuffHere     = p.Map.thingGrid.ThingsListAt(c);
                howManyStacks = 0;
                for (int j = 0; j < stuffHere.Count; j++)
                {
                    Thing thing2 = stuffHere[j];
                    // We look thru for stacks of storeable things; if they match our thing t,
                    //   we see how many we can carry there!
                    if (thing2.def.EverStorable(false))
                    {
                        Utils.Warn(HaulToCellStorageJob, "... already have a stack here of " + thing2.stackCount + " of " + thing2.ToString());
                        howManyStacks++;
                        if (thing2.def == t.def)
                        {
                            job.count += thing2.def.stackLimit - thing2.stackCount;
                            Utils.Warn(HaulToCellStorageJob, "... count is now " + job.count);
                            if ((float)job.count >= statValue || job.count >= t.def.stackLimit)
                            {
                                job.count = Math.Min(t.def.stackLimit, job.count);
                                Utils.Warn(HaulToCellStorageJob, "Final count: " + job.count + " (can carry: " + statValue + ")");
                                return(false);
                            }
                        }
                    } // if storeable
                }     // done looking at all stuff in c
                // So...how many stacks WERE there in c?
                if (howManyStacks < maxStacks)
                {
                    // There's another stack's worth of room!
                    Utils.Warn(HaulToCellStorageJob, "Room for whole stack! " + howManyStacks + "/" + maxStacks);
                    job.count = t.def.stackLimit;
                    return(false);
                }
            } // looking at all cells in storeage area
              // Nowhere else to look, no other way to store anything we pick up.
              // Count stays at job.count
            Utils.Warn(HaulToCellStorageJob, "Final count: " + job.count);
            return(false);
        }
Example #12
0
        public static bool TryFindBestBetterStoreCellFor(Thing t, Pawn carrier, Map map,
                                                         StoragePriority currentPriority, Faction faction,
                                                         out IntVec3 foundCell, bool needAccurateResult = true,
                                                         bool mustBeColder = false, bool mustBeRoofed = true)
        {
            List <SlotGroup> allGroupsListInPriorityOrder = map.slotGroupManager.AllGroupsListInPriorityOrder;

            if (allGroupsListInPriorityOrder.Count == 0)
            {
                foundCell = IntVec3.Invalid;
                return(false);
            }

            var searchSlots = new List <SlotGroup>();

            searchSlots = allGroupsListInPriorityOrder;

            IntVec3         a = (t.MapHeld == null) ? carrier.PositionHeld : t.PositionHeld;
            StoragePriority storagePriority = currentPriority;
            float           maxDist         = 2.14748365E+09f;
            IntVec3         bestCell        = default(IntVec3);
            IntVec3         matchingCell    = IntVec3.Invalid;
            bool            cellDetected    = false;
            int             count           = searchSlots.Count;

            for (int i = 0; i < count; i++)
            {
                SlotGroup       slotGroup = searchSlots[i];
                StoragePriority priority  = slotGroup.Settings.Priority;
                if (priority < storagePriority || priority <= currentPriority)
                {
                    break;
                }

                if (t.Map != searchSlots[i].parent.Map)
                {
                    continue;
                }

                if (slotGroup.Settings.AllowedToAccept(t))
                {
                    var cells = slotGroup.CellsList;
                    IEnumerable <IntVec3> cellsList = cells.InRandomOrder();

                    int numSlotsToSearch;
                    if (needAccurateResult)
                    {
                        numSlotsToSearch = Mathf.FloorToInt(cells.Count * Rand.Range(0.012f, 0.024f));
                    }
                    else
                    {
                        numSlotsToSearch = 0;
                    }
                    foreach (IntVec3 cell in cellsList)
                    {
                        if (mustBeColder && !IsColderEnoughAt(cell, t, map))
                        {
                            continue;
                        }

                        if (mustBeRoofed && cell.GetRoof(map) == null)
                        {
                            continue;
                        }

                        float lengthHorizontalSquared = (a - cell).LengthHorizontalSquared;
                        if (lengthHorizontalSquared <= maxDist)
                        {
                            if (StoreUtility.IsGoodStoreCell(cell, map, t, carrier, faction))
                            {
                                if (ContainsPartialThingWithSameDef(t, cell, map))
                                {
                                    matchingCell = cell;
                                }

                                cellDetected    = true;
                                bestCell        = cell;
                                maxDist         = lengthHorizontalSquared;
                                storagePriority = priority;



                                numSlotsToSearch--;

                                if (numSlotsToSearch <= 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (!cellDetected)
            {
                foundCell = IntVec3.Invalid;

                return(false);
            }

            if (matchingCell.IsValid)
            {
                foundCell = matchingCell;
            }
            else
            {
                foundCell = bestCell;
            }


            return(true);
        }
        static bool Prefix(ref bool __result, Thing t, Pawn carrier, Map map, Faction faction, out IntVec3 foundCell)
        {
            foundCell = IntVec3.Invalid;
            if (carrier == null || faction == null || faction != Faction.OfPlayer || t.SpawnedOrAnyParentSpawned)
            {
                return(true);
            }

            var bill = carrier.CurJob.bill as Bill_Production;

            if (bill == null)
            {
                return(true);
            }

            if (bill.GetStoreMode() != BillStoreModeDefOf.BestStockpile)
            {
                return(true);
            }

            var extendedBillData = Main.Instance.GetExtendedBillDataStorage().GetExtendedDataFor(bill);

            if (extendedBillData == null)
            {
                return(true);
            }

            if (!extendedBillData.UsesTakeToStockpile())
            {
                return(true);
            }

            var stockPile = extendedBillData.GetTakeToStockpile();

            if (!stockPile.settings.AllowedToAccept(t))
            {
                return(true);
            }

            var   cellsList         = stockPile.GetSlotGroup().CellsList;
            var   cellCount         = cellsList.Count;
            var   searchAccuracy    = Mathf.FloorToInt(cellCount * 0.012f);
            var   startingLocation  = carrier.PositionHeld;
            float bestDistanceFound = int.MaxValue;
            var   foundGoodCell     = false;

            for (var j = 0; j < cellCount; j++)
            {
                IntVec3 possibleDestination   = cellsList[j];
                float   distanceToDestination = (startingLocation - possibleDestination).LengthHorizontalSquared;

                if (!(distanceToDestination <= bestDistanceFound))
                {
                    continue;
                }

                if (!StoreUtility.IsGoodStoreCell(possibleDestination, map, t, carrier, faction))
                {
                    continue;
                }

                foundGoodCell = true;
                foundCell     = possibleDestination;
                if (j >= searchAccuracy)
                {
                    break;
                }
                bestDistanceFound = distanceToDestination;
            }

            __result = foundGoodCell;
            return(!foundGoodCell);
        }
Example #14
0
		public static Job TestHaulMaxNumToCellJob(Pawn p, Thing t, IntVec3 storeCell, bool fitInStoreCell)
		{
            bool debug = false;

            var startTime = Time.timeSinceLevelLoad;
            var endTime = 0f;


            var job = new Job(JobDefOf.HaulToCell, t, storeCell);
			var slotGroup = p.Map.slotGroupManager.SlotGroupAt(storeCell);
			if (slotGroup != null)
			{
				var thing = p.Map.thingGrid.ThingAt(storeCell, t.def);
				if (thing != null)
				{
					if (!StoreUtility.IsGoodStoreCell(storeCell, p.Map, t, p, p.Faction))
					{
						return null;
					}

					job.count = t.def.stackLimit;
					if (fitInStoreCell)
					{
						job.count -= thing.stackCount;
					}
				}
				else
				{
					job.count = 99999;
				}
				int num = 0;
				var statValue = p.GetStatValue(StatDefOf.CarryingCapacity, true);
				List<IntVec3> cellsList = slotGroup.CellsList;
				for (int i = 0; i < cellsList.Count; i++)
				{
					if (StoreUtility.IsGoodStoreCell(cellsList[i], p.Map, t, p, p.Faction))
					{

						if (!cellsList[i].InAllowedArea(p))
						{
							continue;
						}

						if (!p.CanReach(cellsList[i], PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn))
						{
							continue;
						}

						var thing2 = p.Map.thingGrid.ThingAt(cellsList[i], t.def);
						if (thing2 != null && thing2 != t)
						{
							num += Mathf.Max(t.def.stackLimit - thing2.stackCount, 0);
						}
						else
						{
							num += t.def.stackLimit;
						}
						if (num >= job.count || num >= statValue)
						{
							break;
						}
					}
				}
				job.count = Mathf.Min(job.count, num);

				if (job.count == 0)
				{



                    endTime = Time.timeSinceLevelLoad;

                    if (debug) Log.Message("TestHaulMaxNumToCellJob spent " + (endTime - startTime).ToString("0.0000") + " seconds making a job to haul " + t.Label + " but got a count of 0.");


                    return null;
				}
			}
			else
			{
				job.count = 99999;
			}
			job.haulOpportunisticDuplicates = true;
			job.haulMode = HaulMode.ToCellStorage;


            endTime = Time.timeSinceLevelLoad;

            if (debug) Log.Message("TestHaulMaxNumToCellJob made a job to haul " + t.Label + " in " + (endTime - startTime).ToString("0.0000") + " seconds.");



            return job;
		}
Example #15
0
        // Token: 0x06000009 RID: 9 RVA: 0x0000266C File Offset: 0x0000086C
        public static bool TryFindBetterStoreCellInRange(Thing t, Pawn carrier, Map map, int range,
                                                         StoragePriority currentPriority, Faction faction, out IntVec3 foundCell, bool needAccurateResult = true)
        {
            var  allGroupsListInPriorityOrder = map.haulDestinationManager.AllGroupsListInPriorityOrder;
            bool result;

            if (allGroupsListInPriorityOrder.Count == 0)
            {
                foundCell = IntVec3.Invalid;
                result    = false;
            }
            else
            {
                var a = t.MapHeld == null ? carrier.PositionHeld : t.PositionHeld;
                var storagePriority = currentPriority;
                var num             = Mathf.Pow(range, 2f);
                var intVec          = default(IntVec3);
                var b     = false;
                var count = allGroupsListInPriorityOrder.Count;
                for (var i = 0; i < count; i++)
                {
                    var slotGroup = allGroupsListInPriorityOrder[i];
                    var priority  = slotGroup.Settings.Priority;
                    if (priority < storagePriority || priority <= currentPriority)
                    {
                        break;
                    }

                    if (!slotGroup.Settings.AllowedToAccept(t))
                    {
                        continue;
                    }

                    var cellsList = slotGroup.CellsList;
                    var count2    = cellsList.Count;
                    var num2      = needAccurateResult ? Mathf.FloorToInt(count2 * Rand.Range(0.005f, 0.018f)) : 0;

                    for (var j = 0; j < count2; j++)
                    {
                        var intVec2 = cellsList[j];
                        var num3    = (float)(a - intVec2).LengthHorizontalSquared;
                        if (!(num3 <= num))
                        {
                            continue;
                        }

                        if (!StoreUtility.IsGoodStoreCell(intVec2, map, t, carrier, faction))
                        {
                            continue;
                        }

                        b               = true;
                        intVec          = intVec2;
                        num             = num3;
                        storagePriority = priority;
                        if (j >= num2)
                        {
                            break;
                        }
                    }
                }

                if (!b)
                {
                    foundCell = IntVec3.Invalid;
                    result    = false;
                }
                else
                {
                    foundCell = intVec;
                    result    = true;
                }
            }

            return(result);
        }
 public static bool Prefix(ref IntVec3 __result, Pawn pawn, Pawn downedPawn)
 {
     __result = CellFinderExtended.RandomClosewalkCellNear(pawn.mindState.duty.focusSecond.Cell, pawn.Map, pawn.kindDef, 6, (IntVec3 x) => x.Standable(pawn.Map) && StoreUtility.IsGoodStoreCell(x, pawn.Map, downedPawn, pawn, pawn.Faction));
     return(false);
 }