/// <summary> /// Loads the existing reports for the village /// </summary> public void Load(Village village) { if (!_reportsLoaded) { _reportsLoaded = true; _currentSituation = new CurrentSituation(village); if (System.IO.File.Exists(File)) { var sets = new XmlReaderSettings(); sets.IgnoreWhitespace = true; sets.CloseInput = true; using (XmlReader r = XmlReader.Create(File, sets)) { ReadXml(r); } } } }
/// <summary> /// Sets the type of the village based on the troops /// inside the village /// </summary> public void GuessVillageType() { if (Village.Reports.CurrentSituation != null) { int def = 0; int off = 0; bool flagNoble = false; bool flagScout = false; CurrentSituation current = Village.Reports.CurrentSituation; foreach (KeyValuePair <UnitTypes, int> pair in current.Defense.OwnTroops) { Unit unit = WorldUnits.Default[pair.Key]; int value = pair.Value; if (value > 0) { if (unit.Offense) { off += value * unit.Cost.People; } else { def += value * unit.Cost.People; } if (unit.Type == UnitTypes.Snob) { flagNoble = true; } if (unit.Type == UnitTypes.Spy && value > 2000) { flagScout = true; } } } if (off + def < 200) { Village.Type = VillageType.Farm; } else { if (def > off * 1.2) { Village.Type = VillageType.Defense; } else if (off > def * 1.2) { Village.Type = VillageType.Attack; } else { Village.Type = VillageType.Attack | VillageType.Defense; } } if (flagNoble) { Village.Type |= VillageType.Noble; } if (flagScout) { Village.Type |= VillageType.Scout; } } }