Пример #1
0
        public static void ResetLighting(BetaWorld world, ChunkManager cm, frmMace frmLogForm, int intTotalChunks)
        {
            int intChunksProcessed = 0;

            //this code is based on a substrate example
            //http://code.google.com/p/substrate-minecraft/source/browse/trunk/Substrate/SubstrateCS/Examples/Relight/Program.cs
            //see the <License Substrate.txt> file for copyright information
            foreach (ChunkRef chunk in cm)
            {
                try
                {
                    chunk.Blocks.RebuildHeightMap();
                    chunk.Blocks.ResetBlockLight();
                    chunk.Blocks.ResetSkyLight();
                    chunk.Blocks.RebuildBlockLight();
                    chunk.Blocks.RebuildSkyLight();
                    cm.Save();
                    intChunksProcessed++;
                    if (intChunksProcessed % 10 == 0)
                    {
                        frmLogForm.UpdateProgress(62 + ((intChunksProcessed * (100 - 62)) / intTotalChunks));
                        world.Save();
                    }
                }
                catch (Exception)
                {
                    Debug.WriteLine("Chunk light fail");
                }
            }
            cm.Save();
            world.Save();
        }
Пример #2
0
        public static void ResetLighting(ChunkManager cm, frmMace frmLogForm, int intTotalChunks)
        {
            int intChunksProcessed = 0;

            // this code is based on a substrate example
            // http://code.google.com/p/substrate-minecraft/source/browse/trunk/Substrate/SubstrateCS/Examples/Relight/Program.cs
            // see the <License Substrate.txt> file for copyright information
            foreach (ChunkRef chunk in cm)
            {
                chunk.Blocks.RebuildHeightMap();
                chunk.Blocks.ResetBlockLight();
                chunk.Blocks.ResetSkyLight();
                cm.Save();
                intChunksProcessed++;
                if (intChunksProcessed % 25 == 0)
                {
                    frmLogForm.UpdateProgress(42 + ((intChunksProcessed * 20) / intTotalChunks));
                }
            }
            intChunksProcessed = 0;
            foreach (ChunkRef chunk in cm)
            {
                chunk.Blocks.RebuildBlockLight();
                chunk.Blocks.RebuildSkyLight();
                cm.Save();
                intChunksProcessed++;
                if (intChunksProcessed % 15 == 0)
                {
                    frmLogForm.UpdateProgress(62 + ((intChunksProcessed * 38) / intTotalChunks));
                }
            }
        }
Пример #3
0
        public static void CropMaceWorld(frmMace frmLogForm)
        {
            // thank you to Surrogard <*****@*****.**> for providing a linux friendly version of this code:
            Directory.CreateDirectory("macecopy".ToMinecraftSaveDirectory());
            BetaWorld        bwCopy = BetaWorld.Create("macecopy".ToMinecraftSaveDirectory());
            BetaChunkManager cmCopy = bwCopy.GetChunkManager();
            BetaWorld        bwCrop = BetaWorld.Open("macemaster".ToMinecraftSaveDirectory());
            BetaChunkManager cmCrop = bwCrop.GetChunkManager();

            foreach (ChunkRef chunk in cmCrop)
            {
                if (chunk.X >= -7 && chunk.X <= 11 && chunk.Z >= 0 && chunk.Z <= 11)
                {
                    Debug.WriteLine("Copying chunk " + chunk.X + "," + chunk.Z);
                    cmCopy.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef());
                }
                cmCopy.Save();
            }
            bwCopy.Level.GameType = GameType.CREATIVE;
            cmCopy.Save();
            bwCopy.Save();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                Process.Start("explorer.exe", @"/select," + "macecopy".ToMinecraftSaveDirectory() + "\\level.dat");
            }
        }
Пример #4
0
        public static void ResetLighting(BetaWorld world, BetaChunkManager cm, frmMace frmLogForm)
        {
            int intChunksChecked   = 0;
            int intChunksProcessed = 0;
            // we process each chunk twice, hence this:
            int intTotalChunks = 0;

            //this code is based on a substrate example
            //http://code.google.com/p/substrate-minecraft/source/browse/trunk/Substrate/SubstrateCS/Examples/Relight/Program.cs
            //see the <License Substrate.txt> file for copyright information
            foreach (ChunkRef chunk in cm)
            {
                intTotalChunks += 2;
            }
            foreach (ChunkRef chunk in cm)
            {
                if (chunk.IsTerrainPopulated)
                {
                    intChunksChecked++;
                    try
                    {
                        chunk.Blocks.RebuildHeightMap();
                        chunk.Blocks.ResetBlockLight();
                        chunk.Blocks.ResetSkyLight();
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Chunk reset light fail");
                    }
                }
                if (++intChunksProcessed % 10 == 0)
                {
                    cm.Save();
                    frmLogForm.UpdateProgress(intChunksProcessed * 0.95 / intTotalChunks);
                }
            }
            foreach (ChunkRef chunk in cm)
            {
                if (chunk.IsTerrainPopulated)
                {
                    try
                    {
                        chunk.Blocks.RebuildBlockLight();
                        chunk.Blocks.RebuildSkyLight();
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Chunk rebuild light fail");
                    }
                }
                if (++intChunksProcessed % 10 == 0)
                {
                    cm.Save();
                    frmLogForm.UpdateProgress(intChunksProcessed * 0.95 / intTotalChunks);
                }
            }
            world.Save();
        }
Пример #5
0
 private static bool CheckCancelled(AnvilWorld worldDest, frmMace frmLogForm)
 {
     if (City.stop)
     {
         worldDest.Level.LevelName = "Generation cancelled. Please delete me.";
         worldDest.Save();
         return(true);
     }
     return(false);
 }
Пример #6
0
 public static void MakeChunks(ChunkManager cm, int intStart, int intEnd, frmMace frmLogForm)
 {
     for (int xi = intStart; xi < intEnd; xi++)
     {
         for (int zi = intStart; zi < intEnd; zi++)
         {
             ChunkRef chunkOriginal = cm.CreateChunk(xi, zi);
             chunkOriginal.IsTerrainPopulated = true;
             chunkOriginal.Blocks.AutoLight   = false;
             FlatChunk(chunkOriginal);
             cm.Save();
         }
         frmLogForm.UpdateProgress((1 + xi) * 34 / (intEnd - intStart));
     }
 }
Пример #7
0
 public static void MakeChunks(ChunkManager cm, int intEnd, frmMace frmLogForm)
 {
     int[, ,] intUndergroundTerrain = MakeUndergroundTerrain(intEnd * 16, 64, intEnd * 16);
     for (int xi = 0; xi < intEnd; xi++)
     {
         for (int zi = 0; zi < intEnd; zi++)
         {
             ChunkRef chunkActive = cm.CreateChunk(xi, zi);
             chunkActive.IsTerrainPopulated = true;
             chunkActive.Blocks.AutoLight   = false;
             FlatChunk(chunkActive, intUndergroundTerrain);
             cm.Save();
         }
         frmLogForm.UpdateProgress((1 + xi) * 24 / intEnd);
     }
     cm.Save();
 }
Пример #8
0
 public static void CreateInitialChunks(RegionChunkManager cm, frmMace frmLogForm, string strUndergroundOres)
 {
     int[, ,] intUndergroundTerrain = MakeUndergroundTerrain(64, frmLogForm, strUndergroundOres);
     for (int xi = 0; xi < City.mapLength / 16; xi++)
     {
         for (int zi = -City.farmLength / 16; zi < City.mapLength / 16; zi++)
         {
             ChunkRef chunkActive = cm.CreateChunk(xi, zi);
             chunkActive.IsTerrainPopulated = true;
             chunkActive.Blocks.AutoLight   = false;
             CreateFlatChunk(chunkActive, intUndergroundTerrain);
             cm.Save();
         }
         frmLogForm.UpdateProgress(((1 + xi) * 24 / (City.mapLength / 16)) / 100);
     }
     cm.Save();
 }
Пример #9
0
        public void CropMaceWorld(frmMace frmLogForm)
        {
            Directory.CreateDirectory(Environment.GetEnvironmentVariable("APPDATA") + "\\.minecraft\\saves\\macecopy");
            BetaWorld    bwCopy = BetaWorld.Create(Environment.GetEnvironmentVariable("APPDATA") + "\\.minecraft\\saves\\macecopy");
            ChunkManager cmCopy = bwCopy.GetChunkManager();

            BetaWorld    bwCrop = BetaWorld.Open(Environment.GetEnvironmentVariable("APPDATA") + "\\.minecraft\\saves\\mace");
            ChunkManager cmCrop = bwCrop.GetChunkManager();

            foreach (ChunkRef chunk in cmCrop)
            {
                Debug.WriteLine("Copying chunk " + chunk.X + "," + chunk.Z);
                cmCopy.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef());
            }
            cmCopy.Save();
            bwCopy.Save();
        }
Пример #10
0
        public static void CropMaceWorld(frmMace frmLogForm)
        {
            // thank you to Surrogard <*****@*****.**> for providing a linux friendly version of this code:
            Directory.CreateDirectory(Utils.GetMinecraftSavesDirectory("macecopy"));
            BetaWorld        bwCopy = BetaWorld.Create(Utils.GetMinecraftSavesDirectory("macecopy"));
            BetaChunkManager cmCopy = bwCopy.GetChunkManager();
            BetaWorld        bwCrop = BetaWorld.Open(Utils.GetMinecraftSavesDirectory("mace"));
            BetaChunkManager cmCrop = bwCrop.GetChunkManager();

            foreach (ChunkRef chunk in cmCrop)
            {
                if (chunk.X >= 0 && chunk.X <= 7 && chunk.Z >= 0 && chunk.Z <= 10)
                {
                    Debug.WriteLine("Copying chunk " + chunk.X + "," + chunk.Z);
                    cmCopy.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef());
                }
            }
            cmCopy.Save();
            bwCopy.Save();
        }
Пример #11
0
        private static int[, ,] MakeUndergroundTerrain(int SizeY, frmMace frmLogForm)
        {
            int[, ,] intArea = new int[(City.MapLength / 8) + 1, (SizeY / 8) + 1, (City.MapLength / 8) + 1];
            int[] intGroundBlockIDs = new int[] { BlockInfo.Stone.ID, BlockInfo.Dirt.ID, BlockInfo.Sand.ID,
                                                  BlockInfo.Gravel.ID };
            int[] intGroundBlockChances = new int[] { 3, 2, 1, 1 };
            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int y = 0; y < intArea.GetLength(1); y++)
                {
                    for (int z = 0; z < intArea.GetLength(2); z++)
                    {
                        intArea[x, y, z] = intGroundBlockIDs[RandomHelper.RandomWeightedNumber(intGroundBlockChances)];
                    }
                }
            }

            double dblSmudgeArrayChance = 0.6;

            intArea = Utils.SmudgeArray3D(Utils.EnlargeThreeDimensionalArray(intArea, 2, 2, 2), dblSmudgeArrayChance);
            intArea = Utils.SmudgeArray3D(Utils.EnlargeThreeDimensionalArray(intArea, 2, 2, 2), dblSmudgeArrayChance);
            intArea = AddResources(intArea, SizeY, frmLogForm);
            intArea = Utils.SmudgeArray3D(Utils.EnlargeThreeDimensionalArray(intArea, 2, 2, 2), dblSmudgeArrayChance);

            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int y = 0; y < intArea.GetLength(1); y++)
                {
                    for (int z = 0; z < intArea.GetLength(2); z++)
                    {
                        if (intArea[x, y, z] == BlockInfo.Sand.ID && RandomHelper.NextDouble() < 0.2)
                        {
                            intArea[x, y, z] = BlockInfo.Sandstone.ID;
                        }
                    }
                }
            }

            return(intArea);
        }
Пример #12
0
        private static int[, ,] MakeUndergroundTerrain(int SizeY, frmMace frmLogForm, string strUndergroundOres)
        {
            int[, ,] intArea = new int[(City.mapLength / 8) + 1, (SizeY / 8) + 1, ((City.farmLength + City.mapLength) / 8) + 1];

            int[] intGroundBlockIDs = Utils.ArrayFromXMLElement(Path.Combine("Resources", "Themes", City.themeName + ".xml"),
                                                                "options", "underground").StringArrayToIntArray();
            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int y = 0; y < intArea.GetLength(1); y++)
                {
                    for (int z = 0; z < intArea.GetLength(2); z++)
                    {
                        intArea[x, y, z] = intGroundBlockIDs[RNG.Next(intGroundBlockIDs.GetLength(0))];
                    }
                }
            }

            double dblSmudgeArrayChance = 0.6;

            intArea = intArea.EnlargeArray3D(4, 4, 4).SmudgeArray3D(dblSmudgeArrayChance);
            intArea = AddResources(intArea, SizeY, frmLogForm, strUndergroundOres);
            intArea = intArea.EnlargeArray3D(2, 2, 2).SmudgeArray3D(dblSmudgeArrayChance);

            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int y = 0; y < intArea.GetLength(1); y++)
                {
                    for (int z = 0; z < intArea.GetLength(2); z++)
                    {
                        if (intArea[x, y, z] == BlockInfo.Sand.ID && RNG.NextDouble() < 0.2)
                        {
                            intArea[x, y, z] = BlockInfo.Sandstone.ID;
                        }
                    }
                }
            }

            return(intArea);
        }
Пример #13
0
        private static int[, ,] AddResources(int[, ,] intEnlargedArea, int Y, frmMace frmLogForm, string strUndergroundOres)
        {
            int X, Z;
            int intResources = City.mapLength * Y * (City.farmLength + City.mapLength);

            switch (strUndergroundOres)
            {
            case "Sparse":   intResources /= 400; break;

            case "Uncommon": intResources /= 300; break;

            case "Normal":   intResources /= 200; break;

            case "Common":   intResources /= 100; break;

            case "Dense":    intResources /= 50; break;

            default: intResources /= 200; Debug.Fail("Invalid switch for underground ores."); break;
            }

            frmLogForm.UpdateLog("Adding resource patches: " + intResources, true, true);
            do
            {
                X = RNG.Next(1, intEnlargedArea.GetLength(0) - 1);
                Y = RNG.Next(1, intEnlargedArea.GetLength(1) - 1);
                Z = RNG.Next(1, intEnlargedArea.GetLength(2) - 1);
                if (intEnlargedArea[X, Y, Z] == BlockInfo.Stone.ID)
                {
                    double dblDepth = (double)Y / intEnlargedArea.GetLength(1);
                    // this increases ore frequency as we get lower
                    if (dblDepth < RNG.NextDouble() * 1.5)
                    {
                        intEnlargedArea[X, Y, Z] = SelectRandomResource(dblDepth);
                        intResources--;
                    }
                }
            } while (intResources > 0);
            return(intEnlargedArea);
        }
