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.
Binary file
@@ -1,12 +1,13 @@
1
1
  import 'fastestsmallesttextencoderdecoder-encodeinto/EncoderDecoderTogether.min.js';
2
2
  import { ClockworkCostMatrix, DistanceMap, FlowField, MonoFlowField } from './wasm/screeps_clockwork';
3
3
  export { ClockworkCostMatrix, DistanceMap, FlowField, MonoFlowField };
4
+ export * from './utils/cleanup';
5
+ export * from './wrappers/astarDistanceMap';
4
6
  export * from './wrappers/bfsDistanceMap';
5
- export * from './wrappers/bfsFlowField';
6
7
  export * from './wrappers/dijkstraDistanceMap';
7
- export * from './wrappers/dijkstraFlowField';
8
8
  export * from './wrappers/flowField';
9
9
  export * from './wrappers/getRange';
10
+ export * from './wrappers/getTerrainCostMatrix';
10
11
  export * from './wrappers/monoFlowField';
11
12
  export * from './wrappers/multiroomFlowField';
12
13
  export * from './wrappers/multiroomMonoFlowField';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Mark an item as ephemeral. This means that the item will be freed after the
3
+ * current tick.
4
+ *
5
+ * If you don't use this to clean up your data, you'll need to call `free()`
6
+ * yourself.
7
+ *
8
+ * @param item - The item to be cleaned up.
9
+ * @returns The item.
10
+ */
11
+ export declare function ephemeral<T extends {
12
+ free: () => void;
13
+ }>(item: T): T;
14
+ /**
15
+ * Persist an ephemeral item. This means that the item will not be freed after
16
+ * the current tick.
17
+ *
18
+ * @param item - The item to be persisted.
19
+ * @returns The item.
20
+ */
21
+ export declare function persist<T extends {
22
+ free: () => void;
23
+ }>(item: T): T;
@@ -1,55 +1,41 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- /**
4
- * WASM wrapper for the BFS multiroom flow field function.
5
- */
6
- export function js_bfs_multiroom_flow_field(start_packed: Uint32Array, get_cost_matrix: Function, max_tiles: number, max_rooms: number, max_room_distance: number, max_tile_distance: number): MultiroomFlowField;
7
- /**
8
- * WASM wrapper for the Dijkstra distance map function.
9
- */
10
- export function js_dijkstra_distance_map(start_packed: Uint32Array, cost_matrix: ClockworkCostMatrix): DistanceMap;
11
- export function js_path_to_flow_field_origin(start: number, flow_field: FlowField): Path;
12
- /**
13
- * WASM wrapper for the BFS distance map function.
14
- */
15
- export function js_bfs_distance_map(start_packed: Uint32Array, cost_matrix: ClockworkCostMatrix): DistanceMap;
16
- export function js_dijkstra_multiroom_distance_map(start_packed: Uint32Array, get_cost_matrix: Function, max_tiles: number, max_rooms: number, max_room_distance: number, max_tile_distance: number): MultiroomDistanceMap;
17
- export function js_dijkstra_multiroom_flow_field(start_packed: Uint32Array, get_cost_matrix: Function, max_tiles: number, max_rooms: number, max_room_distance: number, max_tile_distance: number): MultiroomFlowField;
18
- /**
19
- * WASM wrapper for the BFS multiroom distance map function.
20
- */
21
- export function js_bfs_multiroom_distance_map(start_packed: Uint32Array, get_cost_matrix: Function, max_tiles: number, max_rooms: number, max_room_distance: number, max_tile_distance: number): MultiroomDistanceMap;
22
- /**
23
- * WASM wrapper for the Dijkstra flow field function.
24
- */
25
- export function js_dijkstra_flow_field(start_packed: Uint32Array, cost_matrix: ClockworkCostMatrix): FlowField;
26
- export function js_dijkstra_multiroom_mono_flow_field(start_packed: Uint32Array, get_cost_matrix: Function, max_tiles: number, max_rooms: number, max_room_distance: number, max_tile_distance: number): MultiroomMonoFlowField;
27
- export function js_path_to_multiroom_distance_map_origin(start: number, distance_map: MultiroomDistanceMap): Path;
28
- /**
29
- * WASM wrapper for the BFS flow field function.
30
- */
31
- export function js_bfs_flow_field(start_packed: Uint32Array, cost_matrix: ClockworkCostMatrix): FlowField;
32
- export function js_path_to_mono_flow_field_origin(start: number, flow_field: MonoFlowField): Path;
3
+ export function js_astar_multiroom_distance_map(start_packed: Uint32Array, get_cost_matrix: Function, max_rooms: number, max_ops: number, max_path_cost: number, any_of_destinations?: Uint32Array | null, all_of_destinations?: Uint32Array | null): SearchResult;
33
4
  export function js_path_to_multiroom_mono_flow_field_origin(start: number, flow_field: MultiroomMonoFlowField): Path;
