Exemplo n.º 1
0
 public override void onSelected()
 {
     base.onSelected();
     clearBoard();
     _gui.ChosenPieces.Clear();
     foreach (GameObject hex in GameState.Instance.Board)
     {
         HexScript script = hex.GetComponent <HexScript>();
         if (script._row < 2)
         {
             script.GetComponent <Renderer>().material.SetColor("_Color", GameState.Instance.getPlayer(true).getColor());
         }
         else if (script._row > 5)
         {
             script.GetComponent <Renderer>().material.SetColor("_Color", GameState.Instance.AIPlayer.getColor());
         }
         else
         {
             script.setColor();
         }
     }
     _gui.generatePlayer2Pieces();
     _gui.gameObject.GetComponent <TutorialSelection>().enabled = true;
     _gui.gameObject.GetComponent <TutorialSelection> ().initializePlayer1();
 }
    public void DoTurn()
    {
        Debug.Log("DoTurn");

        if (hexPath == null || hexPath.Count == 0)
        {
            return;
        }
        //Grab the first hex in our queue
        HexScript newHex = hexPath.Dequeue();

        MovementRemaining -= newHex.movementCost;

        if (MovementRemaining < 0)
        {
        }
        else
        {
            //Move to the new Hex
            //SetHex(newHex);
            #region Debuging
            //HexScript oldHex = Hex;
            //newHex = oldHex.HexMap.GetHexAt(oldHex.C + 1, oldHex.R);
            #endregion

            SetHex(newHex);
        }
    }
Exemplo n.º 3
0
    /**
     * Returns the adjacent hex to the given hex, in the given map, at the given offset value.
     * The offset represents the distance, in a clockwise fashion around the given hex, from
     * the adjacent top hex.
     * So, passing 0 for offset will return the hex above the given hex; 1 will return the hex
     * to the top-right of the given hex, and so on.
     */
    public HexScript adjacentHexTo(HexScript hex, int offset)
    {
        try {
            int pos_x = (int)hex.position.x;
            int pos_y = (int)hex.position.y;

            switch(offset) {
                // top
                case 0: return map[pos_x][pos_y - 2];
                // top-right
                case 1: return (pos_y % 2 == 0) ? map[pos_x][pos_y - 1] : map[pos_x + 1][pos_y - 1];
                // bottom-right
                case 2: return (pos_y % 2 == 0) ? map[pos_x][pos_y + 1] : map[pos_x + 1][pos_y + 1];
                // bottom
                case 3: return map[pos_x][pos_y + 2];
                // bottom-left
                case 4: return (pos_y % 2 == 0) ? map[pos_x - 1][pos_y + 1] : map[pos_x][pos_y + 1];
                // top-left
                case 5: return (pos_y % 2 == 0) ? map[pos_x - 1][pos_y - 1] : map[pos_x][pos_y - 1];
                // invalid position
                default: return null;
            }
        } catch(Exception Ex) {
            // Either the hex give is invalid (or null) or the hex is on the map's boundary
            if (Ex is NullReferenceException || Ex is IndexOutOfRangeException || Ex is ArgumentOutOfRangeException) {
                return null;
            }

            throw;
        }
    }
Exemplo n.º 4
0
 public void SetUpGame(int players)
 {
     hexScript     = gameObject.AddComponent <HexScript>();
     grid          = hexScript.CreateGrid(gridDimension, size, hexMaterial);
     colors[0]     = hexMaterial.color;
     PlayersNumber = players;
     Destroy(menuPanel);
 }
Exemplo n.º 5
0
    public void SelectHex(HexScript hex)
    {
        if (SelectedHex != null)
            SelectedHex.Unselect();

        SelectedHex = hex;

        if (SelectedHex != null)
            SelectedHex.Select();
    }
    private void DoEndTurn()
    {
        if (hexes != null)
        {
            foreach (HexScript hex in hexes)
            {
                GameObject tempHexNeighbour_go = GameObject.Find("Hex_" + hex.C + "_" + hex.R);
                if (hex.movementCost == 1)
                {
                    tempHexNeighbour_go.transform.gameObject.GetComponentInChildren <MeshRenderer>().material.color = selectedHexesOriginalColor;
                }
            }
        }
        shortestSquareResult = 0;

        endTurnTrue  = false;
        endTurnDelay = 0;
        selectedHex  = null;

        rows    = new List <int>();
        columns = new List <int>();

        movementActivated = false;
        pathBegun         = true;
        aiTurn            = false;
        noCharacter       = false;

        turnNumber++;

        currentState = States.WaitingForTurn;

        if (currentTurnState == TurnsState.EnemyTurn_1 && MapGeneratorScript.instance.aiUnits.Count > 1)
        {
            currentTurnState = TurnsState.EnemyTurn_2;
            currentState     = States.Stalling;
            aiTurn           = true;
            endTurnTrue      = false;
        }
        else if (currentTurnState == TurnsState.EnemyTurn_2 && MapGeneratorScript.instance.aiUnits.Count > 2)
        {
            currentTurnState = TurnsState.EnemyTurn_3;
            currentState     = States.Stalling;
            aiTurn           = true;
            endTurnTrue      = false;
        }
        else
        {
            currentTurnState = TurnsState.PlayerTurn;
        }
    }
Exemplo n.º 7
0
    public void OnUnitMoved(HexScript oldHex, HexScript newHex)
    {
        // This GameObject is supposed to be a child of the hex we are
        // standing in. This ensures that we are in the correct place
        // in the hierachy
        // Our correct position when we aren't moving, is to be at
        // 0,0 local position relative to our parent.

        // TODO: Get rid of VerticalOffset and instead use a raycast to determine correct height
        // on each frame.
        move        = true;
        oldPosition = oldHex.PositionFromCamera();
        newPosition = newHex.PositionFromCamera();
    }
Exemplo n.º 8
0
 public void Move()
 {
     if (mode != Mode.Movement)
         return;
     if (selectedUnit != null && selectedHex != null)
     {
         if (selectedHex.Distance(selectedUnit.hex) <= selectedUnit.mobility)
         {
             selectedUnit.Move(selectedHex);
             selectedUnit = null;
             selectedHex = null;
             hexfieldMan.DeselectAll();
         }
         else
             selectedHex = null;
     }
 }
    public void SetHex(HexScript newHex)
    {
        HexScript oldHex = Hex;

        if (newHex != null)
        {
            newHex.RemoveUnit(this);
        }

        Hex = newHex;

        newHex.AddUnit(this);

        if (OnUnitMoved != null)
        {
            OnUnitMoved(oldHex, newHex);
        }
    }
