1
0
Fork 0

[javascript] Rework the contracting loop following the asteroids changes

This commit is contained in:
Julien Dessaux 2024-03-15 22:17:10 +01:00
parent 4c4e4cb98f
commit 01e3f05ea0
Signed by: adyxax
GPG key ID: F92E51B86E07177E
5 changed files with 30 additions and 20 deletions

View file

@ -31,8 +31,8 @@ async function runProcurement(contract, ships) {
// TODO check if contract is fulfilled! // TODO check if contract is fulfilled!
const wantedCargo = contract.terms.deliver[0].tradeSymbol; const wantedCargo = contract.terms.deliver[0].tradeSymbol;
const deliveryPoint = contract.terms.deliver[0].destinationSymbol; const deliveryPoint = contract.terms.deliver[0].destinationSymbol;
const asteroidFields = await systems.type({symbol: ships[0].nav.systemSymbol, type: 'ASTEROID_FIELD'}); const asteroids = await systems.type({symbol: ships[0].nav.systemSymbol, type: 'ENGINEERED_ASTEROID'});
const asteroidField = asteroidFields[0].symbol; const asteroidSymbol = asteroids[0].symbol;
ships.forEach(async function(ship) { ships.forEach(async function(ship) {
while (!dbContracts.getContract(contract.id).fulfilled) { while (!dbContracts.getContract(contract.id).fulfilled) {
ship = dbShips.getShip(ship.symbol); ship = dbShips.getShip(ship.symbol);
@ -42,8 +42,11 @@ async function runProcurement(contract, ships) {
if (delay > 0) await api.sleep(delay); if (delay > 0) await api.sleep(delay);
// Then it depends on where we are // Then it depends on where we are
switch (ship.nav.waypointSymbol) { switch (ship.nav.waypointSymbol) {
case asteroidField: case asteroidSymbol:
let response = await mining.mineUntilFullOf({good: wantedCargo, symbol: ship.symbol}); let response = await mining.mineUntilFullOf({
good: wantedCargo,
symbol: ship.symbol
});
await libShips.navigate({symbol: ship.symbol, waypoint: deliveryPoint}); await libShips.navigate({symbol: ship.symbol, waypoint: deliveryPoint});
break; break;
case deliveryPoint: case deliveryPoint:
@ -53,10 +56,10 @@ async function runProcurement(contract, ships) {
break; break;
} }
} }
await libShips.navigate({symbol: ship.symbol, waypoint: asteroidField}); await libShips.navigate({symbol: ship.symbol, waypoint: asteroidSymbol});
break; break;
default: default:
await libShips.navigate({symbol: ship.symbol, waypoint: asteroidField}); await libShips.navigate({symbol: ship.symbol, waypoint: asteroidSymbol});
} }
} }
// TODO repurpose the ship // TODO repurpose the ship

View file

@ -10,7 +10,7 @@ let busy = false; // true if we are already sending api requests.
let backoffSeconds = 0; let backoffSeconds = 0;
let running = false; let running = false;
// other module variables // other module variables
let headers = undefined; // a file scope variable so that we only evaluate these once. let headers = undefined; // a file scoped variable so that we only evaluate these once.
let queue = new PriorityQueue(); // a priority queue to hold api calls we want to send, allows for throttling. let queue = new PriorityQueue(); // a priority queue to hold api calls we want to send, allows for throttling.
// a single queue processor should be running at any time, otherwise there will be trouble! // a single queue processor should be running at any time, otherwise there will be trouble!

View file

@ -5,7 +5,7 @@ import * as systems from '../lib/systems.js';
export async function extract(ctx) { export async function extract(ctx) {
const ship = dbShips.getShip(ctx.symbol); const ship = dbShips.getShip(ctx.symbol);
const asteroidFields = await systems.type({symbol: ship.nav.systemSymbol, type: 'ASTEROID_FIELD'}); const asteroidFields = await systems.type({symbol: ship.nav.systemSymbol, type: 'ENGINEERED_ASTEROID'});
// TODO if there are multiple fields, find the closest one? // TODO if there are multiple fields, find the closest one?
await navigate({symbol: ctx.symbol, waypoint: asteroidFields[0].symbol}); await navigate({symbol: ctx.symbol, waypoint: asteroidFields[0].symbol});
await orbit(ctx); await orbit(ctx);

View file

@ -31,9 +31,9 @@
] ]
}, },
"node_modules/better-sqlite3": { "node_modules/better-sqlite3": {
"version": "9.3.0", "version": "9.4.3",
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-9.3.0.tgz", "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-9.4.3.tgz",
"integrity": "sha512-ww73jVpQhRRdS9uMr761ixlkl4bWoXi8hMQlBGhoN6vPNlUHpIsNmw4pKN6kjknlt/wopdvXHvLk1W75BI+n0Q==", "integrity": "sha512-ud0bTmD9O3uWJGuXDltyj3R47Nz0OHX8iqPOT5PMspGqlu/qQFn+5S2eFBUCrySpavTjFXbi4EgrfVvPAHlImw==",
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"bindings": "^1.5.0", "bindings": "^1.5.0",
@ -217,9 +217,9 @@
"integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==" "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg=="
}, },
"node_modules/node-abi": { "node_modules/node-abi": {
"version": "3.51.0", "version": "3.56.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.51.0.tgz", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.56.0.tgz",
"integrity": "sha512-SQkEP4hmNWjlniS5zdnfIXTk1x7Ome85RDzHlTbBtzE97Gfwz/Ipw4v/Ryk20DWIy3yCNVLVlGKApCnmvYoJbA==", "integrity": "sha512-fZjdhDOeRcaS+rcpve7XuwHBmktS1nS1gzgghwKUQQ8nTy2FdSDr6ZT8k6YhvlJeHmmQMYiT/IH9hfco5zeW2Q==",
"dependencies": { "dependencies": {
"semver": "^7.3.5" "semver": "^7.3.5"
}, },
@ -236,9 +236,9 @@
} }
}, },
"node_modules/prebuild-install": { "node_modules/prebuild-install": {
"version": "7.1.1", "version": "7.1.2",
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.1.tgz", "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.2.tgz",
"integrity": "sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==", "integrity": "sha512-UnNke3IQb6sgarcZIDU3gbMeTp/9SSU1DAIkil7PrqG1vZlBtY5msYccSKSHDqa3hNg436IXK+SNImReuA1wEQ==",
"dependencies": { "dependencies": {
"detect-libc": "^2.0.0", "detect-libc": "^2.0.0",
"expand-template": "^2.0.3", "expand-template": "^2.0.3",
@ -316,9 +316,9 @@
] ]
}, },
"node_modules/semver": { "node_modules/semver": {
"version": "7.5.4", "version": "7.6.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==",
"dependencies": { "dependencies": {
"lru-cache": "^6.0.0" "lru-cache": "^6.0.0"
}, },

7
nodejs/shell.nix Normal file
View file

@ -0,0 +1,7 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
name = "node";
nativeBuildInputs = with pkgs; [ ijq jq nodejs ];
}