Exemplo n.º 1
0
        public static bool IsValidStorageFor(this IntVec3 c, Map map, Thing storable)
        {
            if (!StoreUtility.NoStorageBlockersIn(c, map, storable))
            {
                return(false);
            }
            SlotGroup slotGroup = c.GetSlotGroup(map);

            return(slotGroup != null && slotGroup.parent.Accepts(storable));
        }
Exemplo n.º 2
0
 public void Notify_SlotGroupChanged(SlotGroup sg)
 {
     if (sg.CellsList != null)
     {
         for (int i = 0; i < sg.CellsList.Count; i++)
         {
             RecalcAllInCell(sg.CellsList[i]);
         }
     }
 }
Exemplo n.º 3
0
        public static bool IsInAnyStorage(this Thing t)
        {
            if (!t.Spawned)
            {
                return(false);
            }
            SlotGroup slotGroup = t.Map.slotGroupManager.SlotGroupAt(t.Position);

            return(slotGroup != null);
        }
Exemplo n.º 4
0
        public static bool IsInValidStorage(this Thing t)
        {
            if (!t.Spawned)
            {
                return(false);
            }
            SlotGroup slotGroup = t.GetSlotGroup();

            return(slotGroup != null && slotGroup.Settings.AllowedToAccept(t));
        }