Exemplo n.º 10
0
    /*
      IN: an hex HexScript  || OUT: bool isNeighbor
      This function takes an hex as an argument.
      When you call this function you it will return
      a boolean that indicates if the hex in the argument
      is an immediate neighbor of the hex from which the
      function is called.
    */
    public bool IsNeighbor(HexScript hex)
    {
        bool isNeighbor = false;

        if(
           (hex.coordinates.x == coordinates.x + 1 && hex.coordinates.y == coordinates.y - 1 && hex.coordinates.z == coordinates.z) ||
           (hex.coordinates.x == coordinates.x - 1 && hex.coordinates.y == coordinates.y + 1 && hex.coordinates.z == coordinates.z) ||
           (hex.coordinates.x == coordinates.x && hex.coordinates.y == coordinates.y + 1 && hex.coordinates.z == coordinates.z - 1) ||
           (hex.coordinates.x == coordinates.x && hex.coordinates.y == coordinates.y - 1 && hex.coordinates.z == coordinates.z + 1) ||
           (hex.coordinates.x == coordinates.x + 1 && hex.coordinates.y == coordinates.y && hex.coordinates.z == coordinates.z - 1) ||
           (hex.coordinates.x == coordinates.x - 1 && hex.coordinates.y == coordinates.y && hex.coordinates.z == coordinates.z + 1)
           )
        {
            isNeighbor = true;
        }

        return isNeighbor;
    }
Exemplo n.º 11
0
    public static float Distance(HexScript a, HexScript b)
    {
        int dC = Mathf.Abs(a.C - b.C);

        if (dC > a.HexMap.numColumns / 2)
        {
            dC = a.HexMap.numColumns - dC;
        }

        int dR = Mathf.Abs(a.R - b.R);

        if (dR > a.HexMap.numRows / 2)
        {
            dR = a.HexMap.numRows - dR;
        }

        return(Mathf.Max(dC, dR, Mathf.Abs(a.S - b.S)
                         ));
    }
Exemplo n.º 12
0
    /* Given a unit type and hex type, the cost of the given unit moving through the tile is returned. */
    public static int move_cost(UnitScript.Types u_type, HexScript.HexEnum h_type)
    {
        if (u_type == Types.H_Infantry || u_type == Types.A_Infantry) {
            switch (h_type) {
                case HexScript.HexEnum.plains:		return 1;
                case HexScript.HexEnum.desert:		return 1;
                case HexScript.HexEnum.mountain:	return 3;
                case HexScript.HexEnum.water:		return 9999;
            }
        } else if (u_type == Types.H_Exo || u_type == Types.A_Elite) {
            switch (h_type) {
                case HexScript.HexEnum.plains:		return 1;
                case HexScript.HexEnum.desert:		return 1;
                case HexScript.HexEnum.mountain:	return 1;
                case HexScript.HexEnum.water:		return 9999;
            }
        } else if (u_type == Types.H_Tank || u_type == Types.A_Tank) {
            switch (h_type) {
                case HexScript.HexEnum.plains:		return 1;
                case HexScript.HexEnum.desert:		return 2;
                case HexScript.HexEnum.mountain:	return 9999;
                case HexScript.HexEnum.water:		return 9999;
            }
        } else if (u_type == Types.H_Artillery || u_type == Types.A_Artillery) {
            switch (h_type) {
                case HexScript.HexEnum.plains:		return 1;
                case HexScript.HexEnum.desert:		return 3;
                case HexScript.HexEnum.mountain:	return 9999;
                case HexScript.HexEnum.water:		return 9999;
            }
        } else if (u_type == Types.H_Base || u_type == Types.A_Base) {
            switch (h_type) {
                case HexScript.HexEnum.plains:		return 1;
                case HexScript.HexEnum.desert:		return 1;
                case HexScript.HexEnum.mountain:	return 1;
                case HexScript.HexEnum.water:		return 1;
            }
        }

        // not a valid unit type
        return 9999;
    }
Exemplo n.º 13
0
    //Player selects the hex where to move the unit.
    //Check if position is valid
    public HexScript PlanMovement(UnitScript unit)
    {
        HexScript target  = new HexScript();
        int       newPosX = 0;
        int       newPosY = 0;

        //Here the apply the pos of the selected hex to the variables

        if ((newPosX - unit.posX) + (newPosY - unit.posY) < unit.movement)
        {
            target.posX = newPosX;
            target.posY = newPosY;
        }
        else
        {
            target = null;
        }

        return(target);
    }
Exemplo n.º 14
0
 // Update is called once per frame
 void Update()
 {
     //If left mouse click
     if (Input.GetMouseButtonDown(0))
     {
         //gameStateScript.GetComponent<GameStateScript>().updateGameBoard(0, turn);
         //Get mouse point
         Vector2 pos = Input.mousePosition;
         //Cast Ray
         Ray        ray = Camera.main.ScreenPointToRay(new Vector3(pos.x, pos.y, 0.0f));
         RaycastHit hit;
         //Get hit point
         if (Physics.Raycast(ray, out hit))
         {
             //change the color of the
             HexScript hex = hit.transform.gameObject.GetComponent <HexScript>();
             //Pasing by reference as increment only if we change the color
             hex.rise(ref turn);
         }
     }
 }
