Exemplo n.º 1
0
        private static TileEntityChest MakeHouseChest()
        {
            TileEntityChest tec = new TileEntityChest();

            for (int intItems = RandomHelper.Next(4, 8); intItems >= 0; intItems--)
            {
                tec.Items[intItems] = BlockHelper.MakeItem(RandomHelper.RandomNumber(
                                                               ItemInfo.Apple.ID,
                                                               ItemInfo.Book.ID,
                                                               ItemInfo.Bowl.ID,
                                                               ItemInfo.Bread.ID,
                                                               ItemInfo.Cake.ID,
                                                               ItemInfo.Clock.ID,
                                                               ItemInfo.Compass.ID,
                                                               ItemInfo.Cookie.ID,
                                                               ItemInfo.Diamond.ID,
                                                               ItemInfo.Egg.ID,
                                                               ItemInfo.Feather.ID,
                                                               ItemInfo.FishingRod.ID,
                                                               ItemInfo.GoldMusicDisc.ID,
                                                               ItemInfo.GreenMusicDisc.ID,
                                                               ItemInfo.Paper.ID,
                                                               ItemInfo.Saddle.ID,
                                                               ItemInfo.String.ID,
                                                               ItemInfo.GoldIngot.ID,
                                                               ItemInfo.IronIngot.ID,
                                                               BlockType.TORCH,
                                                               ItemInfo.FlintAndSteel.ID,
                                                               ItemInfo.Bow.ID,
                                                               ItemInfo.IronSword.ID,
                                                               ItemInfo.Shears.ID), 1);
            }
            return(tec);
        }
Exemplo n.º 2
0
        private static void MakeGuardChest(BlockManager bm, int x, int y, int z, bool booIncludeItemsInChests)
        {
            TileEntityChest tec = new TileEntityChest();

            if (booIncludeItemsInChests)
            {
                for (int a = 0; a < 5; a++)
                {
                    tec.Items[a] = BlockHelper.MakeItem(RandomHelper.RandomNumber(ItemInfo.IronSword.ID,
                                                                                  ItemInfo.WoodenSword.ID,
                                                                                  ItemInfo.StoneSword.ID), 1);
                }
                tec.Items[6] = BlockHelper.MakeItem(ItemInfo.Bow.ID, 1);
                tec.Items[7] = BlockHelper.MakeItem(ItemInfo.Arrow.ID, 64);
                int intArmourStartID = RandomHelper.RandomNumber(ItemInfo.LeatherCap.ID, ItemInfo.ChainHelmet.ID,
                                                                 ItemInfo.IronHelmet.ID);
                for (int a = 9; a < 18; a++)
                {
                    // random armour
                    tec.Items[a] = BlockHelper.MakeItem(intArmourStartID + RandomHelper.Next(4), 1);
                }
            }
            bm.SetID(x, y, z, BlockType.CHEST);
            bm.SetTileEntity(x, y, z, tec);
        }
Exemplo n.º 3
0
        private static void MakeEmblem(int intFarmLength, int intMapLength, string strCityEmblem)
        {
            if (strCityEmblem.ToLower() != "none")
            {
                int intBlockyBlock = RandomHelper.RandomNumber(BlockType.IRON_BLOCK, BlockType.GOLD_BLOCK,
                                                               BlockType.DIAMOND_BLOCK);
                string[] strEmblem;
                if (strCityEmblem == "Random")
                {
                    string[] strFiles = Directory.GetFiles("Resources", "Emblem*.txt");
                    strCityEmblem = RandomHelper.RandomItemFromArray(strFiles);
                    strEmblem     = File.ReadAllLines(strCityEmblem);
                }
                else
                {
                    strEmblem = File.ReadAllLines(Path.Combine("Resources", "Emblem " + strCityEmblem + ".txt"));
                }

                for (int y = 0; y < strEmblem.GetLength(0); y++)
                {
                    strEmblem[y] = strEmblem[y].Replace("  ", " ");
                    strEmblem[y] = strEmblem[y].Replace((char)9, ' '); //tab
                    string[] strLine = strEmblem[y].Split(' ');
                    for (int x = 0; x < strLine.GetLength(0); x++)
                    {
                        string[] strSplit = strLine[x].Split(':');
                        if (strSplit.GetLength(0) == 1)
                        {
                            Array.Resize(ref strSplit, 2);
                        }
                        if (strSplit[0] == "-1")
                        {
                            strSplit[0] = intBlockyBlock.ToString();
                        }
                        BlockShapes.MakeBlock(((intMapLength / 2) - (strLine.GetLength(0) + 5)) + x, 71 - y,
                                              intFarmLength + 5, Convert.ToInt32(strSplit[0]), 2, 100,
                                              Convert.ToInt32(strSplit[1]));
                    }
                    for (int x = strLine.GetLength(0) + 1; x < strLine.GetLength(0) + 5; x++)
                    {
                        BlockShapes.MakeBlock((intMapLength / 2) - (5 + x), 69, intFarmLength + 5, BlockType.AIR, 2, 100, 0);
                        BlockShapes.MakeBlock((intMapLength / 2) - (5 + x), 70, intFarmLength + 5, BlockType.AIR, 2, 100, 0);
                    }
                }
            }
        }
Exemplo n.º 4
0
 private static int SelectRandomResource(double dblDepth)
 {
     if (dblDepth > 0.66)
     {
         return(RandomHelper.RandomNumber(BlockType.COAL_ORE,
                                          BlockType.IRON_ORE));
     }
     else if (dblDepth > 0.33)
     {
         return(RandomHelper.RandomNumber(BlockType.LAPIS_ORE,
                                          BlockType.REDSTONE_ORE));
     }
     else
     {
         return(RandomHelper.RandomNumber(BlockType.GOLD_ORE,
                                          BlockType.DIAMOND_ORE));
     }
 }
