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); } }
public static HTMLPrinter GetPrinter(object printObject, World world) { Type printType = printObject.GetType(); if (printType == typeof(Battle)) return new BattlePrinter(printObject as Battle, world); if (printType == typeof(BeastAttack)) return new BeastAttackPrinter(printObject as BeastAttack, world); if (printType == typeof(Entity)) return new EntityPrinter(printObject as Entity, world); if (printType == typeof(Era)) return new EraPrinter(printObject as Era); if (printType == typeof(HistoricalFigure)) return new HistoricalFigureHTMLPrinter(printObject as HistoricalFigure, world); if (printType == typeof(WorldRegion)) return new RegionPrinter(printObject as WorldRegion, world); if (printType == typeof(SiteConquered)) return new SiteConqueredPrinter(printObject as SiteConquered, world); if (printType == typeof(Site)) return new SitePrinter(printObject as Site, world); if (printType == typeof(UndergroundRegion)) return new UndergroundRegionPrinter(printObject as UndergroundRegion, world); if (printType == typeof(War)) return new WarPrinter(printObject as War, world); if (printType == typeof(World)) return new WorldStatsPrinter(world); if (printType == typeof(Artifact)) return new ArtifactPrinter(printObject as Artifact); if (printType == typeof(WorldContruction)) return new WorldConstructionPrinter(printObject as WorldContruction); if (printType == typeof(string)) return new StringPrinter(printObject as string); throw new Exception("No HTML Printer for type: " + printObject.GetType().ToString()); }
public XMLParser(World world, string xmlFile) { World = world; StreamReader reader = new StreamReader(xmlFile, Encoding.GetEncoding("windows-1252")); XML = new XmlTextReader(reader); XML.WhitespaceHandling = WhitespaceHandling.Significant; }
public EntityEntityLink(List<Property> properties, World world) { Type = EntityEntityLinkType.Unknown; foreach (Property property in properties) { switch (property.Name) { case "type": switch (property.Value) { case "CHILD": Type = EntityEntityLinkType.Child; break; case "PARENT": Type = EntityEntityLinkType.Parent; break; default: world.ParsingErrors.Report("Unknown Entity Entity Link Type: " + property.Value); break; } break; case "target": Target = world.GetEntity(Convert.ToInt32(property.Value)); break; case "strength": Strength = Convert.ToInt32(property.Value); break; } } }
public UndergroundRegion(List<Property> properties, World world) : base(properties, world) { Depth = 0; Type = ""; Battles = new List<Battle>(); Coordinates = new List<Location>(); foreach (Property property in properties) switch(property.Name) { case "depth": Depth = Convert.ToInt32(property.Value); break; case "type": Type = Formatting.InitCaps(property.Value); break; case "coords": string[] coordinateStrings = property.Value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (var coordinateString in coordinateStrings) { string[] xYCoordinates = coordinateString.Split(','); int x = Convert.ToInt32(xYCoordinates[0]); int y = Convert.ToInt32(xYCoordinates[1]); Coordinates.Add(new Location(x, y)); } break; } }
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() }
public HistoricalFigureLink(List<Property> properties, World world) { Strength = 0; foreach (Property property in properties) { switch (property.Name) { case "hfid": int id = Convert.ToInt32(property.Value); HistoricalFigure = world.GetHistoricalFigure(id); if (HistoricalFigure == null) notYetLoadedHFID = id; break; case "link_strength": Strength = Convert.ToInt32(property.Value); break; case "link_type": HistoricalFigureLinkType linkType = HistoricalFigureLinkType.Unknown; if (!Enum.TryParse(Formatting.InitCaps(property.Value), out linkType)) { Type = HistoricalFigureLinkType.Unknown; world.ParsingErrors.Report("Unknown HF Link Type: " + property.Value); } else Type = linkType; break; } } //XML states that deity links, that should be 100, are 0. if (Type == HistoricalFigureLinkType.Deity && Strength == 0) Strength = 100; }
public WorldContruction(List<Property> properties, World world) : base(properties, world) { Name = "Untitled"; Coordinates = new List<Location>(); foreach (Property property in properties) { switch (property.Name) { case "name": Name = Formatting.InitCaps(property.Value); break; case "type": Type = Formatting.InitCaps(property.Value); break; case "coords": string[] coordinateStrings = property.Value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (var coordinateString in coordinateStrings) { string[] xYCoordinates = coordinateString.Split(','); int x = Convert.ToInt32(xYCoordinates[0]); int y = Convert.ToInt32(xYCoordinates[1]); Coordinates.Add(new Location(x, y)); } break; } } }
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++; } }
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(); } } }
protected EventCollection(List<Property> properties, World world) { Initialize(); World = world; foreach(Property property in properties) switch(property.Name) { case "id": this.ID = Convert.ToInt32(property.Value); property.Known = true; break; case "start_year": this.StartYear = Convert.ToInt32(property.Value); property.Known = true; break; case "start_seconds72": this.StartSeconds72 = Convert.ToInt32(property.Value); property.Known = true; break; case "end_year": this.EndYear = Convert.ToInt32(property.Value); property.Known = true; break; case "end_seconds72": this.EndSeconds72 = Convert.ToInt32(property.Value); property.Known = true; break; case "type": this.Type = Formatting.InitCaps(String.Intern(property.Value)); property.Known = true; break; case "event": WorldEvent collectionEvent = world.GetEvent(Convert.ToInt32(property.Value)); //Some Events don't exist in the XML now with 34.01? ///TODO: Investigate EventCollection Events that don't exist in the XML, check if they exist in game or if this is just errors. if (collectionEvent != null) { collectionEvent.ParentCollection = this; this.Collection.Add(collectionEvent); property.Known = true; } break; case "eventcol": this.CollectionIDs.Add(Convert.ToInt32(property.Value)); property.Known = true; break; default: break; } }
public HTMLControl(object htmlObject, DwarfTabControl tabControl, World world) { World = world; HTMLObject = htmlObject; Printer = HTMLPrinter.GetPrinter(htmlObject, world); Title = Printer.GetTitle(); TabControl = tabControl; }
public Journey(List<Property> properties, World world) : base(properties, world) { foreach (Property property in properties) switch (property.Name) { case "ordinal": Ordinal = String.Intern(property.Value); break; } }
public dlgHF(World world) { InitializeComponent(); var hfByRace = world.HistoricalFigures.GroupBy(hf => hf.Race).Select(hf => hf.Key).OrderBy(hf => hf); foreach (var race in hfByRace) { listHFRaces.Items.Add(race); } }
public XMLParser(World world, string xmlFile) : this(xmlFile) { World = world; string xmlPlusFile = xmlFile.Replace(".xml", "_plus.xml"); if (File.Exists(xmlPlusFile)) { xmlPlusParser = new XMLPlusParser(world, xmlPlusFile); World.Log.AppendLine("Found LEGENDS_PLUS.XML!"); World.Log.AppendLine("Parsed additional data...\n"); } }
protected WorldObject(List<Property> properties, World world) { ID = -1; Events = new List<WorldEvent>(); foreach(Property property in properties) switch(property.Name) { case "id": ID = Convert.ToInt32(property.Value); property.Known = true; break; default: break; } }
public WorldRegion(List<Property> properties, World world) : base(properties, world) { Battles = new List<Battle>(); foreach(Property property in properties) switch(property.Name) { case "name": Name = Formatting.InitCaps(property.Value); break; case "type": Type = String.Intern(property.Value); break; } }
public Artifact(List<Property> properties, World world) : base(properties, world) { foreach(Property property in properties) switch(property.Name) { case "name": Name = Formatting.InitCaps(property.Value); break; case "item": Item = Formatting.InitCaps(property.Value); break; } }
public Era(List<Property> properties, World world) : base(properties, world) { this.ID = world.Eras.Count; foreach(Property property in properties) switch(property.Name) { case "start_year": StartYear = Convert.ToInt32(property.Value); break; case "name": Name = property.Value; break; } }
public Entity(World world) { ID = -1; Name = "INVALID ENTITY"; Race = "Unknown"; Parent = null; Worshipped = new List<HistoricalFigure>(); LeaderTypes = new List<string>(); Leaders = new List<List<HistoricalFigure>>(); Groups = new List<Entity>(); SiteHistory = new List<OwnerPeriod>(); Wars = new List<War>(); Populations = new List<Population>(); }
public Era(int startYear, int endYear, World world) { world.TempEras.Add(this); this.ID = world.Eras.Count - 1 + world.TempEras.Count; StartYear = startYear; EndYear = endYear; Name = ""; Events = world.Events.Where(ev => ev.Year >= StartYear && ev.Year <= EndYear).OrderBy(events => events.Year).ToList(); Wars = world.EventCollections.OfType<War>().Where(war => (war.StartYear >= StartYear && war.EndYear <= EndYear && war.EndYear != -1) //entire war between || (war.StartYear >= StartYear && war.StartYear <= EndYear) //war started before & ended || (war.EndYear >= StartYear && war.EndYear <= EndYear && war.EndYear != -1) //war started during || (war.StartYear <= StartYear && war.EndYear >= EndYear) //war started before & ended after || (war.StartYear <= StartYear && war.EndYear == -1)).ToList(); }
public UndergroundRegion(List<Property> properties, World world) : base(properties, world) { Depth = 0; Type = ""; Battles = new List<Battle>(); foreach(Property property in properties) switch(property.Name) { case "depth": Depth = Convert.ToInt32(property.Value); break; case "type": Type = Formatting.InitCaps(property.Value); break; } }
public EntityReputation(List<Property> properties, World world) { foreach (Property property in properties) { switch (property.Name) { case "entity_id": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break; case "unsolved_murders": UnsolvedMurders = Convert.ToInt32(property.Value); break; case "first_ageless_year": FirstSuspectedAgelessYear = Convert.ToInt32(property.Value); break; case "first_ageless_season_count": FirstSuspectedAglessSeason = Formatting.TimeCountToSeason(Convert.ToInt32(property.Value)); break; } } }
public Purge(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 "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break; case "adjective": Adjective = property.Value; break; } } Console.WriteLine(); }
public dlgPopulation(World world) { InitializeComponent(); var populationGrouped = from population in world.SitePopulations group population by population.Race into popType select new { Type = popType.Key, Count = popType.Sum(population => population.Count) }; populationGrouped = populationGrouped.OrderBy(population => population.Type); foreach (var population in populationGrouped) { listPopulations.Items.Add(population.Type + ": " + population.Count); Populations.Add(new Population(population.Type, population.Count)); } }
public Structure(List<Property> properties, World world) : base(properties, world) { Name = "UNKNOWN STRUCTURE"; foreach (Property property in properties) { switch (property.Name) { case "name": Name = Formatting.InitCaps(property.Value); break; case "name2": AltName = Formatting.InitCaps(property.Value); break; case "type": Type = Formatting.InitCaps(property.Value); break; } } }
public XMLParser(World world, string xmlFile) { World = world; XML = new XmlTextReader(new StreamReader(xmlFile)); XML.WhitespaceHandling = WhitespaceHandling.Significant; //TODO: Error Handling, fixing missing root element from dwarf fortress versions 31.12 and under exports //try //{ // ParseXML(XML); //} //catch (System.Xml.XmlException xmlError) //{ // XML.Close(); // File.Move(xmlFile, xmlFile + ".bad"); // using (StreamReader badXML = new StreamReader(xmlFile + ".bad", Encoding.Default)) // { // using (StreamWriter fixedXML = new StreamWriter(xmlFile, false)) // { // string CurrentLine = ""; // while (!badXML.EndOfStream) // { // CurrentLine = badXML.ReadLine(); // fixedXML.WriteLine(CurrentLine); // if (CurrentLine == "<?xml version=\"1.0\" encoding='UTF-8'?>") fixedXML.WriteLine("<df_world>"); // } // fixedXML.WriteLine("</df_world>"); // } // } // File.Delete(xmlFile + ".bad"); // XML = new XmlTextReader(xmlFile); // try { ParseXML(XML); } // catch // { // throw; // } //} //catch //{ // throw; //} //finally //{ // XML.Close(); //} }
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; } }
public Artifact(List<Property> properties, World world) : base(properties, world) { Name = "Untitled"; foreach(Property property in properties) { switch (property.Name) { case "name": Name = Formatting.InitCaps(property.Value); break; case "item": Item = Formatting.InitCaps(property.Value); break; case "item_type": Type = property.Value; break; case "item_subtype": SubType = property.Value; break; case "item_description": Description = Formatting.InitCaps(property.Value); break; case "mat": Material = property.Value; break; } } }
public EntityLink(List<Property> properties, World world) { Strength = 0; StartYear = -1; EndYear = -1; foreach (Property property in properties) { switch (property.Name) { case "entity_id": int id = Convert.ToInt32(property.Value); Entity = world.GetEntity(id); break; case "position_profile_id": PositionID = Convert.ToInt32(property.Value); break; case "start_year": StartYear = Convert.ToInt32(property.Value); Type = EntityLinkType.Position; break; case "end_year": EndYear = Convert.ToInt32(property.Value); Type = EntityLinkType.FormerPosition; break; case "link_strength": Strength = Convert.ToInt32(property.Value); break; case "link_type": EntityLinkType linkType; if (!Enum.TryParse(Formatting.InitCaps(property.Value), out linkType)) { switch (property.Value) { case "former member": Type = EntityLinkType.FormerMember; break; case "former prisoner": Type = EntityLinkType.FormerPrisoner; break; case "former slave": Type = EntityLinkType.FormerSlave; break; default: Type = EntityLinkType.Unknown; world.ParsingErrors.Report("Unknown Entity Link Type: " + property.Value); break; } } else { Type = linkType; } break; } } }
public Entity(List <Property> properties, World world) : base(properties, world) { Name = ""; Race = "Unknown"; Parent = null; Worshipped = new List <HistoricalFigure>(); LeaderTypes = new List <string>(); Leaders = new List <List <HistoricalFigure> >(); Groups = new List <Entity>(); SiteHistory = new List <OwnerPeriod>(); SiteLinks = new List <EntitySiteLink>(); EntityLinks = new List <EntityEntityLink>(); Wars = new List <War>(); Populations = new List <Population>(); foreach (Property property in properties) { switch (property.Name) { case "name": Name = Formatting.InitCaps(property.Value); break; case "race": var race = property.Value.Replace("_", " ").Replace("man", "Men"); Race = Formatting.InitCaps(race); break; case "type": switch (property.Value) { case "civilization": Type = EntityType.Civilization; break; case "religion": Type = EntityType.Religion; break; case "sitegovernment": Type = EntityType.SiteGovernment; break; case "nomadicgroup": Type = EntityType.NomadicGroup; break; case "outcast": Type = EntityType.Outcast; break; case "migratinggroup": Type = EntityType.MigratingGroup; break; default: Type = EntityType.Unknown; world.ParsingErrors.Report("Unknown Entity Type: " + property.Value); break; } break; case "child": property.Known = true; break; case "site_link": SiteLinks.Add(new EntitySiteLink(property.SubProperties, world)); break; case "entity_link": property.Known = true; foreach (Property subProperty in property.SubProperties) { subProperty.Known = true; } world.AddEntityEntityLink(this, property); break; case "worship_id": property.Known = true; break; } } }
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; }