// Use this for initialization
		void Start () {
			if(defaultPath==null){
				Debug.Log("DefaultPath on SpawnManager not assigned, auto search for one");
				defaultPath=(PathTD)FindObjectOfType(typeof(PathTD));
			}
			
			if(spawnLimit==_SpawnLimit.Infinite || procedurallyGenerateWave){
				waveGenerator.CheckPathList();
				if(defaultPath!=null && waveGenerator.pathList.Count==0) waveGenerator.pathList.Add(defaultPath);
			}
			
			//waveGenerator.Generate(i);
			if(spawnLimit==_SpawnLimit.Finite && procedurallyGenerateWave){
				for(int i=0; i<waveList.Count; i++){
					waveList[i]=waveGenerator.Generate(i);
				}
			}
			
			if(spawnLimit==_SpawnLimit.Infinite) waveList=new List<Wave>();
			if(spawnLimit==_SpawnLimit.Finite){
				for(int i=0; i<waveList.Count; i++) waveList[i].waveID=i;
			}
			
			if(autoStart) StartCoroutine(AutoStartRoutine());
		}
Beispiel #2
0
        public void Init()
        {
            if (defaultPath == null)
            {
                Debug.Log("DefaultPath on SpawnManager not assigned, auto search for one");
                defaultPath = (PathTD)FindObjectOfType(typeof(PathTD));
            }

            if (procedurallyGenerateWave)
            {
                waveGenerator.CheckPathList();
                if (defaultPath != null && waveGenerator.pathList.Count == 0)
                {
                    waveGenerator.pathList.Add(defaultPath);
                }

                for (int i = 0; i < waveList.Count; i++)
                {
                    waveList[i] = waveGenerator.Generate(i);
                }
            }

            for (int i = 0; i < waveList.Count; i++)
            {
                waveList[i].waveID = i;
            }

            if (autoStart)
            {
                StartCoroutine(AutoStartRoutine());
            }
        }
Beispiel #3
0
        public void SetNewPath(PathTD newPath)
        {
            // TODO Path destruction is here ?
            // Paths zero ??
            if (path != null && path.name == "CreepCustomPath")
            {
                Destroy(path.gameObject);
            }

            path         = newPath;
            waypointID   = 1;
            waypointList = path.GetWaypointList();

            distFromDestination = CalculateDistFromDestination();
        }
Beispiel #4
0
        public int AddSubPath(PathTD pathInstance, int wpID, Transform startP, Transform endP)
        {
            walkable=true;

            int ID=subPathList.Count;

            SubPath subPath=new SubPath();
            subPath.parentPath=pathInstance;
            subPath.wpIDPlatform=wpID;
            subPath.connectStart=startP;
            subPath.connectEnd=endP;

            subPathList.Add(subPath);

            return ID;
        }
Beispiel #5
0
        public int AddSubPath(PathTD pathInstance, int wpID, Transform startP, Transform endP)
        {
            walkable = true;

            int ID = subPathList.Count;

            SubPath subPath = new SubPath();

            subPath.parentPath   = pathInstance;
            subPath.wpIDPlatform = wpID;
            subPath.connectStart = startP;
            subPath.connectEnd   = endP;

            subPathList.Add(subPath);

            return(ID);
        }
Beispiel #6
0
        //parent unit is for unit which is spawned from destroyed unit
        public void Init(PathTD p, int ID, int wID, UnitCreep parentUnit = null)
        {
            Init();

            path       = p;
            instanceID = ID;
            waveID     = wID;

            float dynamicX = Random.Range(-path.dynamicOffset, path.dynamicOffset);
            float dynamicZ = Random.Range(-path.dynamicOffset, path.dynamicOffset);

            pathDynamicOffset = new Vector3(dynamicX, 0, dynamicZ);
            thisT.position   += pathDynamicOffset;

            if (parentUnit == null)
            {
                waypointID    = 1;
                subWaypointID = 0;
                subPath       = path.GetWPSectionPath(waypointID);
            }
            else
            {
                //inherit stats and path from parent unit
                waypointID    = parentUnit.waypointID;
                subWaypointID = parentUnit.subWaypointID;
                subPath       = parentUnit.subPath;

                fullHP     = parentUnit.fullHP * parentUnit.spawnUnitHPMultiplier;
                fullShield = parentUnit.fullShield * parentUnit.spawnUnitHPMultiplier;
                HP         = fullHP; shield = fullShield;
            }

            distFromDestination = CalculateDistFromDestination();

            if (type == _CreepType.Offense)
            {
                StartCoroutine(ScanForTargetRoutine());
                StartCoroutine(TurretRoutine());
            }
            if (type == _CreepType.Support)
            {
                StartCoroutine(SupportRoutine());
            }
        }
