示例#1
0
        private static void MakePond(BlockManager bm, int x, int xlen, int z, int zlen, bool booSmallPond)
        {
            int[,] intArea = new int[xlen, zlen];
            int a, b;

            int c = 0, d = 0, clen = -1, dlen = -1;
            if (!booSmallPond)
            {
                c = RandomHelper.Next(1, intArea.GetUpperBound(0) - 7);
                d = RandomHelper.Next(1, intArea.GetUpperBound(1) - 7);
                clen = RandomHelper.Next(3, 7);
                dlen = RandomHelper.Next(3, 7);
            }

            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, RandomHelper.Next(3, 6), true);
            intArea = CheckAgainstNeighbours(intArea, 6, 0, 2, 2, 1, false);
            intArea = CheckAgainstNeighbours(intArea, 14, 0, 3, 3, 1, false);

            bool booLava = (!booSmallPond && RandomHelper.NextDouble() < 0.15);

            for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++)
            {
                for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++)
                {
                    if (intArea[a, b] == 1)
                    {
                        bm.SetID(x + a, 64, z + b, BlockType.TALL_GRASS);
                        bm.SetData(x + a, 64, z + b, RandomHelper.Next(1, 3));
                    }
                    else
                    {
                        for (int y = 2; y <= intArea[a, b]; y++)
                        {
                            if (booLava)
                            {
                                bm.SetID(x + a, 65 - y, z + b, BlockType.STATIONARY_LAVA);
                            }
                            else
                            {
                                bm.SetID(x + a, 65 - y, z + b, BlockType.STATIONARY_WATER);
                            }
                        }
                    }
                }
            }
        }
        public void LinkRooms (BlockManager bm, int x1, int y1, int z1, int x2, int y2, int z2)
        {
            int xx = originx + (cellxlen + wallxwidth) * x1;
            int yy = originy + (cellylen + wallywidth) * y1;
            int zz = originz + (cellzlen + wallzwidth) * z1;

            if (x1 != x2) {
                xx = originx + (cellxlen + wallxwidth) * Math.Max(x1, x2);
                for (int xi = 0; xi < wallxwidth; xi++) {
                    int zc = zz + wallzwidth + (cellzlen / 2);
                    int yb = yy + wallywidth;
                    bm.SetID(xx + xi, yb, zc - 1, (int)BlockType.AIR);
                    bm.SetID(xx + xi, yb, zc, (int)BlockType.AIR);
                    bm.SetID(xx + xi, yb, zc + 1, (int)BlockType.AIR);
                    bm.SetID(xx + xi, yb + 1, zc - 1, (int)BlockType.AIR);
                    bm.SetID(xx + xi, yb + 1, zc, (int)BlockType.AIR);
                    bm.SetID(xx + xi, yb + 1, zc + 1, (int)BlockType.AIR);
                    bm.SetID(xx + xi, yb + 2, zc, (int)BlockType.AIR);
                }
            }
            else if (z1 != z2) {
                zz = originz + (cellzlen + wallzwidth) * Math.Max(z1, z2);
                for (int zi = 0; zi < wallxwidth; zi++) {
                    int xc = xx + wallxwidth + (cellxlen / 2);
                    int yb = yy + wallywidth;
                    bm.SetID(xc - 1, yb, zz + zi, (int)BlockType.AIR);
                    bm.SetID(xc, yb, zz + zi, (int)BlockType.AIR);
                    bm.SetID(xc + 1, yb, zz + zi, (int)BlockType.AIR);
                    bm.SetID(xc - 1, yb + 1, zz + zi, (int)BlockType.AIR);
                    bm.SetID(xc, yb + 1, zz + zi, (int)BlockType.AIR);
                    bm.SetID(xc + 1, yb + 1, zz + zi, (int)BlockType.AIR);
                    bm.SetID(xc, yb + 2, zz + zi, (int)BlockType.AIR);
                }
            }
            else if (y1 != y2) {
                yy = originy + (cellylen + wallywidth) * Math.Max(y1, y2);
                for (int yi = 0 - cellylen + 1; yi < wallywidth + 1; yi++) {
                    int xc = xx + wallxwidth + (cellxlen / 2);
                    int zc = zz + wallzwidth + (cellzlen / 2);

                    bm.SetID(xc, yy + yi, zc, (int)BlockType.BEDROCK);
                    bm.SetID(xc - 1, yy + yi, zc, (int)BlockType.LADDER);
                    bm.SetData(xc - 1, yy + yi, zc, 4);
                    bm.SetID(xc + 1, yy + yi, zc, (int)BlockType.LADDER);
                    bm.SetData(xc + 1, yy + yi, zc, 5);
                    bm.SetID(xc, yy + yi, zc - 1, (int)BlockType.LADDER);
                    bm.SetData(xc, yy + yi, zc - 1, 2);
                    bm.SetID(xc, yy + yi, zc + 1, (int)BlockType.LADDER);
                    bm.SetData(xc, yy + yi, zc + 1, 3);
                }
            }
        }
