diff options
author | Julien Dessaux | 2024-05-24 00:29:04 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-05-24 00:29:04 +0200 |
commit | d0f6c4343e9b781d4cf603337946ab83d67ce3f1 (patch) | |
tree | 79a9ae3cabaf48b9679903ad365479d8786d9bfe /nodejs/lib | |
parent | [node] factorize sortByPrice (diff) | |
download | spacetraders-d0f6c4343e9b781d4cf603337946ab83d67ce3f1.tar.gz spacetraders-d0f6c4343e9b781d4cf603337946ab83d67ce3f1.tar.bz2 spacetraders-d0f6c4343e9b781d4cf603337946ab83d67ce3f1.zip |
[node] send probes to visit all markets
Diffstat (limited to '')
-rw-r--r-- | nodejs/lib/utils.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/nodejs/lib/utils.ts b/nodejs/lib/utils.ts index 9491583..a5bb142 100644 --- a/nodejs/lib/utils.ts +++ b/nodejs/lib/utils.ts @@ -3,7 +3,7 @@ import { } from './api.ts'; import { PriorityQueue } from './priority_queue.ts'; import { getShips } from './ships.ts'; -import { market } from './systems.ts'; +import { market, trait } from './systems.ts'; import { Cargo, CargoManifest, @@ -25,6 +25,19 @@ type Price = { price: number; }; +export async function are_we_done_visiting_all_markets(): Promise<boolean> { + const marketplaceWaypoints = await trait(getShips()[0].nav.systemSymbol, 'MARKETPLACE'); + let done = true; + for (const w of marketplaceWaypoints) { + const marketplaceData = await market(w); + if (marketplaceData.tradeGoods !== undefined) continue; + if (is_there_a_ship_at_this_waypoint(w)) continue; + done = false; + break; + } + return done; +} + // cargo is a ship.cargo object, want is an optional symbol export function categorizeCargo(cargo: Cargo, want?: string): CategorizedCargo { const wanted = cargo.inventory.filter(i => i.symbol === want || i.symbol === 'ANTIMATTER'); |