Example #1
0
        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.popType == PopType.Soldiers && morale.isBiggerThan(origin.loyalty))
            {
                morale.set(origin.loyalty);
            }

            if (morale.isBiggerThan(Procent.HundredProcent))
            {
                morale.set(1f);
            }
            //if (getPopUnit().loyalty.isSmallerThan(Options.PopMinLoyaltyToMobilizeForGovernment))
            //    getCountry().demobilize(x => x.getPopUnit() == this);
        }
Example #2
0
 public static string getString(this IList <KeyValuePair <Culture, 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);
            }
        }