@korial29/tiny-fps 0.128.0 → 0.129.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +15 -15
- package/dist/local.js +1 -1
- package/dist/server.js +300 -119
- package/dist/types/client/beams.d.ts +9 -2
- package/dist/types/client/craft.d.ts +7 -5
- package/dist/types/client/hud.d.ts +10 -2
- package/dist/types/client/predict.d.ts +2 -1
- package/dist/types/client/rover.d.ts +3 -1
- package/dist/types/client/sfx.d.ts +5 -0
- package/dist/types/client/soldier.d.ts +16 -0
- package/dist/types/client/wreck.d.ts +61 -0
- package/dist/types/shared/constants.d.ts +16 -0
- package/dist/types/shared/plasma.d.ts +1 -1
- package/dist/types/shared/protocol.d.ts +1 -1
- package/dist/types/shared/room.d.ts +42 -13
- package/dist/types/shared/rover.d.ts +36 -3
- package/dist/types/shared/ship.d.ts +4 -13
- package/dist/types/shared/types.d.ts +2 -2
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -194,6 +194,22 @@ var RULES = {
|
|
|
194
194
|
timeLimit: 480,
|
|
195
195
|
map: "highline"
|
|
196
196
|
};
|
|
197
|
+
/**
|
|
198
|
+
* A vehicle's health (the user, 2026-11-12), a rover's and a ship's alike: HP when parked afresh;
|
|
199
|
+
* at 0 it blows up, its crew goes down with it and its wreck lies WRECK ticks (5 s), falling apart
|
|
200
|
+
* over the last FADE of them, before it is parked afresh. A plasma ball takes its power, a cut its
|
|
201
|
+
* hp, a blast what it takes from a body; of the laser bolts and the rifle's rounds every GRAZE that
|
|
202
|
+
* meet the hull take 1; the rail gun's bolt drains it as it does a player. The wire holds HP in 7
|
|
203
|
+
* bits and WRECK / 4 in a byte. A rover's wreck keeps SKID of its speed along the ground each tick:
|
|
204
|
+
* from top speed it skids under 5 m and lies there.
|
|
205
|
+
*/
|
|
206
|
+
var VEHICLE = {
|
|
207
|
+
HP: 10,
|
|
208
|
+
WRECK: 300,
|
|
209
|
+
FADE: 60,
|
|
210
|
+
GRAZE: 4,
|
|
211
|
+
SKID: .92
|
|
212
|
+
};
|
|
197
213
|
// src/shared/relief.ts
|
|
198
214
|
/** Integer hash of a lattice point to [0, 1): the same on every engine. */
|
|
199
215
|
var hash = (x, y, s) => {
|
|
@@ -4944,11 +4960,9 @@ var encodeSnapshot = (s) => {
|
|
|
4944
4960
|
ROVER_F.forEach((k, j) => v.setFloat32(o + 4 * j, r[k]));
|
|
4945
4961
|
v.setUint8(o + 52, r.driver);
|
|
4946
4962
|
v.setUint8(o + 53, r.rider);
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
v.setUint8(o + 56, r.nades ?? 0);
|
|
4951
|
-
}
|
|
4963
|
+
v.setUint8(o + 54, (r.ship ? 128 : 0) | Math.max(0, Math.min(127, r.hp ?? VEHICLE.HP)));
|
|
4964
|
+
v.setUint8(o + 55, Math.min(255, Math.ceil((r.wreck ?? 0) / 4)));
|
|
4965
|
+
v.setUint8(o + 56, r.ship ? r.nades ?? 0 : 0);
|
|
4952
4966
|
});
|
|
4953
4967
|
v.setUint8(end, s.score[0]);
|
|
4954
4968
|
v.setUint8(end + 1, s.score[1]);
|
|
@@ -5087,9 +5101,6 @@ var SHIP = {
|
|
|
5087
5101
|
/** A player this close to the centre (on the floor plane) and within this height gets in. */
|
|
5088
5102
|
ENTER_R: 6,
|
|
5089
5103
|
ENTER_H: 4,
|
|
5090
|
-
/** Armour, and the ticks a destroyed ship is gone before it is back on its pad. */
|
|
5091
|
-
HP: 60,
|
|
5092
|
-
WRECK: 600,
|
|
5093
5104
|
/** The lasers: ticks between two salvos, the bolts' reach, and where the beams cross ahead along the look. */
|
|
5094
5105
|
GUN_COOL: 6,
|
|
5095
5106
|
GUN_RANGE: 160,
|
|
@@ -5098,13 +5109,7 @@ var SHIP = {
|
|
|
5098
5109
|
MISSILES: 4,
|
|
5099
5110
|
MISSILE_COOL: 30,
|
|
5100
5111
|
RELOAD: 300,
|
|
5101
|
-
MISSILE_SPEED: 60
|
|
5102
|
-
/** A missile's burst: the armour it takes at the hull, falling off to nothing this far from it. */
|
|
5103
|
-
BLAST_HP: 14,
|
|
5104
|
-
BLAST_R: 7,
|
|
5105
|
-
/** The armour a laser bolt or a rifle round takes, and a plasma ball per point of its power. */
|
|
5106
|
-
BOLT_HP: 1,
|
|
5107
|
-
BALL_HP: 2
|
|
5112
|
+
MISSILE_SPEED: 60
|
|
5108
5113
|
};
|
|
5109
5114
|
/** The lasers' muzzles under the wings, the missiles' pods under the wings: right of the centre, above it, ahead of it. */
|
|
5110
5115
|
var SHIP_GUNS = [[
|
|
@@ -5182,7 +5187,7 @@ var point = (r, b, u, a) => {
|
|
|
5182
5187
|
r.z + R[2] * b + U[2] * u + F[2] * a
|
|
5183
5188
|
];
|
|
5184
5189
|
};
|
|
5185
|
-
/** The map's ships at rest on their pads: full
|
|
5190
|
+
/** The map's ships at rest on their pads: whole, full of missiles, nobody aboard. */
|
|
5186
5191
|
var dock = (ships = []) => ships.map(([x, y, z, yaw]) => ({
|
|
5187
5192
|
x: f32$1(x),
|
|
5188
5193
|
y: f32$1(y + SHIP.DROP),
|
|
@@ -5200,31 +5205,15 @@ var dock = (ships = []) => ships.map(([x, y, z, yaw]) => ({
|
|
|
5200
5205
|
driver: 255,
|
|
5201
5206
|
rider: 255,
|
|
5202
5207
|
ship: true,
|
|
5203
|
-
hp:
|
|
5208
|
+
hp: VEHICLE.HP,
|
|
5204
5209
|
wreck: 0,
|
|
5205
5210
|
nades: SHIP.MISSILES
|
|
5206
5211
|
}));
|
|
5207
|
-
/** A body that meets nothing: a ship that is gone. */
|
|
5208
|
-
var NONE = {
|
|
5209
|
-
a: [
|
|
5210
|
-
0,
|
|
5211
|
-
-1e4,
|
|
5212
|
-
0
|
|
5213
|
-
],
|
|
5214
|
-
b: [
|
|
5215
|
-
0,
|
|
5216
|
-
-1e4,
|
|
5217
|
-
0
|
|
5218
|
-
],
|
|
5219
|
-
r: 0,
|
|
5220
|
-
h: 0
|
|
5221
|
-
};
|
|
5222
5212
|
/**
|
|
5223
5213
|
* The hull as the players on foot and the rovers meet it: the stadium from the tail to the nose
|
|
5224
5214
|
* along the floor plane, R wide, from the skids up H. A player walks into it and stands on it.
|
|
5225
5215
|
*/
|
|
5226
5216
|
var shipHull = (r) => {
|
|
5227
|
-
if (r.wreck) return NONE;
|
|
5228
5217
|
const [a, b] = [SHIP.BODY[0], SHIP.BODY[2]].map((k) => point(r, 0, -SHIP.DROP, k));
|
|
5229
5218
|
return {
|
|
5230
5219
|
a,
|
|
@@ -5268,8 +5257,8 @@ var roof = (w, x, z, y0, y1) => {
|
|
|
5268
5257
|
/**
|
|
5269
5258
|
* One step of 1 / TICK_HZ s, in place. `i` is the pilot's input as the wire rounds it, or
|
|
5270
5259
|
* undefined with nobody at the stick: the engines are off and it falls under the map's gravity to
|
|
5271
|
-
* a floor
|
|
5272
|
-
*
|
|
5260
|
+
* a floor, a wreck as well. Returns whether it fell under the kill floor: the caller docks it
|
|
5261
|
+
* again.
|
|
5273
5262
|
*
|
|
5274
5263
|
* The nose turns toward the look as fast as the rates allow and banks into the turn; the thrust
|
|
5275
5264
|
* is along the nose, sideways and straight up, against a drag that sets the top speed. Piloted,
|
|
@@ -5277,7 +5266,6 @@ var roof = (w, x, z, y0, y1) => {
|
|
|
5277
5266
|
* skids, level.
|
|
5278
5267
|
*/
|
|
5279
5268
|
var pilot = (r, i, w) => {
|
|
5280
|
-
if (r.wreck) return false;
|
|
5281
5269
|
const keys = i ? i.keys : 0;
|
|
5282
5270
|
const on = (k) => keys & k ? 1 : 0;
|
|
5283
5271
|
const thr = on(KEY.FORWARD) - on(KEY.BACK);
|
|
@@ -5405,10 +5393,9 @@ var pilot = (r, i, w) => {
|
|
|
5405
5393
|
};
|
|
5406
5394
|
/**
|
|
5407
5395
|
* Where a shot from `o` along the unit `d` meets the hull within `m` metres: the distance, or
|
|
5408
|
-
* Infinity. The hull is the HITS spheres
|
|
5396
|
+
* Infinity. The hull is the HITS spheres.
|
|
5409
5397
|
*/
|
|
5410
|
-
var struck = (r, o, d, m) => {
|
|
5411
|
-
if (r.wreck) return Infinity;
|
|
5398
|
+
var struck$1 = (r, o, d, m) => {
|
|
5412
5399
|
let best = Infinity;
|
|
5413
5400
|
for (const k of SHIP.HITS) {
|
|
5414
5401
|
const c = point(r, 0, 0, k);
|
|
@@ -5427,7 +5414,7 @@ var struck = (r, o, d, m) => {
|
|
|
5427
5414
|
return best;
|
|
5428
5415
|
};
|
|
5429
5416
|
/** The distance from `c` to the nearest point of the hull's spheres, 0 inside. */
|
|
5430
|
-
var reach = (r, c) => min$1(...SHIP.HITS.map((k) => {
|
|
5417
|
+
var reach$1 = (r, c) => min$1(...SHIP.HITS.map((k) => {
|
|
5431
5418
|
const [x, y, z] = point(r, 0, 0, k).map((v, n) => c[n] - v);
|
|
5432
5419
|
return max$1(0, sqrt$1(x * x + y * y + z * z) - SHIP.HIT);
|
|
5433
5420
|
}));
|
|
@@ -5587,8 +5574,21 @@ var hull = (r) => {
|
|
|
5587
5574
|
};
|
|
5588
5575
|
};
|
|
5589
5576
|
/**
|
|
5590
|
-
*
|
|
5591
|
-
*
|
|
5577
|
+
* A rover's wreck skids to a stop where it blew up: before each of its steps with nobody at the
|
|
5578
|
+
* wheel it keeps VEHICLE.SKID of its speed along the ground. A ship's wreck falls as it flew.
|
|
5579
|
+
*/
|
|
5580
|
+
var skid = (r) => {
|
|
5581
|
+
if (!r.ship) [r.vx, r.vz] = [f32(r.vx * VEHICLE.SKID), f32(r.vz * VEHICLE.SKID)];
|
|
5582
|
+
};
|
|
5583
|
+
/**
|
|
5584
|
+
* The vehicles' bodies as the step of `p` on foot meets them: every hull(), but for a player who
|
|
5585
|
+
* is down the wrecks' (his own vehicle's among them: he lies where it blew up, and no wreck that
|
|
5586
|
+
* moves under him bends his replay).
|
|
5587
|
+
*/
|
|
5588
|
+
var solid = (rovers, p) => rovers.filter((r) => !(p.down && r.wreck)).map(hull);
|
|
5589
|
+
/**
|
|
5590
|
+
* The map's rovers at rest on their spawns, whole, nobody aboard, then its ships on their pads
|
|
5591
|
+
* (ship.ts): the order of the snapshot's.
|
|
5592
5592
|
*/
|
|
5593
5593
|
var park = (w) => [...cars(w), ...dock(w.def.ships)];
|
|
5594
5594
|
var cars = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
|
|
@@ -5606,9 +5606,64 @@ var cars = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
|
|
|
5606
5606
|
wr: 0,
|
|
5607
5607
|
steer: 0,
|
|
5608
5608
|
driver: 255,
|
|
5609
|
-
rider: 255
|
|
5609
|
+
rider: 255,
|
|
5610
|
+
hp: VEHICLE.HP,
|
|
5611
|
+
wreck: 0
|
|
5610
5612
|
}));
|
|
5611
5613
|
/**
|
|
5614
|
+
* The team whose base vehicle `k` of park() is parked at: of the rovers, then of the ships, the
|
|
5615
|
+
* first half are red's (the renderer paints them so).
|
|
5616
|
+
*/
|
|
5617
|
+
var homeOf = (w, k) => {
|
|
5618
|
+
const [cars, ships] = [w.def.rovers?.length ?? 0, w.def.ships?.length ?? 0];
|
|
5619
|
+
return k < cars ? +(2 * k >= cars) : +(2 * (k - cars) >= ships);
|
|
5620
|
+
};
|
|
5621
|
+
/**
|
|
5622
|
+
* Where a shot from `o` along the unit `d` meets the vehicle's body within `m` metres: the
|
|
5623
|
+
* distance, or Infinity. A rover's body is its footprint()'s circles, BODY_H tall; a ship's is
|
|
5624
|
+
* ship.ts's spheres.
|
|
5625
|
+
*/
|
|
5626
|
+
var struck = (r, o, d, m) => {
|
|
5627
|
+
if (r.ship) return struck$1(r, o, d, m);
|
|
5628
|
+
const t = min(...footprint(r).map(([x, y, z]) => cylinder(o, d, {
|
|
5629
|
+
x,
|
|
5630
|
+
y,
|
|
5631
|
+
z
|
|
5632
|
+
}, ROVER.RB, ROVER.BODY_H)));
|
|
5633
|
+
return t <= m ? t : Infinity;
|
|
5634
|
+
};
|
|
5635
|
+
/** The distance from `c` to the nearest point of the vehicle's body (struck()'s), 0 inside. */
|
|
5636
|
+
var reach = (r, c) => r.ship ? reach$1(r, c) : min(...footprint(r).map(([x, y, z]) => {
|
|
5637
|
+
const side = max(0, sqrt((c[0] - x) ** 2 + (c[2] - z) ** 2) - ROVER.RB);
|
|
5638
|
+
const up = max(0, y - c[1], c[1] - y - ROVER.BODY_H);
|
|
5639
|
+
return sqrt(side * side + up * up);
|
|
5640
|
+
}));
|
|
5641
|
+
/**
|
|
5642
|
+
* Whether a cut of `p` with this reach and arc (blade.ts's strike(), for a hull) meets the
|
|
5643
|
+
* vehicle: its hull() within reach of his centre on the floor plane, inside the arc round his look
|
|
5644
|
+
* (the hull's own angular radius counts), the heights overlapping and no brush before it.
|
|
5645
|
+
*/
|
|
5646
|
+
var slashed = (w, r, p, { reach, arc }) => {
|
|
5647
|
+
const h = hull(r);
|
|
5648
|
+
const [dx, dz, y] = gapTo(h, p.x, p.z);
|
|
5649
|
+
const d = sqrt(dx * dx + dz * dz);
|
|
5650
|
+
const tall = heightOf(p);
|
|
5651
|
+
if (d - h.r > reach || p.y >= y + h.h || y >= p.y + tall) return false;
|
|
5652
|
+
const [fx, fz] = forward(p.yaw);
|
|
5653
|
+
const off = d > h.r ? abs(Math.atan2(fz * dx - fx * dz, -fx * dx - fz * dz)) : 0;
|
|
5654
|
+
const wide = d > h.r ? Math.asin(h.r / d) : Math.PI;
|
|
5655
|
+
const chest = p.y + .7 * tall;
|
|
5656
|
+
return off <= arc + wide && !hidden(w, [
|
|
5657
|
+
p.x,
|
|
5658
|
+
chest,
|
|
5659
|
+
p.z
|
|
5660
|
+
], [
|
|
5661
|
+
p.x - dx,
|
|
5662
|
+
clamp(chest, y, y + h.h),
|
|
5663
|
+
p.z - dz
|
|
5664
|
+
]);
|
|
5665
|
+
};
|
|
5666
|
+
/**
|
|
5612
5667
|
* One step of 1 / TICK_HZ s, in place. `i` is the driver's input as the wire rounds it (FORWARD and
|
|
5613
5668
|
* BACK the throttle, JUMP the handbrake, its yaw where the nose is steered to), or undefined with
|
|
5614
5669
|
* nobody at the wheel: the brake is on. Reads only the rover, the input, the world and the
|
|
@@ -5829,7 +5884,7 @@ var ride = (p, r, i, w, team, fleet = []) => {
|
|
|
5829
5884
|
var gap2 = (r, p) => (r.x - p.x) ** 2 + (r.z - p.z) ** 2;
|
|
5830
5885
|
/**
|
|
5831
5886
|
* A player on foot near enough to get in: on the floor plane within ENTER_R of the centre, and
|
|
5832
|
-
* within the reach in height (a ship's ENTER_H). A
|
|
5887
|
+
* within the reach in height (a ship's ENTER_H). A wreck has no seat.
|
|
5833
5888
|
*/
|
|
5834
5889
|
var nearby = (r, p) => {
|
|
5835
5890
|
const [k, h] = r.ship ? [SHIP.ENTER_R, SHIP.ENTER_H] : [ROVER.ENTER_R, ROVER.ENTER_R];
|
|
@@ -5979,7 +6034,20 @@ var setEvery = (cb, ms) => {
|
|
|
5979
6034
|
* A player on foot walks into the rovers as they stand when his input arrives (hull()); a rover
|
|
5980
6035
|
* stops on the others as they stand when it steps.
|
|
5981
6036
|
* seats() keeps the seats and the players' MODE.RIDE in step.
|
|
6037
|
+
* - A vehicle has VEHICLE.HP of health, the host's alone like a player's hp: every weapon takes
|
|
6038
|
+
* some from the hull of one that is not of the shooter's team (teamOf()), and a shot the hull
|
|
6039
|
+
* stops does not reach its crew. At 0 it blows up (wreck()): its crew goes down, a blast hurts
|
|
6040
|
+
* who is near, and its wreck lies VEHICLE.WRECK ticks, moved by the tick alone, before the
|
|
6041
|
+
* vehicle is parked afresh.
|
|
5982
6042
|
*/
|
|
6043
|
+
/** A vehicle parked afresh, for the host's own count of its damage. */
|
|
6044
|
+
var NEW = {
|
|
6045
|
+
graze: 0,
|
|
6046
|
+
sear: 0,
|
|
6047
|
+
burn: 0,
|
|
6048
|
+
by: 255,
|
|
6049
|
+
team: -1
|
|
6050
|
+
};
|
|
5983
6051
|
/** A player out of any saber lock. */
|
|
5984
6052
|
var FREE = {
|
|
5985
6053
|
lock: 0,
|
|
@@ -6005,7 +6073,7 @@ var Room = class {
|
|
|
6005
6073
|
/** Every connected peer; null until it joins. */
|
|
6006
6074
|
peers = /* @__PURE__ */ new Map();
|
|
6007
6075
|
ticks = 0;
|
|
6008
|
-
/** The players as each snapshot of the last MAX_REWIND ticks sent them. */
|
|
6076
|
+
/** The players and the vehicles as each snapshot of the last MAX_REWIND ticks sent them. */
|
|
6009
6077
|
history = [];
|
|
6010
6078
|
world;
|
|
6011
6079
|
ctf;
|
|
@@ -6018,9 +6086,11 @@ var Room = class {
|
|
|
6018
6086
|
/** The plasma balls in flight, and the ones that burst since the last snapshot, which sends them once more. */
|
|
6019
6087
|
balls = [];
|
|
6020
6088
|
/** The map's rovers, in the order of WorldDef.rovers, then its ships (ship.ts). */
|
|
6021
|
-
rovers;
|
|
6089
|
+
rovers = [];
|
|
6022
6090
|
/** Ticks toward each ship's next missile, by index in `rovers`. */
|
|
6023
6091
|
rearm = [];
|
|
6092
|
+
/** Each vehicle's damage short of a whole hp, by index in `rovers`. */
|
|
6093
|
+
wear = [];
|
|
6024
6094
|
/** The key of the map being played, which the roster tells the clients. */
|
|
6025
6095
|
mapName;
|
|
6026
6096
|
/** The map the host picked for the next match, when it is another one. */
|
|
@@ -6037,7 +6107,13 @@ var Room = class {
|
|
|
6037
6107
|
this.world = build(def ?? mapOf(this.mapName));
|
|
6038
6108
|
this.ctf = new Ctf(this.world, this.rules);
|
|
6039
6109
|
this.gone = this.spots();
|
|
6110
|
+
this.fresh();
|
|
6111
|
+
}
|
|
6112
|
+
/** Every vehicle of the map parked afresh: whole, empty, on its spawn. */
|
|
6113
|
+
fresh() {
|
|
6040
6114
|
this.rovers = park(this.world);
|
|
6115
|
+
this.rearm = [];
|
|
6116
|
+
this.wear = this.rovers.map(() => ({ ...NEW }));
|
|
6041
6117
|
}
|
|
6042
6118
|
/** The health, ammo and cell packs of the map, all there (0 ticks before each is back). */
|
|
6043
6119
|
spots() {
|
|
@@ -6060,7 +6136,7 @@ var Room = class {
|
|
|
6060
6136
|
this.world = build(mapOf(this.mapName));
|
|
6061
6137
|
this.ctf = new Ctf(this.world, this.rules);
|
|
6062
6138
|
this.gone = this.spots();
|
|
6063
|
-
this.
|
|
6139
|
+
this.fresh();
|
|
6064
6140
|
this.history = [];
|
|
6065
6141
|
this.balls = [];
|
|
6066
6142
|
for (const p of this.players()) this.ctf.join(p.info.id, p.info.team, p.state);
|
|
@@ -6107,7 +6183,7 @@ var Room = class {
|
|
|
6107
6183
|
this.lase(p, r, input);
|
|
6108
6184
|
}
|
|
6109
6185
|
} else {
|
|
6110
|
-
const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over, this.rovers.
|
|
6186
|
+
const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over, solid(this.rovers, p.state));
|
|
6111
6187
|
this.ctf.moved(p.state);
|
|
6112
6188
|
this.tackle(p, input.view);
|
|
6113
6189
|
const here = spot(p.state);
|
|
@@ -6138,7 +6214,7 @@ var Room = class {
|
|
|
6138
6214
|
if (!this.size) {
|
|
6139
6215
|
this.ctf.reset();
|
|
6140
6216
|
this.gone.fill(0);
|
|
6141
|
-
this.
|
|
6217
|
+
this.fresh();
|
|
6142
6218
|
this.load();
|
|
6143
6219
|
}
|
|
6144
6220
|
this.seats();
|
|
@@ -6185,14 +6261,21 @@ var Room = class {
|
|
|
6185
6261
|
}
|
|
6186
6262
|
this.seats();
|
|
6187
6263
|
this.rovers.forEach((r, k) => this.dock(r, k));
|
|
6188
|
-
for (const r of this.rovers)
|
|
6189
|
-
|
|
6190
|
-
|
|
6264
|
+
for (const r of this.rovers) {
|
|
6265
|
+
if (r.driver !== 255) {
|
|
6266
|
+
this.carry(r);
|
|
6267
|
+
continue;
|
|
6268
|
+
}
|
|
6269
|
+
if (r.wreck) skid(r);
|
|
6270
|
+
if (drive(r, void 0, this.world, this.rovers)) this.sink(r);
|
|
6271
|
+
else this.carry(r);
|
|
6272
|
+
}
|
|
6191
6273
|
this.seats();
|
|
6192
6274
|
if (now % 2 === 0) {
|
|
6193
6275
|
this.history.push({
|
|
6194
6276
|
tick: now,
|
|
6195
|
-
players: players.map((p) => ({ ...p.state }))
|
|
6277
|
+
players: players.map((p) => ({ ...p.state })),
|
|
6278
|
+
rovers: this.rovers.map((r) => ({ ...r }))
|
|
6196
6279
|
});
|
|
6197
6280
|
while (this.history[0].tick < now - 30) this.history.shift();
|
|
6198
6281
|
const snap = encodeSnapshot({
|
|
@@ -6251,15 +6334,9 @@ var Room = class {
|
|
|
6251
6334
|
/** Every player as the snapshots around the view tick `view` showed him: rewind(), the asker included. */
|
|
6252
6335
|
past(view = 0) {
|
|
6253
6336
|
const now = this.players().map((p) => p.state);
|
|
6254
|
-
const
|
|
6255
|
-
if (!
|
|
6256
|
-
const
|
|
6257
|
-
const t = Math.min(Math.max(this.ticks - back, first.tick), last.tick);
|
|
6258
|
-
let k = 0;
|
|
6259
|
-
while (k + 1 < this.history.length && this.history[k + 1].tick <= t) k++;
|
|
6260
|
-
const [a, b] = [this.history[k], this.history[k + 1] ?? this.history[k]];
|
|
6261
|
-
const u = b.tick > a.tick ? (t - a.tick) / (b.tick - a.tick) : 0;
|
|
6262
|
-
const l = (m, n) => m + (n - m) * u;
|
|
6337
|
+
const at = this.around(view);
|
|
6338
|
+
if (!at) return now;
|
|
6339
|
+
const [a, b, l] = at;
|
|
6263
6340
|
return now.map((p) => {
|
|
6264
6341
|
const pa = a.players.find((q) => q.id === p.id);
|
|
6265
6342
|
const pb = b.players.find((q) => q.id === p.id);
|
|
@@ -6271,6 +6348,43 @@ var Room = class {
|
|
|
6271
6348
|
} : pb ?? pa ?? p;
|
|
6272
6349
|
});
|
|
6273
6350
|
}
|
|
6351
|
+
/** The two kept snapshots around the view tick `view`, and the mix between them; nothing with no history. */
|
|
6352
|
+
around(view) {
|
|
6353
|
+
const [first, last] = [this.history[0], this.history.at(-1)];
|
|
6354
|
+
if (!first || !last) return;
|
|
6355
|
+
const back = ((this.ticks - view + 32768) % 65536 + 65536) % 65536 - 32768;
|
|
6356
|
+
const t = Math.min(Math.max(this.ticks - back, first.tick), last.tick);
|
|
6357
|
+
let k = 0;
|
|
6358
|
+
while (k + 1 < this.history.length && this.history[k + 1].tick <= t) k++;
|
|
6359
|
+
const [a, b] = [this.history[k], this.history[k + 1] ?? this.history[k]];
|
|
6360
|
+
const u = b.tick > a.tick ? (t - a.tick) / (b.tick - a.tick) : 0;
|
|
6361
|
+
return [
|
|
6362
|
+
a,
|
|
6363
|
+
b,
|
|
6364
|
+
(m, n) => m + (n - m) * u
|
|
6365
|
+
];
|
|
6366
|
+
}
|
|
6367
|
+
/**
|
|
6368
|
+
* The vehicles a shooter of `team` may hurt, each with its index, as he drew them at the view
|
|
6369
|
+
* tick `view` (the place interpolated like a player's, the angles the later snapshot's); as
|
|
6370
|
+
* they are now with no `view`. For the katana and the rail gun, which strike where he saw.
|
|
6371
|
+
*/
|
|
6372
|
+
hulls(team, view) {
|
|
6373
|
+
const at = view === void 0 ? void 0 : this.around(view);
|
|
6374
|
+
return this.targets(team).map((r) => {
|
|
6375
|
+
const k = this.rovers.indexOf(r);
|
|
6376
|
+
const [ra, rb] = [at?.[0].rovers[k], at?.[1].rovers[k]];
|
|
6377
|
+
if (!at || !ra || !rb || ra.wreck || rb.wreck) return [r, k];
|
|
6378
|
+
const l = at[2];
|
|
6379
|
+
return [{
|
|
6380
|
+
...r,
|
|
6381
|
+
...rb,
|
|
6382
|
+
x: l(ra.x, rb.x),
|
|
6383
|
+
y: l(ra.y, rb.y),
|
|
6384
|
+
z: l(ra.z, rb.z)
|
|
6385
|
+
}, k];
|
|
6386
|
+
});
|
|
6387
|
+
}
|
|
6274
6388
|
/**
|
|
6275
6389
|
* After a move of `p` at the view tick `view`: a dash or a slide that overlaps an enemy carrier
|
|
6276
6390
|
* tackles him. The carrier is where `p` drew him (lag compensation), so a tackle that hit on
|
|
@@ -6360,9 +6474,9 @@ var Room = class {
|
|
|
6360
6474
|
* Flies the ball `b` on by `m` metres: one that bursts on an enemy who is up takes its power in hp
|
|
6361
6475
|
* from him, and counts a hit to its shooter. An arc takes its cut's hp; one it does not put down
|
|
6362
6476
|
* is floored (FLOOR_TICKS, `zap`), thrown ARC_KNOCK m/s the way it flies, and drops the flag.
|
|
6363
|
-
* A grenade flies one tick of its arc whatever `m`, and its burst is a blast
|
|
6364
|
-
*
|
|
6365
|
-
*
|
|
6477
|
+
* A grenade flies one tick of its arc whatever `m`, and its burst is a blast (boom()); one hit
|
|
6478
|
+
* for the shooter when it hurt an enemy or his vehicle. A ball an enemy vehicle's hull stops
|
|
6479
|
+
* (ram()) hurts the hull, not the crew behind it.
|
|
6366
6480
|
*/
|
|
6367
6481
|
fly(b, m) {
|
|
6368
6482
|
const peers = this.players();
|
|
@@ -6376,34 +6490,22 @@ var Room = class {
|
|
|
6376
6490
|
if (b.power === 7) {
|
|
6377
6491
|
toss(this.world, b, foes.map((f) => f.state));
|
|
6378
6492
|
this.ram(b, o);
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
]);
|
|
6385
|
-
if (d < SHIP.BLAST_R) this.hurt(r, Math.ceil(SHIP.BLAST_HP * (1 - d / SHIP.BLAST_R)), by);
|
|
6386
|
-
}
|
|
6387
|
-
let hit = false;
|
|
6388
|
-
for (const q of b.burst ? peers : []) {
|
|
6389
|
-
const own = q.info.id === b.by;
|
|
6390
|
-
const hp = !q.state.down && (own || q.info.team !== b.team) ? blast(this.world, [
|
|
6391
|
-
b.x,
|
|
6392
|
-
b.y,
|
|
6393
|
-
b.z
|
|
6394
|
-
], q.state) : 0;
|
|
6395
|
-
if (hp) {
|
|
6396
|
-
this.harm(q, hp);
|
|
6397
|
-
hit ||= !own;
|
|
6398
|
-
}
|
|
6399
|
-
}
|
|
6400
|
-
if (hit && by) by.state.hits = by.state.hits + 1 & 255;
|
|
6493
|
+
if (b.burst && this.boom([
|
|
6494
|
+
b.x,
|
|
6495
|
+
b.y,
|
|
6496
|
+
b.z
|
|
6497
|
+
], b.by, b.team) && by) by.state.hits = by.state.hits + 1 & 255;
|
|
6401
6498
|
return;
|
|
6402
6499
|
}
|
|
6403
6500
|
const hit = fly(this.world, b, m, foes.map((f) => f.state));
|
|
6404
|
-
const
|
|
6405
|
-
if (
|
|
6406
|
-
|
|
6501
|
+
const hull = this.ram(b, o);
|
|
6502
|
+
if (hull) {
|
|
6503
|
+
if (by) by.state.hits = by.state.hits + 1 & 255;
|
|
6504
|
+
if (b.power === 0 || b.power === 6) {
|
|
6505
|
+
const w = this.wear[this.rovers.indexOf(hull)];
|
|
6506
|
+
w.graze = (w.graze + 1) % VEHICLE.GRAZE;
|
|
6507
|
+
if (!w.graze) this.hurt(hull, 1, b.by, b.team);
|
|
6508
|
+
} else this.hurt(hull, b.arc ? CUTS[b.arc].hp : b.power ?? 1, b.by, b.team);
|
|
6407
6509
|
return;
|
|
6408
6510
|
}
|
|
6409
6511
|
const foe = foes.find((q) => q.state === hit);
|
|
@@ -6438,7 +6540,8 @@ var Room = class {
|
|
|
6438
6540
|
* (`strike`), and the `hits` count goes up once. Each takes the cut's hp; one it does not put
|
|
6439
6541
|
* down is shocked: a stumble of SHOCK_TICKS thrown SHOCK_KNOCK m/s the way the blade throws him, with
|
|
6440
6542
|
* `zap`, and `by` the attacker. A shock drops no flag. One it puts down loses the limb the blade
|
|
6441
|
-
* crosses where `p` drew him (`limbOf`).
|
|
6543
|
+
* crosses where `p` drew him (`limbOf`). An enemy vehicle's hull the cut meets (slashed(), where
|
|
6544
|
+
* `p` drew it) takes the cut's hp, and its crew none of it.
|
|
6442
6545
|
*/
|
|
6443
6546
|
cut(p, view) {
|
|
6444
6547
|
if (!p.state.blade) {
|
|
@@ -6449,7 +6552,9 @@ var Room = class {
|
|
|
6449
6552
|
this.shoot(p, view, wave(p.state, p.info.team));
|
|
6450
6553
|
return;
|
|
6451
6554
|
}
|
|
6452
|
-
const
|
|
6555
|
+
const cars = this.hulls(p.info.team, view).filter(([r]) => slashed(this.world, r, p.state, swingOf(p.state)));
|
|
6556
|
+
const crew = cars.flatMap(([, k]) => SEATS.map((s) => this.rovers[k][s]));
|
|
6557
|
+
const seen = strike(this.world, p.state, this.enemies(p, view)).filter((s) => !crew.includes(s.id));
|
|
6453
6558
|
let foes = this.players().filter((q) => seen.some((s) => s.id === q.info.id));
|
|
6454
6559
|
const locked = foes.find((q) => crossing(p.state, {
|
|
6455
6560
|
...q.state,
|
|
@@ -6474,8 +6579,9 @@ var Room = class {
|
|
|
6474
6579
|
}
|
|
6475
6580
|
foes = foes.filter((q) => q !== locked);
|
|
6476
6581
|
}
|
|
6477
|
-
if (!foes.length) return;
|
|
6582
|
+
if (!foes.length && !cars.length) return;
|
|
6478
6583
|
p.state.hits = p.state.hits + 1 & 255;
|
|
6584
|
+
for (const [, k] of cars) this.hurt(this.rovers[k], swingOf(p.state).hp, p.info.id, p.info.team);
|
|
6479
6585
|
for (const foe of foes) {
|
|
6480
6586
|
const drawn = seen.find((s) => s.id === foe.info.id);
|
|
6481
6587
|
if (this.harm(foe, swingOf(p.state).hp)) foe.state.lost = limbOf(p.state, drawn);
|
|
@@ -6517,10 +6623,29 @@ var Room = class {
|
|
|
6517
6623
|
/**
|
|
6518
6624
|
* The rail gun's bolt of `p` at the view tick `view`: the first enemy it enters as `p` drew him is
|
|
6519
6625
|
* drained for RAIL_TICKS more (`slow`). A first touch, when he was not drained, takes 1 hp at once
|
|
6520
|
-
* and counts a hit.
|
|
6626
|
+
* and counts a hit. An enemy vehicle's hull is drained the same way, and shields who is behind it.
|
|
6521
6627
|
*/
|
|
6522
6628
|
rail(p, view) {
|
|
6523
|
-
const { hit } = beam(this.world, p.state, this.enemies(p, view));
|
|
6629
|
+
const { o, d, t, hit } = beam(this.world, p.state, this.enemies(p, view));
|
|
6630
|
+
const [s, k] = this.hulls(p.info.team, view).reduce((best, [r, n]) => {
|
|
6631
|
+
const u = struck(r, o, d, best[0]);
|
|
6632
|
+
return u < best[0] ? [u, n] : best;
|
|
6633
|
+
}, [t, -1]);
|
|
6634
|
+
if (s < t) {
|
|
6635
|
+
const w = this.wear[k];
|
|
6636
|
+
const fresh = !w.sear;
|
|
6637
|
+
Object.assign(w, {
|
|
6638
|
+
sear: 180,
|
|
6639
|
+
by: p.info.id,
|
|
6640
|
+
team: p.info.team
|
|
6641
|
+
});
|
|
6642
|
+
if (fresh) {
|
|
6643
|
+
p.state.hits = p.state.hits + 1 & 255;
|
|
6644
|
+
w.burn = 0;
|
|
6645
|
+
this.hurt(this.rovers[k], 1, p.info.id, p.info.team);
|
|
6646
|
+
}
|
|
6647
|
+
return;
|
|
6648
|
+
}
|
|
6524
6649
|
const foe = this.players().find((q) => q.info.id === hit?.id);
|
|
6525
6650
|
if (foe) {
|
|
6526
6651
|
const fresh = !foe.state.slow;
|
|
@@ -6630,7 +6755,7 @@ var Room = class {
|
|
|
6630
6755
|
* respawned or stumbled out is off the rover.
|
|
6631
6756
|
*/
|
|
6632
6757
|
/**
|
|
6633
|
-
* The first enemy
|
|
6758
|
+
* The first enemy vehicle on the way the ball `b` flew this tick, from `o` to where it is now: the
|
|
6634
6759
|
* ball bursts on its hull, short of a body or a wall further on.
|
|
6635
6760
|
*/
|
|
6636
6761
|
ram(b, o) {
|
|
@@ -6699,8 +6824,13 @@ var Room = class {
|
|
|
6699
6824
|
respawn(p.state, this.world, p.info.team);
|
|
6700
6825
|
this.ctf.moved(p.state);
|
|
6701
6826
|
}
|
|
6702
|
-
|
|
6703
|
-
|
|
6827
|
+
this.renew(this.rovers.indexOf(r));
|
|
6828
|
+
}
|
|
6829
|
+
/** Vehicle `k` parked afresh on its spawn: whole, empty. */
|
|
6830
|
+
renew(k) {
|
|
6831
|
+
Object.assign(this.rovers[k], park(this.world)[k]);
|
|
6832
|
+
this.rearm[k] = 0;
|
|
6833
|
+
this.wear[k] = { ...NEW };
|
|
6704
6834
|
}
|
|
6705
6835
|
/**
|
|
6706
6836
|
* After a step of the driver `p` at the view tick `view`: the rover's body (footprint()) over an
|
|
@@ -6734,44 +6864,95 @@ var Room = class {
|
|
|
6734
6864
|
this.shoot(p, i.view, missile(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt, p.side));
|
|
6735
6865
|
}
|
|
6736
6866
|
/**
|
|
6737
|
-
* A
|
|
6738
|
-
*
|
|
6867
|
+
* A vehicle's clock outside its driver's inputs: a wreck is parked afresh after VEHICLE.WRECK
|
|
6868
|
+
* ticks; a hull the rail gun's bolt sears loses 1 hp each RAIL_DRAIN ticks after its first touch;
|
|
6869
|
+
* a ship short of missiles loads one each SHIP.RELOAD ticks.
|
|
6739
6870
|
*/
|
|
6740
6871
|
dock(r, k) {
|
|
6741
|
-
if (!r.ship) return;
|
|
6742
6872
|
if (r.wreck) {
|
|
6743
|
-
if (!--r.wreck)
|
|
6744
|
-
Object.assign(r, park(this.world)[k]);
|
|
6745
|
-
this.rearm[k] = 0;
|
|
6746
|
-
}
|
|
6873
|
+
if (!--r.wreck) this.renew(k);
|
|
6747
6874
|
return;
|
|
6748
6875
|
}
|
|
6876
|
+
const w = this.wear[k];
|
|
6877
|
+
if (w.sear) {
|
|
6878
|
+
w.sear--;
|
|
6879
|
+
if (!(++w.burn % 60)) this.hurt(r, 1, w.by, w.team);
|
|
6880
|
+
}
|
|
6881
|
+
if (!r.ship || r.wreck) return;
|
|
6749
6882
|
this.rearm[k] = (r.nades ?? 0) < SHIP.MISSILES ? (this.rearm[k] ?? 0) + 1 : 0;
|
|
6750
6883
|
if (this.rearm[k] >= SHIP.RELOAD) {
|
|
6751
6884
|
r.nades = (r.nades ?? 0) + 1;
|
|
6752
6885
|
this.rearm[k] = 0;
|
|
6753
6886
|
}
|
|
6754
6887
|
}
|
|
6755
|
-
/** The
|
|
6888
|
+
/** The team a vehicle is of: its driver's, else its rider's, else the one whose base it is parked at. */
|
|
6889
|
+
teamOf(r) {
|
|
6890
|
+
const who = this.players().find((p) => p.info.id === (r.driver === 255 ? r.rider : r.driver));
|
|
6891
|
+
return who ? who.info.team : homeOf(this.world, this.rovers.indexOf(r));
|
|
6892
|
+
}
|
|
6893
|
+
/** The vehicles a shooter of `team` hurts: whole, and not of his team. */
|
|
6756
6894
|
targets(team) {
|
|
6757
|
-
|
|
6758
|
-
|
|
6895
|
+
return this.rovers.filter((r) => !r.wreck && this.teamOf(r) !== team);
|
|
6896
|
+
}
|
|
6897
|
+
/** The vehicle `r` loses `hp` to player `by` of `team`; at 0 it blows up (wreck()). */
|
|
6898
|
+
hurt(r, hp, by, team) {
|
|
6899
|
+
if (r.wreck) return;
|
|
6900
|
+
r.hp = Math.max(0, (r.hp ?? VEHICLE.HP) - hp);
|
|
6901
|
+
if (!r.hp) this.wreck(r, by, team);
|
|
6759
6902
|
}
|
|
6760
6903
|
/**
|
|
6761
|
-
* The
|
|
6762
|
-
*
|
|
6904
|
+
* The vehicle blows up where it is, by the hand of player `by` of `team`: who is aboard goes
|
|
6905
|
+
* down on the spot, and it is a wreck for VEHICLE.WRECK ticks, with no seat, moved by the tick
|
|
6906
|
+
* alone. Its blast is a grenade of `by` at its centre (boom()).
|
|
6763
6907
|
*/
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
r.hp = Math.max(0, (r.hp ?? 0) - hp);
|
|
6767
|
-
if (r.hp) return;
|
|
6768
|
-
for (const q of this.players()) if (this.seatOf(q)[0] === r) this.harm(q, q.state.hp);
|
|
6908
|
+
wreck(r, by, team) {
|
|
6909
|
+
const crew = this.players().filter((q) => this.seatOf(q)[0] === r);
|
|
6769
6910
|
Object.assign(r, {
|
|
6770
|
-
|
|
6911
|
+
hp: 0,
|
|
6912
|
+
wreck: VEHICLE.WRECK,
|
|
6771
6913
|
driver: 255,
|
|
6772
|
-
rider: 255
|
|
6773
|
-
nades: 0
|
|
6914
|
+
rider: 255
|
|
6774
6915
|
});
|
|
6916
|
+
if (r.ship) r.nades = 0;
|
|
6917
|
+
this.wear[this.rovers.indexOf(r)] = { ...NEW };
|
|
6918
|
+
for (const q of crew) this.harm(q, q.state.hp);
|
|
6919
|
+
const hit = this.boom([
|
|
6920
|
+
r.x,
|
|
6921
|
+
r.y,
|
|
6922
|
+
r.z
|
|
6923
|
+
], by, team);
|
|
6924
|
+
const killer = this.players().find((q) => q.info.id === by);
|
|
6925
|
+
if (killer && (hit || crew.length)) killer.state.hits = killer.state.hits + 1 & 255;
|
|
6926
|
+
}
|
|
6927
|
+
/**
|
|
6928
|
+
* A blast at `c`, the grenade's rule, of player `by` of `team`: every enemy on foot who is up,
|
|
6929
|
+
* and `by` himself, lose what blast() gives where they stand now; every enemy vehicle loses
|
|
6930
|
+
* NADE_HP at its hull, less with the distance to it, nothing from NADE_R on or behind a brush.
|
|
6931
|
+
* Who is seated is behind his hull: the blast takes nothing from him. True when it hurt an enemy
|
|
6932
|
+
* or his vehicle.
|
|
6933
|
+
*/
|
|
6934
|
+
boom(c, by, team) {
|
|
6935
|
+
let hit = false;
|
|
6936
|
+
for (const r of this.targets(team)) {
|
|
6937
|
+
const d = reach(r, c);
|
|
6938
|
+
if (d < 5 && !hidden(this.world, c, [
|
|
6939
|
+
r.x,
|
|
6940
|
+
r.y,
|
|
6941
|
+
r.z
|
|
6942
|
+
])) {
|
|
6943
|
+
this.hurt(r, Math.ceil(5 * (1 - d / 5)), by, team);
|
|
6944
|
+
hit = true;
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6947
|
+
for (const q of this.players()) {
|
|
6948
|
+
const own = q.info.id === by;
|
|
6949
|
+
const hp = !q.state.down && q.state.mode !== MODE.RIDE && (own || q.info.team !== team) ? blast(this.world, c, q.state) : 0;
|
|
6950
|
+
if (hp) {
|
|
6951
|
+
this.harm(q, hp);
|
|
6952
|
+
hit ||= !own;
|
|
6953
|
+
}
|
|
6954
|
+
}
|
|
6955
|
+
return hit;
|
|
6775
6956
|
}
|
|
6776
6957
|
splat(p, r, view) {
|
|
6777
6958
|
if (len(r.vx, r.vz) < ROVER.SPLAT_MIN) return;
|
|
@@ -6824,7 +7005,7 @@ var Room = class {
|
|
|
6824
7005
|
const put = [];
|
|
6825
7006
|
this.rr = [0, 0];
|
|
6826
7007
|
this.gone.fill(0);
|
|
6827
|
-
this.
|
|
7008
|
+
this.fresh();
|
|
6828
7009
|
shut(this.world);
|
|
6829
7010
|
for (const p of players) {
|
|
6830
7011
|
const { shots, hits } = p.state;
|