Skip to content

Commit

Permalink
Fixed ship routes reporting wrong jump distances.
Browse files Browse the repository at this point in the history
Resolves #2591
Bring route tracking inside NavWaypointCollection so that each collection can independently track route progress.
  • Loading branch information
Tkael committed Mar 17, 2024
1 parent f4a652f commit ca9171a
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 580 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public class NavigationMonitorConfiguration : Config
public ObservableCollection<NavBookmark> bookmarks { get; set; } = new ObservableCollection<NavBookmark>();

// Current in-game route
public NavWaypointCollection navRouteList { get; set; } = new NavWaypointCollection();
public NavWaypointCollection navRouteList { get; set; } = new NavWaypointCollection(null, true);

// Plotted routes
public NavWaypointCollection plottedRouteList { get; set; } = new NavWaypointCollection();
public NavWaypointCollection carrierPlottedRoute { get; set; } = new NavWaypointCollection(null, true);

public NavWaypointCollection carrierPlottedRoute { get; set; } = new NavWaypointCollection();
public NavWaypointCollection plottedRouteList { get; set; } = new NavWaypointCollection();
}
}
29 changes: 14 additions & 15 deletions DataDefinitions/NavWaypointCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,27 @@ public int? RouteFuelTotal
private decimal? currentZ;

[JsonConstructor]
public NavWaypointCollection()
public NavWaypointCollection (IEnumerable<NavWaypoint> items = null, bool fillVisitedGaps = false)
{
Waypoints.CollectionChanged += NavWaypointList_CollectionChanged;
}
if ( items != null )
{
foreach ( var item in items )
{
Waypoints.Add( item );
}
CalculateFuelUsed();
CalculateRouteDistances();
}

public NavWaypointCollection(bool fillVisitedGaps = false)
{
FillVisitedGaps = fillVisitedGaps;
Waypoints.CollectionChanged += NavWaypointList_CollectionChanged;
}

public NavWaypointCollection(IEnumerable<NavWaypoint> items, bool fillVisitedGaps = false)
public NavWaypointCollection ( decimal x, decimal y, decimal z )
{
foreach (var item in items)
{
Waypoints.Add(item);
}

CalculateFuelUsed();
CalculateRouteDistances();

FillVisitedGaps = fillVisitedGaps;
currentX = x;
currentY = y;
currentZ = z;
Waypoints.CollectionChanged += NavWaypointList_CollectionChanged;
}

