public static void Listener(Pawn healer, Pawn patient, ref Thing __result)
            {
                try
                {
                    //On ne soccupe que des patient étant des androids

                    /*if (!)
                     *  return true;*/


                    if (Settings.androidsCanUseOrganicMedicine)
                    {
                        return;
                    }

                    bool patientIsAndroid = Utils.ExceptionAndroidList.Contains(patient.def.defName) || patient.IsCyberAnimal();

                    if (patient.playerSettings == null || patient.playerSettings.medCare <= MedicalCareCategory.NoMeds)
                    {
                        __result = null;
                        return;
                    }
                    if (Medicine.GetMedicineCountToFullyHeal(patient) <= 0)
                    {
                        __result = null;
                        return;
                    }
                    Predicate <Thing> predicate;

                    //COmpatibilité avec pharmacist, le medoc renvoyé doit avoir une quantitée de soin inferieur ou egal à celui renvoyé par les appels précédents
                    float medicalPotency = 0;
                    if (__result != null)
                    {
                        medicalPotency = __result.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null);
                    }

                    if (patientIsAndroid)
                    {
                        predicate = (Thing m) => Utils.ExceptionNanoKits.Contains(m.def.defName) && m.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null) <= medicalPotency && !m.IsForbidden(healer) && patient.playerSettings.medCare.AllowsMedicine(m.def) && healer.CanReserve(m, 10, 1, null, false);
                    }
                    else
                    {
                        predicate = (Thing m) => !Utils.ExceptionNanoKits.Contains(m.def.defName) && m.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null) <= medicalPotency && !m.IsForbidden(healer) && !m.IsForbidden(healer) && patient.playerSettings.medCare.AllowsMedicine(m.def) && healer.CanReserve(m, 10, 1, null, false);
                    }

                    Func <Thing, float> priorityGetter = (Thing t) => t.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null);

                    IntVec3           position       = patient.Position;
                    Map               map            = patient.Map;
                    List <Thing>      searchSet      = patient.Map.listerThings.ThingsInGroup(ThingRequestGroup.Medicine);
                    PathEndMode       peMode         = PathEndMode.ClosestTouch;
                    TraverseParms     traverseParams = TraverseParms.For(healer, Danger.Deadly, TraverseMode.ByPawn, false);
                    Predicate <Thing> validator      = predicate;
                    __result = GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, priorityGetter);
                }
                catch (Exception e)
                {
                    Log.Message("[ATPP] HealthAIUtility.FindBestMedicine(Error) : " + e.Message + " - " + e.StackTrace);
                }
            }
        private Building_Grave FindBestGrave(Pawn p, Corpse corpse)
        {
            Predicate <Thing> predicate = delegate(Thing m)
            {
                if (!m.IsForbidden(p) && p.CanReserveNew(m))
                {
                    if (!((Building_Grave)m).Accepts(corpse))
                    {
                        return(false);
                    }
                    return(true);
                }
                return(false);
            };

            if (corpse.InnerPawn.ownership != null && corpse.InnerPawn.ownership.AssignedGrave != null)
            {
                Building_Grave assignedGrave = corpse.InnerPawn.ownership.AssignedGrave;
                if (predicate(assignedGrave) && p.Map.reachability.CanReach(corpse.Position, assignedGrave, PathEndMode.ClosestTouch, TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false)))
                {
                    return(assignedGrave);
                }
            }
            Func <Thing, float> priorityGetter = (Thing t) => (float)(int)((IStoreSettingsParent)t).GetStoreSettings().Priority;
            IntVec3             position       = corpse.Position;
            Map               map            = corpse.Map;
            List <Thing>      searchSet      = corpse.Map.listerThings.ThingsInGroup(ThingRequestGroup.Grave);
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            TraverseParms     traverseParams = TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false);
            Predicate <Thing> validator      = predicate;

            return((Building_Grave)GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, priorityGetter));
        }