Пример #14
0
        private static int[, ,] AddResources(int[, ,] intEnlargedArea, int Y, frmMace frmLogForm)
        {
            int X, Z;
            int intResources = (int)(City.MapLength * Y * City.MapLength * 0.005);

            frmLogForm.UpdateLog("Adding resource patches: " + intResources, true, true);
            do
            {
                X = RandomHelper.Next(1, intEnlargedArea.GetLength(0) - 1);
                Y = RandomHelper.Next(1, intEnlargedArea.GetLength(1) - 1);
                Z = RandomHelper.Next(1, intEnlargedArea.GetLength(2) - 1);
                if (intEnlargedArea[X, Y, Z] == BlockInfo.Stone.ID)
                {
                    double dblDepth = (double)Y / intEnlargedArea.GetLength(1);
                    // this increases ore frequency as we get lower
                    if (dblDepth < RandomHelper.NextDouble() * 1.5)
                    {
                        intEnlargedArea[X, Y, Z] = SelectRandomResource(dblDepth);
                        intResources--;
                    }
                }
            } while (intResources > 0);
            return(intEnlargedArea);
        }
Пример #15
0
        // todo low: this is way too big
        private static void MakeLevel(BetaWorld world, BlockManager bm, int intDepth, int intMineshaftSize,
                                      Buildings.structPoint spMineshaftEntrance, frmMace frmLogForm)
        {
            frmLogForm.UpdateLog("Creating mineshaft level " + intDepth, true, true);

            string[] strResourceNames = Utils.ValueFromXMLElement(Path.Combine("Resources", "Mineshaft.xml"),
                                                                  "level" + intDepth, "names").Split(',');
            int[] intResourceChances = Utils.StringArrayToIntArray(Utils.ValueFromXMLElement(
                                                                       Path.Combine("Resources", "Mineshaft.xml"), "level" + intDepth, "chances").Split(','));
            int intTorchChance = Convert.ToInt32(Utils.ValueFromXMLElement(Path.Combine("Resources", "Mineshaft.xml"),
                                                                           "level" + intDepth, "torch_chance"));

            MineshaftBlocks[,] mbAreaFull = new MineshaftBlocks[intMineshaftSize + (MULTIPLIER * 2), intMineshaftSize + (MULTIPLIER * 2)];
            //int[,] mbAreaFull = new int[intMineshaftSize + (MULTIPLIER * 2), intMineshaftSize + (MULTIPLIER * 2)];
            int intXPosOriginal = spMineshaftEntrance.x - _intBlockStartBuildings;
            int intZPosOriginal = spMineshaftEntrance.z - _intBlockStartBuildings;

            _intBlockStartBuildings -= 2;
            int[,] intAreaOverview   = new int[(mbAreaFull.GetLength(0) / MULTIPLIER), (mbAreaFull.GetLength(1) / MULTIPLIER)];
            int intXPos = intXPosOriginal / MULTIPLIER;
            int intZPos = intZPosOriginal / MULTIPLIER;

            intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Air;
            CreateRouteXPlus(intAreaOverview, intXPos + 1, intZPos, 0);
            CreateRouteZPlus(intAreaOverview, intXPos, intZPos + 1, 1);
            CreateRouteXMinus(intAreaOverview, intXPos - 1, intZPos, 2);
            CreateRouteZMinus(intAreaOverview, intXPos, intZPos - 1, 3);
            int intOffsetX = (intXPosOriginal - (intXPos * MULTIPLIER)) - 2;
            int intOffsetZ = (intZPosOriginal - (intZPos * MULTIPLIER)) - 2;

            List <structSection> lstSections = new List <structSection>();

            intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Placeholder;
            intAreaOverview = AddMineshaftSections(intAreaOverview, intDepth);
            intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Air;

            for (int x = 0; x < intAreaOverview.GetLength(0); x++)
            {
                for (int z = 0; z < intAreaOverview.GetLength(1); z++)
                {
                    if (intAreaOverview[x, z] >= 100)
                    {
                        structSection structCurrentSection = new structSection();
                        structCurrentSection.bldMineshaftSection = SourceWorld.GetBuilding(intAreaOverview[x, z] - 100);
                        structCurrentSection.x = ((x * MULTIPLIER) + intOffsetX) - 1;
                        structCurrentSection.z = ((z * MULTIPLIER) + intOffsetZ) - 1;
                        for (int x2 = x; x2 <= x + (structCurrentSection.bldMineshaftSection.intSizeX - 1) / 7; x2++)
                        {
                            for (int z2 = z; z2 <= z + (structCurrentSection.bldMineshaftSection.intSizeZ - 1) / 7; z2++)
                            {
                                if (intAreaOverview[x2, z2] == structCurrentSection.bldMineshaftSection.intID + 100)
                                {
                                    intAreaOverview[x2, z2] = (int)MineshaftBlocks.Structure;
                                }
                            }
                        }
                        lstSections.Add(structCurrentSection);
                    }
                }
            }
            for (int x = 4; x < mbAreaFull.GetLength(0) - 4; x++)
            {
                for (int z = 4; z < mbAreaFull.GetLength(1) - 4; z++)
                {
                    if (intAreaOverview.GetLength(0) > x / MULTIPLIER && intAreaOverview.GetLength(1) > z / MULTIPLIER)
                    {
                        switch (mbAreaFull[x + intOffsetX, z + intOffsetZ])
                        {
                        case MineshaftBlocks.NaturalTerrain:
                        case MineshaftBlocks.Air:
                        case MineshaftBlocks.Placeholder:
                        case MineshaftBlocks.EntranceSection:
                            mbAreaFull[x + intOffsetX, z + intOffsetZ] = (MineshaftBlocks)intAreaOverview[x / MULTIPLIER, z / MULTIPLIER];
                            break;
                        }
                    }
                    if ((x + 3) % 5 == 0 && (z + 3) % 5 == 0 && intAreaOverview[x / MULTIPLIER, z / MULTIPLIER] == (int)MineshaftBlocks.Air)
                    {
                        if (intAreaOverview[(x / MULTIPLIER) + 1, z / MULTIPLIER] >= 100)
                        {
                            for (int x2 = 0; x2 < 5; x2++)
                            {
                                mbAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = MineshaftBlocks.Structure;
                            }
                        }
                        if (intAreaOverview[(x / MULTIPLIER) + 1, z / MULTIPLIER] == (int)MineshaftBlocks.Air)
                        {
                            for (int x2 = 0; x2 < 5; x2++)
                            {
                                if (x2 == 1 || x2 == 3)
                                {
                                    mbAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = MineshaftBlocks.CeilingSupport;
                                    mbAreaFull[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = MineshaftBlocks.CeilingSupport;
                                }
                                else
                                {
                                    mbAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = MineshaftBlocks.Support;
                                    mbAreaFull[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = MineshaftBlocks.Support;
                                }
                            }
                            for (int x2 = 0; x2 <= 5; x2++)
                            {
                                if (mbAreaFull[x + intOffsetX + x2, z + intOffsetZ] == MineshaftBlocks.Support)
                                {
                                    mbAreaFull[x + intOffsetX + x2, z + intOffsetZ] = MineshaftBlocks.RailWithSupport;
                                }
                                else
                                {
                                    mbAreaFull[x + intOffsetX + x2, z + intOffsetZ] = MineshaftBlocks.Rail;
                                }
                            }
                        }
                        if (intAreaOverview[x / MULTIPLIER, (z / MULTIPLIER) + 1] == (int)MineshaftBlocks.Air)
                        {
                            for (int z2 = 0; z2 < 5; z2++)
                            {
                                if (z2 == 1 || z2 == 3)
                                {
                                    mbAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = MineshaftBlocks.CeilingSupport;
                                    mbAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = MineshaftBlocks.CeilingSupport;
                                }
                                else
                                {
                                    mbAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = MineshaftBlocks.Support;
                                    mbAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = MineshaftBlocks.Support;
                                }
                            }
                            for (int z2 = 0; z2 <= 5; z2++)
                            {
                                if (mbAreaFull[x + intOffsetX, z + intOffsetZ + z2] == MineshaftBlocks.Support)
                                {
                                    mbAreaFull[x + intOffsetX, z + intOffsetZ + z2] = MineshaftBlocks.RailWithSupport;
                                }
                                else
                                {
                                    mbAreaFull[x + intOffsetX, z + intOffsetZ + z2] = MineshaftBlocks.Rail;
                                }
                            }
                        }
                        if (intAreaOverview[x / MULTIPLIER, z / MULTIPLIER] == (int)MineshaftBlocks.Air)
                        {
                            MakeChestAndOrTorch(intAreaOverview, mbAreaFull, (x - 3) / MULTIPLIER, z / MULTIPLIER,
                                                x + intOffsetX - 2, z + intOffsetZ);
                            MakeChestAndOrTorch(intAreaOverview, mbAreaFull, (x + 3) / MULTIPLIER, z / MULTIPLIER,
                                                x + intOffsetX + 2, z + intOffsetZ);
                            MakeChestAndOrTorch(intAreaOverview, mbAreaFull, x / MULTIPLIER, (z - 3) / MULTIPLIER,
                                                x + intOffsetX, z + intOffsetZ - 2);
                            MakeChestAndOrTorch(intAreaOverview, mbAreaFull, x / MULTIPLIER, (z + 3) / MULTIPLIER,
                                                x + intOffsetX, z + intOffsetZ + 2);
                        }
                    }
                }
            }
            mbAreaFull[intXPosOriginal, intZPosOriginal] = MineshaftBlocks.EntranceSection;
            int intSupportMaterial = RandomHelper.RandomNumber(BlockInfo.Wood.ID, BlockInfo.WoodPlank.ID, BlockInfo.Fence.ID);

            for (int x = 0; x < mbAreaFull.GetLength(0); x++)
            {
                for (int z = 0; z < mbAreaFull.GetLength(1); z++)
                {
                    if (intDepth <= 4)
                    {
                        if (bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockInfo.Gravel.ID)
                        {
                            bm.SetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings, BlockInfo.Stone.ID);
                        }
                    }
                    if (intDepth <= 2)
                    {
                        if (bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockInfo.Sand.ID ||
                            bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockInfo.Sandstone.ID)
                        {
                            bm.SetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings, BlockInfo.Dirt.ID);
                        }
                    }
                    switch (mbAreaFull[x, z])
                    {
                    case MineshaftBlocks.NaturalTerrain:
                        break;

                    case MineshaftBlocks.Air:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockInfo.Air.ID);
                        }
                        break;

                    case MineshaftBlocks.EntranceSection:
                    case MineshaftBlocks.Rail:
                        for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 38 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockInfo.Gravel.ID);
                            }
                            else if (y == 39 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockInfo.Rails.ID);
                            }
                            else
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockInfo.Air.ID);
                            }
                        }
                        break;

                    case MineshaftBlocks.RailWithSupport:
                        for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 38 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockInfo.Gravel.ID);
                            }
                            else if (y == 39 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockInfo.Rails.ID);
                            }
                            else if (y == 40 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockInfo.Air.ID);
                            }
                            else
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         intSupportMaterial);
                            }
                        }
                        break;

                    case MineshaftBlocks.Support:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                     intSupportMaterial);
                        }
                        break;

                    case MineshaftBlocks.ChestAndOrTorch:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 39 - (5 * intDepth) &&
                                RandomHelper.NextDouble() > 0.9)
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockInfo.Chest.ID);
                                MakeChestItems(bm, x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intResourceChances, strResourceNames);
                            }
                            else if (y == 41 - (5 * intDepth) &&
                                     RandomHelper.NextDouble() < (double)intTorchChance / 100)
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockInfo.Torch.ID);
                                if (mbAreaFull[x - 1, z] == 0)
                                {
                                    bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 1);
                                }
                                else if (mbAreaFull[x + 1, z] == 0)
                                {
                                    bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 2);
                                }
                                else if (mbAreaFull[x, z - 1] == 0)
                                {
                                    bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 3);
                                }
                                else
                                {
                                    bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 4);
                                }
                            }
                            else
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockInfo.Air.ID);
                            }
                        }
                        break;

                    case MineshaftBlocks.CeilingSupport:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 41 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         intSupportMaterial);
                            }
                            else
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockInfo.Air.ID);
                            }
                        }
                        break;

                    case MineshaftBlocks.Unused9:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * (intDepth - 1)); y++)
                        {
                            bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockInfo.Air.ID);
                        }
                        break;

                    case MineshaftBlocks.Structure:
                        // this will be overwritten later
                        break;

                    default:
                        Debug.Fail("Invalid switch result");
                        break;
                    }
                }
            }
            foreach (structSection MineshaftSection in lstSections)
            {
                SourceWorld.InsertBuilding(bm, new int[0, 0], _intBlockStartBuildings, MineshaftSection.x, MineshaftSection.z,
                                           MineshaftSection.bldMineshaftSection, 38 - (5 * intDepth));
            }
            world.Save();
            _intBlockStartBuildings += 2;
            //#if DEBUG
            //    File.WriteAllText("output_area_" + intDepth + ".txt", Utils.TwoDimensionalArrayToString(intAreaOverview));
            //    File.WriteAllText("output_map_" + intDepth + ".txt", Utils.TwoDimensionalArrayToString(intAreaFull));
            //#endif
        }