示例#3
0
        private static void MakeHill(BlockManager bm, int x, int xlen, int z, int zlen, bool booMini)
        {
            int[,] intArea = new int[xlen, zlen];
            int a, b;

            int c = 0, d = 0, clen = -1, dlen = -1;
            if (!booMini)
            {
                c = RandomHelper.Next(1, intArea.GetUpperBound(0) - 7);
                d = RandomHelper.Next(1, intArea.GetUpperBound(1) - 7);
                clen = RandomHelper.Next(3, 7);
                dlen = RandomHelper.Next(3, 7);
            }

            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, RandomHelper.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) - 1; a++)
            {
                for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++)
                {
                    for (int y = 1; y <= intArea[a, b]; y++)
                    {
                        if (y == intArea[a, b])
                        {
                            bm.SetID(x + a, y + 63, z + b, BlockType.GRASS);
                            switch (RandomHelper.Next(0, 10))
                            {
                                case 0:
                                    bm.SetID(x + a, y + 64, z + b, BlockType.RED_ROSE);
                                    break;
                                case 1:
                                    bm.SetID(x + a, y + 64, z + b, BlockType.YELLOW_FLOWER);
                                    break;
                                case 2:
                                case 3:
                                    bm.SetID(x + a, y + 64, z + b, BlockType.TALL_GRASS);
                                    bm.SetData(x + a, y + 64, z + b, RandomHelper.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, BlockType.DIRT);
                        }
                    }
                }
            }
        }
示例#4
0
 private static void MakeFlowers(BlockManager bm, int intFarmLength, int intMapLength)
 {
     for (int x = 0; x <= intMapLength; x++)
     {
         for (int z = 0; z <= intMapLength; z++)
         {
             if (x <= intFarmLength || z <= intFarmLength ||
                 x >= intMapLength - intFarmLength || z >= intMapLength - intFarmLength)
             {
                 bool booFree = true;
                 for (int xCheck = x - 1; xCheck <= x + 1 && booFree; xCheck++)
                 {
                     for (int zCheck = z - 1; zCheck <= z + 1 && booFree; zCheck++)
                     {
                         booFree = bm.GetID(xCheck, 63, zCheck) == BlockType.GRASS &&
                                   bm.GetID(xCheck, 64, zCheck) == BlockType.AIR;
                     }
                 }
                 if (booFree && RandomHelper.NextDouble() > 0.90)
                 {
                     switch (RandomHelper.Next(4))
                     {
                         case 0:
                             bm.SetID(x, 64, z, BlockType.RED_ROSE);
                             break;
                         case 1:
                             bm.SetID(x, 64, z, BlockType.YELLOW_FLOWER);
                             break;
                         case 2:
                         case 3:
                             bm.SetID(x, 64, z, BlockType.TALL_GRASS);
                             bm.SetData(x, 64, z, RandomHelper.Next(1, 3));
                             break;
                         default:
                             Debug.Fail("Invalid switch result");
                             break;
                     }
                 }
             }
         }
     }
 }
