@shipload/sdk 1.0.0-next.55 → 1.0.0-next.56
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 +32 -10
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +32 -10
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/managers/construction.ts +41 -10
package/package.json
CHANGED
|
@@ -95,20 +95,24 @@ export class ConstructionManager extends BaseManager {
|
|
|
95
95
|
now: Date
|
|
96
96
|
): Map<string, InboundTransfer[]> {
|
|
97
97
|
const buckets = new Map<string, Map<string, InboundTransfer>>()
|
|
98
|
+
const entitiesById = new Map(entities.map((entity) => [entity.id.toString(), entity]))
|
|
98
99
|
const nowMs = now.getTime()
|
|
99
100
|
for (const entity of entities) {
|
|
100
|
-
const entityIdStr = entity.id.toString()
|
|
101
|
-
const sourceName = entity.entity_name || entityIdStr
|
|
102
101
|
for (const lane of getLanes(entity)) {
|
|
103
102
|
const startedMs = lane.schedule.started.toDate().getTime()
|
|
104
103
|
let cumulativeSec = 0
|
|
105
104
|
for (const task of lane.schedule.tasks) {
|
|
106
105
|
cumulativeSec += task.duration.toNumber()
|
|
107
|
-
if (!
|
|
108
|
-
|
|
106
|
+
if (!isDeliveryTask(task)) continue
|
|
107
|
+
const target = deliveryTarget(task)
|
|
108
|
+
if (!target) continue
|
|
109
|
+
const source = deliverySource(task, entity, entitiesById)
|
|
110
|
+
if (!source) continue
|
|
109
111
|
const projectedEndMs = startedMs + cumulativeSec * 1000
|
|
110
112
|
if (projectedEndMs < nowMs) continue
|
|
111
|
-
const targetIdStr =
|
|
113
|
+
const targetIdStr = target.entity_id.toString()
|
|
114
|
+
const sourceIdStr = source.id.toString()
|
|
115
|
+
const sourceName = source.entity_name || sourceIdStr
|
|
112
116
|
const etaSeconds = Math.max(0, Math.round((projectedEndMs - nowMs) / 1000))
|
|
113
117
|
let perTarget = buckets.get(targetIdStr)
|
|
114
118
|
if (!perTarget) {
|
|
@@ -119,15 +123,15 @@ export class ConstructionManager extends BaseManager {
|
|
|
119
123
|
const itemId = c.item_id.toNumber()
|
|
120
124
|
const quantity = c.quantity.toNumber()
|
|
121
125
|
if (quantity === 0) continue
|
|
122
|
-
const key = `${
|
|
126
|
+
const key = `${sourceIdStr}#${itemId}`
|
|
123
127
|
const existing = perTarget.get(key)
|
|
124
128
|
if (existing) {
|
|
125
129
|
existing.quantity += quantity
|
|
126
130
|
existing.etaSeconds = Math.min(existing.etaSeconds, etaSeconds)
|
|
127
131
|
} else {
|
|
128
132
|
perTarget.set(key, {
|
|
129
|
-
sourceEntityId:
|
|
130
|
-
sourceEntityType:
|
|
133
|
+
sourceEntityId: source.id,
|
|
134
|
+
sourceEntityType: source.type,
|
|
131
135
|
sourceName,
|
|
132
136
|
itemId,
|
|
133
137
|
quantity,
|
|
@@ -363,7 +367,34 @@ function partitionSources(
|
|
|
363
367
|
return {eligible, unreachable}
|
|
364
368
|
}
|
|
365
369
|
|
|
366
|
-
function
|
|
370
|
+
function isDeliveryTask(task: ServerContract.Types.task): boolean {
|
|
371
|
+
const type = task.type.toNumber()
|
|
372
|
+
return type === TaskType.UNLOAD || type === TaskType.SHUTTLE
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function deliveryTarget(
|
|
376
|
+
task: ServerContract.Types.task
|
|
377
|
+
): ServerContract.Types.entity_ref | undefined {
|
|
378
|
+
if (task.type.toNumber() === TaskType.SHUTTLE) {
|
|
379
|
+
return task.couplings.find((coupling) => coupling.kind.toNumber() === HoldKind.PUSH)
|
|
380
|
+
?.counterpart
|
|
381
|
+
}
|
|
382
|
+
return task.couplings[0]?.counterpart
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function deliverySource(
|
|
386
|
+
task: ServerContract.Types.task,
|
|
387
|
+
transporter: ServerContract.Types.entity_info,
|
|
388
|
+
entitiesById: ReadonlyMap<string, ServerContract.Types.entity_info>
|
|
389
|
+
): ServerContract.Types.entity_info | undefined {
|
|
390
|
+
if (task.type.toNumber() !== TaskType.SHUTTLE) return transporter
|
|
391
|
+
const source = task.couplings.find(
|
|
392
|
+
(coupling) => coupling.kind.toNumber() === HoldKind.PULL
|
|
393
|
+
)?.counterpart
|
|
394
|
+
return source ? entitiesById.get(source.entity_id.toString()) : undefined
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function isReservingPushTask(task: ServerContract.Types.task): boolean {
|
|
367
398
|
return task.type.toNumber() === TaskType.UNLOAD
|
|
368
399
|
}
|
|
369
400
|
|
|
@@ -378,7 +409,7 @@ function isBuildOfPlot(task: ServerContract.Types.task, plotId: UInt64): boolean
|
|
|
378
409
|
function reservationsOf(source: ServerContract.Types.entity_info): Reservation[] {
|
|
379
410
|
const out = new Map<string, Reservation>()
|
|
380
411
|
for (const task of getTasks(source)) {
|
|
381
|
-
if (!
|
|
412
|
+
if (!isReservingPushTask(task)) continue
|
|
382
413
|
if (task.couplings.length === 0) continue
|
|
383
414
|
const targetType = task.couplings[0].counterpart.entity_type
|
|
384
415
|
const targetId = task.couplings[0].counterpart.entity_id
|