Exemple #3
0
 private static Job GotoForce(Pawn pawn, LocalTargetInfo target, PathEndMode pathEndMode)
 {
     using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, target, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAnything, false), pathEndMode))
     {
         IntVec3 cellBeforeBlocker;
         Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
         if (thing != null)
         {
             Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true);
             if (job != null)
             {
                 return(job);
             }
         }
         if (thing == null)
         {
             return(new Job(JobDefOf.Goto, target, 100, true));
         }
         if (pawn.equipment.Primary != null)
         {
             Verb primaryVerb = pawn.equipment.PrimaryEq.PrimaryVerb;
             if (primaryVerb.verbProps.ai_IsBuildingDestroyer && (!primaryVerb.verbProps.ai_IsIncendiary || thing.FlammableNow))
             {
                 return(new Job(JobDefOf.UseVerbOnThing)
                 {
                     targetA = thing,
                     verbToUse = primaryVerb,
                     expiryInterval = 100
                 });
             }
         }
         return(MeleeOrWaitJob(pawn, thing, cellBeforeBlocker));
     }
 }
        private Thing FindIngredient(Pawn pawn, string thirdItem, Building_ItemProcessor building_processor)
        {
            if (building_processor.compItemProcessor.Props.isCategoryBuilding)
            {
                Predicate <Thing> predicate = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, 1, null, false);
                IntVec3           position  = pawn.Position;
                Map          map            = pawn.Map;
                List <Thing> searchSet      = new List <Thing>();
                foreach (ThingDef thingDef in ThingCategoryDef.Named(thirdItem).childThingDefs)
                {
                    if (!(DefDatabase <CombinationDef> .GetNamed(building_processor.thisRecipe).disallowedThingDefs != null &&
                          DefDatabase <CombinationDef> .GetNamed(building_processor.thisRecipe).disallowedThingDefs.Contains(thingDef.defName)))
                    {
                        searchSet.AddRange(pawn.Map.listerThings.ThingsOfDef(thingDef));
                    }
                }

                TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
                Predicate <Thing> validator      = predicate;
                PathEndMode       peMode         = PathEndMode.ClosestTouch;
                return(GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, searchSet, peMode, traverseParams, 9999f, validator, null));
            }
            else
            {
                Predicate <Thing> predicate      = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, 1, null, false);
                IntVec3           position       = pawn.Position;
                Map               map            = pawn.Map;
                ThingRequest      thingReq       = ThingRequest.ForDef(ThingDef.Named(thirdItem));
                PathEndMode       peMode         = PathEndMode.ClosestTouch;
                TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
                Predicate <Thing> validator      = predicate;
                return(GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
            }
        }
        protected override Thing BestIngestTarget(Pawn pawn)
        {
            ChemicalDef  chemical     = this.GetChemical(pawn);
            DrugCategory drugCategory = this.GetDrugCategory(pawn);

            if (chemical == null)
            {
                Log.ErrorOnce("Tried to binge on null chemical.", 1393746152, false);
                return(null);
            }
            Hediff            overdose  = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose, false);
            Predicate <Thing> predicate = delegate(Thing t)
            {
                if (!this.IgnoreForbid(pawn) && t.IsForbidden(pawn))
                {
                    return(false);
                }
                if (!pawn.CanReserve(t, 1, -1, null, false))
                {
                    return(false);
                }
                CompDrug compDrug = t.TryGetComp <CompDrug>();
                return(compDrug.Props.chemical == chemical && (overdose == null || !compDrug.Props.CanCauseOverdose || overdose.Severity + compDrug.Props.overdoseSeverityOffset.max < 0.786f) && (pawn.Position.InHorDistOf(t.Position, 60f) || t.Position.Roofed(t.Map) || pawn.Map.areaManager.Home[t.Position] || t.GetSlotGroup() != null) && t.def.ingestible.drugCategory.IncludedIn(drugCategory));
            };
            IntVec3           position       = pawn.Position;
            Map               map            = pawn.Map;
            ThingRequest      thingReq       = ThingRequest.ForGroup(ThingRequestGroup.Drug);
            PathEndMode       peMode         = PathEndMode.OnCell;
            TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
            Predicate <Thing> validator      = predicate;

            return(GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
        }
Exemple #6
0
        protected virtual Thing BestIngestItem(Pawn pawn, Predicate <Thing> extraValidator)
        {
            Predicate <Thing>  predicate      = (Thing t) => this.CanIngestForJoy(pawn, t) && (extraValidator == null || extraValidator(t));
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                if (this.SearchSetWouldInclude(innerContainer[i]) && predicate(innerContainer[i]))
                {
                    return(innerContainer[i]);
                }
            }
            JoyGiver_Ingest.tmpCandidates.Clear();
            this.GetSearchSet(pawn, JoyGiver_Ingest.tmpCandidates);
            if (JoyGiver_Ingest.tmpCandidates.Count == 0)
            {
                return(null);
            }
            IntVec3           position       = pawn.Position;
            Map               map            = pawn.Map;
            List <Thing>      searchSet      = JoyGiver_Ingest.tmpCandidates;
            PathEndMode       peMode         = PathEndMode.OnCell;
            TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
            Predicate <Thing> validator      = predicate;
            Thing             result         = GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, null);

            JoyGiver_Ingest.tmpCandidates.Clear();
            return(result);
        }
