Exemplo n.º 1
0
        public void HistoricalEventCollection_WarXML_Parses()
        {
            var world = LoadingWorld.GetTestWorld();
            var xdoc  = new XDocument(new XElement("historical_event_collection",
                                                   new XElement("id", 86),
                                                   new XElement("start_year", 1),
                                                   new XElement("start_seconds72", 92400),
                                                   new XElement("end_year", 2),
                                                   new XElement("end_seconds72", 100800),
                                                   new XElement("eventcol", 87),
                                                   new XElement("eventcol", 97),
                                                   new XElement("event", 1212),
                                                   new XElement("type", "war"),
                                                   new XElement("name", "the war of screams"),
                                                   new XElement("aggressor_ent_id", 84),
                                                   new XElement("defender_ent_id", 88)
                                                   )
                                      );

            var historicalEventCollection = HistoricalEventCollection.Create(xdoc, world);

            Assert.AreEqual(historicalEventCollection.Id, 86);
            Assert.AreEqual(historicalEventCollection.StartTime, new WorldTime(1, 92400));
            Assert.AreEqual(historicalEventCollection.EndTime, new WorldTime(2, 100800));
            Assert.AreEqual(historicalEventCollection.EventIDs.Count, 1);
            Assert.AreEqual(historicalEventCollection.EventIDs[0], 1212);
            Assert.AreEqual(HistoricalEventCollection.Types[historicalEventCollection.Type], "war");
            var warEventCollection = historicalEventCollection as EC_War;

            Assert.AreEqual(warEventCollection.EventColIDs.Count, 2);
            Assert.AreEqual(warEventCollection.EventColIDs[0], 87);
            Assert.AreEqual(warEventCollection.EventColIDs[1], 97);
            Assert.AreEqual(warEventCollection.AggressorEntId, 84);
            Assert.AreEqual(warEventCollection.DefenderEntId, 88);
        }
Exemplo n.º 2
0
        public void HistoricalEventCollection_NewTypeXML_Parses()
        {
            var world = LoadingWorld.GetTestWorld();
            var xdoc  = new XDocument(new XElement("historical_event_collection",
                                                   new XElement("id", 30),
                                                   new XElement("start_year", 45),
                                                   new XElement("start_seconds72", 285600),
                                                   new XElement("end_year", 50),
                                                   new XElement("end_seconds72", 285600),
                                                   new XElement("type", "unknown new type")
                                                   )
                                      );

            var historicalEventCollection = HistoricalEventCollection.Create(xdoc, world);

            Assert.AreEqual(historicalEventCollection.Id, 30);
            Assert.AreEqual(historicalEventCollection.StartTime, new WorldTime(45, 285600));
            Assert.AreEqual(historicalEventCollection.EndTime, new WorldTime(50, 285600));
            Assert.IsInstanceOfType(historicalEventCollection, typeof(EC_UnassessedEventCollection));
        }
Exemplo n.º 3
0
        /// <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 historical event or historical event collection we want to use their factory methods to create a new version of those with the given XDocument.
        ///   For all other object types we want to use their constructor to make a new object of that type.
        ///   In any case we add the object after making it to the appropriate dictionary.
        /// Individual object reads are separated out to allow us to work past failing to load any specific XML item for some weird reason.
        /// </summary>
        private static void LoadItem <T>(IDictionary <int, T> WorldList, World world, XmlReader xReader) where T : XMLObject
        {
            XDocument xdoc = null;

            try
            {
                xdoc = XDocument.Load(xReader.ReadSubtree());

                if (typeof(T) == typeof(HistoricalEvent))
                {
                    var evt = HistoricalEvent.Create(xdoc, world);
                    world.HistoricalEvents.Add(evt.ID, evt);
                }
                else if (typeof(T) == typeof(HistoricalEventCollection))
                {
                    var evtcol = HistoricalEventCollection.Create(xdoc, world);
                    world.HistoricalEventCollections.Add(evtcol.ID, evtcol);
                }
                else
                {
                    var WorldObject = (T)Activator.CreateInstance(typeof(T), new object[] { xdoc, world });
                    WorldList.Add(WorldObject.ID, WorldObject);
                }
            }
            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, string.Format("Running {0} Bit World Viewer", (Environment.Is64BitProcess ? "64" : "32")));
                Program.Log(LogType.Error, string.Format("Running {0} Bit Operating System", (Environment.Is64BitOperatingSystem ? "64" : "32")));

                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)
                    {
                        int id = Int32.Parse(((XElement)xdoc.Root.Nodes().ToArray()[1]).Value);

                        if (id < 0)
                        {
                            if (xdoc.Root.Name.LocalName == "historical_event")
                            {
                                if (!workflowDetected)
                                {
                                    Program.Log(LogType.Error,
                                                "Negative ID historical event.  Likely due to dfHack Workflow, ignoring\n" + xdoc);
                                    workflowDetected = true;
                                }
                            }
                            else if (xdoc.Root.Name.LocalName == "historical_figure")
                            {
                                if (!autochopDetected)
                                {
                                    Program.Log(LogType.Error,
                                                "Negative ID historical figure detected. Likely due to autochop, ignoring\n" + xdoc);
                                    autochopDetected = true;
                                }
                            }
                            else
                            {
                                Program.Log(LogType.Error,
                                            "Negative ID " + xdoc.Root.Name.LocalName + " detected. Unknown cause, ignoring\n" + xdoc);
                            }
                        }
                        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;
                }
            }
        }