Beispiel #7
0
        // Use this for initialization
        void Start()
        {
            if (defaultPath == null)
            {
                Debug.Log("DefaultPath on SpawnManager not assigned, auto search for one");
                defaultPath = (PathTD)FindObjectOfType(typeof(PathTD));
            }

            if (spawnLimit == _SpawnLimit.Infinite || procedurallyGenerateWave)
            {
                waveGenerator.CheckPathList();
                if (defaultPath != null && waveGenerator.pathList.Count == 0)
                {
                    waveGenerator.pathList.Add(defaultPath);
                }
            }

            //waveGenerator.Generate(i);
            if (spawnLimit == _SpawnLimit.Finite && procedurallyGenerateWave)
            {
                for (int i = 0; i < waveList.Count; i++)
                {
                    waveList[i] = waveGenerator.Generate(i);
                }
            }

            if (spawnLimit == _SpawnLimit.Infinite)
            {
                waveList = new List <Wave>();
            }
            if (spawnLimit == _SpawnLimit.Finite)
            {
                for (int i = 0; i < waveList.Count; i++)
                {
                    waveList[i].waveID = i;
                }
            }

            if (autoStart)
            {
                StartCoroutine(AutoStartRoutine());
            }
        }
		//parent unit is for unit which is spawned from destroyed unit
		public void Init(PathTD p, int ID, int wID){
			//for navigation using navmesh, not in use at all, require navmesh carving (unity-pro only) to work properly
			//if(useNavMesh){ InitNavMesh(p, ID, wID); return; }
			
			Init();
			
			path=p;
			instanceID=ID;
			waveID=wID;
			
			float dynamicX=Random.Range(-path.dynamicOffset, path.dynamicOffset);
			float dynamicZ=Random.Range(-path.dynamicOffset, path.dynamicOffset);
			pathDynamicOffset=new Vector3(dynamicX, 0, dynamicZ);
			thisT.position+=pathDynamicOffset;
			
			waypointID=1;
			waypointList=path.GetWaypointList();
			
			distFromDestination=CalculateDistFromDestination();
		}
Beispiel #9
0
        //parent unit is for unit which is spawned from destroyed unit
        public void Init(PathTD p, int ID, int wID)
        {
            //for navigation using navmesh, not in use at all, require navmesh carving (unity-pro only) to work properly
            //if(useNavMesh){ InitNavMesh(p, ID, wID); return; }

            Init();

            path       = p;
            instanceID = ID;
            waveID     = wID;

            float dynamicX = Random.Range(-path.dynamicOffset, path.dynamicOffset);
            float dynamicZ = Random.Range(-path.dynamicOffset, path.dynamicOffset);

            pathDynamicOffset = new Vector3(dynamicX, 0, dynamicZ);
            thisT.position   += pathDynamicOffset;

            waypointID   = 1;
            waypointList = path.GetWaypointList();

            distFromDestination = CalculateDistFromDestination();
        }
Beispiel #10
0
		//parent unit is for unit which is spawned from destroyed unit
		public void Init(PathTD p, int ID, int wID, UnitCreep parentUnit=null){
			Init();
			
			path=p;
			instanceID=ID;
			waveID=wID;
			
			float dynamicX=Random.Range(-path.dynamicOffset, path.dynamicOffset);
			float dynamicZ=Random.Range(-path.dynamicOffset, path.dynamicOffset);
			pathDynamicOffset=new Vector3(dynamicX, 0, dynamicZ);
			thisT.position+=pathDynamicOffset;
			
			if(parentUnit==null){
				waypointID=1;
				subWaypointID=0;
				subPath=path.GetWPSectionPath(waypointID);
			}
			else{
				//inherit stats and path from parent unit
				waypointID=parentUnit.waypointID;
				subWaypointID=parentUnit.subWaypointID;
				subPath=parentUnit.subPath;
				
				fullHP=parentUnit.fullHP*parentUnit.spawnUnitHPMultiplier;
				fullShield=parentUnit.fullShield*parentUnit.spawnUnitHPMultiplier;
				HP=fullHP; shield=fullShield;
			}
			
			distFromDestination=CalculateDistFromDestination();
			
			if(type==_CreepType.Offense){
				StartCoroutine(ScanForTargetRoutine());
				StartCoroutine(TurretRoutine());
			}
			if(type==_CreepType.Support){
				StartCoroutine(SupportRoutine());
			}
		}
