/// <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); }
internal void subtract(PrimitiveStorageSet set) { foreach (Storage stor in set) { this.subtract(stor); } }
internal void Buy(Factory buyer, PrimitiveStorageSet buying, CountryWallet subsidizer) { // Storage actualConsumption; foreach (Storage input in buying) { Consume(buyer, input, subsidizer); } }
internal void copyDataFrom(PrimitiveStorageSet consumed) { foreach (Storage stor in consumed) { //if (stor.get() > 0f) this.Set(stor); } // SetZero(); }
/// <summary> /// returns new copy /// </summary> internal PrimitiveStorageSet Divide(float v) { PrimitiveStorageSet result = new PrimitiveStorageSet(); foreach (Storage stor in container) { result.Set(new Storage(stor.getProduct(), stor.get() / v)); } return(result); }
public PrimitiveStorageSet getCopy() { PrimitiveStorageSet res = new PrimitiveStorageSet(); foreach (Storage stor in this) { res.container.Add(new Storage(stor.getProduct(), stor.get())); } return(res); }
/// <summary>Returns False when some check not presented in here</summary> internal bool has(PrimitiveStorageSet check) { foreach (Storage stor in check) { if (!has(stor)) { return(false); } } return(true); }
internal bool CanAfford(PrimitiveStorageSet need) { foreach (Storage stor in need) { if (HowMuchCanAfford(stor).get() < stor.get()) { return(false); } } return(true); }
internal PrimitiveStorageSet getBuildNeeds() { //return new Storage(Product.Food, 40f); PrimitiveStorageSet result = new PrimitiveStorageSet(); result.Set(new Storage(Product.Food, 40f)); //TODO!has connection in pop.invest!! //if (whoCanProduce(Product.Gold) == this) // result.Set(new Storage(Product.Wood, 40f)); return(result); }
/// <summary> /// Including potentially unsold goods /// Basing on last turn production /// </summary> //float getTotalDemand(Product pro) //{ //} internal Value getCost(PrimitiveStorageSet need) { float cost = 0; // float price; foreach (Storage stor in need) { //price = Game.market.findPrice(stor.getProduct()).get(); cost += getCost(stor); } return(new Value(cost)); }
internal FactoryType(string iname, Storage ibasicProduction, PrimitiveStorageSet iresourceInput, bool shaft) { name = iname; if (iname == "Gold pit") { GoldMine = this; } if (iname == "Furniture factory") { Furniture = this; } if (iname == "Metal pit") { MetalDigging = this; } if (iname == "Metal smelter") { MetalSmelter = this; } allTypes.Add(this); basicProduction = ibasicProduction; if (iresourceInput == null) { resourceInput = new PrimitiveStorageSet(); } else { resourceInput = iresourceInput; } //upgradeResource.Set(new Storage(Product.Wood, 10f)); upgradeResource.Set(new Storage(Product.Stone, 10f)); //internal ConditionsList conditionsBuild; enoughMoneyOrResourcesToBuild = new Condition( (delegate(Country forWhom) { if (Economy.isMarket.checkIftrue(forWhom)) { return(forWhom.wallet.canPay(getBuildCost())); } else { return(forWhom.storageSet.has(getBuildNeeds())); } }), "Have enough money or resources to build", true ); conditionsBuild = new ConditionsList(new List <AbstractCondition>() { Economy.isNotLF, enoughMoneyOrResourcesToBuild }); // can build this.shaft = shaft; }
internal bool isProducingOnFactories(PrimitiveStorageSet resourceInput) { foreach (Storage stor in resourceInput) { foreach (Factory factory in allFactories) { if (factory.isWorking() && factory.type.basicProduction.getProduct() == stor.getProduct()) { return(true); } } } return(false); }
internal Factory(Province iprovince, Owner inowner, FactoryType intype) { //assuming this is level 0 building type = intype; needsToUpgrade = type.getBuildNeeds(); iprovince.allFactories.Add(this); factoryOwner = inowner; province = iprovince; gainGoodsThisTurn = new Storage(type.basicProduction.getProduct()); storageNow = new Storage(type.basicProduction.getProduct()); sentToMarket = new Storage(type.basicProduction.getProduct()); salary.set(province.getLocalMinSalary()); modifierHasResourceInProvince = new Modifier(delegate(Country forWhom) { return(!type.isResourceGathering() && province.isProducingOnFactories(type.resourceInput)); }, "Has input resource in thst province", true, 20f); modifierLevelBonus = new Modifier(delegate() { return(this.getLevel()); }, "High production concetration bonus", true, 5f); modifierInventedMiningAndIsShaft = new Modifier( delegate(Country forWhom) { return(forWhom.isInvented(InventionType.mining) && type.isShaft()); }, new StringBuilder("Invented ").Append(InventionType.mining.ToString()).ToString(), false, 50f); modifierBelongsToCountry = new Modifier( delegate(Country forWhom) { return(factoryOwner is Country); }, "Belongs to government", false, -20f); modifierNotBelongsToCountry = new Condition( (Country x) => !(factoryOwner is Country), "Doesn't belongs to government", false); modifierIsSubsidised = new Modifier((x) => isSubsidized(), "Is subsidized", false, -10f); modifierEfficiency = new ModifiersList(new List <Condition>() { new Modifier(InventionType.steamPower, true, 25f), modifierInventedMiningAndIsShaft, new Modifier(Economy.StateCapitalism, true, 10f), new Modifier(Economy.Interventionism, true, 30f), new Modifier(Economy.LaissezFaire, true, 50f), new Modifier(Economy.PlannedEconomy, true, -10f), modifierHasResourceInProvince, modifierLevelBonus, modifierBelongsToCountry, modifierIsSubsidised }); conditionsUpgrade = new ConditionsList(new List <Condition>() { new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true), new Condition(delegate(Owner forWhom) { return(!isUpgrading()); }, "Not upgrading", false), new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false), new Condition(delegate(Owner forWhom) { return(isWorking()); }, "Open", false), new Condition(delegate(Owner forWhom) { return(level != Game.maxFactoryLevel); }, "Max level not achieved", false), new Condition(delegate(Owner forWhom) { Value cost = this.getUpgradeCost(); return(forWhom.wallet.canPay(cost)); }, delegate() { Game.threadDangerSB.Clear(); Game.threadDangerSB.Append("Have ").Append(getUpgradeCost()).Append(" coins"); return(Game.threadDangerSB.ToString()); }, true) }); conditionsClose = new ConditionsList(new List <Condition>() { new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true), new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false), new Condition(delegate(Owner forWhom) { return(isWorking()); }, "Open", false), }); conditionsReopen = new ConditionsList(new List <Condition>() { new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true), new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false), new Condition(delegate(Owner forWhom) { return(!isWorking()); }, "Close", false), new Condition(delegate(Owner forWhom) { return(forWhom.wallet.canPay(getReopenCost())); }, delegate() { Game.threadDangerSB.Clear(); Game.threadDangerSB.Append("Have ").Append(getReopenCost()).Append(" coins"); return(Game.threadDangerSB.ToString()); }, true) }); conditionsDestroy = new ConditionsList(new List <Condition>() { Economy.isNotLF }); //status == Economy.LaissezFaire || status == Economy.Interventionism || status == Economy.NaturalEconomy conditionsSell = ConditionsList.IsNotImplemented; // !Planned and ! State //(status == Economy.StateCapitalism || status == Economy.Interventionism || status == Economy.NaturalEconomy) conditionsBuy = ConditionsList.IsNotImplemented; // ! LF and !Planned // (status == Economy.PlannedEconomy || status == Economy.NaturalEconomy || status == Economy.StateCapitalism) conditionsNatinalize = new ConditionsList(new List <Condition>() { Economy.isNotLF, Economy.isNotInterventionism, modifierNotBelongsToCountry }); //!LF and ! Inter conditionsSubsidize = new ConditionsList(new List <Condition>() { Economy.isNotLF, Economy.isNotNatural }); conditionsDontHireOnSubsidies = new ConditionsList(new List <Condition>() { Economy.isNotLF, Economy.isNotNatural, Condition.IsNotImplemented }); conditionsChangePriority = new ConditionsList(new List <Condition>() { Economy.isNotLF, Condition.IsNotImplemented }); }
internal void upgrade(Owner byWhom) { upgrading = true; needsToUpgrade = type.getUpgradeNeeds().getCopy(); byWhom.wallet.payWithoutRecord(wallet, getUpgradeCost()); }
public void pay(PrimitiveStorageSet whom, Value HowMuch) { whom.take(this, HowMuch); }
public void sendAll(PrimitiveStorageSet storage) { storage.take(this, this); }
public Game() { Application.runInBackground = true; //LoadImages(); generateMapImage(); new Product("Food", false, 0.4f); new Product("Wood", true, 2.7f); new Product("Lumber", false, 8f); new Product("Gold", true, 4f); new Product("Metall ore", true, 3f); new Product("Metall", false, 6f); new Product("Wool", true, 1); new Product("Clothes", false, 3); new Product("Furniture", false, 7); new Product("Stone", true, 1); new Product("Cement", false, 2); new Product("Fruit", true, 1); new Product("Wine", false, 3); market.initialize(); makeMap(); roundMesh(); var mapWidth = mapImage.width * cellMuliplier; var mapHeight = mapImage.height * cellMuliplier; //MainCamera.cameraMy.transform.position = GameObject.FindWithTag("mapObject").transform.position; MainCamera.cameraMy.transform.position = new Vector3(mapWidth / 2f, mapHeight / 2f, MainCamera.cameraMy.transform.position.z); FindProvinceCenters(); r3dTextPrefab = (GameObject)Resources.Load("prefabs/3dTextPrefab", typeof(GameObject)); foreach (Province pro in Province.allProvinces) { pro.SetLabel(); } Province.allProvinces[0].setResource(Product.Gold); //Province.allProvinces[0].setResource(Product.Wood; Province.allProvinces[1].setResource(Product.Wood); Province.allProvinces[2].setResource(Product.Fruit); Province.allProvinces[3].setResource(Product.Wool); Province.allProvinces[4].setResource(Product.Stone); Province.allProvinces[5].setResource(Product.MetallOre); new FactoryType("Forestry", new Storage(Product.Wood, 2f), null, false); new FactoryType("Gold pit", new Storage(Product.Gold, 2f), null, true); new FactoryType("Metal pit", new Storage(Product.MetallOre, 2f), null, true); new FactoryType("Sheepfold", new Storage(Product.Wool, 2f), null, false); new FactoryType("Quarry", new Storage(Product.Stone, 2f), null, true); new FactoryType("Orchard", new Storage(Product.Fruit, 2f), null, false); PrimitiveStorageSet resourceInput = new PrimitiveStorageSet(); resourceInput.Set(new Storage(Product.Lumber, 1f)); new FactoryType("Furniture factory", new Storage(Product.Furniture, 4f), resourceInput, false); resourceInput = new PrimitiveStorageSet(); resourceInput.Set(new Storage(Product.Wood, 1f)); new FactoryType("Sawmill", new Storage(Product.Lumber, 2f), resourceInput, false); resourceInput = new PrimitiveStorageSet(); resourceInput.Set(new Storage(Product.Wood, 0.5f)); resourceInput.Set(new Storage(Product.MetallOre, 2f)); new FactoryType("Metal smelter", new Storage(Product.Metal, 3f), resourceInput, false); resourceInput = new PrimitiveStorageSet(); resourceInput.Set(new Storage(Product.Wool, 1f)); new FactoryType("Weaver factory", new Storage(Product.Clothes, 2f), resourceInput, false); resourceInput = new PrimitiveStorageSet(); resourceInput.Set(new Storage(Product.Wood, 0.5f)); resourceInput.Set(new Storage(Product.Stone, 1f)); new FactoryType("Cement factory", new Storage(Product.Cement, 3f), resourceInput, false); resourceInput = new PrimitiveStorageSet(); resourceInput.Set(new Storage(Product.Fruit, 0.3333f)); new FactoryType("Winery", new Storage(Product.Wine, 2f), resourceInput, false); //new Product("Grain"); //new PopType(PopType.PopTypes.TribeMen, new Storage(Product.findByName("Food"), 1.5f), "Tribemen"); new PopType(PopType.PopTypes.Tribemen, new Storage(Product.findByName("Food"), 1.0f), "Tribemen"); new PopType(PopType.PopTypes.Aristocrats, null, "Aristocrats"); new PopType(PopType.PopTypes.Capitalists, null, "Capitalists"); new PopType(PopType.PopTypes.Farmers, new Storage(Product.findByName("Food"), 2.0f), "Farmers"); //new PopType(PopType.PopTypes.Artisans, null, "Artisans"); //new PopType(PopType.PopTypes.Soldiers, null, "Soldiers"); new PopType(PopType.PopTypes.Workers, null, "Workers"); Culture cul = new Culture("Kocopetji"); player = new Country("Kocopia", cul, new CountryWallet(0f)); player.storageSet.add(new Storage(Product.Food, 200f)); player.wallet.haveMoney.add(100f); CreateRandomPopulation(); Province.allProvinces[0].allPopUnits[0].education.set(1f); MainCamera.topPanel.refresh(); }
/// <summary>WARNING! Can overflow if money > cost of need. use CanAfford before </summary> internal Value HowMuchCanNotAfford(PrimitiveStorageSet need) { return(new Value(Game.market.getCost(need).get() - this.haveMoney.get())); }