Пример #16
0
 public static void MakeMoat(frmMace frmLogForm, BlockManager bm)
 {
     frmLogForm.UpdateLog("Moat type: " + City.MoatType, true, true);
     switch (City.MoatType)
     {
         case "Drop to Bedrock":
             for (int a = City.EdgeLength - 1; a <= City.EdgeLength + 5; a++)
             {
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 2, 63, a,
                                              City.MapLength - a, BlockInfo.Air.ID, 0, -1);
             }
             BlockShapes.MakeHollowLayers(City.EdgeLength - 2, City.MapLength - (City.EdgeLength - 2),
                                          64, 64,
                                          City.EdgeLength - 2, City.MapLength - (City.EdgeLength - 2), BlockInfo.Fence.ID, 0, -1);
             break;
         case "Cactus":
             for (int a = City.EdgeLength - 1; a <= City.EdgeLength + 5; a++)
             {
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 63, 63, a,
                                              City.MapLength - a, BlockInfo.Sand.ID, 0, -1);
             }
             for (int a = City.EdgeLength + 1; a <= City.MapLength / 2; a += 2)
             {
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 64, City.EdgeLength + 1, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 65, City.EdgeLength + 1, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 64, City.EdgeLength + 3, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 65, City.EdgeLength + 3, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
             }
             for (int a = City.EdgeLength; a <= City.MapLength / 2; a += 2)
             {
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 64, City.EdgeLength, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 65, City.EdgeLength, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 64, City.EdgeLength + 2, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 65, City.EdgeLength + 2, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 64, City.EdgeLength + 4, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 65, City.EdgeLength + 4, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
             }
             if (City.HasGuardTowers)
             {
                 for (int a = City.EdgeLength + 3; a <= City.EdgeLength + 13; a += 2)
                 {
                     BlockShapes.MakeBlock(a, 64, City.EdgeLength + 3, BlockInfo.Air.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 65, City.EdgeLength + 3, BlockInfo.Air.ID, 2, 100, -1);
                 }
             }
             break;
         case "Cactus Low":
             for (int a = City.EdgeLength - 1; a <= City.EdgeLength + 5; a++)
             {
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 59, 63,
                                              a, City.MapLength - a, BlockInfo.Air.ID, 0, -1);
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 58, 58,
                                              a, City.MapLength - a, BlockInfo.Sand.ID, 0, -1);
             }
             for (int a = City.EdgeLength + 1; a <= City.MapLength / 2; a += 2)
             {
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 59, City.EdgeLength + 1, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 60, City.EdgeLength + 1, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 59, City.EdgeLength + 3, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 60, City.EdgeLength + 3, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
             }
             for (int a = City.EdgeLength; a <= City.MapLength / 2; a += 2)
             {
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 59, City.EdgeLength, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 60, City.EdgeLength, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 59, City.EdgeLength + 2, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 60, City.EdgeLength + 2, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
                 if (RNG.NextDouble() > 0.5)
                 {
                     BlockShapes.MakeBlock(a, 59, City.EdgeLength + 4, BlockInfo.Cactus.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 60, City.EdgeLength + 4, BlockInfo.Cactus.ID, 2, 50, -1);
                 }
             }
             if (City.HasGuardTowers)
             {
                 for (int a = City.EdgeLength + 3; a <= City.EdgeLength + 13; a += 2)
                 {
                     BlockShapes.MakeBlock(a, 59, City.EdgeLength + 3, BlockInfo.Air.ID, 2, 100, -1);
                     BlockShapes.MakeBlock(a, 60, City.EdgeLength + 3, BlockInfo.Air.ID, 2, 100, -1);
                 }
             }
             break;
         case "Lava":
             for (int a = City.EdgeLength - 1; a <= City.EdgeLength + 5; a++)
             {
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 55, 56,
                                              a, City.MapLength - a, BlockInfo.Lava.ID, 0, -1);
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 57, 63,
                                              a, City.MapLength - a, BlockInfo.Air.ID, 0, -1);
             }
             break;
         case "Fire":
             for (int a = City.EdgeLength - 1; a <= City.EdgeLength + 5; a++)
             {
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 56, 56,
                                              a, City.MapLength - a, BlockInfo.Netherrack.ID, 0, -1);
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 57, 57,
                                              a, City.MapLength - a, BlockInfo.Fire.ID, 0, -1);
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 58, 63,
                                              a, City.MapLength - a, BlockInfo.Air.ID, 0, -1);
             }
             break;
         case "Water":
             for (int a = City.EdgeLength - 1; a <= City.EdgeLength + 5; a++)
             {
                 BlockShapes.MakeHollowLayers(a, City.MapLength - a, 59, 63,
                                              a, City.MapLength - a, BlockInfo.Water.ID, 0, -1);
             }
             break;
         default:
             Debug.Fail("Invalid switch result");
             break;
     }
     // drawbridge
     int intBridgeEnd = City.HasMoat ? -2 : 5;
     if (City.MoatType == "Lava" || City.MoatType == "Fire")
     {
         BlockShapes.MakeSolidBox((City.MapLength / 2) - 2, City.MapLength / 2, 63, 63,
                                  City.EdgeLength + intBridgeEnd, City.EdgeLength + 13, BlockInfo.StoneBrick.ID, 2);
     }
     else
     {
         BlockShapes.MakeSolidBox((City.MapLength / 2) - 2, City.MapLength / 2, 63, 63,
                                  City.EdgeLength + intBridgeEnd, City.EdgeLength + 13, BlockInfo.WoodPlank.ID, 2);
     }
     BlockShapes.MakeSolidBox((City.MapLength / 2) - 2, City.MapLength / 2, 64, 65,
                  City.EdgeLength + intBridgeEnd, City.EdgeLength + 13, BlockInfo.Air.ID, 2);
 }
Пример #17
0
        public static void MakeWalls(AnvilWorld world, frmMace frmLogForm)
        {
            // walls
            for (int a = City.edgeLength + 6; a <= City.edgeLength + 10; a++)
            {
                BlockShapes.MakeHollowLayers(a, City.mapLength - a, 1, 72, a, City.mapLength - a,
                                             City.wallMaterialID, 0, City.wallMaterialData);
                world.Save();
            }
            // outside and inside edges at the top
            BlockShapes.MakeHollowLayers(City.edgeLength + 5, City.mapLength - (City.edgeLength + 5), 72, 73,
                                         City.edgeLength + 5, City.mapLength - (City.edgeLength + 5),
                                         City.wallMaterialID, 0, City.wallMaterialData);
            BlockShapes.MakeHollowLayers(City.edgeLength + 11, City.mapLength - (City.edgeLength + 11), 72, 73,
                                         City.edgeLength + 11, City.mapLength - (City.edgeLength + 11),
                                         City.wallMaterialID, 0, City.wallMaterialData);
            // alternating blocks on top of the edges
            for (int a = City.edgeLength + 6; a <= City.mapLength - (City.edgeLength + 6); a += 2)
            {
                BlockShapes.MakeBlock(a, 74, City.edgeLength + 5, City.wallMaterialID, 2, 100, City.wallMaterialData);
            }
            for (int a = City.edgeLength + 12; a <= City.mapLength - (City.edgeLength + 12); a += 2)
            {
                BlockShapes.MakeBlock(a, 74, City.edgeLength + 11, City.wallMaterialID, 2, 100, City.wallMaterialData);
            }
            // ladder
            BlockHelper.MakeLadder((City.mapLength / 2) - 5, 64, 72, City.edgeLength + 11, 2, City.wallMaterialID);

            BlockShapes.MakeSolidBox((City.mapLength / 2) - 5, (City.mapLength / 2) + 5,
                                     65, 74,
                                     City.edgeLength + 11, City.edgeLength + 11,
                                     BlockInfo.Air.ID, 2);

            // decorations at the gates
            frmLogForm.UpdateLog("Creating wall lights: " + City.outsideLightType, true, true);
            switch (City.outsideLightType)
            {
            case "Fire":
                // fire above the entrances
                BlockShapes.MakeBlock((City.mapLength / 2) - 1, 69, City.edgeLength + 5, BlockInfo.Netherrack.ID, 2, 100, -1);
                BlockShapes.MakeBlock((City.mapLength / 2), 69, City.edgeLength + 5, BlockInfo.Netherrack.ID, 2, 100, -1);
                BlockShapes.MakeBlock((City.mapLength / 2) - 1, 70, City.edgeLength + 5, BlockInfo.Fire.ID, 2, 100, -1);
                BlockShapes.MakeBlock((City.mapLength / 2), 70, City.edgeLength + 5, BlockInfo.Fire.ID, 2, 100, -1);
                // fire on the outside walls
                for (int a = City.edgeLength + 8; a < (City.mapLength / 2) - 9; a += 4)
                {
                    BlockShapes.MakeBlock(a, 69, City.edgeLength + 5, BlockInfo.Netherrack.ID, 2, 100, -1);
                    BlockShapes.MakeBlock(a, 70, City.edgeLength + 5, BlockInfo.Fire.ID, 2, 100, -1);
                }
                break;

            case "Torches":
                // torches above the entrances
                BlockHelper.MakeTorch((City.mapLength / 2), 70, City.edgeLength + 5, City.wallMaterialID, 2);
                BlockHelper.MakeTorch((City.mapLength / 2) - 1, 70, City.edgeLength + 5, City.wallMaterialID, 2);
                // torches on the outside walls
                for (int a = City.edgeLength + 8; a < (City.mapLength / 2) - 9; a += 4)
                {
                    BlockHelper.MakeTorch(a, 70, City.edgeLength + 5, City.wallMaterialID, 2);
                }
                break;

            case "None":
            case "":
                break;

            default:
                Debug.Fail("Invalid switch result");
                break;
            }
            if (City.hasTorchesOnWalkways)
            {
                // torches on the inside walls
                for (int a = City.edgeLength + 16; a < (City.mapLength / 2); a += 4)
                {
                    BlockHelper.MakeTorch(a, 69, City.edgeLength + 11, City.wallMaterialID, 2);
                }
                // torches on the wall roofs
                for (int a = City.edgeLength + 16; a < (City.mapLength / 2); a += 4)
                {
                    BlockShapes.MakeBlock(a, 73, City.edgeLength + 8, BlockInfo.Torch.ID, 2, 100, -1);
                }
            }


            for (int a = City.edgeLength + 16; a < (City.mapLength / 2); a += 24)
            {
                switch (City.npcs)
                {
                case "Ghostdancer's NPCs":
                    EntityVillager eVillager;
                    eVillager        = new EntityVillager(new TypedEntity("GKnight"));
                    eVillager.Health = 20;
                    BlockShapes.MakeEntity(a, 73, City.edgeLength + 8, eVillager, 2);
                    break;

                case "Minecraft Villagers":
                    EntityMob eMob;
                    eMob        = new EntityMob(new TypedEntity("VillagerGolem"));
                    eMob.Health = 100;
                    BlockShapes.MakeEntity(a, 73, City.edgeLength + 8, eMob, 2);
                    break;
                }
            }

            frmLogForm.UpdateLog("Creating wall emblems: " + City.cityEmblemType, true, true);
            MakeEmblem();
        }
Пример #18
0
        private static void MakeCitySettings(frmMace frmLogForm, string strThemeName, int CityID, string strSelectedNPCs)
        {
            City.ClearAllCityData();

            City.ID = CityID;

            City.ThemeName = strThemeName;

            City.CityNamePrefix         = GetThemeRandomXMLElement("options", "city_prefix");
            City.CityNamePrefixFilename = GetThemeRandomXMLElement("options", "city_prefix_file");
            City.CityNameSuffixFilename = GetThemeRandomXMLElement("options", "city_suffix_file");

            City.HasFarms = GetThemeRandomXMLElementBoolean("include", "farms");
            if (City.HasFarms)
            {
                City.FarmLength = Math.Max(2, GetThemeRandomXMLElementNumber("options", "farm_size"));
            }
            City.HasMoat        = GetThemeRandomXMLElementBoolean("include", "moat");
            City.HasWalls       = GetThemeRandomXMLElementBoolean("include", "walls");
            City.HasDrawbridges = GetThemeRandomXMLElementBoolean("include", "drawbridges");
            if (City.HasWalls)
            {
                City.HasGuardTowers = GetThemeRandomXMLElementBoolean("include", "guard_towers");
            }
            City.HasBuildings           = GetThemeRandomXMLElementBoolean("include", "buildings");
            City.HasPaths               = GetThemeRandomXMLElementBoolean("include", "paths");
            City.HasMineshaft           = GetThemeRandomXMLElementBoolean("include", "mineshaft");
            City.HasEmblems             = GetThemeRandomXMLElementBoolean("include", "emblems");
            City.HasOutsideLights       = GetThemeRandomXMLElementBoolean("include", "outside_lights");
            City.HasGuardTowersAddition = GetThemeRandomXMLElementBoolean("include", "guard_towers_addition");
            City.HasFlowers             = GetThemeRandomXMLElementBoolean("include", "flowers");
            City.HasSkyFeature          = GetThemeRandomXMLElementBoolean("include", "sky_feature");
            City.HasStreetLights        = GetThemeRandomXMLElementBoolean("include", "street_lights");
            City.HasTorchesOnWalkways   = GetThemeRandomXMLElementBoolean("include", "torches_on_walkways");

            City.HasValuableBlocks = frmLogForm.chkValuableBlocks.Checked;
            City.HasItemsInChests  = frmLogForm.chkItemsInChests.Checked;

            City.CityLength = Math.Max(5, GetThemeRandomXMLElementNumber("options", "city_size"));
            if (City.CityLength % 2 == 0)
            {
                City.CityLength++;
            }

            string strValue = String.Empty;

            strValue             = GetThemeRandomXMLElement("options", "ground_block");
            City.GroundBlockID   = Convert.ToInt32(strValue.Split('_')[0]);
            City.GroundBlockData = 0;
            if (strValue.Contains("_"))
            {
                City.GroundBlockData = Convert.ToInt32(strValue.Split('_')[1]);
            }

            if (City.HasMoat)
            {
                City.MoatType = GetThemeRandomXMLElement("options", "moat");
            }
            if (City.HasEmblems)
            {
                City.CityEmblemType = GetThemeRandomXMLElement("options", "emblem");
            }
            if (City.HasOutsideLights)
            {
                City.OutsideLightType = GetThemeRandomXMLElement("options", "outside_lights");
            }
            if (City.HasGuardTowers)
            {
                City.TowersAdditionType = GetThemeRandomXMLElement("options", "tower_addition");
            }
            if (City.HasFlowers)
            {
                City.FlowerSpawnPercent = GetThemeRandomXMLElementNumber("options", "flower_percent");
            }
            if (City.HasStreetLights)
            {
                City.StreetLightType = GetThemeRandomXMLElement("options", "street_lights");
            }
            if (City.HasWalls)
            {
                strValue              = GetThemeRandomXMLElement("options", "wall_material");
                City.WallMaterialID   = Convert.ToInt32(strValue.Split('_')[0]);
                City.WallMaterialData = 0;
                if (strValue.Contains("_"))
                {
                    City.WallMaterialData = Convert.ToInt32(strValue.Split('_')[1]);
                }
            }
            City.PathType = GetThemeRandomXMLElement("options", "path");
            City.NPCs     = strSelectedNPCs;
        }
