@shipload/sdk 1.0.0-next.40 → 1.0.0-next.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/shipload.js CHANGED
@@ -3690,7 +3690,7 @@ var recipes = [
3690
3690
  quantity: 300
3691
3691
  },
3692
3692
  {
3693
- itemId: 10006,
3693
+ itemId: 10010,
3694
3694
  quantity: 300
3695
3695
  }
3696
3696
  ],
@@ -5425,8 +5425,8 @@ const DEPTH_THRESHOLD_T9 = 57000;
5425
5425
  const DEPTH_THRESHOLD_T10 = 63000;
5426
5426
  const LOCATION_MIN_DEPTH = 500;
5427
5427
  const LOCATION_MAX_DEPTH = 65535;
5428
- const YIELD_FRACTION_SHALLOW = 0.005;
5429
- const YIELD_FRACTION_DEEP = 0.001;
5428
+ const YIELD_FRACTION_SHALLOW = 0.002;
5429
+ const YIELD_FRACTION_DEEP = 0.0004;
5430
5430
  function yieldThresholdAt(stratum) {
5431
5431
  const clamped = stratum > 65535 ? 65535 : stratum;
5432
5432
  const t = clamped / 65535;
@@ -5606,6 +5606,21 @@ function deriveLocationSize(loc) {
5606
5606
  return Math.floor(LOCATION_MIN_DEPTH + curved * range);
5607
5607
  }
5608
5608
 
5609
+ const COORD_MIN = -2147483648;
5610
+ const COORD_MAX = 2147483647;
5611
+ const COORD_OFFSET = 2147485000;
5612
+ const SECTOR_DIV = 100000000;
5613
+ const REGION_DIV = 10000;
5614
+ const SECTORS_PER_AXIS = 43;
5615
+ const REGION_PER_AXIS = 10000;
5616
+ const LOCAL_HALF = 5000;
5617
+ const LOCAL_MIN = -5000;
5618
+ const LOCAL_MAX = 4999;
5619
+ const SECTOR_COUNT = SECTORS_PER_AXIS * SECTORS_PER_AXIS;
5620
+ const REGION_COUNT = REGION_PER_AXIS * REGION_PER_AXIS;
5621
+ const SECTOR_FEISTEL = { n: SECTOR_COUNT, halfBits: 6, label: 'sector' };
5622
+ const REGION_FEISTEL = { n: REGION_COUNT, halfBits: 14, label: 'region' };
5623
+
5609
5624
  const WH = {
5610
5625
  RSIZE: 75,
5611
5626
  ZONE: 16384,
@@ -5672,6 +5687,9 @@ function endpointInRegion(seed, R, key) {
5672
5687
  function dist$1(a, b) {
5673
5688
  return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
5674
5689
  }
5690
+ function inBounds(c) {
5691
+ return c.x >= COORD_MIN && c.x <= COORD_MAX && c.y >= COORD_MIN && c.y <= COORD_MAX;
5692
+ }
5675
5693
  function wormholeOfRegion(seed, R) {
5676
5694
  const P = partnerRegion(seed, R);
5677
5695
  if (P.rx === R.rx && P.ry === R.ry)
@@ -5681,6 +5699,8 @@ function wormholeOfRegion(seed, R) {
5681
5699
  return null;
5682
5700
  const A = endpointInRegion(seed, R, key);
5683
5701
  const B = endpointInRegion(seed, P, key);
5702
+ if (!inBounds(A) || !inBounds(B))
5703
+ return null;
5684
5704
  if (dist$1(A, B) < WH.MIN_REACH)
5685
5705
  return null;
5686
5706
  return { A, B };
@@ -9316,6 +9336,14 @@ class EntitiesManager extends BaseManager {
9316
9336
  const entities = result;
9317
9337
  return entities.map((e) => new Entity(e));
9318
9338
  }
9339
+ async getAllEntities(kind) {
9340
+ const rows = await this.server.table('entity').all();
9341
+ if (!kind) {
9342
+ return rows;
9343
+ }
9344
+ const wanted = antelope.Name.from(kind);
9345
+ return rows.filter((row) => wanted.equals(row.kind));
9346
+ }
9319
9347
  async getSummaries(owner, kind) {
9320
9348
  const ownerName = this.resolveOwner(owner);
9321
9349
  const result = await this.server.readonly('getsummaries', {
@@ -9349,6 +9377,24 @@ class PlayersManager extends BaseManager {
9349
9377
  }
9350
9378
  return new Player(playerRow);
9351
9379
  }
9380
+ async getPlayers() {
9381
+ const rows = await this.server.table('player').all();
9382
+ return rows.map((row) => new Player(row));
9383
+ }
9384
+ async getRoster() {
9385
+ const [players, companies] = await Promise.all([
9386
+ this.server.table('player').all(),
9387
+ this.platform.table('company').all(),
9388
+ ]);
9389
+ const companyNames = new Map();
9390
+ for (const company of companies) {
9391
+ companyNames.set(company.account.toString(), company.name);
9392
+ }
9393
+ return players.map((player) => ({
9394
+ owner: player.owner,
9395
+ company: companyNames.get(player.owner.toString()),
9396
+ }));
9397
+ }
9352
9398
  }
9353
9399
 
9354
9400
  const RESERVE_TIERS = {
@@ -9999,21 +10045,6 @@ class LocationsManager extends BaseManager {
9999
10045
  }
10000
10046
  }
10001
10047
 
10002
- const COORD_MIN = -2147483648;
10003
- const COORD_MAX = 2147483647;
10004
- const COORD_OFFSET = 2147485000;
10005
- const SECTOR_DIV = 100000000;
10006
- const REGION_DIV = 10000;
10007
- const SECTORS_PER_AXIS = 43;
10008
- const REGION_PER_AXIS = 10000;
10009
- const LOCAL_HALF = 5000;
10010
- const LOCAL_MIN = -5000;
10011
- const LOCAL_MAX = 4999;
10012
- const SECTOR_COUNT = SECTORS_PER_AXIS * SECTORS_PER_AXIS;
10013
- const REGION_COUNT = REGION_PER_AXIS * REGION_PER_AXIS;
10014
- const SECTOR_FEISTEL = { n: SECTOR_COUNT, halfBits: 6, label: 'sector' };
10015
- const REGION_FEISTEL = { n: REGION_COUNT, halfBits: 14, label: 'region' };
10016
-
10017
10048
  const ROUNDS = 4;
10018
10049
  const keyCache = new Map();
10019
10050
  function deriveRoundKeys(seed, label) {
@@ -13549,7 +13580,7 @@ function gathererDepthForTier(tol, tier) {
13549
13580
  }
13550
13581
  function computeGathererCapabilities(stats, tier) {
13551
13582
  const str = stats.strength;
13552
- const con = stats.conductivity;
13583
+ const con = stats.saturation;
13553
13584
  const tol = stats.tolerance;
13554
13585
  return {
13555
13586
  yield: 200 + str,
@@ -14547,8 +14578,23 @@ function reconstruct(cameFrom, origin, dest) {
14547
14578
  const waypoints = path.slice(1);
14548
14579
  return { ok: true, waypoints, legs: waypoints.length, totalDistance };
14549
14580
  }
14581
+ let scanProvider = null;
14582
+ const graphCache = new Map();
14583
+ function setScanProvider(provider) {
14584
+ scanProvider = provider;
14585
+ graphCache.clear();
14586
+ }
14550
14587
  function sdkSystemGraph(seed) {
14551
14588
  const s = antelope.Checksum256.from(seed);
14589
+ const seedHex = s.toString();
14590
+ const cached = graphCache.get(seedHex);
14591
+ if (cached)
14592
+ return cached;
14593
+ const graph = scanProvider ? wasmSystemGraph(s, seedHex, scanProvider) : jsSystemGraph(s);
14594
+ graphCache.set(seedHex, graph);
14595
+ return graph;
14596
+ }
14597
+ function jsSystemGraph(s) {
14552
14598
  return {
14553
14599
  hasSystem: (c) => hasSystem(s, { x: c.x, y: c.y }) || wormholeAt(s, c.x, c.y) !== null,
14554
14600
  nearby: (c, reachTiles) => {
@@ -14573,6 +14619,57 @@ function sdkSystemGraph(seed) {
14573
14619
  },
14574
14620
  };
14575
14621
  }
14622
+ const SCAN_BUCKET = 48;
14623
+ function wasmSystemGraph(s, seedHex, scan) {
14624
+ const bucketCache = new Map();
14625
+ const bucketSystems = (bx, by) => {
14626
+ const k = `${bx},${by}`;
14627
+ let v = bucketCache.get(k);
14628
+ if (v === undefined) {
14629
+ const xMin = bx * SCAN_BUCKET;
14630
+ const yMin = by * SCAN_BUCKET;
14631
+ v = scan
14632
+ .systemsInBox(seedHex, xMin, yMin, xMin + SCAN_BUCKET - 1, yMin + SCAN_BUCKET - 1)
14633
+ .map((cell) => ({ x: cell.x, y: cell.y }));
14634
+ bucketCache.set(k, v);
14635
+ }
14636
+ return v;
14637
+ };
14638
+ return {
14639
+ hasSystem: (c) => scan.getLocationType(seedHex, c.x, c.y) !== 0 || wormholeAt(s, c.x, c.y) !== null,
14640
+ nearby: (c, reachTiles) => {
14641
+ const r = Math.floor(reachTiles);
14642
+ const seen = new Set([`${c.x},${c.y}`]);
14643
+ const out = [];
14644
+ const bx0 = Math.floor((c.x - r) / SCAN_BUCKET);
14645
+ const bx1 = Math.floor((c.x + r) / SCAN_BUCKET);
14646
+ const by0 = Math.floor((c.y - r) / SCAN_BUCKET);
14647
+ const by1 = Math.floor((c.y + r) / SCAN_BUCKET);
14648
+ for (let bx = bx0; bx <= bx1; bx++) {
14649
+ for (let by = by0; by <= by1; by++) {
14650
+ for (const cell of bucketSystems(bx, by)) {
14651
+ const dist = Math.hypot(cell.x - c.x, cell.y - c.y);
14652
+ if (dist > reachTiles)
14653
+ continue;
14654
+ const k = `${cell.x},${cell.y}`;
14655
+ if (seen.has(k))
14656
+ continue;
14657
+ seen.add(k);
14658
+ out.push({ coord: { x: cell.x, y: cell.y }, dist });
14659
+ }
14660
+ }
14661
+ }
14662
+ for (const coord of nearbyWormholes(s, c.x, c.y, reachTiles)) {
14663
+ const k = `${coord.x},${coord.y}`;
14664
+ if (seen.has(k))
14665
+ continue;
14666
+ seen.add(k);
14667
+ out.push({ coord, dist: Math.hypot(coord.x - c.x, coord.y - c.y) });
14668
+ }
14669
+ return out;
14670
+ },
14671
+ };
14672
+ }
14576
14673
 
14577
14674
  function computePerLegReach(s, haulCount = 0) {
14578
14675
  const capacity = s.generator?.capacity;
@@ -16803,8 +16900,8 @@ function buildModuleImmutable(itemId, quantity, stats, originX, originY) {
16803
16900
  const ref = decodeStat(stats, 3);
16804
16901
  base.push({ first: 'strength', second: ['uint16', str] });
16805
16902
  base.push({ first: 'tolerance', second: ['uint16', tol] });
16806
- base.push({ first: 'conductivity', second: ['uint16', con] });
16807
- base.push({ first: 'reflectivity', second: ['uint16', ref] });
16903
+ base.push({ first: 'saturation', second: ['uint16', con] });
16904
+ base.push({ first: 'plasticity', second: ['uint16', ref] });
16808
16905
  base.push({ first: 'yield', second: ['uint16', computeGathererYield(str)] });
16809
16906
  base.push({ first: 'drain', second: ['uint16', computeGathererDrain(con)] });
16810
16907
  base.push({ first: 'depth', second: ['uint16', computeGathererDepth(tol, item.tier)] });
@@ -17687,6 +17784,7 @@ exports.rotation = rotation;
17687
17784
  exports.schedule = schedule;
17688
17785
  exports.sdkSystemGraph = sdkSystemGraph;
17689
17786
  exports.selectGatherLane = selectGatherLane;
17787
+ exports.setScanProvider = setScanProvider;
17690
17788
  exports.setSubscriptionsDebug = setSubscriptionsDebug;
17691
17789
  exports.stackKey = stackKey;
17692
17790
  exports.stackToCargoItem = stackToCargoItem;