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) { 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(); } } }
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) { 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(); } } }