Example #1
0
        // this is a simplified version of the IsValidBuilding method from Paths.cs
        private static bool IsValidBuilding(SourceWorld.Building bldCheck, List <int> lstBuildings)
        {
            if (bldCheck.booUnique)
            {
                return(!lstBuildings.Contains(bldCheck.intID));
            }
            // todo low: need some way to limit (very) rare buildings
            switch (bldCheck.strFrequency)
            {
            case "very common":
            case "common":
            case "average":
            case "rare":
            case "very rare":
                return(true);

            // should never get here to either of these, but just in case
            case "exclude":
                Debug.WriteLine("Excluded buildings are not allowed here");
                return(false);

            default:
                Debug.WriteLine("Unknown frequency type encountered");
                return(false);
            }
        }
Example #2
0
        private static bool IsValidBuilding(SourceWorld.Building bldCheck, List <int> lstBuildings, int[,] intArea,
                                            int intStartX, int intStartZ, int intSizeX, int intSizeZ)
        {
            switch (bldCheck.strFrequency)
            {
            case "very common":
            case "common":
                return(true);

            case "average":
            case "rare":
            case "very rare":
                if (lstBuildings.Contains(bldCheck.intID))
                {
                    return(false);
                }
                else
                {
                    int intDistance = 0;
                    switch (bldCheck.strFrequency)
                    {
                    case "average":
                        intDistance = 12;
                        break;

                    case "rare":
                        intDistance = 25;
                        break;

                    case "very rare":
                        intDistance = 50;
                        break;
                    }
                    for (int x = intStartX - intDistance; x < intStartX + intSizeX + intDistance; x++)
                    {
                        for (int z = intStartZ - intDistance; z < intStartZ + intSizeZ + intDistance; z++)
                        {
                            if (x >= 0 && z >= 0 && x <= intArea.GetUpperBound(0) && z <= intArea.GetUpperBound(1))
                            {
                                if (intArea[x, z] - 100 == bldCheck.intID)
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    return(true);
                }

            // should never get here to either of these, but just in case
            case "exclude":
                Debug.WriteLine("Excluded buildings are not allowed here");
                return(false);

            default:
                Debug.WriteLine("Unknown frequency type encountered");
                return(false);
            }
        }
Example #3
0
        private static int[,] AddMineshaftSections(int[,] intAreaOverview, int intDepth)
        {
            int        intFail      = 0;
            int        intPlaced    = 0;
            int        intSections  = 0;
            List <int> lstBuildings = new List <int>();

            foreach (int intSection in intAreaOverview)
            {
                intSections += intSection;
            }
            do
            {
                SourceWorld.Building bldMineshaftFeature = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.MineshaftSection, intDepth);
                if (!bldMineshaftFeature.booUnique || !lstBuildings.Contains(bldMineshaftFeature.intID))
                {
                    structPoint spPlace = MatchPatternInArray(intAreaOverview, bldMineshaftFeature.strPattern.Split(' '));
                    if (spPlace.x == -1)
                    {
                        intFail++;
                    }
                    else
                    {
                        Debug.WriteLine("Adding " + bldMineshaftFeature.strName);
                        int intPosX  = bldMineshaftFeature.intPosX;
                        int intPosZ  = bldMineshaftFeature.intPosZ;
                        int intSizeX = (bldMineshaftFeature.intSizeX - 1) / 6;
                        int intSizeZ = (bldMineshaftFeature.intSizeZ - 1) / 6;
                        if (spPlace.x >= 0)
                        {
                            for (int x = 0; x < intSizeX; x++)
                            {
                                for (int z = 0; z < intSizeZ; z++)
                                {
                                    intAreaOverview[spPlace.x + intPosX + x, spPlace.z + intPosZ + z] = 100 + bldMineshaftFeature.intID;
                                }
                            }
                            intPlaced++;
                            if (bldMineshaftFeature.booUnique)
                            {
                                lstBuildings.Add(bldMineshaftFeature.intID);
                            }
                        }
                    }
                }
            } while (intFail < 10 && intPlaced < intSections / 15);
            return(intAreaOverview);
        }
Example #4
0
        private static structPoint MakeBuildings(BlockManager bm, int[,] intArea, int intBlockStart, BetaWorld world)
        {
            structPoint structLocationOfMineshaftEntrance = new structPoint();

            structLocationOfMineshaftEntrance.x = -1;
            structLocationOfMineshaftEntrance.z = -1;
            int intBuildings = 0;

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

                        if (CurrentBuilding.btThis == SourceWorld.BuildingTypes.MineshaftEntrance)
                        {
                            structLocationOfMineshaftEntrance.x = intBlockStart + x + (int)(CurrentBuilding.intSizeX / 2);
                            structLocationOfMineshaftEntrance.z = intBlockStart + z + (int)(CurrentBuilding.intSizeZ / 2);
                            if (City.HasSkyFeature)
                            {
                                SourceWorld.Building BalloonBuilding = SourceWorld.GetBuilding("Sky Feature");
                                SourceWorld.InsertBuilding(bm, 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);
        }
Example #5
0
        private static void AddBuilding(BlockManager bm, int intBuildingID)
        {
            bool booAddedBuilding = false;

            SourceWorld.Building bldInsert = SourceWorld.GetBuilding(intBuildingID);
            int  intLen = bldInsert.intSizeX;
            bool booValid;
            int  FailCounter = 0;

            do
            {
                booValid = false;
                int x1 = RandomHelper.Next(3, City.MapLength - (3 + intLen));
                int z1 = RandomHelper.Next(3, City.MapLength - (3 + intLen));
                if (!(x1 >= City.FarmLength && z1 >= City.FarmLength &&
                      x1 <= City.MapLength - City.FarmLength && z1 <= City.MapLength - City.FarmLength))
                {
                    booValid = true;
                    for (int x = x1 - 2; x <= x1 + intLen + 2 && booValid; x++)
                    {
                        for (int z = z1 - 2; z <= z1 + intLen + 2 && booValid; z++)
                        {
                            // make sure it doesn't overlap with the spawn point or another farm
                            if ((x == City.MapLength / 2 && z == SpawnZ) ||
                                bm.GetID(x, 63, z) != City.GroundBlockID ||
                                bm.GetID(x, 64, z) != BlockInfo.Air.ID ||
                                bm.GetID(x, 53, z) == BlockInfo.Air.ID)
                            {
                                booValid = false;
                            }
                        }
                    }
                }
                if (booValid)
                {
                    SourceWorld.InsertBuilding(bm, new int[City.MapLength, City.MapLength], 0, x1, z1, bldInsert, 0);
                    booAddedBuilding = true;
                    FailCounter      = 0;
                }
                else
                {
                    FailCounter++;
                }
            } while (!booAddedBuilding && FailCounter <= 500);
        }
Example #6
0
        private static void MakeBuildings(int[,] intArea, int intBlockStart, BetaWorld world, int intFarmSize)
        {
            int intBuildings = 0;

            for (int x = 0; x < intArea.GetLength(0); x++)
            {
                for (int z = 0; z < intArea.GetLength(1); z++)
                {
                    if (intArea[x, z] >= 100 && intArea[x, z] <= 500)
                    {
                        SourceWorld.Building CurrentBuilding = SourceWorld.GetBuilding(intArea[x, z] - 100);
                        SourceWorld.InsertBuilding(bmDest, intBlockStart, x, z, CurrentBuilding);
                        intArea[x + CurrentBuilding.intSize - 2, z + CurrentBuilding.intSize - 2] = 0;
                        if (++intBuildings == 20)
                        {
                            world.Save();
                            intBuildings = 0;
                        }
                    }
                }
            }
        }
Example #7
0
        private static void AddMushroomFarms(BlockManager bm, int intFarmSize, int intMapSize)
        {
            SourceWorld.Building bldMushroomFarm = SourceWorld.GetBuilding("Mushroom Farm");
            int len = bldMushroomFarm.intSize;
            int intMushroomFarms = (intMapSize / 16) / 5;

            bool booValid = false;

            do
            {
                booValid = false;
                int x1 = rand.Next(2, intMapSize - (2 + len));
                int z1 = rand.Next(2, intMapSize - (2 + len));
                if (!(x1 >= intFarmSize && z1 >= intFarmSize &&
                      x1 <= intMapSize - intFarmSize && z1 <= intMapSize - intFarmSize))
                {
                    booValid = true;
                    for (int x = x1 - 2; x <= x1 + len + 2 && booValid; x++)
                    {
                        for (int z = z1 - 2; z <= z1 + len + 2 && booValid; z++)
                        {
                            // make sure it doesn't overlap with the spawn point or another farm
                            if ((x == intMapSize / 2 && z == intMapSize - (intFarmSize - 10)) ||
                                bm.GetID(x, 63, z) != (int)BlockType.GRASS ||
                                bm.GetID(x, 64, z) != (int)BlockType.AIR ||
                                bm.GetID(x, 53, z) == (int)BlockType.AIR)
                            {
                                booValid = false;
                            }
                        }
                    }
                }
                if (booValid)
                {
                    SourceWorld.InsertBuilding(bm, 0, x1, z1, bldMushroomFarm);
                    intMushroomFarms--;
                }
            } while (intMushroomFarms > 0);
        }
Example #8
0
        // this is a simplified version of the MakeBuildings method from Buildings.cs
        private static void MakeBuildings(BlockManager bm, int[,] intArea, BetaWorld world)
        {
            int intBuildings = 0;

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

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

                        intArea[x + CurrentBuilding.intSizeX - 2, z + CurrentBuilding.intSizeZ - 2] = 0;
                        if (++intBuildings == NumberOfBuildingsBetweenSaves)
                        {
                            world.Save();
                            intBuildings = 0;
                        }
                    }
                }
            }
        }
Example #9
0
        private static void AddBuilding(BlockManager bm, int intFarmLength, int intMapLength, int intBuildingID)
        {
            bool booAddedBuilding = false;

            SourceWorld.Building bldInsert = SourceWorld.GetBuilding(intBuildingID);
            int  intLen = bldInsert.intSizeX;
            bool booValid;

            do
            {
                booValid = false;
                int x1 = RandomHelper.Next(2, intMapLength - (2 + intLen));
                int z1 = RandomHelper.Next(2, intMapLength - (2 + intLen));
                if (!(x1 >= intFarmLength && z1 >= intFarmLength &&
                      x1 <= intMapLength - intFarmLength && z1 <= intMapLength - intFarmLength))
                {
                    booValid = true;
                    for (int x = x1 - 2; x <= x1 + intLen + 2 && booValid; x++)
                    {
                        for (int z = z1 - 2; z <= z1 + intLen + 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 ||
                                bm.GetID(x, 53, z) == BlockType.AIR)
                            {
                                booValid = false;
                            }
                        }
                    }
                }
                if (booValid)
                {
                    SourceWorld.InsertBuilding(bm, new int[intMapLength, intMapLength], 0, x1, z1, bldInsert, 0);
                    booAddedBuilding = true;
                }
            } while (!booAddedBuilding);
        }
