Ejemplo n.º 1
0
        public override void Execute()
        {
            if (_wvm.CurrentWorld == null)
            {
                return;
            }

            // refresh generator if needed
            //if (_noiseGenerator.Seed != _wvm.CurrentWorld.WorldId)
            //{
            _noiseGenerator = new PerlinNoise((int)DateTime.Now.Ticks);
            //}

            var area = new Rectangle(0, (int)_wvm.CurrentWorld.GroundLevel, _wvm.CurrentWorld.TilesWide, _wvm.CurrentWorld.TilesHigh - (int)_wvm.CurrentWorld.GroundLevel - 196);

            if (_wvm.Selection.IsActive)
            {
                if (!_wvm.Selection.SelectionArea.Intersect(new Rectangle(0, 0, _wvm.CurrentWorld.TilesWide, _wvm.CurrentWorld.TilesHigh), out area))
                {
                    return;
                }
            }

            if (area.Width <= 0 || area.Height <= 0)
            {
                return;
            }

            var tile = (ushort)_wvm.TilePicker.Tile;

            for (int x = area.Left; x < area.Right; x++)
            {
                for (int y = area.Top; y < area.Bottom; y++)
                {
                    var result = TestOctaveGenerator(x, y);
                    if (result > 0.6 && result < 0.75)
                    {
                        var curTile = _wvm.CurrentWorld.Tiles[x, y];

                        // Only replace if the tile is dirt or stone and if the wall is empty, stone or dirt.

                        if (curTile.IsActive && _wvm.TilePicker.TileMaskMode == MaskMode.Match && curTile.Type != _wvm.TilePicker.TileMask)
                        {
                            // test mask
                            continue;
                        }

                        if (curTile.IsActive && _wvm.TilePicker.TileMaskMode == MaskMode.NotMatching && curTile.Type == _wvm.TilePicker.TileMask)
                        {
                            // test inverted mask
                            continue;
                        }

                        if (!curTile.IsActive && _wvm.TilePicker.TileMaskMode == MaskMode.Empty)
                        {
                            // if mask is empty and tile is active, skip
                            continue;
                        }

                        if (_wvm.TilePicker.TileMaskMode == MaskMode.Off && !(curTile.Type >= 0 && curTile.Type <= 1 && (curTile.Wall >= 0 && curTile.Wall <= 2)))
                        {
                            // if no mask, only match dirt or stone
                            continue;
                        }

                        _wvm.UndoManager.SaveTile(x, y);
                        _wvm.CurrentWorld.Tiles[x, y].IsActive = true;
                        _wvm.CurrentWorld.Tiles[x, y].Type     = tile;
                        _wvm.UpdateRenderPixel(x, y);
                    }
                }
            }
            _wvm.UndoManager.SaveUndo();
        }
Ejemplo n.º 2
0
 public SimplePerlinGeneratorPlugin(WorldViewModel worldViewModel)
     : base(worldViewModel)
 {
     _noiseGenerator = new PerlinNoise(1);
     Name            = "Simple Ore Generator";
 }