@shipload/sdk 1.0.0-next.45 → 1.0.0-next.47

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.
Files changed (43) hide show
  1. package/lib/shipload.d.ts +236 -39
  2. package/lib/shipload.js +1465 -191
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +1450 -192
  5. package/lib/shipload.m.js.map +1 -1
  6. package/lib/testing.d.ts +81 -15
  7. package/lib/testing.js +377 -44
  8. package/lib/testing.js.map +1 -1
  9. package/lib/testing.m.js +378 -45
  10. package/lib/testing.m.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/capabilities/gathering.test.ts +14 -1
  13. package/src/capabilities/gathering.ts +6 -5
  14. package/src/capabilities/modules.ts +13 -0
  15. package/src/contracts/server.ts +242 -28
  16. package/src/data/capabilities.ts +1 -1
  17. package/src/data/entities.json +93 -19
  18. package/src/data/item-ids.ts +12 -0
  19. package/src/data/items.json +76 -2
  20. package/src/data/kind-registry.json +10 -0
  21. package/src/data/metadata.ts +75 -7
  22. package/src/data/recipes-runtime.ts +1 -0
  23. package/src/data/recipes.json +736 -0
  24. package/src/derivation/capabilities.test.ts +11 -11
  25. package/src/derivation/capabilities.ts +42 -27
  26. package/src/derivation/crafting.ts +13 -9
  27. package/src/derivation/index.ts +2 -0
  28. package/src/derivation/recipe-usage.test.ts +11 -7
  29. package/src/derivation/stars.test.ts +16 -0
  30. package/src/derivation/stars.ts +10 -0
  31. package/src/derivation/stratum.ts +11 -4
  32. package/src/entities/makers.ts +8 -1
  33. package/src/index-module.ts +5 -1
  34. package/src/managers/actions.ts +10 -0
  35. package/src/nft/buildImmutableData.ts +1 -1
  36. package/src/nft/description.ts +25 -12
  37. package/src/resolution/describe-module.ts +21 -8
  38. package/src/resolution/resolve-item.ts +31 -33
  39. package/src/scheduling/projection.ts +8 -1
  40. package/src/subscriptions/manager.cluster.test.ts +7 -2
  41. package/src/subscriptions/types.ts +1 -0
  42. package/src/utils/cargo.test.ts +14 -0
  43. package/src/utils/cargo.ts +2 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "1.0.0-next.45",
4
+ "version": "1.0.0-next.47",
5
5
  "homepage": "https://github.com/shipload/toolkit/tree/master/packages/sdk",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  import {expect, test} from 'bun:test'
2
2
  import type {GathererStats} from '../types/capabilities'
3
- import {calc_gather_energy} from './gathering'
3
+ import {calc_gather_duration, calc_gather_energy} from './gathering'
4
4
 
5
5
  function gatherer(drain: number): GathererStats {
6
6
  return {
@@ -14,3 +14,16 @@ test('calc_gather_energy does not clamp above the old uint16 ceiling', () => {
14
14
  const energy = calc_gather_energy(gatherer(30), 400_000_000)
15
15
  expect(Number(energy)).toBeGreaterThan(65535)
16
16
  })
17
+
18
+ test('splitting a bulk gather never undercuts total lane-time', () => {
19
+ const g: GathererStats = {
20
+ yield: {toNumber: () => 413},
21
+ drain: {toNumber: () => 30},
22
+ depth: {toNumber: () => 0, toString: () => '0'},
23
+ }
24
+ const bulk = Number(calc_gather_duration(g, 1000, 10, 8, 500))
25
+ const unit = Number(calc_gather_duration(g, 1000, 1, 8, 500))
26
+ // d1 >= 1 regime (bulk > quantity), where the split exploit lived
27
+ expect(bulk).toBeGreaterThan(10)
28
+ expect(unit * 10).toBeGreaterThanOrEqual(bulk)
29
+ })
@@ -30,9 +30,9 @@ export function calc_gather_duration(
30
30
  stratum: number,
31
31
  richness: number
32
32
  ): UInt32 {
33
- return UInt32.from(
34
- Math.floor(gather_duration_raw(gatherer, itemMass, quantity, stratum, richness))
35
- )
33
+ const raw = gather_duration_raw(gatherer, itemMass, quantity, stratum, richness)
34
+ // +1 per-gather setup cost mirrors the contract: splitting a bulk gather must not undercut lane-time
35
+ return UInt32.from(raw <= 0 ? 0 : Math.floor(raw) + 1)
36
36
  }
37
37
 
38
38
  export function calc_gather_rate(
@@ -48,6 +48,7 @@ export function calc_gather_rate(
48
48
  }
49
49
 
50
50
  export function calc_gather_energy(gatherer: GathererStats, duration: number): UInt32 {
51
- const energy = Math.floor((duration * gatherer.drain.toNumber()) / PRECISION)
52
- return UInt32.from(energy)
51
+ if (duration <= 0) return UInt32.from(0)
52
+ const raw = Math.floor((duration * gatherer.drain.toNumber()) / PRECISION)
53
+ return UInt32.from(Math.min(Math.max(raw, 1), 4294967295))
53
54
  }
@@ -3,13 +3,17 @@ import {
3
3
  ITEM_CRAFTER_T1,
4
4
  ITEM_ENGINE_T1,
5
5
  ITEM_GATHERER_T1,
6
+ ITEM_GATHERER_T2,
6
7
  ITEM_GENERATOR_T1,
7
8
  ITEM_HAULER_T1,
9
+ ITEM_HAULER_T2,
8
10
  ITEM_LAUNCHER_T1,
9
11
  ITEM_LOADER_T1,
10
12
  ITEM_STORAGE_T1,
11
13
  ITEM_WARP_T1,
12
14
  } from '../data/item-ids'
15
+ import {getItem} from '../data/catalog'
16
+ import type {EntitySlot} from '../data/recipes-runtime'
13
17
 
14
18
  export const MODULE_ANY = 0
15
19
  export const MODULE_ENGINE = 1
@@ -44,6 +48,7 @@ export function getModuleCapabilityType(itemId: number): number {
44
48
  case ITEM_GENERATOR_T1:
45
49
  return MODULE_GENERATOR
46
50
  case ITEM_GATHERER_T1:
51
+ case ITEM_GATHERER_T2:
47
52
  return MODULE_GATHERER
48
53
  case ITEM_LOADER_T1:
49
54
  return MODULE_LOADER
@@ -52,6 +57,7 @@ export function getModuleCapabilityType(itemId: number): number {
52
57
  case ITEM_STORAGE_T1:
53
58
  return MODULE_STORAGE
54
59
  case ITEM_HAULER_T1:
60
+ case ITEM_HAULER_T2:
55
61
  return MODULE_HAULER
56
62
  case ITEM_WARP_T1:
57
63
  return MODULE_WARP
@@ -96,3 +102,10 @@ export function moduleSlotTypeToCode(slotType: string): number {
96
102
  return MODULE_ANY
97
103
  }
98
104
  }
105
+
106
+ export function slotAcceptsModule(slot: EntitySlot, moduleItemId: number): boolean {
107
+ const moduleType = getModuleCapabilityType(moduleItemId)
108
+ if (moduleType === 0xff) return false
109
+ if (!moduleAccepts(moduleSlotTypeToCode(slot.type), moduleType)) return false
110
+ return getItem(moduleItemId).tier <= slot.maxTier
111
+ }