Beispiel #1
0
    void Update()
    {
        if (!FeatureToggles.Get().woodcutters)
        {
            return;
        }

        if (Random.value < .01f)
        {
            var houseCount = _worldPlane.GetBlocksWithHouses().Count;
            if (houseCount < 3)
            {
                return;
            }

            var woodcutters            = _worldPlane.GetBlocksWithWoodcutters().Count();
            var woodcutterToHouseRatio = (float)Mathf.Max(woodcutters, 1) / (float)houseCount;
            if (woodcutterToHouseRatio > .1f)
            {
                return;
            }

            var greensAndVacantLot = _worldPlane
                                     .GetBlocksWithGreens()
                                     .SelectMany(block =>
            {
                return(_worldPlane
                       .GetNearbyVacantLots(block.GetGridPosition())
                       .Select(vacantLot => new Tuple <Block, Block>(block, vacantLot)));
            })
                                     .OrderBy(_ => Random.value)
                                     .FirstOrDefault();

            if (greensAndVacantLot != null)
            {
                SpawnWoodcutter(greensAndVacantLot);
            }
        }

        if (_hasUnfulfilledRequestToStoreWood)
        {
            _hasUnfulfilledRequestToStoreWood = false;

            SpawnStockpile();
        }
    }