Exemple #7
0
        private Building_InternalStorage FindBestStorage(Pawn p, Thing book)
        {
            bool predicate(Thing m) => !m.IsForbidden(p) && p.CanReserveNew(m) && ((Building_InternalStorage)m).Accepts(book);

            float priorityGetter(Thing t)
            {
                var result = 0f;

                result += (float)((IStoreSettingsParent)t).GetStoreSettings().Priority;
                if (t is Building_InternalStorage bS && bS.TryGetInnerInteractableThingOwner()?.Count > 0)
                {
                    result -= bS.TryGetInnerInteractableThingOwner().Count;
                }

                return(result);
            }

            IntVec3           position       = book.Position;
            Map               map            = book.Map;
            List <Thing>      searchSet      = book.Map.listerThings.AllThings.FindAll(x => x is Building_InternalStorage);
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            var               traverseParams = TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false);
            Predicate <Thing> validator      = predicate;

            return((Building_InternalStorage)GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, priorityGetter));
        }
Exemple #8
0
        private Thing FindBestGame(Pawn pawn, bool inBed, IntVec3 partySpot)
        {
            JoyGiver_InteractBuilding.tmpCandidates.Clear();
            this.GetSearchSet(pawn, JoyGiver_InteractBuilding.tmpCandidates);
            if (JoyGiver_InteractBuilding.tmpCandidates.Count == 0)
            {
                return(null);
            }
            Predicate <Thing> predicate = (Thing t) => this.CanInteractWith(pawn, t, inBed);

            if (partySpot.IsValid)
            {
                Predicate <Thing> oldValidator = predicate;
                predicate = ((Thing x) => PartyUtility.InPartyArea(x.Position, partySpot, pawn.Map) && oldValidator(x));
            }
            IntVec3           position       = pawn.Position;
            Map               map            = pawn.Map;
            List <Thing>      searchSet      = JoyGiver_InteractBuilding.tmpCandidates;
            PathEndMode       peMode         = PathEndMode.OnCell;
            TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
            Predicate <Thing> validator      = predicate;
            Thing             result         = GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, null);

            JoyGiver_InteractBuilding.tmpCandidates.Clear();
            return(result);
        }
Exemple #9
0
        private static Thing FindNextFuelItem(Pawn pawn, Thing refuelable)
        {
            List <IngredientAndCostClass> ingredients = refuelable.def.GetModExtension <NPDModExtension>().ingredientList;
            int  i     = 0;
            bool found = false;

            for (i = 0; i < refuelable.TryGetComp <CompRefillable>().items.Count; i++)
            {
                if (refuelable.TryGetComp <CompRefillable>().items[i] < refuelable.def.GetCompProperties <CompProperties_Refillable>().itemCapacity)
                {
                    found = true;
                    break;
                }
            }
            ThingDef item     = null;
            int      quantity = 0;

            if (found)
            {
                item     = ingredients[i].thingDef;
                quantity = refuelable.TryGetComp <CompRefillable>().CountToRefill(i);
            }
            Predicate <Thing> validator    = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false) && x.def == item;
            IntVec3           position     = pawn.Position;
            Map           map              = pawn.Map;
            ThingRequest  itemThingRequest = ThingRequest.ForDef(item);
            PathEndMode   peMode           = PathEndMode.ClosestTouch;
            TraverseParms traverseParams   = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);

            return(GenClosest.ClosestThingReachable(position, map, itemThingRequest, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
        }
Exemple #10
0
        public static TargetInfo ResolvePathMode(Thing thing, TargetInfo dest, ref PathEndMode peMode)
        {
            if (dest.HasThing && !dest.Thing.Spawned)
            {
                peMode = PathEndMode.Touch;
                return(dest);
            }
            if (peMode == PathEndMode.InteractionCell)
            {
                if (!dest.HasThing)
                {
                    Log.Error("Pathed to cell " + dest + " with PathEndMode.InteractionCell.");
                }
                peMode = PathEndMode.OnCell;
                return(new TargetInfo(dest.Thing.InteractionCell, dest.Thing.Map, false));
            }

            // TODO: polish
            if (peMode == PathEndMode.ClosestTouch)
            {
                //peMode = GenPath.ResolveClosestTouchPathMode(pawn, dest.Map, dest.Cell);
                Log.Error("Unsupported PathEndMode");
            }

            return(dest);
        }
        public static bool PreFix(ref Toil __result, TargetIndex ind, PathEndMode peMode)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn actor = toil.actor;
                actor.pather.StartPath(actor.jobs.curJob.GetTarget(ind), peMode);
            };
            toil.AddPreTickAction(delegate()
            {
                Pawn actor = toil.actor;
                if (Gen.IsHashIntervalTick(actor, 240) && actor.jobs.curJob.GetTarget(ind).HasThing)
                {
                    Thing thing = actor.jobs.curJob.GetTarget(ind).Thing;
                    if (thing is Pawn && GenHostility.HostileTo(actor, thing as Pawn))
                    {
                        CamoAIUtility.JobFailIfHid(actor, thing as Pawn, actor.jobs.curJob);
                    }
                }
            });
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            __result = toil;
            return(false);
        }
