Пример #1
0
        public static void output(FactionsInfo factionsObj)
        {
            List <CK2Character> owners   = factionsObj.getOwners();
            List <FactionInfo>  factions = factionsObj.getFactions();
            Dictionary <string, HashSet <CK2Character> > charactersToOutput = new Dictionary <string, HashSet <CK2Character> >();

            foreach (FactionInfo faction in factions)
            {
                if (!faction.getExists())
                {
                    continue;
                }
                CK2Character  owner             = faction.getOwner();
                HashSet <int> writtenCharacters = new HashSet <int>();
                selectCharacter(writtenCharacters, owner, charactersToOutput);
            }
            foreach (var pair in charactersToOutput)
            {
                string filename = ImportantPaths.getOutputPath() + "\\history\\characters\\" + pair.Key + ".txt";
                HashSet <CK2Character> characters = pair.Value;
                using (StreamWriter writer = File.CreateText(filename)) {
                    foreach (CK2Character character in characters)
                    {
                        writeCharacter(writer, character);
                    }
                }
            }
        }
Пример #2
0
        public void updateReligionForCharacter(CK2Character character, bool canOverwrite, HashSet <int> processed)
        {
            bool hasChar = !(processed.Add(character.getFamilyTreeID()));

            if (hasChar)
            {
                return;
            }
            if (character.getReligion() == null || canOverwrite)
            {
                character.setReligion(this.religion);
            }
            CK2Character father = character.getFather();

            if (father != null)
            {
                updateReligionForCharacter(father, canOverwrite, processed);
            }
            List <CK2Character> children = character.getChildren();

            if (children != null)
            {
                foreach (CK2Character child in children)
                {
                    updateReligionForCharacter(child, canOverwrite, processed);
                }
            }
        }
Пример #3
0
        private void updateDynastyForCharacter(CK2Character character, CK2Dynasty newDynasty, bool canOverwrite, HashSet <int> processed)
        {
            bool hasChar = !(processed.Add(character.getFamilyTreeID()));

            if (hasChar)
            {
                return;
            }
            if (character.getDynasty() == null || canOverwrite)
            {
                character.setDynasty(newDynasty);
            }
            CK2Character father = character.getFather();

            if (father != null)
            {
                //CK2Dynasty fatherDynasty = father.getDynasty();
                //if (fatherDynasty == null || fatherDynasty.getID() != newDynasty.getID())
                updateDynastyForCharacter(father, newDynasty, canOverwrite, processed);
            }
            List <CK2Character> children = character.getChildren();

            if (children != null)
            {
                foreach (CK2Character child in children)
                {
                    //CK2Dynasty childDynasty = child.getDynasty();
                    //if (childDynasty == null || childDynasty.getID() != newDynasty.getID())
                    updateDynastyForCharacter(child, newDynasty, canOverwrite, processed);
                }
            }
        }
Пример #4
0
        private static void selectCharacter(HashSet <int> writtenCharacters, StreamWriter writer, CK2Character character)
        {
            if (character == null)
            {
                return;
            }
            bool bWritten = !(writtenCharacters.Add(character.getID()));

            if (bWritten)
            {
                return;
            }
            writeCharacter(writer, character);
            CK2Character father = character.getFather();

            selectCharacter(writtenCharacters, writer, father);
            List <CK2Character> children = character.getChildren();

            if (children != null)
            {
                foreach (CK2Character child in children)
                {
                    selectCharacter(writtenCharacters, writer, child);
                }
            }
            CK2Character spouse = character.getSpouse();

            selectCharacter(writtenCharacters, writer, spouse);
        }
Пример #5
0
        public void updateDynasty(CK2Dynasty newDynasty, CK2Character character, bool canOverwrite)
        {
            associatedDynasties.Add(newDynasty);
            HashSet <int> processed = new HashSet <int>();

            updateDynastyForCharacter(character, newDynasty, canOverwrite, processed);
        }
Пример #6
0
        private static void selectCharacter(HashSet <int> writtenCharacters, CK2Character character, Dictionary <string, HashSet <CK2Character> > charactersToOutput)
        {
            if (character == null)
            {
                return;
            }
            bool bWritten = !(writtenCharacters.Add(character.getID()));

            if (bWritten)
            {
                return;
            }
            appendCharToCTO(character, charactersToOutput);
            CK2Character father = character.getFather();

            selectCharacter(writtenCharacters, father, charactersToOutput);
            List <CK2Character> children = character.getChildren();

            if (children != null)
            {
                foreach (CK2Character child in children)
                {
                    selectCharacter(writtenCharacters, child, charactersToOutput);
                }
            }
            CK2Character spouse = character.getSpouse();

            selectCharacter(writtenCharacters, spouse, charactersToOutput);
        }
