From dd9855943eb46559584af55e6a5e9a56e61bd7ec Mon Sep 17 00:00:00 2001 From: Steve Sharp Date: Sun, 8 Sep 2024 17:20:12 +0100 Subject: [PATCH] Turnur based routing as an option --- EVEData/EveManager.cs | 114 +++++++++++++++++++++++++++++++++ EVEData/LocalCharacter.cs | 38 ++++++++++- EVEData/Navigation.cs | 105 ++++++++++++++++++++---------- EVEData/TurnurConnection.cs | 54 ++++++++++++++++ SMT/CharactersWindow.xaml | 1 + SMT/MainWindow.xaml | 99 +++++++++++++++++++--------- SMT/MainWindow.xaml.cs | 41 +++++++++++- SMT/RegionControl.xaml.cs | 64 ++++++++++++++++-- SMT/RegionsViewControl.xaml | 4 +- SMT/RegionsViewControl.xaml.cs | 100 +++++++++++++++++++++++------ 10 files changed, 523 insertions(+), 97 deletions(-) create mode 100644 EVEData/TurnurConnection.cs diff --git a/EVEData/EveManager.cs b/EVEData/EveManager.cs index dee804d7..5851769e 100644 --- a/EVEData/EveManager.cs +++ b/EVEData/EveManager.cs @@ -208,6 +208,18 @@ public static EveManager Instance /// public event TheraUpdatedHandler TheraUpdateEvent; + + /// + /// Turnur Connections Updated Event Handler + /// + public delegate void TurnurUpdatedHandler(); + + /// + /// Turnur Updated Added Events + /// + public event TurnurUpdatedHandler TurnurUpdateEvent; + + /// /// Storms Updated Event Handler /// @@ -327,6 +339,12 @@ public static EveManager Instance /// public List TheraConnections { get; set; } + /// + /// Gets or sets the current list of Turnur connections + /// + public List TurnurConnections { get; set; } + + public bool UseESIForCharacterPositions { get; set; } public List MetaliminalStorms { get; set; } @@ -2354,6 +2372,89 @@ public async void UpdateTheraConnections() } } + /// + /// Update the current Turnur Connections from EVE-Scout + /// + public async void UpdateTurnurConnections() + { + string turnurApiURL = "https://api.eve-scout.com/v2/public/signatures?system_name=Turnur"; + string strContent = string.Empty; + + try + { + HttpClient hc = new HttpClient(); + var response = await hc.GetAsync(turnurApiURL); + response.EnsureSuccessStatusCode(); + strContent = await response.Content.ReadAsStringAsync(); + + JsonTextReader jsr = new JsonTextReader(new StringReader(strContent)); + + TurnurConnections.Clear(); + + /* + new format + + "id": "46", + "created_at": "2023-12-02T11:24:49.000Z", + "created_by_id": 93027866, + "created_by_name": "Das d'Alembert", + "updated_at": "2023-12-02T11:27:01.000Z", + "updated_by_id": 93027866, + "updated_by_name": "Das d'Alembert", + "completed_at": "2023-12-02T11:27:01.000Z", + "completed_by_id": 93027866, + "completed_by_name": "Das d'Alembert", + "completed": true, + "wh_exits_outward": true, + "wh_type": "Q063", + "max_ship_size": "medium", + "expires_at": "2023-12-03T04:24:49.000Z", + "remaining_hours": 14, + "signature_type": "wormhole", + "out_system_id": 31000005, + "out_system_name": "Thera", + "out_signature": "HMM-222", + "in_system_id": 30001715, + "in_system_class": "hs", + "in_system_name": "Moutid", + "in_region_id": 10000020, + "in_region_name": "Tash-Murkon", + "in_signature": "LPI-677" + */ + + while (jsr.Read()) + { + if (jsr.TokenType == JsonToken.StartObject) + { + JObject obj = JObject.Load(jsr); + string inSignatureId = obj["in_signature"].ToString(); + string outSignatureId = obj["out_signature"].ToString(); + long solarSystemId = long.Parse(obj["in_system_id"].ToString()); + string wormHoleEOL = obj["expires_at"].ToString(); + string type = obj["signature_type"].ToString(); + + if (type != null && type == "wormhole" && solarSystemId != 0 && wormHoleEOL != null && SystemIDToName.ContainsKey(solarSystemId)) + { + System turnurConnectionSystem = GetEveSystemFromID(solarSystemId); + + TurnurConnection tc = new TurnurConnection(turnurConnectionSystem.Name, turnurConnectionSystem.Region, inSignatureId, outSignatureId, wormHoleEOL); + TurnurConnections.Add(tc); + } + } + } + } + catch + { + return; + } + + if (TurnurUpdateEvent != null) + { + TurnurUpdateEvent(); + } + } + + public void UpdateMetaliminalStorms() { MetaliminalStorms.Clear(); @@ -2567,6 +2668,7 @@ private void Init() LoadCharacters(); InitTheraConnections(); + InitTurnurConnections(); InitMetaliminalStorms(); InitFactionWarfareInfo(); @@ -2638,6 +2740,17 @@ private void InitTheraConnections() UpdateTheraConnections(); } + /// + /// Initialise the Turnur Connection Data from EVE-Scout + /// + private void InitTurnurConnections() + { + TurnurConnections = new List(); + UpdateTurnurConnections(); + } + + + /// /// Initialise the Zarzakh Connection Data /// @@ -3167,6 +3280,7 @@ private void StartBackgroundThread() UpdateESIUniverseData(); UpdateServerInfo(); UpdateTheraConnections(); + UpdateTurnurConnections(); } if ((NextDotlanUpdate - DateTime.Now).Minutes < 0) diff --git a/EVEData/LocalCharacter.cs b/EVEData/LocalCharacter.cs index acffc22f..b3417c61 100644 --- a/EVEData/LocalCharacter.cs +++ b/EVEData/LocalCharacter.cs @@ -49,6 +49,8 @@ public class LocalCharacter : Character, INotifyPropertyChanged private bool m_UseZarzakhRouting; + private bool m_UseTurnurRouting; + private bool m_isOnline; private bool m_ObservatoryDecloakWarningEnabled; @@ -420,6 +422,26 @@ public bool UseZarzakhRouting } } + public bool UseTurnurRouting + { + get + { + return m_UseTurnurRouting; + } + set + { + if (m_UseTurnurRouting == value) + { + return; + } + + m_UseTurnurRouting = value; + routeNeedsUpdate = true; + esiRouteNeedsUpdate = true; + OnPropertyChanged("UseTurnurRouting"); + } + } + public int DangerZoneRange { get; set; } @@ -778,12 +800,21 @@ private async void UpdateActiveRoute() // grab the simple list of thera connections List currentActiveTheraConnections = new List(); - foreach (TheraConnection tc in EveManager.Instance.TheraConnections) + foreach (TheraConnection tc in EveManager.Instance.TheraConnections.ToList()) { currentActiveTheraConnections.Add(tc.System); } Navigation.UpdateTheraConnections(currentActiveTheraConnections); + // grab the simple list of turnur connections + List currentActiveTurnurConnections = new List(); + foreach (TurnurConnection tc in EveManager.Instance.TurnurConnections.ToList()) + { + currentActiveTurnurConnections.Add(tc.System); + } + Navigation.UpdateTurnurConnections(currentActiveTurnurConnections); + + lock (ActiveRouteLock) { if (Location == Waypoints[0]) @@ -800,7 +831,7 @@ private async void UpdateActiveRoute() start = end; end = Waypoints[i]; - List sysList = Navigation.Navigate(start, end, UseAnsiblexGates, UseTheraRouting, UseZarzakhRouting, NavigationMode); + List sysList = Navigation.Navigate(start, end, UseAnsiblexGates, UseTheraRouting, UseZarzakhRouting, UseTurnurRouting, NavigationMode); if (sysList != null) { @@ -829,7 +860,8 @@ private async void UpdateActiveRoute() // explicitly add interim waypoints for ansiblex gates or actual waypoints if ( rp.GateToTake == Navigation.GateType.Ansiblex || - rp.GateToTake == Navigation.GateType.Thera || + rp.GateToTake == Navigation.GateType.Thera || + rp.GateToTake == Navigation.GateType.Turnur || rp.GateToTake == Navigation.GateType.Zarzakh|| Waypoints.Contains(rp.SystemName) ) diff --git a/EVEData/Navigation.cs b/EVEData/Navigation.cs index 145f9490..3934801b 100644 --- a/EVEData/Navigation.cs +++ b/EVEData/Navigation.cs @@ -18,12 +18,16 @@ public enum GateType JumpTo, Thera, Zarzakh, + Turnur, } private static Dictionary MapNodes { get; set; } private static List TheraLinks { get; set; } private static List ZarzakhLinks { get; set; } + private static List TurnurLinks { get; set; } + + public static void ClearJumpBridges() { foreach (MapNode mn in MapNodes.Values) @@ -44,7 +48,15 @@ public static void ClearZarzakhConnections() { foreach (MapNode mn in MapNodes.Values) { - mn.ZarzakhConnection = null; + mn.ZarzakhConnections = null; + } + } + + public static void ClearTurnurConnections() + { + foreach (MapNode mn in MapNodes.Values) + { + mn.TurnurConnections = null; } } @@ -64,7 +76,22 @@ public static void UpdateZarzakhConnections(List zazahkSystems) foreach (string ts in zazahkSystems) { - MapNodes[ts].ZarzakhConnection = zazahkSystems; + MapNodes[ts].ZarzakhConnections = zazahkSystems; + } + } + + public static void UpdateTurnurConnections(List turnurSystems) + { + ClearTurnurConnections(); + + MapNodes["Turnur"].TurnurConnections = turnurSystems; + + List toTurnurConnections = new List(); + toTurnurConnections.Add("Turnur"); + + foreach (string ts in turnurSystems) + { + MapNodes[ts].TurnurConnections = toTurnurConnections; } } @@ -213,6 +240,9 @@ public static void InitNavigation(List eveSystems, List jump TheraLinks = new List(); ZarzakhLinks = new List(); + TurnurLinks = new List(); + + // build up the nav structures foreach (System sys in eveSystems) @@ -262,7 +292,7 @@ public static void InitNavigation(List eveSystems, List jump } } - public static List Navigate(string From, string To, bool UseJumpGates, bool UseThera, bool UseZarzakh, RoutingMode routingMode) + public static List Navigate(string From, string To, bool UseJumpGates, bool UseThera, bool UseZarzakh, bool UseTurnur, RoutingMode routingMode) { if (!(MapNodes.ContainsKey(From)) || !(MapNodes.ContainsKey(To)) || From == "" || To == "") @@ -380,9 +410,36 @@ public static List Navigate(string From, string To, bool UseJumpGate } } - if (UseZarzakh && CurrentNode.ZarzakhConnection != null) + if (UseTurnur && CurrentNode.TurnurConnections != null) { - foreach (string ZarzakhConnection in CurrentNode.ZarzakhConnection) + foreach (string turnurConnection in CurrentNode.TurnurConnections) + { + MapNode CMN = MapNodes[turnurConnection]; + + if (CMN.Visited) + continue; + + // dont jump back to the system we came from + if (CurrentNode.Name == turnurConnection) + continue; + + if (CMN.MinCostToStart == 0 || CurrentNode.MinCostToStart + CMN.Cost < CMN.MinCostToStart) + { + CMN.MinCostToStart = CurrentNode.MinCostToStart + CMN.Cost; + CMN.NearestToStart = CurrentNode; + if (!OpenList.Contains(CMN)) + { + OpenList.Add(CMN); + } + } + } + } + + + + if (UseZarzakh && CurrentNode.ZarzakhConnections != null) + { + foreach (string ZarzakhConnection in CurrentNode.ZarzakhConnections) { MapNode CMN = MapNodes[ZarzakhConnection]; @@ -462,10 +519,15 @@ public static List Navigate(string From, string To, bool UseJumpGate RP.GateToTake = GateType.Thera; } - if(UseZarzakh && mn.ZarzakhConnection != null && mn.ZarzakhConnection.Contains(Route[i + 1])) + if(UseZarzakh && mn.ZarzakhConnections != null && mn.ZarzakhConnections.Contains(Route[i + 1])) { RP.GateToTake = GateType.Zarzakh; } + + if (UseTurnur && mn.TurnurConnections != null && mn.TurnurConnections.Contains(Route[i + 1])) + { + RP.GateToTake = GateType.Turnur; + } } ActualRoute.Add(RP); } @@ -600,34 +662,7 @@ public static void UpdateJumpBridges(List jumpBridges) } } - public static void UpdateTheraInfo(List theraList) - { - TheraLinks.Clear(); - foreach (MapNode mapNode in MapNodes.Values) - { - mapNode.TheraInSig = string.Empty; - mapNode.TheraOutSig = string.Empty; - } - - foreach (TheraConnection tc in theraList) - { - MapNode mn = MapNodes[tc.System]; - mn.TheraInSig = tc.InSignatureID; - mn.TheraOutSig = tc.OutSignatureID; - - TheraLinks.Add(tc.System); - } - } - public static void UpdateZarzakhInfo(List zarzakhList) - { - ZarzakhLinks.Clear(); - - foreach (string zc in zarzakhList) - { - ZarzakhLinks.Add(zc); - } - } private struct JumpLink @@ -677,7 +712,9 @@ private class MapNode public double F; public string JBConnection; public List TheraConnections; - public List ZarzakhConnection; + public List ZarzakhConnections; + public List TurnurConnections; + public double MinCostToStart; public MapNode NearestToStart; public string TheraInSig; diff --git a/EVEData/TurnurConnection.cs b/EVEData/TurnurConnection.cs new file mode 100644 index 00000000..d0c76869 --- /dev/null +++ b/EVEData/TurnurConnection.cs @@ -0,0 +1,54 @@ +//----------------------------------------------------------------------- +// Turnur Connection +//----------------------------------------------------------------------- + +namespace SMT.EVEData +{ + /// + /// Represents a Connection into Turnur (sourced from Eve-Scout) + /// + public class TurnurConnection + { + /// + ///Initializes a new instance of the class. + /// + /// System + /// Region + /// In Signature ID + /// Out Signature ID + /// End of Life Status + public TurnurConnection(string sys, string region, string inID, string outID, string eol) + { + Region = region; + System = sys; + InSignatureID = inID; + OutSignatureID = outID; + EstimatedEOL = eol; + } + + /// + /// Gets or sets the Estimated End of Life status + /// + public string EstimatedEOL { get; set; } + + /// + /// Gets or sets the signature ID from the specified system into Turnur + /// + public string InSignatureID { get; set; } + + /// + /// Gets or sets the signature ID from Turnur to the specified system + /// + public string OutSignatureID { get; set; } + + /// + /// Gets or sets the region that this system is in + /// + public string Region { get; set; } + + /// + /// Gets or sets the system with the connection to Turnur + /// + public string System { get; set; } + } +} \ No newline at end of file diff --git a/SMT/CharactersWindow.xaml b/SMT/CharactersWindow.xaml index 394582f8..b3f59c88 100644 --- a/SMT/CharactersWindow.xaml +++ b/SMT/CharactersWindow.xaml @@ -128,6 +128,7 @@ + diff --git a/SMT/MainWindow.xaml b/SMT/MainWindow.xaml index 98e9954e..03993bae 100644 --- a/SMT/MainWindow.xaml +++ b/SMT/MainWindow.xaml @@ -35,7 +35,7 @@ - + @@ -220,7 +220,7 @@ - +