Пример #1
0
        private void AddConnectingPoint(Point workingPoint, int currentDirection, List <ConnectingPoint> connectingPointList, ShrunkNode[,] shrunkMap)
        {
            int percentage;

            if (ShrunkWorldBuilder.PointLegit(workingPoint) && stopRoadCount > 0 && shrunkMap[workingPoint.X, workingPoint.Y].IsRoad())
            {
                for (int i = 0; i < 8; i += 2)
                {
                    int chance = GameController.rnd.Next(0, 100);

                    percentage = percentageTurn;

                    if (currentDirection == i)
                    {
                        percentage = percentageStraight;
                    }

                    if (chance < percentage)
                    {
                        if (CheckIfLandType(AngleStuff.AddPointToDirection(workingPoint, i), shrunkMap, LandType.OPEN))
                        {
                            int amount = GameController.rnd.Next(minRandomLength, maxRandomLength);
                            connectingPointList.Add(new ConnectingPoint(i, workingPoint, amount));
                        }
                    }
                }
            }
        }
Пример #2
0
 public bool CheckIfLandType(Point checkPoint, ShrunkNode[,] shrunkMap, LandType landType)
 {
     if (ShrunkWorldBuilder.PointLegit(checkPoint))
     {
         return(shrunkMap[checkPoint.X, checkPoint.Y].landType == landType);
     }
     return(false);
 }
Пример #3
0
        private bool CheckIfRoad(Point checkPoint, ShrunkNode[,] shrunkMap)
        {
            bool check = false;

            if (ShrunkWorldBuilder.PointLegit(checkPoint))
            {
                if (shrunkMap[checkPoint.X, checkPoint.Y].IsRoad())
                {
                    check = true;
                }
            }
            return(check);
        }
Пример #4
0
        public TownSitesBuilder(ShrunkNode[,] shrunkMap, List <Town> townList, ref List <Point> connectionList, LoadingInfo loadingInfo)
        {
            float percentDone = 0;
            float percentJump = 100f / CreatingWorld.numberOfTowns;

            Random rnd = GameController.GetRandomWithSeed();

            InitTownNames();
            int  numberOfChecks = 5000;
            bool safeDistance;

            distanceBetweenTowns = GetDistanceBetweenTowns();
            int townId = 0;

            for (int i = 0; i < numberOfChecks; i++)
            {
                //TODO: take this next line out i just like this map for debugging
                //rndExtras = GameController.rnd;
                Point checkingPoint = new Point(rnd.Next(offSetFromEdge, ShrunkWorldBuilder.shrunkWorldWidth), rnd.Next(offSetFromEdge, ShrunkWorldBuilder.shrunkWorldHeight - offSetFromEdge));
                safeDistance = false;

                if (ShrunkWorldBuilder.IsOpen(checkingPoint, shrunkMap))
                {
                    safeDistance = true;

                    foreach (Town otherTown in townList)
                    {
                        if (IsToCloseDistance(checkingPoint, otherTown.GetShrunkPoint()))
                        {
                            safeDistance = false;
                            break;
                        }
                    }
                }

                if (safeDistance)
                {
                    townList.Add(new Town(checkingPoint, townId, GetTownName(rnd)));
                    townId++;
                    percentDone += percentJump;
                    loadingInfo.UpdateLoading(LoadingType.PlottingTownPoints, percentDone);
                }

                if (townList.Count == CreatingWorld.numberOfTowns)
                {
                    break;
                }
            }
            connectionList = CreateConnectionList(townList);
        }
Пример #5
0
 private int ExtraToReachRoad(ShrunkNode[,] shrunkMap, int directionToTravel, Point expansionPoint)
 {
     for (int i = 1; i < extraToReachRoad; i++)
     {
         expansionPoint = AngleStuff.AddPointToDirection(expansionPoint, directionToTravel);
         if (ShrunkWorldBuilder.PointLegit(expansionPoint))
         {
             if (shrunkMap[expansionPoint.X, expansionPoint.Y].IsRoad())
             {
                 return(i);
             }
         }
     }
     return(0);
 }
Пример #6
0
        private bool IsMoreThanTwoNeighbours(Point expansionPoint, ShrunkNode[,] shrunkMap)
        {
            Point workingPoint;
            int   count = 0;

            for (int i = 0; i < 8; i += 2)
            {
                workingPoint = AngleStuff.AddPointToDirection(expansionPoint, i);
                if (ShrunkWorldBuilder.PointLegit(workingPoint))
                {
                    if (shrunkMap[workingPoint.X, workingPoint.Y].IsRoad())
                    {
                        count++;
                    }
                }
            }
            return(count > 1);
        }
Пример #7
0
        private bool IsAnyNeighbourRoads(Point point, ShrunkNode[,] shrunkMap)
        {
            Point nextPoint;

            //only checking in four directions;
            for (int i = 0; i < 8; i += 2)
            {
                nextPoint = AngleStuff.AddPointToDirection(point, i);
                if (ShrunkWorldBuilder.PointLegit(nextPoint))
                {
                    if (shrunkMap[nextPoint.X, nextPoint.Y].landType == LandType.CITYROAD || shrunkMap[nextPoint.X, nextPoint.Y].landType == LandType.COUNTRYROAD)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #8
0
        public ClearingRoadErrors(ShrunkNode[,] shrunkMap, LoadingInfo loadingInfo)
        {
            float percentDone = 0;
            float percentJump = 100f / CreatingWorld.worldWidth;

            for (int x = 0; x < ShrunkWorldBuilder.shrunkWorldWidth; x++)
            {
                percentDone += percentJump;
                loadingInfo.UpdateLoading(LoadingType.SmoothingTowns, percentDone);
                for (int y = 0; y < ShrunkWorldBuilder.shrunkWorldHeight; y++)
                {
                    if (!IsAnyNeighbourRoads(new Point(x, y), shrunkMap) && shrunkMap[x, y].landType != LandType.PLOT)
                    {
                        if (ShrunkWorldBuilder.IsRoad(new Point(x, y), shrunkMap))
                        {
                            shrunkMap[x, y].SetLandType(LandType.OPEN);
                        }
                    }
                }
            }
        }
Пример #9
0
        private bool AddPlot(Point expansionPoint, int direction, ShrunkPlot plot, ShrunkNode[,] shrunkMap)
        {
            Point nextPoint = expansionPoint;

            for (int depth = 1; depth <= plot.maxDepth; depth++)
            {
                nextPoint = AngleStuff.AddPointToDirection(nextPoint, direction);
                if (ShrunkWorldBuilder.PointLegit(nextPoint) && CheckIfLandType(nextPoint, shrunkMap, LandType.OPEN))
                {
                    AddCornerPoints(depth, plot, nextPoint);
                    shrunkMap[nextPoint.X, nextPoint.Y].SetLandType(LandType.PLOT);
                }
                else
                {
                    if (depth < 3)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }