Skip to content

Commit

Permalink
fix: make deals_nearby respect active construction
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Feb 25, 2024
1 parent f9d621e commit 062544b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
9 changes: 6 additions & 3 deletions packages/cli/bin/deals_nearby.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ Future<void> 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);
Expand All @@ -57,7 +60,7 @@ Future<void> cliMain(FileSystem fs, Database db, ArgResults argResults) async {
final extraSellOpps = <SellOpp>[];
if (centralCommand.isContractTradingEnabled) {
extraSellOpps
.addAll(centralCommand.contractSellOpps(agentCache!, contractSnapshot));
.addAll(centralCommand.contractSellOpps(agentCache, contractSnapshot));
}
if (centralCommand.isConstructionTradingEnabled) {
extraSellOpps.addAll(centralCommand.constructionSellOpps());
Expand Down
21 changes: 15 additions & 6 deletions packages/cli/lib/behavior/central_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -479,22 +479,27 @@ class CentralCommand {
}
}

Future<Construction?> _computeActiveConstruction(Caches caches) async {
/// Returns the active construction job, if any.
Future<Construction?> 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;
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 062544b

Please sign in to comment.