@shipload/sdk 1.0.0-next.6 → 1.0.0-next.61
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 +52 -0
- package/lib/scan.js +162 -0
- package/lib/scan.js.map +1 -0
- package/lib/scan.m.js +152 -0
- package/lib/scan.m.js.map +1 -0
- package/lib/shipload.d.ts +3601 -1364
- package/lib/shipload.js +15671 -5261
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +15392 -5209
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +1173 -0
- package/lib/testing.js +4971 -0
- package/lib/testing.js.map +1 -0
- package/lib/testing.m.js +4965 -0
- package/lib/testing.m.js.map +1 -0
- package/package.json +20 -2
- package/src/capabilities/craftable.test.ts +82 -0
- package/src/capabilities/craftable.ts +82 -0
- package/src/capabilities/crafting.test.ts +35 -0
- package/src/capabilities/crafting.ts +34 -7
- package/src/capabilities/gathering.test.ts +29 -0
- package/src/capabilities/gathering.ts +37 -19
- package/src/capabilities/hauling.ts +0 -5
- package/src/capabilities/index.ts +0 -1
- package/src/capabilities/modules.ts +27 -30
- package/src/capabilities/movement.ts +1 -1
- package/src/capabilities/storage.ts +16 -1
- package/src/contracts/platform.ts +231 -3
- package/src/contracts/server.ts +1518 -501
- package/src/coordinates/address.ts +88 -0
- package/src/coordinates/constants.test.ts +15 -0
- package/src/coordinates/constants.ts +23 -0
- package/src/coordinates/index.ts +15 -0
- package/src/coordinates/memo.test.ts +47 -0
- package/src/coordinates/memo.ts +20 -0
- package/src/coordinates/permutation.ts +77 -0
- package/src/coordinates/regions.ts +48 -0
- package/src/coordinates/sectors.ts +115 -0
- package/src/data/capabilities.ts +49 -18
- package/src/data/capability-formulas.ts +26 -14
- package/src/data/catalog.ts +7 -8
- package/src/data/colors.ts +14 -48
- package/src/data/entities.json +380 -15
- package/src/data/item-ids.ts +51 -13
- package/src/data/items.json +318 -77
- package/src/data/kind-registry.json +195 -0
- package/src/data/kind-registry.ts +182 -0
- package/src/data/metadata.ts +291 -51
- package/src/data/recipes-runtime.ts +6 -23
- package/src/data/recipes.json +2260 -173
- package/src/data/tiers.ts +9 -6
- package/src/derivation/build-methods.test.ts +13 -0
- package/src/derivation/build-methods.ts +48 -0
- package/src/derivation/capabilities.test.ts +348 -0
- package/src/derivation/capabilities.ts +693 -0
- package/src/derivation/capability-mappings.ts +60 -16
- package/src/derivation/crafting.test.ts +17 -0
- package/src/derivation/crafting.ts +57 -34
- package/src/derivation/index.ts +27 -2
- package/src/derivation/recipe-usage.test.ts +90 -0
- package/src/derivation/recipe-usage.ts +141 -0
- package/src/derivation/reserve-regen.ts +34 -0
- package/src/derivation/resources.ts +9 -1
- package/src/derivation/rollups.test.ts +55 -0
- package/src/derivation/rollups.ts +72 -0
- package/src/derivation/stars.test.ts +67 -0
- package/src/derivation/stars.ts +25 -0
- package/src/derivation/stat-scaling.ts +12 -0
- package/src/derivation/stats.ts +6 -6
- package/src/derivation/stratum.ts +26 -22
- package/src/derivation/tiers.ts +40 -7
- package/src/derivation/upgrades.ts +14 -0
- package/src/derivation/wormhole.ts +154 -0
- package/src/entities/entity.ts +102 -0
- package/src/entities/gamestate.ts +3 -28
- package/src/entities/makers.ts +141 -135
- package/src/entities/slot-multiplier.ts +43 -0
- package/src/errors.ts +12 -16
- package/src/format.ts +26 -4
- package/src/index-module.ts +333 -35
- package/src/managers/actions.ts +668 -103
- package/src/managers/base.ts +6 -2
- package/src/managers/cluster.test.ts +39 -0
- package/src/managers/cluster.ts +53 -0
- package/src/managers/construction-types.ts +80 -0
- package/src/managers/construction.ts +443 -0
- package/src/managers/context.ts +29 -1
- package/src/managers/coordinates.ts +14 -0
- package/src/managers/entities.ts +27 -66
- package/src/managers/epochs.ts +40 -0
- package/src/managers/index.ts +20 -1
- package/src/managers/locations.ts +25 -29
- package/src/managers/nft.test.ts +14 -0
- package/src/managers/nft.ts +70 -0
- package/src/managers/players.ts +25 -0
- package/src/managers/plot.ts +122 -0
- package/src/nft/atomicassets.abi.json +1342 -0
- package/src/nft/atomicassets.ts +237 -0
- package/src/nft/atomicdata.ts +130 -0
- package/src/nft/buildImmutableData.ts +388 -0
- package/src/nft/description.ts +215 -99
- package/src/nft/index.ts +3 -0
- package/src/planner/index.ts +242 -0
- package/src/planner/planner.test.ts +334 -0
- package/src/resolution/describe-module.ts +43 -25
- package/src/resolution/display-name.ts +38 -10
- package/src/resolution/resolve-item.test.ts +48 -0
- package/src/resolution/resolve-item.ts +112 -58
- package/src/scan/index.ts +244 -0
- package/src/scan/scan-wasm.base64.ts +2 -0
- package/src/scheduling/accessor.ts +65 -23
- package/src/scheduling/availability.test.ts +204 -0
- package/src/scheduling/availability.ts +211 -0
- package/src/scheduling/cancel.test.ts +542 -0
- package/src/scheduling/cancel.ts +254 -0
- package/src/scheduling/cluster-stock.test.ts +31 -0
- package/src/scheduling/cluster-stock.ts +15 -0
- package/src/scheduling/energy.ts +47 -0
- package/src/scheduling/idle-resolve.ts +45 -0
- package/src/scheduling/jobs.ts +71 -0
- package/src/scheduling/lane-core.ts +128 -0
- package/src/scheduling/lanes.test.ts +250 -0
- package/src/scheduling/lanes.ts +227 -0
- package/src/scheduling/projection.ts +257 -133
- package/src/scheduling/schedule.test.ts +119 -0
- package/src/scheduling/schedule.ts +257 -117
- package/src/scheduling/task-cargo.test.ts +44 -0
- package/src/scheduling/task-cargo.ts +46 -0
- package/src/scheduling/unwrap.test.ts +86 -0
- package/src/scheduling/unwrap.ts +190 -0
- package/src/shipload.ts +26 -1
- package/src/subscriptions/manager.cluster.test.ts +51 -0
- package/src/subscriptions/manager.ts +245 -172
- package/src/subscriptions/mappers.ts +5 -8
- package/src/subscriptions/types.ts +28 -3
- package/src/testing/catalog-hash.ts +19 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/projection-parity.ts +167 -0
- package/src/travel/reach.ts +21 -0
- package/src/travel/route-planner.ts +288 -0
- package/src/travel/route-simulator.ts +170 -0
- package/src/travel/travel.ts +188 -122
- package/src/types/capabilities.ts +37 -8
- package/src/types/entity.ts +3 -3
- package/src/types/index.ts +0 -1
- package/src/types.ts +51 -16
- package/src/utils/cargo.test.ts +14 -0
- package/src/utils/cargo.ts +29 -0
- package/src/utils/display-name.ts +70 -0
- package/src/utils/system.ts +15 -16
- package/src/capabilities/loading.ts +0 -8
- package/src/entities/container.ts +0 -123
- package/src/entities/ship-deploy.ts +0 -295
- package/src/entities/ship.ts +0 -221
- package/src/entities/warehouse.ts +0 -127
- package/src/types/entity-traits.ts +0 -69
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type {ServerContract} from '../contracts'
|
|
2
|
+
import {HoldKind, TaskType} from '../types'
|
|
3
|
+
import * as schedule from './schedule'
|
|
4
|
+
|
|
5
|
+
type Task = ServerContract.Types.task
|
|
6
|
+
type Coupling = ServerContract.Types.coupling
|
|
7
|
+
type CargoItem = ServerContract.Types.cargo_item
|
|
8
|
+
type ModuleEntry = ServerContract.Types.module_entry
|
|
9
|
+
|
|
10
|
+
export interface CargoEffect {
|
|
11
|
+
added: CargoItem[]
|
|
12
|
+
removed: CargoItem[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AvailabilityInput extends schedule.ScheduleData {
|
|
16
|
+
cargo: CargoItem[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CargoInput {
|
|
20
|
+
itemId: number
|
|
21
|
+
stats: bigint
|
|
22
|
+
modules?: ModuleEntry[]
|
|
23
|
+
quantity: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface IncomingSource {
|
|
27
|
+
holdId: string
|
|
28
|
+
until: Date
|
|
29
|
+
items: CargoItem[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const INCOMING_COUPLING_KINDS = new Set<number>([HoldKind.PUSH, HoldKind.GATHER, HoldKind.FLIGHT])
|
|
33
|
+
|
|
34
|
+
// Mirrors is_incoming_hold_kind: PUSH/GATHER/FLIGHT couplings deliver to the counterpart.
|
|
35
|
+
export function isIncomingCouplingKind(kind: number): boolean {
|
|
36
|
+
return INCOMING_COUPLING_KINDS.has(kind)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Mirrors has_source_hold: a HOLD_SOURCE coupling marks an escrowed clustercraft.
|
|
40
|
+
export function hasSourceCoupling(task: Task): boolean {
|
|
41
|
+
return task.couplings.some((c) => c.kind.toNumber() === HoldKind.SOURCE)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Mirrors has_incoming_coupling: any PUSH/GATHER/FLIGHT coupling delivers output to a counterpart.
|
|
45
|
+
export function hasIncomingCoupling(task: Task): boolean {
|
|
46
|
+
return task.couplings.some((c) => isIncomingCouplingKind(c.kind.toNumber()))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// A CRAFT task's output ownership: clustered escrows inputs off other members; own-output lands on the crafter.
|
|
50
|
+
export function craftCargoOwnership(task: Task): {clustered: boolean; ownOutput: boolean} {
|
|
51
|
+
const clustered = hasSourceCoupling(task)
|
|
52
|
+
return {
|
|
53
|
+
clustered,
|
|
54
|
+
ownOutput: clustered ? !hasIncomingCoupling(task) : task.couplings.length === 0,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Mirrors calc_counterpart_delivery: incoming-kind couplings only; a coupled CRAFT yields its output slot.
|
|
59
|
+
export function calcCounterpartDelivery(task: Task, coupling: Coupling): CargoItem[] {
|
|
60
|
+
if (!isIncomingCouplingKind(coupling.kind.toNumber())) return []
|
|
61
|
+
if (task.type.toNumber() === TaskType.CRAFT) {
|
|
62
|
+
return task.cargo.length === 0 ? [] : [task.cargo[task.cargo.length - 1]]
|
|
63
|
+
}
|
|
64
|
+
return task.cargo
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function taskCargoEffect(task: Task): CargoEffect {
|
|
68
|
+
switch (task.type.toNumber()) {
|
|
69
|
+
case TaskType.LOAD:
|
|
70
|
+
case TaskType.UNWRAP:
|
|
71
|
+
case TaskType.UNDEPLOY:
|
|
72
|
+
return {added: task.cargo, removed: []}
|
|
73
|
+
case TaskType.UNLOAD:
|
|
74
|
+
case TaskType.UPGRADE:
|
|
75
|
+
return {added: [], removed: task.cargo}
|
|
76
|
+
case TaskType.GATHER:
|
|
77
|
+
return task.couplings.length > 0
|
|
78
|
+
? {added: [], removed: []}
|
|
79
|
+
: {added: task.cargo, removed: []}
|
|
80
|
+
case TaskType.CRAFT: {
|
|
81
|
+
if (task.cargo.length === 0) return {added: [], removed: []}
|
|
82
|
+
const {clustered, ownOutput} = craftCargoOwnership(task)
|
|
83
|
+
return {
|
|
84
|
+
added: ownOutput ? [task.cargo[task.cargo.length - 1]] : [],
|
|
85
|
+
removed: clustered ? [] : task.cargo.slice(0, -1),
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return {added: [], removed: []}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function refKey(itemId: number, stats: bigint, modules: ModuleEntry[], entityId: string): string {
|
|
94
|
+
const base = `${itemId}:${stats.toString()}`
|
|
95
|
+
const normalizedEntityId = entityId !== '0' ? entityId : ''
|
|
96
|
+
if (modules.length === 0 && normalizedEntityId === '') return base
|
|
97
|
+
return `${base}:modules=${JSON.stringify(modules)}:entity=${normalizedEntityId}`
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function cargoKey(item: CargoItem): string {
|
|
101
|
+
return refKey(
|
|
102
|
+
item.item_id.toNumber(),
|
|
103
|
+
BigInt(item.stats.toString()),
|
|
104
|
+
item.modules ?? [],
|
|
105
|
+
item.entity_id?.toString() ?? ''
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function cargoInputKey(input: CargoInput): string {
|
|
110
|
+
return refKey(input.itemId, input.stats, input.modules ?? [], '')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function cargoQuantity(item: CargoItem): bigint {
|
|
114
|
+
return BigInt(item.quantity.toString())
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function projectedCargoAvailableAt(
|
|
118
|
+
entity: AvailabilityInput,
|
|
119
|
+
at: Date,
|
|
120
|
+
incoming: readonly IncomingSource[] = []
|
|
121
|
+
): Map<string, bigint> {
|
|
122
|
+
const avail = new Map<string, bigint>()
|
|
123
|
+
|
|
124
|
+
for (const item of entity.cargo) {
|
|
125
|
+
const key = cargoKey(item)
|
|
126
|
+
avail.set(key, (avail.get(key) ?? 0n) + cargoQuantity(item))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Every scheduled task reserves inputs against the unsettled cargo base, even already-elapsed ones.
|
|
130
|
+
const tasks = schedule.orderedTasks(entity)
|
|
131
|
+
|
|
132
|
+
for (const ordered of tasks) {
|
|
133
|
+
if (ordered.completesAt.getTime() >= at.getTime()) continue
|
|
134
|
+
|
|
135
|
+
for (const item of taskCargoEffect(ordered.task).added) {
|
|
136
|
+
const key = cargoKey(item)
|
|
137
|
+
avail.set(key, (avail.get(key) ?? 0n) + cargoQuantity(item))
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const src of incoming) {
|
|
142
|
+
if (src.until.getTime() >= at.getTime()) continue
|
|
143
|
+
for (const item of src.items) {
|
|
144
|
+
const key = cargoKey(item)
|
|
145
|
+
avail.set(key, (avail.get(key) ?? 0n) + cargoQuantity(item))
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for (const ordered of tasks) {
|
|
150
|
+
for (const item of taskCargoEffect(ordered.task).removed) {
|
|
151
|
+
const key = cargoKey(item)
|
|
152
|
+
const current = avail.get(key) ?? 0n
|
|
153
|
+
const quantity = cargoQuantity(item)
|
|
154
|
+
avail.set(key, current > quantity ? current - quantity : 0n)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return avail
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Earliest-sufficient candidate (epoch, own-lane producer completions, incoming untils); else the latest candidate.
|
|
162
|
+
export function cargoReadyAt(
|
|
163
|
+
entity: AvailabilityInput,
|
|
164
|
+
inputs: readonly CargoInput[],
|
|
165
|
+
incoming: readonly IncomingSource[] = []
|
|
166
|
+
): Date {
|
|
167
|
+
const demand = new Map<string, bigint>()
|
|
168
|
+
for (const input of inputs) {
|
|
169
|
+
const key = cargoInputKey(input)
|
|
170
|
+
demand.set(key, (demand.get(key) ?? 0n) + BigInt(input.quantity))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const candidates: number[] = [0]
|
|
174
|
+
for (const ordered of schedule.orderedTasks(entity)) {
|
|
175
|
+
for (const item of taskCargoEffect(ordered.task).added) {
|
|
176
|
+
if (demand.has(cargoKey(item))) {
|
|
177
|
+
candidates.push(ordered.completesAt.getTime())
|
|
178
|
+
break
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const src of incoming) {
|
|
183
|
+
if (src.items.some((item) => demand.has(cargoKey(item)))) {
|
|
184
|
+
candidates.push(src.until.getTime())
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
candidates.sort((a, b) => a - b)
|
|
188
|
+
|
|
189
|
+
for (const candidateMs of candidates) {
|
|
190
|
+
// +1ms mirrors the contract's candidate+1µs probe: inclusive at the candidate instant.
|
|
191
|
+
const available = projectedCargoAvailableAt(entity, new Date(candidateMs + 1), incoming)
|
|
192
|
+
let sufficient = true
|
|
193
|
+
for (const [key, quantity] of demand) {
|
|
194
|
+
if ((available.get(key) ?? 0n) < quantity) {
|
|
195
|
+
sufficient = false
|
|
196
|
+
break
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (sufficient) return new Date(candidateMs)
|
|
200
|
+
}
|
|
201
|
+
return new Date(candidates[candidates.length - 1])
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function availableForItem(avail: Map<string, bigint>, itemId: number): bigint {
|
|
205
|
+
const prefix = `${itemId}:`
|
|
206
|
+
let total = 0n
|
|
207
|
+
for (const [key, quantity] of avail) {
|
|
208
|
+
if (key.startsWith(prefix)) total += quantity
|
|
209
|
+
}
|
|
210
|
+
return total
|
|
211
|
+
}
|