5
+ export function js_path_to_multiroom_flow_field_origin(start: number, flow_field: MultiroomFlowField): Path;
6
+ export function get_terrain_cost_matrix(room_name: number, plain_cost?: number | null, swamp_cost?: number | null, wall_cost?: number | null): ClockworkCostMatrix;
34
7
  /**
35
- * WASM wrapper for the BFS multiroom monodirectional flow field function.
36
- */
37
- export function js_bfs_multiroom_mono_flow_field(start_packed: Uint32Array, get_cost_matrix: Function, max_tiles: number, max_rooms: number, max_room_distance: number, max_tile_distance: number): MultiroomMonoFlowField;
38
- /**
39
- * WASM wrapper for the BFS mono flow field function.
8
+ * Creates a flow field for the given distance map.
40
9
  */
41
- export function js_bfs_mono_flow_field(start_packed: Uint32Array, cost_matrix: ClockworkCostMatrix): MonoFlowField;
42
- export function js_path_to_distance_map_origin(start: number, distance_map: DistanceMap): Path;
43
- export function js_path_to_multiroom_flow_field_origin(start: number, flow_field: MultiroomFlowField): Path;
10
+ export function multiroomFlowField(distance_map: MultiroomDistanceMap): MultiroomFlowField;
11
+ export function js_dijkstra_multiroom_distance_map(start_packed: Uint32Array, get_cost_matrix: Function, max_ops: number, max_rooms: number, max_path_cost: number, any_of_destinations?: Uint32Array | null, all_of_destinations?: Uint32Array | null): SearchResult;
44
12
  /**
45
- * WASM wrapper for the Dijkstra mono flow field function.
13
+ * WASM wrapper for the BFS multiroom distance map function.
14
+ *
15
+ * # Arguments
16
+ * * `start_packed` - Array of packed position integers representing start positions
17
+ * * `get_cost_matrix` - JavaScript function that returns cost matrices for rooms
18
+ * * `max_ops` - Maximum number of tiles to explore
19
+ * * `max_rooms` - Maximum number of rooms to explore
20
+ * * `max_room_distance` - Maximum Manhattan distance in rooms to explore
21
+ * * `max_path_cost` - Maximum distance in tiles to explore
22
+ * * `any_of_destinations` - Array of packed positions to trigger early exit when any are reached
23
+ * * `all_of_destinations` - Array of packed positions to trigger early exit when all are reached
24
+ *
25
+ * # Returns
26
+ * A `MultiroomDistanceMap` containing the distances from the start positions
46
27
  */
47
- export function js_dijkstra_mono_flow_field(start_packed: Uint32Array, cost_matrix: ClockworkCostMatrix): MonoFlowField;
28
+ export function js_bfs_multiroom_distance_map(start_packed: Uint32Array, get_cost_matrix: Function, max_ops: number, max_rooms: number, max_path_cost: number, any_of_destinations?: Uint32Array | null, all_of_destinations?: Uint32Array | null): SearchResult;
48
29
  export function version(): string;
49
30
  /**
50
31
  * Exports the global range calculation between two positions.
51
32
  */
52
33
  export function get_range(packed_pos_1: number, packed_pos_2: number): number;
34
+ /**
35
+ * Creates a monodirectional flow field for the given distance map.
36
+ */
37
+ export function multiroomMonoFlowField(distance_map: MultiroomDistanceMap): MultiroomMonoFlowField;
38
+ export function js_path_to_multiroom_distance_map_origin(start: number, distance_map: MultiroomDistanceMap): Path;
53
39
  /**
54
40
  * Translates `COLOR_*` and `COLORS_ALL` constants.
55
41
  */
