//Cycles through GameObject arrays in arrLayout to add stopSpace property from PointNetwork.cs to all elements of one array public void Change() { cycles = arrLayout.lanes[select].lane; //Selects an array for (int i = 0; i < arrLayout.lanes.Length; i++) { for (int j = 0; j < arrLayout.lanes[i].lane.Length; j++) { //All points are reset to default state GameObject point = arrLayout.lanes[i].lane[j]; PointNetwork intersection = point.GetComponent <PointNetwork>(); intersection.stopSpace = false; } } for (int i = 0; i < arrLayout.lanes.Length; i++) { if (cycles == arrLayout.lanes[i].lane) { for (int j = 0; j < cycles.Length; j++) { //Points in selected array given stopSpace property GameObject point = cycles[j]; PointNetwork intersection = point.GetComponent <PointNetwork>(); intersection.stopSpace = true; } } } //Changes selected array to the next available array in a loop if (select < arrLayout.lanes.Length - 1) { select += 1; } else { select = 0; } }
// Use this for initialization void Start() { shotPointNetwork = ShotPointNetwork.GetComponent<PointNetwork>(); projectiles = new List<GameObject>(); }
//public enum FreeRoamMethod (STAYPUT,PATROL,GORANDOMDIR) /* * Note, we should have a dropDown of attack methods, flight patters, etc * That way we can have one robjust AI controller, and then for each AI type, we can just assign the same controller, and pick and choose settings. * like AttackMethod - followDirect, followIndirect, slowChase * FreeRoam - patrol, randomDirects, etc. * * Following this paradigm will also allow people to create their own AI. */ // Use this for initialization void Start() { if(behaviors.Contains(Behavior.SHOOTATPLAYER)) { shotPointNetwork = ShotPointNetwork.GetComponent<PointNetwork>(); } if (behaviors.Contains(Behavior.SPAWNENEMIES)) { spawnPointNetwork = SpawnPointNetwork.GetComponent<PointNetwork>(); } loopPosition = PlayerShip.transform.position; projectiles = new List<GameObject>(); enemies = new List<GameObject>(); shotTimer = 0; spawnTimer = 0; unloadTimer = 0; shotCount = 0; spawnCount = 0; looping = false; angleLooped = 0; }
//Update function is called once before every frame of animation void Update() { if (!pointNetwork.stopSpace) { mySpeed = spd.mySpeed; //Speed set by SpeedSearch procedures } privateTimer += Time.deltaTime; //Records time between car spawn and deletion if (pointNetwork.nextPos == null && pointNetwork.leftMerge == null && pointNetwork.rightMerge == null && pointNetwork.altNextPos == null) //Car deleted when it has no path to follow { record.SetMean(privateTimer, current); //Sends timer variable to MeanCalculator.cs Destroy(gameObject); } //Car always moves forward when in scene, only stops at stoplights if (!pointNetwork.stopSpace) { transform.position += transform.forward * Time.deltaTime * mySpeed; } else { mySpeed = 0; } //Merging state if (merging) { //Car is deleted if in merging state for too long mergeTimer += Time.deltaTime; if (mergeTimer > 2.0f) { Destroy(gameObject); } //Merge left if (mergingLeft) { //Only true at the beginning of a merge, used for preliminary setup if (enterMerge == true) { if (pointNetwork.leftMerge == null) { merging = false; //Deactivates merging state if there is no path to merge to } else { nextPos = pointNetwork.leftMerge; } enterMerge = false; } else if (IsInLineWith(nextPos)) { merging = false; //Deactivates merging state } else if (transform.position != nextPos.transform.position) { if (IsInFrontOf(nextPos)) { pointNetwork = nextPos.GetComponent <PointNetwork>(); current = pointNetwork.current; nextPos = pointNetwork.nextPos; } transform.position -= transform.right * Time.deltaTime * 3; } else { merging = false; } } //Merge right if (mergingRight) { if (enterMerge == true) { if (pointNetwork.rightMerge == null) { merging = false; } else { nextPos = pointNetwork.rightMerge; } enterMerge = false; } else if (IsInLineWith(nextPos)) { merging = false; } else if (transform.position != nextPos.transform.position) { if (IsInFrontOf(nextPos)) { pointNetwork = nextPos.GetComponent <PointNetwork>(); current = pointNetwork.current; nextPos = pointNetwork.nextPos; } transform.position += transform.right * Time.deltaTime * 3; } else { merging = false; } } } //Non-merging state else if (!merging) { //Prevents car from merging mergingLeft = false; mergingRight = false; if (pointNetwork.leftMerge != null && spd.SafeToMergeL() && spd.WantToMergeL()) //Merging conditions { MergeLeft(); //Function call, activates merging state } if (pointNetwork.rightMerge != null && spd.SafeToMergeR() && spd.WantToMergeR()) //Merging conditions { MergeRight(); //Function call, activates merging state } //Car faces towards nextPos object while moving forward if (transform.position != nextPos.transform.position) { if (IsInFrontOf(nextPos)) { pointNetwork = nextPos.GetComponent <PointNetwork>(); current = pointNetwork.current; nextPos = pointNetwork.nextPos; //If an alternate path exists, car may move on the alternate path instead if (pointNetwork.altNextPos != null) { int x = 0; PointNetwork altNet = pointNetwork.altNextPos.GetComponent <PointNetwork>(); for (int i = 0; i < altNet.destSize; i++) { if (altNet.possibleDestArray[i].name == spd.destination.name) { x = 1; break; } else { x = (int)Random.Range(0.0f, 1.9f); } } if (x == 1) { current = pointNetwork.current; nextPos = pointNetwork.altNextPos; } } } transform.LookAt(nextPos.transform.position); } //After nextPos is reached, car looks for a new next position else { pointNetwork = nextPos.GetComponent <PointNetwork>(); current = pointNetwork.current; nextPos = pointNetwork.nextPos; if (pointNetwork.altNextPos != null) { int x = 0; PointNetwork altNet = pointNetwork.altNextPos.GetComponent <PointNetwork>(); for (int i = 0; i < altNet.destSize; i++) { if (altNet.possibleDestArray[i].name == spd.destination.name) { x = 1; break; } else { x = (int)Random.Range(0.0f, 1.9f); } } if (x == 1) { current = pointNetwork.current; nextPos = pointNetwork.altNextPos; } } } } }