@shipload/sdk 1.0.0-next.41 → 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/scan.d.ts +19 -1
- package/lib/scan.js +54 -28
- package/lib/scan.js.map +1 -1
- package/lib/scan.m.js +52 -29
- package/lib/scan.m.js.map +1 -1
- package/lib/shipload.d.ts +17 -1
- package/lib/shipload.js +117 -19
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +117 -20
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/data/recipes.json +1 -1
- package/src/derivation/capabilities.test.ts +4 -4
- package/src/derivation/capabilities.ts +1 -1
- package/src/derivation/recipe-usage.test.ts +8 -9
- package/src/derivation/wormhole.ts +5 -0
- package/src/index-module.ts +3 -1
- package/src/managers/entities.ts +9 -0
- package/src/managers/index.ts +1 -0
- package/src/managers/players.ts +25 -0
- package/src/nft/buildImmutableData.ts +2 -2
- package/src/scan/index.ts +93 -29
- package/src/scan/scan-wasm.base64.ts +1 -1
- package/src/travel/route-planner.ts +82 -1
package/package.json
CHANGED
package/src/data/recipes.json
CHANGED
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
import type {InstalledModule} from '../entities/slot-multiplier'
|
|
22
22
|
import type {EntitySlot} from '../data/recipes-runtime'
|
|
23
23
|
|
|
24
|
-
function makeGathererStats(strength: number, tolerance: number,
|
|
25
|
-
return encodeStats([strength, tolerance,
|
|
24
|
+
function makeGathererStats(strength: number, tolerance: number, saturation: number): bigint {
|
|
25
|
+
return encodeStats([strength, tolerance, saturation, 0])
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function makeCrafterStats(reactivity: number, conductivity: number): bigint {
|
|
@@ -72,8 +72,8 @@ test('computeEntityCapabilities emits gathererLanes alongside legacy gatherer su
|
|
|
72
72
|
expect(result.gathererLanes![1].slotIndex).toBe(1)
|
|
73
73
|
|
|
74
74
|
// Yields are amp-scaled and distinct
|
|
75
|
-
const caps1 = computeGathererCapabilities({strength: 300, tolerance: 200,
|
|
76
|
-
const caps2 = computeGathererCapabilities({strength: 500, tolerance: 100,
|
|
75
|
+
const caps1 = computeGathererCapabilities({strength: 300, tolerance: 200, saturation: 400}, 1)
|
|
76
|
+
const caps2 = computeGathererCapabilities({strength: 500, tolerance: 100, saturation: 300}, 1)
|
|
77
77
|
const expectedYield1 = applySlotMultiplier(caps1.yield, 100)
|
|
78
78
|
const expectedYield2 = applySlotMultiplier(caps2.yield, 100)
|
|
79
79
|
expect(result.gathererLanes![0].yield).toBe(expectedYield1)
|
|
@@ -26,14 +26,12 @@ test('getRecipeConsumers lists every recipe that consumes Sensor', () => {
|
|
|
26
26
|
const consumers = getRecipeConsumers(ITEM_SENSOR)
|
|
27
27
|
const ids = consumers.map((c) => c.outputItemId).sort((a, b) => a - b)
|
|
28
28
|
expect(ids).toEqual(
|
|
29
|
-
[
|
|
30
|
-
(a, b) => a - b
|
|
31
|
-
)
|
|
29
|
+
[ITEM_CRAFTER_T1, ITEM_SHIP_T1_PACKED, ITEM_EXTRACTOR_T1_PACKED].sort((a, b) => a - b)
|
|
32
30
|
)
|
|
33
31
|
})
|
|
34
32
|
|
|
35
|
-
test('
|
|
36
|
-
const consumers = getRecipeConsumers(
|
|
33
|
+
test('Resin feeds the gatherer drain stat', () => {
|
|
34
|
+
const consumers = getRecipeConsumers(ITEM_RESIN)
|
|
37
35
|
const gatherer = consumers.find((c) => c.outputItemId === ITEM_GATHERER_T1)
|
|
38
36
|
expect(gatherer).toBeDefined()
|
|
39
37
|
const drain = gatherer?.statFlows.find(
|
|
@@ -58,11 +56,12 @@ test('getResourceDemand traces a dual-resource component to both resources', ()
|
|
|
58
56
|
})
|
|
59
57
|
|
|
60
58
|
test('getResourceDemand recurses through a module to raw resources', () => {
|
|
61
|
-
// Gatherer = 300 Beam (5 ore + 5 gas each) + 300
|
|
59
|
+
// Gatherer = 300 Beam (5 ore + 5 gas each) + 300 Resin (5 biomass + 5 crystal each)
|
|
62
60
|
expect(getResourceDemand(ITEM_GATHERER_T1)).toEqual({
|
|
63
61
|
ore: 1500,
|
|
64
62
|
gas: 1500,
|
|
65
|
-
|
|
63
|
+
biomass: 1500,
|
|
64
|
+
crystal: 1500,
|
|
66
65
|
})
|
|
67
66
|
})
|
|
68
67
|
|
|
@@ -70,9 +69,9 @@ test('getResourceDemand scales by quantity', () => {
|
|
|
70
69
|
expect(getResourceDemand(ITEM_PLATE, 3)).toEqual({ore: 30})
|
|
71
70
|
})
|
|
72
71
|
|
|
73
|
-
test('getComponentDemand reports Resin as consumed by
|
|
72
|
+
test('getComponentDemand reports Resin as consumed by two recipes', () => {
|
|
74
73
|
const demand = getComponentDemand()
|
|
75
74
|
const resin = demand.find((d) => d.itemId === ITEM_RESIN)
|
|
76
75
|
expect(resin).toBeDefined()
|
|
77
|
-
expect(resin?.consumerCount).toBe(
|
|
76
|
+
expect(resin?.consumerCount).toBe(2)
|
|
78
77
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {Checksum256Type} from '@wharfkit/antelope'
|
|
2
2
|
import {hash512} from '../utils/hash'
|
|
3
|
+
import {COORD_MAX, COORD_MIN} from '../coordinates/constants'
|
|
3
4
|
|
|
4
5
|
export const WH = {
|
|
5
6
|
RSIZE: 75,
|
|
@@ -72,6 +73,9 @@ function endpointInRegion(seed: Checksum256Type, R: Region, key: string): {x: nu
|
|
|
72
73
|
function dist(a: {x: number; y: number}, b: {x: number; y: number}): number {
|
|
73
74
|
return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2)
|
|
74
75
|
}
|
|
76
|
+
function inBounds(c: {x: number; y: number}): boolean {
|
|
77
|
+
return c.x >= COORD_MIN && c.x <= COORD_MAX && c.y >= COORD_MIN && c.y <= COORD_MAX
|
|
78
|
+
}
|
|
75
79
|
function wormholeOfRegion(
|
|
76
80
|
seed: Checksum256Type,
|
|
77
81
|
R: Region
|
|
@@ -82,6 +86,7 @@ function wormholeOfRegion(
|
|
|
82
86
|
if (roll16(seed, `wh-exists-${key}`) >= WH.THRESHOLD) return null
|
|
83
87
|
const A = endpointInRegion(seed, R, key)
|
|
84
88
|
const B = endpointInRegion(seed, P, key)
|
|
89
|
+
if (!inBounds(A) || !inBounds(B)) return null
|
|
85
90
|
if (dist(A, B) < WH.MIN_REACH) return null
|
|
86
91
|
return {A, B}
|
|
87
92
|
}
|
package/src/index-module.ts
CHANGED
|
@@ -50,6 +50,7 @@ export {
|
|
|
50
50
|
ConstructionManager,
|
|
51
51
|
} from './managers'
|
|
52
52
|
export type {
|
|
53
|
+
PlayerRosterEntry,
|
|
53
54
|
LocationStratum,
|
|
54
55
|
NftConfigForItem,
|
|
55
56
|
BuildableTarget,
|
|
@@ -206,11 +207,12 @@ export type {
|
|
|
206
207
|
HasScheduleAndLocation,
|
|
207
208
|
} from './travel/travel'
|
|
208
209
|
|
|
209
|
-
export {planRoute, sdkSystemGraph, MAX_LEGS} from './travel/route-planner'
|
|
210
|
+
export {planRoute, sdkSystemGraph, setScanProvider, MAX_LEGS} from './travel/route-planner'
|
|
210
211
|
export type {
|
|
211
212
|
Coord,
|
|
212
213
|
Neighbor,
|
|
213
214
|
SystemGraph,
|
|
215
|
+
ScanProvider,
|
|
214
216
|
RoutePlan,
|
|
215
217
|
RouteFailure,
|
|
216
218
|
RouteResult,
|
package/src/managers/entities.ts
CHANGED
|
@@ -34,6 +34,15 @@ export class EntitiesManager extends BaseManager {
|
|
|
34
34
|
return entities.map((e) => new Entity(e))
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
async getAllEntities(kind?: EntityTypeName): Promise<ServerContract.Types.entity_row[]> {
|
|
38
|
+
const rows = await this.server.table('entity').all()
|
|
39
|
+
if (!kind) {
|
|
40
|
+
return rows
|
|
41
|
+
}
|
|
42
|
+
const wanted = Name.from(kind)
|
|
43
|
+
return rows.filter((row) => wanted.equals(row.kind))
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
async getSummaries(
|
|
38
47
|
owner: NameType | ServerContract.Types.player_row,
|
|
39
48
|
kind?: EntityTypeName
|
package/src/managers/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export {BaseManager} from './base'
|
|
|
3
3
|
export {EntitiesManager} from './entities'
|
|
4
4
|
export type {EntityTypeName} from './entities'
|
|
5
5
|
export {PlayersManager} from './players'
|
|
6
|
+
export type {PlayerRosterEntry} from './players'
|
|
6
7
|
export {LocationsManager} from './locations'
|
|
7
8
|
export type {LocationStratum} from './locations'
|
|
8
9
|
export {EpochsManager} from './epochs'
|
package/src/managers/players.ts
CHANGED
|
@@ -2,6 +2,11 @@ import {Name, type NameType} from '@wharfkit/antelope'
|
|
|
2
2
|
import {BaseManager} from './base'
|
|
3
3
|
import {Player} from '../entities/player'
|
|
4
4
|
|
|
5
|
+
export interface PlayerRosterEntry {
|
|
6
|
+
owner: Name
|
|
7
|
+
company?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
5
10
|
export class PlayersManager extends BaseManager {
|
|
6
11
|
async getPlayer(account: NameType): Promise<Player | undefined> {
|
|
7
12
|
const playerRow = await this.server.table('player').get(Name.from(account))
|
|
@@ -10,4 +15,24 @@ export class PlayersManager extends BaseManager {
|
|
|
10
15
|
}
|
|
11
16
|
return new Player(playerRow)
|
|
12
17
|
}
|
|
18
|
+
|
|
19
|
+
async getPlayers(): Promise<Player[]> {
|
|
20
|
+
const rows = await this.server.table('player').all()
|
|
21
|
+
return rows.map((row) => new Player(row))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async getRoster(): Promise<PlayerRosterEntry[]> {
|
|
25
|
+
const [players, companies] = await Promise.all([
|
|
26
|
+
this.server.table('player').all(),
|
|
27
|
+
this.platform.table('company').all(),
|
|
28
|
+
])
|
|
29
|
+
const companyNames = new Map<string, string>()
|
|
30
|
+
for (const company of companies) {
|
|
31
|
+
companyNames.set(company.account.toString(), company.name)
|
|
32
|
+
}
|
|
33
|
+
return players.map((player) => ({
|
|
34
|
+
owner: player.owner,
|
|
35
|
+
company: companyNames.get(player.owner.toString()),
|
|
36
|
+
}))
|
|
37
|
+
}
|
|
13
38
|
}
|
|
@@ -203,8 +203,8 @@ export function buildModuleImmutable(
|
|
|
203
203
|
const ref = decodeStat(stats, 3)
|
|
204
204
|
base.push({first: 'strength', second: ['uint16', str]})
|
|
205
205
|
base.push({first: 'tolerance', second: ['uint16', tol]})
|
|
206
|
-
base.push({first: '
|
|
207
|
-
base.push({first: '
|
|
206
|
+
base.push({first: 'saturation', second: ['uint16', con]})
|
|
207
|
+
base.push({first: 'plasticity', second: ['uint16', ref]})
|
|
208
208
|
base.push({first: 'yield', second: ['uint16', computeGathererYield(str)]})
|
|
209
209
|
base.push({first: 'drain', second: ['uint16', computeGathererDrain(con)]})
|
|
210
210
|
base.push({first: 'depth', second: ['uint16', computeGathererDepth(tol, item.tier)]})
|
package/src/scan/index.ts
CHANGED
|
@@ -44,6 +44,38 @@ function ex(): any {
|
|
|
44
44
|
|
|
45
45
|
const hex = (h: string) => Uint8Array.from(h.match(/../g)!.map((b) => parseInt(b, 16)))
|
|
46
46
|
|
|
47
|
+
// Shared marshalling for the `*_in_box` exports; grow-and-retry once on overflow (export returns -needed).
|
|
48
|
+
function boxScan<T>(
|
|
49
|
+
exportName: string,
|
|
50
|
+
stride: number,
|
|
51
|
+
gameSeed: string,
|
|
52
|
+
xMin: number,
|
|
53
|
+
yMin: number,
|
|
54
|
+
xMax: number,
|
|
55
|
+
yMax: number,
|
|
56
|
+
decode: (dv: DataView, o: number) => T
|
|
57
|
+
): T[] {
|
|
58
|
+
const e = ex()
|
|
59
|
+
const mem = e.memory as WebAssembly.Memory
|
|
60
|
+
const g = e.malloc(32)
|
|
61
|
+
new Uint8Array(mem.buffer, g, 32).set(hex(gameSeed))
|
|
62
|
+
let cap = 256
|
|
63
|
+
let out = e.malloc(cap * stride)
|
|
64
|
+
let n = e[exportName](g, xMin, yMin, xMax, yMax, out, cap)
|
|
65
|
+
if (n < 0) {
|
|
66
|
+
e.free(out)
|
|
67
|
+
cap = -n
|
|
68
|
+
out = e.malloc(cap * stride)
|
|
69
|
+
n = e[exportName](g, xMin, yMin, xMax, yMax, out, cap)
|
|
70
|
+
}
|
|
71
|
+
const dv = new DataView(mem.buffer, out, n * stride)
|
|
72
|
+
const res: T[] = []
|
|
73
|
+
for (let i = 0; i < n; i++) res.push(decode(dv, i * stride))
|
|
74
|
+
e.free(g)
|
|
75
|
+
e.free(out)
|
|
76
|
+
return res
|
|
77
|
+
}
|
|
78
|
+
|
|
47
79
|
export function getLocationType(gameSeed: string, x: number, y: number): number {
|
|
48
80
|
const e = ex()
|
|
49
81
|
const mem = e.memory as WebAssembly.Memory
|
|
@@ -87,32 +119,55 @@ export function systemsInBox(
|
|
|
87
119
|
xMax: number,
|
|
88
120
|
yMax: number
|
|
89
121
|
): SystemCell[] {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
return boxScan('systems_in_box', 12, gameSeed, xMin, yMin, xMax, yMax, (dv, o) => ({
|
|
123
|
+
x: dv.getInt32(o, true),
|
|
124
|
+
y: dv.getInt32(o + 4, true),
|
|
125
|
+
locType: dv.getUint32(o + 8, true),
|
|
126
|
+
}))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface LocationCell {
|
|
130
|
+
x: number
|
|
131
|
+
y: number
|
|
132
|
+
locType: number
|
|
133
|
+
subtype: number
|
|
134
|
+
size: number
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function locationsInBox(
|
|
138
|
+
gameSeed: string,
|
|
139
|
+
xMin: number,
|
|
140
|
+
yMin: number,
|
|
141
|
+
xMax: number,
|
|
142
|
+
yMax: number
|
|
143
|
+
): LocationCell[] {
|
|
144
|
+
return boxScan('locations_in_box', 16, gameSeed, xMin, yMin, xMax, yMax, (dv, o) => ({
|
|
145
|
+
x: dv.getInt32(o, true),
|
|
146
|
+
y: dv.getInt32(o + 4, true),
|
|
147
|
+
locType: dv.getUint8(o + 8),
|
|
148
|
+
subtype: dv.getUint8(o + 9),
|
|
149
|
+
size: dv.getUint32(o + 12, true),
|
|
150
|
+
}))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface WormholeCell {
|
|
154
|
+
x: number
|
|
155
|
+
y: number
|
|
156
|
+
exit: {x: number; y: number}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function wormholesInBox(
|
|
160
|
+
gameSeed: string,
|
|
161
|
+
xMin: number,
|
|
162
|
+
yMin: number,
|
|
163
|
+
xMax: number,
|
|
164
|
+
yMax: number
|
|
165
|
+
): WormholeCell[] {
|
|
166
|
+
return boxScan('wormholes_in_box', 16, gameSeed, xMin, yMin, xMax, yMax, (dv, o) => ({
|
|
167
|
+
x: dv.getInt32(o, true),
|
|
168
|
+
y: dv.getInt32(o + 4, true),
|
|
169
|
+
exit: {x: dv.getInt32(o + 8, true), y: dv.getInt32(o + 12, true)},
|
|
170
|
+
}))
|
|
116
171
|
}
|
|
117
172
|
|
|
118
173
|
export async function scanCells(
|
|
@@ -121,6 +176,15 @@ export async function scanCells(
|
|
|
121
176
|
cells: Coord[]
|
|
122
177
|
): Promise<DerivedCell[]> {
|
|
123
178
|
await scanReady()
|
|
179
|
+
return scanCellsCore(gameSeed, epochSeed, cells)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Sync sibling of scanCells; caller must warm the instance via scanReady() first.
|
|
183
|
+
export function scanCellsSync(gameSeed: string, epochSeed: string, cells: Coord[]): DerivedCell[] {
|
|
184
|
+
return scanCellsCore(gameSeed, epochSeed, cells)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function scanCellsCore(gameSeed: string, epochSeed: string, cells: Coord[]): DerivedCell[] {
|
|
124
188
|
const e = ex()
|
|
125
189
|
const mem = e.memory as WebAssembly.Memory
|
|
126
190
|
const write = (b: Uint8Array) => {
|
|
@@ -146,9 +210,8 @@ export async function scanCells(
|
|
|
146
210
|
depOut = e.malloc(cap * 40)
|
|
147
211
|
n = e.scan_cells(gp, ep, cp, cells.length, locOut, depOut, cap)
|
|
148
212
|
}
|
|
149
|
-
const locView = new DataView(mem.buffer
|
|
150
|
-
const depView = new DataView(mem.buffer
|
|
151
|
-
for (const p of [gp, ep, cp, locOut, depOut]) e.free(p)
|
|
213
|
+
const locView = new DataView(mem.buffer, locOut, cells.length * 8)
|
|
214
|
+
const depView = new DataView(mem.buffer, depOut, n * 40)
|
|
152
215
|
const out: DerivedCell[] = cells.map((c, i) => ({
|
|
153
216
|
location: {
|
|
154
217
|
x: c.x,
|
|
@@ -176,5 +239,6 @@ export async function scanCells(
|
|
|
176
239
|
],
|
|
177
240
|
})
|
|
178
241
|
}
|
|
242
|
+
for (const p of [gp, ep, cp, locOut, depOut]) e.free(p)
|
|
179
243
|
return out
|
|
180
244
|
}
|