Пример #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
        private int GetDirection(DrivingNode one, DrivingNode two)
        {
            int x = one.GetLocationX() - two.GetLocationX();
            int y = one.GetLocationY() - two.GetLocationY();

            return(AngleStuff.GetDirection(new Point(x, y)));
        }
Пример #3
0
        private void CalcShrunkPlots(List <ShrunkPlot> shrunkPlotList, int roadDirection, int townId)
        {
            if (plotLeft != null && plotLeft.currentLength >= plotLeft.maxLength) //we are at the end
            {
                plotLeft = null;
            }

            if (plotRight != null && plotRight.currentLength >= plotRight.maxLength) //we are at the start
            {
                plotRight = null;
            }

            if (plotLeft == null)
            {
                plotLeft = new ShrunkPlot(plotNum, AngleStuff.RotateDirection(roadDirection, 2), townId);
                plotNum++;
                shrunkPlotList.Add(plotLeft);
            }
            if (plotRight == null)
            {
                plotRight = new ShrunkPlot(plotNum, AngleStuff.RotateDirection(roadDirection, -2), townId);
                plotNum++;
                shrunkPlotList.Add(plotRight);
            }


            plotLeft.currentLength++;
            plotRight.currentLength++;
        }
Пример #4
0
 private void SetStartLocation()
 {
     if (life > 0)
     {
         Vector2 endVelocity = AngleStuff.RadianToVector(windDirection) * windSpeed * (life);
         location += endVelocity;
     }
 }
Пример #5
0
        private void AddNewPoints(Reusables reusables, Point workingPoint, AStarNode workingNode)
        {
            for (byte i = 0; i < 8; i += 2)
            {
                Point newPoint = workingPoint + AngleStuff.directionPoint[i];

                if (workingPoint == Point.Zero)
                {
                    string BUG = "";
                    Debug.WriteLine("BUGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG We hit an empty point on an astar");
                }
                else
                {
                    if (WorldController.world.tileGrid[newPoint.X, newPoint.Y].IsRoad() && !WorldController.world.tileGrid[newPoint.X, newPoint.Y].tileLogistic.IsDirectionBlock(i))
                    {
                        if (!IsInLists(newPoint, reusables))
                        {
                            int count     = 1;
                            int tileScore = WorldController.world.tileGrid[newPoint.X, newPoint.Y].tileLogistic.pathFindingScore;
                            int roadId    = WorldController.world.tileGrid[newPoint.X, newPoint.Y].tileLogistic.roadId;

                            TileLogistic workingLogistic = WorldController.world.tileGrid[workingPoint.X, workingPoint.Y].tileLogistic;
                            TileLogistic newLogistic     = WorldController.world.tileGrid[newPoint.X, newPoint.Y].tileLogistic;


                            while (newLogistic.roadId == workingLogistic.roadId && newLogistic.roadId < 12 && !EndOrDirectionBlockOrStop(newPoint, newLogistic, i))
                            {
                                if (!IsInLists(newPoint, reusables))
                                {
                                    count++;
                                    newPoint    = newPoint + AngleStuff.directionPoint[i];
                                    newLogistic = WorldController.world.tileGrid[newPoint.X, newPoint.Y].tileLogistic;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            while (count > -1 && reusables.toCheckList.ContainsKey(GetOneD(newPoint)))
                            {
                                newPoint = newPoint + AngleStuff.directionPoint[AngleStuff.RotateDirection(i, 4)];
                                count--;
                            }

                            if (count > 0 && !reusables.toCheckList.ContainsKey(GetOneD(newPoint)))
                            {
                                int id = GetOneD(newPoint);
                                reusables.toCheckList.Add(id, new AStarNode(id, GetOneD(workingPoint), CalcNScore(tileScore * count, workingNode), CalcHScore(newPoint), i, true));
                            }
                        }
                    }
                }
            }
        }
Пример #6
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);
 }
Пример #7
0
        private const float windSpeed     = 300f; //20 km

        public SmokeParticle(Vector2 location, Vector2 startDrawSize, Color drawColor, float life)
        {
            sprite = GraphicsManager.GetGameSprite(GetRandomSmoke());

            drawRotation = AngleStuff.GetRandomRadian();

            this.drawColor = drawColor;
            this.location  = location;
            this.life      = life;
            //this.life = 0.5f;
            fade = 0.5f;
            SetIncreaseSizes();
            SetStartLocation();
            SetDrawSize(startDrawSize);
        }
