public static Tradeable TradeableMatching(Thing thing, List <Tradeable> tradeables) { if (thing == null || tradeables == null) { return(null); } for (int i = 0; i < tradeables.Count; i++) { Tradeable tradeable = tradeables[i]; if (tradeable.HasAnyThing) { TransferAsOneMode mode = (!tradeable.TraderWillTrade) ? TransferAsOneMode.InactiveTradeable : TransferAsOneMode.Normal; if (TransferableUtility.TransferAsOne(thing, tradeable.AnyThing, mode)) { return(tradeable); } } } return(null); }
private void AddToTransferables(Thing t, bool setToTransferMax = false) { TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatching(t, transferables, TransferAsOneMode.PodsOrCaravanPacking); if (transferableOneWay == null) { transferableOneWay = new TransferableOneWay(); transferables.Add(transferableOneWay); } if (transferableOneWay.things.Contains(t)) { Log.Error("Tried to add the same thing twice to TransferableOneWay: " + t); return; } transferableOneWay.things.Add(t); if (setToTransferMax) { transferableOneWay.AdjustTo(transferableOneWay.CountToTransfer + t.stackCount); } }
public static TransferableOneWay TransferableMatchingDesperate(Thing thing, List <TransferableOneWay> transferables, TransferAsOneMode mode) { if (thing == null || transferables == null) { return(null); } for (int i = 0; i < transferables.Count; i++) { TransferableOneWay transferableOneWay = transferables[i]; if (transferableOneWay.HasAnyThing) { if (transferableOneWay.things.Contains(thing)) { return(transferableOneWay); } } } for (int j = 0; j < transferables.Count; j++) { TransferableOneWay transferableOneWay2 = transferables[j]; if (transferableOneWay2.HasAnyThing) { if (TransferableUtility.TransferAsOne(thing, transferableOneWay2.AnyThing, mode)) { return(transferableOneWay2); } } } for (int k = 0; k < transferables.Count; k++) { TransferableOneWay transferableOneWay3 = transferables[k]; if (transferableOneWay3.HasAnyThing) { if (transferableOneWay3.ThingDef == thing.def) { return(transferableOneWay3); } } } return(null); }
private bool TryReformCaravan() { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(transferables); if (!CheckForErrors(pawnsFromTransferables)) { return(false); } AddItemsFromTransferablesToRandomInventories(pawnsFromTransferables); Caravan caravan = CaravanExitMapUtility.ExitMapAndCreateCaravan(pawnsFromTransferables, Faction.OfPlayer, CurrentTile, CurrentTile, destinationTile, sendMessage: false); map.Parent.CheckRemoveMapNow(); TaggedString taggedString = "MessageReformedCaravan".Translate(); if (caravan.pather.Moving && caravan.pather.ArrivalAction != null) { taggedString += " " + "MessageFormedCaravan_Orders".Translate() + ": " + caravan.pather.ArrivalAction.Label + "."; } Messages.Message(taggedString, caravan, MessageTypeDefOf.TaskCompletion, historical: false); return(true); }
public static Thing ThingFromStockToMergeWith(ITrader trader, Thing thing) { Thing result; if (thing is Pawn) { result = null; } else { foreach (Thing thing2 in trader.Goods) { if (TransferableUtility.TransferAsOne(thing2, thing, TransferAsOneMode.Normal) && thing2.CanStackWith(thing) && thing2.def.stackLimit != 1) { return(thing2); } } result = null; } return(result); }
public static float CapacityTransferables(List <TransferableOneWay> transferables, StringBuilder explanation = null) { CollectionsMassCalculator.tmpThingCounts.Clear(); for (int i = 0; i < transferables.Count; i++) { if (transferables[i].HasAnyThing) { if (transferables[i].AnyThing is Pawn) { TransferableUtility.TransferNoSplit(transferables[i].things, transferables[i].CountToTransfer, delegate(Thing originalThing, int toTake) { CollectionsMassCalculator.tmpThingCounts.Add(new ThingCount(originalThing, toTake)); }, false, false); } } } float result = CollectionsMassCalculator.Capacity(CollectionsMassCalculator.tmpThingCounts, explanation); CollectionsMassCalculator.tmpThingCounts.Clear(); return(result); }
public void AddToTheToLoadList(TransferableOneWay t, int count) { if (!t.HasAnyThing || t.CountToTransfer <= 0) { return; } if (this.leftToLoad == null) { this.leftToLoad = new List <TransferableOneWay>(); } if (TransferableUtility.TransferableMatching <TransferableOneWay>(t.AnyThing, this.leftToLoad, TransferAsOneMode.PodsOrCaravanPacking) != null) { Log.Error("Transferable already exists.", false); return; } TransferableOneWay transferableOneWay = new TransferableOneWay(); this.leftToLoad.Add(transferableOneWay); transferableOneWay.things.AddRange(t.things); transferableOneWay.AdjustTo(count); }
public void AddToTheToLoadList(TransferableOneWay t, int count) { if (t.HasAnyThing && t.CountToTransfer > 0) { if (leftToLoad == null) { leftToLoad = new List <TransferableOneWay>(); } if (TransferableUtility.TransferableMatching(t.AnyThing, leftToLoad, TransferAsOneMode.PodsOrCaravanPacking) != null) { Log.Error("Transferable already exists."); } else { TransferableOneWay transferableOneWay = new TransferableOneWay(); leftToLoad.Add(transferableOneWay); transferableOneWay.things.AddRange(t.things); transferableOneWay.AdjustTo(count); } } }
public int SubtractFromToLoadList(Thing t, int count, bool sendMessageOnFinished = true) { if (leftToLoad == null) { return(0); } TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatchingDesperate(t, leftToLoad, TransferAsOneMode.PodsOrCaravanPacking); if (transferableOneWay == null) { return(0); } if (transferableOneWay.CountToTransfer <= 0) { return(0); } int num = Mathf.Min(count, transferableOneWay.CountToTransfer); transferableOneWay.AdjustBy(-num); if (transferableOneWay.CountToTransfer <= 0) { leftToLoad.Remove(transferableOneWay); } if (sendMessageOnFinished && !AnyInGroupHasAnythingLeftToLoad) { CompShuttle comp = parent.GetComp <CompShuttle>(); if (comp == null || comp.AllRequiredThingsLoaded) { if (Props.max1PerGroup) { Messages.Message("MessageFinishedLoadingTransporterSingle".Translate(), parent, MessageTypeDefOf.TaskCompletion); } else { Messages.Message("MessageFinishedLoadingTransporters".Translate(), parent, MessageTypeDefOf.TaskCompletion); } } } return(num); }
private bool TryAccept() { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(this.transferables); bool result; if (!this.CheckForErrors(pawnsFromTransferables)) { result = false; } else { int transportersGroup = this.CreateAndAssignNewTransportersGroup(); this.AssignTransferablesToRandomTransporters(); IEnumerable <Pawn> enumerable = from x in pawnsFromTransferables where x.IsColonist && !x.Downed select x; if (enumerable.Any <Pawn>()) { foreach (Pawn pawn in enumerable) { Lord lord = pawn.GetLord(); if (lord != null) { lord.Notify_PawnLost(pawn, PawnLostCondition.ForcedToJoinOtherLord); } } LordMaker.MakeNewLord(Faction.OfPlayer, new LordJob_LoadAndEnterTransporters(transportersGroup), this.map, enumerable); foreach (Pawn pawn2 in enumerable) { if (pawn2.Spawned) { pawn2.jobs.EndCurrentJob(JobCondition.InterruptForced, true); } } } Messages.Message("MessageTransportersLoadingProcessStarted".Translate(), this.transporters[0].parent, MessageTypeDefOf.TaskCompletion, false); result = true; } return(result); }
private bool TryFormAndSendCaravan() { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(this.transferables); if (!this.CheckForErrors(pawnsFromTransferables)) { return(false); } Direction8Way direction8WayFromTo = Find.WorldGrid.GetDirection8WayFromTo(this.CurrentTile, this.startingTile); IntVec3 intVec; if (!this.TryFindExitSpot(pawnsFromTransferables, true, out intVec)) { if (!this.TryFindExitSpot(pawnsFromTransferables, false, out intVec)) { Messages.Message("CaravanCouldNotFindExitSpot".Translate(new object[] { direction8WayFromTo.LabelShort() }), MessageSound.RejectInput); return(false); } Messages.Message("CaravanCouldNotFindReachableExitSpot".Translate(new object[] { direction8WayFromTo.LabelShort() }), new GlobalTargetInfo(intVec, this.map, false), MessageSound.Negative); } IntVec3 meetingPoint; if (!this.TryFindRandomPackingSpot(intVec, out meetingPoint)) { Messages.Message("CaravanCouldNotFindPackingSpot".Translate(new object[] { direction8WayFromTo.LabelShort() }), new GlobalTargetInfo(intVec, this.map, false), MessageSound.RejectInput); return(false); } CaravanFormingUtility.StartFormingCaravan(pawnsFromTransferables, Faction.OfPlayer, this.transferables, meetingPoint, intVec, this.startingTile); Messages.Message("CaravanFormationProcessStarted".Translate(), pawnsFromTransferables[0], MessageSound.Benefit); return(true); }
private void SubtractFromToLoadList(Thing t, int count) { if (this.leftToLoad == null) { return; } TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatchingDesperate(t, this.leftToLoad); if (transferableOneWay == null) { return; } transferableOneWay.AdjustBy(-count); if (transferableOneWay.CountToTransfer <= 0) { this.leftToLoad.Remove(transferableOneWay); } if (!this.AnyInGroupHasAnythingLeftToLoad) { Messages.Message("MessageFinishedLoadingTransporters".Translate(), this.parent, MessageSound.Benefit); } }
private void SubtractFromToLoadList(Thing t, int count) { if (this.leftToLoad == null) { return; } TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatchingDesperate(t, this.leftToLoad, TransferAsOneMode.PodsOrCaravanPacking); if (transferableOneWay == null) { return; } transferableOneWay.AdjustBy(-count); if (transferableOneWay.CountToTransfer <= 0) { this.leftToLoad.Remove(transferableOneWay); } if (!this.AnyInGroupHasAnythingLeftToLoad) { Messages.Message("MessageFinishedLoadingTransporters".Translate(), this.parent, MessageTypeDefOf.TaskCompletion, true); } }
public static float CapacityLeftAfterTransfer(List <TransferableOneWay> transferables, StringBuilder explanation = null) { tmpThingCounts.Clear(); for (int i = 0; i < transferables.Count; i++) { if (transferables[i].HasAnyThing && transferables[i].AnyThing is Pawn) { thingsInReverse.Clear(); thingsInReverse.AddRange(transferables[i].things); thingsInReverse.Reverse(); TransferableUtility.TransferNoSplit(thingsInReverse, transferables[i].MaxCount - transferables[i].CountToTransfer, delegate(Thing originalThing, int toTake) { tmpThingCounts.Add(new ThingCount(originalThing, toTake)); }, removeIfTakingEntireThing: false, errorIfNotEnoughThings: false); } } thingsInReverse.Clear(); float result = Capacity(tmpThingCounts, explanation); tmpThingCounts.Clear(); return(result); }
public static float CapacityLeftAfterTransfer(List <TransferableOneWay> transferables) { CollectionsMassCalculator.tmpThingStackParts.Clear(); for (int i = 0; i < transferables.Count; i++) { if (transferables[i].HasAnyThing && transferables[i].AnyThing is Pawn) { CollectionsMassCalculator.thingsInReverse.Clear(); CollectionsMassCalculator.thingsInReverse.AddRange(transferables[i].things); CollectionsMassCalculator.thingsInReverse.Reverse(); TransferableUtility.TransferNoSplit(CollectionsMassCalculator.thingsInReverse, transferables[i].MaxCount - transferables[i].CountToTransfer, delegate(Thing originalThing, int toTake) { CollectionsMassCalculator.tmpThingStackParts.Add(new ThingStackPart(originalThing, toTake)); }, false, false); } } CollectionsMassCalculator.thingsInReverse.Clear(); float result = CollectionsMassCalculator.Capacity(CollectionsMassCalculator.tmpThingStackParts); CollectionsMassCalculator.tmpThingStackParts.Clear(); return(result); }
private bool DebugTryFormCaravanInstantly() { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(this.transferables); if (!pawnsFromTransferables.Any((Pawn x) => CaravanUtility.IsOwner(x, Faction.OfPlayer))) { Messages.Message("CaravanMustHaveAtLeastOneColonist".Translate(), MessageTypeDefOf.RejectInput, false); return(false); } this.AddItemsFromTransferablesToRandomInventories(pawnsFromTransferables); int num = this.startingTile; if (num < 0) { num = CaravanExitMapUtility.RandomBestExitTileFrom(this.map); } if (num < 0) { num = this.CurrentTile; } CaravanFormingUtility.FormAndCreateCaravan(pawnsFromTransferables, Faction.OfPlayer, this.CurrentTile, num, this.destinationTile); return(true); }
private bool TryAccept() { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(transferables); if (!CheckForErrors(pawnsFromTransferables)) { return(false); } if (LoadingInProgressOrReadyToLaunch) { AssignTransferablesToRandomTransporters(); TransporterUtility.MakeLordsAsAppropriate(pawnsFromTransferables, transporters, map); List <Pawn> allPawnsSpawned = map.mapPawns.AllPawnsSpawned; for (int i = 0; i < allPawnsSpawned.Count; i++) { if (allPawnsSpawned[i].CurJobDef == JobDefOf.HaulToTransporter && transporters.Contains(((JobDriver_HaulToTransporter)allPawnsSpawned[i].jobs.curDriver).Transporter)) { allPawnsSpawned[i].jobs.EndCurrentJob(JobCondition.InterruptForced); } } } else { TransporterUtility.InitiateLoading(transporters); AssignTransferablesToRandomTransporters(); TransporterUtility.MakeLordsAsAppropriate(pawnsFromTransferables, transporters, map); if (transporters[0].Props.max1PerGroup) { Messages.Message("MessageTransporterSingleLoadingProcessStarted".Translate(), transporters[0].parent, MessageTypeDefOf.TaskCompletion, historical: false); } else { Messages.Message("MessageTransportersLoadingProcessStarted".Translate(), transporters[0].parent, MessageTypeDefOf.TaskCompletion, historical: false); } } return(true); }
private static int TransferableCountHauledByOthers(Pawn pawn, TransferableOneWay transferable, Lord lord) { if (!transferable.HasAnyThing) { Log.Warning("Can't determine transferable count hauled by others because transferable has 0 things."); return(0); } List <Pawn> allPawnsSpawned = lord.Map.mapPawns.AllPawnsSpawned; int num = 0; for (int i = 0; i < allPawnsSpawned.Count; i++) { Pawn pawn2 = allPawnsSpawned[i]; if (pawn2 != pawn && pawn2.CurJob != null && pawn2.CurJob.def == JobDefOf.PrepareCaravan_GatherItems && pawn2.CurJob.lord == lord) { Thing toHaul = ((JobDriver_PrepareCaravan_GatherItems)pawn2.jobs.curDriver).ToHaul; if (transferable.things.Contains(toHaul) || TransferableUtility.TransferAsOne(transferable.AnyThing, toHaul)) { num += toHaul.stackCount; } } } return(num); }
private void DoBottomButtons(Rect rect) { Rect rect2 = new Rect(rect.width - BottomButtonSize.x, rect.height - 55f - 17f, BottomButtonSize.x, BottomButtonSize.y); if (Widgets.ButtonText(rect2, "Send".Translate())) { if (reform) { if (TryReformCaravan()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } } else { List <string> list = new List <string>(); Pair <float, float> daysWorthOfFood = DaysWorthOfFood; if (daysWorthOfFood.First < 5f) { list.Add((daysWorthOfFood.First < 0.1f) ? "DaysWorthOfFoodWarningDialog_NoFood".Translate() : "DaysWorthOfFoodWarningDialog".Translate(daysWorthOfFood.First.ToString("0.#"))); } else if (MostFoodWillRotSoon) { list.Add("CaravanFoodWillRotSoonWarningDialog".Translate()); } if (!TransferableUtility.GetPawnsFromTransferables(transferables).Any((Pawn pawn) => CaravanUtility.IsOwner(pawn, Faction.OfPlayer) && !pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled)) { list.Add("CaravanIncapableOfSocial".Translate()); } if (list.Count > 0) { if (CheckForErrors(TransferableUtility.GetPawnsFromTransferables(transferables))) { string str2 = string.Concat(list.Select((string str) => str + "\n\n").ToArray()) + "CaravanAreYouSure".Translate(); Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(str2, delegate { if (TryFormAndSendCaravan()) { Close(doCloseSound: false); } })); } } else if (TryFormAndSendCaravan()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } } } if (ShowCancelButton && Widgets.ButtonText(new Rect(0f, rect2.y, BottomButtonSize.x, BottomButtonSize.y), "CancelButton".Translate())) { Close(); } if (Widgets.ButtonText(new Rect(rect.width / 2f - BottomButtonSize.x - 8.5f, rect2.y, BottomButtonSize.x, BottomButtonSize.y), "ResetButton".Translate())) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(); CalculateAndRecacheTransferables(); } if (canChooseRoute) { if (Widgets.ButtonText(new Rect(rect.width / 2f + 8.5f, rect2.y, BottomButtonSize.x, BottomButtonSize.y), "ChangeRouteButton".Translate())) { soundClose.PlayOneShotOnCamera(); Find.WorldRoutePlanner.Start(this); } if (destinationTile != -1) { Rect rect3 = rect2; rect3.y += rect2.height + 4f; rect3.height = 200f; rect3.xMin -= 200f; Text.Anchor = TextAnchor.UpperRight; Widgets.Label(rect3, "CaravanEstimatedDaysToDestination".Translate(((float)TicksToArrive / 60000f).ToString("0.#"))); Text.Anchor = TextAnchor.UpperLeft; } } if (Prefs.DevMode) { float width = 200f; float height = BottomButtonSize.y / 2f; if (Widgets.ButtonText(new Rect(0f, rect2.yMax + 4f, width, height), "Dev: Send instantly") && DebugTryFormCaravanInstantly()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } if (Widgets.ButtonText(new Rect(204f, rect2.yMax + 4f, width, height), "Dev: Select everything")) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); SetToSendEverything(); } } }
private void DoBottomButtons(Rect rect) { double num = rect.width / 2.0; Vector2 bottomButtonSize = this.BottomButtonSize; double x2 = num - bottomButtonSize.x / 2.0; double y = rect.height - 55.0; Vector2 bottomButtonSize2 = this.BottomButtonSize; float x3 = bottomButtonSize2.x; Vector2 bottomButtonSize3 = this.BottomButtonSize; Rect rect2 = new Rect((float)x2, (float)y, x3, bottomButtonSize3.y); if (Widgets.ButtonText(rect2, "AcceptButton".Translate(), true, false, true)) { if (this.reform) { if (this.TryReformCaravan()) { SoundDefOf.TickHigh.PlayOneShotOnCamera(null); this.Close(false); } } else { List <string> list = new List <string>(); Pair <float, float> daysWorthOfFood = this.DaysWorthOfFood; if (daysWorthOfFood.First < 5.0) { list.Add((!(daysWorthOfFood.First < 0.10000000149011612)) ? "DaysWorthOfFoodWarningDialog".Translate(daysWorthOfFood.First.ToString("0.#")) : "DaysWorthOfFoodWarningDialog_NoFood".Translate()); } else if (this.MostFoodWillRotSoon) { list.Add("CaravanFoodWillRotSoonWarningDialog".Translate()); } if (!TransferableUtility.GetPawnsFromTransferables(this.transferables).Any((Pawn pawn) => CaravanUtility.IsOwner(pawn, Faction.OfPlayer) && !pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled)) { list.Add("CaravanIncapableOfSocial".Translate()); } if (list.Count > 0) { if (this.CheckForErrors(TransferableUtility.GetPawnsFromTransferables(this.transferables))) { string text = string.Concat((from str in list select str + "\n\n").ToArray()) + "CaravanAreYouSure".Translate(); Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(text, delegate { if (this.TryFormAndSendCaravan()) { this.Close(false); } }, false, null)); } } else if (this.TryFormAndSendCaravan()) { SoundDefOf.TickHigh.PlayOneShotOnCamera(null); this.Close(false); } } } double num2 = rect2.x - 10.0; Vector2 bottomButtonSize4 = this.BottomButtonSize; double x4 = num2 - bottomButtonSize4.x; float y2 = rect2.y; Vector2 bottomButtonSize5 = this.BottomButtonSize; float x5 = bottomButtonSize5.x; Vector2 bottomButtonSize6 = this.BottomButtonSize; Rect rect3 = new Rect((float)x4, y2, x5, bottomButtonSize6.y); if (Widgets.ButtonText(rect3, "ResetButton".Translate(), true, false, true)) { SoundDefOf.TickLow.PlayOneShotOnCamera(null); this.CalculateAndRecacheTransferables(); } double x6 = rect2.xMax + 10.0; float y3 = rect2.y; Vector2 bottomButtonSize7 = this.BottomButtonSize; float x7 = bottomButtonSize7.x; Vector2 bottomButtonSize8 = this.BottomButtonSize; Rect rect4 = new Rect((float)x6, y3, x7, bottomButtonSize8.y); if (Widgets.ButtonText(rect4, (!this.cancellingWillAbandon) ? "CancelButton".Translate() : "AbandonButton".Translate(), true, false, true)) { this.Close(true); } if (this.showEstTimeToDestinationButton) { float width = rect.width; Vector2 bottomButtonSize9 = this.BottomButtonSize; float x8 = width - bottomButtonSize9.x; float y4 = rect2.y; Vector2 bottomButtonSize10 = this.BottomButtonSize; float x9 = bottomButtonSize10.x; Vector2 bottomButtonSize11 = this.BottomButtonSize; Rect rect5 = new Rect(x8, y4, x9, bottomButtonSize11.y); if (Widgets.ButtonText(rect5, "EstimatedTimeToDestinationButton".Translate(), true, false, true)) { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(this.transferables); if (!pawnsFromTransferables.Any((Pawn x) => CaravanUtility.IsOwner(x, Faction.OfPlayer) && !x.Downed)) { Messages.Message("CaravanMustHaveAtLeastOneColonist".Translate(), MessageTypeDefOf.RejectInput); } else { Find.WorldRoutePlanner.Start(this); } } } if (Prefs.DevMode) { float width2 = 200f; Vector2 bottomButtonSize12 = this.BottomButtonSize; float num3 = (float)(bottomButtonSize12.y / 2.0); Rect rect6 = new Rect(0f, (float)(rect.height - 55.0), width2, num3); if (Widgets.ButtonText(rect6, "Dev: Send instantly", true, false, true) && this.DebugTryFormCaravanInstantly()) { SoundDefOf.TickHigh.PlayOneShotOnCamera(null); this.Close(false); } Rect rect7 = new Rect(0f, (float)(rect.height - 55.0 + num3), width2, num3); if (Widgets.ButtonText(rect7, "Dev: Select everything", true, false, true)) { SoundDefOf.TickHigh.PlayOneShotOnCamera(null); this.SetToSendEverything(); } } }
private void DoBottomButtons(Rect rect) { Rect rect2 = new Rect(rect.width / 2f - this.BottomButtonSize.x / 2f, rect.height - 55f - 17f, this.BottomButtonSize.x, this.BottomButtonSize.y); if (Widgets.ButtonText(rect2, "AcceptButton".Translate(), true, false, true)) { if (this.reform) { if (this.TryReformCaravan()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); this.Close(false); } } else { List <string> list = new List <string>(); Pair <float, float> daysWorthOfFood = this.DaysWorthOfFood; if (daysWorthOfFood.First < 5f) { list.Add((daysWorthOfFood.First >= 0.1f) ? "DaysWorthOfFoodWarningDialog".Translate(daysWorthOfFood.First.ToString("0.#")) : "DaysWorthOfFoodWarningDialog_NoFood".Translate()); } else if (this.MostFoodWillRotSoon) { list.Add("CaravanFoodWillRotSoonWarningDialog".Translate()); } if (!TransferableUtility.GetPawnsFromTransferables(this.transferables).Any((Pawn pawn) => CaravanUtility.IsOwner(pawn, Faction.OfPlayer) && !pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled)) { list.Add("CaravanIncapableOfSocial".Translate()); } if (list.Count > 0) { if (this.CheckForErrors(TransferableUtility.GetPawnsFromTransferables(this.transferables))) { string text = string.Concat((from str in list select str + "\n\n").ToArray <string>()) + "CaravanAreYouSure".Translate(); Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(text, delegate { if (this.TryFormAndSendCaravan()) { this.Close(false); } }, false, null)); } } else if (this.TryFormAndSendCaravan()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); this.Close(false); } } } Rect rect3 = new Rect(rect2.x - 10f - this.BottomButtonSize.x, rect2.y, this.BottomButtonSize.x, this.BottomButtonSize.y); if (Widgets.ButtonText(rect3, "ResetButton".Translate(), true, false, true)) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(null); this.CalculateAndRecacheTransferables(); } if (this.ShowCancelButton) { Rect rect4 = new Rect(rect2.xMax + 10f, rect2.y, this.BottomButtonSize.x, this.BottomButtonSize.y); if (Widgets.ButtonText(rect4, "CancelButton".Translate(), true, false, true)) { this.Close(true); } } if (this.canChooseRoute) { Rect rect5 = new Rect(rect.width - this.BottomButtonSize.x, rect2.y, this.BottomButtonSize.x, this.BottomButtonSize.y); if (Widgets.ButtonText(rect5, "ChooseRouteButton".Translate(), true, false, true)) { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(this.transferables); if (!pawnsFromTransferables.Any((Pawn x) => CaravanUtility.IsOwner(x, Faction.OfPlayer) && !x.Downed)) { Messages.Message("CaravanMustHaveAtLeastOneColonist".Translate(), MessageTypeDefOf.RejectInput, false); } else { Find.WorldRoutePlanner.Start(this); } } if (this.destinationTile != -1) { Rect rect6 = rect5; rect6.y += rect5.height + 4f; rect6.height = 200f; rect6.xMin -= 200f; Text.Anchor = TextAnchor.UpperRight; Widgets.Label(rect6, "CaravanEstimatedDaysToDestination".Translate(((float)this.TicksToArrive / 60000f).ToString("0.#"))); Text.Anchor = TextAnchor.UpperLeft; } } if (Prefs.DevMode) { float width = 200f; float num = this.BottomButtonSize.y / 2f; Rect rect7 = new Rect(0f, rect.height - 55f - 17f, width, num); if (Widgets.ButtonText(rect7, "Dev: Send instantly", true, false, true) && this.DebugTryFormCaravanInstantly()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); this.Close(false); } Rect rect8 = new Rect(0f, rect.height - 55f - 17f + num, width, num); if (Widgets.ButtonText(rect8, "Dev: Select everything", true, false, true)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); this.SetToSendEverything(); } } }
private void DoBottomButtons(Rect rect) { float num = rect.width / 2f; Vector2 bottomButtonSize = BottomButtonSize; float x = num - bottomButtonSize.x / 2f; float y = rect.height - 55f; Vector2 bottomButtonSize2 = BottomButtonSize; float x2 = bottomButtonSize2.x; Vector2 bottomButtonSize3 = BottomButtonSize; Rect rect2 = new Rect(x, y, x2, bottomButtonSize3.y); if (Widgets.ButtonText(rect2, "AcceptButton".Translate())) { if (CaravanMassUsage > CaravanMassCapacity && CaravanMassCapacity != 0f) { if (CheckForErrors(TransferableUtility.GetPawnsFromTransferables(transferables))) { Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("TransportersCaravanWillBeImmobile".Translate(), delegate { if (TryAccept()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } })); } } else if (TryAccept()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } } float num2 = rect2.x - 10f; Vector2 bottomButtonSize4 = BottomButtonSize; float x3 = num2 - bottomButtonSize4.x; float y2 = rect2.y; Vector2 bottomButtonSize5 = BottomButtonSize; float x4 = bottomButtonSize5.x; Vector2 bottomButtonSize6 = BottomButtonSize; Rect rect3 = new Rect(x3, y2, x4, bottomButtonSize6.y); if (Widgets.ButtonText(rect3, "ResetButton".Translate())) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(); CalculateAndRecacheTransferables(); } float x5 = rect2.xMax + 10f; float y3 = rect2.y; Vector2 bottomButtonSize7 = BottomButtonSize; float x6 = bottomButtonSize7.x; Vector2 bottomButtonSize8 = BottomButtonSize; Rect rect4 = new Rect(x5, y3, x6, bottomButtonSize8.y); if (Widgets.ButtonText(rect4, "CancelButton".Translate())) { Close(); } if (Prefs.DevMode) { float width = 200f; Vector2 bottomButtonSize9 = BottomButtonSize; float num3 = bottomButtonSize9.y / 2f; Rect rect5 = new Rect(0f, rect.height - 55f, width, num3); if (Widgets.ButtonText(rect5, "Dev: Load instantly") && DebugTryLoadInstantly()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } Rect rect6 = new Rect(0f, rect.height - 55f + num3, width, num3); if (Widgets.ButtonText(rect6, "Dev: Select everything")) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); SetToLoadEverything(); } } }
public static ThingCount FindThingToLoad(Pawn p, CompTransporter transporter) { neededThings.Clear(); List <TransferableOneWay> leftToLoad = transporter.leftToLoad; tmpAlreadyLoading.Clear(); if (leftToLoad != null) { List <Pawn> allPawnsSpawned = transporter.Map.mapPawns.AllPawnsSpawned; for (int i = 0; i < allPawnsSpawned.Count; i++) { if (allPawnsSpawned[i] != p && allPawnsSpawned[i].CurJobDef == JobDefOf.HaulToTransporter) { JobDriver_HaulToTransporter jobDriver_HaulToTransporter = (JobDriver_HaulToTransporter)allPawnsSpawned[i].jobs.curDriver; if (jobDriver_HaulToTransporter.Container == transporter.parent) { TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatchingDesperate(jobDriver_HaulToTransporter.ThingToCarry, leftToLoad, TransferAsOneMode.PodsOrCaravanPacking); if (transferableOneWay != null) { int value = 0; if (tmpAlreadyLoading.TryGetValue(transferableOneWay, out value)) { tmpAlreadyLoading[transferableOneWay] = value + jobDriver_HaulToTransporter.initialCount; } else { tmpAlreadyLoading.Add(transferableOneWay, jobDriver_HaulToTransporter.initialCount); } } } } } for (int j = 0; j < leftToLoad.Count; j++) { TransferableOneWay transferableOneWay2 = leftToLoad[j]; if (!tmpAlreadyLoading.TryGetValue(leftToLoad[j], out int value2)) { value2 = 0; } if (transferableOneWay2.CountToTransfer - value2 > 0) { for (int k = 0; k < transferableOneWay2.things.Count; k++) { neededThings.Add(transferableOneWay2.things[k]); } } } } if (!neededThings.Any()) { tmpAlreadyLoading.Clear(); return(default(ThingCount)); } Thing thing = GenClosest.ClosestThingReachable(p.Position, p.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.Touch, TraverseParms.For(p), 9999f, (Thing x) => neededThings.Contains(x) && p.CanReserve(x)); if (thing == null) { foreach (Thing neededThing in neededThings) { Pawn pawn = neededThing as Pawn; if (pawn != null && (!pawn.IsColonist || pawn.Downed) && !pawn.inventory.UnloadEverything && p.CanReserveAndReach(pawn, PathEndMode.Touch, Danger.Deadly)) { neededThings.Clear(); tmpAlreadyLoading.Clear(); return(new ThingCount(pawn, 1)); } } } neededThings.Clear(); if (thing != null) { TransferableOneWay transferableOneWay3 = null; for (int l = 0; l < leftToLoad.Count; l++) { if (leftToLoad[l].things.Contains(thing)) { transferableOneWay3 = leftToLoad[l]; break; } } if (!tmpAlreadyLoading.TryGetValue(transferableOneWay3, out int value3)) { value3 = 0; } tmpAlreadyLoading.Clear(); return(new ThingCount(thing, Mathf.Min(transferableOneWay3.CountToTransfer - value3, thing.stackCount))); } tmpAlreadyLoading.Clear(); return(default(ThingCount)); }
private void AssignTransferablesToRandomTransporters() { tmpLeftToLoadCopy.Clear(); for (int j = 0; j < transporters.Count; j++) { tmpLeftToLoadCopy.Add((transporters[j].leftToLoad != null) ? transporters[j].leftToLoad.ToList() : new List <TransferableOneWay>()); if (transporters[j].leftToLoad != null) { transporters[j].leftToLoad.Clear(); } } tmpLeftCountToTransfer.Clear(); for (int k = 0; k < transferables.Count; k++) { tmpLeftCountToTransfer.Add(transferables[k], transferables[k].CountToTransfer); } if (LoadingInProgressOrReadyToLaunch) { int i; for (i = 0; i < transferables.Count; i++) { if (!transferables[i].HasAnyThing || tmpLeftCountToTransfer[transferables[i]] <= 0) { continue; } for (int l = 0; l < tmpLeftToLoadCopy.Count; l++) { TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatching(transferables[i].AnyThing, tmpLeftToLoadCopy[l], TransferAsOneMode.PodsOrCaravanPacking); if (transferableOneWay != null) { int num = Mathf.Min(tmpLeftCountToTransfer[transferables[i]], transferableOneWay.CountToTransfer); if (num > 0) { transporters[l].AddToTheToLoadList(transferables[i], num); tmpLeftCountToTransfer[transferables[i]] -= num; } } Thing thing = transporters[l].innerContainer.FirstOrDefault((Thing x) => TransferableUtility.TransferAsOne(transferables[i].AnyThing, x, TransferAsOneMode.PodsOrCaravanPacking)); if (thing != null) { int num2 = Mathf.Min(tmpLeftCountToTransfer[transferables[i]], thing.stackCount); if (num2 > 0) { transporters[l].AddToTheToLoadList(transferables[i], num2); tmpLeftCountToTransfer[transferables[i]] -= num2; } } } } } tmpLeftToLoadCopy.Clear(); if (transferables.Any()) { TransferableOneWay transferableOneWay2 = transferables.MaxBy((TransferableOneWay x) => tmpLeftCountToTransfer[x]); int num3 = 0; for (int m = 0; m < transferables.Count; m++) { if (transferables[m] != transferableOneWay2 && tmpLeftCountToTransfer[transferables[m]] > 0) { transporters[num3 % transporters.Count].AddToTheToLoadList(transferables[m], tmpLeftCountToTransfer[transferables[m]]); num3++; } } if (num3 < transporters.Count) { int num4 = tmpLeftCountToTransfer[transferableOneWay2]; int num5 = num4 / (transporters.Count - num3); for (int n = num3; n < transporters.Count; n++) { int num6 = (n == transporters.Count - 1) ? num4 : num5; if (num6 > 0) { transporters[n].AddToTheToLoadList(transferableOneWay2, num6); } num4 -= num6; } } else { transporters[num3 % transporters.Count].AddToTheToLoadList(transferableOneWay2, tmpLeftCountToTransfer[transferableOneWay2]); } } tmpLeftCountToTransfer.Clear(); for (int num7 = 0; num7 < transporters.Count; num7++) { for (int num8 = 0; num8 < transporters[num7].innerContainer.Count; num8++) { Thing thing2 = transporters[num7].innerContainer[num8]; int num9 = transporters[num7].SubtractFromToLoadList(thing2, thing2.stackCount, sendMessageOnFinished: false); if (num9 < thing2.stackCount) { transporters[num7].innerContainer.TryDrop(thing2, ThingPlaceMode.Near, thing2.stackCount - num9, out Thing _); } } } }
private void DoBottomButtons(Rect rect) { float num = rect.width / 2f; Vector2 bottomButtonSize = BottomButtonSize; float x2 = num - bottomButtonSize.x / 2f; float y = rect.height - 55f - 17f; Vector2 bottomButtonSize2 = BottomButtonSize; float x3 = bottomButtonSize2.x; Vector2 bottomButtonSize3 = BottomButtonSize; Rect rect2 = new Rect(x2, y, x3, bottomButtonSize3.y); if (Widgets.ButtonText(rect2, "AcceptButton".Translate())) { if (reform) { if (TryReformCaravan()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } } else { List <string> list = new List <string>(); Pair <float, float> daysWorthOfFood = DaysWorthOfFood; if (daysWorthOfFood.First < 5f) { list.Add((!(daysWorthOfFood.First < 0.1f)) ? "DaysWorthOfFoodWarningDialog".Translate(daysWorthOfFood.First.ToString("0.#")) : "DaysWorthOfFoodWarningDialog_NoFood".Translate()); } else if (MostFoodWillRotSoon) { list.Add("CaravanFoodWillRotSoonWarningDialog".Translate()); } if (!TransferableUtility.GetPawnsFromTransferables(transferables).Any((Pawn pawn) => CaravanUtility.IsOwner(pawn, Faction.OfPlayer) && !pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled)) { list.Add("CaravanIncapableOfSocial".Translate()); } if (list.Count > 0) { if (CheckForErrors(TransferableUtility.GetPawnsFromTransferables(transferables))) { string text = string.Concat((from str in list select str + "\n\n").ToArray()) + "CaravanAreYouSure".Translate(); Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(text, delegate { if (TryFormAndSendCaravan()) { Close(doCloseSound: false); } })); } } else if (TryFormAndSendCaravan()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } } } float num2 = rect2.x - 10f; Vector2 bottomButtonSize4 = BottomButtonSize; float x4 = num2 - bottomButtonSize4.x; float y2 = rect2.y; Vector2 bottomButtonSize5 = BottomButtonSize; float x5 = bottomButtonSize5.x; Vector2 bottomButtonSize6 = BottomButtonSize; Rect rect3 = new Rect(x4, y2, x5, bottomButtonSize6.y); if (Widgets.ButtonText(rect3, "ResetButton".Translate())) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(); CalculateAndRecacheTransferables(); } if (ShowCancelButton) { float x6 = rect2.xMax + 10f; float y3 = rect2.y; Vector2 bottomButtonSize7 = BottomButtonSize; float x7 = bottomButtonSize7.x; Vector2 bottomButtonSize8 = BottomButtonSize; Rect rect4 = new Rect(x6, y3, x7, bottomButtonSize8.y); if (Widgets.ButtonText(rect4, "CancelButton".Translate())) { Close(); } } if (canChooseRoute) { float width = rect.width; Vector2 bottomButtonSize9 = BottomButtonSize; float x8 = width - bottomButtonSize9.x; float y4 = rect2.y; Vector2 bottomButtonSize10 = BottomButtonSize; float x9 = bottomButtonSize10.x; Vector2 bottomButtonSize11 = BottomButtonSize; Rect rect5 = new Rect(x8, y4, x9, bottomButtonSize11.y); if (Widgets.ButtonText(rect5, "ChooseRouteButton".Translate())) { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(transferables); if (!pawnsFromTransferables.Any((Pawn x) => CaravanUtility.IsOwner(x, Faction.OfPlayer) && !x.Downed)) { Messages.Message("CaravanMustHaveAtLeastOneColonist".Translate(), MessageTypeDefOf.RejectInput, historical: false); } else { Find.WorldRoutePlanner.Start(this); } } if (destinationTile != -1) { Rect rect6 = rect5; rect6.y += rect5.height + 4f; rect6.height = 200f; rect6.xMin -= 200f; Text.Anchor = TextAnchor.UpperRight; Widgets.Label(rect6, "CaravanEstimatedDaysToDestination".Translate(((float)TicksToArrive / 60000f).ToString("0.#"))); Text.Anchor = TextAnchor.UpperLeft; } } if (Prefs.DevMode) { float width2 = 200f; Vector2 bottomButtonSize12 = BottomButtonSize; float num3 = bottomButtonSize12.y / 2f; Rect rect7 = new Rect(0f, rect.height - 55f - 17f, width2, num3); if (Widgets.ButtonText(rect7, "Dev: Send instantly") && DebugTryFormCaravanInstantly()) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Close(doCloseSound: false); } Rect rect8 = new Rect(0f, rect.height - 55f - 17f + num3, width2, num3); if (Widgets.ButtonText(rect8, "Dev: Select everything")) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); SetToSendEverything(); } } }
public static bool TransferAsOne(Thing a, Thing b, TransferAsOneMode mode) { if (a == b) { return(true); } if (a.def != b.def) { return(false); } a = a.GetInnerIfMinified(); b = b.GetInnerIfMinified(); if (a.def.tradeNeverStack || b.def.tradeNeverStack) { return(false); } if (!TransferableUtility.CanStack(a) || !TransferableUtility.CanStack(b)) { return(false); } if (a.def != b.def || a.Stuff != b.Stuff) { return(false); } if (mode == TransferAsOneMode.PodsOrCaravanPacking) { float num = -1f; CompRottable compRottable = a.TryGetComp <CompRottable>(); if (compRottable != null) { num = compRottable.RotProgressPct; } float num2 = -1f; CompRottable compRottable2 = b.TryGetComp <CompRottable>(); if (compRottable2 != null) { num2 = compRottable2.RotProgressPct; } if (Mathf.Abs(num - num2) > 0.1f) { return(false); } } if (a is Corpse && b is Corpse) { Pawn innerPawn = ((Corpse)a).InnerPawn; Pawn innerPawn2 = ((Corpse)b).InnerPawn; return(innerPawn.def == innerPawn2.def && innerPawn.kindDef == innerPawn2.kindDef && !innerPawn.RaceProps.Humanlike && !innerPawn2.RaceProps.Humanlike && (innerPawn.Name == null || innerPawn.Name.Numerical) && (innerPawn2.Name == null || innerPawn2.Name.Numerical)); } if (a.def.category == ThingCategory.Pawn) { if (b.def != a.def) { return(false); } Pawn pawn = (Pawn)a; Pawn pawn2 = (Pawn)b; return(pawn.kindDef == pawn2.kindDef && pawn.gender == pawn2.gender && pawn.ageTracker.CurLifeStageIndex == pawn2.ageTracker.CurLifeStageIndex && Mathf.Abs(pawn.ageTracker.AgeBiologicalYearsFloat - pawn2.ageTracker.AgeBiologicalYearsFloat) <= 1f); } else { Apparel apparel = a as Apparel; Apparel apparel2 = b as Apparel; if (apparel != null && apparel2 != null && apparel.WornByCorpse != apparel2.WornByCorpse) { return(false); } if (mode != TransferAsOneMode.InactiveTradeable && a.def.useHitPoints && Mathf.Abs(a.HitPoints - b.HitPoints) >= 10) { return(false); } QualityCategory qualityCategory; QualityCategory qualityCategory2; if (a.TryGetQuality(out qualityCategory) && b.TryGetQuality(out qualityCategory2) && qualityCategory != qualityCategory2) { return(false); } if (a.def.category == ThingCategory.Item) { return(a.CanStackWith(b)); } if (a.def.category == ThingCategory.Building) { return(true); } Log.Error(string.Concat(new object[] { "Unknown TransferAsOne pair: ", a, ", ", b }), false); return(false); } }
private void SelectApproximateBestFoodAndMedicine() { IEnumerable <TransferableOneWay> enumerable = transferables.Where((TransferableOneWay x) => x.ThingDef.category != ThingCategory.Pawn && !x.ThingDef.thingCategories.NullOrEmpty() && x.ThingDef.thingCategories.Contains(ThingCategoryDefOf.Medicine)); IEnumerable <TransferableOneWay> enumerable2 = transferables.Where((TransferableOneWay x) => x.ThingDef.IsIngestible && !x.ThingDef.IsDrug && !x.ThingDef.IsCorpse); tmpBeds.Clear(); for (int i = 0; i < transferables.Count; i++) { for (int j = 0; j < transferables[i].things.Count; j++) { Thing thing = transferables[i].things[j]; for (int k = 0; k < thing.stackCount; k++) { Building_Bed building_Bed; if ((building_Bed = thing.GetInnerIfMinified() as Building_Bed) != null && building_Bed.def.building.bed_caravansCanUse) { for (int l = 0; l < building_Bed.SleepingSlotsCount; l++) { tmpBeds.Add(transferables[i]); } } } } } tmpBeds.SortByDescending((TransferableOneWay x) => x.AnyThing.GetStatValue(StatDefOf.BedRestEffectiveness)); foreach (TransferableOneWay item in enumerable) { item.AdjustTo(0); } foreach (TransferableOneWay item2 in enumerable2) { item2.AdjustTo(0); } foreach (TransferableOneWay tmpBed in tmpBeds) { tmpBed.AdjustTo(0); } List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(transferables); if (!pawnsFromTransferables.Any()) { return; } foreach (Pawn item3 in pawnsFromTransferables) { TransferableOneWay transferableOneWay = BestBedFor(item3); if (transferableOneWay != null) { tmpBeds.Remove(transferableOneWay); if (transferableOneWay.CanAdjustBy(1).Accepted) { AddOneIfMassAllows(transferableOneWay); } } if (item3.AnimalOrWildMan() || item3.guest.IsPrisoner) { continue; } for (int m = 0; m < 2; m++) { Transferable transferable = BestMedicineItemFor(item3, enumerable); if (transferable != null) { AddOneIfMassAllows(transferable); } } } if (destinationTile == -1 || !DaysWorthOfFoodCalculator.AnyFoodEatingPawn(pawnsFromTransferables) || !enumerable2.Any()) { return; } try { using WorldPath path = Find.WorldPathFinder.FindPath(CurrentTile, destinationTile, null); int ticksPerMove = CaravanTicksPerMoveUtility.GetTicksPerMove(new CaravanTicksPerMoveUtility.CaravanInfo(this)); CaravanArrivalTimeEstimator.EstimatedTicksToArriveToEvery(CurrentTile, destinationTile, path, 0f, ticksPerMove, Find.TickManager.TicksAbs, tmpTicksToArrive); float num = (float)tmpTicksToArrive.Last().Second / 60000f + 4f; float num2; bool flag; do { num2 = DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(transferables, CurrentTile, IgnoreInventoryMode, Faction.OfPlayer, path, 0f, ticksPerMove); if (num2 >= num) { break; } flag = false; foreach (Pawn item4 in pawnsFromTransferables) { Transferable transferable2 = BestFoodItemFor(item4, enumerable2, tmpTicksToArrive); if (transferable2 != null && AddOneIfMassAllows(transferable2)) { flag = true; } } }while (flag && num2 < num && MassUsage < MassCapacity); } finally { tmpTicksToArrive.Clear(); daysWorthOfFoodDirty = true; massUsageDirty = true; } }
private void DoBottomButtons(Rect rect) { Rect rect2 = new Rect(rect.width / 2f - this.BottomButtonSize.x / 2f, rect.height - 55f, this.BottomButtonSize.x, this.BottomButtonSize.y); if (Widgets.ButtonText(rect2, "AcceptButton".Translate(), true, false, true)) { if (this.reform) { if (this.TryReformCaravan()) { SoundDefOf.TickHigh.PlayOneShotOnCamera(null); this.Close(false); } } else { string text = null; Pair <float, float> daysWorthOfFood = this.DaysWorthOfFood; if (daysWorthOfFood.First < 5f) { text = ((daysWorthOfFood.First >= 0.1f) ? "DaysWorthOfFoodWarningDialog".Translate(new object[] { daysWorthOfFood.First.ToString("0.#") }) : "DaysWorthOfFoodWarningDialog_NoFood".Translate()); } else if (this.MostFoodWillRotSoon) { text = "CaravanFoodWillRotSoonWarningDialog".Translate(); } if (!text.NullOrEmpty()) { if (this.CheckForErrors(TransferableUtility.GetPawnsFromTransferables(this.transferables))) { Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(text, delegate { if (this.TryFormAndSendCaravan()) { this.Close(false); } }, false, null)); } } else if (this.TryFormAndSendCaravan()) { SoundDefOf.TickHigh.PlayOneShotOnCamera(null); this.Close(false); } } } Rect rect3 = new Rect(rect2.x - 10f - this.BottomButtonSize.x, rect2.y, this.BottomButtonSize.x, this.BottomButtonSize.y); if (Widgets.ButtonText(rect3, "ResetButton".Translate(), true, false, true)) { SoundDefOf.TickLow.PlayOneShotOnCamera(null); this.CalculateAndRecacheTransferables(); } Rect rect4 = new Rect(rect2.xMax + 10f, rect2.y, this.BottomButtonSize.x, this.BottomButtonSize.y); if (Widgets.ButtonText(rect4, "CancelButton".Translate(), true, false, true)) { this.Close(true); } if (this.showEstTimeToDestinationButton) { Rect rect5 = new Rect(rect.width - this.BottomButtonSize.x, rect2.y, this.BottomButtonSize.x, this.BottomButtonSize.y); if (Widgets.ButtonText(rect5, "EstimatedTimeToDestinationButton".Translate(), true, false, true)) { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(this.transferables); if (!pawnsFromTransferables.Any((Pawn x) => CaravanUtility.IsOwner(x, Faction.OfPlayer) && !x.Downed)) { Messages.Message("CaravanMustHaveAtLeastOneColonist".Translate(), MessageSound.RejectInput); } else { Find.WorldRoutePlanner.Start(this); } } } if (Prefs.DevMode) { float width = 200f; float num = this.BottomButtonSize.y / 2f; Rect rect6 = new Rect(0f, rect.height - 55f, width, num); if (Widgets.ButtonText(rect6, "Dev: Send instantly", true, false, true) && this.DebugTryFormCaravanInstantly()) { SoundDefOf.TickHigh.PlayOneShotOnCamera(null); this.Close(false); } Rect rect7 = new Rect(0f, rect.height - 55f + num, width, num); if (Widgets.ButtonText(rect7, "Dev: Select everything", true, false, true)) { SoundDefOf.TickHigh.PlayOneShotOnCamera(null); this.SetToSendEverything(); } } }