private void Display() { DataGridViewColumn sortcol = dataGridViewFactions.SortedColumn != null ? dataGridViewFactions.SortedColumn : dataGridViewFactions.Columns[0]; SortOrder sortorder = dataGridViewFactions.SortOrder != SortOrder.None ? dataGridViewFactions.SortOrder : SortOrder.Ascending; string toprowfaction = dataGridViewFactions.SafeFirstDisplayedScrollingRowIndex() >= 0 ? (dataGridViewFactions.Rows[dataGridViewFactions.SafeFirstDisplayedScrollingRowIndex()].Tag as FactionStatistics).Name : ""; dataGridViewFactions.Rows.Clear(); List <MissionState> ml = discoveryform.history.MissionListAccumulator.GetMissionList(last_he?.MissionList ?? 0); DateTime startdateutc = startDateTime.Checked ? EDDConfig.Instance.ConvertTimeToUTCFromSelected(startDateTime.Value) : new DateTime(1980, 1, 1); DateTime enddateutc = endDateTime.Checked ? EDDConfig.Instance.ConvertTimeToUTCFromSelected(endDateTime.Value) : new DateTime(8999, 1, 1); var factionslist = new Dictionary <string, FactionStatistics>(); if (ml != null) { foreach (MissionState ms in ml) { bool withinstarttime = DateTime.Compare(ms.Mission.EventTimeUTC, startdateutc) >= 0 && DateTime.Compare(ms.Mission.EventTimeUTC, enddateutc) <= 0; bool withinexpirytime = ms.Mission.ExpiryValid && DateTime.Compare(ms.Mission.Expiry, startdateutc) >= 0 && DateTime.Compare(ms.Mission.Expiry, enddateutc) <= 0; bool withincompletetime = ms.Completed != null && DateTime.Compare(ms.Completed.EventTimeUTC, startdateutc) >= 0 && DateTime.Compare(ms.Completed.EventTimeUTC, enddateutc) <= 0; if (withinstarttime || withincompletetime) { var faction = ms.Mission.Faction; FactionStatistics factionStats; if (!factionslist.TryGetValue(faction, out factionStats)) { factionStats = new FactionStatistics(faction); factionslist.Add(faction, factionStats); } if (ms.Completed != null) // effects/rewards are dependent on completion { factionStats.AddMissions(1); // 1 more mission, if (ms.Completed.FactionEffects != null) { foreach (var fe in ms.Completed.FactionEffects) { if (fe.Faction == faction) { if (fe.ReputationTrend == "UpGood" && fe.Reputation?.Length > 0) { factionStats.AddReputation(fe.Reputation.Length); } foreach (var si in fe.Influence) { if (si.Trend == "UpGood" && si.Influence?.Length > 0) { factionStats.AddInfluence(si.Influence.Length); factionStats.AddSystemInfluence(si.SystemAddress, si.Influence.Length, ms.Completed.MissionId); } } } } } long credits = ms.Completed.Reward != null ? (long)ms.Completed.Reward : 0; if (credits > 0) { factionStats.AddCredits(credits); } if (ms.Completed.MaterialsReward != null) { foreach (var mr in ms.Completed.MaterialsReward) { factionStats.AddReward(mr.Name_Localised, mr.Count); } } if (ms.Completed.CommodityReward != null) { foreach (var cr in ms.Completed.CommodityReward) { factionStats.AddReward(cr.Name_Localised, cr.Count); } } } else if (withinexpirytime && ms.State == MissionState.StateTypes.InProgress) { factionStats.AddMissionsInProgress(1); } } } } Dictionary <string, Stats.FactionInfo> factioninfo = null; if (startDateTime.Checked || endDateTime.Checked) // if we have a date range, can't rely on stats accumulated automatically { Stats stats = new Stats(); // reprocess this list completely foreach (var he in HistoryList.FilterByDateRange(discoveryform.history.EntryOrder(), startdateutc, enddateutc)) { stats.Process(he.journalEntry, he.StationFaction); } factioninfo = stats.GetLastEntries(); // pick the last generation in there. } else { factioninfo = discoveryform.history.GetStatsAtGeneration(last_he?.Statistics ?? 0); } if (factioninfo != null) { foreach (var fkvp in factioninfo) { if (!factionslist.TryGetValue(fkvp.Value.Faction, out FactionStatistics factionStats)) { factionStats = new FactionStatistics(fkvp.Value.Faction); factionslist.Add(fkvp.Value.Faction, factionStats); } factionslist[fkvp.Value.Faction].AddFactionStats(fkvp.Value); } } if (factionslist.Count > 0) { var rows = new List <DataGridViewRow>(); foreach (FactionStatistics fs in factionslist.Values) { var info = ""; if (fs.MissionsInProgress > 0) { info = info.AppendPrePad("Missions In Progress:".T(EDTx.UserControlFactions_MissionsInProgress) + " " + fs.MissionsInProgress, ", "); } foreach (var reward in fs.Rewards.Values) { info = info.AppendPrePad(reward.Count + " " + reward.Name, ", "); } if (fs.FactionStats.CapShipAwardAsVictimFaction > 0) { info = info.AppendPrePad("Capital ship Victims: ".T(EDTx.UserControlFactions_CapShipVictims) + fs.FactionStats.CapShipAwardAsVictimFaction, ", "); } if (fs.FactionStats.CapShipAwardAsAwaringFaction > 0) { info = info.AppendPrePad("Capital ship Award: ".T(EDTx.UserControlFactions_CapShipAward) + fs.FactionStats.CapShipAwardAsAwaringFaction + ":" + fs.FactionStats.CapShipAwardAsAwaringFactionValue.ToString("N0") + "cr", ", "); } object[] rowobj = { fs.Name, fs.Missions.ToString("N0"), fs.Influence.ToString("N0"), fs.Reputation.ToString("N0"), fs.Credits.ToString("N0"), fs.FactionStats.BoughtCommodity.ToString("N0"), fs.FactionStats.SoldCommodity.ToString("N0"), fs.FactionStats.ProfitCommodity.ToString("N0"), fs.FactionStats.BoughtMaterial.ToString("N0"), fs.FactionStats.SoldMaterial.ToString("N0"), fs.FactionStats.CrimesAgainst.ToString("N0"), fs.FactionStats.BountyKill.ToString("N0"), fs.FactionStats.BountyRewards.ToString("N0"), fs.FactionStats.BountyRewardsValue.ToString("N0"), fs.FactionStats.Interdicted.ToString("N0"), fs.FactionStats.Interdiction.ToString("N0"), fs.FactionStats.KillBondAwardAsVictimFaction.ToString("N0"),fs.FactionStats.KillBondAwardAsAwaringFaction.ToString("N0"), fs.FactionStats.KillBondAwardAsAwaringFactionValue.ToString("N0"), info }; var row = dataGridViewFactions.RowTemplate.Clone() as DataGridViewRow; row.CreateCells(dataGridViewFactions, rowobj); row.Tag = fs; rows.Add(row); } dataGridViewFactions.Rows.AddRange(rows.ToArray()); dataGridViewFactions.Sort(sortcol, (sortorder == SortOrder.Descending) ? System.ComponentModel.ListSortDirection.Descending : System.ComponentModel.ListSortDirection.Ascending); dataGridViewFactions.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder; if (toprowfaction.HasChars()) { for (int i = 0; i < dataGridViewFactions.RowCount; i++) { var fs = dataGridViewFactions.Rows[i].Tag as FactionStatistics; if (fs.Name == toprowfaction) { dataGridViewFactions.SafeFirstDisplayedScrollingRowIndex(i); break; } } } } labelValue.Text = factionslist.Count + " " + "Factions".T(EDTx.UserControlFactions_FactionsPlural); }