Beispiel #1
0
 public static void BuildVassal(Title i_liege, Title i_vassal)
 {
     Debug.Assert(i_liege != null, "liege is null");
     Debug.Assert(i_vassal != null, "vassal is null");
     if (i_liege != null && i_vassal != null)
     {
         i_liege.vassals.Add(i_vassal);
         i_vassal.liege = i_liege;
     }
 }
        static bool ParseTitle(StringReader i_sr, Title i_parent)
        {
            Reader.ReadSpaces(i_sr);
            if (!Reader.ReadAToken(i_sr, '{'))
            {
                Debug.Assert(false, "A token '{' expected");
                return false;
            }
            Reader.ReadSpaces(i_sr);
            while (i_sr.Peek() != '}')
            {
                Reader.ReadSpaces(i_sr);
                string key;
                if (!Reader.ReadAKey(i_sr, out key))
                {
                    Debug.Assert(false, "A key expected");
                    return false;
                }

                Reader.ReadSpaces(i_sr);
                if (!Reader.ReadAToken(i_sr, '='))
                {
                    Debug.Assert(false, "A token '=' expected");
                    return false;
                }
                Reader.ReadSpaces(i_sr);
                if (Title.IsTitle(key))
                {
                    Title title = new Title();
                    title.name = key;
                    Title.BuildVassal(i_parent, title);
                    China.titles.Add(title);
                    ParseTitle(i_sr, title);
                }
                else
                {
                    Reader.ReadValue(i_sr);
                }
                Reader.ReadSpaces(i_sr);

            }
            if (!Reader.ReadAToken(i_sr, '}'))
            {
                Debug.Assert(false, "A token '}' expected");
                return false;
            }
            return true;
        }
 public static void GenCharacter(Title title, DateTime i_beginDateTime, DateTime i_endDateTime)
 {
     Dynasty dynasty = GenDynasty();
     DateTime currentDateTime = i_beginDateTime;
     Person father = null;
     while (currentDateTime < i_endDateTime)
     {
         int intervalYears = Rnd.rnd.Next(minInterval, maxInterval + 1);
         DateTime afterTime = new DateTime(currentDateTime.Year + intervalYears, Rnd.rnd.Next(1, 13), Rnd.rnd.Next(1, 29));
         Person person = GenPerson(dynasty, father, currentDateTime, afterTime);
         title.history.Add(currentDateTime, person);
         currentDateTime = afterTime;
         father = person;
     }
     dynastyNum++;
 }
        static bool ParseHistory(StringReader i_sr, Title title, DateTime DateTime, ref bool isChina, ref bool isEmpty)
        {
            Reader.ReadSpaces(i_sr);
            if (!Reader.ReadAToken(i_sr, '{'))
            {
                Debug.Assert(false, "A token '{' expected");
                return false;
            }
            Reader.ReadSpaces(i_sr);
            while (i_sr.Peek() != '}')
            {
                Reader.ReadSpaces(i_sr);
                string key;
                if (!Reader.ReadAKey(i_sr, out key))
                {
                    Debug.Assert(false, "A key expected");
                    return false;
                }

                Reader.ReadSpaces(i_sr);
                if (!Reader.ReadAToken(i_sr, '='))
                {
                    Debug.Assert(false, "A token '=' expected");
                    return false;
                }
                Reader.ReadSpaces(i_sr);
                Debug.Assert(key == liege || key == holder);
                if (key == liege)
                {
                    if (i_sr.Peek() == '"')
                    {
                        string strliege;
                        if (!Reader.ReadAString(i_sr, out strliege))
                        {
                            Debug.Assert(false, "A string expected");
                        }
                        if (!title.DateTimes.ContainsKey(DateTime))
                        {
                            title.DateTimes.Add(DateTime, strliege);
                        }
                        isChina = strliege == rootTitle;
                        if (strliege == rootTitle && title.liege != null)
                        {
                            if (title.TitleType == TitleType.Count)
                            {
                                title.lieges.Add(DateTime, title.liege.name);
                            }
                            else
                            {
                                title.lieges.Add(DateTime, rootTitle);
                            }
                        }
                        else
                        {
                            title.lieges.Add(DateTime, strliege);
                        }
                    }
                    else
                    {
                        string strliege;
                        if (!Reader.ReadAKey(i_sr, out strliege))
                        {
                            Debug.Assert(false, "A key expected");
                        }
                        if (!title.DateTimes.ContainsKey(DateTime))
                        {
                            title.DateTimes.Add(DateTime, "");
                        }
                        title.lieges.Add(DateTime, "0");
                    }
                }
                else if (key == holder)
                {
                    string strholder;
                    if (!Reader.ReadAKey(i_sr, out strholder))
                    {
                        Debug.Assert(false, "A key expected");
                    }
                    int id = Int32.Parse(strholder);
                    if (id == 0)
                    {
                        if (!title.DateTimes.ContainsKey(DateTime))
                        {
                            title.DateTimes.Add(DateTime, "");
                        }
                        Person person = new Person();
                        person.id = id;
                        title.history.Add(DateTime, person);
                        isEmpty = true;
                    }
                    else
                    {
                        if (isEmpty)
                        {
                            KeyValuePair<DateTime, string> lastTwoKeyValuePair = title.DateTimes.ElementAt(title.DateTimes.Count - 2);
                            isChina = lastTwoKeyValuePair.Value == rootTitle;
                            if (isChina)
                            {
                                if (!title.DateTimes.ContainsKey(DateTime))
                                {
                                    title.DateTimes.Add(DateTime, rootTitle);
                                }
                            }
                            isEmpty = false;
                        }
                        if (!isChina)
                        {
                            Person person = new Person();
                            person.id = id;
                            title.history.Add(DateTime, person);
                        }
                    }
                }
                else
                {
                    Reader.ReadValue(i_sr);
                }
                Reader.ReadSpaces(i_sr);

            }
            if (!Reader.ReadAToken(i_sr, '}'))
            {
                Debug.Assert(false, "A token '}' expected");
                return false;
            }
            return true;
        }
        static bool ParseHistoryFile(string i_content, Title title)
        {
            bool isChina = false;
            bool isEmpty = false;
            DateTime doom = new DateTime(1337,1,1);
            using (StringReader sr = new StringReader(i_content))
            {
                while (sr.Peek() != -1)
                {
                    Reader.ReadSpaces(sr);
                    DateTime DateTime;
                    if (!Reader.ReadADateTime(sr, out DateTime))
                    {
                        Debug.Assert(false, "A DateTime expected");
                        return false;
                    }
                    Reader.ReadSpaces(sr);
                    if (!Reader.ReadAToken(sr, '='))
                    {
                        Debug.Assert(false, "A token '=' expected");
                        return false;
                    }
                    Reader.ReadSpaces(sr);
                    ParseHistory(sr, title, DateTime, ref isChina, ref isEmpty);
                    Reader.ReadSpaces(sr);
                }

                title.DateTimes.Add(doom, "");
            }
            return true;
        }
 static bool ParseTitleFile(string i_content)
 {
     using (StringReader sr = new StringReader(i_content))
     {
         while (sr.Peek() != -1)
         {
             Reader.ReadSpaces(sr);
             string key;
             if (!Reader.ReadAKey(sr, out key))
             {
                 Debug.Assert(false, "A key expected");
                 return false;
             }
             Reader.ReadSpaces(sr);
             if (!Reader.ReadAToken(sr, '='))
             {
                 Debug.Assert(false, "A token '=' expected");
                 return false;
             }
             Reader.ReadSpaces(sr);
             if (key == rootTitle)
             {
                 Title root = new Title();
                 root.name = rootTitle;
                 China.titles.Add(root);
                 ParseTitle(sr, root);
             }
             else
             {
                 Reader.ReadValue(sr);
             }
             Reader.ReadSpaces(sr);
         }
     }
     return true;
 }