@shipload/sdk 1.0.0-next.5 → 1.0.0-next.7
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 +76 -56
- package/lib/shipload.js +270 -209
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +268 -208
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/contracts/server.ts +71 -67
- package/src/data/catalog.ts +0 -5
- package/src/data/colors.ts +0 -16
- package/src/derivation/index.ts +1 -0
- package/src/derivation/resources.ts +89 -18
- package/src/index-module.ts +3 -4
- package/src/managers/actions.ts +14 -20
- package/src/types.ts +5 -0
- package/src/utils/cargo.ts +27 -0
- package/src/utils/system.ts +21 -27
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {getItem} from '../data/catalog'
|
|
2
|
+
import {LocationType} from '../types'
|
|
2
3
|
|
|
3
4
|
export const DEPTH_THRESHOLD_T1 = 0
|
|
4
5
|
export const DEPTH_THRESHOLD_T2 = 1500
|
|
@@ -75,37 +76,107 @@ export function getResourceWeight(itemId: number, stratum: number): number {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const ICY_RESOURCES = [101, 301, 302, 401, 403, 501, 502]
|
|
84
|
-
const OCEAN_RESOURCES = [201, 203, 301, 303, 501, 502, 503]
|
|
85
|
-
const INDUSTRIAL_RESOURCES = [101, 102, 103, 201, 203, 402, 403]
|
|
79
|
+
const RESOURCE_ORE = 0
|
|
80
|
+
const RESOURCE_GAS = 1
|
|
81
|
+
const RESOURCE_REGOLITH = 2
|
|
82
|
+
const RESOURCE_BIOMASS = 3
|
|
83
|
+
const RESOURCE_CRYSTAL = 4
|
|
86
84
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
interface LocationProfileEntry {
|
|
86
|
+
category: number
|
|
87
|
+
maxTier: number
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function categoryBaseId(category: number): number {
|
|
91
|
+
switch (category) {
|
|
92
|
+
case RESOURCE_ORE:
|
|
93
|
+
return 100
|
|
94
|
+
case RESOURCE_CRYSTAL:
|
|
95
|
+
return 200
|
|
96
|
+
case RESOURCE_GAS:
|
|
97
|
+
return 300
|
|
98
|
+
case RESOURCE_REGOLITH:
|
|
99
|
+
return 400
|
|
100
|
+
case RESOURCE_BIOMASS:
|
|
101
|
+
return 500
|
|
102
|
+
default:
|
|
103
|
+
return 0
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function resourceId(category: number, tier: number): number {
|
|
108
|
+
return categoryBaseId(category) + tier
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getLocationProfile(locationType: number, subtype: number): LocationProfileEntry[] {
|
|
112
|
+
if (locationType === LocationType.ASTEROID) {
|
|
113
|
+
return [
|
|
114
|
+
{category: RESOURCE_ORE, maxTier: 5},
|
|
115
|
+
{category: RESOURCE_CRYSTAL, maxTier: 5},
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
if (locationType === LocationType.NEBULA) {
|
|
119
|
+
return [
|
|
120
|
+
{category: RESOURCE_GAS, maxTier: 5},
|
|
121
|
+
{category: RESOURCE_REGOLITH, maxTier: 5},
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
if (locationType === LocationType.ICE_FIELD) {
|
|
125
|
+
return [
|
|
126
|
+
{category: RESOURCE_GAS, maxTier: 5},
|
|
127
|
+
{category: RESOURCE_BIOMASS, maxTier: 5},
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
if (locationType === LocationType.PLANET) {
|
|
91
131
|
switch (subtype) {
|
|
92
132
|
case PLANET_SUBTYPE_GAS_GIANT:
|
|
93
|
-
return
|
|
133
|
+
return [
|
|
134
|
+
{category: RESOURCE_GAS, maxTier: 10},
|
|
135
|
+
{category: RESOURCE_CRYSTAL, maxTier: 3},
|
|
136
|
+
]
|
|
94
137
|
case PLANET_SUBTYPE_ROCKY:
|
|
95
|
-
return
|
|
138
|
+
return [
|
|
139
|
+
{category: RESOURCE_REGOLITH, maxTier: 10},
|
|
140
|
+
{category: RESOURCE_ORE, maxTier: 3},
|
|
141
|
+
]
|
|
96
142
|
case PLANET_SUBTYPE_TERRESTRIAL:
|
|
97
|
-
return
|
|
143
|
+
return [
|
|
144
|
+
{category: RESOURCE_ORE, maxTier: 10},
|
|
145
|
+
{category: RESOURCE_BIOMASS, maxTier: 3},
|
|
146
|
+
]
|
|
98
147
|
case PLANET_SUBTYPE_ICY:
|
|
99
|
-
return
|
|
148
|
+
return [
|
|
149
|
+
{category: RESOURCE_CRYSTAL, maxTier: 10},
|
|
150
|
+
{category: RESOURCE_REGOLITH, maxTier: 3},
|
|
151
|
+
]
|
|
100
152
|
case PLANET_SUBTYPE_OCEAN:
|
|
101
|
-
return
|
|
153
|
+
return [
|
|
154
|
+
{category: RESOURCE_BIOMASS, maxTier: 10},
|
|
155
|
+
{category: RESOURCE_GAS, maxTier: 3},
|
|
156
|
+
]
|
|
102
157
|
case PLANET_SUBTYPE_INDUSTRIAL:
|
|
103
|
-
return
|
|
158
|
+
return [
|
|
159
|
+
{category: RESOURCE_ORE, maxTier: 3},
|
|
160
|
+
{category: RESOURCE_CRYSTAL, maxTier: 3},
|
|
161
|
+
{category: RESOURCE_REGOLITH, maxTier: 3},
|
|
162
|
+
{category: RESOURCE_BIOMASS, maxTier: 3},
|
|
163
|
+
]
|
|
104
164
|
}
|
|
105
165
|
}
|
|
106
166
|
return []
|
|
107
167
|
}
|
|
108
168
|
|
|
169
|
+
export function getLocationCandidates(locationType: number, subtype: number): number[] {
|
|
170
|
+
const profile = getLocationProfile(locationType, subtype)
|
|
171
|
+
const ids: number[] = []
|
|
172
|
+
for (const {category, maxTier} of profile) {
|
|
173
|
+
for (let tier = 1; tier <= maxTier; tier++) {
|
|
174
|
+
ids.push(resourceId(category, tier))
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return ids
|
|
178
|
+
}
|
|
179
|
+
|
|
109
180
|
export function getEligibleResources(
|
|
110
181
|
locationType: number,
|
|
111
182
|
subtype: number,
|
package/src/index-module.ts
CHANGED
|
@@ -31,7 +31,6 @@ export type container_row = ServerContract.Types.container_row
|
|
|
31
31
|
export type gatherer_stats = ServerContract.Types.gatherer_stats
|
|
32
32
|
|
|
33
33
|
export type location_static = ServerContract.Types.location_static
|
|
34
|
-
export type location_epoch = ServerContract.Types.location_epoch
|
|
35
34
|
export type location_derived = ServerContract.Types.location_derived
|
|
36
35
|
export type location_row = ServerContract.Types.location_row
|
|
37
36
|
export {Player} from './entities/player'
|
|
@@ -63,7 +62,6 @@ export {
|
|
|
63
62
|
categoryLabel,
|
|
64
63
|
categoryFromIndex,
|
|
65
64
|
categoryLabelFromIndex,
|
|
66
|
-
tierLabel,
|
|
67
65
|
} from './data/catalog'
|
|
68
66
|
export {getCurrentEpoch, getEpochInfo} from './scheduling/epoch'
|
|
69
67
|
export type {EpochInfo} from './scheduling/epoch'
|
|
@@ -74,7 +72,6 @@ export {
|
|
|
74
72
|
getLocationTypeName,
|
|
75
73
|
isGatherableLocation,
|
|
76
74
|
deriveLocationStatic,
|
|
77
|
-
deriveLocationEpoch,
|
|
78
75
|
deriveLocation,
|
|
79
76
|
} from './utils/system'
|
|
80
77
|
|
|
@@ -86,6 +83,7 @@ export {
|
|
|
86
83
|
getEligibleResources,
|
|
87
84
|
getResourceWeight,
|
|
88
85
|
getLocationCandidates,
|
|
86
|
+
getLocationProfile,
|
|
89
87
|
getDepthThreshold,
|
|
90
88
|
getResourceTier,
|
|
91
89
|
DEPTH_THRESHOLD_T1,
|
|
@@ -164,6 +162,8 @@ export type {HasCargo} from './entities/inventory-accessor'
|
|
|
164
162
|
export * as cargoUtils from './entities/cargo-utils'
|
|
165
163
|
export type {CargoData} from './entities/cargo-utils'
|
|
166
164
|
|
|
165
|
+
export {cargoRef, cargoItem} from './utils/cargo'
|
|
166
|
+
|
|
167
167
|
export {
|
|
168
168
|
createProjectedEntity,
|
|
169
169
|
projectEntity,
|
|
@@ -186,7 +186,6 @@ export * from './capabilities'
|
|
|
186
186
|
export {
|
|
187
187
|
categoryColors,
|
|
188
188
|
tierColors,
|
|
189
|
-
tierLabels,
|
|
190
189
|
categoryIcons,
|
|
191
190
|
categoryIconShapes,
|
|
192
191
|
componentIcon,
|
package/src/managers/actions.ts
CHANGED
|
@@ -90,18 +90,15 @@ export class ActionsManager extends BaseManager {
|
|
|
90
90
|
sourceId: UInt64Type,
|
|
91
91
|
destType: EntityTypeName,
|
|
92
92
|
destId: UInt64Type,
|
|
93
|
-
|
|
94
|
-
stats: UInt64Type,
|
|
95
|
-
quantity: UInt64Type
|
|
93
|
+
items: ServerContract.ActionParams.Type.cargo_item[]
|
|
96
94
|
): Action {
|
|
95
|
+
const cargoItems = items.map((i) => ServerContract.Types.cargo_item.from(i))
|
|
97
96
|
return this.server.action('transfer', {
|
|
98
97
|
source_type: sourceType,
|
|
99
98
|
source_id: UInt64.from(sourceId),
|
|
100
99
|
dest_type: destType,
|
|
101
100
|
dest_id: UInt64.from(destId),
|
|
102
|
-
|
|
103
|
-
stats: UInt64.from(stats),
|
|
104
|
-
quantity: UInt32.from(quantity),
|
|
101
|
+
items: cargoItems,
|
|
105
102
|
})
|
|
106
103
|
}
|
|
107
104
|
|
|
@@ -187,14 +184,12 @@ export class ActionsManager extends BaseManager {
|
|
|
187
184
|
deploy(
|
|
188
185
|
entityType: EntityTypeName,
|
|
189
186
|
entityId: UInt64Type,
|
|
190
|
-
|
|
191
|
-
stats: bigint
|
|
187
|
+
ref: ServerContract.ActionParams.Type.cargo_ref
|
|
192
188
|
): Action {
|
|
193
189
|
return this.server.action('deploy', {
|
|
194
190
|
entity_type: entityType,
|
|
195
191
|
id: UInt64.from(entityId),
|
|
196
|
-
|
|
197
|
-
stats: UInt64.from(stats),
|
|
192
|
+
ref: ServerContract.Types.cargo_ref.from(ref),
|
|
198
193
|
})
|
|
199
194
|
}
|
|
200
195
|
|
|
@@ -202,15 +197,15 @@ export class ActionsManager extends BaseManager {
|
|
|
202
197
|
entityType: EntityTypeName,
|
|
203
198
|
entityId: UInt64Type,
|
|
204
199
|
moduleIndex: number,
|
|
205
|
-
|
|
206
|
-
|
|
200
|
+
moduleRef: ServerContract.ActionParams.Type.cargo_ref,
|
|
201
|
+
targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
|
|
207
202
|
): Action {
|
|
208
203
|
return this.server.action('addmodule', {
|
|
209
204
|
entity_type: entityType,
|
|
210
205
|
entity_id: UInt64.from(entityId),
|
|
211
206
|
module_index: moduleIndex,
|
|
212
|
-
|
|
213
|
-
|
|
207
|
+
module_ref: ServerContract.Types.cargo_ref.from(moduleRef),
|
|
208
|
+
target_ref: targetRef ? ServerContract.Types.cargo_ref.from(targetRef) : null,
|
|
214
209
|
})
|
|
215
210
|
}
|
|
216
211
|
|
|
@@ -218,13 +213,13 @@ export class ActionsManager extends BaseManager {
|
|
|
218
213
|
entityType: EntityTypeName,
|
|
219
214
|
entityId: UInt64Type,
|
|
220
215
|
moduleIndex: number,
|
|
221
|
-
|
|
216
|
+
targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
|
|
222
217
|
): Action {
|
|
223
218
|
return this.server.action('rmmodule', {
|
|
224
219
|
entity_type: entityType,
|
|
225
220
|
entity_id: UInt64.from(entityId),
|
|
226
221
|
module_index: moduleIndex,
|
|
227
|
-
|
|
222
|
+
target_ref: targetRef ? ServerContract.Types.cargo_ref.from(targetRef) : null,
|
|
228
223
|
})
|
|
229
224
|
}
|
|
230
225
|
|
|
@@ -232,15 +227,14 @@ export class ActionsManager extends BaseManager {
|
|
|
232
227
|
owner: NameType,
|
|
233
228
|
entityType: EntityTypeName,
|
|
234
229
|
entityId: UInt64Type,
|
|
235
|
-
|
|
236
|
-
quantity: UInt64Type
|
|
230
|
+
items: ServerContract.ActionParams.Type.cargo_item[]
|
|
237
231
|
): Action {
|
|
232
|
+
const cargoItems = items.map((i) => ServerContract.Types.cargo_item.from(i))
|
|
238
233
|
return this.server.action('wrap', {
|
|
239
234
|
owner: Name.from(owner),
|
|
240
235
|
entity_type: entityType,
|
|
241
236
|
entity_id: UInt64.from(entityId),
|
|
242
|
-
|
|
243
|
-
quantity: UInt64.from(quantity),
|
|
237
|
+
items: cargoItems,
|
|
244
238
|
})
|
|
245
239
|
}
|
|
246
240
|
|
package/src/types.ts
CHANGED
|
@@ -61,6 +61,7 @@ export enum LocationType {
|
|
|
61
61
|
PLANET = 1,
|
|
62
62
|
ASTEROID = 2,
|
|
63
63
|
NEBULA = 3,
|
|
64
|
+
ICE_FIELD = 4,
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
export enum TaskCancelable {
|
|
@@ -162,3 +163,7 @@ export interface Item {
|
|
|
162
163
|
export function formatTier(tier: number): string {
|
|
163
164
|
return 'T' + tier
|
|
164
165
|
}
|
|
166
|
+
|
|
167
|
+
export function tierAdjective(tier: number): string {
|
|
168
|
+
return TIER_ADJECTIVES[tier] ?? `T${tier}`
|
|
169
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {ServerContract} from '../contracts'
|
|
2
|
+
|
|
3
|
+
export function cargoRef(src: {
|
|
4
|
+
item_id: number
|
|
5
|
+
stats: bigint | number
|
|
6
|
+
modules?: ServerContract.Types.module_entry[]
|
|
7
|
+
}): ServerContract.ActionParams.Type.cargo_ref {
|
|
8
|
+
return {
|
|
9
|
+
item_id: src.item_id,
|
|
10
|
+
stats: src.stats,
|
|
11
|
+
modules: src.modules ?? [],
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function cargoItem(
|
|
16
|
+
src: {
|
|
17
|
+
item_id: number
|
|
18
|
+
stats: bigint | number
|
|
19
|
+
modules?: ServerContract.Types.module_entry[]
|
|
20
|
+
},
|
|
21
|
+
quantity: bigint | number
|
|
22
|
+
): ServerContract.ActionParams.Type.cargo_item {
|
|
23
|
+
return {
|
|
24
|
+
...cargoRef(src),
|
|
25
|
+
quantity,
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/utils/system.ts
CHANGED
|
@@ -8,7 +8,6 @@ import nebulaAdjectives from '../data/nebula-adjectives.json'
|
|
|
8
8
|
import nebulaNouns from '../data/nebula-nouns.json'
|
|
9
9
|
|
|
10
10
|
const LOCATION_EXISTS_THRESHOLD = 0x10
|
|
11
|
-
const LOCATION_ACTIVE_THRESHOLD = 0x80
|
|
12
11
|
|
|
13
12
|
export function getLocationType(
|
|
14
13
|
gameSeed: Checksum256Type,
|
|
@@ -22,12 +21,10 @@ export function getLocationType(
|
|
|
22
21
|
return LocationType.EMPTY
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
if (hashResult.array[1] < 96)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return LocationType.NEBULA
|
|
24
|
+
if (hashResult.array[1] < 96) return LocationType.PLANET
|
|
25
|
+
if (hashResult.array[1] < 149) return LocationType.ASTEROID
|
|
26
|
+
if (hashResult.array[1] < 202) return LocationType.NEBULA
|
|
27
|
+
return LocationType.ICE_FIELD
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
export function isGatherableLocation(locationType: LocationType): boolean {
|
|
@@ -44,6 +41,8 @@ export function getLocationTypeName(type: LocationType): string {
|
|
|
44
41
|
return 'Asteroid'
|
|
45
42
|
case LocationType.NEBULA:
|
|
46
43
|
return 'Nebula'
|
|
44
|
+
case LocationType.ICE_FIELD:
|
|
45
|
+
return 'Ice Field'
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
|
|
@@ -76,6 +75,15 @@ function generateNebulaName(hashResult: Checksum512): string {
|
|
|
76
75
|
return `${nebulaAdjectives[adjIdx]} ${nebulaNouns[nounIdx]}`
|
|
77
76
|
}
|
|
78
77
|
|
|
78
|
+
function generateIceFieldName(hashResult: Checksum512): string {
|
|
79
|
+
const A = 65
|
|
80
|
+
const letter1 = String.fromCharCode(A + (hashResult.array[0] % 26))
|
|
81
|
+
const letter2 = String.fromCharCode(A + (hashResult.array[1] % 26))
|
|
82
|
+
const subId = (hashResult.array[2] % 9) + 1
|
|
83
|
+
const num = (uint16(hashResult, 3) % 9000) + 1000
|
|
84
|
+
return `${letter1}${letter2}-${subId}/${num}`
|
|
85
|
+
}
|
|
86
|
+
|
|
79
87
|
export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
|
|
80
88
|
const seed = Checksum256.from(gameSeed)
|
|
81
89
|
const locationType = getLocationType(seed, location)
|
|
@@ -91,6 +99,8 @@ export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesTy
|
|
|
91
99
|
return generateAsteroidName(hashResult)
|
|
92
100
|
case LocationType.NEBULA:
|
|
93
101
|
return generateNebulaName(hashResult)
|
|
102
|
+
case LocationType.ICE_FIELD:
|
|
103
|
+
return generateIceFieldName(hashResult)
|
|
94
104
|
default:
|
|
95
105
|
return generatePlanetName(hashResult)
|
|
96
106
|
}
|
|
@@ -123,10 +133,12 @@ export function deriveLocationStatic(
|
|
|
123
133
|
|
|
124
134
|
if (hashResult.array[1] < 96) {
|
|
125
135
|
loc.type = UInt8.from(LocationType.PLANET)
|
|
126
|
-
} else if (hashResult.array[1] <
|
|
136
|
+
} else if (hashResult.array[1] < 149) {
|
|
127
137
|
loc.type = UInt8.from(LocationType.ASTEROID)
|
|
128
|
-
} else {
|
|
138
|
+
} else if (hashResult.array[1] < 202) {
|
|
129
139
|
loc.type = UInt8.from(LocationType.NEBULA)
|
|
140
|
+
} else {
|
|
141
|
+
loc.type = UInt8.from(LocationType.ICE_FIELD)
|
|
130
142
|
}
|
|
131
143
|
|
|
132
144
|
loc.subtype = UInt8.from(
|
|
@@ -138,31 +150,13 @@ export function deriveLocationStatic(
|
|
|
138
150
|
return loc
|
|
139
151
|
}
|
|
140
152
|
|
|
141
|
-
export function deriveLocationEpoch(
|
|
142
|
-
epochSeed: Checksum256Type,
|
|
143
|
-
coordinates: CoordinatesType
|
|
144
|
-
): ServerContract.Types.location_epoch {
|
|
145
|
-
const seed = Checksum256.from(epochSeed)
|
|
146
|
-
const coords = Coordinates.from(coordinates)
|
|
147
|
-
const str = `system-epoch-${coords.x}-${coords.y}`
|
|
148
|
-
const hashResult = hash512(seed, str)
|
|
149
|
-
|
|
150
|
-
return ServerContract.Types.location_epoch.from({
|
|
151
|
-
active: hashResult.array[0] < LOCATION_ACTIVE_THRESHOLD,
|
|
152
|
-
seed0: hashResult.array[1],
|
|
153
|
-
seed1: hashResult.array[2],
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
|
|
157
153
|
export function deriveLocation(
|
|
158
154
|
gameSeed: Checksum256Type,
|
|
159
|
-
epochSeed: Checksum256Type,
|
|
160
155
|
coordinates: CoordinatesType
|
|
161
156
|
): ServerContract.Types.location_derived {
|
|
162
157
|
const staticProps = deriveLocationStatic(gameSeed, coordinates)
|
|
163
158
|
return ServerContract.Types.location_derived.from({
|
|
164
159
|
static_props: staticProps,
|
|
165
|
-
epoch_props: deriveLocationEpoch(epochSeed, coordinates),
|
|
166
160
|
size: deriveLocationSize(staticProps),
|
|
167
161
|
})
|
|
168
162
|
}
|