예제 #1
0
        private void ReadLeaders()
        {
            while (LeaderStart())
            {
                string leaderType = Formatting.InitCaps(_currentLine.Substring(1, _currentLine.IndexOf("List") - 2));
                _currentCiv.LeaderTypes.Add(leaderType);
                _currentCiv.Leaders.Add(new List <HistoricalFigure>());
                ReadLine();
                while (_currentLine != null && _currentLine.StartsWith("  "))
                {
                    if (_currentLine.Contains("[*]"))
                    {
                        string           leaderName = Formatting.ReplaceNonAscii(_currentLine.Substring(_currentLine.IndexOf("[*]") + 4, _currentLine.IndexOf("(b") - _currentLine.IndexOf("[*]") - 5));
                        HistoricalFigure leader     = null;
                        try
                        {
                            leader = _world.GetHistoricalFigure(leaderName);
                        }
                        catch (Exception e)
                        {
                            leader = _world.HistoricalFigures.FirstOrDefault(hf =>
                                                                             string.Compare(hf.Name, leaderName, StringComparison.OrdinalIgnoreCase) == 0);
                            if (leader == null)
                            {
                                _log.AppendLine(e.Message + ", a Leader of " + _currentCiv.Name);
                                ReadLine();
                                continue;
                            }
                        }

                        int reignBegan = Convert.ToInt32(_currentLine.Substring(_currentLine.IndexOf(":") + 2, _currentLine.IndexOf("), ") - _currentLine.IndexOf(":") - 2));
                        if (_currentCiv.Leaders[_currentCiv.LeaderTypes.Count - 1].Count > 0) //End of previous leader's reign
                        {
                            _currentCiv.Leaders[_currentCiv.LeaderTypes.Count - 1].Last().Positions.Last().Ended = reignBegan - 1;
                        }

                        if (leader.Positions.Count > 0 && leader.Positions.Last().Ended == -1) //End of leader's last leader position (move up rank etc.)
                        {
                            HistoricalFigure.Position lastPosition = leader.Positions.Last();
                            lastPosition.Ended  = reignBegan;
                            lastPosition.Length = lastPosition.Began - reignBegan;
                        }
                        HistoricalFigure.Position newPosition = new HistoricalFigure.Position(_currentCiv, reignBegan, -1, leaderType);
                        if (leader.DeathYear != -1)
                        {
                            newPosition.Ended  = leader.DeathYear;
                            newPosition.Length = leader.DeathYear - newPosition.Ended;
                        }
                        else
                        {
                            newPosition.Length = _world.Events.Last().Year - newPosition.Began;
                        }

                        leader.Positions.Add(newPosition);
                        _currentCiv.Leaders[_currentCiv.LeaderTypes.Count - 1].Add(leader);
                    }
                    ReadLine();
                }
            }
        }
예제 #2
0
        private void ReadLeaders()
        {
            while (LeaderStart())
            {
                string leaderType = Formatting.InitCaps(_currentLine.Substring(1, _currentLine.IndexOf("List", StringComparison.Ordinal) - 2));
                _currentCiv?.LeaderTypes.Add(leaderType);
                _currentCiv?.Leaders.Add(new List <HistoricalFigure>());
                ReadLine();
                while (_currentLine != null && _currentLine.StartsWith("  "))
                {
                    if (_currentCiv != null && _currentLine.Contains("[*]"))
                    {
                        string leaderName = Formatting.ReplaceNonAscii(_currentLine.Substring(_currentLine.IndexOf("[*]", StringComparison.Ordinal) + 4,
                                                                                              _currentLine.IndexOf("(b", StringComparison.Ordinal) - _currentLine.IndexOf("[*]", StringComparison.Ordinal) - 5));
                        var leaders = _world.HistoricalFigures.Where(hf =>
                                                                     string.Compare(hf.Name, leaderName.Replace("'", "`"), StringComparison.OrdinalIgnoreCase) == 0).ToList();
                        if (leaders.Count == 1)
                        {
                            var leader     = leaders.First();
                            int reignBegan = Convert.ToInt32(_currentLine.Substring(_currentLine.IndexOf(":", StringComparison.Ordinal) + 2,
                                                                                    _currentLine.IndexOf("), ", StringComparison.Ordinal) - _currentLine.IndexOf(":", StringComparison.Ordinal) - 2));
                            if (_currentCiv.Leaders[_currentCiv.LeaderTypes.Count - 1].Count > 0) //End of previous leader's reign
                            {
                                _currentCiv.Leaders[_currentCiv.LeaderTypes.Count - 1].Last().Positions.Last().Ended = reignBegan - 1;
                            }

                            if (leader.Positions.Count > 0 && leader.Positions.Last().Ended == -1) //End of leader's last leader position (move up rank etc.)
                            {
                                HistoricalFigure.Position lastPosition = leader.Positions.Last();
                                lastPosition.Ended  = reignBegan;
                                lastPosition.Length = lastPosition.Began - reignBegan;
                            }
                            HistoricalFigure.Position newPosition = new HistoricalFigure.Position(_currentCiv, reignBegan, -1, leaderType);
                            if (leader.DeathYear != -1)
                            {
                                newPosition.Ended  = leader.DeathYear;
                                newPosition.Length = leader.DeathYear - newPosition.Ended;
                            }
                            else
                            {
                                newPosition.Length = _world.Events.Last().Year - newPosition.Began;
                            }

                            leader.Positions.Add(newPosition);
                            _currentCiv.Leaders[_currentCiv.LeaderTypes.Count - 1].Add(leader);
                        }
                        else if (leaders.Count == 0)
                        {
                            _world.ParsingErrors.Report($"Couldn\'t Find Leader:\n{leaderName}, Leader of {_currentCiv.Name}");
                        }
#if DEBUG
                        else
                        {
                            _world.ParsingErrors.Report($"Ambiguous ({leaders.Count}) Leader Name:\n{leaderName}, Leader of {_currentCiv.Name}");
                        }
#endif
                    }
                    ReadLine();
                }
            }
        }