Exemple #12
0
        public static Thing FindBestMedicine(Pawn healer, Pawn patient)
        {
            Thing result;

            if (patient.playerSettings == null || patient.playerSettings.medCare <= MedicalCareCategory.NoMeds)
            {
                result = null;
            }
            else if (Medicine.GetMedicineCountToFullyHeal(patient) <= 0)
            {
                result = null;
            }
            else
            {
                Predicate <Thing>   predicate      = (Thing m) => !m.IsForbidden(healer) && patient.playerSettings.medCare.AllowsMedicine(m.def) && healer.CanReserve(m, 10, 1, null, false);
                Func <Thing, float> priorityGetter = (Thing t) => t.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null);
                IntVec3             position       = patient.Position;
                Map               map            = patient.Map;
                List <Thing>      searchSet      = patient.Map.listerThings.ThingsInGroup(ThingRequestGroup.Medicine);
                PathEndMode       peMode         = PathEndMode.ClosestTouch;
                TraverseParms     traverseParams = TraverseParms.For(healer, Danger.Deadly, TraverseMode.ByPawn, false);
                Predicate <Thing> validator      = predicate;
                result = GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, priorityGetter);
            }
            return(result);
        }
        // Token: 0x060000E0 RID: 224 RVA: 0x000070E0 File Offset: 0x000052E0
        public static bool CanConstruct(Thing t, Pawn p, bool forced = false)
        {
            bool flag = GenConstruct.FirstBlockingThing(t, p) != null;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                LocalTargetInfo target    = t;
                PathEndMode     peMode    = PathEndMode.Touch;
                Danger          maxDanger = (!forced) ? p.NormalMaxDanger() : Danger.Deadly;
                bool            flag2     = !p.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced);
                if (flag2)
                {
                    result = false;
                }
                else
                {
                    bool flag3 = t.IsBurning();
                    if (flag3)
                    {
                        result = false;
                    }
                    else
                    {
                        bool animal = p.RaceProps.Animal;
                        result = (!animal || true);
                    }
                }
            }
            return(result);
        }
 private static UnfinishedThing ClosestUnfinishedThingForBill(Pawn pawn, Bill_ProductionWithUft bill)
 {
     if (ModCheck.Validate.NoJobAuthors.IsInitialized())
     {
         Predicate <Thing> predicate      = (Thing t) => !t.IsForbidden(pawn) && ((UnfinishedThing)t).Recipe == bill.recipe && ((UnfinishedThing)t).ingredients.TrueForAll((Thing x) => bill.IsFixedOrAllowedIngredient(x.def));
         IntVec3           position       = pawn.Position;
         Map               map            = pawn.Map;
         ThingRequest      thingReq       = ThingRequest.ForDef(bill.recipe.unfinishedThingDef);
         PathEndMode       peMode         = PathEndMode.InteractionCell;
         TraverseParms     traverseParams = TraverseParms.For(pawn, pawn.NormalMaxDanger());
         Predicate <Thing> validator      = predicate;
         return((UnfinishedThing)GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator));
     }
     else
     {
         Predicate <Thing> predicate      = (Thing t) => !t.IsForbidden(pawn) && ((UnfinishedThing)t).Recipe == bill.recipe && ((UnfinishedThing)t).Creator == pawn && ((UnfinishedThing)t).ingredients.TrueForAll((Thing x) => bill.IsFixedOrAllowedIngredient(x.def)) && pawn.CanReserve(t);
         IntVec3           position       = pawn.Position;
         Map               map            = pawn.Map;
         ThingRequest      thingReq       = ThingRequest.ForDef(bill.recipe.unfinishedThingDef);
         PathEndMode       peMode         = PathEndMode.InteractionCell;
         TraverseParms     traverseParams = TraverseParms.For(pawn, pawn.NormalMaxDanger());
         Predicate <Thing> validator      = predicate;
         return((UnfinishedThing)GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator));
     }
 }
Exemple #15
0
        public static Thing FindBestMedicine(Pawn healer, Pawn patient)
        {
            if (patient.playerSettings == null || (int)patient.playerSettings.medCare <= 1)
            {
                return(null);
            }
            if (Medicine.GetMedicineCountToFullyHeal(patient) <= 0)
            {
                return(null);
            }
            Predicate <Thing> predicate = delegate(Thing m)
            {
                if (m.IsForbidden(healer) || !patient.playerSettings.medCare.AllowsMedicine(m.def) || !healer.CanReserve(m, 10, 1))
                {
                    return(false);
                }
                return(true);
            };
            Func <Thing, float> priorityGetter = (Thing t) => t.def.GetStatValueAbstract(StatDefOf.MedicalPotency);
            IntVec3             position       = patient.Position;
            Map               map            = patient.Map;
            List <Thing>      searchSet      = patient.Map.listerThings.ThingsInGroup(ThingRequestGroup.Medicine);
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            TraverseParms     traverseParams = TraverseParms.For(healer);
            Predicate <Thing> validator      = predicate;

            return(GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, priorityGetter));
        }
