@korial29/tiny-fps 0.228.0 → 0.228.1

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
@@ -2097,6 +2097,253 @@ var limbOf = (p, f) => {
2097
2097
  if (share < HIPS) return right ? LIMB.LEG_R : LIMB.LEG_L;
2098
2098
  return c === CUT.THRUST && Math.abs(s) <= MIDLINE ? LIMB.NONE : right ? LIMB.ARM_R : LIMB.ARM_L;
2099
2099
  };
2100
+ // src/shared/ctf.ts
2101
+ var home = () => ({
2102
+ state: FLAG$1.HOME,
2103
+ by: 0,
2104
+ x: 0,
2105
+ y: 0,
2106
+ z: 0,
2107
+ left: 0
2108
+ });
2109
+ /** How far under a carrier a flag that he drops in the air is looked for a floor, metres. */
2110
+ var FALL = 60;
2111
+ var Ctf = class {
2112
+ /** Captures per team, red then blue. */
2113
+ score = [0, 0];
2114
+ /** The match is over and the end screen shows. */
2115
+ over = false;
2116
+ /** Frags this match, by everyone: the first is first blood. */
2117
+ frags = 0;
2118
+ /** The flag of each team, red then blue. */
2119
+ flags = [home(), home()];
2120
+ world;
2121
+ rules;
2122
+ mates = /* @__PURE__ */ new Map();
2123
+ /** Ticks to the end of the match, or to the next one while it is over. */
2124
+ clock;
2125
+ /** Ticks before each dropped flag goes home. */
2126
+ back = [0, 0];
2127
+ /** Who may not take each flag, and for how many more ticks: the carrier that was made to drop it. */
2128
+ lock = [{
2129
+ id: -1,
2130
+ left: 0
2131
+ }, {
2132
+ id: -1,
2133
+ left: 0
2134
+ }];
2135
+ /** Ticks before a tackled flag can be sent home: it lies there, and the carrier's mates may take it. */
2136
+ hold = [0, 0];
2137
+ constructor(world, rules) {
2138
+ this.world = world;
2139
+ this.rules = rules;
2140
+ this.clock = rules.timeLimit * 60;
2141
+ }
2142
+ /** A player joined, standing at `at`. */
2143
+ join(id, team, at) {
2144
+ this.mates.set(id, {
2145
+ team,
2146
+ caps: 0,
2147
+ returns: 0,
2148
+ frags: 0,
2149
+ ground: [
2150
+ at.x,
2151
+ at.y,
2152
+ at.z
2153
+ ]
2154
+ });
2155
+ }
2156
+ /** A player left: a flag he carried is dropped where he last stood. */
2157
+ leave(id) {
2158
+ const k = this.carrying(id);
2159
+ const m = this.mates.get(id);
2160
+ if (k >= 0 && m) this.dropAt(k, m.ground);
2161
+ this.mates.delete(id);
2162
+ }
2163
+ /** A player was put at `at` (a new match): his last ground is there. */
2164
+ place(id, at) {
2165
+ const m = this.mates.get(id);
2166
+ if (m) m.ground = [
2167
+ at.x,
2168
+ at.y,
2169
+ at.z
2170
+ ];
2171
+ }
2172
+ /**
2173
+ * The player's state after one move. Under the kill floor and put back at a spawn (EV.RESPAWN),
2174
+ * a carrier drops the flag where he last stood; then a floor under him is his last ground.
2175
+ */
2176
+ moved(p) {
2177
+ const m = this.mates.get(p.id);
2178
+ if (!m) return;
2179
+ const k = this.carrying(p.id);
2180
+ if (p.ev & EV.RESPAWN && k >= 0) this.dropAt(k, m.ground);
2181
+ if (p.ground) m.ground = [
2182
+ p.x,
2183
+ p.y,
2184
+ p.z
2185
+ ];
2186
+ }
2187
+ /**
2188
+ * Makes the player drop the flag he carries (the tackle of step 7). It lies under him: where he
2189
+ * stands, or on the first floor below him, or at his last ground when there is none (over the
2190
+ * void). False when he carried nothing.
2191
+ */
2192
+ drop(p) {
2193
+ const k = this.carrying(p.id);
2194
+ const m = this.mates.get(p.id);
2195
+ if (k < 0 || !m || this.over) return false;
2196
+ let at = m.ground;
2197
+ if (p.ground) at = [
2198
+ p.x,
2199
+ p.y,
2200
+ p.z
2201
+ ];
2202
+ else {
2203
+ const d = ray(this.world, [
2204
+ p.x,
2205
+ p.y + .05,
2206
+ p.z
2207
+ ], [
2208
+ 0,
2209
+ -1,
2210
+ 0
2211
+ ], FALL);
2212
+ if (d < FALL) at = [
2213
+ p.x,
2214
+ p.y + .05 - d,
2215
+ p.z
2216
+ ];
2217
+ }
2218
+ this.dropAt(k, at);
2219
+ this.lock[k] = {
2220
+ id: p.id,
2221
+ left: 120
2222
+ };
2223
+ this.hold[k] = 120;
2224
+ return true;
2225
+ }
2226
+ /** The team whose flag the player carries, or -1. */
2227
+ carrying(id) {
2228
+ return this.flags.findIndex((f) => f.state === FLAG$1.CARRIED && f.by === id);
2229
+ }
2230
+ /** The winning team of a match that is over, or -1 for a draw. */
2231
+ winner() {
2232
+ const [r, b] = this.score;
2233
+ return r > b ? 0 : b > r ? 1 : -1;
2234
+ }
2235
+ /** What every player has done this match. */
2236
+ tally() {
2237
+ return [...this.mates].map(([id, m]) => ({
2238
+ id,
2239
+ caps: m.caps,
2240
+ returns: m.returns,
2241
+ frags: m.frags
2242
+ }));
2243
+ }
2244
+ /**
2245
+ * Player `id` put an enemy down: his frags this match, or 0 when he is not in it or the match is
2246
+ * over.
2247
+ */
2248
+ frag(id) {
2249
+ const m = this.mates.get(id);
2250
+ if (!m || this.over) return 0;
2251
+ this.frags++;
2252
+ return ++m.frags;
2253
+ }
2254
+ /** The room is empty: the next match starts from scratch. */
2255
+ reset() {
2256
+ this.over = false;
2257
+ this.score = [0, 0];
2258
+ this.frags = 0;
2259
+ this.flags = [home(), home()];
2260
+ this.back = [0, 0];
2261
+ this.lock.forEach((l) => l.left = 0);
2262
+ this.hold = [0, 0];
2263
+ this.clock = this.rules.timeLimit * 60;
2264
+ for (const m of this.mates.values()) m.caps = m.returns = m.frags = 0;
2265
+ }
2266
+ /** The part of a snapshot that is the match's. */
2267
+ wire() {
2268
+ return {
2269
+ score: [...this.score],
2270
+ clock: Math.ceil(this.clock / 60),
2271
+ over: this.over,
2272
+ flags: this.flags.map((f) => ({ ...f }))
2273
+ };
2274
+ }
2275
+ /**
2276
+ * One host tick over the players: the dropped flags run down, flags are taken, returned and
2277
+ * captured, the clock runs. 'end' when the match has just ended, 'start' when the end screen is
2278
+ * done and a new match begins (the room puts everyone back at a spawn).
2279
+ */
2280
+ tick(players) {
2281
+ if (this.over) {
2282
+ if (--this.clock <= 0) {
2283
+ this.reset();
2284
+ return "start";
2285
+ }
2286
+ return;
2287
+ }
2288
+ for (const k of [0, 1]) {
2289
+ const f = this.flags[k];
2290
+ this.lock[k].left--;
2291
+ this.hold[k]--;
2292
+ if (f.state === FLAG$1.DROPPED) {
2293
+ f.left = Math.ceil(--this.back[k] / 60);
2294
+ if (this.back[k] <= 0) this.flags[k] = home();
2295
+ }
2296
+ }
2297
+ for (const k of [0, 1]) {
2298
+ const f = this.flags[k];
2299
+ if (f.state === FLAG$1.CARRIED) continue;
2300
+ const at = f.state === FLAG$1.HOME ? this.world.def.teams[k].base : [
2301
+ f.x,
2302
+ f.y,
2303
+ f.z
2304
+ ];
2305
+ const near = players.filter((q) => touches(q.state, at));
2306
+ const mate = f.state === FLAG$1.DROPPED && this.hold[k] <= 0 ? near.find((q) => q.team === k) : void 0;
2307
+ const foe = near.find((q) => q.team !== k && (q.id !== this.lock[k].id || this.lock[k].left <= 0));
2308
+ if (mate) {
2309
+ const m = this.mates.get(mate.id);
2310
+ if (m) m.returns++;
2311
+ this.flags[k] = home();
2312
+ } else if (foe) this.flags[k] = {
2313
+ ...home(),
2314
+ state: FLAG$1.CARRIED,
2315
+ by: foe.id
2316
+ };
2317
+ }
2318
+ for (const p of players) {
2319
+ const k = this.carrying(p.id);
2320
+ if (k >= 0 && this.flags[p.team].state === FLAG$1.HOME && touches(p.state, this.world.def.teams[p.team].base)) {
2321
+ this.score[p.team]++;
2322
+ const m = this.mates.get(p.id);
2323
+ if (m) m.caps++;
2324
+ this.flags[k] = home();
2325
+ }
2326
+ }
2327
+ if (this.score.some((s) => s >= this.rules.scoreLimit) || --this.clock <= 0) {
2328
+ this.over = true;
2329
+ this.clock = 600;
2330
+ return "end";
2331
+ }
2332
+ }
2333
+ dropAt(k, [x, y, z]) {
2334
+ this.flags[k] = {
2335
+ state: FLAG$1.DROPPED,
2336
+ by: 0,
2337
+ x,
2338
+ y,
2339
+ z,
2340
+ left: 10
2341
+ };
2342
+ this.back[k] = 600;
2343
+ }
2344
+ };
2345
+ /** Whether the player's body reaches the flag foot at `at`: close enough, and overlapping its height. */
2346
+ var touches = (p, at) => Math.hypot(p.x - at[0], p.z - at[2]) < 1.5 && p.y < at[1] + 2.2 && p.y + 1.8 > at[1];
2100
2347
  // src/shared/map.ts
