예제 #1
0
        public PathFinder(PathFindingParameters parameters)
        {
            this.parameters = parameters;
              InitNodes(parameters.Map);

              this.startNode = this.nodes[parameters.StartLocation.X, parameters.StartLocation.Y];
              this.destinationNode = this.nodes[parameters.EndLocation.X, parameters.EndLocation.Y];

              this.startNode.State = PathNodeState.Possible;
        }
예제 #2
0
        public PathFinder(PathFindingParameters parameters)
        {
            this.parameters = parameters;
            InitNodes(parameters.Map);

            this.startNode       = this.nodes[parameters.StartLocation.X, parameters.StartLocation.Y];
            this.destinationNode = this.nodes[parameters.EndLocation.X, parameters.EndLocation.Y];

            this.startNode.State = PathNodeState.Possible;
        }
예제 #3
0
        public bool UpdatePathMaps(UnitTower tow, bool destroy = false)
        {
            int index_z = (int)Mathf.Round(tow.Platform.transform.position.z - platform_min_z) / 2;
              int index_x = (int)Mathf.Round(tow.Platform.transform.position.x - platform_min_x) / 2;

              if (index_z < 0)
            return true;

              beerMap[index_x, index_z + 1] = destroy;  // false -> new tower build there

              // Check if the last paths are still walkable
              // exit if true
              if (lastPathOne.Count >= 0 && lastPathTwo.Count >= 0)
              {
            bool lastPathOK = true;

            for (int i = 0; i < lastPathOne.Count; i++)
            {
              if (beerMap[lastPathOne[i].X, lastPathOne[i].Y] == false)
            lastPathOK = false;
            }

            for (int i = 0; i < lastPathTwo.Count; i++)
            {
              if (beerMap[lastPathTwo[i].X, lastPathTwo[i].Y] == false)
            lastPathOK = false;
            }

            if (lastPathOK)
              return true;
              }

              if (!GenerateGlobalPaths())
              {
            beerMap[index_x, index_z + 1] = !destroy;
            GenerateGlobalPaths();
            return false;
              }

              // TODO position of this SpawnManager functions ?
              // Here becazse GenerateGlobalPaths is called at startup
              // Waves not generated at that time
              for (int i = 0; i < SpawnManager.instance.waveList.Count; i++)
              {
            SpawnManager.instance.waveGenerator.UpdateWavePath(SpawnManager.instance.waveList[i]);
              }

              UnitCreep[] creeps = ObjectPoolManager.FindObjectsOfType<UnitCreep>();
              foreach (UnitCreep creep in creeps)
              {
            // Problem with creeps not in the maze -> between start and normal platforms
            // or between normal platforms and goal
            // No new Path, if creep is already past the last tower row
            if (creep.transform.position.z > platform_min_z)
            {
              int c_z;
              if (creep.transform.position.z > platform_max_z)
            c_z = 34;
              else
            c_z = Mathf.CeilToInt(creep.transform.position.z - platform_min_z) / 2; // Changed to CeilToInt and not round

              int c_x = (int)Mathf.Round(creep.transform.position.x - platform_min_x) / 2;
              parameters = new PathFindingParameters(new Point(c_x, c_z), pt_goal, beerMap, nodeMap);
              pf = new PathFinder(parameters);

              PathTD pt = pf.FindPathTD(creep.transform, "CreepCustomPath");

              creep.SetNewPath(pt);
            }
              }

              //Object[] towers = GameObject.FindObjectsOfType(typeof(UnitTower));

              //Object[] platforms = GameObject.FindObjectsOfType(typeof(PlatformTD));

              //Object[] paths = GameObject.FindObjectsOfType(typeof(PathTD));

              //SpawnManager.ChangeDefaultPath(paths[0] as PathTD);
              return true;
        }
예제 #4
0
        public bool GenerateGlobalPaths()
        {
            // Delete the old paths from the previous calculations
              Object[] existingPaths = GameObject.FindObjectsOfType(typeof(PathTD));
              foreach (PathTD item in existingPaths)
              {
            Destroy(item.gameObject);
              }

              parameters = new PathFindingParameters(pt_spawnOne, pt_goal, beerMap, nodeMap);
              pf = new PathFinder(parameters);
              Transform spawnOneTf = (nodeMap[pt_spawnOne.X, pt_spawnOne.Y] as GameObject).transform;
              PathTD pathOne = pf.FindPathTD(spawnOneTf, "GlobalPathOne");
              lastPathOne = pf.getLastPath();

              parameters = new PathFindingParameters(pt_spawnTwo, pt_goal, beerMap, nodeMap);
              pf = new PathFinder(parameters);
              Transform spawnTwoTf = (nodeMap[pt_spawnTwo.X, pt_spawnTwo.Y] as GameObject).transform;
              PathTD pathTwo = pf.FindPathTD(spawnTwoTf, "GlobalPathTwo");
              lastPathTwo = pf.getLastPath();

              if (pathOne.wpList.Count == 0 || pathTwo.wpList.Count == 0)
              {
            return false;
              }

              // TODO better capsulation from the Spawnmanager
              // and also check the initialization of the spawnmanager
              SpawnManager.instance.defaultPath = pathOne;
              SpawnManager.instance.waveGenerator.pathList.Clear();
              SpawnManager.instance.waveGenerator.pathList.Add(pathOne);
              SpawnManager.instance.waveGenerator.pathList.Add(pathTwo);

              return true;
        }