public static void Prefix(Thing t, Pawn carrier, Map map, ref StoragePriority currentPriority,
                           ref IntVec3 foundCell)
 {
     if (t.stackCount > Limits.CalculateStackLimit(t))
     {
         currentPriority = StoragePriority.Unstored;
     }
 }
Esempio n. 2
0
        /*
         #if DEBUG
         *      static bool Prepare() => HarmonyLibInstance.DEBUG = true;
         *      static bool Cleanup() => HarmonyLibInstance.DEBUG = false;
         #endif
         *      static IEnumerable<CodeInstruction> Transpiler(ILGenerator generator, IEnumerable<CodeInstruction> instructions)
         *      => new TranspilerFactory().Search("ret", 2).Insert("localvar int;ldarg.1;ldarg.2;call Limits::CalculateStackLimit(Verse.Map,Verse.IntVec3);stloc.s 0")
         *          .Replace("ldarg.2;ldfld Verse.Thing::def;ldfld Verse.ThingDef::stackLimit", "ldloc.s 0;ldloc.s 0;brtrue 0;pop;ldarg.2;ldfld Verse.Thing::def;ldfld Verse.ThingDef::stackLimit;label 0")
         *          .Replace("ldarg.2;ldfld Verse.Thing::def;ldfld Verse.ThingDef::stackLimit", "ldloc.s 0;ldloc.s 0;brtrue 1;pop;ldarg.2;ldfld Verse.Thing::def;ldfld Verse.ThingDef::stackLimit;label 1")
         *          .Transpiler(generator, instructions);
         */
        public static bool Prefix(IntVec3 c, Map map, Thing thing, IntVec3 center, ref byte __result)
        {
            Mod.Debug("GenPlace.PlaceSpotQualityAt begin");
            if (thing.stackCount < Limits.CalculateStackLimit(map, c))
            {
                return(true);
            }

            __result = 0;
            return(false);
        }
Esempio n. 3
0
        private static void Postfix(Thing thing, ref int __result)
        {
            if (!Limits.HasStackLimit(thing))
            {
                return;
            }

            var t = thing.stackCount - Limits.CalculateStackLimit(thing);

            if (t < 0)
            {
                t = 0;
            }

            __result = Mathf.Min(t, __result);
        }
Esempio n. 4
0
        public static bool Prefix(ref int __result, Thing thing, Thing other, bool respectStackLimit)
        {
            if (respectStackLimit)
            {
                var t = Limits.CalculateStackLimit(thing) - thing.stackCount;
                if (t < 0)
                {
                    t = 0;
                }

                __result = Mathf.Min(other.stackCount, t);
            }
            else
            {
                __result = other.stackCount;
            }

            return(false);
        }
 private static void Postfix(Thing t, ref bool __result)
 {
     if (__result)
     {
         __result = !Limits.HasStackLimit(t) && t.stackCount != Limits.CalculateStackLimit(t);
     }
     //if (t.IsForbidden(Faction.OfPlayer))
     //{
     //    __result = false;
     //}
     //else if (!Limits.HasStackLimit(t))
     //{
     //    __result = false;
     //}
     //else if (t.stackCount == Limits.CalculateStackLimit(t))
     //{
     //    __result = false;
     //}
     //else
     //    __result = true;
     //return false;
 }
        public static bool Prefix(Pawn p, Thing t, IntVec3 storeCell, bool fitInStoreCell, ref Job __result)
        {
            var limit = Limits.CalculateStackLimit(t);

            if (t.stackCount > limit)
            {
                var job = new Job(JobDefOf.HaulToCell, t, storeCell)
                {
                    count = t.stackCount - limit,
                    haulOpportunisticDuplicates = true,
                    haulMode = HaulMode.ToCellStorage
                };
                __result = job;
                Mod.Debug($"dispatch job1, thing={t},cell={storeCell}");
                return(false);
            }

            limit = Limits.CalculateStackLimit(p.Map.haulDestinationManager.SlotGroupAt(storeCell));
            if (limit >= 99999)
            {
                Mod.Debug($"dispatch job3, thing={t},cell={storeCell}");
                return(true);
            }

            {
                var job   = new Job(JobDefOf.HaulToCell, t, storeCell);
                var thing = p.Map.thingGrid.ThingAt(storeCell, t.def);
                job.count = limit - thing?.stackCount ?? limit;

                job.haulOpportunisticDuplicates = false;
                job.haulMode = HaulMode.ToCellStorage;
                __result     = job;
                Mod.Debug($"dispatch job2, thing={t},cell={storeCell}");
                return(false);
            }
        }
Esempio n. 7
0
        public static bool Prefix(Thing __instance, Thing other, bool respectStackLimit, ref bool __result)
        {
            Mod.Debug("Thing.TryAbsorbStack begin");
            if (!Limits.HasStackLimit(__instance))
            {
                return(true);
            }

            if (!__instance.CanStackWith(other))
            {
                __result = false;
                return(false);
            }

            int num;

            if (respectStackLimit)
            {
                var t = Limits.CalculateStackLimit(__instance) - __instance.stackCount;
                if (t < 0)
                {
                    t = 0;
                }

                num = Mathf.Min(other.stackCount, t);
            }
            else
            {
                num = other.stackCount;
            }

            if (num <= 0)
            {
                __result = false;
                return(false);
            }

            if (__instance.def.useHitPoints)
            {
                __instance.HitPoints =
                    Mathf.CeilToInt(((__instance.HitPoints * __instance.stackCount) + (other.HitPoints * num)) /
                                    (float)(__instance.stackCount + num));
            }

            __instance.stackCount += num;
            other.stackCount      -= num;
            StealAIDebugDrawer.Notify_ThingChanged(__instance);
            if (__instance.Spawned)
            {
                __instance.Map.listerMergeables.Notify_ThingStackChanged(__instance);
            }

            if (other.stackCount <= 0)
            {
                other.Destroy();
                __result = true;
            }
            else
            {
                __result = false;
            }

            return(false);
        }