Esempio n. 1
0
        internal Army balance(Procent howMuchShouldBeInSecondArmy)
        {
            //if (howMuchShouldBeInSecondArmy.get() == 1f)
            //{
            //    return this;
            //    //this.personal.Clear();
            //}
            //else
            {
                Army secondArmy = new Army(this.getOwner());

                //Army sumArmy = new Army();
                //sumArmy.add(this);
                //this.joinin(secondArmy);
                int secondArmyExpectedSize = howMuchShouldBeInSecondArmy.getProcentOf(this.getSize());

                //secondArmy.clear();

                int needToFullFill = secondArmyExpectedSize;
                while (needToFullFill > 0)
                {
                    var corpsToBalance = this.getBiggestCorpsSmallerThan(needToFullFill);
                    if (corpsToBalance == null)
                    {
                        break;
                    }
                    else
                    {
                        this.move(corpsToBalance, secondArmy);
                    }
                    needToFullFill = secondArmyExpectedSize - secondArmy.getSize();
                }
                return(secondArmy);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Buying PrimitiveStorageSet, subsidizations allowed
        /// </summary>
        //internal void SellList(Consumer buyer, StorageSet buying, Country subsidizer)
        //{
        //    foreach (Storage item in buying)
        //        if (item.isNotZero())
        //            buy(buyer, item, subsidizer);
        //}

        /// <summary>
        /// Buying needs in circle, by Procent in time
        /// return true if buying is zero (bought all what it wanted)
        /// </summary>
        internal bool Sell(Producer buyer, StorageSet stillHaveToBuy, Procent buyInTime, List <Storage> ofWhat)
        {
            bool buyingIsFinished = true;

            foreach (Storage what in ofWhat)
            {
                Storage consumeOnThisIteration = new Storage(what.Product, what.get() * buyInTime.get());
                if (consumeOnThisIteration.isZero())
                {
                    return(true);
                }

                // check if consumeOnThisIteration is not bigger than stillHaveToBuy
                if (!stillHaveToBuy.has(consumeOnThisIteration))
                {
                    consumeOnThisIteration = stillHaveToBuy.getBiggestStorage(what.Product);
                }
                var reallyBought = Sell(buyer, consumeOnThisIteration, null);

                stillHaveToBuy.Subtract(reallyBought);

                if (stillHaveToBuy.getBiggestStorage(what.Product).isNotZero())
                {
                    buyingIsFinished = false;
                }
            }
            return(buyingIsFinished);
        }
Esempio n. 3
0
    /// <summary>
    /// Not finished, dont use it
    /// </summary>
    /// <param name="reform"></param>
    internal Procent getYesVotes2(AbstractReformValue reform, ref Procent procentPopulationSayedYes)
    {
        uint    totalPopulation       = this.getMenPopulation();
        uint    votingPopulation      = 0;
        uint    populationSayedYes    = 0;
        uint    votersSayedYes        = 0;
        Procent procentVotersSayedYes = new Procent(0f);
        Dictionary <PopType, uint> divisionPopulationResult = new Dictionary <PopType, uint>();
        Dictionary <PopType, uint> divisionVotersResult     = Game.player.getYesVotesByType(reform, ref divisionPopulationResult);

        foreach (KeyValuePair <PopType, uint> next in divisionVotersResult)
        {
            votersSayedYes += next.Value;
        }

        if (totalPopulation != 0)
        {
            procentPopulationSayedYes.set((float)populationSayedYes / totalPopulation);
        }
        else
        {
            procentPopulationSayedYes.set(0);
        }

        if (votingPopulation == 0)
        {
            procentVotersSayedYes.set(0);
        }
        else
        {
            procentVotersSayedYes.set((float)votersSayedYes / votingPopulation);
        }
        return(procentVotersSayedYes);
    }
Esempio n. 4
0
        public Procent getRelativeStrength(Staff toWhom)
        {
            //var governmentHomeArmy = country.getDefenceForces();
            // Movement isToWhomMovement = toWhom as Movement;
            var thisStrenght = getStrengthExluding(toWhom); // null or not null

            // Movement isThisMovement = this as Movement;
            var toWhomStrenght = toWhom.getStrengthExluding(this);// null or not null

            if (toWhomStrenght == 0f)
            {
                if (thisStrenght == 0f)
                {
                    return(Procent.ZeroProcent);
                }
                else
                {
                    return(Procent.Max999);
                }
            }
            else
            {
                return(Procent.makeProcent(thisStrenght, toWhomStrenght));
            }
        }
Esempio n. 5
0
            //public override bool isAvailable(Country country)
            //{
            //    MinPOlValue requested = this;
            //    if ((requested.ID == 4) && country.Science.IsInvented(Invention.Collectivism) && (country.serfdom == Serfdom.Brutal || country.serfdom == Serfdom.Allowed || country.serfdom == Serfdom.AbolishedAndNationalized))
            //        return true;
            //    else
            //    if ((requested.ID == 3) && country.Science.IsInvented(Invention.Banking) && (country.serfdom == Serfdom.Brutal || country.serfdom == Serfdom.Allowed || country.serfdom == Serfdom.AbolishedWithLandPayment))
            //        return true;
            //    else
            //    if ((requested.ID == 2) && (country.serfdom == Serfdom.Brutal || country.serfdom == Serfdom.Allowed || country.serfdom == Serfdom.Abolished))
            //        return true;
            //    else
            //        if ((requested.ID == 1) && (country.serfdom == Serfdom.Brutal || country.serfdom == Serfdom.Allowed))
            //        return true;
            //    else
            //    if ((requested.ID == 0))
            //        return true;
            //    else
            //        return false;
            //}

            public override Procent howIsItGoodForPop(PopUnit pop)
            {
                Procent result;

                if (pop.isStateCulture())
                {
                    result = new Procent(0f);//0.5f);
                }
                else
                {
                    //positive - more rights for minorities
                    int change = GetRelativeConservatism(pop.Country.minorityPolicy.typedValue);
                    //result = new Procent((change + PossibleStatuses.Count - 1) * 0.1f);
                    if (change > 0)
                    {
                        result = new Procent(0.3f);// 1f);
                    }
                    else
                    {
                        //result = new Procent((change + PossibleStatuses.Count - 1) * 0.1f /2f);
                        result = new Procent(0f);
                    }
                }
                return(result);
            }
Esempio n. 6
0
            public override Procent howIsItGoodForPop(PopUnit pop)
            {
                Procent result;

                if (pop.getVotingPower(this) > pop.getVotingPower(pop.Country.government.typedValue))
                {
                    //if (this == Tribal)
                    //    result = new Procent(0.8f);
                    //else
                    result = new Procent(1f);
                }
                else if (this == ProletarianDictatorship)
                {
                    result = new Procent(0.5f);
                }
                else if (this == Despotism && pop.needsFulfilled.get() < 0.1f)
                {
                    result = new Procent(1f);
                }
                else if (this == Tribal)
                {
                    result = new Procent(0.3f);
                }
                else
                {
                    result = new Procent(0f);
                }
                return(result);
            }
Esempio n. 7
0
        /// <summary>
        /// howMuchShouldBeInSecondArmy - procent of this army. Returns second army
        /// </summary>
        public Army balance(Procent howMuchShouldBeInSecondArmy)
        {
            owner.armyCount++;
            Army secondArmy = new Army(owner, Province, owner + "'s " + owner.armyCount.ToString() + "th");

            int secondArmyExpectedSize = howMuchShouldBeInSecondArmy.getProcentOf(getSize());

            //secondArmy.clear();

            int needToFullFill = secondArmyExpectedSize;

            while (needToFullFill > 0)
            {
                var corpsToBalance = getBiggestCorpsSmallerThan(needToFullFill);
                if (corpsToBalance == null)
                {
                    break;
                }
                else
                {
                    moveCorps(corpsToBalance, secondArmy);
                }
                needToFullFill = secondArmyExpectedSize - secondArmy.getSize();
            }

            return(secondArmy);
        }
Esempio n. 8
0
            //public override bool isAvailable(Country country)
            //{
            //    SerfValue requested = this;

            //    if ((requested.ID == 4) && country.Science.IsInvented(Invention.Collectivism) && (country.serfdom.status.ID == 0 || country.serfdom.status.ID == 1 || country.serfdom.status.ID == 4))
            //        return true;
            //    else
            //    if ((requested.ID == 3) && country.Science.IsInvented(Invention.Banking) && (country.serfdom.status.ID == 0 || country.serfdom.status.ID == 1 || country.serfdom.status.ID == 3))
            //        return true;
            //    else
            //    if ((requested.ID == 2) && (country.serfdom.status.ID == 0 || country.serfdom.status.ID == 1 || country.serfdom.status.ID == 2))
            //        return true;
            //    else
            //        if ((requested.ID == 1) && (country.serfdom.status.ID == 0 || country.serfdom.status.ID == 1))
            //        return true;
            //    else
            //    if ((requested.ID == 0))
            //        return true;
            //    else
            //        return false;
            //}



            //public Procent getTax()
            //{
            //    if (this == Brutal)
            //        return brutalTax;
            //    else
            //        if (this == SerfdomAllowed)
            //        return allowedTax;
            //    else
            //        return nullTax;
            //}
            public override Procent howIsItGoodForPop(PopUnit pop)
            {
                Procent result;
                int     change = GetRelativeConservatism(pop.Country.serfdom.typedValue); //positive - more liberal

                if (pop.Type == PopType.Aristocrats)
                {
                    if (change > 0)
                    {
                        result = new Procent(0f);
                    }
                    else
                    {
                        result = new Procent(1f);
                    }
                }
                else
                {
                    if (change > 0)
                    {
                        result = new Procent(1f);
                    }
                    else
                    {
                        result = new Procent(0f);
                    }
                }
                return(result);
            }
Esempio n. 9
0
    /// <summary>
    /// return true if buying is zero
    /// </summary>
    internal bool Buy(Producer buyer, PrimitiveStorageSet buying, Procent buyInTime, PrimitiveStorageSet ofWhat)
    {
        bool buyingIsEmpty = true;

        foreach (Storage what in ofWhat)
        {
            Storage consumeOnThisEteration = new Storage(what.getProduct(), what.get() * buyInTime.get());
            if (consumeOnThisEteration.get() == 0)
            {
                return(true);
            }
            // check if buying still have enoth to subtract consumeOnThisEteration
            if (!buying.has(consumeOnThisEteration))
            {
                consumeOnThisEteration = buying.findStorage(what.getProduct());
            }
            consumeOnThisEteration.multipleInside(Consume(buyer, consumeOnThisEteration, null));

            buying.subtract(consumeOnThisEteration);

            if (buying.findStorage(what.getProduct()).get() > 0)
            {
                buyingIsEmpty = false;
            }
        }
        return(buyingIsEmpty);
    }
Esempio n. 10
0
            public override Procent howIsItGoodForPop(PopUnit pop)
            {
                Procent result;

                if (pop.Type == PopType.Workers)
                {
                    //positive - reform will be better for worker, [-5..+5]
                    int change = GetRelativeConservatism(pop.Country.FamilyPlanning.typedValue); // ID - pop.Country.minimalWage.value.ID;
                                                                                                 //result = new Procent((change + PossibleStatuses.Count - 1) * 0.1f);
                    if (change > 0)
                    {
                        if (this == OneKid)
                        {
                            result = new Procent(0f);
                        }
                        else
                        {
                            result = new Procent(0.6f);
                        }
                    }
                    else
                    {
                        //result = new Procent((change + PossibleStatuses.Count - 1) * 0.1f /2f);
                        result = new Procent(0f);
                    }
                }
                else // rich strata
                {
                    result = new Procent(0f);
                }

                return(result);
            }
Esempio n. 11
0
        /// <summary>
        /// Not finished, don't use it
        /// </summary>
        /// <param name="reform"></param>
        public Procent getYesVotes2(IReformValue reform, ref Procent procentPopulationSayedYes)
        {
            int     totalPopulation       = AllPops.Sum(x => x.population.Get());
            int     votingPopulation      = 0;
            int     populationSayedYes    = 0;
            int     votersSayedYes        = 0;
            Procent procentVotersSayedYes = new Procent(0f);
            Dictionary <PopType, int> divisionPopulationResult = new Dictionary <PopType, int>();
            Dictionary <PopType, int> divisionVotersResult     = getYesVotesByType(reform, ref divisionPopulationResult);

            foreach (KeyValuePair <PopType, int> next in divisionVotersResult)
            {
                votersSayedYes += next.Value;
            }

            if (totalPopulation != 0)
            {
                procentPopulationSayedYes.Set((float)populationSayedYes / totalPopulation);
            }
            else
            {
                procentPopulationSayedYes.Set(0);
            }

            if (votingPopulation == 0)
            {
                procentVotersSayedYes.Set(0);
            }
            else
            {
                procentVotersSayedYes.Set((float)votersSayedYes / votingPopulation);
            }
            return(procentVotersSayedYes);
        }
Esempio n. 12
0
        /// <summary>  Return in pieces basing on current prices and needs  /// </summary>
        //override public float getLocalEffectiveDemand(Product product)
        //{
        //    return getLocalEffectiveDemand(product, getWorkForceFulFilling());
        //}

        /// <summary>
        /// per level
        /// </summary>
        internal Procent getEfficiency(bool useBonuses)
        {
            //limit production by smallest factor
            Procent efficencyFactor;
            Procent workforceProcent = GetWorkForceFulFilling();
            Procent inputFactor      = getInputFactor();

            if (inputFactor.isZero() & isJustHiredPeople())
            {
                inputFactor = Procent.HundredProcent.Copy();
            }

            if (inputFactor.isSmallerThan(workforceProcent))
            {
                efficencyFactor = inputFactor;
            }
            else
            {
                efficencyFactor = workforceProcent;
            }
            //float basicEff = efficencyFactor * getLevel();
            //Procent result = new Procent(basicEff);
            //Procent result = new Procent(efficencyFactor);
            if (useBonuses)
            {
                efficencyFactor.set(efficencyFactor.get() * modifierEfficiency.getModifier(this), false);
            }
            return(efficencyFactor);
        }
Esempio n. 13
0
    /// <summary>
    /// per level
    /// </summary>
    internal Procent getEfficiency(bool useBonuses)
    {
        //limit production by smalest factor
        float efficencyFactor  = 0;
        float workforceProcent = getWorkForceFullFilling();
        float inputFactor      = getInputFactor();

        if (inputFactor < workforceProcent)
        {
            efficencyFactor = inputFactor;
        }
        else
        {
            efficencyFactor = workforceProcent;
        }
        //float basicEff = efficencyFactor * getLevel();
        //Procent result = new Procent(basicEff);
        Procent result = new Procent(efficencyFactor);

        if (useBonuses)
        {
            result.set(result.get() * (1f + modifierEfficiency.getModifier(province.owner) / 100f));
        }
        return(result);
    }
Esempio n. 14
0
            public override Procent howIsItGoodForPop(PopUnit pop)
            {
                Procent result;
                //positive - higher subsidies
                int change = GetRelativeConservatism(pop.Country.UBI.typedValue);

                if (pop.Type.isPoorStrata(pop))
                {
                    if (change > 0)
                    {
                        result = new Procent(1f);
                    }
                    else
                    {
                        result = new Procent(0f);
                    }
                }
                else
                {
                    if (change > 0)
                    {
                        result = new Procent(0f);
                    }
                    else
                    {
                        result = new Procent(1f);
                    }
                }
                return(result);
            }
Esempio n. 15
0
        private void RefreshInfoAboutVotes(Procent procentVotersSayedYes, Procent procentPopulationSayedYes, Dictionary <PopType, int> divisionVotersResult, Dictionary <PopType, int> divisionPopulationResult)
        {
            if (Game.Player.government == Government.Despotism)
            {
                descriptionText.text += "\nNobody to vote - Despot rules everything";
            }
            else
            {
                descriptionText.text += "\n" + procentVotersSayedYes + " of voters want this reform ( ";
                foreach (PopType type in PopType.getAllPopTypes())
                {
                    if (divisionVotersResult[type] > 0)
                    {
                        Procent res = new Procent(divisionVotersResult[type] / (float)Game.Player.Provinces.getPopulationAmountByType(type));
                        descriptionText.text += res + " of " + type + "; ";
                    }
                }
                descriptionText.text += ")";
            }

            descriptionText.text += "\n" + procentPopulationSayedYes + " of population want this reform ( ";
            foreach (PopType type in PopType.getAllPopTypes())
            {
                if (divisionPopulationResult[type] > 0)
                {
                    Procent res = new Procent(divisionPopulationResult[type] / (float)Game.Player.Provinces.getPopulationAmountByType(type));
                    descriptionText.text += res + " of " + type + "; ";
                }
            }
            descriptionText.text += ")";
        }
Esempio n. 16
0
        internal bool IsCountryOwnsControlPacket()
        {
            Value ownedByAnyCountry = new Value(0f);
            Value total             = new Value(0f);

            foreach (var item in GetAll())
            {
                var value = item.Value.GetShare();
                if (item.Key is Country)
                {
                    ownedByAnyCountry.Add(value);
                }
                total.Add(value);
            }

            var res = new Procent(ownedByAnyCountry, total, false); // to avoid console spam with ghost factories

            if (res.isBiggerOrEqual(Procent._50Procent))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 17
0
        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");
            }
        }
Esempio n. 18
0
        public ActionResult DeleteConfirmed(int id)
        {
            Procent procent = db.Procent.Find(id);

            db.Procent.Remove(procent);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 19
0
 public void add(Procent pro)
 {
     base.add(pro);
     if (base.get() > 1f)
     {
         set(1f);
     }
 }
Esempio n. 20
0
 public ActionResult Edit([Bind(Include = "ID,Proc_na_salary,Proc_na_cost")] Procent procent)
 {
     if (ModelState.IsValid)
     {
         db.Entry(procent).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(procent));
 }
Esempio n. 21
0
 private float getColdArmsSupply()
 {
     if (Product.ColdArms.isInventedBy(getOwner().getPlaceDejure()))
     {
         return(Procent.makeProcent(getConsumption(Product.ColdArms), getNeeds(Product.ColdArms), false).get());
     }
     else
     {
         return(0f);
     }
 }
Esempio n. 22
0
        public ActionResult Create([Bind(Include = "ID,Proc_na_salary,Proc_na_cost")] Procent procent)
        {
            if (ModelState.IsValid)
            {
                db.Procent.Add(procent);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(procent));
        }
 protected AbstractReformValue(int id, DoubleConditionsList condition)
 {
     LifeQualityImpact = Procent.ZeroProcent.Copy();
     ID          = id;
     allowed     = condition;
     wantsReform = new Modifier(x => howIsItGoodForPop(x as PopUnit).get(), "Benefit to population", 1f, true);
     loyalty     = new Modifier(x => loyaltyBoostFor(x as PopUnit), "Loyalty", 1f, false);
     modVoting   = new ModifiersList(new List <Condition> {
         wantsReform, loyalty, education
     });
 }
Esempio n. 24
0
 private float getHorsesSupply()
 {
     if (getOwner().getPlaceDejure().isInvented(Invention.Domestication))
     {
         return(Procent.makeProcent(getConsumption(Product.Cattle), getNeeds(Product.Cattle), false).get());
     }
     else
     {
         return(0f);
     }
 }
Esempio n. 25
0
        /// <summary>
        /// New value
        /// </summary>
        public static Procent GetAverageProcent(this IEnumerable <PopUnit> source, Func <PopUnit, Procent> selector)
        {
            Procent result = new Procent(0f);
            int     calculatedPopulation = 0;

            foreach (var item in source)
            {
                result.AddPoportionally(calculatedPopulation, item.getPopulation(), selector(item));
                calculatedPopulation += item.getPopulation();
            }
            return(result);
        }
Esempio n. 26
0
        public Procent getAverageLoyalty()
        {
            Procent result = new Procent(0f);
            int     calculatedPopulation = 0;

            foreach (PopUnit pop in allPopUnits)
            {
                result.addPoportionally(calculatedPopulation, pop.getPopulation(), pop.loyalty);
                calculatedPopulation += pop.getPopulation();
            }
            return(result);
        }
Esempio n. 27
0
        public Procent getAverageMorale()
        {
            Procent result         = new Procent(0);
            int     calculatedSize = 0;

            foreach (var item in allArmies)
            {
                result.addPoportionally(calculatedSize, item.getSize(), item.getAverageMorale());
                calculatedSize += item.getSize();
            }
            return(result);
        }
Esempio n. 28
0
        //public bool canWinUprising()
        //{
        //    var defence = country.getDefenceForces();
        //    if (defence == null)
        //        return true;
        //    else
        //        return getMembership() > defence.getSize();
        //}


        private Procent getAverageLoyalty()
        {
            Procent result         = new Procent(0);
            int     calculatedSize = 0;

            foreach (var item in members)
            {
                result.AddPoportionally(calculatedSize, item.getPopulation(), item.loyalty);
                calculatedSize += item.getPopulation();
            }
            return(result);
        }
Esempio n. 29
0
        public Procent GetAverageCorps(Func <Corps, Procent> selector)
        {
            Procent result         = new Procent(0);
            int     calculatedSize = 0;

            foreach (var item in personal)
            {
                result.AddPoportionally(calculatedSize, item.Value.getSize(), selector(item.Value));
                calculatedSize += item.Value.getSize();
            }
            return(result);
        }
Esempio n. 30
0
        public Procent getWorldProductionShare(Product product)
        {
            var worldProduction = Game.market.getProductionTotal(product, true);

            if (worldProduction.isZero())
            {
                return(Procent.ZeroProcent);
            }
            else
            {
                return(Procent.makeProcent(getProducedTotal(product), worldProduction));
            }
        }