@pocketrts/grid 0.2.0 → 0.4.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 +11 -2
- package/dist/march.d.ts +1 -1
- package/dist/march.js +98 -74
- package/dist/marchChoke.d.ts +3 -3
- package/dist/marchChoke.js +23 -6
- package/dist/marchSlots.d.ts +1 -2
- package/dist/marchSlots.js +14 -22
- package/dist/marchTrail.js +5 -2
- package/dist/marchTypes.d.ts +27 -49
- package/dist/marchTypes.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ ES module, TypeScript types included. Depends on `@pocketrts/determinism`.
|
|
|
37
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
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
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
|
+
| `MarchGround.crossSection`, `MarchCrossSection` | Supply a passage’s transverse unit axis and distances to its physical edges for route alignment and rank placement. The march applies its own padding and member radii. |
|
|
41
|
+
| `MarchGround.probeBlocked` | Check probe movement and trail obstructions in world coordinates. Both ground queries are optional and can return `undefined` locally to use the grid rules. |
|
|
40
42
|
| `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
43
|
| `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
44
|
| `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). |
|
|
@@ -140,8 +142,15 @@ Several sides with different passability (gates that open only for their owner,
|
|
|
140
142
|
- `LocalPathfinder`, `BucketGrid` and the flow-field search reuse their buffers: create one per world, or share one when calls never interleave.
|
|
141
143
|
- 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
144
|
- 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
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
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
147
|
- As for flow fields, the outermost ring of the grid must be blocked.
|
|
148
|
+
|
|
149
|
+
## Upgrading the march from 0.3 to 0.4
|
|
150
|
+
|
|
151
|
+
Start with `marchRules(cellSize / 32)`. The column forms up along the route, keeps clearance beside walls and closes its ranks around bends. Members walk back toward reachable places after a reversal. A member cut off from both its place and its rank follows its own route at the supplied run speed.
|
|
152
|
+
|
|
153
|
+
- Remove `flank`, `faceRoute`, `wheel`, `lookClear`, `waitAhead` and `apartTrail` from rule objects. Drop copied values for `lookMin`, `axisFrom` and `axisFull` to inherit the defaults of ten cells, 0.5 and 0.3. Keep explicit overrides where the map or game uses different tuning.
|
|
154
|
+
- For games that let members advance along their own routes during combat, set `pushAhead` to the distance in world units a member must be ahead of its place to receive `STEER_PUSH` while the group is opposed. The default is `Infinity`.
|
|
155
|
+
- For subcell passages such as diagonal bridges, keep the map's world-space movement queries and optional `crossSection` measurements. They supply the physical boundaries of the passage.
|
|
156
|
+
- March trajectories and checksums change with this version. Pin the same grid version on every peer in a lockstep match and replay recordings with the version that produced them.
|
package/dist/march.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare const STEER: {
|
|
|
62
62
|
* What `steerMember` returns:
|
|
63
63
|
* - `STEER_IDLE`: the group is not marching in ranks right now; the member moves as if it had no march.
|
|
64
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
|
|
65
|
+
* - `STEER_PUSH`: the member stays in the march but walks on along its route while the group is opposed.
|
|
66
66
|
* - `STEER_APART`: the member finds its own way along its route at `STEER.speed`, and rejoins when it can.
|
|
67
67
|
* - `STEER_KEEP`: the member keeps its place: it moves at (`STEER.vx`, `STEER.vy`).
|
|
68
68
|
*/
|
package/dist/march.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* Results are deterministic: the same calls with the same inputs give the same bits.
|
|
10
10
|
*/
|
|
11
11
|
import { dmath, smooth } from '@pocketrts/determinism';
|
|
12
|
-
import {
|
|
12
|
+
import { nearestCell } from './cells.js';
|
|
13
|
+
import { DIR_HERE, DIR_NONE, DIRX, DIRY } from './dirs.js';
|
|
13
14
|
import { FOLLOW, FOLLOW_APART, FOLLOW_SLOT, SLOT, marchFollow, marchRelease, marchSlot, rowsAt } from './marchSlots.js';
|
|
14
15
|
import { TP, TRAIL, TRAIL_MAX, addPoint, cutAhead, layTrail, nearCell, routeCut, trailAt, widthAt } from './marchTrail.js';
|
|
15
16
|
import { MEMBER_ENGAGED, MEMBER_FREE, MEMBER_OPPOSED, MEMBER_OUT, } from './marchTypes.js';
|
|
@@ -77,31 +78,28 @@ export function createMarch(marches, gr, M, order) {
|
|
|
77
78
|
Object.assign(g, {
|
|
78
79
|
alive: true, layer, destX, destY, destCell,
|
|
79
80
|
speed, run, hold, engaged: 0, free: 0, cEngaged: 0, cFree: 0, cOpposed: 0, fx, fy, arrived: false, blocked: false, loose: false, opposedT: 0, n,
|
|
80
|
-
cnt: 0, lagSum: 0, lagApart: 0, over: 0, sx: 0, sy: 0, cap, width, depth, open:
|
|
81
|
+
cnt: 0, lagSum: 0, lagApart: 0, over: 0, sx: 0, sy: 0, cap, width, depth, open: width + big, ahead, rows, tail: false, tailT: 0,
|
|
81
82
|
});
|
|
82
83
|
anchor(gr, g, M, x, y, false);
|
|
83
84
|
return g;
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* `MarchRules.faceRoute` the direction is that of the route's first stretch, and a column forming up round its
|
|
89
|
-
* centre (`front` false) is laid out along the route instead: the straight trail lies behind the place of its rear,
|
|
90
|
-
* the probe walks one column depth further than its lead, and the front rank stands that much on along its way.
|
|
87
|
+
* Lay the column along the route, beginning at the rear when forming around a centre. The probe walks out
|
|
88
|
+
* one column depth plus its lead so the front rank starts one depth along the walkable route.
|
|
91
89
|
* @param x, y The centre of the group (`front` false: the column forms up round it, the front rank at its front), or
|
|
92
90
|
* the front rank's position (`front` true).
|
|
93
91
|
*/
|
|
94
92
|
function anchor(gr, g, M, x, y, front) {
|
|
95
93
|
// The front rank must not start where nobody can stand
|
|
96
94
|
const c0 = gr.cellAt(x, y);
|
|
97
|
-
if (gr.solid(c0)) {
|
|
95
|
+
if (gr.probeBlocked?.(x, y, x, y) ?? gr.solid(c0)) {
|
|
98
96
|
const c = gr.nearestFree(c0, 20);
|
|
99
97
|
x = (c % gr.w + 0.5) * gr.cellSize;
|
|
100
98
|
y = (((c / gr.w) | 0) + 0.5) * gr.cellSize;
|
|
101
99
|
}
|
|
102
100
|
const dx = g.destX - x, dy = g.destY - y, dl = dmath.hypot(dx, dy) || 1;
|
|
103
101
|
let hx = dx / dl, hy = dy / dl;
|
|
104
|
-
if (
|
|
102
|
+
if (gr.lineBlocked(x, y, g.destX, g.destY)) {
|
|
105
103
|
// The route does not set off straight for the goal: face the furthest point in sight along it. A route still
|
|
106
104
|
// being searched is finished on the spot, as for a new route
|
|
107
105
|
const f = gr.field(g.destCell);
|
|
@@ -115,30 +113,21 @@ function anchor(gr, g, M, x, y, front) {
|
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
115
|
}
|
|
118
|
-
// With `faceRoute`: how far along the route the column is laid out when forming up round the centre
|
|
119
116
|
let along = 0;
|
|
120
|
-
if (!front
|
|
117
|
+
if (!front) {
|
|
121
118
|
// The column forms up along the route: its rear as far behind the centre as there is room for (at most half its
|
|
122
119
|
// depth), and from there one column depth on along the way the probe walks. Laid out straight round the centre
|
|
123
120
|
// instead, the ranks of a column that forms up in a cramped place, or whose route sets off round a corner, would
|
|
124
121
|
// have their places in or behind a wall
|
|
125
122
|
const half = g.depth / 2, reach = gr.lineReach(x, y, x - hx * half, y - hy * half);
|
|
126
123
|
const back = reach >= 1 ? half : Math.max(0, half * reach - gr.cellSize / 2);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
const bx = x - hx * back, by = y - hy * back;
|
|
125
|
+
if (back > 0 && !(gr.probeBlocked?.(x, y, bx, by) ?? gr.blocked(gr.cellAt(bx, by)))) {
|
|
126
|
+
x = bx;
|
|
127
|
+
y = by;
|
|
130
128
|
}
|
|
131
129
|
along = g.depth;
|
|
132
130
|
}
|
|
133
|
-
else if (!front) {
|
|
134
|
-
// The front rank at the front of the column (where it can walk there): the column then stands round the centre
|
|
135
|
-
const fwd = Math.min(g.depth / 2, dl - M.scale);
|
|
136
|
-
const lx = x + hx * fwd, ly = y + hy * fwd;
|
|
137
|
-
if (fwd > 0 && !gr.blocked(gr.cellAt(lx, ly)) && !gr.lineBlocked(x, y, lx, ly)) {
|
|
138
|
-
x = lx;
|
|
139
|
-
y = ly;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
131
|
layTrail(g, M, x, y, hx, hy);
|
|
143
132
|
Object.assign(g, {
|
|
144
133
|
x, y, hx, hy, px: x, py: y, phx: hx, phy: hy, head: 0, rec: 0, v: 0, lag: M.lagStop,
|
|
@@ -201,15 +190,15 @@ function placeFront(g, M) {
|
|
|
201
190
|
g.hy = TP.hy;
|
|
202
191
|
}
|
|
203
192
|
const AIM = { x: 0, y: 0 };
|
|
204
|
-
/** The width of the way at the probe as far as it is known:
|
|
193
|
+
/** The width of the way at the probe as far as it is known: the usable width at the newest trail point where that is less than the column's. */
|
|
205
194
|
function wayAt(g, M) {
|
|
206
|
-
return
|
|
195
|
+
return Math.min(g.width, widthAt(g, M, 0));
|
|
207
196
|
}
|
|
208
197
|
/**
|
|
209
198
|
* Count cells along the flow field from under the probe and take the furthest one a straight walk reaches (no
|
|
210
199
|
* further than the look-ahead distance), into `AIM`. A flow field has eight directions; walked as it is, the route
|
|
211
|
-
* is a polyline, and a rank following it would wheel at every kink.
|
|
212
|
-
*
|
|
200
|
+
* is a polyline, and a rank following it would wheel at every kink. The furthest cell
|
|
201
|
+
* with a straight walk clear for a quarter of the usable width to each side is taken when there is one, so the
|
|
213
202
|
* straightened route keeps its distance from the corners it goes round.
|
|
214
203
|
* @param laid False while forming up, before the trail is laid out: no usable width is known yet.
|
|
215
204
|
*/
|
|
@@ -217,11 +206,20 @@ function lookAhead(gr, g, M, f, cell, x = g.px, y = g.py, laid = true) {
|
|
|
217
206
|
const mw = gr.w, T = gr.cellSize;
|
|
218
207
|
const look = Math.max(M.lookMin, g.width * M.lookK);
|
|
219
208
|
const max = Math.ceil(look / T) * 2 + 2;
|
|
220
|
-
|
|
221
|
-
// just in sight: a line of sight that only just passes a corner would lead the column along the corner's wall, to
|
|
222
|
-
// turn round the corner on the spot
|
|
223
|
-
const side = M.lookClear > 0 ? (laid ? wayAt(g, M) : g.width) * M.lookClear : 0;
|
|
209
|
+
const side = (laid ? wayAt(g, M) : g.width) / 4;
|
|
224
210
|
let c = cell, ok = false, wide = false;
|
|
211
|
+
// A real passage can overlap a blocked cell with no flow direction. Rejoin the field through a visible
|
|
212
|
+
// neighbour; its centre remains the aim if the following bend hides every point further down the route.
|
|
213
|
+
if (f.dirs[c] === DIR_NONE && gr.probeBlocked && gr.blocked(c) && gr.probeBlocked(x, y, x, y) === false) {
|
|
214
|
+
c = nearestCell(mw, gr.h, cell, 1, candidate => f.dirs[candidate] !== DIR_NONE && !gr.blocked(candidate)
|
|
215
|
+
&& !gr.lineBlocked(x, y, (candidate % mw + 0.5) * T, (((candidate / mw) | 0) + 0.5) * T));
|
|
216
|
+
if (c !== cell) {
|
|
217
|
+
AIM.x = (c % mw + 0.5) * T;
|
|
218
|
+
AIM.y = (((c / mw) | 0) + 0.5) * T;
|
|
219
|
+
ok = true;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
let inPassage = false;
|
|
225
223
|
for (let k = 0; k < max; k++) {
|
|
226
224
|
const dir = f.dirs[c];
|
|
227
225
|
if (dir > 7) {
|
|
@@ -233,7 +231,28 @@ function lookAhead(gr, g, M, f, cell, x = g.px, y = g.py, laid = true) {
|
|
|
233
231
|
break;
|
|
234
232
|
}
|
|
235
233
|
c += DIRX[dir] + DIRY[dir] * mw;
|
|
236
|
-
|
|
234
|
+
let px = (c % mw + 0.5) * T, py = (((c / mw) | 0) + 0.5) * T;
|
|
235
|
+
let centered = false;
|
|
236
|
+
// A coarse route can alternate between the two edges of a straight passage. Aim down its measured middle
|
|
237
|
+
// wherever that shortcut is walkable. At junctions the ground can leave the waypoint to the field.
|
|
238
|
+
if (gr.crossSection) {
|
|
239
|
+
const d = dir & 1 ? Math.SQRT1_2 : 1;
|
|
240
|
+
const section = gr.crossSection(px, py, DIRX[dir] * d, DIRY[dir] * d);
|
|
241
|
+
if (section && section.negative + section.positive < g.width * M.narrow) {
|
|
242
|
+
const offset = (section.positive - section.negative) / 2;
|
|
243
|
+
const mx = px + section.axisX * offset, my = py + section.axisY * offset;
|
|
244
|
+
if (!gr.lineBlocked(x, y, mx, my)) {
|
|
245
|
+
px = mx;
|
|
246
|
+
py = my;
|
|
247
|
+
centered = true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else if (inPassage) {
|
|
251
|
+
// Keep the exit as the waypoint until it is within one cell. Looking past it draws a straight
|
|
252
|
+
// corridor towards whichever corner happens to reveal the next cell outside.
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
237
256
|
if ((px - x) ** 2 + (py - y) ** 2 > look * look)
|
|
238
257
|
break;
|
|
239
258
|
if (gr.lineBlocked(x, y, px, py))
|
|
@@ -250,10 +269,14 @@ function lookAhead(gr, g, M, f, cell, x = g.px, y = g.py, laid = true) {
|
|
|
250
269
|
}
|
|
251
270
|
AIM.x = px;
|
|
252
271
|
AIM.y = py;
|
|
272
|
+
inPassage = centered && (px - x) ** 2 + (py - y) ** 2 > T * T;
|
|
253
273
|
ok = true;
|
|
254
274
|
}
|
|
255
275
|
return ok;
|
|
256
276
|
}
|
|
277
|
+
function probeStepBlocked(gr, g, cell, nc, nx, ny) {
|
|
278
|
+
return gr.probeBlocked?.(g.px, g.py, nx, ny) ?? (nc !== cell && (gr.blocked(nc) || !gr.canStep(cell, nc)));
|
|
279
|
+
}
|
|
257
280
|
/**
|
|
258
281
|
* The probe walks `dist` along the route (in steps of at most `PROBE_SUB`), recording the trail as it goes. It looks
|
|
259
282
|
* a stretch along the route and heads for the furthest point in sight (straightening the flow field's polyline). Its
|
|
@@ -273,7 +296,7 @@ function probeMove(gr, g, M, dist, vref) {
|
|
|
273
296
|
const cell = ((g.py / T) | 0) * mw + ((g.px / T) | 0);
|
|
274
297
|
const ddx = g.destX - g.px, ddy = g.destY - g.py;
|
|
275
298
|
const dd = Math.sqrt(ddx * ddx + ddy * ddy);
|
|
276
|
-
if (dd <= step + M.scale) {
|
|
299
|
+
if (dd <= step + M.scale && !gr.probeBlocked?.(g.px, g.py, g.destX, g.destY)) {
|
|
277
300
|
advance(gr, g, M, g.destX, g.destY, true);
|
|
278
301
|
g.pDone = true;
|
|
279
302
|
g.pBarred = false;
|
|
@@ -302,6 +325,10 @@ function probeMove(gr, g, M, dist, vref) {
|
|
|
302
325
|
ty = g.py + fdy * T;
|
|
303
326
|
}
|
|
304
327
|
}
|
|
328
|
+
else if (dir === DIR_NONE && gr.probeBlocked && lookAhead(gr, g, M, f, cell)) {
|
|
329
|
+
tx = AIM.x;
|
|
330
|
+
ty = AIM.y;
|
|
331
|
+
}
|
|
305
332
|
else if (dir !== DIR_HERE && f.pending)
|
|
306
333
|
return; // The route is not known here yet: wait
|
|
307
334
|
}
|
|
@@ -311,8 +338,7 @@ function probeMove(gr, g, M, dist, vref) {
|
|
|
311
338
|
da -= Math.PI * 2;
|
|
312
339
|
else if (da < -Math.PI)
|
|
313
340
|
da += Math.PI * 2;
|
|
314
|
-
//
|
|
315
|
-
// squeezed ranks can wheel as tightly as the way is wide
|
|
341
|
+
// Squeezed ranks can turn as tightly as the passage allows.
|
|
316
342
|
const way = wayAt(g, M);
|
|
317
343
|
const radius = dd < g.width ? M.scale : Math.max(M.turnR, way / 2);
|
|
318
344
|
let turn = step / radius;
|
|
@@ -332,13 +358,15 @@ function probeMove(gr, g, M, dist, vref) {
|
|
|
332
358
|
ma += rest;
|
|
333
359
|
let nx = g.px + dmath.cos(ma) * step, ny = g.py + dmath.sin(ma) * step;
|
|
334
360
|
let nc = ((ny / T) | 0) * mw + ((nx / T) | 0);
|
|
335
|
-
|
|
361
|
+
let blocked = probeStepBlocked(gr, g, cell, nc, nx, ny);
|
|
362
|
+
if (blocked && (fdx || fdy)) {
|
|
336
363
|
// The shortcut ran into an obstacle: follow the flow field as it is
|
|
337
364
|
nx = g.px + fdx * step;
|
|
338
365
|
ny = g.py + fdy * step;
|
|
339
366
|
nc = ((ny / T) | 0) * mw + ((nx / T) | 0);
|
|
367
|
+
blocked = probeStepBlocked(gr, g, cell, nc, nx, ny);
|
|
340
368
|
}
|
|
341
|
-
if (
|
|
369
|
+
if (blocked) {
|
|
342
370
|
// No straight way: take the flow field from now on; where its route is barred, stop and wait
|
|
343
371
|
if (!g.field)
|
|
344
372
|
g.field = gr.field(g.destCell);
|
|
@@ -403,11 +431,11 @@ function paceTop(g, M) {
|
|
|
403
431
|
top += (foldRun * M.trot - top) * smooth(fold - 1);
|
|
404
432
|
for (let r = 0; r < g.rows; r++) {
|
|
405
433
|
let kr = g.rowK[r];
|
|
406
|
-
//
|
|
434
|
+
// The outermost place must keep within the rank's speed. A rank on a bend
|
|
407
435
|
// with the front rank past it moves that much less along the trail (it closes up), so the two cancel; a front
|
|
408
436
|
// rank on a bend itself is what this slows down. Not within one width of the goal: there the probe turned as
|
|
409
437
|
// sharply as it took to reach the goal, and the members are about to leave for their own spots
|
|
410
|
-
if (
|
|
438
|
+
if (!(g.pDone && g.lead < g.width))
|
|
411
439
|
kr *= TW[r];
|
|
412
440
|
if (kr <= 1)
|
|
413
441
|
continue;
|
|
@@ -450,6 +478,7 @@ function tally(marches, grounds, mem, M, dt) {
|
|
|
450
478
|
g.cnt = g.lagSum = g.lagApart = g.over = g.cEngaged = g.cFree = g.cOpposed = g.sx = g.sy = 0;
|
|
451
479
|
// Each march's ground, asked for once per tally
|
|
452
480
|
const grs = [];
|
|
481
|
+
const ahead = [];
|
|
453
482
|
for (let i = 0; i < mem.n; i++) {
|
|
454
483
|
const gi = mem.march(i);
|
|
455
484
|
if (gi < 0 || !mem.alive(i))
|
|
@@ -479,15 +508,13 @@ function tally(marches, grounds, mem, M, dt) {
|
|
|
479
508
|
if (!gr.standable(SLOT.x, SLOT.y) || gr.lineBlocked(SLOT.cx, SLOT.cy, SLOT.x, SLOT.y))
|
|
480
509
|
g.over++;
|
|
481
510
|
const ox = SLOT.x - mem.x(i), oy = SLOT.y - mem.y(i);
|
|
482
|
-
// A member
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
continue;
|
|
486
|
-
const lag = Math.sqrt(ox * ox + oy * oy);
|
|
511
|
+
// A later member may be the one in combat. Set aside the lag of potential pushers until everyone is counted.
|
|
512
|
+
const sum = ox * SLOT.hx + oy * SLOT.hy < -M.pushAhead ? ahead[gi] ??= { lagSum: 0, lagApart: 0 } : g;
|
|
513
|
+
const lag = Math.min(Math.sqrt(ox * ox + oy * oy), M.lagCap);
|
|
487
514
|
if (mem.apart(i))
|
|
488
|
-
|
|
515
|
+
sum.lagApart += lag;
|
|
489
516
|
else
|
|
490
|
-
|
|
517
|
+
sum.lagSum += lag;
|
|
491
518
|
}
|
|
492
519
|
for (const g of marches) {
|
|
493
520
|
if (!g.alive)
|
|
@@ -496,6 +523,15 @@ function tally(marches, grounds, mem, M, dt) {
|
|
|
496
523
|
if (!g.cnt)
|
|
497
524
|
g.alive = false;
|
|
498
525
|
else {
|
|
526
|
+
if (g.cOpposed > 0)
|
|
527
|
+
g.opposedT = M.opposedLinger;
|
|
528
|
+
else if (g.opposedT > 0)
|
|
529
|
+
g.opposedT -= dt * TALLY;
|
|
530
|
+
const pushing = ahead[g.id];
|
|
531
|
+
if (pushing && g.opposedT <= 0) {
|
|
532
|
+
g.lagSum += pushing.lagSum;
|
|
533
|
+
g.lagApart += pushing.lagApart;
|
|
534
|
+
}
|
|
499
535
|
// While the column is draped over an obstacle, members out of reach of their places are finding their own way
|
|
500
536
|
// and the front rank does not wait for them: waiting would hold the ranks behind on this side of the obstacle
|
|
501
537
|
// too, and the group would pass it one rank at a time. Once the whole column is clear they count again, and the
|
|
@@ -506,12 +542,6 @@ function tally(marches, grounds, mem, M, dt) {
|
|
|
506
542
|
g.free = g.cFree / g.cnt;
|
|
507
543
|
// Engaged: break ranks. Afterwards the group forms up round where its members are now; it does not walk back
|
|
508
544
|
const loose = (g.hold && g.engaged > M.holdEngaged) || g.free > 0.5;
|
|
509
|
-
// Counted down by the tally interval, so a lone opponent appearing and gone again does not send the group
|
|
510
|
-
// forward and straight back to waiting for places
|
|
511
|
-
if (g.cOpposed > 0)
|
|
512
|
-
g.opposedT = M.opposedLinger;
|
|
513
|
-
else if (g.opposedT > 0)
|
|
514
|
-
g.opposedT -= dt * TALLY;
|
|
515
545
|
if (g.loose && !loose && !g.arrived)
|
|
516
546
|
anchor(grounds(g.layer), g, M, g.sx / g.cnt, g.sy / g.cnt, false);
|
|
517
547
|
g.loose = loose;
|
|
@@ -546,6 +576,10 @@ export function updateMarches(marches, grounds, members, M, dt, tick) {
|
|
|
546
576
|
continue;
|
|
547
577
|
const step = sp * dt;
|
|
548
578
|
if (g.pDone && !g.tail && g.lead <= step + M.scale) {
|
|
579
|
+
if (gr.probeBlocked?.(g.x, g.y, g.destX, g.destY)) {
|
|
580
|
+
anchor(gr, g, M, g.x, g.y, true);
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
549
583
|
g.arrived = true;
|
|
550
584
|
if (needTail(g, M)) {
|
|
551
585
|
// Ranks behind have not passed the narrow place: the column stays and keeps leading; members leave one by one
|
|
@@ -580,10 +614,15 @@ export function updateMarches(marches, grounds, members, M, dt, tick) {
|
|
|
580
614
|
}
|
|
581
615
|
if (!g.tail)
|
|
582
616
|
g.blocked = g.pBarred && g.lead < M.scale;
|
|
617
|
+
const oldX = g.x, oldY = g.y;
|
|
583
618
|
placeFront(g, M);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
619
|
+
if (!g.tail && df > 0) {
|
|
620
|
+
// A gate narrower than the trail sampling interval can close behind the probe.
|
|
621
|
+
if (gr.probeBlocked?.(oldX, oldY, g.x, g.y))
|
|
622
|
+
anchor(gr, g, M, oldX, oldY, true);
|
|
623
|
+
else if (routeCut(gr, g, M))
|
|
624
|
+
anchor(gr, g, M, g.x, g.y, true);
|
|
625
|
+
}
|
|
587
626
|
rowsAt(g, M, g.lead, g.rowB, g.rowLen, g.rowE);
|
|
588
627
|
}
|
|
589
628
|
}
|
|
@@ -598,7 +637,7 @@ export const STEER = { vx: 0, vy: 0, set: false, speed: 0, apart: false };
|
|
|
598
637
|
* What `steerMember` returns:
|
|
599
638
|
* - `STEER_IDLE`: the group is not marching in ranks right now; the member moves as if it had no march.
|
|
600
639
|
* - `STEER_LEAVE`: the member has left the march (the game clears its membership) and makes for its own spot.
|
|
601
|
-
* - `STEER_PUSH`: the member stays in the march but walks on along its route
|
|
640
|
+
* - `STEER_PUSH`: the member stays in the march but walks on along its route while the group is opposed.
|
|
602
641
|
* - `STEER_APART`: the member finds its own way along its route at `STEER.speed`, and rejoins when it can.
|
|
603
642
|
* - `STEER_KEEP`: the member keeps its place: it moves at (`STEER.vx`, `STEER.vy`).
|
|
604
643
|
*/
|
|
@@ -620,14 +659,10 @@ export function steerMember(gr, g, M, row, col, lateral, ux, uy, destX, destY, s
|
|
|
620
659
|
if (g.blocked || g.loose || free)
|
|
621
660
|
return STEER_IDLE;
|
|
622
661
|
marchSlot(g, M, row, col, lateral);
|
|
623
|
-
// Whether the place is behind the member, measured along the column's direction of travel there
|
|
624
|
-
const behind = (SLOT.x - ux) * SLOT.hx + (SLOT.y - uy) * SLOT.hy < -M.waitAhead;
|
|
625
662
|
// Winding up: the rank has passed the goal, or no narrow place lies ahead and the spot is in sight
|
|
626
663
|
if (g.tail && marchRelease(gr, g, ux, uy, destX, destY))
|
|
627
664
|
return STEER_LEAVE;
|
|
628
|
-
|
|
629
|
-
// (past an obstacle it often is not), and there is nothing to catch up with: the member is ahead of its place
|
|
630
|
-
if (behind && g.opposedT > 0)
|
|
665
|
+
if (g.opposedT > 0 && (SLOT.x - ux) * SLOT.hx + (SLOT.y - uy) * SLOT.hy < -M.pushAhead)
|
|
631
666
|
return STEER_PUSH;
|
|
632
667
|
const mode = marchFollow(gr, ux, uy);
|
|
633
668
|
if (mode !== FOLLOW_SLOT)
|
|
@@ -636,24 +671,13 @@ export function steerMember(gr, g, M, row, col, lateral, ux, uy, destX, destY, s
|
|
|
636
671
|
if (mode === FOLLOW_APART && g.tail)
|
|
637
672
|
return STEER_LEAVE;
|
|
638
673
|
if (mode === FOLLOW_APART) {
|
|
639
|
-
|
|
640
|
-
// with a place ahead; with the place behind, move at the rank's pace instead of running ahead to stand and wait
|
|
641
|
-
if (!behind)
|
|
642
|
-
STEER.speed = run;
|
|
643
|
-
else {
|
|
644
|
-
const v = Math.max(SLOT.v, speed * M.apartTrail);
|
|
645
|
-
STEER.speed = v < run ? v : run;
|
|
646
|
-
}
|
|
674
|
+
STEER.speed = run;
|
|
647
675
|
return STEER_APART;
|
|
648
676
|
}
|
|
649
677
|
// Aim a little ahead of the point to follow: on its place the member moves at its rank's pace, behind it runs
|
|
650
678
|
const ex = FOLLOW.x + SLOT.hx * SLOT.v * M.leadTime - ux, ey = FOLLOW.y + SLOT.hy * SLOT.v * M.leadTime - uy;
|
|
651
679
|
const ed = Math.sqrt(ex * ex + ey * ey);
|
|
652
|
-
if (
|
|
653
|
-
// The place is behind (the member got ahead on a detour): stand and wait for it, do not walk back
|
|
654
|
-
STEER.set = true;
|
|
655
|
-
}
|
|
656
|
-
else if (ed > 0.5 * M.scale) {
|
|
680
|
+
if (ed > 0.5 * M.scale) {
|
|
657
681
|
let v = ed / M.leadTime;
|
|
658
682
|
if (v > run)
|
|
659
683
|
v = run;
|
package/dist/marchChoke.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Column march: measuring a narrow place. At a point of the trail, find the shortest cross-section with a large
|
|
3
3
|
* obstacle on both sides, each blocking its whole wing, and give the usable width on each side and the direction of
|
|
4
4
|
* the cross-section. A place with an obstacle on one side only, or one that leaves the wing tip free (the wings can
|
|
5
|
-
* pass round it), is not a narrow place.
|
|
5
|
+
* pass round it), is not a narrow place. A long wall blocks its wing however thin it is, and
|
|
6
6
|
* where no narrow place is found, what stands beside the route is still recorded, side by side, so that ranks keep
|
|
7
7
|
* clear of it.
|
|
8
8
|
*/
|
|
@@ -20,8 +20,8 @@ export declare function chokeClear(g: March): void;
|
|
|
20
20
|
/**
|
|
21
21
|
* Measure the narrow place at trail point (x, y), travelling in direction (tx, ty); the result goes to `CHOKE`. Among
|
|
22
22
|
* four fixed directions, take the shortest line not parallel to the travel that hits a large obstacle both ways as
|
|
23
|
-
* the cross-section: it follows the opening (parallel to the wall), not the heading of the column.
|
|
24
|
-
*
|
|
23
|
+
* the cross-section: it follows the opening (parallel to the wall), not the heading of the column. Without such a line,
|
|
24
|
+
* each side still records its own clearance. The widths are less the clearance `chokePad`,
|
|
25
25
|
* and at a narrow place add up to less than `narrow` times the column's width.
|
|
26
26
|
*/
|
|
27
27
|
export declare function chokeAt(gr: MarchGround, g: March, M: MarchRules, x: number, y: number, tx: number, ty: number): void;
|
package/dist/marchChoke.js
CHANGED
|
@@ -59,7 +59,7 @@ function rayHit(gr, x, y, dx, dy, max) {
|
|
|
59
59
|
* Distance from the trail point (x, y) along (dx, dy) to an obstacle; −1 when the obstacle does not block this whole
|
|
60
60
|
* wing: it must run on from where it was hit out to the wing tip (half the column's width, at least `chokeMin`).
|
|
61
61
|
* It is sampled every half cell, the first sample a quarter cell in, so every cell is looked at twice and a gap one
|
|
62
|
-
* cell wide is not missed.
|
|
62
|
+
* cell wide is not missed. An obstacle thinner than that still counts when it is a wall
|
|
63
63
|
* (`wallRuns`): otherwise a corridor between thin walls is not measured across, only along a diagonal where the
|
|
64
64
|
* walls happen to be thick enough, and passes for as wide as that diagonal is long.
|
|
65
65
|
*/
|
|
@@ -72,7 +72,7 @@ function wallAt(gr, g, M, x, y, dx, dy) {
|
|
|
72
72
|
for (let k = T / 4; k <= run; k += T / 2) {
|
|
73
73
|
const px = x + dx * (d + k), py = y + dy * (d + k);
|
|
74
74
|
if (!solidCell(gr, Math.floor(px / T), Math.floor(py / T)))
|
|
75
|
-
return
|
|
75
|
+
return wallRuns(gr, g, M, x + dx * (d + T / 2), y + dy * (d + T / 2), -dy, dx) ? d : -1;
|
|
76
76
|
}
|
|
77
77
|
return d;
|
|
78
78
|
}
|
|
@@ -100,12 +100,29 @@ function wallRuns(gr, g, M, x, y, ux, uy) {
|
|
|
100
100
|
/**
|
|
101
101
|
* Measure the narrow place at trail point (x, y), travelling in direction (tx, ty); the result goes to `CHOKE`. Among
|
|
102
102
|
* four fixed directions, take the shortest line not parallel to the travel that hits a large obstacle both ways as
|
|
103
|
-
* the cross-section: it follows the opening (parallel to the wall), not the heading of the column.
|
|
104
|
-
*
|
|
103
|
+
* the cross-section: it follows the opening (parallel to the wall), not the heading of the column. Without such a line,
|
|
104
|
+
* each side still records its own clearance. The widths are less the clearance `chokePad`,
|
|
105
105
|
* and at a narrow place add up to less than `narrow` times the column's width.
|
|
106
106
|
*/
|
|
107
107
|
export function chokeAt(gr, g, M, x, y, tx, ty) {
|
|
108
108
|
chokeClear(g);
|
|
109
|
+
const section = gr.crossSection?.(x, y, tx, ty);
|
|
110
|
+
if (section) {
|
|
111
|
+
const { axisX, axisY, positive, negative } = section;
|
|
112
|
+
const forward = -ty * axisX + tx * axisY >= 0;
|
|
113
|
+
const r = forward ? positive : negative, l = forward ? negative : positive;
|
|
114
|
+
if (r === Infinity && l === Infinity)
|
|
115
|
+
return;
|
|
116
|
+
// An unbounded wing has room for a whole rank to shift away from the other edge.
|
|
117
|
+
CHOKE.R = r === Infinity ? g.open : Math.max(0, r - M.chokePad);
|
|
118
|
+
CHOKE.L = l === Infinity ? g.open : Math.max(0, l - M.chokePad);
|
|
119
|
+
if (r + l >= g.width * M.narrow)
|
|
120
|
+
return;
|
|
121
|
+
CHOKE.ax = forward ? axisX : -axisX;
|
|
122
|
+
CHOKE.ay = forward ? axisY : -axisY;
|
|
123
|
+
CHOKE.has = 1;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
109
126
|
let best = g.width * M.narrow;
|
|
110
127
|
for (let a = 0; a < AXES.length; a += 2) {
|
|
111
128
|
const ux = AXES[a], uy = AXES[a + 1];
|
|
@@ -128,9 +145,9 @@ export function chokeAt(gr, g, M, x, y, tx, ty) {
|
|
|
128
145
|
CHOKE.has = 1;
|
|
129
146
|
}
|
|
130
147
|
// A point on a solid cell measures nothing either way (a ray from it would read 0 on both sides)
|
|
131
|
-
if (CHOKE.has ||
|
|
148
|
+
if (CHOKE.has || solidCell(gr, Math.floor(x / gr.cellSize), Math.floor(y / gr.cellSize)))
|
|
132
149
|
return;
|
|
133
|
-
//
|
|
150
|
+
// Without a narrow place, whatever stands within the column's width square to the travel
|
|
134
151
|
// still counts on its own side: no direction of a narrow place goes with it, so ranks stay square to their heading
|
|
135
152
|
const dr = rayHit(gr, x, y, -ty, tx, g.width), dl = rayHit(gr, x, y, ty, -tx, g.width);
|
|
136
153
|
if (dr >= 0)
|
package/dist/marchSlots.d.ts
CHANGED
|
@@ -3,8 +3,7 @@ import type { March, MarchGround, MarchRules } from './marchTypes.js';
|
|
|
3
3
|
* Where each rank stands with the front rank `b` behind the probe: from the front rank back, one after another, each
|
|
4
4
|
* taking the stretch `rowLength` gives. Results go to `rb` (distance of the rank's middle behind the probe), `rl`
|
|
5
5
|
* (length of its stretch), `re` (how much further back it is than unfolded) and, when given, `wh` (how much further
|
|
6
|
-
* the rank's outermost place moves than its point on the trail, averaged over its stretch
|
|
7
|
-
* `MarchRules.wheel`).
|
|
6
|
+
* the rank's outermost place moves than its point on the trail, averaged over its stretch).
|
|
8
7
|
*/
|
|
9
8
|
export declare function rowsAt(g: March, M: MarchRules, b: number, rb: Float64Array, rl: Float64Array, re: Float64Array, wh?: Float64Array): void;
|
|
10
9
|
/**
|
package/dist/marchSlots.js
CHANGED
|
@@ -29,14 +29,14 @@ function wheelAt(g, M, r, b) {
|
|
|
29
29
|
const lo = half - L, hi = R - half, sh = lo > hi ? (R - L) / 2 : lo > 0 ? lo : hi < 0 ? hi : 0;
|
|
30
30
|
return 1 + turn / (2 * d) * ((sh < 0 ? -sh : sh) + half);
|
|
31
31
|
}
|
|
32
|
-
/** Set by `rowLength`: the rank's wheel factor (`wheelAt`), averaged over the stretch it takes; exactly 1 where no piece of it has a factor above 1
|
|
32
|
+
/** Set by `rowLength`: the rank's wheel factor (`wheelAt`), averaged over the stretch it takes; exactly 1 where no piece of it has a factor above 1. */
|
|
33
33
|
let WHEEL = 1;
|
|
34
34
|
/**
|
|
35
35
|
* How long a stretch of trail rank r takes back from its leading edge `edge` (distance behind the probe). Each piece
|
|
36
36
|
* counts for "usable width ÷ rank width" of its length (at most 1, at least 1 / `stretchMax`) towards one rank depth.
|
|
37
37
|
* Where the way is wide enough a piece counts whole, so in the open the stretch is exactly one rank depth; where the
|
|
38
38
|
* way is a fraction of the rank's width the stretch is that many times longer, up to `stretchMax`. The length of a
|
|
39
|
-
* long folded rank changes smoothly across a change of width, without a jump.
|
|
39
|
+
* long folded rank changes smoothly across a change of width, without a jump. A piece on a
|
|
40
40
|
* bend counts for more, by as much as the rank's outermost place moves further than its point on the trail: the
|
|
41
41
|
* stretch is shorter there, and ranks pass a bend closed up along the trail.
|
|
42
42
|
*/
|
|
@@ -44,8 +44,8 @@ function rowLength(g, M, r, edge) {
|
|
|
44
44
|
const d = g.rowD[r], rw = g.rowW[r], pad = g.rowRad[r] * 2;
|
|
45
45
|
const lo = 1 / M.stretchMax, piece = ROW_STEP * M.scale;
|
|
46
46
|
let acc = 0, len = 0, squeezed = false;
|
|
47
|
-
//
|
|
48
|
-
let turned = 0,
|
|
47
|
+
// The wheel factor of each piece times its length, summed, and whether any piece had one above 1
|
|
48
|
+
let turned = 0, bent = false;
|
|
49
49
|
WHEEL = 1;
|
|
50
50
|
for (;;) {
|
|
51
51
|
const q = (d - acc) * (squeezed ? 1 / lo : 1);
|
|
@@ -63,16 +63,13 @@ function rowLength(g, M, r, edge) {
|
|
|
63
63
|
if (f < lo)
|
|
64
64
|
f = lo;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
f *= w;
|
|
71
|
-
squeezed = bent = true;
|
|
72
|
-
}
|
|
73
|
-
else
|
|
74
|
-
w = 1;
|
|
66
|
+
let w = wheelAt(g, M, r, edge + len + step / 2);
|
|
67
|
+
if (w > 1) {
|
|
68
|
+
f *= w;
|
|
69
|
+
squeezed = bent = true;
|
|
75
70
|
}
|
|
71
|
+
else
|
|
72
|
+
w = 1;
|
|
76
73
|
if (acc + f * step >= d) {
|
|
77
74
|
// Wide enough all the way: exactly one rank depth, with no accumulated rounding, so in the open the column is
|
|
78
75
|
// bit for bit the formation it was made from
|
|
@@ -90,8 +87,7 @@ function rowLength(g, M, r, edge) {
|
|
|
90
87
|
* Where each rank stands with the front rank `b` behind the probe: from the front rank back, one after another, each
|
|
91
88
|
* taking the stretch `rowLength` gives. Results go to `rb` (distance of the rank's middle behind the probe), `rl`
|
|
92
89
|
* (length of its stretch), `re` (how much further back it is than unfolded) and, when given, `wh` (how much further
|
|
93
|
-
* the rank's outermost place moves than its point on the trail, averaged over its stretch
|
|
94
|
-
* `MarchRules.wheel`).
|
|
90
|
+
* the rank's outermost place moves than its point on the trail, averaged over its stretch).
|
|
95
91
|
*/
|
|
96
92
|
export function rowsAt(g, M, b, rb, rl, re, wh) {
|
|
97
93
|
let extra = 0;
|
|
@@ -127,13 +123,9 @@ export const SLOT = { x: 0, y: 0, hx: 0, hy: 0, cx: 0, cy: 0, b: 0, l: 0, half:
|
|
|
127
123
|
*/
|
|
128
124
|
export function marchSlot(g, M, r, c, l) {
|
|
129
125
|
const rw = g.rowW[r], sp = g.rowSp[r], len = g.rowLen[r];
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (M.wheel) {
|
|
134
|
-
const fw = (widthAt(g, M, g.rowB[r]) - g.rowRad[r] * 2) / rw;
|
|
135
|
-
m = fw >= 1 ? 1 : fw * M.stretchMax < 1 ? M.stretchMax : 1 / fw;
|
|
136
|
-
}
|
|
126
|
+
// The stretch shortens on bends, so only the usable width at the rank's middle determines folding.
|
|
127
|
+
const fw = (widthAt(g, M, g.rowB[r]) - g.rowRad[r] * 2) / rw;
|
|
128
|
+
const m = fw >= 1 ? 1 : fw * M.stretchMax < 1 ? M.stretchMax : 1 / fw;
|
|
137
129
|
const E = M.foldEase;
|
|
138
130
|
let ph = 0, dc = 0;
|
|
139
131
|
for (let k = 0, p2 = 1; k < 7 && p2 < m; k++, p2 *= 2) {
|
package/dist/marchTrail.js
CHANGED
|
@@ -277,6 +277,9 @@ export function routeCut(gr, g, M) {
|
|
|
277
277
|
const k = ((g.lead - g.rec) / M.trailStep) | 0;
|
|
278
278
|
if (k >= g.cap)
|
|
279
279
|
return false;
|
|
280
|
-
const
|
|
281
|
-
|
|
280
|
+
const o = pt(g, k), c = g.trail[o + T_CELL];
|
|
281
|
+
if (c < 0)
|
|
282
|
+
return false;
|
|
283
|
+
const x = g.trail[o], y = g.trail[o + 1];
|
|
284
|
+
return gr.probeBlocked?.(x, y, x, y) ?? gr.solid(c);
|
|
282
285
|
}
|
package/dist/marchTypes.d.ts
CHANGED
|
@@ -27,15 +27,15 @@ export interface MarchRules {
|
|
|
27
27
|
lagStop: number;
|
|
28
28
|
/** The most one member counts for in that average. Default 400. */
|
|
29
29
|
lagCap: number;
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/** While opposed, members this far ahead of their place may push on along their own route. Infinity keeps them in formation. */
|
|
31
|
+
pushAhead: number;
|
|
32
32
|
/** The most the probe's heading (the direction the ranks face) turns per second. Default 1.4. */
|
|
33
33
|
turn: number;
|
|
34
|
-
/** The column's turning radius is half its width, and at least this; unlimited within one width of the goal. Default 40. */
|
|
34
|
+
/** The column's turning radius is half its usable width, and at least this; unlimited within one width of the goal. Default 40. */
|
|
35
35
|
turnR: number;
|
|
36
36
|
/** While the heading still turns, the probe may walk at most this far off it, so the ranks sidestep onto the route. Default 0.6. */
|
|
37
37
|
slide: number;
|
|
38
|
-
/** How far the probe looks along the route to straighten it: width × `lookK`, at least `lookMin`. Defaults 0.75,
|
|
38
|
+
/** How far the probe looks along the route to straighten it: width × `lookK`, at least `lookMin`. Defaults 0.75, 320. */
|
|
39
39
|
lookK: number;
|
|
40
40
|
lookMin: number;
|
|
41
41
|
/** The probe leads the front rank by the distance the ranks need to narrow from full width to nothing, plus this. Default 48. */
|
|
@@ -57,15 +57,13 @@ export interface MarchRules {
|
|
|
57
57
|
narrow: number;
|
|
58
58
|
/** The most a rank stretches along the trail in a narrow place; narrower still, its members close up sideways. Default 4. */
|
|
59
59
|
stretchMax: number;
|
|
60
|
-
/** A rank's cross-section starts turning from square to the column towards the direction of the narrow place when the usable width drops below `axisFrom` of the column's width, and follows it fully at `axisFull`. Defaults 0.
|
|
60
|
+
/** A rank's cross-section starts turning from square to the column towards the direction of the narrow place when the usable width drops below `axisFrom` of the column's width, and follows it fully at `axisFull`. Defaults 0.5, 0.3. */
|
|
61
61
|
axisFrom: number;
|
|
62
62
|
axisFull: number;
|
|
63
63
|
/** Each fold of a rank first staggers members front to back, then closes them up sideways; each takes this share of a doubling of the stretch. Default 0.3. */
|
|
64
64
|
foldEase: number;
|
|
65
65
|
/** No rank is asked for more than this share of its slowest member's full speed; a column with folded ranks moves up to that. Default 0.88. */
|
|
66
66
|
trot: number;
|
|
67
|
-
/** A member that finds its own way while its place is behind it moves at its rank's pace, and at least this share of its own speed. Default 0.3. */
|
|
68
|
-
apartTrail: number;
|
|
69
67
|
/** A new route keeps the column when the cosine between its first direction and the front rank's heading is at least this (0 = up to a right angle); otherwise the group forms up again. Default 0. */
|
|
70
68
|
rerouteCos: number;
|
|
71
69
|
/** After the front rank arrives, the column keeps leading ranks through a narrow place for at most this many seconds. Default 20. */
|
|
@@ -74,42 +72,6 @@ export interface MarchRules {
|
|
|
74
72
|
opposedLinger: number;
|
|
75
73
|
/** A member aims at where its place will be this many seconds from now, so it settles at its rank's pace. Default 0.4. */
|
|
76
74
|
leadTime: number;
|
|
77
|
-
/**
|
|
78
|
-
* Also keep clear of an obstacle on one side of the route only, and of obstacles too thin to block a whole wing:
|
|
79
|
-
* the ranks move over to the open side, or close up between two such obstacles; a wall that runs on for half the
|
|
80
|
-
* column's width or more makes a narrow place however thin it is, so a corridor between thin walls is measured
|
|
81
|
-
* straight across; and where the way is narrower than the column, the column turns as tightly as half the way's
|
|
82
|
-
* width instead of half its own. Default false: only a place with a large obstacle on both sides narrows the
|
|
83
|
-
* column; elsewhere members whose places are cut off close in towards their rank's middle on their own, which
|
|
84
|
-
* crowds them when the route runs right along a wall.
|
|
85
|
-
*/
|
|
86
|
-
flank: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Form up along the route: facing the way it sets off (the furthest point in sight along it), the rear rank as far
|
|
89
|
-
* behind the group's centre as there is room for (at most half the column's depth), and the ranks ahead of it
|
|
90
|
-
* along the way the probe walks. A route still being searched is finished on the spot for it, whatever the flow
|
|
91
|
-
* fields' budget. Default false: the column forms up in a straight line round the centre, facing the goal; a
|
|
92
|
-
* column whose route sets off round an obstacle then wheels onto it as it sets off, and one that forms up in a
|
|
93
|
-
* cramped place has ranks whose places are in or behind a wall.
|
|
94
|
-
*/
|
|
95
|
-
faceRoute: boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Wheel in turn: on a bend each rank moves at the pace at which its outermost place keeps the column's speed, as
|
|
98
|
-
* the inner flank of a wheeling line shortens its step for the outer one. Along the trail the ranks on the bend
|
|
99
|
-
* close up; the ranks before it march up at the column's pace and the ranks past it march on at it. The front
|
|
100
|
-
* rank slows only while it is on a bend itself. Default false: every rank keeps the column's pace along the trail
|
|
101
|
-
* through a bend, the members on the outside of it fall behind their places and catch up on the next straight
|
|
102
|
-
* stretch.
|
|
103
|
-
*/
|
|
104
|
-
wheel: boolean;
|
|
105
|
-
/**
|
|
106
|
-
* When straightening the route, prefer a point the walk to which is clear this share of the column's width to
|
|
107
|
-
* each side (with `flank`, of the usable width where that is less) to a further one that is only just in sight
|
|
108
|
-
* past a corner. For routes that keep their distance from walls (a game that charges for ground near obstacles):
|
|
109
|
-
* straightened by sight alone they would be drawn back to the corners they go round. Default 0: the furthest
|
|
110
|
-
* point in sight.
|
|
111
|
-
*/
|
|
112
|
-
lookClear: number;
|
|
113
75
|
}
|
|
114
76
|
export declare const DEFAULT_MARCH_RULES: Readonly<MarchRules>;
|
|
115
77
|
/**
|
|
@@ -121,6 +83,15 @@ export declare const DEFAULT_MARCH_RULES: Readonly<MarchRules>;
|
|
|
121
83
|
* @param overrides Rule values to use instead, as given (not scaled).
|
|
122
84
|
*/
|
|
123
85
|
export declare function marchRules(scale: number, overrides?: Partial<Omit<MarchRules, 'scale'>>): MarchRules;
|
|
86
|
+
/** Physical edges of a local passage, measured from the query point in world units. */
|
|
87
|
+
export interface MarchCrossSection {
|
|
88
|
+
/** Unit vector across the passage. Either orientation is valid. */
|
|
89
|
+
axisX: number;
|
|
90
|
+
axisY: number;
|
|
91
|
+
/** Non-negative distances to the edges along and against the axis, before padding or member radii. Infinity means open. */
|
|
92
|
+
positive: number;
|
|
93
|
+
negative: number;
|
|
94
|
+
}
|
|
124
95
|
/**
|
|
125
96
|
* The map as one group of marchers sees it. A game with several movement layers (sides with different gates, say)
|
|
126
97
|
* gives one ground per layer. Cells are numbered row-major, `cell = y × w + x`.
|
|
@@ -135,11 +106,18 @@ export interface MarchGround {
|
|
|
135
106
|
/** The cell holding a world position. */
|
|
136
107
|
cellAt(x: number, y: number): number;
|
|
137
108
|
/**
|
|
138
|
-
*
|
|
139
|
-
* one. Every blocked cell is solid; a game may have solid cells that can be walked over (a wall top, say).
|
|
109
|
+
* Solid for cell-based width measurements, forming up and trail checks. Every blocked cell is solid; a game may have solid cells that can be walked over (a wall top, say).
|
|
140
110
|
*/
|
|
141
111
|
solid(cell: number): boolean;
|
|
142
|
-
/**
|
|
112
|
+
/** Local cross-section at a trail point travelling along (tx, ty). Return undefined to measure the solid cells. */
|
|
113
|
+
crossSection?(x: number, y: number, tx: number, ty: number): MarchCrossSection | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Optional world-space obstruction test for a probe step, including steps inside one cell and the final step
|
|
116
|
+
* to the goal. A zero-length step tests a point when forming up or rechecking the trail. Return undefined to use
|
|
117
|
+
* the ordinary cell rules here. Keep this consistent with standable, lineBlocked and lineReach, including gates.
|
|
118
|
+
*/
|
|
119
|
+
probeBlocked?(ax: number, ay: number, bx: number, by: number): boolean | undefined;
|
|
120
|
+
/** The cell cannot be walked into under the cell-based probe rules. */
|
|
143
121
|
blocked(cell: number): boolean;
|
|
144
122
|
/** Whether a member may step from a cell to a neighbouring one (both passable). */
|
|
145
123
|
canStep(from: number, to: number): boolean;
|
|
@@ -150,7 +128,7 @@ export interface MarchGround {
|
|
|
150
128
|
/** Whether the straight walk between two points is blocked, and how much of it is clear (1 = all of it). */
|
|
151
129
|
lineBlocked(ax: number, ay: number, bx: number, by: number): boolean;
|
|
152
130
|
lineReach(ax: number, ay: number, bx: number, by: number): number;
|
|
153
|
-
/** Whether a member can stand at
|
|
131
|
+
/** Whether a member can stand at this world position, including any subcell terrain. */
|
|
154
132
|
standable(x: number, y: number): boolean;
|
|
155
133
|
/** The flow field towards a cell, and finishing its search at once. */
|
|
156
134
|
field(cell: number): FlowField;
|
|
@@ -241,7 +219,7 @@ export interface March {
|
|
|
241
219
|
blocked: boolean;
|
|
242
220
|
/** The group is not marching in ranks for now (held by engagement, or most members acting on their own); it forms up again afterwards. */
|
|
243
221
|
loose: boolean;
|
|
244
|
-
/** Seconds the group still counts as opposed; while positive, members
|
|
222
|
+
/** Seconds the group still counts as opposed; while positive, members more than `pushAhead` ahead of their places may advance independently. */
|
|
245
223
|
opposedT: number;
|
|
246
224
|
/** Members with an opponent (counted every 8 steps). */
|
|
247
225
|
cOpposed: number;
|
|
@@ -265,7 +243,7 @@ export interface March {
|
|
|
265
243
|
/** The column's width and depth when not folded. */
|
|
266
244
|
width: number;
|
|
267
245
|
depth: number;
|
|
268
|
-
/** The usable width recorded on each side where nothing was measured:
|
|
246
|
+
/** The usable width recorded on each side where nothing was measured: the whole width plus the largest member radius, so a rank has room to move over. */
|
|
269
247
|
open: number;
|
|
270
248
|
/** Distance from the probe to the nearest narrow place on the trail (Infinity = none). */
|
|
271
249
|
narrowB: number;
|
package/dist/marchTypes.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export const DEFAULT_MARCH_RULES = Object.freeze({
|
|
2
2
|
scale: 1,
|
|
3
|
-
lagFull: 30, lagStop: 110, lagCap: 400,
|
|
3
|
+
lagFull: 30, lagStop: 110, lagCap: 400, pushAhead: Infinity, turn: 1.4, turnR: 40, slide: 0.6, lookK: 0.75, lookMin: 320, probePad: 48,
|
|
4
4
|
holdEngaged: 0.15, trailStep: 12, overMin: 0.03, narrowIn: 0.55, narrowOut: 1, chokePad: 1, chokeMin: 32, narrow: 0.95,
|
|
5
|
-
stretchMax: 4, axisFrom: 0.
|
|
6
|
-
opposedLinger: 5, leadTime: 0.4,
|
|
5
|
+
stretchMax: 4, axisFrom: 0.5, axisFull: 0.3, foldEase: 0.3, trot: 0.88, rerouteCos: 0, tailMax: 20,
|
|
6
|
+
opposedLinger: 5, leadTime: 0.4,
|
|
7
7
|
});
|
|
8
8
|
/** The rules that are distances: the ones `marchRules` scales. */
|
|
9
|
-
const LENGTHS = ['lagFull', 'lagStop', 'lagCap', '
|
|
9
|
+
const LENGTHS = ['lagFull', 'lagStop', 'lagCap', 'pushAhead', 'turnR', 'lookMin', 'probePad', 'trailStep', 'chokePad', 'chokeMin'];
|
|
10
10
|
/**
|
|
11
11
|
* The default rules for a world `scale` times the size of the one they were made for (cells of about 32 units,
|
|
12
12
|
* members about 12 across): every rule that is a distance is multiplied by `scale`, and so are the built-in
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pocketrts/grid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Grid algorithms for RTS games: budgeted flow fields, bounded local A*, line reach, distance fields, bucket grids, field of view, polygons, cell chains, line formations and column march",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Junjie Bai <bjj19851010@gmail.com>",
|