Exemplo n.º 4
0
        public void HistoricalEventCollection_BattleXML_Parses()
        {
            var world = LoadingWorld.GetTestWorld();
            var xdoc  = new XDocument(new XElement("historical_event_collection",
                                                   new XElement("id", 21796),
                                                   new XElement("start_year", 660),
                                                   new XElement("start_seconds72", 285600),
                                                   new XElement("end_year", 660),
                                                   new XElement("end_seconds72", 285600),
                                                   new XElement("eventcol", 21797),
                                                   new XElement("eventcol", 21798),
                                                   new XElement("event", 180182),
                                                   new XElement("event", 180183),
                                                   new XElement("type", "battle"),
                                                   new XElement("name", "the siege of assault"),
                                                   new XElement("war_eventcol", 21795),
                                                   new XElement("subregion_id", -1),
                                                   new XElement("feature_layer_id", -1),
                                                   new XElement("site_id", 88),
                                                   new XElement("coords", "27,16"),
                                                   new XElement("subregion_id", -1),
                                                   new XElement("attacking_hfid", 27436),
                                                   new XElement("attacking_hfid", 27437),
                                                   new XElement("defending_hfid", 27278),
                                                   new XElement("defending_hfid", 27284),
                                                   new XElement("noncom_hfid", 27299),
                                                   new XElement("attacking_squad_race", "GIANT_RATTLESNAKE"),
                                                   new XElement("attacking_squad_entity_pop", -1),
                                                   new XElement("attacking_squad_number", 5),
                                                   new XElement("attacking_squad_deaths", 0),
                                                   new XElement("attacking_squad_site", -1),
                                                   new XElement("defending_squad_race", "CROCODILE_CAVE"),
                                                   new XElement("defending_squad_entity_pop", -1),
                                                   new XElement("defending_squad_number", 5),
                                                   new XElement("defending_squad_deaths", 5),
                                                   new XElement("defending_squad_site", -1),
                                                   new XElement("outcome", "defender won")
                                                   )
                                      );

            var historicalEventCollection = HistoricalEventCollection.Create(xdoc, world);

            Assert.AreEqual(historicalEventCollection.Id, 21796);
            Assert.AreEqual(historicalEventCollection.StartTime, new WorldTime(660, 285600));
            Assert.AreEqual(historicalEventCollection.EndTime, new WorldTime(660, 285600));
            Assert.AreEqual(historicalEventCollection.EventIDs.Count, 2);
            Assert.AreEqual(historicalEventCollection.EventIDs[0], 180182);
            Assert.AreEqual(historicalEventCollection.EventIDs[1], 180183);
            Assert.AreEqual(HistoricalEventCollection.Types[historicalEventCollection.Type], "battle");
            var battleEventCollection = historicalEventCollection as EC_Battle;

            Assert.AreEqual(battleEventCollection.EventColIDs.Count, 2);
            Assert.AreEqual(battleEventCollection.EventColIDs[0], 21797);
            Assert.AreEqual(battleEventCollection.EventColIDs[1], 21798);
            Assert.AreEqual(battleEventCollection.WarEventColId, 21795);
            Assert.IsNull(battleEventCollection.SubregionId);
            Assert.IsNull(battleEventCollection.FeatureLayerId);
            Assert.AreEqual(battleEventCollection.SiteId, 88);
            Assert.AreEqual(battleEventCollection.Coords, new Point(27, 16));
            Assert.AreEqual(battleEventCollection.AttackingHfid.Count, 2);
            Assert.AreEqual(battleEventCollection.AttackingHfid[0], 27436);
            Assert.AreEqual(battleEventCollection.AttackingHfid[1], 27437);
            Assert.AreEqual(battleEventCollection.DefendingHfid.Count, 2);
            Assert.AreEqual(battleEventCollection.DefendingHfid[0], 27278);
            Assert.AreEqual(battleEventCollection.DefendingHfid[1], 27284);
            Assert.AreEqual(battleEventCollection.NonComHfid.Count, 1);
            Assert.AreEqual(battleEventCollection.NonComHfid[0], 27299);
            Assert.AreEqual(battleEventCollection.AttackingSquadRace[0], "GIANT_RATTLESNAKE");
            Assert.AreEqual(battleEventCollection.AttackingSquadEntityPop[0], -1);
            Assert.AreEqual(battleEventCollection.AttackingSquadNumber[0], 5);
            Assert.AreEqual(battleEventCollection.AttackingSquadDeaths[0], 0);
            Assert.AreEqual(battleEventCollection.AttackingSquadSite[0], -1);
            Assert.AreEqual(battleEventCollection.DefendingSquadRace[0], "CROCODILE_CAVE");
            Assert.AreEqual(battleEventCollection.DefendingSquadEntityPop[0], -1);
            Assert.AreEqual(battleEventCollection.DefendingSquadNumber[0], 5);
            Assert.AreEqual(battleEventCollection.DefendingSquadDeaths[0], 5);
            Assert.AreEqual(battleEventCollection.DefendingSquadSite[0], -1);
            Assert.AreEqual(battleEventCollection.Outcome, "defender won");
        }