screeps-clockwork 0.5.0 → 0.7.1

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
@@ -183,54 +183,73 @@ function addBorrowedObject(obj) {
183
183
  return stack_pointer;
184
184
  }
185
185
  /**
186
- * WASM wrapper for the BFS multiroom flow field function.
187
186
  * @param {Uint32Array} start_packed
188
187
  * @param {Function} get_cost_matrix
189
- * @param {number} max_tiles
190
188
  * @param {number} max_rooms
191
- * @param {number} max_room_distance
192
- * @param {number} max_tile_distance
193
- * @returns {MultiroomFlowField}
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}
194
194
  */
195
- function js_bfs_multiroom_flow_field(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
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
196
  try {
197
197
  const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
198
198
  const len0 = WASM_VECTOR_LEN;
199
- const ret = wasm.js_bfs_multiroom_flow_field(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
200
- return MultiroomFlowField.__wrap(ret);
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);
201
205
  } finally {
202
206
  heap[stack_pointer++] = undefined;
203
207
  }
204
208
  }
205
209
 
210
+ function getArrayU32FromWasm0(ptr, len) {
211
+ ptr = ptr >>> 0;
212
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
213
+ }
214
+
206
215
  function _assertClass(instance, klass) {
207
216
  if (!(instance instanceof klass)) {
208
217
  throw new Error(`expected instance of ${klass.name}`);
209
218
  }
210
219
  }
211
220
  /**
212
- * WASM wrapper for the Dijkstra distance map function.
213
- * @param {Uint32Array} start_packed
214
- * @param {ClockworkCostMatrix} cost_matrix
215
- * @returns {DistanceMap}
221
+ * @param {number} start
222
+ * @param {MultiroomMonoFlowField} flow_field
223
+ * @returns {Path}
216
224
  */
217
- function js_dijkstra_distance_map(start_packed, cost_matrix) {
218
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
219
- const len0 = WASM_VECTOR_LEN;
220
- _assertClass(cost_matrix, ClockworkCostMatrix);
221
- const ret = wasm.js_dijkstra_distance_map(ptr0, len0, cost_matrix.__wbg_ptr);
222
- return DistanceMap.__wrap(ret);
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;
223
238
  }
224
239
 
240
+ function getArrayU16FromWasm0(ptr, len) {
241
+ ptr = ptr >>> 0;
242
+ return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
243
+ }
225
244
  /**
226
245
  * @param {number} start
227
- * @param {FlowField} flow_field
246
+ * @param {MultiroomFlowField} flow_field
228
247
  * @returns {Path}
229
248
  */
230
- function js_path_to_flow_field_origin(start, flow_field) {
231
- _assertClass(flow_field, FlowField);
232
- const ret = wasm.js_path_to_flow_field_origin(start, flow_field.__wbg_ptr);
233
- return Path$1.__wrap(ret);
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);
234
253
  }
235
254
 
236
255
  function getArrayJsValueFromWasm0(ptr, len) {
@@ -253,249 +272,93 @@ function passArrayJsValueToWasm0(array, malloc) {
253
272
  return ptr;
254
273
  }
255
274
  /**
256
- * WASM wrapper for the BFS distance map function.
257
- * @param {Uint32Array} start_packed
258
- * @param {ClockworkCostMatrix} cost_matrix
259
- * @returns {DistanceMap}
260
- */
261
- function js_bfs_distance_map(start_packed, cost_matrix) {
262
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
263
- const len0 = WASM_VECTOR_LEN;
264
- _assertClass(cost_matrix, ClockworkCostMatrix);
265
- const ret = wasm.js_bfs_distance_map(ptr0, len0, cost_matrix.__wbg_ptr);
266
- return DistanceMap.__wrap(ret);
267
- }
268
-
269
- /**
270
- * @param {Uint32Array} start_packed
271
- * @param {Function} get_cost_matrix
272
- * @param {number} max_tiles
273
- * @param {number} max_rooms
274
- * @param {number} max_room_distance
275
- * @param {number} max_tile_distance
276
- * @returns {MultiroomDistanceMap}
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}
277
280
  */
278
- function js_dijkstra_multiroom_distance_map(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
279
- try {
280
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
281
- const len0 = WASM_VECTOR_LEN;
282
- const ret = wasm.js_dijkstra_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
283
- return MultiroomDistanceMap.__wrap(ret);
284
- } finally {
285
- heap[stack_pointer++] = undefined;
286
- }
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);
287
284
  }
288
285
 
289
286
  /**
290
- * @param {Uint32Array} start_packed
291
- * @param {Function} get_cost_matrix
292
- * @param {number} max_tiles
293
- * @param {number} max_rooms
294
- * @param {number} max_room_distance
295
- * @param {number} max_tile_distance
287
+ * Creates a flow field for the given distance map.
288
+ * @param {MultiroomDistanceMap} distance_map
296
289
  * @returns {MultiroomFlowField}
297
290
  */
298
- function js_dijkstra_multiroom_flow_field(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
299
- try {
300
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
301
- const len0 = WASM_VECTOR_LEN;
302
- const ret = wasm.js_dijkstra_multiroom_flow_field(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
303
- return MultiroomFlowField.__wrap(ret);
304
- } finally {
305
- heap[stack_pointer++] = undefined;
306
- }
307
- }
308
-
309
- /**
310
- * WASM wrapper for the BFS multiroom distance map function.
311
- * @param {Uint32Array} start_packed
312
- * @param {Function} get_cost_matrix
313
- * @param {number} max_tiles
314
- * @param {number} max_rooms
315
- * @param {number} max_room_distance
316
- * @param {number} max_tile_distance
317
- * @returns {MultiroomDistanceMap}
318
- */
319
- function js_bfs_multiroom_distance_map(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
320
- try {
321
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
322
- const len0 = WASM_VECTOR_LEN;
323
- const ret = wasm.js_bfs_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
324
- return MultiroomDistanceMap.__wrap(ret);
325
- } finally {
326
- heap[stack_pointer++] = undefined;
327
- }
328
- }
329
-
330
- /**
331
- * WASM wrapper for the Dijkstra flow field function.
332
- * @param {Uint32Array} start_packed
333
- * @param {ClockworkCostMatrix} cost_matrix
334
- * @returns {FlowField}
335
- */
336
- function js_dijkstra_flow_field(start_packed, cost_matrix) {
337
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
338
- const len0 = WASM_VECTOR_LEN;
339
- _assertClass(cost_matrix, ClockworkCostMatrix);
340
- const ret = wasm.js_dijkstra_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
341
- return FlowField.__wrap(ret);
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);
342
296
  }
343
297
 
344
298
  /**
345
299
  * @param {Uint32Array} start_packed
346
300
  * @param {Function} get_cost_matrix
347
- * @param {number} max_tiles
301
+ * @param {number} max_ops
348
302
  * @param {number} max_rooms
349
- * @param {number} max_room_distance
350
- * @param {number} max_tile_distance
351
- * @returns {MultiroomMonoFlowField}
303
+ * @param {number} max_path_cost
304
+ * @param {Uint32Array | null} [any_of_destinations]
305
+ * @param {Uint32Array | null} [all_of_destinations]
306
+ * @returns {SearchResult}
352
307
  */
353
- function js_dijkstra_multiroom_mono_flow_field(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
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) {
354
309
  try {
355
310
  const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
356
311
  const len0 = WASM_VECTOR_LEN;
357
- const ret = wasm.js_dijkstra_multiroom_mono_flow_field(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
358
- return MultiroomMonoFlowField.__wrap(ret);
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);
359
318
  } finally {
360
319
  heap[stack_pointer++] = undefined;
361
320
  }
362
321
  }