Exemple #16
0
        protected override Thing FindTarget(Pawn pawn)
        {
            Thing             searcher               = pawn;
            Pawn              searcherPawn           = pawn;
            const float       maxDist                = MaxAttackDistance;
            const bool        canBash                = true;
            Predicate <Thing> predicate              = (Thing x) => x is Building;
            const int         searchRegionsMin       = 0;
            const int         searchRegionsMax       = 40;
            RegionType        traversableRegionTypes = RegionType.Set_Passable;
            IntVec3           arg_25D_0              = pawn.Position;
            Map          map       = pawn.Map;
            ThingRequest arg_25D_1 = ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial);
            PathEndMode  arg_25D_2 = PathEndMode.Touch;

            Thing thing = GenClosest.ClosestThingReachable(
                arg_25D_0,
                map,
                arg_25D_1,
                arg_25D_2,
                TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, canBash),
                maxDist,
                predicate,
                null,
                searchRegionsMin,
                searchRegionsMax,
                false,
                traversableRegionTypes,
                false);

            return(thing);
        }
Exemple #17
0
        public static TargetInfo ResolvePathMode(Pawn pawn, TargetInfo dest, ref PathEndMode peMode)
        {
            TargetInfo result;

            if (dest.HasThing && !dest.Thing.Spawned)
            {
                peMode = PathEndMode.Touch;
                result = dest;
            }
            else if (peMode == PathEndMode.InteractionCell)
            {
                if (!dest.HasThing)
                {
                    Log.Error("Pathed to cell " + dest + " with PathEndMode.InteractionCell.", false);
                }
                peMode = PathEndMode.OnCell;
                result = new TargetInfo(dest.Thing.InteractionCell, dest.Thing.Map, false);
            }
            else
            {
                if (peMode == PathEndMode.ClosestTouch)
                {
                    peMode = GenPath.ResolveClosestTouchPathMode(pawn, dest.Map, dest.Cell);
                }
                result = dest;
            }
            return(result);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnAggroMentalState(TargetIndex.A);
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOn(delegate
            {
                return(!Deliveree.OnBaseMechanoidPlatform());
            });
            Need_Maintenance need         = Deliveree.needs.TryGetNeed <Need_Maintenance>() as Need_Maintenance;
            Toil             reserveParts = null;

            reserveParts = ReserveParts(TargetIndex.B, need).FailOnDespawnedNullOrForbidden(TargetIndex.B);
            yield return(reserveParts);

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.B));

            yield return(PickupParts(TargetIndex.B, need).FailOnDestroyedOrNull(TargetIndex.B));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveParts, TargetIndex.B, TargetIndex.None, true, null));

            PathEndMode interactionCell = (this.Deliveree != this.pawn) ? PathEndMode.InteractionCell : PathEndMode.OnCell;

            yield return(Toils_Goto.GotoThing(TargetIndex.A, interactionCell));

            int         duration = (int)(1f / this.pawn.GetStatValue(WTH_DefOf.WTH_HackingMaintenanceSpeed, true) * 600f);
            EffecterDef effect   = DefDatabase <EffecterDef> .AllDefs.FirstOrDefault((EffecterDef ed) => ed.defName == "Repair");

            yield return(Toils_General.Wait(duration, TargetIndex.None).FailOnCannotTouch(TargetIndex.A, interactionCell).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f).WithEffect(effect, TargetIndex.A));

            yield return(FinalizeMaintenance(this.Deliveree, need, reserveParts));
        }