Beispiel #11
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);
        }
Beispiel #12
0
        IEnumerator SpawnSubWave(SubWave subWave, Wave parentWave)
        {
            yield return(new WaitForSeconds(subWave.delay));

            PathTD path = defaultPath;

            if (subWave.path != null)
            {
                path = subWave.path;
            }

            Vector3    pos = path.GetSpawnPoint().position;
            Quaternion rot = path.GetSpawnPoint().rotation;

            int spawnCount = 0;

            while (spawnCount < subWave.count)
            {
                GameObject obj  = ObjectPoolManager.Spawn(subWave.unit, pos, rot);
                UnitCreep  unit = obj.GetComponent <UnitCreep>();

                if (subWave.overrideHP > 0)
                {
                    unit.OverrideByHP(subWave.overrideHP);
                }
                else
                {
                    unit.OverrideByWave(parentWave.waveID, developPerWave);
                }

                unit.Init(path, totalSpawnCount, parentWave.waveID);

                totalSpawnCount            += 1;
                activeUnitCount            += 1;
                parentWave.activeUnitCount += 1;

                spawnCount += 1;
                if (spawnCount == subWave.count)
                {
                    break;
                }

                yield return(new WaitForSeconds(subWave.interval));
            }

            parentWave.subWaveSpawnedCount += 1;
            if (parentWave.subWaveSpawnedCount == parentWave.subWaveList.Count)
            {
                parentWave.spawned = true;
                spawning           = false;
                Debug.Log("wave " + (parentWave.waveID + 1) + " has done spawning");

                yield return(new WaitForSeconds(0.5f));

                if (currentWaveID <= waveList.Count - 2)
                {
                    //for UI to show spawn button again
                    if (spawnMode == _SpawnMode.Continous && allowSkip && onEnableSpawnE != null)
                    {
                        onEnableSpawnE();
                    }
                    if (spawnMode == _SpawnMode.WaveCleared && allowSkip && onEnableSpawnE != null)
                    {
                        onEnableSpawnE();
                    }
                }
            }
        }
Beispiel #13
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);
        }
Beispiel #14
0
        void Awake()
        {
            instance = (PathTD)target;

            EditorUtility.SetDirty(instance);
        }
Beispiel #15
0
        //parent unit is for unit which is spawned from destroyed unit
        public void Init(PathTD p, int ID, int wID, UnitCreep parentUnit = null)
        {
            Init();

            path       = p;
            instanceID = ID;
            waveID     = wID;

            float dynamicX = Random.Range(-path.dynamicOffset, path.dynamicOffset);
            float dynamicZ = Random.Range(-path.dynamicOffset, path.dynamicOffset);

            pathDynamicOffset = new Vector3(dynamicX, 0, dynamicZ);
            thisT.position   += pathDynamicOffset;

            if (parentUnit == null)
            {
                waypointID    = 1;
                subWaypointID = 0;
                subPath       = path.GetWPSectionPath(waypointID);
            }
            else
            {
                //inherit stats and path from parent unit
                waypointID    = parentUnit.waypointID;
                subWaypointID = parentUnit.subWaypointID;
                subPath       = parentUnit.subPath;

                defaultHP = parentUnit.defaultHP * parentUnit.spawnUnitHPMultiplier;
                HP        = GetFullHP();

                defaultShield = parentUnit.defaultShield * parentUnit.spawnUnitHPMultiplier;
                shield        = GetFullShield();
            }

            distFromDestination = CalculateDistFromDestination();

            if (type == _CreepType.Offense)
            {
                maskTarget = 1 << TDTK.GetLayerTower();
                StartCoroutine(ScanForTargetRoutine());
                StartCoroutine(TurretRoutine());
            }
            if (type == _CreepType.Support)
            {
                LayerMask mask1 = 1 << TDTK.GetLayerCreep();
                LayerMask mask2 = 1 << TDTK.GetLayerCreepF();
                maskTarget = mask1 | mask2;

                StartCoroutine(SupportRoutine());
            }

            int rscCount = ResourceManager.GetResourceCount();

            while (valueRscMin.Count < rscCount)
            {
                valueRscMin.Add(0);
            }
            while (valueRscMin.Count > rscCount)
            {
                valueRscMin.RemoveAt(valueRscMin.Count - 1);
            }
            while (valueRscMax.Count < rscCount)
            {
                valueRscMax.Add(0);
            }
            while (valueRscMax.Count > rscCount)
            {
                valueRscMax.RemoveAt(valueRscMax.Count - 1);
            }

            PlayAnimSpawn();
        }
 void Awake()
 {
     instance = (PathTD)target;
 }
