Ejemplo n.º 1
0
    private void Update()
    {
        if (_featureToggles.desertsAreBeaches)
        {
            return;
        }

        var sandSpreadController = _sandSpreadController;

        if (Random.value < sandSpreadController.chance)
        {
            var block = _worldPlane.GetNearbyBlocks(_block.GetGridPosition())
                        .Where(b => _worldPlane.BlockCanBeReplacedBySandBlock(b))
                        .ToList()
                        .OrderBy(_ => Random.value)
                        .First();

            var score = _worldPlane.NatureScore(block.GetGridPosition(), sandSpreadController.natureScoreRadius);
            if (score < _sandSpreadController.spreadResistanceThreshold)
            {
                var sandBlockRoot = Instantiate(sandBlockTemplate);
                var sandBlock     = sandBlockRoot.GetComponentInChildren <Block>();
                _worldPlane.ReplaceBlock(block, sandBlock);
            }
            else if (score > _sandSpreadController.spreadCombatThreshold)
            {
                var grassBlockRoot = Instantiate(grassBlockTemplate);
                var grassBlock     = grassBlockRoot.GetComponentInChildren <Block>();
                _worldPlane.ReplaceBlock(_block, grassBlock);
            }
        }
    }
Ejemplo n.º 2
0
    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;
            }
        }
    }
Ejemplo n.º 3
0
 private void UpdateWaterLockedStatus()
 {
     _block.SetWaterLocked(_worldPlane.GetNearbyBlocks(_block.GetGridPosition())
                           .All(block => block.IsWater()));
 }
Ejemplo n.º 4
0
    void Update()
    {
        if (CanWorkThisFrame() && Random.value < .01f)
        {
            var docks = _worldPlane.GetBlocksWithDocks().Count();
            if (docks > 0)
            {
                if (Random.value < .01f)
                {
                    TrySpawnBoat();
                }
            }
        }

        if (!_featureToggles.docksSpawn)
        {
            return;
        }

        if (CanWorkThisFrame() && Random.value < .01f)
        {
            var houseCount = _worldPlane
                             .GetBlocksWithHouses()
                             .Count(blockWithHouse => blockWithHouse.GetOccupantHouse().IsBig());
            if (houseCount < 1)
            {
                return;
            }

            var docks = _worldPlane.GetBlocksWithDocks().Count();
            if (docks > 0)
            {
                var docksToHouseRatio = (float)Mathf.Max(docks, 1) / (float)houseCount;
                if (docksToHouseRatio > .05f)
                {
                    return;
                }
            }

            var candidate = _worldPlane.GetWaterBlocks()
                            .Where(waterBlock => waterBlock.IsGroundLevel())
                            .OrderBy(_ => Random.value)
                            .Take(2)
                            .Where(waterBlock => _worldPlane.GetMajorityBlockTypeWithinRange(waterBlock.GetGridPosition(), 1f)
                                   == Block.BlockType.Lake &&
                                   _worldPlane.NoNearby(waterBlock.GetGridPosition(), 3f, BlockHasDocksSpawn))
                            .SelectMany(waterBlock =>
            {
                return(_worldPlane
                       .GetNearbyBlocks(waterBlock.GetGridPosition())
                       .Where(block =>
                              Math.Abs(block.GetGridPosition().y - waterBlock.GetGridPosition().y) < .5f &&
                              block.IsGrass() && block.IsVacant())
                       .Select(block => new Tuple <Block, Block>(waterBlock, block)));
            })
                            .OrderBy(_ => Random.value)
                            .FirstOrDefault();

            if (candidate != null)
            {
                var(waterBlock, vacantLot) = candidate;
                var dockSpawn = Instantiate(dockSpawnTemplate);
                vacantLot.Occupy(dockSpawn);
                var target = waterBlock.transform.position;
                target.y = dockSpawn.transform.position.y;
                dockSpawn.transform.LookAt(target);
            }
        }
    }