Пример #19
0
        public void Generate(frmMace frmLogForm, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls,
                             bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeNoticeboard,
                             bool booIncludeBuildings, bool booIncludePaths,
                             string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strFireBeacons)
        {
            #region create minecraft world directory from a random unused city name
            string strFolder = "", strCityName = "";
            do
            {
                strCityName = "City of " + RandomHelper.RandomFileLine("Resources\\CityStartingWords.txt")
                              + RandomHelper.RandomFileLine("Resources\\CityEndingWords.txt");
                strFolder = Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strCityName + @"\";
            } while (Directory.Exists(strFolder));
            Directory.CreateDirectory(strFolder);
            #endregion

            #region get handles to world, chunk manager and block manager
            BetaWorld    worldDest = BetaWorld.Create(@strFolder);
            ChunkManager cmDest    = worldDest.GetChunkManager();
            BlockManager bmDest    = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            Random rand = new Random();

            #region determine block sizes
            // first we set the city size by chunks
            int intCitySize = 12;
            switch (strCitySize)
            {
            case "Random":
                intCitySize = rand.Next(8, 16);
                break;

            case "Very small":
                intCitySize = 5;
                break;

            case "Small":
                intCitySize = 8;
                break;

            case "Medium":
                intCitySize = 12;
                break;

            case "Large":
                intCitySize = 16;
                break;

            case "Very large":
                intCitySize = 25;
                break;
            }
            // then we multiply by 16, because that's the x and z of a chunk
            intCitySize *= 16;
            int intFarmSize = booIncludeFarms ? 32 : 16;
            int intMapSize  = intCitySize + (intFarmSize * 2);
            #endregion

            #region setup classes
            BlockShapes.SetupClass(bmDest, intMapSize);
            BlockHelper.SetupClass(bmDest, intMapSize);
            SourceWorld.SetupClass();
            #endregion

            if (strOutsideLights == "Random")
            {
                strOutsideLights = RandomHelper.RandomString("Fire", "Torches");
            }

            #region make the city
            frmLogForm.UpdateLog("Creating chunks");
            Chunks.MakeChunks(cmDest, 0, intMapSize / 16, frmLogForm);
            frmLogForm.UpdateProgress(35);

            // todo: test excluding paths/buildings
            if (booIncludeBuildings || booIncludePaths)
            {
                frmLogForm.UpdateLog("Creating paths");
                int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmSize, intMapSize);
                frmLogForm.UpdateProgress(38);
                if (booIncludeBuildings)
                {
                    frmLogForm.UpdateLog("Creating buildings");
                    Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmSize, intMapSize, booIncludePaths);
                }
            }
            frmLogForm.UpdateProgress(50);

            if (booIncludeWalls)
            {
                frmLogForm.UpdateLog("Creating walls");
                Walls.MakeWalls(worldDest, intFarmSize, intMapSize, strCityEmblem, strOutsideLights);
            }
            frmLogForm.UpdateProgress(51);

            if (booIncludeMoat)
            {
                frmLogForm.UpdateLog("Creating moat");
                Moat.MakeMoat(intFarmSize, intMapSize, strMoatType, booIncludeGuardTowers);
            }
            frmLogForm.UpdateProgress(52);

            if (booIncludeDrawbridges)
            {
                frmLogForm.UpdateLog("Creating drawbridges");
                Drawbridge.MakeDrawbridges(bmDest, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls);
            }
            frmLogForm.UpdateProgress(53);

            if (booIncludeGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers");
                GuardTowers.MakeGuardTowers(bmDest, intFarmSize, intMapSize, booIncludeWalls, strOutsideLights, strFireBeacons);
            }
            frmLogForm.UpdateProgress(54);

            if (booIncludeWalls && booIncludeNoticeboard)
            {
                frmLogForm.UpdateLog("Creating noticeboard");
                NoticeBoard.MakeNoticeBoard(bmDest, intFarmSize, intMapSize);
            }
            frmLogForm.UpdateProgress(55);

            if (booIncludeFarms)
            {
                frmLogForm.UpdateLog("Creating farms");
                Farms.MakeFarms(worldDest, bmDest, intFarmSize, intMapSize);
            }
            frmLogForm.UpdateProgress(58);
            #endregion

            #region world settings
            // spawn in a guard tower
            //world.Level.SpawnX = intFarmSize + 5;
            //world.Level.SpawnZ = intFarmSize + 5;
            //world.Level.SpawnY = 74;
            // spawn looking at one of the city entrances
            worldDest.Level.SpawnX = intMapSize / 2;
            worldDest.Level.SpawnZ = intMapSize - (intFarmSize - 10);
            worldDest.Level.SpawnY = 64;
            // spawn default
            //world.Level.SpawnX = 0;
            //world.Level.SpawnY = 65;
            //world.Level.SpawnZ = 0;

            worldDest.Level.LevelName = strCityName;
            worldDest.Level.Time      = rand.Next(24000);

            if (rand.NextDouble() < 0.15)
            {
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = rand.Next(6000, 18000);
                if (rand.NextDouble() < 0.25)
                {
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
            #endregion

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.SpawnX + 2, worldDest.Level.SpawnY, worldDest.Level.SpawnZ + 2);
#endif

            frmLogForm.UpdateLog("Resetting lighting");
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapSize / 16, 2));

            worldDest.Save();

            frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!");
            frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list.");
        }
Пример #20
0
        public static void Generate(frmMace frmLogForm, string strUserCityName,
                                    bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls,
                                    bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeBuildings,
                                    bool booIncludePaths, bool booIncludeMineshaft, bool booIncludeItemsInChests,
                                    bool booIncludeValuableBlocks, bool booIncludeGhostdancerSpawners,
                                    string strCitySize, string strMoatType, string strCityEmblem,
                                    string strOutsideLights, string strTowerAddition, string strWallMaterial,
                                    string strCitySeed, string strWorldSeed, bool booExportSchematic)
        {
            #region seed the random number generators
            int    intCitySeed, intWorldSeed;
            Random randSeeds = new Random();
            if (strCitySeed.Length == 0)
            {
                intCitySeed = randSeeds.Next();
                frmLogForm.UpdateLog("Random city seed: " + intCitySeed);
            }
            else
            {
                intCitySeed = JavaStringHashCode(strCitySeed);
                frmLogForm.UpdateLog("Random city seed: " + strCitySeed);
            }
            if (strWorldSeed.Length == 0)
            {
                intWorldSeed = randSeeds.Next();
                frmLogForm.UpdateLog("Random world seed: " + intWorldSeed);
            }
            else
            {
                intWorldSeed = JavaStringHashCode(strWorldSeed);
                frmLogForm.UpdateLog("Random world seed: " + strWorldSeed);
            }
            RandomHelper.SetSeed(intCitySeed);
            #endregion

            #region create minecraft world directory from a random unused city name
            string strFolder = String.Empty, strCityName = String.Empty;

            strUserCityName = SafeFilename(strUserCityName);
            if (strUserCityName.ToLower().Trim().Length == 0)
            {
                strUserCityName = "random";
            }

            if (strUserCityName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(Utils.GetMinecraftSavesDirectory(strUserCityName)))
                {
                    if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " +
                                        "Would you like to use a random name instead?", "World already exists",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        frmLogForm.UpdateLog("Cancelled, because a world with this name already exists.");
                        return;
                    }
                }
                else
                {
                    strCityName = strUserCityName;
                    strFolder   = Utils.GetMinecraftSavesDirectory(strCityName);
                }
            }
            if (strCityName.Length == 0)
            {
                string strStart, strEnd;
                do
                {
                    strStart    = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt"));
                    strEnd      = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityNoun.txt"));
                    strCityName = "City of " + strStart + strEnd;
                    strFolder   = Utils.GetMinecraftSavesDirectory(strCityName);
                } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder) || (strStart + strEnd).Length > 14);
            }
            Directory.CreateDirectory(strFolder);
            RandomHelper.SetSeed(intCitySeed);
            #endregion

            #region get handles to world, chunk manager and block manager
            BetaWorld        worldDest = BetaWorld.Create(@strFolder);
            BetaChunkManager cmDest    = worldDest.GetChunkManager();
            BlockManager     bmDest    = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            #region determine block sizes
            // first we set the city size by chunks
            int intCitySize = 12;
            switch (strCitySize)
            {
            case "Random":
                intCitySize = RandomHelper.Next(8, 16);
                break;

            case "Very small":
                intCitySize = 5;
                break;

            case "Small":
                intCitySize = 8;
                break;

            case "Medium":
                intCitySize = 12;
                break;

            case "Large":
                intCitySize = 16;
                break;

            case "Very large":
                intCitySize = 25;
                break;

            default:
                Debug.Fail("Invalid switch result");
                break;
            }
            // then we multiply by 16, because that's the x and z of a chunk
            intCitySize *= 16;
            int intFarmLength = booIncludeFarms ? 32 : 8;
            int intMapLength  = intCitySize + (intFarmLength * 2);
            #endregion

            #region setup classes
            BlockShapes.SetupClass(bmDest, intMapLength);
            BlockHelper.SetupClass(bmDest, intMapLength);
            if (!SourceWorld.SetupClass(worldDest, booIncludeItemsInChests, booIncludeGhostdancerSpawners))
            {
                return;
            }
            NoticeBoard.SetupClass(intCitySeed, intWorldSeed);
            #endregion

            #region determine random options
            // ensure selected options take priority, but don't set things on fire
            if (strTowerAddition == "Random")
            {
                strTowerAddition = RandomHelper.RandomString("Fire beacon", "Flag");
            }
            if (strWallMaterial.StartsWith("Wood"))
            {
                if (strMoatType == "Lava" || strMoatType == "Fire" || strMoatType == "Random")
                {
                    strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water");
                }
                strOutsideLights = "Torches";
            }
            if (strWallMaterial == "Random")
            {
                if (strMoatType == "Lava" || strMoatType == "Fire" || strOutsideLights == "Fire")
                {
                    strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone");
                }
                else
                {
                    strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone",
                                                                "Stone", "Wood Planks");
                    if (strWallMaterial.StartsWith("Wood"))
                    {
                        if (strMoatType == "Random")
                        {
                            strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water");
                        }
                        strOutsideLights = "Torches";
                    }
                }
            }
            if (strOutsideLights == "Random")
            {
                strOutsideLights = RandomHelper.RandomString("Fire", "Torches");
            }
            if (strMoatType == "Random")
            {
                int intRand = RandomHelper.Next(100);
                if (intRand >= 90)
                {
                    strMoatType = "Drop to Bedrock";
                }
                else if (intRand >= 80)
                {
                    strMoatType = "Cactus";
                }
                else if (intRand >= 50)
                {
                    strMoatType = "Lava";
                }
                else if (intRand >= 40)
                {
                    strMoatType = "Fire";
                }
                else
                {
                    strMoatType = "Water";
                }
            }

            int intWallMaterial = BlockType.STONE;
            switch (strWallMaterial)
            {
            case "Brick":
                intWallMaterial = BlockType.BRICK_BLOCK;
                break;

            case "Cobblestone":
                intWallMaterial = BlockType.COBBLESTONE;
                break;

            case "Sandstone":
                intWallMaterial = BlockType.SANDSTONE;
                break;

            case "Stone":
                intWallMaterial = BlockType.STONE;
                break;

            case "Wood Planks":
                intWallMaterial = BlockType.WOOD_PLANK;
                break;

            case "Wood Logs":
                intWallMaterial = BlockType.WOOD;
                break;

            case "Bedrock":
                intWallMaterial = BlockType.BEDROCK;
                break;

            case "Mossy Cobblestone":
                intWallMaterial = BlockType.MOSS_STONE;
                break;

            case "Netherrack":
                intWallMaterial = BlockType.NETHERRACK;
                break;

            case "Glass":
                intWallMaterial = BlockType.GLASS;
                break;

            case "Ice":
                intWallMaterial = BlockType.ICE;
                break;

            case "Snow":
                intWallMaterial = BlockType.SNOW_BLOCK;
                break;

            case "Glowstone":
                intWallMaterial = BlockType.GLOWSTONE_BLOCK;
                break;

            case "Dirt":
                intWallMaterial = BlockType.DIRT;
                break;

            case "Obsidian":
                intWallMaterial = BlockType.OBSIDIAN;
                break;

            case "Jack-o-Lantern":
                intWallMaterial = BlockType.JACK_O_LANTERN;
                break;

            case "Soul sand":
                intWallMaterial = BlockType.SOUL_SAND;
                break;

            case "Gold":
                intWallMaterial = BlockType.GOLD_BLOCK;
                break;

            case "Diamond":
                intWallMaterial = BlockType.DIAMOND_BLOCK;
                break;

            default:
                Debug.Fail("Invalid switch result");
                break;
            }
            #endregion

            #region make the city
            frmLogForm.UpdateLog("Creating underground terrain");
            Chunks.CreateInitialChunks(cmDest, intMapLength / 16, frmLogForm);
            frmLogForm.UpdateProgress(25);

            Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint();

            if (booIncludeWalls)
            {
                frmLogForm.UpdateLog("Creating walls");
                Walls.MakeWalls(worldDest, intFarmLength, intMapLength, strCityEmblem, strOutsideLights, intWallMaterial);
            }
            frmLogForm.UpdateProgress(34);
            if (booIncludeBuildings || booIncludePaths)
            {
                frmLogForm.UpdateLog("Creating paths");
                int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmLength, intMapLength, strCitySize,
                                                 booIncludeMineshaft);
                frmLogForm.UpdateProgress(36);
                if (booIncludeBuildings)
                {
                    frmLogForm.UpdateLog("Creating buildings");
                    spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmLength, intMapLength, booIncludePaths);
                    frmLogForm.UpdateProgress(45);
                    if (booIncludeMineshaft)
                    {
                        frmLogForm.UpdateLog("Creating mineshaft");
                        Mineshaft.MakeMineshaft(worldDest, bmDest, intFarmLength, intMapLength, spMineshaftEntrance);
                    }
                }
            }
            frmLogForm.UpdateProgress(51);

            if (booIncludeMoat)
            {
                frmLogForm.UpdateLog("Creating moat");
                Moat.MakeMoat(intFarmLength, intMapLength, strMoatType, booIncludeGuardTowers);
            }
            frmLogForm.UpdateProgress(52);

            if (booIncludeDrawbridges)
            {
                frmLogForm.UpdateLog("Creating drawbridges");
                Drawbridge.MakeDrawbridges(bmDest, intFarmLength, intMapLength, booIncludeMoat,
                                           booIncludeWalls, booIncludeItemsInChests, intWallMaterial, strMoatType, strCityName);
            }
            frmLogForm.UpdateProgress(53);

            if (booIncludeGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers");
                GuardTowers.MakeGuardTowers(bmDest, intFarmLength, intMapLength, booIncludeWalls,
                                            strOutsideLights, strTowerAddition, booIncludeItemsInChests, intWallMaterial);
            }
            frmLogForm.UpdateProgress(54);

            if (booIncludeFarms)
            {
                frmLogForm.UpdateLog("Creating farms");
                Farms.MakeFarms(worldDest, bmDest, intFarmLength, intMapLength);
            }
            frmLogForm.UpdateProgress(58);

            if (!booIncludeValuableBlocks)
            {
                cmDest.Save();
                worldDest.Save();
                Chunks.ReplaceValuableBlocks(worldDest, bmDest, intMapLength, intWallMaterial);
            }
            frmLogForm.UpdateProgress(60);
            Chunks.PositionRails(worldDest, bmDest, intMapLength);
            frmLogForm.UpdateProgress(62);
            #endregion

            #region world settings
            // spawn looking at one of the city entrances
            if (booIncludeFarms)
            {
                SpawnPoint spLevel = new SpawnPoint(7, 11, 13);
                worldDest.Level.Spawn = spLevel;
                worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength - (intFarmLength - 10));
            }
            else
            {
                worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength - (intFarmLength - 7));
            }
            // spawn in the middle of the city
//#if DEBUG
            //worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength / 2);
//#endif
            if (strWorldSeed.Length > 0)
            {
                worldDest.Level.RandomSeed = intWorldSeed;
            }

#if RELEASE
            worldDest.Level.Time = RandomHelper.Next(24000);

            if (RandomHelper.NextDouble() < 0.15)
            {
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = RandomHelper.Next(6000, 18000);
                if (RandomHelper.NextDouble() < 0.25)
                {
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
#endif
            #endregion

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2);
#endif

            frmLogForm.UpdateLog("Creating lighting data");
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapLength / 16, 2));

            worldDest.Level.LevelName = strCityName;
            worldDest.Save();

            if (booExportSchematic)
            {
                frmLogForm.UpdateLog("Creating schematic");
                AlphaBlockCollection abcExport = new AlphaBlockCollection(intMapLength, 128, intMapLength);
                for (int x = 0; x < intMapLength; x++)
                {
                    for (int z = 0; z < intMapLength; z++)
                    {
                        for (int y = 0; y < 128; y++)
                        {
                            abcExport.SetBlock(x, y, z, bmDest.GetBlock(x, y, z));
                        }
                    }
                }
                Schematic CitySchematic = new Schematic(intMapLength, 128, intMapLength);
                CitySchematic.Blocks = abcExport;
                CitySchematic.Export(Utils.GetMinecraftSavesDirectory(strCityName) + "\\" + strCityName + ".schematic");
            }

            frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!");
            frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list.");
        }