Exemplo n.º 5
0
        private static void MakeEmblem()
        {
            if (City.CityEmblemType.ToLower() != "none")
            {
                int      intBlockyBlock = RandomHelper.RandomNumber(BlockInfo.GoldBlock.ID, BlockInfo.IronBlock.ID, BlockInfo.DiamondBlock.ID);
                string[] strEmblem;
                strEmblem = File.ReadAllLines(Path.Combine("Resources", "Emblem " + City.CityEmblemType + ".txt"));

                for (int y = 0; y < strEmblem.GetLength(0); y++)
                {
                    strEmblem[y] = strEmblem[y].Replace("  ", " ");
                    strEmblem[y] = strEmblem[y].Replace((char)9, ' '); //tab
                    string[] strLine = strEmblem[y].Split(' ');
                    for (int x = 0; x < strLine.GetLength(0); x++)
                    {
                        string[] strSplit = strLine[x].Split(':');
                        if (strSplit.GetLength(0) == 1)
                        {
                            Array.Resize(ref strSplit, 2);
                        }
                        if (strSplit[0] == "-1")
                        {
                            strSplit[0] = intBlockyBlock.ToString();
                        }
                        BlockShapes.MakeBlock(((City.MapLength / 2) - (strLine.GetLength(0) + 5)) + x, 71 - y,
                                              City.FarmLength + 5, Convert.ToInt32(strSplit[0]), 2, 100,
                                              Convert.ToInt32(strSplit[1]));
                    }
                    for (int x = strLine.GetLength(0) + 1; x < strLine.GetLength(0) + 5; x++)
                    {
                        BlockShapes.MakeBlock((City.MapLength / 2) - (5 + x), 69,
                                              City.FarmLength + 5, BlockInfo.Air.ID, 2, 100, 0);
                        BlockShapes.MakeBlock((City.MapLength / 2) - (5 + x), 70,
                                              City.FarmLength + 5, BlockInfo.Air.ID, 2, 100, 0);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private static TileEntityChest MakeTreasureChest()
        {
            TileEntityChest tec = new TileEntityChest();

            for (int intItems = RandomHelper.Next(5, 7); intItems >= 2; intItems--)
            {
                tec.Items[intItems] = BlockHelper.MakeItem(RandomHelper.RandomNumber(
                                                               ItemInfo.GoldenApple.ID,
                                                               ItemInfo.GoldIngot.ID,
                                                               ItemInfo.Diamond.ID,
                                                               ItemInfo.GoldMusicDisc.ID,
                                                               ItemInfo.GreenMusicDisc.ID,
                                                               ItemInfo.IronIngot.ID,
                                                               ItemInfo.Saddle.ID,
                                                               ItemInfo.Compass.ID,
                                                               ItemInfo.Clock.ID,
                                                               ItemInfo.Cake.ID,
                                                               ItemInfo.Cookie.ID
                                                               ), 1);
            }
            tec.Items[0] = BlockHelper.MakeItem(ItemInfo.GetRandomItem().ID, 1);
            tec.Items[1] = BlockHelper.MakeItem(ItemInfo.GetRandomItem().ID, 1);
            return(tec);
        }
Exemplo n.º 7
0
 private static int SelectRandomResource(double dblDepth)
 {
     if (dblDepth > 0.66)
     {
         return(RandomHelper.RandomNumber(BlockInfo.CoalOre.ID,
                                          BlockInfo.IronOre.ID));
     }
     else if (dblDepth > 0.33)
     {
         return(RandomHelper.RandomNumber(BlockInfo.CoalOre.ID,
                                          BlockInfo.IronOre.ID,
                                          BlockInfo.LapisOre.ID,
                                          BlockInfo.RedstoneOre.ID));
     }
     else
     {
         return(RandomHelper.RandomNumber(BlockInfo.CoalOre.ID,
                                          BlockInfo.IronOre.ID,
                                          BlockInfo.LapisOre.ID,
                                          BlockInfo.RedstoneOre.ID,
                                          BlockInfo.GoldOre.ID,
                                          BlockInfo.DiamondOre.ID));
     }
 }
Exemplo n.º 8
0
        private static void MakeLevel(BetaWorld world, BlockManager bm, int intDepth, int intMineshaftSize, Buildings.structPoint spMineshaftEntrance)
        {
            Debug.WriteLine("----- Mineshaft Level " + intDepth + " -----");

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

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

            _intBlockStartBuildings -= 2;
            int[,] intAreaOverview   = new int[(intAreaFull.GetLength(0) / MULTIPLIER), (intAreaFull.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 < intAreaFull.GetLength(0) - 4; x++)
            {
                for (int z = 4; z < intAreaFull.GetLength(1) - 4; z++)
                {
                    if (intAreaOverview.GetLength(0) > x / MULTIPLIER && intAreaOverview.GetLength(1) > z / MULTIPLIER)
                    {
                        if (intAreaFull[x + intOffsetX, z + intOffsetZ] < 4)
                        {
                            intAreaFull[x + intOffsetX, z + intOffsetZ] = intAreaOverview[x / MULTIPLIER, z / MULTIPLIER];
                        }
                    }
                    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++)
                            {
                                intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Structure;
                            }
                        }
                        if (intAreaOverview[(x / MULTIPLIER) + 1, z / MULTIPLIER] == (int)MineshaftBlocks.Air)
                        {
                            for (int x2 = 0; x2 < 5; x2++)
                            {
                                if (x2 == 1 || x2 == 3)
                                {
                                    intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.CeilingSupport;
                                    intAreaFull[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.CeilingSupport;
                                }
                                else
                                {
                                    intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Support;
                                    intAreaFull[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Support;
                                }
                            }
                            for (int x2 = 0; x2 <= 5; x2++)
                            {
                                if (intAreaFull[x + intOffsetX + x2, z + intOffsetZ] == (int)MineshaftBlocks.Support)
                                {
                                    intAreaFull[x + intOffsetX + x2, z + intOffsetZ] = (int)MineshaftBlocks.RailWithSupport;
                                }
                                else
                                {
                                    intAreaFull[x + intOffsetX + x2, z + intOffsetZ] = (int)MineshaftBlocks.Rail;
                                }
                            }
                        }
                        if (intAreaOverview[x / MULTIPLIER, (z / MULTIPLIER) + 1] == (int)MineshaftBlocks.Air)
                        {
                            for (int z2 = 0; z2 < 5; z2++)
                            {
                                if (z2 == 1 || z2 == 3)
                                {
                                    intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = (int)MineshaftBlocks.CeilingSupport;
                                    intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = (int)MineshaftBlocks.CeilingSupport;
                                }
                                else
                                {
                                    intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = (int)MineshaftBlocks.Support;
                                    intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = (int)MineshaftBlocks.Support;
                                }
                            }
                            for (int z2 = 0; z2 <= 5; z2++)
                            {
                                if (intAreaFull[x + intOffsetX, z + intOffsetZ + z2] == (int)MineshaftBlocks.Support)
                                {
                                    intAreaFull[x + intOffsetX, z + intOffsetZ + z2] = (int)MineshaftBlocks.RailWithSupport;
                                }
                                else
                                {
                                    intAreaFull[x + intOffsetX, z + intOffsetZ + z2] = (int)MineshaftBlocks.Rail;
                                }
                            }
                        }
                        if (intAreaOverview[x / MULTIPLIER, z / MULTIPLIER] == (int)MineshaftBlocks.Air)
                        {
                            MakeChestAndOrTorch(intAreaOverview, intAreaFull, (x - 3) / MULTIPLIER, z / MULTIPLIER,
                                                x + intOffsetX - 2, z + intOffsetZ);
                            MakeChestAndOrTorch(intAreaOverview, intAreaFull, (x + 3) / MULTIPLIER, z / MULTIPLIER,
                                                x + intOffsetX + 2, z + intOffsetZ);
                            MakeChestAndOrTorch(intAreaOverview, intAreaFull, x / MULTIPLIER, (z - 3) / MULTIPLIER,
                                                x + intOffsetX, z + intOffsetZ - 2);
                            MakeChestAndOrTorch(intAreaOverview, intAreaFull, x / MULTIPLIER, (z + 3) / MULTIPLIER,
                                                x + intOffsetX, z + intOffsetZ + 2);
                        }
                    }
                }
            }
            intAreaFull[intXPosOriginal, intZPosOriginal] = (int)MineshaftBlocks.EntranceSection;
            int intSupportMaterial = RandomHelper.RandomNumber(BlockType.WOOD, BlockType.WOOD_PLANK, BlockType.FENCE);

            for (int x = 0; x < intAreaFull.GetLength(0); x++)
            {
                for (int z = 0; z < intAreaFull.GetLength(1); z++)
                {
                    if (intDepth <= 4)
                    {
                        if (bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.GRAVEL)
                        {
                            bm.SetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings, BlockType.STONE);
                        }
                    }
                    if (intDepth <= 2)
                    {
                        if (bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.SAND ||
                            bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.SANDSTONE)
                        {
                            bm.SetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings, BlockType.DIRT);
                        }
                    }
                    switch (intAreaFull[x, z])
                    {
                    case (int)MineshaftBlocks.NaturalTerrain:
                        break;

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

                    case (int)MineshaftBlocks.EntranceSection:
                    case (int)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,
                                         BlockType.GRAVEL);
                            }
                            else if (y == 39 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockType.RAILS);
                            }
                            else
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockType.AIR);
                            }
                        }
                        break;

                    case (int)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,
                                         BlockType.GRAVEL);
                            }
                            else if (y == 39 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockType.RAILS);
                            }
                            else if (y == 40 - (5 * intDepth))
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockType.AIR);
                            }
                            else
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         intSupportMaterial);
                            }
                        }
                        break;

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

                    case (int)MineshaftBlocks.ChestAndOrTorch:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 39 - (5 * intDepth) &&
                                RandomHelper.NextDouble() > 0.9)
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.CHEST);
                                MakeChestItems(bm, x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intResourceChances, strResourceNames);
                            }
                            else if (y == 41 - (5 * intDepth) &&
                                     RandomHelper.NextDouble() < (double)intTorchChance / 100)
                            {
                                bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings,
                                         BlockType.TORCH);
                                if (intAreaFull[x - 1, z] == 0)
                                {
                                    bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 1);
                                }
                                else if (intAreaFull[x + 1, z] == 0)
                                {
                                    bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 2);
                                }
                                else if (intAreaFull[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, BlockType.AIR);
                            }
                        }
                        break;

                    case (int)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, BlockType.AIR);
                            }
                        }
                        break;

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

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

                    default:
                        Debug.Fail("Invalid switch result");
                        break;
                    }
                }
            }
            foreach (structSection MineshaftSection in lstSections)
            {
                SourceWorld.InsertBuilding(bm, new int[0, 0], _intBlockStartBuildings, MineshaftSection.x, MineshaftSection.z,
                                           MineshaftSection.bldMineshaftSection, 38 - (5 * intDepth));
            }
            world.Save();
            _intBlockStartBuildings += 2;
            //#if DEBUG
            //    File.WriteAllText("output_area_" + intDepth + ".txt", Utils.TwoDimensionalArrayToString(intAreaOverview));
            //    File.WriteAllText("output_map_" + intDepth + ".txt", Utils.TwoDimensionalArrayToString(intAreaFull));
            //#endif
        }
