Ejemplo n.º 1
0
    private void SpawnOneHouse()
    {
        var waterAndLot = _worldPlane
                          .GetStableShorelineBlocks()
                          .OrderBy(_ => Random.value)
                          .Take(10)
                          .SelectMany(waterBlock =>
        {
            return(_worldPlane.GetNearbyVacantLotsStream(waterBlock.GetGridPosition())
                   .Where(levelVacantLot => waterBlock.IsLevelWith(levelVacantLot))
                   .Select(vacantLot => new Tuple <Block, Block>(waterBlock, vacantLot)));
        })
                          .OrderBy(_ => Random.value)
                          .FirstOrDefault();

        if (waterAndLot != null)
        {
            var(waterBlock, vacantLot) = waterAndLot;
            var house = Instantiate(tinyHouseTemplate);
            vacantLot.Occupy(house);
            var target = waterBlock.transform.position;
            target.y = house.transform.position.y;
            house.transform.LookAt(target);

            _lastPlacedHouse = Time.fixedTime;
        }
    }
Ejemplo n.º 2
0
    private void TrySpawnFort()
    {
        if (CheckIfThereAreEnoughMountainToSpawnFort())
        {
            return;
        }

        var potentialFortBottoms = _worldPlane.GetVacantBlocksStream()
                                   .Where(vacantBlock =>
        {
            return(vacantBlock.IsGroundLevel() &&
                   _worldPlane
                   .GetMajorityBlockTypeWithinRange(vacantBlock.GetGridPosition(), 1f) == Block.BlockType.Grass &&
                   _worldPlane.NoNearby(
                       vacantBlock.GetGridPosition(),
                       2f,
                       block => block.blockType == Block.BlockType.Lake
                       ));
        });

        var candidates = new List <Tuple <Block, Block> >();

        foreach (var fortBottom in potentialFortBottoms)
        {
            var nearbyHighlands = _worldPlane.GetNearbyVacantLotsStream(fortBottom.GetGridPosition())
                                  .Where(block =>
            {
                var highlandIsOneBlockAboveFortBottomLevel =
                    Math.Abs(block.GetGridPosition().y - (fortBottom.GetGridPosition().y + 1f)) < .5f;

                return(highlandIsOneBlockAboveFortBottomLevel && block.IsGrass() && block.IsVacant());
            });

            foreach (var highland in nearbyHighlands)
            {
                candidates.Add(
                    new Tuple <Block, Block>(fortBottom, highland)
                    );
            }
        }

        var candidateCount = candidates.Count;

        if (candidateCount > 0)
        {
            var(fortBottom, highlands) = candidates.ElementAt(Random.Range(0, candidateCount));
            var fortSpawn = Instantiate(fortSpawnTemplate);
            fortBottom.Occupy(fortSpawn);
            highlands.SetOccupantThatIsTailFromOtherBase(fortSpawn);
            var target = highlands.transform.position;
            target.y = fortSpawn.transform.position.y;
            fortSpawn.transform.LookAt(target);

            _fortCount += 1;
        }
    }
Ejemplo n.º 3
0
    private void SpawnMasterFarm(List <Block> houses)
    {
        var houseBlock   = houses.OrderBy(_ => Random.value).First();
        var lotToReplace = _worldPlane.GetNearbyVacantLotsStream(houseBlock.GetGridPosition())
                           .OrderBy(_ => Random.value)
                           .FirstOrDefault();

        if (lotToReplace != null)
        {
            FarmMasterController.Get().SetupFarmControllerForBlock(lotToReplace);

            _placedFirstFarm = true;
        }
    }