@shipload/sdk 2.0.0-rc10 → 2.0.0-rc12
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 +144 -72
- package/lib/shipload.js +2537 -2238
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +2505 -2224
- package/lib/shipload.m.js.map +1 -1
- package/package.json +2 -2
- package/src/capabilities/gathering.ts +36 -0
- package/src/capabilities/guards.ts +3 -3
- package/src/capabilities/index.ts +1 -1
- package/src/capabilities/modules.ts +4 -4
- package/src/capabilities/storage.ts +92 -2
- package/src/contracts/server.ts +53 -16
- package/src/data/capabilities.ts +28 -28
- package/src/data/categories.ts +1 -1
- package/src/data/colors.ts +1 -0
- package/src/data/recipes.ts +25 -25
- package/src/derivation/crafting.ts +76 -0
- package/src/derivation/index.ts +3 -1
- package/src/derivation/resources.ts +1 -7
- package/src/derivation/stratum.ts +21 -17
- package/src/derivation/tiers.ts +54 -0
- package/src/entities/location.ts +3 -3
- package/src/entities/ship-deploy.ts +17 -17
- package/src/entities/ship.ts +4 -4
- package/src/errors.ts +5 -0
- package/src/index-module.ts +22 -13
- package/src/managers/actions.ts +6 -3
- package/src/market/items.ts +69 -10
- package/src/nft/description.ts +11 -11
- package/src/resolution/resolve-item.ts +7 -7
- package/src/scheduling/projection.ts +86 -77
- package/src/scheduling/schedule.ts +2 -2
- package/src/types/capabilities.ts +5 -5
- package/src/types/entity.ts +1 -1
- package/src/types.ts +3 -2
- package/src/utils/system.ts +14 -1
- package/src/capabilities/extraction.ts +0 -36
package/src/index-module.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type task = ServerContract.Types.task
|
|
|
21
21
|
export type cargo_item = ServerContract.Types.cargo_item
|
|
22
22
|
export type warehouse_row = ServerContract.Types.warehouse_row
|
|
23
23
|
export type container_row = ServerContract.Types.container_row
|
|
24
|
-
export type
|
|
24
|
+
export type gatherer_stats = ServerContract.Types.gatherer_stats
|
|
25
25
|
|
|
26
26
|
export type location_static = ServerContract.Types.location_static
|
|
27
27
|
export type location_epoch = ServerContract.Types.location_epoch
|
|
@@ -50,7 +50,8 @@ export {
|
|
|
50
50
|
getSystemName,
|
|
51
51
|
hasSystem,
|
|
52
52
|
getLocationType,
|
|
53
|
-
|
|
53
|
+
getLocationTypeName,
|
|
54
|
+
isGatherableLocation,
|
|
54
55
|
deriveLocationStatic,
|
|
55
56
|
deriveLocationEpoch,
|
|
56
57
|
deriveLocation,
|
|
@@ -65,7 +66,6 @@ export {
|
|
|
65
66
|
getLocationCandidates,
|
|
66
67
|
getDepthThreshold,
|
|
67
68
|
getResourceTier,
|
|
68
|
-
depthScaleFactor,
|
|
69
69
|
DEPTH_THRESHOLD_T1,
|
|
70
70
|
DEPTH_THRESHOLD_T2,
|
|
71
71
|
DEPTH_THRESHOLD_T3,
|
|
@@ -83,6 +83,9 @@ export {
|
|
|
83
83
|
|
|
84
84
|
export type {StratumInfo, ResourceStats} from './derivation'
|
|
85
85
|
|
|
86
|
+
export {RESERVE_TIERS, TIER_ROLL_MAX, rollTier, rollWithinTier} from './derivation'
|
|
87
|
+
export type {ReserveTier, TierRange} from './derivation'
|
|
88
|
+
|
|
86
89
|
export {getStatDefinitions, getStatName, resolveStats} from './derivation'
|
|
87
90
|
export type {StatDefinition, NamedStats} from './derivation'
|
|
88
91
|
|
|
@@ -134,7 +137,12 @@ export type {HasCargo} from './entities/inventory-accessor'
|
|
|
134
137
|
export * as cargoUtils from './entities/cargo-utils'
|
|
135
138
|
export type {CargoData} from './entities/cargo-utils'
|
|
136
139
|
|
|
137
|
-
export {
|
|
140
|
+
export {
|
|
141
|
+
createProjectedEntity,
|
|
142
|
+
projectEntity,
|
|
143
|
+
projectEntityAt,
|
|
144
|
+
validateSchedule,
|
|
145
|
+
} from './scheduling/projection'
|
|
138
146
|
export type {Projectable, ProjectedEntity} from './scheduling/projection'
|
|
139
147
|
|
|
140
148
|
export * from './types/capabilities'
|
|
@@ -192,12 +200,12 @@ export {
|
|
|
192
200
|
ITEM_GENERATOR_T1,
|
|
193
201
|
ITEM_SHIP_T1_PACKED,
|
|
194
202
|
ITEM_WAREHOUSE_T1_PACKED,
|
|
195
|
-
|
|
196
|
-
|
|
203
|
+
ITEM_MATTER_CONDUIT,
|
|
204
|
+
ITEM_SURVEY_PROBE,
|
|
197
205
|
ITEM_CARGO_ARM,
|
|
198
206
|
ITEM_TOOL_BIT,
|
|
199
207
|
ITEM_REACTION_CHAMBER,
|
|
200
|
-
|
|
208
|
+
ITEM_GATHERER_T1,
|
|
201
209
|
ITEM_LOADER_T1,
|
|
202
210
|
ITEM_MANUFACTURING_T1,
|
|
203
211
|
ITEM_STORAGE_T1,
|
|
@@ -229,8 +237,9 @@ export {
|
|
|
229
237
|
blendCrossGroup,
|
|
230
238
|
categoryItemMass,
|
|
231
239
|
computeInputMass,
|
|
240
|
+
computeCraftedOutputSeed,
|
|
232
241
|
} from './derivation/crafting'
|
|
233
|
-
export type {StackInput, CategoryStacks} from './derivation/crafting'
|
|
242
|
+
export type {StackInput, CategoryStacks, RecipeSlotInput} from './derivation/crafting'
|
|
234
243
|
|
|
235
244
|
export {computeContainerCapabilities, computeContainerT2Capabilities} from './entities/container'
|
|
236
245
|
|
|
@@ -238,7 +247,7 @@ export {
|
|
|
238
247
|
computeShipHullCapabilities,
|
|
239
248
|
computeEngineCapabilities,
|
|
240
249
|
computeGeneratorCapabilities,
|
|
241
|
-
|
|
250
|
+
computeGathererCapabilities,
|
|
242
251
|
computeHaulerCapabilities,
|
|
243
252
|
computeLoaderCapabilities,
|
|
244
253
|
computeManufacturingCapabilities,
|
|
@@ -285,10 +294,10 @@ export {
|
|
|
285
294
|
computeEngineDrain,
|
|
286
295
|
computeGeneratorCap,
|
|
287
296
|
computeGeneratorRech,
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
297
|
+
computeGathererYield,
|
|
298
|
+
computeGathererDrain,
|
|
299
|
+
computeGathererDepth,
|
|
300
|
+
computeGathererSpeed,
|
|
292
301
|
computeLoaderMass,
|
|
293
302
|
computeLoaderThrust,
|
|
294
303
|
computeCrafterSpeed,
|
package/src/managers/actions.ts
CHANGED
|
@@ -97,9 +97,12 @@ export class ActionsManager extends BaseManager {
|
|
|
97
97
|
})
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
return this.server.action('
|
|
102
|
-
|
|
100
|
+
gather(shipId: UInt64Type, stratum: number, quantity: number): Action {
|
|
101
|
+
return this.server.action('gather', {
|
|
102
|
+
entity_type: EntityType.SHIP,
|
|
103
|
+
id: UInt64.from(shipId),
|
|
104
|
+
stratum: UInt16.from(stratum),
|
|
105
|
+
quantity: UInt32.from(quantity),
|
|
103
106
|
})
|
|
104
107
|
}
|
|
105
108
|
|
package/src/market/items.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import {UInt16, UInt16Type} from '@wharfkit/antelope'
|
|
2
2
|
import {Item} from '../types'
|
|
3
3
|
import itemsData from '../data/items.json'
|
|
4
|
+
import {computeInputMass} from '../derivation/crafting'
|
|
5
|
+
import {getComponentById, getEntityRecipeByItemId, getModuleRecipeByItemId} from '../data/recipes'
|
|
4
6
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
+
const itemsById: Map<number, Item> = new Map()
|
|
8
|
+
const synthesizedCache: Map<number, Item> = new Map()
|
|
9
|
+
|
|
10
|
+
for (const g of itemsData) {
|
|
11
|
+
const item = Item.from({
|
|
7
12
|
id: g.id,
|
|
8
13
|
name: g.name,
|
|
9
14
|
description: g.description,
|
|
@@ -12,19 +17,73 @@ const items: Item[] = itemsData.map((g) =>
|
|
|
12
17
|
tier: g.tier,
|
|
13
18
|
color: g.color,
|
|
14
19
|
})
|
|
15
|
-
)
|
|
20
|
+
itemsById.set(item.id.toNumber(), item)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const itemIds = Array.from(itemsById.values(), (i) => i.id)
|
|
24
|
+
|
|
25
|
+
interface RecipeSource {
|
|
26
|
+
name: string
|
|
27
|
+
description: string
|
|
28
|
+
mass: number
|
|
29
|
+
color: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function synthesizeItem(id: number, source: RecipeSource): Item {
|
|
33
|
+
return Item.from({
|
|
34
|
+
id,
|
|
35
|
+
name: source.name,
|
|
36
|
+
description: source.description,
|
|
37
|
+
mass: source.mass,
|
|
38
|
+
category: 'metal',
|
|
39
|
+
tier: 't1',
|
|
40
|
+
color: source.color,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function synthesizeFromRecipes(id: number): Item | undefined {
|
|
45
|
+
const component = getComponentById(id)
|
|
46
|
+
if (component) return synthesizeItem(id, component)
|
|
16
47
|
|
|
17
|
-
|
|
48
|
+
const entityRecipe = getEntityRecipeByItemId(id)
|
|
49
|
+
if (entityRecipe) {
|
|
50
|
+
return synthesizeItem(id, {
|
|
51
|
+
...entityRecipe,
|
|
52
|
+
mass: computeInputMass(entityRecipe.id, 'entity'),
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const moduleRecipe = getModuleRecipeByItemId(id)
|
|
57
|
+
if (moduleRecipe) {
|
|
58
|
+
return synthesizeItem(id, {
|
|
59
|
+
...moduleRecipe,
|
|
60
|
+
mass: computeInputMass(moduleRecipe.id, 'module'),
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return undefined
|
|
65
|
+
}
|
|
18
66
|
|
|
19
67
|
export function getItem(itemId: UInt16Type): Item {
|
|
20
|
-
const id = UInt16.from(itemId)
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
|
|
68
|
+
const id = UInt16.from(itemId).toNumber()
|
|
69
|
+
const existing = itemsById.get(id) ?? synthesizedCache.get(id)
|
|
70
|
+
if (existing) return existing
|
|
71
|
+
|
|
72
|
+
const synthesized = synthesizeFromRecipes(id)
|
|
73
|
+
if (synthesized) {
|
|
74
|
+
synthesizedCache.set(id, synthesized)
|
|
75
|
+
return synthesized
|
|
24
76
|
}
|
|
25
|
-
|
|
77
|
+
|
|
78
|
+
throw new Error(`Item with id ${id} not found`)
|
|
26
79
|
}
|
|
27
80
|
|
|
28
81
|
export function getItems(): Item[] {
|
|
29
|
-
return
|
|
82
|
+
return Array.from(itemsById.values())
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function registerItem(item: Item): void {
|
|
86
|
+
const id = item.id.toNumber()
|
|
87
|
+
itemsById.set(id, item)
|
|
88
|
+
synthesizedCache.delete(id)
|
|
30
89
|
}
|
package/src/nft/description.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getModuleCapabilityType,
|
|
3
3
|
ITEM_ENGINE_T1,
|
|
4
|
-
|
|
4
|
+
ITEM_GATHERER_T1,
|
|
5
5
|
ITEM_GENERATOR_T1,
|
|
6
6
|
ITEM_LOADER_T1,
|
|
7
7
|
ITEM_MANUFACTURING_T1,
|
|
8
8
|
ITEM_STORAGE_T1,
|
|
9
9
|
MODULE_CRAFTER,
|
|
10
10
|
MODULE_ENGINE,
|
|
11
|
-
|
|
11
|
+
MODULE_GATHERER,
|
|
12
12
|
MODULE_GENERATOR,
|
|
13
13
|
MODULE_LOADER,
|
|
14
14
|
MODULE_STORAGE,
|
|
@@ -44,10 +44,10 @@ export const computeEngineThrust = (vol: number): number => 400 + idiv(vol * 3,
|
|
|
44
44
|
export const computeEngineDrain = (thm: number): number => Math.max(30, 50 - idiv(thm, 70))
|
|
45
45
|
export const computeGeneratorCap = (res: number): number => 300 + idiv(res, 6)
|
|
46
46
|
export const computeGeneratorRech = (clr: number): number => 5 + idiv(clr * 15, 1000)
|
|
47
|
-
export const
|
|
48
|
-
export const
|
|
49
|
-
export const
|
|
50
|
-
export const
|
|
47
|
+
export const computeGathererYield = (str: number): number => 200 + str
|
|
48
|
+
export const computeGathererDrain = (con: number): number => Math.max(10, 50 - idiv(con, 20))
|
|
49
|
+
export const computeGathererDepth = (tol: number): number => 200 + idiv(tol * 3, 2)
|
|
50
|
+
export const computeGathererSpeed = (ref: number): number => 100 + idiv(ref * 4, 5)
|
|
51
51
|
export const computeLoaderMass = (duc: number): number => Math.max(200, 2000 - duc * 2)
|
|
52
52
|
export const computeLoaderThrust = (pla: number): number => 1 + idiv(pla, 500)
|
|
53
53
|
export const computeCrafterSpeed = (rea: number): number => 100 + idiv(rea * 4, 5)
|
|
@@ -74,8 +74,8 @@ export function moduleDisplayName(itemId: number): string {
|
|
|
74
74
|
return 'Engine T1'
|
|
75
75
|
case ITEM_GENERATOR_T1:
|
|
76
76
|
return 'Generator T1'
|
|
77
|
-
case
|
|
78
|
-
return '
|
|
77
|
+
case ITEM_GATHERER_T1:
|
|
78
|
+
return 'Gatherer T1'
|
|
79
79
|
case ITEM_LOADER_T1:
|
|
80
80
|
return 'Loader T1'
|
|
81
81
|
case ITEM_MANUFACTURING_T1:
|
|
@@ -110,14 +110,14 @@ export function formatModuleLine(slot: number, itemId: number, seed: bigint): st
|
|
|
110
110
|
out += ` Capacity ${computeGeneratorCap(res)} Recharge ${computeGeneratorRech(clr)}`
|
|
111
111
|
break
|
|
112
112
|
}
|
|
113
|
-
case
|
|
113
|
+
case MODULE_GATHERER: {
|
|
114
114
|
const str = decodeStat(seed, 0)
|
|
115
115
|
const tol = decodeStat(seed, 1)
|
|
116
116
|
const con = decodeStat(seed, 3)
|
|
117
117
|
const ref = decodeStat(seed, 4)
|
|
118
|
-
out += `
|
|
118
|
+
out += ` Yield ${computeGathererYield(str)} Depth ${computeGathererDepth(
|
|
119
119
|
tol
|
|
120
|
-
)}
|
|
120
|
+
)} Speed ${computeGathererSpeed(ref)} Drain ${computeGathererDrain(con)}`
|
|
121
121
|
break
|
|
122
122
|
}
|
|
123
123
|
case MODULE_LOADER: {
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
isModuleItem,
|
|
9
9
|
MODULE_CRAFTER,
|
|
10
10
|
MODULE_ENGINE,
|
|
11
|
-
|
|
11
|
+
MODULE_GATHERER,
|
|
12
12
|
MODULE_GENERATOR,
|
|
13
13
|
MODULE_LOADER,
|
|
14
14
|
MODULE_STORAGE,
|
|
@@ -18,7 +18,7 @@ import {deriveResourceStats} from '../derivation/stratum'
|
|
|
18
18
|
import {getStatDefinitions} from '../derivation/stats'
|
|
19
19
|
import {
|
|
20
20
|
computeEngineCapabilities,
|
|
21
|
-
|
|
21
|
+
computeGathererCapabilities,
|
|
22
22
|
computeGeneratorCapabilities,
|
|
23
23
|
computeLoaderCapabilities,
|
|
24
24
|
computeManufacturingCapabilities,
|
|
@@ -163,15 +163,15 @@ function computeCapabilityGroup(
|
|
|
163
163
|
],
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
case
|
|
167
|
-
const caps =
|
|
166
|
+
case MODULE_GATHERER: {
|
|
167
|
+
const caps = computeGathererCapabilities(stats)
|
|
168
168
|
return {
|
|
169
|
-
capability: '
|
|
169
|
+
capability: 'Gatherer',
|
|
170
170
|
attributes: [
|
|
171
|
-
{label: '
|
|
171
|
+
{label: 'Yield', value: caps.yield},
|
|
172
172
|
{label: 'Drain', value: caps.drain},
|
|
173
173
|
{label: 'Depth', value: caps.depth},
|
|
174
|
-
{label: '
|
|
174
|
+
{label: 'Speed', value: caps.speed},
|
|
175
175
|
],
|
|
176
176
|
}
|
|
177
177
|
}
|
|
@@ -8,21 +8,30 @@ import {
|
|
|
8
8
|
EntityCapabilities,
|
|
9
9
|
EntityState,
|
|
10
10
|
} from '../types/capabilities'
|
|
11
|
+
import {ENTITY_CAPACITY_EXCEEDED} from '../errors'
|
|
11
12
|
import {distanceBetweenCoordinates, lerp} from '../travel/travel'
|
|
12
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
calcStacksMass,
|
|
15
|
+
cargoItemToStack,
|
|
16
|
+
CargoStack,
|
|
17
|
+
mergeStacks,
|
|
18
|
+
removeFromStacks,
|
|
19
|
+
stackToCargoItem,
|
|
20
|
+
} from '../capabilities/storage'
|
|
13
21
|
import * as schedule from './schedule'
|
|
14
22
|
import {ScheduleData} from './schedule'
|
|
15
23
|
|
|
16
24
|
export interface ProjectedEntity {
|
|
17
25
|
location: Coordinates
|
|
18
26
|
energy: UInt16
|
|
19
|
-
|
|
27
|
+
cargo: CargoStack[]
|
|
20
28
|
shipMass: UInt32
|
|
21
29
|
capacity?: UInt64
|
|
22
30
|
engines?: ServerContract.Types.movement_stats
|
|
23
31
|
loaders?: ServerContract.Types.loader_stats
|
|
24
32
|
generator?: ServerContract.Types.energy_stats
|
|
25
33
|
hauler?: ServerContract.Types.hauler_stats
|
|
34
|
+
readonly cargoMass: UInt64
|
|
26
35
|
readonly totalMass: UInt64
|
|
27
36
|
|
|
28
37
|
hasMovement(): boolean
|
|
@@ -52,7 +61,6 @@ function getHullMass(entity: Projectable): UInt32 {
|
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
export function createProjectedEntity(entity: Projectable): ProjectedEntity {
|
|
55
|
-
const cargoMass = calcCargoMass(entity)
|
|
56
64
|
const shipMass = getHullMass(entity)
|
|
57
65
|
const loaders = entity.loaders
|
|
58
66
|
const engines = entity.engines
|
|
@@ -60,10 +68,12 @@ export function createProjectedEntity(entity: Projectable): ProjectedEntity {
|
|
|
60
68
|
const hauler = entity.hauler
|
|
61
69
|
const capacity = entity.capacity
|
|
62
70
|
|
|
71
|
+
const cargo: CargoStack[] = entity.cargo.map(cargoItemToStack)
|
|
72
|
+
|
|
63
73
|
const projected: ProjectedEntity = {
|
|
64
74
|
location: Coordinates.from(entity.coordinates),
|
|
65
75
|
energy: UInt16.from(entity.energy ?? 0),
|
|
66
|
-
|
|
76
|
+
cargo,
|
|
67
77
|
shipMass,
|
|
68
78
|
capacity: capacity ? UInt64.from(capacity) : undefined,
|
|
69
79
|
engines,
|
|
@@ -71,6 +81,10 @@ export function createProjectedEntity(entity: Projectable): ProjectedEntity {
|
|
|
71
81
|
hauler,
|
|
72
82
|
loaders,
|
|
73
83
|
|
|
84
|
+
get cargoMass() {
|
|
85
|
+
return calcStacksMass(this.cargo)
|
|
86
|
+
},
|
|
87
|
+
|
|
74
88
|
get totalMass() {
|
|
75
89
|
let mass = UInt64.from(this.shipMass).adding(this.cargoMass)
|
|
76
90
|
if (this.loaders) {
|
|
@@ -107,7 +121,7 @@ export function createProjectedEntity(entity: Projectable): ProjectedEntity {
|
|
|
107
121
|
location: ServerContract.Types.coordinates.from(this.location),
|
|
108
122
|
energy: this.energy,
|
|
109
123
|
cargomass: UInt32.from(this.cargoMass),
|
|
110
|
-
cargo:
|
|
124
|
+
cargo: this.cargo.map(stackToCargoItem),
|
|
111
125
|
}
|
|
112
126
|
},
|
|
113
127
|
}
|
|
@@ -162,18 +176,23 @@ function applyFlightTask(
|
|
|
162
176
|
}
|
|
163
177
|
}
|
|
164
178
|
|
|
165
|
-
function
|
|
179
|
+
function addCargoItem(projected: ProjectedEntity, item: ServerContract.Types.cargo_item): void {
|
|
180
|
+
projected.cargo = mergeStacks(projected.cargo, cargoItemToStack(item))
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function removeCargoItem(projected: ProjectedEntity, item: ServerContract.Types.cargo_item): void {
|
|
184
|
+
projected.cargo = removeFromStacks(projected.cargo, cargoItemToStack(item))
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function applyAddCargoTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|
|
166
188
|
for (const item of task.cargo) {
|
|
167
|
-
projected
|
|
189
|
+
addCargoItem(projected, item)
|
|
168
190
|
}
|
|
169
191
|
}
|
|
170
192
|
|
|
171
|
-
function
|
|
193
|
+
function applyRemoveCargoTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|
|
172
194
|
for (const item of task.cargo) {
|
|
173
|
-
|
|
174
|
-
projected.cargoMass = projected.cargoMass.gt(cargoMass)
|
|
175
|
-
? projected.cargoMass.subtracting(cargoMass)
|
|
176
|
-
: UInt64.from(0)
|
|
195
|
+
removeCargoItem(projected, item)
|
|
177
196
|
}
|
|
178
197
|
}
|
|
179
198
|
|
|
@@ -185,81 +204,80 @@ function applyEnergyCost(projected: ProjectedEntity, task: ServerContract.Types.
|
|
|
185
204
|
: UInt16.from(0)
|
|
186
205
|
}
|
|
187
206
|
|
|
188
|
-
function
|
|
207
|
+
function applyGatherTask(
|
|
189
208
|
projected: ProjectedEntity,
|
|
190
209
|
task: ServerContract.Types.task,
|
|
191
210
|
options: {complete: boolean}
|
|
192
211
|
): void {
|
|
193
212
|
if (!options.complete) return
|
|
194
|
-
|
|
195
213
|
applyEnergyCost(projected, task)
|
|
196
|
-
|
|
197
|
-
for (const item of task.cargo) {
|
|
198
|
-
projected.cargoMass = projected.cargoMass.adding(calcCargoItemMass(item))
|
|
199
|
-
}
|
|
214
|
+
applyAddCargoTask(projected, task)
|
|
200
215
|
}
|
|
201
216
|
|
|
202
217
|
function applyCraftTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|
|
203
218
|
applyEnergyCost(projected, task)
|
|
219
|
+
if (task.cargo.length === 0) return
|
|
204
220
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const inputMass = calcCargoItemMass(task.cargo[i])
|
|
208
|
-
projected.cargoMass = projected.cargoMass.gt(inputMass)
|
|
209
|
-
? projected.cargoMass.subtracting(inputMass)
|
|
210
|
-
: UInt64.from(0)
|
|
211
|
-
}
|
|
212
|
-
const output = task.cargo[task.cargo.length - 1]
|
|
213
|
-
projected.cargoMass = projected.cargoMass.adding(calcCargoItemMass(output))
|
|
221
|
+
for (let i = 0; i < task.cargo.length - 1; i++) {
|
|
222
|
+
removeCargoItem(projected, task.cargo[i])
|
|
214
223
|
}
|
|
224
|
+
addCargoItem(projected, task.cargo[task.cargo.length - 1])
|
|
215
225
|
}
|
|
216
226
|
|
|
217
227
|
function applyDeployTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|
|
218
228
|
applyEnergyCost(projected, task)
|
|
219
|
-
|
|
220
229
|
if (task.cargo.length > 0) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
230
|
+
removeCargoItem(projected, task.cargo[0])
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function applyTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|
|
235
|
+
switch (task.type.toNumber()) {
|
|
236
|
+
case TaskType.RECHARGE:
|
|
237
|
+
applyRechargeTask(projected, task, {complete: true})
|
|
238
|
+
break
|
|
239
|
+
case TaskType.TRAVEL:
|
|
240
|
+
applyFlightTask(projected, task, {complete: true})
|
|
241
|
+
break
|
|
242
|
+
case TaskType.LOAD:
|
|
243
|
+
case TaskType.UNWRAP:
|
|
244
|
+
applyAddCargoTask(projected, task)
|
|
245
|
+
break
|
|
246
|
+
case TaskType.UNLOAD:
|
|
247
|
+
case TaskType.WRAP:
|
|
248
|
+
applyRemoveCargoTask(projected, task)
|
|
249
|
+
break
|
|
250
|
+
case TaskType.GATHER:
|
|
251
|
+
applyGatherTask(projected, task, {complete: true})
|
|
252
|
+
break
|
|
253
|
+
case TaskType.CRAFT:
|
|
254
|
+
applyCraftTask(projected, task)
|
|
255
|
+
break
|
|
256
|
+
case TaskType.DEPLOY:
|
|
257
|
+
applyDeployTask(projected, task)
|
|
258
|
+
break
|
|
225
259
|
}
|
|
226
260
|
}
|
|
227
261
|
|
|
228
262
|
export function projectEntity(entity: Projectable): ProjectedEntity {
|
|
229
263
|
const projected = createProjectedEntity(entity)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
264
|
+
if (!entity.schedule || entity.schedule.tasks.length === 0) return projected
|
|
265
|
+
for (const task of entity.schedule.tasks) {
|
|
266
|
+
applyTask(projected, task)
|
|
233
267
|
}
|
|
268
|
+
return projected
|
|
269
|
+
}
|
|
234
270
|
|
|
271
|
+
export function validateSchedule(entity: Projectable): void {
|
|
272
|
+
if (!entity.schedule || entity.schedule.tasks.length === 0) return
|
|
273
|
+
|
|
274
|
+
const projected = createProjectedEntity(entity)
|
|
235
275
|
for (const task of entity.schedule.tasks) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
break
|
|
240
|
-
case TaskType.TRAVEL:
|
|
241
|
-
applyFlightTask(projected, task, {complete: true})
|
|
242
|
-
break
|
|
243
|
-
case TaskType.LOAD:
|
|
244
|
-
applyLoadTask(projected, task)
|
|
245
|
-
break
|
|
246
|
-
case TaskType.UNLOAD:
|
|
247
|
-
applyUnloadTask(projected, task)
|
|
248
|
-
break
|
|
249
|
-
case TaskType.EXTRACT:
|
|
250
|
-
applyExtractTask(projected, task, {complete: true})
|
|
251
|
-
break
|
|
252
|
-
case TaskType.CRAFT:
|
|
253
|
-
applyCraftTask(projected, task)
|
|
254
|
-
break
|
|
255
|
-
case TaskType.DEPLOY:
|
|
256
|
-
case TaskType.DEPLOY_SHIP:
|
|
257
|
-
applyDeployTask(projected, task)
|
|
258
|
-
break
|
|
276
|
+
applyTask(projected, task)
|
|
277
|
+
if (projected.capacity && projected.cargoMass.gt(projected.capacity)) {
|
|
278
|
+
throw new Error(ENTITY_CAPACITY_EXCEEDED)
|
|
259
279
|
}
|
|
260
280
|
}
|
|
261
|
-
|
|
262
|
-
return projected
|
|
263
281
|
}
|
|
264
282
|
|
|
265
283
|
export function projectEntityAt(entity: Projectable, now: Date): ProjectedEntity {
|
|
@@ -290,30 +308,21 @@ export function projectEntityAt(entity: Projectable, now: Date): ProjectedEntity
|
|
|
290
308
|
applyFlightTask(projected, task, {complete: taskComplete, progress})
|
|
291
309
|
break
|
|
292
310
|
case TaskType.LOAD:
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
311
|
+
case TaskType.UNWRAP:
|
|
312
|
+
if (taskComplete) applyAddCargoTask(projected, task)
|
|
296
313
|
break
|
|
297
314
|
case TaskType.UNLOAD:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
315
|
+
case TaskType.WRAP:
|
|
316
|
+
if (taskComplete) applyRemoveCargoTask(projected, task)
|
|
301
317
|
break
|
|
302
|
-
case TaskType.
|
|
303
|
-
if (taskComplete) {
|
|
304
|
-
applyExtractTask(projected, task, {complete: true})
|
|
305
|
-
}
|
|
318
|
+
case TaskType.GATHER:
|
|
319
|
+
if (taskComplete) applyGatherTask(projected, task, {complete: true})
|
|
306
320
|
break
|
|
307
321
|
case TaskType.CRAFT:
|
|
308
|
-
if (taskComplete)
|
|
309
|
-
applyCraftTask(projected, task)
|
|
310
|
-
}
|
|
322
|
+
if (taskComplete) applyCraftTask(projected, task)
|
|
311
323
|
break
|
|
312
324
|
case TaskType.DEPLOY:
|
|
313
|
-
|
|
314
|
-
if (taskComplete) {
|
|
315
|
-
applyDeployTask(projected, task)
|
|
316
|
-
}
|
|
325
|
+
if (taskComplete) applyDeployTask(projected, task)
|
|
317
326
|
break
|
|
318
327
|
}
|
|
319
328
|
}
|
|
@@ -174,6 +174,6 @@ export function isUnloading(entity: ScheduleData, now: Date): boolean {
|
|
|
174
174
|
return isTaskType(entity, TaskType.UNLOAD, now)
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
export function
|
|
178
|
-
return isTaskType(entity, TaskType.
|
|
177
|
+
export function isGathering(entity: ScheduleData, now: Date): boolean {
|
|
178
|
+
return isTaskType(entity, TaskType.GATHER, now)
|
|
179
179
|
}
|
|
@@ -20,8 +20,8 @@ export interface LoaderCapability {
|
|
|
20
20
|
loaders: ServerContract.Types.loader_stats
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export interface
|
|
24
|
-
|
|
23
|
+
export interface GathererCapability {
|
|
24
|
+
gatherer: ServerContract.Types.gatherer_stats
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface MassCapability {
|
|
@@ -38,7 +38,7 @@ export interface EntityCapabilities {
|
|
|
38
38
|
engines?: ServerContract.Types.movement_stats
|
|
39
39
|
generator?: ServerContract.Types.energy_stats
|
|
40
40
|
loaders?: ServerContract.Types.loader_stats
|
|
41
|
-
|
|
41
|
+
gatherer?: ServerContract.Types.gatherer_stats
|
|
42
42
|
crafter?: ServerContract.Types.crafter_stats
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -62,8 +62,8 @@ export function capsHasLoaders(caps: EntityCapabilities): boolean {
|
|
|
62
62
|
return caps.loaders !== undefined
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export function
|
|
66
|
-
return caps.
|
|
65
|
+
export function capsHasGatherer(caps: EntityCapabilities): boolean {
|
|
66
|
+
return caps.gatherer !== undefined
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export function capsHasMass(caps: EntityCapabilities): boolean {
|
package/src/types/entity.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type ShipEntity = Entity &
|
|
|
25
25
|
Partial<LoaderCapability> &
|
|
26
26
|
MassCapability &
|
|
27
27
|
ScheduleCapability & {
|
|
28
|
-
|
|
28
|
+
gatherer?: ServerContract.Types.gatherer_stats
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export type WarehouseEntity = Entity &
|
package/src/types.ts
CHANGED
package/src/utils/system.ts
CHANGED
|
@@ -30,10 +30,23 @@ export function getLocationType(
|
|
|
30
30
|
return LocationType.NEBULA
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function
|
|
33
|
+
export function isGatherableLocation(locationType: LocationType): boolean {
|
|
34
34
|
return locationType !== LocationType.EMPTY
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export function getLocationTypeName(type: LocationType): string {
|
|
38
|
+
switch (type) {
|
|
39
|
+
case LocationType.EMPTY:
|
|
40
|
+
return 'Empty'
|
|
41
|
+
case LocationType.PLANET:
|
|
42
|
+
return 'Planet'
|
|
43
|
+
case LocationType.ASTEROID:
|
|
44
|
+
return 'Asteroid'
|
|
45
|
+
case LocationType.NEBULA:
|
|
46
|
+
return 'Nebula'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
37
50
|
function uint16(hash: Checksum512, offset: number): number {
|
|
38
51
|
return (hash.array[offset] << 8) | hash.array[offset + 1]
|
|
39
52
|
}
|