Пример #1
0
        private void ShowHelp(object sender, HelpEventArgs hlpevent)
        {
            string strHelp = String.Empty;

            switch (((Control)sender).Name)
            {
            case "btnAbout":
                strHelp = "You just clicked a question mark with a question mark. The world will now implode.";
                break;

            case "btnGenerateCity":
                strHelp = "This button will create a new world in your MineCraft saves directory, with a randomly generated city at the spawn point.\n\nMace doesn't interact with MineCraft directly, so you don't need MineCraft open.";
                break;

            case "picMace":
                strHelp = "Hiring all those graphics artists was definitely worth it.";
                break;
            }
            if (strHelp.Length == 0)
            {
                if (MessageBox.Show("Sorry, no help is available for this control :(\n\nWould you like to fire a random member of the Help Department?", "Help", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    Random randSeeds = new Random();
                    RandomHelper.SetSeed(randSeeds.Next());
                    MessageBox.Show("Thank you for submitting this request. We have now fired " + RandomHelper.RandomFileLine(Path.Combine("Resources", "HelpDepartment.txt")) + "\n\nYou monster.", "Requested granted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show(strHelp, "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Пример #2
0
 private void picMace_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         DateTime dtNow = new DateTime();
         dtNow = DateTime.Now;
         RandomHelper.SetSeed(dtNow.Millisecond);
         string strNames = String.Empty;
         for (int x = 0; x < 50; x++)
         {
             string strStart    = RandomHelper.RandomFileLine(Path.Combine("Resources", "Adjectives.txt"));
             string strEnd      = RandomHelper.RandomFileLine(Path.Combine("Resources", "Nouns.txt"));
             string strCityName = strStart + strEnd;
             strNames += strCityName + "\r\n";
         }
         MessageBox.Show(strNames);
     }
 }
Пример #3
0
 private void picMace_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         DateTime dtNow = new DateTime();
         dtNow = DateTime.Now;
         RandomHelper.SetSeed(dtNow.Millisecond);
         string strNames = "";
         for (int x = 0; x < 50; x++)
         {
             string strStart    = RandomHelper.RandomFileLine("Resources\\CityAdj.txt");
             string strEnd      = RandomHelper.RandomFileLine("Resources\\CityNoun.txt");
             string strCityName = "City of " + strStart + strEnd;
             strNames += strCityName + "\r\n";
         }
         MessageBox.Show(strNames);
     }
     else
     {
         MessageBox.Show(Environment.TickCount.ToString());
         RandomHelper.SetSeed(Environment.TickCount);
     }
 }
Пример #4
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.");
        }
Пример #5
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.");
        }
Пример #6
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.");
        }
Пример #7
0
        private void ShowHelp(object sender, HelpEventArgs hlpevent)
        {
            string strHelp = "";

            switch (((Control)sender).Name)
            {
            case "lblCitySize":
            case "cmbCitySize":
                strHelp = "Excluding the farms, each edge of the city is roughly:\n\nVery small - 80 blocks\nSmall - 128 blocks\nMedium - 192 blocks\nLarge - 256 blocks\nVery large - 400 blocks\n\nRandomly sized cities will be between 128 and 256 blocks on each edge.";
                break;

            case "lblMoatType":
            case "cmbMoatType":
                strHelp = "The moat is outside the city walls and goes all around the city. Choose a lava moat to increase your \"Oh &$£#!\" moments.";
                break;

            case "lblCityEmblem":
            case "cmbCityEmblem":
                strHelp = "City emblems appear on the outside walls, next to the four city entrances.";
                break;

            case "lblOutsideLights":
            case "cmbOutsideLights":
                strHelp = "This refers to the lights on the outside of the city walls.";
                break;

            case "lblTowerAddition":
            case "cmbTowerAddition":
                strHelp = "Fire beacons or flags give more character to the city and help you see the city from a distance.";
                break;

            case "lblWallMaterial":
            case "cmbWallMaterial":
                strHelp = "This refers to the walls that go all around the city. Selecting \"Random\" will choose a random normal material (brick, cobblestone, sandstone, stone, wood planks).";
                break;

            case "lblCityName":
            case "txtCityName":
                strHelp = "Use all your available intelligence, sarcasm and humour to come up with a city name. Alternatively, leave blank to let Mace generate a name for you. Mace won't overwrite worlds with the specified name.";
                break;

            case "lblCitySeed":
            case "txtCitySeed":
            case "lblWorldSeed":
            case "txtWorldSeed":
                strHelp = "This can be anything or nothing. For example:\n\nYour pet's name (Middy).\nYour favourite colour (Purple).\nYour favourite Buffy character (Willow).\nThe amount of blueberries you've eaten today (Seven and a half).\nThe name of your parole officer (Victor).\nHow many unicorns you've taught to fly (3).\nThe last person you vomitted all over (Mike).\nYour favourite piano tuner from Ukraine (Mikhaylyna).";
                break;

            case "chkIncludeFarms":
                strHelp = "Mace creates a variety of farms outside the city. The farms types are wheat, cactus, mushroom, sugarcane and orchards.";
                break;

            case "chkIncludeMoat":
                strHelp = "The moat is outside the city walls and goes all around the city.";
                break;

            case "chkIncludeDrawbridges":
                strHelp = "Unchecking this will make it rather tricky to enter the city!";
                break;

            case "chkIncludeGuardTowers":
                strHelp = "There's a guard tower at each corner of the city walls. They provide a high vantage point to see into and away from the city. They also make it easier to see the city from a distance.";
                break;

            case "chkIncludeWalls":
                strHelp = "Mace will generate four walls around the city. Unfortunately the fourth wall is frequently broken.";
                break;

            case "chkIncludeBuildings":
                strHelp = "Want to create your own buildings? Uncheck this!";
                break;

            case "chkIncludePaths":
                strHelp = "The city will have paths between the buildings. There's two main routes through the city, which have lights on either side.";
                break;

            case "chkIncludeMineshaft":
                strHelp = "The mineshaft is a large network of tunnels under the city, which spans multiple levels. It is full of resources and monsters.";
                break;

            case "chkValuableBlocks":
                strHelp = "Unchecking this will turn gold, iron, diamond, obsidian and lapis blocks into wool blocks. No sheep will be hurt during this process.";
                break;

            case "chkItemsInChests":
                strHelp = "Usually chests will contain appropriate or random items, to add more flavour to the city. Uncheck this if you'd like all chests to be empty.";
                break;

            case "txtLog":
                strHelp = "Information about the city generation will appear here.";
                break;

            case "btnAbout":
                strHelp = "You just clicked a question mark with a question mark. The world will now implode.";
                break;

            case "btnGenerateCity":
                strHelp = "This button will create a new world in your MineCraft saves directory, with a randomly generated city at the spawn point.\n\nMace doesn't interact with MineCraft directly, so you don't need MineCraft open.";
                break;

            case "picMace":
                strHelp = "Hiring all those graphics artists was definitely worth it.";
                break;
            }
            if (strHelp == "")
            {
                if (MessageBox.Show("Sorry, no help is available for this control :(\n\nWould you like to fire a random member of the Help Department?", "Help", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    Random randSeeds = new Random();
                    RandomHelper.SetSeed(randSeeds.Next());
                    MessageBox.Show("Thank you for submitting this request. We have now fired " + RandomHelper.RandomFileLine(Path.Combine("Resources", "HelpDepartment.txt")) + "\n\nYou monster.", "Requested granted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show(strHelp, "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }