internal override void Link() { base.Link(); if (WcId.HasValue) { if (World.WorldConstructions.ContainsKey(WcId.Value)) { Wc = World.WorldConstructions[WcId.Value]; } else { Wc = new WorldConstruction(WcId.Value, World); World.WorldConstructions[WcId.Value] = Wc; } if (WcId_Master.HasValue && WcId_Master != -1) { if (World.WorldConstructions.ContainsKey(WcId_Master.Value)) { Wc_Master = World.WorldConstructions[WcId_Master.Value]; } else { Wc_Master = new WorldConstruction(WcId_Master.Value, World); World.WorldConstructions[WcId_Master.Value] = Wc_Master; } } } }
private void InternalLink(HistoricalEvent evt, PropertyInfo idProp, PropertyInfo classProp) { var Id = idProp.GetValue(this, null) as int?; XMLObject obj = null; if (Id.HasValue && Id.Value != -1) { if (classProp.PropertyType == typeof(Site)) { obj = World.Sites.ContainsKey(Id.Value) ? World.Sites[Id.Value] : null; } else if (classProp.PropertyType == typeof(Entity)) { obj = World.Entities.ContainsKey(Id.Value) ? World.Entities[Id.Value] : null; } else if (classProp.PropertyType == typeof(HistoricalFigure)) { obj = World.HistoricalFigures.ContainsKey(Id.Value) ? World.HistoricalFigures[Id.Value] : null; } else if (classProp.PropertyType == typeof(Structure)) { var thisSite = this.GetType().GetProperty("Site", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(evt, null) as Site; if (thisSite != null) { obj = thisSite.GetStructure(Id.Value); } } else if (classProp.PropertyType == typeof(Artifact)) { obj = World.Artifacts.ContainsKey(Id.Value) ? World.Artifacts[Id.Value] : null; } else if (classProp.PropertyType == typeof(WorldConstruction)) { WorldConstruction wc; if (!World.WorldConstructions.TryGetValue(Id.Value, out wc)) { wc = new WorldConstruction(Id.Value, World); World.WorldConstructions[Id.Value] = wc; } obj = wc; } else if (classProp.PropertyType == typeof(Region)) { obj = World.Regions.ContainsKey(Id.Value) ? World.Regions[Id.Value] : null; } } classProp.SetValue(this, obj, null); }
internal override void Link() { base.Link(); if (CivID.HasValue && World.Entities.ContainsKey(CivID.Value)) { Civ = World.Entities[CivID.Value]; } if (SiteCivID.HasValue && World.Entities.ContainsKey(SiteCivID.Value)) { SiteCiv = World.Entities[SiteCivID.Value]; } if (WCID.HasValue) { if (World.WorldConstructions.ContainsKey(WCID.Value)) { WC = World.WorldConstructions[WCID.Value]; } else { WC = new WorldConstruction(WCID.Value, World); World.WorldConstructions.Add(WCID.Value, WC); } if (MasterWCID.HasValue && MasterWCID != -1) { if (World.WorldConstructions.ContainsKey(MasterWCID.Value)) { MasterWC = World.WorldConstructions[MasterWCID.Value]; } else { MasterWC = new WorldConstruction(MasterWCID.Value, World); World.WorldConstructions.Add(MasterWCID.Value, MasterWC); } } } if (SiteID1.HasValue && World.Sites.ContainsKey(SiteID1.Value)) { Site1 = World.Sites[SiteID1.Value]; } if (SiteID2.HasValue && World.Sites.ContainsKey(SiteID2.Value)) { Site2 = World.Sites[SiteID2.Value]; } }
public CreatedWorldConstruction(List <Property> properties, World world) : base(properties, world) { foreach (Property property in properties) { switch (property.Name) { case "civ_id": Civ = world.GetEntity(Convert.ToInt32(property.Value)); break; case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break; case "site_id1": Site1 = world.GetSite(Convert.ToInt32(property.Value)); break; case "site_id2": Site2 = world.GetSite(Convert.ToInt32(property.Value)); break; case "wcid": WorldConstruction = world.GetWorldConstruction(Convert.ToInt32(property.Value)); break; case "master_wcid": MasterWorldConstruction = world.GetWorldConstruction(Convert.ToInt32(property.Value)); break; } } Civ.AddEvent(this); SiteEntity.AddEvent(this); WorldConstruction.AddEvent(this); MasterWorldConstruction.AddEvent(this); Site1.AddEvent(this); Site2.AddEvent(this); Site1.AddConnection(Site2); Site2.AddConnection(Site1); if (WorldConstruction != null) { WorldConstruction.Site1 = Site1; WorldConstruction.Site2 = Site2; if (MasterWorldConstruction != null) { MasterWorldConstruction.Sections.Add(WorldConstruction); WorldConstruction.MasterConstruction = MasterWorldConstruction; } } }
/// <summary> /// Now at the open tag of a single object in our XML, we want to dump the entire contents into an XDocument. /// If we have a World Construction it's a new item so it needs to be added, /// in other cases, it already exists and details need to be added to the existing items. /// Individual object reads are separated out to allow us to work past failing to load any specific XML item for any reason. /// </summary> private static void PlusLoadItem <T>(IDictionary <int, T> worldList, World world, XmlReader xReader) where T : XMLObject { XDocument xdoc = null; try { xdoc = XDocument.Load(xReader.ReadSubtree()); var id = Convert.ToInt32(xdoc.Root.Element("id").Value); if (!worldList.ContainsKey(id)) { if (typeof(T) == typeof(WorldConstruction)) { var newWc = new WorldConstruction(xdoc, world); world.WorldConstructions[newWc.Id] = newWc; return; } if (typeof(T) == typeof(Landmass)) { var newLandmass = new Landmass(xdoc, world); world.Landmasses.Add(newLandmass.Id, newLandmass); return; } if (typeof(T) == typeof(Mountain)) { var newMountain = new Mountain(xdoc, world); world.Mountains.Add(newMountain.Id, newMountain); return; } if (typeof(T) == typeof(River)) { var newRiver = new River(xdoc, world); world.Rivers.Add(newRiver.Id, newRiver); return; } if (typeof(T) == typeof(Army)) { var newArmy = new Army(xdoc, world); world.Armies.Add(newArmy.Id, newArmy); return; } if (typeof(T) == typeof(Unit)) { var newUnit = new Unit(xdoc, world); world.Units.Add(newUnit.Id, newUnit); return; } if (typeof(T) == typeof(Engraving)) { var newEngraving = new Engraving(xdoc, world); world.Engravings.Add(newEngraving.Id, newEngraving); return; } if (typeof(T) == typeof(Report)) { var newReport = new Report(xdoc, world); world.Reports.Add(newReport.Id, newReport); return; } if (typeof(T) == typeof(Building)) { var newBuilding = new Building(xdoc, world); world.Buildings.Add(newBuilding.Id, newBuilding); return; } if (typeof(T) == typeof(Construction)) { var newConstruction = new Construction(xdoc, world); world.Constructions.Add(newConstruction.Id, newConstruction); return; } if (typeof(T) == typeof(Item)) { var newItem = new Item(xdoc, world); world.Items.Add(newItem.Id, newItem); return; } if (typeof(T) == typeof(Plant)) { var newPlant = new Plant(xdoc, world); world.Plants.Add(newPlant.Id, newPlant); return; } if (typeof(T) == typeof(Squad)) { var newSquad = new Squad(xdoc, world); world.Squads.Add(newSquad.Id, newSquad); return; } if (typeof(T) == typeof(WrittenContent)) { var newWrittenContent = new WrittenContent(xdoc, world); world.WrittenContents.Add(newWrittenContent.Id, newWrittenContent); return; } if (typeof(T) == typeof(PoeticForm)) { var newPoeticForm = new PoeticForm(xdoc, world); world.PoeticForms.Add(newPoeticForm.Id, newPoeticForm); Console.WriteLine(newPoeticForm.Id); return; } if (typeof(T) == typeof(MusicalForm)) { var newMusicalForm = new MusicalForm(xdoc, world); world.MusicalForms.Add(newMusicalForm.Id, newMusicalForm); return; } if (typeof(T) == typeof(DanceForm)) { var newDanceForm = new DanceForm(xdoc, world); world.DanceForms.Add(newDanceForm.Id, newDanceForm); return; } } if (typeof(T) == typeof(Race)) { var key = xdoc.Root.Element("key").Value.ToLower(); var associatedRace = world.FindRace(key) ?? world.FindRace(xdoc.Root.Element("nameS").Value.ToLower()) ?? world.FindRace(xdoc.Root.Element("nameP").Value.ToLower()); if (associatedRace == null || associatedRace.Id > 0) { var newRace = new Race(xdoc, world) { AddedOrder = world.Races.Keys.Min() - 1 }; if (!world.Races.TryAdd(id, newRace)) { Program.Log(LogType.Error, "Failed to add race - " + newRace.ToString() + " while adding Plus XML"); } return; } id = associatedRace.AddedOrder; } if (worldList.ContainsKey(id)) { worldList[id].Plus(xdoc); } } catch (OutOfMemoryException e) { Program.Log(LogType.Error, "Error reading XML item: id\n" + e.Message); var fi = new FileInfo(_path); Program.Log(LogType.Error, "XML file is" + Math.Round(fi.Length / 1024f / 1024f / 1024f, 2) + " GB"); Program.Log(LogType.Error, $"Running {(Environment.Is64BitProcess ? "64" : "32")} Bit World Viewer"); Program.Log(LogType.Error, $"Running {(Environment.Is64BitOperatingSystem ? "64" : "32")} Bit Operating System"); if (!Environment.Is64BitOperatingSystem) //Running 32 bit OS { Program.Log(LogType.Error, "32 Bit World Viewer does not support Huge XML files"); } else if (!Environment.Is64BitProcess) //Running 32 bit app in 64 bit OS { Program.Log(LogType.Error, "Recommend using 64 Bit World Viewer"); } else { Program.Log(LogType.Error, "Please report Log"); } MemoryFailureQuitParsing = true; } catch (Exception e) { try { if (xdoc != null) { var id = int.Parse(((XElement)xdoc.Root.Nodes().ToArray()[1]).Value); if (id < 0) { switch (xdoc.Root.Name.LocalName) { case "historical_event": if (!_workflowDetected) { Program.Log(LogType.Error, "Negative ID historical event. Likely due to dfHack Workflow, ignoring\n" + xdoc); _workflowDetected = true; } break; case "historical_figure": if (!_autochopDetected) { Program.Log(LogType.Error, "Negative ID historical figure detected. Likely due to autochop, ignoring\n" + xdoc); _autochopDetected = true; } break; default: Program.Log(LogType.Error, "Negative ID " + xdoc.Root.Name.LocalName + " detected. Unknown cause, ignoring\n" + xdoc); break; } } else { Program.Log(LogType.Error, "Error reading XML item: id\n" + e.Message); } } } catch (Exception) { Program.Log(LogType.Error, "Error reading XML item: id\n" + e.Message); throw; } } }
public WorldConstructionPrinter(WorldConstruction worldConstruction, World world) { _worldConstruction = worldConstruction; _world = world; }