363
322
 
364
323
  /**
365
- * @param {number} start
366
- * @param {MultiroomDistanceMap} distance_map
367
- * @returns {Path}
368
- */
369
- function js_path_to_multiroom_distance_map_origin(start, distance_map) {
370
- _assertClass(distance_map, MultiroomDistanceMap);
371
- const ret = wasm.js_path_to_multiroom_distance_map_origin(start, distance_map.__wbg_ptr);
372
- return Path$1.__wrap(ret);
373
- }
374
-
375
- /**
376
- * WASM wrapper for the BFS flow field function.
377
- * @param {Uint32Array} start_packed
378
- * @param {ClockworkCostMatrix} cost_matrix
379
- * @returns {FlowField}
380
- */
381
- function js_bfs_flow_field(start_packed, cost_matrix) {
382
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
383
- const len0 = WASM_VECTOR_LEN;
384
- _assertClass(cost_matrix, ClockworkCostMatrix);
385
- const ret = wasm.js_bfs_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
386
- return FlowField.__wrap(ret);
387
- }
388
-
389
- /**
390
- * @param {number} start
391
- * @param {MonoFlowField} flow_field
392
- * @returns {Path}
393
- */
394
- function js_path_to_mono_flow_field_origin(start, flow_field) {
395
- _assertClass(flow_field, MonoFlowField);
396
- const ret = wasm.js_path_to_mono_flow_field_origin(start, flow_field.__wbg_ptr);
397
- return Path$1.__wrap(ret);
398
- }
399
-
400
- /**
401
- * @param {number} start
402
- * @param {MultiroomMonoFlowField} flow_field
403
- * @returns {Path}
404
- */
405
- function js_path_to_multiroom_mono_flow_field_origin(start, flow_field) {
406
- _assertClass(flow_field, MultiroomMonoFlowField);
407
- const ret = wasm.js_path_to_multiroom_mono_flow_field_origin(start, flow_field.__wbg_ptr);
408
- return Path$1.__wrap(ret);
409
- }
410
-
411
- let cachedUint16ArrayMemory0 = null;
412
-
413
- function getUint16ArrayMemory0() {
414
- if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
415
- cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
416
- }
417
- return cachedUint16ArrayMemory0;
418
- }
419
-
420
- function getArrayU16FromWasm0(ptr, len) {
421
- ptr = ptr >>> 0;
422
- return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
423
- }
424
- /**
425
- * WASM wrapper for the BFS multiroom monodirectional flow field function.
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
426
338
  * @param {Uint32Array} start_packed
427
339
  * @param {Function} get_cost_matrix
428
- * @param {number} max_tiles
340
+ * @param {number} max_ops
429
341
  * @param {number} max_rooms
430
- * @param {number} max_room_distance
431
- * @param {number} max_tile_distance
432
- * @returns {MultiroomMonoFlowField}
342
+ * @param {number} max_path_cost
343
+ * @param {Uint32Array | null} [any_of_destinations]
344
+ * @param {Uint32Array | null} [all_of_destinations]
345
+ * @returns {SearchResult}
433
346
  */
434
- function js_bfs_multiroom_mono_flow_field(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
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) {
435
348
  try {
436
349
  const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
437
350
  const len0 = WASM_VECTOR_LEN;
438
- const ret = wasm.js_bfs_multiroom_mono_flow_field(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
439
- return MultiroomMonoFlowField.__wrap(ret);
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);
440
357
  } finally {
441
358
  heap[stack_pointer++] = undefined;
442
359
  }
443
360
  }
444
361
 
445
- /**
446
- * WASM wrapper for the BFS mono flow field function.
447
- * @param {Uint32Array} start_packed
448
- * @param {ClockworkCostMatrix} cost_matrix
449
- * @returns {MonoFlowField}
450
- */
451
- function js_bfs_mono_flow_field(start_packed, cost_matrix) {
452
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
453
- const len0 = WASM_VECTOR_LEN;
454
- _assertClass(cost_matrix, ClockworkCostMatrix);
455
- const ret = wasm.js_bfs_mono_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
456
- return MonoFlowField.__wrap(ret);
457
- }
458
-
459
- /**
460
- * @param {number} start
461
- * @param {DistanceMap} distance_map
462
- * @returns {Path}
463
- */
464
- function js_path_to_distance_map_origin(start, distance_map) {
465
- _assertClass(distance_map, DistanceMap);
466
- const ret = wasm.js_path_to_distance_map_origin(start, distance_map.__wbg_ptr);
467
- return Path$1.__wrap(ret);
468
- }
469
-
470
- /**
471
- * @param {number} start
472
- * @param {MultiroomFlowField} flow_field
473
- * @returns {Path}
474
- */
475
- function js_path_to_multiroom_flow_field_origin(start, flow_field) {
476
- _assertClass(flow_field, MultiroomFlowField);
477
- const ret = wasm.js_path_to_multiroom_flow_field_origin(start, flow_field.__wbg_ptr);
478
- return Path$1.__wrap(ret);
479
- }
480
-
481
- /**
482
- * WASM wrapper for the Dijkstra mono flow field function.
483
- * @param {Uint32Array} start_packed
484
- * @param {ClockworkCostMatrix} cost_matrix
485
- * @returns {MonoFlowField}
486
- */
487
- function js_dijkstra_mono_flow_field(start_packed, cost_matrix) {
488
- const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
489
- const len0 = WASM_VECTOR_LEN;
490
- _assertClass(cost_matrix, ClockworkCostMatrix);
491
- const ret = wasm.js_dijkstra_mono_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
492
- return MonoFlowField.__wrap(ret);
493
- }
494
-
495
- function getArrayU32FromWasm0(ptr, len) {
496
- ptr = ptr >>> 0;
497
- return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
498
- }
499
362
  /**
500
363
  * @returns {string}
501
364
  */
@@ -527,6 +390,29 @@ function get_range(packed_pos_1, packed_pos_2) {
527
390
  return ret >>> 0;
528
391
  }
529
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
+
530
416
  /**
531
417
  * Translates `COLOR_*` and `COLORS_ALL` constants.
532
418
  * @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}
@@ -692,6 +578,14 @@ const ClockworkCostMatrixFinalization = (typeof FinalizationRegistry === 'undefi
692
578
  */