示例#5
0
        public static void InsertBuilding(BlockManager bmDest, int[,] intArea, int intBlockStart,
                                          int x1dest, int z1dest, Building bldInsert, int y1dest)
        {
            List<Spawner> lstSpawners = new List<Spawner>();
            _lstInstanceSigns.Clear();
            int intRandomWoolColour = RandomHelper.Next(16);
            int intSourceX = 0, intSourceZ = 0;
            int intRotate = -1;
            if (bldInsert.btThis == BuildingTypes.MineshaftSection)
            {
                intRotate = 0;
            }
            else
            {
                for (int intDistance = 0; intRotate == -1 && intDistance < 10; intDistance++)
                {
                    for (int intCheck = 0; intRotate == -1 && intCheck <= bldInsert.intSizeX; intCheck++)
                    {
                        if (CheckArea(intArea, x1dest + intCheck, z1dest - intDistance) == 1)
                        {
                            intRotate = 0;
                        }
                        else if (CheckArea(intArea, x1dest - intDistance, z1dest + intCheck) == 1)
                        {
                            intRotate = 1;
                        }
                        else if (CheckArea(intArea, x1dest + bldInsert.intSizeX + intDistance, z1dest + intCheck) == 1)
                        {
                            intRotate = 2;
                        }
                        else if (CheckArea(intArea, x1dest + intCheck, z1dest + bldInsert.intSizeZ + intDistance) == 1)
                        {
                            intRotate = 3;
                        }
                    }
                }
            }
            if (intRotate == -1)
            {
                intRotate = RandomHelper.Next(4);
            }

            for (int x = 0; x < bldInsert.intSizeX; x++)
            {
                for (int z = 0; z < bldInsert.intSizeZ; z++)
                {
                    switch (intRotate)
                    {
                        case 0:
                            intSourceX = x;
                            intSourceZ = z;
                            break;
                        case 1:
                            intSourceX = (bldInsert.intSizeX - 1) - z;
                            intSourceZ = x;
                            break;
                        case 2:
                            intSourceX = z;
                            intSourceZ = (bldInsert.intSizeZ - 1) - x;
                            break;
                        case 3:
                            intSourceX = (bldInsert.intSizeX - 1) - x;
                            intSourceZ = (bldInsert.intSizeZ - 1) - z;
                            break;
                        default:
                            Debug.Fail("Invalid switch result");
                            break;
                    }

                    int intSourceEndY;
                    if (bldInsert.btThis == BuildingTypes.MineshaftSection)
                    {
                        intSourceEndY = bldInsert.intSourceStartY + 4;
                    }
                    else
                    {
                        for (intSourceEndY = 128; intSourceEndY > 64; intSourceEndY--)
                        {
                            if (_bmSource.GetID(intSourceX + bldInsert.intSourceX, intSourceEndY,
                                                intSourceZ + bldInsert.intSourceZ) != BlockType.AIR)
                            {
                                break;
                            }
                        }
                    }
                    for (int ySource = bldInsert.intSourceStartY; ySource <= intSourceEndY; ySource++)
                    {
                        int yDest = ySource;
                        if (bldInsert.btThis == BuildingTypes.MineshaftSection)
                        {
                            yDest = y1dest + (ySource - bldInsert.intSourceStartY);
                        }

                        if (bldInsert.btThis == BuildingTypes.MineshaftSection ||
                            ((yDest != 64 || bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) == BlockType.AIR) &&
                            bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) != BlockType.WOOD_PLANK))
                        {
                            int intBlockID = _bmSource.GetID(intSourceX + bldInsert.intSourceX, ySource,
                                                             intSourceZ + bldInsert.intSourceZ);
                            int intBlockData = _bmSource.GetData(intSourceX + bldInsert.intSourceX, ySource,
                                                                 intSourceZ + bldInsert.intSourceZ);
                            bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockID);
                            bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockData);

                            #region import paintings
                            // todo: test for mineshaft features
                            foreach (EntityPainting entPainting in _AllEntityPainting)
                            {
                                if (entPainting.TileX == intSourceX + bldInsert.intSourceX &&
                                    entPainting.TileY == ySource &&
                                    entPainting.TileZ == intSourceZ + bldInsert.intSourceZ)
                                {
                                    EntityPainting entNewPainting = (EntityPainting)entPainting.Copy();
                                    entNewPainting.TileX = intBlockStart + x + x1dest;
                                    entNewPainting.TileY = yDest;
                                    entNewPainting.TileZ = intBlockStart + z + z1dest;
                                    entNewPainting.Position.X = entNewPainting.TileX;
                                    entNewPainting.Position.Z = entNewPainting.TileZ;
                                    entNewPainting.Direction = BlockHelper.RotatePortrait(entPainting.Direction,
                                                                                          intRotate);
                                    ChunkRef chunkBuilding = _cmDest.GetChunkRef((intBlockStart + x + x1dest) / 16,
                                                                                 (intBlockStart + z + z1dest) / 16);
                                    chunkBuilding.Entities.Add(entNewPainting);
                                    _cmDest.Save();
                                }
                            }
                            #endregion
                            #region Rotation
                            if (intRotate > 0)
                            {
                                switch (intBlockID)
                                {
                                    case BlockType.PORTAL:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotatePortal(intBlockData, intRotate));
                                        break;
                                    case BlockType.SIGN_POST:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateSignPost(intBlockData, intRotate));
                                        break;
                                    case BlockType.STONE_BUTTON:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateButton(intBlockData, intRotate));
                                        break;
                                    case BlockType.PUMPKIN:
                                    case BlockType.JACK_O_LANTERN:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotatePumpkin(intBlockData, intRotate));
                                        break;
                                    case BlockType.IRON_DOOR:
                                    case BlockType.WOOD_DOOR:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateDoor(intBlockData, intRotate));
                                        break;
                                    case BlockType.TRAPDOOR:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateTrapdoor(intBlockData, intRotate));
                                        break;
                                    case BlockType.BED:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateBed(intBlockData, intRotate));
                                        break;
                                    case BlockType.REDSTONE_TORCH_OFF:
                                    case BlockType.REDSTONE_TORCH_ON:
                                    case BlockType.TORCH:
                                    case BlockType.LEVER:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateTorchOrLever(intBlockData, intRotate));
                                        break;
                                    case BlockType.WALL_SIGN:
                                    case BlockType.LADDER:
                                    case BlockType.DISPENSER:
                                    case BlockType.FURNACE:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                        BlockHelper.RotateWallSignOrLadderOrFurnanceOrDispenser(
                                                          intBlockData, intRotate));
                                        break;
                                    case BlockType.COBBLESTONE_STAIRS:
                                    case BlockType.WOOD_STAIRS:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                        BlockHelper.RotateStairs(intBlockData, intRotate));
                                        break;
                                    // no need for a default - all other blocks are okay
                                }
                            }
                            #endregion
                            #region Handle entities
                            switch (intBlockID)
                            {
                                case BlockType.SPONGE:
                                    bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.WOOL);
                                    bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                   intRandomWoolColour);
                                    break;
                                case BlockType.CHEST:
                                    TileEntityChest tec = (TileEntityChest)_bmSource.GetTileEntity(
                                        intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ);
                                    if (_booIncludeItemsInChests)
                                    {
                                        if (tec.Items[0] != null)
                                        {
                                            if (tec.Items[0].ID == ItemInfo.Paper.ID &&
                                                tec.Items[0].Count == 3)
                                            {
                                                tec = MakeHouseChest();
                                            }
                                            if (tec.Items[0].ID == ItemInfo.Paper.ID &&
                                                tec.Items[0].Count == 4)
                                            {
                                                tec = MakeTreasureChest();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        tec.Items.ClearAllItems();
                                    }
                                    bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tec);
                                    break;
                                case BlockType.FURNACE:
                                case BlockType.MONSTER_SPAWNER:
                                case BlockType.NOTE_BLOCK:
                                    bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                         _bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, ySource,
                                                                                 intSourceZ + bldInsert.intSourceZ));
                                    break;
                                case BlockType.SIGN_POST:
                                case BlockType.WALL_SIGN:
                                    #region Determine sign text
                                    int intUniqueType = 0;
                                    TileEntitySign tes = (TileEntitySign)_bmSource.
                                        GetTileEntity(intSourceX + bldInsert.intSourceX, ySource,
                                                      intSourceZ + bldInsert.intSourceZ);
                                    string strSourceSign = tes.Text1 + " " + tes.Text2 + " " + tes.Text3 + " " + tes.Text4;
                                    switch (strSourceSign.Substring(0, 1))
                                    {
                                        case "2":
                                        case "1":
                                        case "0":
                                            intUniqueType = Convert.ToInt32(strSourceSign.Substring(0, 1));
                                            strSourceSign = strSourceSign.Remove(0, 1);
                                            break;
                                        default:
                                            intUniqueType = 0;
                                            break;
                                    }
                                    if (tes.Text1.ToLower() == "commentsign" || tes.Text1.ToLower() == "comment sign")
                                    {
                                        // these exist to give advice to people in the resource world.
                                        // so we just remove them from the real world
                                        bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                     BlockType.AIR);
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0);
                                    }
                                    if (tes.Text1.ToLower() == "spawner" || tes.Text1.ToLower() == "gspawner")
                                    {
                                        if (!tes.Text2.ToLower().StartsWith("g") || tes.Text2.ToLower() == "[randomenemy]" || _booIncludeGhostdancerSpawners)
                                        {
                                            Spawner spawnerCurrent = new Spawner();
                                            if (tes.Text2.ToLower() == "[randomenemy]")
                                            {
                                                if (_booIncludeGhostdancerSpawners)
                                                {
                                                    spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie", "GGeist", "GGrim");
                                                }
                                                else
                                                {
                                                    spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie");
                                                }
                                            }
                                            else
                                            {
                                                spawnerCurrent.strEntityID = tes.Text2;
                                            }

                                            if (tes.Text3.Split(' ').GetUpperBound(0) == 2)
                                            {
                                                spawnerCurrent.sy = yDest + Convert.ToInt32(tes.Text3.Split(' ')[1]);
                                                spawnerCurrent.sx = 0;
                                                spawnerCurrent.sz = 0;
                                                switch (intRotate)
                                                {
                                                    case 0:
                                                        spawnerCurrent.sx = intBlockStart + x + x1dest +
                                                                            (Convert.ToInt32(tes.Text3.Split(' ')[0]));
                                                        spawnerCurrent.sz = intBlockStart + z + z1dest +
                                                                            (Convert.ToInt32(tes.Text3.Split(' ')[2]));
                                                        break;
                                                    case 1:
                                                        spawnerCurrent.sx = intBlockStart + x + x1dest +
                                                                            (Convert.ToInt32(tes.Text3.Split(' ')[2]));
                                                        spawnerCurrent.sz = intBlockStart + z + z1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0]));
                                                        break;
                                                    case 2:
                                                        spawnerCurrent.sx = intBlockStart + x + x1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2]));
                                                        spawnerCurrent.sz = intBlockStart + z + z1dest +
                                                                            (Convert.ToInt32(tes.Text3.Split(' ')[0]));
                                                        break;
                                                    case 3:
                                                        spawnerCurrent.sx = intBlockStart + x + x1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0]));
                                                        spawnerCurrent.sz = intBlockStart + z + z1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2]));
                                                        break;
                                                }
                                            }
                                            else
                                            {
                                                spawnerCurrent.sx = intBlockStart + x + x1dest;
                                                spawnerCurrent.sy = yDest - 2;
                                                spawnerCurrent.sz = intBlockStart + z + z1dest;
                                            }
                                            if (tes.Text4.ToLower() == "no")
                                            {
                                                spawnerCurrent.booGrass = false;
                                            }
                                            else if (tes.Text4.Split(' ').GetUpperBound(0) == 2)
                                            {
                                                spawnerCurrent.gy = yDest + Convert.ToInt32(tes.Text4.Split(' ')[1]);
                                                switch (intRotate)
                                                {
                                                    case 0:
                                                        spawnerCurrent.gx = intBlockStart + x + x1dest +
                                                                            (Convert.ToInt32(tes.Text4.Split(' ')[0]));
                                                        spawnerCurrent.gz = intBlockStart + z + z1dest +
                                                                            (Convert.ToInt32(tes.Text4.Split(' ')[2]));
                                                        break;
                                                    case 1:
                                                        spawnerCurrent.gx = intBlockStart + x + x1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2]));
                                                        spawnerCurrent.gz = intBlockStart + z + z1dest +
                                                                            (Convert.ToInt32(tes.Text4.Split(' ')[0]));
                                                        break;
                                                    case 2:
                                                        spawnerCurrent.gx = intBlockStart + x + x1dest +
                                                                            (Convert.ToInt32(tes.Text4.Split(' ')[2]));
                                                        spawnerCurrent.gz = intBlockStart + z + z1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0]));
                                                        break;
                                                    case 3:
                                                        spawnerCurrent.gx = intBlockStart + x + x1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0]));
                                                        spawnerCurrent.gz = intBlockStart + z + z1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2]));
                                                        break;
                                                }
                                                spawnerCurrent.booGrass = true;
                                            }
                                            else
                                            {
                                                spawnerCurrent.gx = intBlockStart + x + x1dest;
                                                spawnerCurrent.gy = yDest - 1;
                                                spawnerCurrent.gz = intBlockStart + z + z1dest;
                                                spawnerCurrent.booGrass = true;
                                            }
                                            lstSpawners.Add(spawnerCurrent);
                                        }
                                        bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.AIR);
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0);
                                    }
                                    else if (strSourceSign.Contains("["))
                                    {
                                        string strSignText;
                                        bool booDuplicate;
                                        int intFail = 0;
                                        do
                                        {
                                            strSignText = SignText(strSourceSign);
                                            booDuplicate = false;
                                            switch (intUniqueType)
                                            {
                                                case 1: // unique by instance
                                                    booDuplicate = _lstInstanceSigns.Contains(strSignText);
                                                    break;
                                                case 2: // unique by city
                                                    booDuplicate = _lstCitySigns.Contains(strSignText);
                                                    break;
                                            }
                                            if (++intFail > 100)
                                            {
                                                Debug.WriteLine("Could not make a unique sign for " + strSourceSign);
                                                booDuplicate = false;
                                            }
                                        } while (booDuplicate);
                                        _lstCitySigns.Add(strSignText);
                                        _lstInstanceSigns.Add(strSignText);
                                        string[] strRandomSign = Utils.TextToSign(Utils.ConvertStringToSignText(strSignText));
                                        tes.Text1 = strRandomSign[0];
                                        tes.Text2 = strRandomSign[1];
                                        tes.Text3 = strRandomSign[2];
                                        tes.Text4 = strRandomSign[3];
                                        bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes);
                                    }
                                    else
                                    {
                                        bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes);
                                    }
                                    break;
                                    #endregion
                                // no need for a default - all the other blocks are okay
                            }
                            #endregion
                        }
                    }
                }
            }
            foreach (Spawner spnAdd in lstSpawners)
            {
                bmDest.SetID(spnAdd.sx, spnAdd.sy, spnAdd.sz, BlockType.MONSTER_SPAWNER);
                TileEntityMobSpawner tems = new TileEntityMobSpawner();
                tems.EntityID = spnAdd.strEntityID;
                bmDest.SetTileEntity(spnAdd.sx, spnAdd.sy, spnAdd.sz, tems);
                if (spnAdd.booGrass)
                {
                    bmDest.SetID(spnAdd.gx, spnAdd.gy, spnAdd.gz, BlockType.GRASS);
                }
            }
        }
