@korial29/tiny-fps 0.178.0 → 0.180.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
@@ -1568,7 +1568,7 @@ var holdAt = (p, w, side) => {
1568
1568
  * 2026-11-16: running into a wall, not walking): in the air within WALL_REACH, on a floor touching
1569
1569
  * it, a wall from the knees to the head (wallGap). Not the side it just kicked off.
1570
1570
  */
1571
- var clingTo = (p, w, c) => {
1571
+ var clingTo = (p, w, c, speed) => {
1572
1572
  if (!c.kit.xeno || !c.fwd || !(c.keys & KEY.SPRINT) || c.stumble) return false;
1573
1573
  const reach = p.mode === MODE.AIR ? WALL_REACH : .05;
1574
1574
  for (let side = 1; side <= 4; side++) {
@@ -1577,7 +1577,12 @@ var clingTo = (p, w, c) => {
1577
1577
  if (side !== p.wall && c.fx * nx + c.fz * nz >= .6 && gap !== void 0 && gap <= reach) {
1578
1578
  enter(p, MODE.CLING);
1579
1579
  p.wall = side;
1580
- p.vx = p.vy = p.vz = 0;
1580
+ const [tx, tz] = [-nz, nx];
1581
+ const k = Math.min(1, c.kit.sprint * c.pace / Math.max(speed[0], EPS));
1582
+ const a = (speed[1] * tx + speed[2] * tz) * k;
1583
+ p.vx = tx * a;
1584
+ p.vz = tz * a;
1585
+ p.vy = Math.sqrt(Math.max(0, (speed[0] * k) ** 2 - a * a));
1581
1586
  p.jumps = 1;
1582
1587
  p.coyote = 0;
1583
1588
  p.ev |= EV.GRAB;
@@ -1621,7 +1626,11 @@ var cling = (p, w, c) => {
1621
1626
  const [hu, ha] = [c.fx * nx + c.fz * nz, c.fx * tx + c.fz * tz];
1622
1627
  const [wu, wa] = [fw * hu - s * ha, fw * ha + s * hu];
1623
1628
  const n = Math.sqrt(wu * wu + wa * wa);
1624
- const v = n > 1 ? 8 / n : 8;
1629
+ const was = Math.sqrt(p.vx * p.vx + p.vy * p.vy + p.vz * p.vz);
1630
+ const run = c.kit.run * c.pace;
1631
+ const top = c.keys & KEY.SPRINT ? c.kit.sprint * c.pace : run;
1632
+ const sp = was > top ? Math.max(top, was - 12 * DT$2) : Math.min(top, Math.max(run, was + 3 * c.kit.accel * DT$2));
1633
+ const v = n > 1 ? sp / n : sp;
1625
1634
  const up = wu > .05 ? 1 : wu < -.05 ? -1 : 0;
1626
1635
  const k = wa * v;
1627
1636
  const { a, sign } = along(p, p.wall);
@@ -1689,6 +1698,11 @@ var free$1 = (p, w, c) => {
1689
1698
  if (p.mode === MODE.AIR) air(p, w, c, burst);
1690
1699
  const g = burst && p.vy <= 0 ? 0 : p.mode === MODE.WALLRUN ? WALLRUN_GRAVITY : 1;
1691
1700
  const was = p.mode;
1701
+ const speed = [
1702
+ len$1(p.vx, p.vz),
1703
+ p.vx,
1704
+ p.vz
1705
+ ];
1692
1706
  const hit = fly$1(p, w, heightOf(p), g, onFloor(was), c.bodies);
1693
1707
  if (hit >= 0) {
1694
1708
  if (!onFloor(p.mode)) {
@@ -1708,7 +1722,7 @@ var free$1 = (p, w, c) => {
1708
1722
  p.ev |= p.mode === MODE.SLIDE ? EV.SLIDE_END : 0;
1709
1723
  enter(p, MODE.AIR);
1710
1724
  }
1711
- if ((p.mode === MODE.AIR || p.mode === MODE.GROUND) && clingTo(p, w, c)) return;
1725
+ if ((p.mode === MODE.AIR || p.mode === MODE.GROUND) && clingTo(p, w, c, speed)) return;
1712
1726
  if (p.mode === MODE.AIR) {
1713
1727
  const ledge = ledgeAt(p, w);
1714
1728
  if (ledge) grab(p, ledge, c.kit.dashes);
@@ -7413,6 +7427,9 @@ var HOVER = 4;
7413
7427
  var TACKLE = 4;
7414
7428
  /** Metres a bot without a gun goes out of its way to the rack. */
7415
7429
  var ARM = 30;
7430
+ /** Metres off a bot that takes no gun goes for an enemy in sight, and the most he may be above or below. */
7431
+ var HUNT = 15;
7432
+ var HUNT_Y = 2;
7416
7433
  /**
7417
7434
  * Metres ahead a walking bot looks for a wall or a drop, the seconds of its speed it looks for the
7418
7435
  * floor further on (it does not stop at once), and the share of the drop that hurts it will walk into.
@@ -7519,6 +7536,11 @@ var Bot = class {
7519
7536
  weighed = /* @__PURE__ */ new Set();
7520
7537
  /** Its errand to the orbital station, when it has one. */
7521
7538
  sortie = new Sortie();
7539
+ /**
7540
+ * Whether it jumps unlike the marine the routes were flown with (the ninja, the xenomorph): it
7541
+ * steers every leap in the air to come down on its point, as the moon's (`land`).
7542
+ */
7543
+ steer = false;
7522
7544
  constructor(id, skill = 4) {
7523
7545
  this.id = id;
7524
7546
  this.prefer = id % ROUTES.length;
@@ -7535,6 +7557,7 @@ var Bot = class {
7535
7557
  const t = ++this.ticks;
7536
7558
  const p = s.me.state;
7537
7559
  this.world = s.world;
7560
+ this.steer = !!s.kit && s.kit.jump !== 7;
7538
7561
  if (p.down) {
7539
7562
  this.goal = void 0;
7540
7563
  this.foe = -1;
@@ -7689,7 +7712,19 @@ var Bot = class {
7689
7712
  };
7690
7713
  if (theirs.state === FLAG$1.CARRIED && theirs.by === me.id) return home.base;
7691
7714
  if (this.sortie.board) return this.sortie.board;
7692
- if (p.ammo < 0 && home.rack && flat(p.x, p.z, home.rack[0], home.rack[2]) < ARM) return home.rack;
7715
+ const gear = s.kit?.gear ?? true;
7716
+ if (p.ammo < 0 && gear && home.rack && flat(p.x, p.z, home.rack[0], home.rack[2]) < ARM) return home.rack;
7717
+ const eye = [
7718
+ p.x,
7719
+ p.y + eyeHeight(p),
7720
+ p.z
7721
+ ];
7722
+ const prey = gear ? void 0 : others.find((o) => o.team !== team && !o.state.down && Math.abs(o.state.y - p.y) < HUNT_Y && flat(p.x, p.z, o.state.x, o.state.z) < HUNT && !hidden(world, eye, [
7723
+ o.state.x,
7724
+ o.state.y + 1.2,
7725
+ o.state.z
7726
+ ]));
7727
+ if (prey) return at(prey.state);
7693
7728
  if (mine.state === FLAG$1.CARRIED) {
7694
7729
  const h = holder(mine);
7695
7730
  if (h) return h;
@@ -7920,22 +7955,23 @@ var Bot = class {
7920
7955
  f.k++;
7921
7956
  if (p.mode === MODE.WALLRUN) f.ran = true;
7922
7957
  else if (f.ran && f.ended < 0) f.ended = f.k;
7923
- if (leg.land) {
7958
+ const n = leg.run ? f.ended < 0 ? -1 : f.k - f.ended : f.k;
7959
+ const extra = (n === leg.dash ? DASH : 0) | (n === leg.double ? JUMP : 0);
7960
+ if (leg.land || this.steer) {
7924
7961
  const [tx, tz] = leg.to;
7925
7962
  const d = flat(p.x, p.z, tx, tz);
7926
7963
  const v = (p.vx * (tx - p.x) + p.vz * (tz - p.z)) / (d || 1);
7927
7964
  const g = gravity(this.world);
7928
7965
  const t = Math.max((p.vy + Math.sqrt(Math.max(p.vy ** 2 + 2 * g * (p.y - leg.y), 0))) / g, .05);
7929
7966
  return {
7930
- keys: v * t < d - .3 ? FORWARD : v * t > d + .3 ? BACK : 0,
7967
+ keys: (v * t < d - .3 ? FORWARD : v * t > d + .3 ? BACK : 0) | (leg.land ? 0 : extra),
7931
7968
  yaw,
7932
7969
  free: false,
7933
7970
  exact: true
7934
7971
  };
7935
7972
  }
7936
- const n = leg.run ? f.ended < 0 ? -1 : f.k - f.ended : f.k;
7937
7973
  return {
7938
- keys: (n === leg.dash ? keys | DASH : keys) | (n === leg.double ? JUMP : 0),
7974
+ keys: keys | extra,
7939
7975
  yaw,
7940
7976
  free: false,
7941
7977
  exact: true
@@ -8545,6 +8581,16 @@ var BOT_NAMES = [
8545
8581
  "Gear",
8546
8582
  "Hex"
8547
8583
  ];
8584
+ /**
8585
+ * The classes the bots take in turn by their name (the user, 2026-11-16: bots play the ninja and
8586
+ * the xenomorph too). A map that does not offer one gives its default (roleOf()): the moon's
8587
+ * ninja is an astronaut.
8588
+ */
8589
+ var BOT_ROLES = [
8590
+ ROLE.MARINE,
8591
+ ROLE.NINJA,
8592
+ ROLE.XENO
8593
+ ];
8548
8594
  /** The two seats of a rover, the driver's first. */
8549
8595
  var SEATS = ["driver", "rider"];
8550
8596
  /** An index in [0, n), or undefined. */
@@ -9899,7 +9945,8 @@ var Room = class {
9899
9945
  flags: this.ctf.flags,
9900
9946
  world: this.world,
9901
9947
  balls: this.balls,
9902
- errand: errands.get(p.info.id)
9948
+ errand: errands.get(p.info.id),
9949
+ kit: this.kit(p)
9903
9950
  });
9904
9951
  p.seq = (p.seq ?? -1) + 1 & 65535;
9905
9952
  this.apply(p, onWire({
@@ -9995,8 +10042,9 @@ var Room = class {
9995
10042
  const conn = { send: () => void 0 };
9996
10043
  this.peers.set(conn, null);
9997
10044
  const names = players.map((p) => p.info.name);
9998
- const name = BOT_NAMES.map((n) => `${n} (bot)`).find((n) => !names.includes(n)) ?? "Bot";
9999
- this.join(conn, name, {}, true);
10045
+ const n = BOT_NAMES.findIndex((b) => !names.includes(`${b} (bot)`));
10046
+ const name = n < 0 ? "Bot" : `${BOT_NAMES[n]} (bot)`;
10047
+ this.join(conn, name, { role: BOT_ROLES[Math.max(n, 0) % BOT_ROLES.length] }, true);
10000
10048
  } else return;
10001
10049
  }
10002
10050
  }
@@ -20,8 +20,8 @@ export declare const TAIL: {
20
20
  * A pose of the tail, as bonesOf() takes it: its arch over the back (0 behind, 1 over the head and
21
21
  * forward down into the view), its turn about the pelvis' up (radians, to its left: through its
22
22
  * right side, a tail pointing back turns forward), its lean to the right, its reach (as a share of
23
- * its length, a whip stretched), how much of the hook at its tip it keeps, and how far its root
24
- * rises (radians, less toward the tip).
23
+ * its length, a whip stretched), how much of the hook at its tip it keeps, how far its root
24
+ * rises (radians, less toward the tip), and how far it is coiled in an S to the side (0 to 1, a charge).
25
25
  */
26
26
  export type Lash = readonly [
27
27
  sting: number,
@@ -29,15 +29,17 @@ export type Lash = readonly [
29
29
  lean: number,
30
30
  reach: number,
31
31
  hook: number,
32
- rise: number
32
+ rise: number,
33
+ coil?: number
33
34
  ];
34
35
  /** At rest: behind, hooked. */
35
36
  export declare const HOOKED: Lash;
36
37
  /**
37
38
  * Where its tail is through a strike (TAILS, by the cut): it goes from HOOKED to the strike's poise
38
- * by the top of the wind-up (or most of the way to the strike for a special), is driven to its end
39
- * at the strike, eased in, then comes back. A charge holds the poise and trembles with the clock
40
- * `t`. The SPIN turns the tail low once round the body.
39
+ * in the first third of the wind-up (or most of the way to the strike for a special), so it answers
40
+ * the click at once (the user, 2026-11-16), is driven to its end at the strike, eased in, then
41
+ * comes back. A charge holds the poise drawn in, coils it in an S to the side as it grows (the
42
+ * user, 2026-11-16) and trembles with the clock `t`. The SPIN turns the tail low once round the body.
41
43
  */
42
44
  export declare const lashOf: (p: Pick<PlayerState, "cut" | "swing" | "heavy" | "charge" | "down">, t?: number) => Lash;
43
45
  /** A solved skeleton (solve() in rig.ts): each joint's place and turn in the world. */
@@ -1,5 +1,6 @@
1
1
  import type { Flying } from './plasma';
2
2
  import type { Errand } from './sortie';
3
+ import type { Kit } from './kit';
3
4
  import type { FlagState, PlayerState } from './types';
4
5
  import type { World } from './world';
5
6
  /** A player as a bot sees him: the host's own state, no rewind. */
@@ -18,6 +19,8 @@ export interface Sight {
18
19
  balls?: readonly Flying[];
19
20
  /** What the room asks of it at the orbital station (sortie.ts). */
20
21
  errand?: Errand;
22
+ /** The numbers of its class (kit.ts): the marine's when absent. */
23
+ kit?: Kit;
21
24
  }
22
25
  export type Intent = {
23
26
  keys: number;
@@ -83,6 +86,11 @@ export declare class Bot {
83
86
  private weighed;
84
87
  /** Its errand to the orbital station, when it has one. */
85
88
  private sortie;
89
+ /**
90
+ * Whether it jumps unlike the marine the routes were flown with (the ninja, the xenomorph): it
91
+ * steers every leap in the air to come down on its point, as the moon's (`land`).
92
+ */
93
+ private steer;
86
94
  constructor(id: number, skill?: number);
87
95
  /** A number in [0, 1) from its own sequence. */
88
96
  private rnd;
@@ -259,15 +259,14 @@ export declare const PUNCH_HITS: number, PUNCH_STUN: number, PUNCH_MEMORY: numbe
259
259
  /**
260
260
  * The xenomorph (the user, 2026-11-15; kit.ts). XENO_HP health. It clings to a wall it faces with
261
261
  * forward and the sprint held (MODE.CLING, physics.ts; the sprint since the user, 2026-11-16):
262
- * CLING_SPEED m/s up, down or along it (faster than a man runs, the user 2026-11-16: it was slow)
263
- * while the wall rises CLING_HOLD m over its feet; a jump kicks it off along the look at CLING_LEAP
262
+ * up, down or along it as fast as on a floor, its run and its sprint with the key held (the user,
263
+ * 2026-11-16) while the wall rises CLING_HOLD m over its feet; a jump kicks it off along the look at CLING_LEAP
264
264
  * m/s. It dashes as a man does, XENO_DASH times as fast so as far, three in a row (kit.ts; the
265
265
  * user, 2026-11-16: no more charged pounce); an enemy its dash's burst reaches is pinned (room.ts):
266
266
  * POUNCE_HP health, his flag dropped, a stumble of POUNCE_STUN ticks, once per TACKLE_COOLDOWN. An
267
267
  * enemy whose katana or fists hit it loses ACID_HP.
268
268
  */
269
269
  export declare const XENO_HP = 12;
270
- export declare const CLING_SPEED = 8;
271
270
  export declare const CLING_FACING = 0.6;
272
271
  export declare const CLING_HOLD = 0.4;
273
272
  export declare const CLING_LEAP = 10;
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.178.0",
5
+ "version": "0.180.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"