示例#1
0
        public static void CropMaceWorld(frmMace frmLogForm)
        {
            // thank you to Surrogard <*****@*****.**> for providing a linux friendly version of this code:
            Directory.CreateDirectory("macecopy".ToMinecraftSaveDirectory());
            AnvilWorld         awCopy = AnvilWorld.Create("macecopy".ToMinecraftSaveDirectory());
            RegionChunkManager cmCopy = awCopy.GetChunkManager();
            AnvilWorld         awCrop = AnvilWorld.Open("mace".ToMinecraftSaveDirectory());
            RegionChunkManager cmCrop = awCrop.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();
            }
            awCopy.Level.GameType = GameType.CREATIVE;
            cmCopy.Save();
            awCopy.Save();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                Process.Start("explorer.exe", @"/select," + "macecopy".ToMinecraftSaveDirectory() + "\\level.dat");
            }
        }
示例#2
0
        public static void PositionRails(AnvilWorld worldDest, BlockManager bm)
        {
            // todo low: different elevations
            int intReplaced = 0;

            for (int x = 0; x < City.mapLength; x++)
            {
                for (int z = -City.farmLength; z < City.mapLength; z++)
                {
                    for (int y = 0; y < 128; y++)
                    {
                        switch (bm.GetID(x, y, z))
                        {
                        case BlockType.POWERED_RAIL:
                        case BlockType.DETECTOR_RAIL:
                        case BlockType.RAILS:
                            BlockHelper.MakeRail(x, y, z);
                            if (++intReplaced > 100)
                            {
                                worldDest.Save();
                                intReplaced = 0;
                            }
                            break;
                        }
                    }
                }
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("You must specify a target directory");
                return;
            }
            string dest = args[0];

            AnvilWorld   world = AnvilWorld.Open("F:\\Minecraft\\test");
            BlockManager bm    = world.GetBlockManager();

            bm.AutoLight = false;

            Grid grid = new Grid();

            grid.BuildInit(bm);

            Generator             gen   = new Generator();
            List <Generator.Edge> edges = gen.Generate();

            foreach (Generator.Edge e in edges)
            {
                int x1;
                int y1;
                int z1;
                gen.UnIndex(e.node1, out x1, out y1, out z1);

                int x2;
                int y2;
                int z2;
                gen.UnIndex(e.node2, out x2, out y2, out z2);

                grid.LinkRooms(bm, x1, y1, z1, x2, y2, z2);
            }

            // Entrance Room
            grid.BuildRoom(bm, 2, 5, 2);
            grid.LinkRooms(bm, 2, 5, 2, 1, 5, 2);
            grid.LinkRooms(bm, 2, 5, 2, 3, 5, 2);
            grid.LinkRooms(bm, 2, 5, 2, 2, 5, 1);
            grid.LinkRooms(bm, 2, 5, 2, 2, 5, 3);
            grid.LinkRooms(bm, 2, 4, 2, 2, 5, 2);

            // Exit Room
            grid.BuildRoom(bm, 2, -1, 2);
            grid.LinkRooms(bm, 2, -1, 2, 2, 0, 2);
            grid.AddPrize(bm, 2, -1, 2);

            Console.WriteLine("Relight Chunks");

            RegionChunkManager cm = world.GetChunkManager();

            cm.RelightDirtyChunks();

            world.Save();
        }