示例#6
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
        }
示例#7
0
        private void BuildHouse(int X, int Z, int AverageHeight, BlockManager bm)
        {
            for (int x = 0; x < _fp.X; ++x) {
                for (int z = 0; z < _fp.Z; ++z) {
                    if (x == 0 || x == _fp.X - 1 || z == 0 || z == _fp.Z - 1) {
                        //Walls.
                        for (int y = AverageHeight; y < AverageHeight + 4; ++y) {
                            //Walls should be wood.
                            if (y != AverageHeight + 2)
                                bm.SetID (x + X, y, z + Z, BlockInfo.Wood.ID);
                            else
                                bm.SetID (x + X, y, z + Z, BlockInfo.Glass.ID);
                        }
                    } else {
                        //Floor is wooden planks.
                        bm.SetID (x + X, AverageHeight, z + Z, BlockInfo.WoodPlank.ID);
                    }
                    //Roof.
                    int peak = (int) (x * (x - _fp.X - 1) + z * (z - _fp.Z - 1));
                    if (_o == Orientation.NORTH || _o == Orientation.SOUTH) {
                        //Absolute value function. Graph makes the peak of the roof.
                        //peak = (Abs ((int)((x - 0.5) - _fp.X / 2.0)) * -1) + 7;
                        //Make the stairs face the right direction.
                        bm.SetData (x + X, AverageHeight + peak, z + Z, ((x > _fp.X / 2.0) ? 0x1 : 0x0));
                    } else {
                        //Absolute value function. Graph makes the peak of the roof.
                        //peak = (Abs ((int)((z - 0.5) - _fp.X / 2.0)) * -1) + 7;
                        //Make the stairs face the right direction.
                        bm.SetData (x + X, AverageHeight + peak, z + Z, ((z + 0.5 > _fp.Z / 2.0) ? 0x3 : 0x2));
                    }
                    bm.SetID (x + X, AverageHeight + peak, z + Z, BlockInfo.WoodStairs.ID);

                    if (x == 0 || x == _fp.X - 1 || z == 0 || z == _fp.Z - 1) { //If it is is the sides, fill up to the house height.
                        for (int y = AverageHeight + 4; y < AverageHeight + peak; ++y) {
                            bm.SetID (x + X, y, z + Z, BlockInfo.Wood.ID);
                        }
                    }
                }
            }
        }