Exemplo n.º 5
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.stackCount == t.def.stackLimit)
            {
                return(null);
            }
            if (!HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t, forced))
            {
                return(null);
            }
            SlotGroup slotGroup = t.GetSlotGroup();

            if (slotGroup == null)
            {
                return(null);
            }
            LocalTargetInfo target = t.Position;

            if (!pawn.CanReserve(target, 1, -1, null, forced))
            {
                return(null);
            }
            foreach (Thing current in slotGroup.HeldThings)
            {
                if (current != t)
                {
                    if (current.def == t.def)
                    {
                        if (forced || current.stackCount >= t.stackCount)
                        {
                            if (current.stackCount < current.def.stackLimit)
                            {
                                target = current.Position;
                                if (pawn.CanReserve(target, 1, -1, null, forced))
                                {
                                    if (pawn.CanReserve(current, 1, -1, null, false))
                                    {
                                        if (current.Position.IsValidStorageFor(current.Map, t))
                                        {
                                            return(new Job(JobDefOf.HaulToCell, t, current.Position)
                                            {
                                                count = Mathf.Min(current.def.stackLimit - current.stackCount, t.stackCount),
                                                haulMode = HaulMode.ToCellStorage
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            JobFailReason.Is("NoMergeTarget".Translate(), null);
            return(null);
        }
Exemplo n.º 6
0
        public static bool IsInValidBestStorage(this Thing t)
        {
            if (!t.Spawned)
            {
                return(false);
            }
            SlotGroup slotGroup = t.GetSlotGroup();
            IntVec3   intVec;

            return(slotGroup != null && slotGroup.Settings.AllowedToAccept(t) && !StoreUtility.TryFindBestBetterStoreCellFor(t, null, t.Map, slotGroup.Settings.Priority, Faction.OfPlayer, out intVec, false));
        }
Exemplo n.º 7
0
        public static float CellBeauty(IntVec3 c, Map map, List <Thing> countedThings = null)
        {
            float        num  = 0f;
            float        num2 = 0f;
            bool         flag = false;
            List <Thing> list = map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (BeautyUtility.BeautyRelevant(thing.def.category))
                {
                    if (countedThings != null)
                    {
                        if (countedThings.Contains(thing))
                        {
                            goto IL_EE;
                        }
                        countedThings.Add(thing);
                    }
                    SlotGroup slotGroup = thing.GetSlotGroup();
                    if (slotGroup == null || !slotGroup.parent.IgnoreStoredThingsBeauty)
                    {
                        float num3 = thing.GetStatValue(StatDefOf.Beauty, true);
                        if (thing is Filth && !map.roofGrid.Roofed(c))
                        {
                            num3 *= 0.3f;
                        }
                        if (thing.def.Fillage == FillCategory.Full)
                        {
                            flag  = true;
                            num2 += num3;
                        }
                        else
                        {
                            num += num3;
                        }
                    }
                }
                IL_EE :;
            }
            float result;

            if (flag)
            {
                result = num2;
            }
            else
            {
                num   += map.terrainGrid.TerrainAt(c).GetStatValueAbstract(StatDefOf.Beauty, null);
                result = num;
            }
            return(result);
        }
Exemplo n.º 8
0
 public override void ExposeData()
 {
     base.ExposeData();
     Scribe_Deep.Look <StorageSettings>(ref this.settings, "settings", new object[1]
     {
         this
     });
     if (Scribe.mode == LoadSaveMode.PostLoadInit)
     {
         this.slotGroup = new SlotGroup(this);
     }
 }
Exemplo n.º 9
0
        public void Notify_SlotGroupChanged(SlotGroup sg)
        {
            List <IntVec3> cellsList = sg.CellsList;

            if (cellsList != null)
            {
                for (int i = 0; i < cellsList.Count; i++)
                {
                    RecalcAllInCell(cellsList[i]);
                }
            }
        }
        public static IEnumerable <IntVec3> EmptyCells(this RimWorld.SlotGroup slotGroup)
        {
            List <IntVec3> cellsList = slotGroup.CellsList;

            for (int i = 0; i < cellsList.Count; i++)
            {
                List <Thing> thingsList = slotGroup.parent.Map.thingGrid.ThingsListAtFast(cellsList[i]);
                if (thingsList.Count == 0 || (thingsList.Count == 1 && thingsList[0] == slotGroup.parent))                      //If thingsList is null, don't return true ...
                {
                    yield return(cellsList[i]);
                }
            }
        }
Exemplo n.º 11
0
        public static bool IsValidStorageFor(this IntVec3 c, Map map, Thing storable)
        {
            if (!StoreUtility.NoStorageBlockersIn(c, map, storable))
            {
                return(false);
            }
            SlotGroup slotGroup = c.GetSlotGroup(map);

            if (slotGroup != null && slotGroup.Settings.AllowedToAccept(storable))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 12
0
        public static bool IsValidStorageFor(this IntVec3 c, Map map, Thing storable)
        {
            if (!NoStorageBlockersIn(c, map, storable))
            {
                return(false);
            }
            SlotGroup slotGroup = c.GetSlotGroup(map);

            if (slotGroup == null || !slotGroup.parent.Accepts(storable))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 13
0
        public static float CellBeauty(IntVec3 c, Map map, List <Thing> countedThings = null)
        {
            float        num  = 0f;
            float        num2 = 0f;
            bool         flag = false;
            List <Thing> list = map.thingGrid.ThingsListAt(c);
            int          i    = 0;

            while (i < list.Count)
            {
                Thing thing = list[i];
                if (countedThings == null)
                {
                    goto IL_4D;
                }
                if (!countedThings.Contains(thing))
                {
                    countedThings.Add(thing);
                    goto IL_4D;
                }
IL_CC:
                i++;
                continue;
IL_4D:
                SlotGroup slotGroup = thing.GetSlotGroup();
                if (slotGroup != null && slotGroup.parent.IgnoreStoredThingsBeauty)
                {
                    goto IL_CC;
                }
                float num3 = thing.GetStatValue(StatDefOf.Beauty, true);
                if (thing is Filth && !map.roofGrid.Roofed(c))
                {
                    num3 *= 0.3f;
                }
                if (thing.def.Fillage == FillCategory.Full)
                {
                    flag  = true;
                    num2 += num3;
                    goto IL_CC;
                }
                num += num3;
                goto IL_CC;
            }
            if (flag)
            {
                return(num2);
            }
            return(num + map.terrainGrid.TerrainAt(c).GetStatValueAbstract(StatDefOf.Beauty, null));
        }
Exemplo n.º 14
0
        private IEnumerable <Widgets.DropdownMenuElement <Zone_Stockpile> > GenerateStockpileInclusion()
        {
            yield return(new Widgets.DropdownMenuElement <Zone_Stockpile>
            {
                option = new FloatMenuOption("IncludeFromAll".Translate(), delegate()
                {
                    this.bill.includeFromZone = null;
                }, MenuOptionPriority.Default, null, null, 0f, null, null),
                payload = null
            });

            List <SlotGroup> groupList = this.bill.billStack.billGiver.Map.haulDestinationManager.AllGroupsListInPriorityOrder;
            int groupCount             = groupList.Count;

            for (int i = 0; i < groupCount; i++)
            {
                SlotGroup      group     = groupList[i];
                Zone_Stockpile stockpile = group.parent as Zone_Stockpile;
                if (stockpile != null)
                {
                    if (!this.bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(this.bill, stockpile))
                    {
                        yield return(new Widgets.DropdownMenuElement <Zone_Stockpile>
                        {
                            option = new FloatMenuOption(string.Format("{0} ({1})", "IncludeSpecific".Translate(new object[]
                            {
                                group.parent.SlotYielderLabel()
                            }), "IncompatibleLower".Translate()), null, MenuOptionPriority.Default, null, null, 0f, null, null),
                            payload = stockpile
                        });
                    }
                    else
                    {
                        yield return(new Widgets.DropdownMenuElement <Zone_Stockpile>
                        {
                            option = new FloatMenuOption("IncludeSpecific".Translate(new object[]
                            {
                                group.parent.SlotYielderLabel()
                            }), delegate()
                            {
                                this.bill.includeFromZone = stockpile;
                            }, MenuOptionPriority.Default, null, null, 0f, null, null),
                            payload = stockpile
                        });
                    }
                }
            }
            yield break;
        }
 public void SetCellFor(IntVec3 c, SlotGroup group)
 {
     if (this.SlotGroupAt(c) != null)
     {
         Log.Error(string.Concat(new object[]
         {
             group,
             " overwriting slot group square ",
             c,
             " of ",
             this.SlotGroupAt(c)
         }), false);
     }
     this.groupGrid[c.x, c.y, c.z] = group;
 }
 public void ClearCellFor(IntVec3 c, SlotGroup group)
 {
     if (this.SlotGroupAt(c) != group)
     {
         Log.Error(string.Concat(new object[]
         {
             group,
             " clearing group grid square ",
             c,
             " containing ",
             this.SlotGroupAt(c)
         }), false);
     }
     this.groupGrid[c.x, c.y, c.z] = null;
 }
Exemplo n.º 17
0
        private IEnumerable <Widgets.DropdownMenuElement <Zone_Stockpile> > GenerateStockpileInclusion()
        {
            Widgets.DropdownMenuElement <Zone_Stockpile> dropdownMenuElement = new Widgets.DropdownMenuElement <Zone_Stockpile>
            {
                option = new FloatMenuOption("IncludeFromAll".Translate(), delegate
                {
                    bill.includeFromZone = null;
                }),
                payload = null
            };
            yield return(dropdownMenuElement);

            List <SlotGroup> groupList = bill.billStack.billGiver.Map.haulDestinationManager.AllGroupsListInPriorityOrder;
            int groupCount             = groupList.Count;
            int i = 0;

            while (i < groupCount)
            {
                SlotGroup      slotGroup = groupList[i];
                Zone_Stockpile stockpile = slotGroup.parent as Zone_Stockpile;
                if (stockpile != null)
                {
                    if (!bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(bill, stockpile))
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Zone_Stockpile>
                        {
                            option  = new FloatMenuOption(string.Format("{0} ({1})", "IncludeSpecific".Translate(slotGroup.parent.SlotYielderLabel()), "IncompatibleLower".Translate()), null),
                            payload = stockpile
                        };
                        yield return(dropdownMenuElement);
                    }
                    else
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Zone_Stockpile>
                        {
                            option = new FloatMenuOption("IncludeSpecific".Translate(slotGroup.parent.SlotYielderLabel()), delegate
                            {
                                bill.includeFromZone = stockpile;
                            }),
                            payload = stockpile
                        };
                        yield return(dropdownMenuElement);
                    }
                }
                int num = i + 1;
                i = num;
            }
        }
Exemplo n.º 18
0
        public void RemoveGroup(SlotGroup oldGroup)
        {
            if (!this.allGroups.Contains(oldGroup))
            {
                Log.Error("Removing SlotGroup that isn't registered.");
                return;
            }
            this.allGroups.Remove(oldGroup);
            List <IntVec3> cellsList = oldGroup.CellsList;

            for (int i = 0; i < cellsList.Count; i++)
            {
                IntVec3 intVec = cellsList[i];
                this.groupGrid[intVec.x, intVec.y, intVec.z] = null;
            }
            this.map.listerHaulables.Notify_SlotGroupChanged(oldGroup);
        }
Exemplo n.º 19
0
        public void ListerHaulablesTick()
        {
            ListerHaulables.groupCycleIndex++;
            if (ListerHaulables.groupCycleIndex >= 2147473647)
            {
                ListerHaulables.groupCycleIndex = 0;
            }
            List <SlotGroup> allGroupsListForReading = this.map.haulDestinationManager.AllGroupsListForReading;

            if (allGroupsListForReading.Count == 0)
            {
                return;
            }
            int       num       = ListerHaulables.groupCycleIndex % allGroupsListForReading.Count;
            SlotGroup slotGroup = allGroupsListForReading[ListerHaulables.groupCycleIndex % allGroupsListForReading.Count];

            if (slotGroup.CellsList.Count != 0)
            {
                while (this.cellCycleIndices.Count <= num)
                {
                    this.cellCycleIndices.Add(0);
                }
                if (this.cellCycleIndices[num] >= 2147473647)
                {
                    this.cellCycleIndices[num] = 0;
                }
                for (int i = 0; i < 4; i++)
                {
                    List <int> list;
                    int        index;
                    (list = this.cellCycleIndices)[index = num] = list[index] + 1;
                    IntVec3      c         = slotGroup.CellsList[this.cellCycleIndices[num] % slotGroup.CellsList.Count];
                    List <Thing> thingList = c.GetThingList(this.map);
                    for (int j = 0; j < thingList.Count; j++)
                    {
                        if (thingList[j].def.EverHaulable)
                        {
                            this.Check(thingList[j]);
                            break;
                        }
                    }
                }
            }
        }
 public void AddHaulDestination(IHaulDestination haulDestination)
 {
     if (this.allHaulDestinationsInOrder.Contains(haulDestination))
     {
         Log.Error("Double-added haul destination " + haulDestination.ToStringSafe <IHaulDestination>(), false);
     }
     else
     {
         this.allHaulDestinationsInOrder.Add(haulDestination);
         IList <IHaulDestination> list = this.allHaulDestinationsInOrder;
         if (HaulDestinationManager.< > f__mg$cache0 == null)
         {
             HaulDestinationManager.< > f__mg$cache0 = new Comparison <IHaulDestination>(HaulDestinationManager.CompareHaulDestinationPrioritiesDescending);
         }
         list.InsertionSort(HaulDestinationManager.< > f__mg$cache0);
         ISlotGroupParent slotGroupParent = haulDestination as ISlotGroupParent;
         if (slotGroupParent != null)
         {
             SlotGroup slotGroup = slotGroupParent.GetSlotGroup();
             if (slotGroup == null)
             {
                 Log.Error("ISlotGroupParent gave null slot group: " + slotGroupParent.ToStringSafe <ISlotGroupParent>(), false);
             }
             else
             {
                 this.allGroupsInOrder.Add(slotGroup);
                 IList <SlotGroup> list2 = this.allGroupsInOrder;
                 if (HaulDestinationManager.< > f__mg$cache1 == null)
                 {
                     HaulDestinationManager.< > f__mg$cache1 = new Comparison <SlotGroup>(HaulDestinationManager.CompareSlotGroupPrioritiesDescending);
                 }
                 list2.InsertionSort(HaulDestinationManager.< > f__mg$cache1);
                 List <IntVec3> cellsList = slotGroup.CellsList;
                 for (int i = 0; i < cellsList.Count; i++)
                 {
                     this.SetCellFor(cellsList[i], slotGroup);
                 }
                 this.map.listerHaulables.Notify_SlotGroupChanged(slotGroup);
                 this.map.listerMergeables.Notify_SlotGroupChanged(slotGroup);
             }
         }
     }
 }
Exemplo n.º 21
0
        public static float CellBeauty(IntVec3 c, Map map, List <Thing> countedThings = null)
        {
            float        num  = 0f;
            float        num2 = 0f;
            bool         flag = false;
            List <Thing> list = map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (countedThings != null)
                {
                    if (countedThings.Contains(thing))
                    {
                        continue;
                    }
                    countedThings.Add(thing);
                }
                SlotGroup slotGroup = thing.GetSlotGroup();
                if (slotGroup == null || !slotGroup.parent.IgnoreStoredThingsBeauty)
                {
                    float num3 = thing.GetStatValue(StatDefOf.Beauty, true);
                    if (thing is Filth && !map.roofGrid.Roofed(c))
                    {
                        num3 = (float)(num3 * 0.30000001192092896);
                    }
                    if (thing.def.Fillage == FillCategory.Full)
                    {
                        flag  = true;
                        num2 += num3;
                    }
                    else
                    {
                        num += num3;
                    }
                }
            }
            if (flag)
            {
                return(num2);
            }
            return(num + map.terrainGrid.TerrainAt(c).GetStatValueAbstract(StatDefOf.Beauty, null));
        }
Exemplo n.º 22
0
        public void UpdateResourceCounts()
        {
            this.ResetResourceCounts();
            List <SlotGroup> allGroupsListForReading = this.map.slotGroupManager.AllGroupsListForReading;

            for (int i = 0; i < allGroupsListForReading.Count; i++)
            {
                SlotGroup slotGroup = allGroupsListForReading[i];
                foreach (Thing heldThing in slotGroup.HeldThings)
                {
                    if (heldThing.def.CountAsResource && this.ShouldCount(heldThing))
                    {
                        Dictionary <ThingDef, int> dictionary;
                        ThingDef def;
                        (dictionary = this.countedAmounts)[def = heldThing.def] = dictionary[def] + heldThing.stackCount;
                    }
                }
            }
        }
Exemplo n.º 23
0
        public static Building StoringBuilding(this Thing t)
        {
            if (!t.Spawned)
            {
                return(null);
            }
            SlotGroup slotGroup = t.GetSlotGroup();

            if (slotGroup != null)
            {
                Building building = slotGroup.parent as Building;
                if (building != null)
                {
                    return(building);
                }
                return(null);
            }
            return(null);
        }
Exemplo n.º 24
0
        public void ListerHaulablesTick()
        {
            ListerHaulables.groupCycleIndex++;
            if (ListerHaulables.groupCycleIndex >= 2147473647)
            {
                ListerHaulables.groupCycleIndex = 0;
            }
            List <SlotGroup> allGroupsListForReading = this.map.slotGroupManager.AllGroupsListForReading;

            if (allGroupsListForReading.Count != 0)
            {
                int       num       = ListerHaulables.groupCycleIndex % allGroupsListForReading.Count;
                SlotGroup slotGroup = allGroupsListForReading[ListerHaulables.groupCycleIndex % allGroupsListForReading.Count];
                while (this.cellCycleIndices.Count <= num)
                {
                    this.cellCycleIndices.Add(0);
                }
                if (this.cellCycleIndices[num] >= 2147473647)
                {
                    this.cellCycleIndices[num] = 0;
                }
                for (int i = 0; i < 4; i++)
                {
                    List <int> list;
                    int        index;
                    (list = this.cellCycleIndices)[index = num] = list[index] + 1;
                    IntVec3      c         = slotGroup.CellsList[this.cellCycleIndices[num] % slotGroup.CellsList.Count];
                    List <Thing> thingList = c.GetThingList(this.map);
                    int          num2      = 0;
                    while (num2 < thingList.Count)
                    {
                        if (!thingList[num2].def.EverHaulable)
                        {
                            num2++;
                            continue;
                        }
                        this.Check(thingList[num2]);
                        break;
                    }
                }
            }
        }
Exemplo n.º 25
0
        public void ListerHaulablesTick()
        {
            groupCycleIndex++;
            if (groupCycleIndex >= 2147473647)
            {
                groupCycleIndex = 0;
            }
            List <SlotGroup> allGroupsListForReading = map.haulDestinationManager.AllGroupsListForReading;

            if (allGroupsListForReading.Count == 0)
            {
                return;
            }
            int       num       = groupCycleIndex % allGroupsListForReading.Count;
            SlotGroup slotGroup = allGroupsListForReading[groupCycleIndex % allGroupsListForReading.Count];

            if (slotGroup.CellsList.Count == 0)
            {
                return;
            }
            while (cellCycleIndices.Count <= num)
            {
                cellCycleIndices.Add(0);
            }
            if (cellCycleIndices[num] >= 2147473647)
            {
                cellCycleIndices[num] = 0;
            }
            for (int i = 0; i < 4; i++)
            {
                cellCycleIndices[num]++;
                List <Thing> thingList = slotGroup.CellsList[cellCycleIndices[num] % slotGroup.CellsList.Count].GetThingList(map);
                for (int j = 0; j < thingList.Count; j++)
                {
                    if (thingList[j].def.EverHaulable)
                    {
                        Check(thingList[j]);
                        break;
                    }
                }
            }
        }
Exemplo n.º 26
0
        public void UpdateResourceCounts()
        {
            ResetResourceCounts();
            List <SlotGroup> allGroupsListForReading = map.haulDestinationManager.AllGroupsListForReading;

            for (int i = 0; i < allGroupsListForReading.Count; i++)
            {
                SlotGroup slotGroup = allGroupsListForReading[i];
                foreach (Thing heldThing in slotGroup.HeldThings)
                {
                    Thing innerIfMinified = heldThing.GetInnerIfMinified();
                    if (innerIfMinified.def.CountAsResource && ShouldCount(innerIfMinified))
                    {
                        Dictionary <ThingDef, int> dictionary;
                        ThingDef def;
                        (dictionary = countedAmounts)[def = innerIfMinified.def] = dictionary[def] + innerIfMinified.stackCount;
                    }
                }
            }
        }
Exemplo n.º 27
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.stackCount == t.def.stackLimit)
            {
                return(null);
            }
            if (!HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t, forced))
            {
                return(null);
            }
            SlotGroup slotGroup = t.GetSlotGroup();

            if (slotGroup == null)
            {
                return(null);
            }
            LocalTargetInfo target = t.Position;
            bool            ignoreOtherReservations = forced;

            if (!pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations))
            {
                return(null);
            }
            foreach (Thing heldThing in slotGroup.HeldThings)
            {
                if (heldThing != t && heldThing.def == t.def && (forced || heldThing.stackCount >= t.stackCount) && heldThing.stackCount < heldThing.def.stackLimit)
                {
                    target = heldThing.Position;
                    ignoreOtherReservations = forced;
                    if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations) && pawn.CanReserve(heldThing) && heldThing.Position.IsValidStorageFor(heldThing.Map, t))
                    {
                        Job job = new Job(JobDefOf.HaulToCell, t, heldThing.Position);
                        job.count    = Mathf.Min(heldThing.def.stackLimit - heldThing.stackCount, t.stackCount);
                        job.haulMode = HaulMode.ToCellStorage;
                        return(job);
                    }
                }
            }
            JobFailReason.Is("NoMergeTarget".Translate());
            return(null);
        }
Exemplo n.º 28
0
        public static bool TryFindBestBetterStoreCellFor(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction, out IntVec3 foundCell, bool needAccurateResult = true)
        {
            List <SlotGroup> allGroupsListInPriorityOrder = map.haulDestinationManager.AllGroupsListInPriorityOrder;
            bool             result;

            if (allGroupsListInPriorityOrder.Count == 0)
            {
                foundCell = IntVec3.Invalid;
                result    = false;
            }
            else
            {
                StoragePriority storagePriority = currentPriority;
                float           num             = 2.14748365E+09f;
                IntVec3         invalid         = IntVec3.Invalid;
                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;
                    }
                    StoreUtility.TryFindBestBetterStoreCellForWorker(t, carrier, map, faction, slotGroup, needAccurateResult, ref invalid, ref num, ref storagePriority);
                }
                if (!invalid.IsValid)
                {
                    foundCell = IntVec3.Invalid;
                    result    = false;
                }
                else
                {
                    foundCell = invalid;
                    result    = true;
                }
            }
            return(result);
        }
