Ejemplo n.º 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.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);
        }