public static Toil TakeToInventory(TargetIndex ind, Func <int> countGetter) { Toil takeThing = new Toil(); takeThing.initAction = delegate { Pawn actor = takeThing.actor; Thing thing = actor.CurJob.GetTarget(ind).Thing; if (Toils_Haul.ErrorCheckForCarry(actor, thing)) { return; } int num = Mathf.Min(countGetter(), thing.stackCount); if (actor.CurJob.checkEncumbrance) { num = Math.Min(num, MassUtility.CountToPickUpUntilOverEncumbered(actor, thing)); } if (num <= 0) { actor.jobs.curDriver.ReadyForNextToil(); } else { actor.inventory.GetDirectlyHeldThings().TryAdd(thing.SplitOff(num), true); if (thing.def.ingestible != null && thing.def.ingestible.preferability <= FoodPreferability.RawTasty) { actor.mindState.lastInventoryRawFoodUseTick = Find.TickManager.TicksGame; } thing.def.soundPickup.PlayOneShot(new TargetInfo(actor.Position, actor.Map, false)); } }; return(takeThing); }
protected override Job TryGiveJob(Pawn pawn) { Log.Message(pawn + " JobGiver_StockUp"); if (pawn.StockUpIsFull()) { return(null); } Log.Message("Skip need tend?"); if (pawn.Map.mapPawns.AllPawnsSpawned.Any(p => HealthAIUtility.ShouldBeTendedNow(p) && pawn.CanReserveAndReach(p, PathEndMode.ClosestTouch, Danger.Deadly))) { return(null); } Log.Message("any things?"); IEnumerable <Thing> things = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableEver); Predicate <Thing> validator = (Thing t) => pawn.StockingUpOn(t) && pawn.StockUpNeeds(t) > 0 && pawn.CanReserve(t, FindBestMedicine.maxPawns, 1) && !t.IsForbidden(pawn); Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999, validator); if (thing != null) { int pickupCount = Math.Min(pawn.StockUpNeeds(thing), MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing)); Log.Message(pawn + " stock thing is " + thing + ", count " + pickupCount); if (pickupCount > 0) { return new Job(SmartMedicineJobDefOf.StockUp, thing) { count = pickupCount } } ; } Log.Message(pawn + " looking to return"); Thing toReturn = pawn.StockUpThingToReturn(); if (toReturn == null) { return(null); } Log.Message("returning " + toReturn); int dropCount = -pawn.StockUpNeeds(toReturn); Log.Message("dropping " + dropCount); if (StoreUtility.TryFindBestBetterStoreCellFor(toReturn, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out IntVec3 dropLoc, true)) { return new Job(SmartMedicineJobDefOf.StockDown, toReturn, dropLoc) { count = dropCount } } ; Log.Message("nowhere to store"); return(null); } } }
protected override Job TryGiveJob(Pawn pawn) { if (pawn.StockUpIsFull()) { return(null); } Log.Message($"{pawn} needs stocking up"); if (Skip(pawn)) { return(null); } Log.Message($"any things?"); Predicate <Thing> validator = (Thing t) => pawn.StockingUpOn(t) && pawn.StockUpNeeds(t) > 0 && pawn.CanReserve(t, FindBestMedicine.maxPawns, 1) && !t.IsForbidden(pawn); Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999, validator); if (thing != null) { int pickupCount = Math.Min(pawn.StockUpNeeds(thing), MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing)); Log.Message($"{pawn} stock thing is {thing}, count {pickupCount}"); if (pickupCount > 0) { return new Job(SmartMedicineJobDefOf.StockUp, thing) { count = pickupCount } } ; } Log.Message($"{pawn} looking to return"); Thing toReturn = pawn.StockUpThingToReturn(); if (toReturn == null) { return(null); } Log.Message($"returning {toReturn}"); int dropCount = -pawn.StockUpNeeds(toReturn); Log.Message($"dropping {dropCount}"); if (StoreUtility.TryFindBestBetterStoreCellFor(toReturn, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out IntVec3 dropLoc, true)) { return new Job(SmartMedicineJobDefOf.StockDown, toReturn, dropLoc) { count = dropCount } } ; Log.Message($"nowhere to store"); return(null); } } }
static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { var method = SymbolExtensions.GetMethodInfo(() => MassUtility.CountToPickUpUntilOverEncumbered(null, null)); var method2 = SymbolExtensions.GetMethodInfo(() => CountToPickUpUntilOverEncumberedHooker(null, null)); var found = false; instructions.Where(i => i.Calls(method)).Foreach(i => { found = true; i.operand = method2; }); if (found) { Utilities.Debug("JobDriver_HaulToInventory.MakeNewToils is patched"); } else { Utilities.Error("Cannot find <Call MassUtility.CountToPickUpUntilOverEncumbered> in JobDriver_HaulToInventory.MakeNewToils"); } return(instructions); }
public static int CountToPickUpUntilOverEncumberedHooker(Pawn pawn, Thing thing) { int result = MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing); int limit = AdditionalStorageSettings.CalculateStackLimit(thing.Map, thing.Position); if (thing.stackCount <= limit) { return(result); } int num_can_pick = thing.stackCount - limit; if (result > num_can_pick) { result = num_can_pick; } return(result); }
/// <summary> /// Add pickup option to context menu when right-click on items on map. /// </summary> /// <param name="clickPos"> Position of the mouse when right-click. </param> /// <param name="pawn"> Currently focused pawn. </param> /// <param name="opts"> Options displayed in context menu. </param> public static void Postfix(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts) { ValidateArg.NotNull(pawn, nameof(pawn)); ValidateArg.NotNull(opts, nameof(opts)); if (pawn.IsQuestLodger()) { return; } IntVec3 position = IntVec3.FromVector3(clickPos); List <Thing> items = position.GetThingList(pawn.Map); if (!PickUpAndHaulUtility.IsActive) { foreach (Thing item in items) { if (item.def.category == ThingCategory.Item) { int count = MassUtility.CountToPickUpUntilOverEncumbered(pawn, item); if (count == 0) { continue; } count = Math.Min(count, item.stackCount); string displayText = UIText.Pickup.Translate(item.LabelNoCount + " x" + count); var option = FloatMenuUtility.DecoratePrioritizedTask( new FloatMenuOption( displayText , () => { Job job = JobMaker.MakeJob(JobDefOf.TakeInventory, item); job.count = count; job.checkEncumbrance = true; pawn.jobs.TryTakeOrderedJob(job); }) , pawn , item); opts.Add(option); } } } }
protected override IEnumerable <Toil> MakeNewToils() { //FAIL ON OVERBURDENED this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnForbidden(TargetIndex.A); int ammocount = Utility.AmmoCount(pawn, Utility.WeaponCheck(pawn)); this.FailOn(() => ammocount >= SettingsHelper.LatestVersion.DesiredAmmo); int max = MassUtility.CountToPickUpUntilOverEncumbered(pawn, job.targetA.Thing); int num = 0; if (pawn.IsFighting()) { num = Mathf.Min(job.targetA.Thing.stackCount, max); } else { num = Mathf.Min(Mathf.Min(SettingsHelper.LatestVersion.DesiredAmmo - ammocount, job.targetA.Thing.stackCount), max); } Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.A); yield return(reserveTargetA); Toil go = Toils_Goto.Goto(TargetIndex.A, PathEndMode.Touch); yield return(go); Toil take = Toils_Take.TakeToInventory(TargetIndex.A, () => num); yield return(take); if (pawn.Drafted) { Toil go2 = Toils_Goto.Goto(TargetIndex.B, PathEndMode.OnCell); yield return(go2); } yield break; }
public static Toil TakeToInventory(TargetIndex ind, Func <int> countGetter) { Toil takeThing = new Toil(); takeThing.initAction = delegate { Pawn actor = takeThing.actor; Thing thing = actor.CurJob.GetTarget(ind).Thing; int num = Math.Min(Mathf.Min(countGetter(), thing.stackCount), MassUtility.CountToPickUpUntilOverEncumbered(actor, thing)); if (num <= 0) { actor.jobs.curDriver.ReadyForNextToil(); } else { actor.inventory.GetDirectlyHeldThings().TryAdd(thing.SplitOff(num)); thing.def.soundPickup.PlayOneShot(new TargetInfo(actor.Position, actor.Map)); } }; return(takeThing); }
public static bool FetchAmmo(Pawn pawn, ThingDef ammoType) { bool validator(Thing t) { if (t.IsForbidden(pawn)) { return(false); } return(true); } Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, pawn.Map.listerThings.ThingsOfDef(ammoType), PathEndMode.OnCell, TraverseParms.For(pawn), 9999f, validator); if (thing != null) { if (MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing) > SettingsHelper.LatestVersion.LeastAmmoFetch) { Job job = new Job(JobDefOf.FetchAmmunitionCase, thing, pawn.Position); return(pawn.jobs.TryTakeOrderedJob(job)); } } return(false); }
protected override IEnumerable <Toil> MakeNewToils() { Building_ShellfishTrap crabPot = this.job.GetTarget(CrabPotIndex).Thing as Building_ShellfishTrap; Pawn actor = this.pawn; Toil unloadProcess = new Toil() { initAction = () => { storemode = crabPot.StoreMode; }, defaultDuration = BaseUnloadDuration, defaultCompleteMode = ToilCompleteMode.Delay, activeSkill = (() => SkillDefOf.Animals) } .FailOnDespawnedNullOrForbidden(CrabPotIndex) .FailOnBurningImmobile(CrabPotIndex) .FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall) .FailOnCannotTouch(CrabPotIndex, PathEndMode.Touch) .WithProgressBarToilDelay(CrabPotIndex); Toil unloadPot = new Toil() { initAction = () => { //Log.Message("unloadPot"); AddFinishAction(DropStuff); crabPot.LastOpenTick = Find.TickManager.TicksGame; var items = crabPot.GetDirectlyHeldThings(); //Log.Message("items"); //foreach(var item in items) //{ // Log.Message(item.def.defName + " " + item.stackCount); //} //Log.Message("unloading"); while (!MassUtility.IsOverEncumbered(pawn) && items.Count > 0) { int count = Math.Min(MassUtility.CountToPickUpUntilOverEncumbered(actor, items[0]), items[0].stackCount); //Log.Message(count + " " + items[0].stackCount + MassUtility.CountToPickUpUntilOverEncumbered(actor, items[0])); if (items.TryTransferToContainer(items[0], pawn.inventory.innerContainer, count, out Thing resultingItem, false) > 0) { if (!resultingItem.Destroyed && resultingItem.stackCount > 0) { LoadedFish.Add(resultingItem); } } } items.TryDropAll(pawn.Position, pawn.Map, ThingPlaceMode.Near); //actor.jobs.EndCurrentJob(JobCondition.Succeeded); }, defaultCompleteMode = ToilCompleteMode.Instant }; this.FailOnDespawnedNullOrForbidden(CrabPotIndex); this.FailOnBurningImmobile(CrabPotIndex); this.FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall); yield return(Toils_Goto.GotoThing(CrabPotIndex, PathEndMode.Touch) .FailOnDespawnedNullOrForbidden(CrabPotIndex) .FailOnBurningImmobile(CrabPotIndex) .FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall)); yield return(unloadProcess); yield return(unloadPot); //todo: repeatetive haul Toil finishAndStartHaul = FinishAndStartHaul(); yield return(finishAndStartHaul); yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, HaulableInd)); yield return(Toils_Reserve.Reserve(StoreCellInd)); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(StoreCellInd); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(StoreCellInd, carryToCell, storageMode: true, tryStoreInSameStorageIfSpotCantHoldWholeStack: true)); yield return(Toils_Jump.JumpIf(finishAndStartHaul, () => LoadedFish.Count > 0)); }
// Decompiled code is painful to read... Continue at your own risk public static List <FloatMenuOption> ChoicesForThing(Thing thing, Pawn pawn) { List <FloatMenuOption> opts = new List <FloatMenuOption>(); Thing t = thing; // Copied from FloatMenuMakerMap.AddHumanlikeOrders if (t.def.ingestible != null && pawn.RaceProps.CanEverEat(t) && t.IngestibleNow) { string text; if (t.def.ingestible.ingestCommandString.NullOrEmpty()) { text = "ConsumeThing".Translate(new NamedArgument[] { t.LabelShort }); } else { text = string.Format(t.def.ingestible.ingestCommandString, t.LabelShort); } if (!t.IsSociallyProper(pawn)) { text = text + " (" + "ReservedForPrisoners".Translate() + ")"; } FloatMenuOption item7; if (t.def.IsNonMedicalDrug && pawn.IsTeetotaler()) { item7 = new FloatMenuOption(text + " (" + TraitDefOf.DrugDesire.DataAtDegree(-1).label + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else if (!pawn.CanReach(t, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)) { item7 = new FloatMenuOption(text + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { MenuOptionPriority priority2 = (!(t is Corpse)) ? MenuOptionPriority.Default : MenuOptionPriority.Low; item7 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text, delegate() { t.SetForbidden(false, true); Job job = new Job(JobDefOf.Ingest, t); job.count = FoodUtility.WillIngestStackCountOf(pawn, t.def, t.GetStatValue(StatDefOf.Nutrition, true)); pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, priority2, null, null, 0f, null, null), pawn, t, "ReservedBy"); } opts.Add(item7); } // Add equipment commands // Copied from FloatMenuMakerMap.AddHumanlikeOrders if (thing is ThingWithComps equipment && equipment.GetComp <CompEquippable>() != null) { string labelShort = equipment.LabelShort; FloatMenuOption item4; if (equipment.def.IsWeapon && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) { item4 = new FloatMenuOption("CannotEquip".Translate(new NamedArgument[] { labelShort }) + " (" + "IsIncapableOfViolenceLower".Translate(new NamedArgument[] { pawn.LabelShort }) + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else if (!pawn.CanReach(equipment, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { item4 = new FloatMenuOption("CannotEquip".Translate(new NamedArgument[] { labelShort }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { item4 = new FloatMenuOption("CannotEquip".Translate(new NamedArgument[] { labelShort }) + " (" + "Incapable".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { string text5 = "Equip".Translate(new NamedArgument[] { labelShort }); if (equipment.def.IsRangedWeapon && pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler)) { text5 = text5 + " " + "EquipWarningBrawler".Translate(); } item4 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text5, delegate() { equipment.SetForbidden(false, true); pawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.Equip, equipment), JobTag.Misc); MoteMaker.MakeStaticMote(equipment.DrawPos, equipment.Map, ThingDefOf.Mote_FeedbackEquip, 1f); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.EquippingWeapons, KnowledgeAmount.Total); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, equipment, "ReservedBy"); } opts.Add(item4); } // Add clothing commands Apparel apparel = thing as Apparel; if (apparel != null) { FloatMenuOption item5; if (!pawn.CanReach(apparel, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { item5 = new FloatMenuOption("CannotWear".Translate(new NamedArgument[] { apparel.Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else if (!ApparelUtility.HasPartsToWear(pawn, apparel.def)) { item5 = new FloatMenuOption("CannotWear".Translate(new NamedArgument[] { apparel.Label }) + " (" + "CannotWearBecauseOfMissingBodyParts".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { item5 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("ForceWear".Translate(new NamedArgument[] { apparel.LabelShort }), delegate() { apparel.SetForbidden(false, true); Job job = new Job(JobDefOf.Wear, apparel); pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, apparel, "ReservedBy"); } opts.Add(item5); } // Add caravan commands if (pawn.IsFormingCaravan()) { if (thing != null && thing.def.EverHaulable) { Pawn packTarget = GiveToPackAnimalUtility.UsablePackAnimalWithTheMostFreeSpace(pawn) ?? pawn; JobDef jobDef = (packTarget != pawn) ? JobDefOf.GiveToPackAnimal : JobDefOf.TakeInventory; if (!pawn.CanReach(thing, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { opts.Add(new FloatMenuOption("CannotLoadIntoCaravan".Translate(new NamedArgument[] { thing.Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else if (MassUtility.WillBeOverEncumberedAfterPickingUp(packTarget, thing, 1)) { opts.Add(new FloatMenuOption("CannotLoadIntoCaravan".Translate(new NamedArgument[] { thing.Label }) + " (" + "TooHeavy".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { LordJob_FormAndSendCaravan lordJob = (LordJob_FormAndSendCaravan)pawn.GetLord().LordJob; float capacityLeft = CaravanFormingUtility.CapacityLeft(lordJob); if (thing.stackCount == 1) { float capacityLeft4 = capacityLeft - thing.GetStatValue(StatDefOf.Mass, true); opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(CaravanFormingUtility.AppendOverweightInfo("LoadIntoCaravan".Translate(new NamedArgument[] { thing.Label }), capacityLeft4), delegate() { thing.SetForbidden(false, false); Job job = new Job(jobDef, thing); job.count = 1; job.checkEncumbrance = (packTarget == pawn); pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, thing, "ReservedBy")); } else { if (MassUtility.WillBeOverEncumberedAfterPickingUp(packTarget, thing, thing.stackCount)) { opts.Add(new FloatMenuOption("CannotLoadIntoCaravanAll".Translate(new NamedArgument[] { thing.Label }) + " (" + "TooHeavy".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { float capacityLeft2 = capacityLeft - (float)thing.stackCount * thing.GetStatValue(StatDefOf.Mass, true); opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(CaravanFormingUtility.AppendOverweightInfo("LoadIntoCaravanAll".Translate(new NamedArgument[] { thing.Label }), capacityLeft2), delegate() { thing.SetForbidden(false, false); Job job = new Job(jobDef, thing); job.count = thing.stackCount; job.checkEncumbrance = (packTarget == pawn); pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, thing, "ReservedBy")); } opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("LoadIntoCaravanSome".Translate(new NamedArgument[] { thing.LabelNoCount }), delegate() { int to = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(packTarget, thing), thing.stackCount); Dialog_Slider window = new Dialog_Slider(delegate(int val) { float capacityLeft3 = capacityLeft - (float)val * thing.GetStatValue(StatDefOf.Mass, true); return(CaravanFormingUtility.AppendOverweightInfo(string.Format("LoadIntoCaravanCount".Translate(new NamedArgument[] { thing.LabelNoCount }), val), capacityLeft3)); }, 1, to, delegate(int count) { thing.SetForbidden(false, false); Job job = new Job(jobDef, thing); job.count = count; job.checkEncumbrance = (packTarget == pawn); pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, int.MinValue); Find.WindowStack.Add(window); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, thing, "ReservedBy")); } } } } if (opts.Count == 0) { opts.Add(new FloatMenuOption("NoneBrackets".Translate(), null) { Disabled = true }); } return(opts); }
public static bool AddHumanlikeOrders(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts) { IntVec3 c = IntVec3.FromVector3(clickPos); foreach (Thing thing in c.GetThingList(pawn.Map)) { Pawn pawn2; if ((pawn2 = (thing as Pawn)) != null) { Lord lord = pawn2.GetLord(); if (lord != null && lord.CurLordToil != null) { IEnumerable <FloatMenuOption> enumerable = lord.CurLordToil.ExtraFloatMenuOptions(pawn2, pawn); if (enumerable != null) { foreach (FloatMenuOption item8 in enumerable) { opts.Add(item8); } } } } } if (pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { foreach (LocalTargetInfo item9 in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForArrest(pawn), thingsOnly: true)) { bool flag = item9.HasThing && item9.Thing is Pawn && ((Pawn)item9.Thing).IsWildMan(); if (pawn.Drafted || flag) { if (item9.Thing is Pawn && (pawn.InSameExtraFaction((Pawn)item9.Thing, ExtraFactionType.HomeFaction) || pawn.InSameExtraFaction((Pawn)item9.Thing, ExtraFactionType.MiniFaction))) { opts.Add(new FloatMenuOption("CannotArrest".Translate() + ": " + "SameFaction".Translate((Pawn)item9.Thing), null)); } else if (!pawn.CanReach(item9, PathEndMode.OnCell, Danger.Deadly)) { opts.Add(new FloatMenuOption("CannotArrest".Translate() + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else { Pawn pTarg2 = (Pawn)item9.Thing; Action action = delegate { Building_Bed building_Bed3 = RestUtility.FindBedFor(pTarg2, pawn, sleeperWillBePrisoner: true, checkSocialProperness: false); if (building_Bed3 == null) { building_Bed3 = RestUtility.FindBedFor(pTarg2, pawn, sleeperWillBePrisoner: true, checkSocialProperness: false, ignoreOtherReservations: true); } if (building_Bed3 == null) { Messages.Message("CannotArrest".Translate() + ": " + "NoPrisonerBed".Translate(), pTarg2, MessageTypeDefOf.RejectInput, historical: false); } else { Job job19 = JobMaker.MakeJob(JobDefOf.Arrest, pTarg2, building_Bed3); job19.count = 1; pawn.jobs.TryTakeOrderedJob(job19); if (pTarg2.Faction != null && ((pTarg2.Faction != Faction.OfPlayer && !pTarg2.Faction.Hidden) || pTarg2.IsQuestLodger())) { TutorUtility.DoModalDialogIfNotKnown(ConceptDefOf.ArrestingCreatesEnemies, pTarg2.GetAcceptArrestChance(pawn).ToStringPercent()); } } }; opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("TryToArrest".Translate(item9.Thing.LabelCap, item9.Thing, pTarg2.GetAcceptArrestChance(pawn).ToStringPercent()), action, MenuOptionPriority.High, null, item9.Thing), pawn, pTarg2)); } } } } foreach (Thing thing2 in c.GetThingList(pawn.Map)) { Thing t = thing2; if (t.def.ingestible != null && pawn.RaceProps.CanEverEat(t) && t.IngestibleNow) { string text = (!t.def.ingestible.ingestCommandString.NullOrEmpty()) ? string.Format(t.def.ingestible.ingestCommandString, t.LabelShort) : ((string)"ConsumeThing".Translate(t.LabelShort, t)); if (!t.IsSociallyProper(pawn)) { text = text + ": " + "ReservedForPrisoners".Translate().CapitalizeFirst(); } FloatMenuOption floatMenuOption; if (t.def.IsNonMedicalDrug && pawn.IsTeetotaler()) { floatMenuOption = new FloatMenuOption(text + ": " + TraitDefOf.DrugDesire.DataAtDegree(-1).GetLabelCapFor(pawn), null); } else if (FoodUtility.InappropriateForTitle(t.def, pawn, allowIfStarving: true)) { floatMenuOption = new FloatMenuOption(text + ": " + "FoodBelowTitleRequirements".Translate(pawn.royalty.MostSeniorTitle.def.GetLabelFor(pawn)), null); } else if (!pawn.CanReach(t, PathEndMode.OnCell, Danger.Deadly)) { floatMenuOption = new FloatMenuOption(text + ": " + "NoPath".Translate().CapitalizeFirst(), null); } else { MenuOptionPriority priority = (t is Corpse) ? MenuOptionPriority.Low : MenuOptionPriority.Default; int maxAmountToPickup = FoodUtility.GetMaxAmountToPickup(t, pawn, FoodUtility.WillIngestStackCountOf(pawn, t.def, t.GetStatValue(StatDefOf.Nutrition))); floatMenuOption = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text, delegate { int maxAmountToPickup2 = FoodUtility.GetMaxAmountToPickup(t, pawn, FoodUtility.WillIngestStackCountOf(pawn, t.def, t.GetStatValue(StatDefOf.Nutrition))); if (maxAmountToPickup2 != 0) { t.SetForbidden(value: false); Job job18 = JobMaker.MakeJob(JobDefOf.Ingest, t); job18.count = maxAmountToPickup2; pawn.jobs.TryTakeOrderedJob(job18); } }, priority), pawn, t); if (maxAmountToPickup == 0) { floatMenuOption.action = null; } } opts.Add(floatMenuOption); } } foreach (LocalTargetInfo item10 in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForQuestPawnsWhoWillJoinColony(pawn), thingsOnly: true)) { Pawn toHelpPawn = (Pawn)item10.Thing; FloatMenuOption item4 = pawn.CanReach(item10, PathEndMode.Touch, Danger.Deadly) ? FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(toHelpPawn.IsPrisoner ? "FreePrisoner".Translate() : "OfferHelp".Translate(), delegate { pawn.jobs.TryTakeOrderedJob(JobMaker.MakeJob(JobDefOf.OfferHelp, toHelpPawn)); }, MenuOptionPriority.RescueOrCapture, null, toHelpPawn), pawn, toHelpPawn) : new FloatMenuOption("CannotGoNoPath".Translate(), null); opts.Add(item4); } if (pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { foreach (Thing thing3 in c.GetThingList(pawn.Map)) { Corpse corpse = thing3 as Corpse; if (corpse != null && corpse.IsInValidStorage()) { StoragePriority priority2 = StoreUtility.CurrentHaulDestinationOf(corpse).GetStoreSettings().Priority; if (StoreUtility.TryFindBestBetterNonSlotGroupStorageFor(corpse, pawn, pawn.Map, priority2, Faction.OfPlayer, out IHaulDestination haulDestination, acceptSamePriority: true) && haulDestination.GetStoreSettings().Priority == priority2 && haulDestination is Building_Grave) { Building_Grave grave = haulDestination as Building_Grave; string label = "PrioritizeGeneric".Translate("Burying".Translate(), corpse.Label); opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(label, delegate { pawn.jobs.TryTakeOrderedJob(HaulAIUtility.HaulToContainerJob(pawn, corpse, grave)); }), pawn, new LocalTargetInfo(corpse))); } } } foreach (LocalTargetInfo item11 in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForRescue(pawn), thingsOnly: true)) { Pawn victim3 = (Pawn)item11.Thing; if (!victim3.InBed() && pawn.CanReserveAndReach(victim3, PathEndMode.OnCell, Danger.Deadly, 1, -1, null, ignoreOtherReservations: true) && !victim3.mindState.WillJoinColonyIfRescued) { if (!victim3.IsPrisonerOfColony && (!victim3.InMentalState || victim3.health.hediffSet.HasHediff(HediffDefOf.Scaria)) && (victim3.Faction == Faction.OfPlayer || victim3.Faction == null || !victim3.Faction.HostileTo(Faction.OfPlayer))) { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("Rescue".Translate(victim3.LabelCap, victim3), delegate { Building_Bed building_Bed2 = RestUtility.FindBedFor(victim3, pawn, sleeperWillBePrisoner: false, checkSocialProperness: false); if (building_Bed2 == null) { building_Bed2 = RestUtility.FindBedFor(victim3, pawn, sleeperWillBePrisoner: false, checkSocialProperness: false, ignoreOtherReservations: true); } if (building_Bed2 == null) { string t3 = (!victim3.RaceProps.Animal) ? ((string)"NoNonPrisonerBed".Translate()) : ((string)"NoAnimalBed".Translate()); Messages.Message("CannotRescue".Translate() + ": " + t3, victim3, MessageTypeDefOf.RejectInput, historical: false); } else { Job job17 = JobMaker.MakeJob(JobDefOf.Rescue, victim3, building_Bed2); job17.count = 1; pawn.jobs.TryTakeOrderedJob(job17); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Rescuing, KnowledgeAmount.Total); } }, MenuOptionPriority.RescueOrCapture, null, victim3), pawn, victim3)); } if (victim3.RaceProps.Humanlike && (victim3.InMentalState || victim3.Faction != Faction.OfPlayer || (victim3.Downed && (victim3.guilt.IsGuilty || victim3.IsPrisonerOfColony)))) { TaggedString taggedString = "Capture".Translate(victim3.LabelCap, victim3); if (victim3.Faction != null && victim3.Faction != Faction.OfPlayer && !victim3.Faction.Hidden && !victim3.Faction.HostileTo(Faction.OfPlayer) && !victim3.IsPrisonerOfColony) { taggedString += ": " + "AngersFaction".Translate().CapitalizeFirst(); } opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(taggedString, delegate { Building_Bed building_Bed = RestUtility.FindBedFor(victim3, pawn, sleeperWillBePrisoner: true, checkSocialProperness: false); if (building_Bed == null) { building_Bed = RestUtility.FindBedFor(victim3, pawn, sleeperWillBePrisoner: true, checkSocialProperness: false, ignoreOtherReservations: true); } if (building_Bed == null) { Messages.Message("CannotCapture".Translate() + ": " + "NoPrisonerBed".Translate(), victim3, MessageTypeDefOf.RejectInput, historical: false); } else { Job job16 = JobMaker.MakeJob(JobDefOf.Capture, victim3, building_Bed); job16.count = 1; pawn.jobs.TryTakeOrderedJob(job16); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Capturing, KnowledgeAmount.Total); if (victim3.Faction != null && victim3.Faction != Faction.OfPlayer && !victim3.Faction.Hidden && !victim3.Faction.HostileTo(Faction.OfPlayer) && !victim3.IsPrisonerOfColony) { Messages.Message("MessageCapturingWillAngerFaction".Translate(victim3.Named("PAWN")).AdjustedFor(victim3), victim3, MessageTypeDefOf.CautionInput, historical: false); } } }, MenuOptionPriority.RescueOrCapture, null, victim3), pawn, victim3)); } } } foreach (LocalTargetInfo item12 in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForRescue(pawn), thingsOnly: true)) { LocalTargetInfo localTargetInfo = item12; Pawn victim2 = (Pawn)localTargetInfo.Thing; if (victim2.Downed && pawn.CanReserveAndReach(victim2, PathEndMode.OnCell, Danger.Deadly, 1, -1, null, ignoreOtherReservations: true) && Building_CryptosleepCasket.FindCryptosleepCasketFor(victim2, pawn, ignoreOtherReservations: true) != null) { string text2 = "CarryToCryptosleepCasket".Translate(localTargetInfo.Thing.LabelCap, localTargetInfo.Thing); JobDef jDef = JobDefOf.CarryToCryptosleepCasket; Action action2 = delegate { Building_CryptosleepCasket building_CryptosleepCasket = Building_CryptosleepCasket.FindCryptosleepCasketFor(victim2, pawn); if (building_CryptosleepCasket == null) { building_CryptosleepCasket = Building_CryptosleepCasket.FindCryptosleepCasketFor(victim2, pawn, ignoreOtherReservations: true); } if (building_CryptosleepCasket == null) { Messages.Message("CannotCarryToCryptosleepCasket".Translate() + ": " + "NoCryptosleepCasket".Translate(), victim2, MessageTypeDefOf.RejectInput, historical: false); } else { Job job15 = JobMaker.MakeJob(jDef, victim2, building_CryptosleepCasket); job15.count = 1; pawn.jobs.TryTakeOrderedJob(job15); } }; if (victim2.IsQuestLodger()) { text2 += " (" + "CryptosleepCasketGuestsNotAllowed".Translate() + ")"; opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text2, null, MenuOptionPriority.Default, null, victim2), pawn, victim2)); } else if (victim2.GetExtraHostFaction() != null) { text2 += " (" + "CryptosleepCasketGuestPrisonersNotAllowed".Translate() + ")"; opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text2, null, MenuOptionPriority.Default, null, victim2), pawn, victim2)); } else { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text2, action2, MenuOptionPriority.Default, null, victim2), pawn, victim2)); } } } if (ModsConfig.RoyaltyActive) { foreach (LocalTargetInfo item13 in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForShuttle(pawn), thingsOnly: true)) { LocalTargetInfo localTargetInfo2 = item13; Pawn victim = (Pawn)localTargetInfo2.Thing; Predicate <Thing> validator = (Thing thing) => thing.TryGetComp <CompShuttle>()?.IsAllowedNow(victim) ?? false; Thing shuttleThing = GenClosest.ClosestThingReachable(victim.Position, victim.Map, ThingRequest.ForDef(ThingDefOf.Shuttle), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, validator); if (shuttleThing != null && pawn.CanReserveAndReach(victim, PathEndMode.OnCell, Danger.Deadly, 1, -1, null, ignoreOtherReservations: true) && !pawn.WorkTypeIsDisabled(WorkTypeDefOf.Hauling)) { string label2 = "CarryToShuttle".Translate(localTargetInfo2.Thing); Action action3 = delegate { CompShuttle compShuttle = shuttleThing.TryGetComp <CompShuttle>(); if (!compShuttle.LoadingInProgressOrReadyToLaunch) { TransporterUtility.InitiateLoading(Gen.YieldSingle(compShuttle.Transporter)); } Job job14 = JobMaker.MakeJob(JobDefOf.HaulToTransporter, victim, shuttleThing); job14.ignoreForbidden = true; job14.count = 1; pawn.jobs.TryTakeOrderedJob(job14); }; opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(label2, action3), pawn, victim)); } } } } foreach (LocalTargetInfo item14 in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForStrip(pawn), thingsOnly: true)) { LocalTargetInfo stripTarg = item14; FloatMenuOption item5 = pawn.CanReach(stripTarg, PathEndMode.ClosestTouch, Danger.Deadly) ? ((stripTarg.Pawn == null || !stripTarg.Pawn.HasExtraHomeFaction()) ? FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("Strip".Translate(stripTarg.Thing.LabelCap, stripTarg.Thing), delegate { stripTarg.Thing.SetForbidden(value: false, warnOnFail: false); pawn.jobs.TryTakeOrderedJob(JobMaker.MakeJob(JobDefOf.Strip, stripTarg)); StrippableUtility.CheckSendStrippingImpactsGoodwillMessage(stripTarg.Thing); }), pawn, stripTarg) : new FloatMenuOption("CannotStrip".Translate(stripTarg.Thing.LabelCap, stripTarg.Thing) + ": " + "QuestRelated".Translate().CapitalizeFirst(), null)) : new FloatMenuOption("CannotStrip".Translate(stripTarg.Thing.LabelCap, stripTarg.Thing) + ": " + "NoPath".Translate().CapitalizeFirst(), null); opts.Add(item5); } ThingWithComps equipment; if (pawn.equipment != null) { equipment = null; List <Thing> thingList = c.GetThingList(pawn.Map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i].TryGetComp <CompEquippable>() != null) { equipment = (ThingWithComps)thingList[i]; break; } } if (equipment != null) { string labelShort = equipment.LabelShort; FloatMenuOption item6; string cantReason; if (equipment.def.IsWeapon && pawn.WorkTagIsDisabled(WorkTags.Violent)) { item6 = new FloatMenuOption("CannotEquip".Translate(labelShort) + ": " + "IsIncapableOfViolenceLower".Translate(pawn.LabelShort, pawn), null); } else if (!pawn.CanReach(equipment, PathEndMode.ClosestTouch, Danger.Deadly)) { item6 = new FloatMenuOption("CannotEquip".Translate(labelShort) + ": " + "NoPath".Translate().CapitalizeFirst(), null); } else if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { item6 = new FloatMenuOption("CannotEquip".Translate(labelShort) + ": " + "Incapable".Translate(), null); } else if (equipment.IsBurning()) { item6 = new FloatMenuOption("CannotEquip".Translate(labelShort) + ": " + "BurningLower".Translate(), null); } else if (pawn.IsQuestLodger() && !EquipmentUtility.QuestLodgerCanEquip(equipment, pawn)) { item6 = new FloatMenuOption("CannotEquip".Translate(labelShort) + ": " + "QuestRelated".Translate().CapitalizeFirst(), null); } else if (!EquipmentUtility.CanEquip_NewTmp(equipment, pawn, out cantReason, checkBonded: false)) { item6 = new FloatMenuOption("CannotEquip".Translate(labelShort) + ": " + cantReason.CapitalizeFirst(), null); } else { string text3 = "Equip".Translate(labelShort); if (equipment.def.IsRangedWeapon && pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler)) { text3 += " " + "EquipWarningBrawler".Translate(); } if (EquipmentUtility.AlreadyBondedToWeapon(equipment, pawn)) { text3 += " " + "BladelinkAlreadyBonded".Translate(); TaggedString dialogText = "BladelinkAlreadyBondedDialog".Translate(pawn.Named("PAWN"), equipment.Named("WEAPON"), pawn.equipment.bondedWeapon.Named("BONDEDWEAPON")); item6 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text3, delegate { Find.WindowStack.Add(new Dialog_MessageBox(dialogText)); }, MenuOptionPriority.High), pawn, equipment); } else { item6 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text3, delegate { string personaWeaponConfirmationText = EquipmentUtility.GetPersonaWeaponConfirmationText(equipment, pawn); if (!personaWeaponConfirmationText.NullOrEmpty()) { Find.WindowStack.Add(new Dialog_MessageBox(personaWeaponConfirmationText, "Yes".Translate(), delegate { Equip(); }, "No".Translate())); } else { Equip(); } }, MenuOptionPriority.High), pawn, equipment); } } opts.Add(item6); } } foreach (Pair <CompReloadable, Thing> item15 in ReloadableUtility.FindPotentiallyReloadableGear(pawn, c.GetThingList(pawn.Map))) { CompReloadable comp = item15.First; Thing second = item15.Second; string text4 = "Reload".Translate(comp.parent.Named("GEAR"), NamedArgumentUtility.Named(comp.AmmoDef, "AMMO")) + " (" + comp.LabelRemaining + ")"; List <Thing> chosenAmmo; if (!pawn.CanReach(second, PathEndMode.ClosestTouch, Danger.Deadly)) { opts.Add(new FloatMenuOption(text4 + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else if (!comp.NeedsReload(allowForcedReload: true)) { opts.Add(new FloatMenuOption(text4 + ": " + "ReloadFull".Translate(), null)); } else if ((chosenAmmo = ReloadableUtility.FindEnoughAmmo(pawn, second.Position, comp, forceReload: true)) == null) { opts.Add(new FloatMenuOption(text4 + ": " + "ReloadNotEnough".Translate(), null)); } else { Action action4 = delegate { pawn.jobs.TryTakeOrderedJob(JobGiver_Reload.MakeReloadJob(comp, chosenAmmo)); }; opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text4, action4), pawn, second)); } } if (pawn.apparel != null) { if (pawn.Map.thingGrid.ThingAt(c, ThingCategory.Item) is Apparel apparel) { string key = "CannotWear"; string key2 = "ForceWear"; if (apparel.def.apparel.LastLayer.IsUtilityLayer) { key = "CannotEquipApparel"; key2 = "ForceEquipApparel"; } string cantReason2; FloatMenuOption item7 = (!pawn.CanReach(apparel, PathEndMode.ClosestTouch, Danger.Deadly)) ? new FloatMenuOption(key.Translate(apparel.Label, apparel) + ": " + "NoPath".Translate().CapitalizeFirst(), null) : (apparel.IsBurning() ? new FloatMenuOption(key.Translate(apparel.Label, apparel) + ": " + "Burning".Translate(), null) : (pawn.apparel.WouldReplaceLockedApparel(apparel) ? new FloatMenuOption(key.Translate(apparel.Label, apparel) + ": " + "WouldReplaceLockedApparel".Translate().CapitalizeFirst(), null) : ((!ApparelUtility.HasPartsToWear(pawn, apparel.def)) ? new FloatMenuOption(key.Translate(apparel.Label, apparel) + ": " + "CannotWearBecauseOfMissingBodyParts".Translate(), null) : (EquipmentUtility.CanEquip_NewTmp(apparel, pawn, out cantReason2) ? FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(key2.Translate(apparel.LabelShort, apparel), delegate { apparel.SetForbidden(value: false); Job job13 = JobMaker.MakeJob(JobDefOf.Wear, apparel); pawn.jobs.TryTakeOrderedJob(job13); }, MenuOptionPriority.High), pawn, apparel) : new FloatMenuOption(key.Translate(apparel.Label, apparel) + ": " + cantReason2, null))))); opts.Add(item7); } } if (pawn.IsFormingCaravan()) { Thing item3 = c.GetFirstItem(pawn.Map); if (item3 != null && item3.def.EverHaulable && item3.def.canLoadIntoCaravan) { Pawn packTarget = GiveToPackAnimalUtility.UsablePackAnimalWithTheMostFreeSpace(pawn) ?? pawn; JobDef jobDef = (packTarget == pawn) ? JobDefOf.TakeInventory : JobDefOf.GiveToPackAnimal; if (!pawn.CanReach(item3, PathEndMode.ClosestTouch, Danger.Deadly)) { opts.Add(new FloatMenuOption("CannotLoadIntoCaravan".Translate(item3.Label, item3) + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else if (MassUtility.WillBeOverEncumberedAfterPickingUp(packTarget, item3, 1)) { opts.Add(new FloatMenuOption("CannotLoadIntoCaravan".Translate(item3.Label, item3) + ": " + "TooHeavy".Translate(), null)); } else { LordJob_FormAndSendCaravan lordJob = (LordJob_FormAndSendCaravan)pawn.GetLord().LordJob; float capacityLeft = CaravanFormingUtility.CapacityLeft(lordJob); if (item3.stackCount == 1) { float capacityLeft2 = capacityLeft - item3.GetStatValue(StatDefOf.Mass); opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(CaravanFormingUtility.AppendOverweightInfo("LoadIntoCaravan".Translate(item3.Label, item3), capacityLeft2), delegate { item3.SetForbidden(value: false, warnOnFail: false); Job job12 = JobMaker.MakeJob(jobDef, item3); job12.count = 1; job12.checkEncumbrance = (packTarget == pawn); pawn.jobs.TryTakeOrderedJob(job12); }, MenuOptionPriority.High), pawn, item3)); } else { if (MassUtility.WillBeOverEncumberedAfterPickingUp(packTarget, item3, item3.stackCount)) { opts.Add(new FloatMenuOption("CannotLoadIntoCaravanAll".Translate(item3.Label, item3) + ": " + "TooHeavy".Translate(), null)); } else { float capacityLeft3 = capacityLeft - (float)item3.stackCount * item3.GetStatValue(StatDefOf.Mass); opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(CaravanFormingUtility.AppendOverweightInfo("LoadIntoCaravanAll".Translate(item3.Label, item3), capacityLeft3), delegate { item3.SetForbidden(value: false, warnOnFail: false); Job job11 = JobMaker.MakeJob(jobDef, item3); job11.count = item3.stackCount; job11.checkEncumbrance = (packTarget == pawn); pawn.jobs.TryTakeOrderedJob(job11); }, MenuOptionPriority.High), pawn, item3)); } opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("LoadIntoCaravanSome".Translate(item3.LabelNoCount, item3), delegate { int to3 = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(packTarget, item3), item3.stackCount); Dialog_Slider window3 = new Dialog_Slider(delegate(int val) { float capacityLeft4 = capacityLeft - (float)val * item3.GetStatValue(StatDefOf.Mass); return(CaravanFormingUtility.AppendOverweightInfo(string.Format("LoadIntoCaravanCount".Translate(item3.LabelNoCount, item3), val), capacityLeft4)); }, 1, to3, delegate(int count) { item3.SetForbidden(value: false, warnOnFail: false); Job job10 = JobMaker.MakeJob(jobDef, item3); job10.count = count; job10.checkEncumbrance = (packTarget == pawn); pawn.jobs.TryTakeOrderedJob(job10); }); Find.WindowStack.Add(window3); }, MenuOptionPriority.High), pawn, item3)); } } } } if (!pawn.Map.IsPlayerHome && !pawn.IsFormingCaravan()) { Thing item2 = c.GetFirstItem(pawn.Map); if (item2 != null && item2.def.EverHaulable) { if (!pawn.CanReach(item2, PathEndMode.ClosestTouch, Danger.Deadly)) { opts.Add(new FloatMenuOption("CannotPickUp".Translate(item2.Label, item2) + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else if (MassUtility.WillBeOverEncumberedAfterPickingUp(pawn, item2, 1)) { opts.Add(new FloatMenuOption("CannotPickUp".Translate(item2.Label, item2) + ": " + "TooHeavy".Translate(), null)); } else if (item2.stackCount == 1) { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("PickUp".Translate(item2.Label, item2), delegate { item2.SetForbidden(value: false, warnOnFail: false); Job job9 = JobMaker.MakeJob(JobDefOf.TakeInventory, item2); job9.count = 1; job9.checkEncumbrance = true; pawn.jobs.TryTakeOrderedJob(job9); }, MenuOptionPriority.High), pawn, item2)); } else { if (MassUtility.WillBeOverEncumberedAfterPickingUp(pawn, item2, item2.stackCount)) { opts.Add(new FloatMenuOption("CannotPickUpAll".Translate(item2.Label, item2) + ": " + "TooHeavy".Translate(), null)); } else { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("PickUpAll".Translate(item2.Label, item2), delegate { item2.SetForbidden(value: false, warnOnFail: false); Job job8 = JobMaker.MakeJob(JobDefOf.TakeInventory, item2); job8.count = item2.stackCount; job8.checkEncumbrance = true; pawn.jobs.TryTakeOrderedJob(job8); }, MenuOptionPriority.High), pawn, item2)); } opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("PickUpSome".Translate(item2.LabelNoCount, item2), delegate { int to2 = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(pawn, item2), item2.stackCount); Dialog_Slider window2 = new Dialog_Slider("PickUpCount".Translate(item2.LabelNoCount, item2), 1, to2, delegate(int count) { item2.SetForbidden(value: false, warnOnFail: false); Job job7 = JobMaker.MakeJob(JobDefOf.TakeInventory, item2); job7.count = count; job7.checkEncumbrance = true; pawn.jobs.TryTakeOrderedJob(job7); }); Find.WindowStack.Add(window2); }, MenuOptionPriority.High), pawn, item2)); } } } if (!pawn.Map.IsPlayerHome && !pawn.IsFormingCaravan()) { Thing item = c.GetFirstItem(pawn.Map); if (item != null && item.def.EverHaulable) { Pawn bestPackAnimal = GiveToPackAnimalUtility.UsablePackAnimalWithTheMostFreeSpace(pawn); if (bestPackAnimal != null) { if (!pawn.CanReach(item, PathEndMode.ClosestTouch, Danger.Deadly)) { opts.Add(new FloatMenuOption("CannotGiveToPackAnimal".Translate(item.Label, item) + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else if (MassUtility.WillBeOverEncumberedAfterPickingUp(bestPackAnimal, item, 1)) { opts.Add(new FloatMenuOption("CannotGiveToPackAnimal".Translate(item.Label, item) + ": " + "TooHeavy".Translate(), null)); } else if (item.stackCount == 1) { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("GiveToPackAnimal".Translate(item.Label, item), delegate { item.SetForbidden(value: false, warnOnFail: false); Job job6 = JobMaker.MakeJob(JobDefOf.GiveToPackAnimal, item); job6.count = 1; pawn.jobs.TryTakeOrderedJob(job6); }, MenuOptionPriority.High), pawn, item)); } else { if (MassUtility.WillBeOverEncumberedAfterPickingUp(bestPackAnimal, item, item.stackCount)) { opts.Add(new FloatMenuOption("CannotGiveToPackAnimalAll".Translate(item.Label, item) + ": " + "TooHeavy".Translate(), null)); } else { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("GiveToPackAnimalAll".Translate(item.Label, item), delegate { item.SetForbidden(value: false, warnOnFail: false); Job job5 = JobMaker.MakeJob(JobDefOf.GiveToPackAnimal, item); job5.count = item.stackCount; pawn.jobs.TryTakeOrderedJob(job5); }, MenuOptionPriority.High), pawn, item)); } opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("GiveToPackAnimalSome".Translate(item.LabelNoCount, item), delegate { int to = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(bestPackAnimal, item), item.stackCount); Dialog_Slider window = new Dialog_Slider("GiveToPackAnimalCount".Translate(item.LabelNoCount, item), 1, to, delegate(int count) { item.SetForbidden(value: false, warnOnFail: false); Job job4 = JobMaker.MakeJob(JobDefOf.GiveToPackAnimal, item); job4.count = count; pawn.jobs.TryTakeOrderedJob(job4); }); Find.WindowStack.Add(window); }, MenuOptionPriority.High), pawn, item)); } } } } if (!pawn.Map.IsPlayerHome && pawn.Map.exitMapGrid.MapUsesExitGrid) { foreach (LocalTargetInfo item16 in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForRescue(pawn), thingsOnly: true)) { Pawn p = (Pawn)item16.Thing; if (p.Faction == Faction.OfPlayer || p.IsPrisonerOfColony || CaravanUtility.ShouldAutoCapture(p, Faction.OfPlayer)) { IntVec3 exitSpot; if (!pawn.CanReach(p, PathEndMode.ClosestTouch, Danger.Deadly)) { opts.Add(new FloatMenuOption("CannotCarryToExit".Translate(p.Label, p) + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else if (!RCellFinder.TryFindBestExitSpot(pawn, out exitSpot)) { opts.Add(new FloatMenuOption("CannotCarryToExit".Translate(p.Label, p) + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else { TaggedString taggedString2 = (p.Faction == Faction.OfPlayer || p.IsPrisonerOfColony) ? "CarryToExit".Translate(p.Label, p) : "CarryToExitAndCapture".Translate(p.Label, p); opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(taggedString2, delegate { Job job3 = JobMaker.MakeJob(JobDefOf.CarryDownedPawnToExit, p, exitSpot); job3.count = 1; job3.failIfCantJoinOrCreateCaravan = true; pawn.jobs.TryTakeOrderedJob(job3); }, MenuOptionPriority.High), pawn, item16)); } } } } if (pawn.equipment != null && pawn.equipment.Primary != null && GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForSelf(pawn), thingsOnly: true).Any()) { if (pawn.IsQuestLodger() && !EquipmentUtility.QuestLodgerCanUnequip(pawn.equipment.Primary, pawn)) { opts.Add(new FloatMenuOption("CannotDrop".Translate(pawn.equipment.Primary.Label, pawn.equipment.Primary) + ": " + "QuestRelated".Translate().CapitalizeFirst(), null)); } else { Action action5 = delegate { pawn.jobs.TryTakeOrderedJob(JobMaker.MakeJob(JobDefOf.DropEquipment, pawn.equipment.Primary)); }; opts.Add(new FloatMenuOption("Drop".Translate(pawn.equipment.Primary.Label, pawn.equipment.Primary), action5, MenuOptionPriority.Default, null, pawn)); } } foreach (LocalTargetInfo item17 in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForTrade(), thingsOnly: true)) { if (!pawn.CanReach(item17, PathEndMode.OnCell, Danger.Deadly)) { opts.Add(new FloatMenuOption("CannotTrade".Translate() + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else if (pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled) { opts.Add(new FloatMenuOption("CannotPrioritizeWorkTypeDisabled".Translate(SkillDefOf.Social.LabelCap), null)); } else if (!pawn.CanTradeWith(((Pawn)item17.Thing).Faction, ((Pawn)item17.Thing).TraderKind)) { opts.Add(new FloatMenuOption("CannotTradeMissingTitleAbility".Translate(), null)); } else { Pawn pTarg = (Pawn)item17.Thing; Action action6 = delegate { Job job2 = JobMaker.MakeJob(JobDefOf.TradeWithPawn, pTarg); job2.playerForced = true; pawn.jobs.TryTakeOrderedJob(job2); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.InteractingWithTraders, KnowledgeAmount.Total); }; string t2 = ""; if (pTarg.Faction != null) { t2 = " (" + pTarg.Faction.Name + ")"; } opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("TradeWith".Translate(pTarg.LabelShort + ", " + pTarg.TraderKind.label) + t2, action6, MenuOptionPriority.InitiateSocial, null, item17.Thing), pawn, pTarg)); } } foreach (LocalTargetInfo casket in GenUI.TargetsAt_NewTemp(clickPos, TargetingParameters.ForOpen(pawn), thingsOnly: true)) { if (!pawn.CanReach(casket, PathEndMode.OnCell, Danger.Deadly)) { opts.Add(new FloatMenuOption("CannotOpen".Translate(casket.Thing) + ": " + "NoPath".Translate().CapitalizeFirst(), null)); } else if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { opts.Add(new FloatMenuOption("CannotOpen".Translate(casket.Thing) + ": " + "Incapable".Translate(), null)); } else if (casket.Thing.Map.designationManager.DesignationOn(casket.Thing, DesignationDefOf.Open) == null) { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("Open".Translate(casket.Thing), delegate { Job job = JobMaker.MakeJob(JobDefOf.Open, casket.Thing); job.ignoreDesignations = true; pawn.jobs.TryTakeOrderedJob(job); }, MenuOptionPriority.High), pawn, casket.Thing)); } } foreach (Thing item18 in pawn.Map.thingGrid.ThingsAt(c)) { foreach (FloatMenuOption floatMenuOption2 in item18.GetFloatMenuOptions(pawn)) { opts.Add(floatMenuOption2); } } void Equip() { equipment.SetForbidden(value: false); pawn.jobs.TryTakeOrderedJob(JobMaker.MakeJob(JobDefOf.Equip, equipment)); MoteMaker.MakeStaticMote(equipment.DrawPos, equipment.Map, ThingDefOf.Mote_FeedbackEquip); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.EquippingWeapons, KnowledgeAmount.Total); } return(false); }
private static bool Prefix(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, Pawn trader, List <Thing> wares, List <Pawn> outPawns) { Func <Thing, float> massTotaler = t => t.stackCount * t.GetStatValue(StatDefOf.Mass, true); List <Thing> list = wares.Where(t => !(t is Pawn)).ToList(); list.SortByDescending(massTotaler); float ttlMassThings = list.Sum(massTotaler); float ttlCapacity = 0f; float ttlBodySize = 0f; int numCarriers = 0; IEnumerable <PawnGenOption> carrierKinds = groupMaker.carriers.Where(p => { if (parms.tile != -1) { return(Find.WorldGrid[parms.tile].biome.IsPackAnimalAllowed(p.kind.race)); } return(true); }); PawnKindDef kind = carrierKinds.RandomElementByWeight(x => x.selectionWeight).kind; // No slow or small juveniles Predicate <Pawn> validator = (p => p.ageTracker.CurLifeStage.bodySizeFactor >= 1 && p.GetStatValue(StatDefOf.MoveSpeed, true) >= p.kindDef.race.GetStatValueAbstract(StatDefOf.MoveSpeed) ); // 50/50 chance of uniform carriers (like vanilla) or mixed carriers bool mixedCarriers = Rand.RangeInclusive(0, 1) == 1; // Generate all of the carrier pawns (empty). Either we spawn as many pawns as we need to cover // 120% of the weight of the items, or enough pawns before it seems "unreasonable" based on body // size. for (; ttlCapacity < ttlMassThings * 1.2 && ttlBodySize < 20; numCarriers++) { PawnGenerationRequest request = new PawnGenerationRequest( kind: kind, faction: parms.faction, tile: parms.tile, inhabitant: parms.inhabitants, validatorPreGear: validator ); Pawn pawn = PawnGenerator.GeneratePawn(request); outPawns.Add(pawn); ttlCapacity += MassUtility.Capacity(pawn); // Still can't have 100 chickenmuffalos. That might slow down some PCs. ttlBodySize += Mathf.Max(pawn.BodySize, 0.5f); if (mixedCarriers) { kind = carrierKinds.RandomElementByWeight(x => x.selectionWeight).kind; } } // Add items (in descending order of weight) to randomly chosen pack animals. This isn't the most // efficient routine, as we're trying to be a bit random. If I was trying to be efficient, I would // use something like SortByDescending(p.Capacity) against the existing thing list. foreach (Thing thing in list) { List <Pawn> validPawns = outPawns.FindAll(p => !MassUtility.WillBeOverEncumberedAfterPickingUp(p, thing, thing.stackCount)); if (validPawns.Count() != 0) { validPawns.RandomElement().inventory.innerContainer.TryAdd(thing, true); } else if (thing.stackCount > 1) { // No carrier can handle the full stack; split it up int countLeft = thing.stackCount; int c = 0; // safety counter (while loops can be dangerous) while (countLeft > 0) { validPawns = outPawns.FindAll(p => MassUtility.CountToPickUpUntilOverEncumbered(p, thing) >= 1); if (validPawns.Count() != 0 && c < thing.stackCount) { Pawn pawn = validPawns.RandomElement(); int countToAdd = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing), countLeft); countLeft -= pawn.inventory.innerContainer.TryAdd(thing, countToAdd, true); } else { // Either no carrier can handle a single item, or we're just in some bad while loop breakout. In // any case, force it in, evenly split among all carriers. int splitCount = Mathf.FloorToInt(countLeft / outPawns.Count()); if (splitCount > 0) { outPawns.ForEach(p => p.inventory.innerContainer.TryAdd(thing, splitCount, true)); countLeft -= splitCount * outPawns.Count(); } // Give the remainer to the ones with space (one at a time) while (countLeft > 0) { validPawns = new List <Pawn>(outPawns); validPawns.SortByDescending(p => MassUtility.FreeSpace(p)); validPawns.First().inventory.innerContainer.TryAdd(thing, 1, true); countLeft--; } break; } c++; } } else { // No way to split it; force it in validPawns = new List <Pawn>(outPawns); validPawns.SortByDescending(p => MassUtility.FreeSpace(p)); validPawns.First().inventory.innerContainer.TryAdd(thing, true); } } // Always skip the original method return(false); }
public static void AddHumanlikeOrders(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts) { IntVec3 c = IntVec3.FromVector3(clickPos); foreach (Thing current in c.GetThingList(pawn.Map)) { Thing t = current; if (t.def.ingestible != null && pawn.RaceProps.CanEverEat(t) && t.IngestibleNow) { string text; if (t.def.ingestible.ingestCommandString.NullOrEmpty()) { text = "ConsumeThing".Translate(new object[] { t.LabelShort }); } else { text = string.Format(t.def.ingestible.ingestCommandString, t.LabelShort); } FloatMenuOption item = null; if (t.def.IsPleasureDrug && pawn.story != null && pawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire) < 0) { item = new FloatMenuOption(text + " (" + TraitDefOf.DrugDesire.DataAtDegree(-1).label + ")", null, MenuOptionPriority.Default, null, null, 0f, null); } else if (!pawn.CanReach(t, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)) { item = new FloatMenuOption(text + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null); } else { MenuOptionPriority priority = (!(t is Corpse)) ? MenuOptionPriority.Default : MenuOptionPriority.Low; ITWN.PostMenuOption(opts, pawn, current, text, delegate { t.SetForbidden(false, true); Job job = new Job(JobDefOf.Ingest, t); job.count = FoodUtility.WillIngestStackCountOf(pawn, t.def); pawn.jobs.TryTakeOrderedJob(job); }, priority: priority); } if (item != null) { opts.Add(item); } } } if (pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { foreach (LocalTargetInfo current2 in GenUI.TargetsAt(clickPos, TargetingParameters.ForRescue(pawn), true)) { Pawn victim = (Pawn)current2.Thing; if (!victim.InBed() && pawn.CanReach(victim, PathEndMode.OnCell, Danger.Deadly)) { if ((victim.Faction == Faction.OfPlayer && victim.MentalStateDef == null) || (victim.Faction != Faction.OfPlayer && victim.MentalStateDef == null && !victim.IsPrisonerOfColony && (victim.Faction == null || !victim.Faction.HostileTo(Faction.OfPlayer)))) { Pawn victim2 = victim; ITWN.PostMenuOption(opts, pawn, victim2, "Rescue".Translate(new object[] { victim.LabelCap }), delegate { Building_Bed building_Bed = RestUtility.FindBedFor(victim, pawn, false, false, false); if (building_Bed == null) { string str2; if (victim.RaceProps.Animal) { str2 = "NoAnimalBed".Translate(); } else { str2 = "NoNonPrisonerBed".Translate(); } Messages.Message("CannotRescue".Translate() + ": " + str2, victim, MessageSound.RejectInput); return; } Job job = new Job(JobDefOf.Rescue, victim, building_Bed); job.count = 1; pawn.jobs.TryTakeOrderedJob(job); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Rescuing, KnowledgeAmount.Total); }, MenuOptionPriority.RescueOrCapture, null, victim2, 0f, null); } if (victim.RaceProps.Humanlike && (victim.MentalStateDef != null || victim.Faction != Faction.OfPlayer || (victim.Downed && victim.guilt.IsGuilty))) { Pawn victim2 = victim; ITWN.PostMenuOption(opts, pawn, victim2, "Capture".Translate(new object[] { victim.LabelCap }), delegate { Building_Bed building_Bed = RestUtility.FindBedFor(victim, pawn, true, false, false); if (building_Bed == null) { Messages.Message("CannotCapture".Translate() + ": " + "NoPrisonerBed".Translate(), victim, MessageSound.RejectInput); return; } Job job = new Job(JobDefOf.Capture, victim, building_Bed); job.count = 1; pawn.jobs.TryTakeOrderedJob(job); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Capturing, KnowledgeAmount.Total); }, MenuOptionPriority.RescueOrCapture, null, victim2, 0f, null); } } } foreach (LocalTargetInfo current3 in GenUI.TargetsAt(clickPos, TargetingParameters.ForRescue(pawn), true)) { LocalTargetInfo targetInfo = current3; Pawn victim = (Pawn)targetInfo.Thing; if (victim.Downed && pawn.CanReach(victim, PathEndMode.OnCell, Danger.Deadly) && Building_CryptosleepCasket.FindCryptosleepCasketFor(victim, pawn) != null) { string label = "CarryToCryptosleepCasket".Translate(new object[] { targetInfo.Thing.LabelCap }); JobDef jDef = JobDefOf.CarryToCryptosleepCasket; Action action = delegate { Building_CryptosleepCasket building_CryptosleepCasket = Building_CryptosleepCasket.FindCryptosleepCasketFor(victim, pawn); if (building_CryptosleepCasket == null) { Messages.Message("CannotCarryToCryptosleepCasket".Translate() + ": " + "NoCryptosleepCasket".Translate(), victim, MessageSound.RejectInput); return; } Job job = new Job(jDef, victim, building_CryptosleepCasket); job.count = 1; pawn.jobs.TryTakeOrderedJob(job); }; Pawn victim2 = victim; ITWN.PostMenuOption(opts, pawn, victim2, label, action, MenuOptionPriority.Default, null, victim2, 0f, null); } } } foreach (LocalTargetInfo current4 in GenUI.TargetsAt(clickPos, TargetingParameters.ForStrip(pawn), true)) { LocalTargetInfo stripTarg = current4; FloatMenuOption item2 = null; if (!pawn.CanReach(stripTarg, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { item2 = new FloatMenuOption("CannotStrip".Translate(new object[] { stripTarg.Thing.LabelCap }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null); } else { ITWN.PostMenuOption(opts, pawn, stripTarg.Thing, "Strip".Translate(new object[] { stripTarg.Thing.LabelCap }), delegate { stripTarg.Thing.SetForbidden(false, false); pawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.Strip, stripTarg)); }); } if (item2 != null) { opts.Add(item2); } } if (pawn.equipment != null) { ThingWithComps equipment = null; List <Thing> thingList = c.GetThingList(pawn.Map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i].TryGetComp <CompEquippable>() != null) { equipment = (ThingWithComps)thingList[i]; break; } } if (equipment != null) { string labelShort = equipment.LabelShort; FloatMenuOption item3 = null; if (equipment.def.IsWeapon && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) { item3 = new FloatMenuOption("CannotEquip".Translate(new object[] { labelShort }) + " (" + "IsIncapableOfViolenceLower".Translate(new object[] { pawn.LabelShort }) + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else if (!pawn.CanReach(equipment, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { item3 = new FloatMenuOption("CannotEquip".Translate(new object[] { labelShort }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { item3 = new FloatMenuOption("CannotEquip".Translate(new object[] { labelShort }) + " (" + "Incapable".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null); } else { string text2 = "Equip".Translate(new object[] { labelShort }); if (equipment.def.IsRangedWeapon && pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler)) { text2 = text2 + " " + "EquipWarningBrawler".Translate(); } ITWN.PostMenuOption(opts, pawn, equipment, text2, delegate { equipment.SetForbidden(false, true); pawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.Equip, equipment)); MoteMaker.MakeStaticMote(equipment.DrawPos, equipment.Map, ThingDefOf.Mote_FeedbackEquip, 1f); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.EquippingWeapons, KnowledgeAmount.Total); }); } if (item3 != null) { opts.Add(item3); } } } if (pawn.apparel != null) { Apparel apparel = pawn.Map.thingGrid.ThingAt <Apparel>(c); if (apparel != null) { FloatMenuOption item4 = null; if (!pawn.CanReach(apparel, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { item4 = new FloatMenuOption("CannotWear".Translate(new object[] { apparel.Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null); } else if (!ApparelUtility.HasPartsToWear(pawn, apparel.def)) { item4 = new FloatMenuOption("CannotWear".Translate(new object[] { apparel.Label }) + " (" + "CannotWearBecauseOfMissingBodyParts".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null); } else { ITWN.PostMenuOption(opts, pawn, apparel, "ForceWear".Translate(new object[] { apparel.LabelShort }), delegate { apparel.SetForbidden(false, true); Job job = new Job(JobDefOf.Wear, apparel); pawn.jobs.TryTakeOrderedJob(job); }, priority: MenuOptionPriority.High); } if (item4 != null) { opts.Add(item4); } } } if (!pawn.Map.IsPlayerHome) { Thing item = c.GetFirstItem(pawn.Map); if (item != null && item.def.EverHaulable) { if (!pawn.CanReach(item, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { opts.Add(new FloatMenuOption("CannotPickUp".Translate(new object[] { item.Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else if (MassUtility.WillBeOverEncumberedAfterPickingUp(pawn, item, 1)) { ITWN.PostMenuOption(opts, pawn, item, "CannotPickUp".Translate(new object[] { item.Label }) + " (" + "TooHeavy".Translate() + ")", null); } else if (item.stackCount == 1) { ITWN.PostMenuOption(opts, pawn, item, "PickUp".Translate(new object[] { item.Label }), delegate { item.SetForbidden(false, false); Job job = new Job(JobDefOf.TakeInventory, item); job.count = 1; pawn.jobs.TryTakeOrderedJob(job); }, priority: MenuOptionPriority.High); } else { if (MassUtility.WillBeOverEncumberedAfterPickingUp(pawn, item, item.stackCount)) { ITWN.PostMenuOption(opts, pawn, item, "CannotPickUpAll".Translate(new object[] { item.Label }) + " (" + "TooHeavy".Translate() + ")", null); } else { ITWN.PostMenuOption(opts, pawn, item, "PickUpAll".Translate(new object[] { item.Label }), delegate { item.SetForbidden(false, false); Job job = new Job(JobDefOf.TakeInventory, item); job.count = item.stackCount; pawn.jobs.TryTakeOrderedJob(job); }, priority: MenuOptionPriority.High); } ITWN.PostMenuOption(opts, pawn, item, "PickUpSome".Translate(new object[] { item.Label }), delegate { int to = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(pawn, item), item.stackCount); Dialog_Slider window = new Dialog_Slider("PickUpCount".Translate(new object[] { item.LabelShort }), 1, to, delegate(int count) { item.SetForbidden(false, false); Job job = new Job(JobDefOf.TakeInventory, item); job.count = count; pawn.jobs.TryTakeOrderedJob(job); }, -2147483648); Find.WindowStack.Add(window); }, priority: MenuOptionPriority.High); } } } if (!pawn.Map.IsPlayerHome) { Thing item = c.GetFirstItem(pawn.Map); if (item != null && item.def.EverHaulable) { Pawn bestPackAnimal = GiveToPackAnimalUtility.PackAnimalWithTheMostFreeSpace(pawn.Map, pawn.Faction); if (bestPackAnimal != null) { if (!pawn.CanReach(item, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { opts.Add(new FloatMenuOption("CannotGiveToPackAnimal".Translate(new object[] { item.Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else if (MassUtility.WillBeOverEncumberedAfterPickingUp(bestPackAnimal, item, 1)) { ITWN.PostMenuOption(opts, pawn, item, "CannotGiveToPackAnimal".Translate(new object[] { item.Label }) + " (" + "TooHeavy".Translate() + ")", null); } else if (item.stackCount == 1) { ITWN.PostMenuOption(opts, pawn, item, "GiveToPackAnimal".Translate(new object[] { item.Label }), delegate { item.SetForbidden(false, false); Job job = new Job(JobDefOf.GiveToPackAnimal, item); job.count = 1; pawn.jobs.TryTakeOrderedJob(job); }, MenuOptionPriority.High); } else { if (MassUtility.WillBeOverEncumberedAfterPickingUp(bestPackAnimal, item, item.stackCount)) { ITWN.PostMenuOption(opts, pawn, item, "CannotGiveToPackAnimalAll".Translate(new object[] { item.Label }) + " (" + "TooHeavy".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { ITWN.PostMenuOption(opts, pawn, item, "GiveToPackAnimalAll".Translate(new object[] { item.Label }), delegate { item.SetForbidden(false, false); Job job = new Job(JobDefOf.GiveToPackAnimal, item); job.count = item.stackCount; pawn.jobs.TryTakeOrderedJob(job); }, MenuOptionPriority.High, null, null, 0f, null, null); } ITWN.PostMenuOption(opts, pawn, item, "GiveToPackAnimalSome".Translate(new object[] { item.Label }), delegate { int to = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(bestPackAnimal, item), item.stackCount); Dialog_Slider window = new Dialog_Slider("GiveToPackAnimalCount".Translate(new object[] { item.LabelShort }), 1, to, delegate(int count) { item.SetForbidden(false, false); Job job = new Job(JobDefOf.GiveToPackAnimal, item); job.count = count; pawn.jobs.TryTakeOrderedJob(job); }, -2147483648); Find.WindowStack.Add(window); }, MenuOptionPriority.High, null, null, 0f, null, null); } } } } if (!pawn.Map.IsPlayerHome) { foreach (LocalTargetInfo current5 in GenUI.TargetsAt(clickPos, TargetingParameters.ForRescue(pawn), true)) { Pawn p = (Pawn)current5.Thing; if (p.Faction == Faction.OfPlayer || p.HostFaction == Faction.OfPlayer) { if (!pawn.CanReach(p, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { opts.Add(new FloatMenuOption("CannotCarryToExit".Translate(new object[] { p.Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { IntVec3 exitSpot; if (!RCellFinder.TryFindBestExitSpot(pawn, out exitSpot, TraverseMode.ByPawn)) { ITWN.PostMenuOption(opts, pawn, p, "CannotCarryToExit".Translate(new object[] { p.Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { ITWN.PostMenuOption(opts, pawn, p, "CarryToExit".Translate(new object[] { p.Label }), delegate { Job job = new Job(JobDefOf.CarryDownedPawnToExit, p, exitSpot); job.count = 1; pawn.jobs.TryTakeOrderedJob(job); }, MenuOptionPriority.High, null, null, 0f, null, null); } } } } } if (pawn.equipment != null && pawn.equipment.Primary != null && GenUI.TargetsAt(clickPos, TargetingParameters.ForSelf(pawn), true).Any <LocalTargetInfo>()) { Action action2 = delegate { pawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.DropEquipment, pawn.equipment.Primary)); }; opts.Add(new FloatMenuOption("Drop".Translate(new object[] { pawn.equipment.Primary.Label }), action2, MenuOptionPriority.Default, null, null, 0f, null, null)); } foreach (LocalTargetInfo current6 in GenUI.TargetsAt(clickPos, TargetingParameters.ForTrade(), true)) { LocalTargetInfo dest = current6; if (!pawn.CanReach(dest, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)) { opts.Add(new FloatMenuOption("CannotTrade".Translate() + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { Pawn pTarg = (Pawn)dest.Thing; Action action3 = delegate { Job job = new Job(JobDefOf.TradeWithPawn, pTarg); job.playerForced = true; pawn.jobs.TryTakeOrderedJob(job); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.InteractingWithTraders, KnowledgeAmount.Total); }; string str = string.Empty; if (pTarg.Faction != null) { str = " (" + pTarg.Faction.Name + ")"; } Thing thing = dest.Thing; ITWN.PostMenuOption(opts, pawn, pTarg, "TradeWith".Translate(new object[] { pTarg.LabelShort + ", " + pTarg.TraderKind.label }) + str, action3, MenuOptionPriority.InitiateSocial, null, thing, 0f, null, null); } } foreach (Thing current7 in pawn.Map.thingGrid.ThingsAt(c)) { foreach (FloatMenuOption current8 in current7.GetFloatMenuOptions(pawn)) { opts.Add(current8); } } }
public static bool Prefix(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts) { IntVec3 c = IntVec3.FromVector3(clickPos); CompItemBelt comp = pawn.TryGetComp <CompItemBelt>(); if (comp != null) { if (c.GetThingList(pawn.Map).Count == 0 && !pawn.Drafted) { if (comp.innerContainer != null && comp.innerContainer.Count > 0) { if (!pawn.CanReach(c, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { opts.Add(new FloatMenuOption("IB_CannotDrop".Translate(new object[] { comp.innerContainer[0].Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("IB_DropItemBeltAll".Translate(new object[] { comp.innerContainer.ContentsString }), delegate { Job job = new Job(ItemBeltDefOf.RemoveItemFromBelt, c); pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, c, "ReservedBy")); } } } foreach (Thing current in c.GetThingList(pawn.Map)) { Thing t = current; if (t.def.ingestible != null && pawn.RaceProps.CanEverEat(t) && t.IngestibleNow) { Thing item = c.GetFirstItem(pawn.Map); if (item != null && item.def.EverHaulable) { if (!pawn.CanReach(item, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { opts.Add(new FloatMenuOption("CannotPickUp".Translate(new object[] { item.Label }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else if (MassUtility.WillBeOverEncumberedAfterPickingUp(pawn, item, 1)) { opts.Add(new FloatMenuOption("CannotPickUp".Translate(new object[] { item.Label }) + " (" + "TooHeavy".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else if (item.stackCount == 1) { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("IB_AddToItemBelt".Translate(new object[] { item.Label }), delegate { item.SetForbidden(false, false); Job job = new Job(ItemBeltDefOf.AddItemToBelt, item); job.count = 1; pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, item, "ReservedBy")); } else { if (MassUtility.WillBeOverEncumberedAfterPickingUp(pawn, item, item.stackCount)) { opts.Add(new FloatMenuOption("CannotPickUpAll".Translate(new object[] { item.Label }) + " (" + "TooHeavy".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("IB_AddAllToBelt".Translate(new object[] { item.Label }), delegate { item.SetForbidden(false, false); Job job = new Job(ItemBeltDefOf.AddItemToBelt, item); job.count = item.stackCount; pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, item, "ReservedBy")); } opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("IB_AddSomeToBelt".Translate(new object[] { item.Label }), delegate { int to = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(pawn, item), item.stackCount); Dialog_Slider window = new Dialog_Slider("PickUpCount".Translate(new object[] { item.LabelShort }), 1, to, delegate(int count) { item.SetForbidden(false, false); Job job = new Job(ItemBeltDefOf.AddItemToBelt, item); job.count = count; pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); }, -2147483648); Find.WindowStack.Add(window); }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, item, "ReservedBy")); } } } } } return(true); }
//get next, goto, take, check for more. Branches off to "all over the place" protected override IEnumerable <Toil> MakeNewToils() { CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>(); Toil wait = Toils_General.Wait(2); Toil nextTarget = Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A); //also does count yield return(nextTarget); //honestly the workgiver checks for encumbered, so until CE checks are in this is unnecessary //yield return CheckForOverencumbered();//Probably redundant without CE checks Toil gotoThing = new Toil { initAction = () => { pawn.pather.StartPath(TargetThingA, PathEndMode.ClosestTouch); }, defaultCompleteMode = ToilCompleteMode.PatherArrival }; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(gotoThing); Toil takeThing = new Toil { initAction = () => { Pawn actor = pawn; Thing thing = actor.CurJob.GetTarget(TargetIndex.A).Thing; Toils_Haul.ErrorCheckForCarry(actor, thing); //get max we can pick up int countToPickUp = Mathf.Min(job.count, MassUtility.CountToPickUpUntilOverEncumbered(actor, thing)); Log.Message($"{actor} is hauling to inventory {thing}:{countToPickUp}"); // yo dawg, I heard you like delegates so I put delegates in your delegate, so you can delegate your delegates. // because compilers don't respect IF statements in delegates and toils are fully iterated over as soon as the job starts. try { ((Action)(() => { if (ModCompatibilityCheck.CombatExtendedIsActive) { //CombatExtended.CompInventory ceCompInventory = actor.GetComp<CombatExtended.CompInventory>(); //ceCompInventory.CanFitInInventory(thing, out countToPickUp); } }))(); } catch (TypeLoadException) { } if (countToPickUp > 0) { Thing splitThing = thing.SplitOff(countToPickUp); bool shouldMerge = takenToInventory.GetHashSet().Any(x => x.def == thing.def); actor.inventory.GetDirectlyHeldThings().TryAdd(splitThing, shouldMerge); takenToInventory.RegisterHauledItem(splitThing); try { ((Action)(() => { if (ModCompatibilityCheck.CombatExtendedIsActive) { //CombatExtended.CompInventory ceCompInventory = actor.GetComp<CombatExtended.CompInventory>(); //ceCompInventory.UpdateInventory(); } }))(); } catch (TypeLoadException) { } } //thing still remains, so queue up hauling if we can + end the current job (smooth/instant transition) //This will technically release the reservations in the queue, but what can you do if (thing.Spawned) { Job haul = HaulAIUtility.HaulToStorageJob(actor, thing); if (haul?.TryMakePreToilReservations(actor, false) ?? false) { actor.jobs.jobQueue.EnqueueFirst(haul, JobTag.Misc); } actor.jobs.curDriver.JumpToToil(wait); } } }; yield return(takeThing); yield return(Toils_Jump.JumpIf(nextTarget, () => !job.targetQueueA.NullOrEmpty())); //Find more to haul, in case things spawned while this was in progess yield return(new Toil { initAction = () => { List <Thing> haulables = pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling(); WorkGiver_HaulToInventory haulMoreWork = DefDatabase <WorkGiverDef> .AllDefsListForReading.First(wg => wg.Worker is WorkGiver_HaulToInventory).Worker as WorkGiver_HaulToInventory; Thing haulMoreThing = GenClosest.ClosestThing_Global(pawn.Position, haulables, 12, t => haulMoreWork.HasJobOnThing(pawn, t)); //WorkGiver_HaulToInventory found more work nearby if (haulMoreThing != null) { Log.Message($"{pawn} hauling again : {haulMoreThing}"); Job haulMoreJob = haulMoreWork.JobOnThing(pawn, haulMoreThing); if (haulMoreJob.TryMakePreToilReservations(pawn, false)) { pawn.jobs.jobQueue.EnqueueFirst(haulMoreJob, JobTag.Misc); EndJobWith(JobCondition.Succeeded); } } } }); //maintain cell reservations on the trip back //TODO: do that when we carry things //I guess that means TODO: implement carrying the rest of the items in this job instead of falling back on HaulToStorageJob yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.ClosestTouch)); yield return(new Toil //Queue next job { initAction = () => { Pawn actor = pawn; Job curJob = actor.jobs.curJob; LocalTargetInfo storeCell = curJob.targetB; Job unloadJob = new Job(PickUpAndHaulJobDefOf.UnloadYourHauledInventory, storeCell); if (unloadJob.TryMakePreToilReservations(actor, false)) { actor.jobs.jobQueue.EnqueueFirst(unloadJob, JobTag.Misc); EndJobWith(JobCondition.Succeeded); //This will technically release the cell reservations in the queue, but what can you do } } }); yield return(wait); }
//reserve, goto, take, check for more. Branches off to "all over the place" protected override IEnumerable <Toil> MakeNewToils() { CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>(); HashSet <Thing> carriedThings = takenToInventory.GetHashSet(); DesignationDef HaulUrgentlyDesignation = DefDatabase <DesignationDef> .GetNamed("HaulUrgentlyDesignation", false); //Thanks to AlexTD for the more dynamic search range float searchForOthersRangeFraction = 0.5f; float distanceToOthers = 0f; Toil wait = Toils_General.Wait(2); Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null); Toil calculateExtraDistanceToGo = new Toil { initAction = () => { if (StoreUtility.TryFindStoreCellNearColonyDesperate(this.job.targetA.Thing, this.pawn, out IntVec3 storeLoc)) { distanceToOthers = (storeLoc - job.targetA.Thing.Position).LengthHorizontal * searchForOthersRangeFraction; } } }; yield return(calculateExtraDistanceToGo); Toil checkForOtherItemsToHaulToInventory = CheckForOtherItemsToHaulToInventory(reserveTargetA, TargetIndex.A, distanceToOthers, null); Toil checkForOtherItemsToUrgentlyHaulToInventory = CheckForOtherItemsToHaulToInventory(reserveTargetA, TargetIndex.A, distanceToOthers, (Thing x) => pawn.Map.designationManager.DesignationOn(x)?.def == HaulUrgentlyDesignation); yield return(reserveTargetA); Toil gotoThing = new Toil { initAction = () => { this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.ClosestTouch); }, defaultCompleteMode = ToilCompleteMode.PatherArrival, }; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(gotoThing); Toil takeThing = new Toil { initAction = () => { Pawn actor = this.pawn; Thing thing = actor.CurJob.GetTarget(TargetIndex.A).Thing; Toils_Haul.ErrorCheckForCarry(actor, thing); //get max we can pick up int num = Mathf.Min(thing.stackCount, MassUtility.CountToPickUpUntilOverEncumbered(actor, thing)); // yo dawg, I heard you like delegates so I put delegates in your delegate, so you can delegate your delegates. // because compilers don't respect IF statements in delegates and toils are fully iterated over as soon as the job starts. try { ((Action)(() => { if (ModCompatibilityCheck.CombatExtendedIsActive) { CombatExtended.CompInventory ceCompInventory = actor.GetComp <CombatExtended.CompInventory>(); ceCompInventory.CanFitInInventory(thing, out num, false, false); } }))(); } catch (TypeLoadException) { } //can't store more, so queue up hauling if we can + end the current job (smooth/instant transition) if (num <= 0) { Job haul = HaulAIUtility.HaulToStorageJob(actor, thing); if (haul?.TryMakePreToilReservations(actor) ?? false) { actor.jobs.jobQueue.EnqueueFirst(haul, new JobTag?(JobTag.Misc)); } actor.jobs.curDriver.JumpToToil(wait); } else { bool isUrgent = false; if (ModCompatibilityCheck.AllowToolIsActive) { //check BEFORE absorbing the thing, designation disappears when it's in inventory :^) if (pawn.Map.designationManager.DesignationOn(thing)?.def == HaulUrgentlyDesignation) { isUrgent = true; } } actor.inventory.GetDirectlyHeldThings().TryAdd(thing.SplitOff(num), true); takenToInventory.RegisterHauledItem(thing); try { ((Action)(() => { if (ModCompatibilityCheck.CombatExtendedIsActive) { CombatExtended.CompInventory ceCompInventory = actor.GetComp <CombatExtended.CompInventory>(); ceCompInventory.UpdateInventory(); } }))(); } catch (TypeLoadException) { } if (isUrgent) { actor.jobs.curDriver.JumpToToil(checkForOtherItemsToUrgentlyHaulToInventory); } } } }; yield return(takeThing); yield return(checkForOtherItemsToHaulToInventory); //we end the job in there, so only one of the checks for duplicates gets called. yield return(checkForOtherItemsToUrgentlyHaulToInventory); yield return(wait); }
// Decompiled code is painful to read... Continue at your own risk // TODO: Replace this with a cleaner solution // Maybe explore FloatMenuMakerMap public static List <FloatMenuOption> ChoicesForThing(Thing thing, Pawn pawn, string thingLabelShort) { var opts = new List <FloatMenuOption>(); var t = thing; string labelShort = ""; string label = thingLabelShort; if (thing.stackCount > 1) { label += " x" + thing.stackCount.ToStringCached(); } // Copied from FloatMenuMakerMap.AddHumanlikeOrders if (t.def.ingestible != null && canBeConsumedby[t].Contains(pawn) && t.IngestibleNow) { string text; if (t.def.ingestible.ingestCommandString.NullOrEmpty()) { text = "ConsumeThing".Translate(thingLabelShort, t); } else { text = string.Format(t.def.ingestible.ingestCommandString, thingLabelShort); } if (!t.IsSociallyProper(pawn)) { text = text + " (" + "ReservedForPrisoners".Translate() + ")"; } FloatMenuOption item7; if (t.def.IsNonMedicalDrug && pawn.IsTeetotaler()) { item7 = new FloatMenuOption(text + " (" + TraitDefOf.DrugDesire.DataAtDegree(-1).label + ")", null); } else if (!pawnCanReach_Oncell_Deadly.Contains(pawn)) { item7 = new FloatMenuOption(text + " (" + "NoPath".Translate() + ")", null); } else { var priority2 = !(t is Corpse) ? MenuOptionPriority.Default : MenuOptionPriority.Low; item7 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text, delegate { t.SetForbidden(false); var job = new Job(JobDefOf.Ingest, t); job.count = FoodUtility.WillIngestStackCountOf(pawn, t.def, t.GetStatValue(StatDefOf.Nutrition)); pawn.jobs.TryTakeOrderedJob(job); }, priority2), pawn, t); } opts.Add(item7); } // Add equipment commands // Copied from FloatMenuMakerMap.AddHumanlikeOrders if (thing is ThingWithComps equipment && equipment.GetComp <CompEquippable>() != null) { //ThingWithComps != Thing --> Label is diffrent implementing the override string LabelNoCount labelShort = thingLabelShort; if (equipment.AllComps != null) { int i = 0; for (int count = equipment.AllComps.Count; i < count; i++) { labelShort = equipment.AllComps[i].TransformLabel(labelShort); } } FloatMenuOption item4; if (equipment.def.IsWeapon && pawn.WorkTagIsDisabled(WorkTags.Violent)) { item4 = new FloatMenuOption( "CannotEquip".Translate(labelShort) + " (" + "IsIncapableOfViolenceLower".Translate(pawn.LabelShort, pawn) + ")", null); } else if (!pawnCanReach_Touch_Deadly.Contains(pawn)) { item4 = new FloatMenuOption("CannotEquip".Translate(labelShort) + " (" + "NoPath".Translate() + ")", null); } else if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { item4 = new FloatMenuOption( "CannotEquip".Translate(labelShort) + " (" + "Incapable".Translate() + ")", null); } else { string text5 = "Equip".Translate(labelShort); if (equipment.def.IsRangedWeapon && pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler)) { text5 = text5 + " " + "EquipWarningBrawler".Translate(); } item4 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text5, delegate { equipment.SetForbidden(false); pawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.Equip, equipment)); MoteMaker.MakeStaticMote(equipment.DrawPos, equipment.Map, ThingDefOf.Mote_FeedbackEquip); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.EquippingWeapons, KnowledgeAmount.Total); }, MenuOptionPriority.High), pawn, equipment); } opts.Add(item4); } // Add clothing commands var apparel = thing as Apparel; if (apparel != null) { //replaced apparel.Label label (the former would spawm MaxHitPonts) FloatMenuOption item5; if (!pawnCanReach_Touch_Deadly.Contains(pawn)) { item5 = new FloatMenuOption( "CannotWear".Translate(label, apparel) + " (" + "NoPath".Translate() + ")", null); } else if (!ApparelUtility.HasPartsToWear(pawn, apparel.def)) { item5 = new FloatMenuOption( "CannotWear".Translate(label, apparel) + " (" + "CannotWearBecauseOfMissingBodyParts".Translate() + ")", null); } else /*Apparel has no override for LabelShort therefor we can still use labelShort from ThingWithComps*/ { item5 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption( "ForceWear".Translate(labelShort, apparel), delegate { apparel.SetForbidden(false); var job = new Job(JobDefOf.Wear, apparel); pawn.jobs.TryTakeOrderedJob(job); }, MenuOptionPriority.High), pawn, apparel); } opts.Add(item5); } // Add caravan commands if (pawn.IsFormingCaravan()) { if (thing != null && thing.def.EverHaulable) { var packTarget = GiveToPackAnimalUtility.UsablePackAnimalWithTheMostFreeSpace(pawn) ?? pawn; var jobDef = packTarget != pawn ? JobDefOf.GiveToPackAnimal : JobDefOf.TakeInventory; //replaced thing.Label label (the former would spawm MaxHitPonts) if (!pawnCanReach_Touch_Deadly.Contains(pawn)) { opts.Add(new FloatMenuOption( "CannotLoadIntoCaravan".Translate(label, thing) + " (" + "NoPath".Translate() + ")", null)); } else if (MassUtility.WillBeOverEncumberedAfterPickingUp(packTarget, thing, 1)) { opts.Add(new FloatMenuOption( "CannotLoadIntoCaravan".Translate(label, thing) + " (" + "TooHeavy".Translate() + ")", null)); } else { var lordJob = (LordJob_FormAndSendCaravan)pawn.GetLord().LordJob; var capacityLeft = CaravanFormingUtility.CapacityLeft(lordJob); if (thing.stackCount == 1) { var capacityLeft4 = capacityLeft - thing.GetStatValue(StatDefOf.Mass); opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption( CaravanFormingUtility.AppendOverweightInfo( "LoadIntoCaravan".Translate(label, thing), capacityLeft4), delegate { thing.SetForbidden(false, false); var job = new Job(jobDef, thing); job.count = 1; job.checkEncumbrance = packTarget == pawn; pawn.jobs.TryTakeOrderedJob(job); }, MenuOptionPriority.High), pawn, thing)); } else { if (MassUtility.WillBeOverEncumberedAfterPickingUp(packTarget, thing, thing.stackCount)) { opts.Add(new FloatMenuOption( "CannotLoadIntoCaravanAll".Translate(label, thing) + " (" + "TooHeavy".Translate() + ")", null)); } else { var capacityLeft2 = capacityLeft - thing.stackCount * thing.GetStatValue(StatDefOf.Mass); opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption( CaravanFormingUtility.AppendOverweightInfo( "LoadIntoCaravanAll".Translate(label, thing), capacityLeft2), delegate { thing.SetForbidden(false, false); var job = new Job(jobDef, thing); job.count = thing.stackCount; job.checkEncumbrance = packTarget == pawn; pawn.jobs.TryTakeOrderedJob(job); }, MenuOptionPriority.High), pawn, thing)); } opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption( "LoadIntoCaravanSome".Translate(thingLabelShort, thing), delegate { var to = Mathf.Min(MassUtility.CountToPickUpUntilOverEncumbered(packTarget, thing), thing.stackCount); var window = new Dialog_Slider(delegate(int val) { var capacityLeft3 = capacityLeft - val * thing.GetStatValue(StatDefOf.Mass); return(CaravanFormingUtility.AppendOverweightInfo( string.Format("LoadIntoCaravanCount".Translate(thingLabelShort, thing), val), capacityLeft3)); }, 1, to, delegate(int count) { thing.SetForbidden(false, false); var job = new Job(jobDef, thing); job.count = count; job.checkEncumbrance = packTarget == pawn; pawn.jobs.TryTakeOrderedJob(job); }); Find.WindowStack.Add(window); }, MenuOptionPriority.High), pawn, thing)); } } } } return(opts); }
public static void Postfix(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts) { if (!AwesomeInventoryServiceProvider.TryGetImplementation <IInventoryHelper>(out IInventoryHelper inventoryHelper)) { Log.Error(string.Format(ErrorMessage.NotImplemented, typeof(IInventoryHelper).Name)); return; } IntVec3 position = IntVec3.FromVector3(clickPos); // Add options for equipment. if (pawn.equipment != null) { List <Thing> things = position.GetThingList(pawn.Map); foreach (Thing thing in things) { if (thing.TryGetComp <CompEquippable>() != null) { ThingWithComps equipment = (ThingWithComps)thing; if (equipment.def.IsWeapon && !pawn.WorkTagIsDisabled(WorkTags.Violent) && pawn.CanReach(equipment, PathEndMode.ClosestTouch, Danger.Deadly) && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) && !(pawn.IsQuestLodger() && (!equipment.def.IsWeapon || pawn.equipment.Primary != null)) && EquipmentUtility.CanEquip(equipment, pawn, out _)) { string text3 = UIText.AIEquip.Translate(thing.LabelShort); if (equipment.def.IsRangedWeapon && pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler)) { text3 += " " + UIText.EquipWarningBrawler.Translate(); } var option = FloatMenuUtility.DecoratePrioritizedTask( new FloatMenuOption( text3, () => { TaggedString equipWeaponConfirmationDialogText = ThingRequiringRoyalPermissionUtility.GetEquipWeaponConfirmationDialogText(equipment, pawn); CompBladelinkWeapon compBladelinkWeapon = equipment.TryGetComp <CompBladelinkWeapon>(); if (compBladelinkWeapon != null && compBladelinkWeapon.bondedPawn != pawn) { if (!equipWeaponConfirmationDialogText.NullOrEmpty()) { equipWeaponConfirmationDialogText += "\n\n"; } equipWeaponConfirmationDialogText += "BladelinkEquipWarning".Translate(); } if (!equipWeaponConfirmationDialogText.NullOrEmpty()) { equipWeaponConfirmationDialogText += "\n\n" + "RoyalWeaponEquipConfirmation".Translate(); Find.WindowStack.Add( new Dialog_MessageBox( equipWeaponConfirmationDialogText, "Yes".Translate(), () => { Equip(); }, "No".Translate())); } else { Equip(); } }, MenuOptionPriority.High), pawn, equipment); opts.Add(option); } void Equip() { equipment.SetForbidden(value: false); pawn.jobs.TryTakeOrderedJob(JobMaker.MakeJob(AwesomeInventory_JobDefOf.AwesomeInventory_MapEquip, equipment)); MoteMaker.MakeStaticMote(equipment.DrawPos, equipment.Map, ThingDefOf.Mote_FeedbackEquip); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.EquippingWeapons, KnowledgeAmount.Total); } } } } // Add options for apparel. if (pawn.apparel != null) { Apparel apparel = pawn.Map.thingGrid.ThingAt <Apparel>(position); if (apparel != null) { if (pawn.CanReach(apparel, PathEndMode.ClosestTouch, Danger.Deadly) && !apparel.IsBurning() && !pawn.apparel.WouldReplaceLockedApparel(apparel) && ApparelUtility.HasPartsToWear(pawn, apparel.def)) { FloatMenuOption option = FloatMenuUtility.DecoratePrioritizedTask( new FloatMenuOption( UIText.AIForceWear.Translate(apparel.LabelShort), () => { DressJob dressJob = SimplePool <DressJob> .Get(); dressJob.def = AwesomeInventory_JobDefOf.AwesomeInventory_Dress; dressJob.targetA = apparel; dressJob.ForceWear = true; apparel.SetForbidden(value: false); pawn.jobs.TryTakeOrderedJob(dressJob); }, MenuOptionPriority.High), pawn, apparel); opts.Add(option); option = FloatMenuUtility.DecoratePrioritizedTask( new FloatMenuOption( UIText.AIWear.Translate(apparel.LabelShort), () => { DressJob dressJob = SimplePool <DressJob> .Get(); dressJob.def = AwesomeInventory_JobDefOf.AwesomeInventory_Dress; dressJob.targetA = apparel; dressJob.ForceWear = false; apparel.SetForbidden(value: false); pawn.jobs.TryTakeOrderedJob(dressJob); }, MenuOptionPriority.High), pawn, apparel); opts.Add(option); } } } List <Thing> items = position.GetThingList(pawn.Map); foreach (Thing item in items) { if (item.def.category == ThingCategory.Item) { int count = MassUtility.CountToPickUpUntilOverEncumbered(pawn, item); if (count == 0) { continue; } count = Math.Min(count, item.stackCount); string displayText = UIText.Pickup.Translate(item.LabelNoCount + " x" + count); var option = FloatMenuUtility.DecoratePrioritizedTask( new FloatMenuOption( displayText , () => { Job job = JobMaker.MakeJob(JobDefOf.TakeInventory, item); job.count = count; pawn.jobs.TryTakeOrderedJob(job); }) , pawn , item); opts.Add(option); } } }