示例#4
0
 public static void MoveChunks(AnvilWorld world, RegionChunkManager cm, int CityX, int CityZ)
 {
     cm.Save();
     world.Save();
     for (int x = 0; x < City.mapLength / 16; x++)
     {
         for (int z = -City.farmLength / 16; z < City.mapLength / 16; z++)
         {
             cm.CopyChunk(x, z, CityX + x + CITY_RELOCATION_CHUNKS, CityZ + z + CITY_RELOCATION_CHUNKS);
             ChunkRef chunkActive = cm.GetChunkRef(CityX + x + CITY_RELOCATION_CHUNKS, CityZ + z + CITY_RELOCATION_CHUNKS);
             chunkActive.IsTerrainPopulated = true;
             chunkActive.Blocks.AutoLight   = true;
             biomes.Add(chunkActive.X + "." + chunkActive.Z, City.biome);
             cm.DeleteChunk(x, z);
             cm.Save();
             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);
 }
        public void ExportMap(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            string           path   = e.Argument as string;

            worker.ReportProgress(0, "Exporting map to " + path);

            AnvilWorld world = AnvilWorld.Create(path);

            world.Level.LevelName = "Dwarf Fortress World";
            world.Level.GameType  = GameType.CREATIVE;
            world.Level.Spawn     = new SpawnPoint(36, 255, 36);
            world.Save();
            var chunkManager = world.GetChunkManager();
            int total        = (Tiles[0].Height * tileWidth / 16) * (Tiles[0].Width * tileWidth / 16);
            int done         = 0;

            for (int chunkZ = 0; chunkZ < Tiles[0].Height * tileWidth / 16; chunkZ++)
            {
                for (int chunkX = 0; chunkX < Tiles[0].Width * tileWidth / 16; chunkX++)
                {
                    var chunk  = chunkManager.CreateChunk(chunkX, chunkZ);
                    var blocks = chunk.Blocks;
                    blocks.AutoLight         = false;
                    chunk.IsTerrainPopulated = true;
                    int chunkY = 0;
                    foreach (var level in Tiles)
                    {
                        if (!level.Enabled)
                        {
                            continue;
                        }
                        for (int y = 0; y < tileHeight; y++)
                        {
                            for (int z = 0; z < 16; z++)
                            {
                                for (int x = 0; x < 16; x++)
                                {
                                    blocks.SetBlock(x, y + (chunkY * tileHeight), z,
                                                    level.GetBlock(x + (chunkX * 16), y, z + (chunkZ * 16)));
                                }
                            }
                        }
                        chunkY++;
                    }
                    blocks.RebuildSkyLight();
                    blocks.RebuildBlockLight();
                    blocks.RebuildHeightMap();
                    chunkManager.Save();
                    done++;
                    worker.ReportProgress(done * 100 / total, "Generating Chunks");
                }
            }
            worker.ReportProgress(100, "Finished exporting map");
        }
示例#7
0
        private static structPoint MakeBuildings(BlockManager bm, int[,] intArea, int intBlockStart, AnvilWorld world)
        {
            structPoint structLocationOfMineshaftEntrance = new structPoint();
            structLocationOfMineshaftEntrance.x = -1;
            structLocationOfMineshaftEntrance.z = -1;
            int intBuildings = 0;
            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int z = 0; z < intArea.GetLength(1); z++)
                {
                    // hack low: this 100 to 500 stuff is all a bit hackish really, need to find a proper solution
                    if (intArea[x, z] >= 100 && intArea[x, z] <= 500)
                    {
                        SourceWorld.Building CurrentBuilding = SourceWorld.GetBuilding(intArea[x, z] - 100);
                        SourceWorld.InsertBuilding(bm, intArea, intBlockStart, x, z, CurrentBuilding, 0, -1);

                        if (CurrentBuilding.BuildingType == SourceWorld.BuildingTypes.MineshaftEntrance)
                        {
                            structLocationOfMineshaftEntrance.x = intBlockStart + x + (int)(CurrentBuilding.intSizeX / 2);
                            structLocationOfMineshaftEntrance.z = intBlockStart + z + (int)(CurrentBuilding.intSizeZ / 2);
                            if (City.hasSkyFeature)
                            {
                                SourceWorld.Building BalloonBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.SkyFeature, 0);
                                SourceWorld.InsertBuilding(bm, new int[0, 0], intBlockStart,
                                                           x + ((CurrentBuilding.intSizeX - BalloonBuilding.intSizeX) / 2),
                                                           z + ((CurrentBuilding.intSizeZ - BalloonBuilding.intSizeZ) / 2),
                                                           BalloonBuilding, 0, -1);
                            }
                        }

                        intArea[x + CurrentBuilding.intSizeX - 2, z + CurrentBuilding.intSizeZ - 2] = 0;
                        if (++intBuildings == NumberOfBuildingsBetweenSaves)
                        {
                            world.Save();
                            intBuildings = 0;
                        }
                    }
                }
            }
            world.Save();
            return structLocationOfMineshaftEntrance;
        }