Пример #8
0
        private int CountNeighbourRoadsNormalMap(Tile[,] tileGrid, Point point)
        {
            int amount = 0;

            Point nextPoint;

            //only checking in four directions;
            for (int i = 2; i < 5; i += 1)
            {
                nextPoint = AngleStuff.AddPointToDirection(point, i);
                if (CreatingWorld.IsRoad(tileGrid, nextPoint))
                {
                    amount++;
                }
            }
            return(amount);
        }
Пример #9
0
        public static bool IsAnyNeighbourRoads(Point point, LandType[,] shrunkMap)
        {
            Point nextPoint;

            //only checking in four directions;
            for (int i = 0; i < 8; i += 2)
            {
                nextPoint = AngleStuff.AddPointToDirection(point, i);
                if (xLegitShrunkMap(nextPoint.X, 0) && yLegitShrunkMap(nextPoint.Y, 0))
                {
                    if (shrunkMap[nextPoint.X, nextPoint.Y] == LandType.CITYROAD || shrunkMap[nextPoint.X, nextPoint.Y] == LandType.COUNTRYROAD)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #10
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);
        }
Пример #11
0
        private void FixSpot(Point point, Tile[,] tileGrid)
        {
            Point nextPoint = point;

            for (int i = 2; i < 7; i += 1)
            {
                if (CreatingWorld.IsRoad(tileGrid, nextPoint))
                {
                    int id = tileGrid[nextPoint.X, nextPoint.Y].tileLogistic.roadId;
                    if (id < 12) //Lets try do every road
                    {
                        LandType landtype = tileGrid[nextPoint.X, nextPoint.Y].tileLogistic.landType;
                        tileGrid[nextPoint.X, nextPoint.Y].SetTileLogistic(TileLogisticsController.GetTileLogistic(landtype, id + 12));
                    }
                }
                nextPoint = AngleStuff.AddPointToDirection(point, i);
            }
        }
Пример #12
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);
        }
Пример #13
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;
                    }
                }
            }
        }
Пример #14
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);
        }
Пример #15
0
        public Location(int tileX, int tileY, VehicleParameters vehicleParameters, Sprite sprite)
        {
            this.vehicleParameters = vehicleParameters;
            this.tileX             = tileX;
            this.tileY             = tileY;
            TileLogistic tileLogistic = WorldController.world.tileGrid[tileX, tileY].tileLogistic;

            position  = new Vector2((tileX * GroundLayerController.tileSize), (tileY * GroundLayerController.tileSize)) + tileLogistic.center;
            direction = tileLogistic.GetDefaultDirectionRadian();

            Point newPoint = AngleStuff.AddPointToDirection(new Point(tileX, tileY), tileLogistic.GetDefaultDirectionMirror());

            backTileX = newPoint.X;
            backTileY = newPoint.Y;

            WorldController.world.tileGrid[backTileX, backTileY].vehicle = vehicleParameters.vehicle;
            WorldController.world.tileGrid[tileX, tileY].vehicle         = vehicleParameters.vehicle;
        }
Пример #16
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);
        }
Пример #17
0
        private void CalculateCorners()
        {
            if (drivingNodeList.Count > 2)
            {
                int currentDirection = GetDirection(drivingNodeList[drivingNodeList.Count - 2], drivingNodeList[drivingNodeList.Count - 1]);

                for (int i = drivingNodeList.Count - 1; i > 1; i--)
                {
                    int newDirection = GetDirection(drivingNodeList[i - 1], drivingNodeList[i]);

                    if (newDirection != currentDirection)
                    {
                        Direction turnDirection = AngleStuff.GetTurnDirection(currentDirection, newDirection);


                        if (currentDirection % 2 == 0 && newDirection % 2 == 0)
                        {
                            DrivingNode drivingNode = drivingNodeList[i];
                            drivingNode.SetUseByPassTurn(currentDirection, newDirection);
                            drivingNodeList[i] = drivingNode;
                        }

                        currentDirection = newDirection;

                        for (int p = i - 2; p < i + 6; p++)
                        {
                            if (p > 0 && p < drivingNodeList.Count)
                            {
                                if (drivingNodeList[p].isRoad() && drivingNodeList[p].indicatorDirection == Direction.NONE || drivingNodeList[p].isRoad() && p < i)
                                {
                                    drivingNodeList[p].SetIndicatorDirection(turnDirection);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #18
0
        protected override void Initialize()
        {
            debugDrawTimeStopwatch = new Stopwatch();
            // Window.IsBorderless = false;
            Data.SetSettings();
            ScreenController.graphicsDevice = GraphicsDevice;
            DisplayController.Init(this);
            EngineController.Init();
            GraphicsManager.Init(Content);
            AudioManager.Init(Content);

            //Game specific init. this could probably be done in game load
            GroundLayerController.Init();
            AngleStuff.Init();
            PieceController.Init();
            ShadowSpriteController.Init();
            MapObjectController.Init();
            TileLogisticsController.Init();
            GraphicsDevice.Clear(Color.White);
            IsMouseVisible = true;
            base.Initialize();
            ScreenController.ChangeScreen(new MenuMain());
        }
Пример #19
0
        private List <DrivingNode> AddDirectionTurns(List <DrivingNode> drivingNodeList, Point startPoint)
        {
            if (drivingNodeList.Count > 0)
            {
                Point point     = new Point(drivingNodeList[drivingNodeList.Count - 1].GetLocationX() - startPoint.X, drivingNodeList[drivingNodeList.Count - 1].GetLocationY() - startPoint.Y);
                int   direction = AngleStuff.GetDirection(point);

                DrivingNode node = drivingNodeList[drivingNodeList.Count - 1];
                node.SetDrivingDirection((byte)direction);
                drivingNodeList[drivingNodeList.Count - 1] = node;

                for (int i = drivingNodeList.Count - 2; i > -1; i--)
                {
                    point     = new Point(drivingNodeList[i].GetLocationX() - drivingNodeList[i + 1].GetLocationX(), drivingNodeList[i].GetLocationY() - drivingNodeList[i + 1].GetLocationY());
                    direction = AngleStuff.GetDirection(point);

                    DrivingNode node1 = drivingNodeList[i];
                    node1.SetDrivingDirection((byte)direction);
                    drivingNodeList[i] = node1;
                }
            }
            return(drivingNodeList);
        }
Пример #20
0
        //we need to order it our next tile to drive to is the end off the list
        //as we want to pull them off the end
        public List <DrivingNode> GetDrivingNodeList(Reusables reusables, Point startPoint)
        {
            List <DrivingNode> drivingNodeList = new List <DrivingNode>();

            AStarNode currentNode  = reusables.checkedNodeList[GetOneD(endPoint)];
            Point     currentPoint = currentNode.GetCurrent2D();

            while (currentPoint != startPoint)
            {
                currentPoint = currentNode.GetCurrent2D();
                Point reachPoint = currentNode.GetPrevious2D();

                int direction = currentNode.GetMirrorDirection();

                do
                {
                    drivingNodeList.Add(new DrivingNode(currentPoint.X, currentPoint.Y));
                    currentPoint = AngleStuff.AddPointToDirection(currentPoint, direction);
                }while (currentPoint != reachPoint);
                //probably a better way to do this, but if we reached our reach point we do need to add it one more

                //   drivingNodeList.Add(new DrivingNode(currentPoint.X, currentPoint.Y));



                currentNode = reusables.checkedNodeList[GetOneD(currentPoint)];
            }

            if (drivingNodeList.Count > 0)
            {
                //We need to pop the last from the list
                //   drivingNodeList.RemoveAt(drivingNodeList.Count - 1);
            }

            return(AddDirectionTurns(drivingNodeList, startPoint));
        }
Пример #21
0
        private static void AddLogisticType(LandType landType, Vector2 center, Vector2 byPassTurn, bool isRoad, int directionBlockOne, int directionBlockTwo, int pathfindingScore, int defaultDirection)
        {
            Dictionary <int, TileLogistic> listUsing = new Dictionary <int, TileLogistic>();

            if (landTypeLogisticsList.ContainsKey(landType))
            {
                listUsing = landTypeLogisticsList[landType];
            }
            else
            {
                landTypeLogisticsList.Add(landType, listUsing);
            }
            int index = listUsing.Count();

            for (int i = index; i < index + 4; i++)
            {
                listUsing.Add(i, new TileLogistic(landType, center, byPassTurn, isRoad, i, directionBlockOne, directionBlockTwo, pathfindingScore, defaultDirection));
                center = RotateVectorRight(center);
                //byPassTurn = RotateVectorRight(byPassTurn);
                directionBlockOne = RotateDirectionBlock(directionBlockOne);
                directionBlockTwo = RotateDirectionBlock(directionBlockTwo);
                defaultDirection  = AngleStuff.RotateDirection(defaultDirection, 2);
            }
        }
Пример #22
0
        public bool ReadyNextWayPoint()
        {
            if (waitingOnNewPathfinding)
            {
                //Check if our pathfinding job is done.  If it was in progress and is done we mark it as completed
                UpdateWaitingOnNewPathing();
                return(false);
            }

            //We are not waiting on new pathfinding an
            //Now we work out if the next one is clean.  Be warned we have modified waiting on new pathing in the above method
            if (!waitingOnNewPathfinding && drivingNodeList.Count > 0)
            {
                if (waypointCheckCounter < 0.0001)
                {
                    waypointCheckCounter = 1;

                    Tile nextTile = GetTile(1);
                    bool isStopLight;

                    if (IsTileEmptyFromVehicles(GetTile(1)))
                    {
                        if (!IsStoplightBlock(nextTile, GetDirection(1), out isStopLight))
                        {
                            Tile lastTile = GetTile(2);

                            if (IsTileEmptyFromVehicles(lastTile))
                            {
                                vehicleParameters.followingVehicle = null;
                            }
                            else if (IsTileWithVehicleMovingSameDirection(lastTile))
                            {
                                vehicleParameters.followingVehicle = lastTile.vehicle;
                                //match speed
                            }
                            if (isStopLight)
                            {
                                nextTile.IncreaseStopLightCounter();
                            }

                            waypointCheckCounter = 0;
                            return(true);
                        }
                    }
                    else
                    {
                        //To fix the edge case of were we have 2 vehicles trying to turn right into an intersection
                        //The fix is, we remove them from the tail tile of the map
                        //First we need to determine if were in an intersection
                        //Second if we are stopped
                        //third if we are turning

                        //Tile is our next tile
                        if (nextTile.IsRoad())
                        {
                            if (AngleStuff.GetDirectionDifference(vehicleParameters.directionTravelling, nextTile.vehicle.GetTravellingDirectionInt()) == 4)
                            {
                                location.RemoveTailFromTile();
                            }
                        }
                    }
                }
                else
                {
                    waypointCheckCounter -= 0.03f * EngineController.gameUpdateTime;
                }
            }



            return(false);
        }
Пример #23
0
        private void LayRoadStretch(Point expansionPoint, int directionToTravel, int distanceToTravel, int townId, List <ConnectingPoint> connectingPointList, ShrunkNode[,] shrunkMap, List <ShrunkPlot> shrunkPlotList)
        {
            int  depth = GameController.rnd.Next(minRandomPlotDepth, maxRandomPlotDepth);
            bool addConnectingPoint = false;
            bool forceThroughPlot   = false;


            for (int roadDistance = 0; roadDistance < distanceToTravel; roadDistance++)
            {
                CalcShrunkPlots(shrunkPlotList, directionToTravel, townId);
                expansionPoint = AngleStuff.AddPointToDirection(expansionPoint, directionToTravel);

                if (CheckIfLandType(expansionPoint, shrunkMap, LandType.OPEN) || forceThroughPlot)
                {
                    TurnIntoRoad(expansionPoint, townId, shrunkMap, shrunkPlotList);

                    if (roadDistance != distanceToTravel - 1) //We are not at our last piece
                    {
                        if (!AddPlot(expansionPoint, AngleStuff.RotateDirection(directionToTravel, -2), plotLeft, shrunkMap))
                        {
                            plotLeft = null;
                        }
                        if (!AddPlot(expansionPoint, AngleStuff.RotateDirection(directionToTravel, 2), plotRight, shrunkMap))
                        {
                            plotRight = null;
                        }
                    }

                    if (IsMoreThanTwoNeighbours(expansionPoint, shrunkMap))
                    {
                        addConnectingPoint = false;
                        break;
                    }
                }
                else
                {
                    roadDistance = distanceToTravel - 1;
                }

                if (roadDistance > 4)
                {
                    addConnectingPoint = true;
                }

                if (roadDistance == distanceToTravel - 1 && !forceThroughPlot)
                {
                    int amount = ExtraToReachRoad(shrunkMap, directionToTravel, expansionPoint);
                    if (amount > 0)
                    {
                        TurnIntoRoad(expansionPoint, townId, shrunkMap, shrunkPlotList);
                        distanceToTravel += amount;
                        forceThroughPlot  = true;
                    }
                }
                //Do we add to road distance
                //We also check at the end and do the smooth thing
            }
            plotLeft  = null;
            plotRight = null;


            if (addConnectingPoint)
            {
                AddConnectingPoint(expansionPoint, directionToTravel, connectingPointList, shrunkMap);
            }
        }
Пример #24
0
 private void UpdateVelocity()
 {
     velocity = AngleStuff.RadianToVector(windDirection) * windSpeed * (lifeIncrease * EngineController.gameUpdateTime);
 }
Пример #25
0
 public int GetMirrorDirection()
 {
     return(AngleStuff.RotateDirection(directionFrom, 4));
 }
Пример #26
0
 public int GetDefaultDirectionMirror()
 {
     return(AngleStuff.RotateDirection(defaultDirection, 4));
 }
Пример #27
0
 public float GetDefaultDirectionRadian()
 {
     return(AngleStuff.DirectionToRadian(defaultDirection));
 }