コード例 #1
0
    /// <summary>
    /// moves the cam to the target zone and opens the battle resolution panel
    /// or does autocalc resolution... or both
    /// </summary>
    /// <param name="targetZone"></param>
    public IEnumerator ResolveBattle(Zone targetZone)
    {
        Faction          defenderFaction = GameController.GetFactionByID(targetZone.ownerFaction);
        List <Commander> atkerCmders     = new List <Commander>();

        GameInfo curData = GameController.CurGameData;

        foreach (Commander cmder in GameController.GetCommandersInZone(targetZone))
        {
            if (cmder.ownerFaction != defenderFaction.ID &&
                defenderFaction.GetStandingWith(cmder.ownerFaction) != GameFactionRelations.FactionStanding.ally)
            {
                atkerCmders.Add(cmder);
            }
        }

        battleData.FillInfo(atkerCmders, defenderFaction, targetZone);

        //if the "always autocalc AI battles" option is active,
        //we must check if the player's troops aren't participating
        //before forcing autocalc resolution
        if (curData.alwaysAutocalcAiBattles)
        {
            foreach (TroopContainer tc in battleData.attackerSideInfo.ourContainers)
            {
                if (GameController.GetFactionByID(tc.ownerFaction).isPlayer)
                {
                    yield return(FocusOnBattle(targetZone));

                    battlePanel.OpenWithFilledInfo(battleData);
                    yield break;
                }
            }

            foreach (TroopContainer tc in battleData.defenderSideInfo.ourContainers)
            {
                if (GameController.GetFactionByID(tc.ownerFaction).isPlayer)
                {
                    yield return(FocusOnBattle(targetZone));

                    battlePanel.OpenWithFilledInfo(battleData);
                    yield break;
                }
            }


            if (curData.showBattleResolutionPanelForAutocalcAiBattles)
            {
                yield return(FocusOnBattle(targetZone));

                battlePanel.OpenWithFilledInfo(battleData);
            }
            else
            {
                //a little waiting to avoid freezing and allowing to pause between battles
                yield return(WaitWhileNoOverlays(0.01f));

                battleData.AutocalcResolution();
                OnBattleResolved();
            }
            yield break;
        }
        else
        {
            yield return(FocusOnBattle(targetZone));

            battlePanel.OpenWithFilledInfo(battleData);
        }
    }