Exemplo n.º 1
0
        public override string GetReport()
        {
            Vehicle_Cart cart = TargetThingA as Vehicle_Cart;

            IntVec3   destLoc   = new IntVec3(-1000, -1000, -1000);
            string    destName  = null;
            SlotGroup destGroup = null;

            if (pawn.jobs.curJob.targetB != null)
            {
                destLoc   = pawn.jobs.curJob.targetB.Cell;
                destGroup = StoreUtility.GetSlotGroup(destLoc);
            }

            if (destGroup != null)
            {
                destName = destGroup.parent.SlotYielderLabel();
            }

            string repString;

            if (destName != null)
            {
                repString = "ReportDismountingOn".Translate(cart.LabelCap, destName);
            }
            else
            {
                repString = "ReportDismounting".Translate(cart.LabelCap);
            }

            return(repString);
        }
        public override string GetReport()
        {
            Thing hauledThing = TargetThingA;

            IntVec3   destLoc   = pawn.jobs.curJob.targetB.Cell;
            string    destName  = null;
            SlotGroup destGroup = StoreUtility.GetSlotGroup(destLoc);

            if (destGroup != null)
            {
                destName = destGroup.parent.SlotYielderLabel();
            }

            string repString;

            if (destName != null)
            {
                repString = "ReportHaulingTo".Translate(hauledThing.LabelCap, destName);
            }
            else
            {
                repString = "ReportHauling".Translate(hauledThing.LabelCap);
            }

            return(repString);
        }
Exemplo n.º 3
0
        public static void Postfix(ref List <IHaulDestination> __result)
        {
            int HeldItems(IHaulDestination x) => StoreUtility.GetSlotGroup(x.Position, x.Map).TotalPrecalculatedItemsStack();

            __result = __result.Where(x =>
            {
                if (!Limits.HasLimit(x.GetStoreSettings()))
                {
                    return(true);
                }

                int limit = Limits.GetLimit(x.GetStoreSettings());
                if (limit < 0)
                {
                    limit = int.MaxValue;
                }

                return(HeldItems(x) < limit);
            })
                       .OrderByDescending(x => x.GetStoreSettings().Priority)
                       .ThenByDescending(x =>
            {
                if (!Limits.HasLimit(x.GetStoreSettings()))
                {
                    return(0);
                }

                int limit = Limits.GetLimit(x.GetStoreSettings());
                if (limit < 0)
                {
                    limit = int.MaxValue;
                }

                return(limit - HeldItems(x));
            })

                       /*.ThenByDescending(x =>
                        * {
                        *      int limit = Limits.GetLimit(x.GetStoreSettings());
                        *      if (limit < 0)
                        *              return int.MaxValue;
                        *      else
                        *      {
                        *              int heldItems = HeldItems(x);
                        *              int spaceLeft = limit - heldItems;
                        *              return spaceLeft;
                        *      }
                        * })*/
                       .ToList();
        }
        public static bool Prefix(Pawn pawn, Thing thing, ref Job __result)
        {
            StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);

            if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
            {
                SlotGroup slotGroup = StoreUtility.GetSlotGroup(storeCell, thing.Map);
                if (Limits.HasLimit(slotGroup.Settings))
                {
                    __result = HaulAIUtility.HaulToStorageJob(pawn, thing);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Set fail conditions
            this.FailOnDestroyedOrNull(HaulableInd);
            this.FailOnBurningImmobile(CellInd);
            //Note we only fail on forbidden if the target doesn't start that way
            //This helps haul-aside jobs on forbidden items
            if (!this.forbiddenInitially)
            {
                this.FailOnForbidden(HaulableInd);
            }

            //Reserve target storage cell, if it is a storage
            bool targetIsStorage = StoreUtility.GetSlotGroup(pawn.jobs.curJob.GetTarget(CellInd).Cell, Map) != null;

            if (targetIsStorage)
            {
                yield return(Toils_Reserve.Reserve(CellInd, 1));
            }

            //Reserve thing to be stored
            Toil reserveTargetA = Toils_Reserve.Reserve(HaulableInd, 1, 1, null);

            yield return(reserveTargetA);

            //yield return toilGoto;
            yield return(Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(HaulableInd));

            // Start hauling to
            yield return(Toils_Haul.StartCarryThing(HaulableInd, false, false));

            if (this.job.haulOpportunisticDuplicates)
            {
                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveTargetA, HaulableInd, CellInd));
            }

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(CellInd);

            yield return(carryToCell);

            // start work on target
            yield return(Toils_WaitWithSoundAndEffect(180, "Interact_ConstructMetal", "ConstructMetal", CellInd));


            yield return(Toils_TryToAttachToWeaponBase(pawn, HaulableInd, CellInd));
        }