Пример #7
0
 public void readFamilyTrees(FamilyTrees trees)
 {
     foreach (FactionInfo faction in factionPreProcessMappings)
     {
         CK2Character character = new CK2Character();
         FamilyTree   tree      = trees.getTree(faction.getID());
         if (tree != null)
         {
             character = tree.getOwner();
         }
         CK2Dynasty dynasty = new CK2Dynasty();
         if (faction.getDynasty() != null)
         {
             dynasty = faction.getDynasty();
             if (tree != null)
             {
                 tree.updateDynasty(dynasty, character, true);
             }
         }
         else
         {
             if (tree != null)
             {
                 dynasty = tree.getDynasty();
             }
             faction.setDynasty(dynasty);
         }
         //character.setDynasty(dynasty);
         faction.setOwner(character);
     }
 }
Пример #8
0
        private CK2Dynasty deriveDynasty(CK2Character character)
        {
            CK2Character curChar = character;

            while (curChar.getFather() != null)
            {
                curChar = curChar.getFather();
            }
            CK2Dynasty dynasty = new CK2Dynasty(curChar.getName());

            return(dynasty);
        }
Пример #9
0
 private static void appendCharToCTO(CK2Character character, Dictionary <string, HashSet <CK2Character> > charactersToOutput)
 {
     try {
         HashSet <CK2Character> charList = charactersToOutput[character.getCulture()];
         charList.Add(character);
     }
     catch (Exception) {
         HashSet <CK2Character> charList = new HashSet <CK2Character>();
         charList.Add(character);
         charactersToOutput.Add(character.getCulture(), charList);
     }
 }
Пример #10
0
 private void deriveJobs(CharInfoCreator charInfoCreator)
 {
     foreach (CK2Character character in localCharacters)
     {
         string office = charInfoCreator.getJob(character.getESFID());
         if (office != null)
         {
             character.setOffice(office);
             if (office == "faction_leader")
             {
                 root = character;
             }
         }
     }
 }
Пример #11
0
        public void updateSpouses(CK2Character character, HashSet <int> processed, List <List <string> > esfFamilyTreeStructure)
        {
            bool hasChar = !(processed.Add(character.getID()));

            if (hasChar)
            {
                return;
            }
            CK2Character spouse = character.getSpouse();

            if (character.getSpouse() != null)
            {
                CK2Dynasty spouseDynasty = character.getSpouse().getDynasty();
                if (spouseDynasty == null)
                {
                    discoverTree(spouse, fam2Char, esfFamilyTreeStructure);
                    spouseDynasty = this.deriveDynasty(spouse);
                    associatedDynasties.Add(spouseDynasty);
                    updateDynasty(spouseDynasty, spouse, false);
                    updateReligion(spouse, false);
                    updateCulture(spouse, false);
                }
            }
            CK2Character father = character.getFather();

            if (father != null)
            {
                updateSpouses(father, processed, esfFamilyTreeStructure);
            }
            List <CK2Character> children = character.getChildren();

            if (children != null)
            {
                foreach (CK2Character child in children)
                {
                    updateSpouses(child, processed, esfFamilyTreeStructure);
                }
            }
        }
Пример #12
0
        private void discoverTree(CK2Character character, Dictionary <int, CK2Character> familyID2Characters, List <List <string> > esfFamilyTreeStructure)
        {
            int           charsFamilyID  = character.getFamilyTreeID();
            List <string> familyTreeInfo = esfFamilyTreeStructure[charsFamilyID - 1];
            int           fatherID       = Int32.Parse(familyTreeInfo[4]);
            int           spouseID       = Int32.Parse(familyTreeInfo[5]);
            //This is apparently spouse-related (?)
            int numSpousesPos = 6;
            int numSpouses    = Int32.Parse(familyTreeInfo[numSpousesPos]);

            if (spouseID == 0 && numSpouses > 0)
            {
                spouseID = Int32.Parse(familyTreeInfo[numSpousesPos + 1]);
            }
            int        numChildrenPos = numSpouses + numSpousesPos + 1;
            int        numChildren    = Int32.Parse(familyTreeInfo[numChildrenPos]);
            int        numAdoptedPos  = numChildren + numChildrenPos + 1;
            int        numAdopted     = Int32.Parse(familyTreeInfo[numAdoptedPos]);
            List <int> childrenIDs    = new List <int>(numChildren);

            for (int i = 0; i < numChildren; i++)
            {
                int childID = Int32.Parse(familyTreeInfo[numChildrenPos + i + 1]);
                childrenIDs.Add(childID);
            }
            for (int i = 0; i < numAdopted; i++)
            {
                int childID = Int32.Parse(familyTreeInfo[numAdoptedPos + i + 1]);
                childrenIDs.Add(childID);
            }
            if (fatherID != 0)
            {
                character.setFather(familyID2Characters[fatherID]);
            }
            if (spouseID != 0)
            {
                character.setSpouse(familyID2Characters[spouseID]);
            }
            if ((numChildren + numAdopted) != 0)
            {
                List <CK2Character> children = new List <CK2Character>(numChildren + numAdopted);
                foreach (int childID in childrenIDs)
                {
                    children.Add(familyID2Characters[childID]);
                }
                if (children.Count == 0)
                {
                    character.setChildren(null);
                }
                else
                {
                    character.setChildren(children);
                }
            }
            int  booleanPrefacePos = numAdopted + numAdoptedPos + 1;
            int  booleanListPos    = booleanPrefacePos + 2;
            bool isBastard         = (familyTreeInfo[booleanListPos + 2] == "yes");

            character.setIsBastard(isBastard);

            //Skip the female->male spouse. She is handled in the next run.
            {
                CK2Character father = character.getFather();
                if (father != null)
                {
                    bool hasChar = (father.getChildren() != null);
                    if (!hasChar)
                    {
                        discoverTree(father, familyID2Characters, esfFamilyTreeStructure);
                    }
                    if (character.getBirth().CompareTo(father.getBirth()) <= 0)
                    {
                        character.incrementBirthDay(father);
                    }
                }

                List <CK2Character> children = character.getChildren();
                if (children != null)
                {
                    foreach (CK2Character child in children)
                    {
                        bool hasChar = (child.getFather() != null);
                        if (!hasChar)
                        {
                            discoverTree(child, familyID2Characters, esfFamilyTreeStructure);
                        }
                    }
                }

                //CK2Character spouse = character.getSpouse();
                //if (character.getIsMale() && spouse != null) {
                //    discoverTree(spouse, familyID2Characters, esfFamilyTreeStructure);
                //}
            }
        }