Exemplo n.º 15
0
    public HexScript[] GetNeighbours(GameObject hex_go, int radius, int column, int row)
    {
        List <HexScript> results = new List <HexScript>();
        HexScript        hex     = hex_go.GetComponent <HexComponentScript>().hex;

        hexes = /*MapGeneratorScript.instance.hexes*/ HexMap.hexes;

        for (int dx = -radius; dx < radius + 1; dx++)
        {
            for (int dy = Mathf.Max(-radius, -dx - radius); dy < Mathf.Min(radius + 1, -dx + radius + 1); dy++)
            {
                if (hex.R + dy >= 0 && hex.C + dx >= 0 && hex.R + dy <= /*MapGeneratorScript.instance.numRows*/
                    HexMap.numRows - 1 && hex.C + dx <= /*MapGeneratorScript.instance.numColumns*/ HexMap.numColumns - 1)
                {
                    results.Add(hexes[hex.C + dx, hex.R + dy]);
                }
            }
        }

        return(results.ToArray());
    }
    public void SelfSelectedDoTurn(HexScript[] selectedHexes)
    {
        Debug.Log("DoTurn");

        if (selfSelectedHexPath == null || selfSelectedHexPath.Count == 0)
        {
            return;
        }
        //Grab the first hex in our queue
        HexScript newHex = selfSelectedHexPath.Dequeue();


        //Move to the new Hex
        //SetHex(newHex);
        #region Debuging
        //HexScript oldHex = Hex;
        //newHex = oldHex.HexMap.GetHexAt(oldHex.C + 1, oldHex.R);
        #endregion

        SetHex(newHex);
    }
    private void DoDecidingMostSuitableMovement()
    {
        foreach (var unit in MapGeneratorScript.instance.units)
        {
            selectedPlayerUnit = unit;
        }

        GameObject tempHex_go = GameObject.Find("Hex_" + selectedPlayerUnit.Hex.C + "_" + selectedPlayerUnit.Hex.R);


        #region Attempt1_Of_AI_Movement
        //foreach (HexScript hex in hexes)
        //{
        //    if (!columns.Contains(hex.C))
        //    {
        //        columns.Add(hex.C);
        //    }

        //    if (!rows.Contains(hex.R))
        //    {
        //        rows.Add(hex.R);
        //    }
        //}

        //int closestRow = rows.OrderBy(item => Math.Abs(selectedPlayerUnit.Hex.R - item)).First();
        //int closestColumn = columns.OrderBy(item => Math.Abs(selectedPlayerUnit.Hex.C - item)).First();

        //selectedHexColumnPositioningDifference = closestColumn - selectedAIUnit.Hex.C;
        //selectedHexRowPositioningDifference = closestRow - selectedAIUnit.Hex.R;
        #endregion

        if (goodness > 35)
        {
            foreach (HexScript hex in hexes)//Potential Selectable Hexes for the Current Enemy
            {
                HexScript Found = null;
                foreach (var unit in MapGeneratorScript.instance.aiUnits) //Collection of enemy players
                {
                    if (unit.Hex == hex && unit.Hex != selectedAIUnit.Hex)
                    {
                        Found = unit.Hex;
                        Debug.LogError("The Current: R=" + unit.Hex.R + " C=" + unit.Hex.C);
                    }
                }

                if (Found == null)
                {
                    #region Row And Column Short Distance Algorithm
                    coordinatesX1 = hex.C;
                    coordinatesX2 = selectedPlayerUnit.Hex.C;

                    coordinatesY1 = hex.R;
                    coordinatesY2 = selectedPlayerUnit.Hex.R;

                    xCoordinatesDifference  = (coordinatesX2 - coordinatesX1);
                    yCoordinatesDifference  = (coordinatesY2 - coordinatesY1);
                    xCoordinatesDifference *= xCoordinatesDifference;
                    yCoordinatesDifference *= yCoordinatesDifference;

                    totalResult = (xCoordinatesDifference + yCoordinatesDifference);

                    squaredResult = Mathf.Sqrt(totalResult);

                    if (shortestSquareResult == 0)
                    {
                        shortestSquareResult = squaredResult;
                        selectedHex          = hex;
                    }

                    if (shortestSquareResult > squaredResult)
                    {
                        shortestSquareResult = squaredResult;
                        selectedHex          = hex;
                    }
                    #endregion
                }
            }
        }

        selectedHexColumnPositioningDifference = selectedHex.C - selectedAIUnit.Hex.C;
        selectedHexRowPositioningDifference    = selectedHex.R - selectedAIUnit.Hex.R;

        selectedAIUnit.DUMMY_PATHING_FUNCTION();

        movementActivated = true;
        pathBegun         = false;

        currentState = States.InitiatingPotentialMovement;


        if (goodness < 35)
        {
            defenceTurnCounter++;

            foreach (HexScript hex in hexes)
            {
                coordinatesX1 = hex.C;
                coordinatesX2 = selectedPlayerUnit.Hex.C;

                coordinatesY1 = hex.R;
                coordinatesY2 = selectedPlayerUnit.Hex.R;

                xCoordinatesDifference  = (coordinatesX2 - coordinatesX1);
                yCoordinatesDifference  = (coordinatesY2 - coordinatesY1);
                xCoordinatesDifference *= xCoordinatesDifference;
                yCoordinatesDifference *= yCoordinatesDifference;

                totalResult = (xCoordinatesDifference + yCoordinatesDifference);

                squaredResult = Mathf.Sqrt(totalResult);

                if (shortestSquareResult == 0)
                {
                    shortestSquareResult = squaredResult;
                    selectedHex          = hex;
                }

                if (shortestSquareResult < squaredResult)
                {
                    shortestSquareResult = squaredResult;
                    selectedHex          = hex;
                }
            }

            selectedHexColumnPositioningDifference = selectedHex.C - selectedAIUnit.Hex.C;
            selectedHexRowPositioningDifference    = selectedHex.R - selectedAIUnit.Hex.R;

            selectedAIUnit.DUMMY_PATHING_FUNCTION();

            movementActivated = true;
            pathBegun         = false;

            currentState = States.InitiatingPotentialMovement;
        }
    }
Exemplo n.º 18
0
    public Vector3 GetHexPosition(int c, int r)
    {
        HexScript h = GetHexAt(c, r);

        return(GetHexPosition(h));
    }
Exemplo n.º 19
0
 public void DoGarrisonBattle(HexScript hex)
 {
     List<EnemyScript> enemies = new List<EnemyScript>();
     enemies.AddRange(hex.enemiesOnHex);
     foreach(EnemyScript enemy in rampagingEnemies){
         if (!enemy.isBattling) {
             photonView.RPC("EnemyIsBattling", PhotonTargets.All, enemy.gameObject.GetPhotonView().viewID, true);
             enemies.Add(enemy);
         }
     }
     DoBattle(enemies);
 }
Exemplo n.º 20
0
    /* Determines the action to take if a hex is clicked. */
    public void hexClicked(HexScript hex)
    {
        if (!paused) {

            if (focusedUnit != null) {
                moveCurrentUnit(hex);

            // A space must be adjacent to the current Player's base and not a water tile
            } else if ( focusedCard != null && hex.getType() != HexScript.HexEnum.water &&
                        adjacent_to_base(hex) && placeUnitWithCard(focusedCard, (int)hex.position.x, (int)hex.position.y) ) {
                    // Attempt to place the unit of the focusedCard
                    focusedCard = null;
            }

        }
    }