示例#8
0
        public static void save()
        {
            if (reg != null)
            {
                Undo.clear();

                startThread(RunThread.SaveLayer);

                lvl.Save();
            }
        }
示例#9
0
        public static void ReplaceValuableBlocks(AnvilWorld worldDest, BlockManager bm)
        {
            int intReplaced = 0;

            for (int x = 0; x < City.mapLength; x++)
            {
                for (int z = -City.farmLength; z < City.mapLength; z++)
                {
                    for (int y = 40; y < 128; y++)
                    {
                        if (bm.GetID(x, y, z) != City.wallMaterialID ||
                            bm.GetData(x, y, z) != City.wallMaterialData)
                        {
                            switch ((int)bm.GetID(x, y, z))
                            {
                            case BlockType.GOLD_BLOCK:
                                BlockShapes.MakeBlock(x, y, z, BlockInfo.Wool.ID, (int)WoolColor.YELLOW);
                                intReplaced++;
                                break;

                            case BlockType.IRON_BLOCK:
                                BlockShapes.MakeBlock(x, y, z, BlockInfo.Wool.ID, (int)WoolColor.LIGHT_GRAY);
                                intReplaced++;
                                break;

                            case BlockType.OBSIDIAN:
                                BlockShapes.MakeBlock(x, y, z, BlockInfo.Wool.ID, (int)WoolColor.BLACK);
                                intReplaced++;
                                break;

                            case BlockType.DIAMOND_BLOCK:
                                BlockShapes.MakeBlock(x, y, z, BlockInfo.Wool.ID, (int)WoolColor.LIGHT_BLUE);
                                intReplaced++;
                                break;

                            case BlockType.LAPIS_BLOCK:
                                BlockShapes.MakeBlock(x, y, z, BlockInfo.Wool.ID, (int)WoolColor.BLUE);
                                intReplaced++;
                                break;
                                // no need for a default, because we purposefully want to skip all the other blocks
                            }
                            if (intReplaced > 25)
                            {
                                worldDest.Save();
                                intReplaced = 0;
                            }
                        }
                    }
                }
            }
        }
示例#10
0
 public static structPoint MakeInsideCity(BlockManager bm, AnvilWorld worldDest, int[,] intArea, frmMace frmLogForm)
 {
     int intBlockStart = City.edgeLength + 13;
     structPoint spMineshaftEntrance = MakeBuildings(bm, intArea, intBlockStart, worldDest);
     worldDest.Save();
     if (City.hasPaths)
     {
         JoinPathsToRoad(bm);
     }
     else
     {
         RemovePaths(bm, intArea, intBlockStart);
     }
     if (City.hasMainStreets)
     {
         frmLogForm.UpdateLog("Creating street lights: " + City.streetLightType, true, true);
         MakeStreetLights(bm);
     }
     return spMineshaftEntrance;
 }
示例#11
0
        // this is a simplified version of the MakeBuildings method from Buildings.cs
        private static void MakeBuildings(BlockManager bm, int[,] intArea, AnvilWorld world)
        {
            int intBuildings = 0;

            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int z = 0; z < intArea.GetLength(1); z++)
                {
                    // hack low: this 100 to 500 stuff is all a bit hackish really, need to find a proper solution
                    if (intArea[x, z] >= 100 && intArea[x, z] <= 500)
                    {
                        SourceWorld.Building CurrentBuilding = SourceWorld.GetBuilding(intArea[x, z] - 100);

                        if (CurrentBuilding.intSizeX >= 10 && RNG.NextDouble() > 0.8)
                        {
                            if (RNG.NextDouble() > 0.5)
                            {
                                MakePond(bm, 6 + x, CurrentBuilding.intSizeX, (6 - City.farmLength) + z, CurrentBuilding.intSizeZ);
                            }
                            else
                            {
                                MakeHill(bm, 6 + x, CurrentBuilding.intSizeX, (6 - City.farmLength) + z, CurrentBuilding.intSizeZ);
                            }
                        }
                        else
                        {
                            SourceWorld.InsertBuilding(bm, intArea, 0, 6 + x, (6 - City.farmLength) + z, CurrentBuilding, 0, -1);
                        }

                        intArea[x + CurrentBuilding.intSizeX - 2, z + CurrentBuilding.intSizeZ - 2] = 0;
                        if (++intBuildings == NumberOfBuildingsBetweenSaves)
                        {
                            world.Save();
                            intBuildings = 0;
                        }
                    }
                }
            }
        }