Пример #21
0
        public void Generate(frmMace frmLogForm, string strUserCityName, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls,
                             bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeNoticeboard,
                             bool booIncludeBuildings, bool booIncludePaths,
                             string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strFireBeacons,
                             string strCitySeed, string strWorldSeed)
        {
            #region Seed the random number generators
            int    intCitySeed, intWorldSeed;
            Random randSeeds = new Random();
            if (strCitySeed == "")
            {
                intCitySeed = randSeeds.Next();
                frmLogForm.UpdateLog("Random city seed: " + intCitySeed);
            }
            else
            {
                intCitySeed = JavaStringHashCode(strCitySeed);
                frmLogForm.UpdateLog("Random city seed: " + strCitySeed);
            }
            if (strWorldSeed == "")
            {
                intWorldSeed = randSeeds.Next();
                frmLogForm.UpdateLog("Random world seed: " + intWorldSeed);
            }
            else
            {
                intWorldSeed = JavaStringHashCode(strWorldSeed);
                frmLogForm.UpdateLog("Random world seed: " + strWorldSeed);
            }
            RandomHelper.SetSeed(intCitySeed);
            #endregion

            #region create minecraft world directory from a random unused city name
            string strFolder = "", strCityName = "";

            strUserCityName = SafeFilename(strUserCityName);
            if (strUserCityName.ToLower().Trim() == "")
            {
                strUserCityName = "Random";
            }

            if (strUserCityName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(Environment.GetEnvironmentVariable("APPDATA") +
                                     @"\.minecraft\saves\" + strUserCityName + @"\"))
                {
                    if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " +
                                        "Would you like to use a random name instead?", "World already exists",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        frmLogForm.UpdateLog("Cancelled, because a world with this name already exists.");
                        return;
                    }
                }
                else
                {
                    strCityName = strUserCityName;
                }
            }
            if (strCityName == "")
            {
                string strStart, strEnd;
                do
                {
                    strStart    = RandomHelper.RandomFileLine("Resources\\CityAdj.txt");
                    strEnd      = RandomHelper.RandomFileLine("Resources\\CityNoun.txt");
                    strCityName = "City of " + strStart + strEnd;
                    strFolder   = Environment.GetEnvironmentVariable("APPDATA") +
                                  @"\.minecraft\saves\" + strCityName + @"\";
                } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder));
            }
            Directory.CreateDirectory(strFolder);
            #endregion

            RandomHelper.SetSeed(intCitySeed);

            #region get handles to world, chunk manager and block manager
            BetaWorld    worldDest = BetaWorld.Create(@strFolder);
            ChunkManager cmDest    = worldDest.GetChunkManager();
            BlockManager bmDest    = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            #region determine block sizes
            // first we set the city size by chunks
            int intCitySize = 12;
            switch (strCitySize)
            {
            case "Random":
                intCitySize = RandomHelper.Next(8, 16);
                break;

            case "Very small":
                intCitySize = 5;
                break;

            case "Small":
                intCitySize = 8;
                break;

            case "Medium":
                intCitySize = 12;
                break;

            case "Large":
                intCitySize = 16;
                break;

            case "Very large":
                intCitySize = 25;
                break;
            }
            // then we multiply by 16, because that's the x and z of a chunk
            intCitySize *= 16;
            int intFarmSize = booIncludeFarms ? 32 : 16;
            int intMapSize  = intCitySize + (intFarmSize * 2);
            #endregion

            #region setup classes
            BlockShapes.SetupClass(bmDest, intMapSize);
            BlockHelper.SetupClass(bmDest, intMapSize);
            SourceWorld.SetupClass(worldDest);
            #endregion

            if (strOutsideLights == "Random")
            {
                strOutsideLights = RandomHelper.RandomString("Fire", "Torches");
            }

            #region make the city
            frmLogForm.UpdateLog("Creating chunks");
            Chunks.MakeChunks(cmDest, 0, intMapSize / 16, frmLogForm);
            frmLogForm.UpdateProgress(35);

            if (booIncludeBuildings || booIncludePaths)
            {
                frmLogForm.UpdateLog("Creating paths");
                int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmSize, intMapSize);
                frmLogForm.UpdateProgress(38);
                if (booIncludeBuildings)
                {
                    frmLogForm.UpdateLog("Creating buildings");
                    Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmSize, intMapSize, booIncludePaths);
                }
            }
            frmLogForm.UpdateProgress(50);

            if (booIncludeWalls)
            {
                frmLogForm.UpdateLog("Creating walls");
                Walls.MakeWalls(worldDest, intFarmSize, intMapSize, strCityEmblem, strOutsideLights);
            }
            frmLogForm.UpdateProgress(51);

            if (booIncludeMoat)
            {
                frmLogForm.UpdateLog("Creating moat");
                Moat.MakeMoat(intFarmSize, intMapSize, strMoatType, booIncludeGuardTowers);
            }
            frmLogForm.UpdateProgress(52);

            if (booIncludeDrawbridges)
            {
                frmLogForm.UpdateLog("Creating drawbridges");
                Drawbridge.MakeDrawbridges(bmDest, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls);
            }
            frmLogForm.UpdateProgress(53);

            if (booIncludeGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers");
                GuardTowers.MakeGuardTowers(bmDest, intFarmSize, intMapSize, booIncludeWalls, strOutsideLights, strFireBeacons);
            }
            frmLogForm.UpdateProgress(54);

            if (booIncludeWalls && booIncludeNoticeboard)
            {
                frmLogForm.UpdateLog("Creating noticeboard");
                NoticeBoard.MakeNoticeBoard(bmDest, intFarmSize, intMapSize, intCitySeed, intWorldSeed);
            }
            frmLogForm.UpdateProgress(55);

            if (booIncludeFarms)
            {
                frmLogForm.UpdateLog("Creating farms");
                Farms.MakeFarms(worldDest, bmDest, intFarmSize, intMapSize);
            }
            frmLogForm.UpdateProgress(58);
            #endregion

            #region world settings
            // spawn in a guard tower
            //world.Level.SpawnX = intFarmSize + 5;
            //world.Level.SpawnZ = intFarmSize + 5;
            //world.Level.SpawnY = 74;
            // spawn looking at one of the city entrances
            worldDest.Level.SpawnX = intMapSize / 2;
            worldDest.Level.SpawnZ = intMapSize - (intFarmSize - 10);
            worldDest.Level.SpawnY = 64;
            // spawn in the middle of the city
            //worldDest.Level.SpawnX = intMapSize / 2;
            //worldDest.Level.SpawnZ = (intMapSize / 2) - 1;
            //worldDest.Level.SpawnY = 64;
            // spawn default
            //world.Level.SpawnX = 0;
            //world.Level.SpawnY = 65;
            //world.Level.SpawnZ = 0;
            if (strWorldSeed != "")
            {
                worldDest.Level.RandomSeed = intWorldSeed;
            }

            worldDest.Level.LevelName = strCityName;
            worldDest.Level.Time      = RandomHelper.Next(24000);

            if (RandomHelper.NextDouble() < 0.15)
            {
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = RandomHelper.Next(6000, 18000);
                if (RandomHelper.NextDouble() < 0.25)
                {
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
            #endregion

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.SpawnX + 2, worldDest.Level.SpawnY, worldDest.Level.SpawnZ + 2);
#endif

            frmLogForm.UpdateLog("Resetting lighting");
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapSize / 16, 2));

            worldDest.Save();

            frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!");
            frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list.");
        }
Пример #22
0
        public void Generate(frmMace frmLogForm, string strUserCityName, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls,
                             bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeBuildings, bool booIncludePaths, bool booIncludeMineshaft,
                             bool booIncludeItemsInChests, bool booIncludeValuableBlocks,
                             string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strTowerAddition, string strWallMaterial,
                             string strCitySeed, string strWorldSeed)
        {
            #region seed the random number generators
            int    intCitySeed, intWorldSeed;
            Random randSeeds = new Random();
            if (strCitySeed == "")
            {
                intCitySeed = randSeeds.Next();
                frmLogForm.UpdateLog("Random city seed: " + intCitySeed);
            }
            else
            {
                intCitySeed = JavaStringHashCode(strCitySeed);
                frmLogForm.UpdateLog("Random city seed: " + strCitySeed);
            }
            if (strWorldSeed == "")
            {
                intWorldSeed = randSeeds.Next();
                frmLogForm.UpdateLog("Random world seed: " + intWorldSeed);
            }
            else
            {
                intWorldSeed = JavaStringHashCode(strWorldSeed);
                frmLogForm.UpdateLog("Random world seed: " + strWorldSeed);
            }
            RandomHelper.SetSeed(intCitySeed);
            #endregion

            #region create minecraft world directory from a random unused city name
            string strFolder = "", strCityName = "";

            strUserCityName = SafeFilename(strUserCityName);
            if (strUserCityName.ToLower().Trim() == "")
            {
                strUserCityName = "Random";
            }

            if (strUserCityName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(Utils.GetMinecraftSavesDir(strUserCityName)))
                {
                    if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " +
                                        "Would you like to use a random name instead?", "World already exists",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        frmLogForm.UpdateLog("Cancelled, because a world with this name already exists.");
                        return;
                    }
                }
                else
                {
                    strCityName = strUserCityName;
                    strFolder   = Utils.GetMinecraftSavesDir(strCityName);
                }
            }
            if (strCityName == "")
            {
                string strStart, strEnd;
                do
                {
                    strStart    = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt"));
                    strEnd      = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityNoun.txt"));
                    strCityName = "City of " + strStart + strEnd;
                    strFolder   = Utils.GetMinecraftSavesDir(strCityName);
                } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder));
            }
            Directory.CreateDirectory(strFolder);
            RandomHelper.SetSeed(intCitySeed);
            #endregion

            #region get handles to world, chunk manager and block manager
            BetaWorld    worldDest = BetaWorld.Create(@strFolder);
            ChunkManager cmDest    = worldDest.GetChunkManager();
            BlockManager bmDest    = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            #region determine block sizes
            // first we set the city size by chunks
            int intCitySize = 12;
            switch (strCitySize)
            {
            case "Random":
                intCitySize = RandomHelper.Next(8, 16);
                break;

            case "Very small":
                intCitySize = 5;
                break;

            case "Small":
                intCitySize = 8;
                break;

            case "Medium":
                intCitySize = 12;
                break;

            case "Large":
                intCitySize = 16;
                break;

            case "Very large":
                intCitySize = 25;
                break;
            }
            // then we multiply by 16, because that's the x and z of a chunk
            intCitySize *= 16;
            int intFarmSize = booIncludeFarms ? 32 : 16;
            int intMapSize  = intCitySize + (intFarmSize * 2);
            #endregion

            #region setup classes
            BlockShapes.SetupClass(bmDest, intMapSize);
            BlockHelper.SetupClass(bmDest, intMapSize);
            if (!SourceWorld.SetupClass(worldDest, booIncludeItemsInChests))
            {
                return;
            }
            NoticeBoard.SetupClass(intCitySeed, intWorldSeed);
            #endregion

            #region determine random options
            // ensure selected options take priority, but don't set things on fire
            if (strTowerAddition == "Random")
            {
                strTowerAddition = RandomHelper.RandomString("Fire beacon", "Flag");
            }
            if (strWallMaterial.StartsWith("Wood"))
            {
                if (strMoatType == "Lava" || strMoatType == "Random")
                {
                    strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water");
                }
                strOutsideLights = "Torches";
            }
            if (strWallMaterial == "Random")
            {
                if (strMoatType == "Lava" || strOutsideLights == "Fire")
                {
                    strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone");
                }
                else
                {
                    strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone", "Wood Planks");
                    if (strWallMaterial.StartsWith("Wood"))
                    {
                        if (strMoatType == "Random")
                        {
                            strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water");
                        }
                        strOutsideLights = "Torches";
                    }
                }
            }
            if (strOutsideLights == "Random")
            {
                strOutsideLights = RandomHelper.RandomString("Fire", "Torches");
            }
            if (strMoatType == "Random")
            {
                int intRand = RandomHelper.Next(100);
                if (intRand >= 90)
                {
                    strMoatType = "Drop to Bedrock";
                }
                else if (intRand >= 80)
                {
                    strMoatType = "Cactus";
                }
                else if (intRand >= 50)
                {
                    strMoatType = "Lava";
                }
                else
                {
                    strMoatType = "Water";
                }
            }

            int intWallMaterial = (int)BlockType.STONE;
            switch (strWallMaterial)
            {
            case "Brick":
                intWallMaterial = (int)BlockType.BRICK_BLOCK;
                break;

            case "Cobblestone":
                intWallMaterial = (int)BlockType.COBBLESTONE;
                break;

            case "Sandstone":
                intWallMaterial = (int)BlockType.SANDSTONE;
                break;

            case "Stone":
                intWallMaterial = (int)BlockType.STONE;
                break;

            case "Wood Planks":
                intWallMaterial = (int)BlockType.WOOD_PLANK;
                break;

            case "Wood Logs":
                intWallMaterial = (int)BlockType.WOOD;
                break;

            case "Bedrock":
                intWallMaterial = (int)BlockType.BEDROCK;
                break;

            case "Glass":
                intWallMaterial = (int)BlockType.GLASS;
                break;

            case "Dirt":
                intWallMaterial = (int)BlockType.DIRT;
                break;

            case "Obsidian":
                intWallMaterial = (int)BlockType.OBSIDIAN;
                break;
            }
            #endregion

            #region make the city
            frmLogForm.UpdateLog("Creating underground terrain");
            Chunks.MakeChunks(cmDest, intMapSize / 16, frmLogForm);
            frmLogForm.UpdateProgress(25);

            if (booIncludeBuildings || booIncludePaths)
            {
                frmLogForm.UpdateLog("Creating paths");
                int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmSize, intMapSize);
                frmLogForm.UpdateProgress(34);
                if (booIncludeBuildings)
                {
                    frmLogForm.UpdateLog("Creating buildings");
                    Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmSize, intMapSize, booIncludePaths);
                }
            }
            frmLogForm.UpdateProgress(43);

            if (booIncludeMineshaft)
            {
                frmLogForm.UpdateLog("Creating mineshaft");
                Mineshaft.MakeMineshaft(worldDest, bmDest, intFarmSize, intMapSize);
                frmLogForm.UpdateProgress(49);
            }

            if (booIncludeWalls)
            {
                frmLogForm.UpdateLog("Creating walls");
                Walls.MakeWalls(worldDest, intFarmSize, intMapSize, strCityEmblem, strOutsideLights, intWallMaterial);
            }
            frmLogForm.UpdateProgress(51);

            if (booIncludeMoat)
            {
                frmLogForm.UpdateLog("Creating moat");
                Moat.MakeMoat(intFarmSize, intMapSize, strMoatType, booIncludeGuardTowers);
            }
            frmLogForm.UpdateProgress(52);

            if (booIncludeDrawbridges)
            {
                frmLogForm.UpdateLog("Creating drawbridges");
                Drawbridge.MakeDrawbridges(bmDest, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls, booIncludeItemsInChests, intWallMaterial, strMoatType);
            }
            frmLogForm.UpdateProgress(53);

            if (booIncludeGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers");
                GuardTowers.MakeGuardTowers(bmDest, intFarmSize, intMapSize, booIncludeWalls, strOutsideLights, strTowerAddition, booIncludeItemsInChests, intWallMaterial);
            }
            frmLogForm.UpdateProgress(54);

            if (booIncludeFarms)
            {
                frmLogForm.UpdateLog("Creating farms");
                Farms.MakeFarms(worldDest, bmDest, intFarmSize, intMapSize);
            }
            frmLogForm.UpdateProgress(58);

            if (!booIncludeValuableBlocks)
            {
                cmDest.Save();
                worldDest.Save();
                Chunks.ReplaceValuableBlocks(worldDest, bmDest, intMapSize);
            }
            frmLogForm.UpdateProgress(62);
            #endregion

            #region world settings
            // spawn in a guard tower
            //worldDest.Level.SpawnX = intFarmSize + 5;
            //worldDest.Level.SpawnZ = intFarmSize + 5;
            //worldDest.Level.SpawnY = 82;
            // spawn looking at one of the city entrances
            worldDest.Level.SpawnX = intMapSize / 2;
            worldDest.Level.SpawnZ = intMapSize - (intFarmSize - 10);
            worldDest.Level.SpawnY = 64;
            // spawn in the middle of the city
            //worldDest.Level.SpawnX = intMapSize / 2;
            //worldDest.Level.SpawnZ = (intMapSize / 2) - 1;
            //worldDest.Level.SpawnY = 64;
            // spawn default
            //world.Level.SpawnX = 0;
            //world.Level.SpawnY = 65;
            //world.Level.SpawnZ = 0;
            if (strWorldSeed != "")
            {
                worldDest.Level.RandomSeed = intWorldSeed;
            }

            worldDest.Level.LevelName = strCityName;

