@korial29/tiny-fps 0.137.0 → 0.139.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cli.js +6 -1
- package/dist/index.js +13 -13
- package/dist/local.js +1 -1
- package/dist/server.js +2677 -1344
- package/dist/types/client/armor.d.ts +11 -2
- package/dist/types/client/helm.d.ts +4 -2
- package/dist/types/client/pads.d.ts +11 -2
- package/dist/types/shared/bot.d.ts +134 -0
- package/dist/types/shared/nav.d.ts +42 -0
- package/dist/types/shared/room.d.ts +17 -1
- package/dist/types/shared/routes.d.ts +76 -0
- package/dist/types/shared/types.d.ts +6 -0
- package/package.json +1 -1
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$
|
|
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$
|
|
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$
|
|
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$
|
|
647
|
-
let cz = at$
|
|
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,505 +1606,6 @@ 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
|
|
1617
|
-
});
|
|
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);
|
|
1858
|
-
/**
|
|
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.
|
|
1862
|
-
*/
|
|
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;
|
|
1880
|
-
};
|
|
1881
|
-
/**
|
|
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.
|
|
1884
|
-
*/
|
|
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
1609
|
// src/shared/map.ts
|
|
2109
1610
|
/** The bottom of every building: far below the kill floor, so nothing shows beneath a roof. */
|
|
2110
1611
|
var BASE$1 = -30;
|
|
@@ -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$
|
|
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$
|
|
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,
|
|
@@ -3986,7 +3487,7 @@ var rough = (x, z, out) => {
|
|
|
3986
3487
|
* is 20 m high on it and, past it where nobody goes, rounds off under a crest of 28 to 48 m that
|
|
3987
3488
|
* rolls slowly and falls to the plain at 1.65 of the bound. Lower than the ranges drawn far behind it.
|
|
3988
3489
|
*/
|
|
3989
|
-
var at$
|
|
3490
|
+
var at$2 = (x, z) => {
|
|
3990
3491
|
z = Math.abs(z - 140);
|
|
3991
3492
|
const k = far((x - 80) / 300, z / 360);
|
|
3992
3493
|
const t = Math.max((k - .78) / .22, 0);
|
|
@@ -4068,872 +3569,2604 @@ var rockOf = (s, R, H) => {
|
|
|
4068
3569
|
const T = E < 1e-12 ? 1 / D : (Math.sqrt(D * D + 4 * E) - D) / (2 * E);
|
|
4069
3570
|
return Math.sqrt(T) * swell(u);
|
|
4070
3571
|
};
|
|
4071
|
-
return { reach };
|
|
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
|
+
};
|
|
4072
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
|
+
];
|
|
4073
3841
|
/**
|
|
4074
|
-
* The
|
|
4075
|
-
*
|
|
4076
|
-
*
|
|
4077
|
-
*
|
|
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.
|
|
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.
|
|
4082
3846
|
*/
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
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))
|
|
4090
4016
|
];
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
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,
|
|
4099
4101
|
0,
|
|
4102
|
+
210
|
|
4103
|
+
],
|
|
4104
|
+
[
|
|
4105
|
+
118,
|
|
4106
|
+
5,
|
|
4107
|
+
226
|
|
4108
|
+
],
|
|
4109
|
+
[
|
|
4110
|
+
30,
|
|
4100
4111
|
0,
|
|
4101
|
-
|
|
4102
|
-
]
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
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;
|
|
4119
|
-
}
|
|
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([
|
|
4112
|
+
185
|
|
4113
|
+
],
|
|
4114
|
+
[
|
|
4115
|
+
80,
|
|
4116
|
+
3.5,
|
|
4117
|
+
253.5
|
|
4118
|
+
]
|
|
4119
|
+
], [
|
|
4120
|
+
45,
|
|
4135
4121
|
0,
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
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
|
-
}
|
|
4185
|
-
}
|
|
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];
|
|
4210
|
-
}
|
|
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,
|
|
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,
|
|
4243
4146
|
0,
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
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 ? [[
|
|
4253
4175
|
x,
|
|
4254
|
-
|
|
4255
|
-
|
|
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
|
|
4256
4195
|
],
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
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)
|
|
4268
4292
|
};
|
|
4269
4293
|
};
|
|
4270
|
-
/**
|
|
4271
|
-
var
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
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
|
|
4278
4302
|
],
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
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)
|
|
4285
4316
|
],
|
|
4286
|
-
[
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
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
|
|
4292
4336
|
],
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
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)
|
|
4299
4350
|
],
|
|
4300
|
-
[
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
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)
|
|
4306
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 = 20;
|
|
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 = [
|
|
4307
4500
|
[
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
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
|
+
]
|
|
4313
4541
|
],
|
|
4314
4542
|
[
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4543
|
+
[
|
|
4544
|
+
80,
|
|
4545
|
+
0,
|
|
4546
|
+
208
|
|
4547
|
+
],
|
|
4548
|
+
[
|
|
4549
|
+
80,
|
|
4550
|
+
0,
|
|
4551
|
+
152
|
|
4552
|
+
],
|
|
4553
|
+
[
|
|
4554
|
+
80,
|
|
4555
|
+
0,
|
|
4556
|
+
140
|
|
4557
|
+
]
|
|
4320
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
|
+
]],
|
|
4321
4577
|
[
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
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
|
+
]
|
|
4327
4593
|
]
|
|
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
4594
|
];
|
|
4340
4595
|
/**
|
|
4341
|
-
* The
|
|
4342
|
-
* the
|
|
4343
|
-
*
|
|
4344
|
-
*
|
|
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.
|
|
4345
4668
|
*/
|
|
4346
|
-
var
|
|
4347
|
-
|
|
4348
|
-
const
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
];
|
|
4358
|
-
|
|
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
|
+
}
|
|
4359
4796
|
return {
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
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/plasma.ts
|
|
4863
|
+
/** Metres a ball flies in a tick, and an arc. */
|
|
4864
|
+
var PLASMA_STEP = 40 / 60;
|
|
4865
|
+
var ARC_STEP = ARC_SPEED / 60;
|
|
4866
|
+
/** How far shot `n` of the laser rifle drifts off the look, yaw and pitch: a pattern within RIFLE_DRIFT, the same for the host and every client. */
|
|
4867
|
+
var drift = (n) => [RIFLE_DRIFT * Math.sin(n * 2.4), RIFLE_DRIFT * Math.cos(n * 1.7)];
|
|
4868
|
+
/**
|
|
4869
|
+
* The ball of the shot `p` has just fired (`p` is the state after the step that fired): from the
|
|
4870
|
+
* eye of the mode along the look, GUN_RANGE metres to go, named by his `shots` count, as strong
|
|
4871
|
+
* as the shot (`power`). The laser rifle's (the user, 2026-11-08: the gun's balls, in red) has
|
|
4872
|
+
* power 0, RIFLE_RANGE to go, and leaves along the look drifted by its shot's pattern.
|
|
4873
|
+
*/
|
|
4874
|
+
var launch$1 = (p, team = 0) => {
|
|
4875
|
+
const [dy, dp] = p.rifled ? drift(p.shots) : [0, 0];
|
|
4876
|
+
const [yaw, pitch] = [p.yaw + dy, p.pitch + dp];
|
|
4877
|
+
const [sy, cy, sp, cp] = [
|
|
4878
|
+
Math.sin(yaw),
|
|
4879
|
+
Math.cos(yaw),
|
|
4880
|
+
Math.sin(pitch),
|
|
4881
|
+
Math.cos(pitch)
|
|
4882
|
+
];
|
|
4883
|
+
return {
|
|
4884
|
+
id: p.shots,
|
|
4885
|
+
by: p.id,
|
|
4886
|
+
team,
|
|
4887
|
+
x: p.x,
|
|
4888
|
+
y: p.y + eyeHeight(p),
|
|
4889
|
+
z: p.z,
|
|
4890
|
+
dx: -sy * cp,
|
|
4891
|
+
dy: sp,
|
|
4892
|
+
dz: -cy * cp,
|
|
4893
|
+
left: p.rifled ? 60 : 80,
|
|
4894
|
+
burst: false,
|
|
4895
|
+
power: p.rifled ? 0 : p.power ?? 1
|
|
4364
4896
|
};
|
|
4897
|
+
};
|
|
4898
|
+
/**
|
|
4899
|
+
* The arc of energy the ARC cut of `p` throws at its strike (`p` the state after that step): from
|
|
4900
|
+
* the eye along the look like a ball, ARC_RANGE metres to go, its CUT in `arc`. Its id is the
|
|
4901
|
+
* `shots` count with the top bit turned, apart from his balls' (one arc is gone before the next).
|
|
4902
|
+
*/
|
|
4903
|
+
var wave = (p, team = 0) => ({
|
|
4904
|
+
...launch$1(p, team),
|
|
4905
|
+
id: p.shots ^ 128,
|
|
4906
|
+
left: ARC_RANGE,
|
|
4907
|
+
power: 1,
|
|
4908
|
+
arc: p.cut
|
|
4365
4909
|
});
|
|
4366
|
-
/**
|
|
4367
|
-
var
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
return
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4910
|
+
/** Metres the flight `b` goes in a tick. */
|
|
4911
|
+
var stepOf = (b) => b.arc ? ARC_STEP : b.power === 6 ? 2 : PLASMA_STEP;
|
|
4912
|
+
/**
|
|
4913
|
+
* Distance at which the ray from `o` along the unit `d` enters the upright cylinder of radius `r`
|
|
4914
|
+
* on `c`'s feet, `h` tall; Infinity on a miss.
|
|
4915
|
+
*/
|
|
4916
|
+
var cylinder = (o, d, c, r, h) => {
|
|
4917
|
+
const [px, pz] = [o[0] - c.x, o[2] - c.z];
|
|
4918
|
+
const a = d[0] * d[0] + d[2] * d[2];
|
|
4919
|
+
const b = px * d[0] + pz * d[2];
|
|
4920
|
+
const q = b * b - a * (px * px + pz * pz - r * r);
|
|
4921
|
+
let [lo, hi] = [0, Infinity];
|
|
4922
|
+
if (a > 1e-12) {
|
|
4923
|
+
if (q < 0) return Infinity;
|
|
4924
|
+
[lo, hi] = [(-b - Math.sqrt(q)) / a, (-b + Math.sqrt(q)) / a];
|
|
4925
|
+
} else if (px * px + pz * pz > r * r) return Infinity;
|
|
4926
|
+
const [y0, y1] = [c.y - o[1], c.y + h - o[1]];
|
|
4927
|
+
if (d[1]) [lo, hi] = [Math.max(lo, Math.min(y0 / d[1], y1 / d[1])), Math.min(hi, Math.max(y0 / d[1], y1 / d[1]))];
|
|
4928
|
+
else if (y0 > 0 || y1 < 0) return Infinity;
|
|
4929
|
+
return lo <= hi && hi >= 0 ? Math.max(lo, 0) : Infinity;
|
|
4930
|
+
};
|
|
4931
|
+
/**
|
|
4932
|
+
* Flies `b` on by `m` metres (at most what it has left) as a sphere of PLASMA_R: it stops and
|
|
4933
|
+
* bursts on the first brush, or on the first of `foes` whose body (a cylinder PLASMA_R wider, ARC_R
|
|
4934
|
+
* for an arc) it enters. Returns the foe it burst on.
|
|
4935
|
+
*/
|
|
4936
|
+
var fly = (w, b, m, foes) => {
|
|
4937
|
+
const o = [
|
|
4938
|
+
b.x,
|
|
4939
|
+
b.y,
|
|
4940
|
+
b.z
|
|
4941
|
+
];
|
|
4942
|
+
const d = [
|
|
4943
|
+
b.dx,
|
|
4944
|
+
b.dy,
|
|
4945
|
+
b.dz
|
|
4946
|
+
];
|
|
4947
|
+
const go = Math.min(m, b.left);
|
|
4948
|
+
let t = ray(w, o, d, go, PLASMA_R);
|
|
4949
|
+
let hit;
|
|
4950
|
+
for (const f of foes) {
|
|
4951
|
+
const u = cylinder(o, d, f, PLAYER_R + (b.arc ? ARC_R : PLASMA_R), heightOf(f));
|
|
4952
|
+
if (u < t) [t, hit] = [u, f];
|
|
4953
|
+
}
|
|
4954
|
+
b.burst = t < go;
|
|
4955
|
+
b.left -= t;
|
|
4956
|
+
[b.x, b.y, b.z] = [
|
|
4957
|
+
o[0] + d[0] * t,
|
|
4958
|
+
o[1] + d[1] * t,
|
|
4959
|
+
o[2] + d[2] * t
|
|
4960
|
+
];
|
|
4961
|
+
return hit;
|
|
4962
|
+
};
|
|
4963
|
+
/**
|
|
4964
|
+
* The grenade `p` has just launched (`p` the state after that step): from the eye along the look,
|
|
4965
|
+
* with no drift, at NADE_SPEED, NADE_RANGE metres of flight to go. Named by his `shots` like a ball.
|
|
4966
|
+
*/
|
|
4967
|
+
var lob = (p, team = 0) => ({
|
|
4968
|
+
...launch$1({
|
|
4969
|
+
...p,
|
|
4970
|
+
rifled: false
|
|
4971
|
+
}, team),
|
|
4972
|
+
left: 150,
|
|
4973
|
+
power: 7,
|
|
4974
|
+
v: 36
|
|
4975
|
+
});
|
|
4976
|
+
/**
|
|
4977
|
+
* One tick of the grenade `b`: the map's gravity bends its flight, then it flies on as a ball
|
|
4978
|
+
* (fly()) and bursts on the first brush or foe, or at the end of its range. Float32, so the
|
|
4979
|
+
* shooter's client flies the same one.
|
|
4980
|
+
*/
|
|
4981
|
+
var toss = (w, b, foes) => {
|
|
4982
|
+
const f = Math.fround;
|
|
4983
|
+
const [vx, vy, vz] = [
|
|
4984
|
+
b.dx * b.v,
|
|
4985
|
+
b.dy * b.v - gravity(w) / 60,
|
|
4986
|
+
b.dz * b.v
|
|
4987
|
+
];
|
|
4988
|
+
const v = Math.sqrt(vx * vx + vy * vy + vz * vz) || 1;
|
|
4989
|
+
[b.dx, b.dy, b.dz, b.v] = [
|
|
4990
|
+
f(vx / v),
|
|
4991
|
+
f(vy / v),
|
|
4992
|
+
f(vz / v),
|
|
4993
|
+
f(v)
|
|
4994
|
+
];
|
|
4995
|
+
const hit = fly(w, b, b.v / 60, foes);
|
|
4996
|
+
[b.x, b.y, b.z, b.left] = [
|
|
4997
|
+
f(b.x),
|
|
4998
|
+
f(b.y),
|
|
4999
|
+
f(b.z),
|
|
5000
|
+
f(b.left)
|
|
5001
|
+
];
|
|
5002
|
+
b.burst ||= b.left <= 0;
|
|
5003
|
+
return hit;
|
|
5004
|
+
};
|
|
5005
|
+
/**
|
|
5006
|
+
* The health a grenade bursting at `c` takes from `p`: NADE_HP at the body, less with the distance
|
|
5007
|
+
* to its nearest point (the axis, feet to head), nothing from NADE_R on, rounded up. Nothing when
|
|
5008
|
+
* a brush hides both that point and the chest.
|
|
5009
|
+
*/
|
|
5010
|
+
var blast = (w, c, p) => {
|
|
5011
|
+
const h = heightOf(p);
|
|
5012
|
+
const near = [
|
|
5013
|
+
p.x,
|
|
5014
|
+
Math.max(p.y, Math.min(p.y + h, c[1])),
|
|
5015
|
+
p.z
|
|
5016
|
+
];
|
|
5017
|
+
const [dx, dy, dz] = [
|
|
5018
|
+
near[0] - c[0],
|
|
5019
|
+
near[1] - c[1],
|
|
5020
|
+
near[2] - c[2]
|
|
5021
|
+
];
|
|
5022
|
+
const d = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
5023
|
+
return d >= 5 || hidden(w, c, near) && hidden(w, c, [
|
|
5024
|
+
p.x,
|
|
5025
|
+
p.y + .7 * h,
|
|
5026
|
+
p.z
|
|
5027
|
+
]) ? 0 : Math.ceil(5 * (1 - d / 5));
|
|
4391
5028
|
};
|
|
4392
|
-
|
|
4393
|
-
var
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
var
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
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])]
|
|
5029
|
+
// src/shared/bot.ts
|
|
5030
|
+
var { FORWARD, BACK, LEFT, RIGHT, JUMP, SPRINT, DASH, CROUCH, FIRE, RELOAD } = KEY;
|
|
5031
|
+
/** How far a bot shoots, metres, and how far it sees an enemy to fight. */
|
|
5032
|
+
var RANGE = 35;
|
|
5033
|
+
/** Radians off the target a bot still shoots. */
|
|
5034
|
+
var CONE = .06;
|
|
5035
|
+
/** A number in [0, 1) that looks random, the same for the same n. */
|
|
5036
|
+
var frac = (n) => {
|
|
5037
|
+
const s = Math.sin(n * 12.9898) * 43758.5453;
|
|
5038
|
+
return s - Math.floor(s);
|
|
5039
|
+
};
|
|
5040
|
+
/** The character of the bot `id` in a room of this skill. */
|
|
5041
|
+
var personaOf = (id, skill = 4) => {
|
|
5042
|
+
const r = (k) => frac((id + 1) * 7.31 + k);
|
|
5043
|
+
const s = Math.max(0, Math.min(7, skill)) / 7;
|
|
5044
|
+
return {
|
|
5045
|
+
miss: (.3 - .22 * s) * (.75 + .5 * r(1)),
|
|
5046
|
+
react: Math.round((36 - 28 * s) * (.75 + .5 * r(2))),
|
|
5047
|
+
turn: .05 + .09 * s,
|
|
5048
|
+
jumpy: .003 + .012 * r(3),
|
|
5049
|
+
strafe: Math.round(25 + 45 * r(4)),
|
|
5050
|
+
duck: .15 + .75 * s
|
|
5051
|
+
};
|
|
4439
5052
|
};
|
|
4440
|
-
/**
|
|
4441
|
-
var
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
var
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
/**
|
|
4461
|
-
var
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
var
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
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,
|
|
5053
|
+
/** One jump in DASHY that a fighting bot makes is a dash aside instead; metres it wants open for it. */
|
|
5054
|
+
var DASHY = 2;
|
|
5055
|
+
var ASIDE = 3;
|
|
5056
|
+
/** Seconds ahead a bot looks for a ball coming at it, and how close it must pass, metres, to dash. */
|
|
5057
|
+
var WARN = .5;
|
|
5058
|
+
var CLOSE = 1.3;
|
|
5059
|
+
/** Ticks without a metre of progress before a point close by counts as reached, and before a new way. */
|
|
5060
|
+
var STUCK_JUMP = 45;
|
|
5061
|
+
var STUCK_PLAN = 180;
|
|
5062
|
+
/**
|
|
5063
|
+
* Ticks a straight run to a goal is kept before a way is looked for again, and the metres the goal
|
|
5064
|
+
* may move before a new way: DRIFT, or that share of the way to it when it is farther.
|
|
5065
|
+
*/
|
|
5066
|
+
var REPLAN = 120;
|
|
5067
|
+
var DRIFT = 4;
|
|
5068
|
+
var SHARE = .25;
|
|
5069
|
+
/** Metres over the floor under a player in the air past which he is over a gap, not jumping on a roof. */
|
|
5070
|
+
var HOVER = 4;
|
|
5071
|
+
/** Metres from the enemy carrier a bot dashes into him: the tackle. */
|
|
5072
|
+
var TACKLE = 4;
|
|
5073
|
+
/** Metres a bot without a gun goes out of its way to the rack. */
|
|
5074
|
+
var ARM = 30;
|
|
5075
|
+
/**
|
|
5076
|
+
* Metres ahead a walking bot looks for a wall or a drop, the seconds of its speed it looks for the
|
|
5077
|
+
* floor further on (it does not stop at once), and the share of the drop that hurts it will walk into.
|
|
5078
|
+
*/
|
|
5079
|
+
var AHEAD = 1.5;
|
|
5080
|
+
var BRAKE = .3;
|
|
5081
|
+
var SAFE = .8;
|
|
5082
|
+
/** The turns off its way a walking bot tries round a wall or a drop, radians, nearest first: back a little, last. */
|
|
5083
|
+
var DETOURS = [
|
|
4558
5084
|
0,
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
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,
|
|
5085
|
+
.5,
|
|
5086
|
+
-.5,
|
|
5087
|
+
1,
|
|
5088
|
+
-1,
|
|
4570
5089
|
1.5,
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
5090
|
+
-1.5,
|
|
5091
|
+
2,
|
|
5092
|
+
-2
|
|
5093
|
+
];
|
|
5094
|
+
/** The highest box a bot jumps onto on its way, metres (a standing jump lands on 1.7 m), and the floor it wants behind its edge. */
|
|
5095
|
+
var HOP = 1.6;
|
|
5096
|
+
var HOP_DEPTH = 2.5;
|
|
5097
|
+
/** The most a walking bot turns in a tick (12 rad/s), and the turn past which it stops sprinting to strafe. */
|
|
5098
|
+
var WALK_TURN = .2;
|
|
5099
|
+
var SWING = .6;
|
|
5100
|
+
/** Metres of open floor a bot wants ahead to dash, the least way left to bother, and ticks between two of its dashes. */
|
|
5101
|
+
var DASH_RUN = 7;
|
|
5102
|
+
/** Metres more a dash on a route's run wants before the run's end: its speed takes that to fall back. */
|
|
5103
|
+
var LEG_ROOM = 6;
|
|
5104
|
+
/** Metres of floor a dash wants each side of its run. */
|
|
5105
|
+
var WIDE = 1.2;
|
|
5106
|
+
var DASH_FAR = 8;
|
|
5107
|
+
var DASH_GAP = 120;
|
|
5108
|
+
/** Metres of floor a bot wants on the side it strafes to. */
|
|
5109
|
+
var SIDE = 1.5;
|
|
5110
|
+
/** The bots whose id is GUARD - 1 modulo GUARD stay home. */
|
|
5111
|
+
var GUARD = 8;
|
|
5112
|
+
var flat = (ax, az, bx, bz) => Math.sqrt((bx - ax) ** 2 + (bz - az) ** 2);
|
|
5113
|
+
/** Yaw that faces from (x0, z0) toward (x1, z1): yaw 0 looks toward -z. */
|
|
5114
|
+
var toward$1 = (x0, z0, x1, z1) => norm(Math.atan2(-(x1 - x0), -(z1 - z0)));
|
|
5115
|
+
/** The signed turn from a to b, in (-π, π]. */
|
|
5116
|
+
var turn = (a, b) => {
|
|
5117
|
+
const d = norm(b - a);
|
|
5118
|
+
return d > Math.PI ? d - 2 * Math.PI : d;
|
|
5119
|
+
};
|
|
5120
|
+
/** Where a player stands. */
|
|
5121
|
+
var at$1 = (p) => [
|
|
5122
|
+
p.x,
|
|
5123
|
+
p.y,
|
|
5124
|
+
p.z
|
|
5125
|
+
];
|
|
5126
|
+
/** The keys that move toward the yaw `dir` while looking along `yaw`: one of eight. */
|
|
5127
|
+
var keysFor = (yaw, dir) => {
|
|
5128
|
+
const k = Math.round(norm(dir - yaw) / (Math.PI / 4)) % 8;
|
|
5129
|
+
return [
|
|
5130
|
+
FORWARD,
|
|
5131
|
+
FORWARD | LEFT,
|
|
5132
|
+
LEFT,
|
|
5133
|
+
BACK | LEFT,
|
|
5134
|
+
BACK,
|
|
5135
|
+
BACK | RIGHT,
|
|
5136
|
+
RIGHT,
|
|
5137
|
+
FORWARD | RIGHT
|
|
5138
|
+
][k];
|
|
5139
|
+
};
|
|
5140
|
+
var Bot = class {
|
|
5141
|
+
id;
|
|
5142
|
+
/** The route it prefers, an index of nav.ts's ROUTES. */
|
|
5143
|
+
prefer;
|
|
5144
|
+
nav;
|
|
5145
|
+
way = { edges: [] };
|
|
5146
|
+
/** The goal of the way, and the tick it was planned. */
|
|
5147
|
+
goal;
|
|
5148
|
+
planned = 0;
|
|
5149
|
+
/** -1 walking to the way's entry, then the edge it is on; edges.length walking to the goal. */
|
|
5150
|
+
leg = 0;
|
|
5151
|
+
flight;
|
|
5152
|
+
/** The best distance to the point it walks to, and the tick it was last bettered. */
|
|
5153
|
+
best = Infinity;
|
|
5154
|
+
better = 0;
|
|
5155
|
+
ticks = 0;
|
|
5156
|
+
/** Where it aims, the enemy it aims at and since when. */
|
|
5157
|
+
aim = 0;
|
|
5158
|
+
pitch = 0;
|
|
5159
|
+
foe = -1;
|
|
5160
|
+
since = 0;
|
|
5161
|
+
last = [
|
|
5162
|
+
0,
|
|
5163
|
+
0,
|
|
5164
|
+
0
|
|
5165
|
+
];
|
|
5166
|
+
world;
|
|
5167
|
+
/** Where it looks walking, turned a little each tick; the side of its last detour; its last dash. */
|
|
5168
|
+
look = 0;
|
|
5169
|
+
side = 1;
|
|
5170
|
+
dashed = -120;
|
|
5171
|
+
persona;
|
|
5172
|
+
/** Its own random numbers, seeded by its id: the same match plays the same on every host. */
|
|
5173
|
+
seed;
|
|
5174
|
+
/** The way it strafes in a fight (1 left, -1 right) and the tick it may turn back. */
|
|
5175
|
+
strafing = 1;
|
|
5176
|
+
turnBack = 0;
|
|
5177
|
+
/** The balls it has weighed, by shooter and count: it decides once whether to get out of the way. */
|
|
5178
|
+
weighed = /* @__PURE__ */ new Set();
|
|
5179
|
+
constructor(id, skill = 4) {
|
|
5180
|
+
this.id = id;
|
|
5181
|
+
this.prefer = id % ROUTES.length;
|
|
5182
|
+
this.persona = personaOf(id, skill);
|
|
5183
|
+
this.seed = id * 2654435761 + 1;
|
|
5184
|
+
}
|
|
5185
|
+
/** A number in [0, 1) from its own sequence. */
|
|
5186
|
+
rnd() {
|
|
5187
|
+
this.seed = Math.imul(this.seed, 1664525) + 1013904223 >>> 0;
|
|
5188
|
+
return this.seed / 2 ** 32;
|
|
5189
|
+
}
|
|
5190
|
+
/** The input of this tick. */
|
|
5191
|
+
think(s) {
|
|
5192
|
+
const t = ++this.ticks;
|
|
5193
|
+
const p = s.me.state;
|
|
5194
|
+
this.world = s.world;
|
|
5195
|
+
if (p.down) {
|
|
5196
|
+
this.goal = void 0;
|
|
5197
|
+
this.foe = -1;
|
|
5198
|
+
return {
|
|
5199
|
+
keys: 0,
|
|
5200
|
+
yaw: this.aim,
|
|
5201
|
+
pitch: 0
|
|
5202
|
+
};
|
|
5203
|
+
}
|
|
5204
|
+
if (p.ev & EV.RESPAWN || flat(p.x, p.z, this.last[0], this.last[2]) > 5) this.goal = void 0;
|
|
5205
|
+
this.last = at$1(p);
|
|
5206
|
+
const goal = this.goalOf(s);
|
|
5207
|
+
if (!this.goal && !p.ground) return {
|
|
5208
|
+
keys: FORWARD,
|
|
5209
|
+
yaw: p.yaw,
|
|
5210
|
+
pitch: 0
|
|
5211
|
+
};
|
|
5212
|
+
if (p.ground && (!this.goal || flat(goal[0], goal[2], this.goal[0], this.goal[2]) > Math.max(DRIFT, SHARE * flat(p.x, p.z, goal[0], goal[2])) || !this.way.edges.length && t - this.planned > REPLAN)) this.plan(s.world, p, goal);
|
|
5213
|
+
const move = this.pilot(p);
|
|
5214
|
+
const fight = this.fight(s, move.free);
|
|
5215
|
+
const reload = p.ammo > 0 && !p.mag && !p.reload && t & 1 ? RELOAD : 0;
|
|
5216
|
+
if (!fight) {
|
|
5217
|
+
this.pitch = 0;
|
|
5218
|
+
const runs = s.flags[1 - s.me.team].state === FLAG$1.CARRIED && s.flags[1 - s.me.team].by === s.me.id;
|
|
5219
|
+
if (move.exact || runs) {
|
|
5220
|
+
this.look = this.aim = move.yaw;
|
|
5221
|
+
return this.evade(s, {
|
|
5222
|
+
keys: move.keys | reload,
|
|
5223
|
+
yaw: move.yaw,
|
|
5224
|
+
pitch: 0
|
|
5225
|
+
}, move.exact);
|
|
5226
|
+
}
|
|
5227
|
+
const off = turn(this.look, move.yaw);
|
|
5228
|
+
this.look = this.aim = norm(this.look + Math.max(-.2, Math.min(WALK_TURN, off)));
|
|
5229
|
+
const keys = Math.abs(off) > SWING && move.keys & FORWARD ? move.keys & ~(FORWARD | SPRINT | DASH) | keysFor(this.look, move.yaw) : move.keys;
|
|
5230
|
+
return this.evade(s, {
|
|
5231
|
+
keys: keys | reload,
|
|
5232
|
+
yaw: this.look,
|
|
5233
|
+
pitch: 0
|
|
5234
|
+
}, false);
|
|
5235
|
+
}
|
|
5236
|
+
this.look = this.aim;
|
|
5237
|
+
if (fight.keys & DASH) return {
|
|
5238
|
+
keys: fight.keys,
|
|
5239
|
+
yaw: this.aim,
|
|
5240
|
+
pitch: 0
|
|
5241
|
+
};
|
|
5242
|
+
const keys = move.keys & ~(FORWARD | BACK | LEFT | RIGHT | SPRINT);
|
|
5243
|
+
const out = {
|
|
5244
|
+
keys: (move.keys & FORWARD ? keysFor(this.aim, move.yaw) : 0) & ~(LEFT | RIGHT) | this.dodge(s.world, p) | keys | fight.keys | reload,
|
|
5245
|
+
yaw: this.aim,
|
|
5246
|
+
pitch: this.pitch
|
|
5247
|
+
};
|
|
5248
|
+
return this.evade(s, out, false);
|
|
5249
|
+
}
|
|
5250
|
+
/**
|
|
5251
|
+
* How it moves while it fights, as UT2004's bots do: it strafes, one way for a while then the
|
|
5252
|
+
* other, never toward a drop, and now and then jumps or dashes aside (its Jumpiness).
|
|
5253
|
+
*/
|
|
5254
|
+
dodge(w, p) {
|
|
5255
|
+
if (this.ticks >= this.turnBack) {
|
|
5256
|
+
this.strafing = -this.strafing;
|
|
5257
|
+
this.turnBack = this.ticks + this.persona.strafe + Math.floor(this.rnd() * this.persona.strafe);
|
|
5258
|
+
}
|
|
5259
|
+
for (const k of [this.strafing, -this.strafing]) {
|
|
5260
|
+
const yaw = norm(this.aim + k * (Math.PI / 2));
|
|
5261
|
+
const [x, z] = forward(yaw);
|
|
5262
|
+
if (floorAt(w, p.x + x * SIDE, p.z + z * SIDE, p.y + .5) <= p.y - .5) continue;
|
|
5263
|
+
this.strafing = k;
|
|
5264
|
+
const side = k > 0 ? LEFT : RIGHT;
|
|
5265
|
+
if (!p.ground || this.rnd() >= this.persona.jumpy) return side;
|
|
5266
|
+
if (this.rnd() * DASHY < 1 && !(p.held & DASH) && this.ticks - this.dashed > DASH_GAP && this.open(w, p, yaw, ASIDE) === "open") {
|
|
5267
|
+
this.dashed = this.ticks;
|
|
5268
|
+
return side | DASH;
|
|
5269
|
+
}
|
|
5270
|
+
return p.held & JUMP ? side : side | JUMP;
|
|
5271
|
+
}
|
|
5272
|
+
return 0;
|
|
5273
|
+
}
|
|
5274
|
+
/**
|
|
5275
|
+
* Out of the way of a ball coming at it, as UT2004's bots dodge a rocket: an enemy ball that will
|
|
5276
|
+
* pass within CLOSE of its chest in the next WARN seconds is weighed once, and with the bot's
|
|
5277
|
+
* chance it dashes aside, across the ball's way and away from it, where the floor is open.
|
|
5278
|
+
* Not on a leg of a route, nor in the air.
|
|
5279
|
+
*/
|
|
5280
|
+
evade(s, out, exact) {
|
|
5281
|
+
const p = s.me.state;
|
|
5282
|
+
if (exact || !p.ground || p.held & DASH || !s.balls?.length) return out;
|
|
5283
|
+
const chest = p.y + 1.1;
|
|
5284
|
+
for (const b of s.balls) {
|
|
5285
|
+
if (b.team === s.me.team || b.burst || b.v !== void 0) continue;
|
|
5286
|
+
const [ox, oy, oz] = [
|
|
5287
|
+
p.x - b.x,
|
|
5288
|
+
chest - b.y,
|
|
5289
|
+
p.z - b.z
|
|
5290
|
+
];
|
|
5291
|
+
const along = ox * b.dx + oy * b.dy + oz * b.dz;
|
|
5292
|
+
const [mx, my, mz] = [
|
|
5293
|
+
ox - b.dx * along,
|
|
5294
|
+
oy - b.dy * along,
|
|
5295
|
+
oz - b.dz * along
|
|
5296
|
+
];
|
|
5297
|
+
if (!(along > 0 && along / (stepOf(b) * 60) < WARN) || mx * mx + my * my + mz * mz > CLOSE * CLOSE) continue;
|
|
5298
|
+
const key = b.by * 256 + b.id;
|
|
5299
|
+
if (this.weighed.has(key)) continue;
|
|
5300
|
+
if (this.weighed.size > 64) this.weighed.clear();
|
|
5301
|
+
this.weighed.add(key);
|
|
5302
|
+
if (this.rnd() >= this.persona.duck) continue;
|
|
5303
|
+
const first = mx * -b.dz + mz * b.dx >= 0 ? 1 : -1;
|
|
5304
|
+
for (const k of [first, -first]) {
|
|
5305
|
+
const yaw = norm(Math.atan2(k * b.dz, -k * b.dx));
|
|
5306
|
+
if (this.open(s.world, p, yaw, ASIDE) === "open") {
|
|
5307
|
+
this.dashed = this.ticks;
|
|
5308
|
+
const keys = out.keys & ~(FORWARD | BACK | LEFT | RIGHT | SPRINT | JUMP);
|
|
5309
|
+
return {
|
|
5310
|
+
...out,
|
|
5311
|
+
keys: keys | keysFor(out.yaw, yaw) | DASH
|
|
5312
|
+
};
|
|
5313
|
+
}
|
|
5314
|
+
}
|
|
5315
|
+
}
|
|
5316
|
+
return out;
|
|
5317
|
+
}
|
|
5318
|
+
/** Where it wants to be. */
|
|
5319
|
+
goalOf(s) {
|
|
5320
|
+
const { me, others, flags, world } = s;
|
|
5321
|
+
const p = me.state;
|
|
5322
|
+
const { team } = me;
|
|
5323
|
+
const home = world.def.teams[team];
|
|
5324
|
+
const [mine, theirs] = [flags[team], flags[1 - team]];
|
|
5325
|
+
const holder = (f) => {
|
|
5326
|
+
const h = others.find((o) => o.id === f.by)?.state;
|
|
5327
|
+
const y = h && floorAt(world, h.x, h.z, h.y + .5);
|
|
5328
|
+
return h && [
|
|
5329
|
+
h.x,
|
|
5330
|
+
y > h.y - HOVER ? y : h.y,
|
|
5331
|
+
h.z
|
|
5332
|
+
];
|
|
5333
|
+
};
|
|
5334
|
+
if (theirs.state === FLAG$1.CARRIED && theirs.by === me.id) return home.base;
|
|
5335
|
+
if (p.ammo < 0 && home.rack && flat(p.x, p.z, home.rack[0], home.rack[2]) < ARM) return home.rack;
|
|
5336
|
+
if (mine.state === FLAG$1.CARRIED) {
|
|
5337
|
+
const h = holder(mine);
|
|
5338
|
+
if (h) return h;
|
|
5339
|
+
}
|
|
5340
|
+
if (mine.state === FLAG$1.DROPPED) return [
|
|
5341
|
+
mine.x,
|
|
5342
|
+
mine.y,
|
|
5343
|
+
mine.z
|
|
5344
|
+
];
|
|
5345
|
+
if (this.id % GUARD === 7) return home.base;
|
|
5346
|
+
if (theirs.state === FLAG$1.CARRIED) {
|
|
5347
|
+
const h = holder(theirs);
|
|
5348
|
+
if (h) return h;
|
|
5349
|
+
}
|
|
5350
|
+
if (theirs.state === FLAG$1.DROPPED) return [
|
|
5351
|
+
theirs.x,
|
|
5352
|
+
theirs.y,
|
|
5353
|
+
theirs.z
|
|
5354
|
+
];
|
|
5355
|
+
return world.def.teams[1 - team].base;
|
|
5356
|
+
}
|
|
5357
|
+
plan(w, p, goal) {
|
|
5358
|
+
this.goal = goal;
|
|
5359
|
+
this.planned = this.ticks;
|
|
5360
|
+
this.nav = navOf(w);
|
|
5361
|
+
this.way = path(this.nav, w, at$1(p), goal, this.prefer);
|
|
5362
|
+
this.leg = this.way.entry ? -1 : 0;
|
|
5363
|
+
this.flight = void 0;
|
|
5364
|
+
this.best = Infinity;
|
|
5365
|
+
this.better = this.ticks;
|
|
5366
|
+
}
|
|
5367
|
+
/** The point it walks straight to now: the entry, a walk's end, or the goal past the last edge. */
|
|
5368
|
+
target() {
|
|
5369
|
+
const { edges, entry } = this.way;
|
|
5370
|
+
if (this.leg < 0) return entry;
|
|
5371
|
+
const e = edges[this.leg];
|
|
5372
|
+
return e ? this.nav.nodes[e.to] : this.goal;
|
|
5373
|
+
}
|
|
5374
|
+
/**
|
|
5375
|
+
* The keys and yaw of the move, whether the bot may look away from it to shoot, and whether the
|
|
5376
|
+
* yaw must be kept to the letter (a leg of a route, as the tests fly it).
|
|
5377
|
+
*/
|
|
5378
|
+
pilot(p) {
|
|
5379
|
+
const e = this.leg >= 0 ? this.way.edges[this.leg] : void 0;
|
|
5380
|
+
if (e?.leg) return this.fly(p, e.leg);
|
|
5381
|
+
const [x, , z] = this.target();
|
|
5382
|
+
const d = flat(p.x, p.z, x, z);
|
|
5383
|
+
const near = d < 2 && this.ticks - this.better > STUCK_JUMP;
|
|
5384
|
+
if (d < (e || this.leg < 0 ? .5 : 1) || near && this.leg < this.way.edges.length) {
|
|
5385
|
+
if (this.leg < this.way.edges.length) {
|
|
5386
|
+
this.next();
|
|
5387
|
+
return this.pilot(p);
|
|
5388
|
+
}
|
|
5389
|
+
return {
|
|
5390
|
+
keys: 0,
|
|
5391
|
+
yaw: this.aim,
|
|
5392
|
+
free: true,
|
|
5393
|
+
exact: false
|
|
5394
|
+
};
|
|
5395
|
+
}
|
|
5396
|
+
this.unstick(d);
|
|
5397
|
+
return this.walk(p, toward$1(p.x, p.z, x, z), d);
|
|
5398
|
+
}
|
|
5399
|
+
/**
|
|
5400
|
+
* A straight walk toward `want`: round a wall or a drop that hurts by the nearest turn that is open
|
|
5401
|
+
* (on the side it last went round, first), up a box low enough to jump onto, and a dash when the
|
|
5402
|
+
* way ahead is long, straight and open. It steps down onto a lower roof.
|
|
5403
|
+
*/
|
|
5404
|
+
walk(p, want, d) {
|
|
5405
|
+
const w = this.world;
|
|
5406
|
+
let yaw = want;
|
|
5407
|
+
let hop = false;
|
|
5408
|
+
let shut = true;
|
|
5409
|
+
for (const a of DETOURS) {
|
|
5410
|
+
const way = this.open(w, p, norm(want + a * this.side), AHEAD);
|
|
5411
|
+
if (way) {
|
|
5412
|
+
yaw = norm(want + a * this.side);
|
|
5413
|
+
hop = way === "hop";
|
|
5414
|
+
shut = false;
|
|
5415
|
+
if (a) this.side = Math.sign(a * this.side);
|
|
5416
|
+
break;
|
|
5417
|
+
}
|
|
5418
|
+
}
|
|
5419
|
+
if (shut && p.ground) return {
|
|
5420
|
+
keys: 0,
|
|
5421
|
+
yaw,
|
|
5422
|
+
free: true,
|
|
5423
|
+
exact: false
|
|
5424
|
+
};
|
|
5425
|
+
let keys = FORWARD | SPRINT;
|
|
5426
|
+
if (p.ground && hop && !(p.held & JUMP)) keys |= JUMP;
|
|
5427
|
+
if (Math.abs(turn(this.look, yaw)) < .15 && !this.way.edges[this.leg + 1]?.leg) keys |= this.dash(w, p, yaw, d);
|
|
5428
|
+
return {
|
|
5429
|
+
keys,
|
|
5430
|
+
yaw,
|
|
5431
|
+
free: true,
|
|
5432
|
+
exact: false
|
|
5433
|
+
};
|
|
5434
|
+
}
|
|
5435
|
+
/** DASH when the way ahead is long, open and wide and the last dash is a while back, else 0. */
|
|
5436
|
+
dash(w, p, yaw, d) {
|
|
5437
|
+
if (p.ground && d > DASH_FAR && !(p.held & DASH) && this.ticks - this.dashed > DASH_GAP + this.id % 4 * 15 && this.open(w, p, yaw, DASH_RUN) === "open" && this.wide(w, p, yaw)) {
|
|
5438
|
+
this.dashed = this.ticks;
|
|
5439
|
+
return DASH;
|
|
5440
|
+
}
|
|
5441
|
+
return 0;
|
|
5442
|
+
}
|
|
5443
|
+
/** Whether the floor of a dash's run is wide: a metre each side of it, all along, no edge or beam. */
|
|
5444
|
+
wide(w, p, yaw) {
|
|
5445
|
+
const [fx, fz] = forward(yaw);
|
|
5446
|
+
for (let t = 1; t <= DASH_RUN; t++) for (const s of [-1.2, WIDE]) if (floorAt(w, p.x + fx * t - fz * s, p.z + fz * t + fx * s, p.y + .5) < p.y - .5) return false;
|
|
5447
|
+
return true;
|
|
5448
|
+
}
|
|
5449
|
+
/**
|
|
5450
|
+
* Whether a body may walk `ahead` metres along `yaw` from where it stands: 'open', 'hop' over a box
|
|
5451
|
+
* it can jump onto, or false at a wall, the void or a drop that hurts.
|
|
5452
|
+
*/
|
|
5453
|
+
open(w, p, yaw, ahead) {
|
|
5454
|
+
const [fx, fz] = forward(yaw);
|
|
5455
|
+
const hurts = SAFE * 400 / (2 * gravity(w));
|
|
5456
|
+
const far = Math.max(ahead, AHEAD + BRAKE * Math.sqrt(p.vx ** 2 + p.vz ** 2));
|
|
5457
|
+
for (let t = .5; t <= far; t += .5) if (floorAt(w, p.x + fx * t, p.z + fz * t, p.y + HOP) < p.y - hurts) return false;
|
|
5458
|
+
const reach = Math.min(ahead, AHEAD);
|
|
5459
|
+
if (ray(w, [
|
|
5460
|
+
p.x,
|
|
5461
|
+
p.y + 1.9,
|
|
5462
|
+
p.z
|
|
5463
|
+
], [
|
|
5464
|
+
fx,
|
|
5465
|
+
0,
|
|
5466
|
+
fz
|
|
5467
|
+
], reach) < reach) return false;
|
|
5468
|
+
if (ray(w, [
|
|
5469
|
+
p.x,
|
|
5470
|
+
p.y + .5 + .1,
|
|
5471
|
+
p.z
|
|
5472
|
+
], [
|
|
5473
|
+
fx,
|
|
5474
|
+
0,
|
|
5475
|
+
fz
|
|
5476
|
+
], ahead) >= ahead) return "open";
|
|
5477
|
+
if (ahead !== AHEAD) return false;
|
|
5478
|
+
for (let t = 1; t <= HOP_DEPTH; t += .5) if (floorAt(w, p.x + fx * t, p.z + fz * t, p.y + HOP) < p.y - .5) return false;
|
|
5479
|
+
return "hop";
|
|
5480
|
+
}
|
|
5481
|
+
next() {
|
|
5482
|
+
this.leg++;
|
|
5483
|
+
this.flight = void 0;
|
|
5484
|
+
this.best = Infinity;
|
|
5485
|
+
this.better = this.ticks;
|
|
5486
|
+
}
|
|
5487
|
+
/** Counts the progress toward the point it goes to: a new way when there has been none for a while. */
|
|
5488
|
+
unstick(d) {
|
|
5489
|
+
if (d < this.best - 1) [this.best, this.better] = [d, this.ticks];
|
|
5490
|
+
if (this.ticks - this.better > STUCK_PLAN) {
|
|
5491
|
+
this.goal = void 0;
|
|
5492
|
+
this.side = -this.side;
|
|
5493
|
+
}
|
|
5494
|
+
}
|
|
5495
|
+
/** One step of a leg of a route, the way test/routes.ts flies it. */
|
|
5496
|
+
fly(p, leg) {
|
|
5497
|
+
const f = this.flight ??= {
|
|
5498
|
+
leg,
|
|
5499
|
+
k: -1,
|
|
5500
|
+
ran: false,
|
|
5501
|
+
ended: -1
|
|
5502
|
+
};
|
|
5503
|
+
const go = (x, z, r, keys) => {
|
|
5504
|
+
const d = flat(p.x, p.z, x, z);
|
|
5505
|
+
if (d < r || d < 2 && this.ticks - this.better > STUCK_JUMP) return;
|
|
5506
|
+
this.unstick(d);
|
|
5507
|
+
return {
|
|
5508
|
+
keys,
|
|
5509
|
+
yaw: toward$1(p.x, p.z, x, z),
|
|
5510
|
+
free: false,
|
|
5511
|
+
exact: true
|
|
5512
|
+
};
|
|
5513
|
+
};
|
|
5514
|
+
if (leg.k === "go") {
|
|
5515
|
+
const run = go(leg.to[0], leg.to[1], leg.sprint ? .4 : .15, FORWARD | (leg.sprint ? SPRINT : 0));
|
|
5516
|
+
if (run) {
|
|
5517
|
+
const next = this.way.edges[this.leg + 1]?.leg;
|
|
5518
|
+
const dash = leg.sprint && next?.k !== "leap" ? this.dash(this.world, p, run.yaw, flat(p.x, p.z, ...leg.to) - LEG_ROOM) : 0;
|
|
5519
|
+
return {
|
|
5520
|
+
...run,
|
|
5521
|
+
keys: run.keys | dash,
|
|
5522
|
+
free: !this.leapNext()
|
|
5523
|
+
};
|
|
5524
|
+
}
|
|
5525
|
+
if (!p.ground) return {
|
|
5526
|
+
keys: 0,
|
|
5527
|
+
yaw: p.yaw,
|
|
5528
|
+
free: false,
|
|
5529
|
+
exact: true
|
|
5530
|
+
};
|
|
5531
|
+
return this.landed(p, leg);
|
|
5532
|
+
}
|
|
5533
|
+
if (leg.k === "slide") {
|
|
5534
|
+
if (f.x0 === void 0) {
|
|
5535
|
+
const run = go(leg.from[0], leg.from[1], .4, FORWARD | SPRINT);
|
|
5536
|
+
if (run) return run;
|
|
5537
|
+
[f.x0, f.z0] = [p.x, p.z];
|
|
5538
|
+
}
|
|
5539
|
+
const d = flat(p.x, p.z, f.x0, f.z0);
|
|
5540
|
+
const run = go(leg.to[0], leg.to[1], .4, FORWARD | SPRINT | (d >= leg.c[0] && d <= leg.c[1] ? CROUCH : 0));
|
|
5541
|
+
if (run) return run;
|
|
5542
|
+
return p.ground ? this.landed(p, leg) : {
|
|
5543
|
+
keys: 0,
|
|
5544
|
+
yaw: p.yaw,
|
|
5545
|
+
free: false,
|
|
5546
|
+
exact: true
|
|
5547
|
+
};
|
|
5548
|
+
}
|
|
5549
|
+
const keys = FORWARD | (leg.sprint ? SPRINT : 0);
|
|
5550
|
+
const yaw = toward$1(p.x, p.z, leg.to[0], leg.to[1]);
|
|
5551
|
+
if (f.k < 0) {
|
|
5552
|
+
const run = go(leg.at[0], leg.at[1], leg.land ? 1 : .2, keys);
|
|
5553
|
+
if (run) return run;
|
|
5554
|
+
f.k = 0;
|
|
5555
|
+
return {
|
|
5556
|
+
keys: keys | JUMP,
|
|
5557
|
+
yaw,
|
|
5558
|
+
free: false,
|
|
5559
|
+
exact: true
|
|
5560
|
+
};
|
|
5561
|
+
}
|
|
5562
|
+
if (p.ground) return this.landed(p, leg);
|
|
5563
|
+
f.k++;
|
|
5564
|
+
if (p.mode === MODE.WALLRUN) f.ran = true;
|
|
5565
|
+
else if (f.ran && f.ended < 0) f.ended = f.k;
|
|
5566
|
+
if (leg.land) {
|
|
5567
|
+
const [tx, tz] = leg.to;
|
|
5568
|
+
const d = flat(p.x, p.z, tx, tz);
|
|
5569
|
+
const v = (p.vx * (tx - p.x) + p.vz * (tz - p.z)) / (d || 1);
|
|
5570
|
+
const g = gravity(this.world);
|
|
5571
|
+
const t = Math.max((p.vy + Math.sqrt(Math.max(p.vy ** 2 + 2 * g * (p.y - leg.y), 0))) / g, .05);
|
|
5572
|
+
return {
|
|
5573
|
+
keys: v * t < d - .3 ? FORWARD : v * t > d + .3 ? BACK : 0,
|
|
5574
|
+
yaw,
|
|
5575
|
+
free: false,
|
|
5576
|
+
exact: true
|
|
5577
|
+
};
|
|
5578
|
+
}
|
|
5579
|
+
const n = leg.run ? f.ended < 0 ? -1 : f.k - f.ended : f.k;
|
|
5580
|
+
return {
|
|
5581
|
+
keys: (n === leg.dash ? keys | DASH : keys) | (n === leg.double ? JUMP : 0),
|
|
5582
|
+
yaw,
|
|
5583
|
+
free: false,
|
|
5584
|
+
exact: true
|
|
5585
|
+
};
|
|
5586
|
+
}
|
|
5587
|
+
/** Whether the edge after this one is a jump that wants the run-up of this one. */
|
|
5588
|
+
leapNext() {
|
|
5589
|
+
const l = this.way.edges[this.leg + 1]?.leg;
|
|
5590
|
+
return l?.k === "leap" && l.sprint;
|
|
5591
|
+
}
|
|
5592
|
+
/** A leg is over: on to the next on its roof, else a new way from where the bot came down. */
|
|
5593
|
+
landed(p, leg) {
|
|
5594
|
+
if (Math.abs(p.y - leg.y) > .3) {
|
|
5595
|
+
this.goal = void 0;
|
|
5596
|
+
return {
|
|
5597
|
+
keys: 0,
|
|
5598
|
+
yaw: p.yaw,
|
|
5599
|
+
free: false,
|
|
5600
|
+
exact: true
|
|
5601
|
+
};
|
|
5602
|
+
}
|
|
5603
|
+
this.next();
|
|
5604
|
+
return this.pilot(p);
|
|
5605
|
+
}
|
|
5606
|
+
/** The look and the trigger at the enemy to fight now, if any. */
|
|
5607
|
+
fight(s, free) {
|
|
5608
|
+
const { me, others, world, flags } = s;
|
|
5609
|
+
const p = me.state;
|
|
5610
|
+
if (!p.ground) {
|
|
5611
|
+
this.foe = -1;
|
|
5612
|
+
return;
|
|
5613
|
+
}
|
|
5614
|
+
const eye = [
|
|
5615
|
+
p.x,
|
|
5616
|
+
p.y + eyeHeight(p),
|
|
5617
|
+
p.z
|
|
5618
|
+
];
|
|
5619
|
+
const carrier = flags[me.team].state === FLAG$1.CARRIED ? flags[me.team].by : -1;
|
|
5620
|
+
let foe;
|
|
5621
|
+
let best = Infinity;
|
|
5622
|
+
for (const o of others) {
|
|
5623
|
+
const q = o.state;
|
|
5624
|
+
if (o.team === me.team || q.down) continue;
|
|
5625
|
+
const d = flat(p.x, p.z, q.x, q.z);
|
|
5626
|
+
const score = o.id === carrier ? d - RANGE : d;
|
|
5627
|
+
if (d < RANGE && score < best && !hidden(world, eye, [
|
|
5628
|
+
q.x,
|
|
5629
|
+
q.y + 1.2,
|
|
5630
|
+
q.z
|
|
5631
|
+
])) [foe, best] = [o, score];
|
|
5632
|
+
}
|
|
5633
|
+
const carrying = flags[1 - me.team].state === FLAG$1.CARRIED && flags[1 - me.team].by === me.id;
|
|
5634
|
+
if (!foe || !free || carrying) {
|
|
5635
|
+
this.foe = -1;
|
|
5636
|
+
return;
|
|
5637
|
+
}
|
|
5638
|
+
const q = foe.state;
|
|
5639
|
+
if (foe.id !== this.foe) {
|
|
5640
|
+
this.foe = foe.id;
|
|
5641
|
+
this.since = this.ticks;
|
|
5642
|
+
const miss = this.persona.miss;
|
|
5643
|
+
this.aim = norm(p.yaw + (this.rnd() < .5 ? miss : -miss));
|
|
5644
|
+
}
|
|
5645
|
+
const d = flat(p.x, p.z, q.x, q.z);
|
|
5646
|
+
const lead = d / 40;
|
|
5647
|
+
const [tx, ty, tz] = [
|
|
5648
|
+
q.x + q.vx * lead,
|
|
5649
|
+
q.y + 1.1 + q.vy * lead,
|
|
5650
|
+
q.z + q.vz * lead
|
|
5651
|
+
];
|
|
5652
|
+
const want = toward$1(p.x, p.z, tx, tz);
|
|
5653
|
+
const rate = this.persona.turn;
|
|
5654
|
+
this.aim = norm(this.aim + Math.max(-rate, Math.min(rate, turn(this.aim, want))));
|
|
5655
|
+
this.pitch = Math.atan2(ty - eye[1], Math.max(d, .1));
|
|
5656
|
+
const ready = this.ticks - this.since > this.persona.react && Math.abs(turn(this.aim, want)) < CONE;
|
|
5657
|
+
if (foe.id === carrier && d < TACKLE && p.ground && !(p.held & DASH)) return { keys: FORWARD | DASH };
|
|
5658
|
+
const armed = p.ammo > 0 && (p.mag ?? 0) > 0 && !p.wield;
|
|
5659
|
+
return { keys: ready && (armed && d < RANGE || !armed && d < 1.4) && this.ticks & 1 ? FIRE : 0 };
|
|
5660
|
+
}
|
|
5661
|
+
};
|
|
5662
|
+
// src/shared/ctf.ts
|
|
5663
|
+
var home = () => ({
|
|
5664
|
+
state: FLAG$1.HOME,
|
|
5665
|
+
by: 0,
|
|
5666
|
+
x: 0,
|
|
5667
|
+
y: 0,
|
|
5668
|
+
z: 0,
|
|
5669
|
+
left: 0
|
|
4581
5670
|
});
|
|
4582
|
-
|
|
4583
|
-
var
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
5671
|
+
/** How far under a carrier a flag that he drops in the air is looked for a floor, metres. */
|
|
5672
|
+
var FALL = 60;
|
|
5673
|
+
var Ctf = class {
|
|
5674
|
+
/** Captures per team, red then blue. */
|
|
5675
|
+
score = [0, 0];
|
|
5676
|
+
/** The match is over and the end screen shows. */
|
|
5677
|
+
over = false;
|
|
5678
|
+
/** The flag of each team, red then blue. */
|
|
5679
|
+
flags = [home(), home()];
|
|
5680
|
+
world;
|
|
5681
|
+
rules;
|
|
5682
|
+
mates = /* @__PURE__ */ new Map();
|
|
5683
|
+
/** Ticks to the end of the match, or to the next one while it is over. */
|
|
5684
|
+
clock;
|
|
5685
|
+
/** Ticks before each dropped flag goes home. */
|
|
5686
|
+
back = [0, 0];
|
|
5687
|
+
/** Who may not take each flag, and for how many more ticks: the carrier that was made to drop it. */
|
|
5688
|
+
lock = [{
|
|
5689
|
+
id: -1,
|
|
5690
|
+
left: 0
|
|
5691
|
+
}, {
|
|
5692
|
+
id: -1,
|
|
5693
|
+
left: 0
|
|
5694
|
+
}];
|
|
5695
|
+
/** Ticks before a tackled flag can be sent home: it lies there, and the carrier's mates may take it. */
|
|
5696
|
+
hold = [0, 0];
|
|
5697
|
+
constructor(world, rules) {
|
|
5698
|
+
this.world = world;
|
|
5699
|
+
this.rules = rules;
|
|
5700
|
+
this.clock = rules.timeLimit * 60;
|
|
5701
|
+
}
|
|
5702
|
+
/** A player joined, standing at `at`. */
|
|
5703
|
+
join(id, team, at) {
|
|
5704
|
+
this.mates.set(id, {
|
|
5705
|
+
team,
|
|
5706
|
+
caps: 0,
|
|
5707
|
+
returns: 0,
|
|
5708
|
+
ground: [
|
|
5709
|
+
at.x,
|
|
5710
|
+
at.y,
|
|
5711
|
+
at.z
|
|
5712
|
+
]
|
|
5713
|
+
});
|
|
5714
|
+
}
|
|
5715
|
+
/** A player left: a flag he carried is dropped where he last stood. */
|
|
5716
|
+
leave(id) {
|
|
5717
|
+
const k = this.carrying(id);
|
|
5718
|
+
const m = this.mates.get(id);
|
|
5719
|
+
if (k >= 0 && m) this.dropAt(k, m.ground);
|
|
5720
|
+
this.mates.delete(id);
|
|
5721
|
+
}
|
|
5722
|
+
/** A player was put at `at` (a new match): his last ground is there. */
|
|
5723
|
+
place(id, at) {
|
|
5724
|
+
const m = this.mates.get(id);
|
|
5725
|
+
if (m) m.ground = [
|
|
5726
|
+
at.x,
|
|
5727
|
+
at.y,
|
|
5728
|
+
at.z
|
|
5729
|
+
];
|
|
5730
|
+
}
|
|
5731
|
+
/**
|
|
5732
|
+
* The player's state after one move. Under the kill floor and put back at a spawn (EV.RESPAWN),
|
|
5733
|
+
* a carrier drops the flag where he last stood; then a floor under him is his last ground.
|
|
5734
|
+
*/
|
|
5735
|
+
moved(p) {
|
|
5736
|
+
const m = this.mates.get(p.id);
|
|
5737
|
+
if (!m) return;
|
|
5738
|
+
const k = this.carrying(p.id);
|
|
5739
|
+
if (p.ev & EV.RESPAWN && k >= 0) this.dropAt(k, m.ground);
|
|
5740
|
+
if (p.ground) m.ground = [
|
|
5741
|
+
p.x,
|
|
5742
|
+
p.y,
|
|
5743
|
+
p.z
|
|
5744
|
+
];
|
|
5745
|
+
}
|
|
5746
|
+
/**
|
|
5747
|
+
* Makes the player drop the flag he carries (the tackle of step 7). It lies under him: where he
|
|
5748
|
+
* stands, or on the first floor below him, or at his last ground when there is none (over the
|
|
5749
|
+
* void). False when he carried nothing.
|
|
5750
|
+
*/
|
|
5751
|
+
drop(p) {
|
|
5752
|
+
const k = this.carrying(p.id);
|
|
5753
|
+
const m = this.mates.get(p.id);
|
|
5754
|
+
if (k < 0 || !m || this.over) return false;
|
|
5755
|
+
let at = m.ground;
|
|
5756
|
+
if (p.ground) at = [
|
|
5757
|
+
p.x,
|
|
5758
|
+
p.y,
|
|
5759
|
+
p.z
|
|
5760
|
+
];
|
|
5761
|
+
else {
|
|
5762
|
+
const d = ray(this.world, [
|
|
5763
|
+
p.x,
|
|
5764
|
+
p.y + .05,
|
|
5765
|
+
p.z
|
|
5766
|
+
], [
|
|
5767
|
+
0,
|
|
5768
|
+
-1,
|
|
5769
|
+
0
|
|
5770
|
+
], FALL);
|
|
5771
|
+
if (d < FALL) at = [
|
|
5772
|
+
p.x,
|
|
5773
|
+
p.y + .05 - d,
|
|
5774
|
+
p.z
|
|
5775
|
+
];
|
|
5776
|
+
}
|
|
5777
|
+
this.dropAt(k, at);
|
|
5778
|
+
this.lock[k] = {
|
|
5779
|
+
id: p.id,
|
|
5780
|
+
left: 120
|
|
5781
|
+
};
|
|
5782
|
+
this.hold[k] = 120;
|
|
5783
|
+
return true;
|
|
5784
|
+
}
|
|
5785
|
+
/** The team whose flag the player carries, or -1. */
|
|
5786
|
+
carrying(id) {
|
|
5787
|
+
return this.flags.findIndex((f) => f.state === FLAG$1.CARRIED && f.by === id);
|
|
5788
|
+
}
|
|
5789
|
+
/** The winning team of a match that is over, or -1 for a draw. */
|
|
5790
|
+
winner() {
|
|
5791
|
+
const [r, b] = this.score;
|
|
5792
|
+
return r > b ? 0 : b > r ? 1 : -1;
|
|
5793
|
+
}
|
|
5794
|
+
/** What every player has done this match. */
|
|
5795
|
+
tally() {
|
|
5796
|
+
return [...this.mates].map(([id, m]) => ({
|
|
5797
|
+
id,
|
|
5798
|
+
caps: m.caps,
|
|
5799
|
+
returns: m.returns
|
|
5800
|
+
}));
|
|
5801
|
+
}
|
|
5802
|
+
/** The room is empty: the next match starts from scratch. */
|
|
5803
|
+
reset() {
|
|
5804
|
+
this.over = false;
|
|
5805
|
+
this.score = [0, 0];
|
|
5806
|
+
this.flags = [home(), home()];
|
|
5807
|
+
this.back = [0, 0];
|
|
5808
|
+
this.lock.forEach((l) => l.left = 0);
|
|
5809
|
+
this.hold = [0, 0];
|
|
5810
|
+
this.clock = this.rules.timeLimit * 60;
|
|
5811
|
+
for (const m of this.mates.values()) m.caps = m.returns = 0;
|
|
5812
|
+
}
|
|
5813
|
+
/** The part of a snapshot that is the match's. */
|
|
5814
|
+
wire() {
|
|
5815
|
+
return {
|
|
5816
|
+
score: [...this.score],
|
|
5817
|
+
clock: Math.ceil(this.clock / 60),
|
|
5818
|
+
over: this.over,
|
|
5819
|
+
flags: this.flags.map((f) => ({ ...f }))
|
|
5820
|
+
};
|
|
5821
|
+
}
|
|
5822
|
+
/**
|
|
5823
|
+
* One host tick over the players: the dropped flags run down, flags are taken, returned and
|
|
5824
|
+
* captured, the clock runs. 'end' when the match has just ended, 'start' when the end screen is
|
|
5825
|
+
* done and a new match begins (the room puts everyone back at a spawn).
|
|
5826
|
+
*/
|
|
5827
|
+
tick(players) {
|
|
5828
|
+
if (this.over) {
|
|
5829
|
+
if (--this.clock <= 0) {
|
|
5830
|
+
this.reset();
|
|
5831
|
+
return "start";
|
|
5832
|
+
}
|
|
5833
|
+
return;
|
|
5834
|
+
}
|
|
5835
|
+
for (const k of [0, 1]) {
|
|
5836
|
+
const f = this.flags[k];
|
|
5837
|
+
this.lock[k].left--;
|
|
5838
|
+
this.hold[k]--;
|
|
5839
|
+
if (f.state === FLAG$1.DROPPED) {
|
|
5840
|
+
f.left = Math.ceil(--this.back[k] / 60);
|
|
5841
|
+
if (this.back[k] <= 0) this.flags[k] = home();
|
|
5842
|
+
}
|
|
5843
|
+
}
|
|
5844
|
+
for (const k of [0, 1]) {
|
|
5845
|
+
const f = this.flags[k];
|
|
5846
|
+
if (f.state === FLAG$1.CARRIED) continue;
|
|
5847
|
+
const at = f.state === FLAG$1.HOME ? this.world.def.teams[k].base : [
|
|
5848
|
+
f.x,
|
|
5849
|
+
f.y,
|
|
5850
|
+
f.z
|
|
5851
|
+
];
|
|
5852
|
+
const near = players.filter((q) => touches(q.state, at));
|
|
5853
|
+
const mate = f.state === FLAG$1.DROPPED && this.hold[k] <= 0 ? near.find((q) => q.team === k) : void 0;
|
|
5854
|
+
const foe = near.find((q) => q.team !== k && (q.id !== this.lock[k].id || this.lock[k].left <= 0));
|
|
5855
|
+
if (mate) {
|
|
5856
|
+
const m = this.mates.get(mate.id);
|
|
5857
|
+
if (m) m.returns++;
|
|
5858
|
+
this.flags[k] = home();
|
|
5859
|
+
} else if (foe) this.flags[k] = {
|
|
5860
|
+
...home(),
|
|
5861
|
+
state: FLAG$1.CARRIED,
|
|
5862
|
+
by: foe.id
|
|
5863
|
+
};
|
|
5864
|
+
}
|
|
5865
|
+
for (const p of players) {
|
|
5866
|
+
const k = this.carrying(p.id);
|
|
5867
|
+
if (k >= 0 && this.flags[p.team].state === FLAG$1.HOME && touches(p.state, this.world.def.teams[p.team].base)) {
|
|
5868
|
+
this.score[p.team]++;
|
|
5869
|
+
const m = this.mates.get(p.id);
|
|
5870
|
+
if (m) m.caps++;
|
|
5871
|
+
this.flags[k] = home();
|
|
5872
|
+
}
|
|
5873
|
+
}
|
|
5874
|
+
if (this.score.some((s) => s >= this.rules.scoreLimit) || --this.clock <= 0) {
|
|
5875
|
+
this.over = true;
|
|
5876
|
+
this.clock = 600;
|
|
5877
|
+
return "end";
|
|
5878
|
+
}
|
|
5879
|
+
}
|
|
5880
|
+
dropAt(k, [x, y, z]) {
|
|
5881
|
+
this.flags[k] = {
|
|
5882
|
+
state: FLAG$1.DROPPED,
|
|
5883
|
+
by: 0,
|
|
4595
5884
|
x,
|
|
4596
5885
|
y,
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
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
|
|
5886
|
+
z,
|
|
5887
|
+
left: 10
|
|
5888
|
+
};
|
|
5889
|
+
this.back[k] = 600;
|
|
4764
5890
|
}
|
|
4765
5891
|
};
|
|
4766
|
-
/**
|
|
4767
|
-
var
|
|
4768
|
-
|
|
4769
|
-
var
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
var launch = (p, team = 0) => {
|
|
4783
|
-
const [dy, dp] = p.rifled ? drift(p.shots) : [0, 0];
|
|
4784
|
-
const [yaw, pitch] = [p.yaw + dy, p.pitch + dp];
|
|
4785
|
-
const [sy, cy, sp, cp] = [
|
|
4786
|
-
Math.sin(yaw),
|
|
4787
|
-
Math.cos(yaw),
|
|
4788
|
-
Math.sin(pitch),
|
|
4789
|
-
Math.cos(pitch)
|
|
4790
|
-
];
|
|
4791
|
-
return {
|
|
4792
|
-
id: p.shots,
|
|
4793
|
-
by: p.id,
|
|
4794
|
-
team,
|
|
4795
|
-
x: p.x,
|
|
4796
|
-
y: p.y + eyeHeight(p),
|
|
4797
|
-
z: p.z,
|
|
4798
|
-
dx: -sy * cp,
|
|
4799
|
-
dy: sp,
|
|
4800
|
-
dz: -cy * cp,
|
|
4801
|
-
left: p.rifled ? 60 : 80,
|
|
4802
|
-
burst: false,
|
|
4803
|
-
power: p.rifled ? 0 : p.power ?? 1
|
|
4804
|
-
};
|
|
5892
|
+
/** Whether the player's body reaches the flag foot at `at`: close enough, and overlapping its height. */
|
|
5893
|
+
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];
|
|
5894
|
+
// src/shared/doors.ts
|
|
5895
|
+
var DOOR = {
|
|
5896
|
+
/**
|
|
5897
|
+
* Metres from the doorway within which a player on foot opens it, and a driven rover. A dash
|
|
5898
|
+
* 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
|
|
5899
|
+
* 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.
|
|
5900
|
+
*/
|
|
5901
|
+
R: 7,
|
|
5902
|
+
ROVER_R: 14,
|
|
5903
|
+
/** Ticks it takes to open (0.35 s) and to shut (0.5 s). */
|
|
5904
|
+
OPEN: 21,
|
|
5905
|
+
SHUT: 30,
|
|
5906
|
+
/** Ticks it stays open after the last one has left: a second. */
|
|
5907
|
+
HOLD: 60
|
|
4805
5908
|
};
|
|
5909
|
+
/** How far `p` is from the doorway on the floor plane, Infinity when its feet are not at its height. */
|
|
5910
|
+
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);
|
|
4806
5911
|
/**
|
|
4807
|
-
*
|
|
4808
|
-
*
|
|
4809
|
-
*
|
|
5912
|
+
* One tick of the doors of `w`: each opens while one of `feet` (the players who are up) is within
|
|
5913
|
+
* DOOR.R of it or one of `rovers` (the driven ones) within DOOR.ROVER_R, stays open DOOR.HOLD ticks
|
|
5914
|
+
* after the last, then shuts.
|
|
4810
5915
|
*/
|
|
4811
|
-
var
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
5916
|
+
var swing = (w, feet, rovers = []) => w.doors?.forEach((s, i) => {
|
|
5917
|
+
const d = w.def.doors[i];
|
|
5918
|
+
const near = feet.some((p) => off(d, p) < DOOR.R) || rovers.some((p) => off(d, p) < DOOR.ROVER_R);
|
|
5919
|
+
const all = DOOR.OPEN * DOOR.SHUT;
|
|
5920
|
+
const at = Math.round(s.open * all) + (near || s.wait ? DOOR.SHUT : -DOOR.OPEN);
|
|
5921
|
+
s.open = Math.min(all, Math.max(0, at)) / all;
|
|
5922
|
+
s.wait = near ? DOOR.HOLD : Math.max(0, s.wait - 1);
|
|
4817
5923
|
});
|
|
4818
|
-
/**
|
|
4819
|
-
var
|
|
5924
|
+
/** Every door shut: a new match. */
|
|
5925
|
+
var shut = (w) => w.doors?.forEach((s) => {
|
|
5926
|
+
s.open = s.wait = 0;
|
|
5927
|
+
});
|
|
5928
|
+
// src/shared/gun.ts
|
|
5929
|
+
/** Whether the feet of `p` are within `r` of the point `at` on the floor plane and within PICK_H of its height. */
|
|
5930
|
+
var within = (p, at, r) => {
|
|
5931
|
+
const [dx, dz] = [p.x - at[0], p.z - at[2]];
|
|
5932
|
+
return dx * dx + dz * dz < r * r && Math.abs(p.y - at[1]) < 1;
|
|
5933
|
+
};
|
|
4820
5934
|
/**
|
|
4821
|
-
*
|
|
4822
|
-
*
|
|
5935
|
+
* The start of a cut that moves the body, from a floor only: the lunge throws him along the look at
|
|
5936
|
+
* LUNGE_SPEED for the burst of a dash, and spends the dash; the leap jumps him LEAP_SPEED up.
|
|
4823
5937
|
*/
|
|
4824
|
-
var
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
5938
|
+
var launch = (p) => {
|
|
5939
|
+
if (p.mode !== MODE.GROUND) return;
|
|
5940
|
+
if (p.cut === CUT.LUNGE) {
|
|
5941
|
+
const [fx, fz] = forward(p.yaw);
|
|
5942
|
+
p.vx = fx * 13;
|
|
5943
|
+
p.vz = fz * 13;
|
|
5944
|
+
p.dash = 60;
|
|
5945
|
+
p.ev |= EV.DASH;
|
|
5946
|
+
} else if (p.cut === CUT.LEAP) {
|
|
5947
|
+
p.vy = LEAP_SPEED;
|
|
5948
|
+
p.ev |= EV.JUMP;
|
|
5949
|
+
}
|
|
5950
|
+
};
|
|
5951
|
+
/** 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. */
|
|
5952
|
+
var STRIKE = {
|
|
5953
|
+
NONE: 0,
|
|
5954
|
+
SHOT: 1,
|
|
5955
|
+
CUT: 2,
|
|
5956
|
+
RAIL: 3,
|
|
5957
|
+
LASER: 4,
|
|
5958
|
+
NADE: 5
|
|
4838
5959
|
};
|
|
4839
5960
|
/**
|
|
4840
|
-
*
|
|
4841
|
-
*
|
|
4842
|
-
*
|
|
5961
|
+
* One input: the move, then the weapons. Returns what struck on this step (STRIKE), for the host to
|
|
5962
|
+
* resolve it: a shot, or a cut, which is not a shot.
|
|
5963
|
+
* - Down: the keys are dropped, and when `down` runs out the player is back at a spawn.
|
|
5964
|
+
* - The team's rack fills the gun when the player steps into its circle (`rack` tells he is in it),
|
|
5965
|
+
* and again each time he comes back; staying gives nothing. The katana rack gives the katana,
|
|
5966
|
+
* once and for good: it stays until he goes down.
|
|
5967
|
+
* - The rail rack fills the rail gun with RAIL_MAX ticks of lightning on arrival, as the gun's does.
|
|
5968
|
+
* - In hand is the weapon he wants (KEY.BLADE the katana, KEY.RAIL the rail gun, neither the gun)
|
|
5969
|
+
* when he has it, else the first he has of the gun, the katana and the rail gun; the katana
|
|
5970
|
+
* stays in hand for the length of a swing. `wield` is the katana in hand, `railed` the rail gun.
|
|
5971
|
+
* - The gun fires from its battery (`mag`), the rail gun from its capsule (`cap`). An empty one, or
|
|
5972
|
+
* KEY.RELOAD with room in it, swaps it for a full one from what he carries: `reload` ticks
|
|
5973
|
+
* without firing, then it holds the kit's `mag` (`cap`, `clip`) or what is left. A switch of weapon drops it.
|
|
5974
|
+
* The racks fill both.
|
|
5975
|
+
* - The rail gun throws its bolt on every step FIRE is held, spending a tick of it (`zapping`),
|
|
5976
|
+
* unless it is `hot`: its `heat` rises while it fires and falls when it does not (HEAT_MAX).
|
|
5977
|
+
* - The laser rifle (KEY.RIFLE, `rifled`), filled at its rack on arrival, fires a round from its
|
|
5978
|
+
* cell (`clip`) each RIFLE_COOL ticks while FIRE is held (STRIKE.LASER). Its rack loads NADE_MAX
|
|
5979
|
+
* grenades too: SPECIAL (G) launches one (STRIKE.NADE) when `lob` is 0, even during
|
|
5980
|
+
* a swap of the cell, then `lob` runs NADE_COOL ticks and the rifle holds its fire NADE_HOLD.
|
|
5981
|
+
* - The trigger: `cool` and `swing` run down, and at 0 a held FIRE charges the gun, with ammo, and
|
|
5982
|
+
* letting it go fires a ball as strong as the charge (powerOf()), spending as many shots; or it
|
|
5983
|
+
* starts the katana's swing (`cut` from the keys), unless the hands are busy (a hang, a climb).
|
|
5984
|
+
* The katana in hand, busy hands or no shot left drop the charge.
|
|
5985
|
+
* With SPECIAL (a double click) the swing is the cut's special; its press within SPECIAL_LATE
|
|
5986
|
+
* ticks of a cut's start turns that cut into it. The cut strikes `CUTS[cut].strike` ticks into
|
|
5987
|
+
* its swing. The look is the input's, so both go where the player sees.
|
|
5988
|
+
* `armed` is false while the match is over: no weapon, no rack. `bodies` are move()'s.
|
|
4843
5989
|
*/
|
|
4844
|
-
var
|
|
4845
|
-
const
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
5990
|
+
var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
|
|
5991
|
+
const down = p.down > 0;
|
|
5992
|
+
const locked = !down && (p.lock ?? 0) > 0;
|
|
5993
|
+
move(p, down || locked ? {
|
|
5994
|
+
...i,
|
|
5995
|
+
keys: 0
|
|
5996
|
+
} : i, w, team, bodies, kit);
|
|
5997
|
+
p.heat = Math.max(0, (p.heat ?? 0) - (p.zapping ? 0 : p.hot ? 1 : 2));
|
|
5998
|
+
p.hot = !!p.hot && p.heat > 0;
|
|
5999
|
+
p.zapping = false;
|
|
6000
|
+
p.zap = !!p.stun && !!p.zap;
|
|
6001
|
+
if (down) {
|
|
6002
|
+
if (p.down > 0 && !--p.down) respawn(p, w, team);
|
|
6003
|
+
return STRIKE.NONE;
|
|
6004
|
+
}
|
|
6005
|
+
if (locked) return duel(p, i);
|
|
6006
|
+
const { rack, blade, rail, rifle } = w.def.teams[team];
|
|
6007
|
+
const inside = !!rack && within(p, rack, 1.2);
|
|
6008
|
+
if (armed && inside && !p.rack) [p.ammo, p.mag] = [kit.ammo, kit.mag];
|
|
6009
|
+
p.rack = inside;
|
|
6010
|
+
p.blade = !!p.blade || armed && !!blade && within(p, blade, 1.2);
|
|
6011
|
+
const inRail = !!rail && within(p, rail, 1.2);
|
|
6012
|
+
if (armed && inRail && !p.inRail) [p.rail, p.cap] = [kit.rail, kit.cap];
|
|
6013
|
+
p.inRail = inRail;
|
|
6014
|
+
const inRifle = !!rifle && within(p, rifle, 1.2);
|
|
6015
|
+
if (armed && inRifle && !p.inRifle) [p.rifle, p.clip, p.nades] = [
|
|
6016
|
+
kit.rifle,
|
|
6017
|
+
kit.clip,
|
|
6018
|
+
3
|
|
4849
6019
|
];
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
6020
|
+
p.inRifle = inRifle;
|
|
6021
|
+
p.ammo = Math.min(p.ammo, kit.ammo);
|
|
6022
|
+
p.rail = p.rail === void 0 ? p.rail : Math.min(p.rail, kit.rail);
|
|
6023
|
+
p.rifle = p.rifle === void 0 ? p.rifle : Math.min(p.rifle, kit.rifle);
|
|
6024
|
+
[p.mag, p.cap, p.clip] = [
|
|
6025
|
+
Math.min(p.mag ?? 0, kit.mag),
|
|
6026
|
+
Math.min(p.cap ?? 0, kit.cap),
|
|
6027
|
+
Math.min(p.clip ?? 0, kit.clip)
|
|
4854
6028
|
];
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
6029
|
+
p.cool = Math.max(0, p.cool - 1);
|
|
6030
|
+
p.lob = Math.max(0, (p.lob ?? 0) - 1);
|
|
6031
|
+
const busy = p.mode === MODE.HANG || p.mode === MODE.CLIMB;
|
|
6032
|
+
const { ticks, hold } = CUTS[p.cut ?? 0];
|
|
6033
|
+
const top = !!p.swing && !p.heavy && ticks - (p.swing ?? 0) === hold;
|
|
6034
|
+
if (top && p.wield && armed && !busy && i.keys & KEY.FIRE) p.charge = Math.min((p.charge ?? 0) + 1, HEAVY_MAX);
|
|
6035
|
+
else if (top && armed && !busy && (p.charge ?? 0) >= HEAVY_TAP) {
|
|
6036
|
+
[p.heavy, p.charge] = [true, 0];
|
|
6037
|
+
p.swing = swingOf(p).ticks;
|
|
6038
|
+
} else {
|
|
6039
|
+
p.charge = top ? 0 : p.charge;
|
|
6040
|
+
const s = p.swing ?? 0;
|
|
6041
|
+
const c = swingOf(p);
|
|
6042
|
+
const stop = (v) => v == s - 1 && (v == c.ticks - c.strike || v == PUNCH.ticks - PUNCH.strike || !p.heavy && v == ticks - hold);
|
|
6043
|
+
p.swing = Math.max(0, kit.haste > 1 && stop(s - 1) ? s - 1 : s - kit.haste);
|
|
6044
|
+
p.heavy = !!p.swing && !!p.heavy;
|
|
4861
6045
|
}
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
];
|
|
4869
|
-
return hit;
|
|
4870
|
-
};
|
|
4871
|
-
/**
|
|
4872
|
-
* The grenade `p` has just launched (`p` the state after that step): from the eye along the look,
|
|
4873
|
-
* with no drift, at NADE_SPEED, NADE_RANGE metres of flight to go. Named by his `shots` like a ball.
|
|
4874
|
-
*/
|
|
4875
|
-
var lob = (p, team = 0) => ({
|
|
4876
|
-
...launch({
|
|
4877
|
-
...p,
|
|
4878
|
-
rifled: false
|
|
4879
|
-
}, team),
|
|
4880
|
-
left: 150,
|
|
4881
|
-
power: 7,
|
|
4882
|
-
v: 36
|
|
4883
|
-
});
|
|
4884
|
-
/**
|
|
4885
|
-
* One tick of the grenade `b`: the map's gravity bends its flight, then it flies on as a ball
|
|
4886
|
-
* (fly()) and bursts on the first brush or foe, or at the end of its range. Float32, so the
|
|
4887
|
-
* shooter's client flies the same one.
|
|
4888
|
-
*/
|
|
4889
|
-
var toss = (w, b, foes) => {
|
|
4890
|
-
const f = Math.fround;
|
|
4891
|
-
const [vx, vy, vz] = [
|
|
4892
|
-
b.dx * b.v,
|
|
4893
|
-
b.dy * b.v - gravity(w) / 60,
|
|
4894
|
-
b.dz * b.v
|
|
6046
|
+
p.mag = Math.min(p.mag ?? 0, Math.max(p.ammo, 0));
|
|
6047
|
+
const has = [
|
|
6048
|
+
p.ammo >= 0,
|
|
6049
|
+
!!p.blade,
|
|
6050
|
+
(p.rail ?? -1) >= 0,
|
|
6051
|
+
(p.rifle ?? -1) >= 0
|
|
4895
6052
|
];
|
|
4896
|
-
const
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
6053
|
+
const want = i.keys & KEY.BLADE ? 1 : i.keys & KEY.RAIL ? 2 : i.keys & KEY.RIFLE ? 3 : 0;
|
|
6054
|
+
const hand = p.swing && p.blade ? 1 : has[want] ? want : has.indexOf(true);
|
|
6055
|
+
if (hand != (p.rifled ? 3 : p.railed ? 2 : +!!p.wield)) p.reload = 0;
|
|
6056
|
+
[p.wield, p.railed, p.rifled] = [
|
|
6057
|
+
hand == 1,
|
|
6058
|
+
hand == 2,
|
|
6059
|
+
hand == 3
|
|
4902
6060
|
];
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
6061
|
+
if (p.swing && hand >= 0 && !p.blade) p.swing = 0;
|
|
6062
|
+
if (!armed) {
|
|
6063
|
+
[p.charge, p.reload] = [0, 0];
|
|
6064
|
+
return STRIKE.NONE;
|
|
6065
|
+
}
|
|
6066
|
+
const [key, size, carried, ticks2] = hand == 3 ? [
|
|
6067
|
+
"clip",
|
|
6068
|
+
kit.clip,
|
|
6069
|
+
p.rifle,
|
|
6070
|
+
96
|
|
6071
|
+
] : hand == 2 ? [
|
|
6072
|
+
"cap",
|
|
6073
|
+
kit.cap,
|
|
6074
|
+
p.rail,
|
|
6075
|
+
90
|
|
6076
|
+
] : [
|
|
6077
|
+
"mag",
|
|
6078
|
+
kit.mag,
|
|
6079
|
+
p.ammo,
|
|
6080
|
+
78
|
|
4909
6081
|
];
|
|
4910
|
-
|
|
4911
|
-
|
|
6082
|
+
const [load, full] = [p[key] ?? 0, Math.min(size, carried)];
|
|
6083
|
+
if (p.reload) {
|
|
6084
|
+
if (!--p.reload) p[key] = full;
|
|
6085
|
+
} else if (hand != 1 && carried >= 0 && !busy && load < full && (!load || i.keys & KEY.RELOAD)) [p.reload, p.charge] = [ticks2, 0];
|
|
6086
|
+
const bare = hand < 0;
|
|
6087
|
+
const c = bare ? PUNCH : swingOf(p);
|
|
6088
|
+
if (p.swing && c.ticks - p.swing === c.strike) return STRIKE.CUT;
|
|
6089
|
+
if (p.wield && !top || p.railed || p.rifled || busy || p.reload || !p.wield && !p.mag) p.charge = 0;
|
|
6090
|
+
if (p.rifled && i.keys & KEY.SPECIAL && !busy && p.nades && !p.lob) {
|
|
6091
|
+
p.nades--;
|
|
6092
|
+
[p.lob, p.cool] = [60, 7];
|
|
6093
|
+
p.shots = p.shots + 1 & 255;
|
|
6094
|
+
return STRIKE.NADE;
|
|
6095
|
+
}
|
|
6096
|
+
if (i.keys & KEY.FIRE && !busy) {
|
|
6097
|
+
const late = CUTS[p.cut ?? 0].ticks - (p.swing ?? 0);
|
|
6098
|
+
const special = !!(i.keys & KEY.SPECIAL) && (!p.swing || !p.heavy && (p.cut ?? 0) < 4 && late <= 18);
|
|
6099
|
+
if (bare) {
|
|
6100
|
+
if (!p.swing) [p.cut, p.heavy, p.swing] = [
|
|
6101
|
+
0,
|
|
6102
|
+
false,
|
|
6103
|
+
PUNCH.ticks
|
|
6104
|
+
];
|
|
6105
|
+
} else if (p.wield && (!p.swing || special)) {
|
|
6106
|
+
p.cut = cutOf(i.keys) + (special ? 4 : 0);
|
|
6107
|
+
[p.swing, p.charge] = [CUTS[p.cut].ticks, 0];
|
|
6108
|
+
launch(p);
|
|
6109
|
+
} else if (p.rifled) {
|
|
6110
|
+
if (!p.cool && p.clip && !p.reload) {
|
|
6111
|
+
p.rifle--;
|
|
6112
|
+
p.clip--;
|
|
6113
|
+
p.cool = kit.rifleCool;
|
|
6114
|
+
p.shots = p.shots + 1 & 255;
|
|
6115
|
+
return STRIKE.LASER;
|
|
6116
|
+
}
|
|
6117
|
+
} else if (p.railed) {
|
|
6118
|
+
if (p.cap && !p.reload && !p.hot) {
|
|
6119
|
+
p.heat = (p.heat ?? 0) + 1;
|
|
6120
|
+
p.hot = p.heat >= 120;
|
|
6121
|
+
if (!p.cool) {
|
|
6122
|
+
p.rail--;
|
|
6123
|
+
p.cap--;
|
|
6124
|
+
p.cool = 2;
|
|
6125
|
+
}
|
|
6126
|
+
p.zapping = true;
|
|
6127
|
+
return STRIKE.RAIL;
|
|
6128
|
+
}
|
|
6129
|
+
} else if (!p.wield && !p.cool && p.mag && !p.reload) p.charge = Math.min((p.charge ?? 0) + 1, 60);
|
|
6130
|
+
} else if (p.charge) {
|
|
6131
|
+
p.power = Math.min(powerOf(p.charge), p.mag);
|
|
6132
|
+
p.charge = 0;
|
|
6133
|
+
p.ammo -= p.power;
|
|
6134
|
+
p.mag = p.mag - p.power;
|
|
6135
|
+
p.shots = p.shots + 1 & 255;
|
|
6136
|
+
p.cool = kit.cool;
|
|
6137
|
+
return STRIKE.SHOT;
|
|
6138
|
+
}
|
|
6139
|
+
return STRIKE.NONE;
|
|
4912
6140
|
};
|
|
4913
6141
|
/**
|
|
4914
|
-
*
|
|
4915
|
-
*
|
|
4916
|
-
*
|
|
6142
|
+
* A step in a saber lock: the blade stays in hand and no cut starts. Each FIRE press (FIRE held
|
|
6143
|
+
* now, not at the last step) pushes; a side or back key held counts `away`, up to LOCK_BREAK. The
|
|
6144
|
+
* lock runs down to 1, where it waits for the host, who parts the two (room.ts).
|
|
4917
6145
|
*/
|
|
4918
|
-
var
|
|
4919
|
-
const
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
]
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
near[2] - c[2]
|
|
6146
|
+
var duel = (p, i) => {
|
|
6147
|
+
const fire = !!(i.keys & KEY.FIRE);
|
|
6148
|
+
p.pushes = (p.pushes ?? 0) + +(fire && !p.pressed) & 255;
|
|
6149
|
+
p.pressed = fire;
|
|
6150
|
+
p.away = i.keys & (KEY.LEFT | KEY.RIGHT | KEY.BACK) ? Math.min((p.away ?? 0) + 1, 24) : 0;
|
|
6151
|
+
p.lock = Math.max(1, p.lock - 1);
|
|
6152
|
+
[p.wield, p.swing, p.charge] = [
|
|
6153
|
+
true,
|
|
6154
|
+
0,
|
|
6155
|
+
0
|
|
4929
6156
|
];
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
6157
|
+
return STRIKE.NONE;
|
|
6158
|
+
};
|
|
6159
|
+
/** The strength a charge of `ticks` gives, 1 to CHARGE_MAX: 1 under CHARGE_TAP, CHARGE_MAX at CHARGE_TICKS. */
|
|
6160
|
+
var powerOf = (ticks) => ticks < 10 ? 1 : 1 + Math.floor(4 * (ticks - 10) / 50);
|
|
6161
|
+
// src/shared/maps.ts
|
|
6162
|
+
var MAPS = {
|
|
6163
|
+
highline: HIGHLINE,
|
|
6164
|
+
tranquility: MOON
|
|
4936
6165
|
};
|
|
6166
|
+
/** The map of a key; an unknown or missing one is HIGHLINE. */
|
|
6167
|
+
var mapOf = (key) => key !== void 0 && MAPS[key] || HIGHLINE;
|
|
6168
|
+
/** The key of a known map, else 'highline'. */
|
|
6169
|
+
var mapKey = (key) => key !== void 0 && Object.hasOwn(MAPS, key) ? key : "highline";
|
|
4937
6170
|
/** A rover's floats, in wire order. */
|
|
4938
6171
|
var ROVER_F = [...[
|
|
4939
6172
|
"x",
|
|
@@ -4967,6 +6200,19 @@ var clamp16 = (v) => Math.max(-32768, Math.min(32767, Math.round(v)));
|
|
|
4967
6200
|
var toPitch = (pitch) => clamp16(pitch * 1e4);
|
|
4968
6201
|
var fromPitch = (w) => w / 1e4;
|
|
4969
6202
|
var fromTurn = (w) => w / TURN;
|
|
6203
|
+
/** A view tick in 1/256 tick, modulo the u16 tick circle (24 bits); absent is 0. */
|
|
6204
|
+
var toView = (view = 0) => Math.round(view * 256) & 16777215;
|
|
6205
|
+
/**
|
|
6206
|
+
* The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
|
|
6207
|
+
* rounded to the wire (an absent view stays absent here, and reads 0 on the host). The client
|
|
6208
|
+
* predicts with this, so both sides move with the same values.
|
|
6209
|
+
*/
|
|
6210
|
+
var onWire = (i) => ({
|
|
6211
|
+
...i,
|
|
6212
|
+
yaw: fromTurn(toTurn(i.yaw)),
|
|
6213
|
+
pitch: fromPitch(toPitch(i.pitch)),
|
|
6214
|
+
...i.view !== void 0 && { view: toView(i.view) / 256 }
|
|
6215
|
+
});
|
|
4970
6216
|
/** Null on anything that is not a well-formed input frame. */
|
|
4971
6217
|
var decodeInput = (buf) => {
|
|
4972
6218
|
if (buf.byteLength !== 12) return null;
|
|
@@ -6315,6 +7561,17 @@ var MAX_CATCH_UP = 20;
|
|
|
6315
7561
|
var SPAWN_CLEAR = 2;
|
|
6316
7562
|
/** Ticks before a rover can run the same player over again. */
|
|
6317
7563
|
var SPLAT_COOLDOWN = 30;
|
|
7564
|
+
/** The names of the bots, in turn. */
|
|
7565
|
+
var BOT_NAMES = [
|
|
7566
|
+
"Ada",
|
|
7567
|
+
"Bix",
|
|
7568
|
+
"Cog",
|
|
7569
|
+
"Dot",
|
|
7570
|
+
"Echo",
|
|
7571
|
+
"Flux",
|
|
7572
|
+
"Gear",
|
|
7573
|
+
"Hex"
|
|
7574
|
+
];
|
|
6318
7575
|
/** The two seats of a rover, the driver's first. */
|
|
6319
7576
|
var SEATS = ["driver", "rider"];
|
|
6320
7577
|
/** An index in [0, n), or undefined. */
|
|
@@ -6438,6 +7695,8 @@ var Room = class {
|
|
|
6438
7695
|
next;
|
|
6439
7696
|
/** Joins so far: each player's `since`. */
|
|
6440
7697
|
joins = 0;
|
|
7698
|
+
/** 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. */
|
|
7699
|
+
freed = /* @__PURE__ */ new Set();
|
|
6441
7700
|
/** Missing rules fall back to RULES. The map is the rules' one, unless a definition is given. */
|
|
6442
7701
|
constructor(rules = {}, def) {
|
|
6443
7702
|
this.rules = {
|
|
@@ -6445,10 +7704,11 @@ var Room = class {
|
|
|
6445
7704
|
...rules
|
|
6446
7705
|
};
|
|
6447
7706
|
this.mapName = mapKey(this.rules.map);
|
|
6448
|
-
this.world = build(def ?? mapOf(this.mapName));
|
|
7707
|
+
this.world = build$1(def ?? mapOf(this.mapName));
|
|
6449
7708
|
this.ctf = new Ctf(this.world, this.rules);
|
|
6450
7709
|
this.gone = this.spots();
|
|
6451
7710
|
this.fresh();
|
|
7711
|
+
this.guide();
|
|
6452
7712
|
}
|
|
6453
7713
|
/** Every vehicle of the map parked afresh: whole, empty, on its spawn. */
|
|
6454
7714
|
fresh() {
|
|
@@ -6467,25 +7727,26 @@ var Room = class {
|
|
|
6467
7727
|
}
|
|
6468
7728
|
/** The host: the player in the room the longest. */
|
|
6469
7729
|
host() {
|
|
6470
|
-
return this.
|
|
7730
|
+
return this.humans().reduce((h, p) => h && h.since < p.since ? h : p, void 0);
|
|
6471
7731
|
}
|
|
6472
7732
|
/** The map the host picked, from now on: a new world and a new match, the players in it. */
|
|
6473
7733
|
load() {
|
|
6474
7734
|
if (this.next === void 0) return;
|
|
6475
7735
|
this.mapName = this.next;
|
|
6476
7736
|
this.next = void 0;
|
|
6477
|
-
this.world = build(mapOf(this.mapName));
|
|
7737
|
+
this.world = build$1(mapOf(this.mapName));
|
|
6478
7738
|
this.ctf = new Ctf(this.world, this.rules);
|
|
6479
7739
|
this.gone = this.spots();
|
|
6480
7740
|
this.fresh();
|
|
7741
|
+
this.guide();
|
|
6481
7742
|
this.history = [];
|
|
6482
7743
|
this.balls = [];
|
|
6483
7744
|
for (const p of this.players()) this.ctf.join(p.info.id, p.info.team, p.state);
|
|
6484
7745
|
this.roster();
|
|
6485
7746
|
}
|
|
6486
|
-
/** Number of joined players. */
|
|
7747
|
+
/** Number of joined players, the bots left out: a room of bots alone is empty. */
|
|
6487
7748
|
get size() {
|
|
6488
|
-
return this.
|
|
7749
|
+
return this.humans().length;
|
|
6489
7750
|
}
|
|
6490
7751
|
/** A peer opened. Nothing is sent until it joins. */
|
|
6491
7752
|
connect(conn) {
|
|
@@ -6517,7 +7778,11 @@ var Room = class {
|
|
|
6517
7778
|
return;
|
|
6518
7779
|
}
|
|
6519
7780
|
const input = p && decodeInput(data);
|
|
6520
|
-
if (input
|
|
7781
|
+
if (input) this.apply(p, input);
|
|
7782
|
+
}
|
|
7783
|
+
/** One input of a player, moved at once. An input beyond the bank is dropped, and not acked. */
|
|
7784
|
+
apply(p, input) {
|
|
7785
|
+
if (p.bank > 0) {
|
|
6521
7786
|
p.bank--;
|
|
6522
7787
|
const slow = p.state.slow ?? 0;
|
|
6523
7788
|
const use = (input.keys & KEY.USE) !== 0 && (p.state.held & KEY.USE) === 0;
|
|
@@ -6564,7 +7829,9 @@ var Room = class {
|
|
|
6564
7829
|
this.peers.delete(conn);
|
|
6565
7830
|
if (p) {
|
|
6566
7831
|
this.ctf.leave(p.info.id);
|
|
7832
|
+
this.fill();
|
|
6567
7833
|
if (!this.size) {
|
|
7834
|
+
this.freed.clear();
|
|
6568
7835
|
this.ctf.reset();
|
|
6569
7836
|
this.gone.fill(0);
|
|
6570
7837
|
this.fresh();
|
|
@@ -6584,6 +7851,7 @@ var Room = class {
|
|
|
6584
7851
|
}
|
|
6585
7852
|
/** One host tick. Public so tests can drive the room without a timer. */
|
|
6586
7853
|
tick() {
|
|
7854
|
+
this.freed.clear();
|
|
6587
7855
|
const players = this.players();
|
|
6588
7856
|
if (!players.length) {
|
|
6589
7857
|
this.balls = [];
|
|
@@ -6591,6 +7859,7 @@ var Room = class {
|
|
|
6591
7859
|
}
|
|
6592
7860
|
const now = ++this.ticks;
|
|
6593
7861
|
for (const p of players) p.bank = Math.min(10, p.bank + 1);
|
|
7862
|
+
this.think(players);
|
|
6594
7863
|
for (const b of this.balls) if (!b.burst && b.left > 0) this.fly(b, stepOf(b));
|
|
6595
7864
|
this.heal(players);
|
|
6596
7865
|
swing(this.world, players.filter((p) => !p.state.down).map((p) => [
|
|
@@ -6824,7 +8093,7 @@ var Room = class {
|
|
|
6824
8093
|
* against the others as they are now. Past PLASMA_MAX balls in flight, the oldest bursts. A
|
|
6825
8094
|
* grenade (lob()) is flown on the same way, a tick of its arc at a time.
|
|
6826
8095
|
*/
|
|
6827
|
-
shoot(p, view = 0, b = launch(p.state, p.info.team)) {
|
|
8096
|
+
shoot(p, view = 0, b = launch$1(p.state, p.info.team)) {
|
|
6828
8097
|
const lag = (this.ticks - view + 65536) % 65536;
|
|
6829
8098
|
this.balls.push(b);
|
|
6830
8099
|
const ticks = Math.min(lag < 32768 ? lag : 0, 12);
|
|
@@ -7407,14 +8676,74 @@ var Room = class {
|
|
|
7407
8676
|
players() {
|
|
7408
8677
|
return [...this.peers.values()].filter((p) => p !== null);
|
|
7409
8678
|
}
|
|
7410
|
-
|
|
8679
|
+
humans() {
|
|
8680
|
+
return this.players().filter((p) => !p.bot);
|
|
8681
|
+
}
|
|
8682
|
+
/** Each bot's input of this tick, applied as a client's would be on arrival. */
|
|
8683
|
+
think(players) {
|
|
8684
|
+
const others = players.map((q) => ({
|
|
8685
|
+
id: q.info.id,
|
|
8686
|
+
team: q.info.team,
|
|
8687
|
+
state: q.state
|
|
8688
|
+
}));
|
|
8689
|
+
for (const p of players) if (p.bot) {
|
|
8690
|
+
const me = others.find((o) => o.id === p.info.id);
|
|
8691
|
+
const i = p.bot.think({
|
|
8692
|
+
me,
|
|
8693
|
+
others: others.filter((o) => o !== me),
|
|
8694
|
+
flags: this.ctf.flags,
|
|
8695
|
+
world: this.world,
|
|
8696
|
+
balls: this.balls
|
|
8697
|
+
});
|
|
8698
|
+
p.seq = (p.seq ?? -1) + 1 & 65535;
|
|
8699
|
+
this.apply(p, onWire({
|
|
8700
|
+
...i,
|
|
8701
|
+
seq: p.seq,
|
|
8702
|
+
view: this.ticks & 65535
|
|
8703
|
+
}));
|
|
8704
|
+
}
|
|
8705
|
+
}
|
|
8706
|
+
/** The bots' map of the world, built when it loads rather than in the tick of a bot's first plan. */
|
|
8707
|
+
guide() {
|
|
8708
|
+
if (this.rules.bots) navOf(this.world);
|
|
8709
|
+
}
|
|
8710
|
+
/** The players the bots fill the room up to: none with no human. */
|
|
8711
|
+
wanted() {
|
|
8712
|
+
return this.size ? Math.min(this.rules.bots ?? 0, this.rules.maxPlayers) : 0;
|
|
8713
|
+
}
|
|
8714
|
+
/**
|
|
8715
|
+
* Bots in and out so that there are `want` players, the humans first, the teams even: a bot comes
|
|
8716
|
+
* on the smaller team and leaves the larger one.
|
|
8717
|
+
*/
|
|
8718
|
+
fill(want = this.wanted()) {
|
|
8719
|
+
for (;;) {
|
|
8720
|
+
const players = this.players();
|
|
8721
|
+
const reds = players.filter((p) => p.info.team === 0).length;
|
|
8722
|
+
const bots = players.filter((p) => p.bot);
|
|
8723
|
+
if (players.length > want && bots.length) {
|
|
8724
|
+
const big = reds > players.length - reds ? 0 : 1;
|
|
8725
|
+
const out = bots.reverse().find((p) => p.info.team === big) ?? bots[0];
|
|
8726
|
+
this.peers.delete(out.conn);
|
|
8727
|
+
this.ctf.leave(out.info.id);
|
|
8728
|
+
this.freed.add(out.info.id);
|
|
8729
|
+
} else if (players.length < want) {
|
|
8730
|
+
const conn = { send: () => void 0 };
|
|
8731
|
+
this.peers.set(conn, null);
|
|
8732
|
+
const names = players.map((p) => p.info.name);
|
|
8733
|
+
const name = BOT_NAMES.map((n) => `${n} (bot)`).find((n) => !names.includes(n)) ?? "Bot";
|
|
8734
|
+
this.join(conn, name, {}, true);
|
|
8735
|
+
} else return;
|
|
8736
|
+
}
|
|
8737
|
+
}
|
|
8738
|
+
join(conn, name, picked = {}, bot = false) {
|
|
8739
|
+
if (!bot && this.players().some((p) => p.bot)) this.fill(Math.min(this.wanted(), this.players().length) - 1);
|
|
7411
8740
|
const players = this.players();
|
|
7412
8741
|
if (players.length >= this.rules.maxPlayers) {
|
|
7413
8742
|
conn.send(JSON.stringify({ t: "full" }));
|
|
7414
8743
|
return;
|
|
7415
8744
|
}
|
|
7416
8745
|
let id = 0;
|
|
7417
|
-
while (players.some((p) => p.info.id === id)) id++;
|
|
8746
|
+
while (players.some((p) => p.info.id === id) || this.freed.has(id)) id++;
|
|
7418
8747
|
const reds = players.filter((p) => p.info.team === 0).length;
|
|
7419
8748
|
const team = reds > players.length - reds ? 1 : 0;
|
|
7420
8749
|
const player = {
|
|
@@ -7424,7 +8753,8 @@ var Room = class {
|
|
|
7424
8753
|
name: unique(cleanName(name) || `Player ${id}`, players.map((p) => p.info.name)),
|
|
7425
8754
|
team,
|
|
7426
8755
|
color: TEAM_COLOR[team],
|
|
7427
|
-
...chosen(picked)
|
|
8756
|
+
...chosen(picked),
|
|
8757
|
+
...bot ? { bot } : {}
|
|
7428
8758
|
},
|
|
7429
8759
|
state: this.place(id, team, players.map((p) => p.state)),
|
|
7430
8760
|
since: this.joins++,
|
|
@@ -7432,17 +8762,20 @@ var Room = class {
|
|
|
7432
8762
|
ack: 65535,
|
|
7433
8763
|
by: 0,
|
|
7434
8764
|
tackled: -30,
|
|
7435
|
-
run: -SPLAT_COOLDOWN
|
|
8765
|
+
run: -SPLAT_COOLDOWN,
|
|
8766
|
+
...bot ? { bot: new Bot(id, this.rules.botSkill) } : {}
|
|
7436
8767
|
};
|
|
7437
8768
|
this.peers.set(conn, player);
|
|
7438
8769
|
this.ctf.join(id, team, player.state);
|
|
7439
|
-
|
|
8770
|
+
if (!bot) {
|
|
8771
|
+
this.fill();
|
|
8772
|
+
this.roster();
|
|
8773
|
+
}
|
|
7440
8774
|
}
|
|
7441
8775
|
/** Each joined peer gets the full roster with its own id. */
|
|
7442
8776
|
roster() {
|
|
7443
|
-
const
|
|
7444
|
-
|
|
7445
|
-
players.forEach((p) => p.conn.send(JSON.stringify({
|
|
8777
|
+
const list = this.players().map((p) => p.info).sort((a, b) => a.id - b.id);
|
|
8778
|
+
this.humans().forEach((p) => p.conn.send(JSON.stringify({
|
|
7446
8779
|
t: "roster",
|
|
7447
8780
|
you: p.info.id,
|
|
7448
8781
|
players: list,
|