@korial29/tiny-fps 0.96.0 → 0.98.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 -1
- package/dist/index.js +16 -16
- package/dist/local.js +1 -1
- package/dist/server.js +819 -92
- package/dist/types/client/chase.d.ts +42 -0
- package/dist/types/client/dust.d.ts +23 -0
- package/dist/types/client/foley.d.ts +8 -1
- package/dist/types/client/gait.d.ts +33 -2
- package/dist/types/client/hud.d.ts +16 -1
- package/dist/types/client/index.d.ts +2 -1
- package/dist/types/client/input.d.ts +1 -1
- package/dist/types/client/lights.d.ts +11 -1
- package/dist/types/client/moonbase.d.ts +11 -1
- package/dist/types/client/predict.d.ts +22 -2
- package/dist/types/client/render.d.ts +18 -4
- package/dist/types/client/rover.d.ts +35 -0
- package/dist/types/client/sfx.d.ts +6 -0
- package/dist/types/client/soldier.d.ts +11 -4
- package/dist/types/shared/moonbase.d.ts +29 -1
- package/dist/types/shared/protocol.d.ts +5 -1
- package/dist/types/shared/room.d.ts +33 -0
- package/dist/types/shared/rover.d.ts +41 -6
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -455,12 +455,12 @@ var OFF = 1024;
|
|
|
455
455
|
/** The key of the cell with integer coordinates (cx, cz). */
|
|
456
456
|
var key = (cx, cz) => (cx + OFF) * (2 * OFF) + cz + OFF;
|
|
457
457
|
/** Integer cell coordinate of a metre value, clamped to the keyed range. */
|
|
458
|
-
var at$
|
|
458
|
+
var at$2 = (v, cell) => Math.min(Math.max(Math.floor(v / cell), -1024), 1023);
|
|
459
459
|
/** Builds the grid: each brush is listed in every cell its footprint covers. */
|
|
460
460
|
var build = (def, cell = CELL) => {
|
|
461
461
|
const grid = /* @__PURE__ */ new Map();
|
|
462
462
|
def.brushes.forEach(({ min, max }, i) => {
|
|
463
|
-
for (let cx = at$
|
|
463
|
+
for (let cx = at$2(min[0], cell); cx <= at$2(max[0], cell); cx++) for (let cz = at$2(min[2], cell); cz <= at$2(max[2], cell); cz++) {
|
|
464
464
|
const k = key(cx, cz);
|
|
465
465
|
const list = grid.get(k);
|
|
466
466
|
if (list) list.push(i);
|
|
@@ -484,7 +484,7 @@ var build = (def, cell = CELL) => {
|
|
|
484
484
|
*/
|
|
485
485
|
var near = (w, x, z, r) => {
|
|
486
486
|
const out = [];
|
|
487
|
-
for (let cx = at$
|
|
487
|
+
for (let cx = at$2(x - r, w.cell); cx <= at$2(x + r, w.cell); cx++) for (let cz = at$2(z - r, w.cell); cz <= at$2(z + r, w.cell); cz++) for (const i of w.grid.get(key(cx, cz)) ?? []) if (!out.includes(i)) out.push(i);
|
|
488
488
|
return out;
|
|
489
489
|
};
|
|
490
490
|
/**
|
|
@@ -507,8 +507,8 @@ var ray = (w, o, d, max, grow = 0) => {
|
|
|
507
507
|
var faces = (w, o, d, max, grow) => {
|
|
508
508
|
const { cell, def } = w;
|
|
509
509
|
let best = max;
|
|
510
|
-
let cx = at$
|
|
511
|
-
let cz = at$
|
|
510
|
+
let cx = at$2(o[0], cell);
|
|
511
|
+
let cz = at$2(o[2], cell);
|
|
512
512
|
const sx = Math.sign(d[0]);
|
|
513
513
|
const sz = Math.sign(d[2]);
|
|
514
514
|
const nx = sx ? ((cx + (sx > 0 ? 1 : 0)) * cell - o[0]) / d[0] : Infinity;
|
|
@@ -558,7 +558,7 @@ var hidden = (w, a, b) => {
|
|
|
558
558
|
], len) < len - 1e-4;
|
|
559
559
|
};
|
|
560
560
|
// src/shared/physics.ts
|
|
561
|
-
var DT = 1 / 60;
|
|
561
|
+
var DT$1 = 1 / 60;
|
|
562
562
|
var TAU = Math.PI * 2;
|
|
563
563
|
/** Overlaps smaller than this are rounding noise, not contact. */
|
|
564
564
|
var EPS = 1e-6;
|
|
@@ -577,11 +577,11 @@ var TOUCH = .001;
|
|
|
577
577
|
var norm = (a) => (a % TAU + TAU) % TAU;
|
|
578
578
|
/** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
|
|
579
579
|
var forward = (yaw) => [-Math.sin(yaw), -Math.cos(yaw)];
|
|
580
|
-
var f32 = Math.fround;
|
|
581
|
-
var sqrt = Math.sqrt;
|
|
582
|
-
var clamp = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
|
|
580
|
+
var f32$1 = Math.fround;
|
|
581
|
+
var sqrt$1 = Math.sqrt;
|
|
582
|
+
var clamp$1 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
|
|
583
583
|
/** The length of (x, z). */
|
|
584
|
-
var len = (x, z) => sqrt(x * x + z * z);
|
|
584
|
+
var len$1 = (x, z) => sqrt$1(x * x + z * z);
|
|
585
585
|
/** The unit vector from a player toward a wall or a ledge on each SIDE. */
|
|
586
586
|
var TOWARD = [
|
|
587
587
|
[0, 0],
|
|
@@ -641,9 +641,9 @@ var spawn = (id, w, n, team = 0) => {
|
|
|
641
641
|
const [x, y, z, yaw] = spawns[(n % spawns.length + spawns.length) % spawns.length];
|
|
642
642
|
return {
|
|
643
643
|
id,
|
|
644
|
-
x: f32(x),
|
|
645
|
-
y: f32(y),
|
|
646
|
-
z: f32(z),
|
|
644
|
+
x: f32$1(x),
|
|
645
|
+
y: f32$1(y),
|
|
646
|
+
z: f32$1(z),
|
|
647
647
|
vy: 0,
|
|
648
648
|
yaw: norm(yaw),
|
|
649
649
|
pitch: 0,
|
|
@@ -672,11 +672,11 @@ var heightOf = (p) => p.mode === MODE.SLIDE || p.mode === MODE.CROUCH ? LOW_H :
|
|
|
672
672
|
/** The camera height above the feet in this mode. */
|
|
673
673
|
var eyeHeight = (p) => p.mode === MODE.SLIDE || p.mode === MODE.CROUCH ? LOW_EYE : EYE;
|
|
674
674
|
/** Horizontal speed, m/s. */
|
|
675
|
-
var speedOf = (p) => len(p.vx, p.vz);
|
|
675
|
+
var speedOf = (p) => len$1(p.vx, p.vz);
|
|
676
676
|
/** Whether the brush stops a body of height h whose feet are at y when it walks sideways into it. */
|
|
677
677
|
var blocks = (b, y, h) => b.max[1] > y + .5 + SKIN && b.min[1] < y + h - SKIN;
|
|
678
678
|
/** The closest point of the brush footprint to (x, z), as the offset from it to (x, z). */
|
|
679
|
-
var gap = (b, x, z) => [x - clamp(x, b.min[0], b.max[0]), z - clamp(z, b.min[2], b.max[2])];
|
|
679
|
+
var gap = (b, x, z) => [x - clamp$1(x, b.min[0], b.max[0]), z - clamp$1(z, b.min[2], b.max[2])];
|
|
680
680
|
/**
|
|
681
681
|
* Pushes the player out of every brush that blocks it and that the circle overlaps, deepest first
|
|
682
682
|
* (up to 4 passes: two walls in a corner settle in two). The push is along the vector from the
|
|
@@ -710,7 +710,7 @@ var shove = (p, w, h, r) => {
|
|
|
710
710
|
const d2 = dx * dx + dz * dz;
|
|
711
711
|
if (d2 >= reach) continue;
|
|
712
712
|
if (d2) {
|
|
713
|
-
const d = sqrt(d2);
|
|
713
|
+
const d = sqrt$1(d2);
|
|
714
714
|
if (r - d > best) {
|
|
715
715
|
best = r - d;
|
|
716
716
|
px = dx / d * best;
|
|
@@ -775,6 +775,18 @@ var span = (p, w, h) => {
|
|
|
775
775
|
}
|
|
776
776
|
return [floor, ceil];
|
|
777
777
|
};
|
|
778
|
+
/**
|
|
779
|
+
* The highest floor under the point (x, z) at most as high as y: the ground of the relief, or the
|
|
780
|
+
* top of a brush the point is over. For a rover's wheel.
|
|
781
|
+
*/
|
|
782
|
+
var floorAt = (w, x, z, y) => {
|
|
783
|
+
let floor = ground(w, x, z);
|
|
784
|
+
for (const i of near(w, x, z, 0)) {
|
|
785
|
+
const { min, max } = w.def.brushes[i];
|
|
786
|
+
if (x >= min[0] && x <= max[0] && z >= min[2] && z <= max[2] && max[1] <= y) floor = Math.max(floor, max[1]);
|
|
787
|
+
}
|
|
788
|
+
return floor;
|
|
789
|
+
};
|
|
778
790
|
/** Whether a standing body fits where the player is: no ceiling or box within PLAYER_H. */
|
|
779
791
|
var canStand = (p, w) => {
|
|
780
792
|
const reach = (PLAYER_R - EPS) ** 2;
|
|
@@ -869,7 +881,7 @@ var over = (p, w) => {
|
|
|
869
881
|
return near(w, p.x, p.z, 0).some((i) => {
|
|
870
882
|
const b = w.def.brushes[i];
|
|
871
883
|
const depth = sign > 0 ? c - b.min[a] : b.max[a] - c;
|
|
872
|
-
return f32(b.max[1]) === p.edge && co >= b.min[o] && co <= b.max[o] && depth >= .2;
|
|
884
|
+
return f32$1(b.max[1]) === p.edge && co >= b.min[o] && co <= b.max[o] && depth >= .2;
|
|
873
885
|
});
|
|
874
886
|
};
|
|
875
887
|
/** The world's gravity: GRAVITY times the map's share (the moon's half gravity, the user, 2026-11-09). */
|
|
@@ -878,7 +890,7 @@ var gravity = (w) => 20 * (w.def.gravity ?? 1);
|
|
|
878
890
|
var landingSoon = (p, w) => {
|
|
879
891
|
if (p.vy >= 0) return false;
|
|
880
892
|
const [floor] = span(p, w, PLAYER_H);
|
|
881
|
-
const t = 6 * DT;
|
|
893
|
+
const t = 6 * DT$1;
|
|
882
894
|
return p.y - floor <= -p.vy * t + .5 * gravity(w) * t * t;
|
|
883
895
|
};
|
|
884
896
|
/** Changes the mode, and starts counting the time in it. */
|
|
@@ -896,8 +908,8 @@ var floored = (p) => !!p.zap && p.stun > 24;
|
|
|
896
908
|
*/
|
|
897
909
|
var stumble = (p, dx, dz, ticks = 48, knock = 6) => {
|
|
898
910
|
p.stun = ticks;
|
|
899
|
-
p.vx = f32(dx * knock);
|
|
900
|
-
p.vz = f32(dz * knock);
|
|
911
|
+
p.vx = f32$1(dx * knock);
|
|
912
|
+
p.vz = f32$1(dz * knock);
|
|
901
913
|
p.dash = Math.min(p.dash, 50);
|
|
902
914
|
p.coyote = 0;
|
|
903
915
|
p.buffer = 0;
|
|
@@ -909,7 +921,7 @@ var stumble = (p, dx, dz, ticks = 48, knock = 6) => {
|
|
|
909
921
|
};
|
|
910
922
|
/** Scales the horizontal speed to at most max. */
|
|
911
923
|
var cap = (p, max) => {
|
|
912
|
-
const s = len(p.vx, p.vz);
|
|
924
|
+
const s = len$1(p.vx, p.vz);
|
|
913
925
|
if (s > max) {
|
|
914
926
|
p.vx *= max / s;
|
|
915
927
|
p.vz *= max / s;
|
|
@@ -926,7 +938,7 @@ var unwalled = (p, w, c, h) => {
|
|
|
926
938
|
for (const i of near(w, p.x, p.z, PLAYER_R + TOUCH)) {
|
|
927
939
|
const b = w.def.brushes[i];
|
|
928
940
|
const [dx, dz] = gap(b, p.x, p.z);
|
|
929
|
-
const d = len(dx, dz);
|
|
941
|
+
const d = len$1(dx, dz);
|
|
930
942
|
if (d > 0 && d <= .4 + TOUCH && blocks(b, p.y, h)) {
|
|
931
943
|
const into = (-x * dx - z * dz) / d;
|
|
932
944
|
if (into > 0) {
|
|
@@ -942,10 +954,10 @@ var unwalled = (p, w, c, h) => {
|
|
|
942
954
|
* its length; friction with none.
|
|
943
955
|
*/
|
|
944
956
|
var steer = (p, wish, top) => {
|
|
945
|
-
const m = len(wish[0], wish[1]);
|
|
957
|
+
const m = len$1(wish[0], wish[1]);
|
|
946
958
|
if (m < EPS) {
|
|
947
|
-
const s = len(p.vx, p.vz);
|
|
948
|
-
const k = s ? Math.max(0, s - 45 * DT) / s : 0;
|
|
959
|
+
const s = len$1(p.vx, p.vz);
|
|
960
|
+
const k = s ? Math.max(0, s - 45 * DT$1) / s : 0;
|
|
949
961
|
p.vx *= k;
|
|
950
962
|
p.vz *= k;
|
|
951
963
|
return;
|
|
@@ -953,13 +965,13 @@ var steer = (p, wish, top) => {
|
|
|
953
965
|
const [wx, wz] = [wish[0] / m, wish[1] / m];
|
|
954
966
|
let par = p.vx * wx + p.vz * wz;
|
|
955
967
|
let [px, pz] = [p.vx - par * wx, p.vz - par * wz];
|
|
956
|
-
const across = len(px, pz);
|
|
968
|
+
const across = len$1(px, pz);
|
|
957
969
|
if (across) {
|
|
958
|
-
const k = Math.max(0, across - 45 * DT) / across;
|
|
970
|
+
const k = Math.max(0, across - 45 * DT$1) / across;
|
|
959
971
|
[px, pz] = [px * k, pz * k];
|
|
960
972
|
}
|
|
961
973
|
top *= m;
|
|
962
|
-
par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT) : Math.max(top, par - 12 * DT);
|
|
974
|
+
par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT$1) : Math.max(top, par - 12 * DT$1);
|
|
963
975
|
p.vx = px + par * wx;
|
|
964
976
|
p.vz = pz + par * wz;
|
|
965
977
|
};
|
|
@@ -971,10 +983,10 @@ var steer = (p, wish, top) => {
|
|
|
971
983
|
*/
|
|
972
984
|
var fly$1 = (p, w, h, g, snap) => {
|
|
973
985
|
const y0 = p.y;
|
|
974
|
-
p.x += p.vx * DT;
|
|
975
|
-
p.z += p.vz * DT;
|
|
986
|
+
p.x += p.vx * DT$1;
|
|
987
|
+
p.z += p.vz * DT$1;
|
|
976
988
|
const [cx, cz] = push(p, w, h);
|
|
977
|
-
const d = len(cx, cz);
|
|
989
|
+
const d = len$1(cx, cz);
|
|
978
990
|
if (d) {
|
|
979
991
|
const into = (p.vx * cx + p.vz * cz) / d;
|
|
980
992
|
if (into < 0) {
|
|
@@ -984,8 +996,8 @@ var fly$1 = (p, w, h, g, snap) => {
|
|
|
984
996
|
}
|
|
985
997
|
bound(p, w);
|
|
986
998
|
const [floor, ceil] = span(p, w, h);
|
|
987
|
-
const vy = p.vy - g * gravity(w) * DT;
|
|
988
|
-
p.y += (p.vy + vy) / 2 * DT;
|
|
999
|
+
const vy = p.vy - g * gravity(w) * DT$1;
|
|
1000
|
+
p.y += (p.vy + vy) / 2 * DT$1;
|
|
989
1001
|
p.vy = vy;
|
|
990
1002
|
if (p.y + h > ceil) {
|
|
991
1003
|
p.y = ceil - h;
|
|
@@ -1033,16 +1045,16 @@ var hang = (p, w, c) => {
|
|
|
1033
1045
|
p.coyote = 0;
|
|
1034
1046
|
} else {
|
|
1035
1047
|
const target = Math.max(p.edge - 2, span(p, w, PLAYER_H)[0]);
|
|
1036
|
-
p.y += clamp(target - p.y, -8 * DT, 8 * DT);
|
|
1048
|
+
p.y += clamp$1(target - p.y, -8 * DT$1, 8 * DT$1);
|
|
1037
1049
|
}
|
|
1038
1050
|
};
|
|
1039
1051
|
/** Climbing: up to the top, then in from the edge, then standing on it. */
|
|
1040
1052
|
var climb = (p, w) => {
|
|
1041
1053
|
const [nx, nz] = TOWARD[p.wall];
|
|
1042
|
-
if (p.y < p.edge) p.y = Math.min(p.edge, p.y + 8 * DT);
|
|
1054
|
+
if (p.y < p.edge) p.y = Math.min(p.edge, p.y + 8 * DT$1);
|
|
1043
1055
|
else {
|
|
1044
|
-
p.x += nx * CLIMB_FWD_SPEED * DT;
|
|
1045
|
-
p.z += nz * CLIMB_FWD_SPEED * DT;
|
|
1056
|
+
p.x += nx * CLIMB_FWD_SPEED * DT$1;
|
|
1057
|
+
p.z += nz * CLIMB_FWD_SPEED * DT$1;
|
|
1046
1058
|
}
|
|
1047
1059
|
if (p.y >= p.edge && over(p, w)) {
|
|
1048
1060
|
enter(p, MODE.GROUND);
|
|
@@ -1064,7 +1076,7 @@ var run = (p, w, c) => {
|
|
|
1064
1076
|
const [nx, nz] = TOWARD[p.wall];
|
|
1065
1077
|
const into = p.vx * nx + p.vz * nz;
|
|
1066
1078
|
const [tx, tz] = [p.vx - into * nx, p.vz - into * nz];
|
|
1067
|
-
const s = len(tx, tz);
|
|
1079
|
+
const s = len$1(tx, tz);
|
|
1068
1080
|
if (c.jump) {
|
|
1069
1081
|
enter(p, MODE.AIR);
|
|
1070
1082
|
p.vx = tx - nx * 5;
|
|
@@ -1080,10 +1092,10 @@ var run = (p, w, c) => {
|
|
|
1080
1092
|
p.ev |= EV.WALLRUN_END;
|
|
1081
1093
|
return;
|
|
1082
1094
|
}
|
|
1083
|
-
const k = Math.max(0, s - WALLRUN_DRAG * DT) / s;
|
|
1095
|
+
const k = Math.max(0, s - WALLRUN_DRAG * DT$1) / s;
|
|
1084
1096
|
p.vx = tx * k;
|
|
1085
1097
|
p.vz = tz * k;
|
|
1086
|
-
const pull = Math.min(gap, 4 * DT);
|
|
1098
|
+
const pull = Math.min(gap, 4 * DT$1);
|
|
1087
1099
|
p.x += nx * pull;
|
|
1088
1100
|
p.z += nz * pull;
|
|
1089
1101
|
}
|
|
@@ -1096,19 +1108,19 @@ var run = (p, w, c) => {
|
|
|
1096
1108
|
*/
|
|
1097
1109
|
var startRun = (p, w, c) => {
|
|
1098
1110
|
if (!c.fwd) return;
|
|
1099
|
-
const s = len(p.vx, p.vz);
|
|
1111
|
+
const s = len$1(p.vx, p.vz);
|
|
1100
1112
|
if (s < 4.5) return;
|
|
1101
1113
|
for (let side = 1; side <= 4; side++) {
|
|
1102
1114
|
const [nx, nz] = TOWARD[side];
|
|
1103
1115
|
const into = p.vx * nx + p.vz * nz;
|
|
1104
1116
|
const [tx, tz] = [p.vx - into * nx, p.vz - into * nz];
|
|
1105
1117
|
if (side !== p.wall && into <= .75 * s && into >= -.2 * s && wallGap(p, w, side) !== void 0) {
|
|
1106
|
-
const t = len(tx, tz);
|
|
1118
|
+
const t = len$1(tx, tz);
|
|
1107
1119
|
const k = Math.max(t, WALL_TURN_KEEP * s) / t;
|
|
1108
1120
|
enter(p, MODE.WALLRUN);
|
|
1109
1121
|
p.wall = side;
|
|
1110
1122
|
[p.vx, p.vz] = [tx * k, tz * k];
|
|
1111
|
-
p.vy = clamp(p.vy, 2, 3);
|
|
1123
|
+
p.vy = clamp$1(p.vy, 2, 3);
|
|
1112
1124
|
p.jumps = 1;
|
|
1113
1125
|
p.dashes = 1;
|
|
1114
1126
|
p.coyote = 0;
|
|
@@ -1121,7 +1133,7 @@ var startRun = (p, w, c) => {
|
|
|
1121
1133
|
var grab = (p, l) => {
|
|
1122
1134
|
enter(p, MODE.HANG);
|
|
1123
1135
|
p.wall = l.side;
|
|
1124
|
-
p.edge = f32(l.top);
|
|
1136
|
+
p.edge = f32$1(l.top);
|
|
1125
1137
|
if (l.side <= SIDE.WEST) p.x = l.hang;
|
|
1126
1138
|
else p.z = l.hang;
|
|
1127
1139
|
p.vx = p.vy = p.vz = 0;
|
|
@@ -1164,7 +1176,7 @@ var free = (p, w, c) => {
|
|
|
1164
1176
|
p.dashes = 1;
|
|
1165
1177
|
p.wall = SIDE.NONE;
|
|
1166
1178
|
if (c.keys & KEY.CROUCH) {
|
|
1167
|
-
const slide = len(p.vx, p.vz) >= SLIDE_MIN_SPEED;
|
|
1179
|
+
const slide = len$1(p.vx, p.vz) >= SLIDE_MIN_SPEED;
|
|
1168
1180
|
enter(p, slide ? MODE.SLIDE : MODE.CROUCH);
|
|
1169
1181
|
p.ev |= slide ? EV.SLIDE_START : 0;
|
|
1170
1182
|
} else enter(p, MODE.GROUND);
|
|
@@ -1189,7 +1201,7 @@ var onGround = (p, w, c, burst) => {
|
|
|
1189
1201
|
leap(p, 7);
|
|
1190
1202
|
return;
|
|
1191
1203
|
}
|
|
1192
|
-
const speed = len(p.vx, p.vz);
|
|
1204
|
+
const speed = len$1(p.vx, p.vz);
|
|
1193
1205
|
if (p.mode === MODE.GROUND && low) {
|
|
1194
1206
|
const slide = speed >= SLIDE_MIN_SPEED;
|
|
1195
1207
|
enter(p, slide ? MODE.SLIDE : MODE.CROUCH);
|
|
@@ -1204,12 +1216,12 @@ var onGround = (p, w, c, burst) => {
|
|
|
1204
1216
|
if (burst) return;
|
|
1205
1217
|
if (c.stumble) {
|
|
1206
1218
|
if (speed > 2.5) {
|
|
1207
|
-
const k = Math.max(STUMBLE_SPEED, speed - 12 * DT) / speed;
|
|
1219
|
+
const k = Math.max(STUMBLE_SPEED, speed - 12 * DT$1) / speed;
|
|
1208
1220
|
p.vx *= k;
|
|
1209
1221
|
p.vz *= k;
|
|
1210
1222
|
} else steer(p, unwalled(p, w, c, heightOf(p)), STUMBLE_SPEED);
|
|
1211
1223
|
} else if (p.mode === MODE.SLIDE) {
|
|
1212
|
-
const k = Math.max(0, speed - 4 * DT) / speed;
|
|
1224
|
+
const k = Math.max(0, speed - 4 * DT$1) / speed;
|
|
1213
1225
|
p.vx *= k;
|
|
1214
1226
|
p.vz *= k;
|
|
1215
1227
|
} else if (p.mode === MODE.CROUCH) steer(p, unwalled(p, w, c, LOW_H), 3);
|
|
@@ -1229,9 +1241,9 @@ var air = (p, w, c, burst) => {
|
|
|
1229
1241
|
}
|
|
1230
1242
|
}
|
|
1231
1243
|
if (burst || !c.wx && !c.wz) return;
|
|
1232
|
-
const before = len(p.vx, p.vz);
|
|
1233
|
-
p.vx += c.wx * 14 * DT;
|
|
1234
|
-
p.vz += c.wz * 14 * DT;
|
|
1244
|
+
const before = len$1(p.vx, p.vz);
|
|
1245
|
+
p.vx += c.wx * 14 * DT$1;
|
|
1246
|
+
p.vz += c.wz * 14 * DT$1;
|
|
1235
1247
|
cap(p, Math.max(before, 6));
|
|
1236
1248
|
};
|
|
1237
1249
|
/**
|
|
@@ -1244,7 +1256,7 @@ var move = (p, i, w, team = 0) => {
|
|
|
1244
1256
|
p.pitch = Math.max(-MAX_PITCH, Math.min(MAX_PITCH, i.pitch));
|
|
1245
1257
|
const f = (i.keys & KEY.FORWARD ? 1 : 0) - (i.keys & KEY.BACK ? 1 : 0);
|
|
1246
1258
|
const s = (i.keys & KEY.RIGHT ? 1 : 0) - (i.keys & KEY.LEFT ? 1 : 0);
|
|
1247
|
-
const n = floored(p) ? Infinity : len(f, s) || 1;
|
|
1259
|
+
const n = floored(p) ? Infinity : len$1(f, s) || 1;
|
|
1248
1260
|
const [fx, fz] = forward(p.yaw);
|
|
1249
1261
|
const pressed = (bit) => (i.keys & bit) !== 0 && (p.held & bit) === 0;
|
|
1250
1262
|
const stumbling = p.stun > 0;
|
|
@@ -1282,13 +1294,13 @@ var move = (p, i, w, team = 0) => {
|
|
|
1282
1294
|
if (p.mode === MODE.AIR && before === MODE.AIR) p.coyote = Math.max(0, p.coyote - 1);
|
|
1283
1295
|
p.held = i.keys & (KEY.JUMP | KEY.DASH | KEY.USE);
|
|
1284
1296
|
p.ground = onFloor(p.mode);
|
|
1285
|
-
p.x = f32(p.x);
|
|
1286
|
-
p.y = f32(p.y);
|
|
1287
|
-
p.z = f32(p.z);
|
|
1288
|
-
p.vx = f32(p.vx);
|
|
1289
|
-
p.vy = f32(p.vy);
|
|
1290
|
-
p.vz = f32(p.vz);
|
|
1291
|
-
p.edge = f32(p.edge);
|
|
1297
|
+
p.x = f32$1(p.x);
|
|
1298
|
+
p.y = f32$1(p.y);
|
|
1299
|
+
p.z = f32$1(p.z);
|
|
1300
|
+
p.vx = f32$1(p.vx);
|
|
1301
|
+
p.vy = f32$1(p.vy);
|
|
1302
|
+
p.vz = f32$1(p.vz);
|
|
1303
|
+
p.edge = f32$1(p.edge);
|
|
1292
1304
|
};
|
|
1293
1305
|
// src/shared/blade.ts
|
|
1294
1306
|
/** Where on the body the blade is, as a share of its height: the chest, which a brush must not cover. */
|
|
@@ -2012,7 +2024,7 @@ var BLUE$1 = [
|
|
|
2012
2024
|
];
|
|
2013
2025
|
/** The two team tints, red then blue. */
|
|
2014
2026
|
var TEAM_TINT = [RED$1, BLUE$1];
|
|
2015
|
-
var ORANGE = [
|
|
2027
|
+
var ORANGE$1 = [
|
|
2016
2028
|
1,
|
|
2017
2029
|
.42,
|
|
2018
2030
|
.08
|
|
@@ -2352,7 +2364,7 @@ var half$1 = [
|
|
|
2352
2364
|
96,
|
|
2353
2365
|
17.7,
|
|
2354
2366
|
162
|
|
2355
|
-
], TEX.STEEL, TEX.PAINT, ORANGE),
|
|
2367
|
+
], TEX.STEEL, TEX.PAINT, ORANGE$1),
|
|
2356
2368
|
box$1([
|
|
2357
2369
|
82,
|
|
2358
2370
|
14.5,
|
|
@@ -2423,7 +2435,7 @@ var centre$1 = [
|
|
|
2423
2435
|
17.2,
|
|
2424
2436
|
128
|
|
2425
2437
|
], TEX.CONCRETE),
|
|
2426
|
-
pad(38, 17.2, 116, 50, 17.3, 124, ORANGE),
|
|
2438
|
+
pad(38, 17.2, 116, 50, 17.3, 124, ORANGE$1),
|
|
2427
2439
|
...[
|
|
2428
2440
|
[35, 113],
|
|
2429
2441
|
[35, 126.2],
|
|
@@ -2813,7 +2825,7 @@ var HIGHLINE = {
|
|
|
2813
2825
|
]
|
|
2814
2826
|
};
|
|
2815
2827
|
// src/shared/moonbase.ts
|
|
2816
|
-
var { CONCRETE: CONCRETE$1, METAL: METAL$1, STEEL: STEEL$1 } = TEX;
|
|
2828
|
+
var { CONCRETE: CONCRETE$1, METAL: METAL$1, STEEL: STEEL$1, PAINT: PAINT$1 } = TEX;
|
|
2817
2829
|
/** A box, corners (x0, y0, z0) and (x1, y1, z1), tops and sides, a tint. */
|
|
2818
2830
|
var box = (x0, y0, z0, x1, y1, z1, top, side = top, tint) => ({
|
|
2819
2831
|
min: [
|
|
@@ -2852,7 +2864,7 @@ var bx = (x0, y0, z0, x1, y1, z1) => ({
|
|
|
2852
2864
|
var R = 22.4;
|
|
2853
2865
|
var shell = (y) => y < 5 ? R : R * Math.sqrt(1 - ((y - 5) / 12) ** 2);
|
|
2854
2866
|
var q = (v) => Math.round(v * 10) / 10;
|
|
2855
|
-
/** Height bands of the ghost collision
|
|
2867
|
+
/** Height bands of the ghost collision of the dome: the first is its wall, up past a double jump from a module top; the others its roof. */
|
|
2856
2868
|
var BANDS = [
|
|
2857
2869
|
0,
|
|
2858
2870
|
10.5,
|
|
@@ -2871,11 +2883,50 @@ var around = (r) => [
|
|
|
2871
2883
|
[.71, .93],
|
|
2872
2884
|
[.39, 1]
|
|
2873
2885
|
].map(([a, b]) => [q(a * r), q(b * r)]);
|
|
2874
|
-
var
|
|
2875
|
-
|
|
2886
|
+
var [[A0, B0], [A1, B1]] = around(22.599999999999998);
|
|
2887
|
+
var [T, H] = [.4, 2.48];
|
|
2888
|
+
/** Red's dome (its centre: x, z), modules and tubes (each from its module to where they meet at the dome's wall, the second across the end of the first): what the scenery draws on. */
|
|
2876
2889
|
var DOME = [80, 236];
|
|
2877
2890
|
var MODULES = [bx(111, 0, 222, 125, 5, 230), bx(96, 0, 196, 110, 5, 204)];
|
|
2878
|
-
var TUBES = [bx(
|
|
2891
|
+
var TUBES = [bx(102, 0, 223.2, 111, 3.5, 227.2), bx(98, 0, 204, 102, 3.5, 227.2)];
|
|
2892
|
+
var [[TX0, , TZ0], [TX1, TY, TZ1], [UX0, , UZ0], [UX1]] = TUBES.flatMap((t) => [t.min, t.max]);
|
|
2893
|
+
var [[C0, D0], [C1, D1]] = [[19.8, 6.7], [16, 13.5]];
|
|
2894
|
+
/** The mouths in the hall's wall (x and z of the middle from the centre, half width, height, depth): the door toward the flag, the tubes. */
|
|
2895
|
+
var MOUTHS = [[
|
|
2896
|
+
0,
|
|
2897
|
+
-C0,
|
|
2898
|
+
2,
|
|
2899
|
+
3,
|
|
2900
|
+
2.8
|
|
2901
|
+
], [
|
|
2902
|
+
C1,
|
|
2903
|
+
-10.8,
|
|
2904
|
+
2,
|
|
2905
|
+
3.5,
|
|
2906
|
+
2
|
|
2907
|
+
]];
|
|
2908
|
+
/** The rectangles (x0, z0, x1, z1), their mirrors and their quarter turns about the centre, each once. */
|
|
2909
|
+
var turns = (l) => [...new Map(l.flatMap(([x0, z0, x1, z1]) => [1, -1].flatMap((i) => [1, -1].flatMap((j) => [[
|
|
2910
|
+
x0,
|
|
2911
|
+
x1,
|
|
2912
|
+
z0,
|
|
2913
|
+
z1
|
|
2914
|
+
], [
|
|
2915
|
+
z0,
|
|
2916
|
+
z1,
|
|
2917
|
+
x0,
|
|
2918
|
+
x1
|
|
2919
|
+
]].map(([a, b, c, d]) => [
|
|
2920
|
+
Math.min(i * a, i * b),
|
|
2921
|
+
Math.min(j * c, j * d),
|
|
2922
|
+
Math.max(i * a, i * b),
|
|
2923
|
+
Math.max(j * c, j * d)
|
|
2924
|
+
])))).map((p) => [`${p}`, p])).values()];
|
|
2925
|
+
/** A ghost box about the dome's centre, (x0, z0, x1, z1) from y0 to y1. */
|
|
2926
|
+
var ghost = ([x0, z0, x1, z1], y0, y1, top = CONCRETE$1, side = top) => ({
|
|
2927
|
+
...box(DOME[0] + x0, y0, DOME[1] + z0, DOME[0] + x1, y1, DOME[1] + z1, top, side),
|
|
2928
|
+
ghost: true
|
|
2929
|
+
});
|
|
2879
2930
|
/**
|
|
2880
2931
|
* Stairs from `a` to `b` along z (axis 2) or x (0), across `w0` to `w1`, rising from `y` to `top`
|
|
2881
2932
|
* in steps of at most 0.46 m, each a solid from `y`.
|
|
@@ -2888,16 +2939,156 @@ var stairs = (axis, a, b, w0, w1, y, top) => {
|
|
|
2888
2939
|
return axis ? box(w0, y, s, w1, up, t, CONCRETE$1) : box(s, y, w0, t, up, w1, CONCRETE$1);
|
|
2889
2940
|
});
|
|
2890
2941
|
};
|
|
2942
|
+
/**
|
|
2943
|
+
* What stands in the hall, about the dome's centre: ghosts, since client/moonbase.ts draws them
|
|
2944
|
+
* with the hall (the sun's shadow map is 64 m wide, a brush across the hall would be drawn sunlit).
|
|
2945
|
+
* The mezzanine 3.5 m up along the walls (not over the door), the stairs up to it facing the door,
|
|
2946
|
+
* a console and two parapets on it, three crates on the floor.
|
|
2947
|
+
*/
|
|
2948
|
+
var FIT = [
|
|
2949
|
+
...turns([[
|
|
2950
|
+
12,
|
|
2951
|
+
-D1,
|
|
2952
|
+
C1,
|
|
2953
|
+
D1
|
|
2954
|
+
], [
|
|
2955
|
+
C1,
|
|
2956
|
+
-D0,
|
|
2957
|
+
C0,
|
|
2958
|
+
D0
|
|
2959
|
+
]]).filter((p) => p[1] > -C0).map((p) => ghost(p, 3.1, 3.5, METAL$1, STEEL$1)),
|
|
2960
|
+
...stairs(2, DOME[1] + 5.6, DOME[1] + 12, DOME[0] - 1.5, DOME[0] + 1.5, 0, 3.5).map((b) => ({
|
|
2961
|
+
...b,
|
|
2962
|
+
ghost: true
|
|
2963
|
+
})),
|
|
2964
|
+
ghost([
|
|
2965
|
+
-3,
|
|
2966
|
+
19,
|
|
2967
|
+
3,
|
|
2968
|
+
C0
|
|
2969
|
+
], 3.5, 4.6, STEEL$1, METAL$1),
|
|
2970
|
+
ghost([
|
|
2971
|
+
-9,
|
|
2972
|
+
12,
|
|
2973
|
+
-2.5,
|
|
2974
|
+
12.5
|
|
2975
|
+
], 3.5, 4.6, STEEL$1, PAINT$1),
|
|
2976
|
+
ghost([
|
|
2977
|
+
2.5,
|
|
2978
|
+
12,
|
|
2979
|
+
9,
|
|
2980
|
+
12.5
|
|
2981
|
+
], 3.5, 4.6, STEEL$1, PAINT$1),
|
|
2982
|
+
ghost([
|
|
2983
|
+
-6,
|
|
2984
|
+
-8,
|
|
2985
|
+
-4,
|
|
2986
|
+
-6
|
|
2987
|
+
], 0, 1.4, STEEL$1),
|
|
2988
|
+
ghost([
|
|
2989
|
+
4,
|
|
2990
|
+
-8,
|
|
2991
|
+
6,
|
|
2992
|
+
-6
|
|
2993
|
+
], 0, 1.4, STEEL$1),
|
|
2994
|
+
ghost([
|
|
2995
|
+
5.5,
|
|
2996
|
+
1.5,
|
|
2997
|
+
8,
|
|
2998
|
+
4
|
|
2999
|
+
], 0, 2.4, STEEL$1)
|
|
3000
|
+
];
|
|
3001
|
+
/**
|
|
3002
|
+
* A wall along the axis k from a to b, between p and q across, up to y: a doorway H high in each
|
|
3003
|
+
* gap (from, to). A gap of no width only cuts the wall in two: vision.ts stripes a wall of 8 m.
|
|
3004
|
+
*/
|
|
3005
|
+
var wall = (k, a, b, p, q, y, gaps = []) => {
|
|
3006
|
+
const piece = (s, t, y0) => k ? box(p, y0, s, q, y, t, CONCRETE$1) : box(s, y0, p, t, y, q, CONCRETE$1);
|
|
3007
|
+
return [...gaps, [b, b]].flatMap(([s, t], i, l) => [piece(i ? l[i - 1][1] : a, s, 0), ...t > s ? [piece(s, t, H)] : []]);
|
|
3008
|
+
};
|
|
3009
|
+
/** A module: a roof slab on four walls, with the gaps of the walls at its low z, high z, low x and high x. */
|
|
3010
|
+
var room = ({ min: [x0, , z0], max: [x1, y, z1] }, gaps, crate) => [
|
|
3011
|
+
box(x0, 4, z0, x1, y, z1, METAL$1, CONCRETE$1),
|
|
3012
|
+
...wall(0, x0, x1, z0, z0 + T, 4, gaps[0]),
|
|
3013
|
+
...wall(0, x0, x1, z1 - T, z1, 4, gaps[1]),
|
|
3014
|
+
...wall(2, z0 + T, z1 - T, x0, x0 + T, 4, gaps[2]),
|
|
3015
|
+
...wall(2, z0 + T, z1 - T, x1 - T, x1, 4),
|
|
3016
|
+
crate
|
|
3017
|
+
];
|
|
3018
|
+
var ORANGE = [
|
|
3019
|
+
1,
|
|
3020
|
+
.42,
|
|
3021
|
+
.08
|
|
3022
|
+
];
|
|
2891
3023
|
/** Red's half of the base. */
|
|
2892
3024
|
var BASE = [
|
|
2893
|
-
...BANDS.slice(
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
...
|
|
2900
|
-
|
|
3025
|
+
...BANDS.slice(2).flatMap((y1, i) => around(shell(BANDS[i + 1]) + .2).map(([a, b]) => ghost([
|
|
3026
|
+
-a,
|
|
3027
|
+
-b,
|
|
3028
|
+
a,
|
|
3029
|
+
b
|
|
3030
|
+
], BANDS[i + 1], y1))),
|
|
3031
|
+
...turns([
|
|
3032
|
+
[
|
|
3033
|
+
C0,
|
|
3034
|
+
-B0,
|
|
3035
|
+
A0,
|
|
3036
|
+
B0
|
|
3037
|
+
],
|
|
3038
|
+
[
|
|
3039
|
+
C1,
|
|
3040
|
+
D0,
|
|
3041
|
+
A1,
|
|
3042
|
+
B1
|
|
3043
|
+
],
|
|
3044
|
+
[
|
|
3045
|
+
D1,
|
|
3046
|
+
D1,
|
|
3047
|
+
C1,
|
|
3048
|
+
C1
|
|
3049
|
+
]
|
|
3050
|
+
]).map((p) => ghost(p, MOUTHS.find(([x, z]) => p[0] <= x && x <= p[2] && p[1] <= z && z <= p[3])?.[3] ?? 0, BANDS[1])),
|
|
3051
|
+
...[
|
|
3052
|
+
[
|
|
3053
|
+
-B0,
|
|
3054
|
+
-A0,
|
|
3055
|
+
-MOUTHS[0][2],
|
|
3056
|
+
-C0
|
|
3057
|
+
],
|
|
3058
|
+
[
|
|
3059
|
+
MOUTHS[0][2],
|
|
3060
|
+
-A0,
|
|
3061
|
+
B0,
|
|
3062
|
+
-C0
|
|
3063
|
+
],
|
|
3064
|
+
[
|
|
3065
|
+
C1,
|
|
3066
|
+
TZ1 - DOME[1],
|
|
3067
|
+
A1,
|
|
3068
|
+
-D0
|
|
3069
|
+
],
|
|
3070
|
+
[
|
|
3071
|
+
C1,
|
|
3072
|
+
-B1,
|
|
3073
|
+
UX0 - DOME[0],
|
|
3074
|
+
TZ0 - DOME[1]
|
|
3075
|
+
]
|
|
3076
|
+
].map((p) => ghost(p, 0, BANDS[1])),
|
|
3077
|
+
...FIT,
|
|
3078
|
+
...room(MODULES[0], [
|
|
3079
|
+
[[118, 118]],
|
|
3080
|
+
[[116.8, 119.2]],
|
|
3081
|
+
[[TZ0 + T, TZ1 - T]]
|
|
3082
|
+
], box(121.5, 0, 223.5, 123.5, 1.2, 225.5, PAINT$1, PAINT$1, ORANGE)),
|
|
3083
|
+
...room(MODULES[1], [[[101.8, 104.2]], [[UX0 + T, UX1 - T], [105.8, 105.8]]], box(106, 0, 200.6, 108, 1.2, 202.6, PAINT$1, PAINT$1, ORANGE)),
|
|
3084
|
+
box(TX0, H, TZ0, TX1, TY, TZ1, STEEL$1, METAL$1),
|
|
3085
|
+
box(UX0, H, UZ0, UX1, TY, TZ1, STEEL$1, METAL$1),
|
|
3086
|
+
box(UX0, 0, TZ1 - T, TX1, H, TZ1, METAL$1),
|
|
3087
|
+
box(UX1 - T, 0, TZ0, TX1, H, TZ0 + T, METAL$1),
|
|
3088
|
+
box(UX0, 0, UZ0, UX0 + T, H, TZ0, METAL$1),
|
|
3089
|
+
box(UX1 - T, 0, UZ0, UX1, H, TZ0, METAL$1),
|
|
3090
|
+
...stairs(2, 214, TZ0, 105, 109, 0, 3.5),
|
|
3091
|
+
...stairs(0, 108, UX1, 206, 210, 0, 3.5)
|
|
2901
3092
|
];
|
|
2902
3093
|
var [RED, BLUE] = TEAM_TINT;
|
|
2903
3094
|
var { STONE, CONCRETE, METAL, STEEL, PAINT } = TEX;
|
|
@@ -3049,7 +3240,7 @@ var WRECK = [BOWLS[0][0], 140];
|
|
|
3049
3240
|
* is 20 m high on it and, past it where nobody goes, climbs to a ragged crest of 60 to 95 m and
|
|
3050
3241
|
* falls to the plain at 1.65 of the bound.
|
|
3051
3242
|
*/
|
|
3052
|
-
var at = (x, z) => {
|
|
3243
|
+
var at$1 = (x, z) => {
|
|
3053
3244
|
z = Math.abs(z - 140);
|
|
3054
3245
|
const k = far((x - 80) / 300, z / 360);
|
|
3055
3246
|
const t = Math.max((k - .78) / .22, 0);
|
|
@@ -3072,7 +3263,7 @@ var at = (x, z) => {
|
|
|
3072
3263
|
};
|
|
3073
3264
|
/** The ghost under a drawn rock or mast: a box of half side s from under the ground to h above it. */
|
|
3074
3265
|
var lump = (x, z, s, h) => ({
|
|
3075
|
-
...box(x - s, at(x, z) - 6, z - s, x + s, at(x, z) + h, z + s, STONE),
|
|
3266
|
+
...box(x - s, at$1(x, z) - 6, z - s, x + s, at$1(x, z) + h, z + s, STONE),
|
|
3076
3267
|
ghost: true
|
|
3077
3268
|
});
|
|
3078
3269
|
[...FIELD, ...FIELD.map(([x, z, r]) => [
|
|
@@ -3271,6 +3462,11 @@ var MAPS = {
|
|
|
3271
3462
|
30,
|
|
3272
3463
|
0,
|
|
3273
3464
|
185
|
|
3465
|
+
],
|
|
3466
|
+
[
|
|
3467
|
+
80,
|
|
3468
|
+
3.5,
|
|
3469
|
+
253.5
|
|
3274
3470
|
]
|
|
3275
3471
|
], [
|
|
3276
3472
|
45,
|
|
@@ -3334,7 +3530,7 @@ var MAPS = {
|
|
|
3334
3530
|
360
|
|
3335
3531
|
],
|
|
3336
3532
|
cell: 4,
|
|
3337
|
-
at
|
|
3533
|
+
at: at$1
|
|
3338
3534
|
},
|
|
3339
3535
|
sun: {
|
|
3340
3536
|
dir: [
|
|
@@ -3358,6 +3554,32 @@ var MAPS = {
|
|
|
3358
3554
|
.035
|
|
3359
3555
|
]],
|
|
3360
3556
|
gravity: .5,
|
|
3557
|
+
rovers: [
|
|
3558
|
+
[
|
|
3559
|
+
100,
|
|
3560
|
+
0,
|
|
3561
|
+
178,
|
|
3562
|
+
0
|
|
3563
|
+
],
|
|
3564
|
+
[
|
|
3565
|
+
30,
|
|
3566
|
+
0,
|
|
3567
|
+
255,
|
|
3568
|
+
0
|
|
3569
|
+
],
|
|
3570
|
+
[
|
|
3571
|
+
100,
|
|
3572
|
+
0,
|
|
3573
|
+
102,
|
|
3574
|
+
Math.PI
|
|
3575
|
+
],
|
|
3576
|
+
[
|
|
3577
|
+
30,
|
|
3578
|
+
0,
|
|
3579
|
+
25,
|
|
3580
|
+
Math.PI
|
|
3581
|
+
]
|
|
3582
|
+
],
|
|
3361
3583
|
scenery: "moon",
|
|
3362
3584
|
helmets: true
|
|
3363
3585
|
}
|
|
@@ -3467,6 +3689,23 @@ var fly = (w, b, m, foes) => {
|
|
|
3467
3689
|
];
|
|
3468
3690
|
return hit;
|
|
3469
3691
|
};
|
|
3692
|
+
/** A rover's floats, in wire order. */
|
|
3693
|
+
var ROVER_F = [...[
|
|
3694
|
+
"x",
|
|
3695
|
+
"y",
|
|
3696
|
+
"z",
|
|
3697
|
+
"vx",
|
|
3698
|
+
"vy",
|
|
3699
|
+
"vz",
|
|
3700
|
+
"yaw"
|
|
3701
|
+
], ...[
|
|
3702
|
+
"pitch",
|
|
3703
|
+
"roll",
|
|
3704
|
+
"wy",
|
|
3705
|
+
"wp",
|
|
3706
|
+
"wr",
|
|
3707
|
+
"steer"
|
|
3708
|
+
]];
|
|
3470
3709
|
/** The no-gun value of the ammo's 7 bits. */
|
|
3471
3710
|
var NO_GUN = 127;
|
|
3472
3711
|
/** A flag's resting place on the wire: 1/16 m in an i16, so ±2 km. A ball's: 1/32 m, ±1 km. */
|
|
@@ -3499,13 +3738,15 @@ var decodeInput = (buf) => {
|
|
|
3499
3738
|
/** Bytes of a flag on the wire, by its state. */
|
|
3500
3739
|
var flagBytes = (state) => state === FLAG.CARRIED ? 2 : state === FLAG.DROPPED ? 8 : 1;
|
|
3501
3740
|
var encodeSnapshot = (s) => {
|
|
3502
|
-
const
|
|
3741
|
+
const rovers = (s.rovers ?? []).slice(0, 7);
|
|
3742
|
+
const mid = 4 + 61 * s.players.length;
|
|
3743
|
+
const end = mid + 54 * rovers.length;
|
|
3503
3744
|
const balls = s.balls ?? [];
|
|
3504
3745
|
const tail = end + 10 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0);
|
|
3505
3746
|
const v = new DataView(new ArrayBuffer(tail + (balls.length && 1 + 11 * balls.length)));
|
|
3506
3747
|
v.setUint8(0, 2);
|
|
3507
3748
|
v.setUint16(1, s.tick & 65535);
|
|
3508
|
-
v.setUint8(3, s.players.length);
|
|
3749
|
+
v.setUint8(3, s.players.length | rovers.length << 5);
|
|
3509
3750
|
s.players.forEach((p, i) => {
|
|
3510
3751
|
const o = 4 + i * 61;
|
|
3511
3752
|
v.setUint8(o, p.id);
|
|
@@ -3537,7 +3778,7 @@ var encodeSnapshot = (s) => {
|
|
|
3537
3778
|
v.setUint8(o + 50, p.pushes ?? 0);
|
|
3538
3779
|
v.setUint8(o + 51, p.away ?? 0);
|
|
3539
3780
|
v.setUint8(o + 52, (p.rail ?? -1) + 1);
|
|
3540
|
-
v.setUint8(o + 53, +!!p.railed | +!!p.inRail << 1 | +!!p.zapping << 2 | +!!p.rifled << 3 | +!!p.inRifle << 4 | +!!p.hot << 5);
|
|
3781
|
+
v.setUint8(o + 53, +!!p.railed | +!!p.inRail << 1 | +!!p.zapping << 2 | +!!p.rifled << 3 | +!!p.inRifle << 4 | +!!p.hot << 5 | (p.held & KEY.USE ? 64 : 0));
|
|
3541
3782
|
v.setUint8(o + 54, p.slow ?? 0);
|
|
3542
3783
|
v.setUint8(o + 55, p.mag ?? 0);
|
|
3543
3784
|
v.setUint8(o + 56, p.cap ?? 0);
|
|
@@ -3546,6 +3787,12 @@ var encodeSnapshot = (s) => {
|
|
|
3546
3787
|
v.setUint8(o + 59, p.clip ?? 0);
|
|
3547
3788
|
v.setUint8(o + 60, p.heat ?? 0);
|
|
3548
3789
|
});
|
|
3790
|
+
rovers.forEach((r, i) => {
|
|
3791
|
+
const o = mid + i * 54;
|
|
3792
|
+
ROVER_F.forEach((k, j) => v.setFloat32(o + 4 * j, r[k]));
|
|
3793
|
+
v.setUint8(o + 52, r.driver);
|
|
3794
|
+
v.setUint8(o + 53, r.rider);
|
|
3795
|
+
});
|
|
3549
3796
|
v.setUint8(end, s.score[0]);
|
|
3550
3797
|
v.setUint8(end + 1, s.score[1]);
|
|
3551
3798
|
v.setUint16(end + 2, s.clock & 32767 | (s.over ? 32768 : 0));
|
|
@@ -3621,6 +3868,343 @@ var beam = (w, p, foes = [], range = 30, [dy, dp] = [0, 0]) => {
|
|
|
3621
3868
|
hit
|
|
3622
3869
|
};
|
|
3623
3870
|
};
|
|
3871
|
+
// src/shared/rover.ts
|
|
3872
|
+
/** The rover's sizes and its handling (docs/MOON.md). Lengths in metres, per wheel rates for a body of mass 1. */
|
|
3873
|
+
var ROVER = {
|
|
3874
|
+
/** Half the wheelbase, half the track, the wheel's radius. */
|
|
3875
|
+
A: 1.25,
|
|
3876
|
+
B: 1,
|
|
3877
|
+
WR: .5,
|
|
3878
|
+
/** The spring's length at rest from the body's centre down to the hub, and its travel. */
|
|
3879
|
+
L0: .6,
|
|
3880
|
+
CMAX: .5,
|
|
3881
|
+
/** Stiffness (1/s²) and damping (1/s) of a spring. */
|
|
3882
|
+
K: 30,
|
|
3883
|
+
D: 2,
|
|
3884
|
+
/** Squared radii of gyration in pitch and roll, and the height of the centre the tyre forces lever on. */
|
|
3885
|
+
KP2: 1.2,
|
|
3886
|
+
KR2: .7,
|
|
3887
|
+
HC: .7,
|
|
3888
|
+
/** Engine and brake (m/s²), the top speed forward and in reverse, rolling drag and the handbrake's. */
|
|
3889
|
+
ENGINE: 12,
|
|
3890
|
+
VMAX: 23.2,
|
|
3891
|
+
VREV: 8,
|
|
3892
|
+
BRAKE: 14,
|
|
3893
|
+
ROLL: .6,
|
|
3894
|
+
HB: 6,
|
|
3895
|
+
/** Grip sideways and in traction, as shares of the load; under the handbrake, the share left sideways and how much faster the nose comes round. */
|
|
3896
|
+
MU: 1.1,
|
|
3897
|
+
MUL: 1.2,
|
|
3898
|
+
HBG: .35,
|
|
3899
|
+
HBY: 1.5,
|
|
3900
|
+
/** Steering toward the driver's look: gain, the speed that halves it, the lock, its rate, and the yaw rate's cap and response. */
|
|
3901
|
+
SK: 2.5,
|
|
3902
|
+
SV: 10,
|
|
3903
|
+
SMAX: .55,
|
|
3904
|
+
SRATE: 3.5,
|
|
3905
|
+
YMAX: 2.4,
|
|
3906
|
+
YRESP: 10,
|
|
3907
|
+
/** In the air: the pull back to level, its damping, the rates' decay, and the tilt nothing passes. */
|
|
3908
|
+
AK: 5,
|
|
3909
|
+
AC: 3,
|
|
3910
|
+
AD: .5,
|
|
3911
|
+
TILT: .9,
|
|
3912
|
+
/**
|
|
3913
|
+
* The body against the brushes: circles of radius RB at BODY along the nose, BODY_H tall. A wheel
|
|
3914
|
+
* takes for its floor what is at most WHEEL_STEP above its hub with the spring out; the body
|
|
3915
|
+
* passes over a brush no more than STEP_H above the wheels' floor, like a player.
|
|
3916
|
+
*/
|
|
3917
|
+
RB: 1.05,
|
|
3918
|
+
BODY: [
|
|
3919
|
+
1.15,
|
|
3920
|
+
0,
|
|
3921
|
+
-1.15
|
|
3922
|
+
],
|
|
3923
|
+
BODY_H: 1.5,
|
|
3924
|
+
WHEEL_STEP: .6,
|
|
3925
|
+
/** A player this close to a rover's centre gets in; a rover this fast hurts an enemy, and this fast puts him down. */
|
|
3926
|
+
ENTER_R: 3,
|
|
3927
|
+
SPLAT_MIN: 6,
|
|
3928
|
+
SPLAT_KILL: 12
|
|
3929
|
+
};
|
|
3930
|
+
/** The seats, driver then rider: right of the centre, above it (the feet), ahead of it. */
|
|
3931
|
+
var SEATS$1 = [[
|
|
3932
|
+
-.45,
|
|
3933
|
+
-.35,
|
|
3934
|
+
.1
|
|
3935
|
+
], [
|
|
3936
|
+
.45,
|
|
3937
|
+
-.35,
|
|
3938
|
+
.1
|
|
3939
|
+
]];
|
|
3940
|
+
/** The wheels, front left, front right, rear left, rear right: ahead of the centre and to its right. */
|
|
3941
|
+
var AI = [
|
|
3942
|
+
1,
|
|
3943
|
+
1,
|
|
3944
|
+
-1,
|
|
3945
|
+
-1
|
|
3946
|
+
].map((s) => s * ROVER.A);
|
|
3947
|
+
var BI = [
|
|
3948
|
+
-1,
|
|
3949
|
+
1,
|
|
3950
|
+
-1,
|
|
3951
|
+
1
|
|
3952
|
+
].map((s) => s * ROVER.B);
|
|
3953
|
+
/** From the centre down to the bottom of a wheel on a spring at rest. */
|
|
3954
|
+
var DROP = ROVER.L0 + ROVER.WR;
|
|
3955
|
+
/** Where who gets out stands, from the centre to the side: clear of the body. And the drop he does not get out over. */
|
|
3956
|
+
var OUT = ROVER.RB + PLAYER_R + .15;
|
|
3957
|
+
var LEDGE = 1;
|
|
3958
|
+
/** The numbers of the state: float32 after every step, and on the wire. */
|
|
3959
|
+
var FLOATS = "x y z vx vy vz yaw pitch roll wy wp wr steer".split(" ");
|
|
3960
|
+
var DT = 1 / 60;
|
|
3961
|
+
var f32 = Math.fround;
|
|
3962
|
+
var { sin, cos, min, max, abs, sqrt } = Math;
|
|
3963
|
+
var clamp = (v, lo, hi) => min(max(v, lo), hi);
|
|
3964
|
+
/**
|
|
3965
|
+
* A point of the body, `a` m ahead of the centre, `b` m to its right and `u` m above: it leans with
|
|
3966
|
+
* the pitch (nose up) and the roll (right side down).
|
|
3967
|
+
*/
|
|
3968
|
+
var at = (r, a, b, u = 0) => {
|
|
3969
|
+
const [fx, fz] = forward(r.yaw);
|
|
3970
|
+
const [ca, cb] = [a * cos(r.pitch), b * cos(r.roll)];
|
|
3971
|
+
return [
|
|
3972
|
+
r.x + fx * ca - fz * cb,
|
|
3973
|
+
r.y + u + a * sin(r.pitch) - b * sin(r.roll),
|
|
3974
|
+
r.z + fz * ca + fx * cb
|
|
3975
|
+
];
|
|
3976
|
+
};
|
|
3977
|
+
/**
|
|
3978
|
+
* Each wheel's corner of the body, and how far the floor under it squeezes the spring: below 0 the
|
|
3979
|
+
* wheel hangs. Its floor is at most WHEEL_STEP above the hub of the spring at rest: what is higher
|
|
3980
|
+
* is over it, or a wall for the body.
|
|
3981
|
+
*/
|
|
3982
|
+
var corners = (r, w) => AI.map((a, k) => {
|
|
3983
|
+
const [x, y, z] = at(r, a, BI[k]);
|
|
3984
|
+
return [
|
|
3985
|
+
x,
|
|
3986
|
+
y,
|
|
3987
|
+
z,
|
|
3988
|
+
DROP + floorAt(w, x, z, y - ROVER.L0 + ROVER.WHEEL_STEP) - y
|
|
3989
|
+
];
|
|
3990
|
+
});
|
|
3991
|
+
/**
|
|
3992
|
+
* The body as the brushes and a run-over meet it: the centres of three circles of radius RB along
|
|
3993
|
+
* the nose, front first, each at the height of its bottom, BODY_H under its top.
|
|
3994
|
+
*/
|
|
3995
|
+
var footprint = (r) => ROVER.BODY.map((a) => at(r, a, 0, -DROP));
|
|
3996
|
+
/** The map's rovers at rest on their spawns, nobody aboard. */
|
|
3997
|
+
var park = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
|
|
3998
|
+
x: f32(x),
|
|
3999
|
+
y: f32(y + DROP),
|
|
4000
|
+
z: f32(z),
|
|
4001
|
+
vx: 0,
|
|
4002
|
+
vy: 0,
|
|
4003
|
+
vz: 0,
|
|
4004
|
+
yaw: f32(norm(yaw)),
|
|
4005
|
+
pitch: 0,
|
|
4006
|
+
roll: 0,
|
|
4007
|
+
wy: 0,
|
|
4008
|
+
wp: 0,
|
|
4009
|
+
wr: 0,
|
|
4010
|
+
steer: 0,
|
|
4011
|
+
driver: 255,
|
|
4012
|
+
rider: 255
|
|
4013
|
+
}));
|
|
4014
|
+
/**
|
|
4015
|
+
* One step of 1 / TICK_HZ s, in place. `i` is the driver's input as the wire rounds it (FORWARD and
|
|
4016
|
+
* BACK the throttle, JUMP the handbrake, its yaw where the nose is steered to), or undefined with
|
|
4017
|
+
* nobody at the wheel: the brake is on. Reads only the rover, the input and the world. Returns
|
|
4018
|
+
* whether it fell under the world's kill floor: the caller parks it again.
|
|
4019
|
+
*
|
|
4020
|
+
* The body is a point with a pitch and a roll on four springs. Each wheel reads the floor under
|
|
4021
|
+
* its hub; the four heights give the ground's slope, the springs push along its normal, and the
|
|
4022
|
+
* tyres work on the speed along the nose and across it. Yaw is steered, not simulated: the nose
|
|
4023
|
+
* turns toward the look as fast as the speed allows, and the tyres' grip decides how much of the
|
|
4024
|
+
* speed follows it. The rest drifts.
|
|
4025
|
+
*/
|
|
4026
|
+
var drive = (r, i, w) => {
|
|
4027
|
+
const { A, B, CMAX, K, D, KP2, KR2, HC, MU, MUL, TILT } = ROVER;
|
|
4028
|
+
const g = gravity(w);
|
|
4029
|
+
const keys = i ? i.keys : 0;
|
|
4030
|
+
const thr = (keys & KEY.FORWARD ? 1 : 0) - (keys & KEY.BACK ? 1 : 0);
|
|
4031
|
+
const hb = keys & KEY.JUMP;
|
|
4032
|
+
const [fx, fz] = forward(r.yaw);
|
|
4033
|
+
const [cp, cr] = [cos(r.pitch), cos(r.roll)];
|
|
4034
|
+
const c = corners(r, w);
|
|
4035
|
+
const [g0, g1, g2, g3] = c.map(([, y, , k]) => k + y - DROP);
|
|
4036
|
+
const flat = c.some((k) => k[3] < -CMAX);
|
|
4037
|
+
const sf = flat ? 0 : (g0 + g1 - g2 - g3) / (4 * A * cp);
|
|
4038
|
+
const sr = flat ? 0 : (g1 + g3 - g0 - g2) / (4 * B * cr);
|
|
4039
|
+
const ny = 1 / sqrt(sf * sf + sr * sr + 1);
|
|
4040
|
+
const nx = -(sf * fx - sr * fz) * ny;
|
|
4041
|
+
const nz = -(sf * fz + sr * fx) * ny;
|
|
4042
|
+
const along = () => r.vx * nx + r.vy * ny + r.vz * nz;
|
|
4043
|
+
const pen = max(0, ...c.map((k) => k[3] - CMAX));
|
|
4044
|
+
if (pen) {
|
|
4045
|
+
r.y += pen;
|
|
4046
|
+
const v = min(0, along());
|
|
4047
|
+
r.vx -= v * nx;
|
|
4048
|
+
r.vy -= v * ny;
|
|
4049
|
+
r.vz -= v * nz;
|
|
4050
|
+
}
|
|
4051
|
+
const vn = along();
|
|
4052
|
+
let [s, tp, tr] = [
|
|
4053
|
+
0,
|
|
4054
|
+
0,
|
|
4055
|
+
0
|
|
4056
|
+
];
|
|
4057
|
+
c.forEach(([, , , k], n) => {
|
|
4058
|
+
if (k > pen) {
|
|
4059
|
+
const f = max(0, K * (k - pen) - D * (vn + (AI[n] * cp * r.wp - BI[n] * cr * r.wr) * ny));
|
|
4060
|
+
s += f;
|
|
4061
|
+
tp += f * AI[n];
|
|
4062
|
+
tr += f * BI[n];
|
|
4063
|
+
}
|
|
4064
|
+
});
|
|
4065
|
+
r.vx += s * nx * DT;
|
|
4066
|
+
r.vy += (s * ny - g) * DT;
|
|
4067
|
+
r.vz += s * nz * DT;
|
|
4068
|
+
r.wp += tp / KP2 * DT;
|
|
4069
|
+
r.wr -= tr / KR2 * DT;
|
|
4070
|
+
const load = min(s / g, 2);
|
|
4071
|
+
if (load > 0) {
|
|
4072
|
+
const vl = r.vx * fx + r.vz * fz;
|
|
4073
|
+
const vs = r.vz * fx - r.vx * fz;
|
|
4074
|
+
const err = i ? norm(i.yaw - r.yaw + Math.PI) - Math.PI : 0;
|
|
4075
|
+
const lock = clamp(ROVER.SK * err / (1 + abs(vl) / ROVER.SV), -ROVER.SMAX, ROVER.SMAX);
|
|
4076
|
+
const turn = ROVER.SRATE * DT;
|
|
4077
|
+
r.steer += clamp((vl + thr < 0 ? -lock : lock) - r.steer, -turn, turn);
|
|
4078
|
+
const spin = clamp(vl * r.steer / (2 * A), -ROVER.YMAX, ROVER.YMAX) * (hb ? ROVER.HBY : 1);
|
|
4079
|
+
r.wy += (spin - r.wy) * ROVER.YRESP * DT * min(1, load);
|
|
4080
|
+
const grip = g * load * DT;
|
|
4081
|
+
let dl = clamp((thr * vl < 0 ? thr * ROVER.BRAKE : thr * ROVER.ENGINE * max(0, 1 - abs(vl) / (thr > 0 ? ROVER.VMAX : ROVER.VREV))) * DT, -MUL * grip, MUL * grip);
|
|
4082
|
+
const drag = (ROVER.ROLL + (hb || !i ? ROVER.HB : 0)) * load * DT;
|
|
4083
|
+
dl -= clamp(vl + dl, -drag, drag);
|
|
4084
|
+
const side = MU * grip * (hb ? ROVER.HBG : 1);
|
|
4085
|
+
const ds = -clamp(vs, -side, side);
|
|
4086
|
+
r.vx += dl * fx - ds * fz;
|
|
4087
|
+
r.vz += dl * fz + ds * fx;
|
|
4088
|
+
r.wp += dl * HC / KP2;
|
|
4089
|
+
r.wr -= ds * HC / KR2;
|
|
4090
|
+
} else {
|
|
4091
|
+
r.wp -= (ROVER.AK * r.pitch + ROVER.AC * r.wp) * DT;
|
|
4092
|
+
r.wr -= (ROVER.AK * r.roll + ROVER.AC * r.wr) * DT;
|
|
4093
|
+
}
|
|
4094
|
+
r.wp *= 1 - ROVER.AD * DT;
|
|
4095
|
+
r.wr *= 1 - ROVER.AD * DT;
|
|
4096
|
+
r.x += r.vx * DT;
|
|
4097
|
+
r.y += r.vy * DT;
|
|
4098
|
+
r.z += r.vz * DT;
|
|
4099
|
+
r.yaw = norm(r.yaw + r.wy * DT);
|
|
4100
|
+
r.pitch = clamp(r.pitch + r.wp * DT, -TILT, TILT);
|
|
4101
|
+
r.roll = clamp(r.roll + r.wr * DT, -TILT, TILT);
|
|
4102
|
+
if (abs(r.pitch) === TILT && r.pitch * r.wp > 0) r.wp = 0;
|
|
4103
|
+
if (abs(r.roll) === TILT && r.roll * r.wr > 0) r.wr = 0;
|
|
4104
|
+
for (const a of ROVER.BODY) {
|
|
4105
|
+
const [x, y, z] = at(r, a, 0, -DROP);
|
|
4106
|
+
const [px, pz] = shove({
|
|
4107
|
+
x,
|
|
4108
|
+
y: max(y, g0, g1, g2, g3),
|
|
4109
|
+
z
|
|
4110
|
+
}, w, ROVER.BODY_H, ROVER.RB);
|
|
4111
|
+
const d = px * px + pz * pz;
|
|
4112
|
+
if (d) {
|
|
4113
|
+
r.x += px;
|
|
4114
|
+
r.z += pz;
|
|
4115
|
+
const v = min(0, r.vx * px + r.vz * pz) / d;
|
|
4116
|
+
r.vx -= v * px;
|
|
4117
|
+
r.vz -= v * pz;
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
bound(r, w);
|
|
4121
|
+
for (const k of FLOATS) r[k] = f32(r[k]);
|
|
4122
|
+
return r.y < w.def.floor;
|
|
4123
|
+
};
|
|
4124
|
+
/**
|
|
4125
|
+
* Puts the body of a player on seat `s` (0 the driver's, 1 the rider's) of the rover, with its
|
|
4126
|
+
* speed. The seat leans with the body: on a slope he is not left in the air.
|
|
4127
|
+
*/
|
|
4128
|
+
var seat = (p, r, s) => {
|
|
4129
|
+
const [side, up, ahead] = SEATS$1[s];
|
|
4130
|
+
[p.x, p.y, p.z] = at(r, ahead, side, up).map(f32);
|
|
4131
|
+
p.vx = r.vx;
|
|
4132
|
+
p.vy = r.vy;
|
|
4133
|
+
p.vz = r.vz;
|
|
4134
|
+
};
|
|
4135
|
+
/**
|
|
4136
|
+
* The player takes seat `s`: he rides (MODE.RIDE) from the next step on. What a seated body is not
|
|
4137
|
+
* doing ends: a dash's burst (as in stumble()), a hang or a climb, a jump press kept for a landing.
|
|
4138
|
+
*/
|
|
4139
|
+
var board = (p, r, s) => {
|
|
4140
|
+
r[s ? "rider" : "driver"] = p.id;
|
|
4141
|
+
p.mode = MODE.RIDE;
|
|
4142
|
+
p.t = 0;
|
|
4143
|
+
p.edge = 0;
|
|
4144
|
+
p.ground = false;
|
|
4145
|
+
p.dash = min(p.dash, 50);
|
|
4146
|
+
p.coyote = 0;
|
|
4147
|
+
p.buffer = 0;
|
|
4148
|
+
seat(p, r, s);
|
|
4149
|
+
};
|
|
4150
|
+
/**
|
|
4151
|
+
* The player gets out of seat `s`: in the air, with the rover's speed. Beside it on the side of his
|
|
4152
|
+
* seat when a standing body fits there on a floor, else on the other side, else on top of it: over
|
|
4153
|
+
* a drop, between two walls, in flight. Never in a brush or under the ground. Reads only the two
|
|
4154
|
+
* and the world.
|
|
4155
|
+
*/
|
|
4156
|
+
var leave = (p, r, s, w) => {
|
|
4157
|
+
r[s ? "rider" : "driver"] = 255;
|
|
4158
|
+
p.mode = MODE.AIR;
|
|
4159
|
+
p.t = 0;
|
|
4160
|
+
p.coyote = 0;
|
|
4161
|
+
[p.vx, p.vy, p.vz] = [
|
|
4162
|
+
r.vx,
|
|
4163
|
+
r.vy,
|
|
4164
|
+
r.vz
|
|
4165
|
+
];
|
|
4166
|
+
const side = s ? OUT : -OUT;
|
|
4167
|
+
for (const [b, u] of [
|
|
4168
|
+
[side, -DROP],
|
|
4169
|
+
[-side, -DROP],
|
|
4170
|
+
[0, ROVER.BODY_H - DROP]
|
|
4171
|
+
]) {
|
|
4172
|
+
const [x, y, z] = at(r, SEATS$1[s][2], b, u);
|
|
4173
|
+
Object.assign(p, {
|
|
4174
|
+
x,
|
|
4175
|
+
y,
|
|
4176
|
+
z
|
|
4177
|
+
});
|
|
4178
|
+
bound(p, w);
|
|
4179
|
+
const floor = floorAt(w, p.x, p.z, r.y);
|
|
4180
|
+
p.y = max(y, floor);
|
|
4181
|
+
const [px, pz] = shove(p, w, PLAYER_H, PLAYER_R);
|
|
4182
|
+
if (!b || floor > y - LEDGE && !px && !pz) break;
|
|
4183
|
+
}
|
|
4184
|
+
[p.x, p.y, p.z, p.vx, p.vz] = [
|
|
4185
|
+
p.x,
|
|
4186
|
+
p.y,
|
|
4187
|
+
p.z,
|
|
4188
|
+
p.vx,
|
|
4189
|
+
p.vz
|
|
4190
|
+
].map(f32);
|
|
4191
|
+
};
|
|
4192
|
+
/**
|
|
4193
|
+
* The driver's whole step, on the host and in the predictor alike: the rover is driven by his
|
|
4194
|
+
* input, he follows on his seat, and a press of USE gets him out. Returns drive()'s answer. A step
|
|
4195
|
+
* that takes him off his seat (move() puts a body under the kill floor back at a spawn) frees it.
|
|
4196
|
+
*/
|
|
4197
|
+
var ride = (p, r, i, w, team) => {
|
|
4198
|
+
const out = (i.keys & KEY.USE) !== 0 && (p.held & KEY.USE) === 0;
|
|
4199
|
+
const fell = drive(r, i, w);
|
|
4200
|
+
step(p, i, w, team, false);
|
|
4201
|
+
if (p.mode !== MODE.RIDE) r.driver = 255;
|
|
4202
|
+
else {
|
|
4203
|
+
seat(p, r, 0);
|
|
4204
|
+
if (out) leave(p, r, 0, w);
|
|
4205
|
+
}
|
|
4206
|
+
return fell;
|
|
4207
|
+
};
|
|
3624
4208
|
// src/shared/tackle.ts
|
|
3625
4209
|
/** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
|
|
3626
4210
|
var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
|
|
@@ -3634,6 +4218,10 @@ var reaches = (a, b) => Math.hypot(a.x - b.x, a.z - b.z) < 1.1 && a.y < b.y + he
|
|
|
3634
4218
|
var MAX_CATCH_UP = 20;
|
|
3635
4219
|
/** A new player does not spawn within this many metres of another one. */
|
|
3636
4220
|
var SPAWN_CLEAR = 2;
|
|
4221
|
+
/** Ticks before a rover can run the same player over again. */
|
|
4222
|
+
var SPLAT_COOLDOWN = 30;
|
|
4223
|
+
/** The two seats of a rover, the driver's first. */
|
|
4224
|
+
var SEATS = ["driver", "rider"];
|
|
3637
4225
|
/** First n characters (code points) of s, trimmed. */
|
|
3638
4226
|
var cut = (s, n) => Array.from(s).slice(0, n).join("").trim();
|
|
3639
4227
|
var cleanName = (raw) => cut((typeof raw === "string" ? raw : "").replace(/\s+/g, " ").replace(/\p{Cc}/gu, "").trim(), 16);
|
|
@@ -3643,6 +4231,7 @@ var unique = (name, taken) => {
|
|
|
3643
4231
|
for (let n = 2; taken.includes(out); n++) out = `${cut(name, 15 - `${n}`.length)} ${n}`;
|
|
3644
4232
|
return out;
|
|
3645
4233
|
};
|
|
4234
|
+
var len = (x, z) => Math.sqrt(x * x + z * z);
|
|
3646
4235
|
var setEvery = (cb, ms) => {
|
|
3647
4236
|
const id = setInterval(cb, ms);
|
|
3648
4237
|
return () => clearInterval(id);
|
|
@@ -3666,6 +4255,9 @@ var setEvery = (cb, ms) => {
|
|
|
3666
4255
|
* - The host is the player in the room the longest; when he leaves, the next oldest. Only his
|
|
3667
4256
|
* { t: 'map', map } counts: the map (a MAPS key) is played from the next match on, or from the
|
|
3668
4257
|
* next join once the room is empty. The roster tells everyone the host and the map picked.
|
|
4258
|
+
* - The map's rovers (rover.ts) are in every snapshot. A press of USE near one seats a player; a
|
|
4259
|
+
* driven rover is stepped by its driver's inputs alone (ride()), a driverless one by the tick.
|
|
4260
|
+
* seats() keeps the seats and the players' MODE.RIDE in step.
|
|
3669
4261
|
*/
|
|
3670
4262
|
/** A player out of any saber lock. */
|
|
3671
4263
|
var FREE = {
|
|
@@ -3682,6 +4274,12 @@ var pick = ({ x, y, z, yaw }) => ({
|
|
|
3682
4274
|
z,
|
|
3683
4275
|
yaw
|
|
3684
4276
|
});
|
|
4277
|
+
/** Where a player stands. */
|
|
4278
|
+
var spot = ({ x, y, z }) => ({
|
|
4279
|
+
x,
|
|
4280
|
+
y,
|
|
4281
|
+
z
|
|
4282
|
+
});
|
|
3685
4283
|
var Room = class {
|
|
3686
4284
|
/** Every connected peer; null until it joins. */
|
|
3687
4285
|
peers = /* @__PURE__ */ new Map();
|
|
@@ -3698,6 +4296,8 @@ var Room = class {
|
|
|
3698
4296
|
gone;
|
|
3699
4297
|
/** The plasma balls in flight, and the ones that burst since the last snapshot, which sends them once more. */
|
|
3700
4298
|
balls = [];
|
|
4299
|
+
/** The map's rovers, in the order of WorldDef.rovers. */
|
|
4300
|
+
rovers;
|
|
3701
4301
|
/** The key of the map being played, which the roster tells the clients. */
|
|
3702
4302
|
mapName;
|
|
3703
4303
|
/** The map the host picked for the next match, when it is another one. */
|
|
@@ -3714,6 +4314,7 @@ var Room = class {
|
|
|
3714
4314
|
this.world = build(def ?? mapOf(this.mapName));
|
|
3715
4315
|
this.ctf = new Ctf(this.world, this.rules);
|
|
3716
4316
|
this.gone = this.spots();
|
|
4317
|
+
this.rovers = park(this.world);
|
|
3717
4318
|
}
|
|
3718
4319
|
/** The health, ammo and cell packs of the map, all there (0 ticks before each is back). */
|
|
3719
4320
|
spots() {
|
|
@@ -3736,6 +4337,7 @@ var Room = class {
|
|
|
3736
4337
|
this.world = build(mapOf(this.mapName));
|
|
3737
4338
|
this.ctf = new Ctf(this.world, this.rules);
|
|
3738
4339
|
this.gone = this.spots();
|
|
4340
|
+
this.rovers = park(this.world);
|
|
3739
4341
|
this.history = [];
|
|
3740
4342
|
this.balls = [];
|
|
3741
4343
|
for (const p of this.players()) this.ctf.join(p.info.id, p.info.team, p.state);
|
|
@@ -3765,17 +4367,36 @@ var Room = class {
|
|
|
3765
4367
|
if (input && p.bank > 0) {
|
|
3766
4368
|
p.bank--;
|
|
3767
4369
|
const slow = p.state.slow ?? 0;
|
|
3768
|
-
const
|
|
3769
|
-
this.
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
4370
|
+
const use = (input.keys & KEY.USE) !== 0 && (p.state.held & KEY.USE) === 0;
|
|
4371
|
+
const [r, s] = this.seatOf(p);
|
|
4372
|
+
if (r && !s) {
|
|
4373
|
+
const fell = ride(p.state, r, input, this.world, p.info.team);
|
|
4374
|
+
this.ctf.moved(p.state);
|
|
4375
|
+
if (fell) this.sink(r);
|
|
4376
|
+
else {
|
|
4377
|
+
this.carry(r);
|
|
4378
|
+
this.splat(p, r, input.view);
|
|
4379
|
+
}
|
|
4380
|
+
} else {
|
|
4381
|
+
const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over);
|
|
4382
|
+
this.ctf.moved(p.state);
|
|
4383
|
+
this.tackle(p, input.view);
|
|
4384
|
+
const here = spot(p.state);
|
|
4385
|
+
const seen = r && struck ? this.past(input.view).find((q) => q.id === p.info.id) : void 0;
|
|
4386
|
+
Object.assign(p.state, seen && spot(seen));
|
|
4387
|
+
if (struck === STRIKE.SHOT) this.shoot(p, input.view);
|
|
4388
|
+
else if (struck === STRIKE.CUT) this.cut(p, input.view);
|
|
4389
|
+
else if (struck === STRIKE.RAIL) this.rail(p, input.view);
|
|
4390
|
+
else if (struck === STRIKE.LASER) this.shoot(p, input.view);
|
|
4391
|
+
Object.assign(p.state, here);
|
|
4392
|
+
if (use && r && p.state.mode === MODE.RIDE) leave(p.state, r, 1, this.world);
|
|
4393
|
+
else if (use) this.enter(p);
|
|
4394
|
+
}
|
|
3775
4395
|
p.burn = slow ? (p.burn ?? 0) + 1 : 0;
|
|
3776
4396
|
if (slow && !(p.burn % 60)) this.fry(p);
|
|
3777
4397
|
this.duel(p);
|
|
3778
4398
|
p.ack = input.seq;
|
|
4399
|
+
this.seats();
|
|
3779
4400
|
}
|
|
3780
4401
|
}
|
|
3781
4402
|
/** A peer left: its player goes, the roster goes out again. */
|
|
@@ -3787,8 +4408,10 @@ var Room = class {
|
|
|
3787
4408
|
if (!this.size) {
|
|
3788
4409
|
this.ctf.reset();
|
|
3789
4410
|
this.gone.fill(0);
|
|
4411
|
+
this.rovers = park(this.world);
|
|
3790
4412
|
this.load();
|
|
3791
4413
|
}
|
|
4414
|
+
this.seats();
|
|
3792
4415
|
this.roster();
|
|
3793
4416
|
}
|
|
3794
4417
|
}
|
|
@@ -3811,7 +4434,7 @@ var Room = class {
|
|
|
3811
4434
|
for (const p of players) p.bank = Math.min(10, p.bank + 1);
|
|
3812
4435
|
for (const b of this.balls) if (!b.burst && b.left > 0) this.fly(b, stepOf(b));
|
|
3813
4436
|
this.heal(players);
|
|
3814
|
-
const turn = this.ctf.tick(players.filter((p) => !p.state.down).map((p) => ({
|
|
4437
|
+
const turn = this.ctf.tick(players.filter((p) => !p.state.down && !this.rovers.some((r) => r.driver === p.info.id)).map((p) => ({
|
|
3815
4438
|
id: p.info.id,
|
|
3816
4439
|
team: p.info.team,
|
|
3817
4440
|
state: p.state
|
|
@@ -3821,6 +4444,11 @@ var Room = class {
|
|
|
3821
4444
|
this.load();
|
|
3822
4445
|
this.restart(players);
|
|
3823
4446
|
}
|
|
4447
|
+
this.seats();
|
|
4448
|
+
for (const r of this.rovers) if (r.driver !== 255) this.carry(r);
|
|
4449
|
+
else if (drive(r, void 0, this.world)) this.sink(r);
|
|
4450
|
+
else this.carry(r);
|
|
4451
|
+
this.seats();
|
|
3824
4452
|
if (now % 2 === 0) {
|
|
3825
4453
|
this.history.push({
|
|
3826
4454
|
tick: now,
|
|
@@ -3836,7 +4464,8 @@ var Room = class {
|
|
|
3836
4464
|
})),
|
|
3837
4465
|
...this.ctf.wire(),
|
|
3838
4466
|
packs: this.gone.reduce((m, t, k) => t ? m : m + 2 ** k, 0),
|
|
3839
|
-
balls: this.balls
|
|
4467
|
+
balls: this.balls,
|
|
4468
|
+
rovers: this.rovers
|
|
3840
4469
|
});
|
|
3841
4470
|
players.forEach((p) => p.conn.send(snap));
|
|
3842
4471
|
this.balls = this.balls.filter((b) => !b.burst && b.left > 0);
|
|
@@ -3876,7 +4505,11 @@ var Room = class {
|
|
|
3876
4505
|
* One the history does not hold stands where it is.
|
|
3877
4506
|
*/
|
|
3878
4507
|
rewind(id, view = 0) {
|
|
3879
|
-
|
|
4508
|
+
return this.past(view).filter((p) => p.id !== id);
|
|
4509
|
+
}
|
|
4510
|
+
/** Every player as the snapshots around the view tick `view` showed him: rewind(), the asker included. */
|
|
4511
|
+
past(view = 0) {
|
|
4512
|
+
const now = this.players().map((p) => p.state);
|
|
3880
4513
|
const [first, last] = [this.history[0], this.history.at(-1)];
|
|
3881
4514
|
if (!first || !last) return now;
|
|
3882
4515
|
const back = ((this.ticks - view + 32768) % 65536 + 65536) % 65536 - 32768;
|
|
@@ -3936,6 +4569,7 @@ var Room = class {
|
|
|
3936
4569
|
harm(foe, hp) {
|
|
3937
4570
|
if ((foe.state.hp -= hp) > 0) return false;
|
|
3938
4571
|
foe.graze = 0;
|
|
4572
|
+
if (foe.state.mode === MODE.RIDE) this.unseat(foe);
|
|
3939
4573
|
Object.assign(foe.state, {
|
|
3940
4574
|
hp: 0,
|
|
3941
4575
|
down: 120,
|
|
@@ -4152,6 +4786,97 @@ var Room = class {
|
|
|
4152
4786
|
}
|
|
4153
4787
|
});
|
|
4154
4788
|
}
|
|
4789
|
+
/** The rover `p` is seated in and his seat (0 the driver's), or nothing on foot. */
|
|
4790
|
+
seatOf(p) {
|
|
4791
|
+
if (p.state.mode === MODE.RIDE) for (const r of this.rovers) {
|
|
4792
|
+
const s = SEATS.findIndex((k) => r[k] === p.info.id);
|
|
4793
|
+
if (s >= 0) return [r, s];
|
|
4794
|
+
}
|
|
4795
|
+
return [];
|
|
4796
|
+
}
|
|
4797
|
+
/** Takes `p` off his seat: in the air where he sat. */
|
|
4798
|
+
unseat(p) {
|
|
4799
|
+
for (const r of this.rovers) SEATS.forEach((k) => r[k] = r[k] === p.info.id ? 255 : r[k]);
|
|
4800
|
+
Object.assign(p.state, {
|
|
4801
|
+
mode: MODE.AIR,
|
|
4802
|
+
t: 0,
|
|
4803
|
+
coyote: 0
|
|
4804
|
+
});
|
|
4805
|
+
}
|
|
4806
|
+
/**
|
|
4807
|
+
* The one place seats are kept true: a seat is held by a player who is there and rides, and who
|
|
4808
|
+
* rides holds a seat. So a leaver's seat is free before his id is given again, and one put down,
|
|
4809
|
+
* respawned or stumbled out is off the rover.
|
|
4810
|
+
*/
|
|
4811
|
+
seats() {
|
|
4812
|
+
const players = this.players();
|
|
4813
|
+
for (const r of this.rovers) for (const k of SEATS) if (!players.some((p) => p.info.id === r[k] && p.state.mode === MODE.RIDE)) r[k] = 255;
|
|
4814
|
+
for (const p of players) if (p.state.mode === MODE.RIDE && !this.seatOf(p).length) this.unseat(p);
|
|
4815
|
+
}
|
|
4816
|
+
/**
|
|
4817
|
+
* A press of USE on foot: the nearest rover within ROVER.ENTER_R on the floor plane with a seat
|
|
4818
|
+
* for him, the wheel first; a flag carrier only rides. Not while down, stumbling or in a lock.
|
|
4819
|
+
*/
|
|
4820
|
+
enter(p) {
|
|
4821
|
+
const q = p.state;
|
|
4822
|
+
if (q.down || q.stun || q.lock || q.mode === MODE.RIDE) return;
|
|
4823
|
+
const carrier = this.ctf.carrying(p.info.id) >= 0;
|
|
4824
|
+
const d2 = (r) => Math.abs(r.y - q.y) > ROVER.ENTER_R ? Infinity : (r.x - q.x) ** 2 + (r.z - q.z) ** 2;
|
|
4825
|
+
const free = (r) => r.driver === 255 && !carrier ? 0 : r.rider === 255 ? 1 : -1;
|
|
4826
|
+
const r = this.rovers.filter((r) => d2(r) <= ROVER.ENTER_R ** 2 && free(r) >= 0).sort((a, b) => d2(a) - d2(b))[0];
|
|
4827
|
+
if (r) board(q, r, free(r));
|
|
4828
|
+
}
|
|
4829
|
+
/**
|
|
4830
|
+
* The rider follows the rover on his seat. Over a floor, that is his last ground: where a flag he
|
|
4831
|
+
* carries lies if he is put down or falls with the rover.
|
|
4832
|
+
*/
|
|
4833
|
+
carry(r) {
|
|
4834
|
+
const p = this.players().find((q) => q.info.id === r.rider);
|
|
4835
|
+
if (p?.state.mode === MODE.RIDE) {
|
|
4836
|
+
seat(p.state, r, 1);
|
|
4837
|
+
const y = floorAt(this.world, r.x, r.z, r.y);
|
|
4838
|
+
if (y > this.world.def.floor) this.ctf.place(p.info.id, {
|
|
4839
|
+
...p.state,
|
|
4840
|
+
y
|
|
4841
|
+
});
|
|
4842
|
+
}
|
|
4843
|
+
}
|
|
4844
|
+
/** The rover fell under the kill floor: who was aboard is back at a spawn, it is parked again. */
|
|
4845
|
+
sink(r) {
|
|
4846
|
+
for (const p of this.players()) if (this.seatOf(p)[0] === r) {
|
|
4847
|
+
respawn(p.state, this.world, p.info.team);
|
|
4848
|
+
this.ctf.moved(p.state);
|
|
4849
|
+
}
|
|
4850
|
+
const k = this.rovers.indexOf(r);
|
|
4851
|
+
Object.assign(r, park(this.world)[k]);
|
|
4852
|
+
}
|
|
4853
|
+
/**
|
|
4854
|
+
* After a step of the driver `p` at the view tick `view`: the rover's body (footprint()) over an
|
|
4855
|
+
* enemy on foot, as `p` drew him, runs him over. Closing on him at ROVER.SPLAT_KILL or more puts
|
|
4856
|
+
* him down; from ROVER.SPLAT_MIN it takes 1 hp and throws him the rover's way in a stumble. Once
|
|
4857
|
+
* per SPLAT_COOLDOWN ticks a victim; a hit counts for the driver. The rover is never changed.
|
|
4858
|
+
*/
|
|
4859
|
+
splat(p, r, view) {
|
|
4860
|
+
if (len(r.vx, r.vz) < ROVER.SPLAT_MIN) return;
|
|
4861
|
+
const body = footprint(r);
|
|
4862
|
+
for (const seen of this.enemies(p, view)) {
|
|
4863
|
+
const foe = this.players().find((q) => q.info.id === seen.id);
|
|
4864
|
+
if (!foe || foe.state.mode === MODE.RIDE || this.ticks - foe.run < SPLAT_COOLDOWN) continue;
|
|
4865
|
+
if (!body.find(([x, y, z]) => len(seen.x - x, seen.z - z) < ROVER.RB + .4 && seen.y < y + ROVER.BODY_H && seen.y + heightOf(seen) > y)) continue;
|
|
4866
|
+
const [dx, dz] = [seen.x - r.x, seen.z - r.z];
|
|
4867
|
+
const d = len(dx, dz) || 1;
|
|
4868
|
+
const closing = ((r.vx - seen.vx) * dx + (r.vz - seen.vz) * dz) / d;
|
|
4869
|
+
if (closing < ROVER.SPLAT_MIN) continue;
|
|
4870
|
+
foe.run = this.ticks;
|
|
4871
|
+
p.state.hits = p.state.hits + 1 & 255;
|
|
4872
|
+
if (!this.harm(foe, closing < ROVER.SPLAT_KILL ? 1 : foe.state.hp)) {
|
|
4873
|
+
const v = len(r.vx, r.vz);
|
|
4874
|
+
stumble(foe.state, r.vx / v, r.vz / v);
|
|
4875
|
+
foe.state.zap = false;
|
|
4876
|
+
foe.by = p.info.id;
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
}
|
|
4155
4880
|
/** The first spawn point of the team with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
|
|
4156
4881
|
place(id, team, others) {
|
|
4157
4882
|
const n = this.world.def.teams[team].spawns.findIndex((_, k) => {
|
|
@@ -4182,6 +4907,7 @@ var Room = class {
|
|
|
4182
4907
|
const put = [];
|
|
4183
4908
|
this.rr = [0, 0];
|
|
4184
4909
|
this.gone.fill(0);
|
|
4910
|
+
this.rovers = park(this.world);
|
|
4185
4911
|
for (const p of players) {
|
|
4186
4912
|
const { shots, hits } = p.state;
|
|
4187
4913
|
p.state = {
|
|
@@ -4219,7 +4945,8 @@ var Room = class {
|
|
|
4219
4945
|
bank: 10,
|
|
4220
4946
|
ack: 65535,
|
|
4221
4947
|
by: 0,
|
|
4222
|
-
tackled: -30
|
|
4948
|
+
tackled: -30,
|
|
4949
|
+
run: -SPLAT_COOLDOWN
|
|
4223
4950
|
};
|
|
4224
4951
|
this.peers.set(conn, player);
|
|
4225
4952
|
this.ctf.join(id, team, player.state);
|