Exemplo n.º 1
0
    // TODO hacky af
    IEnumerator NextTurnCoroutine()
    {
        turnTransition = true;
        nextTurnText.SetActive(true);
        yield return(new WaitForSeconds(0.5f));

        // Make money
        money += CalcIncome();
        UpdateMoneyText();

        // Units
        doneWithUnits = false;
        StartCoroutine(hexGrid.ExecuteUnitCommands());
        while (!doneWithUnits)
        {
            yield return(null);
        }

        // Fire
        hexGrid.AgeFire();
        hexGrid.SpreadFire();

        // Update unit command paths after fire has spread
        hexGrid.UpdateUnitCommands();

        UpdateIncomeText(CalcIncome());

        // Check if all fires are out
        int  tileWidth         = hexGrid.tiles.GetLength(0);
        int  tileHeight        = hexGrid.tiles.GetLength(1);
        int  cityFirelineTiles = 0;
        bool fireGone          = true;

        for (int i = 0; i < tileWidth; i++)
        {
            for (int j = 0; j < tileHeight; j++)
            {
                TileInfo tileInfo = hexGrid.tiles[i, j];
                if (tileInfo.fire != null)
                {
                    fireGone = false;
                    break;
                }
                if (tileInfo.type == TileType.CITY_FIRELINE)
                {
                    cityFirelineTiles++;
                }
            }
        }
        if (fireGone)
        {
            // display statistics
            playerTurn     = false;
            turnTransition = true;
            endPopup.SetActive(true);
            Text statValues = endPopup.transform.Find("Panel/StatValues")
                              .gameObject.GetComponent <Text>();

            const int HOMES_PER_TILE   = 147;
            int       homesBurnt       = hexGrid.burntCities * HOMES_PER_TILE;
            int       homesDestroyed   = cityFirelineTiles * HOMES_PER_TILE;
            const int ACRES_PER_TILE   = 1920;
            int       forestsBurnt     = hexGrid.burntForests * ACRES_PER_TILE;
            int       forestsDestroyed = hexGrid.destroyedForests * ACRES_PER_TILE;
            const int PEOPLE_PER_UNIT  = 13;
            int       casualties       = hexGrid.casualties * PEOPLE_PER_UNIT;
            //int moneySpent = moneySpent;
            statValues.text = homesBurnt + "\n\n"
                              + homesDestroyed + "\n\n\n"
                              + forestsBurnt + "\n\n"
                              + forestsDestroyed + "\n\n\n"
                              + casualties + "\n\n"
                              + "$ " + moneySpent;
        }

        nextTurnText.SetActive(false);
        playerTurn = true;
        StartPlayerTurn();
        turnTransition = false;
    }