693
579
  class ClockworkCostMatrix {
694
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
+
695
589
  __destroy_into_raw() {
696
590
  const ptr = this.__wbg_ptr;
697
591
  this.__wbg_ptr = 0;
@@ -706,7 +600,7 @@ class ClockworkCostMatrix {
706
600
  /**
707
601
  * Creates a new cost matrix within the WASM module. Optionally, a default value
708
602
  * can be provided to initialize all cells in the matrix to that value.
709
- * @param {number | undefined} [_default]
603
+ * @param {number | null} [_default]
710
604
  */
711
605
  constructor(_default) {
712
606
  const ret = wasm.clockworkcostmatrix_new(isLikeNone(_default) ? 0xFFFFFF : _default);
@@ -934,7 +828,7 @@ class MonoFlowField {
934
828
  * Set the direction for a given coordinate.
935
829
  * @param {number} x
936
830
  * @param {number} y
937
- * @param {Direction | undefined} [value]
831
+ * @param {Direction | null} [value]
938
832
  */
939
833
  set(x, y, value) {
940
834
  wasm.monoflowfield_set(this.__wbg_ptr, x, y, isLikeNone(value) ? 0 : value);
@@ -1170,7 +1064,7 @@ class MultiroomMonoFlowField {
1170
1064
  * Creates a new empty multiroom monodirectional flow field (JavaScript constructor)
1171
1065
  */
1172
1066
  constructor() {
1173
- const ret = wasm.multiroomdistancemap_js_new();
1067
+ const ret = wasm.multiroommonoflowfield_js_new();
1174
1068
  this.__wbg_ptr = ret >>> 0;
1175
1069
  MultiroomMonoFlowFieldFinalization.register(this, this.__wbg_ptr, this);
1176
1070
  return this;
@@ -1187,7 +1081,7 @@ class MultiroomMonoFlowField {
1187
1081
  /**
1188
1082
  * Sets the direction at a given position
1189
1083
  * @param {number} packed_pos
1190
- * @param {Direction | undefined} [direction]
1084
+ * @param {Direction | null} [direction]
1191
1085
  */
1192
1086
  set(packed_pos, direction) {
1193
1087
  wasm.multiroommonoflowfield_set(this.__wbg_ptr, packed_pos, isLikeNone(direction) ? 0 : direction);
@@ -1226,11 +1120,11 @@ const PathFinalization = (typeof FinalizationRegistry === 'undefined')
1226
1120
  /**
1227
1121
  * A list of positions representing a path.
1228
1122
  */
1229
- class Path$1 {
1123
+ class Path {
1230
1124
 
1231
1125
  static __wrap(ptr) {
1232
1126
  ptr = ptr >>> 0;
1233
- const obj = Object.create(Path$1.prototype);
1127
+ const obj = Object.create(Path.prototype);
1234
1128
  obj.__wbg_ptr = ptr;
1235
1129
  PathFinalization.register(obj, obj.__wbg_ptr, obj);
1236
1130
  return obj;
@@ -1322,22 +1216,91 @@ class Path$1 {
1322
1216
  ? { register: () => {}, unregister: () => {} }
1323
1217
  : new FinalizationRegistry(ptr => wasm.__wbg_searchgoal_free(ptr >>> 0, 1));
1324
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;
1239
+ }
1240
+
1241
+ __destroy_into_raw() {
1242
+ const ptr = this.__wbg_ptr;
1243
+ this.__wbg_ptr = 0;
1244
+ SearchResultFinalization.unregister(this);
1245
+ return ptr;
1246
+ }
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);
1258
+ }
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);
1273
+ }
1274
+ }
1275
+ /**
1276
+ * @returns {number}
1277
+ */
1278
+ get ops() {
1279
+ const ret = wasm.searchresult_ops(this.__wbg_ptr);
1280
+ return ret >>> 0;
1281
+ }
1282
+ }
1283
+
1325
1284
  function __wbg_get_imports() {
1326
1285
  const imports = {};
1327
1286
  imports.wbg = {};
1328
- imports.wbg.__wbg_call_0411c0c3c424db9a = function() { return handleError(function (arg0, arg1, arg2) {
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) {
1329
1292
  const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
1330
1293
  return addHeapObject(ret);
1331
1294
  }, arguments) };
1332
- imports.wbg.__wbg_ceil_73d048b08f059b46 = function(arg0) {
1295
+ imports.wbg.__wbg_ceil_2a411b0e70cc0baf = function(arg0) {
1333
1296
  const ret = Math.ceil(arg0);
1334
1297
  return ret;
1335
1298
  };
1336
- imports.wbg.__wbg_clockworkcostmatrixgetpointer_79ff2a01ab0022a6 = function(arg0) {
1299
+ imports.wbg.__wbg_clockworkcostmatrixgetpointer_ac59edc2cad584d6 = function(arg0) {
1337
1300
  const ret = clockworkcostmatrix_get_pointer(takeObject(arg0));
1338
1301
  return ret;
1339
1302
  };
1340
- imports.wbg.__wbg_create_7616c10d022615b4 = function(arg0) {
1303
+ imports.wbg.__wbg_create_cfe43ccc88c64e0a = function(arg0) {
1341
1304
  const ret = Object.create(getObject(arg0));
1342
1305
  return addHeapObject(ret);
1343
1306
  };
@@ -1352,6 +1315,10 @@ function __wbg_get_imports() {
1352
1315
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
1353
1316
  }
1354
1317
  };
1318
+ imports.wbg.__wbg_getRawBuffer_063ad218fd3b8817 = function(arg0, arg1) {
1319
+ const ret = getObject(arg0).getRawBuffer(getObject(arg1));
1320
+ return addHeapObject(ret);
1321
+ };
1355
1322
  imports.wbg.__wbg_getRoomTerrain_82fcc54e35a8985e = function() { return handleError(function (arg0) {
1356
1323
  const ret = Game.map.getRoomTerrain(getObject(arg0));
1357
1324
  return addHeapObject(ret);
@@ -1360,7 +1327,7 @@ function __wbg_get_imports() {
1360
1327
  const ret = getObject(arg0).get(arg1, arg2);
1361
1328
  return ret;
1362
1329
  };
1363
- imports.wbg.__wbg_get_68aa371864aa301a = function(arg0, arg1) {
1330
+ imports.wbg.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
1364
1331
  const ret = getObject(arg0)[arg1 >>> 0];
1365
1332
  return addHeapObject(ret);
1366
1333
  };
@@ -1368,11 +1335,11 @@ function __wbg_get_imports() {
1368
1335
  const ret = getObject(arg0)[getObject(arg1)];
1369
1336
  return addHeapObject(ret);
1370
1337
  };
1371
- imports.wbg.__wbg_length_e74df4881604f1d9 = function(arg0) {
1338
+ imports.wbg.__wbg_length_e2d2a49132c1b256 = function(arg0) {
1372
1339
  const ret = getObject(arg0).length;
1373
1340
  return ret;
1374
1341
  };
1375
- imports.wbg.__wbg_log_e9cc7e18c0c70cf4 = function(arg0, arg1) {
1342
+ imports.wbg.__wbg_log_223889c5580129ef = function(arg0, arg1) {
1376
1343
  console.log(getStringFromWasm0(arg0, arg1));
1377
1344
  };
1378
1345
  imports.wbg.__wbg_lookFor_04c5885fea38e9b2 = function() { return handleError(function (arg0, arg1) {
@@ -1383,6 +1350,14 @@ function __wbg_get_imports() {
1383
1350
  const ret = new Error();
1384
1351
  return addHeapObject(ret);
1385
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
+ };
1386
1361
  imports.wbg.__wbg_rooms_c7983d4650f28959 = function() {
1387
1362
  const ret = Game.rooms;
1388
1363
  return addHeapObject(ret);
@@ -1413,6 +1388,10 @@ function __wbg_get_imports() {
1413
1388
  const ret = getObject(arg0) === undefined;
1414
1389
  return ret;
1415
1390
  };
1391
+ imports.wbg.__wbindgen_memory = function() {
1392
+ const ret = wasm.memory;
1393
+ return addHeapObject(ret);
1394
+ };
1416
1395
  imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
1417
1396
  const obj = getObject(arg1);
1418
1397
  const ret = typeof(obj) === 'number' ? obj : undefined;
@@ -1481,6 +1460,46 @@ function initSync(module) {
1481
1460
  return __wbg_finalize_init(instance);
1482
1461
  }
1483
1462
 
1463
+ const cache = new Set();
1464
+ let cacheTick = 0;
1465
+ /**
1466
+ * Mark an item as ephemeral. This means that the item will be freed after the
1467
+ * current tick.
1468
+ *
1469
+ * If you don't use this to clean up your data, you'll need to call `free()`
1470
+ * yourself.
1471
+ *
1472
+ * @param item - The item to be cleaned up.
1473
+ * @returns The item.
1474
+ */
1475
+ function ephemeral(item) {
1476
+ if (cacheTick !== Game.time) {
1477
+ for (const item of cache) {
1478
+ try {
1479
+ item.free();
1480
+ }
1481
+ catch (_a) {
1482
+ // may have already been cleaned up
1483
+ }
1484
+ }
1485
+ cache.clear();
1486
+ cacheTick = Game.time;
1487
+ }
1488
+ cache.add(item);
1489
+ return item;
1490
+ }
1491
+ /**
1492
+ * Persist an ephemeral item. This means that the item will not be freed after
1493
+ * the current tick.
1494
+ *
1495
+ * @param item - The item to be persisted.
1496
+ * @returns The item.
1497
+ */
1498
+ function persist(item) {
1499
+ cache.delete(item);
1500
+ return item;
1501
+ }
1502
+
1484
1503
  const MAX_USIZE = 0xffffffff;
1485
1504
 
1486
1505
  function fromPacked(packedPos) {
@@ -1520,14 +1539,59 @@ function packRoomName(room) {
1520
1539
  }
1521
1540
 
1522
1541
  /**
1523
- * A path from a start position to an end position. Typically returned by a
1524
- * function like `pathToFlowFieldOrigin` rather than created directly.
1542
+ * A flow field for a single room that stores multiple directions per tile.
1525
1543
  */
1526
- class Path {
1527
- constructor(path) {
1528
- this.path = path;
1529
- }
1530
- /**
1544
+ class ClockworkFlowField {
1545
+ constructor(_flowField) {
1546
+ this._flowField = _flowField;
1547
+ }
1548
+ /**
1549
+ * Get the internal value for a given coordinate.
1550
+ */
1551
+ get(x, y) {
1552
+ return this._flowField.get(x, y);
1553
+ }
1554
+ /**
1555
+ * Set the internal value for a given coordinate.
1556
+ */
1557
+ set(x, y, value) {
1558
+ this._flowField.set(x, y, value);
1559
+ }
1560
+ /**
1561
+ * Get the list of valid directions for a given coordinate.
1562
+ */
1563
+ getDirections(x, y) {
1564
+ return this._flowField.getDirections(x, y);
1565
+ }
1566
+ /**
1567
+ * Set the list of valid directions for a given coordinate.
1568
+ */
1569
+ setDirections(x, y, directions) {
1570
+ this._flowField.setDirections(x, y, directions);
1571
+ }
1572
+ /**
1573
+ * Add a direction to the list of valid directions for a given coordinate.
1574
+ */
1575
+ addDirection(x, y, direction) {
1576
+ this._flowField.addDirection(x, y, direction);
1577
+ }
1578
+ /**
1579
+ * Free the memory allocated for this flow field.
1580
+ */
1581
+ free() {
1582
+ this._flowField.free();
1583
+ }
1584
+ }
1585
+
1586
+ /**
1587
+ * A path from a start position to an end position. Typically returned by a
1588
+ * function like `pathToFlowFieldOrigin` rather than created directly.
1589
+ */
1590
+ class ClockworkPath {
1591
+ constructor(path) {
1592
+ this.path = path;
1593
+ }
1594
+ /**
1531
1595
  * Iterate over the path.
1532
1596
  *
1533
1597
  * @example
@@ -1625,175 +1689,64 @@ class Path {
1625
1689
  }
1626
1690
 
1627
1691
  /**
1628
- * A distance map for a single room.
1629
- */
1630
- class ClockworkDistanceMap {
1631
- constructor(_map) {
1632
- this._map = _map;
1633
- }
1634
- /**
1635
- * Gets the distance value at a given position.
1636
- */
1637
- get(x, y) {
1638
- return this._map.get(x, y);
1639
- }
1640
- /**
1641
- * Sets the distance value at a given position.
1642
- */
1643
- set(x, y, value) {
1644
- this._map.set(x, y, value);
1645
- }
1646
- /**
1647
- * Converts the distance map into a flat array of distances.
1648
- */
1649
- toArray() {
1650
- return this._map.toArray();
1651
- }
1652
- /**
1653
- * Frees the memory allocated for this distance map.
1654
- */
1655
- free() {
1656
- this._map.free();
1657
- }
1658
- /**
1659
- * Path to the origin from a given position.
1660
- */
1661
- pathToOrigin(start) {
1662
- return new Path(js_path_to_distance_map_origin(start.__packedPos, this._map));
1663
- }
1664
- }
1665
-
1666
- /**
1667
- * A distance map that covers multiple rooms. Typically returned by a function
1668
- * like `bfsMultiroomDistanceMap` rather than created directly.
1692
+ * A flow field that spans multiple rooms, storing multiple directions per tile.
1669
1693
  */
1670
- class ClockworkMultiroomDistanceMap {
1671
- constructor(_map) {
1672
- this._map = _map;
1694
+ class ClockworkMultiroomFlowField {
1695
+ constructor(_flowField) {
1696
+ this._flowField = _flowField;
1673
1697
  }
1674
1698
  /**
1675
- * Get the stored value for a given position.
1699
+ * Get the flow field value at a given position.
1676
1700
  */
1677
1701
  get(pos) {
1678
- return this._map.get(pos.__packedPos);
1702
+ return this._flowField.get(pos.__packedPos);
1679
1703
  }
1680
1704
  /**
1681
- * Set the stored value for a given position.
1705
+ * Set the flow field value at a given position.
1682
1706
  */
1683
1707
  set(pos, value) {
1684
- this._map.set(pos.__packedPos, value);
1685
- }
1686
- /**
1687
- * Get the DistanceMap for a given room.
1688
- */
1689
- getRoom(room) {
1690
- return this._map.get_room(packRoomName(room));
1691
- }
1692
- /**
1693
- * List all the rooms covered by this distance map.
1694
- */
1695
- getRooms() {
1696
- return [...this._map.get_rooms()].map(room => fromPackedRoomName(room));
1697
- }
1698
- /**
1699
- * Free the memory allocated for this distance map.
1700
- */
1701
- free() {
1702
- this._map.free();
1708
+ this._flowField.set(pos.__packedPos, value);
1703
1709
  }
1704
1710
  /**
1705
- * Path to the origin from a given position.
1711
+ * Get the list of valid directions at a given position.
1706
1712
  */
1707
- pathToOrigin(start) {
1708
- return new Path(js_path_to_multiroom_distance_map_origin(start.__packedPos, this._map));
1709
- }
1710
- }
1711
-
1712
- /**
1713
- * Generate a [distance map](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
1714
- * using a breadth-first search algorithm.
1715
- *
1716
- * The BFS algorithm doesn't include variable costs, and only considers
1717
- * values of 255 (impassible) in the provided cost matrix. Any other
1718
- * values are ignored.
1719
- *
1720
- * This might be useful for creeps with only MOVE parts and/or empty
1721
- * CARRY parts, which don't generate fatigue.
1722
- *
1723
- * Note that the `roomName` on start positions is ignored - all positions
1724
- * are assumed to be in the same room as the cost matrix.
1725
- *
1726
- * @param start - The starting positions.
1727
- * @param costMatrix - The cost matrix to use for the flow field.
1728
- * @returns The flow field.
1729
- */
1730
- function bfsDistanceMap(start, costMatrix) {
1731
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
1732
- const result = js_bfs_distance_map(startPacked, costMatrix);
1733
- return new ClockworkDistanceMap(result);
1734
- }
1735
- /**
1736
- * Create a distance map for the given start positions, using a breadth-first search.
1737
- * This does not factor in terrain costs (treating anything less than 255 in the cost
1738
- * matrix as passable), so it's faster but less useful than Dijkstra's algorithm.
1739
- *
1740
- * This calculates a distance map across multiple rooms, with a few configurable limits:
1741
- * - `maxTiles`: The maximum number of tiles to explore.
1742
- * - `maxRooms`: The maximum number of rooms to explore.
1743
- * - `maxRoomDistance`: Don't explore rooms further (in Manhattan distance) than this.
1744
- * - `maxTileDistance`: Don't explore tiles further (in Chebyshev distance) than this.
1745
- *
1746
- * At least one of these limits must be set.
1747
- *
1748
- * @param start - The starting positions.
1749
- * @param options - The options for the distance map.
1750
- * @returns A multi-room distance map.
1751
- */
1752
- function bfsMultiroomDistanceMap(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
1753
- if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
1754
- throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
1755
- }
1756
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
1757
- const result = js_bfs_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomName(room)), maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
1758
- return new ClockworkMultiroomDistanceMap(result);
1759
- }
1760
-
1761
- /**
1762
- * A flow field for a single room that stores multiple directions per tile.
1763
- */
1764
- class ClockworkFlowField {
1765
- constructor(_flowField) {
1766
- this._flowField = _flowField;
1713
+ getDirections(pos) {
1714
+ return this._flowField.getDirections(pos.__packedPos);
1767
1715
  }
1768
1716
  /**
1769
- * Get the internal value for a given coordinate.
1717
+ * Set the list of valid directions at a given position.
1770
1718
  */
1771
- get(x, y) {
1772
- return this._flowField.get(x, y);
1719
+ setDirections(pos, directions) {
1720
+ this._flowField.setDirections(pos.__packedPos, directions);
1773
1721
  }
1774
1722
  /**
1775
- * Set the internal value for a given coordinate.
1723
+ * Add a direction to the list of valid directions at a given position.
1776
1724
  */
1777
- set(x, y, value) {
1778
- this._flowField.set(x, y, value);
1725
+ addDirection(pos, direction) {
1726
+ this._flowField.addDirection(pos.__packedPos, direction);
1779
1727
  }
1780
1728
  /**
1781
- * Get the list of valid directions for a given coordinate.
1729
+ * Get the list of rooms in the flow field.
1782
1730
  */
1783
- getDirections(x, y) {
1784
- return this._flowField.getDirections(x, y);
1731
+ getRooms() {
1732
+ const rooms = [];
1733
+ for (const packedRoomName of this._flowField.getRooms()) {
1734
+ rooms.push(fromPackedRoomName(packedRoomName));
1735
+ }
1736
+ return rooms;
1785
1737
  }
1786
1738
  /**
1787
- * Set the list of valid directions for a given coordinate.
1739
+ * Get the flow field for a given room.
1788
1740
  */
1789
- setDirections(x, y, directions) {
1790
- this._flowField.setDirections(x, y, directions);
1741
+ getRoom(roomName) {
1742
+ const flowField = this._flowField.getRoom(packRoomName(roomName));
1743
+ return flowField ? new ClockworkFlowField(flowField) : null;
1791
1744
  }
1792
1745
  /**
1793
- * Add a direction to the list of valid directions for a given coordinate.
1746
+ * Find a path from a given position to the origin of the flow field.
1794
1747
  */
1795
- addDirection(x, y, direction) {
1796
- this._flowField.addDirection(x, y, direction);
1748
+ pathToOrigin(start) {
1749
+ return new ClockworkPath(js_path_to_multiroom_flow_field_origin(start.__packedPos, this._flowField));
1797
1750
  }
1798
1751
  /**
1799
1752
  * Free the memory allocated for this flow field.
@@ -1801,13 +1754,6 @@ class ClockworkFlowField {
1801
1754
  free() {
1802
1755
  this._flowField.free();
1803
1756
  }
1804
- /**
1805
- * Given a flow field (for a single room), find the path from a given position to
1806
- * the origin. Never paths through other rooms.
1807
- */
1808
- pathToOrigin(start) {
1809
- return new Path(js_path_to_flow_field_origin(start.__packedPos, this._flowField));
1810
- }
1811
1757
  }
1812
1758
 
1813
1759
  /**
@@ -1835,51 +1781,27 @@ class ClockworkMonoFlowField {
1835
1781
  free() {
1836
1782
  this._flowField.free();
1837
1783
  }
1838
- /**
1839
- * Given a monodirectional flow field (for a single room), find the path from a given position to
1840
- * the origin. Never paths through other rooms.
1841
- */
1842
- pathToOrigin(start) {
1843
- return new Path(js_path_to_mono_flow_field_origin(start.__packedPos, this._flowField));
1844
- }
1845
1784
  }
1846
1785
 
1847
1786
  /**
1848
- * A flow field that spans multiple rooms, storing multiple directions per tile.
1787
+ * A flow field that spans multiple rooms, storing a single direction per tile.
1849
1788
  */
1850
- class ClockworkMultiroomFlowField {
1789
+ class ClockworkMultiroomMonoFlowField {
1851
1790
  constructor(_flowField) {
1852
1791
  this._flowField = _flowField;
1853
1792
  }
1854
1793
  /**
1855
- * Get the flow field value at a given position.
1794
+ * Get the direction at a given position.
1856
1795
  */
1857
1796
  get(pos) {
1858
- return this._flowField.get(pos.__packedPos);
1859
- }
1860
- /**
1861
- * Set the flow field value at a given position.
1862
- */
1863
- set(pos, value) {
1864
- this._flowField.set(pos.__packedPos, value);
1865
- }
1866
- /**
1867
- * Get the list of valid directions at a given position.
1868
- */
1869
- getDirections(pos) {
1870
- return this._flowField.getDirections(pos.__packedPos);
1871
- }
1872
- /**
1873
- * Set the list of valid directions at a given position.
1874
- */
1875
- setDirections(pos, directions) {
1876
- this._flowField.setDirections(pos.__packedPos, directions);
1797
+ var _a;
1798
+ return (_a = this._flowField.get(pos.__packedPos)) !== null && _a !== void 0 ? _a : null;
1877
1799
  }
1878
1800
  /**
1879
- * Add a direction to the list of valid directions at a given position.
1801
+ * Set the direction at a given position.
1880
1802
  */
1881
- addDirection(pos, direction) {
1882
- this._flowField.addDirection(pos.__packedPos, direction);
1803
+ set(pos, direction) {
1804
+ this._flowField.set(pos.__packedPos, direction !== null && direction !== void 0 ? direction : undefined);
1883
1805
  }
1884
1806
  /**
1885
1807
  * Get the list of rooms in the flow field.
@@ -1896,13 +1818,13 @@ class ClockworkMultiroomFlowField {
1896
1818
  */
1897
1819
  getRoom(roomName) {
1898
1820
  const flowField = this._flowField.getRoom(packRoomName(roomName));
1899
- return flowField ? new ClockworkFlowField(flowField) : null;
1821
+ return flowField ? new ClockworkMonoFlowField(flowField) : null;
1900
1822
  }
1901
1823
  /**
1902
1824
  * Find a path from a given position to the origin of the flow field.
1903
1825
  */
1904
1826
  pathToOrigin(start) {
1905
- return new Path(js_path_to_multiroom_flow_field_origin(start.__packedPos, this._flowField));
1827
+ return new ClockworkPath(js_path_to_multiroom_mono_flow_field_origin(start.__packedPos, this._flowField));
1906
1828
  }
1907
1829
  /**
1908
1830
  * Free the memory allocated for this flow field.
@@ -1913,182 +1835,156 @@ class ClockworkMultiroomFlowField {
1913
1835
  }
1914
1836
 
1915
1837
  /**
1916
- * A flow field that spans multiple rooms, storing a single direction per tile.
1838
+ * A distance map that covers multiple rooms. Typically returned by a function
1839
+ * like `bfsMultiroomDistanceMap` rather than created directly.
1917
1840
  */
1918
- class ClockworkMultiroomMonoFlowField {
1919
- constructor(_flowField) {
1920
- this._flowField = _flowField;
1841
+ class ClockworkMultiroomDistanceMap {
1842
+ constructor(_map) {
1843
+ this._map = _map;
1921
1844
  }
1922
1845
  /**
1923
- * Get the direction at a given position.
1846
+ * Get the stored value for a given position.
1924
1847
  */
1925
1848
  get(pos) {
1926
- var _a;
1927
- return (_a = this._flowField.get(pos.__packedPos)) !== null && _a !== void 0 ? _a : null;
1849
+ return this._map.get(pos.__packedPos);
1928
1850
  }
1929
1851
  /**
1930
- * Set the direction at a given position.
1852
+ * Set the stored value for a given position.
1931
1853
  */
1932
- set(pos, direction) {
1933
- this._flowField.set(pos.__packedPos, direction !== null && direction !== void 0 ? direction : undefined);
1854
+ set(pos, value) {
1855
+ this._map.set(pos.__packedPos, value);
1934
1856
  }
1935
1857
  /**
1936
- * Get the list of rooms in the flow field.
1858
+ * Get the DistanceMap for a given room.
1859
+ */
1860
+ getRoom(room) {
1861
+ return this._map.get_room(packRoomName(room));
1862
+ }
1863
+ /**
1864
+ * List all the rooms covered by this distance map.
1937
1865
  */
1938
1866
  getRooms() {
1939
- const rooms = [];
1940
- for (const packedRoomName of this._flowField.getRooms()) {
1941
- rooms.push(fromPackedRoomName(packedRoomName));
1942
- }
1943
- return rooms;
1867
+ return [...this._map.get_rooms()].map(room => fromPackedRoomName(room));
1944
1868
  }
1945
1869
  /**
1946
- * Get the flow field for a given room.
1870
+ * Free the memory allocated for this distance map.
1947
1871
  */
1948
- getRoom(roomName) {
1949
- const flowField = this._flowField.getRoom(packRoomName(roomName));
1950
- return flowField ? new ClockworkMonoFlowField(flowField) : null;
1872
+ free() {
1873
+ this._map.free();
1951
1874
  }
1952
1875
  /**
1953
- * Find a path from a given position to the origin of the flow field.
1876
+ * Path to the origin from a given position.
1954
1877
  */
1955
1878
  pathToOrigin(start) {
1956
- return new Path(js_path_to_multiroom_mono_flow_field_origin(start.__packedPos, this._flowField));
1879
+ return new ClockworkPath(js_path_to_multiroom_distance_map_origin(start.__packedPos, this._map));
1957
1880
  }
1958
1881
  /**
1959
- * Free the memory allocated for this flow field.
1882
+ * Flow field for this distance map.
1960
1883
  */
1961
- free() {
1962
- this._flowField.free();
1884
+ toFlowField() {
1885
+ return new ClockworkMultiroomFlowField(multiroomFlowField(this._map));
1886
+ }
1887
+ /**
1888
+ * Mono-directional flow field for this distance map.
1889
+ */
1890
+ toMonoFlowField() {
1891
+ return new ClockworkMultiroomMonoFlowField(multiroomMonoFlowField(this._map));
1963
1892
  }
1964
1893
  }
1965
1894
 
1966
- /**
1967
- * Generate a [flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
1968
- * using a breadth-first search algorithm.
1969
- *
1970
- * The BFS algorithm doesn't include variable costs, and only considers
1971
- * values of 255 (impassible) in the provided cost matrix. Any other
1972
- * values are ignored.
1973
- *
1974
- * This might be useful for creeps with only MOVE parts and/or empty
1975
- * CARRY parts, which don't generate fatigue.
1976
- *
1977
- * @param start - The starting positions.
1978
- * @param costMatrix - The cost matrix to use for the flow field.
1979
- * @returns The flow field.
1980
- */
1981
- function bfsFlowField(start, costMatrix) {
1982
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
1983
- const result = js_bfs_flow_field(startPacked, costMatrix);
1984
- return new ClockworkFlowField(result);
1985
- }
1986
- /**
1987
- * Generate a [mono-directional flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html)
1988
- * for a set of positions using a breadth-first search algorithm.
1989
- *
1990
- * The BFS algorithm doesn't include variable costs, and only considers
1991
- * values of 255 (impassible) in the provided cost matrix. Any other
1992
- * values are ignored.
1993
- *
1994
- * This might be useful for creeps with only MOVE parts and/or empty
1995
- * CARRY parts, which don't generate fatigue.
1996
- *
1997
- * Note that the `roomName` on start positions is ignored - all positions
1998
- * are assumed to be in the same room as the cost matrix.
1999
- *
2000
- * @param start - The starting positions.
2001
- * @param costMatrix - The cost matrix to use for the flow field.
2002
- * @returns The flow field.
2003
- */
2004
- function bfsMonoFlowField(start, costMatrix) {
2005
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2006
- const result = js_bfs_mono_flow_field(startPacked, costMatrix);
2007
- return new ClockworkMonoFlowField(result);
1895
+ function fromPackedSearchResult(result) {
1896
+ const foundTargets = result.found_targets.reduce((acc, pos) => {
1897
+ acc.push(fromPacked(pos));
1898
+ return acc;
1899
+ }, []);
1900
+ const distanceMap = new ClockworkMultiroomDistanceMap(result.distance_map);
1901
+ const ops = result.ops;
1902
+ result.free();
1903
+ return {
1904
+ distanceMap,
1905
+ foundTargets,
1906
+ ops
1907
+ };
2008
1908
  }
1909
+
2009
1910
  /**
2010
- * Generate a multiroom flow field for a set of positions using a breadth-first search algorithm.
1911
+ * Create a distance map for the given start positions, using a breadth-first search.
1912
+ * This does not factor in terrain costs (treating anything less than 255 in the cost
1913
+ * matrix as passable), so it's faster but less useful than Dijkstra's algorithm.
2011
1914
  *
2012
- * The BFS algorithm doesn't include variable costs, and only considers
2013
- * values of 255 (impassible) in the provided cost matrix. Any other
2014
- * values are ignored.
1915
+ * This calculates a distance map across multiple rooms, with a few configurable limits:
1916
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
1917
+ * - `maxRooms`: The maximum number of rooms to explore.
1918
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
2015
1919
  *
2016
- * This might be useful for creeps with only MOVE parts and/or empty
2017
- * CARRY parts, which don't generate fatigue.
1920
+ * At least one of these limits must be set.
2018
1921
  *
2019
1922
  * @param start - The starting positions.
2020
- * @param costMatrixCallback - A function that returns a cost matrix for a given room name.
2021
- * @param options - Options for the flow field generation.
2022
- * @returns The flow field.
1923
+ * @param options - The options for the distance map.
1924
+ * @returns A multi-room distance map.
2023
1925
  */
2024
- function bfsMultiroomFlowField(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
2025
- if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
2026
- throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
1926
+ function astarMultiroomDistanceMap(start, { costMatrixCallback, maxRooms = MAX_USIZE, maxOps = MAX_USIZE, maxPathCost = MAX_USIZE, anyOfDestinations, allOfDestinations }) {
1927
+ if ([maxRooms, maxOps, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
1928
+ throw new Error('At least one of maxRooms, maxOps, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
2027
1929
  }
2028
1930
  const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2029
- const result = js_bfs_multiroom_flow_field(startPacked, (packedRoomName) => {
2030
- const roomName = fromPackedRoomName(packedRoomName);
2031
- return costMatrixCallback(roomName);
2032
- }, maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
2033
- return new ClockworkMultiroomFlowField(result);
1931
+ const result = js_astar_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomName(room)), maxRooms, maxOps, maxPathCost, anyOfDestinations
1932
+ ? new Uint32Array(anyOfDestinations.reduce((acc, { pos, range }) => {
1933
+ acc.push(pos.__packedPos, range);
1934
+ return acc;
1935
+ }, []))
1936
+ : undefined, allOfDestinations
1937
+ ? new Uint32Array(allOfDestinations.reduce((acc, { pos, range }) => {
1938
+ acc.push(pos.__packedPos, range);
1939
+ return acc;
1940
+ }, []))
1941
+ : undefined);
1942
+ return fromPackedSearchResult(result);
2034
1943
  }
1944
+
2035
1945
  /**
2036
- * Generate a multiroom mono-directional flow field for a set of positions using a breadth-first search algorithm.
1946
+ * Create a distance map for the given start positions, using a breadth-first search.
1947
+ * This does not factor in terrain costs (treating anything less than 255 in the cost
1948
+ * matrix as passable), so it's faster but less useful than Dijkstra's algorithm.
2037
1949
  *
2038
- * The BFS algorithm doesn't include variable costs, and only considers
2039
- * values of 255 (impassible) in the provided cost matrix. Any other
2040
- * values are ignored.
1950
+ * This calculates a distance map across multiple rooms, with a few configurable limits:
1951
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
1952
+ * - `maxRooms`: The maximum number of rooms to explore.
1953
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
2041
1954
  *
2042
- * This might be useful for creeps with only MOVE parts and/or empty
2043
- * CARRY parts, which don't generate fatigue.
1955
+ * At least one of these limits must be set.
2044
1956
  *
2045
1957
  * @param start - The starting positions.
2046
- * @param getCostMatrix - A function that returns a cost matrix for a given room name.
2047
- * @param options - Options for the flow field generation.
2048
- * @returns The flow field.
1958
+ * @param options - The options for the distance map.
1959
+ * @returns A multi-room distance map.
2049
1960
  */
2050
- function bfsMultiroomMonoFlowField(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
2051
- if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
2052
- throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
1961
+ function bfsMultiroomDistanceMap(start, { costMatrixCallback, maxOps = MAX_USIZE, maxRooms = MAX_USIZE, maxPathCost = MAX_USIZE, anyOfDestinations, allOfDestinations }) {
1962
+ if ([maxOps, maxRooms, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
1963
+ throw new Error('At least one of maxOps, maxRooms, maxRoomDistance, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
2053
1964
  }
2054
1965
  const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2055
- const result = js_bfs_multiroom_mono_flow_field(startPacked, (packedRoomName) => {
2056
- const roomName = fromPackedRoomName(packedRoomName);
2057
- return costMatrixCallback(roomName);
2058
- }, maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
2059
- return new ClockworkMultiroomMonoFlowField(result);
1966
+ const result = js_bfs_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomName(room)), maxOps, maxRooms, maxPathCost, anyOfDestinations
1967
+ ? new Uint32Array(anyOfDestinations.reduce((acc, { pos, range }) => {
1968
+ acc.push(pos.__packedPos, range);
1969
+ return acc;
1970
+ }, []))
1971
+ : undefined, allOfDestinations
1972
+ ? new Uint32Array(allOfDestinations.reduce((acc, { pos, range }) => {
1973
+ acc.push(pos.__packedPos, range);
1974
+ return acc;
1975
+ }, []))
1976
+ : undefined);
1977
+ return fromPackedSearchResult(result);
2060
1978
  }
2061
1979
 
2062
- /**
2063
- * Generate a [distance map](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
2064
- * using Dijkstra's algorithm.
2065
- *
2066
- * Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
2067
- *
2068
- * Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
2069
- * a cost matrix with a default value of at least 1.
2070
- *
2071
- * Note that the `roomName` on start positions is ignored - all positions
2072
- * are assumed to be in the same room as the cost matrix.
2073
- *
2074
- * @param start - The starting positions.
2075
- * @param costMatrix - The cost matrix to use for the flow field.
2076
- * @returns The flow field.
2077
- */
2078
- function dijkstraDistanceMap(start, costMatrix) {
2079
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2080
- const result = js_dijkstra_distance_map(startPacked, costMatrix);
2081
- return new ClockworkDistanceMap(result);
2082
- }
2083
1980
  /**
2084
1981
  * Create a distance map for the given start positions, using Dijkstra's algorithm to
2085
1982
  * factor in terrain costs (0-255, where 255 is impassable).
2086
1983
  *
2087
1984
  * This calculates a distance map across multiple rooms, with a few configurable limits:
2088
- * - `maxTiles`: The maximum number of tiles to explore.
1985
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
2089
1986
  * - `maxRooms`: The maximum number of rooms to explore.
2090
- * - `maxRoomDistance`: Don't explore rooms further (in Manhattan distance) than this.
2091
- * - `maxTileDistance`: Don't explore tiles further (in accumulated cost) than this.
1987
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
2092
1988
  *
2093
1989
  * At least one of these limits must be set.
2094
1990
  *
@@ -2096,101 +1992,23 @@ function dijkstraDistanceMap(start, costMatrix) {
2096
1992
  * @param options - The options for the distance map.
2097
1993
  * @returns A multi-room distance map.
2098
1994
  */
2099
- function dijkstraMultiroomDistanceMap(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
2100
- if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
2101
- throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
1995
+ function dijkstraMultiroomDistanceMap(start, { costMatrixCallback, maxOps = MAX_USIZE, maxRooms = MAX_USIZE, maxPathCost = MAX_USIZE, anyOfDestinations, allOfDestinations }) {
1996
+ if ([maxOps, maxRooms, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
1997
+ throw new Error('At least one of maxOps, maxRooms, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
2102
1998
  }
2103
1999
  const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2104
- const result = js_dijkstra_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomName(room)), maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
2105
- return new ClockworkMultiroomDistanceMap(result);
2106
- }
2107
-
2108
- /**
2109
- * Generate a [flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
2110
- * using Dijkstra's algorithm.
2111
- *
2112
- * Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
2113
- *
2114
- * Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
2115
- * a cost matrix with a default value of at least 1.
2116
- *
2117
- * @param start - The starting positions.
2118
- * @param costMatrix - The cost matrix to use for the flow field.
2119
- * @returns The flow field.
2120
- */
2121
- function dijkstraFlowField(start, costMatrix) {
2122
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2123
- const result = js_dijkstra_flow_field(startPacked, costMatrix);
2124
- return new ClockworkFlowField(result);
2125
- }
2126
- /**
2127
- * Generate a [mono-directional flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html)
2128
- * for a set of positions using Dijkstra's algorithm.
2129
- *
2130
- * Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
2131
- *
2132
- * Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
2133
- * a cost matrix with a default value of at least 1.
2134
- *
2135
- * Note that the `roomName` on start positions is ignored - all positions
2136
- * are assumed to be in the same room as the cost matrix.
2137
- *
2138
- * @param start - The starting positions.
2139
- * @param costMatrix - The cost matrix to use for the flow field.
2140
- * @returns The flow field.
2141
- */
2142
- function dijkstraMonoFlowField(start, costMatrix) {
2143
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2144
- const result = js_dijkstra_mono_flow_field(startPacked, costMatrix);
2145
- return new ClockworkMonoFlowField(result);
2146
- }
2147
- /**
2148
- * Generate a multiroom flow field for a set of positions using Dijkstra's algorithm.
2149
- *
2150
- * Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
2151
- *
2152
- * Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
2153
- * a cost matrix with a default value of at least 1.
2154
- *
2155
- * @param start - The starting positions.
2156
- * @param costMatrixCallback - A function that returns a cost matrix for a given room name.
2157
- * @param options - Options for the flow field generation.
2158
- * @returns The flow field.
2159
- */
2160
- function dijkstraMultiroomFlowField(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
2161
- if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
2162
- throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
2163
- }
2164
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2165
- const result = js_dijkstra_multiroom_flow_field(startPacked, (packedRoomName) => {
2166
- const roomName = fromPackedRoomName(packedRoomName);
2167
- return costMatrixCallback(roomName);
2168
- }, maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
2169
- return new ClockworkMultiroomFlowField(result);
2170
- }
2171
- /**
2172
- * Generate a multiroom mono-directional flow field for a set of positions using Dijkstra's algorithm.
2173
- *
2174
- * Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
2175
- *
2176
- * Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
2177
- * a cost matrix with a default value of at least 1.
2178
- *
2179
- * @param start - The starting positions.
2180
- * @param costMatrixCallback - A function that returns a cost matrix for a given room name.
2181
- * @param options - Options for the flow field generation.
2182
- * @returns The flow field.
2183
- */
2184
- function dijkstraMultiroomMonoFlowField(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
2185
- if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
2186
- throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
2187
- }
2188
- const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
2189
- const result = js_dijkstra_multiroom_mono_flow_field(startPacked, (packedRoomName) => {
2190
- const roomName = fromPackedRoomName(packedRoomName);
2191
- return costMatrixCallback(roomName);
2192
- }, maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
2193
- return new ClockworkMultiroomMonoFlowField(result);
2000
+ const result = js_dijkstra_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomName(room)), maxOps, maxRooms, maxPathCost, anyOfDestinations
2001
+ ? new Uint32Array(anyOfDestinations.reduce((acc, { pos, range }) => {
2002
+ acc.push(pos.__packedPos, range);
2003
+ return acc;
2004
+ }, []))
2005
+ : undefined, allOfDestinations
2006
+ ? new Uint32Array(allOfDestinations.reduce((acc, { pos, range }) => {
2007
+ acc.push(pos.__packedPos, range);
2008
+ return acc;
2009
+ }, []))
2010
+ : undefined);
2011
+ return fromPackedSearchResult(result);
2194
2012
  }
2195
2013
 
2196
2014
  /**
@@ -2206,6 +2024,10 @@ function getRange(pos1, pos2) {
2206
2024
  return get_range(pos1.__packedPos, pos2.__packedPos);
2207
2025
  }
2208
2026
 
2027
+ function getTerrainCostMatrix(roomName, { plainCost, swampCost, wallCost } = {}) {
2028
+ return get_terrain_cost_matrix(packRoomName(roomName), plainCost, swampCost, wallCost);
2029
+ }
2030
+
2209
2031
  let wasm_bytes;
2210
2032
  let wasm_module;
2211
2033
  let wasm_instance;
@@ -2221,6 +2043,7 @@ let initialized = false;
2221
2043
  function initialize(verbose = false) {
2222
2044
  // need to freshly override the fake console object each tick
2223
2045
  console.error = console_error;
2046
+ const start = Game.cpu.getUsed();
2224
2047
  if (!wasm_bytes)
2225
2048
  wasm_bytes = require('screeps_clockwork.wasm');
2226
2049
  if (verbose && !initialized)
@@ -2233,7 +2056,7 @@ function initialize(verbose = false) {
2233
2056
  wasm_instance = initSync({ module: wasm_module });
2234
2057
  if (verbose && !initialized) {
2235
2058
  console.log('[clockwork] wasm_instance loaded');
2236
- console.log(`[clockwork] version ${version()} initialized`);
2059
+ console.log(`[clockwork] version ${version()} initialized with ${(Game.cpu.getUsed() - start).toFixed(2)} CPU`);
2237
2060
  }
2238
2061
  initialized = true;
2239
2062
  }
@@ -2264,22 +2087,16 @@ exports.ClockworkFlowField = ClockworkFlowField;
2264
2087
  exports.ClockworkMonoFlowField = ClockworkMonoFlowField;
2265
2088
  exports.ClockworkMultiroomFlowField = ClockworkMultiroomFlowField;
2266
2089
  exports.ClockworkMultiroomMonoFlowField = ClockworkMultiroomMonoFlowField;
2090
+ exports.ClockworkPath = ClockworkPath;
2267
2091
  exports.DistanceMap = DistanceMap;
2268
2092
  exports.FlowField = FlowField;
2269
2093
  exports.MonoFlowField = MonoFlowField;
2270
- exports.Path = Path;
2271
- exports.bfsDistanceMap = bfsDistanceMap;
2272
- exports.bfsFlowField = bfsFlowField;
2273
- exports.bfsMonoFlowField = bfsMonoFlowField;
2094
+ exports.astarMultiroomDistanceMap = astarMultiroomDistanceMap;
2274
2095
  exports.bfsMultiroomDistanceMap = bfsMultiroomDistanceMap;
2275
- exports.bfsMultiroomFlowField = bfsMultiroomFlowField;
2276
- exports.bfsMultiroomMonoFlowField = bfsMultiroomMonoFlowField;
2277
- exports.dijkstraDistanceMap = dijkstraDistanceMap;
2278
- exports.dijkstraFlowField = dijkstraFlowField;
2279
- exports.dijkstraMonoFlowField = dijkstraMonoFlowField;
2280
2096
  exports.dijkstraMultiroomDistanceMap = dijkstraMultiroomDistanceMap;
2281
- exports.dijkstraMultiroomFlowField = dijkstraMultiroomFlowField;
2282
- exports.dijkstraMultiroomMonoFlowField = dijkstraMultiroomMonoFlowField;
2097
+ exports.ephemeral = ephemeral;
2283
2098
  exports.getRange = getRange;
2099
+ exports.getTerrainCostMatrix = getTerrainCostMatrix;
2284
2100
  exports.initialize = initialize;
2101
+ exports.persist = persist;
2285
2102
  //# sourceMappingURL=index.js.map