Exemplo n.º 1
0
    private bool AttackEnemy(Empire empire, EmpireController empireController)
    {
        DiplomacyController diplomacy = empireController.GetDiplomacyController();

        foreach (Army army in empire.GetArmies().FindAll(c => c.GetArmyType() == Army.ArmyType.Offensive &&
                                                         c.GetArmyStatus() == Army.ArmyStatus.Idle || c.GetArmyStatus() == Army.ArmyStatus.Training))
        {
            SolarSystem        system  = army.GetComponent <MovementController>().GetSystemLocation();
            List <SolarSystem> systems = system.GetNearbySystems();
            foreach (SolarSystem nearbySystem in systems)
            {
                if (nearbySystem.GetEmpire() && nearbySystem.GetEmpire() != empire && diplomacy.GetDiplomacy(nearbySystem.GetEmpire()).relationship == Relationship.War && Navigation.RouteAvailable(system, nearbySystem, empire))
                {
                    List <Army> combinedOffence = new List <Army>();
                    float       offence         = 0;
                    foreach (Army systemArmy in system.GetArmies().FindAll(c => c.GetArmyType() == Army.ArmyType.Offensive &&
                                                                           c.GetArmyStatus() == Army.ArmyStatus.Idle || c.GetArmyStatus() == Army.ArmyStatus.Training))
                    {
                        combinedOffence.Add(systemArmy);
                        offence += systemArmy.GetArmyStrength();
                    }

                    if (offence > nearbySystem.GetDefence())
                    {
                        CreateFleet(combinedOffence, nearbySystem, system, empire);
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
 private void CheckState(Empire empire, EmpireController empireController, ref State currentState)
 {
     if (!currentState)
     {
         currentState = (config as DefaultConfig).GetGrow();
     }
     if (empire.IsAlive())
     {
         // TODO Simple code to set off war
         DiplomacyController diplomacy = empireController.GetDiplomacyController();
         if (empireController.GetEnemyBorderSystems().Count > 0)
         {
             foreach (SolarSystem system in empireController.GetEnemyBorderSystems())
             {
                 if (diplomacy.GetDiplomacy(system.GetEmpire()).relationship != Relationship.War)
                 {
                     diplomacy.DeclareWar(empire, system.GetEmpire());
                 }
             }
             if (currentState.GetStateName() != "Attack")
             {
                 currentState = (config as DefaultConfig).GetAttack();
             }
         }
         else
         {
             CheckGrowOrBuildUp(empire, empireController, ref currentState);
         }
     }
 }
Exemplo n.º 3
0
    public override void RunBuildBehaviour(Empire empire, EmpireController empireController)
    {
        bool status = true;

        while (status == true)
        {
            status = Build(empire);
        }
    }
Exemplo n.º 4
0
    protected void DefendBorders(Empire empire, EmpireController empireController)
    {
        List <SolarSystem> enemyBorderSystems = empireController.GetEmpireEnemyBorderSystems();
        List <Army>        defensiveArmies    = empire.GetArmies().FindAll(c => c.GetArmyType() == Army.ArmyType.Defensive);

        List <Army> availableArmies;

        availableArmies = empire.GetArmies().FindAll(c => c.GetArmyType() == Army.ArmyType.Defensive &&
                                                     c.GetArmyStatus() != Army.ArmyStatus.Training &&
                                                     c.GetArmyStatus() != Army.ArmyStatus.Attacking);

        foreach (Army army in availableArmies)
        {
            RouteDefensiveArmy(army, enemyBorderSystems, defensiveArmies, empire);
        }
    }
 private void CheckGrowOrBuildUp(Empire empire, EmpireController empireController, ref State currentState)
 {
     if (currentState == (config as DefaultConfig).GetGrow())
     {
         if (empire.HasOrBuildingColonyShip())
         {
             currentState = (config as DefaultConfig).GetBuildUp();
         }
     }
     else if (currentState == (config as DefaultConfig).GetBuildUp())
     {
         if (empireController.GetNeutralBorderSystems().Count > 0 && empire.CheckSystemHealth() && currentState.GetIsInDefaultBuildMode())
         {
             currentState = (config as DefaultConfig).GetGrow();
         }
     }
 }
Exemplo n.º 6
0
    IEnumerator Start()
    {
        Instance = this;

        Localization();
        _timerRequestSilverBank = Time.time;
        _controller             = new EmpireController(this);
        houseDataSelected       = null;

        rectMap             = empireMap.GetComponent <RectTransform>();
        listBuidingFinished = new List <UIEmpireBuildingFinished>();

        InitLand();

        yield return(StartCoroutine(empireMap.Init()));

        StartCoroutine(InitOldBuiding());
    }
Exemplo n.º 7
0
    public override void RunArmyBehaviour(Empire empire, EmpireController empireController)
    {
        DefendBorders(empire, empireController);

        // Keep going until no army has an immediate target
        while (AttackEnemy(empire, empireController) == true)
        {
        }

        foreach (Army army in empire.GetArmies().FindAll(c => c.GetArmyType() == Army.ArmyType.Offensive &&
                                                         c.GetArmyStatus() != Army.ArmyStatus.Training &&
                                                         c.GetArmyStatus() != Army.ArmyStatus.Attacking))
        {
            army.MoveToNearestEnemy();
        }


        return;
    }
Exemplo n.º 8
0
    protected void ColonisePlanets(Empire empire, EmpireController empireController)
    {
        int border = 0;

        foreach (ColonyShip colonyShip in empire.GetColonyShips())
        {
            if (empireController.GetNeutralBorderSystems().Count == 0)
            {
                colonyShip.MoveTo(empire.GetSystems()[0]);
            }
            else
            {
                if (border >= empireController.GetNeutralBorderSystems().Count)
                {
                    border = 0;
                }
                colonyShip.MoveTo(empireController.GetNeutralBorderSystems().ElementAt(border));
                border++;
            }
        }
    }
Exemplo n.º 9
0
 abstract public void RunBuildBehaviour(Empire empire, EmpireController empireController);
Exemplo n.º 10
0
 public override void MakeDecisions(Empire empire, EmpireController empireController, ref State currentState)
 {
     CheckState(empire, empireController, ref currentState);
     currentState.RunArmyBehaviour(empire, empireController);
     currentState.RunBuildBehaviour(empire, empireController);
 }
 public abstract void MakeDecisions(Empire empire, EmpireController empireController, ref State currentState);
Exemplo n.º 12
0
 public override void RunArmyBehaviour(Empire empire, EmpireController empireController)
 {
     DefendBorders(empire, empireController);
     ColonisePlanets(empire, empireController);
     return;
 }
Exemplo n.º 13
0
 public void LeadEmpire(EmpireController empireController)
 {
     personality.MakeDecisions(empire, empireController, ref currentState);
 }
Exemplo n.º 14
0
 public void MakeDecisions(Empire empire, EmpireController empireController, ref State currentState)
 {
     behaviour.MakeDecisions(empire, empireController, ref currentState);
 }