Example #1
0
        public SiteConquered(List<Property> properties, World world)
            : base(properties, world)
        {
            Initialize();
            foreach (Property property in properties)
                switch (property.Name)
                {
                    case "ordinal": Ordinal = Convert.ToInt32(property.Value); break;
                    case "war_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;
                    case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
                    case "attacking_enid": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;
                    case "defending_enid": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }

            

            if (Collection.OfType<PlunderedSite>().Any()) ConquerType = SiteConqueredType.Pillaging;
            else if (Collection.OfType<DestroyedSite>().Any()) ConquerType = SiteConqueredType.Destruction;
            else if (Collection.OfType<NewSiteLeader>().Any() || Collection.OfType<SiteTakenOver>().Any()) ConquerType = SiteConqueredType.Conquest;
            else ConquerType = SiteConqueredType.Unknown;

            if (ConquerType == SiteConqueredType.Pillaging) Notable = false;

            Site.Warfare.Add(this);
            if (ParentCollection != null)
            {
                (ParentCollection as War).DeathCount += Collection.OfType<HFDied>().Count();

                if (Attacker == (ParentCollection as War).Attacker) 
                    (ParentCollection as War).AttackerVictories.Add(this);
                else 
                    (ParentCollection as War).DefenderVictories.Add(this);
            }

        }
Example #2
0
        public BeastAttack(List <Property> properties, World world)
            : base(properties, world)
        {
            Initialize();

            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "ordinal": Ordinal = Convert.ToInt32(property.Value); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

                case "parent_eventcol": ParentEventCol = world.GetEventCollection(Convert.ToInt32(property.Value)); break;

                case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;

                case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "defending_enid": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }

            Site.BeastAttacks.Add(this);

            //--------Attacking Beast is calculated after parsing event collections in ParseXML()
            //--------So that it can also look at eventsList from duel sub collections to calculate the Beast

            //-------Fill in some missing event details with details from collection
            //-------Filled in after parsing event collections in ParseXML()
        }
Example #3
0
 public Duel(List<Property> properties, World world)
     : base(properties, world)
 {
     foreach (Property property in properties)
         switch (property.Name)
         {
             case "ordinal": Ordinal = String.Intern(property.Value); break;
             case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;
             case "parent_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;
             case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;
             case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;
             case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
             case "attacking_hfid": Attacker = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;
             case "defending_hfid": Defender = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;
         }
     //foreach (WorldEvent collectionEvent in Collection) this.AddEvent(collectionEvent);
     if (ParentCollection != null && ParentCollection.GetType() == typeof(Battle))
         foreach (HFDied death in Collection.OfType<HFDied>())
         {
             Battle battle = ParentCollection as Battle;
             if (battle.NotableAttackers.Contains(death.HistoricalFigure))
             {
                 battle.AttackerDeathCount++;
                 battle.Attackers.Single(squad => squad.Race == death.HistoricalFigure.Race).Deaths++;
                 (battle.ParentCollection as War).AttackerDeathCount++;
             }
             else if (battle.NotableDefenders.Contains(death.HistoricalFigure))
             {
                 battle.DefenderDeathCount++;
                 battle.Defenders.Single(squad => squad.Race == death.HistoricalFigure.Race).Deaths++;
                 (battle.ParentCollection as War).DefenderDeathCount++;
             }
             (ParentCollection.ParentCollection as War).DeathCount++;
         }
 }
Example #4
0
        public Abduction(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "ordinal": Ordinal = String.Intern(property.Value); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

                case "parent_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;

                case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;

                case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "attacking_enid": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "defending_enid": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }
        }