Пример #13
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);
        }
Пример #14
0
 public void setSpouse(CK2Character spouse)
 {
     this.spouse = spouse;
 }
Пример #15
0
        private static void writeCharacter(StreamWriter writer, CK2Character character)
        {
            CK2Dynasty dynasty   = character.getDynasty();
            int        dynastyID = 0;

            if (dynasty != null)
            {
                dynastyID = dynasty.getID();
            }
            string name   = character.getName();
            int    charID = character.getID();
            int    dob    = character.getBirthDay();
            int    mob    = character.getBirthMonth();
            int    yob    = character.getBirthYear();

            writer.WriteLine(charID + " = {");
            writer.WriteLine("\tname=\"" + name + "\"");
            if (dynastyID != 0)
            {
                writer.WriteLine("\tdynasty=" + dynastyID);
            }
            else
            {
                writer.WriteLine("\tdynasty=" + "NONE");
            }
            writer.WriteLine("\treligion=\"" + character.getReligion() + "\"");
            writer.WriteLine("\tculture=\"" + character.getCulture() + "\"");

            if (character.getIsMale() == false)
            {
                writer.WriteLine("\tfemale=yes");
            }

            if (character.getIsBastard())
            {
                writer.WriteLine("\tadd_trait=\"bastard\"");
            }

            if (character.getFather() != null)
            {
                writer.WriteLine("\tfather=" + character.getFather().getID());
            }

            writer.WriteLine("\t" + yob + "." + mob + "." + dob + "={");
            writer.WriteLine("\t\tbirth=yes");
            writer.WriteLine("\t}");

            if (character.getSpouse() != null)
            {
                DateTime maxBirthDT = maxBirth(character.getBirth(), character.getSpouse().getBirth());
                int      yom        = maxBirthDT.Year;
                int      mom        = maxBirthDT.Month + 1;
                int      dom        = maxBirthDT.Day + 1;
                writer.WriteLine("\t" + yom + "." + mom + "." + dom + "={");
                writer.WriteLine("\t\tadd_spouse=" + character.getSpouse().getID());
                writer.WriteLine("\t}");
            }

            if (character.getAlive() == false)
            {
                int dod = character.getDeathDay();
                int mod = character.getDeathMonth();
                int yod = character.getDeathYear();
                writer.WriteLine("\t" + yod + "." + mod + "." + dod + "={");
                writer.WriteLine("\t\tdeath=yes");
                writer.WriteLine("\t}");
            }

            writer.WriteLine("}");
        }
Пример #16
0
 public void setOwner(CK2Character owner)
 {
     this.owner = owner;
 }
Пример #17
0
        public void updateReligion(CK2Character character, bool canOverwrite)
        {
            HashSet <int> processed = new HashSet <int>();

            updateReligionForCharacter(character, canOverwrite, processed);
        }
Пример #18
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);
            }
        }
Пример #19
0
 public void setFather(CK2Character father)
 {
     this.father = father;
 }
Пример #20
0
 public void incrementBirthDay(CK2Character character)
 {
     this.birth = character.getBirth().AddDays(1);
 }