public tileStruct TileHas(Vector3Int pos)
    {
        tileStruct tileHas = new tileStruct();

        if (land.HasTile(pos))
        {
            tileHas.land = true;
        }
        if (obstacles.HasTile(pos))
        {
            tileHas.obstacle = true;
        }
        foreach (GameObject town in GameObject.FindGameObjectsWithTag("Town"))
        {
            if (land.WorldToCell(town.transform.position) == pos)
            {
                tileHas.town = town.GetComponent <Town>();
                break;
            }
        }
        foreach (GameObject squad in GameObject.FindGameObjectsWithTag("Unit"))
        {
            if (land.WorldToCell(squad.transform.position) == pos)
            {
                tileHas.squad = squad.GetComponent <Squad>();
                break;
            }
        }
        return(tileHas);
    }
Example #2
0
    public tileStruct TileHas(Vector3Int pos)
    {
        tileStruct tileHas = new tileStruct();

        if (land.HasTile(pos))
        {
            tileHas.land = true;
        }
        if (obstacles.HasTile(pos))
        {
            tileHas.obstacle = true;
        }
        foreach (GameObject unit in GameObject.FindGameObjectsWithTag("Unit"))
        {
            if (land.WorldToCell(unit.transform.position) == pos &&
                unit.GetComponent <Unit>().currentState == unitState.dead)
            {
                tileHas.dead = true;
                break;
            }
            if (land.WorldToCell(unit.transform.position) == pos)
            {
                tileHas.army = unit.GetComponent <Unit>().army;
                break;
            }
        }
        return(tileHas);
    }
    public void endMove(Vector3Int destTile)
    {
        if (moving == null)
        {
            //print("moving == null | "+ currentTurn +" | "+ roundState);
            return;
        }

        if (withinRange.Contains(destTile))
        {
            tileStruct tileHas = TileHas(destTile);
            if (tileHas.squad != null && tileHas.squad.sqKingdom != currentTurn)
            {
                print("Attack!");
                // do the actual stuff here...
                if (currentTurn == red)
                {
                    GameState.GS.currentTurn = blue;
                    GameState.GS.events.Add(new GameEvent(red, moving.GetComponent <Squad>().ID, blue, tileHas.squad.ID, eventType.attacks));
                }
                else
                {
                    GameState.GS.currentTurn = red;
                    GameState.GS.events.Add(new GameEvent(blue, moving.GetComponent <Squad>().ID, red, tileHas.squad.ID, eventType.attacks));
                }
                moving.GetComponent <Squad>().SetPosition(destTile);
                SceneManager.LoadScene("Tactical", LoadSceneMode.Single);
                return;
            }
            moving.GetComponent <Squad>().SetPosition(destTile);

            if (tileHas.town != null && tileHas.town.townKingdom != currentTurn)
            {
                tileHas.town.Flip();
                currentTurn.townIDs.Add(tileHas.town.townID);
                if (currentTurn == red)
                {
                    blue.townIDs.Remove(tileHas.town.townID);
                }
                else
                {
                    red.townIDs.Remove(tileHas.town.townID);
                }
                print("Town taken!");
            }
            NextTurn();
        }
        clearMove();
    }
    public List <Vector3Int> updateQueue(List <Vector3Int> queue)
    {
        List <Vector3Int> queue2 = new List <Vector3Int>();

        while (queue.Count > 0)
        {
            Vector3Int check = queue[0];
            int        x = check.x, y = check.y, z = check.z;
            queue.Remove(check);
            int        row       = Mathf.Abs(check.y % 2);
            Vector3Int left      = new Vector3Int(x - 1, y, z);
            Vector3Int right     = new Vector3Int(x + 1, y, z);
            Vector3Int upLeft    = new Vector3Int(x - 1 + row, y + 1, z);
            Vector3Int upRight   = new Vector3Int(x + row, y + 1, z);
            Vector3Int downLeft  = new Vector3Int(x - 1 + row, y - 1, z);
            Vector3Int downRight = new Vector3Int(x + row, y - 1, z);
            foreach (Vector3Int dir in new Vector3Int[] {
                left, right, upLeft, upRight, downLeft, downRight
            })
            {
                tileStruct tileHas = TileHas(dir);
                if (tileHas.obstacle || !tileHas.land)
                {
                    continue;
                }
                if (!withinRange.Contains(dir) && !excludeRange.Contains(dir) &&
                    !(tileHas.squad && tileHas.squad.kingdom == currentTurn))
                {
                    withinRange.Add(dir);
                }
                queue2.Add(dir);
            }
        }
        queue = queue2;
        return(queue);
    }