Exemplo n.º 9
0
        private static void MakeLevel(BetaWorld world, BlockManager bm, int intDepth, int intMineshaftSize)
        {
            strResourceNames   = ValueFromXMLElement(Path.Combine("Resources", "MineshaftChests.xml"), "level" + intDepth, "names").Split(',');
            intResourceChances = StringArrayToIntArray(
                ValueFromXMLElement(Path.Combine("Resources", "MineshaftChests.xml"), "level" + intDepth, "chances").Split(','));
            int intTorchChance = Convert.ToInt32(ValueFromXMLElement(Path.Combine("Resources", "MineshaftChests.xml"), "level" + intDepth, "torch_chance"));

            int[,] intMap = new int[intMineshaftSize, intMineshaftSize];
            int intXPosOriginal = intMap.GetLength(0) / 2;
            int intZPosOriginal = intMap.GetLength(1) / 2;

            int[,] intArea = new int[intMap.GetLength(0) / MULTIPLIER, intMap.GetLength(1) / MULTIPLIER];
            int intXPos = intXPosOriginal / MULTIPLIER;
            int intZPos = intZPosOriginal / MULTIPLIER;

            intArea[intXPos, intZPos] = 1;
            CreateRouteXPlus(intArea, intXPos + 1, intZPos, 0);
            CreateRouteZPlus(intArea, intXPos, intZPos + 1, 1);
            CreateRouteXMinus(intArea, intXPos - 1, intZPos, 2);
            CreateRouteZMinus(intArea, intXPos, intZPos - 1, 3);
            int  intOffsetX = (intXPosOriginal - (intXPos * MULTIPLIER)) - 2;
            int  intOffsetZ = (intZPosOriginal - (intZPos * MULTIPLIER)) - 2;
            int  intGhostX = 0, intGhostZ = 0;
            bool booGhost = false;

            if (intDepth == 7)
            {
                for (int x = 1; x < intArea.GetLength(0) - 1 && !booGhost; x++)
                {
                    for (int z = 1; z < intArea.GetLength(1) - 1 && !booGhost; z++)
                    {
                        if (intArea[x, z] == 1 && intArea[x + 1, z] == 0 && intArea[x - 1, z] == 0 && intArea[x, z + 1] == 0)
                        {
                            intArea[x, z] = 9;
                            intGhostX     = (x * MULTIPLIER) + intOffsetX;
                            intGhostZ     = (z * MULTIPLIER) + intOffsetZ;
                            booGhost      = true;
                        }
                    }
                }
            }
            for (int x = 4; x < intMap.GetLength(0) - 4; x++)
            {
                for (int z = 4; z < intMap.GetLength(1) - 4; z++)
                {
                    if (intArea.GetLength(0) > x / MULTIPLIER && intArea.GetLength(1) > z / MULTIPLIER)
                    {
                        if (intMap[x + intOffsetX, z + intOffsetZ] < 4)
                        {
                            intMap[x + intOffsetX, z + intOffsetZ] = intArea[x / MULTIPLIER, z / MULTIPLIER];
                        }
                    }
                    if ((x + 3) % 5 == 0 && (z + 3) % 5 == 0 && intArea[x / MULTIPLIER, z / MULTIPLIER] == 1)
                    {
                        if (intArea[(x / MULTIPLIER) + 1, z / MULTIPLIER] == 1)
                        {
                            for (int x2 = 0; x2 < 5; x2++)
                            {
                                if (x2 == 1 || x2 == 3)
                                {
                                    intMap[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = 8;
                                    intMap[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = 8;
                                }
                                else
                                {
                                    intMap[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = 5;
                                    intMap[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = 5;
                                }
                            }
                            for (int x2 = 0; x2 <= 5; x2++)
                            {
                                if (intMap[x + intOffsetX + x2, z + intOffsetZ] == 5)
                                {
                                    intMap[x + intOffsetX + x2, z + intOffsetZ] = 4;
                                }
                                else
                                {
                                    intMap[x + intOffsetX + x2, z + intOffsetZ] = 7;
                                }
                            }
                        }
                        if (intArea[x / MULTIPLIER, (z / MULTIPLIER) + 1] == 1)
                        {
                            for (int z2 = 0; z2 < 5; z2++)
                            {
                                if (z2 == 1 || z2 == 3)
                                {
                                    intMap[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = 8;
                                    intMap[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = 8;
                                }
                                else
                                {
                                    intMap[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = 5;
                                    intMap[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = 5;
                                }
                            }
                            for (int z2 = 0; z2 <= 5; z2++)
                            {
                                if (intMap[x + intOffsetX, z + intOffsetZ + z2] == 5)
                                {
                                    intMap[x + intOffsetX, z + intOffsetZ + z2] = 4;
                                }
                                else
                                {
                                    intMap[x + intOffsetX, z + intOffsetZ + z2] = 7;
                                }
                            }
                        }
                        if (intArea[x / MULTIPLIER, z / MULTIPLIER] == 1)
                        {
                            MakeChestAndOrTorch(intArea, intMap, (x - 3) / MULTIPLIER, z / MULTIPLIER, x + intOffsetX - 2, z + intOffsetZ);
                            MakeChestAndOrTorch(intArea, intMap, (x + 3) / MULTIPLIER, z / MULTIPLIER, x + intOffsetX + 2, z + intOffsetZ);
                            MakeChestAndOrTorch(intArea, intMap, x / MULTIPLIER, (z - 3) / MULTIPLIER, x + intOffsetX, z + intOffsetZ - 2);
                            MakeChestAndOrTorch(intArea, intMap, x / MULTIPLIER, (z + 3) / MULTIPLIER, x + intOffsetX, z + intOffsetZ + 2);
                        }
                    }
                }
            }
            intMap[intXPosOriginal, intZPosOriginal] = 3;
            int intSupportMaterial = RandomHelper.RandomNumber((int)BlockType.WOOD, (int)BlockType.WOOD_PLANK, (int)BlockType.FENCE);

            intSupportMaterial = (int)BlockType.WOOD_PLANK;
            for (int x = 0; x < intMap.GetLength(0); x++)
            {
                for (int z = 0; z < intMap.GetLength(1); z++)
                {
                    switch (intMap[x, z])
                    {
                    case 0:
                        break;

                    case 1:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR);
                        }
                        break;

                    case 9:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * (intDepth - 1)); y++)
                        {
                            bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR);
                        }
                        break;

                    case 2:
                        break;

                    case 4:
                        for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 38 - (5 * intDepth))
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.GRAVEL);
                            }
                            else if (y == 39 - (5 * intDepth))
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.RAILS);
                            }
                            else if (y == 40 - (5 * intDepth))
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR);
                            }
                            else
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, intSupportMaterial);
                            }
                        }
                        break;

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

                    case 6:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 39 - (5 * intDepth) &&
                                RandomHelper.NextDouble() > 0.9)
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.CHEST);
                                MakeChestItems(bm, x + intBlockStart, y, z + intBlockStart);
                            }
                            else if (y == 41 - (5 * intDepth) &&
                                     RandomHelper.NextDouble() < (double)intTorchChance / 100)
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.TORCH);
                                if (intMap[x - 1, z] == 0)
                                {
                                    bm.SetData(x + intBlockStart, y, z + intBlockStart, 1);
                                }
                                else if (intMap[x + 1, z] == 0)
                                {
                                    bm.SetData(x + intBlockStart, y, z + intBlockStart, 2);
                                }
                                else if (intMap[x, z - 1] == 0)
                                {
                                    bm.SetData(x + intBlockStart, y, z + intBlockStart, 3);
                                }
                                else
                                {
                                    bm.SetData(x + intBlockStart, y, z + intBlockStart, 4);
                                }
                            }
                            else
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR);
                            }
                        }
                        break;

                    case 7:
                    case 3:
                        for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 38 - (5 * intDepth))
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.GRAVEL);
                            }
                            else if (y == 39 - (5 * intDepth))
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.RAILS);
                            }
                            else
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR);
                            }
                        }
                        break;

                    case 8:
                        for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++)
                        {
                            if (y == 41 - (5 * intDepth))
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, intSupportMaterial);
                            }
                            else
                            {
                                bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR);
                            }
                        }
                        break;
                    }
                }
            }
            for (int x = 0; x < intMap.GetLength(0); x++)
            {
                for (int z = 0; z < intMap.GetLength(1); z++)
                {
                    switch (intMap[x, z])
                    {
                    case 3:
                    case 4:
                    case 7:
                        BlockHelper.MakeRail(x + intBlockStart, 39 - (5 * intDepth), z + intBlockStart);
                        break;
                    }
                }
            }
            if (booGhost)
            {
                BlockShapes.MakeSolidBox(intBlockStart + intGhostX - 1, intBlockStart + intGhostX + 5,
                                         39 - (5 * intDepth), 46 - (5 * intDepth),
                                         intBlockStart + intGhostZ - 1, intBlockStart + intGhostZ + 5, (int)BlockType.AIR, 0);
                for (int x = intBlockStart + intGhostX; x <= intBlockStart + intGhostX + 4; x++)
                {
                    for (int y = 39 - (5 * intDepth); y <= 44 - (5 * intDepth); y++)
                    {
                        for (int z = intBlockStart + intGhostZ + 3; z <= intBlockStart + intGhostZ + 4; z++)
                        {
                            bm.SetID(x, y, z, (int)BlockType.WOOL);
                            bm.SetData(x, y, z, (int)WoolColor.WHITE);
                        }
                    }
                }
                bm.SetID(intBlockStart + intGhostX + 0, 44 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)BlockType.TORCH);
                bm.SetID(intBlockStart + intGhostX + 0, 44 - (5 * intDepth), intBlockStart + intGhostZ + 4, (int)BlockType.TORCH);
                bm.SetID(intBlockStart + intGhostX + 4, 44 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)BlockType.TORCH);
                bm.SetID(intBlockStart + intGhostX + 4, 44 - (5 * intDepth), intBlockStart + intGhostZ + 4, (int)BlockType.TORCH);
                bm.SetData(intBlockStart + intGhostX + 0, 44 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)TorchOrientation.FLOOR);
                bm.SetData(intBlockStart + intGhostX + 0, 44 - (5 * intDepth), intBlockStart + intGhostZ + 4, (int)TorchOrientation.FLOOR);
                bm.SetData(intBlockStart + intGhostX + 4, 44 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)TorchOrientation.FLOOR);
                bm.SetData(intBlockStart + intGhostX + 4, 44 - (5 * intDepth), intBlockStart + intGhostZ + 4, (int)TorchOrientation.FLOOR);
                bm.SetID(intBlockStart + intGhostX + 1, 43 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)BlockType.OBSIDIAN);
                bm.SetID(intBlockStart + intGhostX + 3, 43 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)BlockType.OBSIDIAN);
                bm.SetID(intBlockStart + intGhostX + 1, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)BlockType.TORCH);
                bm.SetData(intBlockStart + intGhostX + 1, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)TorchOrientation.FLOOR);
                bm.SetID(intBlockStart + intGhostX + 2, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)BlockType.SIGN_POST);
                bm.SetData(intBlockStart + intGhostX + 2, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)SignPostOrientation.EAST);
                BlockHelper.MakeSignPost(intBlockStart + intGhostX + 2, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2,
                                         "Ghostdancer:|Victim of the|Creeper Rush|of '09");
                bm.SetID(intBlockStart + intGhostX + 3, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)BlockType.TORCH);
                bm.SetData(intBlockStart + intGhostX + 3, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)TorchOrientation.FLOOR);
            }
            world.Save();
            //File.WriteAllText("c:\\output.txt", TwoDimensionalArrayToString(intMap));
        }