Example #5
0
        public Theft(List<Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
                switch (property.Name)
                {
                    case "ordinal": Ordinal = String.Intern(property.Value); break;
                    case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;
                    case "parent_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;
                    case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;
                    case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;
                    case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
                    case "attacking_enid": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;
                    case "defending_enid": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }

            foreach (ItemStolen theft in Collection.OfType<ItemStolen>())
            {
                theft.Site = Site;
                Site.AddEvent(theft);
                Site.Events = Site.Events.OrderBy(ev => ev.ID).ToList();
                if (Attacker.SiteHistory.Count == 1)
                {
                    theft.ReturnSite = Attacker.SiteHistory.First().Site;
                    theft.ReturnSite.AddEvent(theft);
                    theft.ReturnSite.Events = theft.ReturnSite.Events.OrderBy(ev => ev.ID).ToList();
                }

            }
        }
Example #6
0
        public BeastAttack(List<Property> properties, World world)
            : base(properties, world)
        {
            Initialize();

            foreach (Property property in properties)
                switch (property.Name)
                {
                    case "ordinal": Ordinal = Convert.ToInt32(property.Value); break;
                    case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;
                    case "parent_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;
                    case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;
                    case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;
                    case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
                    case "defending_enid": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }

            Site.BeastAttacks.Add(this);

            //--------Attacking Beast is calculated after parsing event collections in ParseXML()
            //--------So that it can also look at eventsList from duel sub collections to calculate the Beast

            //-------Fill in some missing event details with details from collection
            //-------Filled in after parsing event collections in ParseXML()
        }
Example #7
0
        public SiteConquered(List <Property> properties, World world)
            : base(properties, world)
        {
            Initialize();
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "ordinal": Ordinal = Convert.ToInt32(property.Value); break;

                case "war_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "attacking_enid": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "defending_enid": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }



            if (Collection.OfType <PlunderedSite>().Any())
            {
                ConquerType = SiteConqueredType.Pillaging;
            }
            else if (Collection.OfType <DestroyedSite>().Any())
            {
                ConquerType = SiteConqueredType.Destruction;
            }
            else if (Collection.OfType <NewSiteLeader>().Any() || Collection.OfType <SiteTakenOver>().Any())
            {
                ConquerType = SiteConqueredType.Conquest;
            }
            else
            {
                ConquerType = SiteConqueredType.Unknown;
            }

            if (ConquerType == SiteConqueredType.Pillaging)
            {
                Notable = false;
            }

            Site.Warfare.Add(this);
            if (ParentCollection != null)
            {
                (ParentCollection as War).DeathCount += Collection.OfType <HFDied>().Count();

                if (Attacker == (ParentCollection as War).Attacker)
                {
                    (ParentCollection as War).AttackerVictories.Add(this);
                }
                else
                {
                    (ParentCollection as War).DefenderVictories.Add(this);
                }
            }
        }
Example #8
0
        public Duel(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "ordinal": Ordinal = String.Intern(property.Value); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

                case "parent_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;

                case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;

                case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "attacking_hfid": Attacker = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "defending_hfid": Defender = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;
                }
            }
            //foreach (WorldEvent collectionEvent in Collection) this.AddEvent(collectionEvent);
            if (ParentCollection != null && ParentCollection.GetType() == typeof(Battle))
            {
                foreach (HFDied death in Collection.OfType <HFDied>())
                {
                    Battle battle    = ParentCollection as Battle;
                    War    parentWar = (battle.ParentCollection as War);
                    if (battle.NotableAttackers.Contains(death.HistoricalFigure))
                    {
                        battle.AttackerDeathCount++;
                        battle.Attackers.Single(squad => squad.Race == death.HistoricalFigure.Race).Deaths++;

                        if (parentWar != null)
                        {
                            parentWar.AttackerDeathCount++;
                        }
                    }
                    else if (battle.NotableDefenders.Contains(death.HistoricalFigure))
                    {
                        battle.DefenderDeathCount++;
                        battle.Defenders.Single(squad => squad.Race == death.HistoricalFigure.Race).Deaths++;
                        if (parentWar != null)
                        {
                            parentWar.DefenderDeathCount++;
                        }
                    }

                    if (parentWar != null)
                    {
                        (ParentCollection.ParentCollection as War).DeathCount++;
                    }
                }
            }
        }