@@ -203,7 +189,7 @@ export class ClockworkCostMatrix {
203
189
  * Creates a new cost matrix within the WASM module. Optionally, a default value
204
190
  * can be provided to initialize all cells in the matrix to that value.
205
191
  */
206
- constructor(_default?: number);
192
+ constructor(_default?: number | null);
207
193
  /**
208
194
  * Gets the cost of a given position in the cost matrix.
209
195
  */
@@ -278,7 +264,7 @@ export class MonoFlowField {
278
264
  /**
279
265
  * Set the direction for a given coordinate.
280
266
  */
281
- set(x: number, y: number, value?: Direction): void;
267
+ set(x: number, y: number, value?: Direction | null): void;
282
268
  }
283
269
  /**
284
270
  * Maps distance values across multiple rooms, storing a DistanceMap for each room
@@ -360,7 +346,7 @@ export class MultiroomMonoFlowField {
360
346
  /**
361
347
  * Sets the direction at a given position
362
348
  */
363
- set(packed_pos: number, direction?: Direction): void;
349
+ set(packed_pos: number, direction?: Direction | null): void;
364
350
  /**
365
351
  * Gets the list of rooms in the flow field
366
352
  */
@@ -420,52 +406,43 @@ export class SearchGoal {
420
406
  readonly pos: any;
421
407
  readonly range: number;
422
408
  }
409
+ /**
410
+ * A distance map search returns both the distance map (filled out
411
+ * with all tiles explored) and the targets found. These aren't necessarily
412
+ * the same positions specified as targets - if the target range is 5, then
413
+ * this is the first position in range 5 of the target. If multiple targets
414
+ * are specified, and you care about matching the found target with one of
415
+ * the original targets, you can iterate through your list and figure out the
416
+ * ones that are in range of the found target(s).
417
+ */
418
+ export class SearchResult {
419
+ private constructor();
420
+ free(): void;
421
+ readonly distance_map: MultiroomDistanceMap;
422
+ readonly found_targets: Uint32Array;
423
+ readonly ops: number;
424
+ }
423
425
 
424
426
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
425
427
 
426
428
  export interface InitOutput {
427
429
  readonly memory: WebAssembly.Memory;
428
- readonly js_bfs_multiroom_flow_field: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
429
- readonly js_dijkstra_distance_map: (a: number, b: number, c: number) => number;
430
- readonly js_path_to_flow_field_origin: (a: number, b: number) => number;
431
- readonly __wbg_flowfield_free: (a: number, b: number) => void;
432
- readonly flowfield_get: (a: number, b: number, c: number) => number;
433
- readonly flowfield_set: (a: number, b: number, c: number, d: number) => void;
434
- readonly flowfield_getDirections: (a: number, b: number, c: number, d: number) => void;
435
- readonly flowfield_setDirections: (a: number, b: number, c: number, d: number, e: number) => void;
436
- readonly flowfield_addDirection: (a: number, b: number, c: number, d: number) => void;
437
- readonly js_bfs_distance_map: (a: number, b: number, c: number) => number;
438
- readonly js_dijkstra_multiroom_distance_map: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
439
- readonly js_dijkstra_multiroom_flow_field: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
440
- readonly js_bfs_multiroom_distance_map: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
441
- readonly js_dijkstra_flow_field: (a: number, b: number, c: number) => number;
442
- readonly js_dijkstra_multiroom_mono_flow_field: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
443
- readonly js_path_to_multiroom_distance_map_origin: (a: number, b: number) => number;
430
+ readonly js_astar_multiroom_distance_map: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => number;
444
431
  readonly __wbg_clockworkcostmatrix_free: (a: number, b: number) => void;
445
432
  readonly clockworkcostmatrix_new: (a: number) => number;
446
433
  readonly clockworkcostmatrix_get: (a: number, b: number, c: number) => number;
447
434
  readonly clockworkcostmatrix_set: (a: number, b: number, c: number, d: number) => void;
448
- readonly js_bfs_flow_field: (a: number, b: number, c: number) => number;
449
- readonly js_path_to_mono_flow_field_origin: (a: number, b: number) => number;
435
+ readonly __wbg_searchresult_free: (a: number, b: number) => void;
436
+ readonly searchresult_distance_map: (a: number) => number;
437
+ readonly searchresult_found_targets: (a: number, b: number) => void;
438
+ readonly searchresult_ops: (a: number) => number;
450
439
  readonly js_path_to_multiroom_mono_flow_field_origin: (a: number, b: number) => number;
451
- readonly __wbg_multiroomdistancemap_free: (a: number, b: number) => void;
452
- readonly multiroomdistancemap_js_new: () => number;
453
- readonly multiroomdistancemap_get: (a: number, b: number) => number;
454
- readonly multiroomdistancemap_set: (a: number, b: number, c: number) => void;
455
- readonly multiroomdistancemap_get_rooms: (a: number, b: number) => void;
456
- readonly multiroomdistancemap_get_room: (a: number, b: number) => number;
457
440
  readonly __wbg_multiroommonoflowfield_free: (a: number, b: number) => void;
441
+ readonly multiroommonoflowfield_js_new: () => number;
458
442
  readonly multiroommonoflowfield_get: (a: number, b: number) => number;
459
443
  readonly multiroommonoflowfield_set: (a: number, b: number, c: number) => void;
460
444
  readonly multiroommonoflowfield_getRooms: (a: number, b: number) => void;
461
445
  readonly multiroommonoflowfield_getRoom: (a: number, b: number) => number;
462
- readonly multiroommonoflowfield_js_new: () => number;
463
- readonly js_bfs_multiroom_mono_flow_field: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
464
- readonly __wbg_monoflowfield_free: (a: number, b: number) => void;
465
- readonly monoflowfield_get: (a: number, b: number, c: number) => number;
466
- readonly monoflowfield_set: (a: number, b: number, c: number, d: number) => void;
467
- readonly js_bfs_mono_flow_field: (a: number, b: number, c: number) => number;
468
- readonly js_path_to_distance_map_origin: (a: number, b: number) => number;
469
446
  readonly js_path_to_multiroom_flow_field_origin: (a: number, b: number) => number;
470
447
  readonly __wbg_multiroomflowfield_free: (a: number, b: number) => void;
471
448
  readonly multiroomflowfield_js_new: () => number;
@@ -476,11 +453,25 @@ export interface InitOutput {
476
453
  readonly multiroomflowfield_getDirections: (a: number, b: number, c: number) => void;
477
454
  readonly multiroomflowfield_setDirections: (a: number, b: number, c: number, d: number) => void;
478
455
  readonly multiroomflowfield_addDirection: (a: number, b: number, c: number) => void;
479
- readonly js_dijkstra_mono_flow_field: (a: number, b: number, c: number) => number;
456
+ readonly get_terrain_cost_matrix: (a: number, b: number, c: number, d: number) => number;
457
+ readonly multiroomFlowField: (a: number) => number;
458
+ readonly js_dijkstra_multiroom_distance_map: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => number;
480
459
  readonly __wbg_distancemap_free: (a: number, b: number) => void;
481
460
  readonly distancemap_toArray: (a: number, b: number) => void;
482
461
  readonly distancemap_get: (a: number, b: number, c: number) => number;
483
462
  readonly distancemap_set: (a: number, b: number, c: number, d: number) => void;
463
+ readonly __wbg_flowfield_free: (a: number, b: number) => void;
464
+ readonly flowfield_get: (a: number, b: number, c: number) => number;
465
+ readonly flowfield_set: (a: number, b: number, c: number, d: number) => void;
466
+ readonly flowfield_getDirections: (a: number, b: number, c: number, d: number) => void;
467
+ readonly flowfield_setDirections: (a: number, b: number, c: number, d: number, e: number) => void;
468
+ readonly flowfield_addDirection: (a: number, b: number, c: number, d: number) => void;
469
+ readonly js_bfs_multiroom_distance_map: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => number;
470
+ readonly __wbg_monoflowfield_free: (a: number, b: number) => void;
471
+ readonly monoflowfield_get: (a: number, b: number, c: number) => number;
472
+ readonly monoflowfield_set: (a: number, b: number, c: number, d: number) => void;
473
+ readonly version: (a: number) => void;
474
+ readonly get_range: (a: number, b: number) => number;
484
475
  readonly __wbg_path_free: (a: number, b: number) => void;
485
476
  readonly __wbg_pathfatigue_free: (a: number, b: number) => void;
486
477
  readonly path_add: (a: number, b: number) => void;
@@ -491,10 +482,16 @@ export interface InitOutput {
491
482
  readonly path_to_array_reversed: (a: number, b: number) => void;
492
483
  readonly pathfatigue_new: (a: number) => number;
493
484
  readonly pathfatigue_refresh: (a: number, b: number) => void;
494
- readonly pathfatigue_moveTime: (a: number, b: number) => number;
495
- readonly version: (a: number) => void;
496
- readonly get_range: (a: number, b: number) => number;
497
485
  readonly pathfatigue_len: (a: number) => number;
486
+ readonly pathfatigue_moveTime: (a: number, b: number) => number;
487
+ readonly multiroomMonoFlowField: (a: number) => number;
488
+ readonly js_path_to_multiroom_distance_map_origin: (a: number, b: number) => number;
489
+ readonly __wbg_multiroomdistancemap_free: (a: number, b: number) => void;
490
+ readonly multiroomdistancemap_js_new: () => number;
491
+ readonly multiroomdistancemap_get: (a: number, b: number) => number;
492
+ readonly multiroomdistancemap_set: (a: number, b: number, c: number) => void;
493
+ readonly multiroomdistancemap_get_rooms: (a: number, b: number) => void;
494
+ readonly multiroomdistancemap_get_room: (a: number, b: number) => number;
498
495
  readonly __wbg_searchgoal_free: (a: number, b: number) => void;
499
496
  readonly searchgoal_pos: (a: number) => number;
500
497
  readonly searchgoal_range: (a: number) => number;
@@ -0,0 +1,35 @@
1
+ import { ClockworkCostMatrix } from '../wasm/screeps_clockwork';
2
+ /**
3
+ * Create a distance map for the given start positions, using a breadth-first search.
4
+ * This does not factor in terrain costs (treating anything less than 255 in the cost
5
+ * matrix as passable), so it's faster but less useful than Dijkstra's algorithm.
6
+ *
7
+ * This calculates a distance map across multiple rooms, with a few configurable limits:
8
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
9
+ * - `maxRooms`: The maximum number of rooms to explore.
10
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
11
+ *
12
+ * At least one of these limits must be set.
13
+ *
14
+ * @param start - The starting positions.
15
+ * @param options - The options for the distance map.
16
+ * @returns A multi-room distance map.
17
+ */
18
+ export declare function astarMultiroomDistanceMap(start: RoomPosition[], { costMatrixCallback, maxRooms, maxOps, maxPathCost, anyOfDestinations, allOfDestinations }: {
19
+ costMatrixCallback: (room: string) => ClockworkCostMatrix | undefined;
20
+ maxRooms?: number;
21
+ maxOps?: number;
22
+ maxPathCost?: number;
23
+ anyOfDestinations?: {
24
+ pos: RoomPosition;
25
+ range: number;
26
+ }[];
27
+ allOfDestinations?: {
28
+ pos: RoomPosition;
29
+ range: number;
30
+ }[];
31
+ }): {
32
+ distanceMap: import("./multiroomDistanceMap").ClockworkMultiroomDistanceMap;
33
+ foundTargets: RoomPosition[];
34
+ ops: number;
35
+ };
@@ -1,35 +1,13 @@
1
1
  import { ClockworkCostMatrix } from '../wasm/screeps_clockwork';
2
- import { ClockworkDistanceMap } from './distanceMap';
3
- import { ClockworkMultiroomDistanceMap } from './multiroomDistanceMap';
4
- /**
5
- * Generate a [distance map](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
6
- * using a breadth-first search algorithm.
7
- *
8
- * The BFS algorithm doesn't include variable costs, and only considers
9
- * values of 255 (impassible) in the provided cost matrix. Any other
10
- * values are ignored.
11
- *
12
- * This might be useful for creeps with only MOVE parts and/or empty
13
- * CARRY parts, which don't generate fatigue.
14
- *
15
- * Note that the `roomName` on start positions is ignored - all positions
16
- * are assumed to be in the same room as the cost matrix.
17
- *
18
- * @param start - The starting positions.
19
- * @param costMatrix - The cost matrix to use for the flow field.
20
- * @returns The flow field.
21
- */
22
- export declare function bfsDistanceMap(start: RoomPosition[], costMatrix: ClockworkCostMatrix): ClockworkDistanceMap;
23
2
  /**
24
3
  * Create a distance map for the given start positions, using a breadth-first search.
25
4
  * This does not factor in terrain costs (treating anything less than 255 in the cost
26
5
  * matrix as passable), so it's faster but less useful than Dijkstra's algorithm.
27
6
  *
28
7
  * This calculates a distance map across multiple rooms, with a few configurable limits:
29
- * - `maxTiles`: The maximum number of tiles to explore.
8
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
30
9
  * - `maxRooms`: The maximum number of rooms to explore.
31
- * - `maxRoomDistance`: Don't explore rooms further (in Manhattan distance) than this.
32
- * - `maxTileDistance`: Don't explore tiles further (in Chebyshev distance) than this.
10
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
33
11
  *
34
12
  * At least one of these limits must be set.
35
13
  *
@@ -37,10 +15,21 @@ export declare function bfsDistanceMap(start: RoomPosition[], costMatrix: Clockw
37
15
  * @param options - The options for the distance map.
38
16
  * @returns A multi-room distance map.
39
17
  */
40
- export declare function bfsMultiroomDistanceMap(start: RoomPosition[], { costMatrixCallback, maxTiles, maxRooms, maxRoomDistance, maxTileDistance }: {
18
+ export declare function bfsMultiroomDistanceMap(start: RoomPosition[], { costMatrixCallback, maxOps, maxRooms, maxPathCost, anyOfDestinations, allOfDestinations }: {
41
19
  costMatrixCallback: (room: string) => ClockworkCostMatrix | undefined;
42
- maxTiles?: number;
20
+ maxOps?: number;
43
21
  maxRooms?: number;
44
- maxRoomDistance?: number;
45
- maxTileDistance?: number;
46
- }): ClockworkMultiroomDistanceMap;
22
+ maxPathCost?: number;
23
+ anyOfDestinations?: {
24
+ pos: RoomPosition;
25
+ range: number;
26
+ }[];
27
+ allOfDestinations?: {
28
+ pos: RoomPosition;
29
+ range: number;
30
+ }[];
31
+ }): {
32
+ distanceMap: import("./multiroomDistanceMap").ClockworkMultiroomDistanceMap;
33
+ foundTargets: RoomPosition[];
34
+ ops: number;
35
+ };
@@ -1,32 +1,12 @@
1
1
  import { ClockworkCostMatrix } from '../wasm/screeps_clockwork';
2
- import { ClockworkDistanceMap } from './distanceMap';
3
- import { ClockworkMultiroomDistanceMap } from './multiroomDistanceMap';
4
- /**
5
- * Generate a [distance map](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
6
- * using Dijkstra's algorithm.
7
- *
8
- * Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
9
- *
10
- * Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
11
- * a cost matrix with a default value of at least 1.
12
- *
13
- * Note that the `roomName` on start positions is ignored - all positions
14
- * are assumed to be in the same room as the cost matrix.
15
- *
16
- * @param start - The starting positions.
17
- * @param costMatrix - The cost matrix to use for the flow field.
18
- * @returns The flow field.
19
- */
20
- export declare function dijkstraDistanceMap(start: RoomPosition[], costMatrix: ClockworkCostMatrix): ClockworkDistanceMap;
21
2
  /**
22
3
  * Create a distance map for the given start positions, using Dijkstra's algorithm to
23
4
  * factor in terrain costs (0-255, where 255 is impassable).
24
5
  *
25
6
  * This calculates a distance map across multiple rooms, with a few configurable limits:
26
- * - `maxTiles`: The maximum number of tiles to explore.
7
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
27
8
  * - `maxRooms`: The maximum number of rooms to explore.
28
- * - `maxRoomDistance`: Don't explore rooms further (in Manhattan distance) than this.
29
- * - `maxTileDistance`: Don't explore tiles further (in accumulated cost) than this.
9
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
30
10
  *
31
11
  * At least one of these limits must be set.
32
12
  *
@@ -34,10 +14,21 @@ export declare function dijkstraDistanceMap(start: RoomPosition[], costMatrix: C
34
14
  * @param options - The options for the distance map.
35
15
  * @returns A multi-room distance map.
36
16
  */
37
- export declare function dijkstraMultiroomDistanceMap(start: RoomPosition[], { costMatrixCallback, maxTiles, maxRooms, maxRoomDistance, maxTileDistance }: {
17
+ export declare function dijkstraMultiroomDistanceMap(start: RoomPosition[], { costMatrixCallback, maxOps, maxRooms, maxPathCost, anyOfDestinations, allOfDestinations }: {
38
18
  costMatrixCallback: (room: string) => ClockworkCostMatrix | undefined;
39
- maxTiles?: number;
19
+ maxOps?: number;
40
20
  maxRooms?: number;
41
- maxRoomDistance?: number;
42
- maxTileDistance?: number;
43
- }): ClockworkMultiroomDistanceMap;
21
+ maxPathCost?: number;
22
+ anyOfDestinations?: {
23
+ pos: RoomPosition;
24
+ range: number;
25
+ }[];
26
+ allOfDestinations?: {
27
+ pos: RoomPosition;
28
+ range: number;
29
+ }[];
30
+ }): {
31
+ distanceMap: import("./multiroomDistanceMap").ClockworkMultiroomDistanceMap;
32
+ foundTargets: RoomPosition[];
33
+ ops: number;
34
+ };
@@ -1,5 +1,4 @@
1
1
  import { DistanceMap } from '../wasm/screeps_clockwork';
2
- import { Path } from './path';
3
2
  /**
4
3
  * A distance map for a single room.
5
4
  */
@@ -22,8 +21,4 @@ export declare class ClockworkDistanceMap {
22
21
  * Frees the memory allocated for this distance map.
23
22
  */
24
23
  free(): void;
25
- /**
26
- * Path to the origin from a given position.
27
- */
28
- pathToOrigin(start: RoomPosition): Path;
29
24
  }
@@ -1,5 +1,4 @@
1
1
  import { FlowField } from '../wasm/screeps_clockwork';
2
- import { Path } from './path';
3
2
  /**
4
3
  * A flow field for a single room that stores multiple directions per tile.
5
4
  */
@@ -30,9 +29,4 @@ export declare class ClockworkFlowField {
30
29
  * Free the memory allocated for this flow field.
31
30
  */
32
31
  free(): void;
33
- /**
34
- * Given a flow field (for a single room), find the path from a given position to
35
- * the origin. Never paths through other rooms.
36
- */
37
- pathToOrigin(start: RoomPosition): Path;
38
32
  }
@@ -0,0 +1,6 @@
1
+ import { ClockworkCostMatrix } from '../wasm/screeps_clockwork';
2
+ export declare function getTerrainCostMatrix(roomName: string, { plainCost, swampCost, wallCost }?: {
3
+ plainCost?: number;
4
+ swampCost?: number;
5
+ wallCost?: number;
6
+ }): ClockworkCostMatrix;
@@ -1,5 +1,4 @@
1
1
  import { MonoFlowField } from '../wasm/screeps_clockwork';
2
- import { Path } from './path';
3
2
  /**
4
3
  * A flow field for a single room that stores one direction per tile.
5
4
  */
@@ -18,9 +17,4 @@ export declare class ClockworkMonoFlowField {
18
17
  * Free the memory allocated for this flow field.
19
18
  */
20
19
  free(): void;
21
- /**
22
- * Given a monodirectional flow field (for a single room), find the path from a given position to
23
- * the origin. Never paths through other rooms.
24
- */
25
- pathToOrigin(start: RoomPosition): Path;
26
20
  }
@@ -1,5 +1,7 @@
1
1
  import { DistanceMap, MultiroomDistanceMap } from '../wasm/screeps_clockwork';
2
- import { Path } from './path';
2
+ import { ClockworkMultiroomFlowField } from './multiroomFlowField';
3
+ import { ClockworkMultiroomMonoFlowField } from './multiroomMonoFlowField';
4
+ import { ClockworkPath } from './path';
3
5
  /**
4
6
  * A distance map that covers multiple rooms. Typically returned by a function
5
7
  * like `bfsMultiroomDistanceMap` rather than created directly.
@@ -30,5 +32,13 @@ export declare class ClockworkMultiroomDistanceMap {
30
32
  /**
31
33
  * Path to the origin from a given position.
32
34
  */
33
- pathToOrigin(start: RoomPosition): Path;
35
+ pathToOrigin(start: RoomPosition): ClockworkPath;
36
+ /**
37
+ * Flow field for this distance map.
38
+ */
39
+ toFlowField(): ClockworkMultiroomFlowField;
40
+ /**
41
+ * Mono-directional flow field for this distance map.
42
+ */
43
+ toMonoFlowField(): ClockworkMultiroomMonoFlowField;
34
44
  }
@@ -1,6 +1,6 @@
1
1
  import { MultiroomFlowField } from '../wasm/screeps_clockwork';
2
2
  import { ClockworkFlowField } from './flowField';
3
- import { Path } from './path';
3
+ import { ClockworkPath } from './path';
4
4
  /**
5
5
  * A flow field that spans multiple rooms, storing multiple directions per tile.
6
6
  */
@@ -38,7 +38,7 @@ export declare class ClockworkMultiroomFlowField {
38
38
  /**
39
39
  * Find a path from a given position to the origin of the flow field.
40
40
  */
41
- pathToOrigin(start: RoomPosition): Path;
41
+ pathToOrigin(start: RoomPosition): ClockworkPath;
42
42
  /**
43
43
  * Free the memory allocated for this flow field.
44
44
  */
@@ -1,6 +1,6 @@
1
1
  import { MultiroomMonoFlowField } from '../wasm/screeps_clockwork';
2
2
  import { ClockworkMonoFlowField } from './monoFlowField';
3
- import { Path } from './path';
3
+ import { ClockworkPath } from './path';
4
4
  /**
5
5
  * A flow field that spans multiple rooms, storing a single direction per tile.
6
6
  */
@@ -26,7 +26,7 @@ export declare class ClockworkMultiroomMonoFlowField {
26
26
  /**
27
27
  * Find a path from a given position to the origin of the flow field.
28
28
  */
29
- pathToOrigin(start: RoomPosition): Path;
29
+ pathToOrigin(start: RoomPosition): ClockworkPath;
30
30
  /**
31
31
  * Free the memory allocated for this flow field.
32
32
  */
@@ -1,11 +1,11 @@
1
- import { Path as ClockworkPath } from '../wasm/screeps_clockwork';
1
+ import { Path } from '../wasm/screeps_clockwork';
2
2
  /**
3
3
  * A path from a start position to an end position. Typically returned by a
4
4
  * function like `pathToFlowFieldOrigin` rather than created directly.
5
5
  */
6
- export declare class Path {
6
+ export declare class ClockworkPath {
7
7
  private readonly path;
8
- constructor(path: ClockworkPath);
8
+ constructor(path: Path);
9
9
  /**
10
10
  * Iterate over the path.
11
11
  *
@@ -0,0 +1,7 @@
1
+ import { SearchResult } from '../wasm/screeps_clockwork';
2
+ import { ClockworkMultiroomDistanceMap } from './multiroomDistanceMap';
3
+ export declare function fromPackedSearchResult(result: SearchResult): {
4
+ distanceMap: ClockworkMultiroomDistanceMap;
5
+ foundTargets: RoomPosition[];
6
+ ops: number;
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screeps-clockwork",
3
- "version": "0.5.0",
3
+ "version": "0.7.1",
4
4
  "description": "A WASM movement library for Screeps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -9,6 +9,7 @@
9
9
  "build:lib": "wasm-pack build --target web --out-dir src/wasm --config build.rustflags=[\\'-Ctarget-feature=-reference-types\\',\\'-Ctarget-feature=-multivalue\\',\\'-Ctarget-feature=-sign-ext\\'] -Z build-std=std,panic_abort",
10
10
  "build:src": "rollup -c",
11
11
  "build:docs": "typedoc",
12
+ "build:pserver": "run-s build:lib build:src && rollup -c --environment DEST:pserver",
12
13
  "watch": "run-s build watch:both",
13
14
  "watch:lib": "cargo-watch -w lib -s \"npm run build:lib\"",
14
15
  "watch:src": "wait-on src/wasm/screeps_clockwork_bg.wasm && rollup -cw",
@@ -33,7 +34,7 @@
33
34
  "homepage": "https://github.com/glitchassassin/screeps-clockwork#readme",
34
35
  "devDependencies": {
35
36
  "@rollup/plugin-commonjs": "^28.0.1",
36
- "@rollup/plugin-node-resolve": "^15.1.0",
37
+ "@rollup/plugin-node-resolve": "^16.0.0",
37
38
  "@rollup/plugin-typescript": "^12.1.1",
38
39
  "@rollup/plugin-wasm": "^6.2.2",
39
40
  "@types/node": "^22.10.1",
@@ -48,6 +49,7 @@
48
49
  "rollup-plugin-copy": "^3.5.0",
49
50
  "rollup-plugin-screeps": "^1.0.1",
50
51
  "source-map": "0.6.1",
52
+ "tslib": "^2.8.1",
51
53
  "typedoc": "^0.27.3",
52
54
  "typescript": "^5.7.2"
53
55
  },