Exemple #19
0
        private IEnumerable <Toil> ChargeToils(IChargeSource charger, PathEndMode pathMode, Action initAction, Action tickAction)
        {
            this.FailOnDestroyedOrNull(PowerSourceIndex);
            this.FailOn(() => !charger.Available);
            this.FailOn(() =>
                        EnergyNeed == null ||
                        !EnergyNeed.CanBeSatisfied ||
                        EnergyNeed.Satisfied ||
                        charger == null ||
                        !charger.Available ||
                        !pawn.CanReach(PowerSource, pathMode, Danger.Deadly));

            yield return(Toils_Goto
                         .GotoThing(PowerSourceIndex, pathMode)
                         .FailOnDestroyedNullOrForbidden(PowerSourceIndex));

            var charge = new Toil()
                         .WithProgressBar(PowerSourceIndex, () => EnergyNeed.CurLevelPercentage, true);

            charge.defaultCompleteMode = ToilCompleteMode.Never;
            charge.AddEndCondition(() =>
                                   EnergyNeed.Satisfied
                    ? JobCondition.Succeeded
                    : JobCondition.Ongoing);
            if (initAction != null)
            {
                charge.initAction = initAction;
            }
            if (tickAction != null)
            {
                charge.tickAction = tickAction;
            }
            yield return(charge);
        }
 private void CalculateAndAddDisallowedCorners(TraverseParms traverseParms, PathEndMode peMode, CellRect destinationRect)
 {
     this.disallowedCornerIndices.Clear();
     if (peMode == PathEndMode.Touch)
     {
         int minX = destinationRect.minX;
         int minZ = destinationRect.minZ;
         int maxX = destinationRect.maxX;
         int maxZ = destinationRect.maxZ;
         if (!this.IsCornerTouchAllowed(minX + 1, minZ + 1, minX + 1, minZ, minX, minZ + 1))
         {
             this.disallowedCornerIndices.Add(this.map.cellIndices.CellToIndex(minX, minZ));
         }
         if (!this.IsCornerTouchAllowed(minX + 1, maxZ - 1, minX + 1, maxZ, minX, maxZ - 1))
         {
             this.disallowedCornerIndices.Add(this.map.cellIndices.CellToIndex(minX, maxZ));
         }
         if (!this.IsCornerTouchAllowed(maxX - 1, maxZ - 1, maxX - 1, maxZ, maxX, maxZ - 1))
         {
             this.disallowedCornerIndices.Add(this.map.cellIndices.CellToIndex(maxX, maxZ));
         }
         if (!this.IsCornerTouchAllowed(maxX - 1, minZ + 1, maxX - 1, minZ, maxX, minZ + 1))
         {
             this.disallowedCornerIndices.Add(this.map.cellIndices.CellToIndex(maxX, minZ));
         }
     }
 }
        public static bool TryFindBestItemToSteal(IntVec3 root, Map map, float maxDist, out Thing item, Pawn thief, List <Thing> disallowed = null)
        {
            if (thief != null && !thief.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                item = null;
                return(false);
            }
            if ((thief != null && !map.reachability.CanReachMapEdge(thief.Position, TraverseParms.For(thief, Danger.Some, TraverseMode.ByPawn, false))) || (thief == null && !map.reachability.CanReachMapEdge(root, TraverseParms.For(TraverseMode.PassDoors, Danger.Some, false))))
            {
                item = null;
                return(false);
            }
            Predicate <Thing> predicate      = (Thing t) => (thief == null || thief.CanReserve(t, 1, -1, null, false)) && (disallowed == null || !disallowed.Contains(t)) && t.def.stealable && !t.IsBurning();
            ThingRequest      thingReq       = ThingRequest.ForGroup(ThingRequestGroup.HaulableEverOrMinifiable);
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            TraverseParms     traverseParams = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Some, false);
            Predicate <Thing> validator      = predicate;

            if (StealAIUtility.< > f__mg$cache0 == null)
            {
                StealAIUtility.< > f__mg$cache0 = new Func <Thing, float>(StealAIUtility.GetValue);
            }
            item = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(root, map, thingReq, peMode, traverseParams, maxDist, validator, StealAIUtility.< > f__mg$cache0, 15, 15);
            if (item != null && StealAIUtility.GetValue(item) < 320f)
            {
                item = null;
            }
            return(item != null);
        }
