@shipload/sdk 1.0.0-next.21 → 1.0.0-next.22
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 +3 -1
- package/lib/shipload.js +43 -10
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +43 -11
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/index-module.ts +2 -0
- package/src/managers/construction.ts +3 -4
- package/src/scheduling/energy.ts +41 -0
- package/src/scheduling/projection.ts +10 -11
package/package.json
CHANGED
package/src/index-module.ts
CHANGED
|
@@ -204,6 +204,8 @@ export type {
|
|
|
204
204
|
export {taskCargoChanges} from './scheduling/task-cargo'
|
|
205
205
|
export type {TaskCargoChange, TaskCargoDirection} from './scheduling/task-cargo'
|
|
206
206
|
|
|
207
|
+
export {energyAtTime} from './scheduling/energy'
|
|
208
|
+
|
|
207
209
|
export * from './types/capabilities'
|
|
208
210
|
export * from './types/entity'
|
|
209
211
|
export {
|
|
@@ -102,11 +102,10 @@ export class ConstructionManager extends BaseManager {
|
|
|
102
102
|
cumulativeSec += task.duration.toNumber()
|
|
103
103
|
if (!isTransferTask(task)) continue
|
|
104
104
|
if (!task.entitytarget) continue
|
|
105
|
+
const projectedEndMs = startedMs + cumulativeSec * 1000
|
|
106
|
+
if (projectedEndMs < nowMs) continue
|
|
105
107
|
const targetIdStr = task.entitytarget.entity_id.toString()
|
|
106
|
-
const etaSeconds = Math.max(
|
|
107
|
-
0,
|
|
108
|
-
Math.round((startedMs + cumulativeSec * 1000 - nowMs) / 1000)
|
|
109
|
-
)
|
|
108
|
+
const etaSeconds = Math.max(0, Math.round((projectedEndMs - nowMs) / 1000))
|
|
110
109
|
let perTarget = buckets.get(targetIdStr)
|
|
111
110
|
if (!perTarget) {
|
|
112
111
|
perTarget = new Map()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {TaskType} from '../types'
|
|
2
|
+
import {createProjectedEntity, type Projectable} from './projection'
|
|
3
|
+
import {currentTaskIndex, currentTaskProgressFloat, isTaskComplete} from './schedule'
|
|
4
|
+
|
|
5
|
+
export function energyAtTime(entity: Projectable, now: Date): number {
|
|
6
|
+
const projected = createProjectedEntity(entity)
|
|
7
|
+
const capacity = projected.generator ? Number(projected.generator.capacity) : undefined
|
|
8
|
+
|
|
9
|
+
const clamp = (value: number): number => {
|
|
10
|
+
const floored = Math.max(0, value)
|
|
11
|
+
return capacity !== undefined ? Math.min(capacity, floored) : floored
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let running = Number(projected.energy)
|
|
15
|
+
|
|
16
|
+
const tasks = entity.schedule?.tasks
|
|
17
|
+
if (!tasks || tasks.length === 0) return clamp(running)
|
|
18
|
+
|
|
19
|
+
const activeIndex = currentTaskIndex(entity, now)
|
|
20
|
+
const activeProgress = currentTaskProgressFloat(entity, now)
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < tasks.length; i++) {
|
|
23
|
+
const complete = isTaskComplete(entity, i, now)
|
|
24
|
+
if (!complete && i !== activeIndex) break
|
|
25
|
+
|
|
26
|
+
const fraction = complete ? 1 : activeProgress
|
|
27
|
+
|
|
28
|
+
if (tasks[i].type.toNumber() === TaskType.RECHARGE) {
|
|
29
|
+
if (capacity !== undefined) {
|
|
30
|
+
running = complete ? capacity : running + (capacity - running) * fraction
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
const cost = Number(tasks[i].energy_cost ?? 0)
|
|
34
|
+
running -= cost * fraction
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
running = clamp(running)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return clamp(running)
|
|
41
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Name, TimePoint, UInt16, UInt32, UInt64} from '@wharfkit/antelope'
|
|
2
2
|
import {ServerContract} from '../contracts'
|
|
3
|
-
import {Coordinates,
|
|
3
|
+
import {Coordinates, TaskType} from '../types'
|
|
4
4
|
import {
|
|
5
5
|
capsHasLoaders,
|
|
6
6
|
capsHasMovement,
|
|
@@ -20,7 +20,7 @@ import {getEntityLayout, getRecipe, type RecipeInput} from '../data/recipes-runt
|
|
|
20
20
|
import {computeEntityCapabilities} from '../derivation/capabilities'
|
|
21
21
|
import {decodeCraftedItemStats} from '../derivation/crafting'
|
|
22
22
|
import {packedModulesToInstalled, type InstalledModule} from '../entities/slot-multiplier'
|
|
23
|
-
import {
|
|
23
|
+
import {lerp} from '../travel/travel'
|
|
24
24
|
import {
|
|
25
25
|
calcStacksMass,
|
|
26
26
|
cargoItemToStack,
|
|
@@ -217,25 +217,22 @@ function applyFlightTask(
|
|
|
217
217
|
task: ServerContract.Types.task,
|
|
218
218
|
options: {complete: boolean; progress?: number}
|
|
219
219
|
): void {
|
|
220
|
-
if (!task.coordinates
|
|
220
|
+
if (!task.coordinates) return
|
|
221
221
|
|
|
222
|
-
const origin = projected.location
|
|
223
222
|
const destination = Coordinates.from(task.coordinates)
|
|
224
|
-
const distance = distanceBetweenCoordinates(origin, task.coordinates)
|
|
225
|
-
const energyUsage = distance.dividing(PRECISION).multiplying(projected.engines.drain)
|
|
226
223
|
|
|
227
224
|
if (options.complete) {
|
|
228
|
-
projected
|
|
229
|
-
? UInt16.from(projected.energy.subtracting(energyUsage))
|
|
230
|
-
: UInt16.from(0)
|
|
225
|
+
applyEnergyCost(projected, task)
|
|
231
226
|
projected.location = destination
|
|
232
227
|
} else if (options.progress !== undefined) {
|
|
233
|
-
const interpolated = lerp(
|
|
228
|
+
const interpolated = lerp(projected.location, destination, options.progress)
|
|
234
229
|
projected.location = Coordinates.from({
|
|
235
230
|
x: Math.round(interpolated.x),
|
|
236
231
|
y: Math.round(interpolated.y),
|
|
237
232
|
})
|
|
238
|
-
const partialEnergy = UInt64.from(
|
|
233
|
+
const partialEnergy = UInt64.from(
|
|
234
|
+
Math.floor(Number(task.energy_cost ?? 0) * options.progress)
|
|
235
|
+
)
|
|
239
236
|
projected.energy = projected.energy.gt(partialEnergy)
|
|
240
237
|
? UInt16.from(projected.energy.subtracting(partialEnergy))
|
|
241
238
|
: UInt16.from(0)
|
|
@@ -305,6 +302,7 @@ function applyTask(projected: ProjectedEntity, task: ServerContract.Types.task):
|
|
|
305
302
|
applyRechargeTask(projected, task, {complete: true})
|
|
306
303
|
break
|
|
307
304
|
case TaskType.TRAVEL:
|
|
305
|
+
case TaskType.WARP:
|
|
308
306
|
applyFlightTask(projected, task, {complete: true})
|
|
309
307
|
break
|
|
310
308
|
case TaskType.LOAD:
|
|
@@ -479,6 +477,7 @@ export function projectEntityAt(entity: Projectable, now: Date): ProjectedEntity
|
|
|
479
477
|
applyRechargeTask(projected, task, {complete: taskComplete, progress})
|
|
480
478
|
break
|
|
481
479
|
case TaskType.TRAVEL:
|
|
480
|
+
case TaskType.WARP:
|
|
482
481
|
applyFlightTask(projected, task, {complete: taskComplete, progress})
|
|
483
482
|
break
|
|
484
483
|
case TaskType.LOAD:
|