Exemplo n.º 21
0
    // Finds the adjacent hexes to a hex and adds them to an iterable Set
    // The returns that set
    HashSet<HexScript> findAdj(HexScript hex)
    {
        if (!paused) {
            int x = (int)hex.getPosition ().x;
            int y = (int)hex.getPosition ().y;
            HashSet<HexScript> set = new HashSet<HexScript> ();
            // Note: The logic here is clunky and long, but it works and runs in O(1)! Hopefully
            //       it won't need any changes.
            if (y % 2 == 0) {
                if (y - 2 >= 0) {
                    set.Add (Map.map [x] [y - 2]);
                }
                if (y - 1 >= 0) {
                    set.Add (Map.map [x] [y - 1]);
                }
                if (y + 1 < Map.map [x].Count) {
                    set.Add (Map.map [x] [y + 1]);
                }
                if (y + 2 < Map.map [x].Count) {
                    set.Add (Map.map [x] [y + 2]);
                }
                if (x - 1 >= 0) {
                    if (y + 1 < Map.map [x].Count) {
                        set.Add (Map.map [x - 1] [y + 1]);
                    }
                    if (y - 1 >= 0) {
                        set.Add (Map.map [x - 1] [y - 1]);
                    }
                }
            }
            if (y % 2 == 1) {
                if (y - 2 >= 0) {
                    set.Add (Map.map [x] [y - 2]);
                }
                if (y - 1 >= 0) {
                    set.Add (Map.map [x] [y - 1]);
                }
                if (y + 1 < Map.map [x].Count) {
                    set.Add (Map.map [x] [y + 1]);
                }
                if (y + 2 < Map.map [x].Count) {
                    set.Add (Map.map [x] [y + 2]);
                }
                if (x + 1 < Map.map.Count) {
                    if (y + 1 < Map.map [x].Count) {
                        set.Add (Map.map [x + 1] [y + 1]);
                    }
                    if (y - 1 >= 0) {
                        set.Add (Map.map [x + 1] [y - 1]);
                    }
                }
            }

            // Remove any hexes that cannot be landed on (water/mountains)
            /*foreach (HexScript hexes in set) {
                  if(hexes.getOccupied())
                     set.Remove(hexes);
                }*/
            return set;
        } else
            return null;
    }
Exemplo n.º 22
0
 // Adds a new hex to the path
 public void addHex(HexScript hex, int cost)
 {
     path [path.Count] = hex;
     //		path.Add (hex, path.Count);
     distance += cost;
 }
Exemplo n.º 23
0
    /**
     * Returns all hexes that surround the given hex, in the map, at a given radius
     * Passing a non-positive value for the radius will simply yeild a singleton
     * containing the given hex.
     */
    private List<HexScript> findArea(HexScript center, int radius, Probability variation)
    {
        List<HexScript> to_fill = new List<HexScript>();
        to_fill.Add(center);

        // find remaining layers
        if (radius > 0) {
            List<HexScript> initial = new List<HexScript>();
            initial.Add(center);
            addNextLayer(initial, to_fill, radius, variation);
        }

        return to_fill;
    }
Exemplo n.º 24
0
 // Moves the player to a hex, if the player has not moved or attacked yet.
 public void move(HexScript hex)
 {
     if (state < 1) {
         setPosition(hex);
         state = 1;
     }
 }
Exemplo n.º 25
0
 public List<HexScript> GetHexNeighbours(HexScript hex)
 {
     return GetHexNeighbours(hex.x, hex.y, hex.z);
 }
Exemplo n.º 26
0
 public void SelectHex(HexScript hex)
 {
     SelectHex(hex.x, hex.y, hex.z);
 }
Exemplo n.º 27
0
 public void SelectHexRange(HexScript hex, int r)
 {
     for (int dx = -r; dx <= r; dx++)
     {
         for(int dy = Mathf.Max(-r, -dx-r); dy <= Mathf.Min(r, -dx+r); dy++)
         {
             int dz = -dx-dy;
             SelectHex(hex.x+dx, hex.y +dy, hex.z +dz);
         }
     }
 }
