public static string ToString <TValue>(this IEnumerable <KeyValuePair <TValue, Procent> > list, string lineBreaker, int howMuchStringsToShow) { var sb = new StringBuilder(); //if (list.Count() <= howMuchStringsToShow || howMuchStringsToShow == 0) //{ // bool isFirstRow = true; // foreach (var item in list) // { // if (!isFirstRow) // sb.Append(lineBreaker); // isFirstRow = false; // sb.Append(item.Key).Append(": ").Append(item.Value); // } //} //else // there is at least howMuchStringsToShow + 1 elements bool isFirstRow = true; bool isAddedAnyStrings = false; //for (int i = 0; i < howMuchStringsToShow; i++) int i = 0; var othersSum = new Procent(0f); foreach (var item in list) { if (i < howMuchStringsToShow || howMuchStringsToShow == 0) { if (!isFirstRow) { sb.Append(lineBreaker); } isFirstRow = false; sb.Append(item.Key).Append(": ").Append(item.Value); isAddedAnyStrings = true; } else { othersSum.Add(item.Value); } // break; i++; } //for (int i = howMuchStringsToShow; i < list.Count; i++) // othersSum.Add(list[i].Value); if (othersSum.isNotZero()) { sb.Append(lineBreaker); sb.Append("Others: ").Append(othersSum); } if (isAddedAnyStrings) { return(sb.ToString()); } else { return("none"); } }
public void consume(Country owner) { var needs = getRealNeeds(owner); float shortage = 0f; Storage realConsumption = Storage.EmptyProduct; foreach (var need in needs) { if (owner.countryStorageSet.has(need)) { if (need.isAbstractProduct()) { // convertToBiggestStorageProduct here are duplicated in this.getConsumptionProcent() (getBiggestStorage()) realConsumption = owner.countryStorageSet.convertToBiggestStorage(need); } else { realConsumption = need; } if (realConsumption.isNotZero()) { owner.consumeFromCountryStorage(realConsumption, owner); //owner.countryStorageSet.subtract(realConsumption); consumption.Add(realConsumption); } } else { shortage += need.get(); } } float moraleChange = getConsumptionProcent(Product.Food, owner).get() - morale.get(); moraleChange = Mathf.Clamp(moraleChange, Options.ArmyMaxMoralChangePerTic * -1f, Options.ArmyMaxMoralChangePerTic); if (morale.get() + moraleChange < 0) { morale.Set(0f); } else { morale.Add(moraleChange); } if (this.origin.Type == PopType.Soldiers && morale.isBiggerThan(origin.loyalty)) { morale.Set(origin.loyalty); } if (morale.isBiggerThan(Procent.HundredProcent)) { morale.Set(1f); } //if (getPopUnit().loyalty.isSmallerThan(Options.PopMinLoyaltyToMobilizeForGovernment)) // Country.demobilize(x => x.getPopUnit() == this); }
public static string getString <TValue>(this IList <KeyValuePair <TValue, Procent> > list, string lineBreaker, int howMuchStringsToShow) { if (list.Count() > 0) { var sb = new StringBuilder(); if (list.Count() <= howMuchStringsToShow) { bool isFirstRow = true; foreach (var item in list) { if (!isFirstRow) { sb.Append(lineBreaker); } isFirstRow = false; sb.Append(item.Key).Append(": ").Append(item.Value); } } else // there is at least howMuchStringsToShow + 1 elements { bool isFirstRow = true; for (int i = 0; i < howMuchStringsToShow; i++) { if (!isFirstRow) { sb.Append(lineBreaker); } isFirstRow = false; sb.Append(list[i].Key).Append(": ").Append(list[i].Value); } var othersSum = new Procent(0f); for (int i = howMuchStringsToShow; i < list.Count; i++) { othersSum.Add(list[i].Value); } sb.Append(lineBreaker); sb.Append("Others: ").Append(othersSum); } return(sb.ToString()); } else { return("none"); } }
internal void CalcMarketPrice() { var isOnsale = IsOnSale(); if (isOnsale || parent.IsClosed) { // reduce price marketPriceModifier.Subtract(0.001f, false); if (marketPriceModifier.isZero()) { marketPriceModifier.Set(0.001f); } } if (!isOnsale && parent.IsOpen) //rise price { marketPriceModifier.Add(0.01f); } }