Exemple #1
0
 public static structPoint MakeInsideCity(BlockManager bm, BetaWorld worldDest, int[,] intArea,
                                          int intFarmLength, int intMapLength, bool booIncludePaths)
 {
     int intBlockStart = intFarmLength + 13;
     structPoint spMineshaftEntrance = MakeBuildings(bm, intArea, intBlockStart, worldDest, intFarmLength);
     worldDest.Save();
     if (!booIncludePaths)
     {
         RemovePaths(bm, intArea, intBlockStart);
     }
     else
     {
         JoinPathsToRoad(bm, intMapLength, intFarmLength);
     }
     MakeStreetLights(bm, intMapLength, intFarmLength);
     MakeFlowers(bm, worldDest, intFarmLength, intMapLength);
     return spMineshaftEntrance;
 }
Exemple #2
0
 public static void PositionRails(BetaWorld worldDest, BlockManager bm, int intCitySize)
 {
     int intReplaced = 0;
     for (int x = 0; x < intCitySize; x++)
     {
         for (int z = 0; z < intCitySize; z++)
         {
             for (int y = 0; y < 128; y++)
             {
                 if (bm.GetID(x, y, z) == BlockType.RAILS)
                 {
                     BlockHelper.MakeRail(x, y, z);
                     if (++intReplaced > 100)
                     {
                         worldDest.Save();
                         intReplaced = 0;
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
 public static void MakeWalls(BetaWorld world, int intFarmLength, int intMapLength,
                              string strCityEmblem, string strOutsideLights,
                              int intWallMaterial)
 {
     // walls
     for (int a = intFarmLength + 6; a <= intFarmLength + 10; a++)
     {
         BlockShapes.MakeHollowLayers(a, intMapLength - a, 1, 72, a, intMapLength - a, intWallMaterial, 0, -1);
         world.Save();
     }
     // outside and inside edges at the top
     BlockShapes.MakeHollowLayers(intFarmLength + 5, intMapLength - (intFarmLength + 5), 72, 73,
                                  intFarmLength + 5, intMapLength - (intFarmLength + 5), intWallMaterial, 0, -1);
     BlockShapes.MakeHollowLayers(intFarmLength + 11, intMapLength - (intFarmLength + 11), 72, 73,
                                  intFarmLength + 11, intMapLength - (intFarmLength + 11), intWallMaterial, 0, -1);
     // alternating blocks on top of the edges
     for (int a = intFarmLength + 6; a <= intMapLength - (intFarmLength + 6); a += 2)
     {
         BlockShapes.MakeBlock(a, 74, intFarmLength + 5, intWallMaterial, 2, 100, -1);
     }
     for (int a = intFarmLength + 12; a <= intMapLength - (intFarmLength + 12); a += 2)
     {
         BlockShapes.MakeBlock(a, 74, intFarmLength + 11, intWallMaterial, 2, 100, -1);
     }
     // ladder
     BlockHelper.MakeLadder((intMapLength / 2) - 5, 64, 72, intFarmLength + 11, 2, intWallMaterial);
     BlockShapes.MakeBlock((intMapLength / 2) - 5, 73, intFarmLength + 11, BlockType.AIR, 2, 100, -1);
     // decorations at the gates
     switch (strOutsideLights)
     {
         case "Fire":
             // fire above the entrances
             BlockShapes.MakeBlock((intMapLength / 2) - 1, 69, intFarmLength + 5, BlockType.NETHERRACK, 2, 100, -1);
             BlockShapes.MakeBlock((intMapLength / 2), 69, intFarmLength + 5, BlockType.NETHERRACK, 2, 100, -1);
             BlockShapes.MakeBlock((intMapLength / 2) - 1, 70, intFarmLength + 5, BlockType.FIRE, 2, 100, -1);
             BlockShapes.MakeBlock((intMapLength / 2), 70, intFarmLength + 5, BlockType.FIRE, 2, 100, -1);
             // fire on the outside walls
             for (int a = intFarmLength + 8; a < (intMapLength / 2) - 9; a += 4)
             {
                 BlockShapes.MakeBlock(a, 69, intFarmLength + 5, BlockType.NETHERRACK, 2, 100, -1);
                 BlockShapes.MakeBlock(a, 70, intFarmLength + 5, BlockType.FIRE, 2, 100, -1);
             }
             break;
         case "Torches":
             // torches above the entrances
             BlockHelper.MakeTorch((intMapLength / 2), 70, intFarmLength + 5, intWallMaterial, 2);
             BlockHelper.MakeTorch((intMapLength / 2) - 1, 70, intFarmLength + 5, intWallMaterial, 2);
             // torches on the outside walls
             for (int a = intFarmLength + 8; a < (intMapLength / 2) - 9; a += 4)
             {
                 BlockHelper.MakeTorch(a, 70, intFarmLength + 5, intWallMaterial, 2);
             }
             break;
         case "None":
             break;
         default:
             Debug.Fail("Invalid switch result");
             break;
     }
     // torches on the inside walls
     for (int a = intFarmLength + 16; a < (intMapLength / 2); a += 4)
     {
         BlockHelper.MakeTorch(a, 69, intFarmLength + 11, intWallMaterial, 2);
     }
     // torches on the wall roofs
     for (int a = intFarmLength + 16; a < (intMapLength / 2); a += 4)
     {
         BlockShapes.MakeBlock(a, 73, intFarmLength + 8, BlockType.TORCH, 2, 100, -1);
     }
     MakeEmblem(intFarmLength, intMapLength, strCityEmblem);
 }
Exemple #4
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);
        }
Exemple #5
0
 private static void MakeMiniPondsAndHills(BetaWorld world, BlockManager bm, int intFarmLength, int intMapLength)
 {
     int intFail = 0;
     int intAdded = 0;
     do
     {
         int xlen = RandomHelper.Next(4, 12);
         int x1 = RandomHelper.Next(1, intMapLength - (1 + xlen));
         int zlen = RandomHelper.Next(4, 12);
         int z1 = RandomHelper.Next(1, intMapLength - (1 + zlen));
         if (!(x1 >= intFarmLength && z1 >= intFarmLength &&
               x1 <= intMapLength - intFarmLength && z1 <= intMapLength - intFarmLength))
         {
             bool booValid = true;
             for (int x = x1 - 1; x <= x1 + xlen + 1 && booValid; x++)
             {
                 for (int z = z1 - 1; z <= z1 + zlen + 1 && 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;
                     }
                 }
             }
             if (booValid)
             {
                 if (RandomHelper.NextDouble() > 0.5)
                 {
                     MakePond(bm, x1, xlen, z1, zlen, true);
                 }
                 else
                 {
                     MakeHill(bm, x1, xlen, z1, zlen, true);
                 }
                 intFail = 0;
                 if (++intAdded % 25 == 0)
                 {
                     world.Save();
                 }
             }
             else
             {
                 intFail++;
             }
         }
     } while (intFail < 500);
 }
Exemple #6
0
 private static void MakeFlowers(BlockManager bmDest, BetaWorld worldDest, int intFarmLength, int intMapLength)
 {
     int intFlowers = 0;
     for (int x = intFarmLength + 11; x <= intMapLength - (intFarmLength + 11); x++)
     {
         for (int z = intFarmLength + 11; z <= intMapLength - (intFarmLength + 11); z++)
         {
             if (bmDest.GetID(x, 63, z) == BlockType.GRASS &&
                 bmDest.GetID(x, 64, z) == BlockType.AIR)
             {
                 bool booFree = true;
                 int intFree = 0;
                 for (int xCheck = x - 1; xCheck <= x + 1 && booFree; xCheck++)
                 {
                     for (int zCheck = z - 1; zCheck <= z + 1 && booFree; zCheck++)
                     {
                         if (bmDest.GetID(xCheck, 63, zCheck) == BlockType.GRASS &&
                             bmDest.GetID(xCheck, 64, zCheck) == BlockType.AIR)
                         {
                             intFree++;
                         }
                     }
                 }
                 if (intFree >= MinimumFreeNeighboursNeededForFlowers &&
                     RandomHelper.NextDouble() <= FlowerChance)
                 {
                     AddFlowersToBlock(bmDest, x, z);
                     if (++intFlowers >= NumberOfFlowersBetweenSaves)
                     {
                         worldDest.Save();
                         intFlowers = 0;
                     }
                 }
             }
         }
     }
 }
Exemple #7
0
        private static structPoint MakeBuildings(BlockManager bmDest, int[,] intArea, int intBlockStart, BetaWorld world, int intFarmLength)
        {
            structPoint structLocationOfMineshaftEntrance = new structPoint();
            structLocationOfMineshaftEntrance.x = -1;
            structLocationOfMineshaftEntrance.z = -1;
            int intBuildings = 0;
            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int z = 0; z < intArea.GetLength(1); z++)
                {
                    // hack: this 100 to 500 stuff is all a bit hackish really, need to find a proper solution
                    if (intArea[x, z] >= 100 && intArea[x, z] <= 500)
                    {
                        SourceWorld.Building CurrentBuilding = SourceWorld.GetBuilding(intArea[x, z] - 100);
                        SourceWorld.InsertBuilding(bmDest, intArea, intBlockStart, x, z,
                                                   CurrentBuilding, 0);

                        if (CurrentBuilding.btThis == SourceWorld.BuildingTypes.MineshaftEntrance)
                        {
                            structLocationOfMineshaftEntrance.x = intBlockStart + x + (int)(CurrentBuilding.intSizeX / 2);
                            structLocationOfMineshaftEntrance.z = intBlockStart + z + (int)(CurrentBuilding.intSizeZ / 2);
                            SourceWorld.Building BalloonBuilding = SourceWorld.GetBuilding("Sky Feature");
                            SourceWorld.InsertBuilding(bmDest, new int[0, 0], intBlockStart,
                                                       x + ((CurrentBuilding.intSizeX - BalloonBuilding.intSizeX) / 2),
                                                       z + ((CurrentBuilding.intSizeZ - BalloonBuilding.intSizeZ) / 2),
                                                       BalloonBuilding, 0);
                        }

                        intArea[x + CurrentBuilding.intSizeX - 2, z + CurrentBuilding.intSizeZ - 2] = 0;
                        if (++intBuildings == NumberOfBuildingsBetweenSaves)
                        {
                            world.Save();
                            intBuildings = 0;
                        }
                    }
                }
            }
            world.Save();
            return structLocationOfMineshaftEntrance;
        }
Exemple #8
0
 public static void ReplaceValuableBlocks(BetaWorld worldDest, BlockManager bm, int intCitySize,
                                          int intWallMaterial)
 {
     int intReplaced = 0;
     for (int x = 0; x < intCitySize; x++)
     {
         for (int z = 0; z < intCitySize; z++)
         {
             for (int y = 32; y < 128; y++)
             {
                 if ((int)bm.GetID(x, y, z) != intWallMaterial)
                 {
                     switch ((int)bm.GetID(x, y, z))
                     {
                         case BlockType.GOLD_BLOCK:
                             BlockShapes.MakeBlock(x, y, z, BlockType.WOOL, (int)WoolColor.YELLOW);
                             intReplaced++;
                             break;
                         case BlockType.IRON_BLOCK:
                             BlockShapes.MakeBlock(x, y, z, BlockType.WOOL, (int)WoolColor.LIGHT_GRAY);
                             intReplaced++;
                             break;
                         case BlockType.OBSIDIAN:
                             BlockShapes.MakeBlock(x, y, z, BlockType.WOOL, (int)WoolColor.BLACK);
                             intReplaced++;
                             break;
                         case BlockType.DIAMOND_BLOCK:
                             BlockShapes.MakeBlock(x, y, z, BlockType.WOOL, (int)WoolColor.LIGHT_BLUE);
                             intReplaced++;
                             break;
                         case BlockType.LAPIS_BLOCK:
                             BlockShapes.MakeBlock(x, y, z, BlockType.WOOL, (int)WoolColor.BLUE);
                             intReplaced++;
                             break;
                         // no need for a default, because we purposefully want to skip all the other blocks
                     }
                     if (intReplaced > 25)
                     {
                         worldDest.Save();
                         intReplaced = 0;
                     }
                 }
             }
         }
     }
 }
Exemple #9
0
 public static void ResetLighting(BetaWorld world, BetaChunkManager cm, frmMace frmLogForm, int intTotalChunks)
 {
     int intChunksProcessed = 0;
     // we process each chunk twice, hence this:
     intTotalChunks *= 2;
     //this code is based on a substrate example
     //http://code.google.com/p/substrate-minecraft/source/browse/trunk/Substrate/SubstrateCS/Examples/Relight/Program.cs
     //see the <License Substrate.txt> file for copyright information
     foreach (ChunkRef chunk in cm)
     {
         try
         {
             chunk.Blocks.RebuildHeightMap();
             chunk.Blocks.ResetBlockLight();
             chunk.Blocks.ResetSkyLight();
         }
         catch (Exception)
         {
             Debug.WriteLine("Chunk reset light fail");
         }
         if (++intChunksProcessed % 10 == 0)
         {
             cm.Save();
             frmLogForm.UpdateProgress(62 + ((intChunksProcessed * (100 - 62)) / intTotalChunks));
         }
     }
     foreach (ChunkRef chunk in cm)
     {
         try
         {
             chunk.Blocks.RebuildBlockLight();
             chunk.Blocks.RebuildSkyLight();
         }
         catch (Exception)
         {
             Debug.WriteLine("Chunk rebuild light fail");
         }
         if (++intChunksProcessed % 10 == 0)
         {
             cm.Save();
             frmLogForm.UpdateProgress(62 + ((intChunksProcessed * (100 - 62)) / intTotalChunks));
         }
     }
     world.Save();
 }
Exemple #10
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
        }
Exemple #11
0
 private static void MakePaths(BetaWorld world, BlockManager bm, int[,] intArea, int intMapLength)
 {
     for (int x = 0; x < intArea.GetLength(0); x++)
     {
         for (int z = 0; z < intArea.GetLength(1); z++)
         {
             if (intArea[x, z] == 1)
             {
                 if (Math.Abs(x - (intArea.GetLength(0) / 2)) == 2 &&
                     Math.Abs(z - (intArea.GetLength(1) / 2)) == 2)
                 {
                     // don't need these
                 }
                 else if (Math.Abs(x - (intArea.GetLength(0) / 2)) == 2 ||
                          Math.Abs(z - (intArea.GetLength(1) / 2)) == 2)
                 {
                     if (MultipleNeighbouringPaths(intArea, x, z))
                     {
                         bm.SetID(_intBlockStart + x, 63, _intBlockStart + z, BlockType.DOUBLE_SLAB);
                     }
                 }
                 else
                 {
                     bm.SetID(_intBlockStart + x, 63, _intBlockStart + z, BlockType.DOUBLE_SLAB);
                 }
             }
         }
         if (x % 20 == 0)
         {
             world.Save();
         }
     }
 }