示例#12
0
        public static void MakeFlowers(AnvilWorld worldDest, BlockManager bm)
        {
            string[] strFlowers  = Utils.ArrayFromXMLElement(Path.Combine("Resources", "Themes", City.themeName + ".xml"), "options", "flowers");
            int      FlowerCount = 0;

            for (int x = 0; x <= City.mapLength; x++)
            {
                for (int z = -City.farmLength; z <= City.mapLength; z++)
                {
                    if (bm.GetID(x, 63, z) == City.groundBlockID &&
                        bm.GetID(x, 64, z) == BlockInfo.Air.ID)
                    {
                        int FreeNeighbours = 0;
                        for (int xCheck = x - 1; xCheck <= x + 1; xCheck++)
                        {
                            for (int zCheck = z - 1; zCheck <= z + 1; zCheck++)
                            {
                                if (bm.GetID(xCheck, 63, zCheck) == City.groundBlockID &&
                                    bm.GetID(xCheck, 64, zCheck) == BlockInfo.Air.ID)
                                {
                                    FreeNeighbours++;
                                }
                            }
                        }
                        if (FreeNeighbours >= MinimumFreeNeighboursNeededForFlowers && RNG.NextDouble() * 100 <= City.flowerSpawnPercent)
                        {
                            AddFlowersToBlock(bm, x, z, FreeNeighbours, RNG.RandomItemFromArray(strFlowers));
                            if (++FlowerCount >= NumberOfFlowersBetweenSaves)
                            {
                                worldDest.Save();
                                FlowerCount = 0;
                            }
                        }
                    }
                }
            }
        }
示例#13
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);
        }
示例#14
0
        // todo low: this is way too big
        private static void MakeLevel(AnvilWorld 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.ValueFromXMLElement(
                Path.Combine("Resources", "Mineshaft.xml"), "level" + intDepth, "chances").Split(',').StringArrayToIntArray();
            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 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 = RNG.RandomItem(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) &&
                                RNG.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) &&
                                     RNG.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), -1);
            }
            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
        }