Example #9
0
 public Abduction(List<Property> properties, World world)
     : base(properties, world)
 {
     foreach (Property property in properties)
         switch (property.Name)
         {
             case "ordinal": Ordinal = String.Intern(property.Value); break;
             case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;
             case "parent_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;
             case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;
             case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;
             case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
             case "attacking_enid": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;
             case "defending_enid": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;
         }
 }
Example #10
0
        private void ProcessCollections()
        {
            World.Wars         = World.EventCollections.OfType <War>().ToList();
            World.Battles      = World.EventCollections.OfType <Battle>().ToList();
            World.BeastAttacks = World.EventCollections.OfType <BeastAttack>().ToList();

            foreach (EventCollection eventCollection in World.EventCollections)
            {
                //Sub Event Collections aren't created until after the main collection
                //So only IDs are stored in the main collection until here now that all collections have been created
                //and can now be added to their Parent collection
                foreach (int collectionID in eventCollection.CollectionIDs)
                {
                    eventCollection.Collections.Add(World.GetEventCollection(collectionID));
                }
            }

            //Attempt at calculating beast historical figure for beast attacks.
            //Find beast by looking at eventsList and fill in some event properties from the beast attacks's properties
            //Calculated here so it can look in Duel collections contained in beast attacks
            foreach (BeastAttack beastAttack in World.EventCollections.OfType <BeastAttack>())
            {
                //Find Beast by looking at fights, Beast always engages the first fight in a Beast Attack?
                if (beastAttack.GetSubEvents().OfType <HFSimpleBattleEvent>().Any())
                {
                    beastAttack.Beast = beastAttack.GetSubEvents().OfType <HFSimpleBattleEvent>().First().HistoricalFigure1;
                    if (beastAttack.Beast.BeastAttacks == null)
                    {
                        beastAttack.Beast.BeastAttacks = new List <BeastAttack>();
                    }
                    beastAttack.Beast.BeastAttacks.Add(beastAttack);
                }
                if (beastAttack.GetSubEvents().OfType <HFDied>().Count() > 1)
                {
                    var slayers = beastAttack.GetSubEvents().OfType <HFDied>().GroupBy(death => death.Slayer).Select(hf => new { HF = hf.Key, Count = hf.Count() });
                    if (slayers.Count(slayer => slayer.Count > 1) == 1)
                    {
                        HistoricalFigure beast = slayers.Single(slayer => slayer.Count > 1).HF;
                        beastAttack.Beast = beast;
                    }
                }

                //Fill in some various event info from collections.

                int insertIndex;
                foreach (ItemStolen theft in beastAttack.Collection.OfType <ItemStolen>())
                {
                    if (theft.Site == null)
                    {
                        theft.Site = beastAttack.Site;
                    }
                    else
                    {
                        beastAttack.Site = theft.Site;
                    }
                    if (theft.Thief == null)
                    {
                        theft.Thief = beastAttack.Beast;
                    }
                    else
                    {
                        beastAttack.Beast = theft.Thief;
                    }

                    if (beastAttack.Site != null)
                    {
                        insertIndex = beastAttack.Site.Events.BinarySearch(theft);
                        if (insertIndex < 0)
                        {
                            beastAttack.Site.Events.Add(theft);
                        }
                    }
                    if (beastAttack.Beast != null)
                    {
                        insertIndex = beastAttack.Beast.Events.BinarySearch(theft);
                        if (insertIndex < 0)
                        {
                            beastAttack.Beast.Events.Add(theft);
                        }
                    }
                }
                foreach (CreatureDevoured devoured in beastAttack.Collection.OfType <CreatureDevoured>())
                {
                    if (devoured.Eater == null)
                    {
                        devoured.Eater = beastAttack.Beast;
                    }
                    else
                    {
                        beastAttack.Beast = devoured.Eater;
                    }
                    if (beastAttack.Beast != null)
                    {
                        insertIndex = beastAttack.Beast.Events.BinarySearch(devoured);
                        if (insertIndex < 0)
                        {
                            beastAttack.Beast.Events.Add(devoured);
                        }
                    }
                }
            }

            //Assign a Conquering Event its corresponding battle
            //Battle = first Battle prior to the conquering?
            foreach (SiteConquered conquer in World.EventCollections.OfType <SiteConquered>())
            {
                for (int i = conquer.ID - 1; i >= 0; i--)
                {
                    EventCollection collection = World.GetEventCollection(i);
                    if (collection == null)
                    {
                        continue;
                    }
                    if (collection.GetType() == typeof(Battle))
                    {
                        conquer.Battle            = collection as Battle;
                        conquer.Battle.Conquering = conquer;
                        if (conquer.Battle.Defender == null && conquer.Defender != null)
                        {
                            conquer.Battle.Defender = conquer.Defender;
                        }
                        break;
                    }
                }
            }
        }