Exemplo n.º 28
0
    // Use this for initialization
    void Start()
    {
        menuAudio = GameObject.Find ("GUI Background").GetComponent<MenuAudio> ();
        scorekeeper = GameObject.Find ("Scorekeeper").GetComponent<Scorekeeper>();
        photonView.RPC("SetScore", PhotonTargets.AllBuffered, PhotonNetwork.player.ID, 0);

        overlayCanvas = transform.GetComponentsInChildren<Canvas>().First(x => x.gameObject.name == "Common Area Overlay");
        mainCanvas = transform.GetComponentsInChildren<Canvas>().First(x => x.gameObject.name == "Main Canvas");
        handCanvas = transform.GetComponentsInChildren<Canvas>().First(x => x.gameObject.name == "Hand Canvas");

        // disables our overlay for other people, so they do not see our score, move, and other values
        if(photonView.isMine)
        {
            overlayCanvas.enabled = true;
            mainCanvas.enabled = true;
            photonView.RPC("DisableCanvas", PhotonTargets.OthersBuffered, overlayCanvas.gameObject.GetPhotonView().viewID);
            photonView.RPC("DisableCanvas", PhotonTargets.OthersBuffered, mainCanvas.gameObject.GetPhotonView().viewID);
            photonView.RPC("DisableCanvas", PhotonTargets.OthersBuffered, handCanvas.gameObject.GetPhotonView().viewID);

        }

        handSizeIncreaseLevels = new int[3]{10, 25, 50};
        turnPhase = Toolbox.TurnPhase.Move;
        handCamera = GameObject.Find ("Hand Camera").GetComponent<Camera>();
        mainCamera = GameObject.Find ("Main Camera").GetComponent<Camera>();
        handCanvas.worldCamera = handCamera;
        mainCanvas.worldCamera = mainCamera;
        mainCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "View Hand Button").onClick.AddListener(() => { ArrangeHand(0); });
        mainCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "View Hand Button").onClick.AddListener(() => { Manager.ChangeCameras("Hand"); });
        handCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "Return To Game Button").onClick.AddListener(() => { Manager.ChangeCameras("Main"); });
        handCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "View Next").onClick.AddListener(() => { ArrangeHand(1); });
        handCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "View Prev").onClick.AddListener(() => { ArrangeHand(-1); });
        player = transform.GetChild (0);
        //portal hex is the seventh child of green tile zero.
        portalHex = GameObject.Find("Green Tile 0").transform.GetChild(6).gameObject;
        destroyedCards = GameObject.Find ("Destroyed Cards");
        onHex = portalHex.GetComponent<HexScript>();
        player.position = portalHex.transform.position;
        attackLabel = GetComponentInChildren<Canvas>().transform.GetComponentsInChildren<Text>().First(x => x.gameObject.name == "Attack Label").gameObject;
        blockLabel = GetComponentInChildren<Canvas>().transform.GetComponentsInChildren<Text>().First(x => x.gameObject.name == "Block Label").gameObject;
        timerLabel = GetComponentInChildren<Canvas>().transform.GetComponentsInChildren<Text>().First(x => x.gameObject.name == "Timer").gameObject;
        retreatLabel = GetComponentInChildren<Canvas>().transform.GetComponentsInChildren<Text>().First(x => x.gameObject.name == "Retreat Label").gameObject;
        usesLabel = GetComponentInChildren<Canvas>().transform.GetComponentsInChildren<Text>().First(x => x.gameObject.name == "Uses Remaining").gameObject;
        turnPhaseLabel = mainCanvas.transform.GetComponentsInChildren<Text>().First(x => x.gameObject.name == "Phase Label").gameObject;
        deckSizeLabel = GetComponentInChildren<Canvas>().transform.GetComponentsInChildren<Text>().First(x => x.gameObject.name == "Deck Size Label").gameObject;
        attackLabel.SetActive(false);
        blockLabel.SetActive(false);
        hand = handCanvas.transform.GetComponentsInChildren<Transform>().First(x => x.gameObject.name == "Hand").gameObject;
        deck = transform.GetComponentsInChildren<Transform>().First (x => x.gameObject.name == "Deed Deck").gameObject;
        energyLabel = transform.GetComponentsInChildren<Transform>().First (x => x.gameObject.name == "Energy Label").gameObject;
        handSizeLabel = transform.GetComponentsInChildren<Transform>().First (x => x.gameObject.name == "Hand Size Label").gameObject;
        armorLabel = transform.GetComponentsInChildren<Transform>().First (x => x.gameObject.name == "Armor Label").gameObject;
        fameLabel = transform.GetComponentsInChildren<Transform>().First (x => x.gameObject.name == "Fame Track").gameObject;
        discardPile = transform.GetComponentsInChildren<Transform>().First (x => x.gameObject.name == "Discard Pile").gameObject;
        InitDeckAndHand();
        ArrangeHand(0);
        endMovesButton = mainCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "End Move Button");
        endMovesButton.onClick.AddListener(() => Manager.SwitchToTurnPhase(Toolbox.TurnPhase.Action));
        endActionButton = mainCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "End Action Button");
        endActionButton.onClick.AddListener(() => Manager.SwitchToTurnPhase(Toolbox.TurnPhase.End));
        interactButton = mainCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "Interaction Button");
        interactButton.onClick.AddListener(() => PrepInteractionMenu());
        restButton = mainCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "Rest Button");
        restButton.onClick.AddListener(() => DoRest());
        provokeButton = mainCanvas.transform.GetComponentsInChildren<Button>().First(x => x.gameObject.name == "Provoke Button");
        provokeButton.onClick.AddListener(() => ProvokeRampagers());
        ShowProvokeButton(false);
        ShowRestButton(false);
        ShowInteractionButton(false);
        ShowActionButton(false);
        UpdateLabels();
    }
Exemplo n.º 29
0
 public void MoveToHex(HexScript hex)
 {
     List<HexScript> oldAdjacentRampagers = GetAdjacentRampagers();
     player.position = hex.transform.position;
     onHex = hex;
     List<HexScript> newAdjacentRampagers = GetAdjacentRampagers();
     if(oldAdjacentRampagers.Count > 0 && newAdjacentRampagers.Count > 0){
         foreach (HexScript rampager in oldAdjacentRampagers.Intersect(newAdjacentRampagers)){
             if (rampager.enemiesOnHex.Count > 0){
                 if (!rampager.enemiesOnHex.ElementAt(0).isBattling) {
                     rampagingEnemies.Add(rampager.enemiesOnHex.ElementAt(0));
                 }
             }
         }
     }
     if(!isRetreating){
         if (hex.hexType == Toolbox.HexType.Garrison){
             //do garrison battle
             DoGarrisonBattle(hex);
         } else {
             if (rampagingEnemies.Count > 0){
                 foreach(EnemyScript enemy in rampagingEnemies){
                     photonView.RPC("EnemyIsBattling", PhotonTargets.All, enemy.gameObject.GetPhotonView().viewID, true);
                 }
                 DoBattle(rampagingEnemies);
             }
         }
     } else {
         isRetreating = false;
         Manager.SwitchToTurnPhase(Toolbox.TurnPhase.End);
     }
     rampagingEnemies.Clear();
 }
Exemplo n.º 30
0
 public int Distance(HexScript hex)
 {
     return (Mathf.Abs(hex.x - x) + Mathf.Abs(hex.y - y) + Mathf.Abs(hex.z - z)) / 2;
 }
Exemplo n.º 31
0
 public void ApplyMovement(UnitScript unit, HexScript hex)
 {
 }
Exemplo n.º 32
0
 // Moves the player to a hex, if the player has not moved yet.
 public void move(HexScript hex)
 {
     if (!hasMoved) {
         position = hex.getPosition ();
         transform.position = new Vector3 (
             hex.transform.position.x,
             hex.transform.position.y,
             hex.transform.position.z - 10f);
         hasMoved = true;
     }
 }
Exemplo n.º 33
0
    /* Finds a hex at a given offset from a point relative to the given hex in the map.
     *
     * If opp_x is set to true, then the point's x position will be equal to the complement
     * of the given hex's x position relative to the map's width bounds: likewise for opp_y,
     * the point's y position, and the map's height bounds.
     *
     * If the given hex is null, then null is returned. */
    public HexScript hex_at_offset_from(HexScript hex, bool opp_x, bool opp_y, int offset)
    {
        if (hex == null) { return null; }

        var pos_x = (int)hex.position.x;
        var pos_y = (int)hex.position.y;
        // flip x position
        if (opp_x) {
            pos_x = width - pos_x - 1;
        }
        // flip y position
        if (opp_y) {
            pos_y = height - pos_y - 1;
        }

        List<HexScript> area = findArea(map[pos_x][pos_y], offset, null);
        // Find a random hex at a radius of the given offset away from the given hex
        int hex_idx = UnityEngine.Random.Range(0, area.Count - 1);

        return area[hex_idx];
    }