Exemple #22
0
        // Token: 0x060000EA RID: 234 RVA: 0x00008318 File Offset: 0x00006518
        public static void CanConstruct_Prefix(ref bool __result, Thing t, Pawn p, bool checkSkills = true, bool forced = false)
        {
            bool flag = !p.kindDef.RaceProps.Humanlike;

            if (flag)
            {
                bool flag2 = GenConstruct.FirstBlockingThing(t, p) != null;
                if (flag2)
                {
                    __result = false;
                }
                LocalTargetInfo target    = t;
                PathEndMode     peMode    = PathEndMode.Touch;
                Danger          maxDanger = (!forced) ? p.NormalMaxDanger() : Danger.Deadly;
                bool            flag3     = !p.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced);
                if (flag3)
                {
                    __result = false;
                }
                bool flag4 = t.IsBurning();
                if (flag4)
                {
                    __result = false;
                }
                __result = true;
            }
            __result = false;
        }
        public static bool CanConstruct(Thing t, Pawn p, bool checkConstructionSkill = true, bool forced = false)
        {
            if (GenConstruct.FirstBlockingThing(t, p) != null)
            {
                return(false);
            }
            LocalTargetInfo target    = t;
            PathEndMode     peMode    = PathEndMode.Touch;
            Danger          maxDanger = (!forced) ? p.NormalMaxDanger() : Danger.Deadly;

            if (!p.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
            {
                return(false);
            }
            if (t.IsBurning())
            {
                return(false);
            }
            if (checkConstructionSkill && p.skills.GetSkill(SkillDefOf.Construction).Level < t.def.constructionSkillPrerequisite)
            {
                JobFailReason.Is(GenConstruct.ConstructionSkillTooLowTrans, null);
                return(false);
            }
            return(true);
        }
        public static Job HandleBlockingThingJob(Thing constructible, Pawn worker, bool forced = false)
        {
            Thing thing = GenConstruct.FirstBlockingThing(constructible, worker);
            Job   result;

            if (thing == null)
            {
                result = null;
            }
            else
            {
                if (thing.def.category == ThingCategory.Plant)
                {
                    LocalTargetInfo target    = thing;
                    PathEndMode     peMode    = PathEndMode.ClosestTouch;
                    Danger          maxDanger = worker.NormalMaxDanger();
                    if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.CutPlant, thing));
                    }
                }
                else if (thing.def.category == ThingCategory.Item)
                {
                    if (thing.def.EverHaulable)
                    {
                        return(HaulAIUtility.HaulAsideJobFor(worker, thing));
                    }
                    Log.ErrorOnce(string.Concat(new object[]
                    {
                        "Never haulable ",
                        thing,
                        " blocking ",
                        constructible.ToStringSafe <Thing>(),
                        " at ",
                        constructible.Position
                    }), 6429262, false);
                }
                else if (thing.def.category == ThingCategory.Building)
                {
                    if (worker.story != null && worker.story.WorkTypeIsDisabled(WorkTypeDefOf.Construction))
                    {
                        JobFailReason.Is(GenConstruct.IncapableOfDeconstruction, null);
                        return(null);
                    }
                    LocalTargetInfo target    = thing;
                    PathEndMode     peMode    = PathEndMode.Touch;
                    Danger          maxDanger = worker.NormalMaxDanger();
                    if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.Deconstruct, thing)
                        {
                            ignoreDesignations = true
                        });
                    }
                }
                result = null;
            }
            return(result);
        }
        public static bool TryFindBestExitSpot(Pawn pawn, out IntVec3 spot, TraverseMode mode = TraverseMode.ByPawn)
        {
            if (mode == TraverseMode.PassAllDestroyableThings && !pawn.Map.reachability.CanReachMapEdge(pawn.Position, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, true)))
            {
                return(RCellFinder_Zombiefied.TryFindRandomPawnEntryCell(out spot, pawn.Map, 0f, true, delegate(IntVec3 x)
                {
                    Pawn pawn2 = pawn;
                    LocalTargetInfo dest = x;
                    PathEndMode peMode = PathEndMode.OnCell;
                    Danger maxDanger = Danger.Deadly;
                    TraverseMode mode2 = mode;
                    return pawn2.CanReach(dest, peMode, maxDanger, false, mode2);
                }));
            }
            int     num  = 0;
            int     num2 = 0;
            IntVec3 intVec2;

            while (true)
            {
                num2++;
                if (num2 > 30)
                {
                    break;
                }
                IntVec3 intVec;
                bool    flag = CellFinder.TryFindRandomCellNear(pawn.Position, pawn.Map, num, null, out intVec, -1);
                num += 4;
                if (flag)
                {
                    int num3 = intVec.x;
                    intVec2 = new IntVec3(0, 0, intVec.z);
                    if (pawn.Map.Size.z - intVec.z < num3)
                    {
                        num3    = pawn.Map.Size.z - intVec.z;
                        intVec2 = new IntVec3(intVec.x, 0, pawn.Map.Size.z - 1);
                    }
                    if (pawn.Map.Size.x - intVec.x < num3)
                    {
                        num3    = pawn.Map.Size.x - intVec.x;
                        intVec2 = new IntVec3(pawn.Map.Size.x - 1, 0, intVec.z);
                    }
                    if (intVec.z < num3)
                    {
                        intVec2 = new IntVec3(intVec.x, 0, 0);
                    }
                    if (intVec2.Standable(pawn.Map) && pawn.CanReach(intVec2, PathEndMode.OnCell, Danger.Deadly, true, mode))
                    {
                        goto Block_9;
                    }
                }
            }
            spot = pawn.Position;
            return(false);

Block_9:
            spot = intVec2;
            return(true);
        }