Example #11
0
        public Battle(List<Property> properties, World world)
            : base(properties, world)
        {

            Initialize();

            List<string> attackerSquadRace, defenderSquadRace;
            List<int> attackerSquadEntityPopulation, attackerSquadNumbers, attackerSquadDeaths, attackerSquadSite,
                         defenderSquadEntityPopulation, defenderSquadNumbers, defenderSquadDeaths, defenderSquadSite;
            NotableAttackers = new List<HistoricalFigure>(); NotableDefenders = new List<HistoricalFigure>();
            AttackerSquads = new List<Squad>(); DefenderSquads = new List<Squad>();
            attackerSquadRace = new List<string>(); attackerSquadEntityPopulation = new List<int>(); attackerSquadNumbers = new List<int>(); attackerSquadDeaths = new List<int>();
            attackerSquadSite = new List<int>();
            defenderSquadRace = new List<string>(); defenderSquadEntityPopulation = new List<int>(); defenderSquadNumbers = new List<int>(); defenderSquadDeaths = new List<int>();
            defenderSquadSite = new List<int>();
            Attackers = new List<Squad>();
            Defenders = new List<Squad>();
            NonCombatants = new List<HistoricalFigure>();
            foreach (Property property in properties)
                switch (property.Name)
                {
                    case "outcome": switch (property.Value)
                        {
                            case "attacker won": Outcome = BattleOutcome.AttackerWon; break;
                            case "defender won": Outcome = BattleOutcome.DefenderWon; break;
                            default: Outcome = BattleOutcome.Unknown; world.ParsingErrors.Report("Unknown Battle Outcome: " + property.Value); break;
                        } break;
                    case "name": Name = Formatting.InitCaps(property.Value); break;
                    case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;
                    case "war_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;
                    case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;
                    case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;
                    case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
                    case "attacking_hfid": NotableAttackers.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;
                    case "defending_hfid": NotableDefenders.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;
                    case "attacking_squad_race": attackerSquadRace.Add(Formatting.FormatRace(property.Value)); break;
                    case "attacking_squad_entity_pop": attackerSquadEntityPopulation.Add(Convert.ToInt32(property.Value)); break;
                    case "attacking_squad_number": attackerSquadNumbers.Add(Convert.ToInt32(property.Value)); break;
                    case "attacking_squad_deaths": attackerSquadDeaths.Add(Convert.ToInt32(property.Value)); break;
                    case "attacking_squad_site": attackerSquadSite.Add(Convert.ToInt32(property.Value)); break;
                    case "defending_squad_race": defenderSquadRace.Add(Formatting.FormatRace(property.Value)); break;
                    case "defending_squad_entity_pop": defenderSquadEntityPopulation.Add(Convert.ToInt32(property.Value)); break;
                    case "defending_squad_number": defenderSquadNumbers.Add(Convert.ToInt32(property.Value)); break;
                    case "defending_squad_deaths": defenderSquadDeaths.Add(Convert.ToInt32(property.Value)); break;
                    case "defending_squad_site": defenderSquadSite.Add(Convert.ToInt32(property.Value)); break;
                    case "noncom_hfid": NonCombatants.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;
                }

            if (Collection.OfType<AttackedSite>().Count() > 0)
            {
                Attacker = Collection.OfType<AttackedSite>().First().Attacker;
                Defender = Collection.OfType<AttackedSite>().First().Defender;
            }
            else if (Collection.OfType<FieldBattle>().Count() > 0)
            {
                Attacker = Collection.OfType<FieldBattle>().First().Attacker;
                Defender = Collection.OfType<FieldBattle>().First().Defender;
            }

            foreach (HistoricalFigure attacker in NotableAttackers) attacker.Battles.Add(this);
            foreach (HistoricalFigure defender in NotableDefenders) defender.Battles.Add(this);
            foreach (HistoricalFigure nonCombatant in NonCombatants) nonCombatant.Battles.Add(this);

            for (int i = 0; i < attackerSquadRace.Count; i++)
                AttackerSquads.Add(new Squad(attackerSquadRace[i], attackerSquadNumbers[i], attackerSquadDeaths[i], attackerSquadSite[i], attackerSquadEntityPopulation[i]));
            for (int i = 0; i < defenderSquadRace.Count; i++)
                DefenderSquads.Add(new Squad(defenderSquadRace[i], defenderSquadNumbers[i], defenderSquadDeaths[i], defenderSquadSite[i], defenderSquadEntityPopulation[i]));

            var groupedAttackerSquads = from squad in AttackerSquads
                                        group squad by squad.Race into squadRace
                                        select new { Race = squadRace.Key, Count = squadRace.Sum(squad => squad.Numbers), Deaths = squadRace.Sum(squad => squad.Deaths) };
            foreach (var squad in groupedAttackerSquads)
                Attackers.Add(new Squad(squad.Race, squad.Count + NotableAttackers.Count(attacker => attacker.Race == squad.Race), squad.Deaths + Collection.OfType<HFDied>().Count(death => death.HistoricalFigure.Race == squad.Race && NotableAttackers.Contains(death.HistoricalFigure)), -1, -1));
            foreach (var attacker in NotableAttackers.Where(hf => Attackers.Count(squad => squad.Race == hf.Race) == 0).GroupBy(hf => hf.Race).Select(race => new { Race = race.Key, Count = race.Count() }))
            {
                Attackers.Add(new Squad(attacker.Race, attacker.Count, Collection.OfType<HFDied>().Count(death => NotableAttackers.Contains(death.HistoricalFigure) && death.HistoricalFigure.Race == attacker.Race), -1, -1));
            }
            AttackersAsList = new List<string>();
            foreach (Squad squad in Attackers)
                for (int i = 0; i < squad.Numbers; i++)
                    AttackersAsList.Add(squad.Race);



            var groupedDefenderSquads = from squad in DefenderSquads
                                        group squad by squad.Race into squadRace
                                        select new { Race = squadRace.Key, Count = squadRace.Sum(squad => squad.Numbers), Deaths = squadRace.Sum(squad => squad.Deaths) };
            foreach (var squad in groupedDefenderSquads)
                Defenders.Add(new Squad(squad.Race, squad.Count + NotableDefenders.Count(defender => defender.Race == squad.Race), squad.Deaths + Collection.OfType<HFDied>().Count(death => death.HistoricalFigure.Race == squad.Race && NotableDefenders.Contains(death.HistoricalFigure)), -1, -1));
            foreach (var defender in NotableDefenders.Where(hf => Defenders.Count(squad => squad.Race == hf.Race) == 0).GroupBy(hf => hf.Race).Select(race => new { Race = race.Key, Count = race.Count() }))
            {
                Defenders.Add(new Squad(defender.Race, defender.Count, Collection.OfType<HFDied>().Count(death => NotableDefenders.Contains(death.HistoricalFigure) && death.HistoricalFigure.Race == defender.Race), -1, -1));
            }
            DefendersAsList = new List<string>();
            foreach (Squad squad in Defenders)
                for (int i = 0; i < squad.Numbers; i++)
                    DefendersAsList.Add(squad.Race);

            Deaths = new List<string>();
            foreach (Squad squad in Attackers.Concat(Defenders))
                for (int i = 0; i < squad.Deaths; i++)
                    Deaths.Add(squad.Race);

            AttackerDeathCount = Attackers.Sum(attacker => attacker.Deaths);
            DefenderDeathCount = Defenders.Sum(defender => defender.Deaths);

            if (Outcome == BattleOutcome.AttackerWon) Victor = Attacker;
            else if (Outcome == BattleOutcome.DefenderWon) Victor = Defender;

            War parentWar = ParentCollection as War;
            if (parentWar != null)
            {
                if (parentWar.Attacker == Attacker)
                {
                    parentWar.AttackerDeathCount += AttackerDeathCount;
                    parentWar.DefenderDeathCount += DefenderDeathCount;
                }
                else
                {
                    parentWar.AttackerDeathCount += DefenderDeathCount;
                    parentWar.DefenderDeathCount += AttackerDeathCount;
                }
                parentWar.DeathCount += attackerSquadDeaths.Sum() + defenderSquadDeaths.Sum() + Collection.OfType<HFDied>().Count();

                if (Attacker == parentWar.Attacker && Victor == Attacker) parentWar.AttackerVictories.Add(this);
                else parentWar.DefenderVictories.Add(this);
            }

            if (Site != null) Site.Warfare.Add(this);
            if (Region != null) Region.Battles.Add(this);
            if (UndergroundRegion != null) UndergroundRegion.Battles.Add(this);

            if ((attackerSquadDeaths.Sum() + defenderSquadDeaths.Sum() + Collection.OfType<HFDied>().Count()) == 0)
                Notable = false;
            if ((attackerSquadNumbers.Sum() + NotableAttackers.Count) > ((defenderSquadNumbers.Sum() + NotableDefenders.Count) * 10) //NotableDefenders outnumbered 10 to 1
                && Victor == Attacker
                && AttackerDeathCount < ((NotableAttackers.Count + attackerSquadNumbers.Sum()) * 0.1)) //NotableAttackers lossses < 10%
                Notable = false;
        }
