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); } }
/// <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); }
/// <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); }
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)); } }
//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); }
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); }
/// <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); }
//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); }
/// <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); }
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); }
/// <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); }
/// <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); }
/// <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); }
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); }
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 += ")"; }
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); } }
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 ActionResult DeleteConfirmed(int id) { Procent procent = db.Procent.Find(id); db.Procent.Remove(procent); db.SaveChanges(); return(RedirectToAction("Index")); }
public void add(Procent pro) { base.add(pro); if (base.get() > 1f) { set(1f); } }
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)); }
private float getColdArmsSupply() { if (Product.ColdArms.isInventedBy(getOwner().getPlaceDejure())) { return(Procent.makeProcent(getConsumption(Product.ColdArms), getNeeds(Product.ColdArms), false).get()); } else { return(0f); } }
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 }); }
private float getHorsesSupply() { if (getOwner().getPlaceDejure().isInvented(Invention.Domestication)) { return(Procent.makeProcent(getConsumption(Product.Cattle), getNeeds(Product.Cattle), false).get()); } else { return(0f); } }
/// <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); }
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); }
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); }
//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); }
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); }
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)); } }