#if RELEASE
            worldDest.Level.Time = RandomHelper.Next(24000);

            if (RandomHelper.NextDouble() < 0.15)
            {
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = RandomHelper.Next(6000, 18000);
                if (RandomHelper.NextDouble() < 0.25)
                {
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
#endif
            #endregion

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.SpawnX + 2, worldDest.Level.SpawnY, worldDest.Level.SpawnZ + 2);
#endif

            frmLogForm.UpdateLog("Resetting lighting");
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapSize / 16, 2));

            worldDest.Save();

            frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!");
            frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list.");
        }
Пример #23
0
        public void Generate(frmMace frmLogForm, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls,
                             bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeNoticeboard,
                             bool booIncludeBuildings, bool booIncludeSewers, string strCitySize, string strMoatLiquid)
        {
            string strFolder, strCityName;

            do
            {
                strCityName = "City of " + RandomHelper.RandomFileLine("CityStartingWords.txt")
                              + RandomHelper.RandomFileLine("CityEndingWords.txt");
                strFolder = Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strCityName + @"\";
            } while (Directory.Exists(strFolder));

            Directory.CreateDirectory(strFolder);
            BetaWorld world = BetaWorld.Create(@strFolder);

            int intFarmSize = 28;

            if (!booIncludeFarms)
            {
                intFarmSize = 2;
            }
            int    intPlotSize = 12;
            int    intPlots    = 15;
            Random rand        = new Random();

            switch (strCitySize)
            {
            case "Random":
                intPlots = rand.Next(10, 20);
                break;

            case "Very small":
                intPlots = 6;
                break;

            case "Small":
                intPlots = 10;
                break;

            case "Medium":
                intPlots = 15;
                break;

            case "Large":
                intPlots = 20;
                break;

            case "Very large":
                intPlots = 23;
                break;

            default:
                Debug.Assert(false);
                break;
            }
            int intMapSize = (intPlots * intPlotSize) + (intFarmSize * 2);

            ChunkManager cm = world.GetChunkManager();

            frmLogForm.UpdateLog("Creating chunks");
            Chunks.MakeChunks(cm, -1, 2 + (intMapSize / 16), frmLogForm);
            frmLogForm.UpdateProgress(34);

            BlockManager bm = world.GetBlockManager();

            bm.AutoLight = false;

            BlockShapes.SetupClass(bm, intMapSize);
            BlockHelper.SetupClass(bm, intMapSize);

            bool[,] booSewerEntrances;
            if (booIncludeSewers)
            {
                frmLogForm.UpdateLog("Creating sewers");
                booSewerEntrances = Sewers.MakeSewers(intFarmSize, intMapSize, intPlotSize);
            }
            else
            {
                booSewerEntrances = new bool[2 + ((intMapSize - ((intFarmSize + 16) * 2)) / intPlotSize),
                                             2 + ((intMapSize - ((intFarmSize + 16) * 2)) / intPlotSize)];
            }
            frmLogForm.UpdateProgress(35);
            if (booIncludeBuildings)
            {
                frmLogForm.UpdateLog("Creating plots");
                Plots.MakeBuildings(bm, booSewerEntrances, intFarmSize, intMapSize, intPlotSize);
            }
            frmLogForm.UpdateProgress(36);
            if (booIncludeWalls)
            {
                frmLogForm.UpdateLog("Creating walls");
                Walls.MakeWalls(intFarmSize, intMapSize);
            }
            frmLogForm.UpdateProgress(37);
            if (booIncludeMoat)
            {
                frmLogForm.UpdateLog("Creating moat");
                Moat.MakeMoat(intFarmSize, intMapSize, strMoatLiquid);
            }
            frmLogForm.UpdateProgress(38);
            if (booIncludeDrawbridges)
            {
                frmLogForm.UpdateLog("Creating drawbridges");
                Drawbridge.MakeDrawbridges(bm, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls);
            }
            frmLogForm.UpdateProgress(39);
            if (booIncludeGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers");
                GuardTowers.MakeGuardTowers(bm, intFarmSize, intMapSize, booIncludeWalls);
            }
            frmLogForm.UpdateProgress(40);
            if (booIncludeWalls && booIncludeNoticeboard)
            {
                frmLogForm.UpdateLog("Creating noticeboard");
                NoticeBoard.MakeNoticeBoard(bm, intFarmSize, intMapSize);
            }
            frmLogForm.UpdateProgress(41);
            if (booIncludeFarms)
            {
                frmLogForm.UpdateLog("Creating farms");
                Farms.MakeFarms(bm, intFarmSize, intMapSize);
            }
            frmLogForm.UpdateProgress(42);

            world.Level.LevelName = strCityName;
            // spawn in a guard tower
            //world.Level.SpawnX = intFarmSize + 5;
            //world.Level.SpawnZ = intFarmSize + 5;
            //world.Level.SpawnY = 74;
            // spawn looking at one of the city entrances
            world.Level.SpawnX = intMapSize / 2;
            world.Level.SpawnZ = intMapSize - 21;
            world.Level.SpawnY = 64;
            if (rand.NextDouble() < 0.1)
            {
                world.Level.IsRaining = true;
                if (rand.NextDouble() < 0.25)
                {
                    world.Level.IsThundering = true;
                }
            }

            //MakeHelperChest(bm, world.Level.SpawnX + 2, world.Level.SpawnY, world.Level.SpawnZ + 2);

            frmLogForm.UpdateLog("Resetting lighting");
            Chunks.ResetLighting(cm, frmLogForm, (int)Math.Pow(3 + (intMapSize / 16), 2));
            world.Save();

            frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!");
            frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list.");
        }
Пример #24
0
        private static void MakeCitySettings(frmMace frmLogForm, string strThemeName, int CityID, string strSelectedNPCs)
        {
            City.ClearAllCityData();

            City.id = CityID;

            City.themeName = strThemeName;

            City.cityNamePrefix         = GetThemeRandomXMLElement("options", "city_prefix");
            City.cityNamePrefixFilename = GetThemeRandomXMLElement("options", "city_prefix_file");
            City.cityNameSuffixFilename = GetThemeRandomXMLElement("options", "city_suffix_file");

            City.hasFarms = GetThemeRandomXMLElementBoolean("include", "farms");
            if (City.hasFarms)
            {
                City.farmLength = Math.Max(2, GetThemeRandomXMLElementNumber("options", "farm_size"));
            }
            City.hasMoat        = GetThemeRandomXMLElementBoolean("include", "moat");
            City.hasWalls       = GetThemeRandomXMLElementBoolean("include", "walls");
            City.hasDrawbridges = GetThemeRandomXMLElementBoolean("include", "drawbridges");
            if (City.hasWalls)
            {
                City.hasGuardTowers = GetThemeRandomXMLElementBoolean("include", "guard_towers");
            }
            City.hasBuildings = GetThemeRandomXMLElementBoolean("include", "buildings");
            City.hasPaths     = GetThemeRandomXMLElementBoolean("include", "paths");

            // to maintain backwards compatibility we assume old theme files want the main streets
            string mainStreets = GetThemeRandomXMLElement("include", "main_streets");

            City.hasMainStreets = mainStreets.Length == 0 || mainStreets.IsAffirmative();

            if (!City.hasPaths)
            {
                City.hasMainStreets = false;
            }

            City.hasMineshaft           = GetThemeRandomXMLElementBoolean("include", "mineshaft");
            City.HasEmblems             = GetThemeRandomXMLElementBoolean("include", "emblems");
            City.hasOutsideLights       = GetThemeRandomXMLElementBoolean("include", "outside_lights");
            City.hasGuardTowersAddition = GetThemeRandomXMLElementBoolean("include", "guard_towers_addition");
            City.hasFlowers             = GetThemeRandomXMLElementBoolean("include", "flowers");
            City.hasSkyFeature          = GetThemeRandomXMLElementBoolean("include", "sky_feature");
            City.hasStreetLights        = GetThemeRandomXMLElementBoolean("include", "street_lights");
            City.hasTorchesOnWalkways   = GetThemeRandomXMLElementBoolean("include", "torches_on_walkways");

            City.hasValuableBlocks = frmLogForm.chkValuableBlocks.Checked;
            City.hasItemsInChests  = frmLogForm.chkItemsInChests.Checked;

            string buildingFrequency = GetThemeRandomXMLElement("options", "building_frequency");

            if (buildingFrequency.Length == 0 || buildingFrequency.ToLower() == "default")
            {
                //City.farmBuildingFrequency = new int[] { 20, 16, 12, 8, 4 };
                City.buildingFrequency = new int[] { 9, 8, 7, 6, 5 };
            }
            else
            {
                City.buildingFrequency = Utils.StringArrayToIntArray(buildingFrequency.Split(' '));
            }
            string farmBuildingFrequency = GetThemeRandomXMLElement("options", "farm_building_frequency");

            if (farmBuildingFrequency.Length == 0 || farmBuildingFrequency.ToLower() == "default")
            {
                City.farmBuildingFrequency = new int[] { 20, 16, 12, 8, 4 };
            }
            else
            {
                City.farmBuildingFrequency = Utils.StringArrayToIntArray(farmBuildingFrequency.Split(' '));
            }



            City.cityLength = Math.Max(5, GetThemeRandomXMLElementNumber("options", "city_size"));
            if (City.cityLength % 2 == 0)
            {
                City.cityLength++;
            }

            string strValue = String.Empty;

            strValue             = GetThemeRandomXMLElement("options", "ground_block");
            City.groundBlockID   = Convert.ToInt32(strValue.Split('_')[0]);
            City.groundBlockData = 0;
            if (strValue.Contains("_"))
            {
                City.groundBlockData = Convert.ToInt32(strValue.Split('_')[1]);
            }

            switch (GetThemeRandomXMLElement("options", "biome"))
            {
            case "desert":
            case "dessert":
                City.biome = BiomeType.Desert;
                break;

            default:
                City.biome = BiomeType.Plains;
                break;
            }

            if (City.hasMoat)
            {
                City.moatType = GetThemeRandomXMLElement("options", "moat");
            }
            if (City.HasEmblems)
            {
                City.cityEmblemType = GetThemeRandomXMLElement("options", "emblem");
            }
            if (City.hasOutsideLights)
            {
                City.outsideLightType = GetThemeRandomXMLElement("options", "outside_lights");
            }
            if (City.hasGuardTowers)
            {
                City.towersAdditionType = GetThemeRandomXMLElement("options", "tower_addition");
            }
            if (City.hasFlowers)
            {
                City.flowerSpawnPercent = GetThemeRandomXMLElementNumber("options", "flower_percent");
            }
            if (City.hasStreetLights)
            {
                City.streetLightType = GetThemeRandomXMLElement("options", "street_lights");
            }
            if (City.hasWalls)
            {
                strValue              = GetThemeRandomXMLElement("options", "wall_material");
                City.wallMaterialID   = Convert.ToInt32(strValue.Split('_')[0]);
                City.wallMaterialData = 0;
                if (strValue.Contains("_"))
                {
                    City.wallMaterialData = Convert.ToInt32(strValue.Split('_')[1]);
                }
            }
            City.pathType = GetThemeRandomXMLElement("options", "path");
            City.npcs     = strSelectedNPCs;
        }
Пример #25
0
        public static void MakeMineshaft(BetaWorld world, BlockManager bm, Buildings.structPoint spMineshaftEntrance, frmMace frmLogForm)
        {
            _intBlockStartBuildings = City.EdgeLength + 13;
            int intMineshaftSize = (1 + City.MapLength) - (_intBlockStartBuildings * 2);

            if (intMineshaftSize % 5 > 0)
            {
                intMineshaftSize += 5 - (intMineshaftSize % 5);
            }
            _intBlockStartBuildings -= 2;
            for (int intLevel = 1; intLevel <= 7; intLevel++)
            {
                if (Utils.ValueFromXMLElement(Path.Combine("Resources", "Mineshaft.xml"), "active", "level" + intLevel.ToString()).IsAffirmative())
                {
                    MakeLevel(world, bm, intLevel, intMineshaftSize, spMineshaftEntrance, frmLogForm);
                }
            }
            int intBlockToReplace = bm.GetID(spMineshaftEntrance.x, 63, spMineshaftEntrance.z + 1);

            BlockShapes.MakeSolidBox(spMineshaftEntrance.x, spMineshaftEntrance.x,
                                     3, 63, spMineshaftEntrance.z + 1, spMineshaftEntrance.z + 1, BlockInfo.Wood.ID, 0);
            BlockHelper.MakeLadder(spMineshaftEntrance.x, 4, 63, spMineshaftEntrance.z, 0, BlockInfo.Wood.ID);
            BlockShapes.MakeSolidBox(spMineshaftEntrance.x, spMineshaftEntrance.x, 3, 63, spMineshaftEntrance.z + 1,
                                     spMineshaftEntrance.z + 1, BlockInfo.Stone.ID, 0);
            bm.SetID(spMineshaftEntrance.x, 63, spMineshaftEntrance.z + 1, intBlockToReplace);
        }