示例#15
0
        public static bool Generate(frmMace frmLogForm, AnvilWorld worldDest, RegionChunkManager cmDest, BlockManager bmDest,
                                    int x, int z, bool booExportSchematics, string strUndergroundOres)
        {
            #region create a city name
            string strStart, strEnd;
            do
            {
                strStart  = RNG.RandomFileLine(Path.Combine("Resources", City.cityNamePrefixFilename));
                strEnd    = RNG.RandomFileLine(Path.Combine("Resources", City.cityNameSuffixFilename));
                City.name = City.cityNamePrefix + strStart + strEnd;
            } while (GenerateWorld.lstCityNames.Contains(City.name) ||
                     strStart.ToLower().Trim() == strEnd.ToLower().Trim() ||
                     (strStart + strEnd).Length > 14);
            GenerateWorld.lstCityNames.Add(City.name);
            #endregion

            #region determine block sizes
            City.cityLength *= 16;
            City.farmLength *= 16;
            City.edgeLength  = 8;
            City.mapLength   = City.cityLength + (City.edgeLength * 2);
            #endregion

            #region setup classes
            BlockShapes.SetupClass(bmDest, cmDest);
            BlockHelper.SetupClass(bmDest);
            NoticeBoard.SetupClass();
            if (!SourceWorld.SetupClass(worldDest))
            {
                return(false);
            }
            #endregion

            #region determine random options
            switch (City.wallMaterialID)
            {
            case BlockType.ICE:
                City.hasTorchesOnWalkways = false;
                City.outsideLightType     = "None";
                switch (City.moatType)
                {
                case "Fire":
                case "Lava":
                    frmLogForm.UpdateLog("Fixing disaster configuration", true, true);
                    City.moatType = "Water";
                    break;
                }
                break;

            case BlockType.WOOD_PLANK:
            case BlockType.WOOD:
            case BlockType.LEAVES:
            case BlockType.VINES:
            case BlockType.WOOL:
            case BlockType.BOOKSHELF:
                switch (City.outsideLightType)
                {
                case "Fire":
                    frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true);
                    City.outsideLightType = "Torches";
                    break;
                }
                switch (City.moatType)
                {
                case "Fire":
                case "Lava":
                    frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true);
                    City.moatType = "Water";
                    break;
                }
                break;
            }
            switch (City.pathType.ToLower().Trim())
            {
            case "stone_raised":
                City.pathBlockID              = BlockInfo.DoubleStoneSlab.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = BlockInfo.StoneSlab.ID;
                City.pathAlternativeBlockData = (int)SlabType.STONE;
                City.pathExtends              = 2;
                break;

            case "sandstone_raised":
                City.pathBlockID              = BlockInfo.Sandstone.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = BlockInfo.StoneSlab.ID;
                City.pathAlternativeBlockData = (int)SlabType.SANDSTONE;
                City.pathExtends              = 2;
                break;

            case "wood_planks_raised":
            case "woodplanks_raised":
                City.pathBlockID              = BlockInfo.WoodPlank.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = BlockInfo.StoneSlab.ID;
                City.pathAlternativeBlockData = (int)SlabType.WOOD;
                City.pathExtends              = 2;
                break;

            case "cobblestone_raised":
                City.pathBlockID              = BlockInfo.Cobblestone.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = BlockInfo.StoneSlab.ID;
                City.pathAlternativeBlockData = (int)SlabType.COBBLESTONE;
                City.pathExtends              = 2;
                break;

            case "brick_raised":
                City.pathBlockID              = BlockInfo.BrickBlock.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = BlockInfo.StoneSlab.ID;
                City.pathAlternativeBlockData = (int)SlabType.BRICK;
                City.pathExtends              = 2;
                break;

            case "stonebrick_raised":
                City.pathBlockID              = BlockInfo.StoneBrick.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = BlockInfo.StoneSlab.ID;
                City.pathAlternativeBlockData = (int)SlabType.STONE_BRICK;
                City.pathExtends              = 2;
                break;

            case "stonebrick":
                City.pathBlockID              = BlockInfo.StoneBrick.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = 0;
                City.pathAlternativeBlockData = 0;
                City.pathExtends              = 1;
                break;

            case "sandstone":
                City.pathBlockID              = BlockInfo.Sandstone.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = 0;
                City.pathAlternativeBlockData = 0;
                City.pathExtends              = 1;
                break;

            case "stone":
                City.pathBlockID              = BlockInfo.Stone.ID;
                City.pathBlockData            = 0;
                City.pathAlternativeBlockID   = 0;
                City.pathAlternativeBlockData = 0;
                City.pathExtends              = 1;
                break;

            case "wood":
                City.pathBlockID              = BlockInfo.Wood.ID;
                City.pathBlockData            = RNG.Next(0, 2);
                City.pathAlternativeBlockID   = 0;
                City.pathAlternativeBlockData = 0;
                City.pathExtends              = 1;
                break;
            }
            #endregion

            #region make the city
            frmLogForm.UpdateLog("Creating the " + City.name, false, false);
            frmLogForm.UpdateLog("City length in blocks: " + City.mapLength, true, true);
            frmLogForm.UpdateLog("Edge length in blocks: " + City.edgeLength, true, true);
            frmLogForm.UpdateLog("Farm length in blocks: " + City.farmLength, true, true);
            frmLogForm.UpdateLog("City position in blocks: " + ((x + Chunks.CITY_RELOCATION_CHUNKS) * 16) + "," +
                                 ((z + Chunks.CITY_RELOCATION_CHUNKS) * 16), true, true);
            frmLogForm.UpdateLog("Theme: " + City.themeName, true, true);
            frmLogForm.UpdateLog("Creating underground terrain", true, false);
            Chunks.CreateInitialChunks(cmDest, frmLogForm, strUndergroundOres);
            frmLogForm.UpdateProgress(0.21);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

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

            if (City.hasWalls)
            {
                frmLogForm.UpdateLog("Creating walls", true, false);
                Walls.MakeWalls(worldDest, frmLogForm);
            }
            frmLogForm.UpdateProgress(0.24);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            if (City.hasDrawbridges)
            {
                frmLogForm.UpdateLog("Creating entrances", true, false);
                Entrances.MakeEntrances(bmDest);
            }
            frmLogForm.UpdateProgress(0.27);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            if (City.hasMoat)
            {
                frmLogForm.UpdateLog("Creating moat", true, false);
                Moat.MakeMoat(frmLogForm, bmDest);
            }
            frmLogForm.UpdateProgress(0.30);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            if (City.hasBuildings || City.hasPaths)
            {
                frmLogForm.UpdateLog("Creating paths", true, false);
                frmLogForm.UpdateLog("Path type: " + City.pathType, true, true);
                int[,] intArea = Paths.MakePaths(worldDest, bmDest);
                frmLogForm.UpdateProgress(0.33);
                if (City.hasBuildings)
                {
                    frmLogForm.UpdateLog("Creating buildings", true, false);
                    spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, frmLogForm);
                    frmLogForm.UpdateProgress(0.36);
                    if (City.hasMineshaft)
                    {
                        frmLogForm.UpdateLog("Creating mineshaft", true, false);
                        Mineshaft.MakeMineshaft(worldDest, bmDest, spMineshaftEntrance, frmLogForm);
                    }
                }
            }
            frmLogForm.UpdateProgress(0.39);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            if (City.hasGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers", true, false);
                GuardTowers.MakeGuardTowers(bmDest, frmLogForm);
            }
            frmLogForm.UpdateProgress(0.42);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            if (City.hasFarms)
            {
                frmLogForm.UpdateLog("Creating farms", true, false);
                Farms2.MakeFarms(worldDest, bmDest);
            }
            frmLogForm.UpdateProgress(0.45);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            if (City.hasFlowers)
            {
                frmLogForm.UpdateLog("Creating flowers", true, false);
                Flowers.MakeFlowers(worldDest, bmDest);
            }
            frmLogForm.UpdateProgress(0.46);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            if (!City.hasValuableBlocks)
            {
                frmLogForm.UpdateLog("Replacing valuable blocks", true, true);
                cmDest.Save();
                worldDest.Save();
                Chunks.ReplaceValuableBlocks(worldDest, bmDest);
            }
            frmLogForm.UpdateProgress(0.48);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            frmLogForm.UpdateLog("Creating rail data", true, false);
            Chunks.PositionRails(worldDest, bmDest);
            frmLogForm.UpdateProgress(0.50);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }

            frmLogForm.UpdateLog("Creating lighting data", true, false);
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm);
            frmLogForm.UpdateProgress(0.95);
            if (CheckCancelled(worldDest, frmLogForm))
            {
                return(false);
            }
            #endregion

            #region export schematic
            if (booExportSchematics)
            {
                frmLogForm.UpdateLog("Creating schematic in world folder", true, false);
                AlphaBlockCollection abcExport = new AlphaBlockCollection(City.mapLength, 128, City.mapLength + City.farmLength);
                for (int xBlock = 0; xBlock < City.mapLength; xBlock++)
                {
                    for (int zBlock = -City.farmLength; zBlock < City.mapLength; zBlock++)
                    {
                        for (int y = 0; y < 128; y++)
                        {
                            abcExport.SetBlock(xBlock, y, City.farmLength + zBlock, bmDest.GetBlock(xBlock, y, zBlock));
                        }
                    }
                }
                Schematic CitySchematic = new Schematic(City.mapLength, 128, City.mapLength + City.farmLength);
                CitySchematic.Blocks = abcExport;
                CitySchematic.Export(worldDest.Path + "\\" + City.name + ".schematic");
            }
            #endregion

            #region positioning
            frmLogForm.UpdateLog("Creating position data", true, false);
            Chunks.MoveChunks(worldDest, cmDest, x, z);
            frmLogForm.UpdateProgress(1);
            #endregion
            return(true);
        }
