public static IEnumerator Move() { GameBrain.ChangeAcceptInput(false); yield return(new WaitForSeconds(1.0f)); HexCell moveTo; for (int i = 0; i < ai_units.Count; ++i) { if (ai_units[i] != null) { HexCell unit_cell = ai_units[i].CurrentHex; MoveMaster.SetTarget(ai_units[i]); moveTo = MapMaster.Map[ai_units[i].CurrentHex.R - 2, ai_units[i].CurrentHex.Q]; MoveMaster.EvaluateTile(moveTo); //Actually moves unit } } yield return(new WaitForSeconds(.75f)); while (MoveMaster.movingUnits != 0) { yield return(null); } yield return(GameBrain.ChangeTurn()); //GameBrain.ChangeAcceptInput(true); }
public static IEnumerator IDontHaveCannons() { GameBrain.ChangeAcceptInput(false); yield return(new WaitForSeconds(2.0f)); yield return(GameBrain.ChangeTurn()); //GameBrain.ChangeAcceptInput(true); }
//AI's current goal is destroying all enemies public static IEnumerator Deploy() { FillDeployment(); //For the purposes of the alpha the AI only needs a single, reasonable deployment phase that it will use on each instance of the game. //Units should be reasonably spaced out. Cannons should spawn with enough units to carry them. //Some cannons will spawn with infantry. A small few will spawn with Cavalry. //In the future, deployment may be based on how the opponent has set up their deployment //Question: Are we going to use a point based system of deployment in the future, replacing the current X-amount-of-each-unit implementation for (int i = 0; i < 30; ++i) { GameObject g = (GameObject)GameObject.Instantiate(Resources.Load("prefabs/" + deployment[i] + (deployment[i] == "Cannon" ? "" : playernum.ToString())), PlayerMaster.CurrentPlayer.backLine[i].SpawnVector, Quaternion.identity); MapMaster.Map[PlayerMaster.CurrentPlayer.backLine[i].R, PlayerMaster.CurrentPlayer.backLine[i].Q].Unit = g.GetComponent <Unit>(); MapMaster.Map[PlayerMaster.CurrentPlayer.backLine[i].R, PlayerMaster.CurrentPlayer.backLine[i].Q].Unit.Player = playernum; MapMaster.Map[PlayerMaster.CurrentPlayer.backLine[i].R, PlayerMaster.CurrentPlayer.backLine[i].Q].Unit.CurrentHex = PlayerMaster.CurrentPlayer.backLine[i]; switch (deployment[i]) { case ("Infantry"): Unit inf = g.GetComponent <Infantry>(); PlayerMaster.CurrentPlayer.Inf.Add(inf); break; case ("Cavalry"): Unit cl = g.GetComponent <Cavalry>(); PlayerMaster.CurrentPlayer.Cav.Add(cl); break; case ("Cannon"): Cannon c = g.GetComponent <Cannon>(); c.Moved = false; c.CurrentHex = PlayerMaster.CurrentPlayer.backLine[i]; PlayerMaster.CurrentPlayer.Can.Add(c); break; } yield return(new WaitForSeconds(0.1f)); } foreach (Cannon c in PlayerMaster.CurrentPlayer.Can) { Cluster(c); } foreach (Cavalry cv in PlayerMaster.CurrentPlayer.Cav) { Cluster(cv); } foreach (Infantry i in PlayerMaster.CurrentPlayer.Inf) { Cluster(i); } GameBrain.ChangeTurn(); }
public static IEnumerator Move() //WIP AI movement. Currently kept simple for the purpose of making it into the alpha. Made a coroutine so the player can see each step { //Cannons move first and prioritize getting in range of an enemy but do not move if already in range of an enemy //yield return new WaitForSeconds(2.0f); //Cavalry and Infantry will move after and prioritize geting in range of the closest enemy //Closest enemy is relative to each unit. Units will not move if already adjacent to an enemy for (int s = 0; s < SquadMaster.Count; ++s) { otherlist = SquadMaster[s]; bool noCannons = true; for (int i = 0; i < otherlist.Count; ++i) { if (otherlist[i].gameObject.tag == "cannon" && otherlist[i] != null) { noCannons = false; //Debug.Log("Found cannon"); } } if (noCannons) { FindClosestEnemy(); yield return(new WaitForSeconds(.2f)); MoveLeadSoldier(); otherlist[0].StartCoroutine(MoveFollowers()); while (moving) //boolean that is changed via MoveFollowers { yield return(null); } } else //Move cannons forward about 2 spaces, then move the units nearby 2 spaces as well { MoveCannon(); yield return(new WaitForSeconds(.2f)); otherlist[0].StartCoroutine(MoveCannonFollowers()); while (moving) //boolean that is changed via MoveCannonFollowers { yield return(null); } } } GameBrain.ChangeTurn(); }
public static IEnumerator Deploy() { GameBrain.ChangeAcceptInput(false); for (int i = 19; i < 29; ++i) { GameObject g = (GameObject)GameObject.Instantiate(Resources.Load("prefabs/Infantry1"), PlayerMaster.CurrentPlayer.backLine[i].SpawnVector, Quaternion.identity); ai_units.Add(g.GetComponent <Unit>()); MapMaster.Map[PlayerMaster.CurrentPlayer.backLine[i].R, PlayerMaster.CurrentPlayer.backLine[i].Q].Unit = g.GetComponent <Unit>(); MapMaster.Map[PlayerMaster.CurrentPlayer.backLine[i].R, PlayerMaster.CurrentPlayer.backLine[i].Q].Unit.Player = 1; MapMaster.Map[PlayerMaster.CurrentPlayer.backLine[i].R, PlayerMaster.CurrentPlayer.backLine[i].Q].Unit.CurrentHex = PlayerMaster.CurrentPlayer.backLine[i]; PlayerMaster.CurrentPlayer.Inf.Add(g.GetComponent <Unit>()); yield return(new WaitForSeconds(0.2f)); } //GameObject cannon = (GameObject)GameObject.Instantiate(Resources.Load("prefabs/Cannon"), PlayerMaster.CurrentPlayer.backLine[30].SpawnVector, Quaternion.identity); yield return(GameBrain.ChangeTurn()); //GameBrain.ChangeAcceptInput(true); }
IEnumerator HandleCannons(Cannon can) { Debug.Log("handling " + can.gameObject.name); CannonMaster.SetAICannon(can); canc = can.transform.GetChild(0).transform.GetChild(0).GetComponent <CannonControll>(); aimAt = CenterOfCluster(); //asigns aimAt as the center of the cluster cube.transform.position = aimAt; Vector3 dir = aimAt - can.transform.position; angle = Vector3.SignedAngle(dir, can.transform.GetChild(0).transform.forward, Vector3.up); //math to figure out the difference between the target's position and where the cannon is currently looking if (angle > 0) { while (angle > 2.0f) { //moves cannon left until it is lined up with target canc.lefts(); angle = Vector3.SignedAngle(dir, can.transform.GetChild(0).transform.forward, Vector3.up); yield return(null); } } else { while (angle < -2.0f) { //moves cannon right until it is lined up with target canc.rights(); angle = Vector3.SignedAngle(dir, can.transform.GetChild(0).transform.forward, Vector3.up); yield return(null); } } for (int i = 17; i >= 0; --i) { //Moves cannon's aim downward so that later we only have to move it up to line up shots canc.downs(); yield return(null); } for (int i = 30; i >= 0; --i) { //Sets cannon at max power to more easily line up shots. Will more than likely be changed later to make lob shots possible canc.Powerup(); yield return(null); } RaycastHit ray; int num = canc.RayCastEnemies(out ray); //function created in CannonControl. Checks if a unit is within the current cannon's path RaycastHit hit; Physics.Raycast(new Ray(cube.gameObject.transform.position + Vector3.up, Vector3.down), out hit, 2.0f, 1 << 8); if (hit.transform != null) { Debug.Log(hit.transform); if (hit.transform.gameObject.GetComponent <HexCell>() != null) { GeneticCannon.goal = hit.transform.gameObject.GetComponent <HexCell>(); Debug.Log(GeneticCannon.goal.ToString()); yield return(GeneticCannon.SolveCannon()); } else { GeneticCannon.goal = currentCluster[0].CurrentHex; } } while (num != -1) { //Move aim up until a unit is found //Needs to be modified to confirm the current target and avoid allies canc.ups(); num = canc.RayCastEnemies(out ray); yield return(null); } canc.firecannon(); //StartCoroutine(AimAndShoot(can)); while (!combat.checkUnits) { yield return(null); } //Check units becomes true when a unit has been touched by a cannonball and becomes false once all "dead" units are removed from play while (combat.checkUnits) { yield return(null); } //if (inRangeTargets[target] == null) // ++target; //If target is dead, move to the next one //need proper target reprioritizing if (can.shots != 0) //if there is ammo left in the cannon, shoot again with the same cannon { inRangeTargets.Clear(); currentCluster.Clear(); biggestCluster.Clear(); //yield return new WaitForSeconds(10f); FindTargets(can); } else { while (currentCannon < PlayerMaster.CurrentPlayer.Can.Count && PlayerMaster.CurrentPlayer.Can[currentCannon].shots == 0) //Moves through cannons until we are out of available cannons or we find one with enough shots { ++currentCannon; } if (currentCannon < PlayerMaster.CurrentPlayer.Can.Count && PlayerMaster.OtherPlayer.Inf.Count > 0) //If we found a cannon that can be shot { //yield return new WaitForSeconds(10f); inRangeTargets.Clear(); currentCluster.Clear(); biggestCluster.Clear(); FindTargets(PlayerMaster.CurrentPlayer.Can[currentCannon]); //Find the targets within it's range and continue from there } else { Debug.Log("Out of cannons"); StartCoroutine(CannonMaster.LeaveCannon()); //If we are out of cannons then zoom back out GameBrain.ChangeTurn(); } } }
public static IEnumerator Fight() { yield return(new WaitForSeconds(2)); //Gives the player a chance to see which units are about to fight GameBrain.ChangeTurn(); }