예제 #1
0
        public TownsAndRoads(Tile[,] tileGrid, List <Intersection> intersectionList, List <Town> townList, LoadingInfo loadingInfo)
        {
            ShrunkWorldBuilder.shrunkWorldWidth  = CreatingWorld.worldWidth / 2;
            ShrunkWorldBuilder.shrunkWorldHeight = CreatingWorld.worldHeight / 2;
            shrunkMap = new ShrunkNode[ShrunkWorldBuilder.shrunkWorldWidth, ShrunkWorldBuilder.shrunkWorldHeight];

            // DebugLine("ShrunkWorldBuilder");
            ShrunkWorldBuilder shrunkWorldBuilder = new ShrunkWorldBuilder(tileGrid, shrunkMap, loadingInfo);
            //  DebugLine("TownSitesBuilder");
            TownSitesBuilder townSitesBuilder = new TownSitesBuilder(shrunkMap, townList, ref connectionList, loadingInfo);
            //   DebugLine("BuildingTownRoads");
            BuildingTownRoads buildingTownRoads = new BuildingTownRoads(townList, shrunkMap, shrunkPlotList, loadingInfo);
            //   DebugLine("ClearingShrunkPlotErrors");
            ClearingShrunkPlotErrors clearingShrunkPlotErrors = new ClearingShrunkPlotErrors(shrunkMap, shrunkPlotList);
            //   DebugLine("ExpandShrunkPlot");
            ExpandShrunkPlot expandShrunkPlot = new ExpandShrunkPlot(shrunkPlotList, townList, loadingInfo);
            //  DebugLine("ConnectingTowns");
            ConnectingTowns connectingTowns = new ConnectingTowns(ref townList, ref connectionList, shrunkMap, loadingInfo);
            //   DebugLine("ClearingRoadErrors");
            ClearingRoadErrors clearingRoadErrors = new ClearingRoadErrors(shrunkMap, loadingInfo);
            //    DebugLine("ExpandShrunkWorld");
            ExpandShrunkWorld expandShrunkWorld = new ExpandShrunkWorld(tileGrid, shrunkMap, loadingInfo);
            //    DebugLine("LoadingTownBuildings");
            LoadingTownBuildings loadingTownBuildings = new LoadingTownBuildings(buildingList);
            //     DebugLine("AddingTownBuildings");
            AddingTownBuildings addingTownBuildings = new AddingTownBuildings(buildingList, tileGrid, townList, loadingInfo);
            //     DebugLine("AddingRoadTiles");
            AddingRoadTiles addingRoadTiles = new AddingRoadTiles(tileGrid, loadingInfo);
            //     DebugLine("CreatingIntersections");
            CreatingIntersections creatingIntersections = new CreatingIntersections(tileGrid, shrunkMap, intersectionList, loadingInfo);
            //     DebugLine("ModifyingIntersectionRoadId");
            ModifyingIntersectionRoadId modifyingIntersectionRoadId = new ModifyingIntersectionRoadId(tileGrid, shrunkMap, loadingInfo);
            //     DebugLine("AddingStreetLights");
            AddingStreetLights addingStreetLights = new AddingStreetLights(tileGrid, shrunkMap, loadingInfo);
        }
예제 #2
0
        private void AddNewPoints(Dictionary <int, AStarNode> toCheckList, Dictionary <int, AStarNode> checkedNodeList, Point workingPoint, AStarNode workingNode, int findTownId)
        {
            for (byte i = 0; i < 8; i += 2)
            {
                Point newPoint = workingPoint + AngleStuff.directionPoint[i];

                if (ShrunkWorldBuilder.xLegitShrunkMap(newPoint.X, 0) && ShrunkWorldBuilder.yLegitShrunkMap(newPoint.Y, 0))
                {
                    if (shrunkMap[newPoint.X, newPoint.Y].townId == findTownId)
                    {
                        //we found it... lets add this cheapy to the list so it will always grab it next time
                        int id = GetOneD(newPoint);
                        toCheckList.Add(id, new AStarNode(id, GetOneD(workingPoint), 1, 1, i, false));
                        break;
                    }
                    else
                    {
                        if (!IsInLists(newPoint, toCheckList, checkedNodeList))
                        {
                            int tileScore = shrunkMap[newPoint.X, newPoint.Y].pathScore;
                            int id        = GetOneD(newPoint);
                            toCheckList.Add(id, new AStarNode(id, GetOneD(workingPoint), CalcNScore(tileScore, workingNode, i != workingNode.directionFrom), CalcHScore(newPoint), i, false));
                        }
                    }
                }
            }
        }
예제 #3
0
 private void CheckingPoints(byte direction, ShrunkNode[,] shrunkMap)
 {
     if (ShrunkWorldBuilder.xLegitShrunkMap(newPoint.X, 0) && ShrunkWorldBuilder.yLegitShrunkMap(newPoint.Y, 0))
     {
         if (!(IsSearched[newPoint.X, newPoint.Y]))  //if it hasnt been searched add it to the list
         {
             if (direction == directionFrom[currentPoint.X, currentPoint.Y])
             {
                 CalculateNewScores(false, shrunkMap);
             }
             else
             {
                 CalculateNewScores(true, shrunkMap);
             }
             AddToList(direction);
         }
         else// it has been searched.  lets remove the old one from the list
         {
             CalculateNewScores(false, shrunkMap);
             if (newPointScore < score[newPoint.X, newPoint.Y])  //this one is better
             {
                 AddToList(direction);
                 RemoveFromList();
             }
         }
     }
 }
