Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public static void MakeEntrances(BlockManager bm)
 {
     if (City.HasWalls)
     {
         SourceWorld.Building CurrentBuilding;
         CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.CityEntrance, 0);
         SourceWorld.InsertBuilding(bm, new int[0, 0], 0, (City.MapLength / 2) - (CurrentBuilding.intSizeX / 2),
                                    City.EdgeLength + 5, CurrentBuilding, 0, 0);
         SourceWorld.InsertBuilding(bm, new int[0, 0], 0, City.EdgeLength + 5,
                                    (City.MapLength / 2) - (CurrentBuilding.intSizeX / 2), CurrentBuilding, 0, 1);
         SourceWorld.InsertBuilding(bm, new int[0, 0], 0, City.MapLength - (City.EdgeLength + 4 + CurrentBuilding.intSizeX),
                                    (City.MapLength / 2) - (CurrentBuilding.intSizeX / 2), CurrentBuilding, 0, 2);
         SourceWorld.InsertBuilding(bm, new int[0, 0], 0, (City.MapLength / 2) - (CurrentBuilding.intSizeX / 2),
                                    City.MapLength - (City.EdgeLength + 4 + CurrentBuilding.intSizeX), CurrentBuilding, 0, 3);
     }
 }
Ejemplo n.º 3
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, -1);

                        if (CurrentBuilding.BuildingType == 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.SelectRandomBuilding(SourceWorld.BuildingTypes.SkyFeature, 0);
                                SourceWorld.InsertBuilding(bm, new int[0, 0], intBlockStart,
                                                           x + ((CurrentBuilding.intSizeX - BalloonBuilding.intSizeX) / 2),
                                                           z + ((CurrentBuilding.intSizeZ - BalloonBuilding.intSizeZ) / 2),
                                                           BalloonBuilding, 0, -1);
                            }
                        }

                        intArea[x + CurrentBuilding.intSizeX - 2, z + CurrentBuilding.intSizeZ - 2] = 0;
                        if (++intBuildings == NumberOfBuildingsBetweenSaves)
                        {
                            world.Save();
                            intBuildings = 0;
                        }
                    }
                }
            }
            world.Save();
            return(structLocationOfMineshaftEntrance);
        }
Ejemplo n.º 4
0
        private static void AddBuildings(BlockManager bm, int intFarmLength, int intMapLength)
        {
            SourceWorld.Building CurrentBuilding;
            List <int>           lstAllFarmingBuildings = new List <int>();
            int intBuildings = 0;

            do
            {
                do
                {
                    CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.Farming, 0);
                } while (lstAllFarmingBuildings.Contains(CurrentBuilding.intID));
                AddBuilding(bm, intFarmLength, intMapLength, CurrentBuilding.intID);
                if (CurrentBuilding.booUnique)
                {
                    lstAllFarmingBuildings.Add(CurrentBuilding.intID);
                }
            } while (++intBuildings < Math.Max(1, (intMapLength / 16) / 2));
        }