Example #10
0
        private static void AddBuilding(BlockManager bm, int intFarmSize, int intMapSize, string strBuildingName)
        {
            SourceWorld.Building bldInsert = SourceWorld.GetBuilding(strBuildingName);
            int  intLen            = bldInsert.intSize;
            int  intBuildingsToAdd = Math.Max(1, (intMapSize / 16) / 6);
            bool booValid;

            do
            {
                booValid = false;
                int x1 = RandomHelper.Next(2, intMapSize - (2 + intLen));
                int z1 = RandomHelper.Next(2, intMapSize - (2 + intLen));
                if (!(x1 >= intFarmSize && z1 >= intFarmSize &&
                      x1 <= intMapSize - intFarmSize && z1 <= intMapSize - intFarmSize))
                {
                    booValid = true;
                    for (int x = x1 - 2; x <= x1 + intLen + 2 && booValid; x++)
                    {
                        for (int z = z1 - 2; z <= z1 + intLen + 2 && booValid; z++)
                        {
                            // make sure it doesn't overlap with the spawn point or another farm
                            if ((x == intMapSize / 2 && z == intMapSize - (intFarmSize - 10)) ||
                                bm.GetID(x, 63, z) != (int)BlockType.GRASS ||
                                bm.GetID(x, 64, z) != (int)BlockType.AIR ||
                                bm.GetID(x, 53, z) == (int)BlockType.AIR)
                            {
                                booValid = false;
                            }
                        }
                    }
                }
                if (booValid)
                {
                    SourceWorld.InsertBuilding(bm, new int[intMapSize, intMapSize], 0, x1, z1, bldInsert);
                    intBuildingsToAdd--;
                }
            } while (intBuildingsToAdd > 0);
        }
