Exemple #1
0
 public override void KnockOffSnow(Vec2 dir, bool vertShake)
 {
     this.iterated = true;
     if (!this.knocked || vertShake)
     {
         bool knocked = this.knocked;
         this.knocked = true;
         PineTree pineTree1 = (PineTree)Level.CheckPoint <PineTreeSnowTileset>(this.x - 8f, this.y, (Thing)this);
         PineTree pineTree2 = (PineTree)Level.CheckPoint <PineTreeSnowTileset>(this.x + 8f, this.y, (Thing)this);
         if (pineTree1 != null && !pineTree1.iterated && (!pineTree1.knocked || vertShake))
         {
             pineTree1.KnockOffSnow(dir, vertShake);
         }
         if (pineTree2 != null && !pineTree2.iterated && (!pineTree2.knocked || vertShake))
         {
             pineTree2.KnockOffSnow(dir, vertShake);
         }
         if (!knocked)
         {
             for (int index = 0; index < 2; ++index)
             {
                 Level.Add((Thing) new SnowFallParticle(this.x + Rando.Float(-4f, 4f), this.y + Rando.Float(-4f, 4f), dir * Rando.Float(1f) + new Vec2(Rando.Float(-0.1f, -0.1f), Rando.Float(-0.1f, -0.1f) - Rando.Float(0.1f, 0.3f))));
             }
         }
     }
     if (this._snowFall.currentAnimation == "idle")
     {
         this._snowFall.SetAnimation("fall");
     }
     if (vertShake)
     {
         this._vertPush = 0.5f;
     }
     this.knocked  = true;
     this.iterated = false;
 }
        public override void Decorate(ChunkColumn column, int chunkX, int chunkZ, BiomeBase biome, float[] thresholdMap, int x, int y, int z, bool surface,
                                      bool isBelowMaxHeight)
        {
            try
            {
                var currentTemperature = biome.Temperature;
                if (y > 64)
                {
                    int distanceToSeaLevel = y - 64;
                    currentTemperature = biome.Temperature - (0.00166667f * distanceToSeaLevel);
                }

                int rx = chunkX * 16 + x;
                int rz = chunkZ * 16 + z;

                bool generated = false;
                if (surface && y >= Preset.SeaLevel)
                {
                    var noise = Simplex.Noise(rx, rz, Math.Min(biome.Downfall * 0.32f, 0.03f), 0.5, true);
                    if (x >= 3 && x <= 13 && z >= 3 && z <= 13)
                    {
                        Structure tree = null;
                        //if (biome.Config.)
                        if (biome.Downfall <= 0f && biome.Temperature >= 2f)
                        {
                            if (GetRandom(32) == 16)
                            {
                                var randValue = GetRandom(18);
                                if (randValue >= 0 && randValue <= 2)                                 //3 tall cactus
                                {
                                    tree = new CactusStructure(3);
                                }
                                else if (randValue > 2 && randValue <= 5)                                 // 2 tall cactus
                                {
                                    tree = new CactusStructure(2);
                                }
                                else if (randValue > 5 && randValue <= 11)                                 // 1 tall cactus
                                {
                                    tree = new CactusStructure(1);
                                }
                            }
                        }

                        if (tree == null && biome.Downfall >= 0 && (noise > (0.5f + (y / 512f))))
                        {
                            if (currentTemperature >= 1f && biome.Downfall >= 0.4f)
                            {
                                if (GetRandom(8) == 4)
                                {
                                    tree = new LargeJungleTree();
                                }
                                else
                                {
                                    tree = new SmallJungleTree();
                                }
                            }

                            /*	else if (currentTemperature >= 0.7F && biome.Downfall >= 0.2f)
                             *      {
                             *              tree = new OakTree(true);
                             *      }*/
                            else if (currentTemperature >= 0.7F && biome.Downfall < 0.2f)
                            {
                                tree = new AcaciaTree();
                            }
                            else if (currentTemperature > 0.25f && biome.Downfall > 0f)
                            {
                                if (biome.Name.Contains("Birch") || GetRandom(16) == 8)
                                {
                                    tree = new BirchTree();
                                }
                                else
                                {
                                    tree = new OakTree();
                                }
                            }
                            else if (currentTemperature <= 0.25f && biome.Downfall > 0f)
                            {
                                tree = new PineTree();
                            }
                        }

                        if (tree != null)
                        {
                            if (y + 1 < 254)
                            {
                                tree.Create(column, x, y + 1, z);
                            }
                            generated = true;
                        }
                    }

                    if (!generated)
                    {
                        if (noise > 0.5)                         //Threshold 1
                        {
                            /*if (currentTemperature > 0.3f && currentTemperature < 1.5f && biome.Downfall >= 0.85f)
                             * {
                             *      column.SetBlock(x, y + 1, z, 18); //Leaves
                             *      column.SetMetadata(x, y + 1, z, 3); //Jungle Leaves
                             * }
                             * else*/
                            if (currentTemperature > 0.3f && currentTemperature < 1.5f && biome.Downfall > 0)
                            {
                                var blockBeneath = column.GetBlockId(x, y, z);                                // column.GetBlock(x, y, z);

                                var sugarPosibility = GetRandom(18);
                                if (/*sugarPosibility <= 11*/ noise > 0.75f &&
                                    (blockBeneath == 3 || blockBeneath == 2 || blockBeneath == 12) &&
                                    IsValidSugarCaneLocation(column, x, y, z))
                                {
                                    int height = 1;
                                    if (sugarPosibility <= 2)
                                    {
                                        height = 3;
                                    }
                                    else if (sugarPosibility <= 5)
                                    {
                                        height = 2;
                                    }

                                    //var growth = Rnd.Next(0x1, 0x15);
                                    for (int mY = y + 1; mY < y + 1 + height; mY++)
                                    {
                                        //column.SetBlock(x, mY, z, 83); //SugarCane
                                        //blocks[OverworldGenerator.GetIndex(x, mY, z)] = 83;

                                        if (mY == y + 1 + height)
                                        {
                                            //metadata[OverworldGenerator.GetIndex(x, mY, z)] = (byte) Rnd.Next(0, 15);
                                            //column.SetMetadata(x, mY, z, (byte) Rnd.Next(0, 15));
                                        }
                                        else
                                        {
                                            //metadata[OverworldGenerator.GetIndex(x, mY, z)] = (byte) 0;
                                            //column.SetMetadata(x, mY, z, 0);
                                        }
                                    }
                                }
                                else if (noise > 0.8 && blockBeneath == 3 || blockBeneath == 2)                                 //If above 0.8, we generate flowers :)
                                {
                                    if (Simplex.Noise(rx, rz, 0.5f, 0.5f, true) > 0.5)
                                    {
                                        column.SetBlock(x, y + 1, z, new RedFlower()
                                        {
                                            FlowerType = FlowerTypes[GetRandom(FlowerTypes.Length - 1)]
                                        });
                                        //blocks[OverworldGenerator.GetIndex(x, y + 1, z)] = 38;
                                        //metadata[OverworldGenerator.GetIndex(x, y + 1, z)] = (byte) GetRandom(8);
                                        //column.SetBlock(x, y + 1, z, 38); //Poppy
                                        //column.SetMetadata(x, y + 1, z, (byte) GetRandom(8));
                                    }
                                    else
                                    {
                                        //	blocks[OverworldGenerator.GetIndex(x, y + 1, z)] = 37;
                                        //	column.SetBlock(x, y + 1, z, new Dan());
                                        //	column.SetBlock(x, y + 1, z, 37); //Dandelion
                                    }
                                }
                                else if (blockBeneath == 3 || blockBeneath == 2)
                                {
                                    column.SetBlock(x, y + 1, z, new Tallgrass());
                                    //blocks[OverworldGenerator.GetIndex(x, y + 1, z)] = 31;
                                    //metadata[OverworldGenerator.GetIndex(x, y + 1, z)] = (byte) 1;
                                    //column.SetBlock(x, y + 1, z, 31); //Grass
                                    //column.SetMetadata(x, y + 1, z, 1);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            Noise                = new Perlin(world.Seed);
            ChanceNoise          = new ClampNoise(Noise);
            ChanceNoise.MaxValue = 2;
            Coordinates2D?lastTree = null;

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    var biome  = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
                    var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
                    var height = chunk.HeightMap[x * Chunk.Width + z];

                    if (lastTree != null && lastTree.Value.DistanceTo(new Coordinates2D(x, z)) < biome.TreeDensity)
                    {
                        continue;
                    }

                    if (Noise.Value2D(blockX, blockZ) > 0.3)
                    {
                        var location = new Coordinates3D(x, height, z);
                        var id       = chunk.GetBlockID(location);
                        var provider = world.BlockRepository.GetBlockProvider(id);
                        if (id == DirtBlock.BlockID || id == GrassBlock.BlockID || id == SnowfallBlock.BlockID ||
                            (id != StationaryWaterBlock.BlockID && id != WaterBlock.BlockID &&
                             id != LavaBlock.BlockID && id != StationaryLavaBlock.BlockID &&
                             provider.BoundingBox == null))
                        {
                            if (provider.BoundingBox == null)
                            {
                                location.Y--;
                            }
                            var oakNoise    = ChanceNoise.Value2D(blockX * 0.6, blockZ * 0.6);
                            var birchNoise  = ChanceNoise.Value2D(blockX * 0.2, blockZ * 0.2);
                            var spruceNoise = ChanceNoise.Value2D(blockX * 0.35, blockZ * 0.35);

                            var baseCoordinates = location + Coordinates3D.Up;
                            if (biome.Trees.Contains(TreeSpecies.Oak) && oakNoise > 1.01 && oakNoise < 1.25)
                            {
                                var oak = new OakTree().GenerateAt(world, chunk, baseCoordinates);
                                if (oak)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Birch) && birchNoise > 0.3 && birchNoise < 0.95)
                            {
                                var birch = new BirchTree().GenerateAt(world, chunk, baseCoordinates);
                                if (birch)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Spruce) && spruceNoise < 0.75)
                            {
                                var random    = new Random(world.Seed);
                                var type      = random.Next(1, 2);
                                var generated = false;
                                if (type.Equals(1))
                                {
                                    generated = new PineTree().GenerateAt(world, chunk, baseCoordinates);
                                }
                                else
                                {
                                    generated = new ConiferTree().GenerateAt(world, chunk, baseCoordinates);
                                }

                                if (generated)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }