private void CheckNeigbours()
    {
        foreach (Vector2Int direction in RandomizeDirectionOfSearch())
        {
            Vector2Int explorationcoordinates = searchCenter.GetGridPos() + direction;
            print("exploring " + explorationcoordinates);
            try
            {
                Waypoint2 neighbour = grid[explorationcoordinates];

                //neighbour.SetTopColor(gameControler.ColorExploration);
                if (neighbour.isExplored == true || queueOfWaypoints.Contains(neighbour))
                {
                    //do nothing
                }
                else
                {
                    queueOfWaypoints.Enqueue(neighbour);
                    neighbour.foundByWaypoint = searchCenter;
                }
                CheckIsEnd(neighbour);
            }
            catch
            {
                //do nothing
            }
        }
    }
Example #2
0
        public void WriteToStream(EndianBinaryWriter stream)
        {
            stream.Write(SquareTypeId);

            stream.Write(Position.X);
            stream.Write(Position.Y);

            stream.Write(Unknown1);
            Waypoint1.WriteToStream(stream);
            Waypoint2.WriteToStream(stream);
            Waypoint3.WriteToStream(stream);
            Waypoint4.WriteToStream(stream);

            stream.Write(DistrictDestinationId);

            stream.Write(Unknown2);

            stream.Write(Value);

            stream.Write(Price);

            stream.Write(Unknown3);

            stream.Write(ShopModelId);
        }
 void CheckIsEnd(Waypoint2 checkedWaypoint)
 {
     if (checkedWaypoint == gameControler.EndWaypoint)
     {
         isRunning = false;
         queueOfWaypoints.Clear();
     }
 }
    private void InstantiateTower(Waypoint2 baseWaypoint)
    {
        var newTower = Instantiate(objectToSpawn, baseWaypoint.transform.position, Quaternion.identity);

        newTower.GetComponent <Tower>().sebaWaypoint = baseWaypoint;
        towerQueue.Enqueue(newTower);
        baseWaypoint.waypointWithObject = true;
    }
    private void MoveTower(Waypoint2 baseWaypoint)
    {
        var oldTower = towerQueue.Dequeue();

        oldTower.GetComponent <Tower>().sebaWaypoint.waypointWithObject = false;
        oldTower.GetComponent <Tower>().sebaWaypoint = baseWaypoint;
        oldTower.GetComponent <Tower>().sebaWaypoint.waypointWithObject = true;
        oldTower.transform.position = baseWaypoint.transform.position;
        towerQueue.Enqueue(oldTower);
    }
 void Pathfind()
 {
     ClearExploredMarks();
     queueOfWaypoints.Enqueue(gameControler.StartWaypoint);
     while (queueOfWaypoints.Count > 0 && isRunning)
     {
         searchCenter            = queueOfWaypoints.Dequeue();
         searchCenter.isExplored = true;
         CheckNeigbours();
     }
     AddWaypointsToThePath();
 }
 public void ManageTowers(Waypoint2 baseWaypoint)
 {
     print("########################" + towerQueue.Count);
     if (FindObjectsOfType <Tower>().Length >= towersLimit)
     {
         MoveTower(baseWaypoint);
     }
     else
     {
         InstantiateTower(baseWaypoint);
     }
     print("########################" + towerQueue.Count);
 }
    private void AddWaypointsToThePath()
    {
        SetAsPath(gameControler.EndWaypoint);
        Waypoint2 WaypointToAdd = gameControler.EndWaypoint.foundByWaypoint;

        while (WaypointToAdd != gameControler.StartWaypoint)
        {
            Path.Add(WaypointToAdd);
            WaypointToAdd.SetTopColor(gameControler.ColorPath);
            WaypointToAdd = WaypointToAdd.foundByWaypoint;
        }
        SetAsPath(gameControler.StartWaypoint);
        Path.Reverse();
        pathReady = true;
    }
 private void SetAsPath(Waypoint2 waypoint)
 {
     Path.Add(waypoint);
 }
Example #10
0
 private void Awake()
 {
     waypoint = GetComponent <Waypoint2>();
 }