Пример #1
0
 public static void CalculateInterval(TitleType i_titleType)
 {
     DateTime begin = new DateTime(1, 1, 1);
     DateTime doom = new DateTime(1337, 1, 1);
     foreach (Title title in China.titles)
     {
         if (title.TitleType == i_titleType)
         {
             if (title.fictional)
             {
                 if (title.captial != null && title.captial.TitleType != TitleType.Baron && title.captial.TitleType != TitleType.Emporer)
                 {
                     bool isLiegeFound = false;
                     foreach (KeyValuePair<DateTime, DateTime> entry in title.captial.Intervals)
                     {
                         title.Intervals.Add(entry.Key, entry.Value);
                         if (!isLiegeFound)
                         {
                             isLiegeFound = true;
                             if (title.liege != null)
                             {
                                 title.lieges.Add(entry.Key, rootNode);
                             }
                         }
                         Person temp = new Person();
                         temp.id = 0;
                         if (entry.Value != doom)
                         {
                             title.history.Add(entry.Value, temp);
                         }
                     }
                 }
                 else
                 {
                     title.Intervals.Add(begin, doom);
                 }
             }
             else
             {
                 if (title.DateTimes.Count > 0)
                 {
                     bool isOn = false;
                     DateTime beginDateTime = new DateTime();
                     foreach (KeyValuePair<DateTime, string> entry in title.DateTimes)
                     {
                         if (entry.Value == rootNode)
                         {
                             isOn = true;
                             beginDateTime = entry.Key;
                         }
                         else
                         {
                             if (isOn)
                             {
                                 isOn = false;
                                 title.Intervals.Add(beginDateTime, entry.Key);
                             }
                         }
                     }
                 }
                 else
                 {
                     title.Intervals.Add(begin, doom);
                 }
             }
         }
     }
 }
Пример #2
0
        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;
        }
 public static Person GenPerson(Dynasty i_dynasty, Person i_father, DateTime i_beginDateTime, DateTime i_endDateTime)
 {
     Person person = new Person();
     if (i_beginDateTime > taoToConfucian)
     {
         person.religion = confucian;
     }
     else
     {
         person.religion = tao;
     }
     person.father = i_father;
     person.name = new Name();
     person.name.first = Name.RandomName();
     DateTime born = new DateTime(Rnd.rnd.Next(i_beginDateTime.Year -maxElectedAge, i_beginDateTime.Year - minElectedAge + 1), Rnd.rnd.Next(1, 13), Rnd.rnd.Next(1, 29));
     if (i_father != null)
     {
         DateTime fatherBorn = i_father.born;
         DateTime minBornTime = i_father.born.AddYears(adultYear);
         if (minBornTime > born)
         {
             born = new DateTime(Rnd.rnd.Next(minBornTime.Year + 1, minBornTime.Year + 1 + 5), Rnd.rnd.Next(1, 13), Rnd.rnd.Next(1, 29));
             born = new DateTime(Math.Min(born.Ticks, i_father.die.AddDays(-1).Ticks));
             born = new DateTime(Math.Min(born.Ticks, i_beginDateTime.AddYears(-16).Ticks));
         }
         i_father.children.Add(person);
     }
     DateTime maxTime = born.AddYears(maxDeathTime);
     DateTime die = new DateTime(Rnd.rnd.Next(i_endDateTime.Year, maxTime.Year + 1), Rnd.rnd.Next(1, 13), Rnd.rnd.Next(1, 29));
     die = new DateTime(Math.Max(die.Ticks, i_endDateTime.AddDays(1).Ticks));
     Debug.Assert(i_father == null || born < i_father.die);
     Debug.Assert(born.AddYears(adultYear) <= i_beginDateTime);
     Debug.Assert(die >= i_endDateTime);
     person.born = born;
     person.die = die;
     if (Rnd.rnd.Next(0, 4) == 0)
     {
         person.name.middle = "";
     }
     else
     {
         person.name.middle = Name.RandomName();
     }
     person.name.dynasty = i_dynasty;
     person.id = personIdBase + personNum;
     China.people.Add(person);
     personNum++;
     return person;
 }