@pocketrts/grid 0.1.0 → 0.2.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/README.md +73 -2
- package/dist/formation.d.ts +23 -1
- package/dist/formation.js +43 -5
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/march.d.ts +77 -0
- package/dist/march.js +665 -0
- package/dist/marchChoke.d.ts +27 -0
- package/dist/marchChoke.js +140 -0
- package/dist/marchGround.d.ts +45 -0
- package/dist/marchGround.js +73 -0
- package/dist/marchSlots.d.ts +66 -0
- package/dist/marchSlots.js +215 -0
- package/dist/marchTrail.d.ts +48 -0
- package/dist/marchTrail.js +282 -0
- package/dist/marchTypes.d.ts +289 -0
- package/dist/marchTypes.js +31 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @pocketrts/grid
|
|
2
2
|
|
|
3
|
-
Grid algorithms for real-time strategy games on an 8-connected cell grid: flow fields shared by whole armies and computed under a fixed per-step budget, bounded local A*, straight-line reach, nearest free cell, distance fields, bucket grids for neighbour queries, field of view, polygons, 8-connected wall chains and
|
|
3
|
+
Grid algorithms for real-time strategy games on an 8-connected cell grid: flow fields shared by whole armies and computed under a fixed per-step budget, bounded local A*, straight-line reach, nearest free cell, distance fields, bucket grids for neighbour queries, field of view, polygons, 8-connected wall chains, line formations and a complete elastic-column march system. Pure logic over typed arrays, deterministic (only `@pocketrts/determinism` math), no DOM. Extracted from Pocket War, where it moves thousands of units.
|
|
4
4
|
|
|
5
5
|
Try it: [`apps/grid-demo`](../../apps/grid-demo) (`pnpm --filter @pocketrts/grid-demo dev`).
|
|
6
6
|
|
|
@@ -33,7 +33,17 @@ ES module, TypeScript types included. Depends on `@pocketrts/determinism`.
|
|
|
33
33
|
| `stampDisc(vis, stamped, w, h, cx, cy, r)` | Reveal a disc of cells; repeated stamps from one cell cost nothing. |
|
|
34
34
|
| `inPolygon(points, x, y)`, `polygonDist(points, x, y)` | Even–odd containment and distance to the outline of a flat `[x0, y0, x1, y1, …]` polygon. |
|
|
35
35
|
| `stepCells`, `ringChain`, `chainLinks`, `chainOutSides` | 8-connected chains (walls, fences): cells between two points, a closed chain through waypoints with loops and extra corner cells removed, which neighbours a chain cell joins, which side of each joined segment faces out. |
|
|
36
|
-
| `lineFormation(units, cx, cy, dx, dy, positions?, options?)`, `FormationUnit`, `Formation`, `FormationOptions`, `DEFAULT_FORMATION_OPTIONS` | Ranks facing a direction: one rank class per rank (lower in front), frontage from the group's footprint; with current positions, members keep their lateral order so paths do not cross. Returns spots, offsets, rank and place per member, and per-rank width, depth, count, radius and slowest speed. |
|
|
36
|
+
| `lineFormation(units, cx, cy, dx, dy, positions?, options?)`, `FormationUnit`, `Formation`, `FormationOptions`, `DEFAULT_FORMATION_OPTIONS` | Ranks facing a direction: one rank class per rank (lower in front), frontage from the group's footprint (with `taper`, the ranks in front narrower: a wedge); with current positions, members keep their lateral order so paths do not cross. Returns spots, offsets, rank and place per member, and per-rank width, depth, count, radius and slowest speed. |
|
|
37
|
+
| `formationShape(shape, scale?)`, `FormationShape`, `FORMATION_SHAPES` | The `lineFormation` options of a named shape (`line`, `column`, `wedge`, `loose`), scaled for another world. A shape is only ranks, so `createMarch` carries it unchanged: a march keeps its formation on the way and at the goal. |
|
|
38
|
+
| `MarchRules`, `DEFAULT_MARCH_RULES`, `marchRules(scale, overrides?)` | The march system's tunable values (distances, speeds' limits, turning, folding, engagement) and the defaults, made for a world of cells of about 32 units; `marchRules` scales the distances for another world. |
|
|
39
|
+
| `MarchGround`, `GridGround`, `GridGroundOptions` | What the game gives the march about its map, per movement layer (cells, passability, lines of sight, routes, ground speed), and a ready-made implementation for a plain grid of open and blocked cells. |
|
|
40
|
+
| `MarchMembers`, `MEMBER_OUT`, `MEMBER_ENGAGED`, `MEMBER_OPPOSED`, `MEMBER_FREE` | What the game gives the march about its units (position, march, rank, place, lateral offset, condition flags) and the condition flags. |
|
|
41
|
+
| `March` | The state of one marching group: the front rank and the probe ahead of it, the trail, the ranks' current widths and lengths, arrival and hold flags. The game reads it; only the march functions write it. |
|
|
42
|
+
| `createMarch(marches, ground, rules, order)`, `MarchOrder`, `rerouteMarch(...)` | Set a group marching from the ranks of a `lineFormation` (reusing a dead entry of `marches`), or turn a group already marching onto a new goal without forming up again (false: the new route turns back, start a new march). |
|
|
43
|
+
| `updateMarches(marches, grounds, members, rules, dt, tick)` | Advance every march one step: tally the members, move the probe and the front rank, settle holding, arriving, breaking up and winding up. Once per step, before the members move. |
|
|
44
|
+
| `steerMember(...)`, `STEER`, `STEER_IDLE`, `STEER_LEAVE`, `STEER_PUSH`, `STEER_APART`, `STEER_KEEP` | What one member does this step: keep its place (a velocity), find its own way or push on along its own route (a speed), leave the march, or act as if it had no march. |
|
|
45
|
+
| `marchSlot`, `marchFollow`, `marchRelease`, `MARCH_SLOT`, `MARCH_FOLLOW`, `FOLLOW_SLOT`, `FOLLOW_SQUEEZE`, `FOLLOW_APART` | The pieces of `steerMember` for games that steer members their own way: a member's place in the column, the point it heads for, and whether it should leave while the column winds up. |
|
|
46
|
+
| `marchTrailAt(march, rules, b)`, `MARCH_POINT` | A point of the trail at distance `b` behind the probe, with its heading and usable width on each side; for drawing the column's route. |
|
|
37
47
|
| `DIRX`, `DIRY`, `DIR_HERE`, `DIR_NONE` | Direction tables and markers. |
|
|
38
48
|
|
|
39
49
|
## Usage
|
|
@@ -67,6 +77,60 @@ setWall(cell);
|
|
|
67
77
|
fields.invalidate();
|
|
68
78
|
```
|
|
69
79
|
|
|
80
|
+
A group of units marching as an elastic column (the ranks bend round corners, close up and fold at gates, spread out again). The game owns the units, their spots at the goal and their collisions; units are plain arrays here, `units` holds `{ row, radius, speed }` per unit with speeds in world units per second:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import {
|
|
84
|
+
cornerFree, createMarch, FlowFields, GridGround, lineFormation, marchRules, STEER, STEER_APART, STEER_KEEP, STEER_LEAVE,
|
|
85
|
+
STEER_PUSH, steerMember, updateMarches, type March, type MarchMembers,
|
|
86
|
+
} from '@pocketrts/grid';
|
|
87
|
+
|
|
88
|
+
// The map: one ground per movement layer (the outer ring of `block` must be blocked)
|
|
89
|
+
const fields = new FlowFields(w, h, [{ cost, canStep: () => true, canStepDiag: (a, b) => cornerFree(block, w, a, b) }]);
|
|
90
|
+
const ground = new GridGround({ w, h, cellSize, block, fields });
|
|
91
|
+
const rules = marchRules(cellSize / 32); // the defaults suit cells of 32 units
|
|
92
|
+
|
|
93
|
+
// The units: per-unit arrays the march reads (march: Int16Array filled with -1; apart: Uint8Array)
|
|
94
|
+
const marches: March[] = [];
|
|
95
|
+
const members: MarchMembers = {
|
|
96
|
+
n, alive: () => true, march: i => marchOf[i], leave: i => { marchOf[i] = -1; },
|
|
97
|
+
x: i => px[i], y: i => py[i], row: i => rank[i], col: i => place[i], lateral: i => offset[i],
|
|
98
|
+
apart: i => apart[i] !== 0, state: () => 0, // MEMBER_… flags when units fight
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// An order: lay the ranks out facing (fx, fy) round the goal (gx, gy), then set the group marching
|
|
102
|
+
function order(gx: number, gy: number, fx: number, fy: number) {
|
|
103
|
+
const f = lineFormation(units, gx, gy, fx, fy, positions); // positions: current { x, y } per unit
|
|
104
|
+
const g = createMarch(marches, ground, rules, {
|
|
105
|
+
layer: 0, x: centreX, y: centreY, destX: gx, destY: gy, destCell: ground.cellAt(gx, gy),
|
|
106
|
+
speed: slowest * 0.9, run: slowest, hold: false, fx, fy, formation: f,
|
|
107
|
+
});
|
|
108
|
+
for (let i = 0; i < n; i++) {
|
|
109
|
+
marchOf[i] = g.id; rank[i] = f.row[i]; place[i] = f.col[i]; offset[i] = f.fl[i];
|
|
110
|
+
spotX[i] = f.sx[i]; spotY[i] = f.sy[i]; // the unit's own spot at the goal
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Each step: the march first, then every member as it answers
|
|
115
|
+
function step(tick: number) {
|
|
116
|
+
ground.tick = tick;
|
|
117
|
+
fields.maintain(tick);
|
|
118
|
+
updateMarches(marches, () => ground, members, rules, dt, tick);
|
|
119
|
+
for (let i = 0; i < n; i++) {
|
|
120
|
+
if (marchOf[i] < 0) continue;
|
|
121
|
+
const what = steerMember(ground, marches[marchOf[i]], rules, rank[i], place[i], offset[i], px[i], py[i],
|
|
122
|
+
spotX[i], spotY[i], speed[i], speed[i], false);
|
|
123
|
+
apart[i] = STEER.apart ? 1 : 0; // read before the next call overwrites STEER
|
|
124
|
+
if (what === STEER_KEEP) moveBy(i, STEER.vx * dt, STEER.vy * dt);
|
|
125
|
+
else if (what === STEER_APART || what === STEER_PUSH) walkOwnRoute(i, STEER.speed * dt);
|
|
126
|
+
else if (what === STEER_LEAVE) { marchOf[i] = -1; walkToSpot(i); }
|
|
127
|
+
// STEER_IDLE: move as if there were no march
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
A group already marching that gets a new order goes to `rerouteMarch` first; `apps/grid-demo/src/sim.ts` (`order`, `step`, `marchStep`) is a complete working example.
|
|
133
|
+
|
|
70
134
|
Several sides with different passability (gates that open only for their owner, say) get one layer each; key the cache so different layers never share a key, for example `layer * 1048576 + goalCell`. Sides that always move alike may share keys and fields.
|
|
71
135
|
|
|
72
136
|
## Notes
|
|
@@ -74,3 +138,10 @@ Several sides with different passability (gates that open only for their owner,
|
|
|
74
138
|
- Flow-field costs are integers in tenths; distances are summed as integers, so results do not depend on float rounding.
|
|
75
139
|
- `FlowFields.maintain` refreshes one outdated field at a time, every `refreshEvery` steps, while at most one search is queued; until then units keep using the old directions.
|
|
76
140
|
- `LocalPathfinder`, `BucketGrid` and the flow-field search reuse their buffers: create one per world, or share one when calls never interleave.
|
|
141
|
+
- The march system knows nothing of sides, buildings, combat or weather. Whether a group is compact enough to march together, the members' own spots at the goal, unit collisions and what members do when they find their own way are the game's.
|
|
142
|
+
- Speeds are world units per second, including the `speed` of the units given to `lineFormation`. The defaults suit cells of about 32 units: for other cells use `marchRules(cellSize / 32)` and scale `lineFormation`'s `gap` and `minWidth` alike.
|
|
143
|
+
- `MarchRules.flank` (default off) also keeps ranks clear of an obstacle on one side and of thin obstacles, counts a thin wall that runs on across the column's width as a narrow place, and lets the column turn as tightly as half the usable width where the way is narrower than the column: turn it on where routes run along walls.
|
|
144
|
+
- `MarchRules.faceRoute`, `wheel` and `lookClear` (all off by default) are for rigid formations on routes that hug walls: `faceRoute` forms the column up along the route's first stretch instead of the straight line to the goal, `wheel` makes only the ranks on a bend close up along the trail, and `lookClear` straightens the route toward points that keep clear of walls to each side. With all of them off, the march is exactly the one Pocket War ships (its state checksums are byte-identical on the package).
|
|
145
|
+
- `createMarch` creates the `March` object with its properties in a fixed order, because games hash their state in property order; a game that hashes a march keeps that order.
|
|
146
|
+
- The result objects `STEER`, `MARCH_SLOT`, `MARCH_FOLLOW` and `MARCH_POINT` are shared and overwritten by each call: copy what is needed before the next one.
|
|
147
|
+
- As for flow fields, the outermost ring of the grid must be blocked.
|
package/dist/formation.d.ts
CHANGED
|
@@ -13,8 +13,29 @@ export interface FormationOptions {
|
|
|
13
13
|
minWidth: number;
|
|
14
14
|
/** Frontage = √(total footprint area × aspect), so the block is about `aspect` times wider than deep. Default 2.6. */
|
|
15
15
|
aspect: number;
|
|
16
|
+
/**
|
|
17
|
+
* Wedge: how much wider each rank may be than the one before it, per unit of rank depth; the front rank may be
|
|
18
|
+
* half that times its own depth wide. With 2 and members of one size the ranks hold 1, 3, 5, … members, up to the
|
|
19
|
+
* frontage. Default 0: every rank may be as wide as the frontage.
|
|
20
|
+
*/
|
|
21
|
+
taper: number;
|
|
16
22
|
}
|
|
17
23
|
export declare const DEFAULT_FORMATION_OPTIONS: Readonly<FormationOptions>;
|
|
24
|
+
/** The shapes `formationShape` knows. */
|
|
25
|
+
export type FormationShape = 'line' | 'column' | 'wedge' | 'loose';
|
|
26
|
+
export declare const FORMATION_SHAPES: readonly FormationShape[];
|
|
27
|
+
/**
|
|
28
|
+
* The options of a named shape, for `lineFormation`:
|
|
29
|
+
* - `line`: the defaults, a block about 2.6 times wider than deep;
|
|
30
|
+
* - `column`: a block about three times deeper than wide, for the march;
|
|
31
|
+
* - `wedge`: a point in front, each rank one member wider on each side than the one before;
|
|
32
|
+
* - `loose`: a line with a member's width of room between neighbours.
|
|
33
|
+
*
|
|
34
|
+
* Whatever its shape, a formation is ranks, so a march carries it the same way (see `createMarch`).
|
|
35
|
+
* @param scale The size of the world relative to the one the defaults were made for (members about 12 across): the
|
|
36
|
+
* options that are lengths are multiplied by it, as `marchRules` does for the march.
|
|
37
|
+
*/
|
|
38
|
+
export declare function formationShape(shape: FormationShape, scale?: number): FormationOptions;
|
|
18
39
|
/** The result of `lineFormation`, per member (in input order) and per rank (front to back). */
|
|
19
40
|
export interface Formation {
|
|
20
41
|
/** Each member's spot. */
|
|
@@ -41,7 +62,8 @@ export interface Formation {
|
|
|
41
62
|
/**
|
|
42
63
|
* Ranks centred on (cx, cy) facing (dx, dy) (any length; a zero vector faces −y). Members are sorted by rank class,
|
|
43
64
|
* then front to back by their current position when `positions` is given, then by input order, and poured into ranks
|
|
44
|
-
* no wider than the frontage
|
|
65
|
+
* no wider than the frontage (with `taper`, the ranks in front narrower still: a wedge), a new rank starting at each
|
|
66
|
+
* class change. Within a rank, members keep that order, or
|
|
45
67
|
* with `positions` are placed left to right by current lateral position, which keeps paths from crossing. Facing east
|
|
46
68
|
* (+x), the left-to-right axis is +y.
|
|
47
69
|
* @param positions Each member's current position, in input order.
|
package/dist/formation.js
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Formations: arrange a group of units in ranks facing a direction, as a line, a column, a wedge or a loose line. */
|
|
2
2
|
import { dmath } from '@pocketrts/determinism';
|
|
3
|
-
export const DEFAULT_FORMATION_OPTIONS = Object.freeze({ gap: 3, minWidth: 48, aspect: 2.6 });
|
|
3
|
+
export const DEFAULT_FORMATION_OPTIONS = Object.freeze({ gap: 3, minWidth: 48, aspect: 2.6, taper: 0 });
|
|
4
|
+
export const FORMATION_SHAPES = ['line', 'column', 'wedge', 'loose'];
|
|
5
|
+
/**
|
|
6
|
+
* The options of a named shape, for `lineFormation`:
|
|
7
|
+
* - `line`: the defaults, a block about 2.6 times wider than deep;
|
|
8
|
+
* - `column`: a block about three times deeper than wide, for the march;
|
|
9
|
+
* - `wedge`: a point in front, each rank one member wider on each side than the one before;
|
|
10
|
+
* - `loose`: a line with a member's width of room between neighbours.
|
|
11
|
+
*
|
|
12
|
+
* Whatever its shape, a formation is ranks, so a march carries it the same way (see `createMarch`).
|
|
13
|
+
* @param scale The size of the world relative to the one the defaults were made for (members about 12 across): the
|
|
14
|
+
* options that are lengths are multiplied by it, as `marchRules` does for the march.
|
|
15
|
+
*/
|
|
16
|
+
export function formationShape(shape, scale = 1) {
|
|
17
|
+
const o = { ...DEFAULT_FORMATION_OPTIONS };
|
|
18
|
+
if (shape === 'column')
|
|
19
|
+
o.aspect = 0.3;
|
|
20
|
+
else if (shape === 'wedge') {
|
|
21
|
+
o.aspect = 4;
|
|
22
|
+
o.taper = 2;
|
|
23
|
+
}
|
|
24
|
+
else if (shape === 'loose')
|
|
25
|
+
o.gap = 12;
|
|
26
|
+
o.gap *= scale;
|
|
27
|
+
o.minWidth *= scale;
|
|
28
|
+
return o;
|
|
29
|
+
}
|
|
4
30
|
/**
|
|
5
31
|
* Ranks centred on (cx, cy) facing (dx, dy) (any length; a zero vector faces −y). Members are sorted by rank class,
|
|
6
32
|
* then front to back by their current position when `positions` is given, then by input order, and poured into ranks
|
|
7
|
-
* no wider than the frontage
|
|
33
|
+
* no wider than the frontage (with `taper`, the ranks in front narrower still: a wedge), a new rank starting at each
|
|
34
|
+
* class change. Within a rank, members keep that order, or
|
|
8
35
|
* with `positions` are placed left to right by current lateral position, which keeps paths from crossing. Facing east
|
|
9
36
|
* (+x), the left-to-right axis is +y.
|
|
10
37
|
* @param positions Each member's current position, in input order.
|
|
11
38
|
*/
|
|
12
39
|
export function lineFormation(units, cx, cy, dx, dy, positions = null, options = {}) {
|
|
13
|
-
const { gap, minWidth, aspect } = { ...DEFAULT_FORMATION_OPTIONS, ...options };
|
|
40
|
+
const { gap, minWidth, aspect, taper } = { ...DEFAULT_FORMATION_OPTIONS, ...options };
|
|
14
41
|
const n = units.length;
|
|
15
42
|
const sx = new Float32Array(n), sy = new Float32Array(n), fa = new Float32Array(n), fl = new Float32Array(n);
|
|
16
43
|
const row = new Int16Array(n), col = new Int16Array(n);
|
|
@@ -42,17 +69,28 @@ export function lineFormation(units, cx, cy, dx, dy, positions = null, options =
|
|
|
42
69
|
const width = Math.max(minWidth, Math.sqrt(area * aspect));
|
|
43
70
|
const rows = [];
|
|
44
71
|
let cur = [], curW = 0, curRow = -1;
|
|
72
|
+
// For a wedge: the depth of the ranks poured so far, the depth of the rank being poured, and how wide it may be
|
|
73
|
+
let before = 0, curD = 0, limit = width;
|
|
45
74
|
for (const m of idx) {
|
|
46
75
|
const u = units[m];
|
|
47
76
|
const sp = u.radius * 2 + gap;
|
|
48
|
-
if (
|
|
77
|
+
if (taper > 0 && !cur.length)
|
|
78
|
+
limit = Math.min(width, taper * (before + sp / 2));
|
|
79
|
+
if (cur.length && (curW + sp > limit || u.row !== curRow)) {
|
|
49
80
|
rows.push(cur);
|
|
50
81
|
cur = [];
|
|
51
82
|
curW = 0;
|
|
83
|
+
if (taper > 0) {
|
|
84
|
+
before += curD;
|
|
85
|
+
curD = 0;
|
|
86
|
+
limit = Math.min(width, taper * (before + sp / 2));
|
|
87
|
+
}
|
|
52
88
|
}
|
|
53
89
|
curRow = u.row;
|
|
54
90
|
cur.push(m);
|
|
55
91
|
curW += sp;
|
|
92
|
+
if (sp > curD)
|
|
93
|
+
curD = sp;
|
|
56
94
|
}
|
|
57
95
|
if (cur.length)
|
|
58
96
|
rows.push(cur);
|
package/dist/index.d.ts
CHANGED
|
@@ -7,3 +7,8 @@ export * from './vision.js';
|
|
|
7
7
|
export * from './polygon.js';
|
|
8
8
|
export * from './chain.js';
|
|
9
9
|
export * from './formation.js';
|
|
10
|
+
export * from './marchTypes.js';
|
|
11
|
+
export * from './march.js';
|
|
12
|
+
export * from './marchGround.js';
|
|
13
|
+
export { TP as MARCH_POINT, trailAt as marchTrailAt } from './marchTrail.js';
|
|
14
|
+
export { FOLLOW as MARCH_FOLLOW, FOLLOW_APART, FOLLOW_SLOT, FOLLOW_SQUEEZE, SLOT as MARCH_SLOT, marchFollow, marchRelease, marchSlot, } from './marchSlots.js';
|
package/dist/index.js
CHANGED
|
@@ -7,3 +7,10 @@ export * from './vision.js';
|
|
|
7
7
|
export * from './polygon.js';
|
|
8
8
|
export * from './chain.js';
|
|
9
9
|
export * from './formation.js';
|
|
10
|
+
export * from './marchTypes.js';
|
|
11
|
+
export * from './march.js';
|
|
12
|
+
export * from './marchGround.js';
|
|
13
|
+
// For games that draw the column or steer members their own way: a point of a march's trail, a member's place, and
|
|
14
|
+
// the point a member heads for. Everything else in the march files works on a march from the inside
|
|
15
|
+
export { TP as MARCH_POINT, trailAt as marchTrailAt } from './marchTrail.js';
|
|
16
|
+
export { FOLLOW as MARCH_FOLLOW, FOLLOW_APART, FOLLOW_SLOT, FOLLOW_SQUEEZE, SLOT as MARCH_SLOT, marchFollow, marchRelease, marchSlot, } from './marchSlots.js';
|
package/dist/march.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Formation } from './formation.js';
|
|
2
|
+
import { type March, type MarchGround, type MarchMembers, type MarchRules } from './marchTypes.js';
|
|
3
|
+
/** What `createMarch` needs to know about the order. */
|
|
4
|
+
export interface MarchOrder {
|
|
5
|
+
/** The movement layer the group marches on; the ground passed along must be that layer's. */
|
|
6
|
+
layer: number;
|
|
7
|
+
/** The centre of the group: the column forms up round it, the front rank at its front. */
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
/** The goal, and the cell it is in. */
|
|
11
|
+
destX: number;
|
|
12
|
+
destY: number;
|
|
13
|
+
destCell: number;
|
|
14
|
+
/** The slowest member's marching speed and full speed, in world units per second. */
|
|
15
|
+
speed: number;
|
|
16
|
+
run: number;
|
|
17
|
+
/** Whether the front rank halts while enough members are engaged. */
|
|
18
|
+
hold: boolean;
|
|
19
|
+
/** The facing at the goal. */
|
|
20
|
+
fx: number;
|
|
21
|
+
fy: number;
|
|
22
|
+
/** The members' ranks, from `lineFormation` (member speeds in world units per second). Each member keeps its rank, place and lateral offset for the whole march. */
|
|
23
|
+
formation: Formation;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Set a group marching. The march is appended to `marches`, or reuses the first one in it that is no longer alive
|
|
27
|
+
* (so its `id` is its index there). Whether a group is compact enough to march together is the game's call, before
|
|
28
|
+
* it asks.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createMarch(marches: March[], gr: MarchGround, M: MarchRules, order: MarchOrder): March;
|
|
31
|
+
/**
|
|
32
|
+
* Turn a marching group onto a new route (the same members ordered elsewhere) without forming up again: the column
|
|
33
|
+
* and its trail stay, and the front rank turns straight for the new goal. Returns false and changes nothing when the
|
|
34
|
+
* new route sets off at an angle to the front rank's heading whose cosine is below `rerouteCos` (it would have to
|
|
35
|
+
* turn back); the game then starts a new march. For a march still on its way: one that has arrived is not asked.
|
|
36
|
+
*
|
|
37
|
+
* The stretch of trail the probe had walked ahead of the front rank is dropped, the probe returns to the front rank
|
|
38
|
+
* and walks out its lead along the new route. The points kept get their envelope redone from the widths measured at
|
|
39
|
+
* each: narrowing passed back from the dropped stretch is gone, narrow places behind still count.
|
|
40
|
+
*/
|
|
41
|
+
export declare function rerouteMarch(gr: MarchGround, g: March, M: MarchRules, destX: number, destY: number, destCell: number, hold: boolean, fx: number, fy: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Advance every march by one step of `dt` seconds; call once per simulation step, before the members move.
|
|
44
|
+
* @param grounds The ground of a movement layer.
|
|
45
|
+
* @param tick The simulation step: the members are tallied on every eighth.
|
|
46
|
+
*/
|
|
47
|
+
export declare function updateMarches(marches: March[], grounds: (layer: number) => MarchGround, members: MarchMembers, M: MarchRules, dt: number, tick: number): void;
|
|
48
|
+
/**
|
|
49
|
+
* Result of `steerMember`. With `STEER_KEEP`: the velocity to move at; `set` is false when the member is on its
|
|
50
|
+
* place and the answer is "as you were" (the velocity is then zero, and a game that had the member moving for a
|
|
51
|
+
* reason of its own may leave that be). With `STEER_APART` and `STEER_PUSH`: the speed to move at along its own
|
|
52
|
+
* route. `apart`: whether the member is off its place this step (the game keeps it for `MarchMembers.apart`).
|
|
53
|
+
*/
|
|
54
|
+
export declare const STEER: {
|
|
55
|
+
vx: number;
|
|
56
|
+
vy: number;
|
|
57
|
+
set: boolean;
|
|
58
|
+
speed: number;
|
|
59
|
+
apart: boolean;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* What `steerMember` returns:
|
|
63
|
+
* - `STEER_IDLE`: the group is not marching in ranks right now; the member moves as if it had no march.
|
|
64
|
+
* - `STEER_LEAVE`: the member has left the march (the game clears its membership) and makes for its own spot.
|
|
65
|
+
* - `STEER_PUSH`: the member stays in the march but walks on along its route instead of waiting for its place.
|
|
66
|
+
* - `STEER_APART`: the member finds its own way along its route at `STEER.speed`, and rejoins when it can.
|
|
67
|
+
* - `STEER_KEEP`: the member keeps its place: it moves at (`STEER.vx`, `STEER.vy`).
|
|
68
|
+
*/
|
|
69
|
+
export declare const STEER_IDLE = 0, STEER_LEAVE = 1, STEER_PUSH = 2, STEER_APART = 3, STEER_KEEP = 4;
|
|
70
|
+
/**
|
|
71
|
+
* What a member of march `g` does this step; call it for each member after `updateMarches`.
|
|
72
|
+
* @param row, col, lateral The member's rank, place in it and lateral offset, from the formation the march was made with.
|
|
73
|
+
* @param ux, uy Where the member stands; destX, destY its own spot at the goal.
|
|
74
|
+
* @param speed, run The member's speed now and its full speed, in world units per second.
|
|
75
|
+
* @param free The member acts on its own this step (it keeps no place).
|
|
76
|
+
*/
|
|
77
|
+
export declare function steerMember(gr: MarchGround, g: March, M: MarchRules, row: number, col: number, lateral: number, ux: number, uy: number, destX: number, destY: number, speed: number, run: number, free: boolean): number;
|