예제 #1
0
    public static void ExitCannon()
    {
        if (currentCannon != null)
        {
            currentCannon.StartCoroutine(LeaveCannon());
            currentCannon.Selected = false;
            currentCannon.DestroyIndicator();
            currentCannon.ReturnToDefault();

            if (!currentCannon.C.Moved)
            {
                HighlightMaster.HighlightUnitToggle(true, currentCannon.C);
            }

            currentCannon = null;

            soundM.ButtonPress();
        }
    }
예제 #2
0
 private static void ScanForCannon()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0) /*&& Events.GetComponent<Pause>().paused == false*/)
     {
         Ray        ray;
         RaycastHit hit;
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit))
         {
             Cannon c = hit.transform.gameObject.GetComponent <Cannon>();
             if (c != null)
             {
                 if (c.player == PlayerMaster.CurrentTurn && !c.Moved && c.shots != 0)
                 {
                     currentCannon = hit.transform.GetComponentInChildren <CannonControll>();
                     CurrentPowerShow();
                     currentCannon.Selected = true;
                     currentCannon.StartCoroutine(CannonMaster.MoveToCannon());
                 }
             }
         }
     }
 }
예제 #3
0
    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();
            }
        }
    }
예제 #4
0
 public static void SetAICannon(Cannon can)
 {
     currentCannon          = can.GetComponentInChildren <CannonControll>();
     currentCannon.Selected = true;
     currentCannon.StartCoroutine(CannonMaster.MoveToCannon());
 }
예제 #5
0
 public static void ResetCurrent()
 {
     currentCannon = null;
 }