Exemplo n.º 10
0
        public static void MakeFarms(BetaWorld world, BlockManager bm, int intFarmSize, int intMapSize)
        {
            AddMushroomFarms(bm, intFarmSize, intMapSize);
            int intFail  = 0;
            int intFarms = 0;

            while (intFail <= 500)
            {
                int xlen = rand.Next(8, 26);
                int x1   = rand.Next(4, intMapSize - (4 + xlen));
                int zlen = rand.Next(8, 26);
                int z1   = rand.Next(4, intMapSize - (4 + zlen));
                if (!(x1 >= intFarmSize && z1 >= intFarmSize &&
                      x1 <= intMapSize - intFarmSize && z1 <= intMapSize - intFarmSize))
                {
                    bool booValid = true;
                    for (int x = x1 - 2; x <= x1 + xlen + 2 && booValid; x++)
                    {
                        for (int z = z1 - 2; z <= z1 + zlen + 2 && booValid; z++)
                        {
                            // make sure it doesn't overlap with the spawn point or another farm
                            if ((x == intMapSize / 2 && z == intMapSize - (intFarmSize - 10)) ||
                                bm.GetID(x, 63, z) != (int)BlockType.GRASS || bm.GetID(x, 64, z) != (int)BlockType.AIR)
                            {
                                booValid = false;
                                intFail++;
                            }
                        }
                    }
                    if (booValid)
                    {
                        // first there is a 25% chance of a hill or pond
                        // if not, for large farms, there is a 50% chance it'll be an orchard
                        // if not, 25% are cactus, 50% are wheat and 25% are sugarcane

                        FarmTypes curFarm;
                        int       intFarmType = rand.Next(100);
                        if (xlen >= 10 && zlen >= 10 && intFarmType > 75)
                        {
                            if (rand.NextDouble() > 0.5)
                            {
                                curFarm = FarmTypes.Pond;
                                MakePond(bm, x1, xlen, z1, zlen, false);
                            }
                            else
                            {
                                curFarm = FarmTypes.Hill;
                                MakeHill(bm, x1, xlen, z1, zlen, false);
                            }
                        }
                        else
                        {
                            intFarmType = rand.Next(100);
                            if (((xlen >= 11 && zlen >= 16) || (xlen >= 16 && zlen >= 11)) && intFarmType > 50)
                            {
                                curFarm = FarmTypes.Orchard;
                                xlen    = ((int)((xlen - 1) / 5) * 5) + 1;
                                zlen    = ((int)((zlen - 1) / 5) * 5) + 1;
                            }
                            else
                            {
                                intFarmType = rand.Next(100);
                                if (intFarmType > 75)
                                {
                                    curFarm = FarmTypes.Cactus;
                                }
                                else if (intFarmType > 25)
                                {
                                    curFarm = FarmTypes.Wheat;
                                    xlen   += (xlen % 2) - 1;
                                    zlen   += (zlen % 2) - 1;
                                }
                                else
                                {
                                    curFarm = FarmTypes.SugarCane;
                                    xlen   += (xlen % 2) - 1;
                                    zlen   += (zlen % 2) - 1;
                                }
                            }
                        }

                        int intWallMaterial =
                            rand.NextDouble() > 0.5 ? (int)BlockType.FENCE : (int)BlockType.LEAVES;

                        switch (curFarm)
                        {
                        case FarmTypes.Hill:
                        case FarmTypes.Pond:
                            intWallMaterial = 0;
                            break;

                        case FarmTypes.SugarCane:
                        case FarmTypes.Mushroom:
                            if (rand.NextDouble() > 0.5)
                            {
                                intWallMaterial = 0;
                            }
                            break;

                        case FarmTypes.Wheat:
                            intWallMaterial = (int)BlockType.LEAVES;
                            break;
                        }
                        switch (intWallMaterial)
                        {
                        case (int)BlockType.FENCE:
                            BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen, (int)BlockType.FENCE);
                            break;

                        case (int)BlockType.LEAVES:
                            // the saplings will all disappear if one of them is broken.
                            // so we put wood beneath them to stop that happening
                            BlockShapes.MakeHollowLayers(x1, x1 + xlen, 63, 63, z1, z1 + zlen, (int)BlockType.WOOD);
                            BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, (int)BlockType.LEAVES, 0,
                                                         RandomHelper.RandomNumber((int)LeafType.OAK, (int)LeafType.SPRUCE, (int)LeafType.BIRCH));
                            break;
                        }

                        switch (curFarm)
                        {
                        case FarmTypes.Orchard:
                            int intSaplingType = RandomHelper.RandomNumber(BlockHelper.SaplingBirch,
                                                                           BlockHelper.SaplingOak,
                                                                           BlockHelper.SaplingSpruce);
                            for (int x = x1 + 3; x <= x1 + xlen - 3; x += 5)
                            {
                                for (int z = z1 + 3; z <= z1 + zlen - 3; z += 5)
                                {
                                    bm.SetID(x, 63, z, (int)BlockType.GRASS);
                                    bm.SetID(x, 64, z, (int)BlockType.SAPLING);
                                    bm.SetData(x, 64, z, intSaplingType);
                                }
                            }
                            break;

                        case FarmTypes.Cactus:
                            int intAttempts = 0;
                            do
                            {
                                int  xCactus = rand.Next(x1 + 1, x1 + xlen), zCactus = rand.Next(z1 + 1, z1 + zlen);
                                bool booValidFarm = true;
                                for (int xCheck = xCactus - 1; xCheck <= xCactus + 1 && booValidFarm; xCheck++)
                                {
                                    for (int zCheck = zCactus - 1; zCheck <= zCactus + 1 && booValidFarm; zCheck++)
                                    {
                                        if (bm.GetID(xCheck, 64, zCheck) != (int)BlockType.AIR)
                                        {
                                            booValidFarm = false;
                                        }
                                    }
                                }
                                if (booValidFarm)
                                {
                                    bm.SetID(xCactus, 64, zCactus, (int)BlockType.CACTUS);
                                    if (rand.NextDouble() > 0.5)
                                    {
                                        bm.SetID(xCactus, 65, zCactus, (int)BlockType.CACTUS);
                                    }
                                }
                                intAttempts++;
                            }while (intAttempts < 100);
                            break;

                        case FarmTypes.Wheat:
                            BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen, (int)BlockType.GLASS);
                            BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1, (int)BlockType.GLASS);
                            break;
                        }

                        for (int x = x1 + 1; x <= x1 + xlen - 1; x++)
                        {
                            for (int z = z1 + 1; z <= z1 + zlen - 1; z++)
                            {
                                switch ((int)curFarm)
                                {
                                case (int)FarmTypes.Cactus:
                                    bm.SetID(x, 63, z, (int)BlockType.SAND);
                                    break;

                                case (int)FarmTypes.Wheat:
                                    if (z == z1 + 1)
                                    {
                                        bm.SetID(x, 63, z, (int)BlockType.DOUBLE_SLAB);
                                    }
                                    else if (x % 2 == 0)
                                    {
                                        bm.SetID(x, 63, z, (int)BlockType.FARMLAND);
                                        bm.SetData(x, 63, z, 1);
                                        bm.SetID(x, 64, z, (int)BlockType.CROPS);
                                    }
                                    else
                                    {
                                        bm.SetID(x, 63, z, (int)BlockType.STATIONARY_WATER);
                                    }
                                    break;

                                case (int)FarmTypes.SugarCane:
                                    if (z != z1 + 1)
                                    {
                                        if (x % 2 == 0)
                                        {
                                            bm.SetID(x, 64, z, (int)BlockType.SUGAR_CANE);
                                            if (rand.Next(100) > 50)
                                            {
                                                bm.SetID(x, 65, z, (int)BlockType.SUGAR_CANE);
                                            }
                                        }
                                        else
                                        {
                                            bm.SetID(x, 63, z, (int)BlockType.STATIONARY_WATER);
                                        }
                                    }
                                    break;
                                }
                            }
                        }

                        int d = rand.Next(x1 + 1, x1 + xlen - 1);
                        if (curFarm == FarmTypes.Wheat)
                        {
                            bm.SetID(d, 63, z1, (int)BlockType.DOUBLE_SLAB);
                        }
                        if (intWallMaterial != 0)
                        {
                            bm.SetID(d, 64, z1, (int)BlockType.WOOD_DOOR);
                            bm.SetData(d, 64, z1, 4);
                            bm.SetID(d, 65, z1, (int)BlockType.WOOD_DOOR);
                            bm.SetData(d, 65, z1, 4 + (int)DoorState.TOPHALF);
                        }
                        intFail = 0;
                        intFarms++;
                        if (intFarms % 10 == 0)
                        {
                            world.Save();
                        }
                    }
                }
            }
            MakeMiniPondsAndHills(world, bm, intFarmSize, intMapSize);
            MakeFlowers(bm, intFarmSize, intMapSize);
        }
