示例#1
0
        /// <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());
            }
        }
示例#2
0
 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));
 }
示例#3
0
 /// <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));
 }
示例#4
0
        /// <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));
        }
示例#5
0
        /// <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));
        }
示例#6
0
        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));
        }
示例#7
0
 internal Value getConsumption(Product prod)
 {
     return(consumption.GetFirstSubstituteStorage(prod));
 }
 public Storage getSentToMarket(Product product)
 {
     return(sentToMarket.GetFirstSubstituteStorage(product));
 }