Ejemplo n.º 5
0
        private static int[,] FillArea(int[,] intArea, int intSizeX, int intSizeZ, int intStartX, int intStartZ, bool booUniqueBonus)
        {
            int[,] intDistrict = new int[intSizeX, intSizeZ];
            int[,] intFinal    = new int[intSizeX, intSizeZ];
            int        intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0;
            int        intBonus              = 0;
            List <int> lstBuildings          = new List <int>();
            List <int> lstAcceptedBuildings  = new List <int>();
            bool       booAreaNeedsMineshaft = false;

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

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

                int intCurWasted = Utils.ZerosInArray2D(intDistrict) - intBonus;
                if (intCurWasted < intWasted)
                {
                    intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)];
                    Array.Copy(intDistrict, intFinal, intDistrict.Length);
                    intWasted   = intCurWasted;
                    intAttempts = 10;
                    lstAcceptedBuildings.Clear();
                    lstAcceptedBuildings.AddRange(lstBuildings);
                }
                Array.Clear(intDistrict, 0, intDistrict.Length);
                intAttempts--;
            } while (intAttempts > 0);
            if (intSizeX == intFinal.GetLength(1))
            {
                intFinal = intFinal.RotateArray(1);
            }
            _lstAllBuildings.AddRange(lstAcceptedBuildings);
            _booIncludedMineshaft = true;
            return(intFinal);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        // this is a simplified version of the FillArea method from Paths.cs
        private static int[,] FillArea(int intSizeX, int intSizeZ)
        {
            int[,] intDistrict = new int[intSizeX, intSizeZ];
            int[,] intFinal    = new int[intSizeX, intSizeZ];
            int        intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0;
            int        intBonus     = 0;
            List <int> lstBuildings = new List <int>();

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

                int intCurWasted = Utils.ZerosInArray2D(intDistrict) - intBonus;
                if (intCurWasted < intWasted)
                {
                    intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)];
                    Array.Copy(intDistrict, intFinal, intDistrict.Length);
                    intWasted   = intCurWasted;
                    intAttempts = 10;
                }
                Array.Clear(intDistrict, 0, intDistrict.Length);
                intAttempts--;
            } while (intAttempts > 0);
            if (intSizeX == intFinal.GetLength(1))
            {
                intFinal = intFinal.RotateArray(1);
            }
            return(intFinal);
        }
Ejemplo n.º 8
0
        private static int[,] FillArea(int[,] intArea, int intSizeX, int intSizeZ, int intStartX, int intStartZ)
        {
            int[,] intDistrict = new int[intSizeX, intSizeZ];
            int[,] intFinal    = new int[intSizeX, intSizeZ];
            int        intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0;
            int        intBonus             = 0;
            List <int> lstBuildings         = new List <int>();
            List <int> lstAcceptedBuildings = new List <int>();

            do
            {
                lstBuildings.Clear();
                intBonus = 0;
                do
                {
                    SourceWorld.Building CurrentBuilding;
                    do
                    {
                        CurrentBuilding = SourceWorld.SelectRandomBuilding();
                    } while (!IsValidBuilding(CurrentBuilding, lstBuildings, intArea, intStartX, intStartZ, intSizeX, intSizeZ));
                    bool booFound = false;
                    if (RandomHelper.NextDouble() > 0.5)
                    {
                        intDistrict = RotateArray(intDistrict, RandomHelper.Next(4));
                    }
                    int x, z = 0;
                    for (x = 0; x < intDistrict.GetLength(0) - CurrentBuilding.intSize && !booFound; x++)
                    {
                        for (z = 0; z < intDistrict.GetLength(1) - CurrentBuilding.intSize && !booFound; z++)
                        {
                            booFound = IsFree(intDistrict, 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++)
                            {
                                intDistrict[a, b] = 2;
                            }
                        }
                        if (CurrentBuilding.booUnique)
                        {
                            // we want to include the unique buildings,
                            //   so we give a slight preference to those
                            intBonus += 15;
                        }
                        lstBuildings.Add(CurrentBuilding.intID);
                        intDistrict[x + 1, z + 1] = 100 + CurrentBuilding.intID;
                        intDistrict[x + CurrentBuilding.intSize - 1, z + CurrentBuilding.intSize - 1] = 100 + CurrentBuilding.intID;
                        intFail = 0;
                    }
                    else
                    {
                        intFail++;
                    }
                } while (intFail < 10);

                int intCurWasted = SquaresWasted(intDistrict) - intBonus;
                if (intCurWasted < intWasted)
                {
                    intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)];
                    Array.Copy(intDistrict, intFinal, intDistrict.Length);
                    intWasted   = intCurWasted;
                    intAttempts = 10;
                    lstAcceptedBuildings.Clear();
                    lstAcceptedBuildings.AddRange(lstBuildings);
                }
                Array.Clear(intDistrict, 0, intDistrict.Length);
                intAttempts--;
            } while (intAttempts > 0);
            if (intSizeX == intFinal.GetLength(1))
            {
                intFinal = RotateArray(intFinal, 1);
            }
            lstAllBuildings.AddRange(lstAcceptedBuildings);
            return(intFinal);
        }