@korial29/tiny-fps 0.97.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 +619 -76
- 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/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/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. */
|
|
@@ -3228,7 +3240,7 @@ var WRECK = [BOWLS[0][0], 140];
|
|
|
3228
3240
|
* is 20 m high on it and, past it where nobody goes, climbs to a ragged crest of 60 to 95 m and
|
|
3229
3241
|
* falls to the plain at 1.65 of the bound.
|
|
3230
3242
|
*/
|
|
3231
|
-
var at = (x, z) => {
|
|
3243
|
+
var at$1 = (x, z) => {
|
|
3232
3244
|
z = Math.abs(z - 140);
|
|
3233
3245
|
const k = far((x - 80) / 300, z / 360);
|
|
3234
3246
|
const t = Math.max((k - .78) / .22, 0);
|
|
@@ -3251,7 +3263,7 @@ var at = (x, z) => {
|
|
|
3251
3263
|
};
|
|
3252
3264
|
/** The ghost under a drawn rock or mast: a box of half side s from under the ground to h above it. */
|
|
3253
3265
|
var lump = (x, z, s, h) => ({
|
|
3254
|
-
...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),
|
|
3255
3267
|
ghost: true
|
|
3256
3268
|
});
|
|
3257
3269
|
[...FIELD, ...FIELD.map(([x, z, r]) => [
|
|
@@ -3518,7 +3530,7 @@ var MAPS = {
|
|
|
3518
3530
|
360
|
|
3519
3531
|
],
|
|
3520
3532
|
cell: 4,
|
|
3521
|
-
at
|
|
3533
|
+
at: at$1
|
|
3522
3534
|
},
|
|
3523
3535
|
sun: {
|
|
3524
3536
|
dir: [
|
|
@@ -3542,6 +3554,32 @@ var MAPS = {
|
|
|
3542
3554
|
.035
|
|
3543
3555
|
]],
|
|
3544
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
|
+
],
|
|
3545
3583
|
scenery: "moon",
|
|
3546
3584
|
helmets: true
|
|
3547
3585
|
}
|
|
@@ -3651,6 +3689,23 @@ var fly = (w, b, m, foes) => {
|
|
|
3651
3689
|
];
|
|
3652
3690
|
return hit;
|
|
3653
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
|
+
]];
|
|
3654
3709
|
/** The no-gun value of the ammo's 7 bits. */
|
|
3655
3710
|
var NO_GUN = 127;
|
|
3656
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. */
|
|
@@ -3683,13 +3738,15 @@ var decodeInput = (buf) => {
|
|
|
3683
3738
|
/** Bytes of a flag on the wire, by its state. */
|
|
3684
3739
|
var flagBytes = (state) => state === FLAG.CARRIED ? 2 : state === FLAG.DROPPED ? 8 : 1;
|
|
3685
3740
|
var encodeSnapshot = (s) => {
|
|
3686
|
-
const
|
|
3741
|
+
const rovers = (s.rovers ?? []).slice(0, 7);
|
|
3742
|
+
const mid = 4 + 61 * s.players.length;
|
|
3743
|
+
const end = mid + 54 * rovers.length;
|
|
3687
3744
|
const balls = s.balls ?? [];
|
|
3688
3745
|
const tail = end + 10 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0);
|
|
3689
3746
|
const v = new DataView(new ArrayBuffer(tail + (balls.length && 1 + 11 * balls.length)));
|
|
3690
3747
|
v.setUint8(0, 2);
|
|
3691
3748
|
v.setUint16(1, s.tick & 65535);
|
|
3692
|
-
v.setUint8(3, s.players.length);
|
|
3749
|
+
v.setUint8(3, s.players.length | rovers.length << 5);
|
|
3693
3750
|
s.players.forEach((p, i) => {
|
|
3694
3751
|
const o = 4 + i * 61;
|
|
3695
3752
|
v.setUint8(o, p.id);
|
|
@@ -3721,7 +3778,7 @@ var encodeSnapshot = (s) => {
|
|
|
3721
3778
|
v.setUint8(o + 50, p.pushes ?? 0);
|
|
3722
3779
|
v.setUint8(o + 51, p.away ?? 0);
|
|
3723
3780
|
v.setUint8(o + 52, (p.rail ?? -1) + 1);
|
|
3724
|
-
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));
|
|
3725
3782
|
v.setUint8(o + 54, p.slow ?? 0);
|
|
3726
3783
|
v.setUint8(o + 55, p.mag ?? 0);
|
|
3727
3784
|
v.setUint8(o + 56, p.cap ?? 0);
|
|
@@ -3730,6 +3787,12 @@ var encodeSnapshot = (s) => {
|
|
|
3730
3787
|
v.setUint8(o + 59, p.clip ?? 0);
|
|
3731
3788
|
v.setUint8(o + 60, p.heat ?? 0);
|
|
3732
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
|
+
});
|
|
3733
3796
|
v.setUint8(end, s.score[0]);
|
|
3734
3797
|
v.setUint8(end + 1, s.score[1]);
|
|
3735
3798
|
v.setUint16(end + 2, s.clock & 32767 | (s.over ? 32768 : 0));
|
|
@@ -3805,6 +3868,343 @@ var beam = (w, p, foes = [], range = 30, [dy, dp] = [0, 0]) => {
|
|
|
3805
3868
|
hit
|
|
3806
3869
|
};
|
|
3807
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
|
+
};
|
|
3808
4208
|
// src/shared/tackle.ts
|
|
3809
4209
|
/** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
|
|
3810
4210
|
var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
|
|
@@ -3818,6 +4218,10 @@ var reaches = (a, b) => Math.hypot(a.x - b.x, a.z - b.z) < 1.1 && a.y < b.y + he
|
|
|
3818
4218
|
var MAX_CATCH_UP = 20;
|
|
3819
4219
|
/** A new player does not spawn within this many metres of another one. */
|
|
3820
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"];
|
|
3821
4225
|
/** First n characters (code points) of s, trimmed. */
|
|
3822
4226
|
var cut = (s, n) => Array.from(s).slice(0, n).join("").trim();
|
|
3823
4227
|
var cleanName = (raw) => cut((typeof raw === "string" ? raw : "").replace(/\s+/g, " ").replace(/\p{Cc}/gu, "").trim(), 16);
|
|
@@ -3827,6 +4231,7 @@ var unique = (name, taken) => {
|
|
|
3827
4231
|
for (let n = 2; taken.includes(out); n++) out = `${cut(name, 15 - `${n}`.length)} ${n}`;
|
|
3828
4232
|
return out;
|
|
3829
4233
|
};
|
|
4234
|
+
var len = (x, z) => Math.sqrt(x * x + z * z);
|
|
3830
4235
|
var setEvery = (cb, ms) => {
|
|
3831
4236
|
const id = setInterval(cb, ms);
|
|
3832
4237
|
return () => clearInterval(id);
|
|
@@ -3850,6 +4255,9 @@ var setEvery = (cb, ms) => {
|
|
|
3850
4255
|
* - The host is the player in the room the longest; when he leaves, the next oldest. Only his
|
|
3851
4256
|
* { t: 'map', map } counts: the map (a MAPS key) is played from the next match on, or from the
|
|
3852
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.
|
|
3853
4261
|
*/
|
|
3854
4262
|
/** A player out of any saber lock. */
|
|
3855
4263
|
var FREE = {
|
|
@@ -3866,6 +4274,12 @@ var pick = ({ x, y, z, yaw }) => ({
|
|
|
3866
4274
|
z,
|
|
3867
4275
|
yaw
|
|
3868
4276
|
});
|
|
4277
|
+
/** Where a player stands. */
|
|
4278
|
+
var spot = ({ x, y, z }) => ({
|
|
4279
|
+
x,
|
|
4280
|
+
y,
|
|
4281
|
+
z
|
|
4282
|
+
});
|
|
3869
4283
|
var Room = class {
|
|
3870
4284
|
/** Every connected peer; null until it joins. */
|
|
3871
4285
|
peers = /* @__PURE__ */ new Map();
|
|
@@ -3882,6 +4296,8 @@ var Room = class {
|
|
|
3882
4296
|
gone;
|
|
3883
4297
|
/** The plasma balls in flight, and the ones that burst since the last snapshot, which sends them once more. */
|
|
3884
4298
|
balls = [];
|
|
4299
|
+
/** The map's rovers, in the order of WorldDef.rovers. */
|
|
4300
|
+
rovers;
|
|
3885
4301
|
/** The key of the map being played, which the roster tells the clients. */
|
|
3886
4302
|
mapName;
|
|
3887
4303
|
/** The map the host picked for the next match, when it is another one. */
|
|
@@ -3898,6 +4314,7 @@ var Room = class {
|
|
|
3898
4314
|
this.world = build(def ?? mapOf(this.mapName));
|
|
3899
4315
|
this.ctf = new Ctf(this.world, this.rules);
|
|
3900
4316
|
this.gone = this.spots();
|
|
4317
|
+
this.rovers = park(this.world);
|
|
3901
4318
|
}
|
|
3902
4319
|
/** The health, ammo and cell packs of the map, all there (0 ticks before each is back). */
|
|
3903
4320
|
spots() {
|
|
@@ -3920,6 +4337,7 @@ var Room = class {
|
|
|
3920
4337
|
this.world = build(mapOf(this.mapName));
|
|
3921
4338
|
this.ctf = new Ctf(this.world, this.rules);
|
|
3922
4339
|
this.gone = this.spots();
|
|
4340
|
+
this.rovers = park(this.world);
|
|
3923
4341
|
this.history = [];
|
|
3924
4342
|
this.balls = [];
|
|
3925
4343
|
for (const p of this.players()) this.ctf.join(p.info.id, p.info.team, p.state);
|
|
@@ -3949,17 +4367,36 @@ var Room = class {
|
|
|
3949
4367
|
if (input && p.bank > 0) {
|
|
3950
4368
|
p.bank--;
|
|
3951
4369
|
const slow = p.state.slow ?? 0;
|
|
3952
|
-
const
|
|
3953
|
-
this.
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
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
|
+
}
|
|
3959
4395
|
p.burn = slow ? (p.burn ?? 0) + 1 : 0;
|
|
3960
4396
|
if (slow && !(p.burn % 60)) this.fry(p);
|
|
3961
4397
|
this.duel(p);
|
|
3962
4398
|
p.ack = input.seq;
|
|
4399
|
+
this.seats();
|
|
3963
4400
|
}
|
|
3964
4401
|
}
|
|
3965
4402
|
/** A peer left: its player goes, the roster goes out again. */
|
|
@@ -3971,8 +4408,10 @@ var Room = class {
|
|
|
3971
4408
|
if (!this.size) {
|
|
3972
4409
|
this.ctf.reset();
|
|
3973
4410
|
this.gone.fill(0);
|
|
4411
|
+
this.rovers = park(this.world);
|
|
3974
4412
|
this.load();
|
|
3975
4413
|
}
|
|
4414
|
+
this.seats();
|
|
3976
4415
|
this.roster();
|
|
3977
4416
|
}
|
|
3978
4417
|
}
|
|
@@ -3995,7 +4434,7 @@ var Room = class {
|
|
|
3995
4434
|
for (const p of players) p.bank = Math.min(10, p.bank + 1);
|
|
3996
4435
|
for (const b of this.balls) if (!b.burst && b.left > 0) this.fly(b, stepOf(b));
|
|
3997
4436
|
this.heal(players);
|
|
3998
|
-
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) => ({
|
|
3999
4438
|
id: p.info.id,
|
|
4000
4439
|
team: p.info.team,
|
|
4001
4440
|
state: p.state
|
|
@@ -4005,6 +4444,11 @@ var Room = class {
|
|
|
4005
4444
|
this.load();
|
|
4006
4445
|
this.restart(players);
|
|
4007
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();
|
|
4008
4452
|
if (now % 2 === 0) {
|
|
4009
4453
|
this.history.push({
|
|
4010
4454
|
tick: now,
|
|
@@ -4020,7 +4464,8 @@ var Room = class {
|
|
|
4020
4464
|
})),
|
|
4021
4465
|
...this.ctf.wire(),
|
|
4022
4466
|
packs: this.gone.reduce((m, t, k) => t ? m : m + 2 ** k, 0),
|
|
4023
|
-
balls: this.balls
|
|
4467
|
+
balls: this.balls,
|
|
4468
|
+
rovers: this.rovers
|
|
4024
4469
|
});
|
|
4025
4470
|
players.forEach((p) => p.conn.send(snap));
|
|
4026
4471
|
this.balls = this.balls.filter((b) => !b.burst && b.left > 0);
|
|
@@ -4060,7 +4505,11 @@ var Room = class {
|
|
|
4060
4505
|
* One the history does not hold stands where it is.
|
|
4061
4506
|
*/
|
|
4062
4507
|
rewind(id, view = 0) {
|
|
4063
|
-
|
|
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);
|
|
4064
4513
|
const [first, last] = [this.history[0], this.history.at(-1)];
|
|
4065
4514
|
if (!first || !last) return now;
|
|
4066
4515
|
const back = ((this.ticks - view + 32768) % 65536 + 65536) % 65536 - 32768;
|
|
@@ -4120,6 +4569,7 @@ var Room = class {
|
|
|
4120
4569
|
harm(foe, hp) {
|
|
4121
4570
|
if ((foe.state.hp -= hp) > 0) return false;
|
|
4122
4571
|
foe.graze = 0;
|
|
4572
|
+
if (foe.state.mode === MODE.RIDE) this.unseat(foe);
|
|
4123
4573
|
Object.assign(foe.state, {
|
|
4124
4574
|
hp: 0,
|
|
4125
4575
|
down: 120,
|
|
@@ -4336,6 +4786,97 @@ var Room = class {
|
|
|
4336
4786
|
}
|
|
4337
4787
|
});
|
|
4338
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
|
+
}
|
|
4339
4880
|
/** The first spawn point of the team with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
|
|
4340
4881
|
place(id, team, others) {
|
|
4341
4882
|
const n = this.world.def.teams[team].spawns.findIndex((_, k) => {
|
|
@@ -4366,6 +4907,7 @@ var Room = class {
|
|
|
4366
4907
|
const put = [];
|
|
4367
4908
|
this.rr = [0, 0];
|
|
4368
4909
|
this.gone.fill(0);
|
|
4910
|
+
this.rovers = park(this.world);
|
|
4369
4911
|
for (const p of players) {
|
|
4370
4912
|
const { shots, hits } = p.state;
|
|
4371
4913
|
p.state = {
|
|
@@ -4403,7 +4945,8 @@ var Room = class {
|
|
|
4403
4945
|
bank: 10,
|
|
4404
4946
|
ack: 65535,
|
|
4405
4947
|
by: 0,
|
|
4406
|
-
tackled: -30
|
|
4948
|
+
tackled: -30,
|
|
4949
|
+
run: -SPLAT_COOLDOWN
|
|
4407
4950
|
};
|
|
4408
4951
|
this.peers.set(conn, player);
|
|
4409
4952
|
this.ctf.join(id, team, player.state);
|