@shipload/sdk 1.0.0-next.52 → 1.0.0-next.54
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.d.ts +61 -21
- package/lib/shipload.js +133 -45
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +134 -46
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +15 -6
- package/lib/testing.js +53 -20
- package/lib/testing.js.map +1 -1
- package/lib/testing.m.js +53 -20
- package/lib/testing.m.js.map +1 -1
- package/package.json +1 -1
- package/src/contracts/server.ts +55 -21
- package/src/data/capabilities.ts +7 -0
- package/src/data/capability-formulas.ts +5 -0
- package/src/data/recipes.json +12 -5
- package/src/derivation/capabilities.test.ts +24 -0
- package/src/derivation/capabilities.ts +4 -4
- package/src/derivation/capability-mappings.ts +2 -0
- package/src/entities/entity.ts +4 -0
- package/src/nft/buildImmutableData.ts +6 -6
- package/src/nft/description.ts +9 -6
- package/src/scheduling/lanes.ts +4 -4
- package/src/scheduling/projection.ts +14 -1
- package/src/scheduling/schedule.test.ts +116 -0
- package/src/scheduling/schedule.ts +23 -2
- package/src/types.ts +7 -0
package/src/entities/entity.ts
CHANGED
|
@@ -31,6 +31,10 @@ export class Entity extends ServerContract.Types.entity_info {
|
|
|
31
31
|
return schedule.isIdle(this)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
get hasPendingCapper(): boolean {
|
|
35
|
+
return schedule.hasPendingCapper(this)
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
get sched(): ScheduleAccessor {
|
|
35
39
|
this._sched ??= new ScheduleAccessor(this)
|
|
36
40
|
return this._sched
|
|
@@ -263,12 +263,12 @@ export function buildModuleImmutable(
|
|
|
263
263
|
break
|
|
264
264
|
}
|
|
265
265
|
case MODULE_BUILDER: {
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
base.push({first: '
|
|
269
|
-
base.push({first: '
|
|
270
|
-
base.push({first: 'speed', second: ['uint16', computeBuilderSpeed(
|
|
271
|
-
base.push({first: 'drain', second: ['uint16', toWholeEnergy(computeBuilderDrain(
|
|
266
|
+
const res = decodeStat(stats, 0)
|
|
267
|
+
const fin = decodeStat(stats, 1)
|
|
268
|
+
base.push({first: 'resonance', second: ['uint16', res]})
|
|
269
|
+
base.push({first: 'fineness', second: ['uint16', fin]})
|
|
270
|
+
base.push({first: 'speed', second: ['uint16', computeBuilderSpeed(res)]})
|
|
271
|
+
base.push({first: 'drain', second: ['uint16', toWholeEnergy(computeBuilderDrain(fin))]})
|
|
272
272
|
break
|
|
273
273
|
}
|
|
274
274
|
case MODULE_STORAGE: {
|
package/src/nft/description.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
ITEM_TUG_T1_PACKED,
|
|
38
38
|
ITEM_PORTER_T1_PACKED,
|
|
39
39
|
ITEM_WRANGLER_T1_PACKED,
|
|
40
|
+
ITEM_WRIGHT_T1_PACKED,
|
|
40
41
|
ITEM_DREDGER_T1_PACKED,
|
|
41
42
|
ITEM_WAREHOUSE_T1_PACKED,
|
|
42
43
|
ITEM_WARP_T1,
|
|
@@ -114,9 +115,9 @@ export const computeLoaderThrust = (pla: number): number => 1 + idiv(pla * pla,
|
|
|
114
115
|
export const computeCrafterSpeed = (rea: number): number => 100 + idiv(rea * 4, 5)
|
|
115
116
|
export const computeCrafterDrain = (fin: number): number =>
|
|
116
117
|
Math.max(5000, 30000 - idiv(fin * 1000, 33))
|
|
117
|
-
export const computeBuilderSpeed = (
|
|
118
|
-
export const computeBuilderDrain = (
|
|
119
|
-
Math.max(5000, 30000 - idiv(
|
|
118
|
+
export const computeBuilderSpeed = (resonance: number): number => 100 + idiv(resonance * 4, 5)
|
|
119
|
+
export const computeBuilderDrain = (fineness: number): number =>
|
|
120
|
+
Math.max(5000, 30000 - idiv(fineness * 1000, 33))
|
|
120
121
|
export const computeHaulerCapacity = (fin: number, tier: number): number =>
|
|
121
122
|
Math.max(tier, tier + idiv(fin, 400))
|
|
122
123
|
export const computeHaulerEfficiency = (con: number): number => 2000 + con * 6
|
|
@@ -159,6 +160,8 @@ export function entityDisplayName(itemId: number): string {
|
|
|
159
160
|
return 'Porter'
|
|
160
161
|
case ITEM_WRANGLER_T1_PACKED:
|
|
161
162
|
return 'Wrangler'
|
|
163
|
+
case ITEM_WRIGHT_T1_PACKED:
|
|
164
|
+
return 'Wright'
|
|
162
165
|
case ITEM_DREDGER_T1_PACKED:
|
|
163
166
|
return 'Dredger'
|
|
164
167
|
case ITEM_WAREHOUSE_T1_PACKED:
|
|
@@ -260,9 +263,9 @@ export function formatModuleLine(slot: number, itemId: number, stats: bigint): s
|
|
|
260
263
|
break
|
|
261
264
|
}
|
|
262
265
|
case MODULE_BUILDER: {
|
|
263
|
-
const
|
|
264
|
-
const
|
|
265
|
-
out += ` Speed ${computeBuilderSpeed(
|
|
266
|
+
const res = decodeStat(stats, 0)
|
|
267
|
+
const fin = decodeStat(stats, 1)
|
|
268
|
+
out += ` Speed ${computeBuilderSpeed(res)} Drain ${toWholeEnergy(computeBuilderDrain(fin))}`
|
|
266
269
|
break
|
|
267
270
|
}
|
|
268
271
|
case MODULE_STORAGE: {
|
package/src/scheduling/lanes.ts
CHANGED
|
@@ -130,12 +130,12 @@ export function resolveLaneBuilder(
|
|
|
130
130
|
const item = getItem(Number(installed.item_id.value ?? installed.item_id))
|
|
131
131
|
if (item.moduleType !== 'builder') throw new Error('lane module is not a builder')
|
|
132
132
|
const stats = BigInt(installed.stats.toString())
|
|
133
|
-
const
|
|
134
|
-
const
|
|
133
|
+
const res = decodeStat(stats, 0)
|
|
134
|
+
const fin = decodeStat(stats, 1)
|
|
135
135
|
const layout = getEntityLayout(entityItemId)?.slots ?? []
|
|
136
136
|
const amp = getSlotAmp(layout, idx)
|
|
137
|
-
const speed = applySlotMultiplier(computeBuilderSpeed(
|
|
138
|
-
const drain = computeBuilderDrain(
|
|
137
|
+
const speed = applySlotMultiplier(computeBuilderSpeed(res), amp)
|
|
138
|
+
const drain = computeBuilderDrain(fin)
|
|
139
139
|
return {slotIndex: idx, speed, drain, outputPct: amp}
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Name, type UInt16, UInt32, UInt64} from '@wharfkit/antelope'
|
|
2
2
|
import {ServerContract} from '../contracts'
|
|
3
|
-
import {Coordinates, TaskType} from '../types'
|
|
3
|
+
import {Coordinates, RefitOp, TaskType} from '../types'
|
|
4
4
|
import {
|
|
5
5
|
capsHasMovement,
|
|
6
6
|
capsHasStorage,
|
|
@@ -402,6 +402,13 @@ function applyCraftTask(projected: ProjectedEntity, task: ServerContract.Types.t
|
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
|
|
405
|
+
// Mirrors calc_task_effect's TASK_REFIT: only ADD has a projectable cargo effect (REMOVE/SWAP return mass the entity row holds, invisible to the task itself).
|
|
406
|
+
function applyRefitTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|
|
407
|
+
if (task.refit?.op.toNumber() === RefitOp.ADD) {
|
|
408
|
+
removeCargoItem(projected, task.cargo[0])
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
405
412
|
function applyTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|
|
406
413
|
switch (task.type.toNumber()) {
|
|
407
414
|
case TaskType.RECHARGE:
|
|
@@ -425,6 +432,9 @@ function applyTask(projected: ProjectedEntity, task: ServerContract.Types.task):
|
|
|
425
432
|
case TaskType.CRAFT:
|
|
426
433
|
applyCraftTask(projected, task)
|
|
427
434
|
break
|
|
435
|
+
case TaskType.REFIT:
|
|
436
|
+
applyRefitTask(projected, task)
|
|
437
|
+
break
|
|
428
438
|
case TaskType.UNDEPLOY:
|
|
429
439
|
case TaskType.DEMOLISH:
|
|
430
440
|
break
|
|
@@ -581,6 +591,9 @@ export function projectEntityAt(entity: Projectable, now: Date): ProjectedEntity
|
|
|
581
591
|
case TaskType.CRAFT:
|
|
582
592
|
if (taskComplete) applyCraftTask(projected, task)
|
|
583
593
|
break
|
|
594
|
+
case TaskType.REFIT:
|
|
595
|
+
if (taskComplete) applyRefitTask(projected, task)
|
|
596
|
+
break
|
|
584
597
|
case TaskType.UNDEPLOY:
|
|
585
598
|
case TaskType.DEMOLISH:
|
|
586
599
|
break
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import {describe, expect, test} from 'bun:test'
|
|
2
|
+
import {ServerContract, TaskType} from '../index-module'
|
|
3
|
+
import {hasPendingCapper, hasResolvable, isCapperTaskType} from './schedule'
|
|
4
|
+
|
|
5
|
+
const T0 = '2026-06-19T00:00:00'
|
|
6
|
+
const NOW = new Date('2026-06-19T00:01:00.000Z')
|
|
7
|
+
|
|
8
|
+
function task(over: Partial<{type: number; duration: number}>) {
|
|
9
|
+
return ServerContract.Types.task.from({
|
|
10
|
+
type: over.type ?? TaskType.TRAVEL,
|
|
11
|
+
duration: over.duration ?? 30,
|
|
12
|
+
cancelable: 0,
|
|
13
|
+
cargo: [],
|
|
14
|
+
couplings: [],
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function entity(
|
|
19
|
+
tasks: ReturnType<typeof task>[],
|
|
20
|
+
holds: ServerContract.Types.hold[] = [],
|
|
21
|
+
startedISO = T0
|
|
22
|
+
) {
|
|
23
|
+
return ServerContract.Types.entity_info.from({
|
|
24
|
+
type: 'ship',
|
|
25
|
+
id: 1,
|
|
26
|
+
owner: 'player.gm',
|
|
27
|
+
entity_name: 'Ship 1',
|
|
28
|
+
coordinates: {x: 0, y: 0, z: 0},
|
|
29
|
+
item_id: 1,
|
|
30
|
+
cargomass: 0,
|
|
31
|
+
cargo: [],
|
|
32
|
+
modules: [],
|
|
33
|
+
lanes: [{lane_key: 0, schedule: {started: startedISO, tasks}}],
|
|
34
|
+
gatherer_lanes: [],
|
|
35
|
+
crafter_lanes: [],
|
|
36
|
+
builder_lanes: [],
|
|
37
|
+
loader_lanes: [],
|
|
38
|
+
holds,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function hold(kind: number) {
|
|
43
|
+
return ServerContract.Types.hold.from({
|
|
44
|
+
id: 1,
|
|
45
|
+
kind,
|
|
46
|
+
counterpart: {entity_type: 'ship', entity_id: 2},
|
|
47
|
+
until: T0,
|
|
48
|
+
incoming_mass: 0,
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe('isCapperTaskType', () => {
|
|
53
|
+
test('UNDEPLOY, DEMOLISH, REFIT are cappers', () => {
|
|
54
|
+
expect(isCapperTaskType(TaskType.UNDEPLOY)).toBe(true)
|
|
55
|
+
expect(isCapperTaskType(TaskType.DEMOLISH)).toBe(true)
|
|
56
|
+
expect(isCapperTaskType(TaskType.REFIT)).toBe(true)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('non-capper task types are not cappers', () => {
|
|
60
|
+
expect(isCapperTaskType(TaskType.TRAVEL)).toBe(false)
|
|
61
|
+
expect(isCapperTaskType(TaskType.LOAD)).toBe(false)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('hasPendingCapper', () => {
|
|
66
|
+
test('false with no schedule', () => {
|
|
67
|
+
expect(hasPendingCapper(entity([]))).toBe(false)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('false with only non-capper tasks queued', () => {
|
|
71
|
+
expect(hasPendingCapper(entity([task({type: TaskType.TRAVEL})]))).toBe(false)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('true when a REFIT task is queued anywhere in the lane', () => {
|
|
75
|
+
const e = entity([task({type: TaskType.TRAVEL}), task({type: TaskType.REFIT})])
|
|
76
|
+
expect(hasPendingCapper(e)).toBe(true)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('true when a DEMOLISH task is queued', () => {
|
|
80
|
+
expect(hasPendingCapper(entity([task({type: TaskType.DEMOLISH})]))).toBe(true)
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('hasResolvable — capper gating', () => {
|
|
85
|
+
test('a completed non-capper front is resolvable', () => {
|
|
86
|
+
const e = entity([task({type: TaskType.TRAVEL, duration: 30})])
|
|
87
|
+
expect(hasResolvable(e, NOW)).toBe(true)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('a completed capper front with no holds is resolvable', () => {
|
|
91
|
+
const e = entity([task({type: TaskType.REFIT, duration: 30})])
|
|
92
|
+
expect(hasResolvable(e, NOW)).toBe(true)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('a completed capper front with a live hold is gated', () => {
|
|
96
|
+
const e = entity([task({type: TaskType.REFIT, duration: 30})], [hold(2)])
|
|
97
|
+
expect(hasResolvable(e, NOW)).toBe(false)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('a capper front clears once holds empty', () => {
|
|
101
|
+
const withHold = entity([task({type: TaskType.REFIT, duration: 30})], [hold(2)])
|
|
102
|
+
const cleared = entity([task({type: TaskType.REFIT, duration: 30})], [])
|
|
103
|
+
expect(hasResolvable(withHold, NOW)).toBe(false)
|
|
104
|
+
expect(hasResolvable(cleared, NOW)).toBe(true)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('a live hold does not gate a non-capper front', () => {
|
|
108
|
+
const e = entity([task({type: TaskType.TRAVEL, duration: 30})], [hold(2)])
|
|
109
|
+
expect(hasResolvable(e, NOW)).toBe(true)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('an in-progress front is not resolvable regardless of holds', () => {
|
|
113
|
+
const e = entity([task({type: TaskType.REFIT, duration: 3600})])
|
|
114
|
+
expect(hasResolvable(e, NOW)).toBe(false)
|
|
115
|
+
})
|
|
116
|
+
})
|
|
@@ -63,6 +63,24 @@ export function isIdle(entity: ScheduleData): boolean {
|
|
|
63
63
|
return !hasSchedule(entity) && !hasHolds(entity)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// Mirrors is_capper_task_type: demolish/undeploy/refit cap a plan — no further appends once queued.
|
|
67
|
+
export function isCapperTaskType(taskType: number): boolean {
|
|
68
|
+
return (
|
|
69
|
+
taskType === TaskType.UNDEPLOY ||
|
|
70
|
+
taskType === TaskType.DEMOLISH ||
|
|
71
|
+
taskType === TaskType.REFIT
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function hasPendingCapper(entity: ScheduleData): boolean {
|
|
76
|
+
for (const l of entity.lanes ?? []) {
|
|
77
|
+
for (const t of l.schedule.tasks) {
|
|
78
|
+
if (isCapperTaskType(t.type.toNumber())) return true
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
|
|
66
84
|
export function isEntityIdle(entity: ScheduleData, now: Date): boolean {
|
|
67
85
|
if (hasHolds(entity)) return false
|
|
68
86
|
const lanes = entity.lanes
|
|
@@ -121,10 +139,13 @@ export function scheduleComplete(entity: ScheduleData, now: Date): boolean {
|
|
|
121
139
|
return remaining === 0
|
|
122
140
|
}
|
|
123
141
|
|
|
124
|
-
// Mirrors
|
|
142
|
+
// Mirrors lane_front_complete && !capper_front_gated for own-entity holds (workshop/undeploy-target gates need cross-entity context this ScheduleData lacks).
|
|
125
143
|
export function hasResolvable(entity: ScheduleData, now: Date): boolean {
|
|
126
144
|
for (const l of entity.lanes ?? []) {
|
|
127
|
-
if (core.laneTaskComplete(l.schedule, 0, now))
|
|
145
|
+
if (!core.laneTaskComplete(l.schedule, 0, now)) continue
|
|
146
|
+
const front = l.schedule.tasks[0]
|
|
147
|
+
if (isCapperTaskType(front.type.toNumber()) && hasHolds(entity)) continue
|
|
148
|
+
return true
|
|
128
149
|
}
|
|
129
150
|
return false
|
|
130
151
|
}
|