screeps-clockwork 0.7.2 → 0.9.0

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/dist/index.js CHANGED
@@ -25,393 +25,71 @@ function requireEncoderDecoderTogether_min () {
25
25
  requireEncoderDecoderTogether_min();
26
26
 
27
27
  function clockworkcostmatrix_get_pointer(value) {
28
- if (!value ||
29
- typeof value !== 'object' ||
30
- !('__wbg_ptr' in value) ||
31
- value.constructor.name !== 'ClockworkCostMatrix') {
32
- return 0;
33
- }
34
- return value.__wbg_ptr;
35
- }
36
-
37
- let wasm;
38
-
39
- const heap = new Array(128).fill(undefined);
40
-
41
- heap.push(undefined, null, true, false);
42
-
43
- function getObject(idx) { return heap[idx]; }
44
-
45
- let heap_next = heap.length;
46
-
47
- function addHeapObject(obj) {
48
- if (heap_next === heap.length) heap.push(heap.length + 1);
49
- const idx = heap_next;
50
- heap_next = heap[idx];
51
-
52
- heap[idx] = obj;
53
- return idx;
54
- }
55
-
56
- function handleError(f, args) {
57
- try {
58
- return f.apply(this, args);
59
- } catch (e) {
60
- wasm.__wbindgen_exn_store(addHeapObject(e));
61
- }
62
- }
63
-
64
- function dropObject(idx) {
65
- if (idx < 132) return;
66
- heap[idx] = heap_next;
67
- heap_next = idx;
68
- }
69
-
70
- function takeObject(idx) {
71
- const ret = getObject(idx);
72
- dropObject(idx);
73
- return ret;
74
- }
75
-
76
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
77
-
78
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }
79
- let cachedUint8ArrayMemory0 = null;
80
-
81
- function getUint8ArrayMemory0() {
82
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
83
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
84
- }
85
- return cachedUint8ArrayMemory0;
86
- }
87
-
88
- function getStringFromWasm0(ptr, len) {
89
- ptr = ptr >>> 0;
90
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
91
- }
92
-
93
- function isLikeNone(x) {
94
- return x === undefined || x === null;
95
- }
96
-
97
- let WASM_VECTOR_LEN = 0;
98
-
99
- const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
100
-
101
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
102
- ? function (arg, view) {
103
- return cachedTextEncoder.encodeInto(arg, view);
104
- }
105
- : function (arg, view) {
106
- const buf = cachedTextEncoder.encode(arg);
107
- view.set(buf);
108
- return {
109
- read: arg.length,
110
- written: buf.length
111
- };
112
- });
113
-
114
- function passStringToWasm0(arg, malloc, realloc) {
115
-
116
- if (realloc === undefined) {
117
- const buf = cachedTextEncoder.encode(arg);
118
- const ptr = malloc(buf.length, 1) >>> 0;
119
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
120
- WASM_VECTOR_LEN = buf.length;
121
- return ptr;
122
- }
123
-
124
- let len = arg.length;
125
- let ptr = malloc(len, 1) >>> 0;
126
-
127
- const mem = getUint8ArrayMemory0();
128
-
129
- let offset = 0;
130
-
131
- for (; offset < len; offset++) {
132
- const code = arg.charCodeAt(offset);
133
- if (code > 0x7F) break;
134
- mem[ptr + offset] = code;
135
- }
136
-
137
- if (offset !== len) {
138
- if (offset !== 0) {
139
- arg = arg.slice(offset);
140
- }
141
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
142
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
143
- const ret = encodeString(arg, view);
144
-
145
- offset += ret.written;
146
- ptr = realloc(ptr, len, offset, 1) >>> 0;
147
- }
148
-
149
- WASM_VECTOR_LEN = offset;
150
- return ptr;
151
- }
152
-
153
- let cachedDataViewMemory0 = null;
154
-
155
- function getDataViewMemory0() {
156
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
157
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
158
- }
159
- return cachedDataViewMemory0;
160
- }
161
- /**
162
- * @returns {string}
163
- */
164
- function version() {
165
- let deferred1_0;
166
- let deferred1_1;
167
- try {
168
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
169
- wasm.version(retptr);
170
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
171
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
172
- deferred1_0 = r0;
173
- deferred1_1 = r1;
174
- return getStringFromWasm0(r0, r1);
175
- } finally {
176
- wasm.__wbindgen_add_to_stack_pointer(16);
177
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
178
- }
179
- }
180
-
181
- /**
182
- * Exports the global range calculation between two positions.
183
- * @param {number} packed_pos_1
184
- * @param {number} packed_pos_2
185
- * @returns {number}
186
- */
187
- function get_range(packed_pos_1, packed_pos_2) {
188
- const ret = wasm.get_range(packed_pos_1, packed_pos_2);
189
- return ret >>> 0;
190
- }
191
-
192
- let cachedUint32ArrayMemory0 = null;
193
-
194
- function getUint32ArrayMemory0() {
195
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
196
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
197
- }
198
- return cachedUint32ArrayMemory0;
199
- }
200
-
201
- function passArray32ToWasm0(arg, malloc) {
202
- const ptr = malloc(arg.length * 4, 4) >>> 0;
203
- getUint32ArrayMemory0().set(arg, ptr / 4);
204
- WASM_VECTOR_LEN = arg.length;
205
- return ptr;
206
- }
207
-
208
- let stack_pointer = 128;
209
-
210
- function addBorrowedObject(obj) {
211
- if (stack_pointer == 1) throw new Error('out of js stack');
212
- heap[--stack_pointer] = obj;
213
- return stack_pointer;
214
- }
215
- /**
216
- * WASM wrapper for the BFS multiroom distance map function.
217
- *
218
- * # Arguments
219
- * * `start_packed` - Array of packed position integers representing start positions
220
- * * `get_cost_matrix` - JavaScript function that returns cost matrices for rooms
221
- * * `max_ops` - Maximum number of tiles to explore
222
- * * `max_rooms` - Maximum number of rooms to explore
223
- * * `max_room_distance` - Maximum Manhattan distance in rooms to explore
224
- * * `max_path_cost` - Maximum distance in tiles to explore
225
- * * `any_of_destinations` - Array of packed positions to trigger early exit when any are reached
226
- * * `all_of_destinations` - Array of packed positions to trigger early exit when all are reached
227
- *
228
- * # Returns
229
- * A `MultiroomDistanceMap` containing the distances from the start positions
230
- * @param {Uint32Array} start_packed
231
- * @param {Function} get_cost_matrix
232
- * @param {number} max_ops
233
- * @param {number} max_rooms
234
- * @param {number} max_path_cost
235
- * @param {Uint32Array | null} [any_of_destinations]
236
- * @param {Uint32Array | null} [all_of_destinations]
237
- * @returns {SearchResult}
238
- */
239
- function js_bfs_multiroom_distance_map(start_packed, get_cost_matrix, max_ops, max_rooms, max_path_cost, any_of_destinations, all_of_destinations) {
240
- try {
241
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
242
- const len0 = WASM_VECTOR_LEN;
243
- var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
244
- var len1 = WASM_VECTOR_LEN;
245
- var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
246
- var len2 = WASM_VECTOR_LEN;
247
- const ret = wasm.js_bfs_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_ops, max_rooms, max_path_cost, ptr1, len1, ptr2, len2);
248
- return SearchResult.__wrap(ret);
249
- } finally {
250
- heap[stack_pointer++] = undefined;
28
+ if (!value ||
29
+ typeof value !== 'object' ||
30
+ !('__wbg_ptr' in value) ||
31
+ value.constructor.name !== 'ClockworkCostMatrix') {
32
+ return 0;
251
33
  }
34
+ return value.__wbg_ptr;
252
35
  }
253
36
 
37
+ /* @ts-self-types="./screeps_clockwork.d.ts" */
254
38
  /**
255
- * @param {Uint32Array} start_packed
256
- * @param {Function} get_cost_matrix
257
- * @param {number} max_ops
258
- * @param {number} max_rooms
259
- * @param {number} max_path_cost
260
- * @param {Uint32Array | null} [any_of_destinations]
261
- * @param {Uint32Array | null} [all_of_destinations]
262
- * @returns {SearchResult}
39
+ * A wrapper around the `LocalCostMatrix` type from the Screeps API.
40
+ * Instances can be passed between WASM and JS as a pointer, using the
41
+ * methods to get and set values, rather than copying the entire matrix.
263
42
  */
