@shipload/sdk 1.0.0-next.7 → 1.0.0-next.9

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.
@@ -1,10 +1,53 @@
1
1
  import {Name} from '@wharfkit/antelope'
2
+ import {
3
+ ITEM_CONTAINER_T1_PACKED,
4
+ ITEM_CONTAINER_T2_PACKED,
5
+ ITEM_EXTRACTOR_T1_PACKED,
6
+ ITEM_SHIP_T1_PACKED,
7
+ ITEM_WAREHOUSE_T1_PACKED,
8
+ } from '../data/item-ids'
2
9
 
3
10
  export const ENTITY_SHIP = Name.from('ship')
4
11
  export const ENTITY_WAREHOUSE = Name.from('warehouse')
12
+ export const ENTITY_EXTRACTOR = Name.from('extractor')
5
13
  export const ENTITY_CONTAINER = Name.from('container')
6
14
 
7
- export type EntityTypeName = 'ship' | 'warehouse' | 'container'
15
+ export enum EntityClass {
16
+ OrbitalVessel = 0,
17
+ PlanetaryStructure = 1,
18
+ }
19
+
20
+ export function getEntityClass(entityType: Name | EntityTypeName): EntityClass {
21
+ const typeName = typeof entityType === 'string' ? entityType : entityType.toString()
22
+ switch (typeName) {
23
+ case 'ship':
24
+ case 'container':
25
+ return EntityClass.OrbitalVessel
26
+ case 'warehouse':
27
+ case 'extractor':
28
+ return EntityClass.PlanetaryStructure
29
+ default:
30
+ throw new Error(`Entity type has no class: ${typeName}`)
31
+ }
32
+ }
33
+
34
+ export function getPackedEntityType(itemId: number): Name | null {
35
+ switch (itemId) {
36
+ case ITEM_SHIP_T1_PACKED:
37
+ return ENTITY_SHIP
38
+ case ITEM_CONTAINER_T1_PACKED:
39
+ case ITEM_CONTAINER_T2_PACKED:
40
+ return ENTITY_CONTAINER
41
+ case ITEM_WAREHOUSE_T1_PACKED:
42
+ return ENTITY_WAREHOUSE
43
+ case ITEM_EXTRACTOR_T1_PACKED:
44
+ return ENTITY_EXTRACTOR
45
+ default:
46
+ return null
47
+ }
48
+ }
49
+
50
+ export type EntityTypeName = 'ship' | 'warehouse' | 'extractor' | 'container'
8
51
 
9
52
  export interface EntityTraits {
10
53
  typeName: Name
@@ -32,6 +75,15 @@ export const warehouseTraits: EntityTraits = {
32
75
  notFoundError: 'warehouse not found',
33
76
  }
34
77
 
78
+ export const extractorTraits: EntityTraits = {
79
+ typeName: ENTITY_EXTRACTOR,
80
+ isMovable: false,
81
+ hasEnergy: true,
82
+ hasLoaders: false,
83
+
84
+ notFoundError: 'extractor not found',
85
+ }
86
+
35
87
  export const containerTraits: EntityTraits = {
36
88
  typeName: ENTITY_CONTAINER,
37
89
  isMovable: true,
@@ -49,6 +101,8 @@ export function getEntityTraits(entityType: Name | EntityTypeName): EntityTraits
49
101
  return shipTraits
50
102
  case 'warehouse':
51
103
  return warehouseTraits
104
+ case 'extractor':
105
+ return extractorTraits
52
106
  case 'container':
53
107
  return containerTraits
54
108
  default:
@@ -64,6 +118,10 @@ export function isWarehouse(entity: {type?: Name}): boolean {
64
118
  return entity.type?.equals(ENTITY_WAREHOUSE) ?? false
65
119
  }
66
120
 
121
+ export function isExtractor(entity: {type?: Name}): boolean {
122
+ return entity.type?.equals(ENTITY_EXTRACTOR) ?? false
123
+ }
124
+
67
125
  export function isContainer(entity: {type?: Name}): boolean {
68
126
  return entity.type?.equals(ENTITY_CONTAINER) ?? false
69
127
  }
package/src/types.ts CHANGED
@@ -12,7 +12,7 @@ import {ServerContract} from './contracts'
12
12
  export const PRECISION = 10000
13
13
  export const CRAFT_ENERGY_DIVISOR = 150000
14
14
 
15
- export const WAREHOUSE_Z = 500
15
+ export const PLANETARY_STRUCTURE_Z = 0
16
16
 
17
17
  export const CONTAINER_Z = 300
18
18
 
@@ -23,6 +23,8 @@ export const MAX_ORBITAL_ALTITUDE = 3000
23
23
 
24
24
  export const BASE_ORBITAL_MASS = 100000
25
25
 
26
+ export const MIN_TRANSFER_DISTANCE = 100
27
+
26
28
  export interface ShipLike {
27
29
  coordinates: ServerContract.Types.coordinates
28
30
  hullmass?: UInt32
@@ -150,6 +150,13 @@ export function deriveLocationStatic(
150
150
  return loc
151
151
  }
152
152
 
153
+ export function isLocationBuildable(
154
+ gameSeed: Checksum256Type,
155
+ coordinates: CoordinatesType
156
+ ): boolean {
157
+ return getLocationType(gameSeed, coordinates) === LocationType.PLANET
158
+ }
159
+
153
160
  export function deriveLocation(
154
161
  gameSeed: Checksum256Type,
155
162
  coordinates: CoordinatesType