@korial29/tiny-fps 0.95.0 → 0.96.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/README.md +4 -4
- package/dist/index.js +13 -13
- package/dist/local.js +1 -1
- package/dist/server.js +413 -71
- package/dist/types/client/moonbase.d.ts +14 -0
- package/dist/types/client/moonscape.d.ts +5 -0
- package/dist/types/client/render.d.ts +2 -0
- package/dist/types/shared/moon.d.ts +6 -7
- package/dist/types/shared/moonbase.d.ts +17 -0
- package/dist/types/shared/physics.d.ts +11 -0
- package/dist/types/shared/relief.d.ts +55 -0
- package/dist/types/shared/rover.d.ts +71 -0
- package/dist/types/shared/types.d.ts +38 -1
- package/dist/types/shared/world.d.ts +10 -6
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -171,6 +171,137 @@ var RULES = {
|
|
|
171
171
|
timeLimit: 480,
|
|
172
172
|
map: "highline"
|
|
173
173
|
};
|
|
174
|
+
// src/shared/relief.ts
|
|
175
|
+
/** Integer hash of a lattice point to [0, 1): the same on every engine. */
|
|
176
|
+
var hash = (x, y, s) => {
|
|
177
|
+
let h = Math.imul(x, 374761393) + Math.imul(y, 668265263) + Math.imul(s, 144665) | 0;
|
|
178
|
+
h = Math.imul(h ^ h >>> 13, 1274126177);
|
|
179
|
+
return ((h ^ h >>> 16) >>> 0) / 4294967296;
|
|
180
|
+
};
|
|
181
|
+
/** Smooth value noise on the integer lattice, in [0, 1): flat across every lattice line, so a fold along one leaves no crease. */
|
|
182
|
+
var noise = (x, y, s) => {
|
|
183
|
+
const [i, j] = [Math.floor(x), Math.floor(y)];
|
|
184
|
+
const [u, v] = [x - i, y - j].map((t) => t * t * (3 - 2 * t));
|
|
185
|
+
const h = (a, b) => hash(i + a, j + b, s);
|
|
186
|
+
return (h(0, 0) * (1 - u) + h(1, 0) * u) * (1 - v) + (h(0, 1) * (1 - u) + h(1, 1) * u) * v;
|
|
187
|
+
};
|
|
188
|
+
var made = /* @__PURE__ */ new WeakMap();
|
|
189
|
+
/** Builds the lattice over the box of the bound, once per definition. */
|
|
190
|
+
var raise = (def) => {
|
|
191
|
+
const old = made.get(def);
|
|
192
|
+
if (old) return old;
|
|
193
|
+
const { hole, bound, cell, at } = def;
|
|
194
|
+
const [cx, cz, a, b] = bound;
|
|
195
|
+
const x0 = Math.floor((cx - a) / cell) * cell;
|
|
196
|
+
const z0 = Math.floor((cz - b) / cell) * cell;
|
|
197
|
+
const nx = Math.ceil((cx + a - x0) / cell) + 1;
|
|
198
|
+
const nz = Math.ceil((cz + b - z0) / cell) + 1;
|
|
199
|
+
const h = new Float32Array(nx * nz);
|
|
200
|
+
let top = -Infinity;
|
|
201
|
+
for (let j = 0; j < nz; j++) for (let i = 0; i < nx; i++) {
|
|
202
|
+
h[i + j * nx] = at(x0 + i * cell, z0 + j * cell);
|
|
203
|
+
top = Math.max(top, h[i + j * nx]);
|
|
204
|
+
}
|
|
205
|
+
const r = {
|
|
206
|
+
x0,
|
|
207
|
+
z0,
|
|
208
|
+
cell,
|
|
209
|
+
nx,
|
|
210
|
+
nz,
|
|
211
|
+
h,
|
|
212
|
+
hole,
|
|
213
|
+
bound,
|
|
214
|
+
top
|
|
215
|
+
};
|
|
216
|
+
made.set(def, r);
|
|
217
|
+
return r;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* The height of the ground at (x, z), or -Infinity where there is none: a world without relief,
|
|
221
|
+
* and inside the hole. Each lattice square is two triangles split from node (i, j) to (i + 1, j + 1).
|
|
222
|
+
*/
|
|
223
|
+
var ground = (w, x, z) => {
|
|
224
|
+
const r = w.relief;
|
|
225
|
+
if (!r || x > r.hole[0] && x < r.hole[2] && z > r.hole[1] && z < r.hole[3]) return -Infinity;
|
|
226
|
+
const u = Math.min(Math.max((x - r.x0) / r.cell, 0), r.nx - 1);
|
|
227
|
+
const v = Math.min(Math.max((z - r.z0) / r.cell, 0), r.nz - 1);
|
|
228
|
+
const i = Math.min(Math.floor(u), r.nx - 2);
|
|
229
|
+
const j = Math.min(Math.floor(v), r.nz - 2);
|
|
230
|
+
const [fu, fv] = [u - i, v - j];
|
|
231
|
+
const n = i + j * r.nx;
|
|
232
|
+
const [a, b, c, d] = [
|
|
233
|
+
r.h[n],
|
|
234
|
+
r.h[n + 1],
|
|
235
|
+
r.h[n + r.nx],
|
|
236
|
+
r.h[n + r.nx + 1]
|
|
237
|
+
];
|
|
238
|
+
return fu >= fv ? a + (b - a) * fu + (d - b) * fv : a + (c - a) * fv + (d - c) * fu;
|
|
239
|
+
};
|
|
240
|
+
/** Keeps a body inside the bound: put back on the ellipse, its speed out of it taken away. */
|
|
241
|
+
var bound = (p, w) => {
|
|
242
|
+
if (!w.relief) return;
|
|
243
|
+
const [cx, cz, a, b] = w.relief.bound;
|
|
244
|
+
const [dx, dz] = [(p.x - cx) / a, (p.z - cz) / b];
|
|
245
|
+
const k = dx * dx + dz * dz;
|
|
246
|
+
if (k <= 1) return;
|
|
247
|
+
const s = 1 / Math.sqrt(k);
|
|
248
|
+
p.x = cx + dx * s * a;
|
|
249
|
+
p.z = cz + dz * s * b;
|
|
250
|
+
const [nx, nz] = [dx * s / a, dz * s / b];
|
|
251
|
+
const out = (p.vx * nx + p.vz * nz) / (nx * nx + nz * nz);
|
|
252
|
+
if (out > 0) {
|
|
253
|
+
p.vx -= out * nx;
|
|
254
|
+
p.vz -= out * nz;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
/** Metres between two samples of a ray, and the halvings that then close in on the ground. */
|
|
258
|
+
var MARCH = 1;
|
|
259
|
+
var HALVINGS = 6;
|
|
260
|
+
/**
|
|
261
|
+
* Distance along the ray from o in the unit direction d to the ground, at most max: for ray(),
|
|
262
|
+
* after the brushes. A ray that starts under the ground hits at 0. With `grow`, the path of a
|
|
263
|
+
* sphere of that radius. Sampled every MARCH metres: a crest thinner than that is missed. The
|
|
264
|
+
* stretch over the hole is skipped: a ray that stays in the arena costs no sample.
|
|
265
|
+
*/
|
|
266
|
+
var trace = (w, o, d, max, grow = 0) => {
|
|
267
|
+
const r = w.relief;
|
|
268
|
+
if (!r || Math.min(o[1], o[1] + d[1] * max) - grow > r.top) return max;
|
|
269
|
+
let [t0, t1] = [0, max];
|
|
270
|
+
for (const a of [0, 1]) {
|
|
271
|
+
const [p, v, lo, hi] = [
|
|
272
|
+
o[a * 2],
|
|
273
|
+
d[a * 2],
|
|
274
|
+
r.hole[a],
|
|
275
|
+
r.hole[a + 2]
|
|
276
|
+
];
|
|
277
|
+
if (v) {
|
|
278
|
+
const [m, n] = [(lo - p) / v, (hi - p) / v];
|
|
279
|
+
t0 = Math.max(t0, Math.min(m, n));
|
|
280
|
+
t1 = Math.min(t1, Math.max(m, n));
|
|
281
|
+
} else if (p <= lo || p >= hi) t1 = -1;
|
|
282
|
+
}
|
|
283
|
+
const over = (t) => o[1] + d[1] * t - grow - ground(w, o[0] + d[0] * t, o[2] + d[2] * t);
|
|
284
|
+
if (!d[0] && !d[2]) {
|
|
285
|
+
const h = over(0);
|
|
286
|
+
return h < 0 ? 0 : d[1] < 0 ? Math.min(max, h / -d[1]) : max;
|
|
287
|
+
}
|
|
288
|
+
for (const [from, to] of t0 < t1 ? [[0, t0], [t1, max]] : [[0, max]]) {
|
|
289
|
+
if (from < to && over(from) < 0) return from;
|
|
290
|
+
for (let t = from; t < to; t += MARCH) {
|
|
291
|
+
const next = Math.min(t + MARCH, to);
|
|
292
|
+
if (over(next) < 0) {
|
|
293
|
+
let [lo, hi] = [t, next];
|
|
294
|
+
for (let n = 0; n < HALVINGS; n++) {
|
|
295
|
+
const mid = (lo + hi) / 2;
|
|
296
|
+
if (over(mid) < 0) hi = mid;
|
|
297
|
+
else lo = mid;
|
|
298
|
+
}
|
|
299
|
+
return lo;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return max;
|
|
304
|
+
};
|
|
174
305
|
// src/shared/types.ts
|
|
175
306
|
/** Where a team's flag is: at its base, on a carrier's back, or on the ground where it was dropped. */
|
|
176
307
|
var FLAG = {
|
|
@@ -211,7 +342,9 @@ var KEY = {
|
|
|
211
342
|
/** Press to swap the battery or the capsule of the gun in hand (see GUN_MAG). */
|
|
212
343
|
RELOAD: 4096,
|
|
213
344
|
/** Set while the player wants the laser rifle in hand (4 or the wheel), with BLADE and RAIL clear. Ignored without it. */
|
|
214
|
-
RIFLE: 8192
|
|
345
|
+
RIFLE: 8192,
|
|
346
|
+
/** Press to get into the rover at hand, or out of the one he rides. */
|
|
347
|
+
USE: 16384
|
|
215
348
|
};
|
|
216
349
|
/**
|
|
217
350
|
* The katana's cuts (PlayerState.cut, constants CUTS), chosen by the keys held when FIRE starts
|
|
@@ -258,7 +391,9 @@ var MODE = {
|
|
|
258
391
|
/** Sliding on the ground, low. */
|
|
259
392
|
SLIDE: 5,
|
|
260
393
|
/** Walking low. */
|
|
261
|
-
CROUCH: 6
|
|
394
|
+
CROUCH: 6,
|
|
395
|
+
/** Seated in a rover (rover.ts): the body follows the seat, move() leaves it there. */
|
|
396
|
+
RIDE: 7
|
|
262
397
|
};
|
|
263
398
|
/**
|
|
264
399
|
* Which side of the player a wall or a ledge is on (PlayerState.wall). In the air it is the side
|
|
@@ -320,19 +455,24 @@ var OFF = 1024;
|
|
|
320
455
|
/** The key of the cell with integer coordinates (cx, cz). */
|
|
321
456
|
var key = (cx, cz) => (cx + OFF) * (2 * OFF) + cz + OFF;
|
|
322
457
|
/** Integer cell coordinate of a metre value, clamped to the keyed range. */
|
|
323
|
-
var at = (v, cell) => Math.min(Math.max(Math.floor(v / cell), -1024), 1023);
|
|
458
|
+
var at$1 = (v, cell) => Math.min(Math.max(Math.floor(v / cell), -1024), 1023);
|
|
324
459
|
/** Builds the grid: each brush is listed in every cell its footprint covers. */
|
|
325
460
|
var build = (def, cell = CELL) => {
|
|
326
461
|
const grid = /* @__PURE__ */ new Map();
|
|
327
462
|
def.brushes.forEach(({ min, max }, i) => {
|
|
328
|
-
for (let cx = at(min[0], cell); cx <= at(max[0], cell); cx++) for (let cz = at(min[2], cell); cz <= at(max[2], cell); cz++) {
|
|
463
|
+
for (let cx = at$1(min[0], cell); cx <= at$1(max[0], cell); cx++) for (let cz = at$1(min[2], cell); cz <= at$1(max[2], cell); cz++) {
|
|
329
464
|
const k = key(cx, cz);
|
|
330
465
|
const list = grid.get(k);
|
|
331
466
|
if (list) list.push(i);
|
|
332
467
|
else grid.set(k, [i]);
|
|
333
468
|
}
|
|
334
469
|
});
|
|
335
|
-
return {
|
|
470
|
+
return def.relief ? {
|
|
471
|
+
def,
|
|
472
|
+
cell,
|
|
473
|
+
grid,
|
|
474
|
+
relief: raise(def.relief)
|
|
475
|
+
} : {
|
|
336
476
|
def,
|
|
337
477
|
cell,
|
|
338
478
|
grid
|
|
@@ -344,24 +484,31 @@ var build = (def, cell = CELL) => {
|
|
|
344
484
|
*/
|
|
345
485
|
var near = (w, x, z, r) => {
|
|
346
486
|
const out = [];
|
|
347
|
-
for (let cx = at(x - r, w.cell); cx <= at(x + r, w.cell); cx++) for (let cz = at(z - r, w.cell); cz <= at(z + r, w.cell); cz++) for (const i of w.grid.get(key(cx, cz)) ?? []) if (!out.includes(i)) out.push(i);
|
|
487
|
+
for (let cx = at$1(x - r, w.cell); cx <= at$1(x + r, w.cell); cx++) for (let cz = at$1(z - r, w.cell); cz <= at$1(z + r, w.cell); cz++) for (const i of w.grid.get(key(cx, cz)) ?? []) if (!out.includes(i)) out.push(i);
|
|
348
488
|
return out;
|
|
349
489
|
};
|
|
350
490
|
/**
|
|
351
|
-
* Distance along the ray from o in the unit direction d to the first brush face
|
|
352
|
-
* that starts inside a brush hits at 0; one that starts on a face
|
|
491
|
+
* Distance along the ray from o in the unit direction d to the first brush face or to the ground of
|
|
492
|
+
* the relief, at most max. A ray that starts inside a brush hits at 0; one that starts on a face
|
|
493
|
+
* and moves away from it does not hit it.
|
|
353
494
|
* With `grow`, every brush is that much bigger on each side: the path of a sphere of that radius
|
|
354
495
|
* (its corners square, and a brush is only found in the cells the ray crosses).
|
|
355
|
-
*
|
|
356
|
-
* Walks the grid cells the ray crosses (Amanatides and Woo), testing the brushes of each against
|
|
357
|
-
* the exact slab test, and stops once the next cell starts beyond the best hit or max. A brush
|
|
358
|
-
* spanning several cells is tested in each: the hit is the same, and lists are short.
|
|
359
496
|
*/
|
|
360
497
|
var ray = (w, o, d, max, grow = 0) => {
|
|
498
|
+
const hit = faces(w, o, d, max, grow);
|
|
499
|
+
return w.relief ? trace(w, o, d, hit, grow) : hit;
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* The brushes' share of ray(). Walks the grid cells the ray crosses (Amanatides and Woo), testing
|
|
503
|
+
* the brushes of each against the exact slab test, and stops once the next cell starts beyond the
|
|
504
|
+
* best hit or max. A brush spanning several cells is tested in each: the hit is the same, and
|
|
505
|
+
* lists are short.
|
|
506
|
+
*/
|
|
507
|
+
var faces = (w, o, d, max, grow) => {
|
|
361
508
|
const { cell, def } = w;
|
|
362
509
|
let best = max;
|
|
363
|
-
let cx = at(o[0], cell);
|
|
364
|
-
let cz = at(o[2], cell);
|
|
510
|
+
let cx = at$1(o[0], cell);
|
|
511
|
+
let cz = at$1(o[2], cell);
|
|
365
512
|
const sx = Math.sign(d[0]);
|
|
366
513
|
const sz = Math.sign(d[2]);
|
|
367
514
|
const nx = sx ? ((cx + (sx > 0 ? 1 : 0)) * cell - o[0]) / d[0] : Infinity;
|
|
@@ -545,10 +692,12 @@ var gap = (b, x, z) => [x - clamp(x, b.min[0], b.max[0]), z - clamp(z, b.min[2],
|
|
|
545
692
|
* step of that size cannot bring the centre across one, however thin. The candidates come from
|
|
546
693
|
* near() with twice PLAYER_R, enough for the one push of at most PLAYER_R that matters.
|
|
547
694
|
*/
|
|
548
|
-
var push = (p, w, h) =>
|
|
695
|
+
var push = (p, w, h) => shove(p, w, h, PLAYER_R);
|
|
696
|
+
/** push() for a circle of radius r: a rover's body is a few of them. */
|
|
697
|
+
var shove = (p, w, h, r) => {
|
|
549
698
|
const { brushes } = w.def;
|
|
550
|
-
const ids = near(w, p.x, p.z, 2 *
|
|
551
|
-
const reach = (
|
|
699
|
+
const ids = near(w, p.x, p.z, 2 * r);
|
|
700
|
+
const reach = (r - EPS) ** 2;
|
|
552
701
|
let [tx, tz] = [0, 0];
|
|
553
702
|
for (let pass = 0; pass < 4; pass++) {
|
|
554
703
|
let best = 0;
|
|
@@ -562,8 +711,8 @@ var push = (p, w, h) => {
|
|
|
562
711
|
if (d2 >= reach) continue;
|
|
563
712
|
if (d2) {
|
|
564
713
|
const d = sqrt(d2);
|
|
565
|
-
if (
|
|
566
|
-
best =
|
|
714
|
+
if (r - d > best) {
|
|
715
|
+
best = r - d;
|
|
567
716
|
px = dx / d * best;
|
|
568
717
|
pz = dz / d * best;
|
|
569
718
|
}
|
|
@@ -591,8 +740,8 @@ var push = (p, w, h) => {
|
|
|
591
740
|
1
|
|
592
741
|
]
|
|
593
742
|
].reduce((a, c) => c[0] < a[0] ? c : a);
|
|
594
|
-
if (m +
|
|
595
|
-
best = m +
|
|
743
|
+
if (m + r > best) {
|
|
744
|
+
best = m + r;
|
|
596
745
|
[px, pz] = [nx * best, nz * best];
|
|
597
746
|
}
|
|
598
747
|
}
|
|
@@ -615,7 +764,7 @@ var push = (p, w, h) => {
|
|
|
615
764
|
var span = (p, w, h) => {
|
|
616
765
|
const { brushes } = w.def;
|
|
617
766
|
const reach = (PLAYER_R - EPS) ** 2;
|
|
618
|
-
let floor =
|
|
767
|
+
let floor = ground(w, p.x, p.z);
|
|
619
768
|
let ceil = Infinity;
|
|
620
769
|
for (const i of near(w, p.x, p.z, PLAYER_R)) {
|
|
621
770
|
const b = brushes[i];
|
|
@@ -724,13 +873,13 @@ var over = (p, w) => {
|
|
|
724
873
|
});
|
|
725
874
|
};
|
|
726
875
|
/** The world's gravity: GRAVITY times the map's share (the moon's half gravity, the user, 2026-11-09). */
|
|
727
|
-
var
|
|
876
|
+
var gravity = (w) => 20 * (w.def.gravity ?? 1);
|
|
728
877
|
/** Whether the player will be back on a floor within the jump buffer: a press now is kept for it. */
|
|
729
878
|
var landingSoon = (p, w) => {
|
|
730
879
|
if (p.vy >= 0) return false;
|
|
731
880
|
const [floor] = span(p, w, PLAYER_H);
|
|
732
881
|
const t = 6 * DT;
|
|
733
|
-
return p.y - floor <= -p.vy * t + .5 *
|
|
882
|
+
return p.y - floor <= -p.vy * t + .5 * gravity(w) * t * t;
|
|
734
883
|
};
|
|
735
884
|
/** Changes the mode, and starts counting the time in it. */
|
|
736
885
|
var enter = (p, mode) => {
|
|
@@ -753,7 +902,7 @@ var stumble = (p, dx, dz, ticks = 48, knock = 6) => {
|
|
|
753
902
|
p.coyote = 0;
|
|
754
903
|
p.buffer = 0;
|
|
755
904
|
if (p.mode === MODE.HANG || p.mode === MODE.CLIMB) p.vy = 0;
|
|
756
|
-
if (p.mode === MODE.HANG || p.mode === MODE.CLIMB || p.mode === MODE.WALLRUN) {
|
|
905
|
+
if (p.mode === MODE.HANG || p.mode === MODE.CLIMB || p.mode === MODE.WALLRUN || p.mode === MODE.RIDE) {
|
|
757
906
|
enter(p, MODE.AIR);
|
|
758
907
|
p.edge = 0;
|
|
759
908
|
}
|
|
@@ -833,8 +982,9 @@ var fly$1 = (p, w, h, g, snap) => {
|
|
|
833
982
|
p.vz -= into * cz / d;
|
|
834
983
|
}
|
|
835
984
|
}
|
|
985
|
+
bound(p, w);
|
|
836
986
|
const [floor, ceil] = span(p, w, h);
|
|
837
|
-
const vy = p.vy - g *
|
|
987
|
+
const vy = p.vy - g * gravity(w) * DT;
|
|
838
988
|
p.y += (p.vy + vy) / 2 * DT;
|
|
839
989
|
p.vy = vy;
|
|
840
990
|
if (p.y + h > ceil) {
|
|
@@ -1098,11 +1248,12 @@ var move = (p, i, w, team = 0) => {
|
|
|
1098
1248
|
const [fx, fz] = forward(p.yaw);
|
|
1099
1249
|
const pressed = (bit) => (i.keys & bit) !== 0 && (p.held & bit) === 0;
|
|
1100
1250
|
const stumbling = p.stun > 0;
|
|
1251
|
+
const riding = p.mode === MODE.RIDE;
|
|
1101
1252
|
const c = {
|
|
1102
1253
|
keys: i.keys,
|
|
1103
1254
|
stumble: stumbling,
|
|
1104
|
-
jump: !stumbling && pressed(KEY.JUMP),
|
|
1105
|
-
dash: !stumbling && pressed(KEY.DASH),
|
|
1255
|
+
jump: !stumbling && !riding && pressed(KEY.JUMP),
|
|
1256
|
+
dash: !stumbling && !riding && pressed(KEY.DASH),
|
|
1106
1257
|
fwd: f > 0,
|
|
1107
1258
|
wx: (fx * f - fz * s) / n,
|
|
1108
1259
|
wz: (fz * f + fx * s) / n,
|
|
@@ -1120,7 +1271,7 @@ var move = (p, i, w, team = 0) => {
|
|
|
1120
1271
|
}
|
|
1121
1272
|
if (p.mode === MODE.HANG) hang(p, w, c);
|
|
1122
1273
|
if (p.mode === MODE.CLIMB) climb(p, w);
|
|
1123
|
-
else if (p.mode !== MODE.HANG) free(p, w, c);
|
|
1274
|
+
else if (p.mode !== MODE.HANG && !riding) free(p, w, c);
|
|
1124
1275
|
if (p.slow) {
|
|
1125
1276
|
p.slow--;
|
|
1126
1277
|
cap(p, 3);
|
|
@@ -1129,7 +1280,7 @@ var move = (p, i, w, team = 0) => {
|
|
|
1129
1280
|
p.t = p.mode === before ? Math.min(255, p.t + 1) : p.t;
|
|
1130
1281
|
p.buffer = Math.max(0, p.buffer - 1);
|
|
1131
1282
|
if (p.mode === MODE.AIR && before === MODE.AIR) p.coyote = Math.max(0, p.coyote - 1);
|
|
1132
|
-
p.held = i.keys & (KEY.JUMP | KEY.DASH);
|
|
1283
|
+
p.held = i.keys & (KEY.JUMP | KEY.DASH | KEY.USE);
|
|
1133
1284
|
p.ground = onFloor(p.mode);
|
|
1134
1285
|
p.x = f32(p.x);
|
|
1135
1286
|
p.y = f32(p.y);
|
|
@@ -1682,12 +1833,12 @@ var duel = (p, i) => {
|
|
|
1682
1833
|
var powerOf = (ticks) => ticks < 10 ? 1 : 1 + Math.floor(4 * (ticks - 10) / 50);
|
|
1683
1834
|
// src/shared/map.ts
|
|
1684
1835
|
/** The bottom of every building: far below the kill floor, so nothing shows beneath a roof. */
|
|
1685
|
-
var BASE = -30;
|
|
1836
|
+
var BASE$1 = -30;
|
|
1686
1837
|
/** A building: the footprint x0..x1 by z0..z1 from the street up to a flat roof at `top`, white concrete over a facade. */
|
|
1687
1838
|
var roof = (x0, z0, x1, z1, top, side = TEX.CONCRETE) => ({
|
|
1688
1839
|
min: [
|
|
1689
1840
|
x0,
|
|
1690
|
-
BASE,
|
|
1841
|
+
BASE$1,
|
|
1691
1842
|
z0
|
|
1692
1843
|
],
|
|
1693
1844
|
max: [
|
|
@@ -1885,7 +2036,7 @@ var pad = (x0, y0, z0, x1, y1, z1, tint) => box$1([
|
|
|
1885
2036
|
* A column of stairs: from `a` to `b` along `axis` (0 for x, 2 for z), across `w0` to `w1` on the
|
|
1886
2037
|
* other one, rising from `y` to `top` in steps of at most 0.46 m, each step a solid from `low`.
|
|
1887
2038
|
*/
|
|
1888
|
-
var stairs$1 = (axis, a, b, w0, w1, y, top, low = BASE) => {
|
|
2039
|
+
var stairs$1 = (axis, a, b, w0, w1, y, top, low = BASE$1) => {
|
|
1889
2040
|
const n = Math.ceil((top - y) / .46);
|
|
1890
2041
|
return Array.from({ length: n }, (_, i) => {
|
|
1891
2042
|
const [s0, s1] = [a + (b - a) * i / n, a + (b - a) * (i + 1) / n].sort((p, q) => p - q);
|
|
@@ -2101,7 +2252,7 @@ var half$1 = [
|
|
|
2101
2252
|
]
|
|
2102
2253
|
].map(([x0, z0, x1, z1, top]) => box$1([
|
|
2103
2254
|
x0,
|
|
2104
|
-
BASE,
|
|
2255
|
+
BASE$1,
|
|
2105
2256
|
z0
|
|
2106
2257
|
], [
|
|
2107
2258
|
x1,
|
|
@@ -2661,8 +2812,8 @@ var HIGHLINE = {
|
|
|
2661
2812
|
.0035
|
|
2662
2813
|
]
|
|
2663
2814
|
};
|
|
2664
|
-
|
|
2665
|
-
var {
|
|
2815
|
+
// src/shared/moonbase.ts
|
|
2816
|
+
var { CONCRETE: CONCRETE$1, METAL: METAL$1, STEEL: STEEL$1 } = TEX;
|
|
2666
2817
|
/** A box, corners (x0, y0, z0) and (x1, y1, z1), tops and sides, a tint. */
|
|
2667
2818
|
var box = (x0, y0, z0, x1, y1, z1, top, side = top, tint) => ({
|
|
2668
2819
|
min: [
|
|
@@ -2697,9 +2848,7 @@ var bx = (x0, y0, z0, x1, y1, z1) => ({
|
|
|
2697
2848
|
z1
|
|
2698
2849
|
]
|
|
2699
2850
|
});
|
|
2700
|
-
/** The
|
|
2701
|
-
var mirror = ({ min, max }) => bx(min[0], min[1], 280 - max[2], max[0], max[1], 280 - min[2]);
|
|
2702
|
-
/** The drawn dome (moonscape.ts): a drum of radius R up to y 5, then a shell to the apex at y 17. */
|
|
2851
|
+
/** The drawn dome (client/moonbase.ts): a drum of radius R up to y 5, then a shell to the apex at y 17. */
|
|
2703
2852
|
var R = 22.4;
|
|
2704
2853
|
var shell = (y) => y < 5 ? R : R * Math.sqrt(1 - ((y - 5) / 12) ** 2);
|
|
2705
2854
|
var q = (v) => Math.round(v * 10) / 10;
|
|
@@ -2723,16 +2872,44 @@ var around = (r) => [
|
|
|
2723
2872
|
[.39, 1]
|
|
2724
2873
|
].map(([a, b]) => [q(a * r), q(b * r)]);
|
|
2725
2874
|
var first = around(22.599999999999998);
|
|
2726
|
-
/**
|
|
2875
|
+
/** Red's dome (its centre: x, z), modules and tubes: what the scenery draws on. */
|
|
2727
2876
|
var DOME = [80, 236];
|
|
2877
|
+
var MODULES = [bx(111, 0, 222, 125, 5, 230), bx(96, 0, 196, 110, 5, 204)];
|
|
2878
|
+
var TUBES = [bx(DOME[0] + first[1][0], 0, DOME[1] - first[0][1] - 4, 111, 3.5, DOME[1] - first[0][1]), bx(98, 0, 204, 102, 3.5, DOME[1] - first[1][1])];
|
|
2879
|
+
/**
|
|
2880
|
+
* Stairs from `a` to `b` along z (axis 2) or x (0), across `w0` to `w1`, rising from `y` to `top`
|
|
2881
|
+
* in steps of at most 0.46 m, each a solid from `y`.
|
|
2882
|
+
*/
|
|
2883
|
+
var stairs = (axis, a, b, w0, w1, y, top) => {
|
|
2884
|
+
const n = Math.ceil((top - y) / .46);
|
|
2885
|
+
return Array.from({ length: n }, (_, i) => {
|
|
2886
|
+
const [s, t] = [a + (b - a) * i / n, a + (b - a) * (i + 1) / n].sort((p, q) => p - q);
|
|
2887
|
+
const up = y + (top - y) * (i + 1) / n;
|
|
2888
|
+
return axis ? box(w0, y, s, w1, up, t, CONCRETE$1) : box(s, y, w0, t, up, w1, CONCRETE$1);
|
|
2889
|
+
});
|
|
2890
|
+
};
|
|
2891
|
+
/** Red's half of the base. */
|
|
2892
|
+
var BASE = [
|
|
2893
|
+
...BANDS.slice(1).flatMap((y1, i) => around(shell(BANDS[i]) + .2).map(([a, b]) => ({
|
|
2894
|
+
...box(DOME[0] - a, BANDS[i], DOME[1] - b, DOME[0] + a, y1, DOME[1] + b, CONCRETE$1),
|
|
2895
|
+
ghost: true
|
|
2896
|
+
}))),
|
|
2897
|
+
...MODULES.map((m) => fromBx(m, METAL$1, CONCRETE$1)),
|
|
2898
|
+
...TUBES.map((t) => fromBx(t, STEEL$1, METAL$1)),
|
|
2899
|
+
...stairs(2, 214, TUBES[0].min[2], 105, 109, 0, 3.5),
|
|
2900
|
+
...stairs(0, 108, 102, 206, 210, 0, 3.5)
|
|
2901
|
+
];
|
|
2902
|
+
var [RED, BLUE] = TEAM_TINT;
|
|
2903
|
+
var { STONE, CONCRETE, METAL, STEEL, PAINT } = TEX;
|
|
2904
|
+
/** The twin of a box across the centre line. */
|
|
2905
|
+
var mirror = ({ min, max }) => bx(min[0], min[1], 280 - max[2], max[0], max[1], 280 - min[2]);
|
|
2906
|
+
/** The domes' centres, the landing pads (x, z, radius), the shuttles, the modules, the tubes and the masts (centres), red's then blue's: what the scenery draws on. */
|
|
2728
2907
|
var PAD = [
|
|
2729
2908
|
40,
|
|
2730
2909
|
220,
|
|
2731
2910
|
13
|
|
2732
2911
|
];
|
|
2733
2912
|
var SHUTTLE = bx(33, .25, 218, 47, 3.25, 222);
|
|
2734
|
-
var MODULES = [bx(111, 0, 222, 125, 5, 230), bx(96, 0, 196, 110, 5, 204)];
|
|
2735
|
-
var TUBES = [bx(DOME[0] + first[1][0], 0, DOME[1] - first[0][1] - 4, 111, 3.5, DOME[1] - first[0][1]), bx(98, 0, 204, 102, 3.5, DOME[1] - first[1][1])];
|
|
2736
2913
|
var MASTS = [
|
|
2737
2914
|
[27.3, 207.3],
|
|
2738
2915
|
[52.7, 207.3],
|
|
@@ -2741,19 +2918,173 @@ var MASTS = [
|
|
|
2741
2918
|
[106.2, 230.4],
|
|
2742
2919
|
[103.2, 212.4]
|
|
2743
2920
|
];
|
|
2744
|
-
|
|
2921
|
+
var c1 = (t) => Math.min(Math.max(t, 0), 1);
|
|
2922
|
+
var sm = (t) => c1(t) * c1(t) * (3 - 2 * c1(t));
|
|
2923
|
+
var far = (a, b) => Math.sqrt(a * a + b * b);
|
|
2924
|
+
/** Craters, x, z, radius: a bowl 0.19 of the radius deep under a rim 0.06 of it high, flat for 4 m. The first is the Bowl. */
|
|
2925
|
+
var BOWLS = [
|
|
2926
|
+
[
|
|
2927
|
+
-100,
|
|
2928
|
+
0,
|
|
2929
|
+
46
|
|
2930
|
+
],
|
|
2931
|
+
[
|
|
2932
|
+
20,
|
|
2933
|
+
215,
|
|
2934
|
+
22
|
|
2935
|
+
],
|
|
2936
|
+
[
|
|
2937
|
+
110,
|
|
2938
|
+
236,
|
|
2939
|
+
16
|
|
2940
|
+
],
|
|
2941
|
+
[
|
|
2942
|
+
-112,
|
|
2943
|
+
108,
|
|
2944
|
+
14
|
|
2945
|
+
],
|
|
2946
|
+
[
|
|
2947
|
+
236,
|
|
2948
|
+
170,
|
|
2949
|
+
13
|
|
2950
|
+
],
|
|
2951
|
+
[
|
|
2952
|
+
-28,
|
|
2953
|
+
228,
|
|
2954
|
+
12
|
|
2955
|
+
]
|
|
2956
|
+
];
|
|
2957
|
+
/** Jump ramps, where the rise starts and the unit way up: 16 m long, 5.6 m high (19 degrees), 12 m wide, the lip flat for 4 m (no knife edge under a rover). */
|
|
2958
|
+
var RAMPS = [
|
|
2959
|
+
[
|
|
2960
|
+
-20,
|
|
2961
|
+
0,
|
|
2962
|
+
-1,
|
|
2963
|
+
0
|
|
2964
|
+
],
|
|
2965
|
+
[
|
|
2966
|
+
192,
|
|
2967
|
+
124,
|
|
2968
|
+
0,
|
|
2969
|
+
-1
|
|
2970
|
+
],
|
|
2971
|
+
[
|
|
2972
|
+
64,
|
|
2973
|
+
236,
|
|
2974
|
+
1,
|
|
2975
|
+
0
|
|
2976
|
+
],
|
|
2977
|
+
[
|
|
2978
|
+
-60,
|
|
2979
|
+
100,
|
|
2980
|
+
0,
|
|
2981
|
+
1
|
|
2982
|
+
]
|
|
2983
|
+
];
|
|
2984
|
+
/** The ridge east of the arena (x, the z its crest ends at) and the antennas' hill south-east (x, z). */
|
|
2985
|
+
var [RIDGE, HILL] = [[248, 64], [180, 200]];
|
|
2986
|
+
/** The boulder field south-west: x, z, radius. */
|
|
2987
|
+
var FIELD = [
|
|
2988
|
+
[
|
|
2989
|
+
0,
|
|
2990
|
+
0,
|
|
2991
|
+
4.5
|
|
2992
|
+
],
|
|
2993
|
+
[
|
|
2994
|
+
-14,
|
|
2995
|
+
6,
|
|
2996
|
+
3
|
|
2997
|
+
],
|
|
2998
|
+
[
|
|
2999
|
+
10,
|
|
3000
|
+
-12,
|
|
3001
|
+
3.5
|
|
3002
|
+
],
|
|
3003
|
+
[
|
|
3004
|
+
16,
|
|
3005
|
+
10,
|
|
3006
|
+
2.5
|
|
3007
|
+
],
|
|
3008
|
+
[
|
|
3009
|
+
-8,
|
|
3010
|
+
-16,
|
|
3011
|
+
2.2
|
|
3012
|
+
],
|
|
3013
|
+
[
|
|
3014
|
+
-20,
|
|
3015
|
+
-8,
|
|
3016
|
+
3.8
|
|
3017
|
+
],
|
|
3018
|
+
[
|
|
3019
|
+
6,
|
|
3020
|
+
18,
|
|
3021
|
+
3
|
|
3022
|
+
],
|
|
3023
|
+
[
|
|
3024
|
+
22,
|
|
3025
|
+
-4,
|
|
3026
|
+
2
|
|
3027
|
+
],
|
|
3028
|
+
[
|
|
3029
|
+
-12,
|
|
3030
|
+
20,
|
|
3031
|
+
2.4
|
|
3032
|
+
]
|
|
3033
|
+
].map(([x, z, r]) => [
|
|
3034
|
+
x - 50,
|
|
3035
|
+
z + 330,
|
|
3036
|
+
r
|
|
3037
|
+
]);
|
|
3038
|
+
/** The three dishes on the hill and the lander wrecked in the Bowl. */
|
|
3039
|
+
var DISHES = [
|
|
3040
|
+
[180, 340],
|
|
3041
|
+
[173, 346],
|
|
3042
|
+
[186, 347]
|
|
3043
|
+
];
|
|
3044
|
+
var WRECK = [BOWLS[0][0], 140];
|
|
2745
3045
|
/**
|
|
2746
|
-
*
|
|
2747
|
-
*
|
|
3046
|
+
* The height of the crater floor round the arena. Only + - * /, Math.sqrt, Math.abs, min, max, floor
|
|
3047
|
+
* and the integer hash: every engine builds the same lattice. Exactly 0 for 12 m round the arena
|
|
3048
|
+
* (a rectangle on lattice lines, so between the nodes too); rolling hills, the pieces above, then the crater wall: it starts 0.78 of the way to the bound,
|
|
3049
|
+
* is 20 m high on it and, past it where nobody goes, climbs to a ragged crest of 60 to 95 m and
|
|
3050
|
+
* falls to the plain at 1.65 of the bound.
|
|
2748
3051
|
*/
|
|
2749
|
-
var
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
3052
|
+
var at = (x, z) => {
|
|
3053
|
+
z = Math.abs(z - 140);
|
|
3054
|
+
const k = far((x - 80) / 300, z / 360);
|
|
3055
|
+
const t = Math.max((k - .78) / .22, 0);
|
|
3056
|
+
let h = sm((Math.max(Math.abs(x - 80) - 80, z - 140) - 12) / 48) * (1 - .7 * sm(t)) * (16 * noise(x / 96, z / 96, 1) + 5 * noise(x / 36, z / 36, 2) + 1.4 * noise(x / 22, z / 22, 3) - 11.2);
|
|
3057
|
+
for (const [cx, cz, r] of BOWLS) {
|
|
3058
|
+
const q = far(x - cx, z - cz) / r;
|
|
3059
|
+
const s = 1 - c1((q - 1 - 4 / r) / .6);
|
|
3060
|
+
h += r * (q < 1 ? .25 * q * q - .19 : .06 * s * s);
|
|
3061
|
+
}
|
|
3062
|
+
for (const [rx, rz, ax, az] of RAMPS) {
|
|
3063
|
+
const [p, q] = [x - rx, z - rz];
|
|
3064
|
+
const a = p * ax + q * az;
|
|
3065
|
+
h += 5.6 * c1(Math.min(a / 16, (32 - a) / 12)) * c1((18 - Math.abs(p * az - q * ax)) / 12);
|
|
3066
|
+
}
|
|
3067
|
+
const d = c1(far(x - RIDGE[0], Math.max(z - RIDGE[1], 0)) / 36);
|
|
3068
|
+
h += 12 * (1 - d * d) * (1 - d * d) + 8 * sm((36 - far(x - HILL[0], z - HILL[1])) / 24);
|
|
3069
|
+
let w = 10 * t * (1 + t);
|
|
3070
|
+
if (k > 1) w = (w + (k - 1) * 60 * (Math.abs(2 * noise(x / 45, z / 45, 5) - 1) - .5)) * (1 + (k - 1) * (1.2 * noise(x / 90, z / 90, 7) - .6)) * (1 - sm((k - 1.25) / .4));
|
|
3071
|
+
return h + w;
|
|
2756
3072
|
};
|
|
3073
|
+
/** The ghost under a drawn rock or mast: a box of half side s from under the ground to h above it. */
|
|
3074
|
+
var lump = (x, z, s, h) => ({
|
|
3075
|
+
...box(x - s, at(x, z) - 6, z - s, x + s, at(x, z) + h, z + s, STONE),
|
|
3076
|
+
ghost: true
|
|
3077
|
+
});
|
|
3078
|
+
[...FIELD, ...FIELD.map(([x, z, r]) => [
|
|
3079
|
+
x,
|
|
3080
|
+
280 - z,
|
|
3081
|
+
r
|
|
3082
|
+
])], [...DISHES, ...DISHES.map(([x, z]) => [x, 280 - z])], RAMPS.flatMap(([x, z, ax, az]) => (z ? [1, -1] : [1]).map((m) => [
|
|
3083
|
+
x + 16 * ax,
|
|
3084
|
+
140 + m * (z + 16 * az),
|
|
3085
|
+
ax,
|
|
3086
|
+
m * az + 0
|
|
3087
|
+
])), DOME[0], 280 - DOME[1], PAD[0], 280 - PAD[1], PAD[2], mirror(SHUTTLE), [...MODULES, ...MODULES.map(mirror)], [...TUBES, ...TUBES.map(mirror)], [...MASTS, ...MASTS.map(([x, z]) => [x, 280 - z])];
|
|
2757
3088
|
/** The twin of a brush, a point or a spawn across the centre line. */
|
|
2758
3089
|
var flip = (b) => ({
|
|
2759
3090
|
...b,
|
|
@@ -2783,10 +3114,7 @@ var both = (l, ...mid) => [
|
|
|
2783
3114
|
/** Red's half: z from 140 to 280. */
|
|
2784
3115
|
var half = [
|
|
2785
3116
|
box(0, -30, 148, 160, 0, 280, STONE),
|
|
2786
|
-
...
|
|
2787
|
-
...box(DOME[0] - a, BANDS[i], DOME[1] - b, DOME[0] + a, y1, DOME[1] + b, CONCRETE),
|
|
2788
|
-
ghost: true
|
|
2789
|
-
}))),
|
|
3117
|
+
...BASE,
|
|
2790
3118
|
box(74, 0, 199, 86, .5, 211, PAINT, CONCRETE, RED),
|
|
2791
3119
|
box(76, .5, 201, 84, 1, 209, PAINT, CONCRETE, RED),
|
|
2792
3120
|
box(60, 0, 259, 70, 1.5, 265, STEEL, PAINT, RED),
|
|
@@ -2799,10 +3127,6 @@ var half = [
|
|
|
2799
3127
|
.88
|
|
2800
3128
|
]
|
|
2801
3129
|
},
|
|
2802
|
-
...MODULES.map((m) => fromBx(m, METAL, CONCRETE)),
|
|
2803
|
-
...TUBES.map((t) => fromBx(t, STEEL, METAL)),
|
|
2804
|
-
...stairs(2, 214, TUBES[0].min[2], 105, 109, 0, 3.5),
|
|
2805
|
-
...stairs(0, 108, 102, 206, 210, 0, 3.5),
|
|
2806
3130
|
...MASTS.map(([x, z]) => box(x - .2, x < 60 ? .25 : 0, z - .2, x + .2, x < 60 ? 10.25 : 10, z + .2, STEEL)),
|
|
2807
3131
|
box(12, -30, 148 - 2.5 / 2, 24, 0, 148, PAINT, STONE, [
|
|
2808
3132
|
1,
|
|
@@ -2852,9 +3176,11 @@ var half = [
|
|
|
2852
3176
|
4,
|
|
2853
3177
|
2.4
|
|
2854
3178
|
]
|
|
2855
|
-
].map(([x, z, w, d, h]) => box(x, 0, z, x + w, h, z + d, STONE))
|
|
3179
|
+
].map(([x, z, w, d, h]) => box(x, 0, z, x + w, h, z + d, STONE)),
|
|
3180
|
+
...FIELD.map(([x, z, r]) => lump(x, z, .6 * r, .6 * r)),
|
|
3181
|
+
...DISHES.map(([x, z]) => lump(x, z, .4, 6))
|
|
2856
3182
|
];
|
|
2857
|
-
/** What stands on the centre line, symmetric as written: the bridge, the stones and the
|
|
3183
|
+
/** What stands on the centre line, symmetric as written: the bridge, the stones, the rille's plugs and the wreck. */
|
|
2858
3184
|
var centre = [
|
|
2859
3185
|
box(74, -1.5, 132, 86, 0, 148, METAL, STEEL),
|
|
2860
3186
|
box(74, 0, 132, 74.4, 1.1, 148, CONCRETE),
|
|
@@ -2862,15 +3188,15 @@ var centre = [
|
|
|
2862
3188
|
box(126, -30, 143, 131, 1.2, 147, STONE),
|
|
2863
3189
|
box(130, -30, 138.5, 135, 2.4, 141.5, STONE),
|
|
2864
3190
|
box(126, -30, 133, 131, 1.2, 137, STONE),
|
|
2865
|
-
|
|
2866
|
-
box(-10, -30,
|
|
2867
|
-
box(160, -30, -10, 170, 14, 290, STONE),
|
|
2868
|
-
box(0, -30, -10, 160, 14, 0, STONE),
|
|
2869
|
-
box(0, -30, 280, 160, 14, 290, STONE)
|
|
2870
|
-
].map((b) => ({
|
|
2871
|
-
...b,
|
|
3191
|
+
{
|
|
3192
|
+
...box(-10, -30, 132, 0, 0, 148, STONE),
|
|
2872
3193
|
ghost: true
|
|
2873
|
-
}
|
|
3194
|
+
},
|
|
3195
|
+
{
|
|
3196
|
+
...box(160, -30, 132, 170, 0, 148, STONE),
|
|
3197
|
+
ghost: true
|
|
3198
|
+
},
|
|
3199
|
+
lump(WRECK[0], WRECK[1], 3, 3)
|
|
2874
3200
|
];
|
|
2875
3201
|
/** Red's spawns behind the dome facing blue (yaw 0 looks toward -z): five in a row, three in front. */
|
|
2876
3202
|
var SPAWNS = [...[
|
|
@@ -2994,6 +3320,22 @@ var MAPS = {
|
|
|
2994
3320
|
140
|
|
2995
3321
|
]),
|
|
2996
3322
|
floor: -20,
|
|
3323
|
+
relief: {
|
|
3324
|
+
hole: [
|
|
3325
|
+
0,
|
|
3326
|
+
0,
|
|
3327
|
+
160,
|
|
3328
|
+
280
|
|
3329
|
+
],
|
|
3330
|
+
bound: [
|
|
3331
|
+
80,
|
|
3332
|
+
140,
|
|
3333
|
+
300,
|
|
3334
|
+
360
|
|
3335
|
+
],
|
|
3336
|
+
cell: 4,
|
|
3337
|
+
at
|
|
3338
|
+
},
|
|
2997
3339
|
sun: {
|
|
2998
3340
|
dir: [
|
|
2999
3341
|
.87996,
|
|
@@ -3148,7 +3490,7 @@ var decodeInput = (buf) => {
|
|
|
3148
3490
|
if (v.getUint8(0) !== 1) return null;
|
|
3149
3491
|
return {
|
|
3150
3492
|
seq: v.getUint16(1),
|
|
3151
|
-
keys: v.getUint16(3) &
|
|
3493
|
+
keys: v.getUint16(3) & 32767,
|
|
3152
3494
|
yaw: fromTurn(v.getUint16(5)),
|
|
3153
3495
|
pitch: fromPitch(v.getInt16(7)),
|
|
3154
3496
|
view: (v.getUint16(9) * 256 + v.getUint8(11)) / 256
|