Exemplo n.º 34
0
 // Sets the position of the unit to a hex.
 // NOTE: This works much better than the other set position method,
 // and should be used whenever possible.
 public void setPosition(HexScript hex)
 {
     position = hex.getPosition ();
     transform.position = new Vector3 (
         hex.transform.position.x,
         hex.transform.position.y,
         -0.5f);
 }
Exemplo n.º 35
0
    // Set's a unit to be the current unit in focus
    public void selectFocus(UnitScript unit)
    {
        if (!paused) {

            focusedUnit = unit;
            updateHexes();

            if (unit != null && unit.getState() < 1) {
                List<HexScript> mapRow = Map.map [(int)unit.getPosition ().x];
                HexScript curHex = mapRow [(int)unit.getPosition ().y];
                // Reinitialize the hexSet to an empty set
                hexSet = new HashSet<HexScript>();
                // Populate the hexSet with moveable hexes
                hexSet = Map.unit_move_range(focusedUnit, true);
                //findMovement (focusedUnit.getMovement (), (Map.map [(int)focusedUnit.getPosition ().x]) [(int)focusedUnit.getPosition ().y], false);
                // For each moveable hex, indicate that it is moveable
                /*foreach (HexScript moveable in hexSet) {
                    moveable.setFocus (true);
                }*/
                focusedHex = curHex;
                curHex.setFocus(true);
            }
        }
    }
Exemplo n.º 36
0
    /* Determines if the given hex is adjacent to current's player's base */
    private bool adjacent_to_base(HexScript hex)
    {
        if (!paused) {
            HexScript baseHex = Map.map[ (int)((getTurn() == 1) ? p1Base : p2Base).getPosition().x ][ (int)((getTurn() == 1) ? p1Base : p2Base).getPosition().y];
            // Determine if the hex is adjacent to the base
            for (int adj = 0; adj < 6; ++adj) {
                HexScript adjHex = Map.adjacentHexTo(baseHex, adj);
                // adjHex is the desired hex
                if (hex != null && MapManager.same_position(adjHex, hex)) { return true; }
            }
        }

        return false;
    }
Exemplo n.º 37
0
    /* Moves the current focused unit to the given hex, if possible. */
    public void moveCurrentUnit(HexScript hex)
    {
        if (!paused) {
            // Makes sure there is currently a focused unit
            if (focusedUnit != null) {
                // If the hex is in the set of moveable hexes, move to it
                if (hexSet.Contains (hex)) {
                    // cover original vision in fog
                    HexScript prev_hex = Map.map [(int)focusedUnit.getPosition().x] [(int)focusedUnit.getPosition().y];
                    prev_hex.setOccupied(0);
                    //Map.update_fog_cover(prev_hex, focusedUnit.getMovement(), true);

                    focusedUnit.move(hex);
                    hex.setOccupied(focusedUnit.getPlayer());
                    // reveal new vision area
                    if (Map.FOG_OF_WAR) { Map.update_field_of_view(focusedUnit, false); }
                }

                focusedUnit = null;
                updateHexes();
            }
        }
    }
Exemplo n.º 38
0
 public void Deselect()
 {
     selectedUnit = null;
     selectedHex = null;
     hexfieldMan.DeselectAll();
 }
Exemplo n.º 39
0
    public void CreateHexBoard(int radius)
    {
        if (radius <= 0)
        {
            return;
        }

        int prevRadius = 0;         //hexBoard == null _WHEN_ prevRadius <= 0

        if (tileBoard != null)
        {
            prevRadius = (tileBoard.GetLength(0) - 1) / 2 + 1;
        }

        if (radius < prevRadius)
        {
            for (int i = 0; i < prevRadius; i++)
            {
                Hex nextHex = AxialHex.GetDirection(4) * i;
                for (int dir = 0; dir < 6; dir++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (i >= radius)
                        {
                            //Destroy
                            if (debugMode)
                            {
                                Debug.Log(nextHex.ToArrayPos(prevRadius).x + "," + nextHex.ToArrayPos(prevRadius).y + " is destroyed");
                            }
                            Destroy(tileBoard[nextHex.ToArrayPos(prevRadius).y, nextHex.ToArrayPos(prevRadius).x].gameObject);

                            nextHex = nextHex.GetNeighbour(dir);
                        }
                    }
                }
            }
        }

        HexScript[,] newHexBoard = new HexScript[(radius - 1) * 2 + 1, (radius - 1) * 2 + 1];

        //Center piece
        if (0 < prevRadius)
        {
            //Migrate
            newHexBoard[0, 0] = (HexScript)tileBoard[0, 0];
            if (debugMode)
            {
                Debug.Log("hexBoard[0,0] can be taken from old array[0,0]");
            }
        }
        else
        {
            //Instantiate
            newHexBoard[0, 0] = Instantiate(tilePrefab[(int)tileType]).GetComponent <HexScript>();
            newHexBoard[0, 0].transform.parent = hexBoardParent;
            if (debugMode)
            {
                Debug.Log("hexBoard[0,0] is instantiated");
            }
        }

        //Set Scale
        newHexBoard[0, 0].transform.localScale = Vector3.one * tileSize;
        newHexBoard[0, 0].position             = new Hex(0, 0);

        newHexBoard[0, 0].isChecked    = false;
        newHexBoard[0, 0].isObstacle   = false;
        newHexBoard[0, 0].movementCost = Mathf.Infinity;
        newHexBoard[0, 0].parentTile   = null;
        newHexBoard[0, 0].state        = TileState.Empty;

        //Ring search
        for (int i = 1; i < radius; i++)
        {
            Hex nextHex = AxialHex.GetDirection(4) * i;
            for (int dir = 0; dir < 6; dir++)
            {
                for (int j = 0; j < i; j++)
                {
                    Hex arrayPos    = nextHex.ToArrayPos(radius);
                    Hex oldArrayPos = nextHex.ToArrayPos(prevRadius);

                    if (i < prevRadius)
                    {
                        //Migrate
                        newHexBoard[arrayPos.y, arrayPos.x] = (HexScript)tileBoard[oldArrayPos.y, oldArrayPos.x];
                        if (debugMode)
                        {
                            Debug.Log("hexBoard[" + arrayPos.y + "," + arrayPos.x + "] can be taken from old array[" + oldArrayPos.y + "," + oldArrayPos.x + "]");
                        }
                    }
                    else
                    {
                        //Instantiate
                        newHexBoard[arrayPos.y, arrayPos.x] = Instantiate(tilePrefab[(int)tileType]).GetComponent <HexScript>();
                        newHexBoard[arrayPos.y, arrayPos.x].transform.parent = hexBoardParent;
                        //newHexBoard[nextHex.ToArrayPos(radius).y, nextHex.ToArrayPos(radius).x].position = new AxialHex(nextHex.y, nextHex.x);
                        if (debugMode)
                        {
                            Debug.Log("hexBoard[" + arrayPos.y + "," + arrayPos.x + "] is instantiated");
                        }
                    }

                    //Set Scale
                    newHexBoard[arrayPos.y, arrayPos.x].transform.localScale = Vector3.one * tileSize;
                    newHexBoard[arrayPos.y, arrayPos.x].position             = new Hex(nextHex.x, nextHex.y);

                    newHexBoard[arrayPos.y, arrayPos.x].isChecked    = false;
                    newHexBoard[arrayPos.y, arrayPos.x].isObstacle   = false;
                    newHexBoard[arrayPos.y, arrayPos.x].movementCost = Mathf.Infinity;
                    newHexBoard[arrayPos.y, arrayPos.x].parentTile   = null;
                    newHexBoard[arrayPos.y, arrayPos.x].state        = TileState.Empty;

                    nextHex = nextHex.GetNeighbour(dir);
                }
            }
        }

        //Save new board
        tileBoard = newHexBoard;
        return;
    }