Beispiel #17
0
        IEnumerator SpawnSubWave(SubWave subWave, Wave parentWave)
        {
            if (subWave.unit == null)
            {
                Debug.LogWarning("No creep prefab has been assigned to sub-wave", this);
                yield break;
            }

            yield return(new WaitForSeconds(subWave.delay));

            PathTD path = defaultPath;

            if (subWave.path != null)
            {
                path = subWave.path;
            }

            Vector3    pos = path.GetSpawnPoint().position;
            Quaternion rot = path.GetSpawnPoint().rotation;

            int spawnCount = 0;

            if (subWave.unitC == null)
            {
                subWave.unitC = subWave.unit.GetComponent <UnitCreep>();
            }

            while (spawnCount < subWave.count)
            {
                if (subWave.unit == null)
                {
                    Debug.LogWarning("no creep has been assigned to subwave", this);
                    break;
                }

                GameObject obj  = ObjectPoolManager.Spawn(subWave.unit, pos, rot);
                UnitCreep  unit = obj.GetComponent <UnitCreep>();

                if (subWave.overrideHP > 0)
                {
                    unit.defaultHP = subWave.overrideHP;
                }
                else
                {
                    unit.defaultHP = subWave.unitC.defaultHP;
                }

                if (subWave.overrideShield > 0)
                {
                    unit.defaultShield = subWave.overrideShield;
                }
                else
                {
                    unit.defaultShield = subWave.unitC.defaultShield;
                }

                if (subWave.overrideMoveSpd > 0)
                {
                    unit.moveSpeed = subWave.overrideMoveSpd;
                }
                else
                {
                    unit.moveSpeed = subWave.unitC.moveSpeed;
                }

                unit.Init(path, totalSpawnCount, parentWave.waveID);

                totalSpawnCount += 1;
                activeUnitCount += 1;

                parentWave.activeUnitCount += 1;

                spawnCount += 1;
                if (spawnCount == subWave.count)
                {
                    break;
                }

                yield return(new WaitForSeconds(subWave.interval));
            }

            parentWave.subWaveSpawnedCount += 1;
            if (parentWave.subWaveSpawnedCount == parentWave.subWaveList.Count)
            {
                parentWave.spawned = true;
                spawning           = false;
                Debug.Log("wave " + (parentWave.waveID + 1) + " has done spawning");

                yield return(new WaitForSeconds(0.5f));

                if (currentWaveID <= waveList.Count - 2)
                {
                    if ((spawnMode == _SpawnMode.WaveCleared || spawnMode == _SpawnMode.Continous) && allowSkip)
                    {
                        TDTK.OnEnableSpawn();
                    }
                }
            }
        }
Beispiel #18
0
        void Awake()
        {
            instance = (PathTD)target;

            EditorUtility.SetDirty(instance);
        }
Beispiel #19
0
        public void Init()
        {
            if (defaultPath == null)
            {
                Debug.Log("DefaultPath on SpawnManager not assigned, auto search for one");
                defaultPath = (PathTD)FindObjectOfType(typeof(PathTD));
            }

            if (procedurallyGenerateWave)
            {
                waveGenerator.CheckPathList();
                if (defaultPath != null && waveGenerator.pathList.Count == 0) waveGenerator.pathList.Add(defaultPath);

                for (int i = 0; i < waveList.Count; i++)
                {
                    waveList[i] = waveGenerator.Generate(i);
                }
            }

            for (int i = 0; i < waveList.Count; i++) waveList[i].waveID = i;

            if (autoStart) StartCoroutine(AutoStartRoutine());
        }
Beispiel #20
0
        public void SetNewPath(PathTD newPath)
        {
            // TODO Path destruction is here ?
              // Paths zero ??
              if (path != null && path.name == "CreepCustomPath")
              {
            Destroy(path.gameObject);
              }

              path = newPath;
              waypointID = 1;
              waypointList = path.GetWaypointList();

              distFromDestination = CalculateDistFromDestination();
        }