Exemplo n.º 6
0
        public override string GetReport()
        {
            IntVec3 destCell = pawn.jobs.curJob.targetB.Cell;

            Thing hauledThing = null;

            if (pawn.carryTracker.CarriedThing != null)
            {
                hauledThing = pawn.carryTracker.CarriedThing;
            }
            else
            {
                hauledThing = pawn.jobs.curJob.GetTarget(HaulableInd).Thing;
            }

            string    destName  = null;
            SlotGroup destGroup = StoreUtility.GetSlotGroup(destCell, Map);

            if (destGroup != null)
            {
                destName = destGroup.parent.SlotYielderLabel();
            }

            string repString;

            if (destName != null)
            {
                repString = "ReportHaulingTo".Translate(hauledThing.Label, destName);
            }
            else
            {
                repString = "ReportHauling".Translate(hauledThing.Label);
            }

            if (!pawn.jobs.curJob.def.reportString.NullOrEmpty())
            {
                repString = pawn.jobs.curJob.def.reportString;
            }

            return(repString);
        }
Exemplo n.º 7
0
        private static void PostOpen(Dialog_Trade __instance)
        {
            if (QOLTweaksPack.TradingStockpiles.Value == false)
            {
                return;
            }
            List <Tradeable> cachedTradeables = Reflection.GetFieldValue(__instance, "cachedTradeables") as List <Tradeable>;

            if (cachedTradeables == null)
            {
                Log.Warning("Could not grab cachedTradeables via reflection");
            }
            foreach (Tradeable tradeable in cachedTradeables)
            {
                foreach (Thing tradeableThing in tradeable.thingsColony)
                {
                    if (tradeableThing.holdingOwner != null)
                    {
                        SlotGroup storage = StoreUtility.GetSlotGroup(tradeableThing);
                        if (storage == null || storage.parent == null)
                        {
                            continue;
                        }
                        if (storage.parent is Zone_Stockpile)
                        {
                            if (QOLTweaksPack.savedData.StockpileIsTradeStockpile(storage.parent as Zone_Stockpile))
                            {
                                if (tradeable.CanAdjustBy(-tradeableThing.stackCount).Accepted)
                                {
                                    tradeable.AdjustBy(-tradeableThing.stackCount);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        public static void SetCountLimit(Pawn p, Thing t, ref Job __result, IntVec3 storeCell)
        {
            SlotGroup toSlotGroup = p.Map.haulDestinationManager.SlotGroupAt(storeCell);            // ?? __result.targetB.Thing?.GetSlotGroup();

            if (toSlotGroup == null)
            {
                //It is a haul destination without a SlotGroup, e.g. a grave
                return;
            }

            int toLimit = Limits.GetLimit(toSlotGroup.Settings);

            //int currentStack = __result.count < 0 ? t.stackCount : __result.count;
            int stackCount = __result.targetA.Thing.stackCount;

            if (stackCount < 1)
            {
                stackCount = int.MaxValue;
            }
            int currentStack = Math.Min(__result.count, stackCount);

            currentStack = Math.Min(currentStack, p.carryTracker.AvailableStackSpace(__result.targetA.Thing.def));


            bool hasSetFirstLimit = false;

            SlotGroup fromSlotGroup = StoreUtility.GetSlotGroup(t.Position, t.Map);

            if (fromSlotGroup != null)
            {
                int fromLimit = Limits.GetLimit(fromSlotGroup.Settings);

                if (fromLimit > 0 && StoreUtility.CurrentStoragePriorityOf(t) > StoreUtility.StoragePriorityAtFor(storeCell, t))
                {
                    //Hauling from limited high priority to low priority. Only haul the minimum necessary to go to exact limit.
                    int stockpileStack1 = fromSlotGroup.TotalPrecalculatedItemsStack();
                    __result.count   = stockpileStack1 - fromLimit;
                    hasSetFirstLimit = true;
                }
            }

            if (toLimit < 0)
            {
                return;
            }

            int stockpileStack = toSlotGroup.TotalPrecalculatedItemsStack();

            if (stockpileStack >= toLimit)
            {
                //Say no spot availible
                JobFailReason.Is(GetNoEmptyPlaceLowerTransString(), null);
                __result = null;
            }
            else if (stockpileStack + currentStack > toLimit)            //It will go over the limit
            {
                int newLimit = toLimit - stockpileStack;

                __result.count = hasSetFirstLimit ? Math.Min(newLimit, __result.count < 0 ? int.MaxValue : __result.count) : newLimit;
            }

            if (__result != null && __result.count <= 0)
            {
                JobFailReason.Is(GetNoEmptyPlaceLowerTransString(), null);
                __result = null;
            }
        }
Exemplo n.º 9
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Set fail conditions
            this.FailOnDestroyedNullOrForbidden(HaulableInd);
            this.FailOnBurningImmobile(CellInd);
            //Note we only fail on forbidden if the target doesn't start that way
            //This helps haul-aside jobs on forbidden items
            if (!TargetThingA.IsForbidden(pawn.Faction))
            {
                this.FailOnForbidden(HaulableInd);
            }


            //Reserve target storage cell, if it is a storage
            bool targetIsStorage = StoreUtility.GetSlotGroup(pawn.jobs.curJob.GetTarget(CellInd).Cell, Map) != null;

            if (targetIsStorage)
            {
                yield return(Toils_Reserve.Reserve(CellInd, 1));
            }

            //Reserve thing to be stored
            Toil reserveTargetA = Toils_Reserve.Reserve(HaulableInd, 1);

            yield return(reserveTargetA);

            // Goto object
            //Toil toilGoto = null;
            //toilGoto = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch)
            //    .FailOn(() =>
            //    {
            //        //Note we don't fail on losing hauling designation
            //        //Because that's a special case anyway

            //        //While hauling to cell storage, ensure storage dest is still valid
            //        Pawn actor = toilGoto.actor;
            //        Job curJob = actor.jobs.curJob;
            //        if (curJob.haulMode == HaulMode.ToCellStorage)
            //        {
            //            Thing haulThing = curJob.GetTarget(HaulableInd).Thing;

            //            IntVec3 destLoc = actor.jobs.curJob.GetTarget(CellInd).Cell;
            //            if (!destLoc.IsValidStorageFor(Map, haulThing))
            //                return true;
            //        }

            //        return false;
            //    });
            //yield return toilGoto;
            yield return(Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(HaulableInd));

            // Start hauling to
            yield return(Toils_Haul.StartCarryThing(HaulableInd, false, false));

            if (this.job.haulOpportunisticDuplicates)
            {
                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveTargetA, HaulableInd, CellInd));
            }

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(CellInd);

            yield return(carryToCell);

            // start work on target
            yield return(Toils_WaitWithSoundAndEffect(180, "Interact_ConstructMetal", "ConstructMetal", CellInd));


            yield return(Toils_TryToAttachToWeaponBase(pawn, HaulableInd, CellInd));
        }