@shipload/sdk 1.0.0-next.67 → 1.0.0-next.68

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 CHANGED
@@ -5080,8 +5080,8 @@ interface CivicShuttleBay {
5080
5080
  queued: number;
5081
5081
  full: boolean;
5082
5082
  }
5083
- declare function civicShuttleBays(modules: ModuleEntry$5[], entityItemId: number, lanes: Lane$1[]): CivicShuttleBay[];
5084
- declare function selectCivicShuttleBay(modules: ModuleEntry$5[], entityItemId: number, lanes: Lane$1[]): CivicShuttleBay | undefined;
5083
+ declare function civicShuttleBays(modules: ModuleEntry$5[], entityItemId: number, lanes: Lane$1[], now?: Date): CivicShuttleBay[];
5084
+ declare function selectCivicShuttleBay(modules: ModuleEntry$5[], entityItemId: number, lanes: Lane$1[], now?: Date): CivicShuttleBay | undefined;
5085
5085
  interface PendingCivicTransfer {
5086
5086
  laneKey: number;
5087
5087
  taskIndex: number;
@@ -5091,11 +5091,12 @@ interface PendingCivicTransfer {
5091
5091
  startsAt: Date;
5092
5092
  completesAt: Date;
5093
5093
  isTail: boolean;
5094
+ complete: boolean;
5094
5095
  callable: boolean;
5095
5096
  }
5096
- declare function pendingCivicTransfers(entity: ScheduleData): PendingCivicTransfer[];
5097
- declare function civicTransfersFrom(entity: ScheduleData, senderIds: Array<UInt64 | string | number>): PendingCivicTransfer[];
5098
- declare function civicTransfersAtCap(entity: ScheduleData, senderIds: Array<UInt64 | string | number>): boolean;
5097
+ declare function pendingCivicTransfers(entity: ScheduleData, now?: Date): PendingCivicTransfer[];
5098
+ declare function civicTransfersFrom(entity: ScheduleData, senderIds: Array<UInt64 | string | number>, now?: Date): PendingCivicTransfer[];
5099
+ declare function civicTransfersAtCap(entity: ScheduleData, senderIds: Array<UInt64 | string | number>, now?: Date): boolean;
5099
5100
 
5100
5101
  declare function citizenryName(gameSeed: Checksum256Type, coordinates: CoordinatesType): string | undefined;
5101
5102
  declare function citizenryPatternCount(): number;
package/lib/shipload.js CHANGED
@@ -20085,7 +20085,21 @@ function depotTransferDuration(params) {
20085
20085
  }
20086
20086
 
20087
20087
  const CIVIC_TRANSFER_PER_PLAYER_CAP = 4;
20088
- function civicShuttleBays(modules, entityItemId, lanes) {
20088
+ function unfinishedTasks(lane, now) {
20089
+ if (!lane)
20090
+ return 0;
20091
+ const startedMs = lane.schedule.started.toDate().getTime();
20092
+ const nowMs = now.getTime();
20093
+ let endSec = 0;
20094
+ let count = 0;
20095
+ for (const task of lane.schedule.tasks) {
20096
+ endSec += task.duration.toNumber();
20097
+ if (startedMs + endSec * 1000 > nowMs)
20098
+ count++;
20099
+ }
20100
+ return count;
20101
+ }
20102
+ function civicShuttleBays(modules, entityItemId, lanes, now = new Date()) {
20089
20103
  const bays = [];
20090
20104
  for (let slotIndex = 0; slotIndex < modules.length; slotIndex++) {
20091
20105
  const installed = modules[slotIndex].installed;
@@ -20096,7 +20110,7 @@ function civicShuttleBays(modules, entityItemId, lanes) {
20096
20110
  const laneKey = laneKeyForModule(slotIndex);
20097
20111
  const loader = resolveLaneLoader(modules, entityItemId, laneKey);
20098
20112
  const lane = lanes.find((l) => l.lane_key.toNumber() === laneKey);
20099
- const queued = lane ? lane.schedule.tasks.length : 0;
20113
+ const queued = unfinishedTasks(lane, now);
20100
20114
  bays.push({
20101
20115
  laneKey,
20102
20116
  slotIndex,
@@ -20109,11 +20123,11 @@ function civicShuttleBays(modules, entityItemId, lanes) {
20109
20123
  }
20110
20124
  return bays;
20111
20125
  }
20112
- function selectCivicShuttleBay(modules, entityItemId, lanes) {
20113
- const bays = civicShuttleBays(modules, entityItemId, lanes);
20126
+ function selectCivicShuttleBay(modules, entityItemId, lanes, now = new Date()) {
20127
+ const bays = civicShuttleBays(modules, entityItemId, lanes, now);
20114
20128
  return bays.find((bay) => bay.queued === 0) ?? bays[0];
20115
20129
  }
20116
- function pendingCivicTransfers(entity) {
20130
+ function pendingCivicTransfers(entity, now = new Date()) {
20117
20131
  const tailIndex = new Map();
20118
20132
  for (const l of entity.lanes ?? []) {
20119
20133
  tailIndex.set(l.lane_key.toNumber(), l.schedule.tasks.length - 1);
@@ -20127,6 +20141,7 @@ function pendingCivicTransfers(entity) {
20127
20141
  if (!pull || !push)
20128
20142
  continue;
20129
20143
  const isTail = tailIndex.get(entry.laneKey) === entry.taskIndex;
20144
+ const complete = entry.completesAt.getTime() <= now.getTime();
20130
20145
  out.push({
20131
20146
  laneKey: entry.laneKey,
20132
20147
  taskIndex: entry.taskIndex,
@@ -20136,17 +20151,19 @@ function pendingCivicTransfers(entity) {
20136
20151
  startsAt: entry.startsAt,
20137
20152
  completesAt: entry.completesAt,
20138
20153
  isTail,
20139
- callable: isTail && !entry.task.entitygroup,
20154
+ complete,
20155
+ callable: isTail && !complete && !entry.task.entitygroup,
20140
20156
  });
20141
20157
  }
20142
20158
  return out;
20143
20159
  }
20144
- function civicTransfersFrom(entity, senderIds) {
20160
+ function civicTransfersFrom(entity, senderIds, now = new Date()) {
20145
20161
  const owned = new Set(senderIds.map((id) => String(id)));
20146
- return pendingCivicTransfers(entity).filter((t) => owned.has(String(t.senderId)));
20162
+ return pendingCivicTransfers(entity, now).filter((t) => owned.has(String(t.senderId)));
20147
20163
  }
20148
- function civicTransfersAtCap(entity, senderIds) {
20149
- return civicTransfersFrom(entity, senderIds).length >= CIVIC_TRANSFER_PER_PLAYER_CAP;
20164
+ function civicTransfersAtCap(entity, senderIds, now = new Date()) {
20165
+ return (civicTransfersFrom(entity, senderIds, now).filter((t) => !t.complete).length >=
20166
+ CIVIC_TRANSFER_PER_PLAYER_CAP);
20150
20167
  }
20151
20168
 
20152
20169
  var citizenryAdjectives = [