@shipload/sdk 1.0.0-next.5 → 1.0.0-next.6

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "1.0.0-next.5",
4
+ "version": "1.0.0-next.6",
5
5
  "homepage": "https://github.com/shipload/toolkit/tree/master/packages/sdk",
6
6
  "repository": {
7
7
  "type": "git",
@@ -7,6 +7,7 @@ export {
7
7
  getEligibleResources,
8
8
  getResourceWeight,
9
9
  getLocationCandidates,
10
+ getLocationProfile,
10
11
  getDepthThreshold,
11
12
  getResourceTier,
12
13
  DEPTH_THRESHOLD_T1,
@@ -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 ASTEROID_RESOURCES = [101, 102, 103, 201, 202]
79
- const NEBULA_RESOURCES = [202, 203, 301, 302, 303]
80
- const GAS_GIANT_RESOURCES = [301, 302, 303, 401, 501]
81
- const ROCKY_RESOURCES = [101, 102, 103, 401, 402, 403, 503]
82
- const TERRESTRIAL_RESOURCES = [201, 202, 401, 402, 501, 502, 503]
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
- export function getLocationCandidates(locationType: number, subtype: number): number[] {
88
- if (locationType === 2) return ASTEROID_RESOURCES
89
- if (locationType === 3) return NEBULA_RESOURCES
90
- if (locationType === 1) {
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 GAS_GIANT_RESOURCES
133
+ return [
134
+ {category: RESOURCE_GAS, maxTier: 10},
135
+ {category: RESOURCE_CRYSTAL, maxTier: 3},
136
+ ]
94
137
  case PLANET_SUBTYPE_ROCKY:
95
- return ROCKY_RESOURCES
138
+ return [
139
+ {category: RESOURCE_REGOLITH, maxTier: 10},
140
+ {category: RESOURCE_ORE, maxTier: 3},
141
+ ]
96
142
  case PLANET_SUBTYPE_TERRESTRIAL:
97
- return TERRESTRIAL_RESOURCES
143
+ return [
144
+ {category: RESOURCE_ORE, maxTier: 10},
145
+ {category: RESOURCE_BIOMASS, maxTier: 3},
146
+ ]
98
147
  case PLANET_SUBTYPE_ICY:
99
- return ICY_RESOURCES
148
+ return [
149
+ {category: RESOURCE_CRYSTAL, maxTier: 10},
150
+ {category: RESOURCE_REGOLITH, maxTier: 3},
151
+ ]
100
152
  case PLANET_SUBTYPE_OCEAN:
101
- return OCEAN_RESOURCES
153
+ return [
154
+ {category: RESOURCE_BIOMASS, maxTier: 10},
155
+ {category: RESOURCE_GAS, maxTier: 3},
156
+ ]
102
157
  case PLANET_SUBTYPE_INDUSTRIAL:
103
- return INDUSTRIAL_RESOURCES
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,
@@ -86,6 +86,7 @@ export {
86
86
  getEligibleResources,
87
87
  getResourceWeight,
88
88
  getLocationCandidates,
89
+ getLocationProfile,
89
90
  getDepthThreshold,
90
91
  getResourceTier,
91
92
  DEPTH_THRESHOLD_T1,
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 {
@@ -22,12 +22,10 @@ export function getLocationType(
22
22
  return LocationType.EMPTY
23
23
  }
24
24
 
25
- if (hashResult.array[1] < 96) {
26
- return LocationType.PLANET
27
- } else if (hashResult.array[1] < 176) {
28
- return LocationType.ASTEROID
29
- }
30
- return LocationType.NEBULA
25
+ if (hashResult.array[1] < 96) return LocationType.PLANET
26
+ if (hashResult.array[1] < 149) return LocationType.ASTEROID
27
+ if (hashResult.array[1] < 202) return LocationType.NEBULA
28
+ return LocationType.ICE_FIELD
31
29
  }
32
30
 
33
31
  export function isGatherableLocation(locationType: LocationType): boolean {
@@ -44,6 +42,8 @@ export function getLocationTypeName(type: LocationType): string {
44
42
  return 'Asteroid'
45
43
  case LocationType.NEBULA:
46
44
  return 'Nebula'
45
+ case LocationType.ICE_FIELD:
46
+ return 'Ice Field'
47
47
  }
48
48
  }
49
49
 
@@ -76,6 +76,15 @@ function generateNebulaName(hashResult: Checksum512): string {
76
76
  return `${nebulaAdjectives[adjIdx]} ${nebulaNouns[nounIdx]}`
77
77
  }
78
78
 
79
+ function generateIceFieldName(hashResult: Checksum512): string {
80
+ const A = 65
81
+ const letter1 = String.fromCharCode(A + (hashResult.array[0] % 26))
82
+ const letter2 = String.fromCharCode(A + (hashResult.array[1] % 26))
83
+ const subId = (hashResult.array[2] % 9) + 1
84
+ const num = (uint16(hashResult, 3) % 9000) + 1000
85
+ return `${letter1}${letter2}-${subId}/${num}`
86
+ }
87
+
79
88
  export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
80
89
  const seed = Checksum256.from(gameSeed)
81
90
  const locationType = getLocationType(seed, location)
@@ -91,6 +100,8 @@ export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesTy
91
100
  return generateAsteroidName(hashResult)
92
101
  case LocationType.NEBULA:
93
102
  return generateNebulaName(hashResult)
103
+ case LocationType.ICE_FIELD:
104
+ return generateIceFieldName(hashResult)
94
105
  default:
95
106
  return generatePlanetName(hashResult)
96
107
  }
@@ -123,10 +134,12 @@ export function deriveLocationStatic(
123
134
 
124
135
  if (hashResult.array[1] < 96) {
125
136
  loc.type = UInt8.from(LocationType.PLANET)
126
- } else if (hashResult.array[1] < 176) {
137
+ } else if (hashResult.array[1] < 149) {
127
138
  loc.type = UInt8.from(LocationType.ASTEROID)
128
- } else {
139
+ } else if (hashResult.array[1] < 202) {
129
140
  loc.type = UInt8.from(LocationType.NEBULA)
141
+ } else {
142
+ loc.type = UInt8.from(LocationType.ICE_FIELD)
130
143
  }
131
144
 
132
145
  loc.subtype = UInt8.from(