Example #11
0
        private static int[,] FillArea(int intSizeX, int intSizeY, int intStartX, int intStartZ)
        {
            int[,] intDist  = new int[intSizeX, intSizeY];
            int[,] intFinal = new int[intSizeX, intSizeY];
            int intWasted = intSizeX * intSizeY, intAttempts = 15, intFail = 0;

            do
            {
                do
                {
                    SourceWorld.Building CurrentBuilding = SourceWorld.SelectRandomBuilding();
                    bool booFound = false;
                    if (rand.NextDouble() > 0.5)
                    {
                        intDist = RotateArray(intDist, -1);
                    }
                    int x, z = 0;
                    for (x = 0; x < intDist.GetLength(0) - CurrentBuilding.intSize && !booFound; x++)
                    {
                        for (z = 0; z < intDist.GetLength(1) - CurrentBuilding.intSize && !booFound; z++)
                        {
                            booFound = IsFree(intDist, x, z, x + CurrentBuilding.intSize, z + CurrentBuilding.intSize);
                        }
                    }
                    x--;
                    z--;
                    if (booFound)
                    {
                        for (int a = x + 1; a <= x + CurrentBuilding.intSize - 1; a++)
                        {
                            for (int b = z + 1; b <= z + CurrentBuilding.intSize - 1; b++)
                            {
                                intDist[a, b] = 2;
                            }
                        }
                        intDist[x + 1, z + 1] = 100 + CurrentBuilding.intID;
                        intDist[x + CurrentBuilding.intSize - 1, z + CurrentBuilding.intSize - 1] = 100 + CurrentBuilding.intID;
                        intFail = 0;
                    }
                    else
                    {
                        intFail++;
                    }
                } while (intFail < 10);
                int intCurWasted = SquaresWasted(intDist);
                if (intCurWasted < intWasted)
                {
                    intFinal = new int[intDist.GetLength(0), intDist.GetLength(1)];
                    Array.Copy(intDist, intFinal, intDist.Length);
                    intWasted   = intCurWasted;
                    intAttempts = 10;
                }
                Array.Clear(intDist, 0, intDist.Length);
                intAttempts--;
            } while (intAttempts > 0);
            if (intSizeX == intFinal.GetLength(1))
            {
                intFinal = RotateArray(intFinal, 1);
            }
            return(intFinal);
        }