public Team(Color tc, int teamIndex, bool ai){ enemyKilled = 0; spawned = 0; score = 0; teamColor = tc; units = new LinkedList<UnitScript>(); spawnBlocks = new LinkedList<GridBlock>(); index = teamIndex; if(ai) this.ai = new TeamAI(this); }
void Awake () { aStarAI = GetComponent<AstarAI> (); gameManager = GameObject.FindGameObjectWithTag ("GameController"); audioSource = GetComponent<AudioSource> (); if(Side == whichSide.Ally) { myTeamAI = GameObject.Find("Ally COMMANDER").GetComponent<TeamAI>(); oppositionLayer = LayerMask.GetMask("Enemy"); oppositionLayerAsString = "Enemy"; } else if(Side == whichSide.Enemy) { myTeamAI = GameObject.Find("Enemy COMMANDER").GetComponent<TeamAI>(); oppositionLayer = LayerMask.GetMask("Ally"); oppositionLayerAsString = "Ally"; } fovCollider = GetComponentInChildren<BoxCollider2D> (); suspiciousLayers = oppositionLayer; //TODO: Add corpses to this sightBlockLayers = LayerMask.GetMask ("Obstacle", "Door", "Ally", "Enemy"); myWeapon = transform.FindChild ("Gun").gameObject; shootScript = myWeapon.GetComponentInChildren<Shooting> (); speed = walkSpeed; aStarAI.speed = speed; normalStates = new stateMachine[] {stateMachine.Guarding, stateMachine.Patroling}; curiousStates = new stateMachine[] {stateMachine.CheckingBody, stateMachine.Searching}; combatStates = new stateMachine[] {stateMachine.Charging, stateMachine.TakingCover, stateMachine.Flanking}; postCombatStates = new stateMachine[] {stateMachine.CheckingBody, stateMachine.Searching}; }
public Vector2 ClosestCoverPoint (GameObject theCaller, bool mustAdvance) { if (allCover.Count == 0) return theCaller.transform.position; bool isAlly = false; if(mustAdvance && theCaller.layer == LayerMask.NameToLayer("Ally")) { isAlly = true; } else if(mustAdvance && theCaller.layer == LayerMask.NameToLayer("Enemy")) { isAlly = false; } float closestYet = Mathf.Infinity; Transform closestCover = null; //if that failed try just for somewhere ahead of me if (closestCover == null) { foreach(Transform coverPoint in allCover) { if(mustAdvance && isAlly && coverPoint.position.x > (theCaller.transform.position.x - 2f)) { continue; } else if(mustAdvance && !isAlly && coverPoint.position.x < (theCaller.transform.position.x + 2f)) { continue; } InCoverDetection coverScript = coverPoint.GetComponentInChildren<InCoverDetection>(); if(!coverScript.someoneIsHeadedHere && !coverScript.isOccupied) { if(Vector2.Distance(theCaller.transform.position, coverPoint.position) < closestYet) { closestCover = coverPoint; closestYet = Vector2.Distance(theCaller.transform.position, coverPoint.position); } } } } if (closestCover == null) { return theCaller.transform.position; } //if there is a point to go to, we pick the point on that cover that is opposite the enemy's avg position if(!isAlly) { oppositionAIScript = GameObject.Find("Ally COMMANDER").GetComponent<TeamAI>(); } else if(isAlly) { oppositionAIScript = GameObject.Find("Enemy COMMANDER").GetComponent<TeamAI>(); } Vector2 oppositionAvgPoint = oppositionAIScript.AveragePositionOfTeam (); Vector2 dir = ((Vector2)closestCover.position - oppositionAvgPoint).normalized; closestCover.GetComponentInChildren<InCoverDetection> ().someoneIsHeadedHere = true; if(theCaller.GetComponent<Soldier> ().coverImHeadedTo != null) theCaller.GetComponent<Soldier> ().coverImHeadedTo.GetComponentInChildren<InCoverDetection>().someoneIsHeadedHere = false; theCaller.GetComponent<Soldier> ().coverImHeadedTo = closestCover; Vector2 coverPointOnClosestCover = (Vector2)closestCover.position + (dir*1.1f); return coverPointOnClosestCover; }