Exemplo n.º 29
0
 public void AddGroup(SlotGroup newGroup)
 {
     if (this.allGroups.Contains(newGroup))
     {
         Log.Error("Double-added slot group. SlotGroup parent is " + newGroup.parent);
     }
     else if ((from g in this.allGroups
               where g.parent == newGroup.parent
               select g).Any())
     {
         Log.Error("Added SlotGroup with a parent matching an existing one. Parent is " + newGroup.parent);
     }
     else
     {
         this.allGroups.Add(newGroup);
         this.allGroups.InsertionSort(SlotGroupManager.CompareSlotGroupPrioritiesDescending);
         List <IntVec3> cellsList = newGroup.CellsList;
         for (int i = 0; i < cellsList.Count; i++)
         {
             this.SetCellFor(cellsList[i], newGroup);
         }
         this.map.listerHaulables.Notify_SlotGroupChanged(newGroup);
     }
 }
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.outfits == null)
            {
                Log.ErrorOnce(pawn + " tried to run JobGiver_OptimizeApparel without an OutfitTracker", 5643897);
                return(null);
            }
            if (pawn.Faction != Faction.OfPlayer)
            {
                Log.ErrorOnce("Non-colonist " + pawn + " tried to optimize apparel.", 764323);
                return(null);
            }
            if (!DebugViewSettings.debugApparelOptimize)
            {
                if (Find.TickManager.TicksGame < pawn.mindState.nextApparelOptimizeTick)
                {
                    return(null);
                }
            }
            else
            {
                JobGiver_OptimizeApparel.debugSb = new StringBuilder();
                JobGiver_OptimizeApparel.debugSb.AppendLine("Scanning for " + pawn + " at " + pawn.Position);
            }
            Outfit         currentOutfit = pawn.outfits.CurrentOutfit;
            List <Apparel> wornApparel   = pawn.apparel.WornApparel;

            for (int num = wornApparel.Count - 1; num >= 0; num--)
            {
                if (!currentOutfit.filter.Allows(wornApparel[num]) && pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(wornApparel[num]))
                {
                    Job job = new Job(JobDefOf.RemoveApparel, wornApparel[num]);
                    job.haulDroppedApparel = true;
                    return(job);
                }
            }
            Thing        thing = null;
            float        num2  = 0f;
            List <Thing> list  = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel);

            if (list.Count == 0)
            {
                this.SetNextOptimizeTick(pawn);
                return(null);
            }
            JobGiver_OptimizeApparel.neededWarmth = PawnApparelGenerator.CalculateNeededWarmth(pawn, pawn.Map.Tile, GenLocalDate.Twelfth(pawn));
            for (int i = 0; i < list.Count; i++)
            {
                Apparel apparel = (Apparel)list[i];
                if (currentOutfit.filter.Allows(apparel))
                {
                    SlotGroup slotGroup = apparel.Map.slotGroupManager.SlotGroupAt(apparel.Position);
                    if (slotGroup != null && !apparel.IsForbidden(pawn))
                    {
                        float num3 = JobGiver_OptimizeApparel.ApparelScoreGain(pawn, apparel);
                        if (DebugViewSettings.debugApparelOptimize)
                        {
                            JobGiver_OptimizeApparel.debugSb.AppendLine(apparel.LabelCap + ": " + num3.ToString("F2"));
                        }
                        if (!(num3 < 0.05000000074505806) && !(num3 < num2) && ApparelUtility.HasPartsToWear(pawn, apparel.def) && pawn.CanReserveAndReach(apparel, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1, -1, null, false))
                        {
                            thing = apparel;
                            num2  = num3;
                        }
                    }
                }
            }
            if (DebugViewSettings.debugApparelOptimize)
            {
                JobGiver_OptimizeApparel.debugSb.AppendLine("BEST: " + thing);
                Log.Message(JobGiver_OptimizeApparel.debugSb.ToString());
                JobGiver_OptimizeApparel.debugSb = null;
            }
            if (thing == null)
            {
                this.SetNextOptimizeTick(pawn);
                return(null);
            }
            return(new Job(JobDefOf.Wear, thing));
        }