Exemplo n.º 1
0
        internal override void WorldAction()
        {
            if (dead)
            {
                return;
            }
            //Update all crops
            foreach (var crop in growingCrops)
            {
                crop.time--;
                if (crop.time == 0)
                {
                    Resource r = crop.Yield();
                    r.amount = (int)(r.amount * (1 + (-0.5 + agriculturalValue / 100d)));
                    ProduceItem(r.name, r.amount);
                }
            }
            growingCrops = growingCrops.Where(c => c.time > 0).ToList();
            while (growingCrops.Count <= workers / 4)
            {
                (double temperature, double humidity) = World.Instance.GetWeather(position);
                List <Crop> list = Crop.GetCrops((int)World.GetCelsius(temperature), (int)(humidity * 1000));
                if (list.Count == 0)
                {
                    break;
                }
                growingCrops.Add(list.GetRandom().Duplicate());
            }

            if (day % 365 == 0)
            {
                double rainFall = World.Instance.rainfallMap.Get(position);
                Trace.TraceInformation($"{name} on {World.Instance.worldMap.Get(position).island.Name} has produced {yearlyProduction} food this year and has {money} money from {lastMoney}");
                if (lastMoney > money)
                {
                    costIncrease += 1;
                }
                else
                {
                    costIncrease -= 1;
                }
                costIncrease     = costIncrease.Min(0);
                yearlyProduction = 0;
                lastMoney        = money;
                while (workers < 20 && money >= 6 * workers * 365)
                {
                    //Trace.TraceInformation($"{name} at {position} has gone grown!");
                    workers++;
                }
            }
            else if (day % 7 == 0)
            {
                money -= workers * 2;
            }
            if (money <= 0)
            {
                Trace.TraceInformation($"{name} at {position} has gone bankrupt!");
                dead = true;
                World.Instance.nation.toChange.Add(this);
            }
            day++;
        }