Ejemplo n.º 1
0
        private static int[,] FillArea(int[,] intArea, int intSizeX, int intSizeZ, int intStartX, int intStartZ, bool booUniqueBonus)
        {
            int[,] intDistrict = new int[intSizeX, intSizeZ];
            int[,] intFinal    = new int[intSizeX, intSizeZ];
            int        intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0;
            int        intBonus              = 0;
            List <int> lstBuildings          = new List <int>();
            List <int> lstAcceptedBuildings  = new List <int>();
            bool       booAreaNeedsMineshaft = false;

            do
            {
                lstBuildings.Clear();
                intBonus = 0;
                if (!_booIncludedMineshaft)
                {
                    booAreaNeedsMineshaft = true;
                }
                do
                {
                    SourceWorld.Building CurrentBuilding;
                    if (booAreaNeedsMineshaft)
                    {
                        CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.MineshaftEntrance, 0);
                        // mineshaft is always the first building, so therefore it will always be possible to place it
                        booAreaNeedsMineshaft = false;
                    }
                    else
                    {
                        do
                        {
                            CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.City, 0);
                        } while (!IsValidBuilding(CurrentBuilding, lstBuildings, intArea,
                                                  intStartX, intStartZ, intSizeX, intSizeZ));
                    }
                    bool booFound = false;
                    if (RNG.NextDouble() > 0.5)
                    {
                        intDistrict = intDistrict.RotateArray(RNG.Next(4));
                    }
                    int x, z = 0;
                    for (x = 0; x < intDistrict.GetLength(0) - CurrentBuilding.intSizeX && !booFound; x++)
                    {
                        for (z = 0; z < intDistrict.GetLength(1) - CurrentBuilding.intSizeZ && !booFound; z++)
                        {
                            booFound = intDistrict.IsArraySectionAllZeros2D(x, z, x + CurrentBuilding.intSizeX, z + CurrentBuilding.intSizeZ);
                        }
                    }
                    x--;
                    z--;
                    if (booFound)
                    {
                        for (int a = x + 1; a <= x + CurrentBuilding.intSizeX - 1; a++)
                        {
                            for (int b = z + 1; b <= z + CurrentBuilding.intSizeZ - 1; b++)
                            {
                                intDistrict[a, b] = 2;
                            }
                        }
                        if (CurrentBuilding.booUnique && booUniqueBonus)
                        {
                            // we want to include the unique buildings,
                            //   so we give a slight preference to those

                            intBonus += 15;
                        }
                        lstBuildings.Add(CurrentBuilding.intID);
                        intDistrict[x + 1, z + 1] = 100 + CurrentBuilding.intID;
                        intDistrict[x + CurrentBuilding.intSizeX - 1,
                                    z + CurrentBuilding.intSizeZ - 1] = 100 + CurrentBuilding.intID;
                        intFail = 0;
                    }
                    else
                    {
                        intFail++;
                    }
                } while (intFail < 10);

                int intCurWasted = Utils.ZerosInArray2D(intDistrict) - intBonus;
                if (intCurWasted < intWasted)
                {
                    intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)];
                    Array.Copy(intDistrict, intFinal, intDistrict.Length);
                    intWasted   = intCurWasted;
                    intAttempts = 10;
                    lstAcceptedBuildings.Clear();
                    lstAcceptedBuildings.AddRange(lstBuildings);
                }
                Array.Clear(intDistrict, 0, intDistrict.Length);
                intAttempts--;
            } while (intAttempts > 0);
            if (intSizeX == intFinal.GetLength(1))
            {
                intFinal = intFinal.RotateArray(1);
            }
            _lstAllBuildings.AddRange(lstAcceptedBuildings);
            _booIncludedMineshaft = true;
            return(intFinal);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private static void MakeHill(BlockManager bm, int x, int xlen, int z, int zlen)
        {
            int[,] intArea = new int[xlen, zlen];
            int a, b;

            int c = 0, d = 0, clen = -1, dlen = -1;

            if (xlen >= 8 && zlen >= 8)
            {
                c    = RNG.Next(1, intArea.GetUpperBound(0) - 7);
                d    = RNG.Next(1, intArea.GetUpperBound(1) - 7);
                clen = RNG.Next(3, 5);
                dlen = RNG.Next(3, 5);
            }

            for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++)
            {
                for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++)
                {
                    if (a < c || a > c + clen || b < d || b > d + dlen)
                    {
                        intArea[a, b] = 1;
                    }
                }
            }

            intArea = CheckAgainstNeighbours(intArea, 0, 0, 7, 0, RNG.Next(7, 11), true);
            intArea = CheckAgainstNeighbours(intArea, 6, 0, 3, 2, 1, false);
            intArea = CheckAgainstNeighbours(intArea, 14, 0, 3, 3, 1, false);

            for (a = 1; a < intArea.GetUpperBound(0); a++)
            {
                for (b = 1; b < intArea.GetUpperBound(1); b++)
                {
                    for (int y = 1; y <= intArea[a, b]; y++)
                    {
                        if (y == intArea[a, b])
                        {
                            bm.SetID(x + a, y + 63, z + b, BlockInfo.Grass.ID);
                            switch (RNG.Next(0, 10))
                            {
                            case 0:
                                bm.SetID(x + a, y + 64, z + b, BlockInfo.RedRose.ID);
                                break;

                            case 1:
                                bm.SetID(x + a, y + 64, z + b, BlockInfo.YellowFlower.ID);
                                break;

                            case 2:
                            case 3:
                                bm.SetID(x + a, y + 64, z + b, BlockInfo.TallGrass.ID);
                                bm.SetData(x + a, y + 64, z + b, RNG.Next(1, 3));
                                break;
                                // we want to skip the other numbers, so there's no need for a default
                            }
                        }
                        else
                        {
                            bm.SetID(x + a, y + 63, z + b, BlockInfo.Dirt.ID);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        // this is a simplified version of the FillArea method from Paths.cs
        private static int[,] FillArea(int intSizeX, int intSizeZ)
        {
            int[,] intDistrict = new int[intSizeX, intSizeZ];
            int[,] intFinal    = new int[intSizeX, intSizeZ];
            int        intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0;
            int        intBonus     = 0;
            List <int> lstBuildings = new List <int>();

            do
            {
                lstBuildings.Clear();
                intBonus = 0;
                do
                {
                    SourceWorld.Building CurrentBuilding;
                    do
                    {
                        CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.Farming, 0);
                    } while (!IsValidBuilding(CurrentBuilding, lstBuildings));
                    bool booFound = false;
                    if (RNG.NextDouble() > 0.5)
                    {
                        intDistrict = intDistrict.RotateArray(RNG.Next(4));
                    }
                    int x, z = 0;
                    for (x = 0; x < intDistrict.GetLength(0) - CurrentBuilding.intSizeX && !booFound; x++)
                    {
                        for (z = 0; z < intDistrict.GetLength(1) - CurrentBuilding.intSizeZ && !booFound; z++)
                        {
                            booFound = intDistrict.IsArraySectionAllZeros2D(x, z, x + CurrentBuilding.intSizeX, z + CurrentBuilding.intSizeZ);
                        }
                    }
                    x--;
                    z--;
                    if (booFound)
                    {
                        for (int a = x + 1; a <= x + CurrentBuilding.intSizeX - 1; a++)
                        {
                            for (int b = z + 1; b <= z + CurrentBuilding.intSizeZ - 1; b++)
                            {
                                intDistrict[a, b] = 2;
                            }
                        }
                        if (CurrentBuilding.booUnique)
                        {
                            intBonus += 15;
                        }
                        lstBuildings.Add(CurrentBuilding.intID);
                        intDistrict[x + 1, z + 1] = 100 + CurrentBuilding.intID;
                        intDistrict[x + CurrentBuilding.intSizeX - 1, z + CurrentBuilding.intSizeZ - 1] = 100 + CurrentBuilding.intID;
                        intFail = 0;
                    }
                    else
                    {
                        intFail++;
                    }
                } while (intFail < 10);

                int intCurWasted = Utils.ZerosInArray2D(intDistrict) - intBonus;
                if (intCurWasted < intWasted)
                {
                    intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)];
                    Array.Copy(intDistrict, intFinal, intDistrict.Length);
                    intWasted   = intCurWasted;
                    intAttempts = 10;
                }
                Array.Clear(intDistrict, 0, intDistrict.Length);
                intAttempts--;
            } while (intAttempts > 0);
            if (intSizeX == intFinal.GetLength(1))
            {
                intFinal = intFinal.RotateArray(1);
            }
            return(intFinal);
        }
Ejemplo n.º 5
0
        private static string RandomSign()
        {
            string strSignText = "*~*~*~*";

            int intRand;

            do
            {
                intRand = RNG.Next(intAmountOfSignTypes);
            } while (intRand >= 5 && _booSignUsed[intRand]);
            _booSignUsed[intRand] = true;

            do
            {
                switch (intRand)
                {
                case 0:
                case 1: strSignText = String.Format("{0} {1} {2} for {3}~-{4} {5}.{6}.",
                                                    RNG.RandomItem("I will", "I can", "Will", "Can", "Can you"),
                                                    RNG.RandomItem("trade", "swap", "sell"),
                                                    RNG.RandomItem("gold", "iron", "dirt", "tools", "glass", "flowers", "cake", "mushrooms"),
                                                    RNG.RandomItem("obsidian", "wood", "sand", "bricks", "coal", "stone", "cookies", "diamonds"),
                                                    RNG.RandomItem("See", "Talk to"),
                                                    RNG.RandomLetter().ToString().ToUpper(),
                                                    RNG.RandomLetter().ToString().ToUpper());
                    break;

                case 2: strSignText = String.Format("{0} of the holy {1} are meeting this {2}",
                                                    RNG.RandomItem("Church", "Order"),
                                                    RNG.RandomFileLine(Path.Combine("Resources", "ChurchNoun.txt")),
                                                    RNG.RandomDay());
                    break;

                case 3: strSignText = String.Format("{0} {1} has lost her {2}. {3}",
                                                    RNG.RandomItem("Mrs", "Miss"),
                                                    RNG.RandomFileLine(Path.Combine("Resources", "Adjectives.txt")),
                                                    RNG.RandomItem("cat", "dog", "glasses", "marbles", "knitting"),
                                                    RNG.RandomItem("Reward offered", "Please help"));
                    break;

                case 4: strSignText = String.Format("{0} for sale~-{1} {2}.{3}.",
                                                    RNG.RandomItem("Armour", "Property", "House", "Weapons", "Gold", "Bodyguard", "Pet wolf", "Books", "Tools"),
                                                    RNG.RandomItem("See", "Talk to"),
                                                    RNG.RandomLetter().ToString().ToUpper(),
                                                    RNG.RandomLetter().ToString().ToUpper());
                    break;

                case 5: strSignText = "Lost pet creeper. Last seen near the mini crater";
                    break;

                case 6: strSignText = "Israphel~~Wanted dead~or alive";
                    break;

                case 7: strSignText = "Lost Jaffa Cakes. Please return to Honeydew";
                    break;

                case 8: strSignText = "Read note " + RNG.Next(500, 999);
                    break;

                case 9: strSignText = "Buy one get one free on gravestones!";
                    break;

                case 10: strSignText = "Archery practice this " + RNG.RandomDay() + " afternoon";
                    break;

                case 11: strSignText = "Seen a crime? Tell the nearest city guard";
                    break;

                case 12: strSignText = "New city law: No minors can be miners";
                    break;

                case 13: strSignText = "Council meeting this " + RNG.RandomDay();
                    break;

                case 14: strSignText = "Numbers for lovers:~" + RNG.RandomItem("220 284", "1184 1210", "2620 2924", "5020 5564", "6232 6368");
                    break;

                default:
                    Debug.Fail("Invalid switch result");
                    break;
                }
            } while (!strSignText.IsValidSign());
            return(strSignText);
        }
Ejemplo n.º 6
0
        private static void MakePond(BlockManager bm, int x, int xlen, int z, int zlen)
        {
            int[,] intArea = new int[xlen, zlen];
            int a, b;

            int c = 0, d = 0, clen = -1, dlen = -1;

            if (xlen >= 12 && zlen >= 12)
            {
                c    = RNG.Next(1, intArea.GetUpperBound(0) - 7);
                d    = RNG.Next(1, intArea.GetUpperBound(1) - 7);
                clen = RNG.Next(2, 4);
                dlen = RNG.Next(2, 4);
            }

            for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++)
            {
                for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++)
                {
                    if (a < c || a > c + clen || b < d || b > d + dlen)
                    {
                        intArea[a, b] = 1;
                    }
                }
            }

            intArea = CheckAgainstNeighbours(intArea, 0, 0, 7, 0, RNG.Next(3, 6), true);
            intArea = CheckAgainstNeighbours(intArea, 6, 0, 2, 2, 1, false);
            intArea = CheckAgainstNeighbours(intArea, 14, 0, 3, 3, 1, false);

            bool booLava = RNG.NextDouble() < 0.15;

            for (a = 1; a < intArea.GetUpperBound(0); a++)
            {
                for (b = 1; b < intArea.GetUpperBound(1); b++)
                {
                    if (intArea[a, b] == 1)
                    {
                        if (!booLava && RNG.NextDouble() < 0.05)
                        {
                            bm.SetID(x + a, 64, z + b, BlockInfo.SugarCane.ID);
                        }
                        else
                        {
                            bm.SetID(x + a, 64, z + b, BlockInfo.TallGrass.ID);
                            bm.SetData(x + a, 64, z + b, RNG.Next(1, 3));
                        }
                    }
                    else
                    {
                        for (int y = 2; y <= intArea[a, b]; y++)
                        {
                            if (booLava)
                            {
                                bm.SetID(x + a, 65 - y, z + b, BlockInfo.StationaryLava.ID);
                            }
                            else
                            {
                                bm.SetID(x + a, 65 - y, z + b, BlockInfo.StationaryWater.ID);
                                if (y == 2 && RNG.NextDouble() < 0.1)
                                {
                                    bm.SetID(x + a, 66 - y, z + b, BlockInfo.LillyPad.ID);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public static T RandomItem <T>(params T[] items)
 {
     return(items[RNG.Next(items.Length)]);
 }
Ejemplo n.º 8
0
 public static T RandomItemFromArray <T>(T[] items)
 {
     return(items[RNG.Next(items.Length)]);
 }
Ejemplo n.º 9
0
 public static char RandomLetter()
 {
     return((char)((short)'a' + RNG.Next(26)));
 }
Ejemplo n.º 10
0
 public static T[] ShuffleArray <T>(T[] items)
 {
     return(items.OrderBy(a => RNG.Next()).ToArray());
 }
Ejemplo n.º 11
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;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private static void SplitArea(BlockManager bm, int[,] intArea, int x1, int z1, int x2, int z2)
        {
            for (int x = x1; x <= x2; x++)
            {
                for (int y = z1; y <= z2; y++)
                {
                    if (x == x1 || x == x2 || y == z1 || y == z2)
                    {
                        if (intArea[x, y] < 500)
                        {
                            intArea[x, y] = 1;
                        }
                    }
                }
            }
            bool booPossibleToSplit = true;
            bool booSplitByX        = false;

            if (Math.Abs(x1 - x2) > 50 && Math.Abs(z1 - z2) > 50)
            {
                booSplitByX = RNG.NextDouble() > 0.5;
            }
            else if (Math.Abs(x1 - x2) > 50)
            {
                booSplitByX = true;
            }
            else if (Math.Abs(z1 - z2) <= 50)
            {
                booPossibleToSplit = false;
            }
            if (City.hasPaths && booPossibleToSplit)
            {
                if (booSplitByX)
                {
                    int intSplitPoint = RNG.Next(x1 + 20, x2 - 20);
                    SplitArea(bm, intArea, x1, z1, intSplitPoint, z2);
                    SplitArea(bm, intArea, intSplitPoint, z1, x2, z2);
                    _intStreet++;
                    if (City.hasPaths)
                    {
                        MakeStreetSign(bm, intSplitPoint - 1, z1 + 1, intSplitPoint - 1, z2 - 1);
                    }
                }
                else
                {
                    int intSplitPoint = RNG.Next(z1 + 20, z2 - 20);
                    SplitArea(bm, intArea, x1, z1, x2, intSplitPoint);
                    SplitArea(bm, intArea, x1, intSplitPoint, x2, z2);
                    _intStreet++;
                    if (City.hasPaths)
                    {
                        MakeStreetSign(bm, x1 + 1, intSplitPoint - 1, x2 - 1, intSplitPoint - 1);
                    }
                }
            }
            else
            {
                structDistrict stdCurrent = new structDistrict();
                stdCurrent.x1 = x1;
                stdCurrent.x2 = x2;
                stdCurrent.z1 = z1;
                stdCurrent.z2 = z2;
                _lstDistricts.Add(stdCurrent);
            }
        }
Ejemplo n.º 13
0
        public static void Generate(frmMace frmLogForm, BetaWorld worldDest, BetaChunkManager 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);
            BlockHelper.SetupClass(bmDest);
            NoticeBoard.SetupClass();
            if (!SourceWorld.SetupClass(worldDest))
            {
                return;
            }
            #endregion

            #region determine random options
            switch (City.WallMaterialID)
            {
            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.DoubleSlab.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 0;
                City.PathExtends              = 2;
                break;

            case "sandstone_raised":
                City.PathBlockID              = BlockInfo.Sandstone.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 1;
                City.PathExtends              = 2;
                break;

            case "woodplanks_raised":
                City.PathBlockID              = BlockInfo.WoodPlank.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 2;
                City.PathExtends              = 2;
                break;

            case "cobblestone_raised":
                City.PathBlockID              = BlockInfo.Cobblestone.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 3;
                City.PathExtends              = 2;
                break;

            case "brick_raised":
                City.PathBlockID              = BlockInfo.BrickBlock.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 4;
                City.PathExtends              = 2;
                break;

            case "stonebrick_raised":
                City.PathBlockID              = BlockInfo.StoneBrick.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 5;
                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);

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

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

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

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

            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 (City.HasGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers", true, false);
                GuardTowers.MakeGuardTowers(bmDest, frmLogForm);
            }
            frmLogForm.UpdateProgress(0.42);

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

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

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

            frmLogForm.UpdateLog("Creating rail data", true, false);
            Chunks.PositionRails(worldDest, bmDest);
            frmLogForm.UpdateProgress(0.50);

            frmLogForm.UpdateLog("Creating lighting data", true, false);
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm);
            frmLogForm.UpdateProgress(0.95);
            #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
        }