From 062544bd9b04568430b44c7c436dc7cb04e34e53 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Sun, 25 Feb 2024 20:09:34 +0000 Subject: [PATCH] fix: make deals_nearby respect active construction --- packages/cli/bin/deals_nearby.dart | 9 +++++--- .../cli/lib/behavior/central_command.dart | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/cli/bin/deals_nearby.dart b/packages/cli/bin/deals_nearby.dart index bf7729f7..4bc5326e 100644 --- a/packages/cli/bin/deals_nearby.dart +++ b/packages/cli/bin/deals_nearby.dart @@ -37,8 +37,11 @@ Future cliMain(FileSystem fs, Database db, ArgResults argResults) async { ? agentCache!.headquarters(systemsCache) : systemsCache.waypointFromString(startArg)!; - final jumpGate = systemsCache.jumpGateWaypointForSystem(start.system)!; - final construction = constructionSnapshot[jumpGate.symbol]; + final construction = await centralCommand.computeActiveConstruction( + db, + agentCache!, + systemsCache, + ); centralCommand.activeConstruction = construction; final exportCache = TradeExportCache.load(fs); @@ -57,7 +60,7 @@ Future cliMain(FileSystem fs, Database db, ArgResults argResults) async { final extraSellOpps = []; if (centralCommand.isContractTradingEnabled) { extraSellOpps - .addAll(centralCommand.contractSellOpps(agentCache!, contractSnapshot)); + .addAll(centralCommand.contractSellOpps(agentCache, contractSnapshot)); } if (centralCommand.isConstructionTradingEnabled) { extraSellOpps.addAll(centralCommand.constructionSellOpps()); diff --git a/packages/cli/lib/behavior/central_command.dart b/packages/cli/lib/behavior/central_command.dart index 33dce56e..6425e2e6 100644 --- a/packages/cli/lib/behavior/central_command.dart +++ b/packages/cli/lib/behavior/central_command.dart @@ -479,22 +479,27 @@ class CentralCommand { } } - Future _computeActiveConstruction(Caches caches) async { + /// Returns the active construction job, if any. + Future computeActiveConstruction( + Database db, + AgentCache agentCache, + SystemsCache systems, + ) async { if (!isConstructionTradingEnabled) { return null; } - if (caches.agent.agent.credits < config.constructionMinCredits) { + if (agentCache.agent.credits < config.constructionMinCredits) { return null; } - final systemSymbol = caches.agent.headquartersSystemSymbol; - final jumpGate = caches.systems.jumpGateWaypointForSystem(systemSymbol); + final systemSymbol = agentCache.headquartersSystemSymbol; + final jumpGate = systems.jumpGateWaypointForSystem(systemSymbol); if (jumpGate == null) { return null; } final construction = - await caches.construction.getConstruction(jumpGate.symbol); + await ConstructionCache(db).getConstruction(jumpGate.symbol); if (construction == null) { return null; } @@ -543,7 +548,11 @@ class CentralCommand { await updateAvailableMounts(db); await _queueMountRequests(caches); - activeConstruction = await _computeActiveConstruction(caches); + activeConstruction = await computeActiveConstruction( + db, + caches.agent, + caches.systems, + ); subsidizedSellOpps = []; if (isConstructionTradingEnabled && activeConstruction != null) { subsidizedSellOpps = await computeConstructionMaterialSubsidies(