Пример #26
0
        public static void MakeGuardTowers(BlockManager bm, frmMace frmLogForm)
        {
            // remove wall
            BlockShapes.MakeSolidBox(City.EdgeLength + 5, City.EdgeLength + 11, 64, 79,
                                     City.EdgeLength + 5, City.EdgeLength + 11, BlockInfo.Air.ID, 1);
            // add tower
            BlockShapes.MakeHollowBox(City.EdgeLength + 4, City.EdgeLength + 12, 63, 80,
                                      City.EdgeLength + 4, City.EdgeLength + 12, City.WallMaterialID, 1, City.WallMaterialData);
            // divide into two rooms
            BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 4, City.EdgeLength + 12, 2, 72,
                                             City.EdgeLength + 4, City.EdgeLength + 12,
                                             City.WallMaterialID, 1, City.WallMaterialData);
            BlockShapes.MakeSolidBox(City.EdgeLength + 5, City.EdgeLength + 11, 64, 67,
                                     City.EdgeLength + 5, City.EdgeLength + 11, BlockInfo.Air.ID, 1);

            switch (City.OutsideLightType)
            {
            case "Fire":
                BlockShapes.MakeBlock(City.EdgeLength + 5, 76, City.EdgeLength + 3, BlockInfo.Netherrack.ID, 2, 100, -1);
                BlockShapes.MakeBlock(City.EdgeLength + 5, 77, City.EdgeLength + 3, BlockInfo.Fire.ID, 2, 100, -1);
                BlockShapes.MakeBlock(City.EdgeLength + 11, 76, City.EdgeLength + 3, BlockInfo.Netherrack.ID, 2, 100, -1);
                BlockShapes.MakeBlock(City.EdgeLength + 11, 77, City.EdgeLength + 3, BlockInfo.Fire.ID, 2, 100, -1);
                break;

            case "Torches":
                for (int y = 73; y <= 80; y += 7)
                {
                    BlockHelper.MakeTorch(City.EdgeLength + 6, y, City.EdgeLength + 3, City.WallMaterialID, 2);
                    BlockHelper.MakeTorch(City.EdgeLength + 10, y, City.EdgeLength + 3, City.WallMaterialID, 2);
                }
                break;

            case "None":
            case "":
                break;

            default:
                Debug.Fail("Invalid switch result");
                break;
            }
            if (City.HasTorchesOnWalkways)
            {
                // add torches
                BlockHelper.MakeTorch(City.EdgeLength + 6, 79, City.EdgeLength + 13, City.WallMaterialID, 2);
                BlockHelper.MakeTorch(City.EdgeLength + 10, 79, City.EdgeLength + 13, City.WallMaterialID, 2);
                // add torches inside
                BlockHelper.MakeTorch(City.EdgeLength + 6, 77, City.EdgeLength + 11, City.WallMaterialID, 2);
                BlockHelper.MakeTorch(City.EdgeLength + 10, 77, City.EdgeLength + 11, City.WallMaterialID, 2);
                BlockHelper.MakeTorch(City.EdgeLength + 5, 77, City.EdgeLength + 6, City.WallMaterialID, 2);
                BlockHelper.MakeTorch(City.EdgeLength + 5, 77, City.EdgeLength + 10, City.WallMaterialID, 2);
            }
            // add openings to the walls
            BlockShapes.MakeBlock(City.EdgeLength + 7, 73, City.EdgeLength + 12, BlockInfo.Air.ID, 2, 100, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 9, 73, City.EdgeLength + 12, BlockInfo.Air.ID, 2, 100, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 7, 74, City.EdgeLength + 12, BlockInfo.Air.ID, 2, 100, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 9, 74, City.EdgeLength + 12, BlockInfo.Air.ID, 2, 100, -1);
            // add blocks on top of the towers
            BlockShapes.MakeHollowLayers(City.EdgeLength + 4, City.EdgeLength + 12, 81, 81,
                                         City.EdgeLength + 4, City.EdgeLength + 12,
                                         City.WallMaterialID, 1, City.WallMaterialData);

            // alternating top blocks
            for (int x = City.EdgeLength + 4; x <= City.EdgeLength + 12; x += 2)
            {
                for (int z = City.EdgeLength + 4; z <= City.EdgeLength + 12; z += 2)
                {
                    if (x == City.EdgeLength + 4 ||
                        x == City.EdgeLength + 12 ||
                        z == City.EdgeLength + 4 ||
                        z == City.EdgeLength + 12)
                    {
                        BlockShapes.MakeBlock(x, 82, z, City.WallMaterialID, 1, 100, City.WallMaterialData);
                    }
                }
            }
            // add central columns
            BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 8, City.EdgeLength + 8, 73, 82,
                                             City.EdgeLength + 8, City.EdgeLength + 8, City.WallMaterialID, 1,
                                             City.WallMaterialData);
            BlockHelper.MakeLadder(City.EdgeLength + 7, 73, 82, City.EdgeLength + 8, 2, City.WallMaterialID);
            BlockHelper.MakeLadder(City.EdgeLength + 9, 73, 82, City.EdgeLength + 8, 2, City.WallMaterialID);
            // add torches on the roof
            if (City.HasTorchesOnWalkways)
            {
                BlockShapes.MakeBlock(City.EdgeLength + 6, 81, City.EdgeLength + 6, BlockInfo.Torch.ID, 1, 100, -1);
                BlockShapes.MakeBlock(City.EdgeLength + 6, 81, City.EdgeLength + 10, BlockInfo.Torch.ID, 2, 100, -1);
                BlockShapes.MakeBlock(City.EdgeLength + 10, 81, City.EdgeLength + 10, BlockInfo.Torch.ID, 1, 100, -1);
            }
            // add cobwebs
            BlockShapes.MakeBlock(City.EdgeLength + 5, 79, City.EdgeLength + 5, BlockInfo.Cobweb.ID, 1, 30, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 5, 79, City.EdgeLength + 11, BlockInfo.Cobweb.ID, 1, 30, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 11, 79, City.EdgeLength + 5, BlockInfo.Cobweb.ID, 1, 30, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 11, 79, City.EdgeLength + 11, BlockInfo.Cobweb.ID, 1, 30, -1);

            // add chests
            MakeGuardChest(bm, City.EdgeLength + 11, 73, City.EdgeLength + 11);
            MakeGuardChest(bm, City.MapLength - (City.EdgeLength + 11), 73, City.EdgeLength + 11);
            MakeGuardChest(bm, City.EdgeLength + 11, 73, City.MapLength - (City.EdgeLength + 11));
            MakeGuardChest(bm, City.MapLength - (City.EdgeLength + 11), 73, City.MapLength - (City.EdgeLength + 11));

            // add archery slots
            BlockShapes.MakeSolidBox(City.EdgeLength + 4, City.EdgeLength + 4, 74, 77,
                                     City.EdgeLength + 8, City.EdgeLength + 8, BlockInfo.Air.ID, 2);
            BlockShapes.MakeSolidBox(City.EdgeLength + 4, City.EdgeLength + 4, 76, 76,
                                     City.EdgeLength + 7, City.EdgeLength + 9, BlockInfo.Air.ID, 2);
            if (!City.HasWalls)
            {
                BlockHelper.MakeLadder(City.EdgeLength + 13, 64, 72, City.EdgeLength + 8, 2, City.WallMaterialID);
            }
            // include beds
            BlockHelper.MakeBed(City.EdgeLength + 5, City.EdgeLength + 6, 64, City.EdgeLength + 8, City.EdgeLength + 8, 2);
            BlockHelper.MakeBed(City.EdgeLength + 5, City.EdgeLength + 6, 64, City.EdgeLength + 10, City.EdgeLength + 10, 2);
            BlockHelper.MakeBed(City.EdgeLength + 11, City.EdgeLength + 10, 64, City.EdgeLength + 8, City.EdgeLength + 8, 2);
            // make columns to orientate torches
            BlockShapes.MakeSolidBox(City.EdgeLength + 5, City.EdgeLength + 5, 64, 73,
                                     City.EdgeLength + 5, City.EdgeLength + 5, BlockInfo.Wood.ID, 2);
            BlockShapes.MakeSolidBox(City.EdgeLength + 11, City.EdgeLength + 11, 64, 71,
                                     City.EdgeLength + 5, City.EdgeLength + 5, BlockInfo.Wood.ID, 2);
            BlockShapes.MakeSolidBox(City.EdgeLength + 5, City.EdgeLength + 5, 64, 71,
                                     City.EdgeLength + 11, City.EdgeLength + 11, BlockInfo.Wood.ID, 2);
            BlockShapes.MakeSolidBox(City.EdgeLength + 11, City.EdgeLength + 11, 64, 71,
                                     City.EdgeLength + 11, City.EdgeLength + 11, BlockInfo.Wood.ID, 2);
            // add ladders
            BlockHelper.MakeLadder(City.EdgeLength + 5, 64, 73, City.EdgeLength + 6, 2, BlockInfo.Wood.ID);
            // make torches
            if (City.HasTorchesOnWalkways)
            {
                BlockHelper.MakeTorch(City.EdgeLength + 10, 66, City.EdgeLength + 5, BlockInfo.Wood.ID, 2);
                BlockHelper.MakeTorch(City.EdgeLength + 6, 66, City.EdgeLength + 11, BlockInfo.Wood.ID, 2);
                BlockHelper.MakeTorch(City.EdgeLength + 10, 66, City.EdgeLength + 11, BlockInfo.Wood.ID, 2);
            }
            // make columns for real
            BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 5, City.EdgeLength + 5, 64, 73, City.EdgeLength + 5,
                                             City.EdgeLength + 5, City.WallMaterialID, 2, City.WallMaterialData);
            BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 11, City.EdgeLength + 11, 64, 71, City.EdgeLength + 5,
                                             City.EdgeLength + 5, City.WallMaterialID, 2, City.WallMaterialData);
            BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 5, City.EdgeLength + 5, 64, 71, City.EdgeLength + 11,
                                             City.EdgeLength + 11, City.WallMaterialID, 2, City.WallMaterialData);
            BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 11, City.EdgeLength + 11, 64, 71, City.EdgeLength + 11,
                                             City.EdgeLength + 11, City.WallMaterialID, 2, City.WallMaterialData);
            // make cobwebs
            BlockShapes.MakeBlock(City.EdgeLength + 11, 67, City.EdgeLength + 8, BlockInfo.Cobweb.ID, 2, 75, -1);
            // make doors from the city to the guard tower
            BlockShapes.MakeBlock(City.EdgeLength + 11, 65, City.EdgeLength + 11, BlockInfo.GoldBlock.ID, 1, 100, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 11, 64, City.EdgeLength + 11, BlockInfo.GoldBlock.ID, 1, 100, -1);
            BlockHelper.MakeDoor(City.EdgeLength + 11, 64, City.EdgeLength + 12, BlockInfo.GoldBlock.ID, true, 2);
            BlockShapes.MakeBlock(City.EdgeLength + 11, 65, City.EdgeLength + 11, BlockInfo.Air.ID, 1, 100, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 11, 64, City.EdgeLength + 11, BlockInfo.Air.ID, 1, 100, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 11, 64, City.EdgeLength + 11, BlockInfo.StonePlate.ID, 1, 100, -1);
            BlockShapes.MakeBlock(City.EdgeLength + 11, 64, City.EdgeLength + 13, BlockInfo.StonePlate.ID, 2, 100, -1);
            //BlockShapes.MakeBlock(City.intFarmSize + 13, 64, City.intFarmSize + 11, BlockInfo.Stone.ID_PLATE, 1, 100, -1);
            // add guard tower sign
            BlockHelper.MakeSign(City.EdgeLength + 12, 65, City.EdgeLength + 13, "~Guard Tower~~", City.WallMaterialID, 1);
            BlockHelper.MakeSign(City.EdgeLength + 8, 74, City.EdgeLength + 13, "~Guard Tower~~", City.WallMaterialID, 2);
            // make beacon
            frmLogForm.UpdateLog("Creating tower addition: " + City.TowersAdditionType, true, true);
            switch (City.TowersAdditionType)
            {
            case "Fire beacon":
                BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 8, City.EdgeLength + 8, 83, 84,
                                                 City.EdgeLength + 8, City.EdgeLength + 8,
                                                 City.WallMaterialID, 1, City.WallMaterialData);
                BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 6, City.EdgeLength + 10, 85, 85,
                                                 City.EdgeLength + 6, City.EdgeLength + 10,
                                                 City.WallMaterialID, 1, City.WallMaterialData);
                BlockShapes.MakeSolidBox(City.EdgeLength + 6, City.EdgeLength + 10, 86, 86,
                                         City.EdgeLength + 6, City.EdgeLength + 10, BlockInfo.Netherrack.ID, 1);
                BlockShapes.MakeSolidBox(City.EdgeLength + 6, City.EdgeLength + 10, 87, 87,
                                         City.EdgeLength + 6, City.EdgeLength + 10, BlockInfo.Fire.ID, 1);
                break;

            case "Flag":
                BlockShapes.MakeSolidBox(City.EdgeLength + 4, City.EdgeLength + 4, 83, 91,
                                         City.EdgeLength + 12, City.EdgeLength + 12, BlockInfo.Fence.ID, 2);
                BlockShapes.MakeBlock(City.EdgeLength + 4, 84, City.EdgeLength + 13, BlockInfo.Fence.ID, 2, 100, 0);
                BlockShapes.MakeBlock(City.EdgeLength + 4, 91, City.EdgeLength + 13, BlockInfo.Fence.ID, 2, 100, 0);
                int[] intColours = RNG.ShuffleArray(Enumerable.Range(0, 15).ToArray());
                // select a random flag file and turn it into an array
                string[] strFlagLines = File.ReadAllLines(RNG.RandomItemFromArray(Directory.GetFiles("Resources", "Flag_*.txt")));
                for (int x = 0; x < strFlagLines[0].Length; x++)
                {
                    for (int y = 0; y < strFlagLines.GetLength(0); y++)
                    {
                        int WoolColourID = Convert.ToInt32(strFlagLines[y].Substring(x, 1));
                        BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 4, City.EdgeLength + 4,
                                                         90 - y, 90 - y,
                                                         City.EdgeLength + 13 + x, City.EdgeLength + 13 + x,
                                                         BlockInfo.Wool.ID, 2, intColours[WoolColourID]);
                    }
                }
                break;
            }
        }
Пример #27
0
        public static structPoint MakeInsideCity(BlockManager bm, BetaWorld worldDest, int[,] intArea, frmMace frmLogForm)
        {
            int         intBlockStart       = City.FarmLength + 13;
            structPoint spMineshaftEntrance = MakeBuildings(bm, intArea, intBlockStart, worldDest);

            worldDest.Save();
            if (City.HasPaths)
            {
                JoinPathsToRoad(bm);
            }
            else
            {
                RemovePaths(bm, intArea, intBlockStart);
            }
            frmLogForm.UpdateLog("Creating street lights: " + City.StreetLightType, true, true);
            MakeStreetLights(bm);
            if (City.HasFlowers)
            {
                frmLogForm.UpdateLog("Creating flowers", true, true);
                MakeFlowers(bm, worldDest);
            }
            return(spMineshaftEntrance);
        }
