Beispiel #1
0
 public LogisticalEffects(FactionArmies forces)
 {
     FoodNeeds    = forces.Armies.SelectMany(item => item.Squadrons).Sum(item => item.FoodCost);
     SumFood      = forces.Armies.Sum(item => item.Logistics.Food);
     SumMedical   = forces.Armies.Sum(item => item.Logistics.Medical);
     SumEquipment = forces.Armies.Sum(item => item.Logistics.Equipment);
 }
Beispiel #2
0
 private IEnumerable <BattleStateForces> GetInitialBattleArmies(FactionArmies forces, BattleSidePreparation preBattle, BattleSite site)
 {
     foreach (Army army in forces.Armies)
     {
         yield return(GetInitialArmyInBattle(army, preBattle, site));
     }
 }
Beispiel #3
0
    public War(ProvinceState location, FactionArmies attackers, FactionArmies defenders)
    {
        Location = location.Identifier;
        IEnumerable <BattleSite> sites = GetSites(location);

        Progression = GetProgression(attackers, defenders, sites);
        Winner      = GetWinner(attackers.Faction, defenders.Faction);
    }
Beispiel #4
0
    public CampaignProgression GetNext()
    {
        BattleState lastBattleState = Battle.States.Last();
        IEnumerable <BattleSite> newRemainingSites = RemainingSites.Skip(1).ToArray();
        FactionArmies            newAttackers      = ToFactionArmies(lastBattleState.Attackers, Attackers.Faction);
        FactionArmies            newDefenders      = ToFactionArmies(lastBattleState.Defenders, Defenders.Faction);

        return(new CampaignProgression(newAttackers, newDefenders, newRemainingSites));
    }
Beispiel #5
0
        private IEnumerable <FactionArmies> GetAttackersForProvince(Province defender, IEnumerable <AttackMove> invaders, WarForcesTable forcesTable)
        {
            IEnumerable <IEnumerable <AttackMove> > invadersByFaction = GetInvadersByFaction(invaders).ToArray();

            foreach (IEnumerable <AttackMove> invadingFaction in invadersByFaction)
            {
                FactionArmies retItem = forcesTable.GetForcesFor(invadingFaction);
                yield return(retItem);
            }
        }
Beispiel #6
0
 public CampaignProgression(FactionArmies attackers, FactionArmies defenders, IEnumerable <BattleSite> sites)
 {
     Attackers      = attackers;
     Defenders      = defenders;
     RemainingSites = sites;
     CurrentSite    = sites.First();
     PreBattle      = new BattlePreparation(Attackers, Defenders, CurrentSite);
     Battle         = GetBattle();
     Outcome        = Battle.Outcome;
 }
Beispiel #7
0
 private IEnumerable <FinalWarsSetup> GetFinalWars(GameState state, Dictionary <Province, List <AttackMove> > byTargetTable, WarForcesTable forcesTable)
 {
     foreach (KeyValuePair <Province, List <AttackMove> > item in byTargetTable)
     {
         FactionArmies defender = forcesTable.GetForcesFor(item.Key);
         IEnumerable <FactionArmies> invaders = GetAttackersForProvince(item.Key, item.Value, forcesTable).ToArray();
         ProvinceState  locationState         = state.GetProvinceState(item.Key);
         FinalWarsSetup retItem = new FinalWarsSetup(locationState, defender, invaders);
         yield return(retItem);
     }
 }
Beispiel #8
0
        private static IEnumerable <War> GetWars(ProvinceState location, FactionArmies defender, IEnumerable <FactionArmies> invaders)
        {
            List <War> ret = new List <War>();

            foreach (FactionArmies invader in invaders)
            {
                War war = new War(location, invader, defender);
                ret.Add(war);
            }
            return(ret);
        }
Beispiel #9
0
        private ReadOnlyDictionary <AttackMove, FactionArmies> GetAttackerForces(GameState state, IEnumerable <AttackMove> attackMoves)
        {
            Dictionary <AttackMove, FactionArmies> ret = new Dictionary <AttackMove, FactionArmies>();

            foreach (AttackMove move in attackMoves)
            {
                int           attacksByFaction = attackMoves.Count(item => item.Faction == move.Faction);
                FactionArmies forces           = CalculateAttackingForces(move, attacksByFaction, state);
                ret.Add(move, forces);
            }
            return(new ReadOnlyDictionary <AttackMove, FactionArmies>(ret));
        }
