Пример #1
0
        public void UpdateDemand(InternalMarket market, Population population)
        {
            ResourceDemand.Reset();

            var lifePriceRatioMap = new Dictionary <ResourceType, double>();

            foreach (ResourceType resourceType in ResourceTypes.resourceTypes)
            {
                if (GetAmountNeeded(resourceType) == 0)
                {
                    continue;
                }
                lifePriceRatioMap[resourceType] = Convert.ToDouble(LifeValues[resourceType.Id]) / market.GetPrice(resourceType);
            }
            ComputeWhatToBuy(market, population, lifePriceRatioMap);
            market.AddDemand(ResourceDemand);
        }
Пример #2
0
        private void ComputeWhatToBuy(InternalMarket market, Population population, Dictionary <ResourceType, double> lifePriceRatioMap)
        {
            double money = population.money;
            IEnumerable <KeyValuePair <ResourceType, double> > orderedLifePriceRatio = lifePriceRatioMap.OrderByDescending(ratio => ratio.Value);

            foreach (KeyValuePair <ResourceType, double> resoucreTypeRatio in orderedLifePriceRatio)
            {
                ResourceType resourceType = resoucreTypeRatio.Key;
                double       price        = market.GetPrice(resourceType);
                double       buyAmount    = Math.Min(money / price, population.GetPopLevel() * GetAmountNeeded(resourceType));
                ResourceDemand.SetResource(new Resource(resourceType, buyAmount));
                money -= buyAmount * price;
                if (money <= 0)
                {
                    break;
                }
            }
        }
Пример #3
0
 public double GetDemand(ResourceType resourceType)
 {
     return(ResourceDemand.GetAmount(resourceType));
 }