예제 #1
0
        //public bool Reserve(Pawn claimant, Job job, LocalTargetInfo target, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null)
        public static bool Prefix(Pawn claimant, Job job, LocalTargetInfo target, ref bool __result)
        {
            if (claimant.IsFreeColonist && target.Cell != LocalTargetInfo.Invalid &&
                claimant.Map.thingGrid.ThingsAt(target.Cell)
                .FirstOrDefault(t => t.GetType() == ExtendedStoragePatches.typeBuilding_ExtendedStorage) is Thing storage &&
                job.def == JobDefOf.HaulToCell)
            {
                int canDo = storage.ApparentMaxStorage() - storage.StoredThingTotal();
                if (canDo > 0)
                {
                    int      count        = job.count;
                    Thing    deliverThing = job.targetA.Thing;
                    ThingDef resource     = deliverThing.def;

                    Log.Message($"{claimant} reservingES {storage} resource = {resource}({count})");
                    Log.Message($"	out of: {canDo}");


                    int availableCount = deliverThing.stackCount;                    // + job.targetQueueA?.Sum(tar => tar.Thing.stackCount) ?? 0;
                    //HaulToCell doesn't queue up its reservations, and so we don't know if there are more to get
                    count = Mathf.Min(new int[] { count, claimant.carryTracker.MaxStackSpaceEver(resource), availableCount, canDo });

                    Log.Message($"{storage} was expecting {resource}(" + ExpectingComp.ExpectedCount(storage, resource) + ")");
                    ExpectingComp.Add(claimant, job, storage, resource, count);
                    Log.Message($"{storage} now expecting {resource}(" + ExpectingComp.ExpectedCount(storage, resource) + ")");

                    __result = true;
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        //public bool Reserve(Pawn claimant, Job job, LocalTargetInfo target, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null)
        public static bool Prefix(Pawn claimant, Job job, LocalTargetInfo target, ref bool __result)
        {
            if (claimant.IsFreeColonist &&
                target.Thing is IConstructible c && !(c is Blueprint_Install) &&
                job.def == JobDefOf.HaulToContainer &&
                c.MaterialsNeeded().Count > 0)
            {
                int      count        = job.count;
                Thing    building     = target.Thing;
                Thing    deliverThing = job.targetA.Thing;
                ThingDef resource     = deliverThing.def;
                int      neededCount  = c.MaterialsNeeded().FirstOrDefault(tc => tc.thingDef == resource)?.count ?? 0;

                Log.Message($"{claimant} reserving {building} resource = {resource}({count})");
                Log.Message($"	out of: {c.MaterialsNeeded().ToStringSafeEnumerable()}");


                int availableCount = deliverThing.stackCount + job.targetQueueA?.Sum(tar => tar.Thing.stackCount) ?? 0;
                count = Mathf.Min(new int[] { count, claimant.carryTracker.MaxStackSpaceEver(resource), availableCount, neededCount });
                Log.Message($"{c} was expecting {resource}(" + ExpectingComp.ExpectedCount(building, resource) + ")");
                ExpectingComp.Add(claimant, job, building, resource, count);
                Log.Message($"{c} now expecting {resource}(" + ExpectingComp.ExpectedCount(building, resource) + ")");
                __result = true;
                return(false);
            }
            return(true);
        }
예제 #3
0
 //public void ReleaseClaimedBy(Pawn claimant, Job job)
 public static void Prefix(Pawn claimant, Job job)
 {
     if (job.def == JobDefOf.HaulToCell)
     {
         ExpectingComp.Remove(q => q.claimant == claimant && q.job == job);
     }
 }
예제 #4
0
 //public void Release(LocalTargetInfo target, Pawn claimant, Job job)
 public static void Prefix(LocalTargetInfo target, Pawn claimant, Job job)
 {
     if (claimant.IsFreeColonist && target.Cell != LocalTargetInfo.Invalid &&
         claimant.Map.thingGrid.ThingsAt(target.Cell).FirstOrDefault(t => t.GetType() == ExtendedStoragePatches.typeBuilding_ExtendedStorage) is Thing thing &&
         job.def == JobDefOf.HaulToCell)
     {
         ExpectingComp.Remove(q => q.claimant == claimant && q.job == job && q.claimed == thing);
     }
 }
예제 #5
0
 //public void Release(LocalTargetInfo target, Pawn claimant, Job job)
 public static void Prefix(LocalTargetInfo target, Pawn claimant, Job job)
 {
     if (claimant.IsFreeColonist &&
         target.Thing is IConstructible c && !(c is Blueprint_Install) &&
         job.def == JobDefOf.HaulToContainer)
     {
         ExpectingComp.Remove(q => q.claimant == claimant && q.job == job && q.claimed == target.Thing);
     }
 }
        public static List <ThingDefCountClass> FilterForExpected(List <ThingDefCountClass> materialsNeeded, Thing c)
        {
            List <ThingDefCountClass> needs = new List <ThingDefCountClass>(materialsNeeded.Count);

            foreach (var t in materialsNeeded)
            {
                needs.Add(new ThingDefCountClass(t.thingDef, t.count));
            }

            for (int i = 0; i < needs.Count; i++)
            {
                ThingDefCountClass thingNeeds = needs[i];
                thingNeeds.count -= ExpectingComp.ExpectedCount(c, thingNeeds.thingDef);
                if (thingNeeds.count <= 0)
                {
                    needs.Remove(thingNeeds);
                    i--;
                }
            }
            return(needs);
        }
        //public bool CanReserve(Pawn claimant, LocalTargetInfo target, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
        public static bool Prefix(Pawn claimant, LocalTargetInfo target, ref bool __result)
        {
            if (claimant.IsFreeColonist && target.Cell != LocalTargetInfo.Invalid)
            {
                if (claimant.Map.thingGrid.ThingsAt(target.Cell).FirstOrDefault(t => t is Building_ExtendedStorage) is Thing thing)
                {
                    Building_ExtendedStorage storage = thing as Building_ExtendedStorage;
                    Log.Message($"{claimant} can reserveES? {target.Cell} is {storage}");

                    int canDo    = storage.ApparentMaxStorage - storage.StoredThingTotal;
                    int expected = ExpectingComp.ExpectedCount(q => q.claimed == thing);

                    if (canDo > expected)
                    {
                        Log.Message($"{claimant} can reserveES {storage}");
                        __result = true;
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #8
0
 //public void ReleaseAllClaimedBy(Pawn claimant)
 public static void Prefix(Pawn claimant)
 {
     ExpectingComp.Remove(q => q.claimant == claimant);
 }
 public static int AdjustForExpected(int needed, Thing c, ThingDef resource)
 {
     return(needed - ExpectingComp.ExpectedCount(c, resource));
 }
예제 #10
0
 public static void Prefix(Thing __instance)
 {
     ExpectingComp.Remove(q => q.claimed == __instance);
 }