Exemplo n.º 40
0
 public void SelectHex(HexScript hex)
 {
     selectedHex = hex;
     // maybe draw pretty path to this tile?
 }
Exemplo n.º 41
0
 /* Finds all hexes within the given radius, centered at the center hex. */
 public List<HexScript> findArea(HexScript center, int radius)
 {
     return findArea(center, radius, null);
 }
Exemplo n.º 42
0
 /*
 IN: HexScript || OUT: int distance
 this function will return the number
 of hex between the hex in the argument
 and the hex from which the function is called.
 The number is an integer.
 */
 public int hexDistance(HexScript hex)
 {
     return (int)((Mathf.Abs(coordinates.x - hex.coordinates.x) + Mathf.Abs(coordinates.y - hex.coordinates.y) + Mathf.Abs(coordinates.z - hex.coordinates.z))/2);
 }
 public int MovementCostToEnterHex(HexScript hex)
 {
     //TODO: Override base movement cost based on our movement plus tile type
     return(hex.BaseMovementCost());
 }
Exemplo n.º 44
0
 public virtual void initialSetup(HexScript hexInfo)
 {
     _teamcolor = GameState.Instance.CurrentPlayer.getColor();
     _homeHex   = hexInfo.gameObject;
     hexInfo.setOccupant(gameObject);
 }
    public float AggregateTurnsToEnterHex(HexScript hex, float turnsToDate)
    {
        {
            // The issue at hand is that if you are trying to enter a tile
            // with a movement cost greater than your current remaining movement
            // points, this will either result in a cheaper-than expected
            // turn cost (Civ5) or a more-expensive-than expected turn cost (Civ6)

            if (Movement > 0)
            {
                float baseTurnsToEnterHex = MovementCostToEnterHex(hex) / Movement; // Example: Entering a forest is "1" turn

                if (baseTurnsToEnterHex < 0)
                {
                    // Impassible terrain
                    Debug.Log("Impassible terrain at:" + hex.ToString());
                    return(-99999);
                }


                if (baseTurnsToEnterHex > 1)
                {
                    // Even if something costs 3 to enter and we have a max move of 2,
                    // you can always enter it using a full turn of movement.
                    return(baseTurnsToEnterHex);
                }


                float turnsRemaining = MovementRemaining / Movement;        // Example, if we are at 1/2 move, then we have .5 turns left

                float turnsToDateWhole    = Mathf.Floor(turnsToDate);       // Example: 4.33 becomes 4
                float turnsToDateFraction = turnsToDate - turnsToDateWhole; // Example: 4.33 becomes 0.33

                if ((turnsToDateFraction > 0 && turnsToDateFraction < 0.01f) || turnsToDateFraction > 0.99f)
                {
                    Debug.LogError("Looks like we've got floating-point drift: " + turnsToDate);

                    if (turnsToDateFraction < 0.01f)
                    {
                        turnsToDateFraction = 0;
                    }

                    if (turnsToDateFraction > 0.99f)
                    {
                        turnsToDateWhole   += 1;
                        turnsToDateFraction = 0;
                    }
                }

                float turnsUsedAfterThismove = turnsToDateFraction + baseTurnsToEnterHex; // Example 0.33 + 1

                if (turnsUsedAfterThismove > 1)
                {
                    // We have hit the situation where we don't actually have enough movement to complete this move.
                    // What do we do?

                    if (MOVEMENT_RULES_LIKE_CIV6)
                    {
                        // We aren't ALLOWED to enter the tile this move. That means, we have to...

                        if (turnsToDateFraction == 0)
                        {
                            // We have full movement, but this isn't enough to enter the tile
                            // EXAMPLE: We have a max move of 2 but the tile costs 3 to enter.
                            // We are good to go.
                        }
                        else
                        {
                            // We are NOT on a fresh turn -- therefore we need to
                            // sit idle for the remainder of this turn.
                            turnsToDateWhole   += 1;
                            turnsToDateFraction = 0;
                        }

                        // So now we know for a fact that we are starting the move into difficult terrain
                        // on a fresh turn.
                        turnsUsedAfterThismove = baseTurnsToEnterHex;
                    }
                    else
                    {
                        // Civ5-style movement state that we can always enter a tile, even if we don't
                        // have enough movement left.
                        turnsUsedAfterThismove = 1;
                    }
                }

                // turnsUsedAfterThismove is now some value from 0..1. (this includes
                // the factional part of moves from previous turns).


                // Do we return the number of turns THIS move is going to take?
                // I say no, this an an "aggregate" function, so return the total
                // turn cost of turnsToDate + turns for this move.

                return(turnsToDateWhole + turnsUsedAfterThismove);
            }
            else
            {
                return(1);
            }
        }
        #endregion
    }