示例#16
0
        private static void MakePaths(AnvilWorld world, BlockManager bm, int[,] intArea)
        {
            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int z = 0; z < intArea.GetLength(1); z++)
                {
                    if (intArea[x, z] == 1)
                    {
                        if (Math.Abs(x - (intArea.GetLength(0) / 2)) == City.pathExtends + 1 &&
                            Math.Abs(z - (intArea.GetLength(1) / 2)) == City.pathExtends + 1)
                        {
                            // don't need these
                        }
                        else if (Math.Abs(x - (intArea.GetLength(0) / 2)) == (City.pathExtends + 1) ||
                                 Math.Abs(z - (intArea.GetLength(1) / 2)) == (City.pathExtends + 1))
                        {
                            if (City.hasMainStreets && MultipleNeighbouringPaths(intArea, x, z))
                            {
                                bm.SetID(_intBlockStart + x, 63, _intBlockStart + z, City.pathBlockID);
                                bm.SetData(_intBlockStart + x, 63, _intBlockStart + z, City.pathBlockData);
                            }
                        }
                        else
                        {
                            bm.SetID(_intBlockStart + x, 63, _intBlockStart + z, City.pathBlockID);
                            bm.SetData(_intBlockStart + x, 63, _intBlockStart + z, City.pathBlockData);
                        }
                        if (City.hasMainStreets && City.pathAlternativeBlockID > 0)
                        {
                            if (x > 0 && z > 0 && x < intArea.GetUpperBound(0) && z < intArea.GetUpperBound(1))
                            {
                                if (Math.Abs(x - (intArea.GetLength(0) / 2)) == City.pathExtends ||
                                    Math.Abs(z - (intArea.GetLength(1) / 2)) == City.pathExtends)
                                {
                                    if (Math.Abs(x - (intArea.GetLength(0) / 2)) >= City.pathExtends &&
                                        Math.Abs(z - (intArea.GetLength(1) / 2)) >= City.pathExtends)
                                    {
                                        bm.SetID(_intBlockStart + x, 64, _intBlockStart + z, City.pathAlternativeBlockID);
                                        bm.SetData(_intBlockStart + x, 64, _intBlockStart + z, City.pathAlternativeBlockData);
                                    }
                                }
                            }
                        }
                    }
                }
                if (x % 20 == 0)
                {
                    world.Save();
                }
            }
            if (City.hasMainStreets)
            {
                for (int a = 0; a <= intArea.GetUpperBound(0); a++)
                {
                    if (a % 8 == 0)
                    {
                        switch (City.npcs)
                        {
                        case "Ghostdancer's NPCs":
                            EntityVillager eVillager = new EntityVillager(new TypedEntity("GPoor"));
                            switch (RNG.Next(2))
                            {
                            case 0:
                                eVillager = new EntityVillager(new TypedEntity("GPoor"));
                                break;

                            case 1:
                                eVillager = new EntityVillager(new TypedEntity("GRich"));
                                break;

                            case 2:
                                eVillager = new EntityVillager(new TypedEntity("GMaid"));
                                break;
                            }
                            eVillager.Health = 20;
                            BlockShapes.MakeEntity(_intBlockStart + a, 65, _intBlockStart + (intArea.GetUpperBound(0) / 2), eVillager, 0);
                            BlockShapes.MakeEntity(_intBlockStart + (intArea.GetUpperBound(0) / 2), 65, _intBlockStart + a, eVillager, 0);
                            break;

                        case "Minecraft Villagers":
                            EntityVillager eMob = new EntityVillager();
                            eMob.Health = 20;
                            BlockShapes.MakeEntity(_intBlockStart + a, 65, _intBlockStart + (intArea.GetUpperBound(0) / 2), eMob, 0);
                            BlockShapes.MakeEntity(_intBlockStart + (intArea.GetUpperBound(0) / 2), 65, _intBlockStart + a, eMob, 0);
                            break;
                        }
                    }
                    for (int c = -City.pathExtends; c <= City.pathExtends; c++)
                    {
                        intArea[a, (intArea.GetUpperBound(0) / 2) + c] = 1;
                        intArea[(intArea.GetUpperBound(0) / 2) + c, a] = 1;
                    }
                }
            }
        }