264
- function js_dijkstra_multiroom_distance_map(start_packed, get_cost_matrix, max_ops, max_rooms, max_path_cost, any_of_destinations, all_of_destinations) {
265
- try {
266
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
267
- const len0 = WASM_VECTOR_LEN;
268
- var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
269
- var len1 = WASM_VECTOR_LEN;
270
- var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
271
- var len2 = WASM_VECTOR_LEN;
272
- const ret = wasm.js_dijkstra_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_ops, max_rooms, max_path_cost, ptr1, len1, ptr2, len2);
273
- return SearchResult.__wrap(ret);
274
- } finally {
275
- heap[stack_pointer++] = undefined;
43
+ class ClockworkCostMatrix {
44
+ static __wrap(ptr) {
45
+ const obj = Object.create(ClockworkCostMatrix.prototype);
46
+ obj.__wbg_ptr = ptr;
47
+ ClockworkCostMatrixFinalization.register(obj, obj.__wbg_ptr, obj);
48
+ return obj;
276
49
  }
277
- }
278
-
279
- function _assertClass(instance, klass) {
280
- if (!(instance instanceof klass)) {
281
- throw new Error(`expected instance of ${klass.name}`);
50
+ __destroy_into_raw() {
51
+ const ptr = this.__wbg_ptr;
52
+ this.__wbg_ptr = 0;
53
+ ClockworkCostMatrixFinalization.unregister(this);
54
+ return ptr;
282
55
  }
283
- }
284
- /**
285
- * @param {number} start
286
- * @param {MultiroomMonoFlowField} flow_field
287
- * @returns {Path}
288
- */
289
- function js_path_to_multiroom_mono_flow_field_origin(start, flow_field) {
290
- _assertClass(flow_field, MultiroomMonoFlowField);
291
- const ret = wasm.js_path_to_multiroom_mono_flow_field_origin(start, flow_field.__wbg_ptr);
292
- return Path.__wrap(ret);
293
- }
294
-
295
- /**
296
- * Creates a monodirectional flow field for the given distance map.
297
- * @param {MultiroomDistanceMap} distance_map
298
- * @returns {MultiroomMonoFlowField}
299
- */
300
- function multiroomMonoFlowField(distance_map) {
301
- _assertClass(distance_map, MultiroomDistanceMap);
302
- var ptr0 = distance_map.__destroy_into_raw();
303
- const ret = wasm.multiroomMonoFlowField(ptr0);
304
- return MultiroomMonoFlowField.__wrap(ret);
305
- }
306
-
307
- function getArrayJsValueFromWasm0(ptr, len) {
308
- ptr = ptr >>> 0;
309
- const mem = getDataViewMemory0();
310
- const result = [];
311
- for (let i = ptr; i < ptr + 4 * len; i += 4) {
312
- result.push(takeObject(mem.getUint32(i, true)));
56
+ free() {
57
+ const ptr = this.__destroy_into_raw();
58
+ wasm.__wbg_clockworkcostmatrix_free(ptr, 0);
313
59
  }
314
- return result;
315
- }
316
-
317
- function passArrayJsValueToWasm0(array, malloc) {
318
- const ptr = malloc(array.length * 4, 4) >>> 0;
319
- const mem = getDataViewMemory0();
320
- for (let i = 0; i < array.length; i++) {
321
- mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
60
+ /**
61
+ * Gets the cost of a given position in the cost matrix.
62
+ * @param {number} x
63
+ * @param {number} y
64
+ * @returns {number}
65
+ */
66
+ get(x, y) {
67
+ const ret = wasm.clockworkcostmatrix_get(this.__wbg_ptr, x, y);
68
+ return ret;
322
69
  }
323
- WASM_VECTOR_LEN = array.length;
324
- return ptr;
325
- }
326
-
327
- function getArrayU32FromWasm0(ptr, len) {
328
- ptr = ptr >>> 0;
329
- return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
330
- }
331
- /**
332
- * @param {number} room_name
333
- * @param {number | null} [plain_cost]
334
- * @param {number | null} [swamp_cost]
335
- * @param {number | null} [wall_cost]
336
- * @returns {ClockworkCostMatrix}
337
- */
338
- function get_terrain_cost_matrix(room_name, plain_cost, swamp_cost, wall_cost) {
339
- const ret = wasm.get_terrain_cost_matrix(room_name, isLikeNone(plain_cost) ? 0xFFFFFF : plain_cost, isLikeNone(swamp_cost) ? 0xFFFFFF : swamp_cost, isLikeNone(wall_cost) ? 0xFFFFFF : wall_cost);
340
- return ClockworkCostMatrix.__wrap(ret);
341
- }
342
-
343
- /**
344
- * Creates a flow field for the given distance map.
345
- * @param {MultiroomDistanceMap} distance_map
346
- * @returns {MultiroomFlowField}
347
- */
348
- function multiroomFlowField(distance_map) {
349
- _assertClass(distance_map, MultiroomDistanceMap);
350
- var ptr0 = distance_map.__destroy_into_raw();
351
- const ret = wasm.multiroomFlowField(ptr0);
352
- return MultiroomFlowField.__wrap(ret);
353
- }
354
-
355
- let cachedUint16ArrayMemory0 = null;
356
-
357
- function getUint16ArrayMemory0() {
358
- if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
359
- cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
70
+ /**
71
+ * Creates a new cost matrix within the WASM module. Optionally, a default value
72
+ * can be provided to initialize all cells in the matrix to that value.
73
+ * @param {number | null} [_default]
74
+ */
75
+ constructor(_default) {
76
+ const ret = wasm.clockworkcostmatrix_new(isLikeNone(_default) ? 0xFFFFFF : _default);
77
+ this.__wbg_ptr = ret;
78
+ ClockworkCostMatrixFinalization.register(this, this.__wbg_ptr, this);
79
+ return this;
360
80
  }
361
- return cachedUint16ArrayMemory0;
362
- }
363
-
364
- function getArrayU16FromWasm0(ptr, len) {
365
- ptr = ptr >>> 0;
366
- return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
367
- }
368
- /**
369
- * @param {number} start
370
- * @param {MultiroomFlowField} flow_field
371
- * @returns {Path}
372
- */
373
- function js_path_to_multiroom_flow_field_origin(start, flow_field) {
374
- _assertClass(flow_field, MultiroomFlowField);
375
- const ret = wasm.js_path_to_multiroom_flow_field_origin(start, flow_field.__wbg_ptr);
376
- return Path.__wrap(ret);
377
- }
378
-
379
- /**
380
- * @param {number} start
381
- * @param {MultiroomDistanceMap} distance_map
382
- * @returns {Path}
383
- */
384
- function js_path_to_multiroom_distance_map_origin(start, distance_map) {
385
- _assertClass(distance_map, MultiroomDistanceMap);
386
- const ret = wasm.js_path_to_multiroom_distance_map_origin(start, distance_map.__wbg_ptr);
387
- return Path.__wrap(ret);
388
- }
389
-
390
- /**
391
- * @param {Uint32Array} start_packed
392
- * @param {Function} get_cost_matrix
393
- * @param {number} max_rooms
394
- * @param {number} max_ops
395
- * @param {number} max_path_cost
396
- * @param {Uint32Array | null} [any_of_destinations]
397
- * @param {Uint32Array | null} [all_of_destinations]
398
- * @returns {SearchResult}
399
- */
400
- function js_astar_multiroom_distance_map(start_packed, get_cost_matrix, max_rooms, max_ops, max_path_cost, any_of_destinations, all_of_destinations) {
401
- try {
402
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
403
- const len0 = WASM_VECTOR_LEN;
404
- var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
405
- var len1 = WASM_VECTOR_LEN;
406
- var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
407
- var len2 = WASM_VECTOR_LEN;
408
- const ret = wasm.js_astar_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_rooms, max_ops, max_path_cost, ptr1, len1, ptr2, len2);
409
- return SearchResult.__wrap(ret);
410
- } finally {
411
- heap[stack_pointer++] = undefined;
81
+ /**
82
+ * Sets the cost of a given position in the cost matrix.
83
+ * @param {number} x
84
+ * @param {number} y
85
+ * @param {number} value
86
+ */
87
+ set(x, y, value) {
88
+ wasm.clockworkcostmatrix_set(this.__wbg_ptr, x, y, value);
412
89
  }
413
90
  }
414
-
91
+ if (Symbol.dispose)
92
+ ClockworkCostMatrix.prototype[Symbol.dispose] = ClockworkCostMatrix.prototype.free;
415
93
  /**
416
94
  * Translates `COLOR_*` and `COLORS_ALL` constants.
417
95
  * @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}
@@ -452,6 +130,73 @@ Object.freeze({
452
130
  Left: 7, "7": "Left",
453
131
  TopLeft: 8, "8": "TopLeft",
454
132
  });
133
+ /**
134
+ * @enum {0 | 1}
135
+ */
136
+ const DirectionOrder = Object.freeze({
137
+ CardinalFirst: 0, "0": "CardinalFirst",
138
+ DiagonalFirst: 1, "1": "DiagonalFirst",
139
+ });
140
+ /**
141
+ * Maps a distance value onto individual room tile positions.
142
+ */
143
+ class DistanceMap {
144
+ static __wrap(ptr) {
145
+ const obj = Object.create(DistanceMap.prototype);
146
+ obj.__wbg_ptr = ptr;
147
+ DistanceMapFinalization.register(obj, obj.__wbg_ptr, obj);
148
+ return obj;
149
+ }
150
+ __destroy_into_raw() {
151
+ const ptr = this.__wbg_ptr;
152
+ this.__wbg_ptr = 0;
153
+ DistanceMapFinalization.unregister(this);
154
+ return ptr;
155
+ }
156
+ free() {
157
+ const ptr = this.__destroy_into_raw();
158
+ wasm.__wbg_distancemap_free(ptr, 0);
159
+ }
160
+ /**
161
+ * Gets the distance value at a given position.
162
+ * @param {number} x
163
+ * @param {number} y
164
+ * @returns {number}
165
+ */
166
+ get(x, y) {
167
+ const ret = wasm.distancemap_get(this.__wbg_ptr, x, y);
168
+ return ret >>> 0;
169
+ }
170
+ /**
171
+ * Sets the distance value at a given position.
172
+ * @param {number} x
173
+ * @param {number} y
174
+ * @param {number} value
175
+ */
176
+ set(x, y, value) {
177
+ wasm.distancemap_set(this.__wbg_ptr, x, y, value);
178
+ }
179
+ /**
180
+ * Converts the distance map into a flat array of distances.
181
+ * @returns {Uint32Array}
182
+ */
183
+ toArray() {
184
+ try {
185
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
186
+ wasm.distancemap_toArray(retptr, this.__wbg_ptr);
187
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
188
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
189
+ var v1 = getArrayU32FromWasm0(r0, r1).slice();
190
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
191
+ return v1;
192
+ }
193
+ finally {
194
+ wasm.__wbindgen_add_to_stack_pointer(16);
195
+ }
196
+ }
197
+ }
198
+ if (Symbol.dispose)
199
+ DistanceMap.prototype[Symbol.dispose] = DistanceMap.prototype.free;
455
200
  /**
456
201
  * Type used for when the game returns a direction to an exit.
457
202
  *
@@ -521,984 +266,1191 @@ Object.freeze({
521
266
  Reactors: 10051, "10051": "Reactors",
522
267
  });
523
268
  /**
524
- * Translates the `EFFECT_*` constants, which are natural effect types
525
- * @enum {1001 | 1002}
526
- */
527
- Object.freeze({
528
- Invulnerability: 1001, "1001": "Invulnerability",
529
- CollapseTimer: 1002, "1002": "CollapseTimer",
530
- });
531
- /**
532
- * Translates the `PWR_*` constants, which are types of powers used by power
533
- * creeps
534
- * @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19}
535
- */
536
- Object.freeze({
537
- GenerateOps: 1, "1": "GenerateOps",
538
- OperateSpawn: 2, "2": "OperateSpawn",
539
- OperateTower: 3, "3": "OperateTower",
540
- OperateStorage: 4, "4": "OperateStorage",
541
- OperateLab: 5, "5": "OperateLab",
542
- OperateExtension: 6, "6": "OperateExtension",
543
- OperateObserver: 7, "7": "OperateObserver",
544
- OperateTerminal: 8, "8": "OperateTerminal",
545
- DisruptSpawn: 9, "9": "DisruptSpawn",
546
- DisruptTower: 10, "10": "DisruptTower",
547
- Shield: 12, "12": "Shield",
548
- RegenSource: 13, "13": "RegenSource",
549
- RegenMineral: 14, "14": "RegenMineral",
550
- DisruptTerminal: 15, "15": "DisruptTerminal",
551
- OperatePower: 16, "16": "OperatePower",
552
- Fortify: 17, "17": "Fortify",
553
- OperateController: 18, "18": "OperateController",
554
- OperateFactory: 19, "19": "OperateFactory",
555
- });
556
- /**
557
- * Translates `TERRAIN_*` constants.
558
- * @enum {0 | 1 | 2}
559
- */
560
- Object.freeze({
561
- Plain: 0, "0": "Plain",
562
- Wall: 1, "1": "Wall",
563
- Swamp: 2, "2": "Swamp",
564
- });
565
-
566
- const __wbindgen_enum_Look = ["creep", "energy", "resource", "source", "mineral", "structure", "flag", "constructionSite", "nuke", "terrain", "tombstone", "powerCreep", "deposit", "ruin", "scoreContainer", "scoreCollector", "symbolContainer", "symbolDecoder", "reactor"];
567
-
568
- const __wbindgen_enum_StructureType = ["spawn", "extension", "road", "constructedWall", "rampart", "keeperLair", "portal", "controller", "link", "storage", "tower", "observer", "powerBank", "powerSpawn", "extractor", "lab", "terminal", "container", "nuker", "factory", "invaderCore"];
569
-
570
- const ClockworkCostMatrixFinalization = (typeof FinalizationRegistry === 'undefined')
571
- ? { register: () => {}, unregister: () => {} }
572
- : new FinalizationRegistry(ptr => wasm.__wbg_clockworkcostmatrix_free(ptr >>> 0, 1));
573
- /**
574
- * A wrapper around the `LocalCostMatrix` type from the Screeps API.
575
- * Instances can be passed between WASM and JS as a pointer, using the
576
- * methods to get and set values, rather than copying the entire matrix.
269
+ * A flow field is a 50x50 grid (representing a room), representing viable directions
270
+ * to travel to reach a particular target (or targets). A given tile may have multiple
271
+ * equally valid directions, so we represent this as a bitfield (where each bit in an
272
+ * 8-bit unsigned integer represents a direction that is either viable or not).
577
273
  */
578
- class ClockworkCostMatrix {
579
-
274
+ class FlowField {
580
275
  static __wrap(ptr) {
581
- ptr = ptr >>> 0;
582
- const obj = Object.create(ClockworkCostMatrix.prototype);
276
+ const obj = Object.create(FlowField.prototype);
583
277
  obj.__wbg_ptr = ptr;
584
- ClockworkCostMatrixFinalization.register(obj, obj.__wbg_ptr, obj);
278
+ FlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
585
279
  return obj;
586
280
  }
587
-
588
281
  __destroy_into_raw() {
589
282
  const ptr = this.__wbg_ptr;
590
283
  this.__wbg_ptr = 0;
591
- ClockworkCostMatrixFinalization.unregister(this);
284
+ FlowFieldFinalization.unregister(this);
592
285
  return ptr;
593
286
  }
594
-
595
287
  free() {
596
288
  const ptr = this.__destroy_into_raw();
597
- wasm.__wbg_clockworkcostmatrix_free(ptr, 0);
289
+ wasm.__wbg_flowfield_free(ptr, 0);
598
290
  }
599
291
  /**
600
- * Creates a new cost matrix within the WASM module. Optionally, a default value
601
- * can be provided to initialize all cells in the matrix to that value.
602
- * @param {number | null} [_default]
292
+ * Add a direction to the list of valid directions for a given coordinate.
293
+ * @param {number} x
294
+ * @param {number} y
295
+ * @param {Direction} direction
603
296
  */
604
- constructor(_default) {
605
- const ret = wasm.clockworkcostmatrix_new(isLikeNone(_default) ? 0xFFFFFF : _default);
606
- this.__wbg_ptr = ret >>> 0;
607
- ClockworkCostMatrixFinalization.register(this, this.__wbg_ptr, this);
608
- return this;
297
+ addDirection(x, y, direction) {
298
+ wasm.flowfield_addDirection(this.__wbg_ptr, x, y, direction);
609
299
  }
610
300
  /**
611
- * Gets the cost of a given position in the cost matrix.
301
+ * Get the internal value for a given coordinate.
612
302
  * @param {number} x
613
303
  * @param {number} y
614
304
  * @returns {number}
615
305
  */
616
306
  get(x, y) {
617
- const ret = wasm.clockworkcostmatrix_get(this.__wbg_ptr, x, y);
307
+ const ret = wasm.flowfield_get(this.__wbg_ptr, x, y);
618
308
  return ret;
619
309
  }
620
310
  /**
621
- * Sets the cost of a given position in the cost matrix.
311
+ * Get the list of valid directions for a given coordinate.
312
+ * @param {number} x
313
+ * @param {number} y
314
+ * @returns {any[]}
315
+ */
316
+ getDirections(x, y) {
317
+ try {
318
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
319
+ wasm.flowfield_getDirections(retptr, this.__wbg_ptr, x, y);
320
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
321
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
322
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
323
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
324
+ return v1;
325
+ }
326
+ finally {
327
+ wasm.__wbindgen_add_to_stack_pointer(16);
328
+ }
329
+ }
330
+ /**
331
+ * Set the internal value for a given coordinate.
622
332
  * @param {number} x
623
333
  * @param {number} y
624
334
  * @param {number} value
625
335
  */
626
336
  set(x, y, value) {
627
- wasm.clockworkcostmatrix_set(this.__wbg_ptr, x, y, value);
337
+ wasm.flowfield_set(this.__wbg_ptr, x, y, value);
338
+ }
339
+ /**
340
+ * Set the list of valid directions for a given coordinate.
341
+ * @param {number} x
342
+ * @param {number} y
343
+ * @param {any[]} directions
344
+ */
345
+ setDirections(x, y, directions) {
346
+ const ptr0 = passArrayJsValueToWasm0(directions, wasm.__wbindgen_malloc);
347
+ const len0 = WASM_VECTOR_LEN;
348
+ wasm.flowfield_setDirections(this.__wbg_ptr, x, y, ptr0, len0);
628
349
  }
629
350
  }
630
-
631
- const DistanceMapFinalization = (typeof FinalizationRegistry === 'undefined')
632
- ? { register: () => {}, unregister: () => {} }
633
- : new FinalizationRegistry(ptr => wasm.__wbg_distancemap_free(ptr >>> 0, 1));
351
+ if (Symbol.dispose)
352
+ FlowField.prototype[Symbol.dispose] = FlowField.prototype.free;
634
353
  /**
635
- * Maps a distance value onto individual room tile positions.
354
+ * A flow field is a 50x50 grid (representing a room), representing viable directions
355
+ * to travel to reach a particular target (or targets). A mono flow field only stores
356
+ * a single direction for each tile, so we represent this as 4 bits of an unsigned
357
+ * integer (0 for no direction, 1 for TOP, etc.).
636
358
  */
637
- class DistanceMap {
638
-
359
+ class MonoFlowField {
639
360
  static __wrap(ptr) {
640
- ptr = ptr >>> 0;
641
- const obj = Object.create(DistanceMap.prototype);
361
+ const obj = Object.create(MonoFlowField.prototype);
642
362
  obj.__wbg_ptr = ptr;
643
- DistanceMapFinalization.register(obj, obj.__wbg_ptr, obj);
363
+ MonoFlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
644
364
  return obj;
645
365
  }
646
-
647
366
  __destroy_into_raw() {
648
367
  const ptr = this.__wbg_ptr;
649
368
  this.__wbg_ptr = 0;
650
- DistanceMapFinalization.unregister(this);
369
+ MonoFlowFieldFinalization.unregister(this);
651
370
  return ptr;
652
371
  }
653
-
654
372
  free() {
655
373
  const ptr = this.__destroy_into_raw();
656
- wasm.__wbg_distancemap_free(ptr, 0);
374
+ wasm.__wbg_monoflowfield_free(ptr, 0);
657
375
  }
658
376
  /**
659
- * Gets the distance value at a given position.
377
+ * Get the direction for a given coordinate.
660
378
  * @param {number} x
661
379
  * @param {number} y
662
- * @returns {number}
380
+ * @returns {Direction | undefined}
663
381
  */
664
382
  get(x, y) {
665
- const ret = wasm.distancemap_get(this.__wbg_ptr, x, y);
666
- return ret >>> 0;
383
+ const ret = wasm.monoflowfield_get(this.__wbg_ptr, x, y);
384
+ return ret === 0 ? undefined : ret;
667
385
  }
668
386
  /**
669
- * Sets the distance value at a given position.
387
+ * Set the direction for a given coordinate.
670
388
  * @param {number} x
671
389
  * @param {number} y
672
- * @param {number} value
390
+ * @param {Direction | null} [value]
673
391
  */
674
392
  set(x, y, value) {
675
- wasm.distancemap_set(this.__wbg_ptr, x, y, value);
393
+ wasm.monoflowfield_set(this.__wbg_ptr, x, y, isLikeNone(value) ? 0 : value);
394
+ }
395
+ }
396
+ if (Symbol.dispose)
397
+ MonoFlowField.prototype[Symbol.dispose] = MonoFlowField.prototype.free;
398
+ /**
399
+ * Maps distance values across multiple rooms, storing a DistanceMap for each room
400
+ */
401
+ class MultiroomDistanceMap {
402
+ static __wrap(ptr) {
403
+ const obj = Object.create(MultiroomDistanceMap.prototype);
404
+ obj.__wbg_ptr = ptr;
405
+ MultiroomDistanceMapFinalization.register(obj, obj.__wbg_ptr, obj);
406
+ return obj;
407
+ }
408
+ __destroy_into_raw() {
409
+ const ptr = this.__wbg_ptr;
410
+ this.__wbg_ptr = 0;
411
+ MultiroomDistanceMapFinalization.unregister(this);
412
+ return ptr;
413
+ }
414
+ free() {
415
+ const ptr = this.__destroy_into_raw();
416
+ wasm.__wbg_multiroomdistancemap_free(ptr, 0);
676
417
  }
677
418
  /**
678
- * Converts the distance map into a flat array of distances.
679
- * @returns {Uint32Array}
419
+ * Gets the distance value at a given position
420
+ * @param {number} packed_pos
421
+ * @returns {number}
680
422
  */
681
- toArray() {
423
+ get(packed_pos) {
424
+ const ret = wasm.multiroomdistancemap_get(this.__wbg_ptr, packed_pos);
425
+ return ret >>> 0;
426
+ }
427
+ /**
428
+ * Gets the DistanceMap for a given room
429
+ * @param {number} room_name
430
+ * @returns {DistanceMap | undefined}
431
+ */
432
+ get_room(room_name) {
433
+ const ret = wasm.multiroomdistancemap_get_room(this.__wbg_ptr, room_name);
434
+ return ret === 0 ? undefined : DistanceMap.__wrap(ret);
435
+ }
436
+ /**
437
+ * Gets the list of rooms in the map
438
+ * @returns {Uint16Array}
439
+ */
440
+ get_rooms() {
682
441
  try {
683
442
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
684
- wasm.distancemap_toArray(retptr, this.__wbg_ptr);
443
+ wasm.multiroomdistancemap_get_rooms(retptr, this.__wbg_ptr);
685
444
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
686
445
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
687
- var v1 = getArrayU32FromWasm0(r0, r1).slice();
688
- wasm.__wbindgen_free(r0, r1 * 4, 4);
446
+ var v1 = getArrayU16FromWasm0(r0, r1).slice();
447
+ wasm.__wbindgen_free(r0, r1 * 2, 2);
689
448
  return v1;
690
- } finally {
449
+ }
450
+ finally {
691
451
  wasm.__wbindgen_add_to_stack_pointer(16);
692
452
  }
693
453
  }
454
+ /**
455
+ * Creates a new empty multiroom distance map (JavaScript constructor)
456
+ */
457
+ constructor() {
458
+ const ret = wasm.multiroomdistancemap_js_new();
459
+ this.__wbg_ptr = ret;
460
+ MultiroomDistanceMapFinalization.register(this, this.__wbg_ptr, this);
461
+ return this;
462
+ }
463
+ /**
464
+ * Sets the distance value at a given position
465
+ * @param {number} packed_pos
466
+ * @param {number} value
467
+ */
468
+ set(packed_pos, value) {
469
+ wasm.multiroomdistancemap_set(this.__wbg_ptr, packed_pos, value);
470
+ }
694
471
  }
695
-
696
- const FlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
697
- ? { register: () => {}, unregister: () => {} }
698
- : new FinalizationRegistry(ptr => wasm.__wbg_flowfield_free(ptr >>> 0, 1));
472
+ if (Symbol.dispose)
473
+ MultiroomDistanceMap.prototype[Symbol.dispose] = MultiroomDistanceMap.prototype.free;
699
474
  /**
700
- * A flow field is a 50x50 grid (representing a room), representing viable directions
701
- * to travel to reach a particular target (or targets). A given tile may have multiple
702
- * equally valid directions, so we represent this as a bitfield (where each bit in an
703
- * 8-bit unsigned integer represents a direction that is either viable or not).
475
+ * Maps flow field values across multiple rooms, storing a FlowField for each room
704
476
  */
705
- class FlowField {
706
-
477
+ class MultiroomFlowField {
707
478
  static __wrap(ptr) {
708
- ptr = ptr >>> 0;
709
- const obj = Object.create(FlowField.prototype);
479
+ const obj = Object.create(MultiroomFlowField.prototype);
710
480
  obj.__wbg_ptr = ptr;
711
- FlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
481
+ MultiroomFlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
712
482
  return obj;
713
483
  }
714
-
715
484
  __destroy_into_raw() {
716
485
  const ptr = this.__wbg_ptr;
717
486
  this.__wbg_ptr = 0;
718
- FlowFieldFinalization.unregister(this);
487
+ MultiroomFlowFieldFinalization.unregister(this);
719
488
  return ptr;
720
489
  }
721
-
722
490
  free() {
723
491
  const ptr = this.__destroy_into_raw();
724
- wasm.__wbg_flowfield_free(ptr, 0);
492
+ wasm.__wbg_multiroomflowfield_free(ptr, 0);
493
+ }
494
+ /**
495
+ * Adds a direction to the list of valid directions at a given position (JavaScript)
496
+ * @param {number} packed_pos
497
+ * @param {Direction} direction
498
+ */
499
+ addDirection(packed_pos, direction) {
500
+ wasm.multiroomflowfield_addDirection(this.__wbg_ptr, packed_pos, direction);
725
501
  }
726
502
  /**
727
- * Add a direction to the list of valid directions for a given coordinate.
728
- * @param {number} x
729
- * @param {number} y
730
- * @param {Direction} direction
503
+ * Gets the flow field value at a given position
504
+ * @param {number} packed_pos
505
+ * @returns {number}
731
506
  */
732
- addDirection(x, y, direction) {
733
- wasm.flowfield_addDirection(this.__wbg_ptr, x, y, direction);
507
+ get(packed_pos) {
508
+ const ret = wasm.multiroomflowfield_get(this.__wbg_ptr, packed_pos);
509
+ return ret;
734
510
  }
735
511
  /**
736
- * Get the list of valid directions for a given coordinate.
737
- * @param {number} x
738
- * @param {number} y
512
+ * Gets the list of valid directions at a given position (JavaScript)
513
+ * @param {number} packed_pos
739
514
  * @returns {any[]}
740
515
  */
741
- getDirections(x, y) {
516
+ getDirections(packed_pos) {
742
517
  try {
743
518
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
744
- wasm.flowfield_getDirections(retptr, this.__wbg_ptr, x, y);
519
+ wasm.multiroomflowfield_getDirections(retptr, this.__wbg_ptr, packed_pos);
745
520
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
746
521
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
747
522
  var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
748
523
  wasm.__wbindgen_free(r0, r1 * 4, 4);
749
524
  return v1;
750
- } finally {
525
+ }
526
+ finally {
751
527
  wasm.__wbindgen_add_to_stack_pointer(16);
752
528
  }
753
529
  }
754
530
  /**
755
- * Set the list of valid directions for a given coordinate.
756
- * @param {number} x
757
- * @param {number} y
758
- * @param {any[]} directions
531
+ * Gets the FlowField for a given room
532
+ * @param {number} room_name
533
+ * @returns {FlowField | undefined}
759
534
  */
760
- setDirections(x, y, directions) {
761
- const ptr0 = passArrayJsValueToWasm0(directions, wasm.__wbindgen_malloc);
762
- const len0 = WASM_VECTOR_LEN;
763
- wasm.flowfield_setDirections(this.__wbg_ptr, x, y, ptr0, len0);
535
+ getRoom(room_name) {
536
+ const ret = wasm.multiroomflowfield_getRoom(this.__wbg_ptr, room_name);
537
+ return ret === 0 ? undefined : FlowField.__wrap(ret);
764
538
  }
765
539
  /**
766
- * Get the internal value for a given coordinate.
767
- * @param {number} x
768
- * @param {number} y
769
- * @returns {number}
540
+ * Gets the list of rooms in the flow field
541
+ * @returns {Uint16Array}
770
542
  */
771
- get(x, y) {
772
- const ret = wasm.flowfield_get(this.__wbg_ptr, x, y);
773
- return ret;
543
+ getRooms() {
544
+ try {
545
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
546
+ wasm.multiroomflowfield_getRooms(retptr, this.__wbg_ptr);
547
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
548
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
549
+ var v1 = getArrayU16FromWasm0(r0, r1).slice();
550
+ wasm.__wbindgen_free(r0, r1 * 2, 2);
551
+ return v1;
552
+ }
553
+ finally {
554
+ wasm.__wbindgen_add_to_stack_pointer(16);
555
+ }
774
556
  }
775
557
  /**
776
- * Set the internal value for a given coordinate.
777
- * @param {number} x
778
- * @param {number} y
558
+ * Creates a new empty multiroom flow field (JavaScript constructor)
559
+ */
560
+ constructor() {
561
+ const ret = wasm.multiroomflowfield_js_new();
562
+ this.__wbg_ptr = ret;
563
+ MultiroomFlowFieldFinalization.register(this, this.__wbg_ptr, this);
564
+ return this;
565
+ }
566
+ /**
567
+ * Sets the flow field value at a given position
568
+ * @param {number} packed_pos
779
569
  * @param {number} value
780
570
  */
781
- set(x, y, value) {
782
- wasm.flowfield_set(this.__wbg_ptr, x, y, value);
571
+ set(packed_pos, value) {
572
+ wasm.multiroomflowfield_set(this.__wbg_ptr, packed_pos, value);
573
+ }
574
+ /**
575
+ * Sets the list of valid directions at a given position (JavaScript)
576
+ * @param {number} packed_pos
577
+ * @param {any[]} directions
578
+ */
579
+ setDirections(packed_pos, directions) {
580
+ const ptr0 = passArrayJsValueToWasm0(directions, wasm.__wbindgen_malloc);
581
+ const len0 = WASM_VECTOR_LEN;
582
+ wasm.multiroomflowfield_setDirections(this.__wbg_ptr, packed_pos, ptr0, len0);
783
583
  }
784
584
  }
785
-
786
- const MonoFlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
787
- ? { register: () => {}, unregister: () => {} }
788
- : new FinalizationRegistry(ptr => wasm.__wbg_monoflowfield_free(ptr >>> 0, 1));
585
+ if (Symbol.dispose)
586
+ MultiroomFlowField.prototype[Symbol.dispose] = MultiroomFlowField.prototype.free;
789
587
  /**
790
- * A flow field is a 50x50 grid (representing a room), representing viable directions
791
- * to travel to reach a particular target (or targets). A mono flow field only stores
792
- * a single direction for each tile, so we represent this as 4 bits of an unsigned
793
- * integer (0 for no direction, 1 for TOP, etc.).
588
+ * Maps monodirectional flow field values across multiple rooms, storing a MonoFlowField for each room
794
589
  */
795
- class MonoFlowField {
796
-
590
+ class MultiroomMonoFlowField {
797
591
  static __wrap(ptr) {
798
- ptr = ptr >>> 0;
799
- const obj = Object.create(MonoFlowField.prototype);
592
+ const obj = Object.create(MultiroomMonoFlowField.prototype);
800
593
  obj.__wbg_ptr = ptr;
801
- MonoFlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
594
+ MultiroomMonoFlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
802
595
  return obj;
803
596
  }
804
-
805
597
  __destroy_into_raw() {
806
598
  const ptr = this.__wbg_ptr;
807
599
  this.__wbg_ptr = 0;
808
- MonoFlowFieldFinalization.unregister(this);
600
+ MultiroomMonoFlowFieldFinalization.unregister(this);
809
601
  return ptr;
810
602
  }
811
-
812
603
  free() {
813
604
  const ptr = this.__destroy_into_raw();
814
- wasm.__wbg_monoflowfield_free(ptr, 0);
605
+ wasm.__wbg_multiroommonoflowfield_free(ptr, 0);
815
606
  }
816
607
  /**
817
- * Get the direction for a given coordinate.
818
- * @param {number} x
819
- * @param {number} y
608
+ * Gets the direction at a given position
609
+ * @param {number} packed_pos
820
610
  * @returns {Direction | undefined}
821
611
  */
822
- get(x, y) {
823
- const ret = wasm.monoflowfield_get(this.__wbg_ptr, x, y);
612
+ get(packed_pos) {
613
+ const ret = wasm.multiroommonoflowfield_get(this.__wbg_ptr, packed_pos);
824
614
  return ret === 0 ? undefined : ret;
825
615
  }
826
616
  /**
827
- * Set the direction for a given coordinate.
828
- * @param {number} x
829
- * @param {number} y
830
- * @param {Direction | null} [value]
617
+ * Gets the MonoFlowField for a given room
618
+ * @param {number} room_name
619
+ * @returns {MonoFlowField | undefined}
831
620
  */
832
- set(x, y, value) {
833
- wasm.monoflowfield_set(this.__wbg_ptr, x, y, isLikeNone(value) ? 0 : value);
621
+ getRoom(room_name) {
622
+ const ret = wasm.multiroommonoflowfield_getRoom(this.__wbg_ptr, room_name);
623
+ return ret === 0 ? undefined : MonoFlowField.__wrap(ret);
624
+ }
625
+ /**
626
+ * Gets the list of rooms in the flow field
627
+ * @returns {Uint16Array}
628
+ */
629
+ getRooms() {
630
+ try {
631
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
632
+ wasm.multiroommonoflowfield_getRooms(retptr, this.__wbg_ptr);
633
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
634
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
635
+ var v1 = getArrayU16FromWasm0(r0, r1).slice();
636
+ wasm.__wbindgen_free(r0, r1 * 2, 2);
637
+ return v1;
638
+ }
639
+ finally {
640
+ wasm.__wbindgen_add_to_stack_pointer(16);
641
+ }
642
+ }
643
+ /**
644
+ * Creates a new empty multiroom monodirectional flow field (JavaScript constructor)
645
+ */
646
+ constructor() {
647
+ const ret = wasm.multiroommonoflowfield_js_new();
648
+ this.__wbg_ptr = ret;
649
+ MultiroomMonoFlowFieldFinalization.register(this, this.__wbg_ptr, this);
650
+ return this;
651
+ }
652
+ /**
653
+ * Sets the direction at a given position
654
+ * @param {number} packed_pos
655
+ * @param {Direction | null} [direction]
656
+ */
657
+ set(packed_pos, direction) {
658
+ wasm.multiroommonoflowfield_set(this.__wbg_ptr, packed_pos, isLikeNone(direction) ? 0 : direction);
834
659
  }
835
660
  }
836
-
837
- const MultiroomDistanceMapFinalization = (typeof FinalizationRegistry === 'undefined')
838
- ? { register: () => {}, unregister: () => {} }
839
- : new FinalizationRegistry(ptr => wasm.__wbg_multiroomdistancemap_free(ptr >>> 0, 1));
661
+ if (Symbol.dispose)
662
+ MultiroomMonoFlowField.prototype[Symbol.dispose] = MultiroomMonoFlowField.prototype.free;
840
663
  /**
841
- * Maps distance values across multiple rooms, storing a DistanceMap for each room
664
+ * Translates the `EFFECT_*` constants, which are natural effect types
665
+ * @enum {1001 | 1002}
842
666
  */
843
- class MultiroomDistanceMap {
844
-
667
+ Object.freeze({
668
+ Invulnerability: 1001, "1001": "Invulnerability",
669
+ CollapseTimer: 1002, "1002": "CollapseTimer",
670
+ });
671
+ /**
672
+ * A list of positions representing a path.
673
+ */
674
+ class Path {
845
675
  static __wrap(ptr) {
846
- ptr = ptr >>> 0;
847
- const obj = Object.create(MultiroomDistanceMap.prototype);
676
+ const obj = Object.create(Path.prototype);
848
677
  obj.__wbg_ptr = ptr;
849
- MultiroomDistanceMapFinalization.register(obj, obj.__wbg_ptr, obj);
678
+ PathFinalization.register(obj, obj.__wbg_ptr, obj);
850
679
  return obj;
851
680
  }
852
-
853
681
  __destroy_into_raw() {
854
682
  const ptr = this.__wbg_ptr;
855
683
  this.__wbg_ptr = 0;
856
- MultiroomDistanceMapFinalization.unregister(this);
684
+ PathFinalization.unregister(this);
857
685
  return ptr;
858
686
  }
859
-
860
687
  free() {
861
688
  const ptr = this.__destroy_into_raw();
862
- wasm.__wbg_multiroomdistancemap_free(ptr, 0);
689
+ wasm.__wbg_path_free(ptr, 0);
863
690
  }
864
691
  /**
865
- * Gets the DistanceMap for a given room
866
- * @param {number} room_name
867
- * @returns {DistanceMap | undefined}
692
+ * @param {number} packed_position
868
693
  */
869
- get_room(room_name) {
870
- const ret = wasm.multiroomdistancemap_get_room(this.__wbg_ptr, room_name);
871
- return ret === 0 ? undefined : DistanceMap.__wrap(ret);
694
+ add(packed_position) {
695
+ wasm.path_add(this.__wbg_ptr, packed_position);
872
696
  }
873
697
  /**
874
- * Gets the list of rooms in the map
875
- * @returns {Uint16Array}
698
+ * Given a position, find the index of the next adjacent position
699
+ * in the path. If the position is not in the path, the target is
700
+ * the next adjacent position closest to the end of the path. If
701
+ * the position is neither on nor adjacent to the path, return None.
702
+ * @param {number} packed_position
703
+ * @returns {number | undefined}
876
704
  */
877
- get_rooms() {
878
- try {
879
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
880
- wasm.multiroomdistancemap_get_rooms(retptr, this.__wbg_ptr);
881
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
882
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
883
- var v1 = getArrayU16FromWasm0(r0, r1).slice();
884
- wasm.__wbindgen_free(r0, r1 * 2, 2);
885
- return v1;
886
- } finally {
887
- wasm.__wbindgen_add_to_stack_pointer(16);
888
- }
705
+ find_next_index(packed_position) {
706
+ const ret = wasm.path_find_next_index(this.__wbg_ptr, packed_position);
707
+ return ret === Number.MAX_SAFE_INTEGER ? undefined : ret;
708
+ }
709
+ /**
710
+ * @param {number} index
711
+ * @returns {number | undefined}
712
+ */
713
+ get(index) {
714
+ const ret = wasm.path_get(this.__wbg_ptr, index);
715
+ return ret === Number.MAX_SAFE_INTEGER ? undefined : ret;
889
716
  }
890
717
  /**
891
- * Gets the distance value at a given position
892
- * @param {number} packed_pos
893
718
  * @returns {number}
894
719
  */
895
- get(packed_pos) {
896
- const ret = wasm.multiroomdistancemap_get(this.__wbg_ptr, packed_pos);
720
+ len() {
721
+ const ret = wasm.path_len(this.__wbg_ptr);
897
722
  return ret >>> 0;
898
723
  }
899
724
  /**
900
- * Creates a new empty multiroom distance map (JavaScript constructor)
725
+ * @returns {Uint32Array}
901
726
  */
902
- constructor() {
903
- const ret = wasm.multiroomdistancemap_js_new();
904
- this.__wbg_ptr = ret >>> 0;
905
- MultiroomDistanceMapFinalization.register(this, this.__wbg_ptr, this);
906
- return this;
727
+ to_array() {
728
+ try {
729
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
730
+ wasm.path_to_array(retptr, this.__wbg_ptr);
731
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
732
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
733
+ var v1 = getArrayU32FromWasm0(r0, r1).slice();
734
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
735
+ return v1;
736
+ }
737
+ finally {
738
+ wasm.__wbindgen_add_to_stack_pointer(16);
739
+ }
907
740
  }
908
741
  /**
909
- * Sets the distance value at a given position
910
- * @param {number} packed_pos
911
- * @param {number} value
742
+ * @returns {Uint32Array}
912
743
  */
913
- set(packed_pos, value) {
914
- wasm.multiroomdistancemap_set(this.__wbg_ptr, packed_pos, value);
744
+ to_array_reversed() {
745
+ try {
746
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
747
+ wasm.path_to_array_reversed(retptr, this.__wbg_ptr);
748
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
749
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
750
+ var v1 = getArrayU32FromWasm0(r0, r1).slice();
751
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
752
+ return v1;
753
+ }
754
+ finally {
755
+ wasm.__wbindgen_add_to_stack_pointer(16);
756
+ }
915
757
  }
916
758
  }
917
-
918
- const MultiroomFlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
919
- ? { register: () => {}, unregister: () => {} }
920
- : new FinalizationRegistry(ptr => wasm.__wbg_multiroomflowfield_free(ptr >>> 0, 1));
759
+ if (Symbol.dispose)
760
+ Path.prototype[Symbol.dispose] = Path.prototype.free;
921
761
  /**
922
- * Maps flow field values across multiple rooms, storing a FlowField for each room
762
+ * Translates the `PWR_*` constants, which are types of powers used by power
763
+ * creeps
764
+ * @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19}
923
765
  */
924
- class MultiroomFlowField {
925
-
766
+ Object.freeze({
767
+ GenerateOps: 1, "1": "GenerateOps",
768
+ OperateSpawn: 2, "2": "OperateSpawn",
769
+ OperateTower: 3, "3": "OperateTower",
770
+ OperateStorage: 4, "4": "OperateStorage",
771
+ OperateLab: 5, "5": "OperateLab",
772
+ OperateExtension: 6, "6": "OperateExtension",
773
+ OperateObserver: 7, "7": "OperateObserver",
774
+ OperateTerminal: 8, "8": "OperateTerminal",
775
+ DisruptSpawn: 9, "9": "DisruptSpawn",
776
+ DisruptTower: 10, "10": "DisruptTower",
777
+ Shield: 12, "12": "Shield",
778
+ RegenSource: 13, "13": "RegenSource",
779
+ RegenMineral: 14, "14": "RegenMineral",
780
+ DisruptTerminal: 15, "15": "DisruptTerminal",
781
+ OperatePower: 16, "16": "OperatePower",
782
+ Fortify: 17, "17": "Fortify",
783
+ OperateController: 18, "18": "OperateController",
784
+ OperateFactory: 19, "19": "OperateFactory",
785
+ });
786
+ /**
787
+ * A distance map search returns both the distance map (filled out
788
+ * with all tiles explored) and the targets found. These aren't necessarily
789
+ * the same positions specified as targets - if the target range is 5, then
790
+ * this is the first position in range 5 of the target. If multiple targets
791
+ * are specified, and you care about matching the found target with one of
792
+ * the original targets, you can iterate through your list and figure out the
793
+ * ones that are in range of the found target(s).
794
+ */
795
+ class SearchResult {
926
796
  static __wrap(ptr) {
927
- ptr = ptr >>> 0;
928
- const obj = Object.create(MultiroomFlowField.prototype);
797
+ const obj = Object.create(SearchResult.prototype);
929
798
  obj.__wbg_ptr = ptr;
930
- MultiroomFlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
799
+ SearchResultFinalization.register(obj, obj.__wbg_ptr, obj);
931
800
  return obj;
932
801
  }
933
-
934
802
  __destroy_into_raw() {
935
803
  const ptr = this.__wbg_ptr;
936
804
  this.__wbg_ptr = 0;
937
- MultiroomFlowFieldFinalization.unregister(this);
805
+ SearchResultFinalization.unregister(this);
938
806
  return ptr;
939
807
  }
940
-
941
808
  free() {
942
809
  const ptr = this.__destroy_into_raw();
943
- wasm.__wbg_multiroomflowfield_free(ptr, 0);
810
+ wasm.__wbg_searchresult_free(ptr, 0);
944
811
  }
945
812
  /**
946
- * Gets the FlowField for a given room
947
- * @param {number} room_name
948
- * @returns {FlowField | undefined}
813
+ * @returns {MultiroomDistanceMap}
949
814
  */
950
- getRoom(room_name) {
951
- const ret = wasm.multiroomflowfield_getRoom(this.__wbg_ptr, room_name);
952
- return ret === 0 ? undefined : FlowField.__wrap(ret);
815
+ get distance_map() {
816
+ const ret = wasm.searchresult_distance_map(this.__wbg_ptr);
817
+ return MultiroomDistanceMap.__wrap(ret);
953
818
  }
954
819
  /**
955
- * Gets the list of rooms in the flow field
956
- * @returns {Uint16Array}
820
+ * @returns {Uint32Array}
957
821
  */
958
- getRooms() {
822
+ get found_targets() {
959
823
  try {
960
824
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
961
- wasm.multiroomflowfield_getRooms(retptr, this.__wbg_ptr);
825
+ wasm.searchresult_found_targets(retptr, this.__wbg_ptr);
962
826
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
963
827
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
964
- var v1 = getArrayU16FromWasm0(r0, r1).slice();
965
- wasm.__wbindgen_free(r0, r1 * 2, 2);
828
+ var v1 = getArrayU32FromWasm0(r0, r1).slice();
829
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
966
830
  return v1;
967
- } finally {
831
+ }
832
+ finally {
968
833
  wasm.__wbindgen_add_to_stack_pointer(16);
969
834
  }
970
835
  }
971
836
  /**
972
- * Adds a direction to the list of valid directions at a given position (JavaScript)
973
- * @param {number} packed_pos
974
- * @param {Direction} direction
837
+ * @returns {number}
975
838
  */
976
- addDirection(packed_pos, direction) {
977
- wasm.multiroomflowfield_addDirection(this.__wbg_ptr, packed_pos, direction);
839
+ get ops() {
840
+ const ret = wasm.searchresult_ops(this.__wbg_ptr);
841
+ return ret >>> 0;
978
842
  }
979
- /**
980
- * Gets the list of valid directions at a given position (JavaScript)
981
- * @param {number} packed_pos
982
- * @returns {any[]}
983
- */
984
- getDirections(packed_pos) {
985
- try {
986
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
987
- wasm.multiroomflowfield_getDirections(retptr, this.__wbg_ptr, packed_pos);
988
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
989
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
990
- var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
991
- wasm.__wbindgen_free(r0, r1 * 4, 4);
992
- return v1;
993
- } finally {
994
- wasm.__wbindgen_add_to_stack_pointer(16);
995
- }
843
+ }
844
+ if (Symbol.dispose)
845
+ SearchResult.prototype[Symbol.dispose] = SearchResult.prototype.free;
846
+ /**
847
+ * Translates `TERRAIN_*` constants.
848
+ * @enum {0 | 1 | 2}
849
+ */
850
+ Object.freeze({
851
+ Plain: 0, "0": "Plain",
852
+ Wall: 1, "1": "Wall",
853
+ Swamp: 2, "2": "Swamp",
854
+ });
855
+ /**
856
+ * Exports the global range calculation between two positions.
857
+ * @param {number} packed_pos_1
858
+ * @param {number} packed_pos_2
859
+ * @returns {number}
860
+ */
861
+ function get_range(packed_pos_1, packed_pos_2) {
862
+ const ret = wasm.get_range(packed_pos_1, packed_pos_2);
863
+ return ret >>> 0;
864
+ }
865
+ /**
866
+ * @param {number} room_name
867
+ * @param {number | null} [plain_cost]
868
+ * @param {number | null} [swamp_cost]
869
+ * @param {number | null} [wall_cost]
870
+ * @returns {ClockworkCostMatrix}
871
+ */
872
+ function get_terrain_cost_matrix(room_name, plain_cost, swamp_cost, wall_cost) {
873
+ const ret = wasm.get_terrain_cost_matrix(room_name, isLikeNone(plain_cost) ? 0xFFFFFF : plain_cost, isLikeNone(swamp_cost) ? 0xFFFFFF : swamp_cost, isLikeNone(wall_cost) ? 0xFFFFFF : wall_cost);
874
+ return ClockworkCostMatrix.__wrap(ret);
875
+ }
876
+ /**
877
+ * @param {Uint32Array} start_packed
878
+ * @param {Function} get_cost_matrix
879
+ * @param {number} max_rooms
880
+ * @param {number} max_ops
881
+ * @param {number} max_path_cost
882
+ * @param {Uint32Array | null} [any_of_destinations]
883
+ * @param {Uint32Array | null} [all_of_destinations]
884
+ * @returns {SearchResult}
885
+ */
886
+ function js_astar_multiroom_distance_map(start_packed, get_cost_matrix, max_rooms, max_ops, max_path_cost, any_of_destinations, all_of_destinations) {
887
+ try {
888
+ const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
889
+ const len0 = WASM_VECTOR_LEN;
890
+ var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
891
+ var len1 = WASM_VECTOR_LEN;
892
+ var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
893
+ var len2 = WASM_VECTOR_LEN;
894
+ const ret = wasm.js_astar_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_rooms, max_ops, max_path_cost, ptr1, len1, ptr2, len2);
895
+ return SearchResult.__wrap(ret);
996
896
  }
997
- /**
998
- * Sets the list of valid directions at a given position (JavaScript)
999
- * @param {number} packed_pos
1000
- * @param {any[]} directions
1001
- */
1002
- setDirections(packed_pos, directions) {
1003
- const ptr0 = passArrayJsValueToWasm0(directions, wasm.__wbindgen_malloc);
897
+ finally {
898
+ heap[stack_pointer++] = undefined;
899
+ }
900
+ }
901
+ /**
902
+ * WASM wrapper for the BFS multiroom distance map function.
903
+ *
904
+ * # Arguments
905
+ * * `start_packed` - Array of packed position integers representing start positions
906
+ * * `get_cost_matrix` - JavaScript function that returns cost matrices for rooms
907
+ * * `max_ops` - Maximum number of tiles to explore
908
+ * * `max_rooms` - Maximum number of rooms to explore
909
+ * * `max_room_distance` - Maximum Manhattan distance in rooms to explore
910
+ * * `max_path_cost` - Maximum distance in tiles to explore
911
+ * * `any_of_destinations` - Array of packed positions to trigger early exit when any are reached
912
+ * * `all_of_destinations` - Array of packed positions to trigger early exit when all are reached
913
+ *
914
+ * # Returns
915
+ * A `MultiroomDistanceMap` containing the distances from the start positions
916
+ * @param {Uint32Array} start_packed
917
+ * @param {Function} get_cost_matrix
918
+ * @param {number} max_ops
919
+ * @param {number} max_rooms
920
+ * @param {number} max_path_cost
921
+ * @param {Uint32Array | null} [any_of_destinations]
922
+ * @param {Uint32Array | null} [all_of_destinations]
923
+ * @returns {SearchResult}
924
+ */
925
+ function js_bfs_multiroom_distance_map(start_packed, get_cost_matrix, max_ops, max_rooms, max_path_cost, any_of_destinations, all_of_destinations) {
926
+ try {
927
+ const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
1004
928
  const len0 = WASM_VECTOR_LEN;
1005
- wasm.multiroomflowfield_setDirections(this.__wbg_ptr, packed_pos, ptr0, len0);
929
+ var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
930
+ var len1 = WASM_VECTOR_LEN;
931
+ var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
932
+ var len2 = WASM_VECTOR_LEN;
933
+ const ret = wasm.js_bfs_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_ops, max_rooms, max_path_cost, ptr1, len1, ptr2, len2);
934
+ return SearchResult.__wrap(ret);
1006
935
  }
1007
- /**
1008
- * Gets the flow field value at a given position
1009
- * @param {number} packed_pos
1010
- * @returns {number}
1011
- */
1012
- get(packed_pos) {
1013
- const ret = wasm.multiroomflowfield_get(this.__wbg_ptr, packed_pos);
1014
- return ret;
936
+ finally {
937
+ heap[stack_pointer++] = undefined;
1015
938
  }
1016
- /**
1017
- * Creates a new empty multiroom flow field (JavaScript constructor)
1018
- */
1019
- constructor() {
1020
- const ret = wasm.multiroomdistancemap_js_new();
1021
- this.__wbg_ptr = ret >>> 0;
1022
- MultiroomFlowFieldFinalization.register(this, this.__wbg_ptr, this);
1023
- return this;
939
+ }
940
+ /**
941
+ * @param {Uint32Array} start_packed
942
+ * @param {Function} get_cost_matrix
943
+ * @param {number} max_ops
944
+ * @param {number} max_rooms
945
+ * @param {number} max_path_cost
946
+ * @param {Uint32Array | null} [any_of_destinations]
947
+ * @param {Uint32Array | null} [all_of_destinations]
948
+ * @returns {SearchResult}
949
+ */
950
+ function js_dijkstra_multiroom_distance_map(start_packed, get_cost_matrix, max_ops, max_rooms, max_path_cost, any_of_destinations, all_of_destinations) {
951
+ try {
952
+ const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
953
+ const len0 = WASM_VECTOR_LEN;
954
+ var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
955
+ var len1 = WASM_VECTOR_LEN;
956
+ var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
957
+ var len2 = WASM_VECTOR_LEN;
958
+ const ret = wasm.js_dijkstra_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_ops, max_rooms, max_path_cost, ptr1, len1, ptr2, len2);
959
+ return SearchResult.__wrap(ret);
1024
960
  }
1025
- /**
1026
- * Sets the flow field value at a given position
1027
- * @param {number} packed_pos
1028
- * @param {number} value
1029
- */
1030
- set(packed_pos, value) {
1031
- wasm.multiroomflowfield_set(this.__wbg_ptr, packed_pos, value);
961
+ finally {
962
+ heap[stack_pointer++] = undefined;
963
+ }
964
+ }
965
+ /**
966
+ * @param {number} start
967
+ * @param {MultiroomDistanceMap} distance_map
968
+ * @param {DirectionOrder} direction_order
969
+ * @returns {Path}
970
+ */
971
+ function js_path_to_multiroom_distance_map_origin(start, distance_map, direction_order) {
972
+ try {
973
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
974
+ _assertClass(distance_map, MultiroomDistanceMap);
975
+ wasm.js_path_to_multiroom_distance_map_origin(retptr, start, distance_map.__wbg_ptr, direction_order);
976
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
977
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
978
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
979
+ if (r2) {
980
+ throw takeObject(r1);
981
+ }
982
+ return Path.__wrap(r0);
983
+ }
984
+ finally {
985
+ wasm.__wbindgen_add_to_stack_pointer(16);
1032
986
  }
1033
987
  }
1034
-
1035
- const MultiroomMonoFlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
1036
- ? { register: () => {}, unregister: () => {} }
1037
- : new FinalizationRegistry(ptr => wasm.__wbg_multiroommonoflowfield_free(ptr >>> 0, 1));
1038
988
  /**
1039
- * Maps monodirectional flow field values across multiple rooms, storing a MonoFlowField for each room
989
+ * @param {number} start
990
+ * @param {MultiroomFlowField} flow_field
991
+ * @returns {Path}
1040
992
  */
1041
- class MultiroomMonoFlowField {
1042
-
1043
- static __wrap(ptr) {
1044
- ptr = ptr >>> 0;
1045
- const obj = Object.create(MultiroomMonoFlowField.prototype);
1046
- obj.__wbg_ptr = ptr;
1047
- MultiroomMonoFlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
1048
- return obj;
1049
- }
1050
-
1051
- __destroy_into_raw() {
1052
- const ptr = this.__wbg_ptr;
1053
- this.__wbg_ptr = 0;
1054
- MultiroomMonoFlowFieldFinalization.unregister(this);
1055
- return ptr;
1056
- }
1057
-
1058
- free() {
1059
- const ptr = this.__destroy_into_raw();
1060
- wasm.__wbg_multiroommonoflowfield_free(ptr, 0);
1061
- }
1062
- /**
1063
- * Gets the MonoFlowField for a given room
1064
- * @param {number} room_name
1065
- * @returns {MonoFlowField | undefined}
1066
- */
1067
- getRoom(room_name) {
1068
- const ret = wasm.multiroommonoflowfield_getRoom(this.__wbg_ptr, room_name);
1069
- return ret === 0 ? undefined : MonoFlowField.__wrap(ret);
1070
- }
1071
- /**
1072
- * Gets the list of rooms in the flow field
1073
- * @returns {Uint16Array}
1074
- */
1075
- getRooms() {
1076
- try {
1077
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1078
- wasm.multiroommonoflowfield_getRooms(retptr, this.__wbg_ptr);
1079
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1080
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1081
- var v1 = getArrayU16FromWasm0(r0, r1).slice();
1082
- wasm.__wbindgen_free(r0, r1 * 2, 2);
1083
- return v1;
1084
- } finally {
1085
- wasm.__wbindgen_add_to_stack_pointer(16);
993
+ function js_path_to_multiroom_flow_field_origin(start, flow_field) {
994
+ try {
995
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
996
+ _assertClass(flow_field, MultiroomFlowField);
997
+ wasm.js_path_to_multiroom_flow_field_origin(retptr, start, flow_field.__wbg_ptr);
998
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
999
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1000
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1001
+ if (r2) {
1002
+ throw takeObject(r1);
1086
1003
  }
1004
+ return Path.__wrap(r0);
1087
1005
  }
1088
- /**
1089
- * Gets the direction at a given position
1090
- * @param {number} packed_pos
1091
- * @returns {Direction | undefined}
1092
- */
1093
- get(packed_pos) {
1094
- const ret = wasm.multiroommonoflowfield_get(this.__wbg_ptr, packed_pos);
1095
- return ret === 0 ? undefined : ret;
1006
+ finally {
1007
+ wasm.__wbindgen_add_to_stack_pointer(16);
1096
1008
  }
1097
- /**
1098
- * Creates a new empty multiroom monodirectional flow field (JavaScript constructor)
1099
- */
1100
- constructor() {
1101
- const ret = wasm.multiroommonoflowfield_js_new();
1102
- this.__wbg_ptr = ret >>> 0;
1103
- MultiroomMonoFlowFieldFinalization.register(this, this.__wbg_ptr, this);
1104
- return this;
1009
+ }
1010
+ /**
1011
+ * @param {number} start
1012
+ * @param {MultiroomMonoFlowField} flow_field
1013
+ * @returns {Path}
1014
+ */
1015
+ function js_path_to_multiroom_mono_flow_field_origin(start, flow_field) {
1016
+ try {
1017
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1018
+ _assertClass(flow_field, MultiroomMonoFlowField);
1019
+ wasm.js_path_to_multiroom_mono_flow_field_origin(retptr, start, flow_field.__wbg_ptr);
1020
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1021
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1022
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1023
+ if (r2) {
1024
+ throw takeObject(r1);
1025
+ }
1026
+ return Path.__wrap(r0);
1105
1027
  }
1106
- /**
1107
- * Sets the direction at a given position
1108
- * @param {number} packed_pos
1109
- * @param {Direction | null} [direction]
1110
- */
1111
- set(packed_pos, direction) {
1112
- wasm.multiroommonoflowfield_set(this.__wbg_ptr, packed_pos, isLikeNone(direction) ? 0 : direction);
1028
+ finally {
1029
+ wasm.__wbindgen_add_to_stack_pointer(16);
1113
1030
  }
1114
1031
  }
1115
-
1116
- const PathFinalization = (typeof FinalizationRegistry === 'undefined')
1117
- ? { register: () => {}, unregister: () => {} }
1118
- : new FinalizationRegistry(ptr => wasm.__wbg_path_free(ptr >>> 0, 1));
1119
1032
  /**
1120
- * A list of positions representing a path.
1033
+ * Creates a flow field for the given distance map.
1034
+ * @param {MultiroomDistanceMap} distance_map
1035
+ * @param {DirectionOrder} direction_order
1036
+ * @returns {MultiroomFlowField}
1121
1037
  */
1122
- class Path {
1123
-
1124
- static __wrap(ptr) {
1125
- ptr = ptr >>> 0;
1126
- const obj = Object.create(Path.prototype);
1127
- obj.__wbg_ptr = ptr;
1128
- PathFinalization.register(obj, obj.__wbg_ptr, obj);
1129
- return obj;
1038
+ function multiroomFlowField(distance_map, direction_order) {
1039
+ _assertClass(distance_map, MultiroomDistanceMap);
1040
+ const ret = wasm.multiroomFlowField(distance_map.__wbg_ptr, direction_order);
1041
+ return MultiroomFlowField.__wrap(ret);
1042
+ }
1043
+ /**
1044
+ * Creates a monodirectional flow field for the given distance map.
1045
+ * @param {MultiroomDistanceMap} distance_map
1046
+ * @param {DirectionOrder} direction_order
1047
+ * @returns {MultiroomMonoFlowField}
1048
+ */
1049
+ function multiroomMonoFlowField(distance_map, direction_order) {
1050
+ _assertClass(distance_map, MultiroomDistanceMap);
1051
+ const ret = wasm.multiroomMonoFlowField(distance_map.__wbg_ptr, direction_order);
1052
+ return MultiroomMonoFlowField.__wrap(ret);
1053
+ }
1054
+ /**
1055
+ * @returns {string}
1056
+ */
1057
+ function version() {
1058
+ let deferred1_0;
1059
+ let deferred1_1;
1060
+ try {
1061
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1062
+ wasm.version(retptr);
1063
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1064
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1065
+ deferred1_0 = r0;
1066
+ deferred1_1 = r1;
1067
+ return getStringFromWasm0(r0, r1);
1130
1068
  }
1131
-
1132
- __destroy_into_raw() {
1133
- const ptr = this.__wbg_ptr;
1134
- this.__wbg_ptr = 0;
1135
- PathFinalization.unregister(this);
1136
- return ptr;
1069
+ finally {
1070
+ wasm.__wbindgen_add_to_stack_pointer(16);
1071
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1137
1072
  }
1138
-
1139
- free() {
1140
- const ptr = this.__destroy_into_raw();
1141
- wasm.__wbg_path_free(ptr, 0);
1073
+ }
1074
+ function __wbg_get_imports() {
1075
+ const import0 = {
1076
+ __proto__: null,
1077
+ __wbg___wbindgen_is_null_2042690d351e14f0: function (arg0) {
1078
+ const ret = getObject(arg0) === null;
1079
+ return ret;
1080
+ },
1081
+ __wbg___wbindgen_is_undefined_35bb9f4c7fd651d5: function (arg0) {
1082
+ const ret = getObject(arg0) === undefined;
1083
+ return ret;
1084
+ },
1085
+ __wbg___wbindgen_number_get_f73a1244370fcc2c: function (arg0, arg1) {
1086
+ const obj = getObject(arg1);
1087
+ const ret = typeof (obj) === 'number' ? obj : undefined;
1088
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1089
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1090
+ },
1091
+ __wbg___wbindgen_rethrow_2b7cc655458909c2: function (arg0) {
1092
+ throw takeObject(arg0);
1093
+ },
1094
+ __wbg___wbindgen_throw_9c31b086c2b26051: function (arg0, arg1) {
1095
+ throw new Error(getStringFromWasm0(arg0, arg1));
1096
+ },
1097
+ __wbg_call_dfde26266607c996: function () {
1098
+ return handleError(function (arg0, arg1, arg2) {
1099
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
1100
+ return addHeapObject(ret);
1101
+ }, arguments);
1102
+ },
1103
+ __wbg_ceil_2f02237b685bdce4: function (arg0) {
1104
+ const ret = Math.ceil(arg0);
1105
+ return ret;
1106
+ },
1107
+ __wbg_clockworkcostmatrix_get_pointer_79c3c65971038fea: function (arg0) {
1108
+ const ret = clockworkcostmatrix_get_pointer(takeObject(arg0));
1109
+ return ret;
1110
+ },
1111
+ __wbg_create_55d0f7a358253d86: function (arg0) {
1112
+ const ret = Object.create(getObject(arg0));
1113
+ return addHeapObject(ret);
1114
+ },
1115
+ __wbg_error_a6fa202b58aa1cd3: function (arg0, arg1) {
1116
+ let deferred0_0;
1117
+ let deferred0_1;
1118
+ try {
1119
+ deferred0_0 = arg0;
1120
+ deferred0_1 = arg1;
1121
+ console.error(getStringFromWasm0(arg0, arg1));
1122
+ }
1123
+ finally {
1124
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
1125
+ }
1126
+ },
1127
+ __wbg_getRawBuffer_2165a0506d77f9ca: function (arg0, arg1) {
1128
+ const ret = getObject(arg0).getRawBuffer(getObject(arg1));
1129
+ return addHeapObject(ret);
1130
+ },
1131
+ __wbg_getRoomTerrain_ff542df2ea2015b1: function () {
1132
+ return handleError(function (arg0) {
1133
+ const ret = Game.map.getRoomTerrain(getObject(arg0));
1134
+ return addHeapObject(ret);
1135
+ }, arguments);
1136
+ },
1137
+ __wbg_get_8f8e5734959cd5fc: function (arg0, arg1, arg2) {
1138
+ const ret = getObject(arg0).get(arg1, arg2);
1139
+ return ret;
1140
+ },
1141
+ __wbg_get_unchecked_1dfe6d05ad91d9b7: function (arg0, arg1) {
1142
+ const ret = getObject(arg0)[arg1 >>> 0];
1143
+ return addHeapObject(ret);
1144
+ },
1145
+ __wbg_get_value_3083233b2ad9f36e: function (arg0, arg1) {
1146
+ const ret = getObject(arg0)[getObject(arg1)];
1147
+ return addHeapObject(ret);
1148
+ },
1149
+ __wbg_length_2591a0f4f659a55c: function (arg0) {
1150
+ const ret = getObject(arg0).length;
1151
+ return ret;
1152
+ },
1153
+ __wbg_log_c30a21014b80980e: function (arg0, arg1) {
1154
+ console.log(getStringFromWasm0(arg0, arg1));
1155
+ },
1156
+ __wbg_lookFor_0ddc4d9f22e9bfe5: function () {
1157
+ return handleError(function (arg0, arg1) {
1158
+ const ret = getObject(arg0).lookFor(__wbindgen_enum_Look[arg1]);
1159
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1160
+ }, arguments);
1161
+ },
1162
+ __wbg_new_1f236d63ba0c4784: function (arg0, arg1) {
1163
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
1164
+ return addHeapObject(ret);
1165
+ },
1166
+ __wbg_new_227d7c05414eb861: function () {
1167
+ const ret = new Error();
1168
+ return addHeapObject(ret);
1169
+ },
1170
+ __wbg_new_internal_dc21004de3373c5f: function () {
1171
+ return handleError(function (arg0) {
1172
+ const ret = new Room.Terrain(getObject(arg0));
1173
+ return addHeapObject(ret);
1174
+ }, arguments);
1175
+ },
1176
+ __wbg_rooms_c5dbffde521939da: function () {
1177
+ const ret = Game.rooms;
1178
+ return addHeapObject(ret);
1179
+ },
1180
+ __wbg_set_packed_cc769b1ab2aa7e8e: function (arg0, arg1) {
1181
+ getObject(arg0).__packedPos = arg1 >>> 0;
1182
+ },
1183
+ __wbg_stack_3b0d974bbf31e44f: function (arg0, arg1) {
1184
+ const ret = getObject(arg1).stack;
1185
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1186
+ const len1 = WASM_VECTOR_LEN;
1187
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1188
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1189
+ },
1190
+ __wbg_static_accessor_ROOM_POSITION_PROTOTYPE_9def1bb4de86c8f7: function () {
1191
+ const ret = RoomPosition.prototype;
1192
+ return addHeapObject(ret);
1193
+ },
1194
+ __wbg_structure_type_dbc211ed19dd8423: function (arg0) {
1195
+ const ret = getObject(arg0).structureType;
1196
+ return (__wbindgen_enum_StructureType.indexOf(ret) + 1 || 22) - 1;
1197
+ },
1198
+ __wbindgen_cast_0000000000000001: function (arg0) {
1199
+ // Cast intrinsic for `F64 -> Externref`.
1200
+ const ret = arg0;
1201
+ return addHeapObject(ret);
1202
+ },
1203
+ __wbindgen_cast_0000000000000002: function (arg0, arg1) {
1204
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
1205
+ const ret = getArrayU8FromWasm0(arg0, arg1);
1206
+ return addHeapObject(ret);
1207
+ },
1208
+ __wbindgen_cast_0000000000000003: function (arg0, arg1) {
1209
+ // Cast intrinsic for `Ref(String) -> Externref`.
1210
+ const ret = getStringFromWasm0(arg0, arg1);
1211
+ return addHeapObject(ret);
1212
+ },
1213
+ __wbindgen_object_drop_ref: function (arg0) {
1214
+ takeObject(arg0);
1215
+ },
1216
+ };
1217
+ return {
1218
+ __proto__: null,
1219
+ "./screeps_clockwork_bg.js": import0,
1220
+ };
1221
+ }
1222
+ const __wbindgen_enum_Look = ["creep", "energy", "resource", "source", "mineral", "structure", "flag", "constructionSite", "nuke", "terrain", "tombstone", "powerCreep", "deposit", "ruin", "scoreContainer", "scoreCollector", "symbolContainer", "symbolDecoder", "reactor"];
1223
+ const __wbindgen_enum_StructureType = ["spawn", "extension", "road", "constructedWall", "rampart", "keeperLair", "portal", "controller", "link", "storage", "tower", "observer", "powerBank", "powerSpawn", "extractor", "lab", "terminal", "container", "nuker", "factory", "invaderCore"];
1224
+ const ClockworkCostMatrixFinalization = (typeof FinalizationRegistry === 'undefined')
1225
+ ? { register: () => { }, unregister: () => { } }
1226
+ : new FinalizationRegistry(ptr => wasm.__wbg_clockworkcostmatrix_free(ptr, 1));
1227
+ const DistanceMapFinalization = (typeof FinalizationRegistry === 'undefined')
1228
+ ? { register: () => { }, unregister: () => { } }
1229
+ : new FinalizationRegistry(ptr => wasm.__wbg_distancemap_free(ptr, 1));
1230
+ const FlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
1231
+ ? { register: () => { }, unregister: () => { } }
1232
+ : new FinalizationRegistry(ptr => wasm.__wbg_flowfield_free(ptr, 1));
1233
+ const MonoFlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
1234
+ ? { register: () => { }, unregister: () => { } }
1235
+ : new FinalizationRegistry(ptr => wasm.__wbg_monoflowfield_free(ptr, 1));
1236
+ const MultiroomDistanceMapFinalization = (typeof FinalizationRegistry === 'undefined')
1237
+ ? { register: () => { }, unregister: () => { } }
1238
+ : new FinalizationRegistry(ptr => wasm.__wbg_multiroomdistancemap_free(ptr, 1));
1239
+ const MultiroomFlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
1240
+ ? { register: () => { }, unregister: () => { } }
1241
+ : new FinalizationRegistry(ptr => wasm.__wbg_multiroomflowfield_free(ptr, 1));
1242
+ const MultiroomMonoFlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
1243
+ ? { register: () => { }, unregister: () => { } }
1244
+ : new FinalizationRegistry(ptr => wasm.__wbg_multiroommonoflowfield_free(ptr, 1));
1245
+ const PathFinalization = (typeof FinalizationRegistry === 'undefined')
1246
+ ? { register: () => { }, unregister: () => { } }
1247
+ : new FinalizationRegistry(ptr => wasm.__wbg_path_free(ptr, 1));
1248
+ (typeof FinalizationRegistry === 'undefined')
1249
+ ? { register: () => { }, unregister: () => { } }
1250
+ : new FinalizationRegistry(ptr => wasm.__wbg_pathfatigue_free(ptr, 1));
1251
+ (typeof FinalizationRegistry === 'undefined')
1252
+ ? { register: () => { }, unregister: () => { } }
1253
+ : new FinalizationRegistry(ptr => wasm.__wbg_searchgoal_free(ptr, 1));
1254
+ const SearchResultFinalization = (typeof FinalizationRegistry === 'undefined')
1255
+ ? { register: () => { }, unregister: () => { } }
1256
+ : new FinalizationRegistry(ptr => wasm.__wbg_searchresult_free(ptr, 1));
1257
+ function addHeapObject(obj) {
1258
+ if (heap_next === heap.length)
1259
+ heap.push(heap.length + 1);
1260
+ const idx = heap_next;
1261
+ heap_next = heap[idx];
1262
+ heap[idx] = obj;
1263
+ return idx;
1264
+ }
1265
+ function _assertClass(instance, klass) {
1266
+ if (!(instance instanceof klass)) {
1267
+ throw new Error(`expected instance of ${klass.name}`);
1142
1268
  }
1143
- /**
1144
- * @returns {Uint32Array}
1145
- */
1146
- to_array() {
1147
- try {
1148
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1149
- wasm.path_to_array(retptr, this.__wbg_ptr);
1150
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1151
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1152
- var v1 = getArrayU32FromWasm0(r0, r1).slice();
1153
- wasm.__wbindgen_free(r0, r1 * 4, 4);
1154
- return v1;
1155
- } finally {
1156
- wasm.__wbindgen_add_to_stack_pointer(16);
1157
- }
1269
+ }
1270
+ function addBorrowedObject(obj) {
1271
+ if (stack_pointer == 1)
1272
+ throw new Error('out of js stack');
1273
+ heap[--stack_pointer] = obj;
1274
+ return stack_pointer;
1275
+ }
1276
+ function dropObject(idx) {
1277
+ if (idx < 1028)
1278
+ return;
1279
+ heap[idx] = heap_next;
1280
+ heap_next = idx;
1281
+ }
1282
+ function getArrayJsValueFromWasm0(ptr, len) {
1283
+ ptr = ptr >>> 0;
1284
+ const mem = getDataViewMemory0();
1285
+ const result = [];
1286
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
1287
+ result.push(takeObject(mem.getUint32(i, true)));
1158
1288
  }
1159
- /**
1160
- * Given a position, find the index of the next adjacent position
1161
- * in the path. If the position is not in the path, the target is
1162
- * the next adjacent position closest to the end of the path. If
1163
- * the position is neither on nor adjacent to the path, return None.
1164
- * @param {number} packed_position
1165
- * @returns {number | undefined}
1166
- */
1167
- find_next_index(packed_position) {
1168
- const ret = wasm.path_find_next_index(this.__wbg_ptr, packed_position);
1169
- return ret === 0x100000001 ? undefined : ret;
1289
+ return result;
1290
+ }
1291
+ function getArrayU16FromWasm0(ptr, len) {
1292
+ ptr = ptr >>> 0;
1293
+ return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
1294
+ }
1295
+ function getArrayU32FromWasm0(ptr, len) {
1296
+ ptr = ptr >>> 0;
1297
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
1298
+ }
1299
+ function getArrayU8FromWasm0(ptr, len) {
1300
+ ptr = ptr >>> 0;
1301
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1302
+ }
1303
+ let cachedDataViewMemory0 = null;
1304
+ function getDataViewMemory0() {
1305
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
1306
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
1170
1307
  }
1171
- /**
1172
- * @returns {Uint32Array}
1173
- */
1174
- to_array_reversed() {
1175
- try {
1176
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1177
- wasm.path_to_array_reversed(retptr, this.__wbg_ptr);
1178
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1179
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1180
- var v1 = getArrayU32FromWasm0(r0, r1).slice();
1181
- wasm.__wbindgen_free(r0, r1 * 4, 4);
1182
- return v1;
1183
- } finally {
1184
- wasm.__wbindgen_add_to_stack_pointer(16);
1185
- }
1308
+ return cachedDataViewMemory0;
1309
+ }
1310
+ function getStringFromWasm0(ptr, len) {
1311
+ return decodeText(ptr >>> 0, len);
1312
+ }
1313
+ let cachedUint16ArrayMemory0 = null;
1314
+ function getUint16ArrayMemory0() {
1315
+ if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
1316
+ cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
1317
+ }
1318
+ return cachedUint16ArrayMemory0;
1319
+ }
1320
+ let cachedUint32ArrayMemory0 = null;
1321
+ function getUint32ArrayMemory0() {
1322
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
1323
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
1186
1324
  }
1187
- /**
1188
- * @param {number} packed_position
1189
- */
1190
- add(packed_position) {
1191
- wasm.path_add(this.__wbg_ptr, packed_position);
1325
+ return cachedUint32ArrayMemory0;
1326
+ }
1327
+ let cachedUint8ArrayMemory0 = null;
1328
+ function getUint8ArrayMemory0() {
1329
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1330
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1192
1331
  }
1193
- /**
1194
- * @param {number} index
1195
- * @returns {number | undefined}
1196
- */
1197
- get(index) {
1198
- const ret = wasm.path_get(this.__wbg_ptr, index);
1199
- return ret === 0x100000001 ? undefined : ret;
1332
+ return cachedUint8ArrayMemory0;
1333
+ }
1334
+ function getObject(idx) { return heap[idx]; }
1335
+ function handleError(f, args) {
1336
+ try {
1337
+ return f.apply(this, args);
1200
1338
  }
1201
- /**
1202
- * @returns {number}
1203
- */
1204
- len() {
1205
- const ret = wasm.path_len(this.__wbg_ptr);
1206
- return ret >>> 0;
1339
+ catch (e) {
1340
+ wasm.__wbindgen_exn_store(addHeapObject(e));
1207
1341
  }
1208
1342
  }
1209
-
1210
- (typeof FinalizationRegistry === 'undefined')
1211
- ? { register: () => {}, unregister: () => {} }
1212
- : new FinalizationRegistry(ptr => wasm.__wbg_pathfatigue_free(ptr >>> 0, 1));
1213
-
1214
- (typeof FinalizationRegistry === 'undefined')
1215
- ? { register: () => {}, unregister: () => {} }
1216
- : new FinalizationRegistry(ptr => wasm.__wbg_searchgoal_free(ptr >>> 0, 1));
1217
-
1218
- const SearchResultFinalization = (typeof FinalizationRegistry === 'undefined')
1219
- ? { register: () => {}, unregister: () => {} }
1220
- : new FinalizationRegistry(ptr => wasm.__wbg_searchresult_free(ptr >>> 0, 1));
1221
- /**
1222
- * A distance map search returns both the distance map (filled out
1223
- * with all tiles explored) and the targets found. These aren't necessarily
1224
- * the same positions specified as targets - if the target range is 5, then
1225
- * this is the first position in range 5 of the target. If multiple targets
1226
- * are specified, and you care about matching the found target with one of
1227
- * the original targets, you can iterate through your list and figure out the
1228
- * ones that are in range of the found target(s).
1229
- */
1230
- class SearchResult {
1231
-
1232
- static __wrap(ptr) {
1233
- ptr = ptr >>> 0;
1234
- const obj = Object.create(SearchResult.prototype);
1235
- obj.__wbg_ptr = ptr;
1236
- SearchResultFinalization.register(obj, obj.__wbg_ptr, obj);
1237
- return obj;
1343
+ let heap = new Array(1024).fill(undefined);
1344
+ heap.push(undefined, null, true, false);
1345
+ let heap_next = heap.length;
1346
+ function isLikeNone(x) {
1347
+ return x === undefined || x === null;
1348
+ }
1349
+ function passArray32ToWasm0(arg, malloc) {
1350
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
1351
+ getUint32ArrayMemory0().set(arg, ptr / 4);
1352
+ WASM_VECTOR_LEN = arg.length;
1353
+ return ptr;
1354
+ }
1355
+ function passArrayJsValueToWasm0(array, malloc) {
1356
+ const ptr = malloc(array.length * 4, 4) >>> 0;
1357
+ const mem = getDataViewMemory0();
1358
+ for (let i = 0; i < array.length; i++) {
1359
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
1238
1360
  }
1239
-
1240
- __destroy_into_raw() {
1241
- const ptr = this.__wbg_ptr;
1242
- this.__wbg_ptr = 0;
1243
- SearchResultFinalization.unregister(this);
1361
+ WASM_VECTOR_LEN = array.length;
1362
+ return ptr;
1363
+ }
1364
+ function passStringToWasm0(arg, malloc, realloc) {
1365
+ if (realloc === undefined) {
1366
+ const buf = cachedTextEncoder.encode(arg);
1367
+ const ptr = malloc(buf.length, 1) >>> 0;
1368
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
1369
+ WASM_VECTOR_LEN = buf.length;
1244
1370
  return ptr;
1245
1371
  }
1246
-
1247
- free() {
1248
- const ptr = this.__destroy_into_raw();
1249
- wasm.__wbg_searchresult_free(ptr, 0);
1250
- }
1251
- /**
1252
- * @returns {MultiroomDistanceMap}
1253
- */
1254
- get distance_map() {
1255
- const ret = wasm.searchresult_distance_map(this.__wbg_ptr);
1256
- return MultiroomDistanceMap.__wrap(ret);
1372
+ let len = arg.length;
1373
+ let ptr = malloc(len, 1) >>> 0;
1374
+ const mem = getUint8ArrayMemory0();
1375
+ let offset = 0;
1376
+ for (; offset < len; offset++) {
1377
+ const code = arg.charCodeAt(offset);
1378
+ if (code > 0x7F)
1379
+ break;
1380
+ mem[ptr + offset] = code;
1257
1381
  }
1258
- /**
1259
- * @returns {Uint32Array}
1260
- */
1261
- get found_targets() {
1262
- try {
1263
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1264
- wasm.searchresult_found_targets(retptr, this.__wbg_ptr);
1265
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1266
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1267
- var v1 = getArrayU32FromWasm0(r0, r1).slice();
1268
- wasm.__wbindgen_free(r0, r1 * 4, 4);
1269
- return v1;
1270
- } finally {
1271
- wasm.__wbindgen_add_to_stack_pointer(16);
1382
+ if (offset !== len) {
1383
+ if (offset !== 0) {
1384
+ arg = arg.slice(offset);
1272
1385
  }
1386
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1387
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1388
+ const ret = cachedTextEncoder.encodeInto(arg, view);
1389
+ offset += ret.written;
1390
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
1273
1391
  }
1274
- /**
1275
- * @returns {number}
1276
- */
1277
- get ops() {
1278
- const ret = wasm.searchresult_ops(this.__wbg_ptr);
1279
- return ret >>> 0;
1392
+ WASM_VECTOR_LEN = offset;
1393
+ return ptr;
1394
+ }
1395
+ let stack_pointer = 1024;
1396
+ function takeObject(idx) {
1397
+ const ret = getObject(idx);
1398
+ dropObject(idx);
1399
+ return ret;
1400
+ }
1401
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1402
+ cachedTextDecoder.decode();
1403
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
1404
+ let numBytesDecoded = 0;
1405
+ function decodeText(ptr, len) {
1406
+ numBytesDecoded += len;
1407
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1408
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1409
+ cachedTextDecoder.decode();
1410
+ numBytesDecoded = len;
1280
1411
  }
1412
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1281
1413
  }
1282
-
1283
- function __wbg_get_imports() {
1284
- const imports = {};
1285
- imports.wbg = {};
1286
- imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
1287
- const ret = getObject(arg0).buffer;
1288
- return addHeapObject(ret);
1289
- };
1290
- imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
1291
- const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
1292
- return addHeapObject(ret);
1293
- }, arguments) };
1294
- imports.wbg.__wbg_ceil_2a411b0e70cc0baf = function(arg0) {
1295
- const ret = Math.ceil(arg0);
1296
- return ret;
1297
- };
1298
- imports.wbg.__wbg_clockworkcostmatrixgetpointer_ee2b0a46684eb38c = function(arg0) {
1299
- const ret = clockworkcostmatrix_get_pointer(takeObject(arg0));
1300
- return ret;
1301
- };
1302
- imports.wbg.__wbg_create_cfe43ccc88c64e0a = function(arg0) {
1303
- const ret = Object.create(getObject(arg0));
1304
- return addHeapObject(ret);
1305
- };
1306
- imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
1307
- let deferred0_0;
1308
- let deferred0_1;
1309
- try {
1310
- deferred0_0 = arg0;
1311
- deferred0_1 = arg1;
1312
- console.error(getStringFromWasm0(arg0, arg1));
1313
- } finally {
1314
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
1315
- }
1316
- };
1317
- imports.wbg.__wbg_getRawBuffer_063ad218fd3b8817 = function(arg0, arg1) {
1318
- const ret = getObject(arg0).getRawBuffer(getObject(arg1));
1319
- return addHeapObject(ret);
1320
- };
1321
- imports.wbg.__wbg_getRoomTerrain_82fcc54e35a8985e = function() { return handleError(function (arg0) {
1322
- const ret = Game.map.getRoomTerrain(getObject(arg0));
1323
- return addHeapObject(ret);
1324
- }, arguments) };
1325
- imports.wbg.__wbg_get_1f5a4efd15e39f01 = function(arg0, arg1, arg2) {
1326
- const ret = getObject(arg0).get(arg1, arg2);
1327
- return ret;
1328
- };
1329
- imports.wbg.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
1330
- const ret = getObject(arg0)[arg1 >>> 0];
1331
- return addHeapObject(ret);
1332
- };
1333
- imports.wbg.__wbg_getvalue_a18eaf2c77e125e4 = function(arg0, arg1) {
1334
- const ret = getObject(arg0)[getObject(arg1)];
1335
- return addHeapObject(ret);
1336
- };
1337
- imports.wbg.__wbg_length_e2d2a49132c1b256 = function(arg0) {
1338
- const ret = getObject(arg0).length;
1339
- return ret;
1340
- };
1341
- imports.wbg.__wbg_log_4a86514c61094407 = function(arg0, arg1) {
1342
- console.log(getStringFromWasm0(arg0, arg1));
1343
- };
1344
- imports.wbg.__wbg_lookFor_04c5885fea38e9b2 = function() { return handleError(function (arg0, arg1) {
1345
- const ret = getObject(arg0).lookFor(__wbindgen_enum_Look[arg1]);
1346
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
1347
- }, arguments) };
1348
- imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
1349
- const ret = new Error();
1350
- return addHeapObject(ret);
1351
- };
1352
- imports.wbg.__wbg_newinternal_306f5ebf22959477 = function() { return handleError(function (arg0) {
1353
- const ret = new Room.Terrain(getObject(arg0));
1354
- return addHeapObject(ret);
1355
- }, arguments) };
1356
- imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
1357
- const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
1358
- return addHeapObject(ret);
1359
- };
1360
- imports.wbg.__wbg_rooms_c7983d4650f28959 = function() {
1361
- const ret = Game.rooms;
1362
- return addHeapObject(ret);
1363
- };
1364
- imports.wbg.__wbg_setpacked_50526296a5796941 = function(arg0, arg1) {
1365
- getObject(arg0).__packedPos = arg1 >>> 0;
1366
- };
1367
- imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
1368
- const ret = getObject(arg1).stack;
1369
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1370
- const len1 = WASM_VECTOR_LEN;
1371
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1372
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1373
- };
1374
- imports.wbg.__wbg_static_accessor_ROOM_POSITION_PROTOTYPE_359d8a1531b99b4c = function() {
1375
- const ret = RoomPosition.prototype;
1376
- return addHeapObject(ret);
1377
- };
1378
- imports.wbg.__wbg_structuretype_d5991613c372a27e = function(arg0) {
1379
- const ret = getObject(arg0).structureType;
1380
- return (__wbindgen_enum_StructureType.indexOf(ret) + 1 || 22) - 1;
1381
- };
1382
- imports.wbg.__wbindgen_is_null = function(arg0) {
1383
- const ret = getObject(arg0) === null;
1384
- return ret;
1385
- };
1386
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
1387
- const ret = getObject(arg0) === undefined;
1388
- return ret;
1389
- };
1390
- imports.wbg.__wbindgen_memory = function() {
1391
- const ret = wasm.memory;
1392
- return addHeapObject(ret);
1393
- };
1394
- imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
1395
- const obj = getObject(arg1);
1396
- const ret = typeof(obj) === 'number' ? obj : undefined;
1397
- getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1398
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1399
- };
1400
- imports.wbg.__wbindgen_number_new = function(arg0) {
1401
- const ret = arg0;
1402
- return addHeapObject(ret);
1403
- };
1404
- imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
1405
- takeObject(arg0);
1406
- };
1407
- imports.wbg.__wbindgen_rethrow = function(arg0) {
1408
- throw takeObject(arg0);
1409
- };
1410
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
1411
- const ret = getStringFromWasm0(arg0, arg1);
1412
- return addHeapObject(ret);
1413
- };
1414
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
1415
- throw new Error(getStringFromWasm0(arg0, arg1));
1416
- };
1417
- imports.wbg.__wbindgen_try_into_number = function(arg0) {
1418
- let result;
1419
- try { result = +getObject(arg0); } catch (e) { result = e; }
1420
- const ret = result;
1421
- return addHeapObject(ret);
1414
+ const cachedTextEncoder = new TextEncoder();
1415
+ if (!('encodeInto' in cachedTextEncoder)) {
1416
+ cachedTextEncoder.encodeInto = function (arg, view) {
1417
+ const buf = cachedTextEncoder.encode(arg);
1418
+ view.set(buf);
1419
+ return {
1420
+ read: arg.length,
1421
+ written: buf.length
1422
+ };
1422
1423
  };
1423
-
1424
- return imports;
1425
1424
  }
1426
-
1425
+ let WASM_VECTOR_LEN = 0;
1426
+ let wasm;
1427
1427
  function __wbg_finalize_init(instance, module) {
1428
1428
  wasm = instance.exports;
1429
1429
  cachedDataViewMemory0 = null;
1430
1430
  cachedUint16ArrayMemory0 = null;
1431
1431
  cachedUint32ArrayMemory0 = null;
1432
1432
  cachedUint8ArrayMemory0 = null;
1433
-
1434
-
1435
-
1436
1433
  return wasm;
1437
1434
  }
1438
-
1439
1435
  function initSync(module) {
1440
- if (wasm !== undefined) return wasm;
1441
-
1442
-
1443
- if (typeof module !== 'undefined') {
1436
+ if (wasm !== undefined)
1437
+ return wasm;
1438
+ if (module !== undefined) {
1444
1439
  if (Object.getPrototypeOf(module) === Object.prototype) {
1445
- ({module} = module);
1446
- } else {
1440
+ ({ module } = module);
1441
+ }
1442
+ else {
1447
1443
  console.warn('using deprecated parameters for `initSync()`; pass a single object instead');
1448
1444
  }
1449
1445
  }
1450
-
1451
1446
  const imports = __wbg_get_imports();
1452
-
1453
1447
  if (!(module instanceof WebAssembly.Module)) {
1454
1448
  module = new WebAssembly.Module(module);
1455
1449
  }
1456
-
1457
1450
  const instance = new WebAssembly.Instance(module, imports);
1458
-
1459
1451
  return __wbg_finalize_init(instance);
1460
1452
  }
1461
1453
 
1462
- const cache = new Set();
1463
- let cacheTick = 0;
1464
- /**
1465
- * Mark an item as ephemeral. This means that the item will be freed after the
1466
- * current tick.
1467
- *
1468
- * If you don't use this to clean up your data, you'll need to call `free()`
1469
- * yourself.
1470
- *
1471
- * @param item - The item to be cleaned up.
1472
- * @returns The item.
1473
- */
1474
- function ephemeral(item) {
1475
- if (cacheTick !== Game.time) {
1476
- for (const item of cache) {
1477
- try {
1478
- item.free();
1479
- }
1480
- catch (_a) {
1481
- // may have already been cleaned up
1482
- }
1483
- }
1484
- cache.clear();
1485
- cacheTick = Game.time;
1486
- }
1487
- cache.add(item);
1488
- return item;
1489
- }
1490
- /**
1491
- * Persist an ephemeral item. This means that the item will not be freed after
1492
- * the current tick.
1493
- *
1494
- * @param item - The item to be persisted.
1495
- * @returns The item.
1496
- */
1497
- function persist(item) {
1498
- cache.delete(item);
1499
- return item;
1500
- }
1501
-
1502
1454
  const MAX_USIZE = 0xffffffff;
1503
1455
 
1504
1456
  function fromPacked(packedPos) {
@@ -1540,6 +1492,33 @@ function packRoomName(room) {
1540
1492
  return (x << 8) | y;
1541
1493
  }
1542
1494
 
1495
+ /**
1496
+ * A distance map for a single room.
1497
+ */
1498
+ class ClockworkDistanceMap {
1499
+ constructor(_map) {
1500
+ this._map = _map;
1501
+ }
1502
+ /**
1503
+ * Gets the distance value at a given position.
1504
+ */
1505
+ get(x, y) {
1506
+ return this._map.get(x, y);
1507
+ }
1508
+ /**
1509
+ * Sets the distance value at a given position.
1510
+ */
1511
+ set(x, y, value) {
1512
+ this._map.set(x, y, value);
1513
+ }
1514
+ /**
1515
+ * Converts the distance map into a flat array of distances.
1516
+ */
1517
+ toArray() {
1518
+ return this._map.toArray();
1519
+ }
1520
+ }
1521
+
1543
1522
  /**
1544
1523
  * A flow field for a single room that stores multiple directions per tile.
1545
1524
  */
@@ -1577,17 +1556,11 @@ class ClockworkFlowField {
1577
1556
  addDirection(x, y, direction) {
1578
1557
  this._flowField.addDirection(x, y, direction);
1579
1558
  }
1580
- /**
1581
- * Free the memory allocated for this flow field.
1582
- */
1583
- free() {
1584
- this._flowField.free();
1585
- }
1586
1559
  }
1587
1560
 
1588
1561
  /**
1589
1562
  * A path from a start position to an end position. Typically returned by a
1590
- * function like `pathToFlowFieldOrigin` rather than created directly.
1563
+ * function like `ClockworkMultiroomFlowField.pathToOrigin` rather than created directly.
1591
1564
  */
1592
1565
  class ClockworkPath {
1593
1566
  constructor(path) {
@@ -1599,7 +1572,7 @@ class ClockworkPath {
1599
1572
  * @example
1600
1573
  * ```typescript
1601
1574
  * for (const pos of path) {
1602
- * console.log(pos);
1575
+ * console.logUnsafe(pos);
1603
1576
  * }
1604
1577
  * ```
1605
1578
  */
@@ -1623,7 +1596,7 @@ class ClockworkPath {
1623
1596
  * @example
1624
1597
  * ```typescript
1625
1598
  * for (const pos of path.reversed()) {
1626
- * console.log(pos);
1599
+ * console.logUnsafe(pos);
1627
1600
  * }
1628
1601
  * ```
1629
1602
  */
@@ -1682,12 +1655,6 @@ class ClockworkPath {
1682
1655
  }
1683
1656
  return result;
1684
1657
  }
1685
- /**
1686
- * Free the memory allocated for this path.
1687
- */
1688
- free() {
1689
- this.path.free();
1690
- }
1691
1658
  }
1692
1659
 
1693
1660
  /**
@@ -1750,12 +1717,6 @@ class ClockworkMultiroomFlowField {
1750
1717
  pathToOrigin(start) {
1751
1718
  return new ClockworkPath(js_path_to_multiroom_flow_field_origin(start.__packedPos, this._flowField));
1752
1719
  }
1753
- /**
1754
- * Free the memory allocated for this flow field.
1755
- */
1756
- free() {
1757
- this._flowField.free();
1758
- }
1759
1720
  }
1760
1721
 
1761
1722
  /**
@@ -1777,12 +1738,6 @@ class ClockworkMonoFlowField {
1777
1738
  set(x, y, value) {
1778
1739
  this._flowField.set(x, y, value);
1779
1740
  }
1780
- /**
1781
- * Free the memory allocated for this flow field.
1782
- */
1783
- free() {
1784
- this._flowField.free();
1785
- }
1786
1741
  }
1787
1742
 
1788
1743
  /**
@@ -1828,14 +1783,9 @@ class ClockworkMultiroomMonoFlowField {
1828
1783
  pathToOrigin(start) {
1829
1784
  return new ClockworkPath(js_path_to_multiroom_mono_flow_field_origin(start.__packedPos, this._flowField));
1830
1785
  }
1831
- /**
1832
- * Free the memory allocated for this flow field.
1833
- */
1834
- free() {
1835
- this._flowField.free();
1836
- }
1837
1786
  }
1838
1787
 
1788
+ const DEFAULT_DIRECTION_ORDER = DirectionOrder.CardinalFirst;
1839
1789
  /**
1840
1790
  * A distance map that covers multiple rooms. Typically returned by a function
1841
1791
  * like `bfsMultiroomDistanceMap` rather than created directly.
@@ -1860,7 +1810,8 @@ class ClockworkMultiroomDistanceMap {
1860
1810
  * Get the DistanceMap for a given room.
1861
1811
  */
1862
1812
  getRoom(room) {
1863
- return this._map.get_room(packRoomName(room));
1813
+ const map = this._map.get_room(packRoomName(room));
1814
+ return map ? new ClockworkDistanceMap(map) : undefined;
1864
1815
  }
1865
1816
  /**
1866
1817
  * List all the rooms covered by this distance map.
@@ -1868,29 +1819,29 @@ class ClockworkMultiroomDistanceMap {
1868
1819
  getRooms() {
1869
1820
  return [...this._map.get_rooms()].map(room => fromPackedRoomName(room));
1870
1821
  }
1871
- /**
1872
- * Free the memory allocated for this distance map.
1873
- */
1874
- free() {
1875
- this._map.free();
1876
- }
1877
1822
  /**
1878
1823
  * Path to the origin from a given position.
1824
+ * Pass `DirectionOrder.DiagonalFirst` to prefer diagonal steps when multiple neighbors are equally close.
1879
1825
  */
1880
- pathToOrigin(start) {
1881
- return new ClockworkPath(js_path_to_multiroom_distance_map_origin(start.__packedPos, this._map));
1826
+ pathToOrigin(start, options = {}) {
1827
+ var _a;
1828
+ return new ClockworkPath(js_path_to_multiroom_distance_map_origin(start.__packedPos, this._map, (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
1882
1829
  }
1883
1830
  /**
1884
1831
  * Flow field for this distance map.
1832
+ * Pass `DirectionOrder.DiagonalFirst` to prefer diagonal directions when multiple neighbors are equally close.
1885
1833
  */
1886
- toFlowField() {
1887
- return new ClockworkMultiroomFlowField(multiroomFlowField(this._map));
1834
+ toFlowField(options = {}) {
1835
+ var _a;
1836
+ return new ClockworkMultiroomFlowField(multiroomFlowField(this._map, (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
1888
1837
  }
1889
1838
  /**
1890
1839
  * Mono-directional flow field for this distance map.
1840
+ * Pass `DirectionOrder.DiagonalFirst` to prefer diagonal directions when multiple neighbors are equally close.
1891
1841
  */
1892
- toMonoFlowField() {
1893
- return new ClockworkMultiroomMonoFlowField(multiroomMonoFlowField(this._map));
1842
+ toMonoFlowField(options = {}) {
1843
+ var _a;
1844
+ return new ClockworkMultiroomMonoFlowField(multiroomMonoFlowField(this._map, (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
1894
1845
  }
1895
1846
  }
1896
1847
 
@@ -1901,7 +1852,6 @@ function fromPackedSearchResult(result) {
1901
1852
  }, []);
1902
1853
  const distanceMap = new ClockworkMultiroomDistanceMap(result.distance_map);
1903
1854
  const ops = result.ops;
1904
- result.free();
1905
1855
  return {
1906
1856
  distanceMap,
1907
1857
  foundTargets,
@@ -2030,6 +1980,7 @@ function getTerrainCostMatrix(roomName, { plainCost, swampCost, wallCost } = {})
2030
1980
  return get_terrain_cost_matrix(packRoomName(roomName), plainCost, swampCost, wallCost);
2031
1981
  }
2032
1982
 
1983
+ /// <reference types="../types.d.ts" />
2033
1984
  let wasm_bytes;
2034
1985
  let wasm_module;
2035
1986
  let wasm_instance;
@@ -2049,16 +2000,16 @@ function initialize(verbose = false) {
2049
2000
  if (!wasm_bytes)
2050
2001
  wasm_bytes = require('screeps_clockwork.wasm');
2051
2002
  if (verbose && !initialized)
2052
- console.log('[clockwork] wasm_bytes loaded');
2003
+ console.logUnsafe('[clockwork] wasm_bytes loaded');
2053
2004
  if (!wasm_module)
2054
2005
  wasm_module = new WebAssembly.Module(wasm_bytes);
2055
2006
  if (verbose && !initialized)
2056
- console.log('[clockwork] wasm_module loaded');
2007
+ console.logUnsafe('[clockwork] wasm_module loaded');
2057
2008
  if (!wasm_instance)
2058
2009
  wasm_instance = initSync({ module: wasm_module });
2059
2010
  if (verbose && !initialized) {
2060
- console.log('[clockwork] wasm_instance loaded');
2061
- console.log(`[clockwork] version ${version()} initialized with ${(Game.cpu.getUsed() - start).toFixed(2)} CPU`);
2011
+ console.logUnsafe('[clockwork] wasm_instance loaded');
2012
+ console.logUnsafe(`[clockwork] version ${version()} initialized with ${(Game.cpu.getUsed() - start).toFixed(2)} CPU`);
2062
2013
  }
2063
2014
  initialized = true;
2064
2015
  }
@@ -2081,7 +2032,7 @@ function console_error() {
2081
2032
  }
2082
2033
  })
2083
2034
  .join(' ');
2084
- console.log('ERROR:', processedArgs);
2035
+ console.logUnsafe('ERROR:', processedArgs);
2085
2036
  }
2086
2037
 
2087
2038
  exports.ClockworkCostMatrix = ClockworkCostMatrix;
@@ -2090,15 +2041,11 @@ exports.ClockworkMonoFlowField = ClockworkMonoFlowField;
2090
2041
  exports.ClockworkMultiroomFlowField = ClockworkMultiroomFlowField;
2091
2042
  exports.ClockworkMultiroomMonoFlowField = ClockworkMultiroomMonoFlowField;
2092
2043
  exports.ClockworkPath = ClockworkPath;
2093
- exports.DistanceMap = DistanceMap;
2094
- exports.FlowField = FlowField;
2095
- exports.MonoFlowField = MonoFlowField;
2044
+ exports.DirectionOrder = DirectionOrder;
2096
2045
  exports.astarMultiroomDistanceMap = astarMultiroomDistanceMap;
2097
2046
  exports.bfsMultiroomDistanceMap = bfsMultiroomDistanceMap;
2098
2047
  exports.dijkstraMultiroomDistanceMap = dijkstraMultiroomDistanceMap;
2099
- exports.ephemeral = ephemeral;
2100
2048
  exports.getRange = getRange;
2101
2049
  exports.getTerrainCostMatrix = getTerrainCostMatrix;
2102
2050
  exports.initialize = initialize;
2103
- exports.persist = persist;
2104
2051
  //# sourceMappingURL=index.js.map