Example #12
0
        public Battle(List<Property> properties, World world)
            : base(properties, world)
        {
            Initialize();

            List<string> attackerSquadRace, defenderSquadRace;
            List<int> attackerSquadEntityPopulation, attackerSquadNumbers, attackerSquadDeaths, attackerSquadSite,
                         defenderSquadEntityPopulation, defenderSquadNumbers, defenderSquadDeaths, defenderSquadSite;
            NotableAttackers = new List<HistoricalFigure>(); NotableDefenders = new List<HistoricalFigure>();
            AttackerSquads = new List<Squad>(); DefenderSquads = new List<Squad>();
            attackerSquadRace = new List<string>(); attackerSquadEntityPopulation = new List<int>(); attackerSquadNumbers = new List<int>(); attackerSquadDeaths = new List<int>();
            attackerSquadSite = new List<int>();
            defenderSquadRace = new List<string>(); defenderSquadEntityPopulation = new List<int>(); defenderSquadNumbers = new List<int>(); defenderSquadDeaths = new List<int>();
            defenderSquadSite = new List<int>();
            Attackers = new List<Squad>();
            Defenders = new List<Squad>();
            NonCombatants = new List<HistoricalFigure>();
            foreach (Property property in properties)
                switch (property.Name)
                {
                    case "outcome": switch (property.Value)
                        {
                            case "attacker won": Outcome = BattleOutcome.AttackerWon; break;
                            case "defender won": Outcome = BattleOutcome.DefenderWon; break;
                            default: Outcome = BattleOutcome.Unknown; world.ParsingErrors.Report("Unknown Battle Outcome: " + property.Value); break;
                        } break;
                    case "name": Name = Formatting.InitCaps(property.Value); break;
                    case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;
                    case "war_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break;
                    case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;
                    case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;
                    case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
                    case "attacking_hfid": NotableAttackers.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;
                    case "defending_hfid": NotableDefenders.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;
                    case "attacking_squad_race": attackerSquadRace.Add(Formatting.FormatRace(property.Value)); break;
                    case "attacking_squad_entity_pop": attackerSquadEntityPopulation.Add(Convert.ToInt32(property.Value)); break;
                    case "attacking_squad_number": attackerSquadNumbers.Add(Convert.ToInt32(property.Value)); break;
                    case "attacking_squad_deaths": attackerSquadDeaths.Add(Convert.ToInt32(property.Value)); break;
                    case "attacking_squad_site": attackerSquadSite.Add(Convert.ToInt32(property.Value)); break;
                    case "defending_squad_race": defenderSquadRace.Add(Formatting.FormatRace(property.Value)); break;
                    case "defending_squad_entity_pop": defenderSquadEntityPopulation.Add(Convert.ToInt32(property.Value)); break;
                    case "defending_squad_number": defenderSquadNumbers.Add(Convert.ToInt32(property.Value)); break;
                    case "defending_squad_deaths": defenderSquadDeaths.Add(Convert.ToInt32(property.Value)); break;
                    case "defending_squad_site": defenderSquadSite.Add(Convert.ToInt32(property.Value)); break;
                    case "noncom_hfid": NonCombatants.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;
                }

            if (Collection.OfType<AttackedSite>().Count() > 0)
            {
                Attacker = Collection.OfType<AttackedSite>().First().Attacker;
                Defender = Collection.OfType<AttackedSite>().First().Defender;
            }
            else if (Collection.OfType<FieldBattle>().Count() > 0)
            {
                Attacker = Collection.OfType<FieldBattle>().First().Attacker;
                Defender = Collection.OfType<FieldBattle>().First().Defender;
            }

            foreach (HistoricalFigure attacker in NotableAttackers) attacker.Battles.Add(this);
            foreach (HistoricalFigure defender in NotableDefenders) defender.Battles.Add(this);
            foreach (HistoricalFigure nonCombatant in NonCombatants) nonCombatant.Battles.Add(this);

            for (int i = 0; i < attackerSquadRace.Count; i++)
                AttackerSquads.Add(new Squad(attackerSquadRace[i], attackerSquadNumbers[i], attackerSquadDeaths[i], attackerSquadSite[i], attackerSquadEntityPopulation[i]));
            for (int i = 0; i < defenderSquadRace.Count; i++)
                DefenderSquads.Add(new Squad(defenderSquadRace[i], defenderSquadNumbers[i], defenderSquadDeaths[i], defenderSquadSite[i], defenderSquadEntityPopulation[i]));

            var groupedAttackerSquads = from squad in AttackerSquads
                                        group squad by squad.Race into squadRace
                                        select new { Race = squadRace.Key, Count = squadRace.Sum(squad => squad.Numbers), Deaths = squadRace.Sum(squad => squad.Deaths) };
            foreach (var squad in groupedAttackerSquads)
                Attackers.Add(new Squad(squad.Race, squad.Count + NotableAttackers.Count(attacker => attacker.Race == squad.Race), squad.Deaths + Collection.OfType<HFDied>().Count(death => death.HistoricalFigure.Race == squad.Race && NotableAttackers.Contains(death.HistoricalFigure)), -1, -1));
            foreach (var attacker in NotableAttackers.Where(hf => Attackers.Count(squad => squad.Race == hf.Race) == 0).GroupBy(hf => hf.Race).Select(race => new { Race = race.Key, Count = race.Count() }))
            {
                Attackers.Add(new Squad(attacker.Race, attacker.Count, Collection.OfType<HFDied>().Count(death => NotableAttackers.Contains(death.HistoricalFigure) && death.HistoricalFigure.Race == attacker.Race), -1, -1));
            }
            AttackersAsList = new List<string>();
            foreach (Squad squad in Attackers)
                for (int i = 0; i < squad.Numbers; i++)
                    AttackersAsList.Add(squad.Race);

            var groupedDefenderSquads = from squad in DefenderSquads
                                        group squad by squad.Race into squadRace
                                        select new { Race = squadRace.Key, Count = squadRace.Sum(squad => squad.Numbers), Deaths = squadRace.Sum(squad => squad.Deaths) };
            foreach (var squad in groupedDefenderSquads)
                Defenders.Add(new Squad(squad.Race, squad.Count + NotableDefenders.Count(defender => defender.Race == squad.Race), squad.Deaths + Collection.OfType<HFDied>().Count(death => death.HistoricalFigure.Race == squad.Race && NotableDefenders.Contains(death.HistoricalFigure)), -1, -1));
            foreach (var defender in NotableDefenders.Where(hf => Defenders.Count(squad => squad.Race == hf.Race) == 0).GroupBy(hf => hf.Race).Select(race => new { Race = race.Key, Count = race.Count() }))
            {
                Defenders.Add(new Squad(defender.Race, defender.Count, Collection.OfType<HFDied>().Count(death => NotableDefenders.Contains(death.HistoricalFigure) && death.HistoricalFigure.Race == defender.Race), -1, -1));
            }
            DefendersAsList = new List<string>();
            foreach (Squad squad in Defenders)
                for (int i = 0; i < squad.Numbers; i++)
                    DefendersAsList.Add(squad.Race);

            Deaths = new List<string>();
            foreach (Squad squad in Attackers.Concat(Defenders))
                for (int i = 0; i < squad.Deaths; i++)
                    Deaths.Add(squad.Race);

            AttackerDeathCount = Attackers.Sum(attacker => attacker.Deaths);
            DefenderDeathCount = Defenders.Sum(defender => defender.Deaths);

            if (Outcome == BattleOutcome.AttackerWon) Victor = Attacker;
            else if (Outcome == BattleOutcome.DefenderWon) Victor = Defender;

            War parentWar = ParentCollection as War;
            if (parentWar != null)
            {
                if (parentWar.Attacker == Attacker)
                {
                    parentWar.AttackerDeathCount += AttackerDeathCount;
                    parentWar.DefenderDeathCount += DefenderDeathCount;
                }
                else
                {
                    parentWar.AttackerDeathCount += DefenderDeathCount;
                    parentWar.DefenderDeathCount += AttackerDeathCount;
                }
                parentWar.DeathCount += attackerSquadDeaths.Sum() + defenderSquadDeaths.Sum() + Collection.OfType<HFDied>().Count();

                if (Attacker == parentWar.Attacker && Victor == Attacker) parentWar.AttackerVictories.Add(this);
                else parentWar.DefenderVictories.Add(this);
            }

            if (Site != null) Site.Warfare.Add(this);
            if (Region != null) Region.Battles.Add(this);
            if (UndergroundRegion != null) UndergroundRegion.Battles.Add(this);

            if ((attackerSquadDeaths.Sum() + defenderSquadDeaths.Sum() + Collection.OfType<HFDied>().Count()) == 0)
                Notable = false;
            if ((attackerSquadNumbers.Sum() + NotableAttackers.Count) > ((defenderSquadNumbers.Sum() + NotableDefenders.Count) * 10) //NotableDefenders outnumbered 10 to 1
                && Victor == Attacker
                && AttackerDeathCount < ((NotableAttackers.Count + attackerSquadNumbers.Sum()) * 0.1)) //NotableAttackers lossses < 10%
                Notable = false;
        }