Expand Down
1 change: 1 addition & 0 deletions EDDI/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Full details of the variables available for each noted event, and VoiceAttack in
* EDDI will no longer report your environment as "Supercruise" right after a Thargoid hyperdiction. (#2597)
* Navigation Monitor
* Improved route guidance updates.
* Fixed ship routes reporting wrong jump distances. (#2591)
* Speech Responder
* Functions
* `Play()` now supports relative file system paths. (#2581)
Expand Down
118 changes: 57 additions & 61 deletions NavigationMonitor/NavigationMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,66 +143,62 @@ public void HandleProfile(JObject profile)

public void PreHandle(Event @event)
{
if (@event.timestamp >= updateDat)
// Handle the events that we care about
if (@event is CarrierJumpRequestEvent carrierJumpRequestEvent)
{
// Handle the events that we care about

if (@event is CarrierJumpRequestEvent carrierJumpRequestEvent)
{
handleCarrierJumpRequestEvent(carrierJumpRequestEvent);
}
else if (@event is CarrierJumpCancelledEvent carrierJumpCancelledEvent)
{
handleCarrierJumpCancelledEvent(carrierJumpCancelledEvent);
}
else if (@event is CarrierJumpedEvent carrierJumpedEvent)
{
handleCarrierJumpedEvent(carrierJumpedEvent);
}
else if (@event is CarrierJumpEngagedEvent carrierJumpEngagedEvent)
{
handleCarrierJumpEngagedEvent(carrierJumpEngagedEvent);
}
else if (@event is CarrierPurchasedEvent carrierPurchasedEvent)
{
handleCarrierPurchasedEvent(carrierPurchasedEvent);
}
else if (@event is CarrierStatsEvent carrierStatsEvent)
{
handleCarrierStatsEvent(carrierStatsEvent);
}
else if (@event is CommodityPurchasedEvent commodityPurchasedEvent)
{
handleCommodityPurchasedEvent(commodityPurchasedEvent);
}
else if (@event is CommoditySoldEvent commoditySoldEvent)
{
handleCommoditySoldEvent(commoditySoldEvent);
}
else if (@event is DockedEvent dockedEvent)
{
handleDockedEvent(dockedEvent);
}
else if (@event is JumpedEvent jumpedEvent)
{
handleJumpedEvent(jumpedEvent);
}
else if (@event is LocationEvent locationEvent)
{
handleLocationEvent(locationEvent);
}
else if (@event is NavRouteEvent navRouteEvent)
{
handleNavRouteEvent(navRouteEvent);
}
else if (@event is RouteDetailsEvent routeDetailsEvent)
{
handleRouteDetailsEvent(routeDetailsEvent);
}
else if (@event is FSDTargetEvent fsdTargetEvent)
{
handleFSDTargetEvent(fsdTargetEvent);
}
handleCarrierJumpRequestEvent(carrierJumpRequestEvent);
}
else if (@event is CarrierJumpCancelledEvent carrierJumpCancelledEvent)
{
handleCarrierJumpCancelledEvent(carrierJumpCancelledEvent);
}
else if (@event is CarrierJumpedEvent carrierJumpedEvent)
{
handleCarrierJumpedEvent(carrierJumpedEvent);
}
else if (@event is CarrierJumpEngagedEvent carrierJumpEngagedEvent)
{
handleCarrierJumpEngagedEvent(carrierJumpEngagedEvent);
}
else if (@event is CarrierPurchasedEvent carrierPurchasedEvent)
{
handleCarrierPurchasedEvent(carrierPurchasedEvent);
}
else if (@event is CarrierStatsEvent carrierStatsEvent)
{
handleCarrierStatsEvent(carrierStatsEvent);
}
else if (@event is CommodityPurchasedEvent commodityPurchasedEvent)
{
handleCommodityPurchasedEvent(commodityPurchasedEvent);
}
else if (@event is CommoditySoldEvent commoditySoldEvent)
{
handleCommoditySoldEvent(commoditySoldEvent);
}
else if (@event is DockedEvent dockedEvent)
{
handleDockedEvent(dockedEvent);
}
else if (@event is JumpedEvent jumpedEvent)
{
handleJumpedEvent(jumpedEvent);
}
else if (@event is LocationEvent locationEvent)
{
handleLocationEvent(locationEvent);
}
else if (@event is NavRouteEvent navRouteEvent)
{
handleNavRouteEvent(navRouteEvent);
}
else if (@event is RouteDetailsEvent routeDetailsEvent)
{
handleRouteDetailsEvent(routeDetailsEvent);
}
else if (@event is FSDTargetEvent fsdTargetEvent)
{
handleFSDTargetEvent(fsdTargetEvent);
}
}

Expand Down Expand Up @@ -635,11 +631,11 @@ private void ReadNavConfig()
GetBookmarkExtras(Bookmarks);

// Restore our in-game routing
NavRoute = navConfig.navRouteList ?? new NavWaypointCollection(true);
NavRoute = navConfig.navRouteList ?? new NavWaypointCollection(null, true);

// Restore our plotted routes
CarrierPlottedRoute = navConfig.carrierPlottedRoute ?? new NavWaypointCollection(null, true);
PlottedRoute = navConfig.plottedRouteList ?? new NavWaypointCollection();
CarrierPlottedRoute = navConfig.carrierPlottedRoute ?? new NavWaypointCollection(true);

// Misc
updateDat = navConfig.updatedat;
Expand Down
6 changes: 4 additions & 2 deletions NavigationService/IQueryResolver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using EddiEvents;
using EddiDataDefinitions;
using EddiEvents;
using JetBrains.Annotations;

namespace EddiNavigationService
{
public interface IQueryResolver
{
QueryType Type { get; }
RouteDetailsEvent Resolve ( Query query );
RouteDetailsEvent Resolve ( [NotNull] Query query, [NotNull] StarSystem startSystem );
}
}
30 changes: 29 additions & 1 deletion NavigationService/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,38 @@ public RouteDetailsEvent NavQuery(QueryType queryType, string stringArg0 = null,
// Resolve the current search query
if ( queryResolvers.ContainsKey( queryType ) )
{
if ( EDDI.Instance.CurrentStarSystem == null )
{
Logging.Debug( "Could not resolve navigation query: current star system is unknown." );
return null;
}

foreach ( var resolver in queryResolvers
.Where( resolver => resolver.Key == queryType ) )
{
result = resolver.Value.Resolve( query );
if ( queryType == QueryType.carrier )
{
var fleetCarrier = EDDI.Instance.FleetCarrier;
if ( fleetCarrier is null )
{
Logging.Warn( "Invalid query: no fleet carrier found." );
return null;
}
else
{
var carrierLocation = StarSystemSqLiteRepository.Instance.GetOrFetchStarSystem( fleetCarrier.currentStarSystem );
if ( carrierLocation is null )
{
Logging.Warn("Invalid query: unable to find fleet carrier location.");
return null;
}
result = resolver.Value.Resolve( query, carrierLocation );
}
}
else
{
result = resolver.Value.Resolve( query, EDDI.Instance.CurrentStarSystem );
}
break;
}
}
Expand Down
Loading

0 comments on commit ca9171a

Please sign in to comment.