Exemplo n.º 11
0
        public static void MakeFarms(BetaWorld world, BlockManager bm, int intFarmLength, int intMapLength)
        {
            AddBuildings(bm, intFarmLength, intMapLength);
            int intFail  = 0;
            int intFarms = 0;

            while (intFail <= 500)
            {
                int xlen = RandomHelper.Next(8, 26);
                int x1   = RandomHelper.Next(4, intMapLength - (4 + xlen));
                int zlen = RandomHelper.Next(8, 26);
                int z1   = RandomHelper.Next(4, intMapLength - (4 + zlen));
                if (!(x1 >= intFarmLength && z1 >= intFarmLength &&
                      x1 <= intMapLength - intFarmLength && z1 <= intMapLength - intFarmLength))
                {
                    bool booValid = true;
                    for (int x = x1 - 2; x <= x1 + xlen + 2 && booValid; x++)
                    {
                        for (int z = z1 - 2; z <= z1 + zlen + 2 && booValid; z++)
                        {
                            // make sure it doesn't overlap with the spawn point or another farm
                            if ((x == intMapLength / 2 && z == intMapLength - (intFarmLength - 10)) ||
                                bm.GetID(x, 63, z) != BlockType.GRASS || bm.GetID(x, 64, z) != BlockType.AIR)
                            {
                                booValid = false;
                                intFail++;
                            }
                        }
                    }
                    if (booValid)
                    {
                        // first there is a 25% chance of a hill or pond
                        // if not, for large farms, there is a 50% chance it'll be an orchard
                        // if not, 33% are cactus, 33% are wheat and 33% are sugarcane

                        FarmTypes curFarm;
                        int       intFarmType = RandomHelper.Next(100);
                        if (xlen >= 10 && zlen >= 10 && intFarmType > 75)
                        {
                            if (RandomHelper.NextDouble() > 0.5)
                            {
                                curFarm = FarmTypes.Pond;
                                MakePond(bm, x1, xlen, z1, zlen, false);
                            }
                            else
                            {
                                curFarm = FarmTypes.Hill;
                                MakeHill(bm, x1, xlen, z1, zlen, false);
                            }
                        }
                        else
                        {
                            intFarmType = RandomHelper.Next(100);
                            if (((xlen >= 11 && zlen >= 16) || (xlen >= 16 && zlen >= 11)) && intFarmType > 50)
                            {
                                curFarm = FarmTypes.Orchard;
                                xlen    = ((int)((xlen - 1) / 5) * 5) + 1;
                                zlen    = ((int)((zlen - 1) / 5) * 5) + 1;
                            }
                            else
                            {
                                intFarmType = RandomHelper.Next(3);
                                if (intFarmType == 2)
                                {
                                    curFarm = FarmTypes.Cactus;
                                }
                                else if (intFarmType == 1)
                                {
                                    curFarm = FarmTypes.Wheat;
                                    xlen   += (xlen % 2) - 1;
                                    zlen   += (zlen % 2) - 1;
                                }
                                else
                                {
                                    curFarm = FarmTypes.SugarCane;
                                    xlen   += (xlen % 2) - 1;
                                    zlen   += (zlen % 2) - 1;
                                }
                            }
                        }

                        int intWallMaterial = RandomHelper.NextDouble() > 0.5 ? BlockType.FENCE : BlockType.LEAVES;

                        switch (curFarm)
                        {
                        case FarmTypes.Hill:
                        case FarmTypes.Pond:
                            intWallMaterial = 0;
                            break;

                        case FarmTypes.SugarCane:
                        case FarmTypes.Mushroom:
                            if (RandomHelper.NextDouble() > 0.5)
                            {
                                intWallMaterial = 0;
                            }
                            break;

                        case FarmTypes.Wheat:
                            intWallMaterial = BlockType.LEAVES;
                            break;
                            // no need for default - the other types don't need anything here
                        }
                        switch (intWallMaterial)
                        {
                        case BlockType.FENCE:
                            BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen,
                                                         BlockType.FENCE, 0, -1);
                            break;

                        case BlockType.LEAVES:
                            // the saplings will all disappear if one of them is broken.
                            // so we put wood beneath them to stop that happening
                            BlockShapes.MakeHollowLayers(x1, x1 + xlen, 63, 63, z1, z1 + zlen,
                                                         BlockType.WOOD, 0, -1);
                            BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, BlockType.LEAVES, 0,
                                                         RandomHelper.RandomNumber((int)LeafType.OAK, (int)LeafType.SPRUCE,
                                                                                   (int)LeafType.BIRCH));
                            break;

                        case 0:
                            // no wall
                            break;

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

                        switch (curFarm)
                        {
                        case FarmTypes.Orchard:
                            int intSaplingType = RandomHelper.RandomNumber(SaplingBirchDataID,
                                                                           SaplingOakDataID,
                                                                           SaplingSpruceDataID);
                            for (int x = x1 + 3; x <= x1 + xlen - 3; x += 5)
                            {
                                for (int z = z1 + 3; z <= z1 + zlen - 3; z += 5)
                                {
                                    bm.SetID(x, 63, z, BlockType.GRASS);
                                    BlockShapes.MakeBlock(x, 64, z, BlockType.SAPLING, intSaplingType);
                                }
                            }
                            break;

                        case FarmTypes.Cactus:
                            int intAttempts = 0;
                            do
                            {
                                int  xCactus      = RandomHelper.Next(x1 + 1, x1 + xlen);
                                int  zCactus      = RandomHelper.Next(z1 + 1, z1 + zlen);
                                bool booValidFarm = true;
                                for (int xCheck = xCactus - 1; xCheck <= xCactus + 1 && booValidFarm; xCheck++)
                                {
                                    for (int zCheck = zCactus - 1; zCheck <= zCactus + 1 && booValidFarm; zCheck++)
                                    {
                                        if (bm.GetID(xCheck, 64, zCheck) != BlockType.AIR)
                                        {
                                            booValidFarm = false;
                                        }
                                    }
                                }
                                if (booValidFarm)
                                {
                                    bm.SetID(xCactus, 64, zCactus, BlockType.CACTUS);
                                    if (RandomHelper.NextDouble() > 0.5)
                                    {
                                        bm.SetID(xCactus, 65, zCactus, BlockType.CACTUS);
                                    }
                                }
                            }while (++intAttempts < 100);
                            break;

                        case FarmTypes.Wheat:
                            BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen,
                                                         BlockType.GLASS, 0, -1);
                            BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1,
                                                     BlockType.GLASS, 0);
                            break;
                            // no need for a default, because there's nothing to do for the other farms
                        }

                        for (int x = x1 + 1; x <= x1 + xlen - 1; x++)
                        {
                            for (int z = z1 + 1; z <= z1 + zlen - 1; z++)
                            {
                                switch (curFarm)
                                {
                                case FarmTypes.Cactus:
                                    bm.SetID(x, 63, z, BlockType.SAND);
                                    break;

                                case FarmTypes.Wheat:
                                    if (z == z1 + 1)
                                    {
                                        bm.SetID(x, 63, z, BlockType.DOUBLE_SLAB);
                                    }
                                    else if (x % 2 == 0)
                                    {
                                        BlockShapes.MakeBlock(x, 63, z, BlockType.FARMLAND, 1);
                                        bm.SetID(x, 64, z, BlockType.CROPS);
                                    }
                                    else
                                    {
                                        bm.SetID(x, 63, z, BlockType.STATIONARY_WATER);
                                    }
                                    break;

                                case FarmTypes.SugarCane:
                                    if (z != z1 + 1)
                                    {
                                        if (x % 2 == 0)
                                        {
                                            bm.SetID(x, 64, z, BlockType.SUGAR_CANE);
                                            if (RandomHelper.Next(100) > 50)
                                            {
                                                bm.SetID(x, 65, z, BlockType.SUGAR_CANE);
                                            }
                                        }
                                        else
                                        {
                                            bm.SetID(x, 63, z, BlockType.STATIONARY_WATER);
                                        }
                                    }
                                    break;
                                    // no need for a default, because there's nothing to do for the other farms
                                }
                            }
                        }
                        int intDoorPosition = x1 + RandomHelper.Next(1, xlen - 1);
                        if (curFarm == FarmTypes.Wheat)
                        {
                            bm.SetID(intDoorPosition, 63, z1, BlockType.DOUBLE_SLAB);
                        }
                        if (intWallMaterial != 0)
                        {
                            BlockShapes.MakeBlock(intDoorPosition, 64, z1, BlockType.WOOD_DOOR, 4);
                            BlockShapes.MakeBlock(intDoorPosition, 65, z1, BlockType.WOOD_DOOR,
                                                  4 + (int)DoorState.TOPHALF);
                        }
                        intFail = 0;
                        if (++intFarms > 10)
                        {
                            world.Save();
                            intFarms = 0;
                        }
                    }
                }
            }
            MakeMiniPondsAndHills(world, bm, intFarmLength, intMapLength);
            MakeFlowers(bm, intFarmLength, intMapLength);
        }
