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>().Any()) { Attacker = Collection.OfType <AttackedSite>().First().Attacker; Defender = Collection.OfType <AttackedSite>().First().Defender; } else if (Collection.OfType <FieldBattle>().Any()) { 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; } }
public Entity(List <Property> properties, World world) : base(properties, world) { Name = ""; Race = "Unknown"; Type = EntityType.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": Race = Formatting.MakePopulationPlural(Formatting.FormatRace(property.Value)); 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; case "performancetroupe": Type = EntityType.PerformanceTroupe; 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 Site(List <Property> properties, World world) : base(properties, world) { Type = Name = UntranslatedName = ""; Warfare = new List <EventCollection>(); OwnerHistory = new List <OwnerPeriod>(); Connections = new List <Site>(); Populations = new List <Population>(); Officials = new List <Official>(); BeastAttacks = new List <BeastAttack>(); Structures = new List <Structure>(); RelatedHistoricalFigures = new List <HistoricalFigure>(); foreach (Property property in properties) { switch (property.Name) { case "type": Type = Formatting.InitCaps(property.Value); switch (property.Value) { case "cave": SiteType = SiteType.Cave; break; case "fortress": SiteType = SiteType.Fortress; break; case "forest retreat": SiteType = SiteType.ForestRetreat; break; case "dark fortress": SiteType = SiteType.DarkFortress; break; case "town": SiteType = SiteType.Town; break; case "hamlet": SiteType = SiteType.Hamlet; break; case "vault": SiteType = SiteType.Vault; break; case "dark pits": SiteType = SiteType.DarkPits; break; case "hillocks": SiteType = SiteType.Hillocks; break; case "tomb": SiteType = SiteType.Tomb; break; case "tower": SiteType = SiteType.Tower; break; case "mountain halls": SiteType = SiteType.MountainHalls; break; case "camp": SiteType = SiteType.Camp; break; case "lair": SiteType = SiteType.Lair; break; case "labyrinth": SiteType = SiteType.Labyrinth; break; case "shrine": SiteType = SiteType.Shrine; break; case "important location": SiteType = SiteType.ImportantLocation; break; default: property.Known = false; break; } break; case "name": Name = Formatting.InitCaps(property.Value); break; case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break; case "structures": HasStructures = true; property.Known = true; if (property.SubProperties != null) { foreach (Property subProperty in property.SubProperties) { subProperty.Known = true; Structures.Add(new Structure(subProperty.SubProperties, world, this)); } } break; case "civ_id": property.Known = true; break; case "cur_owner_id": property.Known = true; break; case "rectangle": char[] delimiterChars = { ':', ',' }; string[] rectArray = property.Value.Split(delimiterChars); if (rectArray.Length == 4) { int x0 = Convert.ToInt32(rectArray[0]); int y0 = Convert.ToInt32(rectArray[1]); int x1 = Convert.ToInt32(rectArray[2]); int y1 = Convert.ToInt32(rectArray[3]); Rectangle = new Rectangle(x0, y0, x1 - x0, y1 - y0); } else { property.Known = false; } break; } } SetIconByType(SiteType); }
private void GenerateCivIdenticons() { _worker.ReportProgress(0, "... Civilization Identicons"); List <Entity> civs = Entities.Where(entity => entity.IsCiv).ToList(); List <string> races = Entities.Where(entity => entity.IsCiv).GroupBy(entity => entity.Race).Select(entity => entity.Key).OrderBy(entity => entity).ToList(); //Calculates color //Creates a variety of colors //Races 1 to 6 get a medium color //Races 7 to 12 get a light color //Races 13 to 18 get a dark color //19+ reduced color variance int maxHue = 300; int colorVariance; if (races.Count <= 1) { colorVariance = 0; } else if (races.Count <= 6) { colorVariance = Convert.ToInt32(Math.Floor(maxHue / Convert.ToDouble(races.Count - 1))); } else if (races.Count > 18) { colorVariance = Convert.ToInt32(Math.Floor(maxHue / (Math.Ceiling(races.Count / 3.0) - 1))); } else { colorVariance = 60; } foreach (Entity civ in civs) { int colorIndex = races.IndexOf(civ.Race); Color raceColor; if (colorIndex * colorVariance < 360) { raceColor = Formatting.HsvToRgb(colorIndex * colorVariance, 1, 1.0); } else if (colorIndex * colorVariance < 720) { raceColor = Formatting.HsvToRgb(colorIndex * colorVariance - 360, 0.4, 1); } else if (colorIndex * colorVariance < 1080) { raceColor = Formatting.HsvToRgb(colorIndex * colorVariance - 720, 1, 0.4); } else { raceColor = Color.Black; } var alpha = 176; if (!MainRaces.ContainsKey(civ.Race)) { MainRaces.Add(civ.Race, raceColor); } civ.LineColor = Color.FromArgb(alpha, raceColor); var iconStyle = new IdenticonStyle { BackColor = Jdenticon.Rendering.Color.FromArgb(alpha, raceColor.R, raceColor.G, raceColor.B) }; var identicon = Identicon.FromValue(civ.Name, 128); identicon.Style = iconStyle; civ.Identicon = identicon.ToBitmap(); using (MemoryStream identiconStream = new MemoryStream()) { civ.Identicon.Save(identiconStream, ImageFormat.Png); byte[] identiconBytes = identiconStream.GetBuffer(); civ.IdenticonString = Convert.ToBase64String(identiconBytes); } var small = Identicon.FromValue(civ.Name, 32); small.Style = iconStyle; var smallIdenticon = small.ToBitmap(); using (MemoryStream smallIdenticonStream = new MemoryStream()) { smallIdenticon.Save(smallIdenticonStream, ImageFormat.Png); byte[] smallIdenticonBytes = smallIdenticonStream.GetBuffer(); civ.SmallIdenticonString = Convert.ToBase64String(smallIdenticonBytes); } foreach (var childGroup in civ.Groups) { childGroup.Identicon = civ.Identicon; childGroup.LineColor = civ.LineColor; } } foreach (var entity in Entities.Where(entity => entity.Identicon == null)) { var identicon = Identicon.FromValue(entity.Name, 128); entity.Identicon = identicon.ToBitmap(); } }