public static bool ShouldIgnoreInventoryOf(Pawn pawn, IgnorePawnsInventoryMode ignoreMode) { switch (ignoreMode) { case IgnorePawnsInventoryMode.Ignore: return(true); case IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload: if (pawn.Spawned) { return(pawn.inventory.UnloadEverything); } return(false); case IgnorePawnsInventoryMode.IgnoreIfAssignedToUnloadOrPlayerPawn: if (!pawn.Spawned || !pawn.inventory.UnloadEverything) { return(Dialog_FormCaravan.CanListInventorySeparately(pawn)); } return(true); case IgnorePawnsInventoryMode.DontIgnore: return(false); default: throw new NotImplementedException("IgnorePawnsInventoryMode"); } }
private void CalculateAndRecacheTransferables() { transferables = new List <TransferableOneWay>(); AddPawnsToTransferables(); AddItemsToTransferables(); IEnumerable <TransferableOneWay> enumerable = null; string sourceLabel = null; string destinationLabel = null; string sourceCountDesc = "FormCaravanColonyThingCountTip".Translate(); bool drawMass = true; IgnorePawnsInventoryMode ignorePawnInventoryMass = IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload; bool includePawnsMassInMassUsage = true; Func <float> availableMassGetter = () => MassCapacity - MassUsage; int tile = map.Tile; pawnsTransfer = new TransferableOneWayWidget(enumerable, sourceLabel, destinationLabel, sourceCountDesc, drawMass, ignorePawnInventoryMass, includePawnsMassInMassUsage, availableMassGetter, 0f, ignoreSpawnedCorpseGearAndInventoryMass: false, tile, drawMarketValue: true, drawEquippedWeapon: true, drawNutritionEatenPerDay: true, drawItemNutrition: false, drawForagedFoodPerDay: true); CaravanUIUtility.AddPawnsSections(pawnsTransfer, transferables); enumerable = from x in transferables where x.ThingDef.category != ThingCategory.Pawn select x; sourceCountDesc = null; destinationLabel = null; sourceLabel = "FormCaravanColonyThingCountTip".Translate(); includePawnsMassInMassUsage = true; ignorePawnInventoryMass = IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload; drawMass = true; availableMassGetter = (() => MassCapacity - MassUsage); tile = map.Tile; itemsTransfer = new TransferableOneWayWidget(enumerable, sourceCountDesc, destinationLabel, sourceLabel, includePawnsMassInMassUsage, ignorePawnInventoryMass, drawMass, availableMassGetter, 0f, ignoreSpawnedCorpseGearAndInventoryMass: false, tile, drawMarketValue: true, drawEquippedWeapon: false, drawNutritionEatenPerDay: false, drawItemNutrition: true, drawForagedFoodPerDay: false, drawDaysUntilRot: true); CountToTransferChanged(); }
private void CalculateAndRecacheTransferables() { this.transferables = new List <TransferableOneWay>(); this.AddPawnsToTransferables(); this.AddItemsToTransferables(); this.AddContentsToTransferables(); IEnumerable <TransferableOneWay> enumerable = null; string text = null; string destinationLabel = null; string text2 = "FormCaravanColonyThingCountTip".Translate(); bool flag = true; IgnorePawnsInventoryMode ignorePawnInventoryMass = IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload; bool flag2 = true; Func <float> availableMassGetter = () => this.MassCapacity - this.MassUsage; int tile = this.map.Tile; this.pawnsTransfer = new TransferableOneWayWidget(enumerable, text, destinationLabel, text2, flag, ignorePawnInventoryMass, flag2, availableMassGetter, 0f, false, tile, true, true, true, false, true, false, false); CaravanUIUtility.AddPawnsSections(this.pawnsTransfer, this.transferables); enumerable = from x in this.transferables where x.ThingDef.category != ThingCategory.Pawn select x; text2 = null; destinationLabel = null; text = "FormCaravanColonyThingCountTip".Translate(); flag2 = true; ignorePawnInventoryMass = IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload; flag = true; availableMassGetter = (() => this.MassCapacity - this.MassUsage); tile = this.map.Tile; this.itemsTransfer = new TransferableOneWayWidget(enumerable, text2, destinationLabel, text, flag2, ignorePawnInventoryMass, flag, availableMassGetter, 0f, false, tile, true, false, false, true, false, true, false); this.CountToTransferChanged(); }
public static bool ShouldIgnoreInventoryOf(Pawn pawn, IgnorePawnsInventoryMode ignoreMode) { bool result; switch (ignoreMode) { case IgnorePawnsInventoryMode.Ignore: result = true; break; case IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload: result = (pawn.Spawned && pawn.inventory.UnloadEverything); break; case IgnorePawnsInventoryMode.IgnoreIfAssignedToUnloadOrPlayerPawn: result = ((pawn.Spawned && pawn.inventory.UnloadEverything) || Dialog_FormCaravan.CanListInventorySeparately(pawn)); break; case IgnorePawnsInventoryMode.DontIgnore: result = false; break; default: throw new NotImplementedException("IgnorePawnsInventoryMode"); } return(result); }
public static float MassUsage(List <ThingCount> thingCounts, IgnorePawnsInventoryMode ignoreInventory, bool includePawnsMass = false, bool ignoreSpawnedCorpsesGearAndInventory = false) { float num = 0f; for (int i = 0; i < thingCounts.Count; i++) { int count = thingCounts[i].Count; if (count <= 0) { continue; } Thing thing = thingCounts[i].Thing; Pawn pawn = thing as Pawn; if (pawn != null) { num = ((!includePawnsMass) ? (num + MassUtility.GearAndInventoryMass(pawn) * (float)count) : (num + pawn.GetStatValue(StatDefOf.Mass) * (float)count)); if (InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignoreInventory)) { num -= MassUtility.InventoryMass(pawn) * (float)count; } continue; } num += thing.GetStatValue(StatDefOf.Mass) * (float)count; if (ignoreSpawnedCorpsesGearAndInventory) { Corpse corpse = thing as Corpse; if (corpse != null && corpse.Spawned) { num -= MassUtility.GearAndInventoryMass(corpse.InnerPawn) * (float)count; } } } return(Mathf.Max(num, 0f)); }
public TransferableOneWayWidget(IEnumerable <TransferableOneWay> transferables, string sourceLabel, string destinationLabel, string sourceCountDesc, bool drawMass = false, IgnorePawnsInventoryMode ignorePawnInventoryMass = IgnorePawnsInventoryMode.DontIgnore, bool includePawnsMassInMassUsage = false, Func <float> availableMassGetter = null, float extraHeaderSpace = 0f, bool ignoreSpawnedCorpseGearAndInventoryMass = false, int tile = -1, bool drawMarketValue = false, bool drawEquippedWeapon = false, bool drawNutritionEatenPerDay = false, bool drawItemNutrition = false, bool drawForagedFoodPerDay = false, bool drawDaysUntilRot = false, bool playerPawnsReadOnly = false) { if (transferables != null) { this.AddSection(null, transferables); } this.sourceLabel = sourceLabel; this.destinationLabel = destinationLabel; this.sourceCountDesc = sourceCountDesc; this.drawMass = drawMass; this.ignorePawnInventoryMass = ignorePawnInventoryMass; this.includePawnsMassInMassUsage = includePawnsMassInMassUsage; this.availableMassGetter = availableMassGetter; this.extraHeaderSpace = extraHeaderSpace; this.ignoreSpawnedCorpseGearAndInventoryMass = ignoreSpawnedCorpseGearAndInventoryMass; this.tile = tile; this.drawMarketValue = drawMarketValue; this.drawEquippedWeapon = drawEquippedWeapon; this.drawNutritionEatenPerDay = drawNutritionEatenPerDay; this.drawItemNutrition = drawItemNutrition; this.drawForagedFoodPerDay = drawForagedFoodPerDay; this.drawDaysUntilRot = drawDaysUntilRot; this.playerPawnsReadOnly = playerPawnsReadOnly; this.sorter1 = TransferableSorterDefOf.Category; this.sorter2 = TransferableSorterDefOf.MarketValue; }
public static float ApproxDaysWorthOfWaterLeftAfterTradeableTransfer( List <Thing> allCurrentThings, List <Tradeable> tradeables, IgnorePawnsInventoryMode ignoreInventory) { TransferableUtility.SimulateTradeableTransfer(allCurrentThings, tradeables, tmpThingStackParts); tmpPawns.Clear(); tmpThingDefCounts.Clear(); for (var i = tmpThingStackParts.Count - 1; i >= 0; i--) { if (tmpThingStackParts[i].Thing is Pawn pawn) { tmpPawns.Add(pawn); } else { tmpThingDefCounts.Add( new ThingDefCount(tmpThingStackParts[i].Thing.def, tmpThingStackParts[i].Count)); } } tmpThingStackParts.Clear(); var result = ApproxDaysWorthOfWater(tmpPawns, tmpThingDefCounts, ignoreInventory); tmpPawns.Clear(); tmpThingDefCounts.Clear(); return(result); }
private void CalculateAndRecacheTransferables() { this.transferables = new List <TransferableOneWay>(); this.AddItemsToTransferables(); IEnumerable <TransferableOneWay> enumerable = null; string text = null; string text2 = null; string text3 = "FormCaravanColonyThingCountTip".Translate(); bool flag = true; IgnorePawnsInventoryMode ignorePawnsInventoryMode = (IgnorePawnsInventoryMode)1; bool flag2 = true; Func <float> func = () => this.MassCapacity - this.MassUsage; int tile = this.map.Tile; this.pawnsTransfer = new TransferableOneWayWidget(enumerable, text, text2, text3, flag, ignorePawnsInventoryMode, flag2, func, 0f, false, tile, true, true, true, false, true, false, false); CaravanUIUtility.AddPawnsSections(this.pawnsTransfer, this.transferables); enumerable = from x in this.transferables where x.ThingDef.category != ThingCategory.Pawn select x; text3 = null; text2 = null; text = "FormCaravanColonyThingCountTip".Translate(); flag2 = true; ignorePawnsInventoryMode = (IgnorePawnsInventoryMode)1; flag = true; func = (() => this.MassCapacity - this.MassUsage); tile = this.map.Tile; this.itemsTransfer = new TransferableOneWayWidget(enumerable, text3, text2, text, flag2, ignorePawnsInventoryMode, flag, func, 0f, false, tile, true, false, false, true, false, true, false); this.CountToTransferChanged(); }
public static float ApproxDaysWorthOfWater( List <TransferableOneWay> transferables, IgnorePawnsInventoryMode ignoreInventory) { tmpThingDefCounts.Clear(); tmpPawns.Clear(); foreach (var transferableOneWay in transferables) { if (!transferableOneWay.HasAnyThing) { continue; } if (transferableOneWay.AnyThing is Pawn) { for (var j = 0; j < transferableOneWay.CountToTransfer; j++) { tmpPawns.Add((Pawn)transferableOneWay.things[j]); } } else { tmpThingDefCounts.Add( new ThingDefCount(transferableOneWay.ThingDef, transferableOneWay.CountToTransfer)); } } var result = ApproxDaysWorthOfWater(tmpPawns, tmpThingDefCounts, ignoreInventory); tmpThingDefCounts.Clear(); tmpPawns.Clear(); return(result); }
public static void CreateCaravanTransferableWidgets(List <TransferableOneWay> transferables , out TransferableOneWayWidget itemsTransfer, string sourceLabel, string destLabel, string thingCountTip , IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreCorpsesGearAndInventoryMass) { //метод из CaravanUIUtility с удалением лишнего itemsTransfer = new TransferableOneWayWidget(from x in transferables //where x.ThingDef.category != ThingCategory.Pawn select x, sourceLabel, destLabel, thingCountTip, true, ignorePawnInventoryMass, false, availableMassGetter, 24f, ignoreCorpsesGearAndInventoryMass); }
//public static class DaysWorthOfFoodCalculator //{ public static void ApproxDaysWorthOfFoodPawns_PostFix(ref List <Pawn> pawns, List <ThingDefCount> extraFood, int tile, IgnorePawnsInventoryMode ignoreInventory, Faction faction, WorldPath path, float nextTileCostLeft, int caravanTicksPerMove, bool assumeCaravanMoving) { if (pawns == null) { pawns = new List <Pawn>(); } pawns.AddRange(caravanVampires); }
//public static class DaysWorthOfFoodCalculator //{ public static void ApproxDaysWorthOfFoodPawns_PreFix(ref List <Pawn> pawns, List <ThingDefCount> extraFood, int tile, IgnorePawnsInventoryMode ignoreInventory, Faction faction, WorldPath path, float nextTileCostLeft, int caravanTicksPerMove, bool assumeCaravanMoving) { if (!pawns.NullOrEmpty()) { caravanVampires = new List <Pawn>(); caravanVampires.AddRange(pawns.FindAll(x => x.IsVampire())); pawns.RemoveAll(x => x.IsVampire()); } }
//public static class DaysWorthOfFoodCalculator //{ public static void ApproxDaysWorthOfFood_PostFix(ref List <TransferableOneWay> transferables, int tile, IgnorePawnsInventoryMode ignoreInventory, Faction faction, WorldPath path = null, float nextTileCostLeft = 0f, int caravanTicksPerMove = 3300) { if (transferables == null) { transferables = new List <TransferableOneWay>(); } transferables.AddRange(caravanTransferrables); }
public static float MassUsage <T>(List <T> things, IgnorePawnsInventoryMode ignoreInventory, bool includePawnsMass = false, bool ignoreCorpsesGearAndInventory = false) where T : Thing { CollectionsMassCalculator.tmpThingStackParts.Clear(); for (int i = 0; i < things.Count; i++) { CollectionsMassCalculator.tmpThingStackParts.Add(new ThingStackPart((Thing)(object)things[i], ((Thing)(object)things[i]).stackCount)); } float result = CollectionsMassCalculator.MassUsage(CollectionsMassCalculator.tmpThingStackParts, ignoreInventory, includePawnsMass, ignoreCorpsesGearAndInventory); CollectionsMassCalculator.tmpThingStackParts.Clear(); return(result); }
//public static class DaysWorthOfFoodCalculator //{ public static void ApproxDaysWorthOfFood_PreFix(ref List <TransferableOneWay> transferables, int tile, IgnorePawnsInventoryMode ignoreInventory, Faction faction, WorldPath path = null, float nextTileCostLeft = 0f, int caravanTicksPerMove = 3300) { if (!transferables.NullOrEmpty()) { caravanTransferrables = new List <TransferableOneWay>(); caravanTransferrables.AddRange(transferables.FindAll(x => x.HasAnyThing && x.AnyThing is Pawn y && y.IsVampire())); transferables.RemoveAll(x => x.HasAnyThing && x.AnyThing is Pawn y && y.IsVampire()); } }
public static float MassUsage <T>(List <T> things, IgnorePawnsInventoryMode ignoreInventory, bool includePawnsMass = false, bool ignoreSpawnedCorpsesGearAndInventory = false) where T : Thing { tmpThingCounts.Clear(); for (int i = 0; i < things.Count; i++) { tmpThingCounts.Add(new ThingCount(things[i], things[i].stackCount)); } float result = MassUsage(tmpThingCounts, ignoreInventory, includePawnsMass, ignoreSpawnedCorpsesGearAndInventory); tmpThingCounts.Clear(); return(result); }
public static void Postfix(List <TransferableOneWay> transferables, ref TransferableOneWayWidget pawnsTransfer, ref TransferableOneWayWidget itemsTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly) { var modifiedTransferables = transferables.Where(x => x.ThingDef.category != ThingCategory.Pawn).ToList(); modifiedTransferables = modifiedTransferables .Where(x => !x.ThingDef.IsWithinCategory(ThingCategoryDef.Named("RoadEquipment"))).ToList(); itemsTransfer = new TransferableOneWayWidget(modifiedTransferables, null, null, thingCountTip, true, ignorePawnInventoryMass, false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, true, false, false, true, false, true); }
public static bool ShouldIgnoreInventoryOf(Pawn pawn, IgnorePawnsInventoryMode ignoreMode) { switch (ignoreMode) { case IgnorePawnsInventoryMode.Ignore: return(true); case IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload: return(pawn.Spawned && pawn.inventory.UnloadEverything); case IgnorePawnsInventoryMode.DontIgnore: return(false); default: throw new NotImplementedException("IgnorePawnsInventoryMode"); } }
public static float MassUsage(List <ThingStackPart> stackParts, IgnorePawnsInventoryMode ignoreInventory, bool includePawnsMass = false, bool ignoreCorpsesGearAndInventory = false) { float num = 0f; for (int i = 0; i < stackParts.Count; i++) { int count = stackParts[i].Count; if (count > 0) { Thing thing = stackParts[i].Thing; Pawn pawn = thing as Pawn; if (pawn != null) { if (includePawnsMass) { num += pawn.GetStatValue(StatDefOf.Mass, true) * (float)count; } else { num += MassUtility.GearAndInventoryMass(pawn) * (float)count; } if (InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignoreInventory)) { num -= MassUtility.InventoryMass(pawn) * (float)count; } } else { num += thing.GetStatValue(StatDefOf.Mass, true) * (float)count; if (ignoreCorpsesGearAndInventory) { Corpse corpse = thing as Corpse; if (corpse != null) { num -= MassUtility.GearAndInventoryMass(corpse.InnerPawn) * (float)count; } } } } } return(Mathf.Max(num, 0f)); }
public TransferableOneWayWidget(IEnumerable <TransferableOneWay> transferables, string sourceLabel, string destinationLabel, string sourceCountDesc, bool drawMass = false, IgnorePawnsInventoryMode ignorePawnInventoryMass = IgnorePawnsInventoryMode.DontIgnore, bool includePawnsMassInMassUsage = false, Func <float> availableMassGetter = null, float extraHeaderSpace = 0f, bool ignoreCorpseGearAndInventoryMass = false, bool drawMarketValue = false, int drawDaysUntilRotForTile = -1) { if (transferables != null) { this.AddSection(null, transferables); } this.sourceLabel = sourceLabel; this.destinationLabel = destinationLabel; this.sourceCountDesc = sourceCountDesc; this.drawMass = drawMass; this.ignorePawnInventoryMass = ignorePawnInventoryMass; this.includePawnsMassInMassUsage = includePawnsMassInMassUsage; this.availableMassGetter = availableMassGetter; this.extraHeaderSpace = extraHeaderSpace; this.ignoreCorpseGearAndInventoryMass = ignoreCorpseGearAndInventoryMass; this.drawMarketValue = drawMarketValue; this.drawDaysUntilRotForTile = drawDaysUntilRotForTile; this.sorter1 = TransferableSorterDefOf.Category; this.sorter2 = TransferableSorterDefOf.MarketValue; }
public static void CreateCaravanTransferableWidgets(List <TransferableOneWay> transferables, out TransferableOneWayWidget pawnsTransfer, out TransferableOneWayWidget itemsTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly = false) { IEnumerable <TransferableOneWay> transferables2 = null; string sourceLabel = null; string destinationLabel = null; bool drawMass = true; bool includePawnsMassInMassUsage = false; bool ignoreSpawnedCorpseGearAndInventoryMass = ignoreSpawnedCorpsesGearAndInventoryMass; bool playerPawnsReadOnly2 = playerPawnsReadOnly; pawnsTransfer = new TransferableOneWayWidget(transferables2, sourceLabel, destinationLabel, thingCountTip, drawMass, ignorePawnInventoryMass, includePawnsMassInMassUsage, availableMassGetter, 0f, ignoreSpawnedCorpseGearAndInventoryMass, tile, drawMarketValue: true, drawEquippedWeapon: true, drawNutritionEatenPerDay: true, drawItemNutrition: false, drawForagedFoodPerDay: true, drawDaysUntilRot: false, playerPawnsReadOnly2); AddPawnsSections(pawnsTransfer, transferables); transferables2 = from x in transferables where x.ThingDef.category != ThingCategory.Pawn select x; string sourceLabel2 = null; destinationLabel = null; playerPawnsReadOnly2 = true; ignoreSpawnedCorpseGearAndInventoryMass = false; includePawnsMassInMassUsage = ignoreSpawnedCorpsesGearAndInventoryMass; itemsTransfer = new TransferableOneWayWidget(transferables2, sourceLabel2, destinationLabel, thingCountTip, playerPawnsReadOnly2, ignorePawnInventoryMass, ignoreSpawnedCorpseGearAndInventoryMass, availableMassGetter, 0f, includePawnsMassInMassUsage, tile, drawMarketValue: true, drawEquippedWeapon: false, drawNutritionEatenPerDay: false, drawItemNutrition: true, drawForagedFoodPerDay: false, drawDaysUntilRot: true); }
public static float ApproxDaysWorthOfFoodLeftAfterTradeableTransfer(List <Thing> allCurrentThings, List <Tradeable> tradeables, bool assumeCanEatLocalPlants, IgnorePawnsInventoryMode ignoreInventory) { TransferableUtility.SimulateTradeableTransfer(allCurrentThings, tradeables, DaysWorthOfFoodCalculator.tmpThingStackParts); DaysWorthOfFoodCalculator.tmpPawns.Clear(); DaysWorthOfFoodCalculator.tmpThingCounts.Clear(); for (int num = DaysWorthOfFoodCalculator.tmpThingStackParts.Count - 1; num >= 0; num--) { Pawn pawn = DaysWorthOfFoodCalculator.tmpThingStackParts[num].Thing as Pawn; if (pawn != null) { if (pawn.RaceProps.EatsFood && (!assumeCanEatLocalPlants || !VirtualPlantsUtility.CanEverEatVirtualPlants(pawn))) { DaysWorthOfFoodCalculator.tmpPawns.Add(pawn); } } else { DaysWorthOfFoodCalculator.tmpThingCounts.Add(new ThingCount(DaysWorthOfFoodCalculator.tmpThingStackParts[num].Thing.def, DaysWorthOfFoodCalculator.tmpThingStackParts[num].Count)); } } DaysWorthOfFoodCalculator.tmpThingStackParts.Clear(); float result = DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(DaysWorthOfFoodCalculator.tmpPawns, DaysWorthOfFoodCalculator.tmpThingCounts, assumeCanEatLocalPlants, ignoreInventory); DaysWorthOfFoodCalculator.tmpPawns.Clear(); DaysWorthOfFoodCalculator.tmpThingCounts.Clear(); return(result); }
private static float ApproxDaysWorthOfFood(List <Pawn> pawns, List <ThingCount> extraFood, bool assumeCanEatLocalPlants, IgnorePawnsInventoryMode ignoreInventory) { if (!DaysWorthOfFoodCalculator.AnyNonLocalPlantsEatingPawn(pawns, assumeCanEatLocalPlants)) { return(1000f); } DaysWorthOfFoodCalculator.tmpFood.Clear(); if (extraFood != null) { for (int i = 0; i < extraFood.Count; i++) { if (extraFood[i].ThingDef.IsNutritionGivingIngestible && extraFood[i].Count > 0) { DaysWorthOfFoodCalculator.tmpFood.Add(extraFood[i]); } } } for (int j = 0; j < pawns.Count; j++) { if (!InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawns[j], ignoreInventory)) { ThingOwner <Thing> innerContainer = pawns[j].inventory.innerContainer; for (int k = 0; k < innerContainer.Count; k++) { if (innerContainer[k].def.IsNutritionGivingIngestible) { DaysWorthOfFoodCalculator.tmpFood.Add(new ThingCount(innerContainer[k].def, innerContainer[k].stackCount)); } } } } if (!DaysWorthOfFoodCalculator.tmpFood.Any()) { return(0f); } DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodPerPawn.Clear(); DaysWorthOfFoodCalculator.tmpAnyFoodLeftIngestibleByPawn.Clear(); for (int l = 0; l < pawns.Count; l++) { DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodPerPawn.Add(0f); DaysWorthOfFoodCalculator.tmpAnyFoodLeftIngestibleByPawn.Add(true); } float num = 0f; while (true) { bool flag = false; for (int m = 0; m < pawns.Count; m++) { Pawn pawn = pawns[m]; if (DaysWorthOfFoodCalculator.tmpAnyFoodLeftIngestibleByPawn[m] && pawn.RaceProps.EatsFood && (!assumeCanEatLocalPlants || !VirtualPlantsUtility.CanEverEatVirtualPlants(pawn))) { while (true) { int num2 = DaysWorthOfFoodCalculator.BestEverEdibleFoodIndexFor(pawns[m], DaysWorthOfFoodCalculator.tmpFood); if (num2 < 0) { DaysWorthOfFoodCalculator.tmpAnyFoodLeftIngestibleByPawn[m] = false; break; } float num3 = Mathf.Min(DaysWorthOfFoodCalculator.tmpFood[num2].ThingDef.ingestible.nutrition, pawn.needs.food.NutritionBetweenHungryAndFed); float num4 = (float)(num3 / pawn.needs.food.NutritionBetweenHungryAndFed * (float)pawn.needs.food.TicksUntilHungryWhenFed / 60000.0); List <float> list; int index; (list = DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodPerPawn)[index = m] = list[index] + num4; DaysWorthOfFoodCalculator.tmpFood[num2] = DaysWorthOfFoodCalculator.tmpFood[num2].WithCount(DaysWorthOfFoodCalculator.tmpFood[num2].Count - 1); flag = true; if (!(DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodPerPawn[m] < num)) { break; } } num = Mathf.Max(num, DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodPerPawn[m]); } } if (!flag) { break; } } float num5 = 1000f; for (int n = 0; n < pawns.Count; n++) { if (pawns[n].RaceProps.EatsFood && (!assumeCanEatLocalPlants || !VirtualPlantsUtility.CanEverEatVirtualPlants(pawns[n]))) { num5 = Mathf.Min(num5, DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodPerPawn[n]); } } return(num5); }
public static float ApproxDaysWorthOfFood(List <Pawn> pawns, List <ThingStackPart> potentiallyFood, bool assumeCanEatLocalPlants, IgnorePawnsInventoryMode ignoreInventory) { DaysWorthOfFoodCalculator.tmpThingCounts.Clear(); for (int i = 0; i < potentiallyFood.Count; i++) { DaysWorthOfFoodCalculator.tmpThingCounts.Add(new ThingCount(potentiallyFood[i].Thing.def, potentiallyFood[i].Count)); } float result = DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(pawns, DaysWorthOfFoodCalculator.tmpThingCounts, assumeCanEatLocalPlants, ignoreInventory); DaysWorthOfFoodCalculator.tmpThingCounts.Clear(); return(result); }
public static float ApproxDaysWorthOfFood(List <Pawn> pawns, List <Thing> potentiallyFood, bool assumeCanEatLocalPlants, IgnorePawnsInventoryMode ignoreInventory) { DaysWorthOfFoodCalculator.tmpThingCounts.Clear(); DaysWorthOfFoodCalculator.tmpPawns.Clear(); for (int i = 0; i < pawns.Count; i++) { Pawn pawn = pawns[i]; if (pawn.RaceProps.EatsFood && (!assumeCanEatLocalPlants || !VirtualPlantsUtility.CanEverEatVirtualPlants(pawn))) { DaysWorthOfFoodCalculator.tmpPawns.Add(pawn); } } for (int j = 0; j < potentiallyFood.Count; j++) { DaysWorthOfFoodCalculator.tmpThingCounts.Add(new ThingCount(potentiallyFood[j].def, potentiallyFood[j].stackCount)); } float result = DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(DaysWorthOfFoodCalculator.tmpPawns, DaysWorthOfFoodCalculator.tmpThingCounts, assumeCanEatLocalPlants, ignoreInventory); DaysWorthOfFoodCalculator.tmpThingCounts.Clear(); DaysWorthOfFoodCalculator.tmpPawns.Clear(); return(result); }
public static float ApproxDaysWorthOfFoodLeftAfterTransfer(List <TransferableOneWay> transferables, bool assumeCanEatLocalPlants, IgnorePawnsInventoryMode ignoreInventory) { DaysWorthOfFoodCalculator.tmpThingCounts.Clear(); DaysWorthOfFoodCalculator.tmpPawns.Clear(); for (int i = 0; i < transferables.Count; i++) { TransferableOneWay transferableOneWay = transferables[i]; if (transferableOneWay.HasAnyThing) { if (transferableOneWay.AnyThing is Pawn) { for (int num = transferableOneWay.things.Count - 1; num >= transferableOneWay.CountToTransfer; num--) { Pawn pawn = (Pawn)transferableOneWay.things[num]; if (pawn.RaceProps.EatsFood && (!assumeCanEatLocalPlants || !VirtualPlantsUtility.CanEverEatVirtualPlants(pawn))) { DaysWorthOfFoodCalculator.tmpPawns.Add(pawn); } } } else { DaysWorthOfFoodCalculator.tmpThingCounts.Add(new ThingCount(transferableOneWay.ThingDef, transferableOneWay.MaxCount - transferableOneWay.CountToTransfer)); } } } float result = DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(DaysWorthOfFoodCalculator.tmpPawns, DaysWorthOfFoodCalculator.tmpThingCounts, assumeCanEatLocalPlants, ignoreInventory); DaysWorthOfFoodCalculator.tmpThingCounts.Clear(); DaysWorthOfFoodCalculator.tmpPawns.Clear(); return(result); }
public static float ApproxDaysUntilRotLeftAfterTradeableTransfer(List <Thing> allCurrentThings, List <Tradeable> tradeables, int tile, IgnorePawnsInventoryMode ignoreInventory) { DaysUntilRotCalculator.tmpThingCountsFromTradeables.Clear(); TransferableUtility.SimulateTradeableTransfer(allCurrentThings, tradeables, DaysUntilRotCalculator.tmpThingCountsFromTradeables); DaysUntilRotCalculator.tmpThingCounts.Clear(); for (int i = DaysUntilRotCalculator.tmpThingCountsFromTradeables.Count - 1; i >= 0; i--) { if (DaysUntilRotCalculator.tmpThingCountsFromTradeables[i].Count > 0) { Pawn pawn = DaysUntilRotCalculator.tmpThingCountsFromTradeables[i].Thing as Pawn; if (pawn != null) { if (!InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignoreInventory)) { ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer; for (int j = 0; j < innerContainer.Count; j++) { DaysUntilRotCalculator.tmpThingCounts.Add(new ThingCount(innerContainer[j], innerContainer[j].stackCount)); } } } else { DaysUntilRotCalculator.tmpThingCounts.Add(DaysUntilRotCalculator.tmpThingCountsFromTradeables[i]); } } } DaysUntilRotCalculator.tmpThingCountsFromTradeables.Clear(); float result = DaysUntilRotCalculator.ApproxDaysUntilRot(DaysUntilRotCalculator.tmpThingCounts, tile, null, 0f, 3300); DaysUntilRotCalculator.tmpThingCounts.Clear(); return(result); }
public static float ApproxDaysUntilRotLeftAfterTransfer(List <TransferableOneWay> transferables, int tile, IgnorePawnsInventoryMode ignoreInventory, WorldPath path = null, float nextTileCostLeft = 0f, int caravanTicksPerMove = 3300) { DaysUntilRotCalculator.tmpThingCounts.Clear(); for (int i = 0; i < transferables.Count; i++) { TransferableOneWay transferableOneWay = transferables[i]; if (transferableOneWay.HasAnyThing) { if (transferableOneWay.AnyThing is Pawn) { for (int j = transferableOneWay.things.Count - 1; j >= transferableOneWay.CountToTransfer; j--) { Pawn pawn = (Pawn)transferableOneWay.things[j]; if (!InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignoreInventory)) { ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer; for (int k = 0; k < innerContainer.Count; k++) { DaysUntilRotCalculator.tmpThingCounts.Add(new ThingCount(innerContainer[k], innerContainer[k].stackCount)); } } } } else if (transferableOneWay.MaxCount - transferableOneWay.CountToTransfer > 0) { DaysUntilRotCalculator.thingsInReverse.Clear(); DaysUntilRotCalculator.thingsInReverse.AddRange(transferableOneWay.things); DaysUntilRotCalculator.thingsInReverse.Reverse(); TransferableUtility.TransferNoSplit(DaysUntilRotCalculator.thingsInReverse, transferableOneWay.MaxCount - transferableOneWay.CountToTransfer, delegate(Thing thing, int count) { DaysUntilRotCalculator.tmpThingCounts.Add(new ThingCount(thing, count)); }, false, false); } } } DaysUntilRotCalculator.thingsInReverse.Clear(); float result = DaysUntilRotCalculator.ApproxDaysUntilRot(DaysUntilRotCalculator.tmpThingCounts, tile, path, nextTileCostLeft, caravanTicksPerMove); DaysUntilRotCalculator.tmpThingCounts.Clear(); return(result); }
public static float MassUsageLeftAfterTransfer(List <TransferableOneWay> transferables, IgnorePawnsInventoryMode ignoreInventory, bool includePawnsMass = false, bool ignoreSpawnedCorpsesGearAndInventory = false) { tmpThingCounts.Clear(); for (int i = 0; i < transferables.Count; i++) { 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); } float result = MassUsage(tmpThingCounts, ignoreInventory, includePawnsMass, ignoreSpawnedCorpsesGearAndInventory); tmpThingCounts.Clear(); return(result); }
public static float MassUsageLeftAfterTradeableTransfer(List <Thing> allCurrentThings, List <Tradeable> tradeables, IgnorePawnsInventoryMode ignoreInventory, bool includePawnsMass = false, bool ignoreSpawnedCorpsesGearAndInventory = false) { tmpThingCounts.Clear(); TransferableUtility.SimulateTradeableTransfer(allCurrentThings, tradeables, tmpThingCounts); float result = MassUsage(tmpThingCounts, ignoreInventory, includePawnsMass, ignoreSpawnedCorpsesGearAndInventory); tmpThingCounts.Clear(); return(result); }