Exemplo n.º 46
0
    public void GenerateMap()
    {
        string holderName = "Generator Map";

        if (transform.Find(holderName))
        {
            DestroyImmediate(transform.Find(holderName).gameObject);
        }

        Transform mapHolder = new GameObject(holderName).transform;

        mapHolder.parent = transform;

        //tileRotations = Random.Range(-90, 90);

        hexes = new HexScript[numColumns, numRows];
        hexToGameObjectMap = new Dictionary <HexScript, GameObject>();

        for (int column = 0; column < numColumns; column++)
        {
            for (int row = 0; row < numRows; row++)
            {
                HexScript h = new HexScript(this, column, row);
                hexes[column, row] = h;

                h.movementCost = 1;

                GameObject hex_go = Instantiate(hexPrefab, h.Position(), Quaternion.identity, this.transform);

                if (h == GetHexAt(3, 4) || h == GetHexAt(4, 3) || h == GetHexAt(5, 2) || h == GetHexAt(15, 16) || h == GetHexAt(14, 17) || h == GetHexAt(13, 18) || h == GetHexAt(12, 19))
                {
                    h.movementCost = -99;
                    hex_go.GetComponentInChildren <MeshRenderer>().material.color = Color.black;
                }
                if (h == GetHexAt(9, 10))
                {
                    h.movementCost = 2;
                    hex_go.GetComponentInChildren <MeshRenderer>().material.color = Color.black;
                }
                if (h == GetHexAt(6, 9) || h == GetHexAt(7, 9) || h == GetHexAt(8, 9) || h == GetHexAt(9, 9) || h == GetHexAt(10, 9))
                {
                    h.movementCost = 3;
                    hex_go.GetComponentInChildren <MeshRenderer>().material.color = Color.black;
                }
                else if (h == GetHexAt(2, 5))
                {
                    h.movementCost = 10;
                    hex_go.GetComponentInChildren <MeshRenderer>().material.color = Color.green;
                }

                hexToGameObjectMap.Add(h, hex_go);

                hex_go.GetComponent <HexComponentScript>().hex = new HexScript(this, column, row);
                hex_go.GetComponent <HexComponentScript>().map = this;

                //hex_go.GetComponentInChildren<TextMesh>().text = string.Format("{0},{1}\n\t{2}", column, row, h.movementCost);

                hex_go.transform.localScale = Vector3.one * (1 - outlinePercent);

                //Rotation of the tiles around the Y axis of their creation
                var rotationVector = hex_go.transform.rotation.eulerAngles;
                rotationVector.y = tileRotation;
                hex_go.transform.localRotation = Quaternion.Euler(rotationVector);

                //Gives the game object a suitable name for debugging
                hex_go.name = "Hex_" + column + "_" + row;

                //Used to create a cleaner hierachy, thus parenting this hex.
                hex_go.transform.SetParent(mapHolder);

                hex_go.isStatic = true;
                #region My Attempt
                //float xPos = column * xOffset;

                ////Are we on a odd row
                //if (row % 2 == 1)
                //{
                //    xPos += xOffset / 2f;
                //}

                //Vector3 tileposition = new Vector3(xPos, 0, row * zOffest);
                //GameObject hex_go = (GameObject)Instantiate(hexPrefab, tileposition, Quaternion.identity);

                //hex_go.transform.localScale = Vector3.one * (1 - outlinePercent);

                ////Rotation of the tiles around the Y axis of their creation
                //var rotationVector = hex_go.transform.rotation.eulerAngles;
                //rotationVector.y = tileRotation;
                //hex_go.transform.localRotation = Quaternion.Euler(rotationVector);

                ////Gives the game object a suitable name for debugging
                //hex_go.name = "Hex_" + column + "_" + row;

                ////Give the Hex awareness of it's place in the array
                //hex_go.GetComponent<HexScript>().x = column;
                //hex_go.GetComponent<HexScript>().y = row;
                //hex_go.GetComponent<HexScript>().tilesWidthMax = width;
                //hex_go.GetComponent<HexScript>().tilesHeightMax = height;

                ////Used to create a cleaner hierachy, thus parenting this hex.
                //hex_go.transform.SetParent(mapHolder);

                //hex_go.isStatic = true;
                #endregion
            }
        }

        GameObject mapGenerator        = GameObject.Find(holderName);
        var        pivotRotationVector = mapGenerator.transform.rotation.eulerAngles;
        pivotRotationVector.y = pivotRotation;
        mapGenerator.transform.localRotation = Quaternion.Euler(pivotRotationVector);
    }
Exemplo n.º 47
0
 // Recursively finds the hexes that a unit can move to given
 // a starting hex and a movement distance
 // TODO: Account for terrain
 // DONE: Account for Zone of Control
 // TODO: Write an implementation of the A* algorithm to find the best path
 void findMovement(int movement, HexScript location, bool moved)
 {
     if (!paused) {
         bool stopped = false;
         bool adjToEnemy = false;
         HashSet<HexScript> adjSet = findAdj (location);
         hexSet.Add (location);
         if (movement == 0) {
         } else {
             foreach (HexScript adjHex in adjSet) {
                 foreach (UnitScript enemy in units) {
                     if (enemy.getPlayer () != turn) {
                         if (moved && enemy.getPosition () == adjHex.getPosition ()) {
                             stopped = true;
                             break;
                         }
                         if (!moved && enemy.getPosition () == adjHex.getPosition ()) {
                             adjToEnemy = true;
                             break;
                         }
                     }
                 }
             }
             if (adjToEnemy) {
                 foreach (HexScript adjHex in adjSet) {
                     bool adj = false;
                     foreach (UnitScript enemy in units) {
                         if (enemy.getPlayer () != turn) {
                             if ((enemy.getPosition () == adjHex.getPosition ())) {
                                 adj = true;
                             }
                         }
                     }
                     if (!adj) {
                         int cost = UnitScript.move_cost(focusedUnit.unitType(), adjHex.getType());
                         //focusedUnit.terrainMap.TryGetValue (adjHex.getType (), out cost);
                         if (movement - cost >= 0) {
                             findMovement (movement - cost, adjHex, true);
                         }
                     }
                 }
             } else if (!stopped) {
                 foreach (HexScript adjHex in adjSet) {
                     int cost = UnitScript.move_cost(focusedUnit.unitType(), adjHex.getType());
                     //focusedUnit.terrainMap.TryGetValue (adjHex.getType (), out cost);
                     if (movement - cost >= 0) {
                         findMovement (movement - cost, adjHex, true);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 48
0
 public Vector3 GetHexPosition(HexScript Hex)
 {
     return(Hex.PositionFromCamera(Camera.main.transform.position, numRows, numColumns));
 }
Exemplo n.º 49
0
 /* Verifies that the two hexes are at the same position in the map */
 public static bool same_position(HexScript h1, HexScript h2)
 {
     return h1 != null && h2 != null && (h1.position.x == h2.position.x) && (h1.position.y == h2.position.y);
 }