@shipload/sdk 2.0.0-rc1 → 2.0.0-rc2
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/README.md +349 -1
- package/lib/shipload.d.ts +609 -248
- package/lib/shipload.js +1683 -1031
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +1613 -1047
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -2
- package/src/capabilities/extraction.ts +37 -0
- package/src/capabilities/guards.ts +43 -0
- package/src/capabilities/index.ts +5 -0
- package/src/capabilities/loading.ts +8 -0
- package/src/capabilities/movement.ts +29 -0
- package/src/capabilities/storage.ts +67 -0
- package/src/contracts/server.ts +340 -136
- package/src/data/goods.json +2 -2
- package/src/entities/cargo-utils.ts +96 -1
- package/src/entities/container.ts +70 -0
- package/src/entities/inventory-accessor.ts +46 -0
- package/src/entities/location.ts +22 -8
- package/src/entities/makers.ts +69 -0
- package/src/entities/player.ts +2 -1
- package/src/entities/ship.ts +86 -437
- package/src/entities/warehouse.ts +28 -144
- package/src/index-module.ts +34 -1
- package/src/managers/actions.ts +60 -28
- package/src/managers/entities.ts +22 -5
- package/src/managers/locations.ts +28 -9
- package/src/managers/trades.ts +2 -2
- package/src/market/market.ts +3 -4
- package/src/scheduling/accessor.ts +82 -0
- package/src/scheduling/projection.ts +125 -53
- package/src/scheduling/schedule.ts +24 -0
- package/src/trading/collect.ts +0 -1
- package/src/trading/deal.ts +0 -1
- package/src/travel/travel.ts +63 -2
- package/src/types/capabilities.ts +79 -0
- package/src/types/entity-traits.ts +70 -0
- package/src/types/entity.ts +36 -0
- package/src/types/index.ts +3 -0
- package/src/types.ts +75 -8
- package/src/utils/hash.ts +1 -1
- package/src/utils/system.ts +132 -4
package/src/types.ts
CHANGED
|
@@ -1,15 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Int64Type,
|
|
3
|
+
Name,
|
|
4
|
+
Struct,
|
|
5
|
+
UInt16,
|
|
6
|
+
UInt16Type,
|
|
7
|
+
UInt32,
|
|
8
|
+
UInt32Type,
|
|
9
|
+
UInt64,
|
|
10
|
+
} from '@wharfkit/antelope'
|
|
2
11
|
import {ServerContract} from './contracts'
|
|
3
12
|
|
|
4
13
|
export const PRECISION = 10000
|
|
5
14
|
|
|
6
|
-
|
|
15
|
+
// Ship constants
|
|
16
|
+
export const INITIAL_SHIP_GENERATOR_CAPACITY = 350
|
|
17
|
+
export const INITIAL_SHIP_DRAIN = 25
|
|
18
|
+
export const INITIAL_SHIP_ENERGY = 350
|
|
19
|
+
export const INITIAL_SHIP_HULLMASS = 100000
|
|
20
|
+
export const INITIAL_SHIP_CAPACITY = 500000
|
|
21
|
+
export const INITIAL_SHIP_Z = 800
|
|
22
|
+
export const INITIAL_SHIP_RECHARGE = 10
|
|
23
|
+
export const INITIAL_SHIP_THRUST = 250
|
|
24
|
+
|
|
25
|
+
// Loader constants
|
|
26
|
+
export const INITIAL_LOADER_MASS = 1000
|
|
27
|
+
export const INITIAL_LOADER_QUANTITY = 1
|
|
28
|
+
export const INITIAL_LOADER_THRUST = 1
|
|
29
|
+
|
|
30
|
+
// Warehouse constants
|
|
31
|
+
export const WAREHOUSE_Z = 500
|
|
32
|
+
export const INITIAL_WAREHOUSE_CAPACITY = 10000000
|
|
33
|
+
|
|
34
|
+
// Container constants
|
|
35
|
+
export const CONTAINER_Z = 300
|
|
36
|
+
export const INITIAL_CONTAINER_HULLMASS = 50000
|
|
37
|
+
export const INITIAL_CONTAINER_CAPACITY = 2000000
|
|
38
|
+
|
|
39
|
+
// Mechanics
|
|
40
|
+
export const TRAVEL_MAX_DURATION = 86400
|
|
41
|
+
|
|
42
|
+
// Altitude limits (for UI/calculations)
|
|
7
43
|
export const MIN_ORBITAL_ALTITUDE = 800
|
|
8
44
|
export const MAX_ORBITAL_ALTITUDE = 3000
|
|
9
45
|
|
|
46
|
+
// Legacy alias (deprecated, use INITIAL_SHIP_CAPACITY)
|
|
47
|
+
export const INITIAL_SHIP_MASS = 500000
|
|
48
|
+
|
|
49
|
+
// Extractor constants
|
|
50
|
+
export const INITIAL_EXTRACTOR_RATE = 700
|
|
51
|
+
export const INITIAL_EXTRACTOR_DRAIN = 2500
|
|
52
|
+
export const INITIAL_EXTRACTOR_EFFICIENCY = 5000
|
|
53
|
+
|
|
10
54
|
export interface ShipLike {
|
|
11
|
-
|
|
12
|
-
|
|
55
|
+
coordinates: ServerContract.Types.coordinates
|
|
56
|
+
hullmass: UInt32
|
|
13
57
|
energy: UInt16
|
|
14
58
|
engines: ServerContract.Types.movement_stats
|
|
15
59
|
generator: ServerContract.Types.energy_stats
|
|
@@ -23,10 +67,19 @@ export interface CargoMassInfo {
|
|
|
23
67
|
}
|
|
24
68
|
|
|
25
69
|
export enum TaskType {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
70
|
+
IDLE = 0,
|
|
71
|
+
TRAVEL = 1,
|
|
72
|
+
RECHARGE = 2,
|
|
73
|
+
LOAD = 3,
|
|
74
|
+
UNLOAD = 4,
|
|
75
|
+
EXTRACT = 5,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export enum LocationType {
|
|
79
|
+
EMPTY = 0,
|
|
80
|
+
PLANET = 1,
|
|
81
|
+
ASTEROID = 2,
|
|
82
|
+
NEBULA = 3,
|
|
30
83
|
}
|
|
31
84
|
|
|
32
85
|
export enum TaskCancelable {
|
|
@@ -38,6 +91,7 @@ export enum TaskCancelable {
|
|
|
38
91
|
export const EntityType = {
|
|
39
92
|
SHIP: Name.from('ship'),
|
|
40
93
|
WAREHOUSE: Name.from('warehouse'),
|
|
94
|
+
CONTAINER: Name.from('container'),
|
|
41
95
|
} as const
|
|
42
96
|
|
|
43
97
|
export type EntityTypeName = (typeof EntityType)[keyof typeof EntityType]
|
|
@@ -56,6 +110,19 @@ export class Coordinates extends ServerContract.Types.coordinates {
|
|
|
56
110
|
const coords = Coordinates.from(other)
|
|
57
111
|
return this.x.equals(coords.x) && this.y.equals(coords.y)
|
|
58
112
|
}
|
|
113
|
+
|
|
114
|
+
toLocationId(): UInt64 {
|
|
115
|
+
return coordsToLocationId(this)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function coordsToLocationId(coords: CoordinatesType): UInt64 {
|
|
120
|
+
const c = Coordinates.from(coords)
|
|
121
|
+
const mask = BigInt(0xffffffff)
|
|
122
|
+
const x = BigInt(c.x.toNumber()) & mask
|
|
123
|
+
const y = BigInt(c.y.toNumber()) & mask
|
|
124
|
+
const id = (x << BigInt(32)) | y
|
|
125
|
+
return UInt64.from(id)
|
|
59
126
|
}
|
|
60
127
|
|
|
61
128
|
export interface Distance {
|
package/src/utils/hash.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Bytes, Checksum256, Checksum256Type, Checksum512} from '@wharfkit/antelope'
|
|
2
2
|
|
|
3
|
-
export function hash(seed: Checksum256Type, string: string):
|
|
3
|
+
export function hash(seed: Checksum256Type, string: string): Checksum256 {
|
|
4
4
|
const bytes = Bytes.from(`${seed}${string}`, 'utf8')
|
|
5
5
|
return Checksum256.hash(bytes)
|
|
6
6
|
}
|
package/src/utils/system.ts
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
import {Checksum256, Checksum256Type} from '@wharfkit/antelope'
|
|
1
|
+
import {Checksum256, Checksum256Type, UInt8} from '@wharfkit/antelope'
|
|
2
2
|
import {hash512} from './hash'
|
|
3
|
-
import {CoordinatesType} from '../types'
|
|
3
|
+
import {Coordinates, CoordinatesType, LocationType, PRECISION} from '../types'
|
|
4
|
+
import {ServerContract} from '../contracts'
|
|
4
5
|
import syllables from '../data/syllables.json'
|
|
5
6
|
|
|
7
|
+
const LOCATION_EXISTS_THRESHOLD = 0x10
|
|
8
|
+
const LOCATION_ACTIVE_THRESHOLD = 0x80
|
|
9
|
+
|
|
10
|
+
export function getLocationType(
|
|
11
|
+
gameSeed: Checksum256Type,
|
|
12
|
+
coordinates: CoordinatesType
|
|
13
|
+
): LocationType {
|
|
14
|
+
const seed = Checksum256.from(gameSeed)
|
|
15
|
+
const str = ['system', coordinates.x, coordinates.y].join('-')
|
|
16
|
+
const hashResult = hash512(seed, str)
|
|
17
|
+
|
|
18
|
+
if (hashResult.array[0] >= LOCATION_EXISTS_THRESHOLD) {
|
|
19
|
+
return LocationType.EMPTY
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (hashResult.array[1] < 96) {
|
|
23
|
+
return LocationType.PLANET
|
|
24
|
+
} else if (hashResult.array[1] < 176) {
|
|
25
|
+
return LocationType.ASTEROID
|
|
26
|
+
}
|
|
27
|
+
return LocationType.NEBULA
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isExtractableLocation(locationType: LocationType): boolean {
|
|
31
|
+
return locationType === LocationType.ASTEROID || locationType === LocationType.NEBULA
|
|
32
|
+
}
|
|
33
|
+
|
|
6
34
|
export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
|
|
7
35
|
const seed = Checksum256.from(gameSeed)
|
|
8
36
|
if (!hasSystem(seed, location)) {
|
|
@@ -21,7 +49,107 @@ export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesTy
|
|
|
21
49
|
}
|
|
22
50
|
|
|
23
51
|
export function hasSystem(gameSeed: Checksum256Type, coordinates: CoordinatesType): boolean {
|
|
52
|
+
return getLocationType(gameSeed, coordinates) !== LocationType.EMPTY
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function deriveLocationStatic(
|
|
56
|
+
gameSeed: Checksum256Type,
|
|
57
|
+
coordinates: CoordinatesType
|
|
58
|
+
): ServerContract.Types.location_static {
|
|
24
59
|
const seed = Checksum256.from(gameSeed)
|
|
25
|
-
const
|
|
26
|
-
|
|
60
|
+
const coords = Coordinates.from(coordinates)
|
|
61
|
+
const str = `system-${coords.x}-${coords.y}`
|
|
62
|
+
const hashResult = hash512(seed, str)
|
|
63
|
+
|
|
64
|
+
const loc = ServerContract.Types.location_static.from({
|
|
65
|
+
coords: coords,
|
|
66
|
+
type: LocationType.EMPTY,
|
|
67
|
+
subtype: 0,
|
|
68
|
+
seed0: 0,
|
|
69
|
+
seed1: 0,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
if (hashResult.array[0] >= LOCATION_EXISTS_THRESHOLD) {
|
|
73
|
+
return loc
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (hashResult.array[1] < 96) {
|
|
77
|
+
loc.type = UInt8.from(LocationType.PLANET)
|
|
78
|
+
} else if (hashResult.array[1] < 176) {
|
|
79
|
+
loc.type = UInt8.from(LocationType.ASTEROID)
|
|
80
|
+
} else {
|
|
81
|
+
loc.type = UInt8.from(LocationType.NEBULA)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
loc.subtype = UInt8.from(hashResult.array[2])
|
|
85
|
+
loc.seed0 = UInt8.from(hashResult.array[3])
|
|
86
|
+
loc.seed1 = UInt8.from(hashResult.array[4])
|
|
87
|
+
|
|
88
|
+
return loc
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function deriveLocationEpoch(
|
|
92
|
+
epochSeed: Checksum256Type,
|
|
93
|
+
coordinates: CoordinatesType
|
|
94
|
+
): ServerContract.Types.location_epoch {
|
|
95
|
+
const seed = Checksum256.from(epochSeed)
|
|
96
|
+
const coords = Coordinates.from(coordinates)
|
|
97
|
+
const str = `system-epoch-${coords.x}-${coords.y}`
|
|
98
|
+
const hashResult = hash512(seed, str)
|
|
99
|
+
|
|
100
|
+
return ServerContract.Types.location_epoch.from({
|
|
101
|
+
active: hashResult.array[0] < LOCATION_ACTIVE_THRESHOLD,
|
|
102
|
+
seed0: hashResult.array[1],
|
|
103
|
+
seed1: hashResult.array[2],
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function deriveLocation(
|
|
108
|
+
gameSeed: Checksum256Type,
|
|
109
|
+
epochSeed: Checksum256Type,
|
|
110
|
+
coordinates: CoordinatesType
|
|
111
|
+
): ServerContract.Types.location_derived {
|
|
112
|
+
return ServerContract.Types.location_derived.from({
|
|
113
|
+
static_props: deriveLocationStatic(gameSeed, coordinates),
|
|
114
|
+
epoch_props: deriveLocationEpoch(epochSeed, coordinates),
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function deriveLocationMixture(
|
|
119
|
+
location: ServerContract.Types.location_derived,
|
|
120
|
+
epochSeed: Checksum256Type
|
|
121
|
+
): ServerContract.Types.mixture_info {
|
|
122
|
+
const locationType = location.static_props.type.toNumber()
|
|
123
|
+
|
|
124
|
+
if (locationType === LocationType.NEBULA) {
|
|
125
|
+
return ServerContract.Types.mixture_info.from({
|
|
126
|
+
components: [{good_id: 1, purity: PRECISION}],
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (locationType === LocationType.ASTEROID) {
|
|
131
|
+
const seed = Checksum256.from(epochSeed)
|
|
132
|
+
const coords = location.static_props.coords
|
|
133
|
+
const str = `mixture-${coords.x}-${coords.y}`
|
|
134
|
+
const hashResult = hash512(seed, str)
|
|
135
|
+
|
|
136
|
+
const ironPrimary = location.static_props.subtype.toNumber() % 2 === 0
|
|
137
|
+
const purityRange = 0.3
|
|
138
|
+
const purityRoll = hashResult.array[0] / 255
|
|
139
|
+
const primaryPurity = 0.5 + purityRoll * purityRange
|
|
140
|
+
|
|
141
|
+
const primaryId = ironPrimary ? 26 : 29
|
|
142
|
+
const secondaryId = ironPrimary ? 29 : 26
|
|
143
|
+
const primaryAmt = Math.floor(primaryPurity * PRECISION)
|
|
144
|
+
const secondaryAmt = PRECISION - primaryAmt
|
|
145
|
+
|
|
146
|
+
return ServerContract.Types.mixture_info.from({
|
|
147
|
+
components: [
|
|
148
|
+
{good_id: primaryId, purity: primaryAmt},
|
|
149
|
+
{good_id: secondaryId, purity: secondaryAmt},
|
|
150
|
+
],
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return ServerContract.Types.mixture_info.from({components: []})
|
|
27
155
|
}
|