@korial29/tiny-fps 0.128.1 → 0.130.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -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) => {
@@ -632,7 +648,7 @@ var SKIN = .01;
632
648
  * A circle this close to a box (1 mm) is touching it: a push leaves it exactly PLAYER_R away, and
633
649
  * the float32 position it is rounded to is a few micrometres off.
634
650
  */
635
- var TOUCH = .001;
651
+ var TOUCH$1 = .001;
636
652
  /** An angle in [0, 2π). */
637
653
  var norm = (a) => (a % TAU + TAU) % TAU;
638
654
  /** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
@@ -932,7 +948,7 @@ var along = (p, side) => {
932
948
  var faceDist = (b, p, side, reach) => {
933
949
  const { a, o, sign, c, co } = along(p, side);
934
950
  const dist = ((sign > 0 ? b.min[a] : b.max[a]) - c) * sign;
935
- return dist >= .4 - TOUCH && dist <= .4 + reach && co >= b.min[o] && co <= b.max[o] ? dist : void 0;
951
+ return dist >= .4 - TOUCH$1 && dist <= .4 + reach && co >= b.min[o] && co <= b.max[o] ? dist : void 0;
936
952
  };
937
953
  /**
938
954
  * The gap between the cylinder and a wall on `side` that covers the body from the knees to the
@@ -1039,11 +1055,11 @@ var cap = (p, max) => {
1039
1055
  */
1040
1056
  var unwalled = (p, w, c, h) => {
1041
1057
  let [x, z] = [c.wx, c.wz];
1042
- for (const i of near(w, p.x, p.z, PLAYER_R + TOUCH)) {
1058
+ for (const i of near(w, p.x, p.z, PLAYER_R + TOUCH$1)) {
1043
1059
  const b = w.def.brushes[i];
1044
1060
  const [dx, dz] = gap(b, p.x, p.z);
1045
1061
  const d = len$1(dx, dz);
1046
- if (d > 0 && d <= .4 + TOUCH && blocks(b, p.y, h)) {
1062
+ if (d > 0 && d <= .4 + TOUCH$1 && blocks(b, p.y, h)) {
1047
1063
  const into = (-x * dx - z * dz) / d;
1048
1064
  if (into > 0) {
1049
1065
  x += into * dx / d;
@@ -3390,7 +3406,7 @@ var { STONE, CONCRETE, METAL, STEEL, PAINT } = TEX;
3390
3406
  /** The twin of a box across the centre line. */
3391
3407
  var mirror = ({ min, max }) => bx(min[0], min[1], 280 - max[2], max[0], max[1], 280 - min[2]);
3392
3408
  /** The domes' centres, the landing pads (x, z, radius), the modules, the tubes and the masts (centres), red's then blue's: what the scenery draws on. */
3393
- var PAD = [
3409
+ var PAD$1 = [
3394
3410
  40,
3395
3411
  220,
3396
3412
  13
@@ -4332,10 +4348,10 @@ var LAYOUT = {
4332
4348
  sites: SITES,
4333
4349
  pillars: PILLARS,
4334
4350
  domes: [DOME, [DOME[0], 280 - DOME[1]]],
4335
- pads: [PAD, [
4336
- PAD[0],
4337
- 280 - PAD[1],
4338
- PAD[2]
4351
+ pads: [PAD$1, [
4352
+ PAD$1[0],
4353
+ 280 - PAD$1[1],
4354
+ PAD$1[2]
4339
4355
  ]],
4340
4356
  modules: [...MODULES, ...MODULES.map(mirror)],
4341
4357
  tubes: [...TUBES, ...TUBES.map(mirror)],
@@ -4651,14 +4667,14 @@ var MAPS = {
4651
4667
  ]
4652
4668
  ],
4653
4669
  ships: [[
4654
- PAD[0],
4670
+ PAD$1[0],
4655
4671
  .25,
4656
- PAD[1],
4672
+ PAD$1[1],
4657
4673
  0
4658
4674
  ], [
4659
- PAD[0],
4675
+ PAD$1[0],
4660
4676
  .25,
4661
- 280 - PAD[1],
4677
+ 280 - PAD$1[1],
4662
4678
  Math.PI
4663
4679
  ]],
4664
4680
  doors: [...DOORS, ...DOORS.map(mirror)],
@@ -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
- if (r.ship) {
4948
- v.setUint8(o + 54, 128 | Math.max(0, Math.min(127, r.hp ?? 0)));
4949
- v.setUint8(o + 55, Math.min(255, Math.ceil((r.wreck ?? 0) / 4)));
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,
@@ -5099,12 +5110,14 @@ var SHIP = {
5099
5110
  MISSILE_COOL: 30,
5100
5111
  RELOAD: 300,
5101
5112
  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
5113
+ /**
5114
+ * A crash (the user, 2026-11-12): the speed a step's collisions take away (m/s, the vertical
5115
+ * part halved, so a sink onto a pad is no crash) past CRASH costs 1 hp each CRASH_HP more.
5116
+ */
5117
+ CRASH: 12,
5118
+ CRASH_HP: 4,
5119
+ /** How much of the speed into another vehicle comes back off it. */
5120
+ BOUNCE: .3
5108
5121
  };
5109
5122
  /** The lasers' muzzles under the wings, the missiles' pods under the wings: right of the centre, above it, ahead of it. */
5110
5123
  var SHIP_GUNS = [[
@@ -5125,6 +5138,87 @@ var PODS = [[
5125
5138
  -.7,
5126
5139
  -2.9
5127
5140
  ]];
5141
+ /**
5142
+ * A wing's sections, at the hull, at the cannon and at the tip: right, the leading and the trailing
5143
+ * edge ahead, the top and the bottom. craft.ts draws them; the shots, the players on foot, the
5144
+ * other vehicles and the brushes meet them (the user, 2026-11-12: the wings went through all).
5145
+ */
5146
+ var WING = [
5147
+ [
5148
+ .9,
5149
+ -2.7,
5150
+ -5.3,
5151
+ .14,
5152
+ -.12
5153
+ ],
5154
+ [
5155
+ 2.6,
5156
+ -2.6,
5157
+ -5.5,
5158
+ .12,
5159
+ -.1
5160
+ ],
5161
+ [
5162
+ 6.4,
5163
+ -4.9,
5164
+ -6.1,
5165
+ -.7,
5166
+ -.78
5167
+ ]
5168
+ ];
5169
+ /** The right wing's section `x` metres right of the centre, between two of WING's. */
5170
+ var section = (x) => {
5171
+ const k = x < WING[1][0] ? 0 : 1;
5172
+ const [a, b] = [WING[k], WING[k + 1]];
5173
+ const t = (x - a[0]) / (b[0] - a[0]);
5174
+ return a.map((v, n) => v + (b[n] - v) * t);
5175
+ };
5176
+ /**
5177
+ * The right wing as the shots meet it: boxes in the ship's frame along the span, each round its
5178
+ * slice of the wing with a margin of PAD: [right, up, ahead] each from, to.
5179
+ */
5180
+ var PAD = .1;
5181
+ var WING_BOXES = [
5182
+ .9,
5183
+ 2.6,
5184
+ 3.9,
5185
+ 5.15,
5186
+ 6.4
5187
+ ].slice(1).map((x1, k, xs) => {
5188
+ const x0 = k ? xs[k - 1] : .9;
5189
+ const [s0, s1] = [section(x0), section(x1)];
5190
+ return [
5191
+ [x0, x1 + PAD],
5192
+ [Math.min(s0[4], s1[4]) - PAD, Math.max(s0[3], s1[3]) + PAD],
5193
+ [Math.min(s0[2], s1[2]) - PAD, Math.max(s0[1], s1[1]) + PAD]
5194
+ ];
5195
+ });
5196
+ /**
5197
+ * The right wing as the players on foot and the other vehicles meet it: stadiums from the root to
5198
+ * near the tip along the middle of the chord ([from, to, radius]), WING_H thick over its bottom.
5199
+ */
5200
+ var WING_BODY = [[
5201
+ 1.4,
5202
+ 3.2,
5203
+ 1.1
5204
+ ], [
5205
+ 3.2,
5206
+ 5.8,
5207
+ .75
5208
+ ]];
5209
+ var WING_H = .4;
5210
+ /** The wing tips against the brushes: a circle this wide, this far right of the centre. */
5211
+ var TIP = {
5212
+ X: 5.6,
5213
+ R: .8
5214
+ };
5215
+ /** Where the wings' undersides meet the floor: right of the centre, and the trailing edge (-1), the middle of the chord (0) or the leading edge (1). */
5216
+ var TOUCH = [
5217
+ [3.2, 0],
5218
+ [4.8, 0],
5219
+ [6.4, -1],
5220
+ [6.4, 1]
5221
+ ];
5128
5222
  /** The pilot's seat in the cockpit, behind the long nose: right of the centre, above it (the feet), ahead of it. */
5129
5223
  var COCKPIT = [
5130
5224
  0,
@@ -5182,7 +5276,7 @@ var point = (r, b, u, a) => {
5182
5276
  r.z + R[2] * b + U[2] * u + F[2] * a
5183
5277
  ];
5184
5278
  };
5185
- /** The map's ships at rest on their pads: full armour and missiles, nobody aboard. */
5279
+ /** The map's ships at rest on their pads: whole, full of missiles, nobody aboard. */
5186
5280
  var dock = (ships = []) => ships.map(([x, y, z, yaw]) => ({
5187
5281
  x: f32$1(x),
5188
5282
  y: f32$1(y + SHIP.DROP),
@@ -5200,31 +5294,15 @@ var dock = (ships = []) => ships.map(([x, y, z, yaw]) => ({
5200
5294
  driver: 255,
5201
5295
  rider: 255,
5202
5296
  ship: true,
5203
- hp: SHIP.HP,
5297
+ hp: VEHICLE.HP,
5204
5298
  wreck: 0,
5205
5299
  nades: SHIP.MISSILES
5206
5300
  }));
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
5301
  /**
5223
5302
  * The hull as the players on foot and the rovers meet it: the stadium from the tail to the nose
5224
5303
  * along the floor plane, R wide, from the skids up H. A player walks into it and stands on it.
5225
5304
  */
5226
5305
  var shipHull = (r) => {
5227
- if (r.wreck) return NONE;
5228
5306
  const [a, b] = [SHIP.BODY[0], SHIP.BODY[2]].map((k) => point(r, 0, -SHIP.DROP, k));
5229
5307
  return {
5230
5308
  a,
@@ -5233,6 +5311,21 @@ var shipHull = (r) => {
5233
5311
  h: SHIP.H
5234
5312
  };
5235
5313
  };
5314
+ /** The wings as solids (WING_BODY), the left one then the right one. */
5315
+ var wings = (r) => [-1, 1].flatMap((s) => WING_BODY.map(([x0, x1, rad]) => {
5316
+ const [a, b] = [x0, x1].map((x) => {
5317
+ const [, le, te, , low] = section(x);
5318
+ return point(r, s * x, low - .05, (le + te) / 2);
5319
+ });
5320
+ return {
5321
+ a,
5322
+ b,
5323
+ r: rad,
5324
+ h: WING_H
5325
+ };
5326
+ }));
5327
+ /** Every solid of the ship: its hull, then its wings. */
5328
+ var shipBodies = (r) => [shipHull(r), ...wings(r)];
5236
5329
  /**
5237
5330
  * The ship against the crater's edge: its distance from the bound's centre and the edge's along the
5238
5331
  * same line, and the unit way out on the floor plane. Undefined on a map without a relief.
@@ -5268,16 +5361,15 @@ var roof = (w, x, z, y0, y1) => {
5268
5361
  /**
5269
5362
  * One step of 1 / TICK_HZ s, in place. `i` is the pilot's input as the wire rounds it, or
5270
5363
  * undefined with nobody at the stick: the engines are off and it falls under the map's gravity to
5271
- * a floor. A ship that is gone (`wreck`) does not move. Returns whether it fell under the kill
5272
- * floor: the caller docks it again.
5364
+ * a floor, a wreck as well. Returns whether it fell under the kill floor: the caller docks it
5365
+ * again.
5273
5366
  *
5274
5367
  * The nose turns toward the look as fast as the rates allow and banks into the turn; the thrust
5275
5368
  * is along the nose, sideways and straight up, against a drag that sets the top speed. Piloted,
5276
5369
  * the engines hold it against gravity: it hovers with no key held. On a floor it rests on its
5277
5370
  * skids, level.
5278
5371
  */
5279
- var pilot = (r, i, w) => {
5280
- if (r.wreck) return false;
5372
+ var pilot = (r, i, w, others = [], crash) => {
5281
5373
  const keys = i ? i.keys : 0;
5282
5374
  const on = (k) => keys & k ? 1 : 0;
5283
5375
  const thr = on(KEY.FORWARD) - on(KEY.BACK);
@@ -5363,6 +5455,11 @@ var pilot = (r, i, w) => {
5363
5455
  r.z -= nz * (d - at - SHIP.OVER);
5364
5456
  }
5365
5457
  }
5458
+ const v0 = [
5459
+ r.vx,
5460
+ r.vy,
5461
+ r.vz
5462
+ ];
5366
5463
  let lifted = 0;
5367
5464
  for (const k of SHIP.BODY) {
5368
5465
  const [x, y, z] = point(r, 0, -SHIP.DROP, k);
@@ -5374,6 +5471,16 @@ var pilot = (r, i, w) => {
5374
5471
  r.vy = max$1(r.vy, 0);
5375
5472
  r.steer = r.vy > .5 ? 0 : -1;
5376
5473
  }
5474
+ let scraped = 0;
5475
+ for (const s of [-1, 1]) for (const [x, edge] of TOUCH) {
5476
+ const [, le, te, , low] = section(x);
5477
+ const [px, py, pz] = point(r, s * x, low, edge < 0 ? te : edge > 0 ? le : (le + te) / 2);
5478
+ scraped = max$1(scraped, floorAt(w, px, pz, py + 1) - py);
5479
+ }
5480
+ if (scraped > 0) {
5481
+ r.y += scraped;
5482
+ r.vy = max$1(r.vy, 0);
5483
+ }
5377
5484
  for (const k of SHIP.BODY) {
5378
5485
  const [x, y, z] = point(r, 0, -SHIP.DROP, k);
5379
5486
  const top = roof(w, x, z, y + .6, y + SHIP.H);
@@ -5398,18 +5505,75 @@ var pilot = (r, i, w) => {
5398
5505
  r.vz -= v * pz;
5399
5506
  }
5400
5507
  }
5508
+ for (const s of [-1, 1]) {
5509
+ const [, le, te, , low] = section(TIP.X);
5510
+ const [x, y, z] = point(r, s * TIP.X, low, (le + te) / 2);
5511
+ const [px, pz] = shove({
5512
+ x,
5513
+ y,
5514
+ z
5515
+ }, w, WING_H, TIP.R);
5516
+ const d = px * px + pz * pz;
5517
+ if (d) {
5518
+ r.x += px;
5519
+ r.z += pz;
5520
+ const v = min$1(0, r.vx * px + r.vz * pz) / d;
5521
+ r.vx -= v * px;
5522
+ r.vz -= v * pz;
5523
+ }
5524
+ }
5525
+ if (others.length) {
5526
+ const [, le, te, , low] = section(TIP.X);
5527
+ const mine = [
5528
+ ...SHIP.BODY.map((k) => [
5529
+ 0,
5530
+ -SHIP.DROP,
5531
+ k,
5532
+ SHIP.R,
5533
+ SHIP.H
5534
+ ]),
5535
+ [
5536
+ -TIP.X,
5537
+ low,
5538
+ (le + te) / 2,
5539
+ TIP.R,
5540
+ WING_H
5541
+ ],
5542
+ [
5543
+ TIP.X,
5544
+ low,
5545
+ (le + te) / 2,
5546
+ TIP.R,
5547
+ WING_H
5548
+ ]
5549
+ ];
5550
+ for (const o of others) for (const [b, u, k, rad, h] of mine) {
5551
+ const [x, y, z] = point(r, b, u, k);
5552
+ const [dx, dz, oy] = gapTo(o, x, z);
5553
+ const reach = rad + o.r;
5554
+ const d = sqrt$1(dx * dx + dz * dz);
5555
+ if (d >= reach - 1e-4 || oy >= y + h || oy + o.h <= y) continue;
5556
+ const [nx, nz] = d ? [dx / d, dz / d] : [cos$1(r.yaw), -sin$1(r.yaw)];
5557
+ r.x += nx * (reach - d);
5558
+ r.z += nz * (reach - d);
5559
+ const v = min$1(0, r.vx * nx + r.vz * nz) * (1 + SHIP.BOUNCE);
5560
+ r.vx -= v * nx;
5561
+ r.vz -= v * nz;
5562
+ }
5563
+ }
5401
5564
  bound(r, w);
5565
+ const jolt = sqrt$1((r.vx - v0[0]) ** 2 + ((r.vy - v0[1]) / 2) ** 2 + (r.vz - v0[2]) ** 2);
5566
+ if (crash && jolt > SHIP.CRASH) crash(jolt);
5402
5567
  if (abs$1(r.roll) < 1e-6) r.roll = 0;
5403
5568
  for (const k of FLOATS$1) r[k] = f32$1(r[k]);
5404
5569
  return r.y < w.def.floor;
5405
5570
  };
5406
5571
  /**
5407
5572
  * 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; a ship that is gone has none.
5573
+ * Infinity. The hull is the HITS spheres.
5409
5574
  */
5410
- var struck = (r, o, d, m) => {
5411
- if (r.wreck) return Infinity;
5412
- let best = Infinity;
5575
+ var struck$1 = (r, o, d, m) => {
5576
+ let best = wingStruck(r, o, d);
5413
5577
  for (const k of SHIP.HITS) {
5414
5578
  const c = point(r, 0, 0, k);
5415
5579
  const [px, py, pz] = [
@@ -5424,13 +5588,51 @@ var struck = (r, o, d, m) => {
5424
5588
  const t = max$1(0, -b - sqrt$1(disc));
5425
5589
  if (t <= m && t < best) best = t;
5426
5590
  }
5591
+ return best <= m ? best : Infinity;
5592
+ };
5593
+ /** `v` in the ship's frame: right, up and ahead of its centre (`at`), or along its axes. */
5594
+ var frame = (r, v, at = true) => {
5595
+ const q = at ? [
5596
+ v[0] - r.x,
5597
+ v[1] - r.y,
5598
+ v[2] - r.z
5599
+ ] : v;
5600
+ return axes(r).map((e) => e[0] * q[0] + e[1] * q[1] + e[2] * q[2]);
5601
+ };
5602
+ /** The boxes of both wings, each [right, up, ahead] from, to. */
5603
+ var BOXES = [-1, 1].flatMap((s) => WING_BOXES.map(([x, y, a]) => [
5604
+ s > 0 ? x : [-x[1], -x[0]],
5605
+ y,
5606
+ a
5607
+ ]));
5608
+ /** Where a shot from `o` along the unit `d` first enters a wing: the distance, or Infinity. */
5609
+ var wingStruck = (r, o, d) => {
5610
+ const [lo, ld] = [frame(r, o), frame(r, d, false)];
5611
+ let best = Infinity;
5612
+ for (const box of BOXES) {
5613
+ let [t0, t1] = [0, Infinity];
5614
+ for (let n = 0; n < 3 && t0 <= t1; n++) {
5615
+ const [from, to] = box[n];
5616
+ if (abs$1(ld[n]) < 1e-9) {
5617
+ if (lo[n] < from || lo[n] > to) t0 = Infinity;
5618
+ continue;
5619
+ }
5620
+ const [a, b] = [(from - lo[n]) / ld[n], (to - lo[n]) / ld[n]];
5621
+ t0 = max$1(t0, min$1(a, b));
5622
+ t1 = min$1(t1, max$1(a, b));
5623
+ }
5624
+ if (t0 <= t1 && t0 < best) best = t0;
5625
+ }
5427
5626
  return best;
5428
5627
  };
5429
- /** 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) => {
5431
- const [x, y, z] = point(r, 0, 0, k).map((v, n) => c[n] - v);
5432
- return max$1(0, sqrt$1(x * x + y * y + z * z) - SHIP.HIT);
5433
- }));
5628
+ /** The distance from `c` to the nearest point of the hull's spheres and the wings, 0 inside. */
5629
+ var reach$1 = (r, c) => {
5630
+ const l = frame(r, c);
5631
+ return min$1(...SHIP.HITS.map((k) => {
5632
+ const [x, y, z] = point(r, 0, 0, k).map((v, n) => c[n] - v);
5633
+ return max$1(0, sqrt$1(x * x + y * y + z * z) - SHIP.HIT);
5634
+ }), ...BOXES.map((box) => sqrt$1(box.reduce((s, [from, to], n) => s + max$1(0, from - l[n], l[n] - to) ** 2, 0))));
5635
+ };
5434
5636
  // src/shared/rover.ts
5435
5637
  /** The rover's sizes and its handling (docs/MOON.md). Lengths in metres, per wheel rates for a body of mass 1. */
5436
5638
  var ROVER = {
@@ -5487,6 +5689,12 @@ var ROVER = {
5487
5689
  WHEEL_STEP: .6,
5488
5690
  /** The share of its speed into another rover a rover bounces back with. */
5489
5691
  BOUNCE: .3,
5692
+ /**
5693
+ * A crash (the user, 2026-11-12): the speed on the level that a step's walls and vehicles take
5694
+ * away (m/s) past CRASH costs 1 hp each CRASH_HP more. A landing is the springs': no crash.
5695
+ */
5696
+ CRASH: 10,
5697
+ CRASH_HP: 3,
5490
5698
  /** A player this close to a rover's centre gets in; a rover this fast hurts an enemy, and this fast puts him down. */
5491
5699
  ENTER_R: 3,
5492
5700
  SPLAT_MIN: 6,
@@ -5586,9 +5794,24 @@ var hull = (r) => {
5586
5794
  h: ROVER.BODY_H
5587
5795
  };
5588
5796
  };
5797
+ /** Every solid of the vehicle: a rover's hull(), a ship's hull and its two wings. */
5798
+ var hulls = (r) => r.ship ? shipBodies(r) : [hull(r)];
5589
5799
  /**
5590
- * The map's rovers at rest on their spawns, nobody aboard, then its ships on their pads (ship.ts):
5591
- * the order of the snapshot's.
5800
+ * A rover's wreck skids to a stop where it blew up: before each of its steps with nobody at the
5801
+ * wheel it keeps VEHICLE.SKID of its speed along the ground. A ship's wreck falls as it flew.
5802
+ */
5803
+ var skid = (r) => {
5804
+ if (!r.ship) [r.vx, r.vz] = [f32(r.vx * VEHICLE.SKID), f32(r.vz * VEHICLE.SKID)];
5805
+ };
5806
+ /**
5807
+ * The vehicles' bodies as the step of `p` on foot meets them: every hull(), but for a player who
5808
+ * is down the wrecks' (his own vehicle's among them: he lies where it blew up, and no wreck that
5809
+ * moves under him bends his replay).
5810
+ */
5811
+ var solid = (rovers, p) => rovers.filter((r) => !(p.down && r.wreck)).flatMap(hulls);
5812
+ /**
5813
+ * The map's rovers at rest on their spawns, whole, nobody aboard, then its ships on their pads
5814
+ * (ship.ts): the order of the snapshot's.
5592
5815
  */
5593
5816
  var park = (w) => [...cars(w), ...dock(w.def.ships)];
5594
5817
  var cars = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
@@ -5606,9 +5829,65 @@ var cars = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
5606
5829
  wr: 0,
5607
5830
  steer: 0,
5608
5831
  driver: 255,
5609
- rider: 255
5832
+ rider: 255,
5833
+ hp: VEHICLE.HP,
5834
+ wreck: 0
5610
5835
  }));
5611
5836
  /**
5837
+ * The team whose base vehicle `k` of park() is parked at: of the rovers, then of the ships, the
5838
+ * first half are red's (the renderer paints them so).
5839
+ */
5840
+ var homeOf = (w, k) => {
5841
+ const [cars, ships] = [w.def.rovers?.length ?? 0, w.def.ships?.length ?? 0];
5842
+ return k < cars ? +(2 * k >= cars) : +(2 * (k - cars) >= ships);
5843
+ };
5844
+ /**
5845
+ * Where a shot from `o` along the unit `d` meets the vehicle's body within `m` metres: the
5846
+ * distance, or Infinity. A rover's body is its footprint()'s circles, BODY_H tall; a ship's is
5847
+ * ship.ts's spheres.
5848
+ */
5849
+ var struck = (r, o, d, m) => {
5850
+ if (r.ship) return struck$1(r, o, d, m);
5851
+ const t = min(...footprint(r).map(([x, y, z]) => cylinder(o, d, {
5852
+ x,
5853
+ y,
5854
+ z
5855
+ }, ROVER.RB, ROVER.BODY_H)));
5856
+ return t <= m ? t : Infinity;
5857
+ };
5858
+ /** The distance from `c` to the nearest point of the vehicle's body (struck()'s), 0 inside. */
5859
+ var reach = (r, c) => r.ship ? reach$1(r, c) : min(...footprint(r).map(([x, y, z]) => {
5860
+ const side = max(0, sqrt((c[0] - x) ** 2 + (c[2] - z) ** 2) - ROVER.RB);
5861
+ const up = max(0, y - c[1], c[1] - y - ROVER.BODY_H);
5862
+ return sqrt(side * side + up * up);
5863
+ }));
5864
+ /**
5865
+ * Whether a cut of `p` with this reach and arc (blade.ts's strike(), for a hull) meets the
5866
+ * vehicle: its hull() within reach of his centre on the floor plane, inside the arc round his look
5867
+ * (the hull's own angular radius counts), the heights overlapping and no brush before it.
5868
+ */
5869
+ var slashed = (w, r, p, { reach, arc }) => hulls(r).some((h) => cuts(w, h, p, reach, arc));
5870
+ /** Whether a cut of `p` with this reach and arc meets the body `h`. */
5871
+ var cuts = (w, h, p, reach, arc) => {
5872
+ const [dx, dz, y] = gapTo(h, p.x, p.z);
5873
+ const d = sqrt(dx * dx + dz * dz);
5874
+ const tall = heightOf(p);
5875
+ if (d - h.r > reach || p.y >= y + h.h || y >= p.y + tall) return false;
5876
+ const [fx, fz] = forward(p.yaw);
5877
+ const off = d > h.r ? abs(Math.atan2(fz * dx - fx * dz, -fx * dx - fz * dz)) : 0;
5878
+ const wide = d > h.r ? Math.asin(h.r / d) : Math.PI;
5879
+ const chest = p.y + .7 * tall;
5880
+ return off <= arc + wide && !hidden(w, [
5881
+ p.x,
5882
+ chest,
5883
+ p.z
5884
+ ], [
5885
+ p.x - dx,
5886
+ clamp(chest, y, y + h.h),
5887
+ p.z - dz
5888
+ ]);
5889
+ };
5890
+ /**
5612
5891
  * One step of 1 / TICK_HZ s, in place. `i` is the driver's input as the wire rounds it (FORWARD and
5613
5892
  * BACK the throttle, JUMP the handbrake, its yaw where the nose is steered to), or undefined with
5614
5893
  * nobody at the wheel: the brake is on. Reads only the rover, the input, the world and the
@@ -5621,8 +5900,8 @@ var cars = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
5621
5900
  * turns toward the look as fast as the speed allows, and the tyres' grip decides how much of the
5622
5901
  * speed follows it. The rest drifts.
5623
5902
  */
5624
- var drive = (r, i, w, fleet = []) => {
5625
- if (r.ship) return pilot(r, i, w);
5903
+ var drive = (r, i, w, fleet = [], crash) => {
5904
+ if (r.ship) return pilot(r, i, w, fleet.filter((o) => o !== r).flatMap(hulls), crash);
5626
5905
  const { A, B, CMAX, K, D, KP2, KR2, HC, MU, MUL, TILT } = ROVER;
5627
5906
  const g = gravity(w);
5628
5907
  const keys = i ? i.keys : 0;
@@ -5700,6 +5979,7 @@ var drive = (r, i, w, fleet = []) => {
5700
5979
  r.roll = clamp(r.roll + r.wr * DT, -TILT, TILT);
5701
5980
  if (abs(r.pitch) === TILT && r.pitch * r.wp > 0) r.wp = 0;
5702
5981
  if (abs(r.roll) === TILT && r.roll * r.wr > 0) r.wr = 0;
5982
+ const [vx0, vz0] = [r.vx, r.vz];
5703
5983
  for (const a of ROVER.BODY) {
5704
5984
  const [x, y, z] = at(r, a, 0, -DROP);
5705
5985
  const [px, pz] = shove({
@@ -5718,13 +5998,12 @@ var drive = (r, i, w, fleet = []) => {
5718
5998
  }
5719
5999
  for (const o of fleet) {
5720
6000
  if (o === r) continue;
5721
- const h = hull(o);
5722
- for (const a of ROVER.BODY) {
6001
+ for (const h of hulls(o)) for (const a of ROVER.BODY) {
5723
6002
  const [x, y, z] = at(r, a, 0, -DROP);
5724
6003
  const [dx, dz, oy] = gapTo(h, x, z);
5725
- const reach = 2 * ROVER.RB;
6004
+ const reach = ROVER.RB + h.r;
5726
6005
  const d = sqrt(dx * dx + dz * dz);
5727
- if (d >= reach - 1e-4 || oy >= y + ROVER.BODY_H || oy + ROVER.BODY_H <= y) continue;
6006
+ if (d >= reach - 1e-4 || oy >= y + ROVER.BODY_H || oy + h.h <= y) continue;
5728
6007
  const [ox, oz] = forward(o.yaw);
5729
6008
  const [nx, nz] = d ? [dx / d, dz / d] : [-oz, ox];
5730
6009
  r.x += nx * (reach - d);
@@ -5735,6 +6014,8 @@ var drive = (r, i, w, fleet = []) => {
5735
6014
  }
5736
6015
  }
5737
6016
  bound(r, w);
6017
+ const jolt = sqrt((r.vx - vx0) ** 2 + (r.vz - vz0) ** 2);
6018
+ if (crash && jolt > ROVER.CRASH) crash(jolt);
5738
6019
  for (const k of FLOATS) r[k] = f32(r[k]);
5739
6020
  return r.y < w.def.floor;
5740
6021
  };
@@ -5814,9 +6095,9 @@ var leave = (p, r, s, w) => {
5814
6095
  * that takes him off his seat (move() puts a body under the kill floor back at a spawn) frees it.
5815
6096
  * `fleet` is drive()'s.
5816
6097
  */
5817
- var ride = (p, r, i, w, team, fleet = []) => {
6098
+ var ride = (p, r, i, w, team, fleet = [], crash) => {
5818
6099
  const out = (i.keys & KEY.USE) !== 0 && (p.held & KEY.USE) === 0;
5819
- const fell = drive(r, i, w, fleet);
6100
+ const fell = drive(r, i, w, fleet, crash);
5820
6101
  step(p, i, w, team, false);
5821
6102
  if (p.mode !== MODE.RIDE) r.driver = 255;
5822
6103
  else {
@@ -5829,7 +6110,7 @@ var ride = (p, r, i, w, team, fleet = []) => {
5829
6110
  var gap2 = (r, p) => (r.x - p.x) ** 2 + (r.z - p.z) ** 2;
5830
6111
  /**
5831
6112
  * 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 ship that is gone has no seat.
6113
+ * within the reach in height (a ship's ENTER_H). A wreck has no seat.
5833
6114
  */
5834
6115
  var nearby = (r, p) => {
5835
6116
  const [k, h] = r.ship ? [SHIP.ENTER_R, SHIP.ENTER_H] : [ROVER.ENTER_R, ROVER.ENTER_R];
@@ -5842,19 +6123,34 @@ var nearby = (r, p) => {
5842
6123
  var free = (r, carrier) => r.driver === 255 && !carrier ? 0 : r.rider === 255 && !r.ship ? 1 : -1;
5843
6124
  /** Metres from the centre to where the lasers cross along the look: a ship's or a rover's. */
5844
6125
  var aimRange = (r) => r.ship ? SHIP.GUN_AIM : ROVER.GUN_AIM;
5845
- /** Where the lasers cross: aimRange() metres from the centre along the driver's look. */
5846
- var aimOf = (r, yaw, pitch) => {
6126
+ /**
6127
+ * Where the lasers cross: on what the driver's look meets within the guns' range (`sight`, the
6128
+ * user, 2026-11-12: with a cross at a fixed distance the two beams went either side of a rover
6129
+ * nearer than it), AIM_MIN at least; else aimRange() metres from the centre along the look.
6130
+ */
6131
+ var aimOf = (r, yaw, pitch, sight) => {
5847
6132
  const [sy, cy, sp, cp] = [
5848
6133
  Math.sin(yaw),
5849
6134
  Math.cos(yaw),
5850
6135
  Math.sin(pitch),
5851
6136
  Math.cos(pitch)
5852
6137
  ];
5853
- const k = aimRange(r);
6138
+ const d = [
6139
+ -sy * cp,
6140
+ sp,
6141
+ -cy * cp
6142
+ ];
6143
+ const far = r.ship ? SHIP.GUN_RANGE : ROVER.GUN_RANGE;
6144
+ const t = sight ? sight([
6145
+ r.x,
6146
+ r.y,
6147
+ r.z
6148
+ ], d, far) : Infinity;
6149
+ const k = t < far ? max(t, 8) : aimRange(r);
5854
6150
  return [
5855
- r.x - sy * cp * k,
5856
- r.y + sp * k,
5857
- r.z - cy * cp * k
6151
+ r.x + d[0] * k,
6152
+ r.y + d[1] * k,
6153
+ r.z + d[2] * k
5858
6154
  ];
5859
6155
  };
5860
6156
  /** A muzzle of the vehicle in the world: `m` is right of the centre, above it, ahead of it. */
@@ -5878,8 +6174,8 @@ var toward = (o, aim) => {
5878
6174
  * the point GUN_AIM metres along the driver's look (the yaw and pitch of his input) from the rover's
5879
6175
  * centre, so the beams cross there, chest high on level ground with a level look. `id` names the first, `id + 1` the second.
5880
6176
  */
5881
- var bolts = (r, by, team, yaw, pitch, id) => {
5882
- const aim = aimOf(r, yaw, pitch);
6177
+ var bolts = (r, by, team, yaw, pitch, id, sight) => {
6178
+ const aim = aimOf(r, yaw, pitch, sight);
5883
6179
  return (r.ship ? SHIP_GUNS : GUNS).map((m, k) => {
5884
6180
  const o = muzzle(r, m);
5885
6181
  const d = toward(o, aim);
@@ -5904,9 +6200,9 @@ var bolts = (r, by, team, yaw, pitch, id) => {
5904
6200
  * (plasma.ts's toss() flies it, blast() is its burst) launched at MISSILE_SPEED plus the ship's own
5905
6201
  * speed along the way, 63 m/s at most (the wire's six bits).
5906
6202
  */
5907
- var missile = (r, by, team, yaw, pitch, id, k) => {
6203
+ var missile = (r, by, team, yaw, pitch, id, k, sight) => {
5908
6204
  const o = muzzle(r, PODS[k]);
5909
- const d = toward(o, aimOf(r, yaw, pitch));
6205
+ const d = toward(o, aimOf(r, yaw, pitch, sight));
5910
6206
  const own = r.vx * d[0] + r.vy * d[1] + r.vz * d[2];
5911
6207
  return {
5912
6208
  id: id & 255,
@@ -5979,7 +6275,20 @@ var setEvery = (cb, ms) => {
5979
6275
  * A player on foot walks into the rovers as they stand when his input arrives (hull()); a rover
5980
6276
  * stops on the others as they stand when it steps.
5981
6277
  * seats() keeps the seats and the players' MODE.RIDE in step.
6278
+ * - A vehicle has VEHICLE.HP of health, the host's alone like a player's hp: every weapon takes
6279
+ * some from the hull of one that is not of the shooter's team (teamOf()), and a shot the hull
6280
+ * stops does not reach its crew. At 0 it blows up (wreck()): its crew goes down, a blast hurts
6281
+ * who is near, and its wreck lies VEHICLE.WRECK ticks, moved by the tick alone, before the
6282
+ * vehicle is parked afresh.
5982
6283
  */
6284
+ /** A vehicle parked afresh, for the host's own count of its damage. */
6285
+ var NEW = {
6286
+ graze: 0,
6287
+ sear: 0,
6288
+ burn: 0,
6289
+ by: 255,
6290
+ team: -1
6291
+ };
5983
6292
  /** A player out of any saber lock. */
5984
6293
  var FREE = {
5985
6294
  lock: 0,
@@ -6005,7 +6314,7 @@ var Room = class {
6005
6314
  /** Every connected peer; null until it joins. */
6006
6315
  peers = /* @__PURE__ */ new Map();
6007
6316
  ticks = 0;
6008
- /** The players as each snapshot of the last MAX_REWIND ticks sent them. */
6317
+ /** The players and the vehicles as each snapshot of the last MAX_REWIND ticks sent them. */
6009
6318
  history = [];
6010
6319
  world;
6011
6320
  ctf;
@@ -6018,9 +6327,11 @@ var Room = class {
6018
6327
  /** The plasma balls in flight, and the ones that burst since the last snapshot, which sends them once more. */
6019
6328
  balls = [];
6020
6329
  /** The map's rovers, in the order of WorldDef.rovers, then its ships (ship.ts). */
6021
- rovers;
6330
+ rovers = [];
6022
6331
  /** Ticks toward each ship's next missile, by index in `rovers`. */
6023
6332
  rearm = [];
6333
+ /** Each vehicle's damage short of a whole hp, by index in `rovers`. */
6334
+ wear = [];
6024
6335
  /** The key of the map being played, which the roster tells the clients. */
6025
6336
  mapName;
6026
6337
  /** The map the host picked for the next match, when it is another one. */
@@ -6037,7 +6348,13 @@ var Room = class {
6037
6348
  this.world = build(def ?? mapOf(this.mapName));
6038
6349
  this.ctf = new Ctf(this.world, this.rules);
6039
6350
  this.gone = this.spots();
6351
+ this.fresh();
6352
+ }
6353
+ /** Every vehicle of the map parked afresh: whole, empty, on its spawn. */
6354
+ fresh() {
6040
6355
  this.rovers = park(this.world);
6356
+ this.rearm = [];
6357
+ this.wear = this.rovers.map(() => ({ ...NEW }));
6041
6358
  }
6042
6359
  /** The health, ammo and cell packs of the map, all there (0 ticks before each is back). */
6043
6360
  spots() {
@@ -6060,7 +6377,7 @@ var Room = class {
6060
6377
  this.world = build(mapOf(this.mapName));
6061
6378
  this.ctf = new Ctf(this.world, this.rules);
6062
6379
  this.gone = this.spots();
6063
- this.rovers = park(this.world);
6380
+ this.fresh();
6064
6381
  this.history = [];
6065
6382
  this.balls = [];
6066
6383
  for (const p of this.players()) this.ctf.join(p.info.id, p.info.team, p.state);
@@ -6097,7 +6414,7 @@ var Room = class {
6097
6414
  const use = (input.keys & KEY.USE) !== 0 && (p.state.held & KEY.USE) === 0;
6098
6415
  const [r, s] = this.seatOf(p);
6099
6416
  if (r && !s) {
6100
- const fell = ride(p.state, r, input, this.world, p.info.team, this.rovers);
6417
+ const fell = ride(p.state, r, input, this.world, p.info.team, this.rovers, (j) => this.crash(r, j));
6101
6418
  this.ctf.moved(p.state);
6102
6419
  if (fell) this.sink(r);
6103
6420
  else {
@@ -6107,7 +6424,7 @@ var Room = class {
6107
6424
  this.lase(p, r, input);
6108
6425
  }
6109
6426
  } else {
6110
- const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over, this.rovers.map(hull));
6427
+ const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over, solid(this.rovers, p.state));
6111
6428
  this.ctf.moved(p.state);
6112
6429
  this.tackle(p, input.view);
6113
6430
  const here = spot(p.state);
@@ -6138,7 +6455,7 @@ var Room = class {
6138
6455
  if (!this.size) {
6139
6456
  this.ctf.reset();
6140
6457
  this.gone.fill(0);
6141
- this.rovers = park(this.world);
6458
+ this.fresh();
6142
6459
  this.load();
6143
6460
  }
6144
6461
  this.seats();
@@ -6185,14 +6502,21 @@ var Room = class {
6185
6502
  }
6186
6503
  this.seats();
6187
6504
  this.rovers.forEach((r, k) => this.dock(r, k));
6188
- for (const r of this.rovers) if (r.driver !== 255) this.carry(r);
6189
- else if (drive(r, void 0, this.world, this.rovers)) this.sink(r);
6190
- else this.carry(r);
6505
+ for (const r of this.rovers) {
6506
+ if (r.driver !== 255) {
6507
+ this.carry(r);
6508
+ continue;
6509
+ }
6510
+ if (r.wreck) skid(r);
6511
+ if (drive(r, void 0, this.world, this.rovers, (j) => this.crash(r, j))) this.sink(r);
6512
+ else this.carry(r);
6513
+ }
6191
6514
  this.seats();
6192
6515
  if (now % 2 === 0) {
6193
6516
  this.history.push({
6194
6517
  tick: now,
6195
- players: players.map((p) => ({ ...p.state }))
6518
+ players: players.map((p) => ({ ...p.state })),
6519
+ rovers: this.rovers.map((r) => ({ ...r }))
6196
6520
  });
6197
6521
  while (this.history[0].tick < now - 30) this.history.shift();
6198
6522
  const snap = encodeSnapshot({
@@ -6251,15 +6575,9 @@ var Room = class {
6251
6575
  /** Every player as the snapshots around the view tick `view` showed him: rewind(), the asker included. */
6252
6576
  past(view = 0) {
6253
6577
  const now = this.players().map((p) => p.state);
6254
- const [first, last] = [this.history[0], this.history.at(-1)];
6255
- if (!first || !last) return now;
6256
- const back = ((this.ticks - view + 32768) % 65536 + 65536) % 65536 - 32768;
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;
6578
+ const at = this.around(view);
6579
+ if (!at) return now;
6580
+ const [a, b, l] = at;
6263
6581
  return now.map((p) => {
6264
6582
  const pa = a.players.find((q) => q.id === p.id);
6265
6583
  const pb = b.players.find((q) => q.id === p.id);
@@ -6271,6 +6589,43 @@ var Room = class {
6271
6589
  } : pb ?? pa ?? p;
6272
6590
  });
6273
6591
  }
6592
+ /** The two kept snapshots around the view tick `view`, and the mix between them; nothing with no history. */
6593
+ around(view) {
6594
+ const [first, last] = [this.history[0], this.history.at(-1)];
6595
+ if (!first || !last) return;
6596
+ const back = ((this.ticks - view + 32768) % 65536 + 65536) % 65536 - 32768;
6597
+ const t = Math.min(Math.max(this.ticks - back, first.tick), last.tick);
6598
+ let k = 0;
6599
+ while (k + 1 < this.history.length && this.history[k + 1].tick <= t) k++;
6600
+ const [a, b] = [this.history[k], this.history[k + 1] ?? this.history[k]];
6601
+ const u = b.tick > a.tick ? (t - a.tick) / (b.tick - a.tick) : 0;
6602
+ return [
6603
+ a,
6604
+ b,
6605
+ (m, n) => m + (n - m) * u
6606
+ ];
6607
+ }
6608
+ /**
6609
+ * The vehicles a shooter of `team` may hurt, each with its index, as he drew them at the view
6610
+ * tick `view` (the place interpolated like a player's, the angles the later snapshot's); as
6611
+ * they are now with no `view`. For the katana and the rail gun, which strike where he saw.
6612
+ */
6613
+ hulls(team, view) {
6614
+ const at = view === void 0 ? void 0 : this.around(view);
6615
+ return this.targets(team).map((r) => {
6616
+ const k = this.rovers.indexOf(r);
6617
+ const [ra, rb] = [at?.[0].rovers[k], at?.[1].rovers[k]];
6618
+ if (!at || !ra || !rb || ra.wreck || rb.wreck) return [r, k];
6619
+ const l = at[2];
6620
+ return [{
6621
+ ...r,
6622
+ ...rb,
6623
+ x: l(ra.x, rb.x),
6624
+ y: l(ra.y, rb.y),
6625
+ z: l(ra.z, rb.z)
6626
+ }, k];
6627
+ });
6628
+ }
6274
6629
  /**
6275
6630
  * After a move of `p` at the view tick `view`: a dash or a slide that overlaps an enemy carrier
6276
6631
  * tackles him. The carrier is where `p` drew him (lag compensation), so a tackle that hit on
@@ -6360,9 +6715,9 @@ var Room = class {
6360
6715
  * Flies the ball `b` on by `m` metres: one that bursts on an enemy who is up takes its power in hp
6361
6716
  * from him, and counts a hit to its shooter. An arc takes its cut's hp; one it does not put down
6362
6717
  * 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: every enemy who is
6364
- * up, and its owner, lose what blast() gives where they stand now; one hit for the shooter when
6365
- * it hurt an enemy.
6718
+ * A grenade flies one tick of its arc whatever `m`, and its burst is a blast (boom()); one hit
6719
+ * for the shooter when it hurt an enemy or his vehicle. A ball an enemy vehicle's hull stops
6720
+ * (ram()) hurts the hull, not the crew behind it.
6366
6721
  */
6367
6722
  fly(b, m) {
6368
6723
  const peers = this.players();
@@ -6376,34 +6731,22 @@ var Room = class {
6376
6731
  if (b.power === 7) {
6377
6732
  toss(this.world, b, foes.map((f) => f.state));
6378
6733
  this.ram(b, o);
6379
- for (const r of b.burst ? this.targets(b.team) : []) {
6380
- const d = reach(r, [
6381
- b.x,
6382
- b.y,
6383
- b.z
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;
6734
+ if (b.burst && this.boom([
6735
+ b.x,
6736
+ b.y,
6737
+ b.z
6738
+ ], b.by, b.team) && by) by.state.hits = by.state.hits + 1 & 255;
6401
6739
  return;
6402
6740
  }
6403
6741
  const hit = fly(this.world, b, m, foes.map((f) => f.state));
6404
- const ship = this.ram(b, o);
6405
- if (ship) {
6406
- this.hurt(ship, b.power === 0 || b.power === 6 ? SHIP.BOLT_HP : SHIP.BALL_HP * (b.power ?? 1), by);
6742
+ const hull = this.ram(b, o);
6743
+ if (hull) {
6744
+ if (by) by.state.hits = by.state.hits + 1 & 255;
6745
+ if (b.power === 0 || b.power === 6) {
6746
+ const w = this.wear[this.rovers.indexOf(hull)];
6747
+ w.graze = (w.graze + 1) % VEHICLE.GRAZE;
6748
+ if (!w.graze) this.hurt(hull, 1, b.by, b.team);
6749
+ } else this.hurt(hull, b.arc ? CUTS[b.arc].hp : b.power ?? 1, b.by, b.team);
6407
6750
  return;
6408
6751
  }
6409
6752
  const foe = foes.find((q) => q.state === hit);
@@ -6438,7 +6781,8 @@ var Room = class {
6438
6781
  * (`strike`), and the `hits` count goes up once. Each takes the cut's hp; one it does not put
6439
6782
  * down is shocked: a stumble of SHOCK_TICKS thrown SHOCK_KNOCK m/s the way the blade throws him, with
6440
6783
  * `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`).
6784
+ * crosses where `p` drew him (`limbOf`). An enemy vehicle's hull the cut meets (slashed(), where
6785
+ * `p` drew it) takes the cut's hp, and its crew none of it.
6442
6786
  */
6443
6787
  cut(p, view) {
6444
6788
  if (!p.state.blade) {
@@ -6449,7 +6793,9 @@ var Room = class {
6449
6793
  this.shoot(p, view, wave(p.state, p.info.team));
6450
6794
  return;
6451
6795
  }
6452
- const seen = strike(this.world, p.state, this.enemies(p, view));
6796
+ const cars = this.hulls(p.info.team, view).filter(([r]) => slashed(this.world, r, p.state, swingOf(p.state)));
6797
+ const crew = cars.flatMap(([, k]) => SEATS.map((s) => this.rovers[k][s]));
6798
+ const seen = strike(this.world, p.state, this.enemies(p, view)).filter((s) => !crew.includes(s.id));
6453
6799
  let foes = this.players().filter((q) => seen.some((s) => s.id === q.info.id));
6454
6800
  const locked = foes.find((q) => crossing(p.state, {
6455
6801
  ...q.state,
@@ -6474,8 +6820,9 @@ var Room = class {
6474
6820
  }
6475
6821
  foes = foes.filter((q) => q !== locked);
6476
6822
  }
6477
- if (!foes.length) return;
6823
+ if (!foes.length && !cars.length) return;
6478
6824
  p.state.hits = p.state.hits + 1 & 255;
6825
+ for (const [, k] of cars) this.hurt(this.rovers[k], swingOf(p.state).hp, p.info.id, p.info.team);
6479
6826
  for (const foe of foes) {
6480
6827
  const drawn = seen.find((s) => s.id === foe.info.id);
6481
6828
  if (this.harm(foe, swingOf(p.state).hp)) foe.state.lost = limbOf(p.state, drawn);
@@ -6517,10 +6864,29 @@ var Room = class {
6517
6864
  /**
6518
6865
  * The rail gun's bolt of `p` at the view tick `view`: the first enemy it enters as `p` drew him is
6519
6866
  * drained for RAIL_TICKS more (`slow`). A first touch, when he was not drained, takes 1 hp at once
6520
- * and counts a hit.
6867
+ * and counts a hit. An enemy vehicle's hull is drained the same way, and shields who is behind it.
6521
6868
  */
6522
6869
  rail(p, view) {
6523
- const { hit } = beam(this.world, p.state, this.enemies(p, view));
6870
+ const { o, d, t, hit } = beam(this.world, p.state, this.enemies(p, view));
6871
+ const [s, k] = this.hulls(p.info.team, view).reduce((best, [r, n]) => {
6872
+ const u = struck(r, o, d, best[0]);
6873
+ return u < best[0] ? [u, n] : best;
6874
+ }, [t, -1]);
6875
+ if (s < t) {
6876
+ const w = this.wear[k];
6877
+ const fresh = !w.sear;
6878
+ Object.assign(w, {
6879
+ sear: 180,
6880
+ by: p.info.id,
6881
+ team: p.info.team
6882
+ });
6883
+ if (fresh) {
6884
+ p.state.hits = p.state.hits + 1 & 255;
6885
+ w.burn = 0;
6886
+ this.hurt(this.rovers[k], 1, p.info.id, p.info.team);
6887
+ }
6888
+ return;
6889
+ }
6524
6890
  const foe = this.players().find((q) => q.info.id === hit?.id);
6525
6891
  if (foe) {
6526
6892
  const fresh = !foe.state.slow;
@@ -6630,7 +6996,7 @@ var Room = class {
6630
6996
  * respawned or stumbled out is off the rover.
6631
6997
  */
6632
6998
  /**
6633
- * The first enemy ship on the way the ball `b` flew this tick, from `o` to where it is now: the
6999
+ * The first enemy vehicle on the way the ball `b` flew this tick, from `o` to where it is now: the
6634
7000
  * ball bursts on its hull, short of a body or a wall further on.
6635
7001
  */
6636
7002
  ram(b, o) {
@@ -6699,8 +7065,13 @@ var Room = class {
6699
7065
  respawn(p.state, this.world, p.info.team);
6700
7066
  this.ctf.moved(p.state);
6701
7067
  }
6702
- const k = this.rovers.indexOf(r);
6703
- Object.assign(r, park(this.world)[k]);
7068
+ this.renew(this.rovers.indexOf(r));
7069
+ }
7070
+ /** Vehicle `k` parked afresh on its spawn: whole, empty. */
7071
+ renew(k) {
7072
+ Object.assign(this.rovers[k], park(this.world)[k]);
7073
+ this.rearm[k] = 0;
7074
+ this.wear[k] = { ...NEW };
6704
7075
  }
6705
7076
  /**
6706
7077
  * After a step of the driver `p` at the view tick `view`: the rover's body (footprint()) over an
@@ -6717,7 +7088,7 @@ var Room = class {
6717
7088
  if (!(i.keys & KEY.FIRE) || p.gun || this.ctf.over || p.state.mode !== MODE.RIDE) return;
6718
7089
  p.gun = r.ship ? SHIP.GUN_COOL : ROVER.GUN_COOL;
6719
7090
  p.bolt = (p.bolt ?? 0) + 2 & 255;
6720
- for (const b of bolts(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt)) this.shoot(p, i.view, b);
7091
+ for (const b of bolts(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt, this.sight(p, i))) this.shoot(p, i.view, b);
6721
7092
  }
6722
7093
  /**
6723
7094
  * A ship's missiles: while its pilot holds SPECIAL (G), one each SHIP.MISSILE_COOL of his inputs
@@ -6731,47 +7102,117 @@ var Room = class {
6731
7102
  p.side = (p.side ?? 0) ^ 1;
6732
7103
  r.nades--;
6733
7104
  p.bolt = (p.bolt ?? 0) + 1 & 255;
6734
- this.shoot(p, i.view, missile(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt, p.side));
7105
+ this.shoot(p, i.view, missile(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt, p.side, this.sight(p, i)));
6735
7106
  }
6736
7107
  /**
6737
- * A ship's clock outside its pilot's inputs: one that is gone comes back on its pad, new, after
6738
- * SHIP.WRECK ticks; one short of missiles loads one each SHIP.RELOAD ticks.
7108
+ * What the look of the driver `p` meets for his guns' aim (aimOf()): a brush, an enemy vehicle's
7109
+ * hull where it is, or an enemy on foot who is up as `p` drew him at the input's view tick.
7110
+ */
7111
+ sight(p, i) {
7112
+ const foes = new Set(this.players().filter((q) => q.info.team !== p.info.team).map((q) => q.info.id));
7113
+ const drawn = this.past(i.view).filter((q) => foes.has(q.id) && !q.down && q.mode !== MODE.RIDE);
7114
+ const hulls = this.targets(p.info.team);
7115
+ return (o, d, m) => Math.min(ray(this.world, o, d, m), ...hulls.map((v) => struck(v, o, d, m)), ...drawn.map((q) => cylinder(o, d, q, PLAYER_R, heightOf(q))));
7116
+ }
7117
+ /**
7118
+ * A vehicle's clock outside its driver's inputs: a wreck is parked afresh after VEHICLE.WRECK
7119
+ * ticks; a hull the rail gun's bolt sears loses 1 hp each RAIL_DRAIN ticks after its first touch;
7120
+ * a ship short of missiles loads one each SHIP.RELOAD ticks.
6739
7121
  */
6740
7122
  dock(r, k) {
6741
- if (!r.ship) return;
6742
7123
  if (r.wreck) {
6743
- if (!--r.wreck) {
6744
- Object.assign(r, park(this.world)[k]);
6745
- this.rearm[k] = 0;
6746
- }
7124
+ if (!--r.wreck) this.renew(k);
6747
7125
  return;
6748
7126
  }
7127
+ const w = this.wear[k];
7128
+ if (w.sear) {
7129
+ w.sear--;
7130
+ if (!(++w.burn % 60)) this.hurt(r, 1, w.by, w.team);
7131
+ }
7132
+ if (!r.ship || r.wreck) return;
6749
7133
  this.rearm[k] = (r.nades ?? 0) < SHIP.MISSILES ? (this.rearm[k] ?? 0) + 1 : 0;
6750
7134
  if (this.rearm[k] >= SHIP.RELOAD) {
6751
7135
  r.nades = (r.nades ?? 0) + 1;
6752
7136
  this.rearm[k] = 0;
6753
7137
  }
6754
7138
  }
6755
- /** The ships an enemy of `team` pilots and that are there to hit. */
7139
+ /** The team a vehicle is of: its driver's, else its rider's, else the one whose base it is parked at. */
7140
+ teamOf(r) {
7141
+ const who = this.players().find((p) => p.info.id === (r.driver === 255 ? r.rider : r.driver));
7142
+ return who ? who.info.team : homeOf(this.world, this.rovers.indexOf(r));
7143
+ }
7144
+ /** The vehicles a shooter of `team` hurts: whole, and not of his team. */
6756
7145
  targets(team) {
6757
- const by = new Map(this.players().map((p) => [p.info.id, p.info.team]));
6758
- return this.rovers.filter((r) => r.ship && !r.wreck && r.driver !== 255 && by.get(r.driver) !== team);
7146
+ return this.rovers.filter((r) => !r.wreck && this.teamOf(r) !== team);
6759
7147
  }
6760
7148
  /**
6761
- * The ship `r` loses `hp` of armour to the shot of `by`; at 0 it blows up where it is: its pilot
6762
- * goes down with it, and it is gone SHIP.WRECK ticks.
7149
+ * A vehicle that crashed with a jolt of `jolt` m/s: a ship into a brush, the ground or another
7150
+ * vehicle (pilot()), a rover into a wall or a vehicle (drive()). 1 hp each CRASH_HP past CRASH
7151
+ * (SHIP's, ROVER's), nobody's shot; at 0 it blows up as its team's, so its blast spares its mates.
6763
7152
  */
6764
- hurt(r, hp, by) {
6765
- if (by) by.state.hits = by.state.hits + 1 & 255;
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);
7153
+ crash(r, jolt) {
7154
+ const [from, per] = r.ship ? [SHIP.CRASH, SHIP.CRASH_HP] : [ROVER.CRASH, ROVER.CRASH_HP];
7155
+ this.hurt(r, Math.ceil((jolt - from) / per), 255, this.teamOf(r));
7156
+ }
7157
+ /** The vehicle `r` loses `hp` to player `by` of `team`; at 0 it blows up (wreck()). */
7158
+ hurt(r, hp, by, team) {
7159
+ if (r.wreck) return;
7160
+ r.hp = Math.max(0, (r.hp ?? VEHICLE.HP) - hp);
7161
+ if (!r.hp) this.wreck(r, by, team);
7162
+ }
7163
+ /**
7164
+ * The vehicle blows up where it is, by the hand of player `by` of `team`: who is aboard goes
7165
+ * down on the spot, and it is a wreck for VEHICLE.WRECK ticks, with no seat, moved by the tick
7166
+ * alone. Its blast is a grenade of `by` at its centre (boom()).
7167
+ */
7168
+ wreck(r, by, team) {
7169
+ const crew = this.players().filter((q) => this.seatOf(q)[0] === r);
6769
7170
  Object.assign(r, {
6770
- wreck: SHIP.WRECK,
7171
+ hp: 0,
7172
+ wreck: VEHICLE.WRECK,
6771
7173
  driver: 255,
6772
- rider: 255,
6773
- nades: 0
7174
+ rider: 255
6774
7175
  });
7176
+ if (r.ship) r.nades = 0;
7177
+ this.wear[this.rovers.indexOf(r)] = { ...NEW };
7178
+ for (const q of crew) this.harm(q, q.state.hp);
7179
+ const hit = this.boom([
7180
+ r.x,
7181
+ r.y,
7182
+ r.z
7183
+ ], by, team);
7184
+ const killer = this.players().find((q) => q.info.id === by);
7185
+ if (killer && (hit || crew.length)) killer.state.hits = killer.state.hits + 1 & 255;
7186
+ }
7187
+ /**
7188
+ * A blast at `c`, the grenade's rule, of player `by` of `team`: every enemy on foot who is up,
7189
+ * and `by` himself, lose what blast() gives where they stand now; every enemy vehicle loses
7190
+ * NADE_HP at its hull, less with the distance to it, nothing from NADE_R on or behind a brush.
7191
+ * Who is seated is behind his hull: the blast takes nothing from him. True when it hurt an enemy
7192
+ * or his vehicle.
7193
+ */
7194
+ boom(c, by, team) {
7195
+ let hit = false;
7196
+ for (const r of this.targets(team)) {
7197
+ const d = reach(r, c);
7198
+ if (d < 5 && !hidden(this.world, c, [
7199
+ r.x,
7200
+ r.y,
7201
+ r.z
7202
+ ])) {
7203
+ this.hurt(r, Math.ceil(5 * (1 - d / 5)), by, team);
7204
+ hit = true;
7205
+ }
7206
+ }
7207
+ for (const q of this.players()) {
7208
+ const own = q.info.id === by;
7209
+ const hp = !q.state.down && q.state.mode !== MODE.RIDE && (own || q.info.team !== team) ? blast(this.world, c, q.state) : 0;
7210
+ if (hp) {
7211
+ this.harm(q, hp);
7212
+ hit ||= !own;
7213
+ }
7214
+ }
7215
+ return hit;
6775
7216
  }
6776
7217
  splat(p, r, view) {
6777
7218
  if (len(r.vx, r.vz) < ROVER.SPLAT_MIN) return;
@@ -6824,7 +7265,7 @@ var Room = class {
6824
7265
  const put = [];
6825
7266
  this.rr = [0, 0];
6826
7267
  this.gone.fill(0);
6827
- this.rovers = park(this.world);
7268
+ this.fresh();
6828
7269
  shut(this.world);
6829
7270
  for (const p of players) {
6830
7271
  const { shots, hits } = p.state;