예제 #4
0
 private bool AnyRoadsLeftOrRight(int x, int y, ShrunkNode[,] shrunkMap)
 {
     if (!ShrunkWorldBuilder.IsRoad(new Point(x - 1, y), shrunkMap))
     {
         return(ShrunkWorldBuilder.IsRoad(new Point(x + 1, y), shrunkMap));
     }
     return(true);
 }
예제 #5
0
 private bool AnyRoadsUpOrDown(int x, int y, ShrunkNode[,] shrunkMap)
 {
     if (!ShrunkWorldBuilder.IsRoad(new Point(x, y - 1), shrunkMap))
     {
         return(ShrunkWorldBuilder.IsRoad(new Point(x, y + 1), shrunkMap));
     }
     return(true);
 }
예제 #6
0
        private int CountNeighbourRoadsShrunkMap(ShrunkNode[,] shrunkMap, Point point)
        {
            int   amount = 0;
            Point nextPoint;

            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)
                    {
                        amount++;
                    }
                }
            }
            return(amount);
        }
예제 #7
0
        private void UpdateNewPoints(ShrunkNode[,] shrunkMap, int findTownId)
        {
            for (byte i = 0; i < 8; i += 2)
            {
                newPoint = AngleStuff.AddPointToDirection(currentPoint, i);
                CheckingPoints(i, shrunkMap);

                if (ShrunkWorldBuilder.xLegitShrunkMap(newPoint.X, 0) && ShrunkWorldBuilder.yLegitShrunkMap(newPoint.Y, 0))
                {
                    if (shrunkMap[newPoint.X, newPoint.Y].townId == findTownId)
                    {
                        found        = true;
                        currentPoint = newPoint;
                        break;
                    }
                }
            }
        }
예제 #8
0
        //should each stoplight be its own mapobject
        //its extra things to add to our draw list then
        private void AddIntersection(List <Intersection> intersectionList, Tile[,] tileGrid, ShrunkNode[,] shrunkMap, int shrunkX, int shrunkY, Point expandedPoint, Random rndExtras, int id)
        {
            Intersection intersection = new Intersection(rndExtras, expandedPoint.X, expandedPoint.Y, id);

            MapObject mapObject;

            Dictionary <Direction, StopLight> stopLightList = new Dictionary <Direction, StopLight>();
            int       tileX;
            int       tileY;
            StopLight stopLight;

            int stageLeftRight = rndExtras.Next(0, 1) * 2;  //should always be 0 or 2
            int stageUpDown;

            if (stageLeftRight == 0)
            {
                stageUpDown = 2;
            }
            else
            {
                stageUpDown = 0;
            }


            //Road Down
            if (ShrunkWorldBuilder.IsRoad(new Point(shrunkX, shrunkY + 1), shrunkMap))
            {
                tileX     = expandedPoint.X;
                tileY     = expandedPoint.Y + 1;
                stopLight = new StopLight(0, stageUpDown, intersection, 0);
                stopLightList.Add(Direction.DOWN, stopLight);
                mapObject = new MapObject(stopLight, tileX, tileY, Color.White, 1f);
                tileGrid[tileX, tileY].AddMapObject(mapObject, false, false, true, null, false);
                AddWhiteLine(tileGrid, tileX, tileY, 3);
            }

            // Road Right
            if (ShrunkWorldBuilder.IsRoad(new Point(shrunkX + 1, shrunkY), shrunkMap))
            {
                tileX     = expandedPoint.X + 1;
                tileY     = expandedPoint.Y + 1;
                stopLight = new StopLight(6, stageLeftRight, intersection, 3);
                stopLightList.Add(Direction.RIGHT, stopLight);
                mapObject = new MapObject(stopLight, tileX, tileY, Color.White, 1f);
                tileGrid[tileX, tileY].AddMapObject(mapObject, false, false, true, null, false);
                AddWhiteLine(tileGrid, tileX, tileY, 2);
            }

            // Road Up
            if (ShrunkWorldBuilder.IsRoad(new Point(shrunkX, shrunkY - 1), shrunkMap))
            {
                tileX = expandedPoint.X + 1;
                tileY = expandedPoint.Y;

                stopLight = new StopLight(4, stageUpDown, intersection, 2);
                stopLightList.Add(Direction.UP, stopLight);
                mapObject = new MapObject(stopLight, tileX, tileY, Color.White, 1f);
                tileGrid[tileX, tileY].AddMapObject(mapObject, false, false, true, null, false);
                AddWhiteLine(tileGrid, tileX, tileY, 1);
            }

            //Road Left
            if (ShrunkWorldBuilder.IsRoad(new Point(shrunkX - 1, shrunkY), shrunkMap))
            {
                tileX = expandedPoint.X;
                tileY = expandedPoint.Y;

                stopLight = new StopLight(2, stageLeftRight, intersection, 1);
                stopLightList.Add(Direction.LEFT, stopLight);
                mapObject = new MapObject(stopLight, tileX, tileY, Color.White, 1f);
                tileGrid[tileX, tileY].AddMapObject(mapObject, false, false, true, null, false);
                AddWhiteLine(tileGrid, tileX, tileY, 0);
            }

            AddTurningArrows(tileGrid, expandedPoint, 0);

            intersection.SetStopLightList(stopLightList);
            intersectionList.Add(intersection);
        }