示例#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
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: BlockReplace <world> <jsonFile>");
                return;
            }

            StreamReader streamReader = new StreamReader(args [1]);
            string       json         = streamReader.ReadToEnd();

            streamReader.Close();

            JObject o = JObject.Parse(json);


            IList <int> elevations = o.SelectToken("elevation-flat").Select(s => (int)s).ToList();

            Console.WriteLine("Load Elevations...");
            string dest = args [0];

            AnvilWorld   world = AnvilWorld.Open(dest);
            BlockManager bm    = world.GetBlockManager();

            bm.AutoLight = true;


            // Set Elevations
            int i = 0;

            while (i < elevations.Count)
            {
                if (i % 100 == 0)
                {
                    //RegionChunkManager cm = world.GetChunkManager();
                    //cm.RelightDirtyChunks();
                }
                int el = elevations[i];
                int x  = i / 1001 | 0;
                int y  = i % 1001;
                x  = 1001 - x; // Symetry
                x -= 500;
                y -= 500;

                bm.SetID(x, el, y, (int)BlockType.GRASS);

                if (el > 1)
                {
                    bm.SetID(x, el - 1, y, (int)BlockType.DIRT);
                }
                if (el > 2)
                {
                    bm.SetID(x, el - 2, y, (int)BlockType.DIRT);
                }
                if (el > 3)
                {
                    bm.SetID(x, el - 3, y, (int)BlockType.DIRT);
                }
                if (el > 4)
                {
                    bm.SetID(x, el - 4, y, (int)BlockType.DIRT);
                }
                ++i;
            }

            Console.WriteLine("Load Mods...");
            IList <int> mods = o.SelectToken("mods").Select(s => (int)s).ToList();

            Console.WriteLine(mods.Count);
            i = 0;
            while (i < mods.Count - 4)
            {
                int x = (int)mods [i++];
                int y = (int)mods [i++];
                int z = (int)mods [i++];
                int t = (int)mods [i++];

                if (t > 126)
                {
                    Console.WriteLine("Failed");
                    Console.WriteLine(t);
                    Console.WriteLine(x);
                    Console.WriteLine(y);
                    Console.WriteLine(z);
                    continue;
                }

                x = 1001 - x; // Symetry

                x -= 500;
                y -= 500;
                // Check if valid block
                if (t < 256 && z > 0 && z <= 255)
                {
                    bm.SetID(x, z, y, t);
                }
            }
            Console.WriteLine("over generation");

            world.Save();
        }
示例#19
0
 public static void MakeFarms(AnvilWorld world, BlockManager bm)
 {
     world.Save();
     MakeBuildings(bm, FillArea(City.mapLength - 12, City.farmLength - 4), world);
     world.Save();
 }
示例#20
0
        public static void ResetLighting(AnvilWorld world, RegionChunkManager cm, frmMace frmLogForm)
        {
            int intChunksProcessed = 0, 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)
            {
                if (chunk.IsTerrainPopulated)
                {
                    if (chunk.X * 16 >= 0 &&
                        chunk.X * 16 <= City.mapLength &&
                        chunk.Z * 16 >= -City.farmLength &&
                        chunk.Z * 16 <= City.mapLength)
                    {
                        // we process each chunk twice, hence this:
                        intTotalChunks += 2;
                    }
                }
            }
            foreach (ChunkRef chunk in cm)
            {
                if (chunk.IsTerrainPopulated)
                {
                    if (chunk.X * 16 >= 0 &&
                        chunk.X * 16 <= City.mapLength &&
                        chunk.Z * 16 >= -City.farmLength &&
                        chunk.Z * 16 <= City.mapLength)
                    {
                        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(0.5 + (intChunksProcessed * 0.45 / intTotalChunks));
                        }
                    }
                }
            }
            foreach (ChunkRef chunk in cm)
            {
                if (chunk.IsTerrainPopulated)
                {
                    if (chunk.X * 16 >= 0 &&
                        chunk.X * 16 <= City.mapLength &&
                        chunk.Z * 16 >= -City.farmLength &&
                        chunk.Z * 16 <= City.mapLength)
                    {
                        try
                        {
                            chunk.Blocks.RebuildBlockLight();
                            chunk.Blocks.RebuildSkyLight();
                        }
                        catch (Exception)
                        {
                            Debug.WriteLine("Chunk rebuild light fail");
                        }
                        if (++intChunksProcessed % 10 == 0)
                        {
                            cm.Save();
                            frmLogForm.UpdateProgress(0.5 + (intChunksProcessed * 0.45 / intTotalChunks));
                        }
                    }
                }
            }
            world.Save();
        }