Exemple #26
0
        public static bool TryFindRandomExitSpot(Pawn pawn, out IntVec3 spot, TraverseMode mode = TraverseMode.ByPawn)
        {
            Danger danger = Danger.Some;
            int    num    = 0;

            goto IL_0004;
IL_0004:
            IntVec3 intVec;

            while (true)
            {
                num++;
                if (num > 40)
                {
                    spot = pawn.Position;
                    return(false);
                }
                if (num > 15)
                {
                    danger = Danger.Deadly;
                }
                intVec = CellFinder.RandomCell(pawn.Map);
                int num2 = Rand.RangeInclusive(0, 3);
                if (num2 == 0)
                {
                    intVec.x = 0;
                }
                if (num2 == 1)
                {
                    IntVec3 size = pawn.Map.Size;
                    intVec.x = size.x - 1;
                }
                if (num2 == 2)
                {
                    intVec.z = 0;
                }
                if (num2 == 3)
                {
                    IntVec3 size2 = pawn.Map.Size;
                    intVec.z = size2.z - 1;
                }
                if (intVec.Standable(pawn.Map))
                {
                    LocalTargetInfo dest      = intVec;
                    PathEndMode     peMode    = PathEndMode.OnCell;
                    Danger          maxDanger = danger;
                    TraverseMode    mode2     = mode;
                    if (pawn.CanReach(dest, peMode, maxDanger, canBash: false, mode2))
                    {
                        break;
                    }
                }
            }
            spot = intVec;
            return(true);

IL_00ee:
            goto IL_0004;
        }
        public ThingPath FindPath(IntVec3 start, LocalTargetInfo dest, Thing thing, PathEndMode peMode = PathEndMode.OnCell)
        {
            bool canBash = false;

            /*if (thing != null && pawn.CurJob != null && pawn.CurJob.canBash)
             *  canBash = true;*/
            return(this.FindPath(start, dest, TraverseParms.For(thing, Danger.Deadly, TraverseMode.ByPawn, canBash), peMode));
        }
 public static bool CanReach(this Pawn pawn, LocalTargetInfo dest, PathEndMode peMode, Danger maxDanger, bool canBash = false, TraverseMode mode = TraverseMode.ByPawn)
 {
     if (!pawn.Spawned)
     {
         return(false);
     }
     return(pawn.Map.reachability.CanReach(pawn.Position, dest, peMode, TraverseParms.For(pawn, maxDanger, mode, canBash)));
 }
        private CellRect CalculateDestinationRect(LocalTargetInfo dest, PathEndMode peMode)
        {
            CellRect result;

            result = (!dest.HasThing || peMode == PathEndMode.OnCell) ? CellRect.SingleCell(dest.Cell) : dest.Thing.OccupiedRect();
            result = (peMode == PathEndMode.Touch) ? result.ExpandedBy(1) : result;
            return(result);
        }
 public static bool CanReserveAndReach(this Pawn p, LocalTargetInfo target, PathEndMode peMode, Danger maxDanger, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
 {
     if (!p.Spawned)
     {
         return(false);
     }
     return(p.CanReach(target, peMode, maxDanger, false, TraverseMode.ByPawn) && p.Map.reservationManager.CanReserve(p, target, maxPawns, stackCount, layer, ignoreOtherReservations));
 }
        public Toil GotoThing(IntVec3 cell, PathEndMode PathEndMode)
        {
            Toil toil = new Toil();
            TargetInfo target = new TargetInfo(cell);

            toil.initAction = delegate
            {
                Pawn actor = toil.actor;
                actor.pather.StartPath(target, PathEndMode);
            };

            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            return toil;
        }
        public static Thing ClosestThing_Global_Reachable(IntVec3 center, IEnumerable<Thing> searchSet, PathEndMode pathMode, TraverseParms traverseParams, float maxDistance, Pawn pawn)
        {
            if (searchSet == null)
            {
                return null;
            }
            int num = 0;
            int num2 = 0;
            Thing result = null;
            int num3 = -2147483648;
            int num4 = 0;
            float num5 = maxDistance * maxDistance;
            float num6 = 2.14748365E+09f;
            foreach (Thing current in searchSet)
            {
                num2++;
                float lengthHorizontalSquared = (center - current.Position).LengthHorizontalSquared;
                if (lengthHorizontalSquared <= num5)
                {
                    if (num4 > num3 || lengthHorizontalSquared < num6)
                    {
                        if (center.CanReach(current, pathMode, traverseParams))
                        {
                            if (current.SpawnedInWorld)
                            {

                                if(((Building_DroidChargePad)current).IsAvailable(pawn))
                                {
                                    result = current;
                                    num6 = lengthHorizontalSquared;
                                    num3 = num4;
                                    num++;
                                }
                            }
                        }
                    }
                }
            }
            return result;
        }