Esempio n. 1
0
        private void extractESFFamilyTreeStructure(XmlNode root, CharInfoCreator charInfoCreator, DateConverter dtConverter)
        {
            int treeSize = Int32.Parse(root.FirstChild.InnerText);

            esfFamilyTreeStructure = new List <List <string> >(treeSize);
            for (XmlNode node = root.FirstChild.NextSibling; node != null; node = node.NextSibling)
            {
                if (node.Name != "rec")
                {
                    continue;
                }
                List <string> treeContents = new List <string>();
                for (XmlNode treeContentItem = node.FirstChild; treeContentItem != null; treeContentItem = treeContentItem.NextSibling)
                {
                    if (treeContentItem.Name == "u")
                    {
                        treeContents.Add(treeContentItem.InnerText);
                    }
                    else if (treeContentItem.Name == "no" || treeContentItem.Name == "yes")
                    {
                        treeContents.Add(treeContentItem.Name);
                    }
                    else if (treeContentItem.Attributes.Count > 0 && treeContentItem.Attributes[0].InnerText == "CHARACTER_DETAILS")
                    {
                        int    detailCount      = 0;
                        bool   i1AryFound       = false;
                        int    countedUAfterPol = 0;
                        bool   foundGender      = false;
                        int    ascCount         = 0;
                        bool   male             = false;
                        int    treeID           = Int32.Parse(treeContents[0]);
                        string name             = "";
                        string birthStr         = "";
                        string deathStr         = "";
                        for (XmlNode detailNode = treeContentItem.FirstChild; detailNode != null; detailNode = detailNode.NextSibling)
                        {
                            if (detailNode.Name == "asc")
                            {
                                ascCount++;
                            }
                            if (birthStr != "" && deathStr == "" && detailNode.Name == "date2")
                            {
                                deathStr = detailNode.InnerText;
                            }
                            if (birthStr == "" && detailNode.Name == "date2")
                            {
                                birthStr = detailNode.InnerText;
                            }
                            if (foundGender == false && ascCount == 2 && (detailNode.Name == "yes" || detailNode.Name == "no"))
                            {
                                male        = (detailNode.Name == "yes");
                                foundGender = true;
                            }/*
                              * if (detailCount == 12) {
                              * male = (detailNode.Name == "yes");
                              * }*/
                            if (detailNode.Name == "i1_ary")
                            {
                                i1AryFound = true;
                            }
                            if (detailNode.Name == "u" && i1AryFound)
                            {
                                countedUAfterPol++;
                                if (countedUAfterPol == 5)
                                {
                                    treeID = Int32.Parse(detailNode.InnerText);
                                }
                            }
                            if (detailNode.Name != "rec")
                            {
                                detailCount++;
                            }
                            if (detailNode.Attributes.Count == 0)
                            {
                                continue;
                            }
                            XmlAttribute detailAttr = detailNode.Attributes[0];
                            if (detailAttr.Name == "type" && detailAttr.InnerText == "CHARACTER_NAME")
                            {
                                name = charInfoCreator.extractName(detailNode);
                            }
                        }
                        DateTime     birth     = dtConverter.convertDate(birthStr);
                        DateTime     death     = dtConverter.convertDate(deathStr);
                        CK2Character character = new CK2Character(name, 0, treeID, male, birth, death, "", "");
                        allCharacters.Add(character);
                    }
                }
                esfFamilyTreeStructure.Add(treeContents);
            }
        }
Esempio n. 2
0
        private List <Tuple <String, CK2Character> > generateCharInfo(ImportantPaths importantPaths, List <Tuple <String, String> > charXMLLocs, DateConverter dtConverter)
        {
            List <Tuple <String, CK2Character> > charInfo = new List <Tuple <String, CK2Character> >();
            string savegamePath = importantPaths.getSavegameXMLPath();

            foreach (Tuple <String, String> charXMLLoc in charXMLLocs)
            {
                string      name = "";
                XmlDocument doc  = new XmlDocument();
                try {
                    doc.Load(savegamePath + "\\" + charXMLLoc.Item2);
                }
                catch (Exception) {
                    continue;
                }
                XmlNode root      = doc.DocumentElement.FirstChild;
                int     esfID     = 0;
                int     treeID    = 0;
                int     nodeCount = 0;
                bool    male      = false;
                string  birthStr  = "";
                for (XmlNode node = root.FirstChild; node != null; node = node.NextSibling)
                {
                    if (nodeCount == 0 && node.Name != "rec")
                    {
                        esfID = Int32.Parse(node.InnerText);
                    }
                    if (node.Name != "rec")
                    {
                        nodeCount++;
                    }
                    if (node.Attributes.Count == 0)
                    {
                        continue;
                    }
                    XmlAttribute attr = node.Attributes[0];
                    if (attr.Name == "type" && attr.InnerText == "CHARACTER_DETAILS")
                    {
                        int  detailCount      = 0;
                        bool i1AryFound       = false;
                        int  countedUAfterPol = 0;
                        bool foundGender      = false;
                        int  ascCount         = 0;
                        for (XmlNode detailNode = node.FirstChild; detailNode != null; detailNode = detailNode.NextSibling)
                        {
                            if (detailNode.Name == "asc")
                            {
                                ascCount++;
                            }
                            if (birthStr == "" && detailNode.Name == "date2")
                            {
                                birthStr = detailNode.InnerText;
                            }
                            if (foundGender == false && ascCount == 2 && (detailNode.Name == "yes" || detailNode.Name == "no"))
                            {
                                male        = (detailNode.Name == "yes");
                                foundGender = true;
                            }/*
                              * if (detailCount == 11) {
                              * male = (detailNode.Name == "yes");
                              * }*/
                            if (detailNode.Name == "i1_ary")
                            {
                                i1AryFound = true;
                            }
                            if (detailNode.Name == "u" && i1AryFound)
                            {
                                countedUAfterPol++;
                                if (countedUAfterPol == 5)
                                {
                                    treeID = Int32.Parse(detailNode.InnerText);
                                }
                            }
                            if (detailNode.Name != "rec")
                            {
                                detailCount++;
                            }
                            if (detailNode.Attributes.Count == 0)
                            {
                                continue;
                            }
                            XmlAttribute detailAttr = detailNode.Attributes[0];
                            if (detailAttr.Name == "type" && detailAttr.InnerText == "CHARACTER_NAME")
                            {
                                name = extractName(detailNode);
                            }
                        }
                    }
                }
                DateTime birth    = dtConverter.convertDate(birthStr);
                DateTime death    = dtConverter.convertDate("1 0 0 0");
                string   religion = faction2ReligionMap[charXMLLoc.Item1];
                string   culture  = "";
                try {
                    culture = faction2CultureMap[charXMLLoc.Item1];
                }
                catch (Exception) { }
                CK2Character character             = new CK2Character(name, esfID, treeID, male, birth, death, religion, culture);
                Tuple <String, CK2Character> tuple = Tuple.Create <String, CK2Character>(charXMLLoc.Item1, character);
                charInfo.Add(tuple);
            }
            return(charInfo);
        }