@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 CHANGED
@@ -17353,23 +17353,28 @@ class ConstructionManager extends BaseManager {
17353
17353
  }
17354
17354
  inboundTransfersByTarget(entities, now) {
17355
17355
  const buckets = new Map();
17356
+ const entitiesById = new Map(entities.map((entity) => [entity.id.toString(), entity]));
17356
17357
  const nowMs = now.getTime();
17357
17358
  for (const entity of entities) {
17358
- const entityIdStr = entity.id.toString();
17359
- const sourceName = entity.entity_name || entityIdStr;
17360
17359
  for (const lane of getLanes(entity)) {
17361
17360
  const startedMs = lane.schedule.started.toDate().getTime();
17362
17361
  let cumulativeSec = 0;
17363
17362
  for (const task of lane.schedule.tasks) {
17364
17363
  cumulativeSec += task.duration.toNumber();
17365
- if (!isPushTask(task))
17364
+ if (!isDeliveryTask(task))
17366
17365
  continue;
17367
- if (task.couplings.length === 0)
17366
+ const target = deliveryTarget(task);
17367
+ if (!target)
17368
+ continue;
17369
+ const source = deliverySource(task, entity, entitiesById);
17370
+ if (!source)
17368
17371
  continue;
17369
17372
  const projectedEndMs = startedMs + cumulativeSec * 1000;
17370
17373
  if (projectedEndMs < nowMs)
17371
17374
  continue;
17372
- const targetIdStr = task.couplings[0].counterpart.entity_id.toString();
17375
+ const targetIdStr = target.entity_id.toString();
17376
+ const sourceIdStr = source.id.toString();
17377
+ const sourceName = source.entity_name || sourceIdStr;
17373
17378
  const etaSeconds = Math.max(0, Math.round((projectedEndMs - nowMs) / 1000));
17374
17379
  let perTarget = buckets.get(targetIdStr);
17375
17380
  if (!perTarget) {
@@ -17381,7 +17386,7 @@ class ConstructionManager extends BaseManager {
17381
17386
  const quantity = c.quantity.toNumber();
17382
17387
  if (quantity === 0)
17383
17388
  continue;
17384
- const key = `${entityIdStr}#${itemId}`;
17389
+ const key = `${sourceIdStr}#${itemId}`;
17385
17390
  const existing = perTarget.get(key);
17386
17391
  if (existing) {
17387
17392
  existing.quantity += quantity;
@@ -17389,8 +17394,8 @@ class ConstructionManager extends BaseManager {
17389
17394
  }
17390
17395
  else {
17391
17396
  perTarget.set(key, {
17392
- sourceEntityId: entity.id,
17393
- sourceEntityType: entity.type,
17397
+ sourceEntityId: source.id,
17398
+ sourceEntityType: source.type,
17394
17399
  sourceName,
17395
17400
  itemId,
17396
17401
  quantity,
@@ -17583,7 +17588,24 @@ function partitionSources(target, entities, cargo) {
17583
17588
  }
17584
17589
  return { eligible, unreachable };
17585
17590
  }
17586
- function isPushTask(task) {
17591
+ function isDeliveryTask(task) {
17592
+ const type = task.type.toNumber();
17593
+ return type === exports.TaskType.UNLOAD || type === exports.TaskType.SHUTTLE;
17594
+ }
17595
+ function deliveryTarget(task) {
17596
+ if (task.type.toNumber() === exports.TaskType.SHUTTLE) {
17597
+ return task.couplings.find((coupling) => coupling.kind.toNumber() === exports.HoldKind.PUSH)
17598
+ ?.counterpart;
17599
+ }
17600
+ return task.couplings[0]?.counterpart;
17601
+ }
17602
+ function deliverySource(task, transporter, entitiesById) {
17603
+ if (task.type.toNumber() !== exports.TaskType.SHUTTLE)
17604
+ return transporter;
17605
+ const source = task.couplings.find((coupling) => coupling.kind.toNumber() === exports.HoldKind.PULL)?.counterpart;
17606
+ return source ? entitiesById.get(source.entity_id.toString()) : undefined;
17607
+ }
17608
+ function isReservingPushTask(task) {
17587
17609
  return task.type.toNumber() === exports.TaskType.UNLOAD;
17588
17610
  }
17589
17611
  function isBuildOfPlot(task, plotId) {
@@ -17594,7 +17616,7 @@ function isBuildOfPlot(task, plotId) {
17594
17616
  function reservationsOf(source) {
17595
17617
  const out = new Map();
17596
17618
  for (const task of getTasks(source)) {
17597
- if (!isPushTask(task))
17619
+ if (!isReservingPushTask(task))
17598
17620
  continue;
17599
17621
  if (task.couplings.length === 0)
17600
17622
  continue;