コード例 #1
0
        public void ZipRetrieveLocalSector()
        {
            string filename = Path.Combine(TestingUtilities.Config["DataPath"], "LocalSector.zip");

            if (!File.Exists(filename))
            {
                ZipStoreLocalSector();
            }

            IStellarMap map;
            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.ZipStorage);

            using StreamReader reader = new StreamReader(filename);
            map = store.Retreive <ProgressionMap>(reader);

            // now serialize it to json file to inspect
            filename = Path.Combine(TestingUtilities.Config["DataPath"], "LocalSectorCheck.json");

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            store = MapStorageFactory.GetStorage(MapStorageFactory.JsonStorage);

            using StreamWriter writer = new StreamWriter(filename);
            store.Store(map, writer);
        }
コード例 #2
0
 /// <summary>
 /// Sets a block at the given position.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <param name="blocktype"></param>
 private static void SetBlock(IMapStorage map, int x, int y, int z, int blocktype)
 {
     if (MapUtil.IsValidPos(map, x, y, z))
     {
         map.SetBlock(x, y, z, blocktype);
     }
 }
コード例 #3
0
        public static void MakeSmallTrees(IMapStorage map, int cx, int cy, int cz, int chunksize, Random rnd, int count)
        {
            int chooseTreeType;

            for (int i = 0; i < count; i++)
            {
                int x = cx + rnd.Next(chunksize);
                int y = cy + rnd.Next(chunksize);
                int z = cz + rnd.Next(chunksize);
                if (!MapUtil.IsValidPos(map, x, y, z) || map.GetBlock(x, y, z) != WorldGeneratorTools.TileIdGrass)
                {
                    continue;
                }
                chooseTreeType = rnd.Next(0, 3);
                switch (chooseTreeType)
                {
                case 0: MakeTreeType1(map, x, y, z, rnd); break;

                case 1: MakeTreeType2(map, x, y, z, rnd); break;

                case 2: MakeTreeType3(map, x, y, z, rnd); break;
                }
                ;
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a cuboid at the given location and using the given sizes.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="sizex"></param>
        /// <param name="sizey"></param>
        /// <param name="sizez"></param>
        /// <param name="blocktype"></param>
        /// <param name="allowin"></param>
        /// <param name="chance"></param>
        /// <param name="rnd"></param>
        public static void MakeCuboid(IMapStorage map, int x, int y, int z, int sizex, int sizey, int sizez, int blocktype, int[] allowin, double chance, Random rnd)
        {
            for (int xx = 0; xx < sizex; xx++)
            {
                for (int yy = 0; yy < sizey; yy++)
                {
                    for (int zz = 0; zz < sizez; zz++)
                    {
                        if (MapUtil.IsValidPos(map, x + xx, y + yy, z + zz))
                        {
                            int t = map.GetBlock(x + xx, y + yy, z + zz);
                            if (allowin == null)
                            {
                                goto ok;
                            }
                            foreach (int tt in allowin)
                            {
                                if (tt == t)
                                {
                                    goto ok;
                                }
                            }
                            continue;
ok:
                            if (rnd.NextDouble() < chance)
                            {
                                map.SetBlock(x + xx, y + yy, z + zz, blocktype);
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Creates some flowers all over the chunk.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="cz"></param>
        /// <param name="chunksize"></param>
        /// <param name="rnd"></param>
        public static void MakeFlowers(IMapStorage map, int cx, int cy, int cz, int chunksize, Random rnd)
        {
            for (int i = 0; i < 5; i++)
            {
                int x = cx + rnd.Next(chunksize);
                int y = cy + rnd.Next(chunksize);
                int z = cz + rnd.Next(chunksize);
                if (!MapUtil.IsValidPos(map, x, y, z) || map.GetBlock(x, y, z) != WorldGeneratorTools.TileIdGrass)
                {
                    continue;
                }
                int xx; int yy; int zz;
                int tile  = rnd.NextDouble() < 0.75 ? WorldGeneratorTools.TileIdYellowFlower : WorldGeneratorTools.TileIdRedFlower;
                int count = rnd.Next(50, 80);
                for (int j = 0; j < count; j++)
                {
                    xx = x + rnd.Next(-6, 6);
                    yy = y + rnd.Next(-6, 6);
                    zz = z + rnd.Next(-2, 2);
                    if (!MapUtil.IsValidPos(map, xx, yy, zz) || map.GetBlock(xx, yy, zz) != WorldGeneratorTools.TileIdGrass)
                    {
                        continue;
                    }

                    // set the block
                    SetBlock(map, x, y, z, tile);
                }
            }
        }
コード例 #6
0
ファイル: CoreStorage.cs プロジェクト: ErgodicMage/StellarMap
        public void ZipRetrieveSolarSystem()
        {
            string filename = Path.Combine(TestingUtilities.Config["DataPath"], "SolarSystem.zip");

            if (!File.Exists(filename))
            {
                ZipStoreSolarSystem();
            }

            IStellarMap map;
            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.ZipStorage);

            using StreamReader reader = new StreamReader(filename);
            map = store.Retreive <BaseStellarMap>(reader);

#pragma warning disable S125
            //// now serialize it to json file to inspect
            //filename = Path.Combine(TestingUtilities.Config["DataPath"], "SolarSystem from zip.json");

            //if (File.Exists(filename))
            //    File.Delete(filename);

            //store = MapStorageFactory.GetStorage(MapStorageFactory.JsonStorage);

            //using StreamWriter writer = new StreamWriter(filename);
            //store.Store(map, writer);
#pragma warning restore S125

            IStellarMap generatedMap = SolarSystem.CreateSolSystem();

            Assert.IsTrue(BaseStellarMapEqualityComparer.Comparer.Equals(map as BaseStellarMap, generatedMap as BaseStellarMap));
        }
コード例 #7
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static bool IsValidChunkPos(IMapStorage map, int cx, int cy, int cz, int chunksize)
 {
     return(cx >= 0 && cy >= 0 && cz >= 0 &&
            cx < map.MapSizeX / chunksize &&
            cy < map.MapSizeY / chunksize &&
            cz < map.MapSizeZ / chunksize);
 }
コード例 #8
0
 /// <summary>
 /// Sets a block at the given position, but only if it is empty.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <param name="blocktype"></param>
 private static void SetBlockIfEmpty(IMapStorage map, int x, int y, int z, int blocktype)
 {
     if (MapUtil.IsValidPos(map, x, y, z) && map.GetBlock(x, y, z) == WorldGeneratorTools.TileIdEmpty)
     {
         map.SetBlock(x, y, z, blocktype);
     }
 }
コード例 #9
0
        /// <summary>
        /// Creates a tree of type #3 at the given location.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="rnd"></param>
        public static void MakeTreeType3(IMapStorage map, int x, int y, int z, Random rnd)
        {
            int treeHeight = rnd.Next(6, 9);
            int xx         = 0;
            int yy         = 0;
            int dir        = 0;

            for (int i = 0; i < treeHeight; i++)
            {
                SetBlock(map, x, y, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                if (i % 3 == 0 && i > 3)
                {
                    for (int j = 1; j < 9; j++)
                    {
                        dir += 45;
                        for (int k = 1; k < 2; k++)
                        {
                            int length = dir % 90 == 0 ? k : (int)(k / 2);
                            xx = length * (int)Math.Round(Math.Cos(dir * Math.PI / 180));
                            yy = length * (int)Math.Round(Math.Sin(dir * Math.PI / 180));

                            SetBlock(map, x + xx, y + yy, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                            SetBlockIfEmpty(map, x + xx, y + yy, z + i + 1, WorldGeneratorTools.TileIdLeaves);

                            SetBlockIfEmpty(map, x + xx + 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx - 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx, y + yy + 1, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx, y + yy - 1, z + i, WorldGeneratorTools.TileIdLeaves);
                        }
                    }
                }
                if (i % 3 == 2 && i > 3)
                {
                    dir = 45;
                    for (int j = 1; j < 9; j++)
                    {
                        dir += 45;
                        for (int k = 1; k < 3; k++)
                        {
                            int length = dir % 90 == 0 ? k : (int)(k / 2);
                            xx = length * (int)Math.Round(Math.Cos(dir * Math.PI / 180));
                            yy = length * (int)Math.Round(Math.Sin(dir * Math.PI / 180));

                            SetBlock(map, x + xx, y + yy, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                            SetBlockIfEmpty(map, x + xx, y + yy, z + i + 1, WorldGeneratorTools.TileIdLeaves);

                            SetBlockIfEmpty(map, x + xx + 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx - 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx, y + yy + 1, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx, y + yy - 1, z + i, WorldGeneratorTools.TileIdLeaves);
                        }
                    }
                }
                SetBlockIfEmpty(map, x, y, z + treeHeight, WorldGeneratorTools.TileIdLeaves);
            }
        }
コード例 #10
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static int SearchColumn(IMapStorage map, int x, int y, int id, int startH)
 {
     for (int h = startH; h > 0; h--)
     {
         if (map.GetBlock(x, y, h) == (byte)id)
         {
             return(h);
         }
     }
     return(-1); // -1 means 'not found'
 }
コード例 #11
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static int blockheight(IMapStorage map, int tileidempty, int x, int y)
 {
     for (int z = map.MapSizeZ - 1; z >= 0; z--)
     {
         if (map.GetBlock(x, y, z) != tileidempty)
         {
             return(z + 1);
         }
     }
     return(map.MapSizeZ / 2);
 }
コード例 #12
0
        public static void JsonRetrieveLocalSector()
        {
            string filename = Path.Combine(dataDir, "LocalSector.json");

            IStellarMap map;
            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.JsonStorage);

            using StreamReader reader = new StreamReader(filename);
            map = store.Retreive <ProgressionMap>(reader);

            Console.WriteLine(map.ToString());
        }
コード例 #13
0
        public static void RetrieveSolarSystem()
        {
            string filename = Path.Combine(dataDir, "SolarSystem.json");

            IStellarMap map;
            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.JsonStorage);

            using StreamReader reader = new StreamReader(filename);
            map = store.Retreive <BaseStellarMap>(reader);

            Console.WriteLine(map.ToString());
        }
コード例 #14
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static bool IsValidPos(IMapStorage map, int x, int y, int z)
 {
     if (x < 0 || y < 0 || z < 0)
     {
         return(false);
     }
     if (x >= map.MapSizeX || y >= map.MapSizeY || z >= map.MapSizeZ)
     {
         return(false);
     }
     return(true);
 }
コード例 #15
0
        public void JsonRetrieveSolarSystem()
        {
            string filename = Path.Combine(TestingUtilities.Config["DataPath"], "LocalSector.json");

            if (!File.Exists(filename))
            {
                JsonStoreLocalSector();
            }

            IStellarMap map;
            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.JsonStorage);

            using StreamReader reader = new StreamReader(filename);
            map = store.Retreive <ProgressionMap>(reader);
        }
コード例 #16
0
 /// <summary>
 /// Populates a chunk using the default Manic Digger chunk generation algorithm.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 public override void PopulateChunk(IMapStorage map, int x, int y, int z)
 {
     x *= this.ChunkSize;
     y *= this.ChunkSize;
     z *= this.ChunkSize;
     if (!EnableBigTrees)
     {
         PopulationTools.MakeSmallTrees(map, x, y, z, this.ChunkSize, _rnd, 30);
     }
     else
     {
         PopulationTools.MakeTrees(map, x, y, z, this.ChunkSize, _rnd);
     }
     PopulationTools.MakeCaves(map, x, y, z, this.ChunkSize, _rnd, this.EnableCaves, gravellength, goldorelength, ironorelength, coalorelength, dirtlength, silverlength);
 }
コード例 #17
0
ファイル: GroundPhysics.cs プロジェクト: henon/manic_digger
        public void BlockChange(IMapStorage map, int x, int y, int z)
        {
            this.map = map;

            if (IsValidDualPos(x, y, z - 1) && (IsSlideDown(x, y, z, data.BlockIdSand) || IsSlideDown(x, y, z, data.BlockIdGravel)))
            {
                BlockMoveDown(x, y, z - 1, 0);
                BlockChange(map, x, y, z - 1);
            }
            else if (IsValidDualPos(x, y, z) && (IsDestroyOfBase(x, y, z, data.BlockIdSand) || IsDestroyOfBase(x, y, z, data.BlockIdGravel)))
            {
                BlockMoveDown(x, y, z, GetDepth(x, y, z));
                BlockChange(map, x, y, z + 1);
            }
        }
コード例 #18
0
        public void BlockChange(IMapStorage map, int x, int y, int z)
        {
            this.map = map;

            if (IsValidDualPos(x, y, z - 1) && (IsSlideDown(x, y, z, data.BlockIdSand) || IsSlideDown(x, y, z, data.BlockIdGravel)))
            {
                BlockMoveDown(x, y, z - 1, 0);
                BlockChange(map, x, y, z - 1);
            }
            else if (IsValidDualPos(x, y, z) && (IsDestroyOfBase(x, y, z, data.BlockIdSand) || IsDestroyOfBase(x, y, z, data.BlockIdGravel)))
            {
                BlockMoveDown(x, y, z, GetDepth(x, y, z));
                BlockChange(map, x, y, z + 1);
            }
        }
コード例 #19
0
ファイル: CoreStorage.cs プロジェクト: ErgodicMage/StellarMap
        public void ZipStoreSolarSystem()
        {
            IStellarMap map = SolarSystem.CreateSolSystem();

            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.ZipStorage);

            string filename = Path.Combine(TestingUtilities.Config["DataPath"], "SolarSystem.zip");

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            using StreamWriter writer = new StreamWriter(filename);
            store.Store(map, writer);
        }
コード例 #20
0
        public static IMapStorage GetStorage(string type)
        {
            IMapStorage storage = null;

            switch (type)
            {
            case JsonStorage:
                storage = new JSonMapStorage();
                break;

            case ZipStorage:
                storage = new ZipMapStorage();
                break;
            }

            return(storage);
        }
コード例 #21
0
        /// <summary>
        /// Creates a tree of type #2 at the given location.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="rnd"></param>
        public static void MakeTreeType2(IMapStorage map, int x, int y, int z, Random rnd)
        {
            int   treeHeight        = rnd.Next(4, 6);
            int   xx                = 0;
            int   yy                = 0;
            int   dir               = 0;
            float chanceToAppleTree = 0.1f;

            for (int i = 0; i < treeHeight; i++)
            {
                SetBlock(map, x, y, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                if (i == treeHeight - 1)
                {
                    for (int j = 1; j < 9; j++)
                    {
                        dir += 45;
                        for (int k = 1; k < 2; k++)
                        {
                            int length = dir % 90 == 0 ? k : (int)(k / 2);
                            xx = length * (int)Math.Round(Math.Cos(dir * Math.PI / 180));
                            yy = length * (int)Math.Round(Math.Sin(dir * Math.PI / 180));

                            SetBlock(map, x + xx, y + yy, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                            if (chanceToAppleTree < rnd.NextDouble())
                            {
                                SetBlockIfEmpty(map, x + xx, y + yy, z + i + 1, WorldGeneratorTools.TileIdLeaves);
                                SetBlockIfEmpty(map, x + xx + 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                                SetBlockIfEmpty(map, x + xx - 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                                SetBlockIfEmpty(map, x + xx, y + yy + 1, z + i, WorldGeneratorTools.TileIdLeaves);
                                SetBlockIfEmpty(map, x + xx, y + yy - 1, z + i, WorldGeneratorTools.TileIdLeaves);
                            }
                            else
                            {
                                float appleChance = 0.4f;
                                int   tile;
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx, y + yy, z + i + 1, tile);
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx + 1, y + yy, z + i, tile);
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx - 1, y + yy, z + i, tile);
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx, y + yy + 1, z + i, tile);
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx, y + yy - 1, z + i, tile);
                            }
                        }
                    }
                }
            }
        }
コード例 #22
0
ファイル: WaterFinite.cs プロジェクト: henon/manic_digger
 void BlockChangeFlood(IMapStorage map, int x, int y, int z)
 {
     //water here
     if (MapUtil.IsValidPos(map, x, y, z)
         && IsWater(map.GetBlock(x, y, z)))
     {
         Flood(new Vector3(x, y, z));
     }
     //water around
     foreach (var vv in BlocksAroundAll(new Vector3(x, y, z)))
     {
         if (MapUtil.IsValidPos(map, (int)vv.X, (int)vv.Y, (int)vv.Z) &&
             IsWater(map.GetBlock((int)vv.X, (int)vv.Y, (int)vv.Z)))
         {
             Flood(vv);
         }
     }
 }
コード例 #23
0
        public static void StoreSolarSystem()
        {
            IStellarMap map = new BaseStellarMap("SolarSystem");

            PhysicalSolarSystemCreator.CreateSolarSystem(map);

            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.JsonStorage);

            string filename = Path.Combine(dataDir, "SolarSystem.json");

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            using StreamWriter writer = new StreamWriter(filename);
            store.Store(map, writer);
        }
コード例 #24
0
ファイル: WaterFinite.cs プロジェクト: henon/manic_digger
 void BlockChangeFlood(IMapStorage map, int x, int y, int z)
 {
     //water here
     if (MapUtil.IsValidPos(map, x, y, z) &&
         IsWater(map.GetBlock(x, y, z)))
     {
         Flood(new Vector3(x, y, z));
     }
     //water around
     foreach (var vv in BlocksAroundAll(new Vector3(x, y, z)))
     {
         if (MapUtil.IsValidPos(map, (int)vv.X, (int)vv.Y, (int)vv.Z) &&
             IsWater(map.GetBlock((int)vv.X, (int)vv.Y, (int)vv.Z)))
         {
             Flood(vv);
         }
     }
 }
コード例 #25
0
        public void PopulateChunk(IMapStorage map, int x, int y, int z)
        {
            x *= this.ChunkSize;
            y *= this.ChunkSize;
            z *= this.ChunkSize;
            //forests
            //if (Math.Abs(treenoise.GetValue(x, 0, y)) >= 0.9)
            double count = treenoise.GetValue(x, 0, y) * 1000;

            {
                count = System.Math.Min(count, 300);
                PopulationTools.MakeSmallTrees(map, x, y, z, this.ChunkSize, _rnd, (int)count);
            }
            //random trees
            PopulationTools.MakeSmallTrees(map, x, y, z, this.ChunkSize, _rnd, treeCount + 10 - (10 - treeCount / 10));

            PopulationTools.MakeCaves(map, x, y, z, this.ChunkSize, _rnd, this.EnableCaves, gravellength, goldorelength, ironorelength, coalorelength, dirtlength, silverlength);
        }
コード例 #26
0
ファイル: CoreStorage.cs プロジェクト: ErgodicMage/StellarMap
        public void JsonRetrieveSolarSystem()
        {
            string filename = Path.Combine(TestingUtilities.Config["DataPath"], "SolarSystem.json");

            if (!File.Exists(filename))
            {
                JsonStoreSolarSystem();
            }

            IStellarMap map;
            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.JsonStorage);

            using StreamReader reader = new StreamReader(filename);
            map = store.Retreive <BaseStellarMap>(reader);

            IStellarMap generatedMap = SolarSystem.CreateSolSystem();

            Assert.IsTrue(BaseStellarMapEqualityComparer.Comparer.Equals(map as BaseStellarMap, generatedMap as BaseStellarMap));
        }
コード例 #27
0
        public static void JsonGenerateLocalSector()
        {
            ProgressionMap localsector = new ProgressionMap("Local Sector");

            LocalSectorMap create = new LocalSectorMap(localsector);

            create.CreateLocalSector();

            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.JsonStorage);

            string filename = Path.Combine(dataDir, "LocalSector.json");

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            using StreamWriter writer = new StreamWriter(filename);
            store.Store(localsector, writer);
        }
コード例 #28
0
        public void ZipStoreLocalSector()
        {
            ProgressionMap localsector = new ProgressionMap("Local Sector");

            LocalSectorMap create = new LocalSectorMap(localsector);

            create.CreateLocalSector();

            IMapStorage store = MapStorageFactory.GetStorage(MapStorageFactory.ZipStorage);

            string filename = Path.Combine(TestingUtilities.Config["DataPath"], "LocalSector.zip");

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            using StreamWriter writer = new StreamWriter(filename);
            store.Store(localsector, writer);
        }
コード例 #29
0
ファイル: Forester.cs プロジェクト: henon/manic_digger
        public static int DistanceToBlock(IMapStorage map, Vector3f coord, Vector3f vec, int blockType, bool invert)
        {
            coord += .5f;
            int iterations = 0;

            while (MapUtil.IsValidPos(map, (int)coord.x, (int)coord.y, (int)coord.h))
            {
                byte blockAtPos = (byte)map.GetBlock((int)coord.x, (int)coord.y, (int)coord.h);
                if ((blockAtPos == (byte)blockType && !invert) ||
                    (blockAtPos != (byte)blockType && invert))
                {
                    break;
                }
                else
                {
                    coord += vec;
                    iterations++;
                }
            }
            return(iterations);
        }
コード例 #30
0
ファイル: WaterFinite.cs プロジェクト: henon/manic_digger
        public void BlockChange(IMapStorage map, int x, int y, int z)
        {
            this.flooded = new Dictionary <Vector3, Vector3>();
            this.map     = map;
            //sponge just built.
            if (MapUtil.IsValidPos(map, x, y, z) && map.GetBlock(x, y, z) == data.BlockIdSponge)
            {
                for (int xx = x - spongerange; xx <= x + spongerange; xx++)
                {
                    for (int yy = y - spongerange; yy <= y + spongerange; yy++)
                    {
                        for (int zz = z - spongerange; zz <= z + spongerange; zz++)
                        {
                            if (MapUtil.IsValidPos(map, xx, yy, zz) && IsWater(map.GetBlock(xx, yy, zz)))
                            {
                                tosetempty.Add(new Vector3(xx, yy, zz));
                            }
                        }
                    }
                }
            }
            //maybe sponge destroyed. todo faster test.
            for (int xx = x - spongerange; xx <= x + spongerange; xx++)
            {
                for (int yy = y - spongerange; yy <= y + spongerange; yy++)
                {
                    for (int zz = z - spongerange; zz <= z + spongerange; zz++)
                    {
                        if (MapUtil.IsValidPos(map, xx, yy, zz) && map.GetBlock(xx, yy, zz) == SpecialBlockId.Empty)
                        {
                            BlockChangeFlood(map, xx, yy, zz);
                        }
                    }
                }
            }
            BlockChangeFlood(map, x, y, z);
            var v = new Vector3(x, y, z);

            tosetwater.Sort((a, b) => (v - a.pos).Length.CompareTo((v - b.pos).Length));
        }
コード例 #31
0
ファイル: WaterSimple.cs プロジェクト: henon/manic_digger
 public void BlockChange(IMapStorage map, int x, int y, int z)
 {
     this.flooded = new Dictionary<Vector3, Vector3>();
     this.map = map;
     //sponge just built.
     if (MapUtil.IsValidPos(map, x, y, z) && map.GetBlock(x, y, z) == data.BlockIdSponge)
     {
         for (int xx = x - spongerange; xx <= x + spongerange; xx++)
         {
             for (int yy = y - spongerange; yy <= y + spongerange; yy++)
             {
                 for (int zz = z - spongerange; zz <= z + spongerange; zz++)
                 {
                     if (MapUtil.IsValidPos(map, xx, yy, zz) && data.IsWater[map.GetBlock(xx, yy, zz)])
                     {
                         tosetempty.Add(new Vector3(xx, yy, zz));
                     }
                 }
             }
         }
     }
     //maybe sponge destroyed. todo faster test.
     for (int xx = x - spongerange; xx <= x + spongerange; xx++)
     {
         for (int yy = y - spongerange; yy <= y + spongerange; yy++)
         {
             for (int zz = z - spongerange; zz <= z + spongerange; zz++)
             {
                 if (MapUtil.IsValidPos(map, xx, yy, zz) && map.GetBlock(xx, yy, zz) == 0)
                 {
                     BlockChangeFlood(map, xx, yy, zz);
                 }
             }
         }
     }
     BlockChangeFlood(map, x, y, z);
     var v = new Vector3(x, y, z);
     tosetwater.Sort((a, b) => (v - a).Length.CompareTo((v - b).Length));
 }
コード例 #32
0
        /// <summary>
        /// Creates some trees all over the chunk.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="chunksize"></param>
        /// <param name="rnd"></param>
        public static void MakeTrees(IMapStorage map, int x, int y, int z, int chunksize, Random rnd)
        {
            if (z != 0)
            {
                return;
            }
            //if (rnd.Next(100) > 30) { return; }
            var foresterArgs = new fCraft.Forester.ForesterArgs();

            if (rnd.Next(100) < 15)
            {
                foresterArgs.SHAPE = fCraft.Forester.TreeShape.Procedural;
            }
            else
            {
                foresterArgs.SHAPE     = (fCraft.Forester.TreeShape)rnd.Next(9);
                foresterArgs.HEIGHT    = rnd.Next(5, 10);
                foresterArgs.TREECOUNT = 3;
            }
            fCraft.Forester forester = new fCraft.Forester(foresterArgs);
            foresterArgs.inMap  = map;
            foresterArgs.outMap = map;
            forester.Generate(x, y, z, chunksize);
        }
コード例 #33
0
ファイル: Forester.cs プロジェクト: henon/manic_digger
 public static int DistanceToBlock(IMapStorage map, Vector3f coord, Vector3f vec, int blockType, bool invert)
 {
     coord += .5f;
     int iterations = 0;
     while (MapUtil.IsValidPos(map, (int)coord.x, (int)coord.y, (int)coord.h))
     {
         byte blockAtPos = (byte)map.GetBlock((int)coord.x, (int)coord.y, (int)coord.h);
         if ((blockAtPos == (byte)blockType && !invert) ||
             (blockAtPos != (byte)blockType && invert))
         {
             break;
         }
         else
         {
             coord += vec;
             iterations++;
         }
     }
     return iterations;
 }
コード例 #34
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static bool IsValidPos(IMapStorage map, int x, int y, int z)
 {
     if (x < 0 || y < 0 || z < 0)
     {
         return false;
     }
     if (x >= map.MapSizeX || y >= map.MapSizeY || z >= map.MapSizeZ)
     {
         return false;
     }
     return true;
 }
コード例 #35
0
ファイル: Forester.cs プロジェクト: henon/manic_digger
 public static int DistanceToBlock(IMapStorage map, Vector3f coord, Vector3f vec, int blockType)
 {
     return DistanceToBlock(map, coord, vec, blockType, false);
 }
コード例 #36
0
 public void PopulateChunk(IMapStorage map, int x, int y, int z, int chunksize)
 {
 }
コード例 #37
0
 public byte[] SaveMap(IMapStorage map)
 {
     return GzipCompression.Compress(SaveXml(map));
 }
コード例 #38
0
 public void SaveMap(IMapStorage map, string filename)
 {
     //using (FileStream s = File.OpenWrite("default.minesave"))
     /*
     MemoryStream s = new MemoryStream();
     {
         BinaryWriter bw = new BinaryWriter(s);
         bw.Write((int)0);//format version
         bw.Write((int)MapSizeZ);
         bw.Write((int)MapSizeX);
         bw.Write((int)MapSizeY);
         for (int z = 0; z < MapSizeZ; z++)
         {
             for (int y = 0; y < MapSizeY; y++)
             {
                 for (int x = 0; x < MapSizeX; x++)
                 {
                     bw.Write((byte)map[x, y, z]);
                 }
             }
         }
     }
     File.WriteAllBytes("default.minesave", GzipCompression.Compress(s.ToArray()));
     */
     File.WriteAllBytes(filename, GzipCompression.Compress(SaveXml(map)));
     Console.WriteLine("Game saved successfully.");
 }
コード例 #39
0
    public void PopulateChunk(IMapStorage map, int x, int y, int z, int chunksize)
    {
        x *= chunksize;
            y *= chunksize;
            z *= chunksize;
            //if (rnd.NextDouble() >= 0.6)
            {
                //return;
            }

            //find cave start
            double curx = x;
            double cury = y;
            double curz = z;
            for (int i = 0; i < 10; i++)
            {
                curx = x + rnd.Next(chunksize);
                cury = y + rnd.Next(chunksize);
                curz = z + rnd.Next(chunksize);
                if (map.GetBlock((int)curx, (int)cury, (int)curz) == TileIdStone)
                {
                    goto ok;
                }
            }
            return;
        ok:
            int blocktype = TileIdEmpty;
            int length = 200;
            if (rnd.NextDouble() < 0.5)
            {
                int oretype = rnd.Next(3);
                if (oretype == 0) { length = goldorelength; }
                if (oretype == 1) { length = ironorelength; }
                if (oretype == 2) { length = coalorelength; }
                length = rnd.Next(length);
                blocktype = TileIdGoldOre + oretype;
            }
            //map.SetBlock(x, y, z, TileIdLava);
            int dirx = rnd.NextDouble() < 0.5 ? -1 : 1;
            int dirz = rnd.NextDouble() < 0.5 ? -1 : 1;
            double curspeedx = rnd.NextDouble() * dirx;
            double curspeedy = rnd.NextDouble();
            double curspeedz = rnd.NextDouble() * 0.5 * dirz;
            for (int i = 0; i < length; i++)
            {
                if (rnd.NextDouble() < 0.05)
                {
                    curspeedx = rnd.NextDouble() * dirx;
                }
                if (rnd.NextDouble() < 0.05)
                {
                    curspeedy = rnd.NextDouble();
                }
                if (rnd.NextDouble() < 0.02)
                {
                    curspeedz = rnd.NextDouble() * 0.5 * dirz;
                }
                curx += curspeedx;
                cury += curspeedy;
                curz += curspeedz;
                if (!MapUtil.IsValidPos(map, (int)curx, (int)cury, (int)curz))
                {
                    continue;
                }
                for (int ii = 0; ii < 3; ii++)
                {
                    int sizex = rnd.Next(3, 5);
                    int sizey = rnd.Next(3, 5);
                    int sizez = rnd.Next(3, 5);
                    int dx = rnd.Next(-sizex / 1, sizex / 1);
                    int dy = rnd.Next(-sizey / 1, sizey / 1);
                    int dz = rnd.Next(-sizez / 2, sizez / 2);
                    int[] allowin = blocktype == TileIdEmpty
                        ? new int[] { TileIdStone, TileIdDirt, TileIdGrass, TileIdGoldOre, TileIdIronOre, TileIdCoalOre }
                        : new int[] { TileIdStone };
                    double density = blocktype == TileIdEmpty ? 1 : rnd.NextDouble() * 0.4;
                    MakeCuboid(map, (int)curx - sizex / 2 + dx, (int)cury - sizey / 2 + dy, (int)curz - sizez / 2 + dz, sizex, sizey, sizez, blocktype, allowin, density);
                }
            }
    }
コード例 #40
0
ファイル: PopulationTools.cs プロジェクト: henon/manic_digger
 /// <summary>
 /// Sets a block at the given position.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <param name="blocktype"></param>
 private static void SetBlock(IMapStorage map, int x, int y, int z, int blocktype)
 {
     if (MapUtil.IsValidPos(map, x, y, z))
     {
         map.SetBlock(x, y, z, blocktype);
     }
 }
コード例 #41
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static bool IsValidChunkPos(IMapStorage map, int cx, int cy, int cz, int chunksize)
 {
     return cx >= 0 && cy >= 0 && cz >= 0
         && cx < map.MapSizeX / chunksize
         && cy < map.MapSizeY / chunksize
         && cz < map.MapSizeZ / chunksize;
 }
コード例 #42
0
ファイル: PopulationTools.cs プロジェクト: henon/manic_digger
        /// <summary>
        /// Creates a tree of type #3 at the given location.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="rnd"></param>
        public static void MakeTreeType3(IMapStorage map, int x, int y, int z, Random rnd)
        {
            int treeHeight = rnd.Next(6, 9);
            int xx = 0;
            int yy = 0;
            int dir = 0;
            for (int i = 0; i < treeHeight; i++)
            {
                SetBlock(map, x, y, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                if (i % 3 == 0 && i > 3)
                {
                    for (int j = 1; j < 9; j++)
                    {
                        dir += 45;
                        for (int k = 1; k < 2; k++)
                        {
                            int length = dir % 90 == 0 ? k : (int)(k / 2);
                            xx = length * (int)Math.Round(Math.Cos(dir * Math.PI / 180));
                            yy = length * (int)Math.Round(Math.Sin(dir * Math.PI / 180));

                            SetBlock(map, x + xx, y + yy, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                            SetBlockIfEmpty(map, x + xx, y + yy, z + i + 1, WorldGeneratorTools.TileIdLeaves);

                            SetBlockIfEmpty(map, x + xx + 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx - 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx, y + yy + 1, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx, y + yy - 1, z + i, WorldGeneratorTools.TileIdLeaves);
                        }
                    }
                }
                if (i % 3 == 2 && i > 3)
                {
                    dir = 45;
                    for (int j = 1; j < 9; j++)
                    {
                        dir += 45;
                        for (int k = 1; k < 3; k++)
                        {
                            int length = dir % 90 == 0 ? k : (int)(k / 2);
                            xx = length * (int)Math.Round(Math.Cos(dir * Math.PI / 180));
                            yy = length * (int)Math.Round(Math.Sin(dir * Math.PI / 180));

                            SetBlock(map, x + xx, y + yy, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                            SetBlockIfEmpty(map, x + xx, y + yy, z + i + 1, WorldGeneratorTools.TileIdLeaves);

                            SetBlockIfEmpty(map, x + xx + 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx - 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx, y + yy + 1, z + i, WorldGeneratorTools.TileIdLeaves);
                            SetBlockIfEmpty(map, x + xx, y + yy - 1, z + i, WorldGeneratorTools.TileIdLeaves);
                        }
                    }
                }
                SetBlockIfEmpty(map, x, y, z + treeHeight, WorldGeneratorTools.TileIdLeaves);
            }
        }
コード例 #43
0
ファイル: PopulationTools.cs プロジェクト: henon/manic_digger
        /// <summary>
        /// Creates caves all over the chunk.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="chunksize"></param>
        /// <param name="rnd"></param>
        /// <param name="enableCaves"></param>
        /// <param name="gravelLength"></param>
        /// <param name="goldOreLength"></param>
        /// <param name="ironOreLength"></param>
        /// <param name="coalOreLength"></param>
        /// <param name="dirtOreLength"></param>
        public static void MakeCaves(IMapStorage map, int x, int y, int z, int chunksize, Random rnd,
            bool enableCaves,
            int gravelLength,
            int goldOreLength,
            int ironOreLength,
            int coalOreLength,
            int dirtOreLength,
            int silverOreLength)
        {
            //if (rnd.NextDouble() >= 0.6)
            {
                //return;
            }

            //find cave start
            double curx = x;
            double cury = y;
            double curz = z;
            for (int i = 0; i < 2; i++)
            {
                curx = x + rnd.Next(chunksize);
                cury = y + rnd.Next(chunksize);
                curz = z + rnd.Next(chunksize);
                if (map.GetBlock((int)curx, (int)cury, (int)curz) == WorldGeneratorTools.TileIdStone)
                {
                    goto ok;
                }
            }
            return;
            ok:
            int blocktype = WorldGeneratorTools.TileIdEmpty;
            int length = 200;
            if (rnd.NextDouble() < 0.85)
            {
                int oretype = rnd.Next(6);
                if (oretype == 0) { length = gravelLength; }
                if (oretype == 1) { length = goldOreLength; }
                if (oretype == 2) { length = ironOreLength; }
                if (oretype == 3) { length = coalOreLength; }
                if (oretype == 4) { length = dirtOreLength; }
                if (oretype == 5) { length = silverOreLength; }

                length = rnd.Next(length);
                blocktype = oretype < 4 ? WorldGeneratorTools.TileIdGravel + oretype : (oretype > 4 ? WorldGeneratorTools.TileIdGravel + oretype + 115 : WorldGeneratorTools.TileIdDirt);
            }
            if (blocktype == WorldGeneratorTools.TileIdEmpty && (!enableCaves))
            {
                return;
            }
            //map.SetBlock(x, y, z, WorldGeneratorTools.TileIdLava);
            int dirx = rnd.NextDouble() < 0.5 ? -1 : 1;
            int dirz = rnd.NextDouble() < 0.5 ? -1 : 1;
            double curspeedx = rnd.NextDouble() * dirx;
            double curspeedy = rnd.NextDouble();
            double curspeedz = rnd.NextDouble() * 0.5 * dirz;
            for (int i = 0; i < length; i++)
            {
                if (rnd.NextDouble() < 0.06)
                {
                    curspeedx = rnd.NextDouble() * dirx;
                }
                if (rnd.NextDouble() < 0.06)
                {
                    curspeedy = rnd.NextDouble() * dirx;
                }
                if (rnd.NextDouble() < 0.02)
                {
                    curspeedz = rnd.NextDouble() * 0.5 * dirz;
                }
                curx += curspeedx;
                cury += curspeedy;
                curz += curspeedz;
                if (!MapUtil.IsValidPos(map, (int)curx, (int)cury, (int)curz))
                {
                    continue;
                }
                for (int ii = 0; ii < 3; ii++)
                {
                    int sizex = rnd.Next(3, 6);
                    int sizey = rnd.Next(3, 6);
                    int sizez = rnd.Next(2, 3);
                    int dx = rnd.Next(-sizex / 2, sizex / 2);
                    int dy = rnd.Next(-sizey / 2, sizey / 2);
                    int dz = rnd.Next(-sizez / 1, sizez / 1);

                    int[] allowin = new int[] { WorldGeneratorTools.TileIdStone };
                    double density = blocktype == WorldGeneratorTools.TileIdEmpty ? 1 : rnd.NextDouble() * 0.90;
                    if (blocktype == WorldGeneratorTools.TileIdEmpty)
                    {
                        allowin = new int[] {
                            WorldGeneratorTools.TileIdStone,
                            WorldGeneratorTools.TileIdDirt,
                            WorldGeneratorTools.TileIdGrass,
                            WorldGeneratorTools.TileIdGoldOre,
                            WorldGeneratorTools.TileIdIronOre,
                            WorldGeneratorTools.TileIdCoalOre,
                            WorldGeneratorTools.TileIdSilverOre
                        };
                    }
                    if (blocktype == WorldGeneratorTools.TileIdGravel)
                    {
                        density = 1;
                        allowin = new int[] {
                            WorldGeneratorTools.TileIdDirt,
                            WorldGeneratorTools.TileIdStone,
                            WorldGeneratorTools.TileIdSand,
                            WorldGeneratorTools.TileIdGoldOre,
                            WorldGeneratorTools.TileIdIronOre,
                            WorldGeneratorTools.TileIdCoalOre,
                            WorldGeneratorTools.TileIdSilverOre
                        };
                    }

                    MakeCuboid(map, (int)curx - sizex / 2 + dx, (int)cury - sizey / 2 + dy, (int)curz - sizez / 2 + dz, sizex, sizey, sizez, blocktype, allowin, density, rnd);
                }
            }
        }
コード例 #44
0
ファイル: PopulationTools.cs プロジェクト: henon/manic_digger
        /// <summary>
        /// Creates a tree of type #2 at the given location.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="rnd"></param>
        public static void MakeTreeType2(IMapStorage map, int x, int y, int z, Random rnd)
        {
            int treeHeight = rnd.Next(4, 6);
            int xx = 0;
            int yy = 0;
            int dir = 0;
            float chanceToAppleTree = 0.1f;
            for (int i = 0; i < treeHeight; i++)
            {
                SetBlock(map, x, y, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                if (i == treeHeight - 1)
                {
                    for (int j = 1; j < 9; j++)
                    {
                        dir += 45;
                        for (int k = 1; k < 2; k++)
                        {
                            int length = dir % 90 == 0 ? k : (int)(k / 2);
                            xx = length * (int)Math.Round(Math.Cos(dir * Math.PI / 180));
                            yy = length * (int)Math.Round(Math.Sin(dir * Math.PI / 180));

                            SetBlock(map, x + xx, y + yy, z + i, WorldGeneratorTools.TileIdTreeTrunk);
                            if (chanceToAppleTree < rnd.NextDouble())
                            {
                                SetBlockIfEmpty(map, x + xx, y + yy, z + i + 1, WorldGeneratorTools.TileIdLeaves);
                                SetBlockIfEmpty(map, x + xx + 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                                SetBlockIfEmpty(map, x + xx - 1, y + yy, z + i, WorldGeneratorTools.TileIdLeaves);
                                SetBlockIfEmpty(map, x + xx, y + yy + 1, z + i, WorldGeneratorTools.TileIdLeaves);
                                SetBlockIfEmpty(map, x + xx, y + yy - 1, z + i, WorldGeneratorTools.TileIdLeaves);
                            }
                            else
                            {
                                float appleChance = 0.4f;
                                int tile;
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx, y + yy, z + i + 1, tile);
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx + 1, y + yy, z + i, tile);
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx - 1, y + yy, z + i, tile);
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx, y + yy + 1, z + i, tile);
                                tile = rnd.NextDouble() < appleChance ? WorldGeneratorTools.TileIdApples : WorldGeneratorTools.TileIdLeaves; SetBlockIfEmpty(map, x + xx, y + yy - 1, z + i, tile);
                            }
                        }
                    }
                }
            }
        }
コード例 #45
0
ファイル: PopulationTools.cs プロジェクト: henon/manic_digger
 /// <summary>
 /// Creates some trees all over the chunk.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <param name="chunksize"></param>
 /// <param name="rnd"></param>
 public static void MakeTrees(IMapStorage map, int x, int y, int z, int chunksize, Random rnd)
 {
     if (z != 0) { return; }
     //if (rnd.Next(100) > 30) { return; }
     var foresterArgs = new fCraft.Forester.ForesterArgs();
     if (rnd.Next(100) < 15)
     {
         foresterArgs.SHAPE = fCraft.Forester.TreeShape.Procedural;
     }
     else
     {
         foresterArgs.SHAPE = (fCraft.Forester.TreeShape)rnd.Next(9);
         foresterArgs.HEIGHT = rnd.Next(5, 10);
         foresterArgs.TREECOUNT = 3;
     }
     fCraft.Forester forester = new fCraft.Forester(foresterArgs);
     foresterArgs.inMap = map;
     foresterArgs.outMap = map;
     forester.Generate(x, y, z, chunksize);
 }
コード例 #46
0
ファイル: PopulationTools.cs プロジェクト: henon/manic_digger
 public static void MakeSmallTrees(IMapStorage map, int cx, int cy, int cz, int chunksize, Random rnd, int count)
 {
     int chooseTreeType;
     for (int i = 0; i < count; i++)
     {
         int x = cx + rnd.Next(chunksize);
         int y = cy + rnd.Next(chunksize);
         int z = cz + rnd.Next(chunksize);
         if (!MapUtil.IsValidPos(map, x, y, z) || map.GetBlock(x, y, z) != WorldGeneratorTools.TileIdGrass)
         {
             continue;
         }
         chooseTreeType = rnd.Next(0, 3);
         switch (chooseTreeType)
         {
             case 0: MakeTreeType1(map, x, y, z, rnd); break;
             case 1: MakeTreeType2(map, x, y, z, rnd); break;
             case 2: MakeTreeType3(map, x, y, z, rnd); break;
         };
     }
 }
コード例 #47
0
 /// <summary>
 /// Populates a chunk using the default Manic Digger chunk generation algorithm.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 public override void PopulateChunk(IMapStorage map, int x, int y, int z)
 {
     x *= this.ChunkSize;
     y *= this.ChunkSize;
     z *= this.ChunkSize;
     if (!EnableBigTrees)
     {
         PopulationTools.MakeSmallTrees(map, x, y, z, this.ChunkSize, _rnd, 30);
     }
     else
     {
         PopulationTools.MakeTrees(map, x, y, z, this.ChunkSize, _rnd);
     }
     PopulationTools.MakeCaves(map, x, y, z, this.ChunkSize, _rnd, this.EnableCaves, gravellength, goldorelength, ironorelength, coalorelength, dirtlength, silverlength);
 }
コード例 #48
0
 public void LoadMapArray(IMapStorage map, Stream s)
 {
     BinaryReader br = new BinaryReader(s);
     map.UseMap(new byte[map.MapSizeX, map.MapSizeY, map.MapSizeZ]);
     for (int z = 0; z < map.MapSizeZ; z++)
     {
         for (int y = 0; y < map.MapSizeY; y++)
         {
             for (int x = 0; x < map.MapSizeX; x++)
             {
                 map.SetBlock(x, y, z, br.ReadByte());
             }
         }
     }
     //.gui.DrawMap();
     Console.WriteLine("Game loaded successfully.");
 }
コード例 #49
0
ファイル: PopulationTools.cs プロジェクト: henon/manic_digger
 /// <summary>
 /// Sets a block at the given position, but only if it is empty.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <param name="blocktype"></param>
 private static void SetBlockIfEmpty(IMapStorage map, int x, int y, int z, int blocktype)
 {
     if (MapUtil.IsValidPos(map, x, y, z) && map.GetBlock(x, y, z) == WorldGeneratorTools.TileIdEmpty)
     {
         map.SetBlock(x, y, z, blocktype);
     }
 }
コード例 #50
0
 public void LoadMapMinecraft(IMapStorage map, string filename)
 {
     byte[] serialized = GzipCompression.Decompress(new FileInfo(getfile.GetFile(filename)));
     fCraft.MapLoaderDAT maploaderdat = new fCraft.MapLoaderDAT();
     fCraft.IFMap mymap = new MyFCraftMap() { map = map };
     maploaderdat.log = new fCraft.FLogDummy();
     maploaderdat.Load(filename, mymap);
 }
コード例 #51
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static int blockheight(IMapStorage map, int tileidempty, int x, int y)
 {
     for (int z = map.MapSizeZ - 1; z >= 0; z--)
     {
         if (map.GetBlock(x, y, z) != tileidempty)
         {
             return z + 1;
         }
     }
     return map.MapSizeZ / 2;
 }
コード例 #52
0
 byte[] SaveXml(IMapStorage map)
 {
     StringBuilder b = new StringBuilder();
     b.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
     b.AppendLine("<ManicDiggerSave>");
     b.AppendLine(XmlTool.X("FormatVersion", "1"));
     b.AppendLine("<MapSize>");
     b.AppendLine(XmlTool.X("X", "" + map.MapSizeX));
     b.AppendLine(XmlTool.X("Y", "" + map.MapSizeY));
     b.AppendLine(XmlTool.X("Z", "" + map.MapSizeZ));
     b.AppendLine("</MapSize>");
     MemoryStream mapdata = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(mapdata);
     for (int z = 0; z < map.MapSizeZ; z++)
     {
         for (int y = 0; y < map.MapSizeY; y++)
         {
             for (int x = 0; x < map.MapSizeX; x++)
             {
                 bw.Write((byte)map.GetBlock(x, y, z));
             }
         }
     }
     b.AppendLine(XmlTool.X("MapData", Convert.ToBase64String(mapdata.ToArray())));
     //b.AppendLine(X("DefaultSpawn", ));
     b.AppendLine("</ManicDiggerSave>");
     /*
     <ManicDiggerSave>
       <SaveFormat>1</SaveFormat>
       <MapSize>
     <X>256</X>
     <Y>256</Y>
     <Z>64</Z>
       </MapSize>
       <MapData>BASE64</MapData>
       <Players>
     <Player>
       <Id>0</Id>
       <SpawnPoint>
         <X>5</X>
         <Y>5</Y>
         <Z>40</Z>
       </SpawnPoint>
     </Player>
       </Players>
     </ManicDiggerSave>
     */
     return Encoding.UTF8.GetBytes(b.ToString());
 }
コード例 #53
0
 /// <summary>
 /// Populates the chunk at the given position.
 /// </summary>
 /// <param name="map">The <see cref="IMapStorage"/> instance containing the map.</param>
 /// <param name="x">The x-position of the chunk to populate.</param>
 /// <param name="y">The y-position of the chunk to populate.</param>
 /// <param name="z">The z-position of the chunk to populate.</param>
 public override void PopulateChunk(IMapStorage map, int x, int y, int z)
 {
     this.UpdateValues();
     _default.PopulateChunk(map, x, y, z);
 }
コード例 #54
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static int SearchColumn(IMapStorage map, int x, int y, int id)
 {
     return SearchColumn(map, x, y, id, map.MapSizeZ - 1);
 }
コード例 #55
0
 void MakeCuboid(IMapStorage map, int x, int y, int z, int sizex, int sizey, int sizez, int blocktype, int[] allowin, double chance)
 {
     for (int xx = 0; xx < sizex; xx++)
         {
             for (int yy = 0; yy < sizey; yy++)
             {
                 for (int zz = 0; zz < sizez; zz++)
                 {
                     if (MapUtil.IsValidPos(map, x + xx, y + yy, z + zz))
                     {
                         int t = map.GetBlock(x + xx, y + yy, z + zz);
                         if (allowin == null) { goto ok; }
                         foreach (int tt in allowin)
                         {
                             if (tt == t) { goto ok; }
                         }
                         continue;
                     ok:
                         if (rnd.NextDouble() < chance)
                         {
                             map.SetBlock(x + xx, y + yy, z + zz, blocktype);
                         }
                     }
                 }
             }
         }
 }
コード例 #56
0
ファイル: ManicDigger.cs プロジェクト: henon/manic_digger
 public static int SearchColumn(IMapStorage map, int x, int y, int id, int startH)
 {
     for (int h = startH; h > 0; h--)
     {
         if (map.GetBlock(x, y, h) == (byte)id)
         {
             return h;
         }
     }
     return -1; // -1 means 'not found'
 }
コード例 #57
0
ファイル: PopulationTools.cs プロジェクト: henon/manic_digger
        /// <summary>
        /// Creates some flowers all over the chunk.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="cz"></param>
        /// <param name="chunksize"></param>
        /// <param name="rnd"></param>
        public static void MakeFlowers(IMapStorage map, int cx, int cy, int cz, int chunksize, Random rnd)
        {
            for (int i = 0; i < 5; i++)
            {
                int x = cx + rnd.Next(chunksize);
                int y = cy + rnd.Next(chunksize);
                int z = cz + rnd.Next(chunksize);
                if (!MapUtil.IsValidPos(map, x, y, z) || map.GetBlock(x, y, z) != WorldGeneratorTools.TileIdGrass)
                {
                    continue;
                }
                int xx; int yy; int zz;
                int tile = rnd.NextDouble() < 0.75 ? WorldGeneratorTools.TileIdYellowFlower : WorldGeneratorTools.TileIdRedFlower;
                int count = rnd.Next(50, 80);
                for (int j = 0; j < count; j++)
                {
                    xx = x + rnd.Next(-6, 6);
                    yy = y + rnd.Next(-6, 6);
                    zz = z + rnd.Next(-2, 2);
                    if (!MapUtil.IsValidPos(map, xx, yy, zz) || map.GetBlock(xx, yy, zz) != WorldGeneratorTools.TileIdGrass)
                    {
                        continue;
                    }

                    // set the block
                    SetBlock(map, x, y, z, tile);
                }
            }
        }
コード例 #58
0
 public void LoadMap(IMapStorage map, byte[] data)
 {
     using (Stream s = new MemoryStream(GzipCompression.Decompress(data)))
     {
         StreamReader sr = new StreamReader(s);
         XmlDocument d = new XmlDocument();
         d.Load(sr);
         int format = int.Parse(XmlTool.XmlVal(d, "/ManicDiggerSave/FormatVersion"));
         if (format != 1)
         {
             throw new Exception("Invalid map format");
         }
         map.MapSizeX = int.Parse(XmlTool.XmlVal(d, "/ManicDiggerSave/MapSize/X"));
         map.MapSizeY = int.Parse(XmlTool.XmlVal(d, "/ManicDiggerSave/MapSize/Y"));
         map.MapSizeZ = int.Parse(XmlTool.XmlVal(d, "/ManicDiggerSave/MapSize/Z"));
         byte[] mapdata = Convert.FromBase64String(XmlTool.XmlVal(d, "/ManicDiggerSave/MapData"));
         LoadMapArray(map, new MemoryStream(mapdata));
     }
 }
コード例 #59
0
 public StateMachineBuilder UsingMapStorage(IMapStorage mapStorage)
 {
     StorageHelper.Storage = mapStorage;
     return(this);
 }
コード例 #60
0
 public void LoadMap(IMapStorage map, string filename)
 {
     if ((!File.Exists(filename)) && File.Exists(filename + MinecraftMapSaveExtension))
     {
         filename += MinecraftMapSaveExtension;
     }
     if ((!File.Exists(filename)) && File.Exists(filename + XmlSaveExtension))
     {
         filename += XmlSaveExtension;
     }
     if (!File.Exists(filename))
     {
         Console.WriteLine(filename + " not found.");
     }
     if (filename.EndsWith(MinecraftMapSaveExtension))
     {
         //minecraft map
         LoadMapMinecraft(map, filename);
         return;
     }
     LoadMap(map, File.ReadAllBytes(filename));
 }