/// <summary> /// Result > 1 mean demand is higher, price should go up Result fewer 1 mean supply is higher, price should go down /// based on last turn data ///</summary> internal float getDemandSupplyBalance(Product product, bool forceDSBRecalculation) { if (product == Product.Gold) { return(Options.MarketInfiniteDSB); } //Debug.Log("I'm in DSBBalancer, dateOfDSB = " + dateOfDSB); float balance; if (!dateOfDSB.IsToday || forceDSBRecalculation) // recalculate DSBbuffer { //Debug.Log("Recalculation of DSB started"); foreach (Storage nextProduct in marketPrice) { if (nextProduct.Product.isTradable()) { //getProductionTotal(product, false); // for pre-turn initialization //getTotalConsumption(product, false);// for pre-turn initialization float supply = getMarketSupply(nextProduct.Product, forceDSBRecalculation).get(); float demand = getBouthOnMarket(nextProduct.Product, forceDSBRecalculation).get(); //if (supply == 0 && demand == 0) // both zero // balance = Options.MarketInfiniteDSB; //else //{ if (supply == 0) { balance = Options.MarketInfiniteDSB; // supply zero } else { if (demand == 0) // demand zero { balance = Options.MarketZeroDSB; // otherwise - furniture bag } else { balance = demand / supply; } } //} DSBbuffer.Set(new Storage(nextProduct.Product, balance)); } } dateOfDSB.set(Date.Today); } if (product == null) { return(0f); } else { return(DSBbuffer.GetFirstSubstituteStorage(product).get()); } }
public void Initialize(Country country) { priceHistory = new PricePool(); foreach (var item in Product.getAll().Where(x => !x.isAbstract())) { if (item != Product.Gold) { prices.Set(new Storage(item, (float)item.defaultPrice.Get())); } } Country = country; }
/// <summary> /// Only goods sent to market /// Based on last turn data /// </summary> internal Storage getMarketSupply(Product product, bool takeThisTurnData) { if (takeThisTurnData) { return(recalculateProductForSellers(product, x => x.getSentToMarket(product))); } if (!dateOfgetSupplyOnMarket.IsToday) { //recalculate supply buffer foreach (Storage recalculatingProduct in marketPrice) { if (recalculatingProduct.Product.isTradable()) { var result = recalculateProductForSellers(recalculatingProduct.Product, x => x.getSentToMarket(recalculatingProduct.Product)); supplyOnMarket.Set(new Storage(recalculatingProduct.Product, result)); } } dateOfgetSupplyOnMarket.set(Date.Today); } return(supplyOnMarket.GetFirstSubstituteStorage(product)); }
internal Storage getTotalConsumption(Product product, bool takeThisTurnData) { if (takeThisTurnData) { return(recalculateProductForConsumers(product, x => x.getConsumed())); } if (!dateOfgetTotalConsumption.IsToday) { //recalculate buffer foreach (Storage recalculatingProduct in marketPrice) { if (recalculatingProduct.Product.isTradable()) { var result = recalculateProductForConsumers(recalculatingProduct.Product, x => x.getConsumed()); totalConsumption.Set(new Storage(recalculatingProduct.Product, result)); } } dateOfgetTotalConsumption.set(Date.Today); } return(totalConsumption.GetFirstSubstituteStorage(product)); }
/// <summary> /// All produced supplies /// Based on last turn data /// </summary> public Storage getProductionTotal(Product product, bool takeThisTurnData) { if (takeThisTurnData) { return(recalculateProductForProducers(product, x => x.getGainGoodsThisTurn())); } if (!dateOfgetTotalProduction.IsToday) { //recalculate Production buffer foreach (Storage recalculatingProduct in prices) { if (recalculatingProduct.Product.isTradable()) { var result = recalculateProductForProducers(recalculatingProduct.Product, x => x.getGainGoodsThisTurn()); totalProduction.Set(new Storage(recalculatingProduct.Product, result)); } } dateOfgetTotalProduction.set(Date.Today); } return(totalProduction.GetFirstSubstituteStorage(product)); }
/// <summary> /// All produced supplies /// Based on last turn data /// </summary> internal Storage getProductionTotal(Product product, bool takeThisTurnData) { if (takeThisTurnData) { return(recalculateProductForProducers(product, x => x.getGainGoodsThisTurn())); } if (dateOfgetTotalProduction != Game.date) { //recalculate Production buffer foreach (Storage recalculatingProduct in marketPrice) { if (recalculatingProduct.getProduct().isTradable()) { var result = recalculateProductForProducers(recalculatingProduct.getProduct(), x => x.getGainGoodsThisTurn()); totalProduction.Set(new Storage(recalculatingProduct.getProduct(), result)); } } dateOfgetTotalProduction.set(Game.date); } return(totalProduction.GetFirstSubstituteStorage(product)); }
internal Storage getBouthOnMarket(Product product, bool takeThisTurnData) { if (takeThisTurnData) { // recalculate only 1 product return(recalculateProductForBuyers(product, x => x.getConsumedInMarket())); } if (!dateOfgetBought.IsToday) { //recalculate all products foreach (Storage recalculatingProduct in marketPrice) { if (recalculatingProduct.Product.isTradable()) { var result = recalculateProductForConsumers(recalculatingProduct.Product, x => x.getConsumedInMarket()); bought.Set(new Storage(recalculatingProduct.Product, result)); } } dateOfgetBought.set(Date.Today); } return(bought.GetFirstSubstituteStorage(product)); }
//internal void ForceDSBRecalculation() //{ // //dateOfDSB--;//!!! Warning! This need to be uncommented to work properly // getDemandSupplyBalance(null); //} /// <summary> /// per 1 unit /// </summary> public void SetDefaultPrice(Product pro, float inprice) { marketPrice.Set(new Storage(pro, inprice)); }
static ProductionType() { new ProductionType("Forestry", new Storage(Product.Wood, 2f), false); new ProductionType("Gold pit", new Storage(Product.Gold, 2f * Options.goldToCoinsConvert), true); new ProductionType("Metal pit", new Storage(Product.MetalOre, 2f), true); new ProductionType("Coal pit", new Storage(Product.Coal, 6f), true); new ProductionType("Cotton farm", new Storage(Product.Cotton, 2f), false); new ProductionType("Quarry", new Storage(Product.Stone, 2f), true); new ProductionType("Orchard", new Storage(Product.Fruit, 2f), false); new ProductionType("Fishery", new Storage(Product.Fish, 2f), false); new ProductionType("Tobacco farm", new Storage(Product.Tobacco, 2f), false); new ProductionType("Oil rig", new Storage(Product.Oil, 2f), true); new ProductionType("Rubber plantation", new Storage(Product.Rubber, 1f), false); StorageSet resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Grain, 1f)); new ProductionType("Barnyard", new Storage(Product.Cattle, 2f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Lumber, 1f)); new ProductionType("Furniture factory", new Storage(Product.Furniture, 4f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Wood, 1f)); new ProductionType("Sawmill", new Storage(Product.Lumber, 4f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Fuel, 0.5f)); resourceInput.Set(new Storage(Product.MetalOre, 2f)); new ProductionType("Metal smelter", new Storage(Product.Metal, 8f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Fibers, 1f)); new ProductionType("Weaver factory", new Storage(Product.Clothes, 4f), resourceInput); //resourceInput = new StorageSet(); //resourceInput.Set(new Storage(Product.Fuel, 0.5f)); //resourceInput.Set(new Storage(Product.Stone, 2f)); //new ProductionType("Cement factory", new Storage(Product.Cement, 4f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Sugar, 1f)); new ProductionType("Distillery", new Storage(Product.Liquor, 4f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Metal, 1f)); new ProductionType("Smithery", new Storage(Product.ColdArms, 4f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Stone, 1f)); resourceInput.Set(new Storage(Product.Metal, 1f)); new ProductionType("Ammunition factory", new Storage(Product.Ammunition, 8f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Lumber, 1f)); resourceInput.Set(new Storage(Product.Metal, 1f)); new ProductionType("Firearms factory", new Storage(Product.Firearms, 8f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Lumber, 1f)); resourceInput.Set(new Storage(Product.Metal, 1f)); new ProductionType("Artillery factory", new Storage(Product.Artillery, 8f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Oil, 1f)); new ProductionType("Oil refinery", new Storage(Product.MotorFuel, 4f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Metal, 1f)); new ProductionType("Machinery factory", new Storage(Product.Machinery, 4f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Machinery, 1f)); resourceInput.Set(new Storage(Product.Metal, 1f)); resourceInput.Set(new Storage(Product.Rubber, 1f)); new ProductionType("Car factory", new Storage(Product.Cars, 12f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Machinery, 1f)); resourceInput.Set(new Storage(Product.Metal, 1f)); resourceInput.Set(new Storage(Product.Artillery, 1f)); new ProductionType("Tank factory", new Storage(Product.Tanks, 12f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Lumber, 1f)); resourceInput.Set(new Storage(Product.Metal, 1f)); resourceInput.Set(new Storage(Product.Machinery, 1f)); new ProductionType("Airplane factory", new Storage(Product.Airplanes, 12f), resourceInput); resourceInput = new StorageSet(); resourceInput.Set(new Storage(Product.Metal, 1f)); resourceInput.Set(new Storage(Product.Oil, 1f)); resourceInput.Set(new Storage(Product.Rubber, 1f)); new ProductionType("Electronics factory", new Storage(Product.Electronics, 12f), resourceInput); University = new ProductionType("University", new Storage(Product.Education, 4f), new StorageSet()); }
public void ForceDSBRecalculation2() { // get all MarketSupply foreach (Country country in World.AllExistingCountries()) { foreach (var agent in country.Provinces.AllAgents) { //if (found.isExactlySameProduct(product)) var isSeller = agent as Producer; if (isSeller != null) { foreach (var deal in isSeller.AllSellDeals()) { if (deal.Key == this)// && deal.Value.Product.isTradable()) { marketSupply.AddAndSum(deal.Value.Product, deal.Value); } } } var isConsumer = agent as Consumer; if (isConsumer != null) { foreach (var deal in isConsumer.AllConsumedInMarket(this)) { //if (deal.Product.isTradable()) boughtOnMarket.AddAndSum(deal.Product, deal); } } } } // get all getBoughtOnMarket //foreach (Country country in World.getAllExistingCountries()) //{ // foreach (var consumer in country.AllConsumers()) // { // //if (found.isExactlySameProduct(product)) // foreach (var deal in consumer.AllConsumedInMarket(this)) // { // //if (deal.Product.isTradable()) // boughtOnMarket.AddAndSum(deal.Product, deal); // } // } //} //calculate DSB foreach (var product in Product.AllNonAbstract()) { float balance, demand = 0f, supply = 0f; Value demandValue; if (boughtOnMarket.TryGetValue(product, out demandValue)) { demand = demandValue.get(); } Value supplyValue; if (marketSupply.TryGetValue(product, out supplyValue)) { supply = supplyValue.get(); } if (supply == 0) { balance = Options.MarketInfiniteDSB; // supply zero } else { if (demand == 0f) // demand zero { balance = Options.MarketZeroDSB; // otherwise - furniture bag } else { balance = demand / supply; } } if (supply != 0f && demand == 0f) { balance = Options.MarketZeroDSB; // Options.MarketInfiniteDSB; // supply zero } else if (supply == 0f && demand == 0f) { balance = Options.MarketInfiniteDSB; // Options.MarketInfiniteDSB; // supply zero } else { if (demand == 0f) // demand zero { balance = Options.MarketZeroDSB; // otherwise - furniture bag } else { balance = demand / supply; } } DSBbuffer.Set(new Storage(product, balance)); } dateOfDSB.set(Date.Today); }