Пример #28
0
        // todo low: long code is long
        static public void Generate(frmMace frmLogForm, string UserWorldName, string strWorldSeed,
                                    string strWorldType, bool booWorldMapFeatures, int TotalCities, string[] strCheckedThemes,
                                    int ChunksBetweenCities, string strSpawnPoint)
        {
            worldCities = new WorldCity[TotalCities];
            lstCityNames.Clear();

            RandomHelper.SetRandomSeed();

            #region create minecraft world directory from a random unused city name
            string strFolder = String.Empty, strWorldName = String.Empty;

            UserWorldName = Utils.SafeFilename(UserWorldName);
            if (UserWorldName.Trim().Length == 0)
            {
                UserWorldName = "random";
            }

            if (UserWorldName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(Utils.GetMinecraftSavesDirectory(UserWorldName)))
                {
                    if (MessageBox.Show("A world called \"" + UserWorldName + "\" already exists. " +
                                        "Would you like to use a random name instead?", "World already exists",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        frmLogForm.UpdateLog("Cancelled, because a world with this name already exists.", false, false);
                        return;
                    }
                }
                else
                {
                    strWorldName = UserWorldName;
                    strFolder    = Utils.GetMinecraftSavesDirectory(strWorldName);
                }
            }
            if (strWorldName.Length == 0)
            {
                strWorldName = Utils.GenerateWorldName();
                strFolder    = Utils.GetMinecraftSavesDirectory(strWorldName);
            }
            Directory.CreateDirectory(strFolder);
            frmLogForm.UpdateLog("World name: " + strWorldName, false, true);
            #endregion

            #region get handles to world, chunk manager and block manager
            BetaWorld worldDest = BetaWorld.Create(@strFolder);
            worldDest.Level.LevelName = "Creating. Don't open until Mace is finished.";
            BetaChunkManager cmDest = worldDest.GetChunkManager();
            BlockManager     bmDest = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            #region Determine themes
            // "how does this work, robson?"
            // well, I'm glad you asked!
            // we keep selecting a random unused checked theme, until they've all been used once.
            // after that, all other cities will have a random checked theme
            strCheckedThemes = RandomHelper.ShuffleArray(strCheckedThemes);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                if (CurrentCityID <= strCheckedThemes.GetUpperBound(0))
                {
                    worldCities[CurrentCityID].ThemeName = strCheckedThemes[CurrentCityID];
                }
                else
                {
                    worldCities[CurrentCityID].ThemeName = RandomHelper.RandomString(strCheckedThemes);
                }
                Debug.WriteLine(worldCities[CurrentCityID].ThemeName);
                City.ThemeName = worldCities[CurrentCityID].ThemeName;
                worldCities[CurrentCityID].ChunkLength = GetThemeRandomXMLElementNumber("options", "city_size");
            }
            #endregion

            GenerateCityLocations(TotalCities, ChunksBetweenCities);

            int intRandomCity = RandomHelper.Next(TotalCities);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                MakeCitySettings(frmLogForm, worldCities[CurrentCityID].ThemeName, CurrentCityID);
                GenerateCity.Generate(frmLogForm, worldDest, cmDest, bmDest, worldCities[CurrentCityID].x, worldCities[CurrentCityID].z);
                #region set spawn point
                if (City.ID == intRandomCity)
                {
                    switch (strSpawnPoint)
                    {
                    case "Away from the cities":
                        worldDest.Level.Spawn = new SpawnPoint(0, 65, 0);
                        break;

                    case "Inside a random city":
                        worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2),
                                                               65,
                                                               ((worldCities[intRandomCity].z + 30) * 16) + (City.MapLength / 2));
                        break;

                    case "Outside a random city":
                        if (City.HasFarms)
                        {
                            worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2),
                                                                   65,
                                                                   ((worldCities[intRandomCity].z + 30) * 16) + 20);
                        }
                        else
                        {
                            worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2),
                                                                   65,
                                                                   ((worldCities[intRandomCity].z + 30) * 16) + 2);
                        }
                        break;

                    default:
                        Debug.Fail("invalid spawn point");
                        break;
                    }
                    frmLogForm.UpdateLog("Spawn point set to " + worldDest.Level.Spawn.X + "," + worldDest.Level.Spawn.Y + "," + worldDest.Level.Spawn.Z, false, true);
                }
                #endregion
            }

            City.ID = TotalCities;
            frmLogForm.UpdateProgress(0);

            #region weather
#if RELEASE
            frmLogForm.UpdateLog("Setting weather", false, true);
            worldDest.Level.Time = RandomHelper.Next(24000);
            if (RandomHelper.NextDouble() < 0.2)
            {
                frmLogForm.UpdateLog("Rain", false, true);
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = RandomHelper.Next(6000, 18000);
                if (RandomHelper.NextDouble() < 0.25)
                {
                    frmLogForm.UpdateLog("Thunder", false, true);
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
#endif
            #endregion

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2);
#endif

            #region lighting
            frmLogForm.UpdateLog("\nCreating world lighting data", false, false);
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm);
            frmLogForm.UpdateProgress(0.95);
            #endregion

            #region world details
            worldDest.Level.LevelName = strWorldName;
            frmLogForm.UpdateLog("Setting world type: " + strWorldType, false, true);
            switch (strWorldType.ToLower())
            {
            case "creative":
                worldDest.Level.GameType = GameType.CREATIVE;
                break;

            case "survival":
                worldDest.Level.GameType = GameType.SURVIVAL;
                break;

            case "hardcore":
                worldDest.Level.GameType        = GameType.SURVIVAL;
                worldDest.Level.UseHardcoreMode = true;
                break;

            default:
                Debug.Fail("Invalidate world type selected.");
                break;
            }
            frmLogForm.UpdateLog("World map features: " + booWorldMapFeatures.ToString(), false, true);
            worldDest.Level.UseMapFeatures = booWorldMapFeatures;
            if (strWorldSeed != String.Empty)
            {
                worldDest.Level.RandomSeed = Utils.JavaStringHashCode(strWorldSeed);
                frmLogForm.UpdateLog("Specified world seed: " + worldDest.Level.RandomSeed, false, true);
            }
            else
            {
                worldDest.Level.RandomSeed = RandomHelper.Next();
                frmLogForm.UpdateLog("Random world seed: " + worldDest.Level.RandomSeed, false, true);
            }
            worldDest.Level.LastPlayed = (DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000;
            frmLogForm.UpdateLog("World time: " + worldDest.Level.LastPlayed, false, true);
            #endregion

            worldDest.Save();
            frmLogForm.UpdateProgress(1);

            frmLogForm.UpdateLog("\nCreated the " + strWorldName + "!", false, false);
            frmLogForm.UpdateLog("It'll be at the top of your MineCraft world list.", false, false);

            // todo low: export schematic
            #region export schematic
            //if (booExportSchematic)
            //{
            //    frmLogForm.UpdateLog("Creating schematic");
            //    AlphaBlockCollection abcExport = new AlphaBlockCollection(intMapLength, 128, intMapLength);
            //    for (int x = 0; x < intMapLength; x++)
            //    {
            //        for (int z = 0; z < intMapLength; z++)
            //        {
            //            for (int y = 0; y < 128; y++)
            //            {
            //                abcExport.SetBlock(x, y, z, bmDest.GetBlock(x, y, z));
            //            }
            //        }
            //    }
            //    Schematic CitySchematic = new Schematic(intMapLength, 128, intMapLength);
            //    CitySchematic.Blocks = abcExport;
            //    CitySchematic.Export(Utils.GetMinecraftSavesDirectory(strCityName) + "\\" + strCityName + ".schematic");
            //}
            #endregion
        }
Пример #29
0
        static public void Generate(frmMace frmLogForm, string UserWorldName, string strWorldSeed,
                                    string strWorldType, bool booWorldMapFeatures, int TotalCities, string[] strCheckedThemes,
                                    int ChunksBetweenCities, string strSpawnPoint, bool booExportSchematics,
                                    string strSelectedNPCs, string strUndergroundOres)
        {
            frmLogForm.UpdateLog("Started at " + DateTime.Now.ToLocalTime(), false, true);

            worldCities = new WorldCity[TotalCities];
            lstCityNames.Clear();
            Chunks.biomes.Clear();

            RNG.SetRandomSeed();

            #region create minecraft world directory from a random unused world name
            string strFolder = String.Empty, strWorldName = String.Empty;

            UserWorldName = UserWorldName.ToSafeFilename();
            if (UserWorldName.Trim().Length == 0)
            {
                UserWorldName = "random";
            }

            if (UserWorldName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(UserWorldName.ToMinecraftSaveDirectory()))
                {
                    if (MessageBox.Show("A world called \"" + UserWorldName + "\" already exists. " +
                                        "Would you like to use a random name instead?", "World already exists",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        frmLogForm.UpdateLog("Cancelled, because a world with this name already exists.", false, false);
                        return;
                    }
                }
                else
                {
                    strWorldName = UserWorldName;
                    strFolder    = strWorldName.ToMinecraftSaveDirectory();
                }
            }
            if (strWorldName.Length == 0)
            {
                strWorldName = Utils.GenerateWorldName();
                strFolder    = strWorldName.ToMinecraftSaveDirectory();
            }
            Directory.CreateDirectory(strFolder);
            frmLogForm.btnSaveLogNormal.Tag  = Path.Combine(strFolder, "LogNormal.txt");
            frmLogForm.btnSaveLogVerbose.Tag = Path.Combine(strFolder, "LogVerbose.txt");
            frmLogForm.UpdateLog("World name: " + strWorldName, false, true);
            #endregion

            #region get handles to world, chunk manager and block manager
            AnvilWorld worldDest = AnvilWorld.Create(@strFolder);
            worldDest.Level.LevelName = "Creating. Don't open until Mace is finished.";
            RegionChunkManager cmDest = worldDest.GetChunkManager();
            BlockManager       bmDest = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            #region Determine themes
            // "how does this work, robson?"
            // well, I'm glad you asked!
            // we keep selecting a random unused checked theme, until they've all been used once.
            // after that, all other cities will have a random checked theme

            int maxFarmSize = 0;

            strCheckedThemes = RNG.ShuffleArray(strCheckedThemes);
            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                if (CurrentCityID <= strCheckedThemes.GetUpperBound(0))
                {
                    worldCities[CurrentCityID].ThemeName = strCheckedThemes[CurrentCityID];
                }
                else
                {
                    worldCities[CurrentCityID].ThemeName = RNG.RandomItem(strCheckedThemes);
                }
                City.themeName = worldCities[CurrentCityID].ThemeName;
                worldCities[CurrentCityID].ChunkLength = GetThemeRandomXMLElementNumber("options", "city_size");
                int farmSize = GetThemeLastXMLElementNumber("options", "farm_size");
                maxFarmSize = Math.Max(maxFarmSize, farmSize);
            }
            #endregion

            GenerateCityLocations(TotalCities, ChunksBetweenCities + maxFarmSize);

            int intRandomCity = RNG.Next(TotalCities);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                MakeCitySettings(frmLogForm, worldCities[CurrentCityID].ThemeName, CurrentCityID, strSelectedNPCs);
                if (!GenerateCity.Generate(frmLogForm, worldDest, cmDest, bmDest, worldCities[CurrentCityID].x, worldCities[CurrentCityID].z, booExportSchematics, strUndergroundOres))
                {
                    frmLogForm.UpdateLog("World generation failed/cancelled.", false, false);
                    return;
                }
                #region set spawn point
                if (City.id == intRandomCity)
                {
                    switch (strSpawnPoint)
                    {
                    case "Away from the cities":
                        worldDest.Level.Spawn = new SpawnPoint(0, 65, 0);
                        break;

                    case "Inside a random city":
                        worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2),
                                                               65,
                                                               ((worldCities[intRandomCity].z + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2));
                        break;

                    case "Outside a random city":
                        worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2),
                                                               65,
                                                               ((worldCities[intRandomCity].z + Chunks.CITY_RELOCATION_CHUNKS) * 16) + 2);
                        break;

                    default:
                        Debug.Fail("invalid spawn point");
                        break;
                    }
                    frmLogForm.UpdateLog("Spawn point set to " + worldDest.Level.Spawn.X + "," + worldDest.Level.Spawn.Y + "," + worldDest.Level.Spawn.Z, false, true);
                }
                #endregion
            }

            #region weather
            frmLogForm.UpdateLog("Setting weather", false, true);
            worldDest.Level.Time = RNG.Next(24000);
            if (RNG.NextDouble() < 0.15)
            {
                frmLogForm.UpdateLog("Rain", false, true);
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = RNG.Next(6000, 18000);
                if (RNG.NextDouble() < 0.25)
                {
                    frmLogForm.UpdateLog("Thunder", false, true);
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
            #endregion

            #region world details
            worldDest.Level.LevelName = strWorldName;
            frmLogForm.UpdateLog("Setting world type: " + strWorldType, false, true);
            switch (strWorldType.ToLower())
            {
            case "creative":
                worldDest.Level.GameType = GameType.CREATIVE;
                break;

            case "survival":
                worldDest.Level.GameType = GameType.SURVIVAL;
                break;

            case "hardcore":
                worldDest.Level.GameType = GameType.SURVIVAL;
                worldDest.Level.Hardcore = true;
                break;

            default:
                Debug.Fail("Invalidate world type selected.");
                break;
            }
            frmLogForm.UpdateLog("World map features: " + booWorldMapFeatures.ToString(), false, true);
            worldDest.Level.UseMapFeatures = booWorldMapFeatures;
            if (strWorldSeed != String.Empty)
            {
                long seed = 0;
                if (long.TryParse(strWorldSeed, out seed))
                {
                    worldDest.Level.RandomSeed = seed;
                    frmLogForm.UpdateLog("Specified world seed: " + worldDest.Level.RandomSeed, false, true);
                }
                else
                {
                    worldDest.Level.RandomSeed = strWorldSeed.ToJavaHashCode();
                    frmLogForm.UpdateLog("Specified world seed: " + strWorldSeed, false, true);
                    frmLogForm.UpdateLog("Specified world seed converted to a number: " + worldDest.Level.RandomSeed, false, true);
                }
            }
            else
            {
                worldDest.Level.RandomSeed = RNG.Next();
                frmLogForm.UpdateLog("Random world seed: " + worldDest.Level.RandomSeed, false, true);
            }
            worldDest.Level.LastPlayed = (DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000;
            frmLogForm.UpdateLog("World time: " + worldDest.Level.LastPlayed, false, true);
            #endregion

            cmDest.Save();
            worldDest.Save();

            Chunks.SetBiomeData(@strFolder);

            frmLogForm.UpdateLog("\nCreated the " + strWorldName + "!", false, false);
            frmLogForm.UpdateLog("It'll be at the top of your MineCraft world list.", false, false);

            frmLogForm.UpdateLog("Finished at " + DateTime.Now.ToLocalTime(), false, true);
        }
Пример #30
0
        public static void MakeMineshaft(BetaWorld world, BlockManager bm, Buildings.structPoint spMineshaftEntrance, frmMace frmLogForm)
        {
            _intBlockStartBuildings = City.FarmLength + 13;
            int intMineshaftSize = (1 + City.MapLength) - (_intBlockStartBuildings * 2);

            if (intMineshaftSize % 5 > 0)
            {
                intMineshaftSize += 5 - (intMineshaftSize % 5);
            }
            _intBlockStartBuildings -= 2;
            for (int intLevel = 1; intLevel <= 7; intLevel++)
            {
                MakeLevel(world, bm, intLevel, intMineshaftSize, spMineshaftEntrance, frmLogForm);
            }
            int intBlockToReplace = bm.GetID(spMineshaftEntrance.x, 63, spMineshaftEntrance.z + 1);

            BlockShapes.MakeSolidBox(spMineshaftEntrance.x, spMineshaftEntrance.x,
                                     3, 63, spMineshaftEntrance.z + 1, spMineshaftEntrance.z + 1, BlockInfo.Wood.ID, 0);
            BlockHelper.MakeLadder(spMineshaftEntrance.x, 4, 63, spMineshaftEntrance.z, 0, BlockInfo.Wood.ID);
            BlockShapes.MakeSolidBox(spMineshaftEntrance.x, spMineshaftEntrance.x, 3, 63, spMineshaftEntrance.z + 1,
                                     spMineshaftEntrance.z + 1, BlockInfo.Stone.ID, 0);
            bm.SetID(spMineshaftEntrance.x, 63, spMineshaftEntrance.z + 1, intBlockToReplace);
        }