@korial29/tiny-fps 0.136.0 → 0.138.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
@@ -464,7 +464,7 @@ var MODE = {
464
464
  * Which side of the player a wall or a ledge is on (PlayerState.wall). In the air it is the side
465
465
  * of the last wall-run or hang, which does not catch the player again until he lands.
466
466
  */
467
- var SIDE = {
467
+ var SIDE$1 = {
468
468
  NONE: 0,
469
469
  EAST: 1,
470
470
  WEST: 2,
@@ -579,12 +579,12 @@ var OFF = 1024;
579
579
  /** The key of the cell with integer coordinates (cx, cz). */
580
580
  var key = (cx, cz) => (cx + OFF) * (2 * OFF) + cz + OFF;
581
581
  /** Integer cell coordinate of a metre value, clamped to the keyed range. */
582
- var at$2 = (v, cell) => Math.min(Math.max(Math.floor(v / cell), -1024), 1023);
582
+ var at$3 = (v, cell) => Math.min(Math.max(Math.floor(v / cell), -1024), 1023);
583
583
  /** Builds the grid: each brush is listed in every cell its footprint covers. */
584
- var build = (def, cell = CELL) => {
584
+ var build$1 = (def, cell = CELL) => {
585
585
  const grid = /* @__PURE__ */ new Map();
586
586
  def.brushes.forEach(({ min, max }, i) => {
587
- for (let cx = at$2(min[0], cell); cx <= at$2(max[0], cell); cx++) for (let cz = at$2(min[2], cell); cz <= at$2(max[2], cell); cz++) {
587
+ 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++) {
588
588
  const k = key(cx, cz);
589
589
  const list = grid.get(k);
590
590
  if (list) list.push(i);
@@ -608,7 +608,7 @@ var build = (def, cell = CELL) => {
608
608
  */
609
609
  var near = (w, x, z, r) => {
610
610
  const out = [];
611
- for (let cx = at$2(x - r, w.cell); cx <= at$2(x + r, w.cell); cx++) for (let cz = at$2(z - r, w.cell); cz <= at$2(z + r, w.cell); cz++) for (const i of w.grid.get(key(cx, cz)) ?? []) if (!out.includes(i)) out.push(i);
611
+ 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);
612
612
  return out;
613
613
  };
614
614
  /**
@@ -643,8 +643,8 @@ var ray = (w, o, d, max, grow = 0) => {
643
643
  var faces = (w, o, d, max, grow) => {
644
644
  const { cell, def } = w;
645
645
  let best = max;
646
- let cx = at$2(o[0], cell);
647
- let cz = at$2(o[2], cell);
646
+ let cx = at$3(o[0], cell);
647
+ let cz = at$3(o[2], cell);
648
648
  const sx = Math.sign(d[0]);
649
649
  const sz = Math.sign(d[2]);
650
650
  const nx = sx ? ((cx + (sx > 0 ? 1 : 0)) * cell - o[0]) / d[0] : Infinity;
@@ -732,7 +732,7 @@ var STILL = {
732
732
  vz: 0,
733
733
  mode: MODE.GROUND,
734
734
  t: 0,
735
- wall: SIDE.NONE,
735
+ wall: SIDE$1.NONE,
736
736
  edge: 0,
737
737
  jumps: 1,
738
738
  dashes: 1,
@@ -1207,7 +1207,7 @@ var fly$1 = (p, w, h, g, snap, bodies) => {
1207
1207
  return -1;
1208
1208
  };
1209
1209
  /** A jump or a kick: the vertical speed, and the windows closed. */
1210
- var leap = (p, up) => {
1210
+ var leap$1 = (p, up) => {
1211
1211
  p.vy = up;
1212
1212
  p.coyote = 0;
1213
1213
  p.buffer = 0;
@@ -1227,7 +1227,7 @@ var hang = (p, w, c) => {
1227
1227
  go(MODE.AIR);
1228
1228
  p.vx = -nx * 4;
1229
1229
  p.vz = -nz * 4;
1230
- leap(p, 6);
1230
+ leap$1(p, 6);
1231
1231
  } else if (c.jump || c.fwd && p.t >= 6) enter(p, MODE.CLIMB);
1232
1232
  else if (p.t >= 30) {
1233
1233
  go(MODE.AIR);
@@ -1251,13 +1251,13 @@ var climb = (p, w) => {
1251
1251
  p.vz = nz * 3;
1252
1252
  p.vy = 0;
1253
1253
  p.edge = 0;
1254
- p.wall = SIDE.NONE;
1254
+ p.wall = SIDE$1.NONE;
1255
1255
  p.coyote = 6;
1256
1256
  p.ev |= EV.CLIMB;
1257
1257
  } else if (p.t >= 40) {
1258
1258
  enter(p, p.y >= p.edge ? MODE.GROUND : MODE.AIR);
1259
1259
  p.edge = 0;
1260
- p.wall = SIDE.NONE;
1260
+ p.wall = SIDE$1.NONE;
1261
1261
  }
1262
1262
  };
1263
1263
  /** Running along a wall: kick off it, or keep going, or end the run. */
@@ -1271,7 +1271,7 @@ var run = (p, w, c) => {
1271
1271
  const b = s > 0 ? 1 + 2 / s : 1;
1272
1272
  p.vx = tx * b - nx * WALL_KICK_SPEED;
1273
1273
  p.vz = tz * b - nz * WALL_KICK_SPEED;
1274
- leap(p, WALL_KICK_UP);
1274
+ leap$1(p, WALL_KICK_UP);
1275
1275
  p.jumps = 1;
1276
1276
  p.dashes = c.kit.dashes;
1277
1277
  p.ev |= EV.WALLRUN_END;
@@ -1324,7 +1324,7 @@ var grab = (p, l, dashes) => {
1324
1324
  enter(p, MODE.HANG);
1325
1325
  p.wall = l.side;
1326
1326
  p.edge = f32$2(l.top);
1327
- if (l.side <= SIDE.WEST) p.x = l.hang;
1327
+ if (l.side <= SIDE$1.WEST) p.x = l.hang;
1328
1328
  else p.z = l.hang;
1329
1329
  p.vx = p.vy = p.vz = 0;
1330
1330
  p.jumps = 1;
@@ -1367,7 +1367,7 @@ var free$1 = (p, w, c) => {
1367
1367
  p.fall = hit;
1368
1368
  p.jumps = 1;
1369
1369
  p.dashes = c.kit.dashes;
1370
- p.wall = SIDE.NONE;
1370
+ p.wall = SIDE$1.NONE;
1371
1371
  if (c.keys & KEY.CROUCH) {
1372
1372
  const slide = len$1(p.vx, p.vz) >= SLIDE_MIN_SPEED;
1373
1373
  enter(p, slide ? MODE.SLIDE : MODE.CROUCH);
@@ -1391,7 +1391,7 @@ var onGround = (p, w, c, burst) => {
1391
1391
  if (p.buffer > 0 && (p.mode === MODE.GROUND || canStand(p, w))) {
1392
1392
  p.ev |= p.mode === MODE.SLIDE ? EV.SLIDE_END : 0;
1393
1393
  enter(p, MODE.AIR);
1394
- leap(p, c.kit.jump);
1394
+ leap$1(p, c.kit.jump);
1395
1395
  return;
1396
1396
  }
1397
1397
  const speed = len$1(p.vx, p.vz);
@@ -1427,10 +1427,10 @@ var onGround = (p, w, c, burst) => {
1427
1427
  /** In the air: the extra jump, a jump just after an edge (coyote), and air control. */
1428
1428
  var air = (p, w, c, burst) => {
1429
1429
  if (p.buffer > 0) {
1430
- if (p.coyote > 0) leap(p, c.kit.jump);
1430
+ if (p.coyote > 0) leap$1(p, c.kit.jump);
1431
1431
  else if (p.jumps > 0 && !landingSoon(p, w)) {
1432
1432
  p.jumps--;
1433
- leap(p, c.kit.double);
1433
+ leap$1(p, c.kit.double);
1434
1434
  p.ev = p.ev & ~EV.JUMP | EV.DOUBLE;
1435
1435
  }
1436
1436
  }
@@ -1606,744 +1606,245 @@ var limbOf = (p, f) => {
1606
1606
  if (share < HIPS) return right ? LIMB.LEG_R : LIMB.LEG_L;
1607
1607
  return c === CUT.THRUST && Math.abs(s) <= MIDLINE ? LIMB.NONE : right ? LIMB.ARM_R : LIMB.ARM_L;
1608
1608
  };
1609
- // src/shared/ctf.ts
1610
- var home = () => ({
1611
- state: FLAG$1.HOME,
1612
- by: 0,
1613
- x: 0,
1614
- y: 0,
1615
- z: 0,
1616
- left: 0
1609
+ // src/shared/map.ts
1610
+ /** The bottom of every building: far below the kill floor, so nothing shows beneath a roof. */
1611
+ var BASE$1 = -30;
1612
+ /** A building: the footprint x0..x1 by z0..z1 from the street up to a flat roof at `top`, white concrete over a facade. */
1613
+ var roof$1 = (x0, z0, x1, z1, top, side = TEX.CONCRETE) => ({
1614
+ min: [
1615
+ x0,
1616
+ BASE$1,
1617
+ z0
1618
+ ],
1619
+ max: [
1620
+ x1,
1621
+ top,
1622
+ z1
1623
+ ],
1624
+ top: TEX.CONCRETE,
1625
+ side
1617
1626
  });
1618
- /** How far under a carrier a flag that he drops in the air is looked for a floor, metres. */
1619
- var FALL = 60;
1620
- var Ctf = class {
1621
- /** Captures per team, red then blue. */
1622
- score = [0, 0];
1623
- /** The match is over and the end screen shows. */
1624
- over = false;
1625
- /** The flag of each team, red then blue. */
1626
- flags = [home(), home()];
1627
- world;
1628
- rules;
1629
- mates = /* @__PURE__ */ new Map();
1630
- /** Ticks to the end of the match, or to the next one while it is over. */
1631
- clock;
1632
- /** Ticks before each dropped flag goes home. */
1633
- back = [0, 0];
1634
- /** Who may not take each flag, and for how many more ticks: the carrier that was made to drop it. */
1635
- lock = [{
1636
- id: -1,
1637
- left: 0
1638
- }, {
1639
- id: -1,
1640
- left: 0
1641
- }];
1642
- /** Ticks before a tackled flag can be sent home: it lies there, and the carrier's mates may take it. */
1643
- hold = [0, 0];
1644
- constructor(world, rules) {
1645
- this.world = world;
1646
- this.rules = rules;
1647
- this.clock = rules.timeLimit * 60;
1648
- }
1649
- /** A player joined, standing at `at`. */
1650
- join(id, team, at) {
1651
- this.mates.set(id, {
1652
- team,
1653
- caps: 0,
1654
- returns: 0,
1655
- ground: [
1656
- at.x,
1657
- at.y,
1658
- at.z
1659
- ]
1660
- });
1661
- }
1662
- /** A player left: a flag he carried is dropped where he last stood. */
1663
- leave(id) {
1664
- const k = this.carrying(id);
1665
- const m = this.mates.get(id);
1666
- if (k >= 0 && m) this.dropAt(k, m.ground);
1667
- this.mates.delete(id);
1668
- }
1669
- /** A player was put at `at` (a new match): his last ground is there. */
1670
- place(id, at) {
1671
- const m = this.mates.get(id);
1672
- if (m) m.ground = [
1673
- at.x,
1674
- at.y,
1675
- at.z
1676
- ];
1677
- }
1678
- /**
1679
- * The player's state after one move. Under the kill floor and put back at a spawn (EV.RESPAWN),
1680
- * a carrier drops the flag where he last stood; then a floor under him is his last ground.
1681
- */
1682
- moved(p) {
1683
- const m = this.mates.get(p.id);
1684
- if (!m) return;
1685
- const k = this.carrying(p.id);
1686
- if (p.ev & EV.RESPAWN && k >= 0) this.dropAt(k, m.ground);
1687
- if (p.ground) m.ground = [
1688
- p.x,
1689
- p.y,
1690
- p.z
1691
- ];
1692
- }
1693
- /**
1694
- * Makes the player drop the flag he carries (the tackle of step 7). It lies under him: where he
1695
- * stands, or on the first floor below him, or at his last ground when there is none (over the
1696
- * void). False when he carried nothing.
1697
- */
1698
- drop(p) {
1699
- const k = this.carrying(p.id);
1700
- const m = this.mates.get(p.id);
1701
- if (k < 0 || !m || this.over) return false;
1702
- let at = m.ground;
1703
- if (p.ground) at = [
1704
- p.x,
1705
- p.y,
1706
- p.z
1707
- ];
1708
- else {
1709
- const d = ray(this.world, [
1710
- p.x,
1711
- p.y + .05,
1712
- p.z
1713
- ], [
1714
- 0,
1715
- -1,
1716
- 0
1717
- ], FALL);
1718
- if (d < FALL) at = [
1719
- p.x,
1720
- p.y + .05 - d,
1721
- p.z
1722
- ];
1723
- }
1724
- this.dropAt(k, at);
1725
- this.lock[k] = {
1726
- id: p.id,
1727
- left: 120
1728
- };
1729
- this.hold[k] = 120;
1730
- return true;
1731
- }
1732
- /** The team whose flag the player carries, or -1. */
1733
- carrying(id) {
1734
- return this.flags.findIndex((f) => f.state === FLAG$1.CARRIED && f.by === id);
1735
- }
1736
- /** The winning team of a match that is over, or -1 for a draw. */
1737
- winner() {
1738
- const [r, b] = this.score;
1739
- return r > b ? 0 : b > r ? 1 : -1;
1740
- }
1741
- /** What every player has done this match. */
1742
- tally() {
1743
- return [...this.mates].map(([id, m]) => ({
1744
- id,
1745
- caps: m.caps,
1746
- returns: m.returns
1747
- }));
1748
- }
1749
- /** The room is empty: the next match starts from scratch. */
1750
- reset() {
1751
- this.over = false;
1752
- this.score = [0, 0];
1753
- this.flags = [home(), home()];
1754
- this.back = [0, 0];
1755
- this.lock.forEach((l) => l.left = 0);
1756
- this.hold = [0, 0];
1757
- this.clock = this.rules.timeLimit * 60;
1758
- for (const m of this.mates.values()) m.caps = m.returns = 0;
1759
- }
1760
- /** The part of a snapshot that is the match's. */
1761
- wire() {
1762
- return {
1763
- score: [...this.score],
1764
- clock: Math.ceil(this.clock / 60),
1765
- over: this.over,
1766
- flags: this.flags.map((f) => ({ ...f }))
1767
- };
1768
- }
1769
- /**
1770
- * One host tick over the players: the dropped flags run down, flags are taken, returned and
1771
- * captured, the clock runs. 'end' when the match has just ended, 'start' when the end screen is
1772
- * done and a new match begins (the room puts everyone back at a spawn).
1773
- */
1774
- tick(players) {
1775
- if (this.over) {
1776
- if (--this.clock <= 0) {
1777
- this.reset();
1778
- return "start";
1779
- }
1780
- return;
1781
- }
1782
- for (const k of [0, 1]) {
1783
- const f = this.flags[k];
1784
- this.lock[k].left--;
1785
- this.hold[k]--;
1786
- if (f.state === FLAG$1.DROPPED) {
1787
- f.left = Math.ceil(--this.back[k] / 60);
1788
- if (this.back[k] <= 0) this.flags[k] = home();
1789
- }
1790
- }
1791
- for (const k of [0, 1]) {
1792
- const f = this.flags[k];
1793
- if (f.state === FLAG$1.CARRIED) continue;
1794
- const at = f.state === FLAG$1.HOME ? this.world.def.teams[k].base : [
1795
- f.x,
1796
- f.y,
1797
- f.z
1798
- ];
1799
- const near = players.filter((q) => touches(q.state, at));
1800
- const mate = f.state === FLAG$1.DROPPED && this.hold[k] <= 0 ? near.find((q) => q.team === k) : void 0;
1801
- const foe = near.find((q) => q.team !== k && (q.id !== this.lock[k].id || this.lock[k].left <= 0));
1802
- if (mate) {
1803
- const m = this.mates.get(mate.id);
1804
- if (m) m.returns++;
1805
- this.flags[k] = home();
1806
- } else if (foe) this.flags[k] = {
1807
- ...home(),
1808
- state: FLAG$1.CARRIED,
1809
- by: foe.id
1810
- };
1811
- }
1812
- for (const p of players) {
1813
- const k = this.carrying(p.id);
1814
- if (k >= 0 && this.flags[p.team].state === FLAG$1.HOME && touches(p.state, this.world.def.teams[p.team].base)) {
1815
- this.score[p.team]++;
1816
- const m = this.mates.get(p.id);
1817
- if (m) m.caps++;
1818
- this.flags[k] = home();
1819
- }
1820
- }
1821
- if (this.score.some((s) => s >= this.rules.scoreLimit) || --this.clock <= 0) {
1822
- this.over = true;
1823
- this.clock = 600;
1824
- return "end";
1825
- }
1826
- }
1827
- dropAt(k, [x, y, z]) {
1828
- this.flags[k] = {
1829
- state: FLAG$1.DROPPED,
1830
- by: 0,
1831
- x,
1832
- y,
1833
- z,
1834
- left: 10
1835
- };
1836
- this.back[k] = 600;
1837
- }
1838
- };
1839
- /** Whether the player's body reaches the flag foot at `at`: close enough, and overlapping its height. */
1840
- var touches = (p, at) => Math.hypot(p.x - at[0], p.z - at[2]) < 1.5 && p.y < at[1] + 2.2 && p.y + 1.8 > at[1];
1841
- // src/shared/doors.ts
1842
- var DOOR = {
1843
- /**
1844
- * Metres from the doorway within which a player on foot opens it, and a driven rover. A dash
1845
- * from 7 m is there in 0.65 s (2.7 m of burst at 16 m/s, the rest at a sprint's 9), a rover at
1846
- * its 23.2 m/s from 14 m in 0.6 s: the door has been open 0.3 s and 0.25 s by then.
1847
- */
1848
- R: 7,
1849
- ROVER_R: 14,
1850
- /** Ticks it takes to open (0.35 s) and to shut (0.5 s). */
1851
- OPEN: 21,
1852
- SHUT: 30,
1853
- /** Ticks it stays open after the last one has left: a second. */
1854
- HOLD: 60
1855
- };
1856
- /** How far `p` is from the doorway on the floor plane, Infinity when its feet are not at its height. */
1857
- var off = ({ min, max }, [x, y, z]) => y < min[1] - 1 || y >= max[1] ? Infinity : Math.sqrt((x - Math.min(Math.max(x, min[0]), max[0])) ** 2 + (z - Math.min(Math.max(z, min[2]), max[2])) ** 2);
1627
+ /** Any box, corners (x0, y0, z0) and (x1, y1, z1). */
1628
+ var box$1 = ([x0, y0, z0], [x1, y1, z1], top, side = top, tint) => ({
1629
+ min: [
1630
+ x0,
1631
+ y0,
1632
+ z0
1633
+ ],
1634
+ max: [
1635
+ x1,
1636
+ y1,
1637
+ z1
1638
+ ],
1639
+ top,
1640
+ side,
1641
+ tint
1642
+ });
1643
+ /** Six steps of 0.4 m, 1 m deep and 2 m wide (x 12 to 14) from z down to z - 6, on a roof at y. */
1644
+ var stair = (z, y) => [
1645
+ 1,
1646
+ 2,
1647
+ 3,
1648
+ 4,
1649
+ 5,
1650
+ 6
1651
+ ].map((k) => box$1([
1652
+ 12,
1653
+ y,
1654
+ z - k
1655
+ ], [
1656
+ 14,
1657
+ y + .4 * k,
1658
+ z - k + 1
1659
+ ], TEX.CONCRETE));
1660
+ [
1661
+ roof$1(4, 57.7, 24, 76, 10),
1662
+ roof$1(4, 36, 24, 53.5, 10, TEX.GLASS),
1663
+ roof$1(4, 20, 24, 36, 12.4),
1664
+ roof$1(4, -5, 24, 7, 12.4, TEX.GLASS),
1665
+ roof$1(27, 20, 47, 50, 8),
1666
+ roof$1(27, 60, 47, 76, 8, TEX.BRICK),
1667
+ box$1([
1668
+ 9,
1669
+ 12.2,
1670
+ 39
1671
+ ], [
1672
+ 19,
1673
+ 12.6,
1674
+ 47
1675
+ ], TEX.STEEL),
1676
+ ...stair(53, 10),
1677
+ box$1([
1678
+ 5,
1679
+ 10,
1680
+ 42
1681
+ ], [
1682
+ 5.5,
1683
+ 14,
1684
+ 42.5
1685
+ ], TEX.STEEL),
1686
+ box$1([
1687
+ 5,
1688
+ 10,
1689
+ 50
1690
+ ], [
1691
+ 5.5,
1692
+ 14,
1693
+ 50.5
1694
+ ], TEX.STEEL),
1695
+ box$1([
1696
+ 8,
1697
+ 12.4,
1698
+ 24
1699
+ ], [
1700
+ 20,
1701
+ 12.85,
1702
+ 24.45
1703
+ ], TEX.STEEL),
1704
+ box$1([
1705
+ 36,
1706
+ 8,
1707
+ 22
1708
+ ], [
1709
+ 37,
1710
+ 14.5,
1711
+ 48
1712
+ ], TEX.PAINT, TEX.PAINT, [
1713
+ .15,
1714
+ .72,
1715
+ .62
1716
+ ]),
1717
+ box$1([
1718
+ 30,
1719
+ 8,
1720
+ 28
1721
+ ], [
1722
+ 34,
1723
+ 10,
1724
+ 32
1725
+ ], TEX.CONCRETE),
1726
+ box$1([
1727
+ 40,
1728
+ 8,
1729
+ 30
1730
+ ], [
1731
+ 44,
1732
+ 10.2,
1733
+ 34
1734
+ ], TEX.PAINT, TEX.PAINT, [
1735
+ 1,
1736
+ .3,
1737
+ .06
1738
+ ]),
1739
+ box$1([
1740
+ 28,
1741
+ 9.2,
1742
+ 44
1743
+ ], [
1744
+ 35,
1745
+ 12,
1746
+ 46
1747
+ ], TEX.STEEL, TEX.PAINT, [
1748
+ .2,
1749
+ .42,
1750
+ 1
1751
+ ]),
1752
+ box$1([
1753
+ 41.5,
1754
+ 7.6,
1755
+ 50
1756
+ ], [
1757
+ 42,
1758
+ 8,
1759
+ 60
1760
+ ], TEX.STEEL),
1761
+ box$1([
1762
+ 30,
1763
+ 8,
1764
+ 64
1765
+ ], [
1766
+ 34,
1767
+ 9.6,
1768
+ 68
1769
+ ], TEX.PAINT, TEX.PAINT, [
1770
+ .2,
1771
+ .8,
1772
+ .3
1773
+ ])
1774
+ ];
1775
+ /** The map is 240 m long: a point at z has its twin at ZED - z. */
1776
+ var ZED$1 = 240;
1777
+ /** Team colours as brush tints: the flip swaps one for the other, so a red accent has a blue twin. */
1778
+ var RED$1 = [
1779
+ 1,
1780
+ .22,
1781
+ .26
1782
+ ];
1783
+ var BLUE$1 = [
1784
+ .2,
1785
+ .46,
1786
+ 1
1787
+ ];
1788
+ /** The two team tints, red then blue. */
1789
+ var TEAM_TINT = [RED$1, BLUE$1];
1790
+ var ORANGE$1 = [
1791
+ 1,
1792
+ .42,
1793
+ .08
1794
+ ];
1795
+ var TEAL = [
1796
+ .12,
1797
+ .7,
1798
+ .62
1799
+ ];
1800
+ /** An accent: a slab of tinted paint, corners (x0, y0, z0) and (x1, y1, z1). */
1801
+ var pad = (x0, y0, z0, x1, y1, z1, tint) => box$1([
1802
+ x0,
1803
+ y0,
1804
+ z0
1805
+ ], [
1806
+ x1,
1807
+ y1,
1808
+ z1
1809
+ ], TEX.PAINT, TEX.PAINT, tint);
1858
1810
  /**
1859
- * One tick of the doors of `w`: each opens while one of `feet` (the players who are up) is within
1860
- * DOOR.R of it or one of `rovers` (the driven ones) within DOOR.ROVER_R, stays open DOOR.HOLD ticks
1861
- * after the last, then shuts.
1811
+ * A column of stairs: from `a` to `b` along `axis` (0 for x, 2 for z), across `w0` to `w1` on the
1812
+ * other one, rising from `y` to `top` in steps of at most 0.46 m, each step a solid from `low`.
1862
1813
  */
1863
- var swing = (w, feet, rovers = []) => w.doors?.forEach((s, i) => {
1864
- const d = w.def.doors[i];
1865
- const near = feet.some((p) => off(d, p) < DOOR.R) || rovers.some((p) => off(d, p) < DOOR.ROVER_R);
1866
- const all = DOOR.OPEN * DOOR.SHUT;
1867
- const at = Math.round(s.open * all) + (near || s.wait ? DOOR.SHUT : -DOOR.OPEN);
1868
- s.open = Math.min(all, Math.max(0, at)) / all;
1869
- s.wait = near ? DOOR.HOLD : Math.max(0, s.wait - 1);
1870
- });
1871
- /** Every door shut: a new match. */
1872
- var shut = (w) => w.doors?.forEach((s) => {
1873
- s.open = s.wait = 0;
1874
- });
1875
- // src/shared/gun.ts
1876
- /** Whether the feet of `p` are within `r` of the point `at` on the floor plane and within PICK_H of its height. */
1877
- var within = (p, at, r) => {
1878
- const [dx, dz] = [p.x - at[0], p.z - at[2]];
1879
- return dx * dx + dz * dz < r * r && Math.abs(p.y - at[1]) < 1;
1814
+ var stairs$1 = (axis, a, b, w0, w1, y, top, low = BASE$1) => {
1815
+ const n = Math.ceil((top - y) / .46);
1816
+ return Array.from({ length: n }, (_, i) => {
1817
+ const [s0, s1] = [a + (b - a) * i / n, a + (b - a) * (i + 1) / n].sort((p, q) => p - q);
1818
+ const up = y + (top - y) * (i + 1) / n;
1819
+ return axis === 0 ? box$1([
1820
+ s0,
1821
+ low,
1822
+ w0
1823
+ ], [
1824
+ s1,
1825
+ up,
1826
+ w1
1827
+ ], TEX.CONCRETE) : box$1([
1828
+ w0,
1829
+ low,
1830
+ s0
1831
+ ], [
1832
+ w1,
1833
+ up,
1834
+ s1
1835
+ ], TEX.CONCRETE);
1836
+ });
1880
1837
  };
1881
1838
  /**
1882
- * The start of a cut that moves the body, from a floor only: the lunge throws him along the look at
1883
- * LUNGE_SPEED for the burst of a dash, and spends the dash; the leap jumps him LEAP_SPEED up.
1839
+ * A ledge ladder: one platform 4 m wide and `d` deep per top in `tops`, the first at (x, z), each
1840
+ * next one (dx, dz) further, over the roof at `low`. The hands catch the face of each from the one before.
1884
1841
  */
1885
- var launch$1 = (p) => {
1886
- if (p.mode !== MODE.GROUND) return;
1887
- if (p.cut === CUT.LUNGE) {
1888
- const [fx, fz] = forward(p.yaw);
1889
- p.vx = fx * 13;
1890
- p.vz = fz * 13;
1891
- p.dash = 60;
1892
- p.ev |= EV.DASH;
1893
- } else if (p.cut === CUT.LEAP) {
1894
- p.vy = LEAP_SPEED;
1895
- p.ev |= EV.JUMP;
1896
- }
1897
- };
1898
- /** What a step struck, for the host to resolve: nothing, a shot (a plasma ball), the katana's cut, a rail gun's beam, a laser rifle's shot, or a grenade from its launcher. */
1899
- var STRIKE = {
1900
- NONE: 0,
1901
- SHOT: 1,
1902
- CUT: 2,
1903
- RAIL: 3,
1904
- LASER: 4,
1905
- NADE: 5
1906
- };
1907
- /**
1908
- * One input: the move, then the weapons. Returns what struck on this step (STRIKE), for the host to
1909
- * resolve it: a shot, or a cut, which is not a shot.
1910
- * - Down: the keys are dropped, and when `down` runs out the player is back at a spawn.
1911
- * - The team's rack fills the gun when the player steps into its circle (`rack` tells he is in it),
1912
- * and again each time he comes back; staying gives nothing. The katana rack gives the katana,
1913
- * once and for good: it stays until he goes down.
1914
- * - The rail rack fills the rail gun with RAIL_MAX ticks of lightning on arrival, as the gun's does.
1915
- * - In hand is the weapon he wants (KEY.BLADE the katana, KEY.RAIL the rail gun, neither the gun)
1916
- * when he has it, else the first he has of the gun, the katana and the rail gun; the katana
1917
- * stays in hand for the length of a swing. `wield` is the katana in hand, `railed` the rail gun.
1918
- * - The gun fires from its battery (`mag`), the rail gun from its capsule (`cap`). An empty one, or
1919
- * KEY.RELOAD with room in it, swaps it for a full one from what he carries: `reload` ticks
1920
- * without firing, then it holds the kit's `mag` (`cap`, `clip`) or what is left. A switch of weapon drops it.
1921
- * The racks fill both.
1922
- * - The rail gun throws its bolt on every step FIRE is held, spending a tick of it (`zapping`),
1923
- * unless it is `hot`: its `heat` rises while it fires and falls when it does not (HEAT_MAX).
1924
- * - The laser rifle (KEY.RIFLE, `rifled`), filled at its rack on arrival, fires a round from its
1925
- * cell (`clip`) each RIFLE_COOL ticks while FIRE is held (STRIKE.LASER). Its rack loads NADE_MAX
1926
- * grenades too: SPECIAL (G) launches one (STRIKE.NADE) when `lob` is 0, even during
1927
- * a swap of the cell, then `lob` runs NADE_COOL ticks and the rifle holds its fire NADE_HOLD.
1928
- * - The trigger: `cool` and `swing` run down, and at 0 a held FIRE charges the gun, with ammo, and
1929
- * letting it go fires a ball as strong as the charge (powerOf()), spending as many shots; or it
1930
- * starts the katana's swing (`cut` from the keys), unless the hands are busy (a hang, a climb).
1931
- * The katana in hand, busy hands or no shot left drop the charge.
1932
- * With SPECIAL (a double click) the swing is the cut's special; its press within SPECIAL_LATE
1933
- * ticks of a cut's start turns that cut into it. The cut strikes `CUTS[cut].strike` ticks into
1934
- * its swing. The look is the input's, so both go where the player sees.
1935
- * `armed` is false while the match is over: no weapon, no rack. `bodies` are move()'s.
1936
- */
1937
- var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
1938
- const down = p.down > 0;
1939
- const locked = !down && (p.lock ?? 0) > 0;
1940
- move(p, down || locked ? {
1941
- ...i,
1942
- keys: 0
1943
- } : i, w, team, bodies, kit);
1944
- p.heat = Math.max(0, (p.heat ?? 0) - (p.zapping ? 0 : p.hot ? 1 : 2));
1945
- p.hot = !!p.hot && p.heat > 0;
1946
- p.zapping = false;
1947
- p.zap = !!p.stun && !!p.zap;
1948
- if (down) {
1949
- if (p.down > 0 && !--p.down) respawn(p, w, team);
1950
- return STRIKE.NONE;
1951
- }
1952
- if (locked) return duel(p, i);
1953
- const { rack, blade, rail, rifle } = w.def.teams[team];
1954
- const inside = !!rack && within(p, rack, 1.2);
1955
- if (armed && inside && !p.rack) [p.ammo, p.mag] = [kit.ammo, kit.mag];
1956
- p.rack = inside;
1957
- p.blade = !!p.blade || armed && !!blade && within(p, blade, 1.2);
1958
- const inRail = !!rail && within(p, rail, 1.2);
1959
- if (armed && inRail && !p.inRail) [p.rail, p.cap] = [kit.rail, kit.cap];
1960
- p.inRail = inRail;
1961
- const inRifle = !!rifle && within(p, rifle, 1.2);
1962
- if (armed && inRifle && !p.inRifle) [p.rifle, p.clip, p.nades] = [
1963
- kit.rifle,
1964
- kit.clip,
1965
- 3
1966
- ];
1967
- p.inRifle = inRifle;
1968
- p.ammo = Math.min(p.ammo, kit.ammo);
1969
- p.rail = p.rail === void 0 ? p.rail : Math.min(p.rail, kit.rail);
1970
- p.rifle = p.rifle === void 0 ? p.rifle : Math.min(p.rifle, kit.rifle);
1971
- [p.mag, p.cap, p.clip] = [
1972
- Math.min(p.mag ?? 0, kit.mag),
1973
- Math.min(p.cap ?? 0, kit.cap),
1974
- Math.min(p.clip ?? 0, kit.clip)
1975
- ];
1976
- p.cool = Math.max(0, p.cool - 1);
1977
- p.lob = Math.max(0, (p.lob ?? 0) - 1);
1978
- const busy = p.mode === MODE.HANG || p.mode === MODE.CLIMB;
1979
- const { ticks, hold } = CUTS[p.cut ?? 0];
1980
- const top = !!p.swing && !p.heavy && ticks - (p.swing ?? 0) === hold;
1981
- if (top && p.wield && armed && !busy && i.keys & KEY.FIRE) p.charge = Math.min((p.charge ?? 0) + 1, HEAVY_MAX);
1982
- else if (top && armed && !busy && (p.charge ?? 0) >= HEAVY_TAP) {
1983
- [p.heavy, p.charge] = [true, 0];
1984
- p.swing = swingOf(p).ticks;
1985
- } else {
1986
- p.charge = top ? 0 : p.charge;
1987
- const s = p.swing ?? 0;
1988
- const c = swingOf(p);
1989
- const stop = (v) => v == s - 1 && (v == c.ticks - c.strike || v == PUNCH.ticks - PUNCH.strike || !p.heavy && v == ticks - hold);
1990
- p.swing = Math.max(0, kit.haste > 1 && stop(s - 1) ? s - 1 : s - kit.haste);
1991
- p.heavy = !!p.swing && !!p.heavy;
1992
- }
1993
- p.mag = Math.min(p.mag ?? 0, Math.max(p.ammo, 0));
1994
- const has = [
1995
- p.ammo >= 0,
1996
- !!p.blade,
1997
- (p.rail ?? -1) >= 0,
1998
- (p.rifle ?? -1) >= 0
1999
- ];
2000
- const want = i.keys & KEY.BLADE ? 1 : i.keys & KEY.RAIL ? 2 : i.keys & KEY.RIFLE ? 3 : 0;
2001
- const hand = p.swing && p.blade ? 1 : has[want] ? want : has.indexOf(true);
2002
- if (hand != (p.rifled ? 3 : p.railed ? 2 : +!!p.wield)) p.reload = 0;
2003
- [p.wield, p.railed, p.rifled] = [
2004
- hand == 1,
2005
- hand == 2,
2006
- hand == 3
2007
- ];
2008
- if (p.swing && hand >= 0 && !p.blade) p.swing = 0;
2009
- if (!armed) {
2010
- [p.charge, p.reload] = [0, 0];
2011
- return STRIKE.NONE;
2012
- }
2013
- const [key, size, carried, ticks2] = hand == 3 ? [
2014
- "clip",
2015
- kit.clip,
2016
- p.rifle,
2017
- 96
2018
- ] : hand == 2 ? [
2019
- "cap",
2020
- kit.cap,
2021
- p.rail,
2022
- 90
2023
- ] : [
2024
- "mag",
2025
- kit.mag,
2026
- p.ammo,
2027
- 78
2028
- ];
2029
- const [load, full] = [p[key] ?? 0, Math.min(size, carried)];
2030
- if (p.reload) {
2031
- if (!--p.reload) p[key] = full;
2032
- } else if (hand != 1 && carried >= 0 && !busy && load < full && (!load || i.keys & KEY.RELOAD)) [p.reload, p.charge] = [ticks2, 0];
2033
- const bare = hand < 0;
2034
- const c = bare ? PUNCH : swingOf(p);
2035
- if (p.swing && c.ticks - p.swing === c.strike) return STRIKE.CUT;
2036
- if (p.wield && !top || p.railed || p.rifled || busy || p.reload || !p.wield && !p.mag) p.charge = 0;
2037
- if (p.rifled && i.keys & KEY.SPECIAL && !busy && p.nades && !p.lob) {
2038
- p.nades--;
2039
- [p.lob, p.cool] = [60, 7];
2040
- p.shots = p.shots + 1 & 255;
2041
- return STRIKE.NADE;
2042
- }
2043
- if (i.keys & KEY.FIRE && !busy) {
2044
- const late = CUTS[p.cut ?? 0].ticks - (p.swing ?? 0);
2045
- const special = !!(i.keys & KEY.SPECIAL) && (!p.swing || !p.heavy && (p.cut ?? 0) < 4 && late <= 18);
2046
- if (bare) {
2047
- if (!p.swing) [p.cut, p.heavy, p.swing] = [
2048
- 0,
2049
- false,
2050
- PUNCH.ticks
2051
- ];
2052
- } else if (p.wield && (!p.swing || special)) {
2053
- p.cut = cutOf(i.keys) + (special ? 4 : 0);
2054
- [p.swing, p.charge] = [CUTS[p.cut].ticks, 0];
2055
- launch$1(p);
2056
- } else if (p.rifled) {
2057
- if (!p.cool && p.clip && !p.reload) {
2058
- p.rifle--;
2059
- p.clip--;
2060
- p.cool = kit.rifleCool;
2061
- p.shots = p.shots + 1 & 255;
2062
- return STRIKE.LASER;
2063
- }
2064
- } else if (p.railed) {
2065
- if (p.cap && !p.reload && !p.hot) {
2066
- p.heat = (p.heat ?? 0) + 1;
2067
- p.hot = p.heat >= 120;
2068
- if (!p.cool) {
2069
- p.rail--;
2070
- p.cap--;
2071
- p.cool = 2;
2072
- }
2073
- p.zapping = true;
2074
- return STRIKE.RAIL;
2075
- }
2076
- } else if (!p.wield && !p.cool && p.mag && !p.reload) p.charge = Math.min((p.charge ?? 0) + 1, 60);
2077
- } else if (p.charge) {
2078
- p.power = Math.min(powerOf(p.charge), p.mag);
2079
- p.charge = 0;
2080
- p.ammo -= p.power;
2081
- p.mag = p.mag - p.power;
2082
- p.shots = p.shots + 1 & 255;
2083
- p.cool = kit.cool;
2084
- return STRIKE.SHOT;
2085
- }
2086
- return STRIKE.NONE;
2087
- };
2088
- /**
2089
- * A step in a saber lock: the blade stays in hand and no cut starts. Each FIRE press (FIRE held
2090
- * now, not at the last step) pushes; a side or back key held counts `away`, up to LOCK_BREAK. The
2091
- * lock runs down to 1, where it waits for the host, who parts the two (room.ts).
2092
- */
2093
- var duel = (p, i) => {
2094
- const fire = !!(i.keys & KEY.FIRE);
2095
- p.pushes = (p.pushes ?? 0) + +(fire && !p.pressed) & 255;
2096
- p.pressed = fire;
2097
- p.away = i.keys & (KEY.LEFT | KEY.RIGHT | KEY.BACK) ? Math.min((p.away ?? 0) + 1, 24) : 0;
2098
- p.lock = Math.max(1, p.lock - 1);
2099
- [p.wield, p.swing, p.charge] = [
2100
- true,
2101
- 0,
2102
- 0
2103
- ];
2104
- return STRIKE.NONE;
2105
- };
2106
- /** The strength a charge of `ticks` gives, 1 to CHARGE_MAX: 1 under CHARGE_TAP, CHARGE_MAX at CHARGE_TICKS. */
2107
- var powerOf = (ticks) => ticks < 10 ? 1 : 1 + Math.floor(4 * (ticks - 10) / 50);
2108
- // src/shared/map.ts
2109
- /** The bottom of every building: far below the kill floor, so nothing shows beneath a roof. */
2110
- var BASE$1 = -30;
2111
- /** A building: the footprint x0..x1 by z0..z1 from the street up to a flat roof at `top`, white concrete over a facade. */
2112
- var roof$1 = (x0, z0, x1, z1, top, side = TEX.CONCRETE) => ({
2113
- min: [
2114
- x0,
2115
- BASE$1,
2116
- z0
2117
- ],
2118
- max: [
2119
- x1,
2120
- top,
2121
- z1
2122
- ],
2123
- top: TEX.CONCRETE,
2124
- side
2125
- });
2126
- /** Any box, corners (x0, y0, z0) and (x1, y1, z1). */
2127
- var box$1 = ([x0, y0, z0], [x1, y1, z1], top, side = top, tint) => ({
2128
- min: [
2129
- x0,
2130
- y0,
2131
- z0
2132
- ],
2133
- max: [
2134
- x1,
2135
- y1,
2136
- z1
2137
- ],
2138
- top,
2139
- side,
2140
- tint
2141
- });
2142
- /** Six steps of 0.4 m, 1 m deep and 2 m wide (x 12 to 14) from z down to z - 6, on a roof at y. */
2143
- var stair = (z, y) => [
2144
- 1,
2145
- 2,
2146
- 3,
2147
- 4,
2148
- 5,
2149
- 6
2150
- ].map((k) => box$1([
2151
- 12,
2152
- y,
2153
- z - k
2154
- ], [
2155
- 14,
2156
- y + .4 * k,
2157
- z - k + 1
2158
- ], TEX.CONCRETE));
2159
- [
2160
- roof$1(4, 57.7, 24, 76, 10),
2161
- roof$1(4, 36, 24, 53.5, 10, TEX.GLASS),
2162
- roof$1(4, 20, 24, 36, 12.4),
2163
- roof$1(4, -5, 24, 7, 12.4, TEX.GLASS),
2164
- roof$1(27, 20, 47, 50, 8),
2165
- roof$1(27, 60, 47, 76, 8, TEX.BRICK),
2166
- box$1([
2167
- 9,
2168
- 12.2,
2169
- 39
2170
- ], [
2171
- 19,
2172
- 12.6,
2173
- 47
2174
- ], TEX.STEEL),
2175
- ...stair(53, 10),
2176
- box$1([
2177
- 5,
2178
- 10,
2179
- 42
2180
- ], [
2181
- 5.5,
2182
- 14,
2183
- 42.5
2184
- ], TEX.STEEL),
2185
- box$1([
2186
- 5,
2187
- 10,
2188
- 50
2189
- ], [
2190
- 5.5,
2191
- 14,
2192
- 50.5
2193
- ], TEX.STEEL),
2194
- box$1([
2195
- 8,
2196
- 12.4,
2197
- 24
2198
- ], [
2199
- 20,
2200
- 12.85,
2201
- 24.45
2202
- ], TEX.STEEL),
2203
- box$1([
2204
- 36,
2205
- 8,
2206
- 22
2207
- ], [
2208
- 37,
2209
- 14.5,
2210
- 48
2211
- ], TEX.PAINT, TEX.PAINT, [
2212
- .15,
2213
- .72,
2214
- .62
2215
- ]),
2216
- box$1([
2217
- 30,
2218
- 8,
2219
- 28
2220
- ], [
2221
- 34,
2222
- 10,
2223
- 32
2224
- ], TEX.CONCRETE),
2225
- box$1([
2226
- 40,
2227
- 8,
2228
- 30
2229
- ], [
2230
- 44,
2231
- 10.2,
2232
- 34
2233
- ], TEX.PAINT, TEX.PAINT, [
2234
- 1,
2235
- .3,
2236
- .06
2237
- ]),
2238
- box$1([
2239
- 28,
2240
- 9.2,
2241
- 44
2242
- ], [
2243
- 35,
2244
- 12,
2245
- 46
2246
- ], TEX.STEEL, TEX.PAINT, [
2247
- .2,
2248
- .42,
2249
- 1
2250
- ]),
2251
- box$1([
2252
- 41.5,
2253
- 7.6,
2254
- 50
2255
- ], [
2256
- 42,
2257
- 8,
2258
- 60
2259
- ], TEX.STEEL),
2260
- box$1([
2261
- 30,
2262
- 8,
2263
- 64
2264
- ], [
2265
- 34,
2266
- 9.6,
2267
- 68
2268
- ], TEX.PAINT, TEX.PAINT, [
2269
- .2,
2270
- .8,
2271
- .3
2272
- ])
2273
- ];
2274
- /** The map is 240 m long: a point at z has its twin at ZED - z. */
2275
- var ZED$1 = 240;
2276
- /** Team colours as brush tints: the flip swaps one for the other, so a red accent has a blue twin. */
2277
- var RED$1 = [
2278
- 1,
2279
- .22,
2280
- .26
2281
- ];
2282
- var BLUE$1 = [
2283
- .2,
2284
- .46,
2285
- 1
2286
- ];
2287
- /** The two team tints, red then blue. */
2288
- var TEAM_TINT = [RED$1, BLUE$1];
2289
- var ORANGE$1 = [
2290
- 1,
2291
- .42,
2292
- .08
2293
- ];
2294
- var TEAL = [
2295
- .12,
2296
- .7,
2297
- .62
2298
- ];
2299
- /** An accent: a slab of tinted paint, corners (x0, y0, z0) and (x1, y1, z1). */
2300
- var pad = (x0, y0, z0, x1, y1, z1, tint) => box$1([
2301
- x0,
2302
- y0,
2303
- z0
2304
- ], [
2305
- x1,
2306
- y1,
2307
- z1
2308
- ], TEX.PAINT, TEX.PAINT, tint);
2309
- /**
2310
- * A column of stairs: from `a` to `b` along `axis` (0 for x, 2 for z), across `w0` to `w1` on the
2311
- * other one, rising from `y` to `top` in steps of at most 0.46 m, each step a solid from `low`.
2312
- */
2313
- var stairs$1 = (axis, a, b, w0, w1, y, top, low = BASE$1) => {
2314
- const n = Math.ceil((top - y) / .46);
2315
- return Array.from({ length: n }, (_, i) => {
2316
- const [s0, s1] = [a + (b - a) * i / n, a + (b - a) * (i + 1) / n].sort((p, q) => p - q);
2317
- const up = y + (top - y) * (i + 1) / n;
2318
- return axis === 0 ? box$1([
2319
- s0,
2320
- low,
2321
- w0
2322
- ], [
2323
- s1,
2324
- up,
2325
- w1
2326
- ], TEX.CONCRETE) : box$1([
2327
- w0,
2328
- low,
2329
- s0
2330
- ], [
2331
- w1,
2332
- up,
2333
- s1
2334
- ], TEX.CONCRETE);
2335
- });
2336
- };
2337
- /**
2338
- * A ledge ladder: one platform 4 m wide and `d` deep per top in `tops`, the first at (x, z), each
2339
- * next one (dx, dz) further, over the roof at `low`. The hands catch the face of each from the one before.
2340
- */
2341
- var ladder = (x, z, dx, dz, d, low, tops) => tops.map((top, k) => box$1([
2342
- x + k * dx,
2343
- low,
2344
- z + k * dz
2345
- ], [
2346
- x + k * dx + 4,
1842
+ var ladder = (x, z, dx, dz, d, low, tops) => tops.map((top, k) => box$1([
1843
+ x + k * dx,
1844
+ low,
1845
+ z + k * dz
1846
+ ], [
1847
+ x + k * dx + 4,
2347
1848
  top,
2348
1849
  z + k * dz + d
2349
1850
  ], TEX.STEEL, TEX.CONCRETE));
@@ -2804,7 +2305,7 @@ var centre$1 = [
2804
2305
  ], TEX.STEEL)
2805
2306
  ];
2806
2307
  /** The twin of a brush across the centre line. */
2807
- var flip$1 = (b) => ({
2308
+ var flip$2 = (b) => ({
2808
2309
  ...b,
2809
2310
  min: [
2810
2311
  b.min[0],
@@ -2953,7 +2454,7 @@ var HIGHLINE = {
2953
2454
  lore: "The towers of an old business district, closed for years, far above streets that still have traffic. Two crews of runners have taken the roofs. Three routes cross between them, and a fall takes you back to your tower.",
2954
2455
  brushes: [
2955
2456
  ...half$1,
2956
- ...half$1.map(flip$1),
2457
+ ...half$1.map(flip$2),
2957
2458
  ...centre$1
2958
2459
  ],
2959
2460
  teams: [{
@@ -3484,7 +2985,7 @@ var BASE = [
3484
2985
  var [RED, BLUE] = TEAM_TINT;
3485
2986
  var { STONE, CONCRETE, METAL, STEEL, PAINT } = TEX;
3486
2987
  /** The twin of a box across the centre line. */
3487
- var mirror = ({ min, max }) => bx(min[0], min[1], 280 - max[2], max[0], max[1], 280 - min[2]);
2988
+ var mirror$1 = ({ min, max }) => bx(min[0], min[1], 280 - max[2], max[0], max[1], 280 - min[2]);
3488
2989
  /** The domes' centres, the landing pads (x, z, radius), the modules, the tubes and the masts (centres), red's then blue's: what the scenery draws on. */
3489
2990
  var PAD$1 = [
3490
2991
  40,
@@ -3880,888 +3381,2382 @@ var SITES = [
3880
3381
  const [x, z0] = b < 2 ? [(b ? 151 : 0) + h(2) * 9, 150 + h(3) * 122] : [5 + h(2) * 150, 273 + h(3) * 7];
3881
3382
  return [
3882
3383
  x,
3883
- z0 + (b === 0 && Math.abs(z0 - 174) < 8 ? 16 : 0),
3884
- .6 + 2.4 * h(4) * h(4)
3885
- ];
3886
- }),
3887
- ...FIELD
3888
- ];
3889
- /** What the craters dig and raise at (x, z from the centre line), and how far in a pit's crater it is (1 on its terrace, 0 well clear): the hills fade out there. */
3890
- var bowls = (x, z) => {
3891
- let [h, m] = [0, 0];
3892
- for (const [cx, cz, r, k = .17, flat = 0] of BOWLS) {
3893
- const d = far(x - cx, z - cz);
3894
- const [ux, uz] = d ? [(x - cx) / d, (z - cz) / d] : [1, 0];
3895
- const q = d / r * (.9 + .2 * noise(2.5 * ux + .37 * cx, 2.5 * uz + .21 * cz, 9));
3896
- const rim = .03 + .045 * noise(4 * ux - .1 * cz, 4 * uz + .1 * cx, 10);
3897
- const s = 1 - c1((q - 1 - 4 / r) / .6);
3898
- const wall = flat ? (k + rim) * c1((q - flat) / (1 - flat)) - k : (k + rim) * q * q - k;
3899
- h += r * (q < 1 ? wall : rim * s * s);
3900
- m = Math.max(m, flat ? c1((1.6 - q) / (1.5 - flat)) : 0);
3384
+ z0 + (b === 0 && Math.abs(z0 - 174) < 8 ? 16 : 0),
3385
+ .6 + 2.4 * h(4) * h(4)
3386
+ ];
3387
+ }),
3388
+ ...FIELD
3389
+ ];
3390
+ /** What the craters dig and raise at (x, z from the centre line), and how far in a pit's crater it is (1 on its terrace, 0 well clear): the hills fade out there. */
3391
+ var bowls = (x, z) => {
3392
+ let [h, m] = [0, 0];
3393
+ for (const [cx, cz, r, k = .17, flat = 0] of BOWLS) {
3394
+ const d = far(x - cx, z - cz);
3395
+ const [ux, uz] = d ? [(x - cx) / d, (z - cz) / d] : [1, 0];
3396
+ const q = d / r * (.9 + .2 * noise(2.5 * ux + .37 * cx, 2.5 * uz + .21 * cz, 9));
3397
+ const rim = .03 + .045 * noise(4 * ux - .1 * cz, 4 * uz + .1 * cx, 10);
3398
+ const s = 1 - c1((q - 1 - 4 / r) / .6);
3399
+ const wall = flat ? (k + rim) * c1((q - flat) / (1 - flat)) - k : (k + rim) * q * q - k;
3400
+ h += r * (q < 1 ? wall : rim * s * s);
3401
+ m = Math.max(m, flat ? c1((1.6 - q) / (1.5 - flat)) : 0);
3402
+ }
3403
+ return [h, m];
3404
+ };
3405
+ /**
3406
+ * How much of a mound's height there is at x, across it: all of it for 4 m each side of its
3407
+ * middle cx, none 8 m further, and none over the spurs that close the rille's east end. Straight
3408
+ * between the lattice's lines, so the ground between two nodes is what at() says.
3409
+ */
3410
+ var across = (cx, x) => {
3411
+ const f = (u) => c1((12 - Math.abs(u - cx)) / 8) * c1((152 - u) / 4);
3412
+ const x0 = 4 * Math.floor(x / 4);
3413
+ return f(x0) + (f(x0 + 4) - f(x0)) * (x - x0) / 4;
3414
+ };
3415
+ /**
3416
+ * Where the small relief stays out, besides FLATS: the strips whose jumps are measured, x0, z0, x1,
3417
+ * z1 with z from the centre line. The west long jump's take-off and landing, the bridge's ends,
3418
+ * the east stones' approaches, and the two mounds a rover flies the rille from with their flanks
3419
+ * (their run-ups are in FLATS). All to 16 m from the centre line, where the field's mounds begin
3420
+ * at the nearest: what was level there stays level.
3421
+ */
3422
+ var STRIPS = [
3423
+ [
3424
+ 8,
3425
+ 0,
3426
+ 28,
3427
+ 16
3428
+ ],
3429
+ [
3430
+ 70,
3431
+ 0,
3432
+ 90,
3433
+ 16
3434
+ ],
3435
+ [
3436
+ 122,
3437
+ 0,
3438
+ 139,
3439
+ 16
3440
+ ],
3441
+ [
3442
+ 36,
3443
+ 0,
3444
+ 60,
3445
+ 16
3446
+ ],
3447
+ [
3448
+ 132,
3449
+ 0,
3450
+ 156,
3451
+ 16
3452
+ ]
3453
+ ];
3454
+ /**
3455
+ * The small relief, laid over everything: the moon is rugged, no ground is dead flat for long.
3456
+ * `out` is how far out of the arena (under 0: in it). The lattice is 4 m: it carries hummocks and
3457
+ * pans from 8 m across, no less (what is finer is drawn only), and a patch is exactly level only
3458
+ * if every node within 5.7 m of it is, so a level patch costs 6 m of margin whatever its size. In
3459
+ * the arena, over the slabs, only hummocks (up to 0.45 m, nothing under the floor), gentle;
3460
+ * outside, hummocks, shallow pans and a slow swell, -0.45 to 0.55 m, on every 10 m or so. It is
3461
+ * exactly 0 on the arena's edge (the slabs end there), on the lips, on
3462
+ * STRIPS, on FLATS (a base, a rover's place; 1.8 m round a pack or a spawn), and stays off
3463
+ * the jump ramps outside with their run-ups and landings, the craters and the dishes' hill.
3464
+ */
3465
+ var rough = (x, z, out) => {
3466
+ const gap = (l, by, over) => l.reduce((m, [x0, z0, x1, z1]) => m * sm((far(Math.max(x0 - x, x - x1, 0), Math.max(z0 - z, z - z1, 0)) - by) / over), 1);
3467
+ if (out < 0) {
3468
+ const i = Math.min(Math.max(Math.floor(x), 6), LIP.length - 7);
3469
+ const lip = Math.max(...LIP.slice(i - 6, i + 7), 0);
3470
+ return (.6 * Math.max(noise(x / 5, z / 5, 61) - .42, 0) + .25 * Math.max(noise(x / 9, z / 9, 67) - .5, 0)) * sm(-out / 4) * sm((z - 14 - lip) / 3) * gap(FLATS.filter((f) => f[0] === f[2]), 7.5, 2) * gap(FLATS.filter((f) => f[0] < f[2]), 5.7, 2) * gap(STRIPS, 5.7, 2);
3471
+ }
3472
+ let m = sm(out / 4) * (Math.abs(x - 80) < 96 ? sm((z - 10) / 6) : 1);
3473
+ for (const [rx, rz, ax, az] of RAMPS) {
3474
+ const [p, q] = [x - rx, z - rz];
3475
+ const a = p * ax + q * az;
3476
+ m *= sm((far(Math.max(-22 - a, a - 38, 0), Math.max(Math.abs(p * az - q * ax) - 10, 0)) - 2) / 4);
3477
+ }
3478
+ for (const [cx, cz, r] of BOWLS) m *= sm((far(x - cx, z - cz) / r - 1.3) / .25);
3479
+ m *= sm((far(x - HILL[0], z - HILL[1]) - 40) / 20);
3480
+ return (.75 * Math.max(noise(x / 5, z / 5, 61) - .42, 0) - .8 * Math.max(noise(x / 7, z / 7, 63) - .6, 0) + .25 * (noise(x / 11, z / 11, 65) - .5)) * m;
3481
+ };
3482
+ /**
3483
+ * The height of the crater floor round the arena. Only + - * /, Math.sqrt, Math.abs, min, max, floor
3484
+ * and the integer hash: every engine builds the same lattice. In the arena, the field (see FLATS)
3485
+ * and the mounds; exactly 0 for 12 m round it (a rectangle on lattice lines, so between the nodes
3486
+ * too); then rolling hills, the pieces above, then the crater wall: it starts 0.78 of the way to the bound,
3487
+ * is 20 m high on it and, past it where nobody goes, rounds off under a crest of 28 to 48 m that
3488
+ * rolls slowly and falls to the plain at 1.65 of the bound. Lower than the ranges drawn far behind it.
3489
+ */
3490
+ var at$2 = (x, z) => {
3491
+ z = Math.abs(z - 140);
3492
+ const k = far((x - 80) / 300, z / 360);
3493
+ const t = Math.max((k - .78) / .22, 0);
3494
+ const dug = bowls(x, z);
3495
+ const out = Math.max(Math.abs(x - 80) - 80, z - 140);
3496
+ let h = sm((out - 12) / 48) * (1 - .7 * sm(t)) * (16 * noise(x / 96, z / 96, 1) + 6 * noise(x / 52, z / 52, 4) + 5 * noise(x / 36, z / 36, 2) + 1.4 * noise(x / 22, z / 22, 3) - 14.2);
3497
+ if (out < 0) {
3498
+ let m = sm((z - 16 - 10 * noise(x / 19, .5, 37)) / 8) * sm(-out / 10);
3499
+ for (const [x0, z0, x1, z1] of FLATS) m *= sm((far(Math.max(x0 - x, x - x1, 0), Math.max(z0 - z, z - z1, 0)) - (x0 < x1 ? 6 : 7.5)) / 6);
3500
+ h = m * Math.min(Math.max(4.8 * noise(x / 15, z / 15, 21) - .9, 0) + Math.max(3 * noise(x / 31, z / 31, 23) - .6, 0), 2.6);
3501
+ const s = sm((10 - far(x - HOLLOW[0], z - (HOLLOW[1] - 140))) / 8);
3502
+ h = h * (1 - s) - HOLLOW[2] * s;
3503
+ for (const cx of MOUNDS) h += MOUND * c1((8 + RISE - z) / RISE) * across(cx, x);
3504
+ h = z < 8 ? 0 : h;
3505
+ }
3506
+ h = (out < 0 ? h : h * (1 - dug[1])) + dug[0] + rough(x, z, out) * (1 - dug[1]) * (1 - sm(t));
3507
+ for (const [rx, rz, ax, az] of RAMPS) {
3508
+ const [p, q] = [x - rx, z - rz];
3509
+ const a = p * ax + q * az;
3510
+ h += 5.6 * c1(Math.min(a / 16, (32 - a) / 12)) * c1((18 - Math.abs(p * az - q * ax)) / 12);
3511
+ }
3512
+ const d = c1(far(x - RIDGE[0], Math.max(z - RIDGE[1], 0)) / 36);
3513
+ h += 12 * (1 - d * d) * (1 - d * d) + 8 * sm((36 - far(x - HILL[0], z - HILL[1])) / 24);
3514
+ let w = 10 * t * (1 + t);
3515
+ if (k > 1) {
3516
+ const crest = 28 + 14 * noise(x / 170, z / 170, 5) + 6 * noise(x / 70, z / 70, 7);
3517
+ const soft = 10 * sm((k - 1) / .1);
3518
+ w = (w + crest - Math.sqrt((w - crest) * (w - crest) + soft * soft)) / 2 * (1 - sm((k - 1.3) / .35));
3519
+ }
3520
+ return Math.max(h, -14.5) + w;
3521
+ };
3522
+ /** How high a rock's middle is over the ground: three tenths of its height, and 0.6 m or half its height if less. Its widest is there, its flank steep down to the ground: a body is stopped at its foot. */
3523
+ var rockMid = (H) => Math.max(.3 * H, Math.min(.5 * H, .8));
3524
+ /**
3525
+ * The form of a boulder of radius R and height H from a seed: how far it reaches from its middle
3526
+ * (rockMid() over the ground) along a unit vector. A rounded solid, no plane in it:
3527
+ * an ellipsoid stretched unevenly on its three axes and turned by the seed, upright under its
3528
+ * middle (it stands in the regolith, as wide at the ground as at its middle) and a dome over it, swollen and shrunk by two low octaves
3529
+ * of noise with the bearing (large soft lobes), with one gentle hollow and one flatter side. Only
3530
+ * + - * /, Math.sqrt and the hash: the boxes below come from it on every side.
3531
+ */
3532
+ var rockOf = (s, R, H) => {
3533
+ const h = (k) => hash(s, k, 131);
3534
+ const flat = (k) => {
3535
+ const [a, b] = [2 * h(k) - 1, 2 * h(k + 1) - 1];
3536
+ const l = Math.sqrt(a * a + b * b) || 1;
3537
+ return [a / l, b / l];
3538
+ };
3539
+ const [cx, sx] = flat(1);
3540
+ const [a, b] = [R * (.9 + .25 * h(3)), R * (.68 + .22 * h(4))];
3541
+ const lean = .3 * h(9) - .15;
3542
+ const [hx, hz] = flat(5);
3543
+ const [fx, fz] = flat(7);
3544
+ const swell = (u) => {
3545
+ const n = .8 + .28 * noise(1.1 * u[0] + s, 1.1 * u[2] + .9 * u[1], s) + .1 * noise(2.3 * u[0] - s, 2.3 * u[2] + 1.7 * u[1], s + 1);
3546
+ const hollow = c1((.8 * (u[0] * hx + u[2] * hz) + .6 * u[1] - .55) / .45);
3547
+ const side = c1((.954 * (u[0] * fx + u[2] * fz) + .3 * u[1] - .4) / .6);
3548
+ return n * (1 - .14 * hollow * hollow) * (1 - .16 * side * side);
3549
+ };
3550
+ const cu = (H - rockMid(H)) / swell([
3551
+ 0,
3552
+ 1,
3553
+ 0
3554
+ ]);
3555
+ const deep = rockMid(H) + .7 * H;
3556
+ const reach = (u) => {
3557
+ if (u[1] < 0) {
3558
+ const l = Math.sqrt(u[0] * u[0] + u[2] * u[2]);
3559
+ return l < 1e-6 ? deep : Math.min(reach([
3560
+ u[0] / l,
3561
+ 0,
3562
+ u[2] / l
3563
+ ]) / l, deep / -u[1]);
3564
+ }
3565
+ const x = (u[0] * cx + u[2] * sx - lean * u[1]) / a;
3566
+ const z = (u[2] * cx - u[0] * sx - (.15 - lean) * u[1]) / b;
3567
+ const q = u[1] * u[1] / (cu * cu);
3568
+ const [D, E] = [x * x + z * z + .65 * q, .35 * q * q];
3569
+ const T = E < 1e-12 ? 1 / D : (Math.sqrt(D * D + 4 * E) - D) / (2 * E);
3570
+ return Math.sqrt(T) * swell(u);
3571
+ };
3572
+ return { reach };
3573
+ };
3574
+ /**
3575
+ * The boxes a boulder collides with, x0, y0, z0, x1, y1, z1 round its middle: what stops a body is
3576
+ * where the rock is drawn. From `lo` (the ground round it) to its top it is cut in layers: up to
3577
+ * `band` (a body's height over the ground) a layer ends where the rock has moved in or out by
3578
+ * FIT[0] on a bearing, or at 0.9 m; over it by FIT[1], or at 1.5 m; none thinner than 0.25 m. In
3579
+ * each a grid of points says where the rock is at the layer's foot and top (a box may stand 7 cm
3580
+ * out of it), and boxes are picked on it one after the other: the largest first, then the one
3581
+ * that brings the most of the outline within FIT[2] (FIT[3] over the band) of a box, overlapping
3582
+ * one already there, until the whole outline is. No crack between them.
3583
+ */
3584
+ /** How far over the ground a rock's first layer of boxes goes: more than a body steps up, from ground a little higher. */
3585
+ var WALL = STEP_H + .2;
3586
+ var FIT = [
3587
+ .16,
3588
+ .3,
3589
+ .16,
3590
+ .3
3591
+ ];
3592
+ var fitted = ({ reach }, R, lo, band, foot) => {
3593
+ /**
3594
+ * The rock's outline at a height: how far it goes from its axis on 8 m bearings, m to each side
3595
+ * of a square round it (no Math.cos), 7 cm out of it; then whether a point is in that outline.
3596
+ */
3597
+ const outline = (y, m) => {
3598
+ const o = new Float64Array(8 * m);
3599
+ const u = [
3600
+ 0,
3601
+ 0,
3602
+ 0
3603
+ ];
3604
+ for (let k = 0; k < 8 * m; k++) {
3605
+ const t = (k % (2 * m) + .5) / m - 1;
3606
+ const side = Math.floor(k / (2 * m));
3607
+ const l = Math.sqrt(1 + t * t) * (side > 1 ? -1 : 1);
3608
+ const dx = (side % 2 ? -t : 1) / l;
3609
+ const dz = (side % 2 ? 1 : t) / l;
3610
+ let p = 0;
3611
+ let q = 1.6 * R;
3612
+ for (let it = 0; it < 8; it++) {
3613
+ const r = (p + q) / 2;
3614
+ const d = Math.sqrt(r * r + y * y);
3615
+ u[0] = r * dx / d;
3616
+ u[1] = y / d;
3617
+ u[2] = r * dz / d;
3618
+ if (d <= reach(u) + .07) p = r;
3619
+ else q = r;
3620
+ }
3621
+ o[k] = p;
3622
+ }
3623
+ return o;
3624
+ };
3625
+ const within = (o, x, z) => {
3626
+ const m = o.length / 8;
3627
+ const wide = Math.abs(x) >= Math.abs(z);
3628
+ if (Math.abs(x) + Math.abs(z) < 1e-9) return true;
3629
+ const side = wide ? x > 0 ? 0 : 2 : z > 0 ? 1 : 3;
3630
+ const f = ((wide ? z / x : -x / z) + 1) * m - .5 + side * 2 * m;
3631
+ const k = Math.floor(f);
3632
+ const r = o[(k + 8 * m) % (8 * m)] * (1 - (f - k)) + o[(k + 1) % (8 * m)] * (f - k);
3633
+ return x * x + z * z <= r * r;
3634
+ };
3635
+ const top = reach([
3636
+ 0,
3637
+ 1,
3638
+ 0
3639
+ ]) - .1;
3640
+ const c = Math.max(.07, Math.min(.12, R / 12));
3641
+ const out = [];
3642
+ const wall = band - PLAYER_H + WALL;
3643
+ const cuts = [lo];
3644
+ for (let a = lo; a < top - 1e-9;) {
3645
+ const shift = a < band - 1e-9 ? FIT[0] : FIT[1];
3646
+ const base = outline(a + .03, 2);
3647
+ let b = Math.min(a === lo && wall < top - .3 ? wall : a + .25, top);
3648
+ while (b < top && b - a < .9 && outline(Math.min(b + .1, top), 2).every((r, k) => Math.abs(r - base[k]) <= shift)) b = Math.min(b + .1, top);
3649
+ a = top - b < .15 ? top : b;
3650
+ cuts.push(a);
3651
+ }
3652
+ const lines = cuts.map((y, k) => outline(k ? y : y + .03, 8));
3653
+ for (let l = 0; l + 1 < cuts.length; l++) {
3654
+ const [a, b] = [cuts[l], cuts[l + 1]];
3655
+ const near = a < band - 1e-9 ? FIT[2] : FIT[3];
3656
+ const n = Math.ceil(Math.min(Math.max(...lines[l]), Math.max(...lines[l + 1])) / c) + 1;
3657
+ const N = 2 * n + 1;
3658
+ const inl = new Uint8Array(N * N);
3659
+ for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) {
3660
+ const [x, z] = [(i - n) * c, (j - n) * c];
3661
+ inl[i + j * N] = within(lines[l], x, z) && within(lines[l + 1], x, z) ? 1 : 0;
3662
+ }
3663
+ const NEAR = Math.max(1, Math.round(near / c));
3664
+ const on = (i, j) => i >= 0 && i < N && j >= 0 && j < N && inl[i + j * N] > 0;
3665
+ const edge = new Uint8Array(N * N);
3666
+ for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) edge[i + j * N] = on(i, j) && !(on(i - 1, j) && on(i + 1, j) && on(i, j - 1) && on(i, j + 1)) ? 1 : 0;
3667
+ const rects = [];
3668
+ const all = new Uint8Array(N);
3669
+ const hop = N > 48 ? 2 : 1;
3670
+ for (let i0 = 0; i0 < N; i0 += hop) {
3671
+ all.fill(1);
3672
+ for (let i1 = i0; i1 < N; i1++) {
3673
+ let any = false;
3674
+ for (let j = 0, from = 0; j <= N; j++) {
3675
+ all[j] = j < N && all[j] && inl[i1 + j * N] ? 1 : 0;
3676
+ if (!all[j]) {
3677
+ if (j - 1 - from >= 2 && i1 - i0 >= 2 && (i1 - i0) % hop === 0) rects.push([
3678
+ i0,
3679
+ from,
3680
+ i1,
3681
+ j - 1
3682
+ ]);
3683
+ any ||= j - 1 > from;
3684
+ from = j + 1;
3685
+ }
3686
+ }
3687
+ if (!any) break;
3688
+ }
3689
+ }
3690
+ const sum = new Int32Array((N + 1) * (N + 1));
3691
+ const count = (i0, j0, i1, j1) => {
3692
+ const [a0, b0, a1, b1] = [
3693
+ Math.max(i0, 0),
3694
+ Math.max(j0, 0),
3695
+ Math.min(i1, N - 1) + 1,
3696
+ Math.min(j1, N - 1) + 1
3697
+ ];
3698
+ return sum[a1 + b1 * (N + 1)] - sum[a0 + b1 * (N + 1)] - sum[a1 + b0 * (N + 1)] + sum[a0 + b0 * (N + 1)];
3699
+ };
3700
+ const picked = [];
3701
+ for (let k = 0; k < 40 && rects.length; k++) {
3702
+ for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) sum[i + 1 + (j + 1) * (N + 1)] = edge[i + j * N] + sum[i + (j + 1) * (N + 1)] + sum[i + 1 + j * (N + 1)] - sum[i + j * (N + 1)];
3703
+ let [best, score] = [-1, 0];
3704
+ for (let m = 0; m < rects.length; m++) {
3705
+ const q = rects[m];
3706
+ if (k && !picked.some((p) => q[0] < p[2] && p[0] < q[2] && q[1] < p[3] && p[1] < q[3])) continue;
3707
+ const area = (q[2] - q[0]) * (q[3] - q[1]);
3708
+ const gain = k ? count(q[0] - NEAR, q[1] - NEAR, q[2] + NEAR, q[3] + NEAR) : 2;
3709
+ const v = k ? gain * 1e6 + area : area;
3710
+ if (gain >= 2 && v > score) [best, score] = [m, v];
3711
+ }
3712
+ if (best < 0) break;
3713
+ const [i0, j0, i1, j1] = rects[best];
3714
+ picked.push(rects[best]);
3715
+ for (let i = Math.max(i0 - NEAR, 0); i <= Math.min(i1 + NEAR, N - 1); i++) for (let j = Math.max(j0 - NEAR, 0); j <= Math.min(j1 + NEAR, N - 1); j++) edge[i + j * N] = 0;
3716
+ out.push([
3717
+ (i0 - n) * c,
3718
+ l ? a : foot,
3719
+ (j0 - n) * c,
3720
+ (i1 - n) * c,
3721
+ b,
3722
+ (j1 - n) * c
3723
+ ]);
3724
+ }
3725
+ }
3726
+ return out;
3727
+ };
3728
+ /** The ground as it is walked on: at()'s 4 m lattice, each square two triangles, as ground() in relief.ts reads it. */
3729
+ var walked = (x, z) => {
3730
+ const [i, j] = [Math.floor(x / 4), Math.floor(z / 4)];
3731
+ const [fu, fv] = [x / 4 - i, z / 4 - j];
3732
+ const h = (u, v) => at$2(4 * (i + u), 4 * (j + v));
3733
+ const [a, d] = [h(0, 0), h(1, 1)];
3734
+ return fu >= fv ? a + (h(1, 0) - a) * fu + (d - h(1, 0)) * fv : a + (h(0, 1) - a) * fv + (d - h(0, 1)) * fu;
3735
+ };
3736
+ /** A rock of the map: where its middle is over the ground (x, the ground's height, z), its radius, height and seed, and the boxes it collides with (x0, y0, z0, x1, y1, z1), inside what rockOf() draws. */
3737
+ var crag = (x, z, R, H, s) => {
3738
+ const g = walked(x, z);
3739
+ const y = g + rockMid(H);
3740
+ const span = [
3741
+ -3,
3742
+ -2,
3743
+ -1,
3744
+ 0,
3745
+ 1,
3746
+ 2,
3747
+ 3
3748
+ ].map((k) => .4 * R * k);
3749
+ const round = span.map((u) => span.map((v) => walked(x + u, z + v)));
3750
+ const lo = Math.max(Math.min(...round.flat()), g - .55 * H);
3751
+ const band = Math.max(...round.flat()) + PLAYER_H;
3752
+ return {
3753
+ at: [
3754
+ x,
3755
+ g,
3756
+ z
3757
+ ],
3758
+ R,
3759
+ H,
3760
+ s,
3761
+ parts: fitted(rockOf(s, R, H), R, lo - y, band - y, lo - .5 - y).map(([x0, y0, z0, x1, y1, z1]) => [
3762
+ x + x0,
3763
+ y + y0,
3764
+ z + z0,
3765
+ x + x1,
3766
+ y + y1,
3767
+ z + z1
3768
+ ])
3769
+ };
3770
+ };
3771
+ /** Red's boulders, each with the boxes it collides with; blue's are their mirrors. */
3772
+ var CRAGS = [
3773
+ [
3774
+ 32.5,
3775
+ 156.5,
3776
+ 3.1,
3777
+ 3.45,
3778
+ 62
3779
+ ],
3780
+ [
3781
+ 67.5,
3782
+ 159.5,
3783
+ 1.86,
3784
+ 1.84,
3785
+ 63
3786
+ ],
3787
+ [
3788
+ 97.5,
3789
+ 166,
3790
+ 2.79,
3791
+ 2.99,
3792
+ 64
3793
+ ],
3794
+ [
3795
+ 128,
3796
+ 177.5,
3797
+ 3.41,
3798
+ 3.68,
3799
+ 65
3800
+ ],
3801
+ [
3802
+ -50,
3803
+ 330,
3804
+ 3.6,
3805
+ 2.9,
3806
+ 100
3807
+ ],
3808
+ [
3809
+ -64,
3810
+ 336,
3811
+ 2.4,
3812
+ 1.9,
3813
+ 101
3814
+ ],
3815
+ [
3816
+ -14,
3817
+ 204,
3818
+ 2.4,
3819
+ 1.9,
3820
+ 110
3821
+ ],
3822
+ [
3823
+ 176,
3824
+ 212,
3825
+ 2.8,
3826
+ 2.3,
3827
+ 111
3828
+ ]
3829
+ ].map(([x, z, R, H, s]) => crag(x, z, R, H, s));
3830
+ var ghosts = (l) => l.flatMap((c) => c.parts).map(([x0, y0, z0, x1, y1, z1]) => ({
3831
+ ...box(x0, y0, z0, x1, y1, z1, STONE),
3832
+ ghost: true
3833
+ }));
3834
+ /** A pit: PIT_R in radius, cut in a square of half side PIT_S of its crater's terrace, its floor at PIT_FLOOR, 7 m over the kill floor; a flight of PIT_STEPS steps up its east wall. */
3835
+ var [PIT_R, PIT_S, PIT_FLOOR, PIT_STEPS] = [
3836
+ 9,
3837
+ 12,
3838
+ -19,
3839
+ 7
3840
+ ];
3841
+ /**
3842
+ * The pits of red's side and of the centre line (the Bowl's): the middle, the terrace's level and
3843
+ * the rows, a metre of z each: z0, z1 and how far the void goes west and east of the middle. A
3844
+ * circle that wanders by 12 % with z, the same north and south of the middle, rounded up to half
3845
+ * a metre: the void is never narrower than the outline the scenery draws.
3846
+ */
3847
+ var PITS = BOWLS.filter((b) => b[4]).map(([x, zf], n) => {
3848
+ const z = 140 + zf;
3849
+ const rows = Array.from({ length: 2 * PIT_R }, (_, i) => {
3850
+ const dz = Math.abs(i + .5 - PIT_R);
3851
+ const half = Math.sqrt(PIT_R * PIT_R - dz * dz);
3852
+ const w = (side) => Math.ceil(2 * half * (.88 + .24 * noise(dz / 4, side + .5, 60 + n))) / 2;
3853
+ return [
3854
+ z - PIT_R + i,
3855
+ z - PIT_R + i + 1,
3856
+ w(0),
3857
+ w(1)
3858
+ ];
3859
+ });
3860
+ return {
3861
+ x,
3862
+ z,
3863
+ level: at$2(x, z),
3864
+ rows
3865
+ };
3866
+ });
3867
+ /** What a pit collides with: its square of terrace in pieces round the void (two caps and, for each run of rows of one width, a box each side), its floor, and the steps: each as high again as a body jumps at half gravity, 1.3 m deep, up to the terrace at the east wall. */
3868
+ var pit = ({ x, z, level, rows }) => {
3869
+ const runs = rows.reduce((l, [z0, z1, a, b]) => {
3870
+ const last = l.at(-1);
3871
+ if (last && last[2] === a && last[3] === b) last[1] = z1;
3872
+ else l.push([
3873
+ z0,
3874
+ z1,
3875
+ a,
3876
+ b
3877
+ ]);
3878
+ return l;
3879
+ }, []);
3880
+ const east = rows[PIT_R][3];
3881
+ const rise = (level - PIT_FLOOR) / PIT_STEPS;
3882
+ return [
3883
+ box(x - PIT_S, -30, z - PIT_S, x + PIT_S, level, z - PIT_R, STONE),
3884
+ box(x - PIT_S, -30, z + PIT_R, x + PIT_S, level, z + PIT_S, STONE),
3885
+ ...runs.flatMap(([z0, z1, a, b]) => [box(x - PIT_S, -30, z0, x - a, level, z1, STONE), box(x + b, -30, z0, x + PIT_S, level, z1, STONE)]),
3886
+ box(x - PIT_R - 1.5, -30, z - PIT_R, x + PIT_R + 1.5, PIT_FLOOR, z + PIT_R, STONE),
3887
+ ...Array.from({ length: PIT_STEPS - 1 }, (_, k) => box(x + east - 1.3 * (PIT_STEPS - 1 - k), PIT_FLOOR, z - 1, x + east - 1.3 * (PIT_STEPS - 2 - k), PIT_FLOOR + rise * (k + 1), z + 1, STONE))
3888
+ ].map((b) => ({
3889
+ ...b,
3890
+ ghost: true
3891
+ }));
3892
+ };
3893
+ /** The ghost under a drawn rock or mast: a box of half side s from under the ground to h above it. */
3894
+ var lump = (x, z, s, h) => ({
3895
+ ...box(x - s, at$2(x, z) - 6, z - s, x + s, at$2(x, z) + h, z + s, STONE),
3896
+ ghost: true
3897
+ });
3898
+ var LAYOUT = {
3899
+ /** Outside the arena: the dishes, the ramps (the middle of the lip and the unit way up it), the wreck. */
3900
+ dishes: [...DISHES, ...DISHES.map(([x, z]) => [x, 280 - z])],
3901
+ ramps: RAMPS.flatMap(([x, z, ax, az]) => (z ? [1, -1] : [1]).map((m) => [
3902
+ x + 16 * ax,
3903
+ 140 + m * (z + 16 * az),
3904
+ ax,
3905
+ m * az + 0
3906
+ ])),
3907
+ wreck: WRECK,
3908
+ /** The pits, both sides: the middle, the terrace's level and the rows (z0, z1, the void's reach west and east). */
3909
+ pits: PITS.flatMap((p) => p.z === 140 ? [p] : [p, {
3910
+ ...p,
3911
+ z: 280 - p.z,
3912
+ rows: p.rows.map(([z0, z1, a, b]) => [
3913
+ 280 - z1,
3914
+ 280 - z0,
3915
+ a,
3916
+ b
3917
+ ]).reverse()
3918
+ }]),
3919
+ /** The craters of the relief, both sides: x, z, radius, depth as a share of it. */
3920
+ bowls: BOWLS.flatMap(([x, z, r, k = .17]) => (z ? [1, -1] : [1]).map((m) => [
3921
+ x,
3922
+ 140 + m * z,
3923
+ r,
3924
+ k
3925
+ ])),
3926
+ /** Red's boulders, in the field and outside: blue's are their mirrors. */
3927
+ crags: CRAGS,
3928
+ /** Where the boulders stood, red's side (x, z, radius): pebbles lie thickest there. */
3929
+ sites: SITES,
3930
+ pillars: PILLARS,
3931
+ domes: [DOME, [DOME[0], 280 - DOME[1]]],
3932
+ pads: [PAD$1, [
3933
+ PAD$1[0],
3934
+ 280 - PAD$1[1],
3935
+ PAD$1[2]
3936
+ ]],
3937
+ modules: [...MODULES, ...MODULES.map(mirror$1)],
3938
+ tubes: [...TUBES, ...TUBES.map(mirror$1)],
3939
+ masts: [...MASTS, ...MASTS.map(([x, z]) => [x, 280 - z])]
3940
+ };
3941
+ /** The twin of a brush, a point or a spawn across the centre line. */
3942
+ var flip$1 = (b) => ({
3943
+ ...b,
3944
+ min: [
3945
+ b.min[0],
3946
+ b.min[1],
3947
+ 280 - b.max[2]
3948
+ ],
3949
+ max: [
3950
+ b.max[0],
3951
+ b.max[1],
3952
+ 280 - b.min[2]
3953
+ ],
3954
+ tint: b.tint === RED ? BLUE : b.tint
3955
+ });
3956
+ var flipPoint = ([x, y, z]) => [
3957
+ x,
3958
+ y,
3959
+ 280 - z
3960
+ ];
3961
+ /** The list and its twins, then the pieces by the rille. */
3962
+ var both = (l, ...mid) => [
3963
+ ...l,
3964
+ ...l.map(flipPoint),
3965
+ ...mid
3966
+ ];
3967
+ /** Red's half: z from 140 to 280. */
3968
+ var half = [
3969
+ ...[
3970
+ box(0, -30, 160, 160, 0, HOLLOW[1] - 12, STONE),
3971
+ box(0, -30, HOLLOW[1] - 12, HOLLOW[0] - 12, 0, HOLLOW[1] + 12, STONE),
3972
+ box(HOLLOW[0] + 12, -30, HOLLOW[1] - 12, 160, 0, HOLLOW[1] + 12, STONE),
3973
+ box(0, -30, HOLLOW[1] + 12, 160, 0, 280, STONE),
3974
+ box(HOLLOW[0] - 12, -30, HOLLOW[1] - 12, HOLLOW[0] + 12, -3, HOLLOW[1] + 12, STONE),
3975
+ ...RUNS.filter((r) => r[2] < 0).map(([x, w, n]) => box(x, -30, 148 + n, x + w, 0, 160, STONE)),
3976
+ ...Array.from({ length: 14 }, (_, k) => runs(LIP.map((n) => n < 0 ? 2 : n > k / 2 ? 1 : 0)).filter((r) => !r[2]).map(([x, w]) => box(x, -30, 148 + k / 2, x + w, 0, k < 13 ? 148.5 + k / 2 : 160, STONE))).flat(),
3977
+ ...MOUNDS.flatMap((x) => [
3978
+ -12,
3979
+ -10,
3980
+ -8,
3981
+ -6,
3982
+ -4,
3983
+ 4,
3984
+ 6,
3985
+ 8,
3986
+ 10
3987
+ ].map((a) => [a, a + (a === -4 ? 8 : 2)]).map(([a, b]) => [
3988
+ x + a,
3989
+ x + b,
3990
+ MOUND * Math.min(across(x, x + a), across(x, x + b)) * (1 - .5 / RISE) - .12
3991
+ ]).filter((r) => r[2] > .3).map(([a, b, y]) => box(a, 0, 148, b, y, 148.5, STONE)))
3992
+ ].map((b) => ({
3993
+ ...b,
3994
+ ghost: true
3995
+ })),
3996
+ ...BASE,
3997
+ {
3998
+ ...box(75.25, 0, FLAG - 4.75, 84.75, .5, FLAG + 4.75, PAINT, CONCRETE, RED),
3999
+ ghost: true
4000
+ },
4001
+ {
4002
+ ...box(75.75, .5, FLAG - 4.25, 84.25, 1, FLAG + 4.25, PAINT, CONCRETE, RED),
4003
+ ghost: true
4004
+ },
4005
+ box(60, 0, 259, 70, 1.5, 265, STEEL, PAINT, RED),
4006
+ box(27, 0, 207, 53, .25, 233, METAL),
4007
+ ...MASTS.map(([x, z]) => box(x - .2, x < 60 ? .25 : 0, z - .2, x + .2, x < 60 ? 10.25 : 10, z + .2, STEEL)),
4008
+ box(12, -30, 148 - 2.5 / 2, 24, 0, 148, PAINT, STONE, [
4009
+ 1,
4010
+ .42,
4011
+ .08
4012
+ ]),
4013
+ ...PITS.filter((p) => p.z !== 140).flatMap(pit),
4014
+ ...ghosts(CRAGS),
4015
+ ...DISHES.map(([x, z]) => lump(x, z, .4, 6))
4016
+ ];
4017
+ /** What stands on the centre line, symmetric as written: the bridge, the stones, the rille's plugs and the wreck. */
4018
+ var centre = [
4019
+ box(74, -1.5, 132, 86, 0, 148, METAL, STEEL),
4020
+ box(74, 0, 132, 74.4, 1.1, 148, CONCRETE),
4021
+ box(85.6, 0, 132, 86, 1.1, 148, CONCRETE),
4022
+ ...PILLARS.map(([x0, z0, x1, z1, y]) => ({
4023
+ ...box(x0, -30, z0, x1, y, z1, STONE),
4024
+ ghost: true
4025
+ })),
4026
+ {
4027
+ ...box(-10, -30, 132, 0, 0, 148, STONE),
4028
+ ghost: true
4029
+ },
4030
+ {
4031
+ ...box(160, -30, 132, 170, 0, 148, STONE),
4032
+ ghost: true
4033
+ },
4034
+ {
4035
+ ...box(WRECK[0] - 3.6, -30, WRECK[1] - 3.6, WRECK[0] + 3.6, PIT_FLOOR + 3.5, WRECK[1] + 3.6, STONE),
4036
+ ghost: true
4037
+ },
4038
+ ...PITS.filter((p) => p.z === 140).flatMap(pit),
4039
+ ...LAYOUT.ramps.flatMap(([x, z, ax, az]) => [-8, 8].map((c) => lump(x + c * az, z - c * ax, .2, 2.2)))
4040
+ ];
4041
+ /** Red's spawns behind the dome facing blue (yaw 0 looks toward -z): five in a row, three in front. */
4042
+ var SPAWNS = [...[
4043
+ 56,
4044
+ 68,
4045
+ 80,
4046
+ 92,
4047
+ 104
4048
+ ].map((x) => [
4049
+ x,
4050
+ 0,
4051
+ 271,
4052
+ 0
4053
+ ]), ...[
4054
+ 62,
4055
+ 80,
4056
+ 98
4057
+ ].map((x) => [
4058
+ x,
4059
+ 0,
4060
+ 267,
4061
+ 0
4062
+ ])];
4063
+ /** The racks on the plinth, 2.5 m apart: rifle, rail, gun, katana. */
4064
+ var racks = (z) => Object.fromEntries([
4065
+ "rifle",
4066
+ "rail",
4067
+ "rack",
4068
+ "blade"
4069
+ ].map((k, i) => [k, [
4070
+ 61.25 + 2.5 * i,
4071
+ 1.5,
4072
+ z
4073
+ ]]));
4074
+ var team = (z, s) => ({
4075
+ base: [
4076
+ 80,
4077
+ 1,
4078
+ z
4079
+ ],
4080
+ spawns: s,
4081
+ ...racks(z + (z > 140 ? 28 : -28))
4082
+ });
4083
+ var MOON = {
4084
+ name: "Tranquility",
4085
+ tag: "Moon · half gravity",
4086
+ lore: "A mining base left in a lunar crater, its domes still lit. Two crews fight for it in space helmets, under the Earth and a black sky. Jumps float twice as high, and a rille cuts the base in two.",
4087
+ brushes: [
4088
+ ...half,
4089
+ ...half.map(flip$1),
4090
+ ...centre
4091
+ ],
4092
+ teams: [team(FLAG, SPAWNS), team(280 - FLAG, SPAWNS.map(([x, y, z]) => [
4093
+ x,
4094
+ y,
4095
+ 280 - z,
4096
+ Math.PI
4097
+ ]))],
4098
+ packs: both([
4099
+ [
4100
+ 90,
4101
+ 0,
4102
+ 210
4103
+ ],
4104
+ [
4105
+ 118,
4106
+ 5,
4107
+ 226
4108
+ ],
4109
+ [
4110
+ 30,
4111
+ 0,
4112
+ 185
4113
+ ],
4114
+ [
4115
+ 80,
4116
+ 3.5,
4117
+ 253.5
4118
+ ]
4119
+ ], [
4120
+ 45,
4121
+ 0,
4122
+ 162
4123
+ ], [
4124
+ 45,
4125
+ 0,
4126
+ 118
4127
+ ]),
4128
+ ammo: both([
4129
+ [
4130
+ 50,
4131
+ 0,
4132
+ 246
4133
+ ],
4134
+ [
4135
+ 103,
4136
+ 5,
4137
+ 200
4138
+ ],
4139
+ [
4140
+ 135,
4141
+ 0,
4142
+ 190
4143
+ ]
4144
+ ], [
4145
+ 115,
4146
+ 0,
4147
+ 162
4148
+ ], [
4149
+ 115,
4150
+ 0,
4151
+ 118
4152
+ ]),
4153
+ cells: both([[
4154
+ 106.5,
4155
+ 3.5,
4156
+ 226
4157
+ ], [
4158
+ 35,
4159
+ 0,
4160
+ 244
4161
+ ]], [
4162
+ 80,
4163
+ 0,
4164
+ 140
4165
+ ]),
4166
+ floor: -26,
4167
+ relief: {
4168
+ hole: [
4169
+ 0,
4170
+ 132,
4171
+ 160,
4172
+ 148
4173
+ ],
4174
+ pits: [...RUNS.flatMap(([x, w, n]) => n > 0 ? [[
4175
+ x,
4176
+ 148,
4177
+ x + w,
4178
+ 148 + n
4179
+ ], [
4180
+ x,
4181
+ 132 - n,
4182
+ x + w,
4183
+ 132
4184
+ ]] : []), ...LAYOUT.pits.flatMap(({ x, rows }) => rows.map(([z0, z1, a, b]) => [
4185
+ x - a,
4186
+ z0,
4187
+ x + b,
4188
+ z1
4189
+ ]))],
4190
+ bound: [
4191
+ 80,
4192
+ 140,
4193
+ 300,
4194
+ 360
4195
+ ],
4196
+ cell: 4,
4197
+ at: at$2
4198
+ },
4199
+ sun: {
4200
+ dir: [
4201
+ .87996,
4202
+ .40998,
4203
+ .23999
4204
+ ],
4205
+ color: [
4206
+ 3,
4207
+ 2.95,
4208
+ 2.85
4209
+ ]
4210
+ },
4211
+ sky: [[
4212
+ .002,
4213
+ .002,
4214
+ .006
4215
+ ], [
4216
+ .02,
4217
+ .02,
4218
+ .035
4219
+ ]],
4220
+ gravity: .5,
4221
+ rovers: [
4222
+ [
4223
+ 100,
4224
+ 0,
4225
+ 178,
4226
+ 0
4227
+ ],
4228
+ [
4229
+ 30,
4230
+ 0,
4231
+ 255,
4232
+ 0
4233
+ ],
4234
+ [
4235
+ 100,
4236
+ 0,
4237
+ 102,
4238
+ Math.PI
4239
+ ],
4240
+ [
4241
+ 30,
4242
+ 0,
4243
+ 25,
4244
+ Math.PI
4245
+ ]
4246
+ ],
4247
+ ships: [[
4248
+ PAD$1[0],
4249
+ .25,
4250
+ PAD$1[1],
4251
+ 0
4252
+ ], [
4253
+ PAD$1[0],
4254
+ .25,
4255
+ 280 - PAD$1[1],
4256
+ Math.PI
4257
+ ]],
4258
+ doors: [...DOORS, ...DOORS.map(mirror$1)],
4259
+ scenery: "moon",
4260
+ helmets: true,
4261
+ armor: true
4262
+ };
4263
+ // src/shared/routes.ts
4264
+ var go = (x, z, y, sprint = true) => ({
4265
+ k: "go",
4266
+ to: [x, z],
4267
+ y,
4268
+ sprint
4269
+ });
4270
+ var leap = (at, to, y, o = {}) => ({
4271
+ k: "leap",
4272
+ at,
4273
+ to,
4274
+ y,
4275
+ sprint: true,
4276
+ ...o
4277
+ });
4278
+ /** The mirror image of a leg across z = zed / 2. */
4279
+ var mirror = (l, zed) => {
4280
+ const f = ([x, z]) => [x, zed - z];
4281
+ return l.k === "go" ? {
4282
+ ...l,
4283
+ to: f(l.to)
4284
+ } : l.k === "leap" ? {
4285
+ ...l,
4286
+ at: f(l.at),
4287
+ to: f(l.to)
4288
+ } : {
4289
+ ...l,
4290
+ from: f(l.from),
4291
+ to: f(l.to)
4292
+ };
4293
+ };
4294
+ /** The mirror image of a leg across HIGHLINE's centre line. */
4295
+ var flip = (l) => mirror(l, 240);
4296
+ /** The Spine: the tower's north edge across 11 m, the viaduct along its wall, the beam over the plaza. */
4297
+ var HIGH = {
4298
+ mid: [
4299
+ 15.6,
4300
+ 26,
4301
+ 120
4302
+ ],
4303
+ start: 0,
4304
+ flag: [go(16.5, 236, 26)],
4305
+ out: [
4306
+ go(16.5, 213, 26),
4307
+ leap([16.5, 212.2], [16.5, 192], 26, { dash: 32 }),
4308
+ go(15.6, 166, 26),
4309
+ leap([15.6, 164.2], [15.6, 142], 26, {
4310
+ run: true,
4311
+ dash: 1,
4312
+ double: 12
4313
+ }),
4314
+ go(15.6, 134.5, 26),
4315
+ go(15.6, 120, 26)
4316
+ ],
4317
+ in: [
4318
+ go(15.6, 134.5, 26),
4319
+ go(15.6, 146.5, 26),
4320
+ leap([15.6, 146.8], [15.6, 170], 26, {
4321
+ run: true,
4322
+ dash: 1,
4323
+ double: 12
4324
+ }),
4325
+ go(16.5, 199, 26),
4326
+ leap([16.5, 200.8], [16.5, 225], 26, { dash: 32 }),
4327
+ go(32, 224, 26)
4328
+ ]
4329
+ };
4330
+ /** Midtown: down onto the forecourt, two roofs, the plaza and its dais; back by the ledge ladders. */
4331
+ var MID = {
4332
+ mid: [
4333
+ 45.5,
4334
+ 17.2,
4335
+ 120
4336
+ ],
4337
+ start: 4,
4338
+ flag: [],
4339
+ out: [
4340
+ go(45.5, 214, 26),
4341
+ leap([45.5, 212.2], [45.5, 196], 19),
4342
+ go(45.5, 188, 19),
4343
+ leap([45.5, 186.2], [45.5, 176], 21.2),
4344
+ go(45.5, 167.5, 21.2),
4345
+ leap([45.5, 166.2], [45.5, 150], 19),
4346
+ go(45.5, 141.5, 19),
4347
+ leap([45.5, 140.2], [45.5, 131], 15),
4348
+ go(45.5, 130, 15),
4349
+ leap([45.5, 129.3], [45.5, 120], 17.2)
4350
+ ],
4351
+ in: [
4352
+ go(38, 131, 15),
4353
+ leap([38, 133.8], [38, 138], 17.2, { sprint: false }),
4354
+ leap([38, 139], [38, 150], 19, { sprint: false }),
4355
+ go(38, 159.8, 19),
4356
+ leap([38, 160.4], [38, 172], 21.2),
4357
+ go(38, 181.2, 21.2),
4358
+ leap([38, 181.8], [38, 195], 19),
4359
+ go(34.5, 207, 19),
4360
+ leap([34.5, 208], [35, 211], 21.2, { sprint: false }),
4361
+ leap([36.8, 210.5], [42, 210.5], 23.4, { sprint: false }),
4362
+ leap([43.8, 210.5], [49, 210.5], 25, { sprint: false }),
4363
+ leap([49, 211.5], [49, 215], 26, { sprint: false }),
4364
+ go(32, 224, 26)
4365
+ ]
4366
+ };
4367
+ /** The Lowline: the stairs down the tower's east face, short gaps, the east terrace; back up. */
4368
+ var LOW = {
4369
+ mid: [
4370
+ 86,
4371
+ 14.5,
4372
+ 120
4373
+ ],
4374
+ start: 7,
4375
+ flag: [],
4376
+ out: [
4377
+ go(52.5, 229, 26),
4378
+ go(78, 229, 14.5),
4379
+ go(88, 222, 14.5),
4380
+ go(88, 214.3, 14.5),
4381
+ leap([88, 213.3], [88, 206], 14.5),
4382
+ go(88, 186.3, 14.5),
4383
+ leap([88, 185.3], [88, 178], 14.5),
4384
+ go(98, 176, 14.5),
4385
+ go(98, 139, 14.5),
4386
+ leap([98, 138.3], [98, 130], 14.5),
4387
+ go(86, 120, 14.5)
4388
+ ],
4389
+ in: [
4390
+ go(98, 131, 14.5),
4391
+ leap([98, 133.7], [98, 141], 14.5),
4392
+ go(98, 180.5, 14.5),
4393
+ leap([98, 181.2], [98, 189], 14.5),
4394
+ go(98, 207.5, 14.5),
4395
+ leap([98, 208.5], [98, 216], 14.5),
4396
+ go(86, 229, 14.5),
4397
+ go(77.2, 229, 14.5),
4398
+ go(52.3, 229, 26),
4399
+ go(32, 224, 26)
4400
+ ]
4401
+ };
4402
+ /**
4403
+ * The ways back up after a miss, from the roof a fall lands on to the roof above (red's half):
4404
+ * the terrace under the first gap of the Spine, the roof under the viaduct, the plaza under the
4405
+ * beam, and the shortcut from the forecourt of Midtown up to the first Spine roof. Each starts with
4406
+ * the player on the lower roof, standing at `from`.
4407
+ */
4408
+ var UP = {
4409
+ terrace: {
4410
+ from: [
4411
+ 8,
4412
+ 19,
4413
+ 208
4414
+ ],
4415
+ legs: [
4416
+ leap([8, 206.6], [8, 203], 21.2, { sprint: false }),
4417
+ go(6.6, 203, 21.2, false),
4418
+ leap([9.4, 203], [15, 203], 23.4, { sprint: false }),
4419
+ go(13.6, 203, 23.4, false),
4420
+ leap([16.4, 203], [22, 203], 25, { sprint: false }),
4421
+ leap([22, 202.2], [22, 196], 26, { sprint: false })
4422
+ ]
4423
+ },
4424
+ viaduct: {
4425
+ from: [
4426
+ 20,
4427
+ 19,
4428
+ 149
4429
+ ],
4430
+ legs: [
4431
+ leap([20, 150.6], [20, 154], 21.2, { sprint: false }),
4432
+ leap([20, 155.4], [20, 160], 23.4, { sprint: false }),
4433
+ leap([21.4, 161], [24.5, 161], 25, { sprint: false }),
4434
+ leap([24.5, 163], [24.5, 168], 26, { sprint: false })
4435
+ ]
4436
+ },
4437
+ forecourt: {
4438
+ from: [
4439
+ 36,
4440
+ 19,
4441
+ 198
4442
+ ],
4443
+ legs: [
4444
+ leap([34, 198], [30, 198], 21.2, { sprint: false }),
4445
+ leap([30.4, 196.6], [30, 192], 23.4, { sprint: false }),
4446
+ leap([30, 190.4], [28, 186], 25, { sprint: false }),
4447
+ leap([27.2, 186], [21, 186], 26, { sprint: false })
4448
+ ]
4449
+ },
4450
+ plaza: {
4451
+ from: [
4452
+ 8.5,
4453
+ 15,
4454
+ 124
4455
+ ],
4456
+ legs: [
4457
+ leap([8.5, 127.5], [8.5, 131], 17.2, { sprint: false }),
4458
+ leap([10.1, 131], [14.5, 131], 19.4, { sprint: false }),
4459
+ leap([16.1, 131], [20.5, 131], 21.6, { sprint: false }),
4460
+ leap([22.1, 131], [26.5, 131], 23.8, { sprint: false }),
4461
+ leap([25.5, 133], [25.5, 138], 26, { sprint: false })
4462
+ ]
4463
+ }
4464
+ };
4465
+ // src/shared/nav.ts
4466
+ /** Metres a second a bot is taken to run, for the costs. */
4467
+ var PACE = 7;
4468
+ /** Seconds added to a jump, and to a jump that wants a dash, a double jump or a wall-run. */
4469
+ var LEAP = .5;
4470
+ var TRICK = 1.5;
4471
+ /** The longest straight walk between two points, metres. */
4472
+ var WALK = 30;
4473
+ /** The most a straight walk steps down, metres: off a plinth, down a short drop. */
4474
+ var DROP$1 = 2;
4475
+ /**
4476
+ * Metres to the nearest node a bot heads for when no straight walk reaches one (the moon's relief
4477
+ * fails most, a stair all), how far above it may be (up a stair, or a ledge to climb) and how far
4478
+ * below: a drop that does not hurt at full gravity.
4479
+ */
4480
+ var NEAR = 16;
4481
+ var ABOVE = 2.2;
4482
+ /** Two points of the routes this close (metres, and in height) are one. */
4483
+ var SAME = .6;
4484
+ /** The routes, fastest first: the Spine, Midtown, the Lowline. */
4485
+ var ROUTES = [
4486
+ HIGH,
4487
+ MID,
4488
+ LOW
4489
+ ];
4490
+ /** A leg of a route the bot does not prefer costs this many times more. */
4491
+ var OTHER = 3;
4492
+ /**
4493
+ * MOON's lanes in red's half, walked straight from point to point both ways: round the dome on the
4494
+ * west (the modules close the east), in at its door to the flag, and across the field to the three
4495
+ * crossings of the rille (the bridge, the west jump's run-up, the east stones' lip). Blue's are
4496
+ * their mirror across z = 140. Relief and boulders fail walkable(), so these are not checked: a
4497
+ * bot jumps what it bumps into.
4498
+ */
4499
+ var LANES = [
4500
+ [
4501
+ [
4502
+ 72,
4503
+ 0,
4504
+ 258
4505
+ ],
4506
+ [
4507
+ 80,
4508
+ 0,
4509
+ 269
4510
+ ],
4511
+ [
4512
+ 52,
4513
+ 0,
4514
+ 270
4515
+ ],
4516
+ [
4517
+ 50,
4518
+ 0,
4519
+ 212
4520
+ ],
4521
+ [
4522
+ 80,
4523
+ 0,
4524
+ 208
4525
+ ],
4526
+ [
4527
+ 80,
4528
+ 0,
4529
+ 214.5
4530
+ ],
4531
+ [
4532
+ 80,
4533
+ 0,
4534
+ 224
4535
+ ],
4536
+ [
4537
+ 80,
4538
+ 1,
4539
+ 232
4540
+ ]
4541
+ ],
4542
+ [
4543
+ [
4544
+ 80,
4545
+ 0,
4546
+ 208
4547
+ ],
4548
+ [
4549
+ 80,
4550
+ 0,
4551
+ 152
4552
+ ],
4553
+ [
4554
+ 80,
4555
+ 0,
4556
+ 140
4557
+ ]
4558
+ ],
4559
+ [[
4560
+ 50,
4561
+ 0,
4562
+ 212
4563
+ ], [
4564
+ 18,
4565
+ 0,
4566
+ 190
4567
+ ]],
4568
+ [[
4569
+ 18,
4570
+ 0,
4571
+ 125
4572
+ ], [
4573
+ 18,
4574
+ 0,
4575
+ 90
4576
+ ]],
4577
+ [
4578
+ [
4579
+ 80,
4580
+ 0,
4581
+ 208
4582
+ ],
4583
+ [
4584
+ 128.5,
4585
+ 0,
4586
+ 160
4587
+ ],
4588
+ [
4589
+ 128.5,
4590
+ 0,
4591
+ 150
4592
+ ]
4593
+ ]
4594
+ ];
4595
+ /**
4596
+ * The jumps over MOON's rille from red's side, as moon.test.ts flies them: the west long jump (a
4597
+ * sprint jumped at the lip, a dash late in the air), and the east stones at 1.2, 2.4 and 1.2 m,
4598
+ * each a jump that comes down on the stone. Blue's are their mirror. With the bridge (LANES[1]),
4599
+ * they are the moon's three routes, an index of ROUTES each, so that bots spread over them.
4600
+ */
4601
+ var BRIDGE = 1;
4602
+ var CROSSINGS = [[
4603
+ 1,
4604
+ [
4605
+ 18,
4606
+ 0,
4607
+ 190
4608
+ ],
4609
+ [leap([18, 147], [18, 125], 0, { dash: 20 })]
4610
+ ], [
4611
+ 2,
4612
+ [
4613
+ 128.5,
4614
+ 0,
4615
+ 150
4616
+ ],
4617
+ [
4618
+ [
4619
+ 128.5,
4620
+ 150,
4621
+ 128.5,
4622
+ 145,
4623
+ 1.2
4624
+ ],
4625
+ [
4626
+ 128.5,
4627
+ 145,
4628
+ 132.5,
4629
+ 140,
4630
+ 2.4
4631
+ ],
4632
+ [
4633
+ 132.5,
4634
+ 140,
4635
+ 128.5,
4636
+ 135,
4637
+ 1.2
4638
+ ],
4639
+ [
4640
+ 128.5,
4641
+ 135,
4642
+ 128.5,
4643
+ 130,
4644
+ 0
4645
+ ]
4646
+ ].map(([ax, az, tx, tz, y]) => leap([ax, az], [tx, tz], y, {
4647
+ sprint: false,
4648
+ land: true
4649
+ }))
4650
+ ]];
4651
+ /** Where a leg ends: a jump steers for its `to`, which is on the roof it lands on. */
4652
+ var end = (l) => [
4653
+ l.to[0],
4654
+ l.y,
4655
+ l.to[1]
4656
+ ];
4657
+ /** Where a leg starts its own move: a jump's take-off, a slide's run-in, a run's goal. */
4658
+ var from = (l) => l.k === "leap" ? l.at : l.k === "slide" ? l.from : l.to;
4659
+ var flat$1 = (a, b) => {
4660
+ const [ax, az] = a.length === 3 ? [a[0], a[2]] : a;
4661
+ const [bx, bz] = b.length === 3 ? [b[0], b[2]] : b;
4662
+ return Math.sqrt((bx - ax) ** 2 + (bz - az) ** 2);
4663
+ };
4664
+ /**
4665
+ * Whether a body walks in a straight line from a to b, a step up or a drop of DROP at most: a floor
4666
+ * under the middle and both sides of the body every half metre, and nothing in the way at the knees
4667
+ * or the head from the height of a.
4668
+ */
4669
+ var walkable = (w, a, b) => {
4670
+ if (b[1] - a[1] > .5 || a[1] - b[1] > DROP$1) return false;
4671
+ const d = flat$1(a, b);
4672
+ if (d < .001) return true;
4673
+ const [ux, uz] = [(b[0] - a[0]) / d, (b[2] - a[2]) / d];
4674
+ const y = Math.min(a[1], b[1]);
4675
+ for (const s of [
4676
+ -PLAYER_R,
4677
+ 0,
4678
+ PLAYER_R
4679
+ ]) {
4680
+ const [ox, oz] = [a[0] - uz * s, a[2] + ux * s];
4681
+ for (const h of [STEP_H + .1, 1.5]) if (ray(w, [
4682
+ ox,
4683
+ a[1] + h,
4684
+ oz
4685
+ ], [
4686
+ ux,
4687
+ 0,
4688
+ uz
4689
+ ], d) < d) return false;
4690
+ 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;
4691
+ }
4692
+ return true;
4693
+ };
4694
+ var built = /* @__PURE__ */ new WeakMap();
4695
+ /** The bots' map of a world, built once per world. */
4696
+ var navOf = (w) => {
4697
+ let nav = built.get(w);
4698
+ if (!nav) {
4699
+ nav = build(w);
4700
+ built.set(w, nav);
4701
+ }
4702
+ return nav;
4703
+ };
4704
+ var build = (w) => {
4705
+ const nodes = [];
4706
+ const out = [];
4707
+ const runUp = /* @__PURE__ */ new Set();
4708
+ const node = (p) => {
4709
+ let i = nodes.findIndex((n) => flat$1(n, p) < SAME && Math.abs(n[1] - p[1]) < SAME);
4710
+ if (i < 0) {
4711
+ i = nodes.push(p) - 1;
4712
+ out.push([]);
4713
+ }
4714
+ return i;
4715
+ };
4716
+ const chain = (start, legs, route = -1) => {
4717
+ let at = node(start);
4718
+ for (const l of legs) {
4719
+ const to = node(end(l));
4720
+ const tricky = l.k === "leap" && (l.dash !== void 0 || l.double !== void 0 || l.run);
4721
+ const cost = (flat$1(nodes[at], from(l)) + flat$1(from(l), end(l))) / PACE + (l.k === "go" ? 0 : tricky ? TRICK : LEAP);
4722
+ out[at].push({
4723
+ to,
4724
+ leg: l,
4725
+ route,
4726
+ cost
4727
+ });
4728
+ if (l.k === "leap" && l.sprint && legs[0] !== l) runUp.add(at);
4729
+ at = to;
4730
+ }
4731
+ };
4732
+ if (w.def === HIGHLINE) {
4733
+ const [red] = w.def.teams;
4734
+ for (const f of [(l) => l, flip]) {
4735
+ const z = (p) => f === flip ? [
4736
+ p[0],
4737
+ p[1],
4738
+ 240 - p[2]
4739
+ ] : p;
4740
+ ROUTES.forEach((r, k) => {
4741
+ const [sx, sy, sz] = red.spawns[r.start];
4742
+ chain(z([
4743
+ sx,
4744
+ sy,
4745
+ sz
4746
+ ]), r.out.map(f), k);
4747
+ if (r.flag.length) chain(z(red.base), [...r.flag, ...r.out].map(f), k);
4748
+ chain(z(r.mid), r.in.map(f), k);
4749
+ });
4750
+ for (const u of Object.values(UP)) chain(z(u.from), u.legs.map(f));
4751
+ }
4752
+ }
4753
+ if (w.def === MOON) {
4754
+ for (const [route, [x, y, z], legs] of CROSSINGS) {
4755
+ chain([
4756
+ x,
4757
+ y,
4758
+ z
4759
+ ], legs, route);
4760
+ chain([
4761
+ x,
4762
+ y,
4763
+ 280 - z
4764
+ ], legs.map((l) => mirror(l, 280)), route);
4765
+ }
4766
+ [...LANES, ...LANES.map((l) => l.map(([x, y, z]) => [
4767
+ x,
4768
+ y,
4769
+ 280 - z
4770
+ ]))].forEach((lane, i) => {
4771
+ const route = i % LANES.length === BRIDGE ? 0 : -1;
4772
+ for (let k = 1; k < lane.length; k++) {
4773
+ const [a, b] = [node(lane[k - 1]), node(lane[k])];
4774
+ const cost = flat$1(nodes[a], nodes[b]) / PACE;
4775
+ out[a].push({
4776
+ to: b,
4777
+ route,
4778
+ cost
4779
+ });
4780
+ out[b].push({
4781
+ to: a,
4782
+ route,
4783
+ cost
4784
+ });
4785
+ }
4786
+ });
4787
+ }
4788
+ for (let i = 0; i < nodes.length; i++) for (let j = 0; j < nodes.length; j++) {
4789
+ const d = flat$1(nodes[i], nodes[j]);
4790
+ if (i !== j && !runUp.has(j) && d <= WALK && walkable(w, nodes[i], nodes[j])) out[i].push({
4791
+ to: j,
4792
+ route: -1,
4793
+ cost: d / PACE
4794
+ });
4795
+ }
4796
+ return {
4797
+ nodes,
4798
+ out,
4799
+ runUp
4800
+ };
4801
+ };
4802
+ /**
4803
+ * The cheapest way from the point `a` to the point `b`. No entry when `a` walks straight to `b`, or
4804
+ * when the map has no way. The legs of the routes other than `prefer` (an index of ROUTES) cost
4805
+ * more, so bots that prefer different ones spread over the map.
4806
+ */
4807
+ var path = (nav, w, a, b, prefer = -1) => {
4808
+ const { nodes, out, runUp } = nav;
4809
+ if (!nodes.length || walkable(w, a, b)) return { edges: [] };
4810
+ const n = nodes.length;
4811
+ const cost = new Array(n).fill(Infinity);
4812
+ const prev = new Array(n);
4813
+ const back = new Array(n).fill(-1);
4814
+ const done = new Array(n).fill(false);
4815
+ for (let i = 0; i < n; i++) if (!runUp.has(i) && flat$1(a, nodes[i]) <= WALK && walkable(w, a, nodes[i])) cost[i] = flat$1(a, nodes[i]) / PACE;
4816
+ for (const clear of [true, false]) {
4817
+ if (cost.some((c) => c < Infinity)) break;
4818
+ let near = -1;
4819
+ for (let i = 0; i < n; i++) {
4820
+ const [d, dy] = [flat$1(a, nodes[i]), nodes[i][1] - a[1]];
4821
+ const [ux, uz] = [(nodes[i][0] - a[0]) / (d || 1), (nodes[i][2] - a[2]) / (d || 1)];
4822
+ if (!runUp.has(i) && d < NEAR && dy <= ABOVE && dy >= -8 && (!clear || ray(w, [
4823
+ a[0],
4824
+ a[1] + 1.5,
4825
+ a[2]
4826
+ ], [
4827
+ ux,
4828
+ 0,
4829
+ uz
4830
+ ], d) >= d) && (near < 0 || d < flat$1(a, nodes[near]))) near = i;
4831
+ }
4832
+ if (near >= 0) cost[near] = flat$1(a, nodes[near]) / PACE;
4833
+ }
4834
+ for (;;) {
4835
+ let i = -1;
4836
+ for (let k = 0; k < n; k++) if (!done[k] && cost[k] < Infinity && (i < 0 || cost[k] < cost[i])) i = k;
4837
+ if (i < 0) break;
4838
+ done[i] = true;
4839
+ for (const e of out[i]) {
4840
+ const c = cost[i] + e.cost * (e.route >= 0 && prefer >= 0 && e.route !== prefer ? OTHER : 1);
4841
+ if (c < cost[e.to]) {
4842
+ cost[e.to] = c;
4843
+ prev[e.to] = e;
4844
+ back[e.to] = i;
4845
+ }
4846
+ }
4847
+ }
4848
+ let best = -1;
4849
+ let total = Infinity;
4850
+ for (let i = 0; i < n; i++) {
4851
+ const c = cost[i] + flat$1(nodes[i], b) / PACE;
4852
+ if (cost[i] < Infinity && c < total && flat$1(nodes[i], b) <= WALK && walkable(w, nodes[i], b)) [best, total] = [i, c];
4853
+ }
4854
+ const edges = [];
4855
+ let i = best;
4856
+ for (; i >= 0 && prev[i]; i = back[i]) edges.unshift(prev[i]);
4857
+ return i < 0 ? { edges: [] } : {
4858
+ entry: nodes[i],
4859
+ edges
4860
+ };
4861
+ };
4862
+ // src/shared/bot.ts
4863
+ var { FORWARD, BACK, LEFT, RIGHT, JUMP, SPRINT, DASH, CROUCH, FIRE, RELOAD } = KEY;
4864
+ /** How far a bot shoots, metres, and how far it sees an enemy to fight. */
4865
+ var RANGE = 35;
4866
+ /** Ticks an enemy must be in sight before the first shot: the reaction time. */
4867
+ var REACT = 15;
4868
+ /** The most a bot turns its aim in a tick, radians (6 rad/s). */
4869
+ var TURN$1 = .1;
4870
+ /** Radians off the target a bot still shoots, and the error its aim starts with on a new target. */
4871
+ var CONE = .06;
4872
+ var MISS = .12;
4873
+ /** Ticks without a metre of progress before a jump, and before a new way. */
4874
+ var STUCK_JUMP = 45;
4875
+ var STUCK_PLAN = 180;
4876
+ /** Ticks a straight run to a goal is kept before a way is looked for again, and metres the goal may move before a new way. */
4877
+ var REPLAN = 120;
4878
+ var DRIFT = 4;
4879
+ /** Metres from the enemy carrier a bot dashes into him: the tackle. */
4880
+ var TACKLE = 4;
4881
+ /** Metres a bot without a gun goes out of its way to the rack. */
4882
+ var ARM = 30;
4883
+ /** Metres ahead a walking bot looks for the floor, and the share of the drop that hurts it will walk into. */
4884
+ var AHEAD = 1.5;
4885
+ var SAFE = .8;
4886
+ /** Ticks a bot strafes one way while it fights, and metres of floor it wants on that side. */
4887
+ var DODGE = 40;
4888
+ var SIDE = 1.5;
4889
+ /** The bots whose id is GUARD - 1 modulo GUARD stay home. */
4890
+ var GUARD = 8;
4891
+ var flat = (ax, az, bx, bz) => Math.sqrt((bx - ax) ** 2 + (bz - az) ** 2);
4892
+ /** Yaw that faces from (x0, z0) toward (x1, z1): yaw 0 looks toward -z. */
4893
+ var toward$1 = (x0, z0, x1, z1) => norm(Math.atan2(-(x1 - x0), -(z1 - z0)));
4894
+ /** The signed turn from a to b, in (-π, π]. */
4895
+ var turn = (a, b) => {
4896
+ const d = norm(b - a);
4897
+ return d > Math.PI ? d - 2 * Math.PI : d;
4898
+ };
4899
+ /** Where a player stands. */
4900
+ var at$1 = (p) => [
4901
+ p.x,
4902
+ p.y,
4903
+ p.z
4904
+ ];
4905
+ /** The keys that move toward the yaw `dir` while looking along `yaw`: one of eight. */
4906
+ var keysFor = (yaw, dir) => {
4907
+ const k = Math.round(norm(dir - yaw) / (Math.PI / 4)) % 8;
4908
+ return [
4909
+ FORWARD,
4910
+ FORWARD | LEFT,
4911
+ LEFT,
4912
+ BACK | LEFT,
4913
+ BACK,
4914
+ BACK | RIGHT,
4915
+ RIGHT,
4916
+ FORWARD | RIGHT
4917
+ ][k];
4918
+ };
4919
+ var Bot = class {
4920
+ id;
4921
+ /** The route it prefers, an index of nav.ts's ROUTES. */
4922
+ prefer;
4923
+ nav;
4924
+ way = { edges: [] };
4925
+ /** The goal of the way, and the tick it was planned. */
4926
+ goal;
4927
+ planned = 0;
4928
+ /** -1 walking to the way's entry, then the edge it is on; edges.length walking to the goal. */
4929
+ leg = 0;
4930
+ flight;
4931
+ /** The best distance to the point it walks to, and the tick it was last bettered. */
4932
+ best = Infinity;
4933
+ better = 0;
4934
+ ticks = 0;
4935
+ /** Where it aims, the enemy it aims at and since when. */
4936
+ aim = 0;
4937
+ pitch = 0;
4938
+ foe = -1;
4939
+ since = 0;
4940
+ last = [
4941
+ 0,
4942
+ 0,
4943
+ 0
4944
+ ];
4945
+ world;
4946
+ constructor(id) {
4947
+ this.id = id;
4948
+ this.prefer = id % ROUTES.length;
4949
+ }
4950
+ /** The input of this tick. */
4951
+ think(s) {
4952
+ const t = ++this.ticks;
4953
+ const p = s.me.state;
4954
+ this.world = s.world;
4955
+ if (p.down) {
4956
+ this.goal = void 0;
4957
+ this.foe = -1;
4958
+ return {
4959
+ keys: 0,
4960
+ yaw: this.aim,
4961
+ pitch: 0
4962
+ };
4963
+ }
4964
+ if (p.ev & EV.RESPAWN || flat(p.x, p.z, this.last[0], this.last[2]) > 5) this.goal = void 0;
4965
+ this.last = at$1(p);
4966
+ const goal = this.goalOf(s);
4967
+ if (!this.goal && !p.ground) return {
4968
+ keys: FORWARD,
4969
+ yaw: p.yaw,
4970
+ pitch: 0
4971
+ };
4972
+ if (p.ground && (!this.goal || flat(goal[0], goal[2], this.goal[0], this.goal[2]) > DRIFT || !this.way.edges.length && t - this.planned > REPLAN)) this.plan(s.world, p, goal);
4973
+ const move = this.pilot(p);
4974
+ const fight = this.fight(s, move.free);
4975
+ const reload = p.ammo > 0 && !p.mag && !p.reload && t & 1 ? RELOAD : 0;
4976
+ if (!fight) {
4977
+ this.aim = move.yaw;
4978
+ this.pitch = 0;
4979
+ return {
4980
+ keys: move.keys | reload,
4981
+ yaw: move.yaw,
4982
+ pitch: 0
4983
+ };
4984
+ }
4985
+ if (fight.keys & DASH) return {
4986
+ keys: fight.keys,
4987
+ yaw: this.aim,
4988
+ pitch: 0
4989
+ };
4990
+ const keys = move.keys & ~(FORWARD | BACK | LEFT | RIGHT | SPRINT);
4991
+ return {
4992
+ keys: (move.keys & FORWARD ? keysFor(this.aim, move.yaw) : 0) & ~(LEFT | RIGHT) | this.dodge(s.world, p) | keys | fight.keys | reload,
4993
+ yaw: this.aim,
4994
+ pitch: this.pitch
4995
+ };
4996
+ }
4997
+ /** A side step while it fights, one way then the other, never toward a drop. */
4998
+ dodge(w, p) {
4999
+ const left = ((this.ticks + this.id * 17) / DODGE | 0) & 1;
5000
+ for (const k of [left, 1 - left]) {
5001
+ const [x, z] = forward(this.aim + (k ? 1 : -1) * (Math.PI / 2));
5002
+ if (floorAt(w, p.x + x * SIDE, p.z + z * SIDE, p.y + .5) > p.y - .5) return k ? LEFT : RIGHT;
5003
+ }
5004
+ return 0;
5005
+ }
5006
+ /** Where it wants to be. */
5007
+ goalOf(s) {
5008
+ const { me, others, flags, world } = s;
5009
+ const p = me.state;
5010
+ const { team } = me;
5011
+ const home = world.def.teams[team];
5012
+ const [mine, theirs] = [flags[team], flags[1 - team]];
5013
+ const holder = (f) => others.find((o) => o.id === f.by)?.state;
5014
+ if (theirs.state === FLAG$1.CARRIED && theirs.by === me.id) return home.base;
5015
+ if (p.ammo < 0 && home.rack && flat(p.x, p.z, home.rack[0], home.rack[2]) < ARM) return home.rack;
5016
+ if (mine.state === FLAG$1.CARRIED) {
5017
+ const h = holder(mine);
5018
+ if (h) return at$1(h);
5019
+ }
5020
+ if (mine.state === FLAG$1.DROPPED) return [
5021
+ mine.x,
5022
+ mine.y,
5023
+ mine.z
5024
+ ];
5025
+ if (this.id % GUARD === 7) return home.base;
5026
+ if (theirs.state === FLAG$1.CARRIED) {
5027
+ const h = holder(theirs);
5028
+ if (h) return at$1(h);
5029
+ }
5030
+ if (theirs.state === FLAG$1.DROPPED) return [
5031
+ theirs.x,
5032
+ theirs.y,
5033
+ theirs.z
5034
+ ];
5035
+ return world.def.teams[1 - team].base;
5036
+ }
5037
+ plan(w, p, goal) {
5038
+ this.goal = goal;
5039
+ this.planned = this.ticks;
5040
+ this.nav = navOf(w);
5041
+ this.way = path(this.nav, w, at$1(p), goal, this.prefer);
5042
+ this.leg = this.way.entry ? -1 : 0;
5043
+ this.flight = void 0;
5044
+ this.best = Infinity;
5045
+ this.better = this.ticks;
5046
+ }
5047
+ /** The point it walks straight to now: the entry, a walk's end, or the goal past the last edge. */
5048
+ target() {
5049
+ const { edges, entry } = this.way;
5050
+ if (this.leg < 0) return entry;
5051
+ const e = edges[this.leg];
5052
+ return e ? this.nav.nodes[e.to] : this.goal;
5053
+ }
5054
+ /** The keys and yaw of the move, and whether the bot may look away from it to shoot. */
5055
+ pilot(p) {
5056
+ const e = this.leg >= 0 ? this.way.edges[this.leg] : void 0;
5057
+ if (e?.leg) return this.fly(p, e.leg);
5058
+ const [x, , z] = this.target();
5059
+ const d = flat(p.x, p.z, x, z);
5060
+ const near = d < 2 && this.ticks - this.better > STUCK_JUMP;
5061
+ if (d < (e || this.leg < 0 ? .5 : 1) || near && this.leg < this.way.edges.length) {
5062
+ if (this.leg < this.way.edges.length) {
5063
+ this.next();
5064
+ return this.pilot(p);
5065
+ }
5066
+ return {
5067
+ keys: 0,
5068
+ yaw: this.aim,
5069
+ free: true
5070
+ };
5071
+ }
5072
+ const yaw = toward$1(p.x, p.z, x, z);
5073
+ const [fx, fz] = forward(yaw);
5074
+ const w = this.world;
5075
+ const hurts = SAFE * 400 / (2 * gravity(w));
5076
+ if (p.ground && floorAt(w, p.x + fx * AHEAD, p.z + fz * AHEAD, p.y + .5) < p.y - hurts) {
5077
+ this.unstick(p, d, 0);
5078
+ return {
5079
+ keys: 0,
5080
+ yaw,
5081
+ free: true
5082
+ };
5083
+ }
5084
+ return {
5085
+ keys: this.unstick(p, d, FORWARD | SPRINT),
5086
+ yaw,
5087
+ free: true
5088
+ };
5089
+ }
5090
+ next() {
5091
+ this.leg++;
5092
+ this.flight = void 0;
5093
+ this.best = Infinity;
5094
+ this.better = this.ticks;
5095
+ }
5096
+ /** `keys`, with a jump when it has not got closer for a while; a new way when that does not help. */
5097
+ unstick(p, d, keys) {
5098
+ if (d < this.best - 1) [this.best, this.better] = [d, this.ticks];
5099
+ const idle = this.ticks - this.better;
5100
+ if (idle > STUCK_PLAN) {
5101
+ this.goal = void 0;
5102
+ return keys;
5103
+ }
5104
+ return idle > STUCK_JUMP && p.mode !== MODE.HANG && idle % 30 === 0 ? keys | JUMP : keys;
5105
+ }
5106
+ /** One step of a leg of a route, the way test/routes.ts flies it. */
5107
+ fly(p, leg) {
5108
+ const f = this.flight ??= {
5109
+ leg,
5110
+ k: -1,
5111
+ ran: false,
5112
+ ended: -1
5113
+ };
5114
+ const go = (x, z, r, keys) => {
5115
+ const d = flat(p.x, p.z, x, z);
5116
+ return d < r || d < 2 && this.ticks - this.better > STUCK_JUMP ? void 0 : {
5117
+ keys: this.unstick(p, d, keys),
5118
+ yaw: toward$1(p.x, p.z, x, z),
5119
+ free: false
5120
+ };
5121
+ };
5122
+ if (leg.k === "go") {
5123
+ const run = go(leg.to[0], leg.to[1], leg.sprint ? .4 : .15, FORWARD | (leg.sprint ? SPRINT : 0));
5124
+ if (run) return {
5125
+ ...run,
5126
+ free: !this.leapNext()
5127
+ };
5128
+ if (!p.ground) return {
5129
+ keys: 0,
5130
+ yaw: p.yaw,
5131
+ free: false
5132
+ };
5133
+ return this.landed(p, leg);
5134
+ }
5135
+ if (leg.k === "slide") {
5136
+ if (f.x0 === void 0) {
5137
+ const run = go(leg.from[0], leg.from[1], .4, FORWARD | SPRINT);
5138
+ if (run) return run;
5139
+ [f.x0, f.z0] = [p.x, p.z];
5140
+ }
5141
+ const d = flat(p.x, p.z, f.x0, f.z0);
5142
+ const run = go(leg.to[0], leg.to[1], .4, FORWARD | SPRINT | (d >= leg.c[0] && d <= leg.c[1] ? CROUCH : 0));
5143
+ if (run) return run;
5144
+ return p.ground ? this.landed(p, leg) : {
5145
+ keys: 0,
5146
+ yaw: p.yaw,
5147
+ free: false
5148
+ };
5149
+ }
5150
+ const keys = FORWARD | (leg.sprint ? SPRINT : 0);
5151
+ const yaw = toward$1(p.x, p.z, leg.to[0], leg.to[1]);
5152
+ if (f.k < 0) {
5153
+ const run = go(leg.at[0], leg.at[1], leg.land ? 1 : .2, keys);
5154
+ if (run) return run;
5155
+ f.k = 0;
5156
+ return {
5157
+ keys: keys | JUMP,
5158
+ yaw,
5159
+ free: false
5160
+ };
5161
+ }
5162
+ if (p.ground) return this.landed(p, leg);
5163
+ f.k++;
5164
+ if (p.mode === MODE.WALLRUN) f.ran = true;
5165
+ else if (f.ran && f.ended < 0) f.ended = f.k;
5166
+ if (leg.land) {
5167
+ const [tx, tz] = leg.to;
5168
+ const d = flat(p.x, p.z, tx, tz);
5169
+ const v = (p.vx * (tx - p.x) + p.vz * (tz - p.z)) / (d || 1);
5170
+ const g = gravity(this.world);
5171
+ const t = Math.max((p.vy + Math.sqrt(Math.max(p.vy ** 2 + 2 * g * (p.y - leg.y), 0))) / g, .05);
5172
+ return {
5173
+ keys: v * t < d - .3 ? FORWARD : v * t > d + .3 ? BACK : 0,
5174
+ yaw,
5175
+ free: false
5176
+ };
5177
+ }
5178
+ const n = leg.run ? f.ended < 0 ? -1 : f.k - f.ended : f.k;
5179
+ return {
5180
+ keys: (n === leg.dash ? keys | DASH : keys) | (n === leg.double ? JUMP : 0),
5181
+ yaw,
5182
+ free: false
5183
+ };
5184
+ }
5185
+ /** Whether the edge after this one is a jump that wants the run-up of this one. */
5186
+ leapNext() {
5187
+ const l = this.way.edges[this.leg + 1]?.leg;
5188
+ return l?.k === "leap" && l.sprint;
5189
+ }
5190
+ /** A leg is over: on to the next on its roof, else a new way from where the bot came down. */
5191
+ landed(p, leg) {
5192
+ if (Math.abs(p.y - leg.y) > .3) {
5193
+ this.goal = void 0;
5194
+ return {
5195
+ keys: 0,
5196
+ yaw: p.yaw,
5197
+ free: false
5198
+ };
5199
+ }
5200
+ this.next();
5201
+ return this.pilot(p);
5202
+ }
5203
+ /** The look and the trigger at the enemy to fight now, if any. */
5204
+ fight(s, free) {
5205
+ const { me, others, world, flags } = s;
5206
+ const p = me.state;
5207
+ if (!p.ground) {
5208
+ this.foe = -1;
5209
+ return;
5210
+ }
5211
+ const eye = [
5212
+ p.x,
5213
+ p.y + eyeHeight(p),
5214
+ p.z
5215
+ ];
5216
+ const carrier = flags[me.team].state === FLAG$1.CARRIED ? flags[me.team].by : -1;
5217
+ let foe;
5218
+ let best = Infinity;
5219
+ for (const o of others) {
5220
+ const q = o.state;
5221
+ if (o.team === me.team || q.down) continue;
5222
+ const d = flat(p.x, p.z, q.x, q.z);
5223
+ const score = o.id === carrier ? d - RANGE : d;
5224
+ if (d < RANGE && score < best && !hidden(world, eye, [
5225
+ q.x,
5226
+ q.y + 1.2,
5227
+ q.z
5228
+ ])) [foe, best] = [o, score];
5229
+ }
5230
+ const carrying = flags[1 - me.team].state === FLAG$1.CARRIED && flags[1 - me.team].by === me.id;
5231
+ if (!foe || !free || carrying) {
5232
+ this.foe = -1;
5233
+ return;
5234
+ }
5235
+ const q = foe.state;
5236
+ if (foe.id !== this.foe) {
5237
+ this.foe = foe.id;
5238
+ this.since = this.ticks;
5239
+ this.aim = norm(p.yaw + (this.id & 1 ? MISS : -.12));
5240
+ }
5241
+ const d = flat(p.x, p.z, q.x, q.z);
5242
+ const lead = d / 40;
5243
+ const [tx, ty, tz] = [
5244
+ q.x + q.vx * lead,
5245
+ q.y + 1.1 + q.vy * lead,
5246
+ q.z + q.vz * lead
5247
+ ];
5248
+ const want = toward$1(p.x, p.z, tx, tz);
5249
+ this.aim = norm(this.aim + Math.max(-.1, Math.min(TURN$1, turn(this.aim, want))));
5250
+ this.pitch = Math.atan2(ty - eye[1], Math.max(d, .1));
5251
+ const ready = this.ticks - this.since > REACT && Math.abs(turn(this.aim, want)) < CONE;
5252
+ if (foe.id === carrier && d < TACKLE && p.ground && !(p.held & DASH)) return { keys: FORWARD | DASH };
5253
+ const armed = p.ammo > 0 && (p.mag ?? 0) > 0 && !p.wield;
5254
+ return { keys: ready && (armed && d < RANGE || !armed && d < 1.4) && this.ticks & 1 ? FIRE : 0 };
5255
+ }
5256
+ };
5257
+ // src/shared/ctf.ts
5258
+ var home = () => ({
5259
+ state: FLAG$1.HOME,
5260
+ by: 0,
5261
+ x: 0,
5262
+ y: 0,
5263
+ z: 0,
5264
+ left: 0
5265
+ });
5266
+ /** How far under a carrier a flag that he drops in the air is looked for a floor, metres. */
5267
+ var FALL = 60;
5268
+ var Ctf = class {
5269
+ /** Captures per team, red then blue. */
5270
+ score = [0, 0];
5271
+ /** The match is over and the end screen shows. */
5272
+ over = false;
5273
+ /** The flag of each team, red then blue. */
5274
+ flags = [home(), home()];
5275
+ world;
5276
+ rules;
5277
+ mates = /* @__PURE__ */ new Map();
5278
+ /** Ticks to the end of the match, or to the next one while it is over. */
5279
+ clock;
5280
+ /** Ticks before each dropped flag goes home. */
5281
+ back = [0, 0];
5282
+ /** Who may not take each flag, and for how many more ticks: the carrier that was made to drop it. */
5283
+ lock = [{
5284
+ id: -1,
5285
+ left: 0
5286
+ }, {
5287
+ id: -1,
5288
+ left: 0
5289
+ }];
5290
+ /** Ticks before a tackled flag can be sent home: it lies there, and the carrier's mates may take it. */
5291
+ hold = [0, 0];
5292
+ constructor(world, rules) {
5293
+ this.world = world;
5294
+ this.rules = rules;
5295
+ this.clock = rules.timeLimit * 60;
5296
+ }
5297
+ /** A player joined, standing at `at`. */
5298
+ join(id, team, at) {
5299
+ this.mates.set(id, {
5300
+ team,
5301
+ caps: 0,
5302
+ returns: 0,
5303
+ ground: [
5304
+ at.x,
5305
+ at.y,
5306
+ at.z
5307
+ ]
5308
+ });
5309
+ }
5310
+ /** A player left: a flag he carried is dropped where he last stood. */
5311
+ leave(id) {
5312
+ const k = this.carrying(id);
5313
+ const m = this.mates.get(id);
5314
+ if (k >= 0 && m) this.dropAt(k, m.ground);
5315
+ this.mates.delete(id);
5316
+ }
5317
+ /** A player was put at `at` (a new match): his last ground is there. */
5318
+ place(id, at) {
5319
+ const m = this.mates.get(id);
5320
+ if (m) m.ground = [
5321
+ at.x,
5322
+ at.y,
5323
+ at.z
5324
+ ];
5325
+ }
5326
+ /**
5327
+ * The player's state after one move. Under the kill floor and put back at a spawn (EV.RESPAWN),
5328
+ * a carrier drops the flag where he last stood; then a floor under him is his last ground.
5329
+ */
5330
+ moved(p) {
5331
+ const m = this.mates.get(p.id);
5332
+ if (!m) return;
5333
+ const k = this.carrying(p.id);
5334
+ if (p.ev & EV.RESPAWN && k >= 0) this.dropAt(k, m.ground);
5335
+ if (p.ground) m.ground = [
5336
+ p.x,
5337
+ p.y,
5338
+ p.z
5339
+ ];
5340
+ }
5341
+ /**
5342
+ * Makes the player drop the flag he carries (the tackle of step 7). It lies under him: where he
5343
+ * stands, or on the first floor below him, or at his last ground when there is none (over the
5344
+ * void). False when he carried nothing.
5345
+ */
5346
+ drop(p) {
5347
+ const k = this.carrying(p.id);
5348
+ const m = this.mates.get(p.id);
5349
+ if (k < 0 || !m || this.over) return false;
5350
+ let at = m.ground;
5351
+ if (p.ground) at = [
5352
+ p.x,
5353
+ p.y,
5354
+ p.z
5355
+ ];
5356
+ else {
5357
+ const d = ray(this.world, [
5358
+ p.x,
5359
+ p.y + .05,
5360
+ p.z
5361
+ ], [
5362
+ 0,
5363
+ -1,
5364
+ 0
5365
+ ], FALL);
5366
+ if (d < FALL) at = [
5367
+ p.x,
5368
+ p.y + .05 - d,
5369
+ p.z
5370
+ ];
5371
+ }
5372
+ this.dropAt(k, at);
5373
+ this.lock[k] = {
5374
+ id: p.id,
5375
+ left: 120
5376
+ };
5377
+ this.hold[k] = 120;
5378
+ return true;
5379
+ }
5380
+ /** The team whose flag the player carries, or -1. */
5381
+ carrying(id) {
5382
+ return this.flags.findIndex((f) => f.state === FLAG$1.CARRIED && f.by === id);
5383
+ }
5384
+ /** The winning team of a match that is over, or -1 for a draw. */
5385
+ winner() {
5386
+ const [r, b] = this.score;
5387
+ return r > b ? 0 : b > r ? 1 : -1;
5388
+ }
5389
+ /** What every player has done this match. */
5390
+ tally() {
5391
+ return [...this.mates].map(([id, m]) => ({
5392
+ id,
5393
+ caps: m.caps,
5394
+ returns: m.returns
5395
+ }));
5396
+ }
5397
+ /** The room is empty: the next match starts from scratch. */
5398
+ reset() {
5399
+ this.over = false;
5400
+ this.score = [0, 0];
5401
+ this.flags = [home(), home()];
5402
+ this.back = [0, 0];
5403
+ this.lock.forEach((l) => l.left = 0);
5404
+ this.hold = [0, 0];
5405
+ this.clock = this.rules.timeLimit * 60;
5406
+ for (const m of this.mates.values()) m.caps = m.returns = 0;
5407
+ }
5408
+ /** The part of a snapshot that is the match's. */
5409
+ wire() {
5410
+ return {
5411
+ score: [...this.score],
5412
+ clock: Math.ceil(this.clock / 60),
5413
+ over: this.over,
5414
+ flags: this.flags.map((f) => ({ ...f }))
5415
+ };
5416
+ }
5417
+ /**
5418
+ * One host tick over the players: the dropped flags run down, flags are taken, returned and
5419
+ * captured, the clock runs. 'end' when the match has just ended, 'start' when the end screen is
5420
+ * done and a new match begins (the room puts everyone back at a spawn).
5421
+ */
5422
+ tick(players) {
5423
+ if (this.over) {
5424
+ if (--this.clock <= 0) {
5425
+ this.reset();
5426
+ return "start";
5427
+ }
5428
+ return;
5429
+ }
5430
+ for (const k of [0, 1]) {
5431
+ const f = this.flags[k];
5432
+ this.lock[k].left--;
5433
+ this.hold[k]--;
5434
+ if (f.state === FLAG$1.DROPPED) {
5435
+ f.left = Math.ceil(--this.back[k] / 60);
5436
+ if (this.back[k] <= 0) this.flags[k] = home();
5437
+ }
5438
+ }
5439
+ for (const k of [0, 1]) {
5440
+ const f = this.flags[k];
5441
+ if (f.state === FLAG$1.CARRIED) continue;
5442
+ const at = f.state === FLAG$1.HOME ? this.world.def.teams[k].base : [
5443
+ f.x,
5444
+ f.y,
5445
+ f.z
5446
+ ];
5447
+ const near = players.filter((q) => touches(q.state, at));
5448
+ const mate = f.state === FLAG$1.DROPPED && this.hold[k] <= 0 ? near.find((q) => q.team === k) : void 0;
5449
+ const foe = near.find((q) => q.team !== k && (q.id !== this.lock[k].id || this.lock[k].left <= 0));
5450
+ if (mate) {
5451
+ const m = this.mates.get(mate.id);
5452
+ if (m) m.returns++;
5453
+ this.flags[k] = home();
5454
+ } else if (foe) this.flags[k] = {
5455
+ ...home(),
5456
+ state: FLAG$1.CARRIED,
5457
+ by: foe.id
5458
+ };
5459
+ }
5460
+ for (const p of players) {
5461
+ const k = this.carrying(p.id);
5462
+ if (k >= 0 && this.flags[p.team].state === FLAG$1.HOME && touches(p.state, this.world.def.teams[p.team].base)) {
5463
+ this.score[p.team]++;
5464
+ const m = this.mates.get(p.id);
5465
+ if (m) m.caps++;
5466
+ this.flags[k] = home();
5467
+ }
5468
+ }
5469
+ if (this.score.some((s) => s >= this.rules.scoreLimit) || --this.clock <= 0) {
5470
+ this.over = true;
5471
+ this.clock = 600;
5472
+ return "end";
5473
+ }
5474
+ }
5475
+ dropAt(k, [x, y, z]) {
5476
+ this.flags[k] = {
5477
+ state: FLAG$1.DROPPED,
5478
+ by: 0,
5479
+ x,
5480
+ y,
5481
+ z,
5482
+ left: 10
5483
+ };
5484
+ this.back[k] = 600;
3901
5485
  }
3902
- return [h, m];
3903
5486
  };
3904
- /**
3905
- * How much of a mound's height there is at x, across it: all of it for 4 m each side of its
3906
- * middle cx, none 8 m further, and none over the spurs that close the rille's east end. Straight
3907
- * between the lattice's lines, so the ground between two nodes is what at() says.
3908
- */
3909
- var across = (cx, x) => {
3910
- const f = (u) => c1((12 - Math.abs(u - cx)) / 8) * c1((152 - u) / 4);
3911
- const x0 = 4 * Math.floor(x / 4);
3912
- return f(x0) + (f(x0 + 4) - f(x0)) * (x - x0) / 4;
5487
+ /** Whether the player's body reaches the flag foot at `at`: close enough, and overlapping its height. */
5488
+ var touches = (p, at) => Math.hypot(p.x - at[0], p.z - at[2]) < 1.5 && p.y < at[1] + 2.2 && p.y + 1.8 > at[1];
5489
+ // src/shared/doors.ts
5490
+ var DOOR = {
5491
+ /**
5492
+ * Metres from the doorway within which a player on foot opens it, and a driven rover. A dash
5493
+ * from 7 m is there in 0.65 s (2.7 m of burst at 16 m/s, the rest at a sprint's 9), a rover at
5494
+ * its 23.2 m/s from 14 m in 0.6 s: the door has been open 0.3 s and 0.25 s by then.
5495
+ */
5496
+ R: 7,
5497
+ ROVER_R: 14,
5498
+ /** Ticks it takes to open (0.35 s) and to shut (0.5 s). */
5499
+ OPEN: 21,
5500
+ SHUT: 30,
5501
+ /** Ticks it stays open after the last one has left: a second. */
5502
+ HOLD: 60
3913
5503
  };
5504
+ /** How far `p` is from the doorway on the floor plane, Infinity when its feet are not at its height. */
5505
+ var off = ({ min, max }, [x, y, z]) => y < min[1] - 1 || y >= max[1] ? Infinity : Math.sqrt((x - Math.min(Math.max(x, min[0]), max[0])) ** 2 + (z - Math.min(Math.max(z, min[2]), max[2])) ** 2);
3914
5506
  /**
3915
- * Where the small relief stays out, besides FLATS: the strips whose jumps are measured, x0, z0, x1,
3916
- * z1 with z from the centre line. The west long jump's take-off and landing, the bridge's ends,
3917
- * the east stones' approaches, and the two mounds a rover flies the rille from with their flanks
3918
- * (their run-ups are in FLATS). All to 16 m from the centre line, where the field's mounds begin
3919
- * at the nearest: what was level there stays level.
5507
+ * One tick of the doors of `w`: each opens while one of `feet` (the players who are up) is within
5508
+ * DOOR.R of it or one of `rovers` (the driven ones) within DOOR.ROVER_R, stays open DOOR.HOLD ticks
5509
+ * after the last, then shuts.
3920
5510
  */
3921
- var STRIPS = [
3922
- [
3923
- 8,
3924
- 0,
3925
- 28,
3926
- 16
3927
- ],
3928
- [
3929
- 70,
3930
- 0,
3931
- 90,
3932
- 16
3933
- ],
3934
- [
3935
- 122,
3936
- 0,
3937
- 139,
3938
- 16
3939
- ],
3940
- [
3941
- 36,
3942
- 0,
3943
- 60,
3944
- 16
3945
- ],
3946
- [
3947
- 132,
3948
- 0,
3949
- 156,
3950
- 16
3951
- ]
3952
- ];
5511
+ var swing = (w, feet, rovers = []) => w.doors?.forEach((s, i) => {
5512
+ const d = w.def.doors[i];
5513
+ const near = feet.some((p) => off(d, p) < DOOR.R) || rovers.some((p) => off(d, p) < DOOR.ROVER_R);
5514
+ const all = DOOR.OPEN * DOOR.SHUT;
5515
+ const at = Math.round(s.open * all) + (near || s.wait ? DOOR.SHUT : -DOOR.OPEN);
5516
+ s.open = Math.min(all, Math.max(0, at)) / all;
5517
+ s.wait = near ? DOOR.HOLD : Math.max(0, s.wait - 1);
5518
+ });
5519
+ /** Every door shut: a new match. */
5520
+ var shut = (w) => w.doors?.forEach((s) => {
5521
+ s.open = s.wait = 0;
5522
+ });
5523
+ // src/shared/gun.ts
5524
+ /** Whether the feet of `p` are within `r` of the point `at` on the floor plane and within PICK_H of its height. */
5525
+ var within = (p, at, r) => {
5526
+ const [dx, dz] = [p.x - at[0], p.z - at[2]];
5527
+ return dx * dx + dz * dz < r * r && Math.abs(p.y - at[1]) < 1;
5528
+ };
3953
5529
  /**
3954
- * The small relief, laid over everything: the moon is rugged, no ground is dead flat for long.
3955
- * `out` is how far out of the arena (under 0: in it). The lattice is 4 m: it carries hummocks and
3956
- * pans from 8 m across, no less (what is finer is drawn only), and a patch is exactly level only
3957
- * if every node within 5.7 m of it is, so a level patch costs 6 m of margin whatever its size. In
3958
- * the arena, over the slabs, only hummocks (up to 0.45 m, nothing under the floor), gentle;
3959
- * outside, hummocks, shallow pans and a slow swell, -0.45 to 0.55 m, on every 10 m or so. It is
3960
- * exactly 0 on the arena's edge (the slabs end there), on the lips, on
3961
- * STRIPS, on FLATS (a base, a rover's place; 1.8 m round a pack or a spawn), and stays off
3962
- * the jump ramps outside with their run-ups and landings, the craters and the dishes' hill.
5530
+ * The start of a cut that moves the body, from a floor only: the lunge throws him along the look at
5531
+ * LUNGE_SPEED for the burst of a dash, and spends the dash; the leap jumps him LEAP_SPEED up.
3963
5532
  */
3964
- var rough = (x, z, out) => {
3965
- const gap = (l, by, over) => l.reduce((m, [x0, z0, x1, z1]) => m * sm((far(Math.max(x0 - x, x - x1, 0), Math.max(z0 - z, z - z1, 0)) - by) / over), 1);
3966
- if (out < 0) {
3967
- const i = Math.min(Math.max(Math.floor(x), 6), LIP.length - 7);
3968
- const lip = Math.max(...LIP.slice(i - 6, i + 7), 0);
3969
- return (.6 * Math.max(noise(x / 5, z / 5, 61) - .42, 0) + .25 * Math.max(noise(x / 9, z / 9, 67) - .5, 0)) * sm(-out / 4) * sm((z - 14 - lip) / 3) * gap(FLATS.filter((f) => f[0] === f[2]), 7.5, 2) * gap(FLATS.filter((f) => f[0] < f[2]), 5.7, 2) * gap(STRIPS, 5.7, 2);
3970
- }
3971
- let m = sm(out / 4) * (Math.abs(x - 80) < 96 ? sm((z - 10) / 6) : 1);
3972
- for (const [rx, rz, ax, az] of RAMPS) {
3973
- const [p, q] = [x - rx, z - rz];
3974
- const a = p * ax + q * az;
3975
- m *= sm((far(Math.max(-22 - a, a - 38, 0), Math.max(Math.abs(p * az - q * ax) - 10, 0)) - 2) / 4);
5533
+ var launch$1 = (p) => {
5534
+ if (p.mode !== MODE.GROUND) return;
5535
+ if (p.cut === CUT.LUNGE) {
5536
+ const [fx, fz] = forward(p.yaw);
5537
+ p.vx = fx * 13;
5538
+ p.vz = fz * 13;
5539
+ p.dash = 60;
5540
+ p.ev |= EV.DASH;
5541
+ } else if (p.cut === CUT.LEAP) {
5542
+ p.vy = LEAP_SPEED;
5543
+ p.ev |= EV.JUMP;
3976
5544
  }
3977
- for (const [cx, cz, r] of BOWLS) m *= sm((far(x - cx, z - cz) / r - 1.3) / .25);
3978
- m *= sm((far(x - HILL[0], z - HILL[1]) - 40) / 20);
3979
- return (.75 * Math.max(noise(x / 5, z / 5, 61) - .42, 0) - .8 * Math.max(noise(x / 7, z / 7, 63) - .6, 0) + .25 * (noise(x / 11, z / 11, 65) - .5)) * m;
5545
+ };
5546
+ /** What a step struck, for the host to resolve: nothing, a shot (a plasma ball), the katana's cut, a rail gun's beam, a laser rifle's shot, or a grenade from its launcher. */
5547
+ var STRIKE = {
5548
+ NONE: 0,
5549
+ SHOT: 1,
5550
+ CUT: 2,
5551
+ RAIL: 3,
5552
+ LASER: 4,
5553
+ NADE: 5
3980
5554
  };
3981
5555
  /**
3982
- * The height of the crater floor round the arena. Only + - * /, Math.sqrt, Math.abs, min, max, floor
3983
- * and the integer hash: every engine builds the same lattice. In the arena, the field (see FLATS)
3984
- * and the mounds; exactly 0 for 12 m round it (a rectangle on lattice lines, so between the nodes
3985
- * too); then rolling hills, the pieces above, then the crater wall: it starts 0.78 of the way to the bound,
3986
- * is 20 m high on it and, past it where nobody goes, rounds off under a crest of 28 to 48 m that
3987
- * rolls slowly and falls to the plain at 1.65 of the bound. Lower than the ranges drawn far behind it.
5556
+ * One input: the move, then the weapons. Returns what struck on this step (STRIKE), for the host to
5557
+ * resolve it: a shot, or a cut, which is not a shot.
5558
+ * - Down: the keys are dropped, and when `down` runs out the player is back at a spawn.
5559
+ * - The team's rack fills the gun when the player steps into its circle (`rack` tells he is in it),
5560
+ * and again each time he comes back; staying gives nothing. The katana rack gives the katana,
5561
+ * once and for good: it stays until he goes down.
5562
+ * - The rail rack fills the rail gun with RAIL_MAX ticks of lightning on arrival, as the gun's does.
5563
+ * - In hand is the weapon he wants (KEY.BLADE the katana, KEY.RAIL the rail gun, neither the gun)
5564
+ * when he has it, else the first he has of the gun, the katana and the rail gun; the katana
5565
+ * stays in hand for the length of a swing. `wield` is the katana in hand, `railed` the rail gun.
5566
+ * - The gun fires from its battery (`mag`), the rail gun from its capsule (`cap`). An empty one, or
5567
+ * KEY.RELOAD with room in it, swaps it for a full one from what he carries: `reload` ticks
5568
+ * without firing, then it holds the kit's `mag` (`cap`, `clip`) or what is left. A switch of weapon drops it.
5569
+ * The racks fill both.
5570
+ * - The rail gun throws its bolt on every step FIRE is held, spending a tick of it (`zapping`),
5571
+ * unless it is `hot`: its `heat` rises while it fires and falls when it does not (HEAT_MAX).
5572
+ * - The laser rifle (KEY.RIFLE, `rifled`), filled at its rack on arrival, fires a round from its
5573
+ * cell (`clip`) each RIFLE_COOL ticks while FIRE is held (STRIKE.LASER). Its rack loads NADE_MAX
5574
+ * grenades too: SPECIAL (G) launches one (STRIKE.NADE) when `lob` is 0, even during
5575
+ * a swap of the cell, then `lob` runs NADE_COOL ticks and the rifle holds its fire NADE_HOLD.
5576
+ * - The trigger: `cool` and `swing` run down, and at 0 a held FIRE charges the gun, with ammo, and
5577
+ * letting it go fires a ball as strong as the charge (powerOf()), spending as many shots; or it
5578
+ * starts the katana's swing (`cut` from the keys), unless the hands are busy (a hang, a climb).
5579
+ * The katana in hand, busy hands or no shot left drop the charge.
5580
+ * With SPECIAL (a double click) the swing is the cut's special; its press within SPECIAL_LATE
5581
+ * ticks of a cut's start turns that cut into it. The cut strikes `CUTS[cut].strike` ticks into
5582
+ * its swing. The look is the input's, so both go where the player sees.
5583
+ * `armed` is false while the match is over: no weapon, no rack. `bodies` are move()'s.
3988
5584
  */
3989
- var at$1 = (x, z) => {
3990
- z = Math.abs(z - 140);
3991
- const k = far((x - 80) / 300, z / 360);
3992
- const t = Math.max((k - .78) / .22, 0);
3993
- const dug = bowls(x, z);
3994
- const out = Math.max(Math.abs(x - 80) - 80, z - 140);
3995
- let h = sm((out - 12) / 48) * (1 - .7 * sm(t)) * (16 * noise(x / 96, z / 96, 1) + 6 * noise(x / 52, z / 52, 4) + 5 * noise(x / 36, z / 36, 2) + 1.4 * noise(x / 22, z / 22, 3) - 14.2);
3996
- if (out < 0) {
3997
- let m = sm((z - 16 - 10 * noise(x / 19, .5, 37)) / 8) * sm(-out / 10);
3998
- for (const [x0, z0, x1, z1] of FLATS) m *= sm((far(Math.max(x0 - x, x - x1, 0), Math.max(z0 - z, z - z1, 0)) - (x0 < x1 ? 6 : 7.5)) / 6);
3999
- h = m * Math.min(Math.max(4.8 * noise(x / 15, z / 15, 21) - .9, 0) + Math.max(3 * noise(x / 31, z / 31, 23) - .6, 0), 2.6);
4000
- const s = sm((10 - far(x - HOLLOW[0], z - (HOLLOW[1] - 140))) / 8);
4001
- h = h * (1 - s) - HOLLOW[2] * s;
4002
- for (const cx of MOUNDS) h += MOUND * c1((8 + RISE - z) / RISE) * across(cx, x);
4003
- h = z < 8 ? 0 : h;
5585
+ var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
5586
+ const down = p.down > 0;
5587
+ const locked = !down && (p.lock ?? 0) > 0;
5588
+ move(p, down || locked ? {
5589
+ ...i,
5590
+ keys: 0
5591
+ } : i, w, team, bodies, kit);
5592
+ p.heat = Math.max(0, (p.heat ?? 0) - (p.zapping ? 0 : p.hot ? 1 : 2));
5593
+ p.hot = !!p.hot && p.heat > 0;
5594
+ p.zapping = false;
5595
+ p.zap = !!p.stun && !!p.zap;
5596
+ if (down) {
5597
+ if (p.down > 0 && !--p.down) respawn(p, w, team);
5598
+ return STRIKE.NONE;
5599
+ }
5600
+ if (locked) return duel(p, i);
5601
+ const { rack, blade, rail, rifle } = w.def.teams[team];
5602
+ const inside = !!rack && within(p, rack, 1.2);
5603
+ if (armed && inside && !p.rack) [p.ammo, p.mag] = [kit.ammo, kit.mag];
5604
+ p.rack = inside;
5605
+ p.blade = !!p.blade || armed && !!blade && within(p, blade, 1.2);
5606
+ const inRail = !!rail && within(p, rail, 1.2);
5607
+ if (armed && inRail && !p.inRail) [p.rail, p.cap] = [kit.rail, kit.cap];
5608
+ p.inRail = inRail;
5609
+ const inRifle = !!rifle && within(p, rifle, 1.2);
5610
+ if (armed && inRifle && !p.inRifle) [p.rifle, p.clip, p.nades] = [
5611
+ kit.rifle,
5612
+ kit.clip,
5613
+ 3
5614
+ ];
5615
+ p.inRifle = inRifle;
5616
+ p.ammo = Math.min(p.ammo, kit.ammo);
5617
+ p.rail = p.rail === void 0 ? p.rail : Math.min(p.rail, kit.rail);
5618
+ p.rifle = p.rifle === void 0 ? p.rifle : Math.min(p.rifle, kit.rifle);
5619
+ [p.mag, p.cap, p.clip] = [
5620
+ Math.min(p.mag ?? 0, kit.mag),
5621
+ Math.min(p.cap ?? 0, kit.cap),
5622
+ Math.min(p.clip ?? 0, kit.clip)
5623
+ ];
5624
+ p.cool = Math.max(0, p.cool - 1);
5625
+ p.lob = Math.max(0, (p.lob ?? 0) - 1);
5626
+ const busy = p.mode === MODE.HANG || p.mode === MODE.CLIMB;
5627
+ const { ticks, hold } = CUTS[p.cut ?? 0];
5628
+ const top = !!p.swing && !p.heavy && ticks - (p.swing ?? 0) === hold;
5629
+ if (top && p.wield && armed && !busy && i.keys & KEY.FIRE) p.charge = Math.min((p.charge ?? 0) + 1, HEAVY_MAX);
5630
+ else if (top && armed && !busy && (p.charge ?? 0) >= HEAVY_TAP) {
5631
+ [p.heavy, p.charge] = [true, 0];
5632
+ p.swing = swingOf(p).ticks;
5633
+ } else {
5634
+ p.charge = top ? 0 : p.charge;
5635
+ const s = p.swing ?? 0;
5636
+ const c = swingOf(p);
5637
+ const stop = (v) => v == s - 1 && (v == c.ticks - c.strike || v == PUNCH.ticks - PUNCH.strike || !p.heavy && v == ticks - hold);
5638
+ p.swing = Math.max(0, kit.haste > 1 && stop(s - 1) ? s - 1 : s - kit.haste);
5639
+ p.heavy = !!p.swing && !!p.heavy;
4004
5640
  }
4005
- h = (out < 0 ? h : h * (1 - dug[1])) + dug[0] + rough(x, z, out) * (1 - dug[1]) * (1 - sm(t));
4006
- for (const [rx, rz, ax, az] of RAMPS) {
4007
- const [p, q] = [x - rx, z - rz];
4008
- const a = p * ax + q * az;
4009
- h += 5.6 * c1(Math.min(a / 16, (32 - a) / 12)) * c1((18 - Math.abs(p * az - q * ax)) / 12);
5641
+ p.mag = Math.min(p.mag ?? 0, Math.max(p.ammo, 0));
5642
+ const has = [
5643
+ p.ammo >= 0,
5644
+ !!p.blade,
5645
+ (p.rail ?? -1) >= 0,
5646
+ (p.rifle ?? -1) >= 0
5647
+ ];
5648
+ const want = i.keys & KEY.BLADE ? 1 : i.keys & KEY.RAIL ? 2 : i.keys & KEY.RIFLE ? 3 : 0;
5649
+ const hand = p.swing && p.blade ? 1 : has[want] ? want : has.indexOf(true);
5650
+ if (hand != (p.rifled ? 3 : p.railed ? 2 : +!!p.wield)) p.reload = 0;
5651
+ [p.wield, p.railed, p.rifled] = [
5652
+ hand == 1,
5653
+ hand == 2,
5654
+ hand == 3
5655
+ ];
5656
+ if (p.swing && hand >= 0 && !p.blade) p.swing = 0;
5657
+ if (!armed) {
5658
+ [p.charge, p.reload] = [0, 0];
5659
+ return STRIKE.NONE;
4010
5660
  }
4011
- const d = c1(far(x - RIDGE[0], Math.max(z - RIDGE[1], 0)) / 36);
4012
- h += 12 * (1 - d * d) * (1 - d * d) + 8 * sm((36 - far(x - HILL[0], z - HILL[1])) / 24);
4013
- let w = 10 * t * (1 + t);
4014
- if (k > 1) {
4015
- const crest = 28 + 14 * noise(x / 170, z / 170, 5) + 6 * noise(x / 70, z / 70, 7);
4016
- const soft = 10 * sm((k - 1) / .1);
4017
- w = (w + crest - Math.sqrt((w - crest) * (w - crest) + soft * soft)) / 2 * (1 - sm((k - 1.3) / .35));
5661
+ const [key, size, carried, ticks2] = hand == 3 ? [
5662
+ "clip",
5663
+ kit.clip,
5664
+ p.rifle,
5665
+ 96
5666
+ ] : hand == 2 ? [
5667
+ "cap",
5668
+ kit.cap,
5669
+ p.rail,
5670
+ 90
5671
+ ] : [
5672
+ "mag",
5673
+ kit.mag,
5674
+ p.ammo,
5675
+ 78
5676
+ ];
5677
+ const [load, full] = [p[key] ?? 0, Math.min(size, carried)];
5678
+ if (p.reload) {
5679
+ if (!--p.reload) p[key] = full;
5680
+ } else if (hand != 1 && carried >= 0 && !busy && load < full && (!load || i.keys & KEY.RELOAD)) [p.reload, p.charge] = [ticks2, 0];
5681
+ const bare = hand < 0;
5682
+ const c = bare ? PUNCH : swingOf(p);
5683
+ if (p.swing && c.ticks - p.swing === c.strike) return STRIKE.CUT;
5684
+ if (p.wield && !top || p.railed || p.rifled || busy || p.reload || !p.wield && !p.mag) p.charge = 0;
5685
+ if (p.rifled && i.keys & KEY.SPECIAL && !busy && p.nades && !p.lob) {
5686
+ p.nades--;
5687
+ [p.lob, p.cool] = [60, 7];
5688
+ p.shots = p.shots + 1 & 255;
5689
+ return STRIKE.NADE;
4018
5690
  }
4019
- return Math.max(h, -14.5) + w;
4020
- };
4021
- /** How high a rock's middle is over the ground: three tenths of its height, and 0.6 m or half its height if less. Its widest is there, its flank steep down to the ground: a body is stopped at its foot. */
4022
- var rockMid = (H) => Math.max(.3 * H, Math.min(.5 * H, .8));
4023
- /**
4024
- * The form of a boulder of radius R and height H from a seed: how far it reaches from its middle
4025
- * (rockMid() over the ground) along a unit vector. A rounded solid, no plane in it:
4026
- * an ellipsoid stretched unevenly on its three axes and turned by the seed, upright under its
4027
- * middle (it stands in the regolith, as wide at the ground as at its middle) and a dome over it, swollen and shrunk by two low octaves
4028
- * of noise with the bearing (large soft lobes), with one gentle hollow and one flatter side. Only
4029
- * + - * /, Math.sqrt and the hash: the boxes below come from it on every side.
4030
- */
4031
- var rockOf = (s, R, H) => {
4032
- const h = (k) => hash(s, k, 131);
4033
- const flat = (k) => {
4034
- const [a, b] = [2 * h(k) - 1, 2 * h(k + 1) - 1];
4035
- const l = Math.sqrt(a * a + b * b) || 1;
4036
- return [a / l, b / l];
4037
- };
4038
- const [cx, sx] = flat(1);
4039
- const [a, b] = [R * (.9 + .25 * h(3)), R * (.68 + .22 * h(4))];
4040
- const lean = .3 * h(9) - .15;
4041
- const [hx, hz] = flat(5);
4042
- const [fx, fz] = flat(7);
4043
- const swell = (u) => {
4044
- const n = .8 + .28 * noise(1.1 * u[0] + s, 1.1 * u[2] + .9 * u[1], s) + .1 * noise(2.3 * u[0] - s, 2.3 * u[2] + 1.7 * u[1], s + 1);
4045
- const hollow = c1((.8 * (u[0] * hx + u[2] * hz) + .6 * u[1] - .55) / .45);
4046
- const side = c1((.954 * (u[0] * fx + u[2] * fz) + .3 * u[1] - .4) / .6);
4047
- return n * (1 - .14 * hollow * hollow) * (1 - .16 * side * side);
4048
- };
4049
- const cu = (H - rockMid(H)) / swell([
4050
- 0,
4051
- 1,
4052
- 0
4053
- ]);
4054
- const deep = rockMid(H) + .7 * H;
4055
- const reach = (u) => {
4056
- if (u[1] < 0) {
4057
- const l = Math.sqrt(u[0] * u[0] + u[2] * u[2]);
4058
- return l < 1e-6 ? deep : Math.min(reach([
4059
- u[0] / l,
5691
+ if (i.keys & KEY.FIRE && !busy) {
5692
+ const late = CUTS[p.cut ?? 0].ticks - (p.swing ?? 0);
5693
+ const special = !!(i.keys & KEY.SPECIAL) && (!p.swing || !p.heavy && (p.cut ?? 0) < 4 && late <= 18);
5694
+ if (bare) {
5695
+ if (!p.swing) [p.cut, p.heavy, p.swing] = [
4060
5696
  0,
4061
- u[2] / l
4062
- ]) / l, deep / -u[1]);
4063
- }
4064
- const x = (u[0] * cx + u[2] * sx - lean * u[1]) / a;
4065
- const z = (u[2] * cx - u[0] * sx - (.15 - lean) * u[1]) / b;
4066
- const q = u[1] * u[1] / (cu * cu);
4067
- const [D, E] = [x * x + z * z + .65 * q, .35 * q * q];
4068
- const T = E < 1e-12 ? 1 / D : (Math.sqrt(D * D + 4 * E) - D) / (2 * E);
4069
- return Math.sqrt(T) * swell(u);
4070
- };
4071
- return { reach };
4072
- };
4073
- /**
4074
- * The boxes a boulder collides with, x0, y0, z0, x1, y1, z1 round its middle: what stops a body is
4075
- * where the rock is drawn. From `lo` (the ground round it) to its top it is cut in layers: up to
4076
- * `band` (a body's height over the ground) a layer ends where the rock has moved in or out by
4077
- * FIT[0] on a bearing, or at 0.9 m; over it by FIT[1], or at 1.5 m; none thinner than 0.25 m. In
4078
- * each a grid of points says where the rock is at the layer's foot and top (a box may stand 7 cm
4079
- * out of it), and boxes are picked on it one after the other: the largest first, then the one
4080
- * that brings the most of the outline within FIT[2] (FIT[3] over the band) of a box, overlapping
4081
- * one already there, until the whole outline is. No crack between them.
4082
- */
4083
- /** How far over the ground a rock's first layer of boxes goes: more than a body steps up, from ground a little higher. */
4084
- var WALL = STEP_H + .2;
4085
- var FIT = [
4086
- .16,
4087
- .3,
4088
- .16,
4089
- .3
4090
- ];
4091
- var fitted = ({ reach }, R, lo, band, foot) => {
4092
- /**
4093
- * The rock's outline at a height: how far it goes from its axis on 8 m bearings, m to each side
4094
- * of a square round it (no Math.cos), 7 cm out of it; then whether a point is in that outline.
4095
- */
4096
- const outline = (y, m) => {
4097
- const o = new Float64Array(8 * m);
4098
- const u = [
4099
- 0,
4100
- 0,
4101
- 0
4102
- ];
4103
- for (let k = 0; k < 8 * m; k++) {
4104
- const t = (k % (2 * m) + .5) / m - 1;
4105
- const side = Math.floor(k / (2 * m));
4106
- const l = Math.sqrt(1 + t * t) * (side > 1 ? -1 : 1);
4107
- const dx = (side % 2 ? -t : 1) / l;
4108
- const dz = (side % 2 ? 1 : t) / l;
4109
- let p = 0;
4110
- let q = 1.6 * R;
4111
- for (let it = 0; it < 8; it++) {
4112
- const r = (p + q) / 2;
4113
- const d = Math.sqrt(r * r + y * y);
4114
- u[0] = r * dx / d;
4115
- u[1] = y / d;
4116
- u[2] = r * dz / d;
4117
- if (d <= reach(u) + .07) p = r;
4118
- else q = r;
5697
+ false,
5698
+ PUNCH.ticks
5699
+ ];
5700
+ } else if (p.wield && (!p.swing || special)) {
5701
+ p.cut = cutOf(i.keys) + (special ? 4 : 0);
5702
+ [p.swing, p.charge] = [CUTS[p.cut].ticks, 0];
5703
+ launch$1(p);
5704
+ } else if (p.rifled) {
5705
+ if (!p.cool && p.clip && !p.reload) {
5706
+ p.rifle--;
5707
+ p.clip--;
5708
+ p.cool = kit.rifleCool;
5709
+ p.shots = p.shots + 1 & 255;
5710
+ return STRIKE.LASER;
4119
5711
  }
4120
- o[k] = p;
4121
- }
4122
- return o;
4123
- };
4124
- const within = (o, x, z) => {
4125
- const m = o.length / 8;
4126
- const wide = Math.abs(x) >= Math.abs(z);
4127
- if (Math.abs(x) + Math.abs(z) < 1e-9) return true;
4128
- const side = wide ? x > 0 ? 0 : 2 : z > 0 ? 1 : 3;
4129
- const f = ((wide ? z / x : -x / z) + 1) * m - .5 + side * 2 * m;
4130
- const k = Math.floor(f);
4131
- const r = o[(k + 8 * m) % (8 * m)] * (1 - (f - k)) + o[(k + 1) % (8 * m)] * (f - k);
4132
- return x * x + z * z <= r * r;
4133
- };
4134
- const top = reach([
4135
- 0,
4136
- 1,
4137
- 0
4138
- ]) - .1;
4139
- const c = Math.max(.07, Math.min(.12, R / 12));
4140
- const out = [];
4141
- const wall = band - PLAYER_H + WALL;
4142
- const cuts = [lo];
4143
- for (let a = lo; a < top - 1e-9;) {
4144
- const shift = a < band - 1e-9 ? FIT[0] : FIT[1];
4145
- const base = outline(a + .03, 2);
4146
- let b = Math.min(a === lo && wall < top - .3 ? wall : a + .25, top);
4147
- while (b < top && b - a < .9 && outline(Math.min(b + .1, top), 2).every((r, k) => Math.abs(r - base[k]) <= shift)) b = Math.min(b + .1, top);
4148
- a = top - b < .15 ? top : b;
4149
- cuts.push(a);
4150
- }
4151
- const lines = cuts.map((y, k) => outline(k ? y : y + .03, 8));
4152
- for (let l = 0; l + 1 < cuts.length; l++) {
4153
- const [a, b] = [cuts[l], cuts[l + 1]];
4154
- const near = a < band - 1e-9 ? FIT[2] : FIT[3];
4155
- const n = Math.ceil(Math.min(Math.max(...lines[l]), Math.max(...lines[l + 1])) / c) + 1;
4156
- const N = 2 * n + 1;
4157
- const inl = new Uint8Array(N * N);
4158
- for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) {
4159
- const [x, z] = [(i - n) * c, (j - n) * c];
4160
- inl[i + j * N] = within(lines[l], x, z) && within(lines[l + 1], x, z) ? 1 : 0;
4161
- }
4162
- const NEAR = Math.max(1, Math.round(near / c));
4163
- const on = (i, j) => i >= 0 && i < N && j >= 0 && j < N && inl[i + j * N] > 0;
4164
- const edge = new Uint8Array(N * N);
4165
- for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) edge[i + j * N] = on(i, j) && !(on(i - 1, j) && on(i + 1, j) && on(i, j - 1) && on(i, j + 1)) ? 1 : 0;
4166
- const rects = [];
4167
- const all = new Uint8Array(N);
4168
- const hop = N > 48 ? 2 : 1;
4169
- for (let i0 = 0; i0 < N; i0 += hop) {
4170
- all.fill(1);
4171
- for (let i1 = i0; i1 < N; i1++) {
4172
- let any = false;
4173
- for (let j = 0, from = 0; j <= N; j++) {
4174
- all[j] = j < N && all[j] && inl[i1 + j * N] ? 1 : 0;
4175
- if (!all[j]) {
4176
- if (j - 1 - from >= 2 && i1 - i0 >= 2 && (i1 - i0) % hop === 0) rects.push([
4177
- i0,
4178
- from,
4179
- i1,
4180
- j - 1
4181
- ]);
4182
- any ||= j - 1 > from;
4183
- from = j + 1;
4184
- }
5712
+ } else if (p.railed) {
5713
+ if (p.cap && !p.reload && !p.hot) {
5714
+ p.heat = (p.heat ?? 0) + 1;
5715
+ p.hot = p.heat >= 120;
5716
+ if (!p.cool) {
5717
+ p.rail--;
5718
+ p.cap--;
5719
+ p.cool = 2;
4185
5720
  }
4186
- if (!any) break;
4187
- }
4188
- }
4189
- const sum = new Int32Array((N + 1) * (N + 1));
4190
- const count = (i0, j0, i1, j1) => {
4191
- const [a0, b0, a1, b1] = [
4192
- Math.max(i0, 0),
4193
- Math.max(j0, 0),
4194
- Math.min(i1, N - 1) + 1,
4195
- Math.min(j1, N - 1) + 1
4196
- ];
4197
- return sum[a1 + b1 * (N + 1)] - sum[a0 + b1 * (N + 1)] - sum[a1 + b0 * (N + 1)] + sum[a0 + b0 * (N + 1)];
4198
- };
4199
- const picked = [];
4200
- for (let k = 0; k < 40 && rects.length; k++) {
4201
- for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) sum[i + 1 + (j + 1) * (N + 1)] = edge[i + j * N] + sum[i + (j + 1) * (N + 1)] + sum[i + 1 + j * (N + 1)] - sum[i + j * (N + 1)];
4202
- let [best, score] = [-1, 0];
4203
- for (let m = 0; m < rects.length; m++) {
4204
- const q = rects[m];
4205
- if (k && !picked.some((p) => q[0] < p[2] && p[0] < q[2] && q[1] < p[3] && p[1] < q[3])) continue;
4206
- const area = (q[2] - q[0]) * (q[3] - q[1]);
4207
- const gain = k ? count(q[0] - NEAR, q[1] - NEAR, q[2] + NEAR, q[3] + NEAR) : 2;
4208
- const v = k ? gain * 1e6 + area : area;
4209
- if (gain >= 2 && v > score) [best, score] = [m, v];
5721
+ p.zapping = true;
5722
+ return STRIKE.RAIL;
4210
5723
  }
4211
- if (best < 0) break;
4212
- const [i0, j0, i1, j1] = rects[best];
4213
- picked.push(rects[best]);
4214
- for (let i = Math.max(i0 - NEAR, 0); i <= Math.min(i1 + NEAR, N - 1); i++) for (let j = Math.max(j0 - NEAR, 0); j <= Math.min(j1 + NEAR, N - 1); j++) edge[i + j * N] = 0;
4215
- out.push([
4216
- (i0 - n) * c,
4217
- l ? a : foot,
4218
- (j0 - n) * c,
4219
- (i1 - n) * c,
4220
- b,
4221
- (j1 - n) * c
4222
- ]);
4223
- }
4224
- }
4225
- return out;
4226
- };
4227
- /** The ground as it is walked on: at()'s 4 m lattice, each square two triangles, as ground() in relief.ts reads it. */
4228
- var walked = (x, z) => {
4229
- const [i, j] = [Math.floor(x / 4), Math.floor(z / 4)];
4230
- const [fu, fv] = [x / 4 - i, z / 4 - j];
4231
- const h = (u, v) => at$1(4 * (i + u), 4 * (j + v));
4232
- const [a, d] = [h(0, 0), h(1, 1)];
4233
- return fu >= fv ? a + (h(1, 0) - a) * fu + (d - h(1, 0)) * fv : a + (h(0, 1) - a) * fv + (d - h(0, 1)) * fu;
4234
- };
4235
- /** A rock of the map: where its middle is over the ground (x, the ground's height, z), its radius, height and seed, and the boxes it collides with (x0, y0, z0, x1, y1, z1), inside what rockOf() draws. */
4236
- var crag = (x, z, R, H, s) => {
4237
- const g = walked(x, z);
4238
- const y = g + rockMid(H);
4239
- const span = [
4240
- -3,
4241
- -2,
4242
- -1,
4243
- 0,
4244
- 1,
4245
- 2,
4246
- 3
4247
- ].map((k) => .4 * R * k);
4248
- const round = span.map((u) => span.map((v) => walked(x + u, z + v)));
4249
- const lo = Math.max(Math.min(...round.flat()), g - .55 * H);
4250
- const band = Math.max(...round.flat()) + PLAYER_H;
4251
- return {
4252
- at: [
4253
- x,
4254
- g,
4255
- z
4256
- ],
4257
- R,
4258
- H,
4259
- s,
4260
- parts: fitted(rockOf(s, R, H), R, lo - y, band - y, lo - .5 - y).map(([x0, y0, z0, x1, y1, z1]) => [
4261
- x + x0,
4262
- y + y0,
4263
- z + z0,
4264
- x + x1,
4265
- y + y1,
4266
- z + z1
4267
- ])
4268
- };
4269
- };
4270
- /** Red's boulders, each with the boxes it collides with; blue's are their mirrors. */
4271
- var CRAGS = [
4272
- [
4273
- 32.5,
4274
- 156.5,
4275
- 3.1,
4276
- 3.45,
4277
- 62
4278
- ],
4279
- [
4280
- 67.5,
4281
- 159.5,
4282
- 1.86,
4283
- 1.84,
4284
- 63
4285
- ],
4286
- [
4287
- 97.5,
4288
- 166,
4289
- 2.79,
4290
- 2.99,
4291
- 64
4292
- ],
4293
- [
4294
- 128,
4295
- 177.5,
4296
- 3.41,
4297
- 3.68,
4298
- 65
4299
- ],
4300
- [
4301
- -50,
4302
- 330,
4303
- 3.6,
4304
- 2.9,
4305
- 100
4306
- ],
4307
- [
4308
- -64,
4309
- 336,
4310
- 2.4,
4311
- 1.9,
4312
- 101
4313
- ],
4314
- [
4315
- -14,
4316
- 204,
4317
- 2.4,
4318
- 1.9,
4319
- 110
4320
- ],
4321
- [
4322
- 176,
4323
- 212,
4324
- 2.8,
4325
- 2.3,
4326
- 111
4327
- ]
4328
- ].map(([x, z, R, H, s]) => crag(x, z, R, H, s));
4329
- var ghosts = (l) => l.flatMap((c) => c.parts).map(([x0, y0, z0, x1, y1, z1]) => ({
4330
- ...box(x0, y0, z0, x1, y1, z1, STONE),
4331
- ghost: true
4332
- }));
4333
- /** A pit: PIT_R in radius, cut in a square of half side PIT_S of its crater's terrace, its floor at PIT_FLOOR, 7 m over the kill floor; a flight of PIT_STEPS steps up its east wall. */
4334
- var [PIT_R, PIT_S, PIT_FLOOR, PIT_STEPS] = [
4335
- 9,
4336
- 12,
4337
- -19,
4338
- 7
4339
- ];
4340
- /**
4341
- * The pits of red's side and of the centre line (the Bowl's): the middle, the terrace's level and
4342
- * the rows, a metre of z each: z0, z1 and how far the void goes west and east of the middle. A
4343
- * circle that wanders by 12 % with z, the same north and south of the middle, rounded up to half
4344
- * a metre: the void is never narrower than the outline the scenery draws.
4345
- */
4346
- var PITS = BOWLS.filter((b) => b[4]).map(([x, zf], n) => {
4347
- const z = 140 + zf;
4348
- const rows = Array.from({ length: 2 * PIT_R }, (_, i) => {
4349
- const dz = Math.abs(i + .5 - PIT_R);
4350
- const half = Math.sqrt(PIT_R * PIT_R - dz * dz);
4351
- const w = (side) => Math.ceil(2 * half * (.88 + .24 * noise(dz / 4, side + .5, 60 + n))) / 2;
4352
- return [
4353
- z - PIT_R + i,
4354
- z - PIT_R + i + 1,
4355
- w(0),
4356
- w(1)
4357
- ];
4358
- });
4359
- return {
4360
- x,
4361
- z,
4362
- level: at$1(x, z),
4363
- rows
4364
- };
4365
- });
4366
- /** What a pit collides with: its square of terrace in pieces round the void (two caps and, for each run of rows of one width, a box each side), its floor, and the steps: each as high again as a body jumps at half gravity, 1.3 m deep, up to the terrace at the east wall. */
4367
- var pit = ({ x, z, level, rows }) => {
4368
- const runs = rows.reduce((l, [z0, z1, a, b]) => {
4369
- const last = l.at(-1);
4370
- if (last && last[2] === a && last[3] === b) last[1] = z1;
4371
- else l.push([
4372
- z0,
4373
- z1,
4374
- a,
4375
- b
4376
- ]);
4377
- return l;
4378
- }, []);
4379
- const east = rows[PIT_R][3];
4380
- const rise = (level - PIT_FLOOR) / PIT_STEPS;
4381
- return [
4382
- box(x - PIT_S, -30, z - PIT_S, x + PIT_S, level, z - PIT_R, STONE),
4383
- box(x - PIT_S, -30, z + PIT_R, x + PIT_S, level, z + PIT_S, STONE),
4384
- ...runs.flatMap(([z0, z1, a, b]) => [box(x - PIT_S, -30, z0, x - a, level, z1, STONE), box(x + b, -30, z0, x + PIT_S, level, z1, STONE)]),
4385
- box(x - PIT_R - 1.5, -30, z - PIT_R, x + PIT_R + 1.5, PIT_FLOOR, z + PIT_R, STONE),
4386
- ...Array.from({ length: PIT_STEPS - 1 }, (_, k) => box(x + east - 1.3 * (PIT_STEPS - 1 - k), PIT_FLOOR, z - 1, x + east - 1.3 * (PIT_STEPS - 2 - k), PIT_FLOOR + rise * (k + 1), z + 1, STONE))
4387
- ].map((b) => ({
4388
- ...b,
4389
- ghost: true
4390
- }));
4391
- };
4392
- /** The ghost under a drawn rock or mast: a box of half side s from under the ground to h above it. */
4393
- var lump = (x, z, s, h) => ({
4394
- ...box(x - s, at$1(x, z) - 6, z - s, x + s, at$1(x, z) + h, z + s, STONE),
4395
- ghost: true
4396
- });
4397
- var LAYOUT = {
4398
- /** Outside the arena: the dishes, the ramps (the middle of the lip and the unit way up it), the wreck. */
4399
- dishes: [...DISHES, ...DISHES.map(([x, z]) => [x, 280 - z])],
4400
- ramps: RAMPS.flatMap(([x, z, ax, az]) => (z ? [1, -1] : [1]).map((m) => [
4401
- x + 16 * ax,
4402
- 140 + m * (z + 16 * az),
4403
- ax,
4404
- m * az + 0
4405
- ])),
4406
- wreck: WRECK,
4407
- /** The pits, both sides: the middle, the terrace's level and the rows (z0, z1, the void's reach west and east). */
4408
- pits: PITS.flatMap((p) => p.z === 140 ? [p] : [p, {
4409
- ...p,
4410
- z: 280 - p.z,
4411
- rows: p.rows.map(([z0, z1, a, b]) => [
4412
- 280 - z1,
4413
- 280 - z0,
4414
- a,
4415
- b
4416
- ]).reverse()
4417
- }]),
4418
- /** The craters of the relief, both sides: x, z, radius, depth as a share of it. */
4419
- bowls: BOWLS.flatMap(([x, z, r, k = .17]) => (z ? [1, -1] : [1]).map((m) => [
4420
- x,
4421
- 140 + m * z,
4422
- r,
4423
- k
4424
- ])),
4425
- /** Red's boulders, in the field and outside: blue's are their mirrors. */
4426
- crags: CRAGS,
4427
- /** Where the boulders stood, red's side (x, z, radius): pebbles lie thickest there. */
4428
- sites: SITES,
4429
- pillars: PILLARS,
4430
- domes: [DOME, [DOME[0], 280 - DOME[1]]],
4431
- pads: [PAD$1, [
4432
- PAD$1[0],
4433
- 280 - PAD$1[1],
4434
- PAD$1[2]
4435
- ]],
4436
- modules: [...MODULES, ...MODULES.map(mirror)],
4437
- tubes: [...TUBES, ...TUBES.map(mirror)],
4438
- masts: [...MASTS, ...MASTS.map(([x, z]) => [x, 280 - z])]
5724
+ } else if (!p.wield && !p.cool && p.mag && !p.reload) p.charge = Math.min((p.charge ?? 0) + 1, 60);
5725
+ } else if (p.charge) {
5726
+ p.power = Math.min(powerOf(p.charge), p.mag);
5727
+ p.charge = 0;
5728
+ p.ammo -= p.power;
5729
+ p.mag = p.mag - p.power;
5730
+ p.shots = p.shots + 1 & 255;
5731
+ p.cool = kit.cool;
5732
+ return STRIKE.SHOT;
5733
+ }
5734
+ return STRIKE.NONE;
4439
5735
  };
4440
- /** The twin of a brush, a point or a spawn across the centre line. */
4441
- var flip = (b) => ({
4442
- ...b,
4443
- min: [
4444
- b.min[0],
4445
- b.min[1],
4446
- 280 - b.max[2]
4447
- ],
4448
- max: [
4449
- b.max[0],
4450
- b.max[1],
4451
- 280 - b.min[2]
4452
- ],
4453
- tint: b.tint === RED ? BLUE : b.tint
4454
- });
4455
- var flipPoint = ([x, y, z]) => [
4456
- x,
4457
- y,
4458
- 280 - z
4459
- ];
4460
- /** The list and its twins, then the pieces by the rille. */
4461
- var both = (l, ...mid) => [
4462
- ...l,
4463
- ...l.map(flipPoint),
4464
- ...mid
4465
- ];
4466
- /** Red's half: z from 140 to 280. */
4467
- var half = [
4468
- ...[
4469
- box(0, -30, 160, 160, 0, HOLLOW[1] - 12, STONE),
4470
- box(0, -30, HOLLOW[1] - 12, HOLLOW[0] - 12, 0, HOLLOW[1] + 12, STONE),
4471
- box(HOLLOW[0] + 12, -30, HOLLOW[1] - 12, 160, 0, HOLLOW[1] + 12, STONE),
4472
- box(0, -30, HOLLOW[1] + 12, 160, 0, 280, STONE),
4473
- box(HOLLOW[0] - 12, -30, HOLLOW[1] - 12, HOLLOW[0] + 12, -3, HOLLOW[1] + 12, STONE),
4474
- ...RUNS.filter((r) => r[2] < 0).map(([x, w, n]) => box(x, -30, 148 + n, x + w, 0, 160, STONE)),
4475
- ...Array.from({ length: 14 }, (_, k) => runs(LIP.map((n) => n < 0 ? 2 : n > k / 2 ? 1 : 0)).filter((r) => !r[2]).map(([x, w]) => box(x, -30, 148 + k / 2, x + w, 0, k < 13 ? 148.5 + k / 2 : 160, STONE))).flat(),
4476
- ...MOUNDS.flatMap((x) => [
4477
- -12,
4478
- -10,
4479
- -8,
4480
- -6,
4481
- -4,
4482
- 4,
4483
- 6,
4484
- 8,
4485
- 10
4486
- ].map((a) => [a, a + (a === -4 ? 8 : 2)]).map(([a, b]) => [
4487
- x + a,
4488
- x + b,
4489
- MOUND * Math.min(across(x, x + a), across(x, x + b)) * (1 - .5 / RISE) - .12
4490
- ]).filter((r) => r[2] > .3).map(([a, b, y]) => box(a, 0, 148, b, y, 148.5, STONE)))
4491
- ].map((b) => ({
4492
- ...b,
4493
- ghost: true
4494
- })),
4495
- ...BASE,
4496
- {
4497
- ...box(75.25, 0, FLAG - 4.75, 84.75, .5, FLAG + 4.75, PAINT, CONCRETE, RED),
4498
- ghost: true
4499
- },
4500
- {
4501
- ...box(75.75, .5, FLAG - 4.25, 84.25, 1, FLAG + 4.25, PAINT, CONCRETE, RED),
4502
- ghost: true
4503
- },
4504
- box(60, 0, 259, 70, 1.5, 265, STEEL, PAINT, RED),
4505
- box(27, 0, 207, 53, .25, 233, METAL),
4506
- ...MASTS.map(([x, z]) => box(x - .2, x < 60 ? .25 : 0, z - .2, x + .2, x < 60 ? 10.25 : 10, z + .2, STEEL)),
4507
- box(12, -30, 148 - 2.5 / 2, 24, 0, 148, PAINT, STONE, [
4508
- 1,
4509
- .42,
4510
- .08
4511
- ]),
4512
- ...PITS.filter((p) => p.z !== 140).flatMap(pit),
4513
- ...ghosts(CRAGS),
4514
- ...DISHES.map(([x, z]) => lump(x, z, .4, 6))
4515
- ];
4516
- /** What stands on the centre line, symmetric as written: the bridge, the stones, the rille's plugs and the wreck. */
4517
- var centre = [
4518
- box(74, -1.5, 132, 86, 0, 148, METAL, STEEL),
4519
- box(74, 0, 132, 74.4, 1.1, 148, CONCRETE),
4520
- box(85.6, 0, 132, 86, 1.1, 148, CONCRETE),
4521
- ...PILLARS.map(([x0, z0, x1, z1, y]) => ({
4522
- ...box(x0, -30, z0, x1, y, z1, STONE),
4523
- ghost: true
4524
- })),
4525
- {
4526
- ...box(-10, -30, 132, 0, 0, 148, STONE),
4527
- ghost: true
4528
- },
4529
- {
4530
- ...box(160, -30, 132, 170, 0, 148, STONE),
4531
- ghost: true
4532
- },
4533
- {
4534
- ...box(WRECK[0] - 3.6, -30, WRECK[1] - 3.6, WRECK[0] + 3.6, PIT_FLOOR + 3.5, WRECK[1] + 3.6, STONE),
4535
- ghost: true
4536
- },
4537
- ...PITS.filter((p) => p.z === 140).flatMap(pit),
4538
- ...LAYOUT.ramps.flatMap(([x, z, ax, az]) => [-8, 8].map((c) => lump(x + c * az, z - c * ax, .2, 2.2)))
4539
- ];
4540
- /** Red's spawns behind the dome facing blue (yaw 0 looks toward -z): five in a row, three in front. */
4541
- var SPAWNS = [...[
4542
- 56,
4543
- 68,
4544
- 80,
4545
- 92,
4546
- 104
4547
- ].map((x) => [
4548
- x,
4549
- 0,
4550
- 271,
4551
- 0
4552
- ]), ...[
4553
- 62,
4554
- 80,
4555
- 98
4556
- ].map((x) => [
4557
- x,
4558
- 0,
4559
- 267,
4560
- 0
4561
- ])];
4562
- /** The racks on the plinth, 2.5 m apart: rifle, rail, gun, katana. */
4563
- var racks = (z) => Object.fromEntries([
4564
- "rifle",
4565
- "rail",
4566
- "rack",
4567
- "blade"
4568
- ].map((k, i) => [k, [
4569
- 61.25 + 2.5 * i,
4570
- 1.5,
4571
- z
4572
- ]]));
4573
- var team = (z, s) => ({
4574
- base: [
4575
- 80,
4576
- 1,
4577
- z
4578
- ],
4579
- spawns: s,
4580
- ...racks(z + (z > 140 ? 28 : -28))
4581
- });
5736
+ /**
5737
+ * A step in a saber lock: the blade stays in hand and no cut starts. Each FIRE press (FIRE held
5738
+ * now, not at the last step) pushes; a side or back key held counts `away`, up to LOCK_BREAK. The
5739
+ * lock runs down to 1, where it waits for the host, who parts the two (room.ts).
5740
+ */
5741
+ var duel = (p, i) => {
5742
+ const fire = !!(i.keys & KEY.FIRE);
5743
+ p.pushes = (p.pushes ?? 0) + +(fire && !p.pressed) & 255;
5744
+ p.pressed = fire;
5745
+ p.away = i.keys & (KEY.LEFT | KEY.RIGHT | KEY.BACK) ? Math.min((p.away ?? 0) + 1, 24) : 0;
5746
+ p.lock = Math.max(1, p.lock - 1);
5747
+ [p.wield, p.swing, p.charge] = [
5748
+ true,
5749
+ 0,
5750
+ 0
5751
+ ];
5752
+ return STRIKE.NONE;
5753
+ };
5754
+ /** The strength a charge of `ticks` gives, 1 to CHARGE_MAX: 1 under CHARGE_TAP, CHARGE_MAX at CHARGE_TICKS. */
5755
+ var powerOf = (ticks) => ticks < 10 ? 1 : 1 + Math.floor(4 * (ticks - 10) / 50);
4582
5756
  // src/shared/maps.ts
4583
5757
  var MAPS = {
4584
5758
  highline: HIGHLINE,
4585
- tranquility: {
4586
- name: "Tranquility",
4587
- tag: "Moon · half gravity",
4588
- lore: "A mining base left in a lunar crater, its domes still lit. Two crews fight for it in space helmets, under the Earth and a black sky. Jumps float twice as high, and a rille cuts the base in two.",
4589
- brushes: [
4590
- ...half,
4591
- ...half.map(flip),
4592
- ...centre
4593
- ],
4594
- teams: [team(FLAG, SPAWNS), team(280 - FLAG, SPAWNS.map(([x, y, z]) => [
4595
- x,
4596
- y,
4597
- 280 - z,
4598
- Math.PI
4599
- ]))],
4600
- packs: both([
4601
- [
4602
- 90,
4603
- 0,
4604
- 210
4605
- ],
4606
- [
4607
- 118,
4608
- 5,
4609
- 226
4610
- ],
4611
- [
4612
- 30,
4613
- 0,
4614
- 185
4615
- ],
4616
- [
4617
- 80,
4618
- 3.5,
4619
- 253.5
4620
- ]
4621
- ], [
4622
- 45,
4623
- 0,
4624
- 162
4625
- ], [
4626
- 45,
4627
- 0,
4628
- 118
4629
- ]),
4630
- ammo: both([
4631
- [
4632
- 50,
4633
- 0,
4634
- 246
4635
- ],
4636
- [
4637
- 103,
4638
- 5,
4639
- 200
4640
- ],
4641
- [
4642
- 135,
4643
- 0,
4644
- 190
4645
- ]
4646
- ], [
4647
- 115,
4648
- 0,
4649
- 162
4650
- ], [
4651
- 115,
4652
- 0,
4653
- 118
4654
- ]),
4655
- cells: both([[
4656
- 106.5,
4657
- 3.5,
4658
- 226
4659
- ], [
4660
- 35,
4661
- 0,
4662
- 244
4663
- ]], [
4664
- 80,
4665
- 0,
4666
- 140
4667
- ]),
4668
- floor: -26,
4669
- relief: {
4670
- hole: [
4671
- 0,
4672
- 132,
4673
- 160,
4674
- 148
4675
- ],
4676
- pits: [...RUNS.flatMap(([x, w, n]) => n > 0 ? [[
4677
- x,
4678
- 148,
4679
- x + w,
4680
- 148 + n
4681
- ], [
4682
- x,
4683
- 132 - n,
4684
- x + w,
4685
- 132
4686
- ]] : []), ...LAYOUT.pits.flatMap(({ x, rows }) => rows.map(([z0, z1, a, b]) => [
4687
- x - a,
4688
- z0,
4689
- x + b,
4690
- z1
4691
- ]))],
4692
- bound: [
4693
- 80,
4694
- 140,
4695
- 300,
4696
- 360
4697
- ],
4698
- cell: 4,
4699
- at: at$1
4700
- },
4701
- sun: {
4702
- dir: [
4703
- .87996,
4704
- .40998,
4705
- .23999
4706
- ],
4707
- color: [
4708
- 3,
4709
- 2.95,
4710
- 2.85
4711
- ]
4712
- },
4713
- sky: [[
4714
- .002,
4715
- .002,
4716
- .006
4717
- ], [
4718
- .02,
4719
- .02,
4720
- .035
4721
- ]],
4722
- gravity: .5,
4723
- rovers: [
4724
- [
4725
- 100,
4726
- 0,
4727
- 178,
4728
- 0
4729
- ],
4730
- [
4731
- 30,
4732
- 0,
4733
- 255,
4734
- 0
4735
- ],
4736
- [
4737
- 100,
4738
- 0,
4739
- 102,
4740
- Math.PI
4741
- ],
4742
- [
4743
- 30,
4744
- 0,
4745
- 25,
4746
- Math.PI
4747
- ]
4748
- ],
4749
- ships: [[
4750
- PAD$1[0],
4751
- .25,
4752
- PAD$1[1],
4753
- 0
4754
- ], [
4755
- PAD$1[0],
4756
- .25,
4757
- 280 - PAD$1[1],
4758
- Math.PI
4759
- ]],
4760
- doors: [...DOORS, ...DOORS.map(mirror)],
4761
- scenery: "moon",
4762
- helmets: true,
4763
- armor: true
4764
- }
5759
+ tranquility: MOON
4765
5760
  };
4766
5761
  /** The map of a key; an unknown or missing one is HIGHLINE. */
4767
5762
  var mapOf = (key) => key !== void 0 && MAPS[key] || HIGHLINE;
@@ -4967,6 +5962,19 @@ var clamp16 = (v) => Math.max(-32768, Math.min(32767, Math.round(v)));
4967
5962
  var toPitch = (pitch) => clamp16(pitch * 1e4);
4968
5963
  var fromPitch = (w) => w / 1e4;
4969
5964
  var fromTurn = (w) => w / TURN;
5965
+ /** A view tick in 1/256 tick, modulo the u16 tick circle (24 bits); absent is 0. */
5966
+ var toView = (view = 0) => Math.round(view * 256) & 16777215;
5967
+ /**
5968
+ * The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
5969
+ * rounded to the wire (an absent view stays absent here, and reads 0 on the host). The client
5970
+ * predicts with this, so both sides move with the same values.
5971
+ */
5972
+ var onWire = (i) => ({
5973
+ ...i,
5974
+ yaw: fromTurn(toTurn(i.yaw)),
5975
+ pitch: fromPitch(toPitch(i.pitch)),
5976
+ ...i.view !== void 0 && { view: toView(i.view) / 256 }
5977
+ });
4970
5978
  /** Null on anything that is not a well-formed input frame. */
4971
5979
  var decodeInput = (buf) => {
4972
5980
  if (buf.byteLength !== 12) return null;
@@ -6315,6 +7323,17 @@ var MAX_CATCH_UP = 20;
6315
7323
  var SPAWN_CLEAR = 2;
6316
7324
  /** Ticks before a rover can run the same player over again. */
6317
7325
  var SPLAT_COOLDOWN = 30;
7326
+ /** The names of the bots, in turn. */
7327
+ var BOT_NAMES = [
7328
+ "Ada",
7329
+ "Bix",
7330
+ "Cog",
7331
+ "Dot",
7332
+ "Echo",
7333
+ "Flux",
7334
+ "Gear",
7335
+ "Hex"
7336
+ ];
6318
7337
  /** The two seats of a rover, the driver's first. */
6319
7338
  var SEATS = ["driver", "rider"];
6320
7339
  /** An index in [0, n), or undefined. */
@@ -6438,6 +7457,8 @@ var Room = class {
6438
7457
  next;
6439
7458
  /** Joins so far: each player's `since`. */
6440
7459
  joins = 0;
7460
+ /** 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. */
7461
+ freed = /* @__PURE__ */ new Set();
6441
7462
  /** Missing rules fall back to RULES. The map is the rules' one, unless a definition is given. */
6442
7463
  constructor(rules = {}, def) {
6443
7464
  this.rules = {
@@ -6445,10 +7466,11 @@ var Room = class {
6445
7466
  ...rules
6446
7467
  };
6447
7468
  this.mapName = mapKey(this.rules.map);
6448
- this.world = build(def ?? mapOf(this.mapName));
7469
+ this.world = build$1(def ?? mapOf(this.mapName));
6449
7470
  this.ctf = new Ctf(this.world, this.rules);
6450
7471
  this.gone = this.spots();
6451
7472
  this.fresh();
7473
+ this.guide();
6452
7474
  }
6453
7475
  /** Every vehicle of the map parked afresh: whole, empty, on its spawn. */
6454
7476
  fresh() {
@@ -6467,25 +7489,26 @@ var Room = class {
6467
7489
  }
6468
7490
  /** The host: the player in the room the longest. */
6469
7491
  host() {
6470
- return this.players().reduce((h, p) => h && h.since < p.since ? h : p, void 0);
7492
+ return this.humans().reduce((h, p) => h && h.since < p.since ? h : p, void 0);
6471
7493
  }
6472
7494
  /** The map the host picked, from now on: a new world and a new match, the players in it. */
6473
7495
  load() {
6474
7496
  if (this.next === void 0) return;
6475
7497
  this.mapName = this.next;
6476
7498
  this.next = void 0;
6477
- this.world = build(mapOf(this.mapName));
7499
+ this.world = build$1(mapOf(this.mapName));
6478
7500
  this.ctf = new Ctf(this.world, this.rules);
6479
7501
  this.gone = this.spots();
6480
7502
  this.fresh();
7503
+ this.guide();
6481
7504
  this.history = [];
6482
7505
  this.balls = [];
6483
7506
  for (const p of this.players()) this.ctf.join(p.info.id, p.info.team, p.state);
6484
7507
  this.roster();
6485
7508
  }
6486
- /** Number of joined players. */
7509
+ /** Number of joined players, the bots left out: a room of bots alone is empty. */
6487
7510
  get size() {
6488
- return this.players().length;
7511
+ return this.humans().length;
6489
7512
  }
6490
7513
  /** A peer opened. Nothing is sent until it joins. */
6491
7514
  connect(conn) {
@@ -6517,7 +7540,11 @@ var Room = class {
6517
7540
  return;
6518
7541
  }
6519
7542
  const input = p && decodeInput(data);
6520
- if (input && p.bank > 0) {
7543
+ if (input) this.apply(p, input);
7544
+ }
7545
+ /** One input of a player, moved at once. An input beyond the bank is dropped, and not acked. */
7546
+ apply(p, input) {
7547
+ if (p.bank > 0) {
6521
7548
  p.bank--;
6522
7549
  const slow = p.state.slow ?? 0;
6523
7550
  const use = (input.keys & KEY.USE) !== 0 && (p.state.held & KEY.USE) === 0;
@@ -6564,7 +7591,9 @@ var Room = class {
6564
7591
  this.peers.delete(conn);
6565
7592
  if (p) {
6566
7593
  this.ctf.leave(p.info.id);
7594
+ this.fill();
6567
7595
  if (!this.size) {
7596
+ this.freed.clear();
6568
7597
  this.ctf.reset();
6569
7598
  this.gone.fill(0);
6570
7599
  this.fresh();
@@ -6584,6 +7613,7 @@ var Room = class {
6584
7613
  }
6585
7614
  /** One host tick. Public so tests can drive the room without a timer. */
6586
7615
  tick() {
7616
+ this.freed.clear();
6587
7617
  const players = this.players();
6588
7618
  if (!players.length) {
6589
7619
  this.balls = [];
@@ -6591,6 +7621,7 @@ var Room = class {
6591
7621
  }
6592
7622
  const now = ++this.ticks;
6593
7623
  for (const p of players) p.bank = Math.min(10, p.bank + 1);
7624
+ this.think(players);
6594
7625
  for (const b of this.balls) if (!b.burst && b.left > 0) this.fly(b, stepOf(b));
6595
7626
  this.heal(players);
6596
7627
  swing(this.world, players.filter((p) => !p.state.down).map((p) => [
@@ -7407,14 +8438,73 @@ var Room = class {
7407
8438
  players() {
7408
8439
  return [...this.peers.values()].filter((p) => p !== null);
7409
8440
  }
7410
- join(conn, name, picked = {}) {
8441
+ humans() {
8442
+ return this.players().filter((p) => !p.bot);
8443
+ }
8444
+ /** Each bot's input of this tick, applied as a client's would be on arrival. */
8445
+ think(players) {
8446
+ const others = players.map((q) => ({
8447
+ id: q.info.id,
8448
+ team: q.info.team,
8449
+ state: q.state
8450
+ }));
8451
+ for (const p of players) if (p.bot) {
8452
+ const me = others.find((o) => o.id === p.info.id);
8453
+ const i = p.bot.think({
8454
+ me,
8455
+ others: others.filter((o) => o !== me),
8456
+ flags: this.ctf.flags,
8457
+ world: this.world
8458
+ });
8459
+ p.seq = (p.seq ?? -1) + 1 & 65535;
8460
+ this.apply(p, onWire({
8461
+ ...i,
8462
+ seq: p.seq,
8463
+ view: this.ticks & 65535
8464
+ }));
8465
+ }
8466
+ }
8467
+ /** The bots' map of the world, built when it loads rather than in the tick of a bot's first plan. */
8468
+ guide() {
8469
+ if (this.rules.bots) navOf(this.world);
8470
+ }
8471
+ /** The players the bots fill the room up to: none with no human. */
8472
+ wanted() {
8473
+ return this.size ? Math.min(this.rules.bots ?? 0, this.rules.maxPlayers) : 0;
8474
+ }
8475
+ /**
8476
+ * Bots in and out so that there are `want` players, the humans first, the teams even: a bot comes
8477
+ * on the smaller team and leaves the larger one.
8478
+ */
8479
+ fill(want = this.wanted()) {
8480
+ for (;;) {
8481
+ const players = this.players();
8482
+ const reds = players.filter((p) => p.info.team === 0).length;
8483
+ const bots = players.filter((p) => p.bot);
8484
+ if (players.length > want && bots.length) {
8485
+ const big = reds > players.length - reds ? 0 : 1;
8486
+ const out = bots.reverse().find((p) => p.info.team === big) ?? bots[0];
8487
+ this.peers.delete(out.conn);
8488
+ this.ctf.leave(out.info.id);
8489
+ this.freed.add(out.info.id);
8490
+ } else if (players.length < want) {
8491
+ const conn = { send: () => void 0 };
8492
+ this.peers.set(conn, null);
8493
+ const names = players.map((p) => p.info.name);
8494
+ const name = BOT_NAMES.map((n) => `${n} (bot)`).find((n) => !names.includes(n)) ?? "Bot";
8495
+ this.join(conn, name, {}, true);
8496
+ } else return;
8497
+ }
8498
+ }
8499
+ join(conn, name, picked = {}, bot = false) {
8500
+ if (!bot && this.players().some((p) => p.bot)) this.fill(Math.min(this.wanted(), this.players().length) - 1);
7411
8501
  const players = this.players();
7412
8502
  if (players.length >= this.rules.maxPlayers) {
7413
8503
  conn.send(JSON.stringify({ t: "full" }));
7414
8504
  return;
7415
8505
  }
7416
8506
  let id = 0;
7417
- while (players.some((p) => p.info.id === id)) id++;
8507
+ while (players.some((p) => p.info.id === id) || this.freed.has(id)) id++;
7418
8508
  const reds = players.filter((p) => p.info.team === 0).length;
7419
8509
  const team = reds > players.length - reds ? 1 : 0;
7420
8510
  const player = {
@@ -7424,7 +8514,8 @@ var Room = class {
7424
8514
  name: unique(cleanName(name) || `Player ${id}`, players.map((p) => p.info.name)),
7425
8515
  team,
7426
8516
  color: TEAM_COLOR[team],
7427
- ...chosen(picked)
8517
+ ...chosen(picked),
8518
+ ...bot ? { bot } : {}
7428
8519
  },
7429
8520
  state: this.place(id, team, players.map((p) => p.state)),
7430
8521
  since: this.joins++,
@@ -7432,17 +8523,20 @@ var Room = class {
7432
8523
  ack: 65535,
7433
8524
  by: 0,
7434
8525
  tackled: -30,
7435
- run: -SPLAT_COOLDOWN
8526
+ run: -SPLAT_COOLDOWN,
8527
+ ...bot ? { bot: new Bot(id) } : {}
7436
8528
  };
7437
8529
  this.peers.set(conn, player);
7438
8530
  this.ctf.join(id, team, player.state);
7439
- this.roster();
8531
+ if (!bot) {
8532
+ this.fill();
8533
+ this.roster();
8534
+ }
7440
8535
  }
7441
8536
  /** Each joined peer gets the full roster with its own id. */
7442
8537
  roster() {
7443
- const players = this.players();
7444
- const list = players.map((p) => p.info).sort((a, b) => a.id - b.id);
7445
- players.forEach((p) => p.conn.send(JSON.stringify({
8538
+ const list = this.players().map((p) => p.info).sort((a, b) => a.id - b.id);
8539
+ this.humans().forEach((p) => p.conn.send(JSON.stringify({
7446
8540
  t: "roster",
7447
8541
  you: p.info.id,
7448
8542
  players: list,