@korial29/tiny-fps 0.145.1 → 0.146.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
@@ -788,7 +788,8 @@ var STILL = {
788
788
  coyote: 6,
789
789
  buffer: 0,
790
790
  held: 0,
791
- hp: 5,
791
+ hp: 8,
792
+ armor: 0,
792
793
  ammo: -1,
793
794
  cool: 0,
794
795
  mag: 0,
@@ -2608,6 +2609,23 @@ var HIGHLINE = {
2608
2609
  ZED$1 / 2
2609
2610
  ]
2610
2611
  ],
2612
+ vests: [
2613
+ [
2614
+ 36,
2615
+ 17.2,
2616
+ ZED$1 / 2
2617
+ ],
2618
+ [
2619
+ 23,
2620
+ 26,
2621
+ 136
2622
+ ],
2623
+ [
2624
+ 23,
2625
+ 26,
2626
+ 104
2627
+ ]
2628
+ ],
2611
2629
  floor: -25,
2612
2630
  sun: {
2613
2631
  dir: [
@@ -4210,6 +4228,15 @@ var MOON = {
4210
4228
  0,
4211
4229
  140
4212
4230
  ]),
4231
+ vests: both([[
4232
+ 107,
4233
+ 5,
4234
+ 200
4235
+ ]], [
4236
+ 132.5,
4237
+ 2.4,
4238
+ 140
4239
+ ]),
4213
4240
  floor: -26,
4214
4241
  relief: {
4215
4242
  hole: [
@@ -6345,16 +6372,16 @@ var encodeSnapshot = (s) => {
6345
6372
  v.setUint8(o + 37, p.dash | (p.by >> 2 & 3) << 6);
6346
6373
  v.setUint8(o + 38, p.coyote & 7 | (p.buffer & 7) << 3 | (p.held & KEY.JUMP ? 64 : 0) | (p.held & KEY.DASH ? 128 : 0));
6347
6374
  v.setUint8(o + 39, p.stun | (p.by & 3) << 6);
6348
- const gun = p.hp | (p.cool & 7) << 3 | (p.ammo < 0 ? NO_GUN : p.ammo) << 6 | p.down << 13 | +!!p.rack << 20 | +!!p.blade << 21 | +!!p.wield << 22 | +!!p.zap << 23;
6375
+ const gun = p.hp & 7 | (p.cool & 7) << 3 | (p.ammo < 0 ? NO_GUN : p.ammo) << 6 | p.down << 13 | +!!p.rack << 20 | +!!p.blade << 21 | +!!p.wield << 22 | +!!p.zap << 23;
6349
6376
  v.setUint8(o + 40, gun >> 16);
6350
6377
  v.setUint16(o + 41, gun & 65535);
6351
6378
  v.setUint8(o + 43, p.shots);
6352
6379
  v.setUint8(o + 44, p.hits);
6353
6380
  v.setUint8(o + 45, (p.swing ?? 0) & 63 | ((p.cut ?? 0) & 3) << 6);
6354
- v.setUint8(o + 46, (p.lost ?? 0) & 7 | ((p.cut ?? 0) & 4) << 1 | (p.fried ? 16 : 0) | (p.heavy ? 32 : 0));
6381
+ v.setUint8(o + 46, (p.lost ?? 0) & 7 | ((p.cut ?? 0) & 4) << 1 | (p.fried ? 16 : 0) | (p.heavy ? 32 : 0) | (p.armor ?? 0) << 6);
6355
6382
  v.setUint8(o + 47, p.down ? p.fell ?? 0 : p.charge ?? 0);
6356
6383
  v.setUint8(o + 48, p.lock ?? 0);
6357
- v.setUint8(o + 49, (p.foe ?? 0) & 15 | (p.dashes & 2) << 3 | (p.pressed ? 128 : 0));
6384
+ v.setUint8(o + 49, (p.foe ?? 0) & 15 | (p.dashes & 2) << 3 | (p.hp & 8) << 2 | (p.pressed ? 128 : 0));
6358
6385
  v.setUint8(o + 50, p.pushes ?? 0);
6359
6386
  v.setUint8(o + 51, p.away ?? 0);
6360
6387
  v.setUint8(o + 52, (p.rail ?? -1) + 1);
@@ -7795,13 +7822,14 @@ var Room = class {
7795
7822
  this.rearm = [];
7796
7823
  this.wear = this.rovers.map(() => ({ ...NEW }));
7797
7824
  }
7798
- /** The health, ammo and cell packs of the map, all there (0 ticks before each is back). */
7825
+ /** The health, ammo and cell packs and the armours of the map, all there (0 ticks before each is back). */
7799
7826
  spots() {
7800
- const { packs = [], ammo = [], cells = [] } = this.world.def;
7827
+ const { packs = [], ammo = [], cells = [], vests = [] } = this.world.def;
7801
7828
  return [
7802
7829
  ...packs,
7803
7830
  ...ammo,
7804
- ...cells
7831
+ ...cells,
7832
+ ...vests
7805
7833
  ].map(() => 0);
7806
7834
  }
7807
7835
  /** The host: the player in the room the longest. */
@@ -8128,13 +8156,15 @@ var Room = class {
8128
8156
  return bank >= 2 && this.harm(foe, Math.floor(bank / 2), by, how, felled(FALL$1.SHOT, dx, dz));
8129
8157
  }
8130
8158
  /**
8131
- * `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
8132
- * the katana, a flag he carries drops with the lock, and `lost` is NONE (a cut sets it after).
8133
- * True when he went down: an enemy `by` scores a frag made `how` (FRAG), told to everyone. `fell`
8134
- * is how he falls (felled()).
8159
+ * `hp` of damage to `foe`, his armour taking it first (Infinity goes through it); the last one
8160
+ * puts him down: he lies where he fell, without the gun, the katana or armour, a flag he carries
8161
+ * drops with the lock, and `lost` is NONE (a cut sets it after). True when he went down: an enemy
8162
+ * `by` scores a frag made `how` (FRAG), told to everyone. `fell` is how he falls (felled()).
8135
8163
  */
8136
8164
  harm(foe, hp, by, how = FRAG.GUN, fell = 0) {
8137
- if ((foe.state.hp -= hp) > 0) return false;
8165
+ const armor = foe.state.armor ?? 0;
8166
+ foe.state.armor = Math.max(0, armor - hp);
8167
+ if ((foe.state.hp -= Math.max(0, hp - armor)) > 0) return false;
8138
8168
  [foe.graze, foe.bruise, foe.blows, foe.halves] = [
8139
8169
  0,
8140
8170
  0,
@@ -8144,6 +8174,7 @@ var Room = class {
8144
8174
  if (foe.state.mode === MODE.RIDE) this.unseat(foe);
8145
8175
  Object.assign(foe.state, {
8146
8176
  hp: 0,
8177
+ armor: 0,
8147
8178
  down: 120,
8148
8179
  ammo: -1,
8149
8180
  cool: 0,
@@ -8427,42 +8458,51 @@ var Room = class {
8427
8458
  }
8428
8459
  }
8429
8460
  /**
8430
- * The packs, health ones first, then the ammo ones, then the rail cells: one that is gone comes
8431
- * back after PACK_BACK s, an ammo pack after AMMO_BACK s. A health pack goes to a hurt player standing at it, an ammo pack to one
8461
+ * The packs, health ones first, then the ammo ones, then the rail cells, then the armours: one
8462
+ * that is gone comes back after PACK_BACK s, an ammo pack after AMMO_BACK s, an armour after
8463
+ * ARMOR_BACK s. A health pack goes to a hurt player standing at it, an ammo pack to one
8432
8464
  * with the gun short of AMMO_MAX or the laser rifle short of RIFLE_MAX (RIFLE_CLIP more rounds), a rail cell to one with the rail gun and less than
8433
- * RAIL_MAX of lightning. Both change the state between two inputs, like a hit: the snapshot
8465
+ * RAIL_MAX of lightning, an armour to one short of ARMOR_MAX. All change the state between two inputs, like a hit: the snapshot
8434
8466
  * carries the result and the predictor replays its unacked inputs on it.
8435
8467
  */
8436
8468
  heal(players) {
8437
- const { packs = [], ammo = [], cells = [] } = this.world.def;
8469
+ const { packs = [], ammo = [], cells = [], vests = [] } = this.world.def;
8438
8470
  [
8439
8471
  ...packs,
8440
8472
  ...ammo,
8441
- ...cells
8473
+ ...cells,
8474
+ ...vests
8442
8475
  ].forEach((at, k) => {
8443
8476
  if (this.gone[k] > 0) {
8444
8477
  this.gone[k]--;
8445
8478
  return;
8446
8479
  }
8447
- const kind = +(k >= packs.length) + +(k >= packs.length + ammo.length);
8480
+ const kind = +(k >= packs.length) + +(k >= packs.length + ammo.length) + +(k >= packs.length + ammo.length + cells.length);
8448
8481
  const wants = ({ state: q, info }) => {
8449
8482
  const kit = kitOf(info.role, this.world.def);
8450
8483
  return [
8451
- q.hp < 5,
8484
+ q.hp < 8,
8452
8485
  q.ammo >= 0 && q.ammo < kit.ammo || (q.rifle ?? -1) >= 0 && q.rifle < kit.rifle,
8453
- (q.rail ?? -1) >= 0 && q.rail < kit.rail
8486
+ (q.rail ?? -1) >= 0 && q.rail < kit.rail,
8487
+ (q.armor ?? 0) < 3
8454
8488
  ][kind];
8455
8489
  };
8456
8490
  const p = players.find((o) => !o.state.down && wants(o) && within(o.state, at, .9));
8457
8491
  if (p) {
8458
8492
  const q = p.state;
8459
8493
  const kit = kitOf(p.info.role, this.world.def);
8460
- if (kind == 0) q.hp = Math.min(5, q.hp + 2);
8494
+ if (kind == 0) q.hp = Math.min(8, q.hp + 2);
8461
8495
  else if (kind == 1) {
8462
8496
  q.ammo = q.ammo < 0 ? -1 : Math.min(kit.ammo, q.ammo + 20);
8463
8497
  q.rifle = (q.rifle ?? -1) < 0 ? -1 : Math.min(kit.rifle, q.rifle + 60);
8464
- } else q.rail = Math.min(kit.rail, q.rail + 80);
8465
- this.gone[k] = (kind == 1 ? 10 : 20) * 60;
8498
+ } else if (kind == 2) q.rail = Math.min(kit.rail, q.rail + 80);
8499
+ else q.armor = 3;
8500
+ this.gone[k] = [
8501
+ 20,
8502
+ 10,
8503
+ 20,
8504
+ 10
8505
+ ][kind] * 60;
8466
8506
  }
8467
8507
  });
8468
8508
  }
@@ -8669,7 +8709,7 @@ var Room = class {
8669
8709
  if (r.ship) r.nades = 0;
8670
8710
  this.wear[this.rovers.indexOf(r)] = { ...NEW };
8671
8711
  const killer = this.players().find((q) => q.info.id === by);
8672
- for (const q of crew) this.harm(q, q.state.hp, killer, FRAG.VEHICLE);
8712
+ for (const q of crew) this.harm(q, Infinity, killer, FRAG.VEHICLE);
8673
8713
  const hit = this.boom([
8674
8714
  r.x,
8675
8715
  r.y,
@@ -8721,7 +8761,7 @@ var Room = class {
8721
8761
  foe.run = this.ticks;
8722
8762
  p.state.hits = p.state.hits + 1 & 255;
8723
8763
  const fell = felled(FALL$1.SHOT, r.vx, r.vz);
8724
- const hp = closing < ROVER.SPLAT_KILL ? 1 : foe.state.hp;
8764
+ const hp = closing < ROVER.SPLAT_KILL ? 1 : Infinity;
8725
8765
  if (!this.harm(foe, hp, p, FRAG.VEHICLE, fell)) {
8726
8766
  const v = len(r.vx, r.vz);
8727
8767
  stumble(foe.state, r.vx / v, r.vz / v);
@@ -41,6 +41,8 @@ export interface CtfScene {
41
41
  ammo?: readonly Vec3[];
42
42
  /** The rail cells that are there to take. */
43
43
  cells?: readonly Vec3[];
44
+ /** The armours that are there to take. */
45
+ vests?: readonly Vec3[];
44
46
  }
45
47
  /** The flags to draw from a snapshot: each at its base, where it lies, or on the back of its carrier (none if he is not drawn). */
46
48
  export declare const flagDraws: (flags: readonly FlagState[], bases: readonly Vec3[], who: (id: number) => PlayerState | undefined) => FlagDraw[];
@@ -85,9 +85,10 @@ export interface Hud {
85
85
  * holds, in the same count: big, with the rest after it as the magazines it makes (an open one for
86
86
  * a part) over its count; faded while `swapping` it. `rifle` is the
87
87
  * laser rifle's rounds (-1 none), shown with the glyph in red when `rifled` (slot 4), with the
88
- * `nades` left in its launcher as dots after the count, hollow for the ones spent.
88
+ * `nades` left in its launcher as dots after the count, hollow for the ones spent. `armor` shows
89
+ * as gold pips after the health's, only the ones he has.
89
90
  */
90
- vitals(hp: number, ammo: number, blade?: boolean, wield?: boolean, rail?: number, railed?: boolean, loaded?: number, swapping?: boolean, rifle?: number, rifled?: boolean, nades?: number): void;
91
+ vitals(hp: number, ammo: number, blade?: boolean, wield?: boolean, rail?: number, railed?: boolean, loaded?: number, swapping?: boolean, rifle?: number, rifled?: boolean, nades?: number, armor?: number): void;
91
92
  /** A hit marker on the crosshair for a moment: a ball or a cut of the own player hit. */
92
93
  hit(): void;
93
94
  /** The face over the health, frame `n` of face.ts (-1 hides it). */
@@ -19,3 +19,5 @@ export declare const kit: (out: Out, at: Vec3, t: number) => void;
19
19
  export declare const cell: (out: Out, at: Vec3, t: number) => void;
20
20
  /** A rail cell at `at`: a gunmetal box with a glowing violet-white bolt on each side, the rail gun's colours. */
21
21
  export declare const battery: (out: Out, at: Vec3, t: number) => void;
22
+ /** An armour at `at`: a bigger steel box with a glowing gold shield on each side. */
23
+ export declare const vest: (out: Out, at: Vec3, t: number) => void;
@@ -166,8 +166,15 @@ export declare const FLAG_REACH = 1.5;
166
166
  export declare const FLAG_H = 2.2;
167
167
  /** Seconds a dropped flag lies before it goes home by itself. */
168
168
  export declare const FLAG_RETURN = 10;
169
- /** Health of a player; a hit takes 1, so HP_MAX hits put him down. */
170
- export declare const HP_MAX = 5;
169
+ /** Health of a player; a hit takes 1, so HP_MAX hits put him down (8 since the user, 2026-11-14: 5 before). */
170
+ export declare const HP_MAX = 8;
171
+ /**
172
+ * Armour (the user, 2026-11-14): points on top of the health, spent first, 1 per point of damage.
173
+ * An armour pickup (WorldDef.armor) fills it to ARMOR_MAX for a player short of it, then it is
174
+ * gone ARMOR_BACK s. Going down loses it; a spawn starts without.
175
+ */
176
+ export declare const ARMOR_MAX = 3;
177
+ export declare const ARMOR_BACK = 10;
171
178
  /**
172
179
  * Fall damage (the user, 2026-11-13): a landing faster than FALL_SAFE m/s (a 10 m drop at full
173
180
  * gravity; Highline's routes land at 18.4 at most) takes 1 hp, and 1 more each FALL_HP m/s past it.
@@ -264,7 +271,7 @@ export declare const PACK_BACK = 20;
264
271
  /** Shots an ammo pack gives, up to AMMO_MAX, and seconds before a taken one is back. */
265
272
  export declare const AMMO_PACK = 20;
266
273
  export declare const AMMO_BACK = 10;
267
- /** Health packs, ammo packs and rail cells a map has at most: the bits of Snapshot.packs. */
274
+ /** Health packs, ammo packs, rail cells and armours a map has at most: the bits of Snapshot.packs. */
268
275
  export declare const PACK_BITS = 48;
269
276
  /** Metres from a pack or a rack, feet to point on the floor plane, that take it. */
270
277
  export declare const PACK_R = 0.9;
@@ -23,6 +23,7 @@ export declare const STILL: {
23
23
  buffer: number;
24
24
  held: number;
25
25
  hp: number;
26
+ armor: number;
26
27
  ammo: number;
27
28
  cool: number;
28
29
  mag: number;
@@ -39,7 +39,7 @@ export declare class Room {
39
39
  constructor(rules?: Partial<Rules>, def?: WorldDef);
40
40
  /** Every vehicle of the map parked afresh: whole, empty, on its spawn. */
41
41
  private fresh;
42
- /** The health, ammo and cell packs of the map, all there (0 ticks before each is back). */
42
+ /** The health, ammo and cell packs and the armours of the map, all there (0 ticks before each is back). */
43
43
  private spots;
44
44
  /** The host: the player in the room the longest. */
45
45
  private host;
@@ -107,10 +107,10 @@ export declare class Room {
107
107
  */
108
108
  private shot;
109
109
  /**
110
- * `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
111
- * the katana, a flag he carries drops with the lock, and `lost` is NONE (a cut sets it after).
112
- * True when he went down: an enemy `by` scores a frag made `how` (FRAG), told to everyone. `fell`
113
- * is how he falls (felled()).
110
+ * `hp` of damage to `foe`, his armour taking it first (Infinity goes through it); the last one
111
+ * puts him down: he lies where he fell, without the gun, the katana or armour, a flag he carries
112
+ * drops with the lock, and `lost` is NONE (a cut sets it after). True when he went down: an enemy
113
+ * `by` scores a frag made `how` (FRAG), told to everyone. `fell` is how he falls (felled()).
114
114
  */
115
115
  private harm;
116
116
  /**
@@ -163,10 +163,11 @@ export declare class Room {
163
163
  */
164
164
  private duel;
165
165
  /**
166
- * The packs, health ones first, then the ammo ones, then the rail cells: one that is gone comes
167
- * back after PACK_BACK s, an ammo pack after AMMO_BACK s. A health pack goes to a hurt player standing at it, an ammo pack to one
166
+ * The packs, health ones first, then the ammo ones, then the rail cells, then the armours: one
167
+ * that is gone comes back after PACK_BACK s, an ammo pack after AMMO_BACK s, an armour after
168
+ * ARMOR_BACK s. A health pack goes to a hurt player standing at it, an ammo pack to one
168
169
  * with the gun short of AMMO_MAX or the laser rifle short of RIFLE_MAX (RIFLE_CLIP more rounds), a rail cell to one with the rail gun and less than
169
- * RAIL_MAX of lightning. Both change the state between two inputs, like a hit: the snapshot
170
+ * RAIL_MAX of lightning, an armour to one short of ARMOR_MAX. All change the state between two inputs, like a hit: the snapshot
170
171
  * carries the result and the predictor replays its unacked inputs on it.
171
172
  */
172
173
  private heal;
@@ -222,6 +222,8 @@ export interface PlayerState {
222
222
  held: number;
223
223
  /** Health, 0 to HP_MAX. */
224
224
  hp: number;
225
+ /** Armour, 0 to ARMOR_MAX, spent before the health; the host's alone, like hp. Absent: none. */
226
+ armor?: number;
225
227
  /** Shots left in the gun; -1 without the gun (taken at the team's rack, lost on death). */
226
228
  ammo: number;
227
229
  /** Ticks to the next shot. */
@@ -421,8 +423,8 @@ export interface Snapshot {
421
423
  flags: [FlagState, FlagState];
422
424
  /**
423
425
  * Bit n set: pack n is there to take, the health packs of WorldDef.packs first, then the ammo
424
- * packs of WorldDef.ammo (bit packs.length + n), then the rail cells of WorldDef.cells (after
425
- * both). PACK_BITS bits, past the 32 of the bitwise operators: read a bit with arithmetic.
426
+ * packs of WorldDef.ammo (bit packs.length + n), then the rail cells of WorldDef.cells, then the
427
+ * armours of WorldDef.vests. PACK_BITS bits, past the 32 of the bitwise operators: read a bit with arithmetic.
426
428
  * Absent: none.
427
429
  */
428
430
  packs?: number;
@@ -52,6 +52,8 @@ export interface WorldDef {
52
52
  ammo?: Vec3[];
53
53
  /** Rail cells, points on tops (with the health and ammo packs at most PACK_BITS): within PACK_R a player with the rail gun and less than RAIL_MAX of lightning takes RAIL_CELL, then it is gone PACK_BACK seconds. */
54
54
  cells?: Vec3[];
55
+ /** Armours, points on tops (with the packs and the cells at most PACK_BITS): within PACK_R a player short of ARMOR_MAX is filled to it, then it is gone ARMOR_BACK seconds. */
56
+ vests?: Vec3[];
55
57
  /** Unit direction toward the sun, and its colour (linear RGB, may exceed 1). */
56
58
  sun: {
57
59
  dir: Vec3;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@korial29/tiny-fps",
3
3
  "description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
4
4
  "license": "Apache-2.0",
5
- "version": "0.145.1",
5
+ "version": "0.146.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"