2101
2348
  /** The bottom of every building: far below the kill floor, so nothing shows beneath a roof. */
2102
2349
  var BASE$1 = -30;
@@ -8899,6 +9146,8 @@ var DRIFT = 4;
8899
9146
  var SHARE = .25;
8900
9147
  /** Metres over the floor under a player in the air past which he is over a gap, not jumping on a roof. */
8901
9148
  var HOVER = 4;
9149
+ /** How long a carrier waits at home for the team to break a flag exchange before joining the chase. */
9150
+ var FLAG_WAIT = 1200;
8902
9151
  /** Metres from the enemy carrier a bot dashes into him: the tackle. */
8903
9152
  var TACKLE = 4;
8904
9153
  /** Metres a bot without a gun goes out of its way to the rack. */
@@ -9000,7 +9249,7 @@ var squad = (team, players, flags, world) => {
9000
9249
  const ours = theirs.state === FLAG$1.CARRIED ? by(theirs.by) : void 0;
9001
9250
  const enemy = mine.state === FLAG$1.CARRIED ? by(mine.by) : void 0;
9002
9251
  let trouble;
9003
- for (const o of up) if (o.team === team && o.state.hp <= LOW && (!trouble || o.state.hp < trouble.state.hp) && up.some((f) => f.team !== team && flat(f.state.x, f.state.z, o.state.x, o.state.z) < NEAR)) trouble = o;
9252
+ for (const o of up) if (mine.state === FLAG$1.HOME && o.team === team && o.state.hp <= LOW && (!trouble || o.state.hp < trouble.state.hp) && up.some((f) => f.team !== team && flat(f.state.x, f.state.z, o.state.x, o.state.z) < NEAR)) trouble = o;
9004
9253
  const free = up.filter((o) => o.team === team && o.bot && o !== ours && o !== trouble).sort((a, b) => a.id - b.id);
9005
9254
  const n = free.length;
9006
9255
  const take = (role, count, x, z, far = Infinity) => {
@@ -9066,7 +9315,10 @@ var Bot = class {
9066
9315
  steps = [];
9067
9316
  /** The goal of the way, and the tick it was planned. */
9068
9317
  goal;
9318
+ plannedWhy = "";
9069
9319
  planned = 0;
9320
+ /** Tick the carrier reached home during a flag exchange, or 0 while it is still on the way. */
9321
+ flagWait = 0;
9070
9322
  /** Tick of the last grounded rack search, and the path to its chosen rack. */
9071
9323
  rackChecked = -120;
9072
9324
  rackTarget;
@@ -9185,6 +9437,7 @@ var Bot = class {
9185
9437
  this.steer = !!s.kit && s.kit.jump !== 7;
9186
9438
  if (p.down) {
9187
9439
  this.goal = this.rackTarget = void 0;
9440
+ this.flagWait = 0;
9188
9441
  this.rackChecked = -120;
9189
9442
  this.foe = -1;
9190
9443
  return {
@@ -9218,12 +9471,12 @@ var Bot = class {
9218
9471
  yaw: p.yaw,
9219
9472
  pitch: 0
9220
9473
  };
9221
- if (p.ground && (!this.goal || !!this.rackSteps || flat(goal[0], goal[2], this.goal[0], this.goal[2]) > Math.max(DRIFT, SHARE * flat(p.x, p.z, goal[0], goal[2])) || !this.steps.some((st) => st.leg) && t - this.planned > REPLAN)) this.plan(s.world, p, goal);
9474
+ if (p.ground && (!this.goal || !!this.rackSteps || this.plannedWhy !== this.why && (this.urgent() || this.urgent(this.plannedWhy)) || this.urgent() && Math.abs(goal[1] - this.goal[1]) > HOVER || flat(goal[0], goal[2], this.goal[0], this.goal[2]) > Math.max(DRIFT, SHARE * flat(p.x, p.z, goal[0], goal[2])) || !this.steps.some((st) => st.leg) && t - this.planned > REPLAN)) this.plan(s.world, p, goal);
9222
9475
  const move = this.pilot(p);
9223
9476
  const fight = this.fight(s, move.free, weapon);
9224
9477
  if (!fight) {
9225
9478
  this.pitch = 0;
9226
- const runs = s.flags[1 - s.me.team].state === FLAG$1.CARRIED && s.flags[1 - s.me.team].by === s.me.id;
9479
+ const runs = this.why === "flag home";
9227
9480
  if (move.exact || runs) {
9228
9481
  this.look = this.aim = move.yaw;
9229
9482
  return this.evade(s, {
@@ -9331,7 +9584,7 @@ var Bot = class {
9331
9584
  const home = world.def.teams[team];
9332
9585
  const [mine, theirs] = [flags[team], flags[1 - team]];
9333
9586
  const holder = (f) => {
9334
- const h = others.find((o) => o.id === f.by)?.state;
9587
+ const h = others.find((o) => o.id === f.by && !o.state.down)?.state;
9335
9588
  const y = h && floorAt(world, h.x, h.z, h.y + .5);
9336
9589
  return h && [
9337
9590
  h.x,
@@ -9340,16 +9593,45 @@ var Bot = class {
9340
9593
  ];
9341
9594
  };
9342
9595
  if (theirs.state === FLAG$1.CARRIED && theirs.by === me.id) {
9596
+ if (mine.state === FLAG$1.CARRIED) {
9597
+ if (touches(p, home.base)) this.flagWait ||= this.ticks;
9598
+ if (this.flagWait && this.ticks - this.flagWait >= FLAG_WAIT) {
9599
+ const enemy = holder(mine);
9600
+ if (enemy) {
9601
+ this.why = "chase carrier";
9602
+ return enemy;
9603
+ }
9604
+ }
9605
+ } else this.flagWait = 0;
9343
9606
  this.why = "flag home";
9344
9607
  return home.base;
9345
9608
  }
9346
- if (this.sortie.board) {
9347
- this.why = "station";
9348
- return this.sortie.board;
9349
- }
9350
- const gear = s.kit?.gear ?? true;
9351
- const eye = [
9352
- p.x,
9609
+ this.flagWait = 0;
9610
+ const { roles, trouble } = s.squad ?? squad(team, [{
9611
+ ...me,
9612
+ bot: true
9613
+ }, ...others], flags, world);
9614
+ const role = roles.get(me.id);
9615
+ const enemy = role === "chase" ? holder(mine) : void 0;
9616
+ if (enemy) {
9617
+ this.why = "chase carrier";
9618
+ return enemy;
9619
+ }
9620
+ if (role === "return") {
9621
+ this.why = "return flag";
9622
+ return [
9623
+ mine.x,
9624
+ mine.y,
9625
+ mine.z
9626
+ ];
9627
+ }
9628
+ if (this.sortie.board) {
9629
+ this.why = "station";
9630
+ return this.sortie.board;
9631
+ }
9632
+ const gear = s.kit?.gear ?? true;
9633
+ const eye = [
9634
+ p.x,
9353
9635
  p.y + eyeHeight(p),
9354
9636
  p.z
9355
9637
  ];
@@ -9362,12 +9644,7 @@ var Bot = class {
9362
9644
  this.why = "hunt";
9363
9645
  return at(prey.state);
9364
9646
  }
9365
- const { roles, trouble } = s.squad ?? squad(team, [{
9366
- ...me,
9367
- bot: true
9368
- }, ...others], flags, world);
9369
- const role = roles.get(me.id);
9370
- if (p.hp <= LOW && role !== "chase") {
9647
+ if (p.hp <= LOW) {
9371
9648
  let pack;
9372
9649
  let nearest = MEND;
9373
9650
  for (const q of s.packs ?? []) {
@@ -9379,19 +9656,11 @@ var Bot = class {
9379
9656
  return pack;
9380
9657
  }
9381
9658
  }
9382
- const h = role === "chase" ? holder(mine) : role === "escort" ? holder(theirs) : void 0;
9659
+ const h = role === "escort" ? holder(theirs) : void 0;
9383
9660
  if (h) {
9384
- this.why = role === "chase" ? "chase carrier" : "escort";
9661
+ this.why = "escort";
9385
9662
  return h;
9386
9663
  }
9387
- if (role === "return") {
9388
- this.why = "return flag";
9389
- return [
9390
- mine.x,
9391
- mine.y,
9392
- mine.z
9393
- ];
9394
- }
9395
9664
  if (role === "help" && trouble) {
9396
9665
  this.why = "help";
9397
9666
  return at(trouble.state);
@@ -9479,10 +9748,14 @@ var Bot = class {
9479
9748
  }
9480
9749
  return this.posts[this.post].at;
9481
9750
  }
9751
+ urgent(why = this.why) {
9752
+ return why === "flag home" || why === "chase carrier" || why === "return flag";
9753
+ }
9482
9754
  plan(w, p, goal) {
9483
9755
  this.goal = goal;
9756
+ this.plannedWhy = this.why;
9484
9757
  this.planned = this.ticks;
9485
- const direct = this.why === "flag home" && !this.steer || this.why.endsWith(" rack");
9758
+ const direct = this.urgent() && !this.steer || this.why.endsWith(" rack");
9486
9759
  const nav = navOf(w);
9487
9760
  const prefer = direct ? -1 : this.id % nav.ways;
9488
9761
  this.steps = this.rackSteps ?? path(nav, w, at(p), goal, prefer);
@@ -9756,7 +10029,7 @@ var Bot = class {
9756
10029
  const { me, others, world, flags } = s;
9757
10030
  const p = me.state;
9758
10031
  const theirs = flags[1 - me.team];
9759
- if (!p.ground || !free || theirs.state === FLAG$1.CARRIED && theirs.by === me.id) {
10032
+ if (!p.ground || !free || theirs.state === FLAG$1.CARRIED && theirs.by === me.id && this.why !== "chase carrier") {
9760
10033
  this.foe = -1;
9761
10034
  return;
9762
10035
  }
@@ -9849,253 +10122,6 @@ var Bot = class {
9849
10122
  return { keys: ready && pull && (rail || rifle || this.ticks & 1) ? FIRE : 0 };
9850
10123
  }
9851
10124
  };
9852
- // src/shared/ctf.ts
9853
- var home = () => ({
9854
- state: FLAG$1.HOME,
9855
- by: 0,
9856
- x: 0,
9857
- y: 0,
9858
- z: 0,
9859
- left: 0
9860
- });
9861
- /** How far under a carrier a flag that he drops in the air is looked for a floor, metres. */
9862
- var FALL = 60;
9863
- var Ctf = class {
9864
- /** Captures per team, red then blue. */
9865
- score = [0, 0];
9866
- /** The match is over and the end screen shows. */
9867
- over = false;
9868
- /** Frags this match, by everyone: the first is first blood. */
9869
- frags = 0;
9870
- /** The flag of each team, red then blue. */
9871
- flags = [home(), home()];
9872
- world;
9873
- rules;
9874
- mates = /* @__PURE__ */ new Map();
9875
- /** Ticks to the end of the match, or to the next one while it is over. */
9876
- clock;
9877
- /** Ticks before each dropped flag goes home. */
9878
- back = [0, 0];
9879
- /** Who may not take each flag, and for how many more ticks: the carrier that was made to drop it. */
9880
- lock = [{
9881
- id: -1,
9882
- left: 0
9883
- }, {
9884
- id: -1,
9885
- left: 0
9886
- }];
9887
- /** Ticks before a tackled flag can be sent home: it lies there, and the carrier's mates may take it. */
9888
- hold = [0, 0];
9889
- constructor(world, rules) {
9890
- this.world = world;
9891
- this.rules = rules;
9892
- this.clock = rules.timeLimit * 60;
9893
- }
9894
- /** A player joined, standing at `at`. */
9895
- join(id, team, at) {
9896
- this.mates.set(id, {
9897
- team,
9898
- caps: 0,
9899
- returns: 0,
9900
- frags: 0,
9901
- ground: [
9902
- at.x,
9903
- at.y,
9904
- at.z
9905
- ]
9906
- });
9907
- }
9908
- /** A player left: a flag he carried is dropped where he last stood. */
9909
- leave(id) {
9910
- const k = this.carrying(id);
9911
- const m = this.mates.get(id);
9912
- if (k >= 0 && m) this.dropAt(k, m.ground);
9913
- this.mates.delete(id);
9914
- }
9915
- /** A player was put at `at` (a new match): his last ground is there. */
9916
- place(id, at) {
9917
- const m = this.mates.get(id);
9918
- if (m) m.ground = [
9919
- at.x,
9920
- at.y,
9921
- at.z
9922
- ];
9923
- }
9924
- /**
9925
- * The player's state after one move. Under the kill floor and put back at a spawn (EV.RESPAWN),
9926
- * a carrier drops the flag where he last stood; then a floor under him is his last ground.
9927
- */
9928
- moved(p) {
9929
- const m = this.mates.get(p.id);
9930
- if (!m) return;
9931
- const k = this.carrying(p.id);
9932
- if (p.ev & EV.RESPAWN && k >= 0) this.dropAt(k, m.ground);
9933
- if (p.ground) m.ground = [
9934
- p.x,
9935
- p.y,
9936
- p.z
9937
- ];
9938
- }
9939
- /**
9940
- * Makes the player drop the flag he carries (the tackle of step 7). It lies under him: where he
9941
- * stands, or on the first floor below him, or at his last ground when there is none (over the
9942
- * void). False when he carried nothing.
9943
- */
9944
- drop(p) {
9945
- const k = this.carrying(p.id);
9946
- const m = this.mates.get(p.id);
9947
- if (k < 0 || !m || this.over) return false;
9948
- let at = m.ground;
9949
- if (p.ground) at = [
9950
- p.x,
9951
- p.y,
9952
- p.z
9953
- ];
9954
- else {
9955
- const d = ray(this.world, [
9956
- p.x,
9957
- p.y + .05,
9958
- p.z
9959
- ], [
9960
- 0,
9961
- -1,
9962
- 0
9963
- ], FALL);
9964
- if (d < FALL) at = [
9965
- p.x,
9966
- p.y + .05 - d,
9967
- p.z
9968
- ];
9969
- }
9970
- this.dropAt(k, at);
9971
- this.lock[k] = {
9972
- id: p.id,
9973
- left: 120
9974
- };
9975
- this.hold[k] = 120;
9976
- return true;
9977
- }
9978
- /** The team whose flag the player carries, or -1. */
9979
- carrying(id) {
9980
- return this.flags.findIndex((f) => f.state === FLAG$1.CARRIED && f.by === id);
9981
- }
9982
- /** The winning team of a match that is over, or -1 for a draw. */
9983
- winner() {
9984
- const [r, b] = this.score;
9985
- return r > b ? 0 : b > r ? 1 : -1;
9986
- }
9987
- /** What every player has done this match. */
9988
- tally() {
9989
- return [...this.mates].map(([id, m]) => ({
9990
- id,
9991
- caps: m.caps,
9992
- returns: m.returns,
9993
- frags: m.frags
9994
- }));
9995
- }
9996
- /**
9997
- * Player `id` put an enemy down: his frags this match, or 0 when he is not in it or the match is
9998
- * over.
9999
- */
10000
- frag(id) {
10001
- const m = this.mates.get(id);
10002
- if (!m || this.over) return 0;
10003
- this.frags++;
10004
- return ++m.frags;
10005
- }
10006
- /** The room is empty: the next match starts from scratch. */
10007
- reset() {
10008
- this.over = false;
10009
- this.score = [0, 0];
10010
- this.frags = 0;
10011
- this.flags = [home(), home()];
10012
- this.back = [0, 0];
10013
- this.lock.forEach((l) => l.left = 0);
10014
- this.hold = [0, 0];
10015
- this.clock = this.rules.timeLimit * 60;
10016
- for (const m of this.mates.values()) m.caps = m.returns = m.frags = 0;
10017
- }
10018
- /** The part of a snapshot that is the match's. */
10019
- wire() {
10020
- return {
10021
- score: [...this.score],
10022
- clock: Math.ceil(this.clock / 60),
10023
- over: this.over,
10024
- flags: this.flags.map((f) => ({ ...f }))
10025
- };
10026
- }
10027
- /**
10028
- * One host tick over the players: the dropped flags run down, flags are taken, returned and
10029
- * captured, the clock runs. 'end' when the match has just ended, 'start' when the end screen is
10030
- * done and a new match begins (the room puts everyone back at a spawn).
10031
- */
10032
- tick(players) {
10033
- if (this.over) {
10034
- if (--this.clock <= 0) {
10035
- this.reset();
10036
- return "start";
10037
- }
10038
- return;
10039
- }
10040
- for (const k of [0, 1]) {
10041
- const f = this.flags[k];
10042
- this.lock[k].left--;
10043
- this.hold[k]--;
10044
- if (f.state === FLAG$1.DROPPED) {
10045
- f.left = Math.ceil(--this.back[k] / 60);
10046
- if (this.back[k] <= 0) this.flags[k] = home();
10047
- }
10048
- }
10049
- for (const k of [0, 1]) {
10050
- const f = this.flags[k];
10051
- if (f.state === FLAG$1.CARRIED) continue;
10052
- const at = f.state === FLAG$1.HOME ? this.world.def.teams[k].base : [
10053
- f.x,
10054
- f.y,
10055
- f.z
10056
- ];
10057
- const near = players.filter((q) => touches(q.state, at));
10058
- const mate = f.state === FLAG$1.DROPPED && this.hold[k] <= 0 ? near.find((q) => q.team === k) : void 0;
10059
- const foe = near.find((q) => q.team !== k && (q.id !== this.lock[k].id || this.lock[k].left <= 0));
10060
- if (mate) {
10061
- const m = this.mates.get(mate.id);
10062
- if (m) m.returns++;
10063
- this.flags[k] = home();
10064
- } else if (foe) this.flags[k] = {
10065
- ...home(),
10066
- state: FLAG$1.CARRIED,
10067
- by: foe.id
10068
- };
10069
- }
10070
- for (const p of players) {
10071
- const k = this.carrying(p.id);
10072
- if (k >= 0 && this.flags[p.team].state === FLAG$1.HOME && touches(p.state, this.world.def.teams[p.team].base)) {
10073
- this.score[p.team]++;
10074
- const m = this.mates.get(p.id);
10075
- if (m) m.caps++;
10076
- this.flags[k] = home();
10077
- }
10078
- }
10079
- if (this.score.some((s) => s >= this.rules.scoreLimit) || --this.clock <= 0) {
10080
- this.over = true;
10081
- this.clock = 600;
10082
- return "end";
10083
- }
10084
- }
10085
- dropAt(k, [x, y, z]) {
10086
- this.flags[k] = {
10087
- state: FLAG$1.DROPPED,
10088
- by: 0,
10089
- x,
10090
- y,
10091
- z,
10092
- left: 10
10093
- };
10094
- this.back[k] = 600;
10095
- }
10096
- };
10097
- /** Whether the player's body reaches the flag foot at `at`: close enough, and overlapping its height. */
10098
- var touches = (p, at) => Math.hypot(p.x - at[0], p.z - at[2]) < 1.5 && p.y < at[1] + 2.2 && p.y + 1.8 > at[1];
10099
10125
  // src/shared/doors.ts
10100
10126
  var DOOR = {
10101
10127
  /**
@@ -102,7 +102,10 @@ export declare class Bot {
102
102
  private steps;
103
103
  /** The goal of the way, and the tick it was planned. */
104
104
  private goal;
105
+ private plannedWhy;
105
106
  private planned;
107
+ /** Tick the carrier reached home during a flag exchange, or 0 while it is still on the way. */
108
+ private flagWait;
106
109
  /** Tick of the last grounded rack search, and the path to its chosen rack. */
107
110
  private rackChecked;
108
111
  private rackTarget?;
@@ -191,6 +194,7 @@ export declare class Bot {
191
194
  private goalOf;
192
195
  /** The guard's point: round its flag, a stop at each point, one way or the other by its id. */
193
196
  private patrol;
197
+ private urgent;
194
198
  private plan;
195
199
  /**
196
200
  * The keys and yaw of the move, whether the bot may look away from it to shoot, and whether the
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.228.0",
5
+ "version": "0.228.1",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"