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