@korial29/tiny-fps 0.193.0 → 0.195.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -829,7 +829,7 @@ var roleOf = (role, def) => {
829
829
  var kitOf = (role, def) => KITS[roleOf(role, def)];
830
830
  // src/shared/world.ts
831
831
  /** Metres per grid cell: about the size of the player's reach, so a query touches 1 to 4 cells. */
832
- var CELL = 4;
832
+ var CELL$1 = 4;
833
833
  /** Cell coordinates run from -OFF to OFF - 1: a 8 km square at 4 m, far more than any map. */
834
834
  var OFF = 1024;
835
835
  /** The key of the cell with integer coordinates (cx, cz). */
@@ -837,7 +837,7 @@ var key = (cx, cz) => (cx + OFF) * (2 * OFF) + cz + OFF;
837
837
  /** Integer cell coordinate of a metre value, clamped to the keyed range. */
838
838
  var at$3 = (v, cell) => Math.min(Math.max(Math.floor(v / cell), -1024), 1023);
839
839
  /** Builds the grid: each brush is listed in every cell its footprint covers. */
840
- var build$1 = (def, cell = CELL) => {
840
+ var build$1 = (def, cell = CELL$1) => {
841
841
  const grid = /* @__PURE__ */ new Map();
842
842
  def.brushes.forEach(({ min, max }, i) => {
843
843
  for (let cx = at$3(min[0], cell); cx <= at$3(max[0], cell); cx++) for (let cz = at$3(min[2], cell); cz <= at$3(max[2], cell); cz++) {
@@ -858,13 +858,21 @@ var build$1 = (def, cell = CELL) => {
858
858
  })) } : {}
859
859
  };
860
860
  };
861
+ /** The call of near() that last listed each brush, so a brush in several cells is listed once (the bots' mesh asks for hundreds). */
862
+ var marks = /* @__PURE__ */ new Uint32Array(0);
863
+ var mark = 0;
861
864
  /**
862
865
  * Indices of the brushes whose footprint may overlap the square of half side r around (x, z): every
863
866
  * brush listed in a cell the square touches, once each. A candidate list, not an exact overlap.
864
867
  */
865
868
  var near = (w, x, z, r) => {
866
869
  const out = [];
867
- for (let cx = at$3(x - r, w.cell); cx <= at$3(x + r, w.cell); cx++) for (let cz = at$3(z - r, w.cell); cz <= at$3(z + r, w.cell); cz++) for (const i of w.grid.get(key(cx, cz)) ?? []) if (!out.includes(i)) out.push(i);
870
+ if (marks.length < w.def.brushes.length) marks = new Uint32Array(w.def.brushes.length);
871
+ mark = mark + 1 >>> 0 || (marks.fill(0), 1);
872
+ for (let cx = at$3(x - r, w.cell); cx <= at$3(x + r, w.cell); cx++) for (let cz = at$3(z - r, w.cell); cz <= at$3(z + r, w.cell); cz++) for (const i of w.grid.get(key(cx, cz)) ?? []) if (marks[i] !== mark) {
873
+ marks[i] = mark;
874
+ out.push(i);
875
+ }
868
876
  return out;
869
877
  };
870
878
  /**
@@ -1088,7 +1096,7 @@ var gap = (b, x, z) => [x - clamp$3(x, b.min[0], b.max[0]), z - clamp$3(z, b.min
1088
1096
  * step of that size cannot bring the centre across one, however thin. The candidates come from
1089
1097
  * near() with twice PLAYER_R, enough for the one push of at most PLAYER_R that matters.
1090
1098
  */
1091
- var push = (p, w, h) => shove(p, w, h, PLAYER_R);
1099
+ var push$1 = (p, w, h) => shove(p, w, h, PLAYER_R);
1092
1100
  /** push() for a circle of radius r: a rover's body is a few of them. */
1093
1101
  var shove = (p, w, h, r) => {
1094
1102
  const { brushes } = w.def;
@@ -1438,10 +1446,10 @@ var fly$1 = (p, w, h, g, snap, bodies) => {
1438
1446
  const y0 = p.y;
1439
1447
  p.x += p.vx * DT$2;
1440
1448
  p.z += p.vz * DT$2;
1441
- let [cx, cz] = push(p, w, h);
1449
+ let [cx, cz] = push$1(p, w, h);
1442
1450
  const [jx, jz] = jostle(p, bodies, h);
1443
1451
  if (jx || jz) {
1444
- const [ex, ez] = push(p, w, h);
1452
+ const [ex, ez] = push$1(p, w, h);
1445
1453
  cx += jx + ex;
1446
1454
  cz += jz + ez;
1447
1455
  }
@@ -5167,142 +5175,76 @@ var UP = {
5167
5175
  }
5168
5176
  };
5169
5177
  // src/shared/nav.ts
5178
+ /** How a body goes through a portal: walks either way, drops down it, or jumps up onto a box. */
5179
+ var PASS = {
5180
+ WALK: 0,
5181
+ DROP: 1,
5182
+ HOP: 2
5183
+ };
5170
5184
  /** Metres a second a bot is taken to run, for the costs. */
5171
5185
  var PACE = 7;
5172
5186
  /** Seconds added to a jump, and to a jump that wants a dash, a double jump or a wall-run. */
5173
5187
  var LEAP = .5;
5174
5188
  var TRICK = 1.5;
5175
- /** The longest straight walk between two points, metres. */
5176
- var WALK = 30;
5177
- /** The most a straight walk steps down, metres: off a plinth, down a short drop. */
5189
+ /** Seconds added to a drop and to a jump onto a box. */
5190
+ var DOWN = .3;
5191
+ var HOP_COST = 1;
5192
+ /** The highest box a body jumps onto standing (a standing jump lands on 1.7 m), and the floor it wants behind the edge. */
5193
+ var HOP$1 = 1.6;
5194
+ var HOP_DEPTH$1 = 2.5;
5195
+ /** The most a body drops onto any floor; past it, it wants SPAN metres of floor ahead to come down on at a run. */
5178
5196
  var DROP$1 = 2;
5179
- /**
5180
- * Metres to the nearest node a bot heads for when no straight walk reaches one (the moon's relief
5181
- * fails most, a stair all), how far above it may be (up a stair, or a ledge to climb) and how far
5182
- * below: a drop that does not hurt at full gravity.
5183
- */
5184
- var NEAR = 20;
5185
- var ABOVE = 2.2;
5186
- /** Two points of the routes this close (metres, and in height) are one. */
5187
- var SAME = .6;
5197
+ var SPAN = 4;
5198
+ /** Seconds added to a crossing of a route the bot does not prefer: the bridge's rectangles, a jump's first link. */
5199
+ var AREA = 20;
5200
+ /** The widest crack two rectangles are joined across: a drop's, where the higher's edge is a body's radius off the lower. */
5201
+ var PORTAL = PLAYER_R + .1;
5202
+ /** Metres a wall is kept off: the body's radius and a little. */
5203
+ var KEEP = PLAYER_R + .05;
5204
+ /** Metres back along a jump's way a bot comes at its take-off from. */
5205
+ var RUN_IN = 3;
5206
+ /** Metres the ends of a portal are drawn in, at most. */
5207
+ var EDGE = .7;
5208
+ /** The relief's squares merged into a rectangle at most, a side. */
5209
+ var MERGE = 8;
5210
+ /** Metres of grid cell. */
5211
+ var CELL = 4;
5212
+ /** A link of a route the bot does not prefer costs this many times more, one of its own as many times less. */
5213
+ var OTHER = 3;
5188
5214
  /** The routes, fastest first: the Spine, Midtown, the Lowline. */
5189
5215
  var ROUTES = [
5190
5216
  HIGH,
5191
5217
  MID,
5192
5218
  LOW
5193
5219
  ];
5194
- /** A leg of a route the bot does not prefer costs this many times more. */
5195
- var OTHER = 3;
5196
5220
  /**
5197
- * MOON's lanes in red's half, walked straight from point to point both ways: round the dome on the
5198
- * west (the modules close the east), in at its door to the flag, and across the field to the three
5199
- * crossings of the rille (the bridge, the west jump's run-up, the east stones' lip). Blue's are
5200
- * their mirror across z = 140. Relief and boulders fail walkable(), so these are not checked: a
5201
- * bot jumps what it bumps into.
5221
+ * MOON's walks across the rille, x0 and x1 and the route each is a crossing of: the bridge (the
5222
+ * first), and round the rille's two closed ends (the west with the long jump, the east with the
5223
+ * stones). The jumps are links of their own.
5202
5224
  */
5203
- var LANES = [
5225
+ var ACROSS = [
5204
5226
  [
5205
- [
5206
- 72,
5207
- 0,
5208
- 258
5209
- ],
5210
- [
5211
- 80,
5212
- 0,
5213
- 269
5214
- ],
5215
- [
5216
- 52,
5217
- 0,
5218
- 270
5219
- ],
5220
- [
5221
- 50,
5222
- 0,
5223
- 212
5224
- ],
5225
- [
5226
- 80,
5227
- 0,
5228
- 208
5229
- ],
5230
- [
5231
- 80,
5232
- 0,
5233
- 214.5
5234
- ],
5235
- [
5236
- 80,
5237
- 0,
5238
- 224
5239
- ],
5240
- [
5241
- 80,
5242
- 1,
5243
- 232
5244
- ]
5227
+ 74,
5228
+ 86,
5229
+ 0
5245
5230
  ],
5246
5231
  [
5247
- [
5248
- 80,
5249
- 0,
5250
- 208
5251
- ],
5252
- [
5253
- 80,
5254
- 0,
5255
- 152
5256
- ],
5257
- [
5258
- 80,
5259
- 0,
5260
- 140
5261
- ]
5262
- ],
5263
- [[
5264
- 50,
5265
- 0,
5266
- 212
5267
- ], [
5268
- 18,
5269
- 0,
5270
- 190
5271
- ]],
5272
- [[
5273
- 18,
5274
- 0,
5275
- 125
5276
- ], [
5277
- 18,
5232
+ -60,
5278
5233
  0,
5279
- 90
5280
- ]],
5234
+ 1
5235
+ ],
5281
5236
  [
5282
- [
5283
- 80,
5284
- 0,
5285
- 208
5286
- ],
5287
- [
5288
- 128.5,
5289
- 0,
5290
- 160
5291
- ],
5292
- [
5293
- 128.5,
5294
- 0,
5295
- 150
5296
- ]
5237
+ 160,
5238
+ 220,
5239
+ 2
5297
5240
  ]
5298
5241
  ];
5299
5242
  /**
5300
5243
  * The jumps over MOON's rille from red's side, as moon.test.ts flies them: the west long jump (a
5301
5244
  * sprint jumped at the lip, a dash late in the air), and the east stones at 1.2, 2.4 and 1.2 m,
5302
- * each a jump that comes down on the stone. Blue's are their mirror. With the bridge (LANES[1]),
5303
- * they are the moon's three routes, an index of ROUTES each, so that bots spread over them.
5245
+ * each a jump that comes down on the stone. Blue's are their mirror. With the bridge, they are the
5246
+ * moon's three routes, an index of ROUTES each, so that bots spread over them.
5304
5247
  */
5305
- var BRIDGE = 1;
5306
5248
  var CROSSINGS = [[
5307
5249
  1,
5308
5250
  [
@@ -5358,81 +5300,332 @@ var end = (l) => [
5358
5300
  l.y,
5359
5301
  l.to[1]
5360
5302
  ];
5361
- /** Where a leg starts its own move: a jump's take-off, a slide's run-in, a run's goal. */
5362
- var from = (l) => l.k === "leap" ? l.at : l.k === "slide" ? l.from : l.to;
5363
- var flat$2 = (a, b) => {
5364
- const [ax, az] = a.length === 3 ? [a[0], a[2]] : a;
5365
- const [bx, bz] = b.length === 3 ? [b[0], b[2]] : b;
5366
- return Math.sqrt((bx - ax) ** 2 + (bz - az) ** 2);
5367
- };
5368
- /**
5369
- * Whether a body walks in a straight line from a to b, a step up or a drop of DROP at most: a floor
5370
- * under the middle and both sides of the body every half metre, and nothing in the way at the knees
5371
- * or the head from the height of a.
5372
- */
5373
- var walkable = (w, a, b) => {
5374
- if (b[1] - a[1] > .5 || a[1] - b[1] > DROP$1) return false;
5375
- const d = flat$2(a, b);
5376
- if (d < .001) return true;
5377
- const [ux, uz] = [(b[0] - a[0]) / d, (b[2] - a[2]) / d];
5378
- const y = Math.min(a[1], b[1]);
5379
- for (const s of [
5380
- -PLAYER_R,
5381
- 0,
5382
- PLAYER_R
5383
- ]) {
5384
- const [ox, oz] = [a[0] - uz * s, a[2] + ux * s];
5385
- for (const h of [STEP_H + .1, 1.5]) if (ray(w, [
5386
- ox,
5387
- a[1] + h,
5388
- oz
5389
- ], [
5390
- ux,
5391
- 0,
5392
- uz
5393
- ], d) < d) return false;
5394
- for (let t = 0; t <= d; t += .5) if (floorAt(w, ox + ux * t, oz + uz * t, Math.max(a[1], b[1]) + .5) < y - .3) return false;
5395
- }
5396
- return true;
5303
+ var flat$2 = (ax, az, bx, bz) => Math.sqrt((bx - ax) ** 2 + (bz - az) ** 2);
5304
+ /** The rectangle r less h: up to four rectangles. */
5305
+ var cut$1 = (r, h) => {
5306
+ if (h[0] >= r[2] || h[2] <= r[0] || h[1] >= r[3] || h[3] <= r[1]) return [r];
5307
+ const out = [];
5308
+ const [x0, x1] = [Math.max(r[0], h[0]), Math.min(r[2], h[2])];
5309
+ if (h[0] > r[0]) out.push([
5310
+ r[0],
5311
+ r[1],
5312
+ h[0],
5313
+ r[3]
5314
+ ]);
5315
+ if (h[2] < r[2]) out.push([
5316
+ h[2],
5317
+ r[1],
5318
+ r[2],
5319
+ r[3]
5320
+ ]);
5321
+ if (h[1] > r[1]) out.push([
5322
+ x0,
5323
+ r[1],
5324
+ x1,
5325
+ h[1]
5326
+ ]);
5327
+ if (h[3] < r[3]) out.push([
5328
+ x0,
5329
+ h[3],
5330
+ x1,
5331
+ r[3]
5332
+ ]);
5333
+ return out;
5397
5334
  };
5398
- var built = /* @__PURE__ */ new WeakMap();
5399
- /** The bots' map of a world, built once per world. */
5400
- var navOf = (w) => {
5401
- let nav = built.get(w);
5402
- if (!nav) {
5403
- nav = build(w);
5404
- built.set(w, nav);
5335
+ /** Rectangles that share a whole side, merged, until none do. */
5336
+ var merge = (rs) => {
5337
+ for (let i = 0; i < rs.length; i++) for (let j = i + 1; j < rs.length; j++) {
5338
+ const [a, b] = [rs[i], rs[j]];
5339
+ const m = a[0] === b[0] && a[2] === b[2] && (a[3] === b[1] || b[3] === a[1]) ? [
5340
+ a[0],
5341
+ Math.min(a[1], b[1]),
5342
+ a[2],
5343
+ Math.max(a[3], b[3])
5344
+ ] : a[1] === b[1] && a[3] === b[3] && (a[2] === b[0] || b[2] === a[0]) ? [
5345
+ Math.min(a[0], b[0]),
5346
+ a[1],
5347
+ Math.max(a[2], b[2]),
5348
+ a[3]
5349
+ ] : void 0;
5350
+ if (m) {
5351
+ rs[i] = m;
5352
+ rs.splice(j, 1);
5353
+ j = i;
5354
+ }
5405
5355
  }
5406
- return nav;
5356
+ return rs;
5407
5357
  };
5408
- var build = (w) => {
5409
- const nodes = [];
5358
+ /** The height of a rectangle's floor at (x, z). */
5359
+ var heightAt = (w, p, x, z) => p.r ? ground(w, x, z) : p.y;
5360
+ /** The relief's ground as rectangles of whole squares, none over the hole, a pit or past the bound. */
5361
+ var lowlands = (w) => {
5362
+ const r = w.relief;
5363
+ if (!r) return [];
5364
+ const { x0, z0, cell, nx, nz, hole, pits, pitted, bound } = r;
5365
+ const [cx, cz, ea, eb] = bound;
5366
+ const [mx, mz] = [nx - 1, nz - 1];
5367
+ const over = (q, h) => q[0] < h[2] && q[2] > h[0] && q[1] < h[3] && q[3] > h[1];
5368
+ const free = new Uint8Array(mx * mz);
5369
+ for (let j = 0; j < mz; j++) for (let i = 0; i < mx; i++) {
5370
+ const q = [
5371
+ x0 + i * cell,
5372
+ z0 + j * cell,
5373
+ x0 + (i + 1) * cell,
5374
+ z0 + (j + 1) * cell
5375
+ ];
5376
+ let inside = true;
5377
+ for (const [x, z] of [
5378
+ [q[0], q[1]],
5379
+ [q[2], q[1]],
5380
+ [q[0], q[3]],
5381
+ [q[2], q[3]]
5382
+ ]) inside &&= ((x - cx) / ea) ** 2 + ((z - cz) / eb) ** 2 <= 1;
5383
+ free[i + j * mx] = +(inside && !over(q, hole) && !(pitted[i + j * nx] && pits.some((p) => over(q, p))));
5384
+ }
5410
5385
  const out = [];
5411
- const runUp = /* @__PURE__ */ new Set();
5412
- const node = (p) => {
5413
- let i = nodes.findIndex((n) => flat$2(n, p) < SAME && Math.abs(n[1] - p[1]) < SAME);
5414
- if (i < 0) {
5415
- i = nodes.push(p) - 1;
5416
- out.push([]);
5386
+ for (let j = 0; j < mz; j++) for (let i = 0; i < mx; i++) {
5387
+ if (!free[i + j * mx]) continue;
5388
+ let a = 1;
5389
+ while (i + a < mx && a < MERGE && free[i + a + j * mx]) a++;
5390
+ let b = 1;
5391
+ while (j + b < mz && b < MERGE) {
5392
+ let row = true;
5393
+ for (let k = 0; k < a; k++) row &&= !!free[i + k + (j + b) * mx];
5394
+ if (!row) break;
5395
+ b++;
5417
5396
  }
5418
- return i;
5419
- };
5420
- const chain = (start, legs, route = -1) => {
5421
- let at = node(start);
5422
- for (const l of legs) {
5423
- const to = node(end(l));
5424
- const tricky = l.k === "leap" && (l.dash !== void 0 || l.double !== void 0 || l.run);
5425
- const cost = (flat$2(nodes[at], from(l)) + flat$2(from(l), end(l))) / PACE + (l.k === "go" ? 0 : tricky ? TRICK : LEAP);
5426
- out[at].push({
5427
- to,
5428
- leg: l,
5429
- route,
5430
- cost
5397
+ for (let l = 0; l < b; l++) free.fill(0, i + (j + l) * mx, i + a + (j + l) * mx);
5398
+ out.push([
5399
+ x0 + i * cell,
5400
+ z0 + j * cell,
5401
+ x0 + (i + a) * cell,
5402
+ z0 + (j + b) * cell
5403
+ ]);
5404
+ }
5405
+ return out;
5406
+ };
5407
+ /**
5408
+ * The floor of a world as rectangles a body's middle may stand on: each brush's top, and the
5409
+ * relief's ground, less the footprint of what stands on it within a body's height: kept KEEP off
5410
+ * a wall, cut to the edge of a box low enough to step onto (which is a floor of its own).
5411
+ */
5412
+ var floors = (w) => {
5413
+ const { brushes, floor } = w.def;
5414
+ const polys = [];
5415
+ const add = (q, y, r, self) => {
5416
+ const s = Math.max(q[2] - q[0], q[3] - q[1]) / 2 + KEEP;
5417
+ let rs = [q];
5418
+ for (const i of near(w, (q[0] + q[2]) / 2, (q[1] + q[3]) / 2, s)) {
5419
+ const b = brushes[i];
5420
+ if (i === self || b.max[0] <= q[0] - KEEP || b.min[0] >= q[2] + KEEP) continue;
5421
+ if (b.max[2] <= q[1] - KEEP || b.min[2] >= q[3] + KEEP) continue;
5422
+ let [lo, hi] = [y, y];
5423
+ if (r) {
5424
+ const [ax, az] = [Math.max(q[0], b.min[0]), Math.max(q[1], b.min[2])];
5425
+ const [bx, bz] = [Math.min(q[2], b.max[0]), Math.min(q[3], b.max[2])];
5426
+ const gs = [
5427
+ [ax, az],
5428
+ [bx, az],
5429
+ [ax, bz],
5430
+ [bx, bz],
5431
+ [(ax + bx) / 2, (az + bz) / 2]
5432
+ ].map(([x, z]) => ground(w, x, z));
5433
+ [lo, hi] = [Math.min(...gs), Math.max(...gs)];
5434
+ }
5435
+ const top = b.max[1];
5436
+ if (top < lo - .05 || b.min[1] >= hi + 1.8 - .05) continue;
5437
+ if (top <= hi + .001 && (r || !(top >= y - .001 && i < self))) continue;
5438
+ const k = top - hi <= .5 ? 0 : KEEP;
5439
+ rs = rs.flatMap((c) => cut$1(c, [
5440
+ b.min[0] - k,
5441
+ b.min[2] - k,
5442
+ b.max[0] + k,
5443
+ b.max[2] + k
5444
+ ]));
5445
+ }
5446
+ for (const c of merge(rs)) {
5447
+ const [x, z] = [(c[0] + c[2]) / 2, (c[1] + c[3]) / 2];
5448
+ if (c[2] - c[0] > .1 && c[3] - c[1] > .1 && (r || ground(w, x, z) <= y + .05)) polys.push({
5449
+ q: c,
5450
+ y,
5451
+ ...r ? { r } : {}
5431
5452
  });
5432
- if (l.k === "leap" && l.sprint && legs[0] !== l) runUp.add(at);
5433
- at = to;
5434
5453
  }
5435
5454
  };
5455
+ brushes.forEach((b, i) => {
5456
+ if (b.max[1] > floor) add([
5457
+ b.min[0],
5458
+ b.min[2],
5459
+ b.max[0],
5460
+ b.max[2]
5461
+ ], b.max[1], false, i);
5462
+ });
5463
+ for (const q of lowlands(w)) add(q, 0, true, -1);
5464
+ return polys;
5465
+ };
5466
+ /** The cells a rectangle touches, `m` metres round it. */
5467
+ var cells = (q, m, f) => {
5468
+ for (let cx = Math.floor((q[0] - m) / CELL); cx <= Math.floor((q[2] + m) / CELL); cx++) for (let cz = Math.floor((q[1] - m) / CELL); cz <= Math.floor((q[3] + m) / CELL); cz++) f(key(cx, cz));
5469
+ };
5470
+ /**
5471
+ * Joins the rectangles that touch, or face each other across a crack of PORTAL at most, along a
5472
+ * side: walked either way when their heights are a step apart, dropped down when the lower is a
5473
+ * fall that does not hurt, jumped up onto a box of HOP at most.
5474
+ */
5475
+ var portals = (w, polys, grid) => {
5476
+ const out = polys.map(() => []);
5477
+ const deep = 256 / (2 * gravity(w));
5478
+ const met = new Int32Array(polys.length).fill(-1);
5479
+ polys.forEach((pa, i) => {
5480
+ cells(pa.q, PORTAL, (k) => {
5481
+ for (const j of grid.get(k) ?? []) {
5482
+ if (j <= i || met[j] === i) continue;
5483
+ met[j] = i;
5484
+ const [a, b] = [pa.q, polys[j].q];
5485
+ const gx = Math.max(b[0] - a[2], a[0] - b[2]);
5486
+ const gz = Math.max(b[1] - a[3], a[1] - b[3]);
5487
+ const alongZ = gx > -.001 && gx <= PORTAL && gz < -.1;
5488
+ if (!alongZ && !(gz > -.001 && gz <= PORTAL && gx < -.1)) continue;
5489
+ const c = alongZ ? a[2] <= b[0] + .001 ? (a[2] + b[0]) / 2 : (a[0] + b[2]) / 2 : a[3] <= b[1] + .001 ? (a[3] + b[1]) / 2 : (a[1] + b[3]) / 2;
5490
+ const [s0, s1] = alongZ ? [Math.max(a[1], b[1]), Math.min(a[3], b[3])] : [Math.max(a[0], b[0]), Math.min(a[2], b[2])];
5491
+ const m = (s0 + s1) / 2;
5492
+ const at = (s) => alongZ ? [c, s] : [s, c];
5493
+ const [mx, mz] = at(m);
5494
+ const dy = heightAt(w, polys[j], mx, mz) - heightAt(w, pa, mx, mz);
5495
+ const [pa0, pa1] = [at(s0), at(s1)];
5496
+ const join = (from, to, pass) => out[from].push({
5497
+ to,
5498
+ a: pa0,
5499
+ b: pa1,
5500
+ pass,
5501
+ cost: 0
5502
+ });
5503
+ if (Math.abs(dy) <= .55) {
5504
+ join(i, j, PASS.WALK);
5505
+ join(j, i, PASS.WALK);
5506
+ } else {
5507
+ const [up, down] = dy > 0 ? [j, i] : [i, j];
5508
+ const depth = (k) => {
5509
+ const q = polys[k].q;
5510
+ return alongZ ? q[2] - q[0] : q[3] - q[1];
5511
+ };
5512
+ if (Math.abs(dy) <= DROP$1 || Math.abs(dy) <= deep && depth(down) >= SPAN) join(up, down, PASS.DROP);
5513
+ if (Math.abs(dy) <= HOP$1 && depth(up) >= HOP_DEPTH$1) join(down, up, PASS.HOP);
5514
+ }
5515
+ }
5516
+ });
5517
+ });
5518
+ return out;
5519
+ };
5520
+ /** A rectangle with (x, z) on or within `m` of it and its floor the highest not over y + 0.6, else -1. */
5521
+ var under = (nav, w, x, y, z, m) => {
5522
+ let best = -1;
5523
+ let top = -Infinity;
5524
+ for (const i of nav.grid.get(key(Math.floor(x / CELL), Math.floor(z / CELL))) ?? []) {
5525
+ const p = nav.polys[i];
5526
+ const q = p.q;
5527
+ if (x < q[0] - m || x > q[2] + m || z < q[1] - m || z > q[3] + m) continue;
5528
+ const h = heightAt(w, p, Math.min(Math.max(x, q[0]), q[2]), Math.min(Math.max(z, q[1]), q[3]));
5529
+ if (h <= y + .6 && h > top) [best, top] = [i, h];
5530
+ }
5531
+ return best;
5532
+ };
5533
+ /** The point of a rectangle nearest (x, z), on its floor. */
5534
+ var onto = (w, p, x, z) => {
5535
+ const [cx, cz] = [Math.min(Math.max(x, p.q[0]), p.q[2]), Math.min(Math.max(z, p.q[1]), p.q[3])];
5536
+ return [
5537
+ cx,
5538
+ heightAt(w, p, cx, cz),
5539
+ cz
5540
+ ];
5541
+ };
5542
+ /** Metres to the nearest floor of a body on none, and how far above and below him it may be. */
5543
+ var NEAR = 6;
5544
+ var ABOVE = 2.2;
5545
+ var BELOW = 8;
5546
+ /**
5547
+ * The rectangle a body at `v` stands on, or the nearest one within NEAR metres, at most ABOVE over
5548
+ * it and BELOW under it, as (index, the point of it to walk to); -1 when none.
5549
+ */
5550
+ var locate = (nav, w, v) => {
5551
+ const i = under(nav, w, v[0], v[1], v[2], PLAYER_R);
5552
+ if (i >= 0 && heightAt(w, nav.polys[i], v[0], v[2]) > v[1] - 1.5) return [i, onto(w, nav.polys[i], v[0], v[2])];
5553
+ let best = -1;
5554
+ let least = Infinity;
5555
+ let pt = v;
5556
+ const seen = /* @__PURE__ */ new Set();
5557
+ cells([
5558
+ v[0],
5559
+ v[2],
5560
+ v[0],
5561
+ v[2]
5562
+ ], NEAR, (k) => {
5563
+ for (const j of nav.grid.get(k) ?? []) {
5564
+ if (seen.has(j)) continue;
5565
+ seen.add(j);
5566
+ const o = onto(w, nav.polys[j], v[0], v[2]);
5567
+ const d = flat$2(v[0], v[2], o[0], o[2]) + Math.abs(o[1] - v[1]);
5568
+ if (d < least && o[1] - v[1] <= ABOVE && v[1] - o[1] <= BELOW) [best, least, pt] = [
5569
+ j,
5570
+ d,
5571
+ o
5572
+ ];
5573
+ }
5574
+ });
5575
+ return [least <= NEAR ? best : -1, pt];
5576
+ };
5577
+ /**
5578
+ * Adds a route's legs from `start` as links: a jump with the run up to it, a slide; the runs
5579
+ * between are the mesh's. With `toll`, the first is a crossing's (see Edge.toll).
5580
+ */
5581
+ var links = (nav, w, start, legs, route = -1, toll = false) => {
5582
+ let at = start;
5583
+ legs.forEach((l, k) => {
5584
+ const next = legs[k + 1];
5585
+ if (l.k === "go" && next?.k === "leap" && next.sprint) return;
5586
+ const run = legs[k - 1]?.k === "go" && l.k === "leap" && l.sprint;
5587
+ const from = at;
5588
+ if (l.k !== "go") {
5589
+ const [i] = locate(nav, w, from);
5590
+ const [j] = locate(nav, w, end(l));
5591
+ if (i >= 0 && j >= 0) {
5592
+ const tricky = l.k === "leap" && (l.dash !== void 0 || l.double !== void 0 || l.run);
5593
+ const pts = run ? [
5594
+ from,
5595
+ end(legs[k - 1]),
5596
+ end(l)
5597
+ ] : [from, end(l)];
5598
+ let len = 0;
5599
+ for (let n = 1; n < pts.length; n++) len += flat$2(pts[n - 1][0], pts[n - 1][2], pts[n][0], pts[n][2]);
5600
+ nav.out[i].push({
5601
+ to: j,
5602
+ from,
5603
+ end: end(l),
5604
+ legs: run ? [legs[k - 1], l] : [l],
5605
+ route,
5606
+ cost: len / PACE + (tricky ? TRICK : LEAP),
5607
+ ...toll && k === 0 ? { toll } : {}
5608
+ });
5609
+ }
5610
+ }
5611
+ at = end(l);
5612
+ });
5613
+ };
5614
+ var build = (w) => {
5615
+ const polys = floors(w);
5616
+ const grid = /* @__PURE__ */ new Map();
5617
+ polys.forEach((p, i) => cells(p.q, PORTAL, (k) => {
5618
+ const list = grid.get(k);
5619
+ if (list) list.push(i);
5620
+ else grid.set(k, [i]);
5621
+ }));
5622
+ const route = new Int8Array(polys.length).fill(-1);
5623
+ const nav = {
5624
+ polys,
5625
+ out: portals(w, polys, grid),
5626
+ grid,
5627
+ route
5628
+ };
5436
5629
  if (w.def === HIGHLINE) {
5437
5630
  const [red] = w.def.teams;
5438
5631
  for (const f of [(l) => l, flip]) {
@@ -5443,140 +5636,263 @@ var build = (w) => {
5443
5636
  ] : p;
5444
5637
  ROUTES.forEach((r, k) => {
5445
5638
  const [sx, sy, sz] = red.spawns[r.start];
5446
- chain(z([
5639
+ links(nav, w, z([
5447
5640
  sx,
5448
5641
  sy,
5449
5642
  sz
5450
5643
  ]), r.out.map(f), k);
5451
- if (r.flag.length) chain(z(red.base), [...r.flag, ...r.out].map(f), k);
5452
- chain(z(r.mid), r.in.map(f), k);
5644
+ if (r.flag.length) links(nav, w, z(red.base), [...r.flag, ...r.out].map(f), k);
5645
+ links(nav, w, z(r.mid), r.in.map(f), k);
5453
5646
  });
5454
- for (const u of Object.values(UP)) chain(z(u.from), u.legs.map(f));
5647
+ for (const u of Object.values(UP)) links(nav, w, z(u.from), u.legs.map(f));
5455
5648
  }
5456
5649
  }
5457
5650
  if (w.def === MOON) {
5458
- for (const [route, [x, y, z], legs] of CROSSINGS) {
5459
- chain([
5651
+ polys.forEach(({ q }, i) => {
5652
+ const a = ACROSS.find(([x0, x1]) => q[0] < x1 && q[2] > x0 && q[1] < 140 && q[3] > 140);
5653
+ if (a) route[i] = a[2];
5654
+ });
5655
+ for (const [k, [x, y, z], legs] of CROSSINGS) {
5656
+ links(nav, w, [
5460
5657
  x,
5461
5658
  y,
5462
5659
  z
5463
- ], legs, route);
5464
- chain([
5660
+ ], legs, k, true);
5661
+ links(nav, w, [
5465
5662
  x,
5466
5663
  y,
5467
5664
  280 - z
5468
- ], legs.map((l) => mirror(l, 280)), route);
5665
+ ], legs.map((l) => mirror(l, 280)), k, true);
5469
5666
  }
5470
- [...LANES, ...LANES.map((l) => l.map(([x, y, z]) => [
5471
- x,
5472
- y,
5473
- 280 - z
5474
- ]))].forEach((lane, i) => {
5475
- const route = i % LANES.length === BRIDGE ? 0 : -1;
5476
- for (let k = 1; k < lane.length; k++) {
5477
- const [a, b] = [node(lane[k - 1]), node(lane[k])];
5478
- const cost = flat$2(nodes[a], nodes[b]) / PACE;
5479
- out[a].push({
5480
- to: b,
5481
- route,
5482
- cost
5483
- });
5484
- out[b].push({
5485
- to: a,
5486
- route,
5487
- cost
5488
- });
5489
- }
5490
- });
5491
5667
  }
5492
- for (let i = 0; i < nodes.length; i++) for (let j = 0; j < nodes.length; j++) {
5493
- const d = flat$2(nodes[i], nodes[j]);
5494
- if (i !== j && !runUp.has(j) && d <= WALK && walkable(w, nodes[i], nodes[j])) out[i].push({
5495
- to: j,
5496
- route: -1,
5497
- cost: d / PACE
5498
- });
5668
+ return nav;
5669
+ };
5670
+ var built = /* @__PURE__ */ new WeakMap();
5671
+ /** The bots' map of a world, built once per world. */
5672
+ var navOf = (w) => {
5673
+ let nav = built.get(w);
5674
+ if (!nav) {
5675
+ nav = build(w);
5676
+ built.set(w, nav);
5499
5677
  }
5500
- return {
5501
- nodes,
5502
- out,
5503
- runUp
5504
- };
5678
+ return nav;
5505
5679
  };
5680
+ /** Twice the signed area of the triangle a, b, c on the floor plane. */
5681
+ var area = (a, b, c) => (c[0] - a[0]) * (b[1] - a[1]) - (b[0] - a[0]) * (c[1] - a[1]);
5506
5682
  /**
5507
- * The node a bot goes to, or from, when no straight walk joins it to the point `p`: among the nodes
5508
- * `ok` takes, within NEAR, the best by `weigh` whose height off `p` a body manages (a stair, a
5509
- * ledge to climb, a drop that does not hurt), `up` 1 when the bot goes from `p` to the node and -1
5510
- * when it goes from the node to `p`; with nothing in the way of the head first, then even hidden.
5511
- */
5512
- var close = (w, nodes, p, ok, weigh, up) => {
5513
- for (const clear of [true, false]) {
5514
- let best = -1;
5515
- let least = Infinity;
5516
- for (let i = 0; i < nodes.length; i++) {
5517
- const [d, dy] = [flat$2(p, nodes[i]), (nodes[i][1] - p[1]) * up];
5518
- const [ux, uz] = [(nodes[i][0] - p[0]) / (d || 1), (nodes[i][2] - p[2]) / (d || 1)];
5519
- const head = Math.max(p[1], nodes[i][1]) + 1.5;
5520
- if (ok(i) && d < NEAR && dy <= ABOVE && dy >= -8 && weigh(d, i) < least && (!clear || ray(w, [
5521
- p[0],
5522
- head,
5523
- p[2]
5524
- ], [
5525
- ux,
5526
- 0,
5527
- uz
5528
- ], d) >= d)) [best, least] = [i, weigh(d, i)];
5683
+ * The corners of the shortest line from `s` to `t` through the portals, each [left, right] as one
5684
+ * goes (the simple stupid funnel algorithm), `t` last.
5685
+ */
5686
+ var funnel = (s, ports, t) => {
5687
+ const ps = [...ports, [t, t]];
5688
+ const out = [];
5689
+ let [apex, left, right] = [
5690
+ s,
5691
+ s,
5692
+ s
5693
+ ];
5694
+ let [ai, li, ri] = [
5695
+ -1,
5696
+ -1,
5697
+ -1
5698
+ ];
5699
+ for (let i = 0; i < ps.length; i++) {
5700
+ const [l, r] = ps[i];
5701
+ if (area(apex, right, r) <= 0) {
5702
+ if (apex === right || area(apex, left, r) > 0) [right, ri] = [r, i];
5703
+ else {
5704
+ out.push(left);
5705
+ [apex, ai] = [left, li];
5706
+ [left, right, ri] = [
5707
+ apex,
5708
+ apex,
5709
+ ai
5710
+ ];
5711
+ i = ai;
5712
+ continue;
5713
+ }
5714
+ }
5715
+ if (area(apex, left, l) >= 0) {
5716
+ if (apex === left || area(apex, right, l) < 0) [left, li] = [l, i];
5717
+ else {
5718
+ out.push(right);
5719
+ [apex, ai] = [right, ri];
5720
+ [left, right, li] = [
5721
+ apex,
5722
+ apex,
5723
+ ai
5724
+ ];
5725
+ i = ai;
5726
+ continue;
5727
+ }
5529
5728
  }
5530
- if (best >= 0) return best;
5531
5729
  }
5532
- return -1;
5730
+ if (out.at(-1) !== t) out.push(t);
5731
+ return out;
5732
+ };
5733
+ /** A binary heap of indices by cost, smallest first. */
5734
+ var pop = (h, f) => {
5735
+ const top = h[0];
5736
+ const last = h.pop();
5737
+ if (h.length) {
5738
+ let i = 0;
5739
+ for (;;) {
5740
+ const [l, r] = [2 * i + 1, 2 * i + 2];
5741
+ let m = i;
5742
+ if (l < h.length && f[h[l]] < f[last] && (r >= h.length || f[h[l]] <= f[h[r]])) m = l;
5743
+ else if (r < h.length && f[h[r]] < f[last]) m = r;
5744
+ if (m === i) break;
5745
+ h[i] = h[m];
5746
+ i = m;
5747
+ }
5748
+ h[i] = last;
5749
+ }
5750
+ return top;
5751
+ };
5752
+ var push = (h, f, v) => {
5753
+ let i = h.push(v) - 1;
5754
+ while (i > 0) {
5755
+ const p = i - 1 >> 1;
5756
+ if (f[h[p]] <= f[v]) break;
5757
+ h[i] = h[p];
5758
+ i = p;
5759
+ }
5760
+ h[i] = v;
5761
+ };
5762
+ /** The point of the segment a b nearest (x, z). */
5763
+ var nearest = (a, b, x, z) => {
5764
+ const [dx, dz] = [b[0] - a[0], b[1] - a[1]];
5765
+ const t = Math.min(Math.max(((x - a[0]) * dx + (z - a[1]) * dz) / (dx * dx + dz * dz || 1), 0), 1);
5766
+ return [a[0] + dx * t, a[1] + dz * t];
5533
5767
  };
5534
5768
  /**
5535
- * The cheapest way from the point `a` to the point `b`. No entry when `a` walks straight to `b`, or
5536
- * when the map has no way. The legs of the routes other than `prefer` (an index of ROUTES) cost
5537
- * more, so bots that prefer different ones spread over the map.
5769
+ * The points a bot goes through from `a` to `b`, the last `b` or, when no way gets there, the
5770
+ * nearest point it can get to. The links of the routes other than `prefer` (an index of ROUTES)
5771
+ * cost more, so bots that prefer different ones spread over the map. Off the mesh, `b` alone.
5538
5772
  */
5539
5773
  var path = (nav, w, a, b, prefer = -1) => {
5540
- const { nodes, out, runUp } = nav;
5541
- if (!nodes.length || walkable(w, a, b)) return { edges: [] };
5542
- const n = nodes.length;
5543
- const cost = new Array(n).fill(Infinity);
5774
+ const [s, sp] = locate(nav, w, a);
5775
+ const [t, tp] = locate(nav, w, b);
5776
+ if (s < 0) return [{ to: b }];
5777
+ const n = nav.polys.length;
5778
+ const g = new Float64Array(n).fill(Infinity);
5779
+ const f = new Float64Array(n).fill(Infinity);
5544
5780
  const prev = new Array(n);
5545
- const back = new Array(n).fill(-1);
5546
- const done = new Array(n).fill(false);
5547
- for (let i = 0; i < n; i++) if (!runUp.has(i) && flat$2(a, nodes[i]) <= WALK && walkable(w, a, nodes[i])) cost[i] = flat$2(a, nodes[i]) / PACE;
5548
- if (!cost.some((c) => c < Infinity)) {
5549
- const first = close(w, nodes, a, (i) => !runUp.has(i), (d) => d, 1);
5550
- if (first >= 0) cost[first] = flat$2(a, nodes[first]) / PACE;
5551
- }
5552
- for (;;) {
5553
- let i = -1;
5554
- for (let k = 0; k < n; k++) if (!done[k] && cost[k] < Infinity && (i < 0 || cost[k] < cost[i])) i = k;
5555
- if (i < 0) break;
5556
- done[i] = true;
5557
- for (const e of out[i]) {
5558
- const c = cost[i] + e.cost * (e.route >= 0 && prefer >= 0 && e.route !== prefer ? OTHER : 1);
5559
- if (c < cost[e.to]) {
5560
- cost[e.to] = c;
5781
+ const back = new Int32Array(n).fill(-1);
5782
+ const at = new Float64Array(2 * n);
5783
+ const done = new Uint8Array(n);
5784
+ const h = (i) => flat$2(at[2 * i], at[2 * i + 1], b[0], b[2]) / PACE;
5785
+ g[s] = flat$2(a[0], a[2], sp[0], sp[2]) / PACE;
5786
+ [at[2 * s], at[2 * s + 1]] = [sp[0], sp[2]];
5787
+ f[s] = g[s] + h(s);
5788
+ const heap = [s];
5789
+ let close = s;
5790
+ while (heap.length) {
5791
+ const i = pop(heap, f);
5792
+ if (done[i]) continue;
5793
+ done[i] = 1;
5794
+ if (h(i) < h(close)) close = i;
5795
+ if (i === t) break;
5796
+ const [x, z] = [at[2 * i], at[2 * i + 1]];
5797
+ for (const e of nav.out[i]) {
5798
+ if (done[e.to]) continue;
5799
+ let c;
5800
+ let p;
5801
+ if (e.legs) {
5802
+ const [fx, , fz] = e.from;
5803
+ const other = e.route < 0 || prefer < 0 ? 1 : e.route === prefer ? 1 / OTHER : OTHER;
5804
+ c = flat$2(x, z, fx, fz) / PACE + e.cost * other * (1 + (e.fails ?? 0)) + (e.toll && other > 1 ? AREA : 0);
5805
+ p = [e.end[0], e.end[2]];
5806
+ } else {
5807
+ p = nearest(e.a, e.b, x, z);
5808
+ const r = nav.route[e.to];
5809
+ c = flat$2(x, z, p[0], p[1]) / PACE + (e.pass === PASS.HOP ? HOP_COST : e.pass ? DOWN : 0) + (r >= 0 && prefer >= 0 && r !== prefer && nav.route[i] !== r ? AREA : 0);
5810
+ }
5811
+ if (g[i] + c < g[e.to]) {
5812
+ g[e.to] = g[i] + c;
5561
5813
  prev[e.to] = e;
5562
5814
  back[e.to] = i;
5815
+ [at[2 * e.to], at[2 * e.to + 1]] = p;
5816
+ f[e.to] = g[e.to] + h(e.to);
5817
+ push(heap, f, e.to);
5563
5818
  }
5564
5819
  }
5565
5820
  }
5566
- let best = -1;
5567
- let total = Infinity;
5568
- for (let i = 0; i < n; i++) {
5569
- const c = cost[i] + flat$2(nodes[i], b) / PACE;
5570
- if (cost[i] < Infinity && c < total && flat$2(nodes[i], b) <= WALK && walkable(w, nodes[i], b)) [best, total] = [i, c];
5571
- }
5572
- if (best < 0) best = close(w, nodes, b, (i) => cost[i] < Infinity, (d, i) => cost[i] + d / PACE, -1);
5821
+ const goal = t >= 0 && done[t] ? t : close;
5822
+ const target = goal !== t ? onto(w, nav.polys[goal], b[0], b[2]) : flat$2(b[0], b[2], tp[0], tp[2]) < .5 ? b : tp;
5573
5823
  const edges = [];
5574
- let i = best;
5575
- for (; i >= 0 && prev[i]; i = back[i]) edges.unshift(prev[i]);
5576
- return i < 0 ? { edges: [] } : {
5577
- entry: nodes[i],
5578
- edges
5824
+ for (let i = goal; i !== s && prev[i]; i = back[i]) edges.unshift(prev[i]);
5825
+ const steps = [];
5826
+ let from = a;
5827
+ let polyAt = s;
5828
+ let ports = [];
5829
+ let heights = [];
5830
+ const walk = (to) => {
5831
+ const pts = funnel([from[0], from[2]], ports, [to[0], to[2]]);
5832
+ for (const [k, q] of pts.entries()) if (k < pts.length - 1) {
5833
+ const y = heights[ports.findIndex((pt) => pt[0] === q || pt[1] === q)] ?? to[1];
5834
+ steps.push({ to: [
5835
+ q[0],
5836
+ y,
5837
+ q[1]
5838
+ ] });
5839
+ }
5840
+ steps.push({ to });
5841
+ ports = [];
5842
+ heights = [];
5579
5843
  };
5844
+ for (const e of edges) {
5845
+ if (e.legs) {
5846
+ const [fx, , fz] = e.from;
5847
+ if (ports.length || !steps.at(-1)?.leg || flat$2(from[0], from[2], fx, fz) > 1) {
5848
+ const l = e.legs[0];
5849
+ if (l.k === "leap") {
5850
+ const d = flat$2(l.at[0], l.at[1], l.to[0], l.to[1]) || 1;
5851
+ const [rx, rz] = [fx - (l.to[0] - l.at[0]) / d * RUN_IN, fz - (l.to[1] - l.at[1]) / d * RUN_IN];
5852
+ let level = true;
5853
+ for (let u = 0; u <= 1 && level; u += .25) {
5854
+ const [ux, uz] = [rx + (fx - rx) * u, rz + (fz - rz) * u];
5855
+ const k = under(nav, w, ux, e.from[1], uz, 0);
5856
+ level = k >= 0 && Math.abs(heightAt(w, nav.polys[k], ux, uz) - e.from[1]) < .3;
5857
+ }
5858
+ if (level) {
5859
+ walk([
5860
+ rx,
5861
+ e.from[1],
5862
+ rz
5863
+ ]);
5864
+ from = [
5865
+ rx,
5866
+ e.from[1],
5867
+ rz
5868
+ ];
5869
+ }
5870
+ }
5871
+ walk(e.from);
5872
+ }
5873
+ for (const l of e.legs) steps.push({
5874
+ to: end(l),
5875
+ leg: l,
5876
+ edge: e
5877
+ });
5878
+ from = e.end;
5879
+ } else {
5880
+ const [p, q] = [nav.polys[polyAt].q, nav.polys[e.to].q];
5881
+ const [dx, dz] = [(q[0] + q[2] - p[0] - p[2]) / 2, (q[1] + q[3] - p[1] - p[3]) / 2];
5882
+ const [ax, az] = e.a;
5883
+ const [bx, bz] = e.b;
5884
+ const len = flat$2(ax, az, bx, bz);
5885
+ const k = Math.min(EDGE, len * .4) / (len || 1);
5886
+ const ea = [ax + (bx - ax) * k, az + (bz - az) * k];
5887
+ const eb = [bx - (bx - ax) * k, bz - (bz - az) * k];
5888
+ const right = dx * (eb[1] - ea[1]) - dz * (eb[0] - ea[0]) < 0;
5889
+ ports.push(right ? [ea, eb] : [eb, ea]);
5890
+ heights.push(heightAt(w, nav.polys[e.to], (ax + bx) / 2, (az + bz) / 2));
5891
+ }
5892
+ polyAt = e.to;
5893
+ }
5894
+ walk(target);
5895
+ return steps;
5580
5896
  };
5581
5897
  ARC_SPEED / 60;
5582
5898
  /** How far shot `n` of the laser rifle drifts off the look, yaw and pitch: a pattern within RIFLE_DRIFT, the same for the host and every client. */
@@ -7312,6 +7628,8 @@ var SORTIE = {
7312
7628
  EAST: 6,
7313
7629
  LAND: 10
7314
7630
  };
7631
+ /** Metres before a ship's centre a bot walks to, to board it. */
7632
+ var NOSE = 4;
7315
7633
  var flat$1 = (ax, az, bx, bz) => Math.sqrt((bx - ax) ** 2 + (bz - az) ** 2);
7316
7634
  var toward$1 = (x0, z0, x1, z1) => norm(Math.atan2(-(x1 - x0), -(z1 - z0)));
7317
7635
  var clamp = (v, a, b) => Math.min(b, Math.max(a, v));
@@ -7457,10 +7775,11 @@ var Sortie = class {
7457
7775
  yaw: toward$1(p.x, p.z, ship.x, ship.z),
7458
7776
  pitch: 0
7459
7777
  };
7778
+ const [fx, fz] = forward(ship.yaw);
7460
7779
  this.board = [
7461
- ship.x,
7780
+ ship.x + fx * NOSE,
7462
7781
  ship.y - SHIP.DROP,
7463
- ship.z
7782
+ ship.z + fz * NOSE
7464
7783
  ];
7465
7784
  }
7466
7785
  }
@@ -7607,13 +7926,13 @@ var Bot = class {
7607
7926
  id;
7608
7927
  /** The route it prefers, an index of nav.ts's ROUTES. */
7609
7928
  prefer;
7610
- nav;
7611
- way = { edges: [] };
7929
+ /** Its way: the points it goes through, walking or on a leg; the last is its goal or as near as it gets. */
7930
+ steps = [];
7612
7931
  /** The goal of the way, and the tick it was planned. */
7613
7932
  goal;
7614
7933
  planned = 0;
7615
- /** -1 walking to the way's entry, then the edge it is on; edges.length walking to the goal. */
7616
- leg = 0;
7934
+ /** The step it is on; steps.length once there. */
7935
+ step = 0;
7617
7936
  flight;
7618
7937
  /** The best distance to the point it walks to, and the tick it was last bettered. */
7619
7938
  best = Infinity;
@@ -7675,21 +7994,18 @@ var Bot = class {
7675
7994
  * goes to now, what it is doing on the way, the enemy it fights and the keys it last pressed.
7676
7995
  */
7677
7996
  view() {
7678
- const { entry, edges } = this.way;
7679
7997
  const r = (v) => [
7680
7998
  v[0],
7681
7999
  v[1],
7682
8000
  v[2]
7683
8001
  ].map((n) => Math.round(n * 10) / 10);
7684
- const path = [...entry ? [entry] : [], ...edges.map((e) => this.nav.nodes[e.to])];
7685
- if (this.goal) path.push(this.goal);
7686
- const e = edges[this.leg];
8002
+ const s = this.steps[this.step];
7687
8003
  return {
7688
8004
  id: this.id,
7689
8005
  why: this.why,
7690
- path: path.map(r),
7691
- next: this.leg < 0 ? 0 : this.leg + (entry ? 1 : 0),
7692
- doing: !this.goal ? "no way" : this.leg < 0 ? "to entry" : e ? e.leg?.k ?? "walk" : "to goal",
8006
+ path: this.steps.map((st) => r(st.to)),
8007
+ next: Math.max(0, Math.min(this.step, this.steps.length - 1)),
8008
+ doing: !this.goal ? "no way" : !s ? "there" : s.leg ? s.leg.k : this.step === this.steps.length - 1 ? "to goal" : "walk",
7693
8009
  foe: this.foe,
7694
8010
  keys: this.keys
7695
8011
  };
@@ -7730,7 +8046,7 @@ var Bot = class {
7730
8046
  yaw: p.yaw,
7731
8047
  pitch: 0
7732
8048
  };
7733
- if (p.ground && (!this.goal || flat(goal[0], goal[2], this.goal[0], this.goal[2]) > Math.max(DRIFT, SHARE * flat(p.x, p.z, goal[0], goal[2])) || !this.way.edges.length && t - this.planned > REPLAN)) this.plan(s.world, p, goal);
8049
+ if (p.ground && (!this.goal || flat(goal[0], goal[2], this.goal[0], this.goal[2]) > Math.max(DRIFT, SHARE * flat(p.x, p.z, goal[0], goal[2])) || !this.steps.some((st) => st.leg) && t - this.planned > REPLAN)) this.plan(s.world, p, goal);
7734
8050
  const move = this.pilot(p);
7735
8051
  const fight = this.fight(s, move.free);
7736
8052
  const reload = p.ammo > 0 && !p.mag && !p.reload && t & 1 ? RELOAD : 0;
@@ -7919,32 +8235,38 @@ var Bot = class {
7919
8235
  plan(w, p, goal) {
7920
8236
  this.goal = goal;
7921
8237
  this.planned = this.ticks;
7922
- this.nav = navOf(w);
7923
- this.way = path(this.nav, w, at(p), goal, this.prefer);
7924
- this.leg = this.way.entry ? -1 : 0;
8238
+ const prefer = this.why === "flag home" && !this.steer ? -1 : this.prefer;
8239
+ this.steps = path(navOf(w), w, at(p), goal, prefer);
8240
+ this.step = 0;
7925
8241
  this.flight = void 0;
7926
8242
  this.best = Infinity;
7927
8243
  this.better = this.ticks;
7928
8244
  }
7929
- /** The point it walks straight to now: the entry, a walk's end, or the goal past the last edge. */
7930
- target() {
7931
- const { edges, entry } = this.way;
7932
- if (this.leg < 0) return entry;
7933
- const e = edges[this.leg];
7934
- return e ? this.nav.nodes[e.to] : this.goal;
7935
- }
7936
8245
  /**
7937
8246
  * The keys and yaw of the move, whether the bot may look away from it to shoot, and whether the
7938
8247
  * yaw must be kept to the letter (a leg of a route, as the tests fly it).
7939
8248
  */
7940
8249
  pilot(p) {
7941
- const e = this.leg >= 0 ? this.way.edges[this.leg] : void 0;
7942
- if (e?.leg) return this.fly(p, e.leg);
7943
- const [x, , z] = this.target();
8250
+ const s = this.steps[this.step];
8251
+ if (s?.leg) return this.fly(p, s.leg);
8252
+ if (!s) return {
8253
+ keys: 0,
8254
+ yaw: this.aim,
8255
+ free: true,
8256
+ exact: false
8257
+ };
8258
+ const [x, y, z] = s.to;
7944
8259
  const d = flat(p.x, p.z, x, z);
8260
+ if (!p.ground) return {
8261
+ keys: this.alight(p, x, y, z),
8262
+ yaw: toward(p.x, p.z, x, z),
8263
+ free: false,
8264
+ exact: false
8265
+ };
8266
+ const last = this.step === this.steps.length - 1;
7945
8267
  const near = d < 2 && this.ticks - this.better > STUCK_JUMP;
7946
- if (d < (e || this.leg < 0 ? .5 : 1) || near && this.leg < this.way.edges.length) {
7947
- if (this.leg < this.way.edges.length) {
8268
+ if (d < (last ? 1 : .5) || near && !last) {
8269
+ if (!last) {
7948
8270
  this.next();
7949
8271
  return this.pilot(p);
7950
8272
  }
@@ -7986,7 +8308,7 @@ var Bot = class {
7986
8308
  };
7987
8309
  let keys = FORWARD | SPRINT;
7988
8310
  if (p.ground && hop && !(p.held & JUMP)) keys |= JUMP;
7989
- if (Math.abs(turn(this.look, yaw)) < .15 && !this.way.edges[this.leg + 1]?.leg) keys |= this.dash(w, p, yaw, d);
8311
+ if (Math.abs(turn(this.look, yaw)) < .15 && !this.steps[this.step + 1]?.leg) keys |= this.dash(w, p, yaw, d);
7990
8312
  return {
7991
8313
  keys,
7992
8314
  yaw,
@@ -8016,7 +8338,11 @@ var Bot = class {
8016
8338
  const [fx, fz] = forward(yaw);
8017
8339
  const hurts = SAFE * 400 / (2 * gravity(w));
8018
8340
  const far = Math.max(ahead, AHEAD + BRAKE * Math.sqrt(p.vx ** 2 + p.vz ** 2));
8019
- for (let t = .5; t <= far; t += .5) if (floorAt(w, p.x + fx * t, p.z + fz * t, p.y + HOP) < p.y - hurts) return false;
8341
+ for (let t = .5; t <= far; t += .5) {
8342
+ const [x, z] = [p.x + fx * t, p.z + fz * t];
8343
+ const y = p.y + HOP;
8344
+ if (Math.max(floorAt(w, x, z, y), floorAt(w, x - fz * .4, z + fx * .4, y), floorAt(w, x + fz * .4, z - fx * .4, y)) < p.y - hurts) return false;
8345
+ }
8020
8346
  const reach = Math.min(ahead, AHEAD);
8021
8347
  if (ray(w, [
8022
8348
  p.x,
@@ -8041,7 +8367,7 @@ var Bot = class {
8041
8367
  return "hop";
8042
8368
  }
8043
8369
  next() {
8044
- this.leg++;
8370
+ this.step++;
8045
8371
  this.flight = void 0;
8046
8372
  this.best = Infinity;
8047
8373
  this.better = this.ticks;
@@ -8076,7 +8402,7 @@ var Bot = class {
8076
8402
  if (leg.k === "go") {
8077
8403
  const run = go(leg.to[0], leg.to[1], leg.sprint ? .4 : .15, FORWARD | (leg.sprint ? SPRINT : 0));
8078
8404
  if (run) {
8079
- const next = this.way.edges[this.leg + 1]?.leg;
8405
+ const next = this.steps[this.step + 1]?.leg;
8080
8406
  const dash = leg.sprint && next?.k !== "leap" ? this.dash(this.world, p, run.yaw, flat(p.x, p.z, ...leg.to) - LEG_ROOM) : 0;
8081
8407
  return {
8082
8408
  ...run,
@@ -8127,19 +8453,13 @@ var Bot = class {
8127
8453
  else if (f.ran && f.ended < 0) f.ended = f.k;
8128
8454
  const n = leg.run ? f.ended < 0 ? -1 : f.k - f.ended : f.k;
8129
8455
  const extra = (n === leg.dash ? DASH : 0) | (n === leg.double ? JUMP : 0);
8130
- if (leg.land || this.steer) {
8131
- const [tx, tz] = leg.to;
8132
- const d = flat(p.x, p.z, tx, tz);
8133
- const v = (p.vx * (tx - p.x) + p.vz * (tz - p.z)) / (d || 1);
8134
- const g = gravity(this.world);
8135
- const t = Math.max((p.vy + Math.sqrt(Math.max(p.vy ** 2 + 2 * g * (p.y - leg.y), 0))) / g, .05);
8136
- return {
8137
- keys: (v * t < d - .3 ? FORWARD : v * t > d + .3 ? BACK : 0) | (leg.land ? 0 : extra),
8138
- yaw,
8139
- free: false,
8140
- exact: true
8141
- };
8142
- }
8456
+ const spent = n > Math.max(leg.dash ?? -1, leg.double ?? -1);
8457
+ if (leg.land || this.steer && spent) return {
8458
+ keys: this.alight(p, leg.to[0], leg.y, leg.to[1]) | (leg.land ? 0 : extra),
8459
+ yaw,
8460
+ free: false,
8461
+ exact: true
8462
+ };
8143
8463
  return {
8144
8464
  keys: keys | extra,
8145
8465
  yaw,
@@ -8147,14 +8467,27 @@ var Bot = class {
8147
8467
  exact: true
8148
8468
  };
8149
8469
  }
8470
+ /**
8471
+ * FORWARD or BACK in the air to come down on (x, y, z) facing it: will the flight carry it past
8472
+ * the point, or short of it, by the time it is down at its height? 0 when it will land there.
8473
+ */
8474
+ alight(p, x, y, z) {
8475
+ const d = flat(p.x, p.z, x, z);
8476
+ const v = (p.vx * (x - p.x) + p.vz * (z - p.z)) / (d || 1);
8477
+ const g = gravity(this.world);
8478
+ const t = Math.max((p.vy + Math.sqrt(Math.max(p.vy ** 2 + 2 * g * (p.y - y), 0))) / g, .05);
8479
+ return v * t < d - .3 ? FORWARD : v * t > d + .3 ? BACK : 0;
8480
+ }
8150
8481
  /** Whether the edge after this one is a jump that wants the run-up of this one. */
8151
8482
  leapNext() {
8152
- const l = this.way.edges[this.leg + 1]?.leg;
8483
+ const l = this.steps[this.step + 1]?.leg;
8153
8484
  return l?.k === "leap" && l.sprint;
8154
8485
  }
8155
8486
  /** A leg is over: on to the next on its roof, else a new way from where the bot came down. */
8156
8487
  landed(p, leg) {
8157
8488
  if (Math.abs(p.y - leg.y) > .3) {
8489
+ const e = this.steps[this.step]?.edge;
8490
+ if (e) e.fails = (e.fails ?? 0) + 1;
8158
8491
  this.goal = void 0;
8159
8492
  return {
8160
8493
  keys: 0,
@@ -8886,6 +9219,8 @@ var Room = class {
8886
9219
  mapName;
8887
9220
  /** The map the host picked for the next match, when it is another one. */
8888
9221
  next;
9222
+ /** The next map's world, built with the bots' mesh while the end screen runs rather than in the tick that starts the match. */
9223
+ ready;
8889
9224
  /** Joins so far: each player's `since`. */
8890
9225
  joins = 0;
8891
9226
  /** Ids of bots let go this tick, not given again before the next: the person who takes a bot's place would be drawn where it stood. */
@@ -8936,7 +9271,9 @@ var Room = class {
8936
9271
  if (this.next === void 0) return;
8937
9272
  this.mapName = this.next;
8938
9273
  this.next = void 0;
8939
- this.world = build$1(mapOf(this.mapName));
9274
+ const [map, world] = this.ready ?? [];
9275
+ this.ready = void 0;
9276
+ this.world = map === this.mapName && world ? world : build$1(mapOf(this.mapName));
8940
9277
  this.ctf = new Ctf(this.world, this.rules);
8941
9278
  this.gone = this.spots();
8942
9279
  this.fresh();
@@ -8947,6 +9284,14 @@ var Room = class {
8947
9284
  for (const p of this.players()) this.ctf.join(p.info.id, p.info.team, p.state);
8948
9285
  this.roster();
8949
9286
  }
9287
+ /** The next map's world and the bots' mesh of it, built ahead (Tranquility's mesh takes some 30 ms). */
9288
+ prepare() {
9289
+ if (this.next !== void 0) {
9290
+ const world = build$1(mapOf(this.next));
9291
+ if (this.rules.bots) navOf(world);
9292
+ this.ready = [this.next, world];
9293
+ }
9294
+ }
8950
9295
  /** Number of joined players, the bots left out: a room of bots alone is empty. */
8951
9296
  get size() {
8952
9297
  return this.humans().length;
@@ -9083,8 +9428,10 @@ var Room = class {
9083
9428
  team: p.info.team,
9084
9429
  state: p.state
9085
9430
  })));
9086
- if (turn === "end") this.end(players);
9087
- else if (turn === "start") {
9431
+ if (turn === "end") {
9432
+ this.end(players);
9433
+ this.prepare();
9434
+ } else if (turn === "start") {
9088
9435
  this.load();
9089
9436
  this.restart(players);
9090
9437
  }