public static float ApproxDaysWorthOfWater(List <TransferableOneWay> transferables, IgnorePawnsInventoryMode ignoreInventory) { tmpThingCounts.Clear(); tmpPawns.Clear(); for (int i = 0; i < transferables.Count; i++) { TransferableOneWay transferableOneWay = transferables[i]; if (transferableOneWay.HasAnyThing) { if (transferableOneWay.AnyThing is Pawn) { for (int j = 0; j < transferableOneWay.CountToTransfer; j++) { tmpPawns.Add((Pawn)transferableOneWay.things[j]); } } else { tmpThingCounts.Add(new ThingCount(transferableOneWay.ThingDef, transferableOneWay.CountToTransfer)); } } } float result = DaysWorthOfWaterCalculator.ApproxDaysWorthOfWater(tmpPawns, tmpThingCounts, ignoreInventory); tmpThingCounts.Clear(); tmpPawns.Clear(); return(result); }
public static void AppendWaterWorthToCaravanInspectString(Caravan c, StringBuilder stringBuilder) { if (AnyPawnOutOfWater(c, out var worstDehydrationText)) { // 水不足のポーンがいる stringBuilder.AppendLine(); stringBuilder.Append(MizuStrings.InspectCaravanOutOfWater.Translate()); if (worstDehydrationText.NullOrEmpty()) { return; } // 脱水症状のテキストがあるならそれも追加 stringBuilder.Append(" "); stringBuilder.Append(worstDehydrationText); stringBuilder.Append("."); } else { // 水不足のポーンがいないなら、総量をチェック var daysWorthOfWater = DaysWorthOfWaterCalculator.ApproxDaysWorthOfWater(c); if (!(daysWorthOfWater < InfiniteDaysWorthOfWaterThreshold)) { return; } // 水は大量というわけでないなら、水残量を表示 stringBuilder.AppendLine(); stringBuilder.Append( string.Format(MizuStrings.InspectCaravanDaysOfWater.Translate(), daysWorthOfWater.ToString("0.#"))); } }
public static float DaysWorthOfWater_FormCaravan(Dialog_FormCaravan dialog) { if (MizuCaravanUtility.daysWorthOfWaterDirty) { MizuCaravanUtility.daysWorthOfWaterDirty = false; MizuCaravanUtility.cachedDaysWorthOfWater = DaysWorthOfWaterCalculator.ApproxDaysWorthOfWater(dialog.transferables, IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload); } return(MizuCaravanUtility.cachedDaysWorthOfWater); }
public static float DaysWorthOfWater_Trade(List <Thing> playerCaravanAllPawnsAndItems, List <Tradeable> tradeables) { if (MizuCaravanUtility.daysWorthOfWaterDirty) { MizuCaravanUtility.daysWorthOfWaterDirty = false; MizuCaravanUtility.cachedDaysWorthOfWater = DaysWorthOfWaterCalculator.ApproxDaysWorthOfWaterLeftAfterTradeableTransfer(playerCaravanAllPawnsAndItems, tradeables, IgnorePawnsInventoryMode.Ignore); } return(MizuCaravanUtility.cachedDaysWorthOfWater); }
public static float DaysWorthOfWater_LoadTransporters(List <TransferableOneWay> transferables) { //if (MizuCaravanUtility.daysWorthOfWaterDirty) //{ MizuCaravanUtility.daysWorthOfWaterDirty = false; MizuCaravanUtility.cachedDaysWorthOfWater = DaysWorthOfWaterCalculator.ApproxDaysWorthOfWater(transferables, IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload); //} return(MizuCaravanUtility.cachedDaysWorthOfWater); }
private static float ApproxDaysWorthOfWater(List <Pawn> pawns, List <ThingCount> extraWater, IgnorePawnsInventoryMode ignoreInventory) { if (!DaysWorthOfWaterCalculator.AnyNonTerrainDrinkingPawn(pawns)) { return(1000f); } List <ThingCount> tmpWater = new List <ThingCount>(); tmpWater.Clear(); if (extraWater != null) { for (int i = 0; i < extraWater.Count; i++) { bool canGetWater = false; for (int j = 0; j < extraWater[i].ThingDef.comps.Count; j++) { var compprop = extraWater[i].ThingDef.comps[j] as CompProperties_WaterSource; if (compprop != null && compprop.sourceType == CompProperties_WaterSource.SourceType.Item && compprop.waterAmount > 0.0f) { canGetWater = true; break; } } if (canGetWater && extraWater[i].Count > 0) { tmpWater.Add(extraWater[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].CanGetWater()) { tmpWater.Add(new ThingCount(innerContainer[k].def, innerContainer[k].stackCount)); } } } } if (!tmpWater.Any <ThingCount>()) { return(0f); } List <float> tmpDaysWorthOfFoodPerPawn = new List <float>(); List <bool> tmpAnyFoodLeftIngestibleByPawn = new List <bool>(); tmpDaysWorthOfFoodPerPawn.Clear(); tmpAnyFoodLeftIngestibleByPawn.Clear(); for (int l = 0; l < pawns.Count; l++) { tmpDaysWorthOfFoodPerPawn.Add(0f); tmpAnyFoodLeftIngestibleByPawn.Add(true); } float num = 0f; bool flag; do { flag = false; for (int m = 0; m < pawns.Count; m++) { Pawn pawn = pawns[m]; if (tmpAnyFoodLeftIngestibleByPawn[m]) { do { int num2 = DaysWorthOfWaterCalculator.BestEverGetWaterIndexFor(pawns[m], tmpWater); if (num2 < 0) { tmpAnyFoodLeftIngestibleByPawn[m] = false; break; } CompProperties_WaterSource compprop = null; for (int x = 0; x < tmpWater[num2].ThingDef.comps.Count; x++) { compprop = tmpWater[num2].ThingDef.comps[x] as CompProperties_WaterSource; if (compprop != null && compprop.sourceType == CompProperties_WaterSource.SourceType.Item) { break; } } if (compprop == null) { tmpAnyFoodLeftIngestibleByPawn[m] = false; break; } Need_Water need_water = pawn.needs.water(); if (need_water == null) { tmpAnyFoodLeftIngestibleByPawn[m] = false; break; } float num3 = Mathf.Min(compprop.waterAmount, need_water.WaterAmountBetweenThirstyAndHealthy); float num4 = num3 / need_water.WaterAmountBetweenThirstyAndHealthy * (float)need_water.TicksUntilThirstyWhenHealthy / 60000f; tmpDaysWorthOfFoodPerPawn[m] = tmpDaysWorthOfFoodPerPawn[m] + num4; tmpWater[num2] = tmpWater[num2].WithCount(tmpWater[num2].Count - 1); flag = true; }while (tmpDaysWorthOfFoodPerPawn[m] < num); num = Mathf.Max(num, tmpDaysWorthOfFoodPerPawn[m]); } } }while (flag); float num6 = 1000f; for (int n = 0; n < pawns.Count; n++) { num6 = Mathf.Min(num6, tmpDaysWorthOfFoodPerPawn[n]); } return(num6); }
public static float ApproxDaysWorthOfWater(Caravan caravan) { return(DaysWorthOfWaterCalculator.ApproxDaysWorthOfWater(caravan.PawnsListForReading, null, IgnorePawnsInventoryMode.DontIgnore)); }