public override Job JobOnThing(Pawn pawn, Thing t) { Vehicle_Cart cart = t as Vehicle_Cart; if (cart == null) { return((Job)null); } if (cart.IsForbidden(pawn.Faction) || !ReservationUtility.CanReserveAndReach(pawn, cart, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(pawn))) { return((Job)null); } if (FireUtility.IsBurning(cart)) { JobFailReason.Is(ToolsForHaulUtility.BurningLowerTrans); return((Job)null); } if (ListerHaulables.ThingsPotentiallyNeedingHauling().Count == 0 && cart.storage.Count == 0) { JobFailReason.Is(ToolsForHaulUtility.NoHaulable); return((Job)null); } if (Find.SlotGroupManager.AllGroupsListInPriorityOrder.Count == 0) { JobFailReason.Is(ToolsForHaulUtility.NoEmptyPlaceLowerTrans); return((Job)null); } if (ToolsForHaulUtility.AvailableAnimalCart(cart) || ToolsForHaulUtility.AvailableCart(cart, pawn)) { return(ToolsForHaulUtility.HaulWithTools(pawn, cart)); } JobFailReason.Is(ToolsForHaulUtility.NoAvailableCart); return((Job)null); }
// Token: 0x0600003C RID: 60 RVA: 0x00002F10 File Offset: 0x00001110 public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { CompUniversalFermenter compUniversalFermenter = ThingCompUtility.TryGetComp <CompUniversalFermenter>(t); if (compUniversalFermenter == null || compUniversalFermenter.Fermented || compUniversalFermenter.SpaceLeftForIngredient <= 0) { return(false); } float ambientTemperature = compUniversalFermenter.parent.AmbientTemperature; if (ambientTemperature < compUniversalFermenter.Product.temperatureSafe.min + 2f || ambientTemperature > compUniversalFermenter.Product.temperatureSafe.max - 2f) { JobFailReason.Is(WorkGiver_FillUniversalFermenter.TemperatureTrans, null); return(false); } if (ForbidUtility.IsForbidden(t, pawn) || !ReservationUtility.CanReserveAndReach(pawn, t, (PathEndMode)2, DangerUtility.NormalMaxDanger(pawn), 1, -1, null, forced)) { return(false); } if (pawn.Map.designationManager.DesignationOn(t, DesignationDefOf.Deconstruct) != null) { return(false); } if (this.FindIngredient(pawn, t) == null) { JobFailReason.Is(WorkGiver_FillUniversalFermenter.NoIngredientTrans, null); return(false); } return(!FireUtility.IsBurning(t)); }
public static Toil CheckDuplicates(Toil jumpToil, TargetIndex CarrierInd, TargetIndex HaulableInd) { Toil toil = new Toil(); toil.initAction = () => { IntVec3 storeCell = IntVec3.Invalid; Pawn actor = toil.GetActor(); TargetInfo target = toil.actor.jobs.curJob.GetTarget(HaulableInd); if (target.Thing.def.stackLimit <= 1) { return; } List <TargetInfo> targetQueue = toil.actor.jobs.curJob.GetTargetQueue(HaulableInd); if (!targetQueue.NullOrEmpty() && target.Thing.def.defName == targetQueue.First().Thing.def.defName) { toil.actor.jobs.curJob.SetTarget(HaulableInd, targetQueue.First()); Find.Reservations.Reserve(actor, targetQueue.First()); targetQueue.RemoveAt(0); toil.actor.jobs.curDriver.JumpToToil(jumpToil); return; } Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart; Apparel_Backpack backpack = toil.actor.jobs.curJob.GetTarget(CarrierInd).Thing as Apparel_Backpack; if (cart == null && backpack == null) { Log.Error(actor.LabelCap + " Report: Don't have Carrier"); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); return; } int curItemCount = (cart != null ? cart.storage.Count : actor.inventory.container.Count) + targetQueue.Count; int curItemStack = (cart != null ? cart.storage.TotalStackCount : actor.inventory.container.TotalStackCount) + targetQueue.Sum(item => item.Thing.stackCount); int maxItem = cart != null ? cart.MaxItem : backpack.MaxItem; int maxStack = cart != null ? cart.MaxStack : backpack.MaxStack; if (curItemCount >= maxItem || curItemStack >= maxStack) { return; } //Check target's nearby Thing thing = GenClosest.ClosestThing_Global_Reachable(actor.Position, ListerHaulables.ThingsPotentiallyNeedingHauling(), PathEndMode.Touch, TraverseParms.For(actor, Danger.Some), NearbyCell, item => !targetQueue.Contains(item) && item.def.defName == target.Thing.def.defName && !FireUtility.IsBurning(item) && Find.Reservations.CanReserve(actor, item)); if (thing != null) { toil.actor.jobs.curJob.SetTarget(HaulableInd, thing); Find.Reservations.Reserve(actor, thing); toil.actor.jobs.curDriver.JumpToToil(jumpToil); return; } }; return(toil); }
// Token: 0x06000032 RID: 50 RVA: 0x000035FC File Offset: 0x000017FC internal bool JPComposMentis(Pawn pilot, Thing JP, out string Reason) { Reason = ""; if (pilot == null) { Reason = Translator.Translate("JetPack.ReasonNotFound"); return(false); } if (FireUtility.IsBurning(pilot)) { Reason = Translator.Translate("JetPack.ReasonOnFire"); return(false); } if (pilot.Dead) { Reason = Translator.Translate("JetPack.ReasonDead"); return(false); } if (pilot.InMentalState) { Reason = Translator.Translate("JetPack.ReasonMental"); return(false); } if (pilot.Downed || pilot.stances.stunner.Stunned) { Reason = Translator.Translate("JetPack.ReasonIncap"); return(false); } if (!RestUtility.Awake(pilot) || !pilot.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { Reason = Translator.Translate("JetPack.ReasonOperate") + GenText.CapitalizeFirst(JP.Label); return(false); } return(true); }
public static Building_BaseRobotRechargeStation FindRechargeStationFor(ArcBaseRobot sleeper, ArcBaseRobot traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool medicalBedNeeded = false) { Predicate <Thing> predicate = delegate(Thing t) { bool flag3 = !ReservationUtility.CanReserveAndReach(traveler, t, PathEndMode.OnCell, Danger.Some, 1, -1, null, false); bool result2; if (flag3) { result2 = false; } else { Building_BaseRobotRechargeStation rechargeStation = t as Building_BaseRobotRechargeStation; bool flag4 = rechargeStation == null; if (flag4) { result2 = false; } else { bool flag5 = rechargeStation.robot != null && rechargeStation.robot != sleeper; if (flag5) { result2 = false; } else { bool flag6 = ForbidUtility.IsForbidden(rechargeStation, traveler); if (flag6) { result2 = false; } else { bool flag7 = FireUtility.IsBurning(rechargeStation); result2 = !flag7; } } } } return(result2); }; bool flag = sleeper.rechargeStation != null && predicate(sleeper.rechargeStation); Building_BaseRobotRechargeStation result; if (flag) { Building_BaseRobotRechargeStation rechargeStation = sleeper.rechargeStation; bool flag2 = rechargeStation != null; if (flag2) { result = rechargeStation; return(result); } } result = null; return(result); }
public static Job HaulWithTools(Pawn pawn, Vehicle_Cart cart = null) { Trace.stopWatchStart(); //Job Setting JobDef jobDef; TargetInfo targetC; int maxItem; int thresholdItem; int reservedMaxItem; IEnumerable <Thing> remainingItems; bool ShouldDrop; Thing lastItem = ToolsForHaulUtility.TryGetBackpackLastItem(pawn); if (cart == null) { Apparel_Backpack backpack = ToolsForHaulUtility.TryGetBackpack(pawn); jobDef = jobDefHaulWithBackpack; targetC = backpack; maxItem = backpack.MaxItem; thresholdItem = (int)Math.Ceiling(maxItem * 0.5); reservedMaxItem = pawn.inventory.container.Count; remainingItems = pawn.inventory.container; ShouldDrop = true; if (lastItem != null) { for (int i = 0; i < pawn.inventory.container.Count; i++) { if (pawn.inventory.container[i] == lastItem && (reservedMaxItem - (i + 1)) <= 0) { ShouldDrop = false; break; } } } } else { jobDef = (cart.TryGetComp <CompMountable>().IsMounted&& cart.TryGetComp <CompMountable>().Driver.RaceProps.Animal)? jobDefHaulWithAnimalCart : jobDefHaulWithCart; targetC = cart; maxItem = cart.MaxItem; thresholdItem = (int)Math.Ceiling(maxItem * 0.5); reservedMaxItem = cart.storage.Count; remainingItems = cart.storage; ShouldDrop = (reservedMaxItem > 0) ? true : false; } Job job = new Job(jobDef); job.targetQueueA = new List <TargetInfo>(); job.targetQueueB = new List <TargetInfo>(); job.targetC = targetC; Trace.AppendLine(pawn.LabelCap + " In HaulWithTools: " + jobDef.defName + "\n" + "MaxItem: " + maxItem + " reservedMaxItem: " + reservedMaxItem); //Drop remaining item if (ShouldDrop) { Trace.AppendLine("Start Drop remaining item"); bool startDrop = false; for (int i = 0; i < remainingItems.Count(); i++) { if (cart == null && startDrop == false) { if (remainingItems.ElementAt(i) == lastItem) { startDrop = true; } else { continue; } } IntVec3 storageCell = FindStorageCell(pawn, remainingItems.ElementAt(i), job.targetQueueB); if (storageCell == IntVec3.Invalid) { break; } job.targetQueueB.Add(storageCell); } if (!job.targetQueueB.NullOrEmpty()) { Trace.AppendLine("Droping Job is issued"); Trace.LogMessage(); return(job); } if (cart != null && job.def == jobDefHaulWithCart && !cart.IsInValidStorage()) { Trace.AppendLine("In DismountInBase"); return(DismountInBase(pawn, cart)); } JobFailReason.Is(ToolsForHaulUtility.NoEmptyPlaceLowerTrans); Trace.AppendLine("End Drop remaining item"); Trace.AppendLine("No Job. Reason: " + JobFailReason.Reason); Trace.LogMessage(); return((Job)null); } //Collect item Trace.AppendLine("Start Collect item"); IntVec3 searchPos = (cart != null) ? cart.Position : pawn.Position; bool flag1 = false; foreach (SlotGroup slotGroup in Find.SlotGroupManager.AllGroupsListInPriorityOrder) { Trace.AppendLine("Start searching slotGroup"); if (slotGroup.CellsList.Count() - slotGroup.HeldThings.Count() < maxItem) { continue; } //Counting valid items Trace.AppendLine("Start Counting valid items"); int thingsCount = ListerHaulables.ThingsPotentiallyNeedingHauling().Count(item => slotGroup.Settings.AllowedToAccept(item)); //Finding valid items Trace.AppendLine("Start Finding valid items"); if (thingsCount > thresholdItem) { //ClosestThing_Global_Reachable Configuration Predicate <Thing> predicate = item => !job.targetQueueA.Contains(item) && !FireUtility.IsBurning(item) && ((cart != null && cart.allowances.Allows(item)) || cart == null) && slotGroup.Settings.AllowedToAccept(item) && pawn.CanReserveAndReach(item, PathEndMode.Touch, DangerUtility.NormalMaxDanger(pawn)); //&& !(item is UnfinishedThing && ((UnfinishedThing)item).BoundBill != null) //&& (item.def.IsNutritionSource && !SocialProperness.IsSociallyProper(item, pawn, false, false)); Thing thing = GenClosest.ClosestThing_Global_Reachable(searchPos, ListerHaulables.ThingsPotentiallyNeedingHauling(), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.ByPawn, DangerUtility.NormalMaxDanger(pawn)), 9999, predicate); if (thing == null) { continue; } IntVec3 center = thing.Position; //Enqueue items in valid distance Trace.AppendLine("Start Enqueuing items in valid distance"); foreach (Thing item in ListerHaulables.ThingsPotentiallyNeedingHauling().Where(item => !job.targetQueueA.Contains(item) && !FireUtility.IsBurning(item) && ((cart != null && cart.allowances.Allows(item)) || cart == null) && slotGroup.Settings.AllowedToAccept(item) && pawn.CanReserveAndReach(item, PathEndMode.Touch, DangerUtility.NormalMaxDanger(pawn)) && center.DistanceToSquared(item.Position) <= ValidDistance)) { job.targetQueueA.Add(item); if (reservedMaxItem + job.targetQueueA.Count >= maxItem) { break; } } //Find storage cell Trace.AppendLine("Start Finding storage cell"); if (reservedMaxItem + job.targetQueueA.Count > thresholdItem) { List <IntVec3> availableCells = new List <IntVec3>(); foreach (IntVec3 cell in slotGroup.CellsList.Where(cell => ReservationUtility.CanReserve(pawn, cell) && cell.Standable() && cell.GetStorable() == null)) { job.targetQueueB.Add(cell); if (job.targetQueueB.Count >= job.targetQueueA.Count) { break; } } flag1 = true; break; } else { job.targetQueueA.Clear(); } } if (flag1) { break; } } Trace.AppendLine("Elapsed Time"); Trace.stopWatchStop(); //Check job is valid if (!job.targetQueueA.NullOrEmpty() && reservedMaxItem + job.targetQueueA.Count > thresholdItem && !job.targetQueueB.NullOrEmpty()) { Trace.AppendLine("Hauling Job is issued"); Trace.LogMessage(); return(job); } if (cart != null && job.def == jobDefHaulWithCart && !cart.IsInValidStorage()) { Trace.AppendLine("In DismountInBase: "); return(DismountInBase(pawn, cart)); } if (job.targetQueueA.NullOrEmpty()) { JobFailReason.Is(ToolsForHaulUtility.NoHaulable); } else if (reservedMaxItem + job.targetQueueA.Count <= thresholdItem) { JobFailReason.Is(ToolsForHaulUtility.TooLittleHaulable); } else if (job.targetQueueB.NullOrEmpty()) { JobFailReason.Is(ToolsForHaulUtility.NoEmptyPlaceLowerTrans); } Trace.AppendLine("No Job. Reason: " + JobFailReason.Reason); Trace.LogMessage(); return((Job)null); }
// Token: 0x06000042 RID: 66 RVA: 0x000030B0 File Offset: 0x000012B0 public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { CompUniversalFermenter compUniversalFermenter = ThingCompUtility.TryGetComp <CompUniversalFermenter>(t); return(compUniversalFermenter != null && compUniversalFermenter.Fermented && !FireUtility.IsBurning(t) && !ForbidUtility.IsForbidden(t, pawn) && ReservationUtility.CanReserveAndReach(pawn, t, (PathEndMode)2, DangerUtility.NormalMaxDanger(pawn), 1, -1, null, forced)); }
public override void MapComponentTick() { if (!enabled) { firstPass = true; } else { foreach (Pawn p in map.mapPawns.FreeColonistsSpawned) { if (!lastJobStrings.ContainsKey(p)) { lastJobStrings.Add(p, NOTHING); } if (!lastJobSignificance.ContainsKey(p)) { lastJobSignificance.Add(p, false); } string lastJobString = lastJobStrings[p]; bool lastJobSignificant = lastJobSignificance[p]; string curJobString = NOTHING; bool curJobSignificant = false; bool interruptSignificant = false; if (p.Downed) { curJobString = DOWNED; curJobSignificant = false; interruptSignificant = true; } else if (FireUtility.IsBurning(p)) { curJobString = BURNING; curJobSignificant = true; interruptSignificant = true; } else { curJobString = getJobString(p.CurJob); if (p.CurJob.playerForced) { if (curJobString == MOVING) { if (draftedWalking) { curJobSignificant = true; } } else { curJobSignificant = true; } } } if (!firstPass) { if (lastJobString != curJobString) { if (interruptSignificant) { if (curJobString == DOWNED) { notifyAndPause( "Downed!", p.NameStringShort + " is downed, their last job was \"" + lastJobString + "\"", p ); } else if (curJobString == BURNING) { notifyAndPause( "Burning!", p.NameStringShort + " is burning, their last job was \"" + lastJobString + "\"", p ); } else { notifyAndPause( "Interrupted!", p.NameStringShort + " was interrupted, their last job was \"" + lastJobString + "\"", p ); } } else if (lastJobSignificant) { notifyAndPause( "Job Done", p.NameStringShort + " has completed or stopped their last job to \"" + lastJobString + "\" and is now \"" + curJobString + "\"", p ); } } } lastJobStrings[p] = curJobString; lastJobSignificance[p] = curJobSignificant; } firstPass = false; } }
// Token: 0x0600006E RID: 110 RVA: 0x00006AA4 File Offset: 0x00004CA4 public static bool IsDRCapable(Pawn pawn) { return((pawn.IsColonistPlayerControlled || pawn.IsPrisoner) && !pawn.Downed && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Moving) && !MSPainlessData.MedicallyPrevented(pawn) && !FireUtility.IsBurning(pawn) && !pawn.InMentalState); }
// Token: 0x0600007B RID: 123 RVA: 0x00006E50 File Offset: 0x00005050 public static void CheckPainResponse(Pawn pawn) { if ((pawn.IsColonist || (pawn.IsPrisoner && DRSettings.DoIfPrisoner)) && MSPainlessData.IsPainManager(pawn) && MSPainUtility.IsInPain(pawn) && !FireUtility.IsBurning(pawn) && !pawn.InMentalState && !pawn.Drafted && ((RestUtility.Awake(pawn) && !pawn.IsPrisoner) || pawn.IsPrisoner)) { Job painjob = MSPainResponse.DoPainReliefResponse(pawn); if (painjob != null) { if (pawn.jobs != null && pawn.jobs.curJob != null) { pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true, true); pawn.jobs.ClearQueuedJobs(true); } pawn.jobs.TryTakeOrderedJob(painjob, 0); } } }
// Token: 0x0600007D RID: 125 RVA: 0x00005AF8 File Offset: 0x00003CF8 protected override bool Satisfied(Pawn pawn) { return(Settings.DoAutoRefuel && (pawn.IsColonistPlayerControlled && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Moving)) && (!pawn.Downed && !FireUtility.IsBurning(pawn) && !pawn.InMentalState && !pawn.Drafted && RestUtility.Awake(pawn)) && !HealthAIUtility.ShouldSeekMedicalRest(pawn)); }