Beispiel #10
0
    public BattlePreparation(FactionArmies attacker, FactionArmies defender, BattleSite site)
    {
        ScoutingEffects   attackerScout     = new ScoutingEffects(attacker, defender);
        ScoutingEffects   defenderScout     = new ScoutingEffects(defender, attacker);
        SpyingEffects     attackerSpies     = new SpyingEffects(attacker);
        SpyingEffects     defenderSpies     = new SpyingEffects(defender);
        RaidingEffects    raiding           = new RaidingEffects(attacker, site);
        LogisticalEffects attackerLogistics = new LogisticalEffects(attacker);
        LogisticalEffects defenderLogistics = new LogisticalEffects(defender);

        Attacker = new BattleSidePreparation(attackerScout, raiding, attackerLogistics, attackerSpies);
        Defender = new BattleSidePreparation(defenderScout, RaidingEffects.Defender, defenderLogistics, defenderSpies);
    }
Beispiel #11
0
        private ReadOnlyDictionary <Province, FactionArmies> GetDefenderForces(GameState state, IEnumerable <AttackMove> attacks)
        {
            Dictionary <Province, FactionArmies> ret = new Dictionary <Province, FactionArmies>();
            HashSet <Province> targets = new HashSet <Province>(attacks.Select(item => item.TargetProvince));

            foreach (Province target in targets)
            {
                ProvinceState provinceOwner     = state.GetProvinceState(target);
                int           attacksByDefender = attacks.Count(item => item.Faction == provinceOwner.Owner);
                FactionArmies forces            = CalculateDefendingForces(provinceOwner, attacksByDefender, state);
                ret.Add(target, forces);
            }
            return(new ReadOnlyDictionary <Province, FactionArmies>(ret));
        }
Beispiel #12
0
    private ReadOnlyCollection <CampaignProgression> GetProgression(FactionArmies attackers, FactionArmies defenders, IEnumerable <BattleSite> sites)
    {
        List <CampaignProgression> ret  = new List <CampaignProgression>();
        CampaignProgression        loop = new CampaignProgression(attackers, defenders, sites);

        foreach (BattleSite site in sites)
        {
            ret.Add(loop);
            if (loop.Outcome != WarOutcome.AttackersWon)
            {
                break;
            }
            loop = loop.GetNext();
        }
        return(ret.AsReadOnly());
    }
Beispiel #13
0
 public RaidingEffects(FactionArmies attacker, BattleSite site)
 {
     RaidingSum     = attacker.Armies.SelectMany(item => item.Squadrons).Sum(item => item.Raiding);
     LogisticsDrain = Math.Max(0, RaidingSum - site.InitialDefense);
 }
Beispiel #14
0
 public ScoutingEffects(FactionArmies self, FactionArmies other)
 {
     ScoutsSum  = self.Armies.Sum(item => item.Scouts.ScoutingEffectiveness);
     Scouted    = other.Armies.SelectMany(item => item.Squadrons).Sum(item => GetScoutingVisibility(item));
     ScoutBonus = ScoutsSum * Scouted;
 }
Beispiel #15
0
 public SpyingEffects(FactionArmies forces)
 {
     SpySum   = forces.Armies.Sum(item => item.Spies.LeaderDrain);
     Sabotage = forces.Armies.Sum(item => item.Spies.SupplySabotage);
 }
Beispiel #16
0
        }                                   // Null if multiple invaders beat the defender

        public FinalWarsSetup(ProvinceState location, FactionArmies defender, IEnumerable <FactionArmies> invaders)
        {
            Wars        = GetWars(location, defender, invaders);
            FinalWinner = GetFinalWindner(defender.Faction, Wars);
        }
Beispiel #17
0
        public FactionArmies GetForcesFor(IEnumerable <AttackMove> convergingAttacks)
        {
            IEnumerable <FactionArmies> forces = convergingAttacks.Select(item => _attackerForces[item]);

            return(FactionArmies.CombineForces(forces, convergingAttacks.First().Faction));
        }