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