Exemplo n.º 12
0
        public static void MakeFarms(BetaWorld world, BlockManager bm, frmMace frmLogForm)
        {
            if (City.HasFarms)
            {
                frmLogForm.UpdateLog("Creating farm buildings", true, true);
                AddBuildings(bm);
                frmLogForm.UpdateLog("Creating farms and outside features", true, true);
                int intFail  = 0;
                int intFarms = 0;
                while (intFail <= 500)
                {
                    int xlen = RandomHelper.Next(8, 26);
                    int x1   = RandomHelper.Next(5, City.MapLength - (5 + xlen));
                    int zlen = RandomHelper.Next(8, 26);
                    int z1   = RandomHelper.Next(5, City.MapLength - (5 + zlen));
                    if (!(x1 >= City.FarmLength && z1 >= City.FarmLength &&
                          x1 <= City.MapLength - City.FarmLength && z1 <= City.MapLength - City.FarmLength))
                    {
                        bool booValid = true;
                        for (int x = x1 - 2; x <= x1 + xlen + 2 && booValid; x++)
                        {
                            for (int z = z1 - 2; z <= z1 + zlen + 2 && booValid; z++)
                            {
                                // make sure it doesn't overlap with the spawn point or another farm
                                if ((x == City.MapLength / 2 && z == SpawnZ) ||
                                    bm.GetID(x, 63, z) != City.GroundBlockID ||
                                    bm.GetID(x, 64, z) != BlockInfo.Air.ID)
                                {
                                    booValid = false;
                                    intFail++;
                                }
                            }
                        }
                        if (booValid)
                        {
                            // first there is a 25% chance of a hill or pond
                            // if not, for large farms, there is a 50% chance it'll be an orchard
                            // if not, 33% are cactus, 33% are wheat and 33% are sugarcane

                            FarmTypes curFarm;
                            int       intFarmType = RandomHelper.Next(100);
                            if (xlen >= 10 && zlen >= 10 && intFarmType > 75)
                            {
                                if (RandomHelper.NextDouble() > 0.5)
                                {
                                    curFarm = FarmTypes.Pond;
                                    MakePond(bm, x1, xlen, z1, zlen, false);
                                }
                                else
                                {
                                    curFarm = FarmTypes.Hill;
                                    MakeHill(bm, x1, xlen, z1, zlen, false);
                                }
                            }
                            else
                            {
                                intFarmType = RandomHelper.Next(100);
                                if (((xlen >= 11 && zlen >= 16) || (xlen >= 16 && zlen >= 11)) && intFarmType > 50)
                                {
                                    curFarm = FarmTypes.Orchard;
                                    xlen    = ((int)((xlen - 1) / 5) * 5) + 1;
                                    zlen    = ((int)((zlen - 1) / 5) * 5) + 1;
                                }
                                else
                                {
                                    intFarmType = RandomHelper.Next(3);
                                    if (intFarmType == 2)
                                    {
                                        curFarm = FarmTypes.Cactus;
                                    }
                                    else if (intFarmType == 1)
                                    {
                                        curFarm = FarmTypes.Wheat;
                                        xlen   += (xlen % 2) - 1;
                                        zlen   += (zlen % 2) - 1;
                                    }
                                    else
                                    {
                                        curFarm = FarmTypes.SugarCane;
                                        xlen   += (xlen % 2) - 1;
                                        zlen   += (zlen % 2) - 1;
                                    }
                                }
                            }

                            int intWallMaterial = RandomHelper.NextDouble() > 0.5 ? BlockInfo.Fence.ID : BlockInfo.Leaves.ID;

                            switch (curFarm)
                            {
                            case FarmTypes.Hill:
                            case FarmTypes.Pond:
                                intWallMaterial = 0;
                                break;

                            case FarmTypes.SugarCane:
                            case FarmTypes.Mushroom:
                                if (RandomHelper.NextDouble() > 0.5)
                                {
                                    intWallMaterial = 0;
                                }
                                break;

                            case FarmTypes.Wheat:
                                intWallMaterial = BlockInfo.Leaves.ID;
                                break;
                                // no need for default - the other types don't need anything here
                            }
#pragma warning disable
                            switch (intWallMaterial)
                            {
                            case BlockType.FENCE:
                                BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen,
                                                             BlockInfo.Fence.ID, 0, -1);
                                break;

                            case BlockType.LEAVES:
                                // the saplings will all disappear if one of them is broken.
                                // so we put wood beneath them to stop that happening
                                BlockShapes.MakeHollowLayers(x1, x1 + xlen, 63, 63, z1, z1 + zlen,
                                                             BlockInfo.Wood.ID, 0, -1);
                                BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, BlockInfo.Leaves.ID, 0,
                                                             RandomHelper.RandomNumber((int)LeafType.OAK, (int)LeafType.SPRUCE,
                                                                                       (int)LeafType.BIRCH));
                                break;

                            case 0:
                                // no wall
                                break;

                            default:
                                Debug.Fail("Invalid switch result");
                                break;
                            }
#pragma warning restore

                            switch (curFarm)
                            {
                            case FarmTypes.Orchard:
                                int intSaplingType = RandomHelper.RandomNumber(SaplingBirchDataID,
                                                                               SaplingOakDataID,
                                                                               SaplingSpruceDataID);
                                for (int x = x1 + 3; x <= x1 + xlen - 3; x += 5)
                                {
                                    for (int z = z1 + 3; z <= z1 + zlen - 3; z += 5)
                                    {
                                        BlockShapes.MakeBlock(x, 63, z, City.GroundBlockID, City.GroundBlockData);
                                        BlockShapes.MakeBlock(x, 64, z, BlockInfo.Sapling.ID, intSaplingType);
                                    }
                                }
                                break;

                            case FarmTypes.Cactus:
                                int intAttempts = 0;
                                do
                                {
                                    int  xCactus      = RandomHelper.Next(x1 + 1, x1 + xlen);
                                    int  zCactus      = RandomHelper.Next(z1 + 1, z1 + zlen);
                                    bool booValidFarm = true;
                                    for (int xCheck = xCactus - 1; xCheck <= xCactus + 1 && booValidFarm; xCheck++)
                                    {
                                        for (int zCheck = zCactus - 1; zCheck <= zCactus + 1 && booValidFarm; zCheck++)
                                        {
                                            if (bm.GetID(xCheck, 64, zCheck) != BlockInfo.Air.ID)
                                            {
                                                booValidFarm = false;
                                            }
                                        }
                                    }
                                    if (booValidFarm)
                                    {
                                        bm.SetID(xCactus, 64, zCactus, BlockInfo.Cactus.ID);
                                        if (RandomHelper.NextDouble() > 0.5)
                                        {
                                            bm.SetID(xCactus, 65, zCactus, BlockInfo.Cactus.ID);
                                        }
                                    }
                                }while (++intAttempts < 100);
                                break;

                            case FarmTypes.Wheat:
                                BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen,
                                                             BlockInfo.Glass.ID, 0, -1);
                                BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1,
                                                         BlockInfo.Glass.ID, 0);
                                break;
                                // no need for a default, because there's nothing to do for the other farms
                            }

                            for (int x = x1 + 1; x <= x1 + xlen - 1; x++)
                            {
                                for (int z = z1 + 1; z <= z1 + zlen - 1; z++)
                                {
                                    switch (curFarm)
                                    {
                                    case FarmTypes.Cactus:
                                        bm.SetID(x, 63, z, BlockInfo.Sand.ID);
                                        break;

                                    case FarmTypes.Wheat:
                                        if (z == z1 + 1)
                                        {
                                            bm.SetID(x, 63, z, BlockInfo.DoubleSlab.ID);
                                        }
                                        else if (x % 2 == 0)
                                        {
                                            BlockShapes.MakeBlock(x, 63, z, BlockInfo.Farmland.ID, 1);
                                            bm.SetID(x, 64, z, BlockInfo.Crops.ID);
                                        }
                                        else
                                        {
                                            bm.SetID(x, 63, z, BlockInfo.StationaryWater.ID);
                                        }
                                        break;

                                    case FarmTypes.SugarCane:
                                        if (z != z1 + 1)
                                        {
                                            if (x % 2 == 0)
                                            {
                                                bm.SetID(x, 64, z, BlockInfo.SugarCane.ID);
                                                if (RandomHelper.Next(100) > 50)
                                                {
                                                    bm.SetID(x, 65, z, BlockInfo.SugarCane.ID);
                                                }
                                            }
                                            else
                                            {
                                                bm.SetID(x, 63, z, BlockInfo.StationaryWater.ID);
                                            }
                                        }
                                        break;
                                        // no need for a default, because there's nothing to do for the other farms
                                    }
                                }
                            }
                            int intDoorPosition = x1 + RandomHelper.Next(1, xlen - 1);
                            if (curFarm == FarmTypes.Wheat)
                            {
                                bm.SetID(intDoorPosition, 63, z1, BlockInfo.DoubleSlab.ID);
                            }
                            if (intWallMaterial != 0)
                            {
                                if (curFarm == FarmTypes.Wheat || intWallMaterial == BlockInfo.Leaves.ID)
                                {
                                    BlockShapes.MakeBlock(intDoorPosition, 64, z1, BlockInfo.WoodDoor.ID, 4);
                                    BlockShapes.MakeBlock(intDoorPosition, 65, z1, BlockInfo.WoodDoor.ID, 4 + (int)DoorState.TOPHALF);
                                }
                                else
                                {
                                    bm.SetID(intDoorPosition, 64, z1, BlockInfo.FenceGate.ID);
                                    bm.SetData(intDoorPosition, 64, z1, 0);
                                }
                            }
                            intFail = 0;
                            if (++intFarms > 10)
                            {
                                world.Save();
                                intFarms = 0;
                            }
                        }
                    }
                }
                MakeMiniPondsAndHills(world, bm);
            }
            if (City.HasFlowers)
            {
                MakeFlowers(world, bm);
            }
        }