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(); } }
private void Expand() { foreach (var block in _soils.ToList()) { var candidates = _worldPlane.GetNearbyVacantLots(block.GetGridPosition()) .Where(vacantBlock => { var amountOfNeighbouringWaterBlocks = _worldPlane.GetNearbyBlocks(vacantBlock.GetGridPosition()) .Count(nearbyBlock => nearbyBlock.IsWater()); return(amountOfNeighbouringWaterBlocks == 0); }) .OrderBy(_ => Random.value) .ToList(); if (candidates.Any()) { var choice = candidates.First(); MakeToSoilWithFarm(choice); return; } } }