diff --git a/build/notes.mjs b/build/notes.mjs index bac001848..b2f41ee9d 100644 --- a/build/notes.mjs +++ b/build/notes.mjs @@ -3,6 +3,16 @@ // and once after an update ("What's new"). A PR adds its entry under the number it expects; the merge queue (tools/queue.mjs) // gives it the number it really gets and writes this file. export const NOTES = { + 486: { + ru: ["🌍 Одна земля для всех: высоту, на которой стоит нога, лапа или колесо, теперь находит один модуль. Раньше её искали 11 модулей, каждый по-своему, и ещё 18 циклов шли вниз по колонке блоков вручную: один знал наклон пандуса, другой нет, один проваливался сквозь воду, другой вставал на неё", + "🛣️ Что видно: перевернувшаяся машина лежит на наклонной поверхности пандуса, а не на клетке под ним; полицейская машина и грузовик ремонтников, появляясь под настилом моста, встают на настил, а не внутрь него (как уже умело такси); самолёт и машина вдали больше не считают траву и колосья полом", + "🧪 Новый тест ground.test: смысл на колонках, собранных вручную (ступень, стена, яма, брод, пандус, пещера под холмом, плита без места под ней), и 60 000 случайных колонок, где новый модуль обязан ответить так же, как прежние искатели, сохранённые в тесте дословно", + "🔎 Мест, где одно и то же сделано по-разному, стало 45 вместо 67. Счётчик циклов по колонке стал строже и нашёл ещё 7, которых раньше не видел: они следующие"], + en: ["🌍 One ground for everybody: the height a foot, a paw or a wheel stands on is now found by one module. Eleven modules used to look for it, each in its own way, and eighteen more loops walked down a column of blocks by hand: one knew the slope of a ramp and the next did not, one fell through water and the next stood on it", + "🛣️ What shows: a car that rolled over lies on the sloped top of a ramp, not on the cell under it; a police car and a builders' truck that appear under a bridge deck stand on the deck, not inside it (as the taxi already did); a plane and a car far away no longer take grass and crops for a floor", + "🧪 A new test, ground.test: the meaning on columns built by hand (a step, a wall, a pit, a ford, a ramp, a cave under a hill, a slab with no room under it), and 60,000 random columns where the new module must answer as the old finders did, kept in the test word for word", + "🔎 The places where one thing is done in different ways are down to 45 from 67. The counter of column loops got stricter and found 7 more it had not seen: they are next"], + }, 485: { ru: ["🚪 Такси открывает ту дверь, через которую ты садишься: тебе даётся свободное заднее место с твоей стороны, а вход и выход идут через проём двери этого места, а не сквозь кузов. Это общее правило для всех: жители у своих машин, полицейские и строители тоже садятся и выходят через дверь своего места, и она открывается", "🧩 Всё, что движется, теперь в одном реестре: у каждого тела одна физика и один агент, а особая работа такси, полиции и ремонтников идёт задачей поверх общего агента, без обхода правил. Что ещё идёт в обход, записано с тредом-владельцем, и тест-храповик не даёт этому расти", diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 2bcb9558f..49789161f 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -25,7 +25,7 @@ The layers of `src/game`, bottom up: | `30–39` | **The world generator**: blocks, terrain, land streaming, flora, settlements, roads, bridges, tunnels, rail, architecture, cultures, town plans, airports, squares | `31_terrain`, `32_land` (LodPool workers), `34_settle`, `35_roads`, `36_arch`, `37_urban`, `38_air` | | `40–50` | The house and its lot: house and villa plans, furniture, shops, venues, building interiors, the start-screen model | `40_house`, `41_villa`, `45_furnish`, `49_dwell` | | `59–69` | Catalog, item models, edit history, the quality controller | `60_lib`, `62_items`, `68_hist`, `69_quality` | -| `70–71` | The player and the shared core of the living world: walking/building, the Ent store, Lock, navigation, simulation radius | `70_walk`, `71_ent`, `71_lock`, `71_nav`, `71_sim` | +| `70–71` | The player and the shared core of the living world: walking/building, the Ent store, Lock, the ground, navigation, simulation radius | `70_walk`, `71_ent`, `71_lock`, `71_ground`, `71_nav`, `71_sim` | | `72–79` | **Living systems**, each its own rule set: animals, water life, drivers and vehicle classes, maps, street life, saves, seed, gestures, neighbours, VR, gravity, ferry, flood, townsfolk, planes, crashes, driving, sitting, events, fire, repairs, jets, lava, police, characters, taxi, trains, volcanoes… | `73_pilot`, `74_town`, `76_life`, `77_folk`, `78_drive`, `79_*` | | `80–83` | Catalog UI, multiplayer, voice, friends | `81_net`, `82_voice`, `83_pals` | | `90–99` | Start screen, the main loop | `90_ui_start`, `99_main` (`window.G`: the debug handle every test uses) | @@ -68,6 +68,10 @@ The layers of `src/game`, bottom up: - **Each feature adds `tools/.test.mjs`.** The runner `tools/test.mjs` discovers it by name; there is nothing to register. - Node tests (no browser) are preferred for generators and rules: load the code in a `vm` like `tools/gen/load.mjs` or `tools/city.mjs`. + - A node test that loads game files by a list of its own keeps a copy of what those files need, and the copy rots without a word + (build 485: `10_vox.js` began to read a constant of `09_core.js`, and four tests that listed the one without the other threw + before their first check, on main, unseen). `tools/srclist.test.mjs` reads every such list in `tools/` and fails when a listed + file needs at load time a name that no listed file declares and the test does not stand in for. - Browser tests use puppeteer on the built `index.html`; import `./chrome.mjs` before puppeteer. Wait for frames or for state, never for fixed sleeps (cloud machines draw at ~1 fps). - Split a test over ~5 minutes into pieces: `// @parts VAR=a,b,c` in its first lines (one CI job per piece). @@ -193,9 +197,25 @@ General rules that come out of Anton's remarks and measurements. Each names the of a drive), police officers and builders all use it; what differs is only who decides when. A taxi gives the free back seat nearest the player, so the door that opens is the one on their side. `tools/board.test.mjs` checks the geometry, the door and the taxi seat on a car turned four ways, and that no file takes a person out of a vehicle without it. +- **The ground is asked in one place: `Ground` (`71_ground.js`).** The height a foot, a paw or a wheel stands on is found by + `Ground.at(x, z, y, o)` and nowhere else; no module walks down a column of blocks by itself. Who asks says what it needs as data, never + as code: `GROUND.walk` (a floor within a step or two, or the bottom of a pit; the default), `GROUND.fall`, `GROUND.roll`, `GROUND.fly`, + `GROUND.hover` give how far up a floor still counts, how deep the search goes and what water is (waded, fallen into, passed, stood + on). Around it: `Ground.drop` and `Ground.top` answer in whole cells (where an animal or a nest is put), `Ground.land` is the + generator's answer where no blocks are made yet, `Ground.under` and `Ground.road` join the two for what comes from afar (a plane, a + police car that drives into view), and `Ground.cell / roof / room` are the kernel in whole cells for the searches that walk thousands + of columns (`Nav`, the walking grid of a lot, a driver's look ahead). So a rule about the ground is written once and holds for + everybody: the sloped top of a road ramp, no digging through a hill for the cave under it, a vehicle that is put somewhere never + under a slab with no room. A new body that stands on something adds a row to `GROUND` at most. `tools/ground.test.mjs` checks the + meaning on columns built by hand and asks the finders that were folded in, kept in the test as they were written, the same questions on + 60 000 random columns: a refactor of the ground may not change an answer by accident. - **The inventory is a test.** `tools/split.test.mjs` lists every second way still in the code by concept (`--list` prints it) and counts - inline ones (loops that scan a column down for the ground, places that integrate gravity). Their numbers live in + inline ones (loops that walk down a column of blocks, places that integrate gravity). Their numbers live in `tools/rules/ratchet.json` (`split.*`) and may only go down: fold a second way into the shared one, delete its entry, lower the number. + A way that was folded in is listed as `gone` and may not come back under its old name; the file of the shared way is the only one a + detector does not count. Nor may a test or a screenshot recipe still call it: they reach the game through `G` and short names of its + modules (`const T = G.Town`), which no check of the game's own source sees, so the same test reads every file of `tools/` for a call + of a `gone` function under any such name. ### Light diff --git a/docs/WASM_SPIKE.md b/docs/WASM_SPIKE.md index 540667f1b..063a61edd 100644 --- a/docs/WASM_SPIKE.md +++ b/docs/WASM_SPIKE.md @@ -148,7 +148,7 @@ Tools: `tools/wasm/town.prof.mjs` (CPU of the walk's frames without drawing: a t | Near chunks (greedy + AO) | already Rust (v167) and in a worker (v273): main thread 0.1 ms a frame on a fast ride | done | | Rust writes the 16-byte QMesh records itself (no `packQuads`) | same bytes on 1000 real chunks; 80 µs → 74 µs a chunk in the worker (7–10 %) | not merged | | A cache of 256 columns in front of `Land.col` | `lastCol` already answers 97 % of lookups: `solid` 20 ns, `get` 10 ns a query; the cache was slower | not merged | -| Vehicle voxel physics (`worldFree`, `buried`, `Town.ground`, `shove`) in WASM | 0.2 ms a frame in a still town, 0.6 ms with 40 cars, 1 ms on a taxi ride with 8 moving (about 0.1 ms per moving vehicle); `Town.ground` 0.4 µs a call | not worth it: the queries need the voxels in JS, a whole-kernel port saves < 0.5 ms a frame | +| Vehicle voxel physics (`worldFree`, `buried`, `Ground.at`, `shove`) in WASM | 0.2 ms a frame in a still town, 0.6 ms with 40 cars, 1 ms on a taxi ride with 8 moving (about 0.1 ms per moving vehicle); `Town.ground` 0.4 µs a call | not worth it: the queries need the voxels in JS, a whole-kernel port saves < 0.5 ms a frame | | **Item models (cars, people, catalog) in Rust: `mesh_box`** | same quads for 1121 items, 300 car looks, 96 people; mesher **2.58× in V8, 1.59× in JSC**; a car model when it first drives in: **14.3 → 9.2 ms (−35 %)** on the main thread | **merged** | Costs of the merge: `homy_core.wasm` +3.6 KB (bundle +4 KB gzip), a scratch block in the core's memory that grows to the biggest model diff --git a/index.html b/index.html index 727aab518..86f94903d 100644 --- a/index.html +++ b/index.html @@ -786,13 +786,13 @@
diff --git a/src/game/10_shape.js b/src/game/10_shape.js index 799798c4b..b6878cc96 100644 --- a/src/game/10_shape.js +++ b/src/game/10_shape.js @@ -9,7 +9,7 @@ // A shape lives in the palette: its colour is written '#rrggbb/c' with the shape code c, so the saves, the network, the far workers and // every map from one palette to another carry the shape with no change (hex2rgb stops at the '/'). In the land a shaped block is // see-through to the light (transp 3) and not solid (Land.solid): the walkers and the wheels stand on its top through Shape.top -// (Town.ground, Drive.floor, Walk.moveStep), everything else sees the ground cell under it as the floor, as before. +// (Ground.at in 71_ground.js, Walk.moveStep), everything else sees the ground cell under it as the floor, as before. // The mesher of the land cuts the shaped blocks out of the padded chunk before the greedy mesher (JS, Rust or the worker) sees it and draws // them as vertices of their own (QMesh.sm, the same path as the sloped faces of far tiles). // the corners of each code: a (x 0, z 0), b (x 1, z 0), c (x 0, z 1), d (x 1, z 1), in quarters of a cell diff --git a/src/game/71_ground.js b/src/game/71_ground.js new file mode 100644 index 000000000..f44b7683a --- /dev/null +++ b/src/game/71_ground.js @@ -0,0 +1,81 @@ +// ---------- the ground: the one finder of the height a foot, a paw or a wheel stands on ---------- +// One concept, one way (docs/ARCHITECTURE.md): until build 486 eleven modules had a finder of their own (Town.ground, Drive.floor, Drive.bed, +// Fauna.drop, Roll.top, Arm.floor, Art.floor, Law.ground, Taxi.gnd, Nest.top, Rotor.top) and eighteen loops walked down a column by hand. +// They differed in small ways nobody had chosen: one knew the sloped top of a road ramp and the next did not, one fell through water and the +// next stood on it, one gave up inside a hill and the next dug on for a cave under it. Now the column is walked here and nowhere else +// (tools/split.test.mjs counts such loops in every other file and its number may only go down), and who asks says what it needs as data: +// +// Ground.at(x, z, y, o) the height to stand at near y, as a number of cells with a fraction on a ramp; null: nothing to stand on +// Ground.drop(x, z, y, n) the floor cell at or under y within n cells (whole cells, water passed through, no ramp tops); null +// Ground.top(x, z, y, n) the top of whatever is there under y within n cells (a crown, a roof, the land), also from inside it; null +// Ground.sky(X, Z) the top of the whole loaded column; -1: empty +// Ground.land(x, z) the generator's answer where nothing is built yet: the land or the water level +// Ground.under(x, z, y) what a flyer comes down on, what a vehicle seen from afar stands on: at() with GROUND.fly, else the land +// Ground.road(x, z, y) the same for a car or a person on the roads, with the bridge decks when it is put there (no y) +// Ground.cell / roof / room the kernel in whole cells of a given world, for the searches that walk thousands of columns (Nav, Life, Pilot) +// +// What the one who asks needs (cells): up — how far over y a floor still counts; near — how far under y a floor is taken as it is (a step +// or two down); down — how deep the search goes on from there, as a fall: in a fall the inside of the ground ends it (null: no digging for +// a cave under a hill) and so does water, unless wet says otherwise: 1 — water is passed (the bed under it), 2 — its surface is the floor +// (wings, hulls, what is seen from afar), 3 — water anywhere under it means no floor at all. +const GROUND = { + walk: { up: 3, near: 6, down: 72, wet: 0 }, // feet and wheels on the streets (the default): a floor within a step or two, or the bottom of a pit + fall: { up: 0, near: 0, down: 71, wet: 0 }, // nothing under the feet: the first floor straight below + roll: { up: 2, near: 40, down: 40, wet: 3 }, // a vehicle rolling over: any floor under it, never one in water + fly: { up: 2, near: 70, down: 70, wet: 2 }, // from the air and from afar: the land, a roof, the water + hover: { up: 0, near: 300, down: 300, wet: 2 }, // from high up (a saucer over the land): the same, as deep as it flies +}; +const Ground = { + // ---- the kernel: whole cells of world w ---- + // the feet level of column (X, Z) from `top` down to `bot`: the highest free cell with a solid one under it and, with `room`, that many + // free cells in all (a floor with less is passed); -1: none + cell(w, X, Z, top, bot, room) { for (let Y = top; Y >= bot; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z) && (!room || this.room(w, X, Y, Z, room))) return Y; return -1; }, + // the top of the highest solid cell from `top` down to `bot` (the cell over it); -1: none + roof(w, X, Z, top, bot) { for (let Y = top; Y >= bot; Y--) if (w.solid(X, Y, Z)) return Y + 1; return -1; }, + // is a body hh cells tall free over floor cell Y (the cell itself is)? + room(w, X, Y, Z, hh) { for (let k = 1; k < hh; k++) if (w.solid(X, Y + k, Z)) return false; return true; }, + // ---- the height to stand at ---- + at(x, z, y, o) { + if (!o) o = GROUND.walk; + const w = Walk.w, X = Math.floor(x), Z = Math.floor(z), wet = o.wet, deep = y - o.near; + for (let Y = Math.floor(y) + o.up, lo = y - o.down; Y > lo && Y > 0; Y--) { + if (w.solid(X, Y, Z)) { if (Y <= deep) return null; continue; } + if (w.solid(X, Y - 1, Z)) return Y + Shape.lift(w, x, Y, z); // on a road ramp: its sloped top (10_shape.js) + const id = w.get(X, Y - 1, Z); if (!id) continue; + if (w.shp && w.shp[id]) return Y - 1 + Shape.h(w.shp[id], x - X, z - Z); // a ramp block with nothing under it (the edge of a deck) + if (w.transp[id] === 2 && wet !== 1 && (wet > 1 || Y <= deep)) return wet === 2 ? Y : null; + } + return null; + }, + drop(x, z, y, n) { const Y = this.cell(Walk.w, Math.floor(x), Math.floor(z), Math.floor(y), Math.max(1, Math.floor(y - n) + 1)); return Y < 0 ? null : Y; }, + top(x, z, y, n) { const Y = this.roof(Walk.w, Math.floor(x), Math.floor(z), Math.floor(y) - 1, Math.max(0, Math.floor(y - n))); return Y < 0 ? null : Y; }, + sky(X, Z) { const w = Walk.w, ch = w.col(X >> 4, Z >> 4).ch; for (let cy = LNCY - 1; cy >= 0; cy--) if (ch[cy] !== 0) { const r = this.roof(w, X, Z, cy * 16 + 15, cy * 16); if (r >= 0) return r; } return -1; }, + // ---- where the blocks are not made yet ---- + // The land is asked at full detail (T.q 0): the far tiles leave a coarser T.q behind, and at a coarse step the road network and its + // decks are not looked up at all + land(x, z) { const T = Walk.w.T, q = T.q; T.q = 0; const h = Math.ceil(Math.max(T.at(x, z), WL)); T.q = q; return h; }, + under(x, z, y) { if (!Town.loaded(x, z)) return this.land(x, z); const g = this.at(x, z, y, GROUND.fly); return g == null ? y - 70 : g; }, + // The ground a car or a person of the roads stands on at (x, z): looked for from y down (where they are now), never below the land (one + // that arrives from the unbuilt far world may be under a slope, and a search from there would find nothing and sink it). Without y (one + // put there: it comes into view, it is brought back after a reload) from the highest way there is: a bridge deck of the road network + // (T.dk, the decks over the point, of the road that is there: not an overpass of another road; T.rdb is cleared again by what Terr.at lays + // after the decks, so it is not to be trusted here) or of the home street (T.deck: its deck is at LG, 32_land.js) over the land, not the + // river bed under it. + // room (by default: when it is put there): never a floor with no room over it. Without a height the floor is looked for at the generator's + // ground or water level, which under a deck (the street's bridge round an island) is the hollow under the slab: a car put there sat inside + // the deck, saw a wall in the road at every step and never got out. The same under a road's bridge over a river: a car that went on while + // the land there was not made yet took the water level, and with the blocks made it stood on the water under the deck. Such a floor is + // left for the first one above it with room (nothing hard from the wheels up to where the body starts: DRIVE_STEP + 1; leaves and rubble + // are not hard) + road(x, z, y, room) { + const w = Walk.w, T = w.T; let h = this.land(x, z); + if (y == null) { h = Math.max(h, T.deck(x, z, 0) ? LG : 0); if (T.dk) for (const e of T.dk) if (e.d <= e.r.w + 1 && (!T.rdr || e.r === T.rdr)) h = Math.max(h, Math.ceil(e.y)); } + if (!Town.loaded(x, z)) return h; + const s = Math.max(y != null ? y : h, h - 1), f = this.at(x, z, s, GROUND.fly), g = f != null && f > s - 60 ? f : h; + if (room == null ? y != null : !room) return g; + const X = Math.floor(x), Z = Math.floor(z), G = Math.floor(g), hard = Y => w.solid(X, Y, Z) && !CRASH_DUST[w.pm[w.get(X, Y, Z)]], free = Y => { for (let k = 0; k <= DRIVE_STEP + 1; k++) if (hard(Y + k)) return false; return true; }; + if (free(G)) return g; + for (let Y = G + 1; Y <= G + 16; Y++) if (hard(Y - 1) && free(Y)) return Y; + return g; + }, +}; diff --git a/src/game/71_nav.js b/src/game/71_nav.js index 3372f6376..53e0b1376 100644 --- a/src/game/71_nav.js +++ b/src/game/71_nav.js @@ -22,12 +22,8 @@ const Nav = { loaded(X, Z) { const c = this.w.cols.get(ckey(X >> 4, Z >> 4)); return !!c && c.ready; }, // the floor of a column around height y: the feet level, or -1 (a wall, a drop, no headroom, water deeper than one cell) feet(X, Z, y, o, j) { - const w = this.w, D = j && o.jd || o.dn; - for (let Y = y + (j && o.ju || o.up); Y >= y - D; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) { - for (let k = 1; k < o.hh; k++) if (w.solid(X, Y + k, Z)) return -1; - const id = w.get(X, Y + 1, Z); return id && w.transp[id] === 2 ? -1 : Y; - } - return -1; + const w = this.w, Y = Ground.cell(w, X, Z, y + (j && o.ju || o.up), y - (j && o.jd || o.dn)); if (Y < 0 || !Ground.room(w, X, Y, Z, o.hh)) return -1; + const id = w.get(X, Y + 1, Z); return id && w.transp[id] === 2 ? -1 : Y; }, // may a body stand at this point of the world (coming from height y)? free(x, z, y, o, j) { const X = Math.floor(x), Z = Math.floor(z); return !this.loaded(X, Z) || this.feet(X, Z, Math.floor(y + .01), o, j) >= 0; }, @@ -198,9 +194,7 @@ const Nav = { // the floor a body of profile pf can stand on in column (X, Z), coming from floor height y: up to `up` cells higher, down to 8 lower, // with room above it; -1 — none (a wall) stand(X, Z, y, pf, up) { - const w = this.w, hh = this.kh(pf); - for (let Y = y + up; Y >= y - 8; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) { for (let k = 1; k < hh; k++) if (w.solid(X, Y + k, Z)) return -1; return Y; } - return -1; + const w = this.w, Y = Ground.cell(w, X, Z, y + up, y - 8); return Y < 0 || !Ground.room(w, X, Y, Z, this.kh(pf)) ? -1 : Y; }, // is a body inside the blocks? (any solid cell from a cell above its feet up to its head: a foot that is sinking into a step it is // about to climb is not counted) @@ -296,8 +290,8 @@ const Nav = { // nothing under the feet of a kept place K: it comes down (24 cells a second) to the first floor below, within 72 cells; over water or // a bottomless hole it stays where it is fall(K, dt) { - const w = this.w, X = Math.floor(K.x), Z = Math.floor(K.z), y = Math.floor(K.y + .01); if (w.solid(X, y - 1, Z)) return; - for (let Y = y - 1; Y > y - 72 && Y > 0; Y--) { if (w.solid(X, Y, Z)) return; const id = w.get(X, Y - 1, Z); if (id && w.transp[id] === 2) return; if (w.solid(X, Y - 1, Z)) { K.y = Math.max(Y, K.y - Math.max(1, dt * 24)); return; } } + const y = Math.floor(K.y + .01); if (this.w.solid(Math.floor(K.x), y - 1, Math.floor(K.z))) return; + const g = Ground.at(K.x, K.z, y - 1, GROUND.fall); if (g != null) K.y = Math.max(g, K.y - Math.max(1, dt * 24)); }, // a resident off its plan goes after the place the plan gives (tx, tz) on foot, round whatever is in the way; when it is near and the // way to it is free, the plan has it again diff --git a/src/game/71_occ.js b/src/game/71_occ.js index 2d6b6e096..b8fa75721 100644 --- a/src/game/71_occ.js +++ b/src/game/71_occ.js @@ -141,7 +141,7 @@ const Occ = { // the height vehicle c rests at on (x, z): afloat at its draft, else on the ground under its middle (y0: the height it comes from) rest(c, x, z, y0) { if (this.hull(c)) { const wl = Walk.w.T.wl; return wl - (c.veh && c.veh.draft != null ? c.veh.draft : .45); } - const g = Town.ground(x, z, y0 != null ? y0 : c.y); return g == null ? null : g; + const g = Ground.at(x, z, y0 != null ? y0 : c.y); return g == null ? null : g; }, // ---- the nearest free pose: rings a cell apart up to o.R cells (24 by default), points along a ring a cell apart starting from the // heading of the vehicle, at each point the heading it has and then turned round; the vehicle is moved there. false: nowhere ---- @@ -212,8 +212,7 @@ const Occ = { const rr = ri / 2, n = ri ? Math.max(6, Math.ceil(TAU * rr * 2)) : 1; for (let k = 0; k < n; k++) { const a = k * TAU / n, px = x + Math.sin(a) * rr, pz = z + Math.cos(a) * rr; if (!Fauna.loaded(px, pz)) continue; - const X = Math.floor(px), Z = Math.floor(pz); let fy = null; - for (let Y = Math.floor(y) + 3; Y > y - 6; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) { fy = Y; break; } + const X = Math.floor(px), Z = Math.floor(pz), fy = Ground.drop(px, pz, y + 3, 9); if (fy == null || this.wet(w, X, fy, Z) && this.wet(w, X, fy + 1, Z)) continue; if (!this.foot(px, fy, pz, hh, r) && !this.onCar(px, fy, pz, hh)) return [px, fy, pz]; } diff --git a/src/game/72_aqua.js b/src/game/72_aqua.js index 5c2051a5c..7df9e2ef4 100644 --- a/src/game/72_aqua.js +++ b/src/game/72_aqua.js @@ -191,7 +191,7 @@ const Aqua = { if (!good()) { c.ex *= .8; c.ez *= .8; X = x + fx; Z = z + fz; this.probe(X, Z, o); if (!good()) { X = x; Z = z; this.probe(X, Z, o); } } if (s > 0) { const k = s * s * (3 - 2 * s), r = c.or * .6 + c.rad * (g.sh ? 1.6 : .5) * (c.ai ? 1 : 0); X = lerp(X, g.sx + Math.cos(c.oa) * r, k); Z = lerp(Z, g.sz + Math.sin(c.oa) * r, k); this.probe(X, Z, o); } const wl = o.wl, sea = o.w === 4 && o.d > 0, loaded = Fauna.loaded(X, Z), fh = Math.floor(o.h); - const ground = () => { const y = loaded ? Fauna.drop(X, fh + 4, Z) : null; return y == null ? fh : y; }; + const ground = () => { const y = loaded ? Ground.drop(X, Z, fh + 4, 14) : null; return y == null ? fh : y; }; // the layer let y, pit = 0, idle = stop || s > .6; let sw = 0; // the swell a deep body does not follow (it does when it comes up for air) diff --git a/src/game/72_fauna.js b/src/game/72_fauna.js index aad7d2b5d..2d7aee08a 100644 --- a/src/game/72_fauna.js +++ b/src/game/72_fauna.js @@ -76,14 +76,14 @@ const Fauna = { // a free floor cell in a rectangle (a few attempts: the spot may be taken by furniture) const put = (id, x0, z0, x1, z1) => { const it = L(id); if (!it) return; - for (let t = 0; t < 30; t++) { const x = x0 + Math.floor(Math.random() * (x1 - x0 + 1)), z = z0 + Math.floor(Math.random() * (z1 - z0 + 1)), y = this.drop(x, GY + ly + 2, z); if (y != null && y >= GY + ly && !this.w.solid(x, y + 1, z)) { this.adopt(it, x + .5, y, z + .5, Math.random() * TAU); return; } } + for (let t = 0; t < 30; t++) { const x = x0 + Math.floor(Math.random() * (x1 - x0 + 1)), z = z0 + Math.floor(Math.random() * (z1 - z0 + 1)), y = Ground.drop(x, z, GY + ly + 2, 14); if (y != null && y >= GY + ly && !this.w.solid(x, y + 1, z)) { this.adopt(it, x + .5, y, z + .5, Math.random() * TAU); return; } } }; const lv = room('living') || room('hall'); if (lv) put('pet_cat', m.ox + lv[2] + 3, m.oz + lv[3] + 3, m.ox + lv[4] - 3, m.oz + lv[5] - 3); const sx = Math.floor(m.spawn.x); put('pet_dog', sx + 5, 8, sx + 12, 20); // the dog gets a kennel next to the porch: it sleeps there at night const dog = this.list.find(c => c.it.id === 'pet_dog'), kn = Lib.byId.dog_house, w = this.w; if (dog && kn && kn.state === 2) for (let t = 0; t < 40; t++) { - const x = Math.floor(dog.x) - 8 + Math.floor(Math.random() * 14), z = 4 + Math.floor(Math.random() * 14), y = this.drop(x, GY + ly + 2, z); + const x = Math.floor(dog.x) - 8 + Math.floor(Math.random() * 14), z = 4 + Math.floor(Math.random() * 14), y = Ground.drop(x, z, GY + ly + 2, 14); if (y != null && y === GY + ly && w.canPlace(kn, x, y, z, 2, 0)) { w.addInst(makeInst(kn, x, y, z, 2)); dog.hx = x + 2.5; dog.hz = z - 2; dog.den = 1; Save.touch(); break; } } { const pd = this.w.lot && this.w.lot.meta.pond; if (pd) { for (let i = 0; i < 2; i++) put('duck', pd.x0 - 2, pd.z0 - 2, pd.x1 + 2, pd.z1 + 2); put('frog', pd.x0 - 2, pd.z0 - 2, pd.x1 + 2, pd.z1 + 2); } } @@ -92,8 +92,6 @@ const Fauna = { // ---- support and water ---- loaded(x, z) { const c = this.w.cols.get(ckey(Math.floor(x) >> 4, Math.floor(z) >> 4)); return !!c && c.ready; }, water(x, y, z) { const id = this.w.get(Math.floor(x), Math.floor(y), Math.floor(z)); return id !== 0 && this.w.transp[id] === 2; }, - // the first support going down from y (for placement); null — none - drop(x, y, z) { const w = this.w, X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y); Y > y - 14; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) return Y; return null; }, // where the feet land when stepping to (x, z) from height y: a number or null (a wall, a drop, deep water, a column that is not loaded) foot(c, x, z) { const w = this.w, X = Math.floor(x), Z = Math.floor(z), Y = Math.floor(c.y + .01), hh = Math.min(3, Math.ceil(c.ht)); @@ -101,7 +99,7 @@ const Fauna = { let y = null; if (w.solid(X, Y, Z)) { const top = c.pit || 1; let s = 1; while (s <= top && w.solid(X, Y + s, Z)) s++; if (s > top) return null; y = Y + s; } // a step up (in a pit: a ledge as high as itself, scrambling out) else for (let d = 1; d <= 4; d++) if (w.solid(X, Y - d, Z)) { y = Y - d + 1; break; } - if (y === null && !w.solid(X, Y - 5, Z)) { const g = Town.ground(x, z, Y); if (g != null && g < Y - 4) { y = g; c.pit = 3; } } // a pit opened under it (a crater): down to its bottom + if (y === null && !w.solid(X, Y - 5, Z)) { const g = Ground.at(x, z, Y); if (g != null && g < Y - 4) { y = g; c.pit = 3; } } // a pit opened under it (a crater): down to its bottom if (y === null) return null; for (let k = 1; k < hh; k++) if (w.solid(X, y + k, Z)) return null; if (this.water(X, y + 1, Z)) return null; // never go deeper than one cell @@ -157,7 +155,7 @@ const Fauna = { if (s) { if (!this.loaded(s[0], s[2])) continue; c = this.make(it, s[0], s[1], s[2], s[3], null, false); c.in = !!s[4]; c.perch = !!s[5]; if (c.in) c.wait = 2; else this.aim(c, s[6], s[7], s[8], s[9], s[10]); } else if (mv === 'swim') { if (!this.loaded(l.wx, l.wz) || !this.water(l.wx, WL - 1, l.wz)) continue; c = this.make(it, l.wx + (rnd() - .5) * 5, WL - .12, l.wz + (rnd() - .5) * 5, rnd() * TAU, null, false); } else if (mv === 'fly') { c = this.make(it, l.x + .5 + (rnd() - .5) * 6, (nest ? l.top : l.y) + 4 + rnd() * 4, l.z + .5 + (rnd() - .5) * 6, rnd() * TAU, null, false); } - else { const x = e.x + (rnd() - .5) * 6, z = e.z + (rnd() - .5) * 6, y = this.loaded(x, z) ? this.drop(x, l.y + 9, z) : null; if (y == null || this.water(x, y + 1, z)) continue; c = this.make(it, x, y, z, rnd() * TAU, null, false); } + else { const x = e.x + (rnd() - .5) * 6, z = e.z + (rnd() - .5) * 6, y = this.loaded(x, z) ? Ground.drop(x, z, l.y + 9, 14) : null; if (y == null || this.water(x, y + 1, z)) continue; c = this.make(it, x, y, z, rnd() * TAU, null, false); } c.home = l; c.hi = i; h.c[i] = c; h.st[i] = null; c.grp = l.key + 1; // the residents of a home are one group (a herd, a pack, a colony) if (mv === 'swim') { c.hx = l.wx; c.hz = l.wz; } else if (mv === 'fly') { c.hx = nest ? l.x + .5 : e.x; c.hz = nest ? l.z + .5 : e.z; c.hy = nest ? l.top + 2 : l.y + 4.5; } @@ -306,7 +304,7 @@ const Fauna = { const g = Math.floor(this.w.T.at(sx, sz)); let y; if (mv === 'fly') y = Math.max(g, WL) + 10 + Math.random() * 20; else if (mv === 'swim') { if (!this.water(sx, WL - 1, sz)) continue; y = it.id === 'fish' ? WL - 2.5 : WL - .12; } - else { y = this.drop(sx, g + 8, sz); if (y == null || this.water(sx, y + 1, sz)) continue; } + else { y = Ground.drop(sx, sz, g + 8, 14); if (y == null || this.water(sx, y + 1, sz)) continue; } const c = this.make(it, sx, y, sz, Math.random() * TAU, null, false); if (mv === 'fly' && c.alt < 12) c.y = Math.max(g, WL) + c.alt; if (!g0) g0 = c; c.grp = -g0.nid; c.lead = g0; // those who came together are a group, the first one leads this.n++; diff --git a/src/game/72_herd.js b/src/game/72_herd.js index d8c818ec8..fc4c7342e 100644 --- a/src/game/72_herd.js +++ b/src/game/72_herd.js @@ -97,7 +97,7 @@ const Herd = { g.mem = []; for (let i = 0; i < g.n; i++) { const a = a0 + i * 2.4, r = S.r * (.6 + Math.sqrt(i) * 1.1), x = o[0] + Math.cos(a) * r, z = o[1] + Math.sin(a) * r; - const y = Fauna.drop(x, this.w.T.at(x, z) + 10, z); if (y == null) continue; + const y = Ground.drop(x, z, this.w.T.at(x, z) + 10, 14); if (y == null) continue; const c = Fauna.make(it, x, y, z, R() * TAU, null, false); c.hd = g; c.nid = 0; c.grp = g.grp; c.lead = g.mem.length === 0 ? 1 : 0; c.pit = 0; Flock.join(c, i, g.hs); g.mem.push(c); } diff --git a/src/game/72_legend.js b/src/game/72_legend.js index 2fb62eca4..d9165c5b5 100644 --- a/src/game/72_legend.js +++ b/src/game/72_legend.js @@ -202,7 +202,7 @@ const Legend = { const walk = a.y === 'walk' || a.y === 'hop'; this.probe(X, Z, o); if (!this.room(a, o) || walk && !c.new && (c.ex || c.ez) && Math.abs(o.h - c.y) > 6) { c.ex *= .8; c.ez *= .8; X = q[0] + fx; Z = q[1] + fz; this.probe(X, Z, o); } // no running off a cliff or into a lake const loaded = Fauna.loaded(X, Z); - const ground = (x, z, h) => { const y = Fauna.loaded(x, z) ? Fauna.drop(x, Math.floor(h) + 3, z) : null; return y == null ? Math.floor(h) : y; }; + const ground = (x, z, h) => { const y = Fauna.loaded(x, z) ? Ground.drop(x, z, Math.floor(h) + 3, 14) : null; return y == null ? Math.floor(h) : y; }; // on foot: around trunks, rocks and walls (a step aside, kept while needed) if (walk && loaded) { const blocked = (x, z, h) => { const Y = ground(x, z, h), X0 = Math.floor(x), Z0 = Math.floor(z); return w.solid(X0, Y + 2, Z0) && w.solid(X0, Y + 3, Z0); }; diff --git a/src/game/72_nest.js b/src/game/72_nest.js index 180b4343f..6e5e2e1db 100644 --- a/src/game/72_nest.js +++ b/src/game/72_nest.js @@ -51,7 +51,7 @@ const Nest = { return o; }, // the top of what stands at (x, z) near height y (a crown, the grass): the nest sits on it - top(x, y, z) { const w = Walk.w || this.w, X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y) + 10; Y > y - 16; Y--) if (w.solid(X, Y - 1, Z)) return Y; return null; }, + top(x, y, z) { return Ground.top(x, z, y + 10, 26); }, // a parent away for food: out and back once a trip; → 0 at the nest … 1 the farthest away(c, t) { const P = NEST.trip, u = ((t + c.hs % 97) % P) / P; return u < .55 ? 0 : Math.sin(Math.PI * (u - .55) / .45); }, draw(c, s, t, p) { diff --git a/src/game/72_night.js b/src/game/72_night.js index 0175096a7..21d639358 100644 --- a/src/game/72_night.js +++ b/src/game/72_night.js @@ -37,7 +37,7 @@ const Night = { const G = NIGHT.fG, R = NIGHT.fR, w = this.w; let n = 0; for (let gz = Math.floor((p.z - R) / G); gz <= Math.floor((p.z + R) / G); gz++) for (let gx = Math.floor((p.x - R) / G); gx <= Math.floor((p.x + R) / G); gx++) { const c = this.flyCell(gx, gz); if (!c) continue; const dd = Math.hypot(c.x - p.x, c.z - p.z); if (dd > R) continue; - if (c.y == null) { if (!Fauna.loaded(c.x, c.z)) continue; const y = Fauna.drop(c.x, c.h + 10, c.z); c.y = y == null ? c.h + 1 : y; if (w.get(Math.floor(c.x), c.y - 1, Math.floor(c.z)) && w.transp[w.get(Math.floor(c.x), c.y - 1, Math.floor(c.z))] === 2) c.y += .5; } + if (c.y == null) { if (!Fauna.loaded(c.x, c.z)) continue; const y = Ground.drop(c.x, c.z, c.h + 10, 14); c.y = y == null ? c.h + 1 : y; if (w.get(Math.floor(c.x), c.y - 1, Math.floor(c.z)) && w.transp[w.get(Math.floor(c.x), c.y - 1, Math.floor(c.z))] === 2) c.y += .5; } for (let i = 0; i < c.n; i++) { const H = j => hash2(c.hs, i * 8 + j, 51); if (H(0) > k) continue; // the first ones come out early, the last ones only deep in the night const ph = H(1) * TAU, sp = .5 + H(2) * .6, x = c.x + (H(3) - .5) * G + 1.7 * Math.sin(t * .23 * sp + ph), z = c.z + (H(4) - .5) * G + 1.7 * Math.sin(t * .19 * sp + ph * 1.7); @@ -92,7 +92,7 @@ const Night = { for (let i = 0; i < c.n; i++) { if (hash2(c.hs, i, 53) > k) continue; const m = this.keep(c.id + ':' + i, 'bat'); if (!m) return; - this.batAt(c, i, t, o); if (c.y == null && Fauna.loaded(c.x, c.z)) { const y = Fauna.drop(c.x, c.h + 30, c.z); c.y = y == null ? c.h : Math.max(c.h, y); } + this.batAt(c, i, t, o); if (c.y == null && Fauna.loaded(c.x, c.z)) { const y = Ground.drop(c.x, c.z, c.h + 30, 14); c.y = y == null ? c.h : Math.max(c.h, y); } this.place(m, o[0], o[1] + ((c.y || c.h) - c.h), o[2], dt, 1); m.at = t + i * .37; } } diff --git a/src/game/73_kin.js b/src/game/73_kin.js index 242ed6f6d..b4c46adb1 100644 --- a/src/game/73_kin.js +++ b/src/game/73_kin.js @@ -122,7 +122,7 @@ const Kin = { if (hk) { // on the ground under the trailing axle, the pivot up at the hitch (dy above the ground under the vehicle in front: the wheel-lift) if (hk.dy !== hk.dyT) hk.dy = hk.dyT > hk.dy ? Math.min(hk.dyT, hk.dy + dt * 1.2) : Math.max(hk.dyT, hk.dy - dt * 1.2); - const gy = Town.ground(k[0], k[1], c.y + 2), y0 = gy == null ? c.y : gy, th = Math.atan2(c.y + hk.dy - y0, dl), tl = hk.rv ? th : -th, zt = hk.rv ? -am : am; + const gy = Ground.at(k[0], k[1], c.y + 2), y0 = gy == null ? c.y : gy, th = Math.atan2(c.y + hk.dy - y0, dl), tl = hk.rv ? th : -th, zt = hk.rv ? -am : am; const y = y0 + Math.sin(tl) * zt; hk.y = !dt || hk.y == null ? y : hk.y + (y - hk.y) * Math.min(1, dt * 10); u.y = hk.y; u.tilt = tl; } } diff --git a/src/game/73_pilot.js b/src/game/73_pilot.js index d36aa672c..bc78aadc1 100644 --- a/src/game/73_pilot.js +++ b/src/game/73_pilot.js @@ -383,9 +383,10 @@ const Pilot = { const q = W.at(s + sg * e), nx = Math.cos(q[2]), nz = -Math.sin(q[2]); for (let i = 0; i <= n; i++) { const k = -hw + 2 * hw * i / n, X = Math.floor(q[0] + nx * k), Z = Math.floor(q[1] + nz * k); - let y0 = ys[i]; if (y0 == null) { y0 = Y - 12; for (let y = Y + 8; y >= Y - 12; y--) if (w.solid(X, y, Z) && !w.solid(X, y + 1, Z) && !w.solid(X, y + 2, Z)) { y0 = y; break; } } - let g = null; for (let y = y0 + DRIVE_STEP; y >= y0 - 8; y--) if (w.solid(X, y, Z)) { if (w.solid(X, y + 1, Z) || w.solid(X, y + 2, Z)) return false; g = y; break; } - if (g == null) g = y0 - 8; // a pit: Drive.free below looks at the edges + let y0 = ys[i]; if (y0 == null) { const f = Ground.cell(w, X, Z, Y + 9, Y - 11, 2); y0 = f < 0 ? Y - 12 : f - 1; } + let g = Ground.roof(w, X, Z, y0 + DRIVE_STEP, y0 - 8) - 1; + if (g < -1) g = y0 - 8; // a pit: Drive.free below looks at the edges + else if (w.solid(X, g + 1, Z) || w.solid(X, g + 2, Z)) return false; for (let y = g + 3; y <= g + 5; y++) if (hard(X, y, Z)) return false; ys[i] = g; } diff --git a/src/game/73_plan.js b/src/game/73_plan.js index 6f37e0ffa..7d04a91e0 100644 --- a/src/game/73_plan.js +++ b/src/game/73_plan.js @@ -36,9 +36,8 @@ const Plan = { for (let d = 0; d < 4; d++) { const a = d === 0 ? i - 1 : d === 1 ? i + 1 : i, b = d === 2 ? j - 1 : d === 3 ? j + 1 : j; if (a < 0 || b < 0 || a >= nx || b >= nz) continue; const m = a * nz + b; if (D[m] || tr[m] === h) continue; tr[m] = h; - const X = x0 + a, Z = z0 + b; let L = null; - for (let Y = h; Y >= h - 2; Y--) if (w.solid(X, Y, Z)) { L = Y + 1; break; } // the top of the ground: a cell up, level or a cell down - if (L === null || L > h && w.solid(X, L, Z) || !body(X, Z, L)) continue; // (nothing under it, two up, or no room for the body) + const X = x0 + a, Z = z0 + b, L = Ground.roof(w, X, Z, h, h - 2); // the top of the ground: a cell up, level or a cell down + if (L < 0 || L > h && w.solid(X, L, Z) || !body(X, Z, L)) continue; // (nothing under it, two up, or no room for the body) lv[m] = L; D[m] = BIG; q[qt++] = m; } } diff --git a/src/game/74_town.js b/src/game/74_town.js index 1d6c7f1e8..3d51016fa 100644 --- a/src/game/74_town.js +++ b/src/game/74_town.js @@ -135,15 +135,6 @@ const Town = { const s = it.model.size, inst = makeInst(it, 0, 0, 0, 0, slots), vs = it.model.vs || .25; // vs: cells per voxel (a big ship is drawn in coarser voxels, 72_ships.mjs) return { it, inst, x, y, z, yaw, rad: Math.max(s[0], s[2]) * vs / 2, ht: s[1] * vs, ph: Math.random() * 9, gait: 0 }; }, - // ground under a walker: the first free cell above something solid around the street level - ground(x, z, y) { - const w = this.w, X = Math.floor(x), Z = Math.floor(z); let Y = Math.floor(y) + 3; - for (; Y > y - 6; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) return Y + Shape.lift(w, x, Y, z); // on a road ramp: its sloped top (10_shape.js) - // nothing within a step or two, only air below: a pit (a crater, a hole blown or dug). What stands here goes down to its bottom; - // water on the way means a lake or the sea, where nothing walks - for (; Y > y - 72 && Y > 0; Y--) { if (w.solid(X, Y, Z)) return null; const id = w.get(X, Y - 1, Z); if (id && w.transp[id] === 2) return null; if (w.solid(X, Y - 1, Z)) return Y + Shape.lift(w, x, Y, z); } - return null; - }, loaded(x, z) { return Fauna.loaded(x, z); }, // may a walker start crossing at x? Only if every car coming towards the crossing can still stop in front of it safe(x) { @@ -400,7 +391,7 @@ const Town = { if (l) { Kin.follow(c, l, s, mv ? dt : 0); x = c.x; z = c.z; yaw = c.yaw; } // front axle on the way, the rear one trailing (73_kin.js) else { x = a[0]; z = a[1]; yaw = a[2]; } const fx = Math.sin(yaw), fz = Math.cos(yaw), hl = c.len * .35; - const gy = (x, z) => { const h = Math.ceil(Math.max(this.w.T.at(x, z), WL)); return this.loaded(x, z) ? Drive.floor(x, z, h + 1) : h; }, gf = gy(x + fx * hl, z + fz * hl), gr = gy(x - fx * hl, z - fz * hl), y = (gf + gr) / 2, e = dt ? Math.min(1, dt * 10) : 1; + const gy = (x, z) => { const h = Ground.land(x, z); return this.loaded(x, z) ? Ground.under(x, z, h + 1) : h; }, gf = gy(x + fx * hl, z + fz * hl), gr = gy(x - fx * hl, z - fz * hl), y = (gf + gr) / 2, e = dt ? Math.min(1, dt * 10) : 1; c.x = x; c.z = z; c.yaw = yaw; c.dist += c.v * dt; c.y += (y - c.y) * e; c.tilt = (c.tilt || 0) + (clamp(Math.atan2(gr - gf, hl * 2), -.45, .45) - (c.tilt || 0)) * (dt ? Math.min(1, dt * 6) : 1); } if (!back && rest < 2 && Math.abs(c.v) < .5) c.cAt = 1; // on the spot: the crew gets out (79_fire.js) @@ -615,14 +606,14 @@ const Town = { // where the wheels stand at (x, z): the real ground where the world is built, otherwise what the generator will make there hAt(x, z, P, y) { if (P && P.rd) { // a path of the road network: the blocks where they are loaded (a bridge deck too), the generator's road level further away - if (y != null && this.loaded(x, z)) { const g = this.ground(x, z, y); if (g != null) return g; } + if (y != null && this.loaded(x, z)) { const g = Ground.at(x, z, y); if (g != null) return g; } const T = this.w.T, h = T.at(x, z); if (T.tn && T.tnr === P.rd) return Math.floor(T.tn); // the floor of a tunnel of this road (35_tunnel.js) if (T.dk) { for (const e of T.dk) if (e.r === P.rd) return Math.floor(e.y); return Math.floor(h); } // the deck of this very road, or the ground under somebody else's bridge return Math.floor(T.rdb > h ? T.rdb : h); } const N = this._net, a = z > ROAD.side0 - .5 ? LG : z > N.k.z1 ? Math.floor(this.w.T.linkH(z)) : N.y; - if (this.loaded(x, z)) { const g = this.ground(x, z, a); if (g != null) return g; } + if (this.loaded(x, z)) { const g = Ground.at(x, z, a); if (g != null) return g; } return a; }, // the indices at which a path comes into the circle of radius r around the player diff --git a/src/game/74_town_ahead.js b/src/game/74_town_ahead.js index 76727e8a8..320128de3 100644 --- a/src/game/74_town_ahead.js +++ b/src/game/74_town_ahead.js @@ -34,7 +34,7 @@ Town.ahead1 = function (c, l, s, o = {}) { if (me && Math.hypot(x - p.x, z - p.z) < hw + 1.5 && Math.abs(p.y - c.y) < 12) hit(e, 0, 'me'); // a wall across the way: the ground rises by more than DRIVE_STEP at once (under the middle of the car), or solid blocks at body height over it across the inner part of the car (leaves and petals are no wall: a car brushes through a bough; a railing or a kerb at the edge of a narrow bridge is not in the way: lane cars pass there too); only where blocks are made if (lim > 1e8 && made(x, z)) { - const f = Law.ground(x, z, gy + 1); // (looks from DRIVE_STEP + 1 up down: a bough or a lamp arm overhead is no ground) + const f = Ground.road(x, z, gy + 1); // (looks from DRIVE_STEP + 1 up down: a bough or a lamp arm overhead is no ground) if (f - gy > DRIVE_STEP) { hit(e, 0, 'wall'); c.bw = [Math.floor(x), f - 1, Math.floor(z), 'rise', gy]; } else { gy = f; const cw = AHEAD.core * hw, n = Math.max(1, Math.ceil(cw / .7)); // across: points under .7 apart; along: a cell apart (the step is 2: one more row between) diff --git a/src/game/76_life.js b/src/game/76_life.js index d97f6b308..51063cada 100644 --- a/src/game/76_life.js +++ b/src/game/76_life.js @@ -216,13 +216,11 @@ const Life = { }, // ---- the walking grid of a lot: the height of the floor under the feet in every cell (−1: no way), built a few rows per frame ---- feet(f, X, Z) { - const w = this.w; - for (let Y = f.y0 + 3; Y >= f.y0 - 4; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) { for (let k = 1; k < 8; k++) if (w.solid(X, Y + k, Z)) return -1; return Y; } - return -1; + const w = this.w, Y = Ground.cell(w, X, Z, f.y0 + 3, f.y0 - 4); return Y < 0 || !Ground.room(w, X, Y, Z, 8) ? -1 : Y; }, buildGrid(f, ms) { const w = this.w, t0 = now(); - if (!f.hh) { const y = Town.ground(f.door.x, f.door.z, LG + 2); if (y == null) return; f.y0 = y; f.hh = new Int16Array(f.gw * f.gd); f.ok = new Uint8Array(f.gw * f.gd); f.prev = new Int32Array(f.gw * f.gd); } + if (!f.hh) { const y = Ground.at(f.door.x, f.door.z, LG + 2); if (y == null) return; f.y0 = y; f.hh = new Int16Array(f.gw * f.gd); f.ok = new Uint8Array(f.gw * f.gd); f.prev = new Int32Array(f.gw * f.gd); } for (const n = f.gw * f.gd; f.row < n; f.row++) { if (!(f.row & 15) && now() - t0 > ms) return; f.hh[f.row] = this.feet(f, f.gx + f.row % f.gw, f.gz + Math.floor(f.row / f.gw)); @@ -239,7 +237,7 @@ const Life = { for (const a of f.mem) { const r = this.saved.get(f.i * 16 + a.n); if (!r) { this.settle(a); continue; } this.saved.delete(f.i * 16 + a.n); a.x = r.x; a.y = r.y; a.z = r.z; a.yaw = r.yaw; a.hide = !!(r.fl & 1); a.re = r; a.reT = 0; } if (f.dog) { const c = this.freeCell(f, f.door.x - 8, 6, f.door.x + 8, f.box.z0 - 4, f.R) || [f.door.x, f.door.z - 6], d = f.dog, r = this.saved.get(f.i * 16 + 15); d.hx = c[0]; d.hz = c[1]; - if (r) { this.saved.delete(f.i * 16 + 15); d.x = d.tx = r.x; d.z = d.tz = r.z; d.y = r.y; d.yaw = r.yaw; d.own0 = r.fl & 4 ? f.mem[r.ld] || null : null; } else { d.x = d.tx = c[0]; d.z = d.tz = c[1]; d.y = Town.ground(d.x, d.z, f.y0 + 1) || f.y0; } + if (r) { this.saved.delete(f.i * 16 + 15); d.x = d.tx = r.x; d.z = d.tz = r.z; d.y = r.y; d.yaw = r.yaw; d.own0 = r.fl & 4 ? f.mem[r.ld] || null : null; } else { d.x = d.tx = c[0]; d.z = d.tz = c[1]; d.y = Ground.at(d.x, d.z, f.y0 + 1) || f.y0; } this.dogs.push(d); } }, @@ -477,9 +475,9 @@ const Life = { // ---- living: one step of a person ---- // a new family member starts right in the middle of the day: at the place of the first thing to do settle(a) { - const f = a.fam, y = Town.ground(f.entry[0], f.entry[1], f.y0 + 1); a.x = f.entry[0]; a.z = f.entry[1]; a.y = y == null ? f.y0 : y; + const f = a.fam, y = Ground.at(f.entry[0], f.entry[1], f.y0 + 1); a.x = f.entry[0]; a.z = f.entry[1]; a.y = y == null ? f.y0 : y; this.plan(a); const s = a.steps[0]; - if (s && s.t === 'go' && s.L === f && a.steps[1] && a.steps[1].t !== 'wait') { a.x = s.x; a.z = s.z; const g = Town.ground(a.x, a.z, f.y0 + 1); if (g != null) a.y = g; a.say = s.say; this.next(a); } + if (s && s.t === 'go' && s.L === f && a.steps[1] && a.steps[1].t !== 'wait') { a.x = s.x; a.z = s.z; const g = Ground.at(a.x, a.z, f.y0 + 1); if (g != null) a.y = g; a.say = s.say; this.next(a); } }, finish(a) { a.jog = 0; const s = a.steps[0]; if (s && s.on) this.end(a, s); this.drop(a); a.steps = []; }, end(a, s) { const i = a.inst; i.legs = 0; i.arms = 0; a.tilt = 0; a.jump = 0; a.jy = 0; a.hide = false; if (s.t === 'do') { this.drop(a); if (s.back) { a.x = s.back[0]; a.z = s.back[1]; a.y = s.back[2]; } } }, @@ -578,7 +576,7 @@ const Life = { return true; }, // the floor under the feet: from the lot's grid, on the street from the world (only where it is loaded in detail) - floor(a) { const L = this.lotAt(a.x, a.z); if (L) { const h = L.hh[this.cell(L, a.x, a.z)]; if (h >= 0) return h; } return Town.loaded(a.x, a.z) ? Town.ground(a.x, a.z, a.y) : null; }, + floor(a) { const L = this.lotAt(a.x, a.z); if (L) { const h = L.hh[this.cell(L, a.x, a.z)]; if (h >= 0) return h; } return Town.loaded(a.x, a.z) ? Ground.at(a.x, a.z, a.y) : null; }, // the dog: trots after its owner (on the leash or playing), otherwise potters around the yard stepDog(d, dt) { if (d.own0) { if (d.own0.re) return; d.own0 = null; } // after a reload: waits for the one who held the leash to carry on diff --git a/src/game/77_ferry.js b/src/game/77_ferry.js index 0a04902a6..f02acbb33 100644 --- a/src/game/77_ferry.js +++ b/src/game/77_ferry.js @@ -69,7 +69,7 @@ const Ferry = { else if (s) { // on the way: a point of the path, the ground under the feet (the deck and the quay are level) const a = clamp(s.t, 0, 1) * P.len; let i = 1; while (i < P.pts.length - 1 && P.acc[i] < a) i++; const A = P.pts[i - 1], B = P.pts[i], t = (a - P.acc[i - 1]) / Math.max(1e-6, P.acc[i] - P.acc[i - 1]); - o.x = lerp(A[0], B[0], t); o.z = lerp(A[1], B[1], t); const g = Town.ground(o.x, o.z, LG + 1); o.y = g == null ? LG : g; + o.x = lerp(A[0], B[0], t); o.z = lerp(A[1], B[1], t); const g = Ground.at(o.x, o.z, LG + 1); o.y = g == null ? LG : g; o.yaw = Math.atan2((B[0] - A[0]) * s.dir, (B[1] - A[1]) * s.dir); o.gait = 1; this.walk.push(o); } } diff --git a/src/game/77_plane.js b/src/game/77_plane.js index 3b7a6b74f..5c57b64be 100644 --- a/src/game/77_plane.js +++ b/src/game/77_plane.js @@ -340,7 +340,7 @@ const Plane = { if (Drive.halt) { thr = -1; st = 0; } // the power lever: forward opens it, back closes it (and brakes on the ground) if (thr > .2) c.pw = Math.min(1, c.pw + dt * .6); else if (thr < -.2) c.pw = Math.max(0, c.pw - dt * .8); - const g = Drive.floor(c.x, c.z, c.y); c.gy = g; + const g = Ground.under(c.x, c.z, c.y); c.gy = g; if (!c.air) { // on the ground: the engines pull, the brakes and the rolling hold back, the nose wheel steers const pull = c.pw * 34 - (thr < -.2 ? 45 : 2 + Math.abs(c.v) * .02); c.v = Math.max(0, c.v + pull * dt); if (!you && c.v < 2) c.v = Math.max(0, c.v - 10 * dt); @@ -363,10 +363,10 @@ const Plane = { // something solid at the nose or a wing tip: it stops dead (in the air it drops) const hit = (a, b, h) => { const x = Math.floor(nx + fx * a + fz * b), z = Math.floor(nz + fz * a - fx * b); return Town.loaded(x, z) && w.solid(x, Math.floor(ny + h), z); }; if (c.v > 3 && (hit(c.len / 2, 0, 10) || hit(-2, c.wid / 2 - 1, 10) || hit(-2, -c.wid / 2 + 1, 10))) { nx = c.x; nz = c.z; if (c.v > 30) { Sfx.play('crash', c); c.shake = 1; toast(tr('💥 Самолёт во что-то врезался', '💥 The plane hit something'), 2400); } c.v = 0; if (c.air) c.vy = Math.min(c.vy, -20); c.pw = 0; } - const g2 = Drive.floor(nx, nz, Math.max(ny, c.y)); + const g2 = Ground.under(nx, nz, Math.max(ny, c.y)); if (c.air && ny <= g2) { // touchdown // soft only on level ground (a runway, a field) — not on treetops or roofs: the ground under the nose, the tail and the wing tips agrees - const flat = [[c.len / 2 - 3, 0], [3 - c.len / 2, 0], [0, c.wid / 2 - 2], [0, 2 - c.wid / 2]].every(([a, b]) => Math.abs(Drive.floor(nx + fx * a + fz * b, nz + fz * a - fx * b, g2 + 4) - g2) <= 2); + const flat = [[c.len / 2 - 3, 0], [3 - c.len / 2, 0], [0, c.wid / 2 - 2], [0, 2 - c.wid / 2]].every(([a, b]) => Math.abs(Ground.under(nx + fx * a + fz * b, nz + fz * a - fx * b, g2 + 4) - g2) <= 2); const hard = c.vy < -24 || Math.abs(c.bank) > .35 || !flat; c.air = 0; ny = g2; c.vy = 0; c.bank = 0; if (hard) { c.v *= .3; c.shake = 1; Sfx.play('crash', c); toast(flat ? tr('💥 Жёсткая посадка! Снижайся плавнее и держи крылья ровно', '💥 A hard landing! Sink gently and keep the wings level') : tr('💥 Тут не сесть: нужна полоса или ровное поле', '💥 No place to land: it needs a runway or a level field'), 3200); } else if (you) toast(tr('🛬 Мягкая посадка! Назад — тормоза', '🛬 A soft landing! Back to brake'), 2400); @@ -388,7 +388,7 @@ Ent.reg('ticket', { v: 1, load(rows) { Plane.tkRow = rows[0] || null; }, }); Ent.reg('plane', { v: 1, q: { x: 8, y: 8, z: 8, yaw: 40 }, - save() { const c = Plane.own; if (!c || Town.cars.indexOf(c) < 0 || Net.pk && Walk.ride && Walk.ride.car === c) return []; return [{ x: c.x, y: c.air ? Drive.floor(c.x, c.z, c.y) : c.y, z: c.z, yaw: _ang(c.yaw), you: Walk.ride && Walk.ride.car === c && !c.air ? 1 : 0 }]; }, + save() { const c = Plane.own; if (!c || Town.cars.indexOf(c) < 0 || Net.pk && Walk.ride && Walk.ride.car === c) return []; return [{ x: c.x, y: c.air ? Ground.under(c.x, c.z, c.y) : c.y, z: c.z, yaw: _ang(c.yaw), you: Walk.ride && Walk.ride.car === c && !c.air ? 1 : 0 }]; }, load(rows) { Plane.ownRow = rows[0] || null; }, }); // ---- the lights: the field's (Air.lamps) and the planes' own, as the eye sees them (Flare, 57_flare.js) ---- diff --git a/src/game/78_drive.js b/src/game/78_drive.js index cac87d4a5..b65d1c5ce 100644 --- a/src/game/78_drive.js +++ b/src/game/78_drive.js @@ -208,7 +208,7 @@ const Drive = { // for the player (a car of the road at the edge of a bridge, build 452) aside(u, a, b) { const hw = (u.veh.hw || u.wid / 2) + 1.6, sd = b < 0 ? -1 : 1, at = (x, z, y) => [x, y, z, Math.atan2(u.x - x, u.z - z)]; - for (const [da, side] of [[-3.4, sd], [0, sd], [-3.4, -sd], [0, -sd]]) { const [x, z] = this.world(u, a + da, side * hw), y = Town.ground(x, z, u.y + 1); if (y != null && Math.abs(y - u.y) < 5) return at(x, z, y); } + for (const [da, side] of [[-3.4, sd], [0, sd], [-3.4, -sd], [0, -sd]]) { const [x, z] = this.world(u, a + da, side * hw), y = Ground.at(x, z, u.y + 1); if (y != null && Math.abs(y - u.y) < 5) return at(x, z, y); } const t = u.car && u.car.units ? u.car.units[u.car.units.length - 1] : u, [x, z] = this.world(t, -(t.len / 2 + 2.5), 0); return at(x, z, t.y); // (behind what it tows, if anything) }, cede(u, seat, say) { @@ -247,7 +247,7 @@ const Drive = { // a free spot next to the door, the other side, ahead or behind; the roof as the last resort const [a, b] = this.seatAB(u, seat), hw = (u.veh.hw || u.wid / 2) + 1.2, s = Train.open(c) ? -Train.sd(u, c.tr.r.st[c.tr.k].side) : b < 0 ? -1 : 1; let done = false; // out of a train onto its platform for (const [qa, qb] of [[a, s * hw], [a, -s * hw], [a + 3, s * hw], [a - 3, s * hw], [a - 3, -s * hw], [u.len / 2 + 1.5, 0], [-u.len / 2 - 1.5, 0]]) { - const [x, z] = this.world(u, qa, qb), y = Town.ground(x, z, u.y + 1); + const [x, z] = this.world(u, qa, qb), y = Ground.at(x, z, u.y + 1); if (y != null && Math.abs(y - u.y) < 5 && !Walk.hitTest(x, y, z) && !Occ.onCar(x, y, z)) { done = [x, y, z]; break; } // (no other vehicle there either: 71_occ.js) } // the climb out: the door opens and the player steps to that spot; the rest happens when they stand there (see leave) @@ -276,7 +276,7 @@ const Drive = { if (c.kind === 'dragon') { c.mode = 'pet'; c.pet = 'come'; c.petT = 50; c.spot = null; c.bank = 0; Walk.syncButtons(); } if (c.fa) { // somebody else's dragon: back to its own life right here; a settled one now lives around this place const f = c.fa, i = Town.cars.indexOf(c); if (i >= 0) Town.cars.splice(i, 1); - f.x = c.x; f.y = c.y; f.z = c.z; f.yaw = c.yaw; f.go = false; f.wait = 2; f.tx = c.x; f.ty = c.y; f.tz = c.z; if (f.own) { f.hx = c.x; f.hy = this.floor(c.x, c.z, c.y); f.hz = c.z; } + f.x = c.x; f.y = c.y; f.z = c.z; f.yaw = c.yaw; f.go = false; f.wait = 2; f.tx = c.x; f.ty = c.y; f.tz = c.z; if (f.own) { f.hx = c.x; f.hy = Ground.under(c.x, c.z, c.y); f.hz = c.z; } if (Fauna.list.indexOf(f) < 0) Fauna.list.push(f); Save.touch(); } p.vy = 0; if (!at) Sfx.play('door', Walk.p); if (Walk.me) Walk.me.inst.legs = 0; @@ -307,7 +307,7 @@ const Drive = { }, // …and goes on with its life where the player leaves it (after a reload in the saddle the animal is made anew; own.vo keeps "from the catalog") release(c) { - const b = c.beast || Fauna.make(c.it, c.x, c.y, c.z, c.yaw, c.inst.slots, c.own.vo), y = Town.ground(c.x, c.z, c.y + 1); + const b = c.beast || Fauna.make(c.it, c.x, c.y, c.z, c.yaw, c.inst.slots, c.own.vo), y = Ground.at(c.x, c.z, c.y + 1); Object.assign(b, { x: c.x, y: y == null ? c.y : y, z: c.z, yaw: c.yaw, go: false, wait: 2.5, stuck: 0 }); b.tx = b.x; b.ty = b.y; b.tz = b.z; if (b.own) { b.hx = b.x; b.hy = b.y; b.hz = b.z; } // a settled one now lives around the new spot if (Fauna.list.indexOf(b) < 0) Fauna.list.push(b); @@ -336,11 +336,11 @@ const Drive = { if (T && this.tool(u, T, ux, uz, uy, us, uc, sl, rb, 0) < 0) return false; for (let i = -na; i <= na; i++) for (let j = -nb; j <= nb; j++) { if (i > -na && i < na && j > -nb && j < nb && (j || i % 3)) continue; - const a = sh + hl * i / na, b = hw * j / nb, px = ux + us * a + uc * b, pz = uz + uc * a - us * b, gy = uy - sl * a + rb * b, g = Town.ground(px, pz, gy); + const a = sh + hl * i / na, b = hw * j / nb, px = ux + us * a + uc * b, pz = uz + uc * a - us * b, gy = uy - sl * a + rb * b, g = Ground.at(px, pz, gy); // a kerb is fine, a fence or a wall is not; on a slope the ground is expected to follow the tilt of the vehicle const e = g == null ? 0 : g - gy; if (g == null || e > tol || -e > (dn == null ? tol : dn)) return false; const X = Math.floor(px), Z = Math.floor(pz), id = w.get(X, g, Z); if (id && w.transp[id] === 2) return false; // water - // the ground found far below is a drop only if nothing stands between it and the body (Town.ground looks down from a little over + // the ground found far below is a drop only if nothing stands between it and the body (Ground.at looks down from a little over // the wheels: the face of a step a cell too high for them reads as a pit under it) if (-e > tol) { const yb = Math.floor(gy) + DRIVE_STEP; for (let Y = g; Y <= yb; Y++) if (w.solid(X, Y, Z)) return false; } for (let k = 2; k < top; k += 2) if (w.solid(X, g + k, Z)) return false; @@ -431,7 +431,7 @@ const Drive = { settle(c) { if (c.ghost || !c.it || !Walk.w) return false; const S = Susp.geo(c), fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), h = [0, 0, 0, 0]; - for (let i = 0; i < 4; i++) { const a = S.A[i], b = S.B[i], g = this.bed(c.x + fx * a + fz * b, c.z + fz * a - fx * b, c.y + 4); if (g == null || g < c.y - 12) return false; h[i] = g; } + for (let i = 0; i < 4; i++) { const a = S.A[i], b = S.B[i], g = Ground.drop(c.x + fx * a + fz * b, c.z + fz * a - fx * b, c.y + 4, 72); if (g == null || g < c.y - 12) return false; h[i] = g; } const t = S.A[0] - S.A[2] > .5 ? ((h[2] + h[3]) - (h[0] + h[1])) / 2 / (S.A[0] - S.A[2]) : 0, r = S.lean || S.B[1] - S.B[0] < .5 ? 0 : ((h[1] + h[3]) - (h[0] + h[2])) / 2 / ((S.B[1] - S.B[0] + S.B[3] - S.B[2]) / 2); let y = 0; for (let i = 0; i < 4; i++) y += h[i] + t * S.A[i] - r * S.B[i]; y /= 4; const o = [c.y, c.tilt, c.bank]; c.y = y; c.tilt = clamp(Math.atan(t), -.6, .6); if (!S.lean) c.bank = clamp(Math.atan(r), -.6, .6); @@ -601,7 +601,7 @@ const Drive = { if (Math.random() < dt * 10) { const top = this.horseSurf(c.x, c.z, c.y); if (top != null) Splash.bubbles(c.x, c.y + 2, c.z, top, 2, 1.5); } } const y1 = c.y + c.vy * dt, hl = c.len * .35; let g = null; - for (let k = -1; k <= 1; k++) { const q = this.bed(c.x + fx * hl * k, c.z + fz * hl * k, c.y + 1); if (q != null && q <= c.y + 1 && (g == null || q > g)) g = q; } + for (let k = -1; k <= 1; k++) { const q = Ground.drop(c.x + fx * hl * k, c.z + fz * hl * k, c.y + 1, 72); if (q != null && q <= c.y + 1 && (g == null || q > g)) g = q; } if (g != null && g >= y1) { if (c.vy < -25) { c.shake = 1; Sfx.play('step', c); } c.y = g; c.vy = 0; c.air = 0; } else c.y = y1; return; } @@ -694,7 +694,7 @@ const Drive = { const v = dt > 0 && u.px != null ? Math.hypot(u.x - u.px, u.z - u.pz) / dt : 0; u.px = u.x; u.pz = u.z; u.dv = (u.dv || 0) + (Math.min(v, 60) - (u.dv || 0)) * Math.min(1, dt * 5); this.stride(u, u.dv, dt); if (!u.veh.sway) return; - const g = Town.ground(u.x, u.z, u.y + CAMEL_KNEEL + 1); u.inst.act = g == null || u.dv > 2 ? 0 : clamp((g - u.y - 2) / (CAMEL_KNEEL - 2), 0, 1); // (up to 2 under: its legs on lower ground, see horse) + const g = Ground.at(u.x, u.z, u.y + CAMEL_KNEEL + 1); u.inst.act = g == null || u.dv > 2 ? 0 : clamp((g - u.y - 2) / (CAMEL_KNEEL - 2), 0, 1); // (up to 2 under: its legs on lower ground, see horse) }, // kneeling, kn 0…1: the legs fold under the body and it sinks to the ground; going down the front goes first, getting up the hind legs // do (both tip the nose down on the way) @@ -752,7 +752,7 @@ const Drive = { } c.dist += c.v * dt; if (you) this.shove(c, dt, v0); // drawing: on the ground the body lies on what is under the front and the hind legs; in the air it follows the arc of the jump - const gf = Town.ground(c.x + fx * hl, c.z + fz * hl, c.y + 1), gr = Town.ground(c.x - fx * hl, c.z - fz * hl, c.y + 1); + const gf = Ground.at(c.x + fx * hl, c.z + fz * hl, c.y + 1), gr = Ground.at(c.x - fx * hl, c.z - fz * hl, c.y + 1); let vo = 0, tilt = -Math.atan2(c.vy, Math.max(20, Math.abs(c.v))) * .8; if (swim) tilt = -.1 + Math.sin(Anim.t * 3) * .04; else if (c.gnd) { const a = gf == null ? c.y - 4 : Math.min(gf, c.y), b = gr == null ? c.y - 4 : Math.min(gr, c.y); vo = clamp((a + b) / 2 - c.y, -2, 0); tilt = Math.atan2(b - a, hl * 2); } @@ -833,19 +833,12 @@ const Drive = { Object.assign(u, { y, units: [u], car: u, kind: 'dragon', edge: false, vmax: 40, v: 0, vy: 0, dist: 0, stopT: 0, honkT: 0, head: 0, tail: 0, mode: 'pet', pet: 'come', petT: 80 + Math.random() * 50, tilt: 0, gait: 1, dir: 1, seed: 1 }); Town.cars.push(u); return u; }, - // what a flyer may land on at (x, z): the ground, a roof, water (the generator answers where the world is not built yet) - // the first solid thing under (x, y, z) within a fall, water passed through; null: nothing loaded there - bed(x, z, y) { const w = Walk.w, X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y); Y > y - 72 && Y > 0; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) return Y; return null; }, wet(x, y, z) { const w = Walk.w, id = w.get(Math.floor(x), Math.floor(y), Math.floor(z)); return !!id && w.transp[id] === 2; }, - floor(x, z, y) { - if (Town.loaded(x, z)) { const w = Walk.w, X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y) + 2; Y > y - 70; Y--) { const id = w.get(X, Y - 1, Z); if (id && !w.solid(X, Y, Z)) return w.shp && w.shp[id] ? Y - 1 + Shape.h(w.shp[id], x - X, z - Z) : Y; } return y - 70; } // the sloped top of a road ramp (10_shape.js) - return Math.ceil(Math.max(Walk.w.T.at(x, z), WL)); - }, // an open spot near the player, level with them: [x, y, z] landing(p) { const w = Walk.w; for (let n = 0; n < 14; n++) { - const a = p.yaw + (Math.random() - .5) * (n < 6 ? 1.6 : 6.3), r = 9 + Math.random() * (n < 6 ? 11 : 17), x = p.x + Math.sin(a) * r, z = p.z + Math.cos(a) * r, g = Town.ground(x, z, p.y); + const a = p.yaw + (Math.random() - .5) * (n < 6 ? 1.6 : 6.3), r = 9 + Math.random() * (n < 6 ? 11 : 17), x = p.x + Math.sin(a) * r, z = p.z + Math.cos(a) * r, g = Ground.at(x, z, p.y); if (g == null || Math.abs(g - p.y) > 4 || [0, 3, -3].some(o => { const k = w.T.road(x + o, z + o); return k === 1 || k === 4; })) continue; // not on the roadway let ok = true; for (const [ox, oz] of [[0, 0], [3, 0], [-3, 0], [0, 4], [0, -4]]) { const X = Math.floor(x + ox), Z = Math.floor(z + oz), id = w.get(X, g - 1, Z); if (!id || w.transp[id] === 2) ok = false; for (let k = 0; k < 8 && ok; k++) if (w.solid(X, g + k, Z)) ok = false; } if (ok) return [x, g, z]; @@ -879,7 +872,7 @@ const Drive = { let lk = 0, look = 0; if (you) { const k = Walk.keys; st = this.in[0]; thr = this.in[1]; up = (k.hold_up || k.Space ? 1 : 0) - (k.hold_down || k.ShiftLeft ? 1 : 0); c.ghost = false; } else { [thr, st, up] = this.petAI(c, dt, p); c.ghost = true; if (Town.cars.indexOf(c) < 0) return; } // on its own it never gets stuck in the scenery - const g = this.floor(c.x, c.z, c.y), air = c.y > g + .3, top = air ? DRIVE_TOP.dragon : 12; + const g = Ground.under(c.x, c.z, c.y), air = c.y > g + .3, top = air ? DRIVE_TOP.dragon : 12; // Pushed forward, it flies where the rider looks (a finger, the mouse or the head in a headset): it turns to the gaze and climbs or // sinks along it. The view itself is not carried by that turn (yaw0), so the gaze stays where the rider put it and the dragon lines up // with it. A few degrees around the horizon fly level; on the ground it takes a clear look up to take off. @@ -901,7 +894,7 @@ const Drive = { if (Math.abs(c.v) > .5 && (w.solid(hx, Math.floor(c.y + 3), hz) || w.solid(hx, Math.floor(c.y + 5), hz))) { nx = c.x; nz = c.z; c.v = 0; } if (c.vy > 0 && w.solid(Math.floor(nx), Math.floor(ny + c.ht + 2), Math.floor(nz))) { ny = c.y; c.vy = 0; } } - const g2 = this.floor(nx, nz, Math.max(ny, c.y)); if (ny <= g2) { ny = Math.min(g2, c.y + 30 * dt); c.vy = Math.max(0, c.vy); } + const g2 = Ground.under(nx, nz, Math.max(ny, c.y)); if (ny <= g2) { ny = Math.min(g2, c.y + 30 * dt); c.vy = Math.max(0, c.vy); } c.x = nx; c.y = ny; c.z = nz; c.dist += c.v * dt; const up2 = c.y > g2 + .3; c.gait += ((up2 ? 1 : Math.abs(c.v) > 1 ? .6 : 0) - c.gait) * Math.min(1, dt * 5); @@ -914,7 +907,7 @@ const Drive = { if (D.row) { const r = D.row; D.row = null; const c = this.dragon(r.x, r.y, r.z, r.yaw); if (c) { c.met = 1; c.pet = r.st === 2 ? 'visit' : 'come'; if (r.st === 3) { const yaw = p.yaw, pitch = p.pitch; this.enter({ u: c, n: 0, now: 1 }); p.yaw = yaw; p.pitch = pitch; } } return; } if (Town.cars.some(c => c.kind === 'dragon' && !c.fa)) return; if ((D.t -= dt) > 0) return; - const a = Math.random() * TAU, x = p.x + Math.cos(a) * 230, z = p.z + Math.sin(a) * 230, c = this.dragon(x, Math.max(this.floor(x, z, p.y + 40), p.y) + 70, z, Math.atan2(p.x - x, p.z - z)); + const a = Math.random() * TAU, x = p.x + Math.cos(a) * 230, z = p.z + Math.sin(a) * 230, c = this.dragon(x, Math.max(Ground.under(x, z, p.y + 40), p.y) + 70, z, Math.atan2(p.x - x, p.z - z)); if (c) c.v = 30; else D.t = 5; }, tick(dt, p) { diff --git a/src/game/78_glide.js b/src/game/78_glide.js index 2d332f6a2..4f0e7331b 100644 --- a/src/game/78_glide.js +++ b/src/game/78_glide.js @@ -1,7 +1,7 @@ // ---------- a skateboard and roller skates: rolling on one's own legs ---------- // Both are vehicles of the street (Town.cars) the player stands on (Drive.enter; TOWN_VEH.*.glide), with physics of their own (Glide.step, // from Drive.step) built on the shared pieces of every vehicle: the class (73_vcls.js: how hard a push is, the top a push gets to, the -// brake), Drive.glide against walls and fences (slide along them, or bump), Town.ground under the wheels. What is their own: +// brake), Drive.glide against walls and fences (slide along them, or bump), Ground.at under the wheels. What is their own: // · momentum: let go of the stick and it rolls on, slowly losing speed to the bearings and the air (and a lot more on grass, dirt or sand: // GLIDE_SOFT, so it is a thing for streets, paths and squares); pushing only goes up to the // class top, but a slope adds g·sin(slope) both ways: down a hill it runs past the top, up a ramp it slows and rolls back; @@ -52,7 +52,7 @@ const Glide = { // on the ground: push, brake, the slope, the turn, the wheels over the ground roll(c, dt, G, K, st, thr, pop) { const fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), hl = Math.max(1, c.len * .4); - const gf = Town.ground(c.x + fx * hl, c.z + fz * hl, c.y + 1), gr = Town.ground(c.x - fx * hl, c.z - fz * hl, c.y + 1); + const gf = Ground.at(c.x + fx * hl, c.z + fz * hl, c.y + 1), gr = Ground.at(c.x - fx * hl, c.z - fz * hl, c.y + 1); // the push: as hard as the class pulls, fading towards its top; behind it the rolling and the air; the slope both ways c.push = thr > .05 && c.v < K.top && c.v > -1; if (c.push) { c.v += K.acc * thr * (1 - .6 * Math.max(0, c.v / K.top) ** 2) * dt; c.pp = ((c.pp || 0) + dt * (.9 + c.v / 20)) % 1; } @@ -65,8 +65,8 @@ const Glide = { const y0 = c.y, n = Math.max(1, Math.ceil(a * dt / .8)); for (let i = 0; i < n; i++) Drive.glide(c, c.yaw + rate * dt / n, c.v * dt / n, dt / n, 0); // the wheels on the ground: the board follows it; off a lip or a ledge it flies on with the way it was going - const gm = Town.ground(c.x, c.z, c.y + 1.5), f2 = Math.sin(c.yaw), g2 = Math.cos(c.yaw); - const a1 = Town.ground(c.x + f2 * hl, c.z + g2 * hl, c.y + 1.5), b1 = Town.ground(c.x - f2 * hl, c.z - g2 * hl, c.y + 1.5); + const gm = Ground.at(c.x, c.z, c.y + 1.5), f2 = Math.sin(c.yaw), g2 = Math.cos(c.yaw); + const a1 = Ground.at(c.x + f2 * hl, c.z + g2 * hl, c.y + 1.5), b1 = Ground.at(c.x - f2 * hl, c.z - g2 * hl, c.y + 1.5); // a step down of a curb or a stair (up to 1.2 cells under the ground it was on) it rolls down; off anything higher it flies const gy = c.gy != null ? c.gy : c.y; if (gm == null || gm < gy - 1.2 && (a1 == null || a1 < gy - 1.2)) { c.air = true; c.vy = c.vg || 0; return; } @@ -83,7 +83,7 @@ const Glide = { c.tilt = (c.tilt || 0) * (1 - Math.min(1, dt * 3)); if (c.vy < 0) { // coming down: a rail under the board, or the ground const r = this.rail(c, c.x, c.z, c.y, y1); if (r) return this.lock(c, r); - const g = Drive.bed(c.x, c.z, c.y + 1); + const g = Ground.drop(c.x, c.z, c.y + 1, 72); if (g != null && y1 <= g) { if (c.vy < -32) { c.v *= .6; c.shake = 1; } c.y = c.gy = g; c.vy = 0; c.air = false; c.vg = 0; Sfx.play('step', c); return; } } if (c.vy > 0 && this.hit(c, c.x, c.z, y1)) c.vy = 0; // a head against a ceiling @@ -92,7 +92,7 @@ const Glide = { // the body of the board and its rider at (x, z) with the feet at y: does it run into blocks? (the lowest half cell is the wheels: they roll over it) // dir: moving forwards (1) or backwards (-1) only the leading half can run into something: the trailing end may still hang over the step it left hit(c, x, z, y, dir) { - const w = Walk.w, s = Math.sin(c.yaw), cs = Math.cos(c.yaw), hl = c.len / 2 - .2, y0 = Math.floor(y + .45); // a lip lower than the wheels does not stop it: it lands on it (Drive.bed) + const w = Walk.w, s = Math.sin(c.yaw), cs = Math.cos(c.yaw), hl = c.len / 2 - .2, y0 = Math.floor(y + .45); // a lip lower than the wheels does not stop it: it lands on it (Ground.drop) for (const a of dir > 0 ? [0, hl] : dir < 0 ? [-hl, 0] : [-hl, 0, hl]) { const X = Math.floor(x + s * a), Z = Math.floor(z + cs * a); for (let Y = y0; Y < y0 + 9; Y++) if (w.solid(X, Y, Z)) return true; } return false; }, diff --git a/src/game/78_hitch.js b/src/game/78_hitch.js index 5bd3a5f06..212066ada 100644 --- a/src/game/78_hitch.js +++ b/src/game/78_hitch.js @@ -47,7 +47,7 @@ const Hitch = { const i = a.units.indexOf(b); if (i < 1 || !b.hk) return false; a.units.splice(i, 1); a.vc = null; this.ends(a); if (a.inst) a.inst.lift = 0; b.hk = null; b.off = 0; b.car = b; b.units = [b]; b.ka = null; b.kt = null; b.tilt = 0; b.v = 0; b.dist = b.dist || 0; - const y = Town.ground(b.x, b.z, b.y + 2); if (y != null) b.y = y; + const y = Ground.at(b.x, b.z, b.y + 2); if (y != null) b.y = y; b.mode = b.occ[0] && b.occ[0] !== 'you' ? 'back' : 'park'; b.stuck = 0; b.rev = 0; b.lost = 0; b.empty = !b.occ[0]; Town.cars.push(b); Town.place(b, 0); Net.touch(b); if (b.own && !b.occ.includes('you')) Drive.park(b); // an own trailer (or a car let down off the lift) left behind is furniture again, unless the player sits in it @@ -78,7 +78,7 @@ const Hitch = { let gf = null, gr = null; for (let i = -na; i <= na; i++) for (const j of [-1, 0, 1]) { if (j === 0 && i % 2) continue; - const a = hl * i / na, px = x + s * a + cs * hw * j, pz = z + cs * a - s * hw * j, g = Drive.bed(px, pz, b.y + HITCH.climb + 1); + const a = hl * i / na, px = x + s * a + cs * hw * j, pz = z + cs * a - s * hw * j, g = Ground.drop(px, pz, b.y + HITCH.climb + 1, 72); if (g == null || g > b.y + HITCH.climb) return null; const X = Math.floor(px), Z = Math.floor(pz); for (let k = 1; k < top; k++) if (w.solid(X, g + k, Z) && !CRASH_DUST[w.pm[w.get(X, g + k, Z)]]) return null; if (i === na) gf = Math.max(gf == null ? -1e9 : gf, g); if (i === -na) gr = Math.max(gr == null ? -1e9 : gr, g); @@ -147,7 +147,7 @@ const Hitch = { return best; } // a trailer standing behind: its drawbar within reach of the ball - const P = [a.x + Math.sin(a.yaw) * this.spot(a), a.z + Math.cos(a.yaw) * this.spot(a)], gy = Town.ground(P[0], P[1], a.y + 2), py = gy == null ? a.y : gy; // the ground under the ball: on a slope the car's middle stands higher or lower than the coupling it meets + const P = [a.x + Math.sin(a.yaw) * this.spot(a), a.z + Math.cos(a.yaw) * this.spot(a)], gy = Ground.at(P[0], P[1], a.y + 2), py = gy == null ? a.y : gy; // the ground under the ball: on a slope the car's middle stands higher or lower than the coupling it meets for (const b of Town.cars) if (b !== a && b.veh.tr && b.units.length === 1 && !b.occ[0]) { const H = this.hook(b, 1); if (Math.hypot(H[0] - P[0], H[1] - P[1]) < HITCH.ball && Math.min(Math.abs(b.y - py), Math.abs(b.y - a.y)) < 3) return { k: 'ball', b }; } diff --git a/src/game/78_roll.js b/src/game/78_roll.js index 92a0c7cc2..97a575aba 100644 --- a/src/game/78_roll.js +++ b/src/game/78_roll.js @@ -26,16 +26,11 @@ const Roll = { const P = [[-w, 0, 1], [w, 0, 1], [W, H * .32, 0], [W * .82, H, 0], [-W * .82, H, 0], [-W, H * .32, 0]]; return (m.roll = { P, hc: Math.min(T.h, H * .7), k2: Math.max(.5, T.k2), H }); }, - // the top of the ground in the column at (x, z) at most a little above y; null: nothing to stand on (a void, water) - top(x, z, y) { - const w = Walk.w, X = Math.floor(x), Z = Math.floor(z); - for (let Y = Math.floor(y) + 2; Y > y - 40; Y--) { if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) return Y; const id = w.get(X, Y - 1, Z); if (id && w.transp[id] === 2) return null; } - return null; - }, - // the highest ground across the body's length at lateral offset X (cells to the right of c.x, c.z) + // the highest ground across the body's length at lateral offset X (cells to the right of c.x, c.z): Ground.at at three points of it; + // null: nothing to stand on (a void, water) ground(c, X, y) { const fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), x = c.x + fz * X, z = c.z - fx * X, hl = c.len * .3; let g = null; - for (let k = -1; k <= 1; k++) { const q = this.top(x + fx * hl * k, z + fz * hl * k, y); if (q != null && (g == null || q > g)) g = q; } + for (let k = -1; k <= 1; k++) { const q = Ground.at(x + fx * hl * k, z + fz * hl * k, y, GROUND.roll); if (q != null && (g == null || q > g)) g = q; } return g; }, // over it goes (Drive.tip, the weight past the outer wheels): from the turn about the outer wheels to a free body. ph, om: the tip and @@ -102,7 +97,7 @@ const Roll = { // lying still on its side or its roof: rocked back after a while if (Math.abs(w) < .4 && Math.abs(u) < 1 && Math.abs(vy) < 2 && Math.abs(c.v) < .5 && (body || wheels)) { if ((S.t += dt) > P.rest) { S.fix = 1; if (c === (Walk.ride && Walk.ride.car)) toast(tr('💥 Перевернулись! Сейчас поставим на колёса', '💥 Tipped over! Putting it back on its wheels'), 2600); } } else S.t = 0; // along its heading it goes on as it went: a wall at the front (or the back, going backwards) stops it with a thump - const d = c.v * dt; if (d) { const a = Math.sign(d) * c.len / 2 + d, gw = this.top(c.x + fx * a + fz * Xc, c.z + fz * a - fx * Xc, Yc + 1); + const d = c.v * dt; if (d) { const a = Math.sign(d) * c.len / 2 + d, gw = Ground.at(c.x + fx * a + fz * Xc, c.z + fz * a - fx * Xc, Yc + 1, GROUND.roll); if (gw != null && gw > Yc + 1.5) { if (Math.abs(c.v) > 6) { Sfx.play('crash', c); c.shake = 1; } c.v *= -.15; } else { c.x += fx * d; c.z += fz * d; } } // the line under the middle of the body moves with it: sideways over the ground (a wall it rolls into stops it) const Xo = Xc + hc * Math.sin(th), nx = c.x + fz * Xo, nz = c.z - fx * Xo, Yo = Yc - hc * Math.cos(th); diff --git a/src/game/78_rotor.js b/src/game/78_rotor.js index 4afe01ea3..5de6e27d4 100644 --- a/src/game/78_rotor.js +++ b/src/game/78_rotor.js @@ -20,7 +20,6 @@ const Rotor = { // a new rotorcraft state on H (hovering where it is; put above whatever it would be in: a roof, a crown, a tower) init(H) { if (Walk.w) for (let n = 0; n < 150 && this.pose(H.x, H.y, H.z, H.yaw); n++) H.y += 4; H.vx = H.vy = H.vz = 0; H.wy = 0; H.tilt = H.tilt || 0; H.bank = H.bank || 0; H.in = { col: 1 / ROTOR.T, cp: 0, cr: 0, cy: 0 }; H.gnd = 0; return H; }, // the ground the skids cannot go below where nothing is loaded yet (the terrain, the water) - floor(x, z) { const T = Walk.w.T, q = T.q; T.q = 0; const h = Math.ceil(Math.max(T.at(x, z), WL)); T.q = q; return h; }, // the points of the body at (x, y, z) heading yaw that are in a block, as bits (where the land is loaded: elsewhere only the ground counts, Rotor.floor) pose(x, y, z, yaw) { const w = Walk.w, s = Math.sin(yaw), c = Math.cos(yaw), P = ROTOR.pts; let m = 0; @@ -62,7 +61,7 @@ const Rotor = { if (this.hits(x1, ny, z1, H.yaw)) { if (H.vy < 0) H.gnd = 1; H.vy = 0; ny = H.y; } nx = x1; nz = z1; H.blk = (H.blk || 0) + dt; } else { H.blk = Math.max(0, (H.blk || 0) - dt); if (H.vy > .5 || !this.hits(nx, ny - .3, nz, H.yaw)) H.gnd = 0; } - const fl = this.floor(nx, nz); if (ny <= fl) { ny = fl; if (H.vy < 0) H.vy = 0; H.gnd = 1; } + const fl = Ground.land(nx, nz); if (ny <= fl) { ny = fl; if (H.vy < 0) H.vy = 0; H.gnd = 1; } if (H.gnd && T * up < R.g) { const f = Math.max(0, 1 - dt * 6); H.vx *= f; H.vz *= f; H.wy *= f; } // the skids hold it where it sits (while its weight is on them) H.x = nx; H.y = ny; H.z = nz; H.v = Math.hypot(H.vx, H.vz); }, @@ -80,10 +79,7 @@ const Rotor = { }, // the top of whatever stands at (x, z): the highest block of the column where the land is loaded (a crown, a roof, a tower), else the ground top(x, z) { - const X = Math.floor(x), Z = Math.floor(z), g = this.floor(X, Z); if (!Town.loaded(X, Z)) return g; - const w = Walk.w, ch = w.col(X >> 4, Z >> 4).ch; - for (let cy = LNCY - 1; cy >= 0; cy--) { if (ch[cy] === 0) continue; for (let y = cy * 16 + 15; y >= cy * 16; y--) if (w.solid(X, y, Z)) return Math.max(g, y + 1); } - return g; + const X = Math.floor(x), Z = Math.floor(z), g = Ground.land(X, Z); return Town.loaded(X, Z) ? Math.max(g, Ground.sky(X, Z)) : g; }, // ---- the pilot: the controls that take it to (tx, ty, tz) at up to V cells/s over the ground ---- // It flies at the point, faster the further it is but never faster than it can still stop there (leaning back as hard as the machine diff --git a/src/game/78_susp.js b/src/game/78_susp.js index c493c99da..7bbaabecc 100644 --- a/src/game/78_susp.js +++ b/src/game/78_susp.js @@ -44,8 +44,8 @@ const Susp = { // middle; null if nothing under the wheel (a void, water, or the wheel inside a wall) // (a step higher than a wheel climbs, DRIVE_STEP, is not smoothed into a ramp: it stays a wall that the body runs into, worldFree) wheel(x, z, fx, fz, y, fp) { - let s = 0, n = 0; const g0 = Town.ground(x, z, y), lim = DRIVE_STEP + .5; - for (let k = -fp; k <= fp; k++) { const g = k ? Town.ground(x + fx * k, z + fz * k, y) : g0, q = fp + 1 - Math.abs(k); if (g != null && g < y + 3.5 && (g0 == null || Math.abs(g - g0) <= lim)) { s += g * q; n += q; } } + let s = 0, n = 0; const g0 = Ground.at(x, z, y), lim = DRIVE_STEP + .5; + for (let k = -fp; k <= fp; k++) { const g = k ? Ground.at(x + fx * k, z + fz * k, y) : g0, q = fp + 1 - Math.abs(k); if (g != null && g < y + 3.5 && (g0 == null || Math.abs(g - g0) <= lim)) { s += g * q; n += q; } } return n ? s / n : null; }, // the ground under the four wheels of c (Gs: an array of 4, null where none) diff --git a/src/game/79_arm.js b/src/game/79_arm.js index 59e8db446..8d09f1ea8 100644 --- a/src/game/79_arm.js +++ b/src/game/79_arm.js @@ -159,14 +159,13 @@ const Arm = { hookGoal(c, A, S, T) { const L = A.load; if (!L) return T[1] + (A.roof ? .2 : .1); const hw = A.hw || T, r = L.car ? Math.max(L.car.len, L.car.wid) / 2 : L.r; let top = T[1] - 1; - for (const [dx, dz] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1], [.7, .7], [-.7, .7], [.7, -.7], [-.7, -.7]]) for (const P of [T, hw]) top = Math.max(top, this.floor(P[0] + dx * r, P[2] + dz * r, P[1] + 40)); // over whatever stands under it, on the way and where it goes + for (const [dx, dz] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1], [.7, .7], [-.7, .7], [.7, -.7], [-.7, -.7]]) for (const P of [T, hw]) top = Math.max(top, Ground.top(P[0] + dx * r, P[2] + dz * r, P[1] + 41, 90) ?? P[1] - 50); // over whatever stands under it, on the way and where it goes for (const v of Town.cars) { // and over the vehicles standing there if (v === c || v === L.car) continue; const rr = r + Math.max(v.len || 8, v.wid || 4) / 2; if (Math.hypot(v.x - T[0], v.z - T[2]) < rr || Math.hypot(v.x - hw[0], v.z - hw[2]) < rr) top = Math.max(top, v.y + (v.ht || 6)); } return top + 4 + L.h + ARM.sling + .8; // carried a little under a metre above what it passes over }, - floor(x, z, y0) { const w = Walk.w, X = Math.floor(x), Z = Math.floor(z); for (let y = Math.floor(y0); y > y0 - 90 && y > 0; y--) if (w.solid(X, y, Z)) return y + 1; return y0 - 90; }, // ---- the hydraulics ---- move(c, A, S, dt) { const R = ARM.rate, step = (v, t, r) => v + clamp(t - v, -r * dt, r * dt); @@ -388,7 +387,7 @@ const Arm = { if (H) { // the hose: off the outlet down to the ground, along it to the feet and up to the hands (a red canvas hose) const p = Walk.p, o = H.o, f = Jet.from(), n = 8; let px = o[0], py = o[1], pz = o[2]; for (let i = 0; i <= n; i++) { - const k = i / n, x = o[0] + (p.x - o[0]) * k, z = o[2] + (p.z - o[2]) * k, g = Town.ground(x, z, Math.max(o[1], p.y) + 4), y = (g == null ? p.y : g) + .15; + const k = i / n, x = o[0] + (p.x - o[0]) * k, z = o[2] + (p.z - o[2]) * k, g = Ground.at(x, z, Math.max(o[1], p.y) + 4), y = (g == null ? p.y : g) + .15; line(px, py, pz, x, y, z, 1); px = x; py = y; pz = z; } line(px, py, pz, f[0], f[1], f[2], 1); diff --git a/src/game/79_art.js b/src/game/79_art.js index bc0efba7d..a7b294e0f 100644 --- a/src/game/79_art.js +++ b/src/game/79_art.js @@ -73,7 +73,7 @@ const Art = { const s = Settle.on && Settle.at(w.T, p.x, p.z); if (s && Math.hypot(p.x - s.x, p.z - s.z) < s.R + R) { const P = Settle.plan(w, s), sk = s.gx + '_' + s.gz + '_'; - const rest = (x, y0, z) => { const X = Math.floor(x), Z = Math.floor(z); if (!Town.loaded(x, z)) return null; for (let y = Math.floor(y0); y > y0 - 8; y--) if (w.solid(X, y - 1, Z) && !w.solid(X, y, Z)) return y; return null; }; + const rest = (x, y0, z) => Town.loaded(x, z) ? Ground.drop(x, z, y0, 8) : null; P.seats.forEach((q, j) => { if (Math.abs(q.x - p.x) > R || Math.abs(q.z - p.z) > R) return; nest('b' + sk + j, 'b', ART.P.b, () => { const y = rest(q.x, P.y + 3, q.z); return y == null ? null : [q.x, y, q.z, (q.yaw || 0) + (this.hk('b' + j, 4) - .5)]; }); }); P.stops.forEach((q, j) => { if (Math.abs(q.x - p.x) > R || Math.abs(q.z - p.z) > R) return; nest('s' + sk + j, 's', ART.P.s, () => { const y = rest(q.x, P.y + 3, q.z); return y == null ? null : [q.x, y, q.z, this.hk('s' + j, 4) * TAU]; }); }); (P.play || []).forEach((q, j) => { if (Math.abs(q.x - p.x) > R || Math.abs(q.z - p.z) > R) return; const k = 'p' + sk + j; nest(k, 'p', ART.P.p, () => { const x = q.x + (this.hk(k, 5) - .5) * 4, z = q.z + (this.hk(k, 6) - .5) * 4, y = rest(x, P.y + 4, z); return y == null ? null : [x, y, z, this.hk(k, 4) * TAU]; }); }); @@ -84,7 +84,7 @@ const Art = { const k = 'g' + gx + '_' + gz; if (this.units.has(k) || this.gone.has(k)) { seen.add(k); continue; } if (this.no.get(k) === null) { seen.add(k); continue; } const x = (gx + .15 + .7 * this.hk(k, 5)) * G, z = (gz + .15 + .7 * this.hk(k, 6)) * G; if (!Town.loaded(x, z)) continue; - const X = Math.floor(x), Z = Math.floor(z), y = Town.ground(x, z, T.at(x, z)); if (y == null) { seen.add(k); this.no.set(k, null); continue; } + const X = Math.floor(x), Z = Math.floor(z), y = Ground.at(x, z, T.at(x, z)); if (y == null) { seen.add(k); this.no.set(k, null); continue; } const id = w.get(X, y - 1, Z), m = id ? w.pm[id] : -1, c = m === MAT.sand ? 'e' : m === MAT.grass || m === MAT.dirt || m === MAT.leaves ? 'g' : m === MAT.water ? '' : 'g'; if (!c || w.get(X, y, Z)) { seen.add(k); this.no.set(k, null); continue; } nest(k, c, c === 'e' ? ART.P.e : ART.P.g * (m === MAT.grass || m === MAT.dirt ? 1 : .5), () => [x, y, z, this.hk(k, 4) * TAU]); @@ -155,14 +155,13 @@ const Art = { // put a thing from the backpack down in front of the player put(s, c) { if (!this.has(s)) return null; const w = this.w, p = Walk.p; if (!w) return null; - const x = p.x + Math.sin(p.yaw) * 3, z = p.z + Math.cos(p.yaw) * 3, y = (w.inf ? Town.ground(x, z, p.y + 2) : null) ?? this.floor(x, p.y + 2, z); + const x = p.x + Math.sin(p.yaw) * 3, z = p.z + Math.cos(p.yaw) * 3, y = (w.inf ? Ground.at(x, z, p.y + 2) : null) ?? Ground.drop(x, z, p.y + 2, 12); if (y == null) { Sfx.play('err'); toast(tr('🚫 Сюда не положить', '🚫 Cannot put it here'), 1400); return null; } this.sub(s); const A = this.A(s), k = 'd' + Net.pid + '_' + Date.now().toString(36) + Math.floor(Math.random() * 1e4).toString(36); const d = { k, s, x, y, z, yaw: p.yaw + Math.PI, c: A && A.m === 'chest' ? (c || []) : null }; this.dropIn(d); Net.art(['d', k, s, +x.toFixed(2), +y.toFixed(2), +z.toFixed(2), +d.yaw.toFixed(2), d.c ? d.c.join(',') : '']); Sfx.play('place', [x, y, z]); Save.touch(); return this.units.get(k); }, - floor(x, y0, z) { const w = this.w, X = Math.floor(x), Z = Math.floor(z); for (let y = Math.floor(y0); y > y0 - 12 && y > 0; y--) if (w.solid(X, y - 1, Z) && !w.solid(X, y, Z)) return y; return null; }, dropIn(d) { this.drops.set(d.k, d); this.gone.delete(d.k); this.spawn(d.k, d.s, d.x, d.y, d.z, d.yaw, 'd'); }, // ---- the hand ---- hold(s) { if (!this.has(s)) return; this.unlook(); this.hand = s; this.fpT = null; if (Build.mode !== 'art') Walk.setMode('art'); else { Walk.refreshSub(); Walk.refreshActs(); } toast(this.name(s), 1100); }, diff --git a/src/game/79_boom.js b/src/game/79_boom.js index 4287efa59..06be379c3 100644 --- a/src/game/79_boom.js +++ b/src/game/79_boom.js @@ -219,7 +219,7 @@ const Boom = { // more after that: things put into the world that were held before (by the floor, a wall, a ceiling, the table under them) and now // touch nothing come down to whatever is under them; parked vehicles drop into the crater; the walking grids of the homes nearby // are measured again, so their people go down into the hole (Nav.lift) and climb out of it on their way. People of the towns - // (Folk, sink) and animals (Fauna.foot) find the bottom of a pit by themselves (Town.ground looks down through air). + // (Folk, sink) and animals (Fauna.foot) find the bottom of a pit by themselves (Ground.at looks down through air). // The things that came down are part of the command of the blast: one undo step puts them back where they were. aft: [], falls: [], near(i, cx, cy, cz) { const b = Cmd.ibox(i); return Math.hypot(clamp(cx, b[0], b[3] + 1) - cx, clamp(cy, b[1], b[4] + 1) - cy, clamp(cz, b[2], b[5] + 1) - cz); }, @@ -291,7 +291,7 @@ const Boom = { for (const c of Town.cars) { if (c.mode !== 'park' || !(c.still && c.empty) || Math.hypot(c.x - a.x, c.z - a.z) > r + (c.len || 8) / 2 || this.falls.some(f => f.c === c)) continue; const fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), L = (c.len || 8) * .35, W2 = (c.wid || 6) * .35; let g = null; - for (const [u, v] of [[0, 0], [L, W2], [L, -W2], [-L, W2], [-L, -W2]]) { const y = Town.ground(c.x + fx * u + fz * v, c.z + fz * u - fx * v, c.y); if (y != null && (g == null || y > g)) g = y; } + for (const [u, v] of [[0, 0], [L, W2], [L, -W2], [-L, W2], [-L, -W2]]) { const y = Ground.at(c.x + fx * u + fz * v, c.z + fz * u - fx * v, c.y); if (y != null && (g == null || y > g)) g = y; } if (g == null || g > c.y - .3) continue; const y0 = c.y; this.falls.push({ c, g, vy: 0 }); if (cmd) cmd.ops.push({ do: () => {}, undo: () => { const k = this.falls.findIndex(f => f.c === c); if (k >= 0) this.falls.splice(k, 1); c.y = y0; Town.place(c, 0); } }); @@ -306,7 +306,7 @@ const Boom = { // (a crater) falling, and climbs back out of it as its way goes on; elsewhere it simply stands at y sink(o, x, z, y, dt) { const w = Walk.w; if (!w || !w.modC || !w.modC.has(ckey(Math.floor(x) >> 4, Math.floor(z) >> 4))) { o.gy = null; return y; } - let g = Town.loaded(x, z) ? Town.ground(x, z, y) : null; g = g == null ? y : Math.min(g, y); + let g = Town.loaded(x, z) ? Ground.at(x, z, y) : null; g = g == null ? y : Math.min(g, y); if (o.gy == null || dt < 0) { o.gy = g; o.vy = 0; return g; } if (g < o.gy) { o.vy = (o.vy || 0) + 45 * dt; o.gy = Math.max(g, o.gy - o.vy * dt); } else { o.vy = 0; o.gy = Math.min(g, o.gy + dt * 9); } return o.gy; diff --git a/src/game/79_farm.js b/src/game/79_farm.js index 3fb69525b..16a2bbe08 100644 --- a/src/game/79_farm.js +++ b/src/game/79_farm.js @@ -272,7 +272,7 @@ const Farm = { put(c, W, s, dt) { const g = Kin.geo(c), a = W.at(s + (g.rs ? g.ar : g.af)); Kin.track(c, a[0], a[1], a[2], !!g.rs, dt); // (rear-wheel steering: the front axle is the pivot, the rear one trails it) const fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), hl = c.len * .35, T = this.w.T; - const gy = (x, z) => { const h = Math.ceil(Math.max(T.at(x, z), WL)); return Town.loaded(x, z) ? Drive.floor(x, z, h + 1) : h; }, gf = gy(c.x + fx * hl, c.z + fz * hl), gr = gy(c.x - fx * hl, c.z - fz * hl), e = dt ? Math.min(1, dt * 10) : 1; + const gy = (x, z) => { const h = Ground.land(x, z); return Town.loaded(x, z) ? Ground.under(x, z, h + 1) : h; }, gf = gy(c.x + fx * hl, c.z + fz * hl), gr = gy(c.x - fx * hl, c.z - fz * hl), e = dt ? Math.min(1, dt * 10) : 1; const hw = c.wid * .35, gL = gy(c.x - fz * hw, c.z + fx * hw), gR = gy(c.x + fz * hw, c.z - fx * hw), k = dt ? Math.min(1, dt * 6) : 1; // (and across: a wide machine on a side slope leans with it, so the physics takes it over as it stands, Pilot.near) c.y += ((gf + gr) / 2 - c.y) * e; c.tilt = (c.tilt || 0) + (clamp(Math.atan2(gr - gf, hl * 2), -.45, .45) - (c.tilt || 0)) * k; c.bank = (c.bank || 0) + (clamp(Math.atan2(gR - gL, hw * 2), -.45, .45) - (c.bank || 0)) * k; c.dist += Math.abs(c.v) * dt; if (c.veh.tl && Town.loaded(c.x, c.z)) Drive.lift(c, dt, !c.fon); diff --git a/src/game/79_fire.js b/src/game/79_fire.js index 5a208dd9a..8fd83e0a3 100644 --- a/src/game/79_fire.js +++ b/src/game/79_fire.js @@ -100,7 +100,7 @@ const Fire = { for (const f of this.list) { if (!f.cA || f.a > f.o + 14) { f.eng = null; continue; } const pk = this.park(f), back = f.a > f.o + 5, s = back ? (f.a - f.o - 5) * FIRE.drive : Math.max(0, (f.cA - f.a) * FIRE.drive); if (s > 520 || Math.hypot(pk.x - p.x, pk.z - p.z) > 700) continue; - const gy = (x, z) => { const h = Math.floor(w.T.at(x, z)), g = Town.ground(x, z, h); return g == null ? h : g; }; + const gy = (x, z) => { const h = Math.floor(w.T.at(x, z)), g = Ground.at(x, z, h); return g == null ? h : g; }; if (!f.sent && Town.dispatch) f.sent = Town.dispatch(this.callOf(f)) ? 2 : 1; if (f.sent !== 2) { const it = Town.it('car_fire') || Town.it('car_van'); if (!it) continue; @@ -129,7 +129,7 @@ const Fire = { if (ld) r = Nav.go(c, tx, tz, k, Nav.MAN); else { c.x += dx / d * k; c.z += dz / d * k; c.nx = dx / d; c.nz = dz / d; } // (not loaded in detail: straight) if (r < 0) { if (d < 6) c.at = want; else if ((c.blk += dt) > 3) c.at = want; } else if (r > 0) c.blk = 0; // the very spot is taken by a trunk, or no way there at all: as near as it gets if (c.nx != null) c.yaw = _turn(c.yaw, Math.atan2(c.nx, c.nz), dt * 8); - const g = ld ? Town.ground(c.x, c.z, c.y) : null; if (g != null) Nav.lift(c, g, dt); else c.y = gy(c.x, c.z); + const g = ld ? Ground.at(c.x, c.z, c.y) : null; if (g != null) Nav.lift(c, g, dt); else c.y = gy(c.x, c.z); c.gait += ((r > 0 ? 1 : 0) - c.gait) * Math.min(1, dt * 9); c.inst.arms = 0; } else if (c.at === want) { if (home) return; c.gait += (0 - c.gait) * Math.min(1, dt * 9); c.inst.arms = 1; c.jy = 0; c.yaw = _turn(c.yaw, Math.atan2(f.x - c.x, f.z - c.z), dt * 6); } // (back at the engine: inside) U.push(c); if (c.at !== 2) Nav.mind(c, Nav.MAN, 0); diff --git a/src/game/79_fix.js b/src/game/79_fix.js index 3e6ffcf83..0f29eb5eb 100644 --- a/src/game/79_fix.js +++ b/src/game/79_fix.js @@ -138,8 +138,8 @@ const Fix = { pyaw(s) { const pk = this.park(s), P = s.rt && s.rt.pts, n = P ? P.length : 0; if (n >= 3) return Math.atan2(P[n - 2][0] - P[n - 3][0], P[n - 2][1] - P[n - 3][1]); return Math.atan2(-pk.ux, -pk.uz); }, // a flat patch of the truck's size along (ux, uz) with nothing standing on it room(x, z, ux, uz) { - const w = Walk.w, g = Law.ground(x, z); - for (let i = -3; i <= 3; i++) for (let j = -1; j <= 1; j++) { const X = Math.floor(x + ux * i * 2.6 + uz * j * 3), Z = Math.floor(z + uz * i * 2.6 - ux * j * 3), h = Law.ground(X, Z, g); if (Math.abs(h - g) > 2) return false; for (let k = 0; k < 7; k++) if (w.solid(X, h + k, Z)) return false; } + const w = Walk.w, g = Ground.road(x, z); + for (let i = -3; i <= 3; i++) for (let j = -1; j <= 1; j++) { const X = Math.floor(x + ux * i * 2.6 + uz * j * 3), Z = Math.floor(z + uz * i * 2.6 - ux * j * 3), h = Ground.road(X, Z, g); if (Math.abs(h - g) > 2) return false; for (let k = 0; k < 7; k++) if (w.solid(X, h + k, Z)) return false; } return true; }, // ---- the list of work: the difference between the world and the generator inside the site, one column a frame ---- @@ -342,7 +342,7 @@ const Fix = { const seed = (s.id * 2654435761) >>> 0, c = Town.build('car_works', x, z, yaw, { R: RNG(seed), seed, solo: true, col: '#f2b21b' }); if (!c) return null; if (c.inst.slots.length > 12) { const sl = c.inst.slots.map(q => q.slice()); sl[11][0] = '#5a3a08'; sl[12][0] = '#5a3a08'; c.instA = c.inst; c.instB = makeInst(c.it, 0, 0, 0, 0, sl); } Object.assign(c, { mode: 'fix', ghost: true, v: 0, edge: false, dir: 1, empty: false, fix: s }); - c.y = Law.ground(x, z); Town.place(c, 0); return Occ.add(c, 'must'); + c.y = Ground.road(x, z); Town.place(c, 0); return Occ.add(c, 'must'); }, body(s, p) { const pk = this.park(s); @@ -354,7 +354,7 @@ const Fix = { } if (!s.car) { s.car = this.truck(s, pk.x, pk.z, this.pyaw(s)); if (!s.car) return; } if (!s.crew && s.car.crew.length) this.out(s); - if (!s.crew) { s.crew = []; for (let k = 0; k < FIX.crew; k++) { const o = this.man(s, k), [x, z] = Drive.world(s.car, 0, (k - 1) * 3.2); o.x = x - Math.sin(s.car.yaw) * (s.car.len / 2 + 2); o.z = z - Math.cos(s.car.yaw) * (s.car.len / 2 + 2); o.y = Law.ground(o.x, o.z, s.car.y); o.yaw = s.car.yaw; s.crew.push(o); } } + if (!s.crew) { s.crew = []; for (let k = 0; k < FIX.crew; k++) { const o = this.man(s, k), [x, z] = Drive.world(s.car, 0, (k - 1) * 3.2); o.x = x - Math.sin(s.car.yaw) * (s.car.len / 2 + 2); o.z = z - Math.cos(s.car.yaw) * (s.car.len / 2 + 2); o.y = Ground.road(o.x, o.z, s.car.y); o.yaw = s.car.yaw; s.crew.push(o); } } }, unbody(s) { const c = s.car; if (c) { const i = Town.cars.indexOf(c); if (i >= 0 && (!Walk.ride || Walk.ride.car !== c)) Town.cars.splice(i, 1); } @@ -363,7 +363,7 @@ const Fix = { // the crew gets out at the doors of the cab out(s) { const c = s.car; if (!c) return; s.crew = []; - for (const o of c.crew.slice()) { const [x, z] = Drive.beside(c, o.seat, 1.4), q = [o.x, o.y, o.z], n = o.seat; Town.vacate(c, o); o.inst.legs = 0; o.inst.arms = 0; o.brd = Drive.board(c, n, 'out', [x, Law.ground(x, z, c.y), z], q); Drive.through(o.brd, 0, o); /* out by the door of the seat: the one way, Drive.board */ o.yaw = c.yaw; o.nv = null; o.gait = 0; o.jy = 0; o.blk = 0; s.crew.push(o); } + for (const o of c.crew.slice()) { const [x, z] = Drive.beside(c, o.seat, 1.4), q = [o.x, o.y, o.z], n = o.seat; Town.vacate(c, o); o.inst.legs = 0; o.inst.arms = 0; o.brd = Drive.board(c, n, 'out', [x, Ground.road(x, z, c.y), z], q); Drive.through(o.brd, 0, o); /* out by the door of the seat: the one way, Drive.board */ o.yaw = c.yaw; o.nv = null; o.gait = 0; o.jy = 0; o.blk = 0; s.crew.push(o); } c.crew.length = 0; Sfx.play('door', c); }, // and back in when the work is done; whoever is not back in time comes on board unseen @@ -385,7 +385,7 @@ const Fix = { if (ld && o.blk < FIX.give) r = Nav.go(o, tx, tz, k, Nav.MAN); else { o.x += dx / d * k; o.z += dz / d * k; o.nx = dx / d; o.nz = dz / d; } if (r < 0 || r === 0) o.blk += dt; else if (o.blk < FIX.give) o.blk = Math.max(0, o.blk - dt); if (o.nx != null) o.yaw = _turn(o.yaw, Math.atan2(o.nx, o.nz), dt * 8); - const g = ld ? Town.ground(o.x, o.z, o.y) : null; if (g != null) Nav.lift(o, g, dt); else o.y = Law.ground(o.x, o.z, o.y); + const g = ld ? Ground.at(o.x, o.z, o.y) : null; if (g != null) Nav.lift(o, g, dt); else o.y = Ground.road(o.x, o.z, o.y); o.gait += ((r > 0 ? 1 : 0) - o.gait) * Math.min(1, dt * 9); o.inst.arms = 0; return r; }, @@ -486,7 +486,7 @@ const Fix = { } else { const D = pk.D * f, k = away ? -1 : 1; x = pk.x + pk.ux * D * k; z = pk.z + pk.uz * D * k; yaw = go || away ? Math.atan2(-pk.ux * k, -pk.uz * k) : this.pyaw(s); } c.yaw = dt && c.dr ? _turn(c.yaw, yaw, dt * 4) : yaw; c.dr = 1; - const fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), hl = c.len * .35, gf = Law.ground(x + fx * hl, z + fz * hl, c.y), gr = Law.ground(x - fx * hl, z - fz * hl, c.y), e = dt ? Math.min(1, dt * 10) : 1; + const fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), hl = c.len * .35, gf = Ground.road(x + fx * hl, z + fz * hl, c.y), gr = Ground.road(x - fx * hl, z - fz * hl, c.y), e = dt ? Math.min(1, dt * 10) : 1; c.x = x; c.z = z; c.v = mv ? FIX.V : 0; c.dist += c.v * dt; c.y += ((gf + gr) / 2 - c.y) * e; c.tilt = (c.tilt || 0) + (clamp(Math.atan2(gr - gf, hl * 2), -.45, .45) - (c.tilt || 0)) * e; if (c.instB) c.inst = s.ph >= 1 && s.ph <= 3 && Math.floor(Anim.t * 3 + s.id) % 2 ? c.instB : c.instA; Town.place(c, dt); diff --git a/src/game/79_law.js b/src/game/79_law.js index da89921ec..b261cc0ca 100644 --- a/src/game/79_law.js +++ b/src/game/79_law.js @@ -189,14 +189,6 @@ const Law = { return S.cell = { x: q.x + ux * m, z: q.z + uz * m, ux, uz, bx: q.x, bz: q.z, y: S.sh.y, r: Math.max(3.2, m - 1.2) }; }, // ---- the cars ---- - // the floor under (x, z) at about the height y: a roof, a bridge or the land; never below the land (a car that arrives from the unbuilt far - // world may be under a slope, and a search from there would find nothing and sink it) - // the ground a car or a person stands on at x, z: looked for from y down (where they are now); without y (one put there: a taxi that comes - // into view, one brought back after a reload) from the highest way there is: a bridge deck of the road network (T.dk, the decks over the point, of the road that - // is there: not an overpass of another road; T.rdb is cleared again by what Terr.at lays after the decks, so it is not to be trusted here) or of the home - // street (T.deck: its deck is at LG, 32_land.js) over the land, not the river bed under it. The land is asked at full detail (T.q 0: the far - // tiles leave a coarser T.q behind, and at a coarse step the road network and its decks are not looked up at all) - ground(x, z, y) { const w = Walk.w, T = w.T, q = T.q; T.q = 0; const h0 = Math.ceil(Math.max(T.at(x, z), WL)); T.q = q; let h = h0; if (y == null) { h = Math.max(h, T.deck(x, z, 0) ? LG : 0); if (T.dk) for (const e of T.dk) if (e.d <= e.r.w + 1 && (!T.rdr || e.r === T.rdr)) h = Math.max(h, Math.ceil(e.y)); } if (!Town.loaded(x, z)) return h; const s = Math.max(y != null ? y : h, h - 1), f = Drive.floor(x, z, s); return f > s - 60 ? f : h; }, // a patrol car with two officers: from the station along the roads (Navi.way, the shortest way, as the navigator finds it) to a spot near // the player on the side of the road, or to the road itself when the player is far from it. Until the way is found the car is nowhere (c.hid) send() { @@ -206,7 +198,7 @@ const Law = { const n = this.cars.length, a = (n % 3 - 1) * .5, ex = dx * Math.cos(a) - dz * Math.sin(a), ez = dx * Math.sin(a) + dz * Math.cos(a); let bx = p.x + ex * LAW.near, bz = p.z + ez * LAW.near; if (B && B.d > LAW.off) { bx = B.x - dx * 6 * (n % 3 - 1); bz = B.z - dz * 6 * (n % 3 - 1); } const ax = S ? S.x : bx + ex * LAW.far, az = S ? S.z : bz + ez * LAW.far, c = this.make('car_police', ax, az, Math.atan2(-ex, -ez)); if (!c) return; - c.y = this.ground(ax, az); c.hid = 1; this.road(c, 'come', bx, bz, LAW.come, 0, LAW.dash); + c.y = Ground.road(ax, az); c.hid = 1; this.road(c, 'come', bx, bz, LAW.come, 0, LAW.dash); this.cars.push(c); this.sent++; }, // a vehicle of the police at (x, z) with two officers in the front seats; its beacons are two looks of it, swapped all the time @@ -244,7 +236,7 @@ const Law = { if (c.gen !== g) return; if (c.lg !== L) { const P = l.pts; let b = 0, bd = 1e9; for (let i = 0; i < Math.min(P.length, 60); i++) { const d = Math.hypot(P[i][0] - c.x, P[i][1] - c.z); if (d < bd) { bd = d; b = i; } } l = Navi.line([[c.x, c.z], ...P.slice(b + 1)]); c.lg = L; } L.l = l; if (seen) L.s = Math.max(0, l.L - seen); if (dash) L.V = clamp(l.L / dash, V, LAW.top); - if (c.hid) { c.hid = 0; const a = Navi.at(l, L.s); c.x = a.x; c.z = a.z; c.yaw = a.yaw; c.y = this.ground(a.x, a.z); Occ.add(c, 'must'); } + if (c.hid) { c.hid = 0; const a = Navi.at(l, L.s); c.x = a.x; c.z = a.z; c.yaw = a.yaw; c.y = Ground.road(a.x, a.z); Occ.add(c, 'must'); } }); }, // a car on its way along its line, driven like every car (Pilot: the pedals and the wheel of the one physics, its class's engine and @@ -304,7 +296,7 @@ const Law = { c.v = mv ? v : 0; c.dist += c.v * dt; if (car) Kin.follow(c, l, L.s, mv ? dt : 0); else { if (mv && v > .2 || !dt) c.yaw = L.yaw != null ? L.yaw : dt ? _turn(c.yaw, a.yaw, dt * 5) : a.yaw; c.x = x; c.z = z; } const fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), hl = c.len * .35, e = dt ? Math.min(1, dt * 10) : 1; - { const gf = this.ground(c.x + fx * hl, c.z + fz * hl, c.y), gr = this.ground(c.x - fx * hl, c.z - fz * hl, c.y); c.y += ((gf + gr) / 2 - c.y) * e; c.tilt = (c.tilt || 0) + (clamp(Math.atan2(gr - gf, hl * 2), -.45, .45) - (c.tilt || 0)) * e; } + { const gf = Ground.road(c.x + fx * hl, c.z + fz * hl, c.y), gr = Ground.road(c.x - fx * hl, c.z - fz * hl, c.y); c.y += ((gf + gr) / 2 - c.y) * e; c.tilt = (c.tilt || 0) + (clamp(Math.atan2(gr - gf, hl * 2), -.45, .45) - (c.tilt || 0)) * e; } siren(mv); Town.place(c, dt); if (!mv && !L.done) { L.done = 1; this.arrived(c, L.k); } @@ -346,7 +338,7 @@ const Law = { const p = Walk.p, me = !Walk.ride && Math.abs(p.y - y0) < 8; let out = 1e9; for (let k = 2; k <= D; k = k < 8 ? k + 3 : k * 1.5) { const a = Navi.at(l, s + k); if (!Town.loaded(a.x, a.z)) break; - const fx = Math.sin(a.yaw), fz = Math.cos(a.yaw), hl = c.len * .35, gf = this.ground(a.x + fx * hl, a.z + fz * hl, y0), gr = this.ground(a.x - fx * hl, a.z - fz * hl, y0); // the pose there: on the ground and tilted with it, as it will drive + const fx = Math.sin(a.yaw), fz = Math.cos(a.yaw), hl = c.len * .35, gf = Ground.road(a.x + fx * hl, a.z + fz * hl, y0), gr = Ground.road(a.x - fx * hl, a.z - fz * hl, y0); // the pose there: on the ground and tilted with it, as it will drive c.y = (gf + gr) / 2; c.tilt = clamp(Math.atan2(gr - gf, hl * 2), -.45, .45); if (wall && Drive.buried(c, a.x, a.z, a.yaw, 1)) { out = k; c.bo = null; break; } if (!Drive.free(c, a.x, a.z, a.yaw)) { out = k; c.bo = Drive.who || Town.cars.reduce((b, q) => q !== c && (!b || Math.hypot(q.x - a.x, q.z - a.z) < Math.hypot(b.x - a.x, b.z - a.z)) ? q : b, null); break; } @@ -388,7 +380,7 @@ const Law = { for (const o of u.crew.slice()) { if (!o.cop) continue; const [x, z] = Drive.beside(u, o.seat, 1.4), q = [o.x, o.y, o.z], n = o.seat; Town.vacate(u, o); u.crew.splice(u.crew.indexOf(o), 1); o.inst.legs = 0; o.inst.arms = 0; o.yaw = c.yaw; o.nv = null; o.gait = 0; o.jy = 0; o.cl = null; o.blk = 0; - o.brd = Drive.board(u, n, 'out', [x, this.ground(x, z, c.y), z], q); Drive.through(o.brd, 0, o); + o.brd = Drive.board(u, n, 'out', [x, Ground.road(x, z, c.y), z], q); Drive.through(o.brd, 0, o); this.cops.push(o); } Sfx.play('door', c); @@ -405,8 +397,8 @@ const Law = { const f = Nav.feet(Math.floor(c.x), Math.floor(c.z), Math.floor(c.y + .01), pf, 1); if (f > c.y + 2.5) { c.x = ox; c.z = oz; r = -1; c.blk += dt; } // a wall: not up it else if (f >= 0) Nav.lift(c, f, dt); - else { const g = Town.ground(c.x, c.z, c.y); if (g != null) Nav.lift(c, g, dt); } - } else if (!ld) c.y = this.ground(c.x, c.z, c.y); + else { const g = Ground.at(c.x, c.z, c.y); if (g != null) Nav.lift(c, g, dt); } + } else if (!ld) c.y = Ground.road(c.x, c.z, c.y); if (c.nx != null) c.yaw = _turn(c.yaw, Math.atan2(c.nx, c.nz), dt * 9); c.inst.arms = 0; c.gait += ((r > 0 ? 1.2 : 0) - c.gait) * Math.min(1, dt * 9); return r; @@ -424,7 +416,7 @@ const Law = { if (d < LAW.catch + (v ? v.len / 2 : 0) && Math.abs(p.y - c.y) < 4 && !(v && Math.abs(v.car.v) > 3)) { if ((c.grab = (c.grab || 0) + dt) >= LAW.grab) return this.arrest(c); if (c.grab === dt) { Sfx.play('click', p); toast(tr('📢 «Стоять! Полиция!»', '📢 “Stop! Police!”'), 1500); } } else c.grab = 0; const sp = c.swat ? LAW.srun : LAW.run; - if (d > 300) { c.x += dx / d * sp * dt; c.z += dz / d * sp * dt; c.y = this.ground(c.x, c.z); continue; } // far away: only on the map of the radio + if (d > 300) { c.x += dx / d * sp * dt; c.z += dz / d * sp * dt; c.y = Ground.road(c.x, c.z); continue; } // far away: only on the map of the radio const r = this.chase(c, tx, tz, dt, sp); if (r < 0 && d < 30) stuck = 1; } if (this.pursue(dt, p, m)) return; @@ -506,7 +498,7 @@ const Law = { copter(k) { const p = Walk.p, it = Town.it('heli_police'); if (!it) return null; const S = this.sta, a = S ? Math.atan2(S.x - p.x, S.z - p.z) : this.R() * TAU, x = S ? S.x : p.x + Math.sin(a) * LAW.far, z = S ? S.z : p.z + Math.cos(a) * LAW.far, A = makeInst(it, 0, 0, 0, 0), sl = A.slots.map(s => s.slice()); sl[5][0] = '#101a3a'; sl[6][0] = '#ff2a2a'; - return Rotor.init({ it, inst: A, instA: A, instB: makeInst(it, 0, 0, 0, 0, sl), x, z, y: this.ground(x, z) + LAW.hUp, yaw: a + Math.PI, rad: 20, ht: 14, ph: 0, gait: 0, tilt: 0, bank: 0, bp: 40, far: 4000, k, t: 0, v: 0, sw: [], n: 0, lx: p.x, lz: p.z }); + return Rotor.init({ it, inst: A, instA: A, instB: makeInst(it, 0, 0, 0, 0, sl), x, z, y: Ground.road(x, z) + LAW.hUp, yaw: a + Math.PI, rad: 20, ht: 14, ph: 0, gait: 0, tilt: 0, bank: 0, bp: 40, far: 4000, k, t: 0, v: 0, sw: [], n: 0, lx: p.x, lz: p.z }); }, // one more helicopter after a player in the air (nobody on board but the pilots): it follows them, and circles them once they are down chopper() { @@ -525,10 +517,10 @@ const Law = { const h = this.air[i]; h.t += dt; h.inst = Math.floor(Anim.t * 3 + i * .5) % 2 ? h.instB : h.instA; if ((h.snd = (h.snd || 0) - dt) <= 0 && Math.hypot(h.x - p.x, h.z - p.z) < 900) { h.snd = .8 + i * .13; Sfx.play('rotor', h); } if (h.k !== 'leave' && this.st !== 1) this.away(h); - if (h.k === 'leave') { if (this.fly(h, h.to[0], this.ground(h.to[0], h.to[1]) + LAW.hUp * 1.5, h.to[1], LAW.hV, dt) < 30 || Math.hypot(h.x - p.x, h.z - p.z) > LAW.far + 250) this.air.splice(i, 1); continue; } + if (h.k === 'leave') { if (this.fly(h, h.to[0], Ground.road(h.to[0], h.to[1]) + LAW.hUp * 1.5, h.to[1], LAW.hV, dt) < 30 || Math.hypot(h.x - p.x, h.z - p.z) > LAW.far + 250) this.air.splice(i, 1); continue; } if (this.m === 'air') { h.k = 'chase'; this.follow(h, i, p, dt); continue; } if (h.k !== 'orbit') { h.k = 'orbit'; h.a = Math.atan2(h.x - p.x, h.z - p.z); } - const R = LAW.hR + 25 + i * 18; h.a += LAW.hW * dt * (i % 2 ? -1 : 1); this.fly(h, p.x + Math.sin(h.a) * R, this.ground(p.x, p.z) + LAW.hUp + i * 12, p.z + Math.cos(h.a) * R, LAW.hV * .6, dt); + const R = LAW.hR + 25 + i * 18; h.a += LAW.hW * dt * (i % 2 ? -1 : 1); this.fly(h, p.x + Math.sin(h.a) * R, Ground.road(p.x, p.z) + LAW.hUp + i * 12, p.z + Math.cos(h.a) * R, LAW.hV * .6, dt); const k = Math.min(1, dt * 1.2); h.lx += (p.x + Math.sin(h.t * .8 + i) * 6 - h.lx) * k; h.lz += (p.z + Math.cos(h.t * .6 + i) * 6 - h.lz) * k; } }, @@ -537,7 +529,7 @@ const Law = { // 30 cells over the ground (o.land: down to ty, sinking at most o.dn cells/s); vk: climbs vk times faster (after a player in the air). // Returns the distance fly(H, tx, ty, tz, V, dt, vk, o) { - if (!(o && o.land)) ty = Math.max(ty, this.ground(H.x, H.z) + 30, this.ground(tx, tz) + 30); + if (!(o && o.land)) ty = Math.max(ty, Ground.road(H.x, H.z) + 30, Ground.road(tx, tz) + 30); const d = Rotor.aim(H, tx, ty, tz, V, dt, { vy: LAW.hVy * (vk || 1), dn: o && o.dn || LAW.hVy, land: o && o.land }); if (dt) Rotor.step(H, dt); return d; @@ -547,17 +539,17 @@ const Law = { const H = this.H; if (!H) return; H.t += dt; H.inst = Math.floor(Anim.t * 3) % 2 ? H.instB : H.instA; if ((H.snd = (H.snd || 0) - dt) <= 0 && Math.hypot(H.x - p.x, H.z - p.z) < 900) { H.snd = .8; Sfx.play('rotor', H); } - const gp = this.ground(p.x, p.z); + const gp = Ground.road(p.x, p.z); if (H.k === 'in') { // to a clearing near the player, then down to the height of the ropes (after them while they are in the air) if (this.m === 'air' && this.st === 1) return this.follow(H, this.air.length, p, dt); if (!H.to || Math.hypot(H.to[0] - p.x, H.to[1] - p.z) > 60) { const a = this.R() * TAU; H.to = [p.x + Math.sin(a) * 26, p.z + Math.cos(a) * 26]; } - const g = this.ground(H.to[0], H.to[1]), far = Math.hypot(H.to[0] - H.x, H.to[1] - H.z) > 50; + const g = Ground.road(H.to[0], H.to[1]), far = Math.hypot(H.to[0] - H.x, H.to[1] - H.z) > 50; if (this.fly(H, H.to[0], far ? Math.max(g, gp) + LAW.hUp : g + LAW.hRope, H.to[1], LAW.hV, dt) < 3 && H.v < 3) { H.k = 'rope'; H.t = 0; H.gy = g; Sfx.play('door', H); } } else if (H.k === 'rope') { // the team goes down the ropes from both doors, two by two this.fly(H, H.to[0], H.gy + LAW.hRope, H.to[1], 0, dt); // (it hovers over the spot: the pilot holds it there) if (H.n < LAW.swat && H.t > .6 + H.n * .8) this.swat(H, H.n++); for (let i = H.sw.length - 1; i >= 0; i--) { - const o = H.sw[i]; o.x = H.x + o.rx; o.z = H.z + o.rz; const g = this.ground(o.x, o.z, o.y); o.y -= LAW.rope * dt; o.gait = 0; + const o = H.sw[i]; o.x = H.x + o.rx; o.z = H.z + o.rz; const g = Ground.road(o.x, o.z, o.y); o.y -= LAW.rope * dt; o.gait = 0; if (o.y <= g) { o.y = g; o.inst.arms = 0; o.inst.legs = 0; H.sw.splice(i, 1); this.cops.push(o); Sfx.play('step', o); } } if (H.n >= LAW.swat && !H.sw.length) { H.k = 'orbit'; H.a = Math.atan2(H.x - p.x, H.z - p.z); toast(tr('🚁 Спецназ на земле!', '🚁 SWAT on the ground!'), 2400); } @@ -566,13 +558,13 @@ const Law = { const k = Math.min(1, dt * 1.2); H.lx += (p.x + Math.sin(H.t * .9) * 5 - H.lx) * k; H.lz += (p.z + Math.cos(H.t * .7) * 5 - H.lz) * k; } else if (H.k === 'pick') { // hovers over the team and takes them up the ropes if (!H.to) { let x = 0, z = 0, n = 0; for (const o of this.cops) if (o.swat) { x += o.x; z += o.z; n++; } H.to = n ? [x / n, z / n] : [H.x, H.z]; } - const g = this.ground(H.to[0], H.to[1]); this.fly(H, H.to[0], g + LAW.hRope, H.to[1], LAW.hV * .6, dt); + const g = Ground.road(H.to[0], H.to[1]); this.fly(H, H.to[0], g + LAW.hRope, H.to[1], LAW.hV * .6, dt); for (let i = H.sw.length - 1; i >= 0; i--) { const o = H.sw[i]; o.up = 1; o.x = H.x + o.rx; o.z = H.z + o.rz; o.inst.arms = 5; o.y += LAW.rope * dt; if (o.y > H.y + 1) H.sw.splice(i, 1); } if (H === this.lift) this.liftUp(H, p, dt); if (!H.sw.length && (!this.cops.some(o => o.swat) || H.t > 40) && (H !== this.lift || this.inH)) { this.cops = this.cops.filter(o => !o.swat); if (H === this.lift) this.toStation(H); else this.away(H); } } else if (H.k === 'go' || H.k === 'land') { // with the player on board: to the station at cruise height, then straight down onto its yard - this.ride(H, p); const S = this.sta, T = H.pad || (H.k === 'land' ? H.pad = this.pad(S) : S ? [S.x, S.z] : this.gate()), g = this.ground(T[0], T[1]); // (the pad is looked for once the land round the station is loaded) - if (H.k === 'go') { if (this.fly(H, T[0], Math.max(g, this.ground(H.x, H.z)) + LAW.hUp * 1.2, T[1], LAW.hV, dt) < 40) { H.k = 'land'; H.t = 0; } } + this.ride(H, p); const S = this.sta, T = H.pad || (H.k === 'land' ? H.pad = this.pad(S) : S ? [S.x, S.z] : this.gate()), g = Ground.road(T[0], T[1]); // (the pad is looked for once the land round the station is loaded) + if (H.k === 'go') { if (this.fly(H, T[0], Math.max(g, Ground.road(H.x, H.z)) + LAW.hUp * 1.2, T[1], LAW.hV, dt) < 40) { H.k = 'land'; H.t = 0; } } else { const d = Math.hypot(T[0] - H.x, T[1] - H.z); if (d >= 3 && !H.gnd) this.fly(H, T[0], g + 30, T[1], LAW.hV * .3, dt); @@ -580,7 +572,7 @@ const Law = { if ((H.gnd || H.y <= g + .05) && !this.fade) { Sfx.play('door', H); this.fadeTo(() => this.landed(H)); } } } else if (H.k === 'leave') { - if (this.fly(H, H.to[0], this.ground(H.to[0], H.to[1]) + LAW.hUp * 1.5, H.to[1], LAW.hV, dt) < 30 || Math.hypot(H.x - p.x, H.z - p.z) > LAW.far + 250) { this.H = null; this.cops = this.cops.filter(o => !o.swat); } + if (this.fly(H, H.to[0], Ground.road(H.to[0], H.to[1]) + LAW.hUp * 1.5, H.to[1], LAW.hV, dt) < 30 || Math.hypot(H.x - p.x, H.z - p.z) > LAW.far + 250) { this.H = null; this.cops = this.cops.filter(o => !o.swat); } } }, // the n-th SWAT officer at the door of their side, on the rope @@ -605,7 +597,7 @@ const Law = { // hovering over the player: after the handcuffs (1.8 s) up the rope with the team, into the cabin liftUp(H, p, dt) { if (this.inH) return this.ride(H, p); - const d = Math.hypot(H.x - p.x, H.z - p.z); if (!this.up) { H.to = [p.x, p.z]; if (this.t < 1.8 || d > 4 || H.y > this.ground(H.x, H.z) + LAW.hRope + 3) return; } + const d = Math.hypot(H.x - p.x, H.z - p.z); if (!this.up) { H.to = [p.x, p.z]; if (this.t < 1.8 || d > 4 || H.y > Ground.road(H.x, H.z) + LAW.hRope + 3) return; } if (!this.up) { this.up = 1; if (this.by) this.by.back = 1; this.by = null; this.cuff = true; } const [x, y, z] = this.seatH(H); p.x += (x - p.x) * Math.min(1, dt * 4); p.z += (z - p.z) * Math.min(1, dt * 4); p.vy = 0; p.y = Math.min(y, p.y + LAW.rope * dt); if (p.y >= y - .01) { this.inH = 1; this.up = 0; Sfx.play('door', H); } @@ -617,7 +609,7 @@ const Law = { pad(S) { if (!S) return this.gate(); // top(x, z): the first free cell over the land there (a street or a square may lie on blocks over the terrain); a roof would be higher - const w = Walk.w, top = (x, z) => { const X = Math.floor(x), Z = Math.floor(z); let y = Math.floor(this.ground(x, z)) - 2; for (let k = 0; k < 10 && w.get(X, y, Z); k++) y++; return w.get(X, y, Z) ? 1e9 : y; }; + const w = Walk.w, top = (x, z) => { const X = Math.floor(x), Z = Math.floor(z); let y = Math.floor(Ground.road(x, z)) - 2; for (let k = 0; k < 10 && w.get(X, y, Z); k++) y++; return w.get(X, y, Z) ? 1e9 : y; }; const gS = top(S.x, S.z), open = (x, z) => { const g = top(x, z); if (Math.abs(g - gS) > 2) return false; // the level of the street at the door: not a roof, not a pit for (let dz = -9; dz <= 9; dz += 3) for (let dx = -9; dx <= 9; dx += 3) { @@ -636,9 +628,9 @@ const Law = { // down at the station: a patrol car of the station will take the player home after the cell (as after a boat, ashore); no station: home landed(H) { this.lift = null; this.inH = 0; const p = Walk.p, S = this.sta; this.away(H); - if (!S) { this.st = 6; this.t = LAW.parole; this.cuff = false; p.y = this.ground(p.x, p.z) + 1; toast(tr('🕊️ Вы дома. Условно-досрочное: 3 минуты', '🕊️ You are home. Parole: 3 minutes'), 3600); return this.ui(); } + if (!S) { this.st = 6; this.t = LAW.parole; this.cuff = false; p.y = Ground.road(p.x, p.z) + 1; toast(tr('🕊️ Вы дома. Условно-досрочное: 3 минуты', '🕊️ You are home. Parole: 3 minutes'), 3600); return this.ui(); } const c = this.make('car_police', S.x, S.z, Math.atan2(S.dx || 0, S.dz || 1)); if (!c) { this.st = 6; this.t = LAW.parole; this.cuff = false; this.homeQ = 1; return this.ui(); } - c.y = this.ground(S.x, S.z); Town.place(c, 0); Town.cars.push(c); this.cars.push(c); this.car = c; this.st = 3; this.jail(); + c.y = Ground.road(S.x, S.z); Town.place(c, 0); Town.cars.push(c); this.cars.push(c); this.car = c; this.st = 3; this.jail(); }, // the ropes and, by night, the cone of the searchlight (drawn after the glass, 74_town.js drawLines) lines(cam) { @@ -652,7 +644,7 @@ const Law = { gl.bufferSubData(gl.ARRAY_BUFFER, 0, v, 0, n * 3); gl.uniform4f(u.uColor, .1, .09, .08, 1); gl.drawArrays(gl.LINES, 0, n); } for (const H of lit) { // a cone of light from under the nose to a spot round the player, added to whatever is behind it - const cs = Math.cos(H.yaw), sn = Math.sin(H.yaw), ax = H.x + sn * 6, ay = H.y + 2.5, az = H.z + cs * 6, by = this.ground(H.lx, H.lz) + .2, r = 7; n = 0; + const cs = Math.cos(H.yaw), sn = Math.sin(H.yaw), ax = H.x + sn * 6, ay = H.y + 2.5, az = H.z + cs * 6, by = Ground.road(H.lx, H.lz) + .2, r = 7; n = 0; for (let i = 0; i < 20; i++) { const a0 = i / 20 * TAU, a1 = (i + 1) / 20 * TAU; v.set([ax, ay, az, H.lx + Math.cos(a0) * r, by, H.lz + Math.sin(a0) * r, H.lx + Math.cos(a1) * r, by, H.lz + Math.sin(a1) * r], n * 3); n += 3; } gl.bufferSubData(gl.ARRAY_BUFFER, 0, v, 0, n * 3); gl.blendFunc(gl.SRC_ALPHA, gl.ONE); gl.uniform4f(u.uColor, 1, .95, .75, .13); gl.drawArrays(gl.TRIANGLES, 0, n); n = 0; for (let i = 0; i < 20; i++) { const a0 = i / 20 * TAU, a1 = (i + 1) / 20 * TAU; v.set([H.lx, by, H.lz, H.lx + Math.cos(a0) * r, by, H.lz + Math.sin(a0) * r, H.lx + Math.cos(a1) * r, by, H.lz + Math.sin(a1) * r], n * 3); n += 3; } @@ -726,7 +718,7 @@ const Law = { ashore(b) { this.drop(b); const S = this.sta, c = S && this.make('car_police', S.x, S.z, 0); if (!c) { this.st = 6; this.t = LAW.parole; this.cuff = false; this.homeQ = 1; return this.ui(); } // no station near: home on parole - c.y = this.ground(S.x, S.z); Town.place(c, 0); Occ.add(c, 'must'); this.cars.push(c); this.car = c; this.st = 3; this.jail(); + c.y = Ground.road(S.x, S.z); Town.place(c, 0); Occ.add(c, 'must'); this.cars.push(c); this.car = c; this.st = 3; this.jail(); }, // into the back seat; the officers take the front seats board() { @@ -745,7 +737,7 @@ const Law = { jail(t) { const C = this.cell(), p = Walk.p; this.let = 1; Drive.exit(true); this.let = 0; if (!C) { this.st = 5; Drive.enter({ u: this.car.units[0], n: 2, now: 1 }); this.road(this.car, 'home', ...this.gate(), LAW.ride); return this.ui(); } - const x = C.x + C.ux * (C.r - .8), z = C.z + C.uz * (C.r - .8), y = Town.ground(x, z, C.y + 2); p.x = x; p.z = z; p.y = y != null ? y : C.y; p.vy = 0; p.yaw = Math.atan2(-C.ux, -C.uz); p.pitch = -.22; // at the bars, facing the bench Walk.eyeY = p.y + EYE; + const x = C.x + C.ux * (C.r - .8), z = C.z + C.uz * (C.r - .8), y = Ground.at(x, z, C.y + 2); p.x = x; p.z = z; p.y = y != null ? y : C.y; p.vy = 0; p.yaw = Math.atan2(-C.ux, -C.uz); p.pitch = -.22; // at the bars, facing the bench Walk.eyeY = p.y + EYE; this.st = 4; this.t = t != null ? t : LAW.cell; this.talkT = 3; this.talkN = 0; this.cuff = false; // the other inmates: three on the bench at the back wall, facing the newcomer at the bars const R = this.R, vx = C.uz, vz = -C.ux, put = (o, x, z, sit, yaw) => { o.x = x; o.z = z; o.y = p.y + (sit ? (8 - o.inst.hip) / 4 : 0); o.inst.legs = sit ? 6 : 0; o.inst.arms = 0; o.yaw = yaw; o.gait = 0; o.say = ''; o.sayT = 0; this.ins.push(o); }; @@ -796,7 +788,7 @@ const Law = { if (Walk.ride) { this.let = 1; Drive.exit(true); this.let = 0; } const c = this.make('car_police', at[0], at[1], at[2]); if (!c) { this.st = 6; this.t = LAW.parole; this.cuff = false; this.homeQ = 1; this.ui(); return true; } - c.y = this.ground(at[0], at[1]); if (r.s !== 4 && (at[0] !== p.x || at[1] !== p.z) && Drive.buried(c, c.x, c.z, c.yaw, 1)) { c.x = p.x; c.z = p.z; c.y = this.ground(p.x, p.z); } + c.y = Ground.road(at[0], at[1]); if (r.s !== 4 && (at[0] !== p.x || at[1] !== p.z) && Drive.buried(c, c.x, c.z, c.yaw, 1)) { c.x = p.x; c.z = p.z; c.y = Ground.road(p.x, p.z); } Town.place(c, 0); Occ.add(c, 'must'); this.cars.push(c); this.car = c; if (r.s === 4) { this.st = 3; this.jail(r.t); return true; } Drive.enter({ u: c.units[0], n: 2, now: 1 }); @@ -812,7 +804,7 @@ const Law = { if (this.rem.size) this.netTick(dt); // the police of the other players if (this.hold) { this.ui(); return; } // frozen for a picture (tools/shots/223.mjs) if (this.pend && !this.restore(p)) return this.ui(); // after a reload: until the town is there, everything waits - if (this.homeQ) { this.homeQ = 0; const [x, z] = this.gate(); p.x = x; p.z = z; p.y = this.ground(x, z) + 1; p.vy = 0; p.fly = false; } + if (this.homeQ) { this.homeQ = 0; const [x, z] = this.gate(); p.x = x; p.z = z; p.y = Ground.road(x, z) + 1; p.vy = 0; p.fly = false; } if (this.alarm && (this.alarm.t -= dt) <= 0) { const { ev, who } = this.alarm; this.alarm = null; if (!this.st && !ev.called) Evt.call('police', ev, who || null); } if (this.fade) { const f = this.fade; f.t += dt; if (f.t >= .7 && !f.done) { f.done = 1; f.fn(); } if (f.t >= 1.6) this.fade = null; } if (this.st >= 1 && this.st <= 5) this.drop0(p); diff --git a/src/game/79_leash.js b/src/game/79_leash.js index 0aefc94a6..daba3160f 100644 --- a/src/game/79_leash.js +++ b/src/game/79_leash.js @@ -143,7 +143,7 @@ const Leash = { taut = 1; if (got > .01 && L.m !== 'balk' && L.m !== 'sit') c.yaw = _turn(c.yaw, Math.atan2(-ux, -uz), dt * 6); // pulled along: it turns and trots after the hand (a cat that digs in slides on its bottom) if (local) { if (rest > 1.5) { if ((this.stuck += dt) > 3) return this.free(3); } else this.stuck = Math.max(0, this.stuck - dt * 2); } - else if (rest > LEASH.L * 2) { c.x = H[0] - ux * Lr * .9; c.z = H[2] - uz * Lr * .9; const fy = Fauna.drop(c.x, c.y + 6, c.z); if (fy != null) c.y = fy; } // a copy that fell far behind its holder catches up at once + else if (rest > LEASH.L * 2) { c.x = H[0] - ux * Lr * .9; c.z = H[2] - uz * Lr * .9; const fy = Ground.drop(c.x, c.z, c.y + 6, 14); if (fy != null) c.y = fy; } // a copy that fell far behind its holder catches up at once } else taut = d / Lr; } if (local) this.taut += (taut - this.taut) * Math.min(1, dt * 8); diff --git a/src/game/79_pen.js b/src/game/79_pen.js index 876bf0b6c..47fb85375 100644 --- a/src/game/79_pen.js +++ b/src/game/79_pen.js @@ -164,7 +164,7 @@ const Pen = { this.btnTick(dt, p); }, // the ground at (x, z): the level floor of the pen, or the land around it (the pasture may lie well above or below the pen) - drop(q, x, z) { const y = Fauna.drop(x, q.y + 10, z); return y != null ? y : Fauna.drop(x, Math.ceil(this.w.T.at(x, z)) + 10, z); }, + drop(q, x, z) { const y = Ground.drop(x, z, q.y + 10, 14); return y != null ? y : Ground.drop(x, z, Math.ceil(this.w.T.at(x, z)) + 10, 14); }, // the land under the whole pen and its pasture is built (the columns come in one by one: an animal put on a column that is not there yet // would be lost, so a pen wakes only when every place an animal may stand is ready) ready(q) { @@ -355,7 +355,7 @@ const Pen = { dogPass(st, b, x, z) { if (Flock.inPen(st.P, x, z) && !Flock.inPen(st.P, b.sx, b.sz) || st.ga < .35 && this.cross(st, b.sx, b.sz, x, z)) return null; return this.manPass(st, b, x, z); }, // (the keeper goes through the gate as he pleases: he opens it and shuts it behind him) manPass(st, b, x, z) { - if (!Fauna.loaded(x, z)) return null; const y = b.sy != null ? b.sy : st.q.y, g = Town.ground(x, z, y); if (g == null || Math.abs(g - y) > 2) return null; + if (!Fauna.loaded(x, z)) return null; const y = b.sy != null ? b.sy : st.q.y, g = Ground.at(x, z, y); if (g == null || Math.abs(g - y) > 2) return null; return g; }, // the leaf: hinged at one gate post; open, it swings out to lie along the fence diff --git a/src/game/79_slip.js b/src/game/79_slip.js index 6c8b60528..20bbba762 100644 --- a/src/game/79_slip.js +++ b/src/game/79_slip.js @@ -82,7 +82,7 @@ const Slip = { if (!Walk.ride && Math.hypot(p.x - P[0], p.z - P[1]) < P[3]) { // the player who drove it up steps ashore beside the trailer: the first dry place from its middle towards the drawbar const s = Math.sin(P[2]), c = Math.cos(P[2]), it = Lib.byId.trailer_boat, sw = (it ? it.model.size[0] / 8 : 5.5) + 2; // clear of its side out: for (const k of [0, .25, .5, .7]) for (const sd of [1, -1]) { - const x = P[0] + s * P[3] * k + c * sw * sd, z = P[1] + c * P[3] * k - s * sw * sd, y = Town.ground(x, z, (t.y || 0) + 3); + const x = P[0] + s * P[3] * k + c * sw * sd, z = P[1] + c * P[3] * k - s * sw * sd, y = Ground.at(x, z, (t.y || 0) + 3); if (y != null && !Boat.wet(x, z) && !Walk.hitTest(x, y, z)) { p.x = x; p.y = y; p.z = z; p.vy = 0; break out; } } } diff --git a/src/game/79_taxi.js b/src/game/79_taxi.js index 746a1b60d..dd6dce407 100644 --- a/src/game/79_taxi.js +++ b/src/game/79_taxi.js @@ -94,7 +94,7 @@ const Taxi = { if (seen) { L.s = Math.max(0, L.l.L - seen); L.V = clamp((L.l.L - L.s) / TAXI.come, 40, TAXI.V * 1.3); } if (o) { const a = Navi.at(L.l, Math.min(o.ps, L.l.L)); if (Math.hypot(a.x - c.x, a.z - c.z) > 12) return this.road(k, x, z); L.s = Math.min(o.ps, L.l.L); L.V = o.V || L.V; c.v = o.v || 0; c.lo = o.off || 0; } // (a way that came out otherwise: a new one from here) this.share(c, L); - if (c.hid) { c.hid = 0; const a = Navi.at(L.l, L.s); c.x = a.x; c.z = a.z; c.yaw = a.yaw; c.y = this.gnd(a.x, a.z); c.v = L.V; Occ.add(c, 'must'); } + if (c.hid) { c.hid = 0; const a = Navi.at(L.l, L.s); c.x = a.x; c.z = a.z; c.yaw = a.yaw; c.y = Ground.road(a.x, a.z); c.v = L.V; Occ.add(c, 'must'); } if (k === 'come') { const sec = Math.round((L.l.L - L.s) / L.V) + 2; toast(tr('🚕 Такси едет к вам: будет через {0} с', '🚕 A taxi is on its way: here in {0} s', sec), 3000); } }, L.ban); // (a ride that took another way before a reload: the same places kept away from) }, @@ -106,7 +106,7 @@ const Taxi = { const s = all[0] && all[0][1], B = !s && Roads.snap(T, p.x, p.z, 900), a = Math.atan2(B ? B.x - p.x : 1, B ? B.z - p.z : 0), ax = s ? s.x : p.x + Math.sin(a) * 700, az = s ? s.z : p.z + Math.cos(a) * 700; const seed = (hash2(this.n, Math.floor(p.x) ^ Math.floor(p.z) * 31, (w.seed | 0) + 7177) * 4294967296) >>> 0; const c = Town.build('car_taxi', ax, az, 0, { R: RNG(seed), seed, solo: true, col: '#f2c230' }); if (!c) return; - Object.assign(c, { mode: 'taxi', ghost: true, v: 0, edge: false, dir: 1, empty: false, hid: 1 }); c.y = this.gnd(ax, az); + Object.assign(c, { mode: 'taxi', ghost: true, v: 0, edge: false, dir: 1, empty: false, hid: 1 }); c.y = Ground.road(ax, az); this.car = c; this.st = 1; this.t = 0; this.road('come', p.x, p.z, TAXI.seen); }, // the ride: from where the car is to the kerb nearest to the place @@ -261,20 +261,7 @@ const Taxi = { lay(c, dt) { const fx = Math.sin(c.yaw), fz = Math.cos(c.yaw), hl = c.len * .35, e = dt ? Math.min(1, dt * 10) : 1; c.dist = (c.dist || 0) + Math.abs(c.v) * dt; - const gf = this.gnd(c.x + fx * hl, c.z + fz * hl, c.y), gr = this.gnd(c.x - fx * hl, c.z - fz * hl, c.y); c.y += ((gf + gr) / 2 - c.y) * e; c.tilt = (c.tilt || 0) + (clamp(Math.atan2(gr - gf, hl * 2), -.45, .45) - (c.tilt || 0)) * e; - }, - // the ground under (x, z) for a car at about height y (none: not known): Law.ground, but never a floor with no room over it. Without a - // height that is the floor at the generator's ground or water level, which under a deck (the street's bridge round an island, 32_land.js) - // is the hollow under the slab: a car put there (where it appears, after a reload) sat inside the deck, saw a wall in the road at every - // step and never got out. The same under a road's bridge over a river: a car that went on while the land there was not made yet took the - // water level, and with the blocks made it stood on the water under the deck. Such a floor is left for the first one above it with room - // (nothing hard from the wheels up to where Taxi.core starts looking: DRIVE_STEP + 1) - gnd(x, z, y) { - const w = Walk.w, g = Law.ground(x, z, y); if (!Town.loaded(x, z)) return g; - const X = Math.floor(x), Z = Math.floor(z), hard = Y => w.solid(X, Y, Z) && !CRASH_DUST[w.pm[w.get(X, Y, Z)]], room = Y => { for (let k = 0; k <= DRIVE_STEP + 1; k++) if (hard(Y + k)) return false; return true; }; - if (room(g)) return g; - for (let Y = g + 1; Y <= g + 16; Y++) if (hard(Y - 1) && room(Y)) return Y; - return g; + const gf = Ground.road(c.x + fx * hl, c.z + fz * hl, c.y, 1), gr = Ground.road(c.x - fx * hl, c.z - fz * hl, c.y, 1); c.y += ((gf + gr) / 2 - c.y) * e; c.tilt = (c.tilt || 0) + (clamp(Math.atan2(gr - gf, hl * 2), -.45, .45) - (c.tilt || 0)) * e; }, // is the body in the blocks at a pose: Drive.buried (the test of the player's car) over the inner part of its width, so that a railing, a // kerb post or a lamp at the very edge of a narrow street is brushed past while a wall, a house or a fence across the way stops it @@ -295,7 +282,7 @@ const Taxi = { // the body free all along a shifted way (the same test as the guard below: a post or a fence the look ahead misses counts too) // (from s on, over d cells: the shift grows from o0 to o as the car rolls, as in drive; from where it backs up to first when it is close) clear(c, l, s, o, d, o0) { - for (let e = 0; e <= d; e += 3) { const a = Navi.at(l, s + e), k = o0 + clamp(o - o0, -.45 * e, .45 * e), x = a.x + Math.cos(a.yaw) * k, z = a.z - Math.sin(a.yaw) * k; if (this.core(c, x, z, a.yaw, Law.ground(x, z, c.y), 0)) return false; } + for (let e = 0; e <= d; e += 3) { const a = Navi.at(l, s + e), k = o0 + clamp(o - o0, -.45 * e, .45 * e), x = a.x + Math.cos(a.yaw) * k, z = a.z - Math.sin(a.yaw) * k; if (this.core(c, x, z, a.yaw, Ground.road(x, z, c.y), 0)) return false; } return true; }, buried0(c) { const q = c.lq; return this.core(c, q[0], q[1], q[2], q[5], q[6]); }, @@ -408,7 +395,7 @@ const Taxi = { const l = Lock.line(s.r); if (!l) return; const sd = Lock.drawn(a, f); if (!c) { const P = Lock.pt(l, sd); c = Town.build('car_taxi', P.x, P.z, Math.atan2(P.dx, P.dz), { R: RNG(s.seed), seed: s.seed, solo: true, col: '#f2c230' }); if (!c) return; - Object.assign(c, { mode: 'taxi', ghost: true, v: s.v, edge: false, dir: 1, empty: false, lk: a.id }); c.y = this.gnd(P.x, P.z); Town.place(c, 0); a.v = c; + Object.assign(c, { mode: 'taxi', ghost: true, v: s.v, edge: false, dir: 1, empty: false, lk: a.id }); c.y = Ground.road(P.x, P.z); Town.place(c, 0); a.v = c; } Occ.add(c, 'must'); // never into a wall or another car (71_occ.js) c.ll = l; c.ls = sd; c.lv = s.v; c.lo = s.o || 0; @@ -429,7 +416,7 @@ const Taxi = { this.pend = null; this.x = r.x; this.z = r.z; this.n = r.n || 0; this.t = r.t || 0; this.dd = this.dt3 = 0; if (r.s === 1 && !has) { this.send(); this.ui(); return true; } const seed = r.seed >>> 0, c = Town.build('car_taxi', r.cx, r.cz, r.yaw || 0, { R: RNG(seed), seed, solo: true, col: '#f2c230' }); if (!c) { this.ui(); return true; } - Object.assign(c, { mode: 'taxi', ghost: true, v: 0, edge: false, dir: 1, empty: false, hid: 0 }); c.y = this.gnd(r.cx, r.cz, r.cy); Town.place(c, 0); Occ.add(c, 'must'); this.car = c; + Object.assign(c, { mode: 'taxi', ghost: true, v: 0, edge: false, dir: 1, empty: false, hid: 0 }); c.y = Ground.road(r.cx, r.cz, r.cy, 1); Town.place(c, 0); Occ.add(c, 'must'); this.car = c; const o = r.ox != null ? r : null; if (r.s === 3) { const u = c.units[0], n = r.seat >= 2 && r.seat < u.veh.seats.length ? r.seat : this.seat(u, p), yaw = p.yaw, pitch = p.pitch; diff --git a/src/game/79_train.js b/src/game/79_train.js index 63b6f274d..1f3dd86ff 100644 --- a/src/game/79_train.js +++ b/src/game/79_train.js @@ -134,7 +134,7 @@ const Train = { // the door of unit u on the platform side: [x, z] outside it door(u, side, out) { return Drive.world(u, TRAIN_DOOR, -this.sd(u, side) * (u.veh.hw - .9 + (out || 0))); }, // the platform level of a station (the walkers' feet) - floor(x, z, q, far) { const g = Town.loaded(x, z) ? Town.ground(x, z, q.y + RL_PH + 2) : null; return g != null && (far ? g > q.y - 4 : Math.abs(g - q.y - RL_PH) < 3) ? g : far ? q.y : q.y + RL_PH; }, // far: off the platform (the hall, its steps, the way to town) + floor(x, z, q, far) { const g = Town.loaded(x, z) ? Ground.at(x, z, q.y + RL_PH + 2) : null; return g != null && (far ? g > q.y - 4 : Math.abs(g - q.y - RL_PH) < 3) ? g : far ? q.y : q.y + RL_PH; }, // far: off the platform (the hall, its steps, the way to town) // the way from [x, z] on the platform of station st through its hall: in at the middle door, across, out of the town door down the steps (and on to the gate) via(c, st, x, z, R, gate) { const r = c.tr.r, ss = st.i * RD_STEP + (st.hu || 0), sd = st.side, p = (u, a) => this.pt(r, ss + (R() - .5) * u, sd * a).slice(0, 2); @@ -230,7 +230,7 @@ const Train = { for (const k of this.gates.keys()) if (!seen.has(k)) this.gates.delete(k); if (ring && (this.bellT -= dt) <= 0) { this.bellT = .55; Sfx.play('xbell', ring.g[0]); } }, - gy(x, z, j) { if (!Town.loaded(x, z)) return null; const g = Town.ground(x, z, j.yA + 4); return g == null ? null : g; }, + gy(x, z, j) { if (!Town.loaded(x, z)) return null; const g = Ground.at(x, z, j.yA + 4); return g == null ? null : g; }, mkGate(r, j) { const it = Town.it('rail_gate'); if (!it) return null; const rA = !!j.A.rail, O = rA ? j.B : j.A, tO = rA ? j.tb : j.ta, tR = rA ? j.ta : j.tb, sn = Math.max(.42, j.sn), w = RD_CLS[O.cls].w, a = (RL_W + 3) / sn, g = []; diff --git a/src/game/79_ufo.js b/src/game/79_ufo.js index dc8c0602a..df70b3a92 100644 --- a/src/game/79_ufo.js +++ b/src/game/79_ufo.js @@ -78,7 +78,7 @@ const Ufo = { // the first surface going down from y0 at (x, z): the land, a roof, a crown, the water; where the world is not loaded yet, the landscape top(x, z, y0) { const w = this.w, T = w.T; - if (Fauna.loaded(x, z)) { const X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y0); Y > y0 - 300 && Y > 1; Y--) { const id = w.get(X, Y - 1, Z); if (id && (w.solid(X, Y - 1, Z) || w.transp[id] === 2)) return Y; } } + if (Fauna.loaded(x, z)) { const g = Ground.at(x, z, y0, GROUND.hover); if (g != null) return g; } return Math.max(T.at(x, z), T.wl); }, // the height of a hover over (x, z): clear of the roofs and crowns of the footprint @@ -244,7 +244,7 @@ const Ufo = { if (W.wait > 0) { W.wait -= dt; c.gait *= .8; continue; } if (W.r === undefined) { W.r = Folk.route(P, W.from, ag.hh.pl); if (W.r === undefined) continue; c.say = '🏠 ' + tr('идёт домой после встречи с инопланетянами', 'is walking home after meeting the aliens'); } const o = this._o; W.d += 5.2 * dt; Folk.along(W.r, W.d, o, 0, 0); c.x = o.x; c.z = o.z; c.yaw = _turn(c.yaw, o.yaw, dt * 8); c.gait += (1 - c.gait) * Math.min(1, dt * 9); - const g = Town.ground(c.x, c.z, c.y); if (g != null) c.y += (g - c.y) * Math.min(1, dt * 12); + const g = Ground.at(c.x, c.z, c.y); if (g != null) c.y += (g - c.y) * Math.min(1, dt * 12); if (W.d >= W.r.len) { Folk.act.delete(ag.i); this.walk.splice(i, 1); } // home: indoors for the night } }, diff --git a/src/game/81_net.js b/src/game/81_net.js index be6a74d16..f9339e6a8 100644 --- a/src/game/81_net.js +++ b/src/game/81_net.js @@ -545,8 +545,8 @@ const Net = { const bx = v ? v.x : s ? s[0] : p.x, by = v ? v.y : s ? s[1] : p.y, bz = v ? v.z : s ? s[2] : p.z, hl = v ? (v.len || c && c.len || 4) / 2 : 0, air = p.fly || c && (c.air || c.kind === 'dragon'); for (let r = 3; r <= 42; r += 1.5) for (let k = 0; k < 12; k++) { const a = (k / 12 + r * .13) * TAU, x = bx + Math.cos(a) * (r + hl), z = bz + Math.sin(a) * (r + hl); - let g = Drive.floor(x, z, by + 2); if (g <= by - 68) { if (!air) continue; g = Math.ceil(Math.max(w.T.at(x, z), WL)); } - const y = Town.ground(x, z, g); if (y == null || !air && Math.abs(y - by) > 8 || U.some(u => Drive.inside(u, u.x, u.z, u.yaw, x, z, 1.5)) || Walk.hitTest(x, y, z)) continue; + let g = Ground.under(x, z, by + 2); if (g <= by - 68) { if (!air) continue; g = Ground.land(x, z); } + const y = Ground.at(x, z, g); if (y == null || !air && Math.abs(y - by) > 8 || U.some(u => Drive.inside(u, u.x, u.z, u.yaw, x, z, 1.5)) || Walk.hitTest(x, y, z)) continue; return { x, y, z, yaw: Math.atan2(bx - x, bz - z) }; } return w.meta.spawn; diff --git a/src/game/99_main.js b/src/game/99_main.js index f5c4dbe0b..3f5c7ce47 100644 --- a/src/game/99_main.js +++ b/src/game/99_main.js @@ -297,7 +297,7 @@ function bench(n) { for (let i = 0; i < n; i++) { Render.frame(now() / 1000, 1 / 60); gl.bindFramebuffer(gl.FRAMEBUFFER, null); gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px); } return { ms: +((now() - t0) / n).toFixed(2), draws: Stats.draws, tris: Math.round(Stats.tris) }; } -window.G = { Vill, Estate, EST_TY, Rotor, ROTOR, GENV, GFLOOR, Glow, GLOW, Glare, Hdr, Occ, Slip, SLIP, Pen, PEN, PEN_KIND, Herd, HERD, Flock, FLOCK_SP, Hull, HULL, Helm, HELM, Hover, HOVER, UFO_BODY, Weave, Sport, SPORT, SPORT_MD, Ball, BALL, Shape, SHC, Arm, ARM, RS, Ships, Port, SHIP, frame, Camera, Guard, GUARD, Perf, PERF_SCEN, GpuT, Till, TILL, TILL_K, TILL_V, Camp, CAMP, Under, UG, Hitch, HITCH, TOW, Fair, FAIR, Post, POST, Caravan, CARAVAN, Circus, CIRCUS, Dent, DENT, dentModel, Odds, ODD_KIND, Ice, ICE, Quake, QUAKE, Bloom, BLOOM, Farm, FARM, Night, NIGHT, Nest, NEST, Mote, Art, ART, ArtFx, ArtUI, ART_USE, Optic, Planets, ART_PLANETS, MIND_TOY, toast, Beam, Lamps, LAMP, Grip, Flare, Fest, FEST, FEST_FOOD, FEST_ACT, IceVan, ICEVAN, Mind, MIND_SAY, Lock, LOCK, Dm, Bg, Grass, GRASS, Log, Jet, JET, Kin, Pilot, Plan, Rail, Train, MeshW, GENW, BoomCore, LightVol, LightW, Plaza, PlazaLife, ckey, Cold, COLD, coldEnc, coldDec, Flood, FLOOD, Wet, Recs, MAT, Fix, FIX, FarLayer, FarCache, Roads, RD_CLS, Span, Tunnel, Xing, BRT_NAME, XG_NAME, Vcls, VCLS, Navi, Wx, WX, Arch, Fall, Pal, Core, Tool, Law, BigMap, Mem, Cars, CAR, LodPool, RayFar, Game, Mouse, Seed, Lib, Thumb, Hist, HistPanel, Cmd, Minimap, P, Picker, UIStart, Render, Walk, Build, Save, Worlds, DB, Catalog, Favs, Stats, Fauna, Etho, ETHO, Leash, LEASH, Aqua, Legend, LEGENDS, Ufo, UFO, Town, Ferry, Rent, Glide, Coaster, Lift, LIFT, Plane, Air, Airway, SKY, Boat, Drive, Susp, SUSP, Roll, ROLL, Crash, Boom, BOOM, Splash, Sit, Jam, Use, Taxi, TAXI, Life, Ent, Feed, Sim, Nav, Flora, Lv, lvHash, Settle, Urban, Garage, Venue, Stock, Dwell, Folk, Who, Me, Fp, Ppl, PPL, RNG, Fire, Volc, Lava, LavaSim, LavaW, Evt, News, Net, Voice, QR, Mq, NOTES, Wind, VR, Sfx, Music, Babble, BAB_L, Radio, RADIO_ST, RADIO_G, Horn, Quality, Sea, Sky, Shadow, I18N, Unz, LANGS, loc, tr, bench, dbg: { greedyQuads, quadsToVerts, QuadBuf, packQuads, QMesh, compile, VS_MAIN, FS_MAIN, gl, PADB, fbm, vnoise, genPlan, buildHouse, furnishWorld, makeInst, rowInst, instRow, Terr, WL, ROAD, SLOT } }; +window.G = { Ground, GROUND, Vill, Estate, EST_TY, Rotor, ROTOR, GENV, GFLOOR, Glow, GLOW, Glare, Hdr, Occ, Slip, SLIP, Pen, PEN, PEN_KIND, Herd, HERD, Flock, FLOCK_SP, Hull, HULL, Helm, HELM, Hover, HOVER, UFO_BODY, Weave, Sport, SPORT, SPORT_MD, Ball, BALL, Shape, SHC, Arm, ARM, RS, Ships, Port, SHIP, frame, Camera, Guard, GUARD, Perf, PERF_SCEN, GpuT, Till, TILL, TILL_K, TILL_V, Camp, CAMP, Under, UG, Hitch, HITCH, TOW, Fair, FAIR, Post, POST, Caravan, CARAVAN, Circus, CIRCUS, Dent, DENT, dentModel, Odds, ODD_KIND, Ice, ICE, Quake, QUAKE, Bloom, BLOOM, Farm, FARM, Night, NIGHT, Nest, NEST, Mote, Art, ART, ArtFx, ArtUI, ART_USE, Optic, Planets, ART_PLANETS, MIND_TOY, toast, Beam, Lamps, LAMP, Grip, Flare, Fest, FEST, FEST_FOOD, FEST_ACT, IceVan, ICEVAN, Mind, MIND_SAY, Lock, LOCK, Dm, Bg, Grass, GRASS, Log, Jet, JET, Kin, Pilot, Plan, Rail, Train, MeshW, GENW, BoomCore, LightVol, LightW, Plaza, PlazaLife, ckey, Cold, COLD, coldEnc, coldDec, Flood, FLOOD, Wet, Recs, MAT, Fix, FIX, FarLayer, FarCache, Roads, RD_CLS, Span, Tunnel, Xing, BRT_NAME, XG_NAME, Vcls, VCLS, Navi, Wx, WX, Arch, Fall, Pal, Core, Tool, Law, BigMap, Mem, Cars, CAR, LodPool, RayFar, Game, Mouse, Seed, Lib, Thumb, Hist, HistPanel, Cmd, Minimap, P, Picker, UIStart, Render, Walk, Build, Save, Worlds, DB, Catalog, Favs, Stats, Fauna, Etho, ETHO, Leash, LEASH, Aqua, Legend, LEGENDS, Ufo, UFO, Town, Ferry, Rent, Glide, Coaster, Lift, LIFT, Plane, Air, Airway, SKY, Boat, Drive, Susp, SUSP, Roll, ROLL, Crash, Boom, BOOM, Splash, Sit, Jam, Use, Taxi, TAXI, Life, Ent, Feed, Sim, Nav, Flora, Lv, lvHash, Settle, Urban, Garage, Venue, Stock, Dwell, Folk, Who, Me, Fp, Ppl, PPL, RNG, Fire, Volc, Lava, LavaSim, LavaW, Evt, News, Net, Voice, QR, Mq, NOTES, Wind, VR, Sfx, Music, Babble, BAB_L, Radio, RADIO_ST, RADIO_G, Horn, Quality, Sea, Sky, Shadow, I18N, Unz, LANGS, loc, tr, bench, dbg: { greedyQuads, quadsToVerts, QuadBuf, packQuads, QMesh, compile, VS_MAIN, FS_MAIN, gl, PADB, fbm, vnoise, genPlan, buildHouse, furnishWorld, makeInst, rowInst, instRow, Terr, WL, ROAD, SLOT } }; Guard.arm(window.G); // every tick / update / frame of the modules runs isolated from here on (01_guard.js) // save when the tab is hidden; when the WebGL context is lost (happens on tablets), reload with auto-resume document.addEventListener('visibilitychange', () => { if (document.hidden && Game.state === 'walk') Save.now(); }); diff --git a/tools/arm.test.mjs b/tools/arm.test.mjs index 3c5c26a9c..b5a18dcca 100644 --- a/tools/arm.test.mjs +++ b/tools/arm.test.mjs @@ -17,7 +17,7 @@ const T = `(()=>{ const W = G.Walk, A = G.Arm, w = W.w, out = {}; G.Fp.on = fals out.btn = W.focus().a; A.hook(); out.mode = v.mode; out.btn2 = W.focus().a; const x0 = v.x, z0 = v.z; aim(-34, HC.y, -30); run(600); out.moved = +Math.hypot(v.x - x0, v.z - z0).toFixed(1); out.up = +(v.y - gy).toFixed(1); A.drop(); run(240); out.mode2 = v.mode; out.down = +(v.y - gy).toFixed(1); - const g = G.Town.ground(-14, -15, 90); out.gen = A.loose(-14, g - 1, -15); aim(-14, g + 1, -15); run(300); A.hook(); out.ground = !!HC.arm.load; + const g = G.Ground.at(-14, -15, 90); out.gen = A.loose(-14, g - 1, -15); aim(-14, g + 1, -15); run(300); A.hook(); out.ground = !!HC.arm.load; const n = pile(-18, -16, 4), id0 = w.get(-17, PG, -15); aim(-16, PG + 3, -14); run(400); A.hook(); out.n = [n, HC.arm.load && HC.arm.load.n]; out.gone = w.get(-17, PG, -15); aim(-36, HC.y, -34); run(500); A.drop(); run(120); let k = 0; for (let x = -50; x < -25; x++) for (let z = -48; z < -22; z++) for (let y = PG - 4; y < PG + 8; y++) if (A.loose(x, y, z)) k++; out.laid = k; G.Build.undoLast(); out.back = w.get(-17, PG, -15) === id0; diff --git a/tools/boom.test.mjs b/tools/boom.test.mjs index 06c819d58..abc99331a 100644 --- a/tools/boom.test.mjs +++ b/tools/boom.test.mjs @@ -4,7 +4,7 @@ // 2. an error inside a blast never stops the game loop; 3. a charge restored from a save with its fuse almost out waits a few seconds; // 4. cars: a near blast sets a car on fire, a passer-by calls the fire brigade, it comes and repairs it; a close strong blast wrecks a car into // cubes at once (nothing burns); furniture inside the house breaks into cubes; undo brings back cars and furniture; -// 5. nothing hangs over a hole: the ground under people and animals is found at the bottom of a pit (Town.ground, Boom.sink, +// 5. nothing hangs over a hole: the ground under people and animals is found at the bottom of a pit (Ground.at, Boom.sink, // Fauna.foot) and they climb back out; a table over a crater comes down into it, a parked car too (a small one on flat ground, its wheels // within the mouth of the crater: Boom.pass), and one undo step puts them back. import './chrome.mjs'; // Chrome as shipped in cloud containers (see there) @@ -91,7 +91,7 @@ try { const r = await ev(`(() => { const w = G.Walk.w, x = 8, z = 8, y = gy(x, z), keep = []; for (let Y = y - 8; Y < y; Y++) for (let Z = z - 3; Z <= z + 3; Z++) for (let X = x - 3; X <= x + 3; X++) { keep.push([X, Y, Z, w.get(X, Y, Z)]); w.set(X, Y, Z, 0); } - const g = G.Town.ground(x + .5, z + .5, y), o = {}, a = G.Boom.sink(o, x + .5, z + .5, y, -1); + const g = G.Ground.at(x + .5, z + .5, y), o = {}, a = G.Boom.sink(o, x + .5, z + .5, y, -1); let b = y; for (let i = 0; i < 120; i++) b = G.Boom.sink(o, x + 4.5, z + .5, y, 1 / 60); // walking on, out of the pit const c = { y, ht: 1 }, f = G.Fauna.foot(c, x + .5, z + .5); const col = w.cols.get(G.ckey(x >> 4, z >> 4)), why = [G.Town.loaded(x + .5, z + .5), !!col && col.ready, col && col.todo, !!col && !!col.z, w.modC.has(G.ckey(x >> 4, z >> 4))]; @@ -110,7 +110,7 @@ try { assert(typeof t0 === 'number', t0); const cy = []; for (let i = 0; i < 12; i++) { await ev('run(1)'); await sleep(300); cy.push(await ev('Math.round(CC.y * 100) / 100')); } await until('!G.Crash.jobs.size && !G.Crash.bat', 'the gravity kernel answers'); await ev('run(5)'); - const t1 = await ev(`(() => { const t = G.Walk.w.insts.find(i => i && /garden table/i.test(G.Cmd.iname(i))); return [t.y, t !== TT, CC.y, G.Town.cars.includes(CC), CY, CC.mode, !!CC.burn, CC.dmg, CC.vy, G.Town.ground(CC.x, CC.z, CC.y), G.Town.ground(CC.x, CC.z, CY), (() => { const fx = Math.sin(CC.yaw), fz = Math.cos(CC.yaw), hl = CC.len * .35; return [G.Town.ground(CC.x + fx * hl, CC.z + fz * hl, CC.y + 1), G.Town.ground(CC.x - fx * hl, CC.z - fz * hl, CC.y + 1), G.Drive.buried(CC, CC.x, CC.z, CC.yaw), [-1, 0, 1].map(k => G.Drive.bed(CC.x + fx * hl * k, CC.z + fz * hl * k, CC.y + 1))]; })()] })()`); + const t1 = await ev(`(() => { const t = G.Walk.w.insts.find(i => i && /garden table/i.test(G.Cmd.iname(i))); return [t.y, t !== TT, CC.y, G.Town.cars.includes(CC), CY, CC.mode, !!CC.burn, CC.dmg, CC.vy, G.Ground.at(CC.x, CC.z, CC.y), G.Ground.at(CC.x, CC.z, CY), (() => { const fx = Math.sin(CC.yaw), fz = Math.cos(CC.yaw), hl = CC.len * .35; return [G.Ground.at(CC.x + fx * hl, CC.z + fz * hl, CC.y + 1), G.Ground.at(CC.x - fx * hl, CC.z - fz * hl, CC.y + 1), G.Drive.buried(CC, CC.x, CC.z, CC.yaw), [-1, 0, 1].map(k => G.Ground.drop(CC.x + fx * hl * k, CC.z + fz * hl * k, CC.y + 1, 72))]; })()] })()`); assert(t1[0] < t0 && t1[1], 'the table came down into the crater: ' + t0 + ' -> ' + t1); assert(!t1[3] || t1[2] < t1[4] - 3, 'the car went down into its crater (or was blown apart): ' + JSON.stringify(t1) + ' y ' + cy); await ev('G.Build.undoLast(); G.Build.undoLast(); run(.2); 1'); diff --git a/tools/camel.test.mjs b/tools/camel.test.mjs index f69643591..ff19ba51c 100644 --- a/tools/camel.test.mjs +++ b/tools/camel.test.mjs @@ -130,7 +130,7 @@ try { for (const t = Date.now(); !(await host.evaluate(() => !G.Walk.ride && !G.Drive.tr));) { await host.evaluate(() => { for (let i = 0; i < 2; i++) { G.Walk.update(1 / 60); G.Net.tick(1 / 60); } }); await sleep(250); knelt = knelt || await guest.evaluate(() => { for (let i = 0; i < 4; i++) G.Net.tick(1 / 60); const pl = G.Net.players.get(0); return !!(pl && pl.vn === 1 && pl.vu[0].inst.act > .7); }); - if (process.env.DBG) console.log(await host.evaluate(() => { const T = G.Drive.tr, u = G.Walk.ride; return [T && T.k, T && T.t.toFixed(2), u && (u.jy || 0).toFixed(2), u && (u.inst.act || 0).toFixed(2)].join(); }), await guest.evaluate(() => { const pl = G.Net.players.get(0), u = pl && pl.vn && pl.vu[0]; return u ? [(u.dv || 0).toFixed(2), (u.inst.act || 0).toFixed(2), (G.Town.ground(u.x, u.z, u.y + 5.8) - u.y).toFixed(2), pl.to[10].toFixed(2), u.y.toFixed(2)].join() : 'none ' + (pl && pl.to && pl.to[8]); })); + if (process.env.DBG) console.log(await host.evaluate(() => { const T = G.Drive.tr, u = G.Walk.ride; return [T && T.k, T && T.t.toFixed(2), u && (u.jy || 0).toFixed(2), u && (u.inst.act || 0).toFixed(2)].join(); }), await guest.evaluate(() => { const pl = G.Net.players.get(0), u = pl && pl.vn && pl.vu[0]; return u ? [(u.dv || 0).toFixed(2), (u.inst.act || 0).toFixed(2), (G.Ground.at(u.x, u.z, u.y + 5.8) - u.y).toFixed(2), pl.to[10].toFixed(2), u.y.toFixed(2)].join() : 'none ' + (pl && pl.to && pl.to[8]); })); if (Date.now() - t > 240000) assert.fail('the owner did not get off'); } assert.ok(knelt, 'the guest sees the camel kneel to let the rider off'); diff --git a/tools/etho.test.mjs b/tools/etho.test.mjs index 2f27214fa..8ad5e6ce3 100644 --- a/tools/etho.test.mjs +++ b/tools/etho.test.mjs @@ -67,9 +67,13 @@ function load() { ckey: (cx, cz) => (cx + 32768) * 65536 + (cz + 32768), }); ctx.globalThis = ctx; - const files = ['00_util', '71_nav', '72_etho', '72_fauna']; + const files = ['00_util', '10_shape', '71_ground', '71_nav', '72_etho', '72_fauna']; let code = files.map(f => fs.readFileSync(path.join(ROOT, 'src/game', f + '.js'), 'utf8')).join('\n'); - vm.runInContext('let WL = 36; const RARE_LAIR = [{ sp: "dragon" }, { sp: "unicorn" }, { sp: "fairy" }];\n' + code + '\n;globalThis.X = { Etho, Fauna, Nav, ETHO, ETHO_CALL, setWL: v => { WL = v; } };', ctx); + // The ground is the real one (71_ground.js) for whoever walks (Nav), but for the rule of Fauna.foot that takes an animal to the bottom of a + // pit it says "none", as this test's stand-in for Town.ground always did: these scenes have no craters. (With the real answer an animal + // that a scene leaves in the air between two plans is taken down at once; falling becomes one law for every body in the next step of the + // refactor, docs/ARCHITECTURE.md "One concept, one way".) + vm.runInContext('let WL = 36; const RARE_LAIR = [{ sp: "dragon" }, { sp: "unicorn" }, { sp: "fairy" }];\n' + code + '\n;{ const at = Ground.at.bind(Ground); Ground.at = (x, z, y, o) => o ? at(x, z, y, o) : null; } globalThis.X = { Etho, Fauna, Nav, ETHO, ETHO_CALL, setWL: v => { WL = v; } };', ctx); ctx.X.ctx = ctx; ctx.X.sounds = sounds; return ctx.X; } @@ -81,7 +85,7 @@ const SPEED = { pet_cat: 6, pet_dog: 8, cow: 3, horse: 9, sheep: 4, goat: 5, pig function stage(fn) { const X = load(), w = mkWorld(); fn && fn(w); const { Fauna, Nav, Etho } = X, ctx = X.ctx; - Fauna.reset(w, null); Nav.reset(w); ctx.Walk.p = { x: 0, y: G, z: -50, yaw: 0 }; + Fauna.reset(w, null); Nav.reset(w); ctx.Walk.w = w; ctx.Walk.p = { x: 0, y: G, z: -50, yaw: 0 }; const it = id => ({ id, name: id, meta: { animal: { move: MOVE[id] || 'walk', speed: SPEED[id] || 4, wild: 1, biome: [] }, emoji: '' }, model: { size: SIZE[id] || [6, 6, 6] }, state: 2 }); const add = (id, x, z, o) => { const c = Fauna.make(it(id), x + .5, (o && o.y) || G, z + .5, 0, null, o && o.own); c.hx = c.x; c.hy = c.y; c.hz = c.z; if (o && o.grp) c.grp = o.grp; if (MOVE[id] === 'fly' && !(o && o.y)) { c.y = G + 6; c.alt = 6; } return c; }; const p = ctx.Walk.p; diff --git a/tools/ground.test.mjs b/tools/ground.test.mjs new file mode 100644 index 000000000..582083e02 --- /dev/null +++ b/tools/ground.test.mjs @@ -0,0 +1,112 @@ +// One ground for everybody (src/game/71_ground.js, docs/ARCHITECTURE.md "One concept, one way"): node tools/ground.test.mjs +// Until build 486 eleven modules found the ground each in its own way. This test keeps the one finder honest, without a browser: +// 1. the meaning, on columns built by hand: a floor, a step, a wall, a pit, water (waded, fallen into, passed, stood on), a road ramp, +// a cave under a hill, a slab with no room under it, the land where no blocks are made yet; +// 2. the same answer for everybody: on a road ramp the feet (GROUND.walk), a body rolling over (GROUND.roll) and what is seen from afar +// (GROUND.fly) get one height, where before only two of the eleven finders knew the ramp at all; +// 3. nothing changed by accident: the finders that were folded in are kept here as they were written (OLD) and asked the same questions on +// 60 000 random columns of air, blocks, water and ramps; the new answers must be theirs, but for the differences that were chosen: +// the top of a ramp where the old one gave its cell (a body rolling over; a look from afar that began in the ramp's own cell). +import fs from 'node:fs'; +import vm from 'node:vm'; +const ROOT = new URL('..', import.meta.url).pathname; +const ctx = vm.createContext({ console, Math, WL: 40, LG: 60, DRIVE_STEP: 2, CRASH_DUST: Uint8Array.from({ length: 64 }, (_, m) => m === 7 ? 1 : 0), PADB: 3, Walk: { w: null }, Town: { loaded: () => true } }); +vm.runInContext(['10_shape', '71_ground'].map(f => fs.readFileSync(ROOT + 'src/game/' + f + '.js', 'utf8')).join('\n') + '\n;globalThis.X = { Ground, GROUND, Shape };', ctx); +const { Ground, GROUND, Shape } = ctx.X; +let fails = 0; const ok = (c, m) => { if (!c) { fails++; console.log('✗ ' + m); } else console.log('✓ ' + m); }; + +// a world of one kind of column everywhere: col(y) → 0 air, 1 a block, 2 water, 3 a ramp block (rising along x from 0 to a whole cell) +const RAMP = Shape.code(0, 4, 0, 4), LEAF = 5; +const world = (col, o = {}) => ({ + get: (x, y, z) => { const c = y < 0 ? 1 : col(y, x, z); return c === 3 ? 9 : c; }, solid(x, y, z) { const c = y < 0 ? 1 : col(y, x, z); return c === 1 || c === LEAF; }, + transp: [0, 0, 2, 0, 0, 0, 0, 0, 0, 3], shp: [0, 0, 0, 0, 0, 0, 0, 0, 0, RAMP], nshp: 1, pm: [0, 1, 0, 0, 0, 7, 0, 0, 0, 1], + T: { q: 3, at: () => o.land ?? 50, deck: () => !!o.deck, dk: o.dk || null, rdr: null }, + col: () => ({ ch: Array.from({ length: 16 }, (_, cy) => { for (let y = cy * 16; y < cy * 16 + 16; y++) if (col(y, 0, 0)) return [1]; return 0; }) }), +}); +const on = (col, o) => (ctx.Walk.w = world(col, o)); +vm.runInContext('var LNCY = 16;', ctx); + +// ---- 1. the meaning ---- +on(y => y < 50 ? 1 : 0); +ok(Ground.at(.5, .5, 50) === 50 && Ground.at(.5, .5, 50.9) === 50, 'flat land: the feet stand on its top'); +ok(Ground.at(.5, .5, 47) === 50 && Ground.at(.5, .5, 55) === 50, 'a step up of three cells and a drop of five are the floor as it is'); +ok(Ground.at(.5, .5, 46) === null, 'deeper in the ground than a step up there is no floor (a wall)'); +ok(Ground.at(.5, .5, 100) === 50 && Ground.at(.5, .5, 130) === null, 'a pit of 50 cells is fallen into, 72 and more is no ground'); +ok(Ground.drop(.5, .5, 60, 14) === 50 && Ground.drop(.5, .5, 70, 14) === null && Ground.top(.5, .5, 60, 14) === 50, 'drop and top give the cell within their reach, null beyond'); +ok(Ground.top(.5, .5, 40, 5) === 40, 'top from inside the ground: at least where it was asked from (a crane keeps clear of it)'); +ok(Ground.sky(0, 0) === 50, 'sky: the top of the whole column'); +on(y => y < 40 ? 1 : y < 48 ? 2 : 0); // a lake 8 deep, its surface at 48 +ok(Ground.at(.5, .5, 60) === null, 'a fall into water: nothing walks there'); +ok(Ground.at(.5, .5, 60, { up: 3, near: 6, down: 72, wet: 1 }) === 40, 'wet 1: the bed under the water'); +ok(Ground.at(.5, .5, 60, GROUND.fly) === 48 && Ground.under(.5, .5, 60) === 48, 'from the air: the surface of the water'); +ok(Ground.at(.5, .5, 60, GROUND.roll) === null && Ground.drop(.5, .5, 60, 72) === 40, 'a body rolling over finds no floor in water; drop passes water'); +on(y => y < 47 ? 1 : y < 49 ? 2 : 0); // a ford two cells deep +ok(Ground.at(.5, .5, 49) === 47, 'shallow water within a step is waded: the bed'); +on(y => y < 50 ? 1 : y === 50 ? 3 : 0); // a road ramp on the land +{ + const a = Ground.at(.25, .5, 50.2), b = Ground.at(.75, .5, 50.2), r = Ground.at(.75, .5, 51, GROUND.roll), f = Ground.under(.75, .5, 70), d = Ground.drop(.75, .5, 52, 14); + ok(Math.abs(a - 50.25) < 1e-9 && Math.abs(b - 50.75) < 1e-9, `a road ramp: the sloped top under the feet (${a}, ${b})`); + ok(r === b && f === b, `the same height for the feet, a body rolling over and a look from afar (${b}, ${r}, ${f})`); + ok(d === 50, 'whole cells (drop) see the ground cell under the ramp, as an animal does'); +} +on(y => y < 50 ? 1 : y === 60 ? 3 : 0); // the edge of a deck: a ramp block with nothing under it +ok(Math.abs(Ground.at(.5, .5, 61) - 60.5) < 1e-9, 'a ramp block with air under it is a floor too'); +on(y => y < 30 ? 1 : y < 38 ? 0 : y < 50 ? 1 : 0); // a cave under a hill +ok(Ground.at(.5, .5, 50) === 50 && Ground.at(.5, .5, 32) === 30, 'a hill with a cave: on the hill and in the cave each stands on its own floor'); +ok(Ground.at(.5, .5, 44) === null, 'inside the hill: no digging down to the cave'); +on(y => y < 50 ? 1 : y === 52 ? 1 : 0, { land: 49.2 }); // a slab two cells over the ground +ok(Ground.road(.5, .5) === 53 && Ground.road(.5, .5, 50) === 50, 'a car put under a slab with no room goes on top of it; one that drives there stays on its floor'); +ok(Ground.road(.5, .5, 50, 1) === 53, 'room asked for by one that moves (the taxi): the floor with room'); +on(y => y < 50 ? 1 : y === 52 ? LEAF : 0, { land: 49.2 }); +ok(Ground.road(.5, .5) === 50, 'a bough overhead is no slab (leaves are not hard)'); +on(y => y < 50 ? 1 : 0, { land: 44.3 }); ctx.Town.loaded = () => false; +ok(Ground.land(.5, .5) === 45 && Ground.under(.5, .5, 90) === 45 && Ground.road(.5, .5, 90) === 45 && ctx.Walk.w.T.q === 3, 'where no blocks are made yet the generator answers (asked at full detail, its detail put back)'); +on(y => 0, { land: 30 }); ok(Ground.land(.5, .5) === 40, 'the sea: the water level'); +on(y => 0, { land: 44.3, deck: 1 }); ok(Ground.road(.5, .5) === 60 && Ground.road(.5, .5, 45) === 45, 'put on a bridge of the home street: its deck, not the river bed; from its own height: the land'); +on(y => 0, { land: 44.3, dk: [{ d: 2, y: 71.4, r: { w: 4 } }, { d: 30, y: 90, r: { w: 4 } }] }); ok(Ground.road(.5, .5) === 72, 'put on a bridge of the road network: the deck over the point'); +ctx.Town.loaded = () => true; +{ const w = on(y => y < 50 ? 1 : y >= 58 ? 1 : 0); ok(Ground.cell(w, 0, 0, 56, 40) === 50 && Ground.cell(w, 0, 0, 56, 40, 9) === -1 && Ground.room(w, 0, 50, 0, 8) && !Ground.room(w, 0, 50, 0, 9) && Ground.roof(w, 0, 0, 56, 40) === 50, 'the kernel: the feet cell, the room over it (8 cells under a ceiling, not 9), the roof'); } + +// ---- 3. the finders that were folded in, as they were written ---- +const OLD = { + town(w, x, z, y) { const X = Math.floor(x), Z = Math.floor(z); let Y = Math.floor(y) + 3; + for (; Y > y - 6; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) return Y + Shape.lift(w, x, Y, z); + for (; Y > y - 72 && Y > 0; Y--) { if (w.solid(X, Y, Z)) return null; const id = w.get(X, Y - 1, Z); if (id && w.transp[id] === 2) return null; if (w.solid(X, Y - 1, Z)) return Y + Shape.lift(w, x, Y, z); } + return null; }, + drive(w, x, z, y) { const X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y) + 2; Y > y - 70; Y--) { const id = w.get(X, Y - 1, Z); if (id && !w.solid(X, Y, Z)) return w.shp && w.shp[id] ? Y - 1 + Shape.h(w.shp[id], x - X, z - Z) : Y; } return y - 70; }, + bed(w, x, z, y) { const X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y); Y > y - 72 && Y > 0; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) return Y; return null; }, + fauna(w, x, y, z) { const X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y); Y > y - 14; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) return Y; return null; }, + roll(w, x, z, y) { const X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y) + 2; Y > y - 40; Y--) { if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) return Y; const id = w.get(X, Y - 1, Z); if (id && w.transp[id] === 2) return null; } return null; }, + arm(w, x, z, y0) { const X = Math.floor(x), Z = Math.floor(z); for (let y = Math.floor(y0); y > y0 - 90 && y > 0; y--) if (w.solid(X, y, Z)) return y + 1; return y0 - 90; }, + art(w, x, y0, z) { const X = Math.floor(x), Z = Math.floor(z); for (let y = Math.floor(y0); y > y0 - 12 && y > 0; y--) if (w.solid(X, y - 1, Z) && !w.solid(X, y, Z)) return y; return null; }, + nest(w, x, y, z) { const X = Math.floor(x), Z = Math.floor(z); for (let Y = Math.floor(y) + 10; Y > y - 16; Y--) if (w.solid(X, Y - 1, Z)) return Y; return null; }, + navfall(w, K) { const X = Math.floor(K.x), Z = Math.floor(K.z), y = Math.floor(K.y + .01); if (w.solid(X, y - 1, Z)) return null; + for (let Y = y - 1; Y > y - 72 && Y > 0; Y--) { if (w.solid(X, Y, Z)) return null; const id = w.get(X, Y - 1, Z); if (id && w.transp[id] === 2) return null; if (w.solid(X, Y - 1, Z)) return Y; } return null; }, + feet(w, X, Z, y, up, dn, hh) { for (let Y = y + up; Y >= y - dn; Y--) if (w.solid(X, Y - 1, Z) && !w.solid(X, Y, Z)) { for (let k = 1; k < hh; k++) if (w.solid(X, Y + k, Z)) return -1; return Y; } return -1; }, + pilot(w, X, Z, Y) { let y0 = Y - 12; for (let y = Y + 8; y >= Y - 12; y--) if (w.solid(X, y, Z) && !w.solid(X, y + 1, Z) && !w.solid(X, y + 2, Z)) { y0 = y; break; } return y0; }, +}; +// a random column: runs of air, blocks and water (water only over something, never hanging), now and then a ramp block on top of a block +let seed = 12345; const rnd = () => (seed = (seed * 1664525 + 1013904223) >>> 0) / 4294967296; +const column = () => { const c = new Uint8Array(160); let y = 0, k = 1; while (y < 160) { let n = 1 + Math.floor(rnd() * (k === 1 ? 14 : k === 2 ? 5 : 22)); const k0 = k; while (n-- && y < 160) c[y++] = k; k = k0 === 1 ? (rnd() < .25 ? 2 : 0) : k0 === 2 ? 0 : 1; + if (k0 === 1 && k === 0 && rnd() < .2 && y < 160) c[y++] = 3; } return c; }; +const same = (a, b) => a === b || a != null && b != null && Math.abs(a - b) < 1e-9; +{ + const N = 60000, miss = {}, n = {}; const diff = (k, a, b, q) => { n[k] = (n[k] || 0) + 1; if (!same(a, b)) (miss[k] || (miss[k] = [])).push(`${q}: was ${b}, is ${a}`); }; + for (let i = 0; i < N; i++) { + const c = column(), w = on(y => y < 160 ? c[y] : 0), x = rnd(), z = rnd(), y = 2 + rnd() * 150, Yi = Math.floor(y), q = `y ${y.toFixed(2)} column ${Array.from(c.slice(Math.max(0, Yi - 12), Yi + 6)).join('')} (from ${Math.max(0, Yi - 12)})`; + diff('walk = Town.ground', Ground.at(x, z, y), OLD.town(w, x, z, y), q); + { const a = Ground.under(x, z, y), b = OLD.drive(w, x, z, y); diff('fly = Drive.floor', a, b === Math.floor(b) && b > 0 ? b + Shape.lift(w, x, b, z) : b, q); } // (asked from under a ramp it gave the ramp's cell, not its top) + diff('drop 72 = Drive.bed', Ground.drop(x, z, y, 72), OLD.bed(w, x, z, y), q); + diff('drop 14 = Fauna.drop', Ground.drop(x, z, y, 14), OLD.fauna(w, x, y, z), q); + diff('drop 12 = Art.floor', Ground.drop(x, z, y, 12), OLD.art(w, x, y, z), q); + if (y > 91) diff('top = Arm.floor', Ground.top(x, z, y + 1, 90) ?? y - 90, OLD.arm(w, x, z, y), q); // (the old one never looked at the lowest cell of the world) + diff('top = Nest.top', Ground.top(x, z, y + 10, 26), OLD.nest(w, x, y, z), q); + { const a = Ground.at(x, z, y, GROUND.roll), b = OLD.roll(w, x, z, y); diff('roll = Roll.top', a == null ? a : Math.floor(a + 1e-9), b, q); } // (the old one gave the cell of a ramp, now its top) + { const K = { x, y, z }, yk = Math.floor(y + .01), b = OLD.navfall(w, K), a = w.solid(0, yk - 1, 0) ? null : Ground.at(x, z, yk - 1, GROUND.fall); diff('fall = Nav.fall', a == null ? a : Math.floor(a + 1e-9), b, q); } + { const up = 1 + Math.floor(rnd() * 3), dn = 2 + Math.floor(rnd() * 3), hh = 3 + Math.floor(rnd() * 6), Y = Ground.cell(w, 0, 0, Yi + up, Yi - dn); diff('cell + room = Nav.feet', Y < 0 || !Ground.room(w, 0, Y, 0, hh) ? -1 : Y, OLD.feet(w, 0, 0, Yi, up, dn, hh), q); } + { const f = Ground.cell(w, 0, 0, Yi + 9, Yi - 11, 2); diff('cell with room = Pilot.rough', f < 0 ? Yi - 12 : f - 1, OLD.pilot(w, 0, 0, Yi), q); } + } + for (const k in n) ok(!miss[k], `${k}: ${n[k]} random columns, ${miss[k] ? miss[k].length + ' differ, e.g. ' + miss[k].slice(0, 2).join(' | ') : 'the same answer'}`); +} +if (fails) { console.error(`✗ ground: ${fails} failed`); process.exit(1); } +console.log('ok: one ground for everybody'); diff --git a/tools/herd.test.mjs b/tools/herd.test.mjs index 499ae3b01..e74f396af 100644 --- a/tools/herd.test.mjs +++ b/tools/herd.test.mjs @@ -28,8 +28,8 @@ const Walk = { p: { x: 1e5, y: 0, z: 1e5 }, runK: 0, ride: null }; const stubs = { Life, Walk, Net: { players: new Map(), role: null, live: () => false }, Sfx: { play() {}, animal() {} }, Ent: { reg() {} }, toast() {}, ckey: (cx, cz) => (cx + 32768) * 65536 + (cz + 32768), _turn: (a, b, k) => { let d = (b - a) % (Math.PI * 2); if (d > Math.PI) d -= Math.PI * 2; else if (d < -Math.PI) d += Math.PI * 2; return a + Math.max(-k, Math.min(k, d)); }, - Fauna: { list: [], loaded: () => true, drop: () => 0, water: (x, y, z) => !!W.water && W.water(x, z), foot: (c, x, z) => solid(x, z) ? null : 0, make: (it, x, y, z, yaw) => ({ it, x, y, z, yaw, gait: 0, hop: 0, pit: 0, ht: 4 }), on: () => true }, - Town: { ground: (x, z) => solid(x, z) ? null : 0, cars: [], make: () => ({}) }, Sim: { r: r => r, live: () => true, eye: p => p }, PW: .8, PH: 8.6, + Fauna: { list: [], loaded: () => true, water: (x, y, z) => !!W.water && W.water(x, z), foot: (c, x, z) => solid(x, z) ? null : 0, make: (it, x, y, z, yaw) => ({ it, x, y, z, yaw, gait: 0, hop: 0, pit: 0, ht: 4 }), on: () => true }, + Ground: { at: (x, z) => solid(x, z) ? null : 0, drop: () => 0 }, Town: { cars: [], make: () => ({}) }, Sim: { r: r => r, live: () => true, eye: p => p }, PW: .8, PH: 8.6, Lib: { byId: {} }, dogSlots: { v: [] }, defSlots: () => stubs.dogSlots.v.map(a => a.slice()), Ppl: { bake: () => ({ hip: 0 }) }, TOWN_COL: { skin: ['#c08a60'], hair: ['#3a2a1e'] }, PPL: { slots: Array.from({ length: 9 }, () => ['', '', 'plain']) }, TOWN_NAMES: { m: ['Ivan'], f: ['Anna'] }, Splash: { at() {} }, Sea: { h: () => 0, lift: () => 0, fade: () => 0 }, }; diff --git a/tools/hut.test.mjs b/tools/hut.test.mjs index 5ef683240..8bb4c84d3 100644 --- a/tools/hut.test.mjs +++ b/tools/hut.test.mjs @@ -16,8 +16,8 @@ import { fileURLToPath } from 'node:url'; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const stub = new Proxy(function () {}, { get: (t, k) => k === Symbol.toPrimitive ? () => '' : stub, apply: () => stub, construct: () => stub }); const ctx = vm.createContext({ console, Math, document: stub, navigator: stub, localStorage: stub, window: stub, MutationObserver: stub, Image: stub, performance, BUILD: { n: 0 }, sessionStorage: stub, setInterval: () => 0, clearInterval: () => 0, addEventListener: () => 0, location: stub, fetch: stub }); -const code = ['00_util', '08_mats', '10_vox', '30_world', '31_terrain', '31_terrforms', '31_terrgeo', '38_port', '40_house', '41_villa', '42_plan'].map(f => fs.readFileSync(path.join(ROOT, 'src/game', f + '.js'), 'utf8')).join('\n'); -vm.runInContext(VM_FAST + 'const ST_G = 1600, Settle = { on: false, pad: () => false, cell: () => ({ s: null }) };\n' + code + '\n;globalThis.T = { genPlan, buildHouse, HTYPES, Terr, siteSet };', ctx); +const code = ['00_util', '08_mats', '09_core', '10_vox', '30_world', '31_terrain', '31_terrforms', '31_terrgeo', '33_flora', '33_species', '38_port', '40_house', '41_villa', '42_plan'].map(f => fs.readFileSync(path.join(ROOT, 'src/game', f + '.js'), 'utf8')).join('\n'); +vm.runInContext(VM_FAST + 'const treeId = (L, id) => id, NUL = new Proxy({}, { get: (t, k) => k === "on" ? false : () => null }), Roads = NUL, Air = NUL, ST_G = 1600, Settle = { on: false, pad: () => false, cell: () => ({ s: null }), kmax: () => -1 };\n' + code + '\n;globalThis.T = { genPlan, buildHouse, HTYPES, Terr, siteSet };', ctx); const { genPlan, buildHouse, HTYPES, Terr, siteSet } = ctx.T; const TYPES = Object.keys(HTYPES), LOTS = [200, 300, 400, 600, 800, 1200, 1600, 2400], AREAS = [60, 80, 120, 160, 240, 320, 480, 640]; const OUTSETS = [['hut'], ['hut', 'shed'], ['hut', 'bath'], ['hut', 'glass'], ['shed', 'hut', 'bath', 'green', 'gazebo'], ['shed', 'hut', 'bath', 'green', 'gazebo', 'glass']]; diff --git a/tools/iceplay.test.mjs b/tools/iceplay.test.mjs index 5a67be930..ed98de5ce 100644 --- a/tools/iceplay.test.mjs +++ b/tools/iceplay.test.mjs @@ -60,7 +60,7 @@ try { if (o.brokeAt) o.maxTilt = Math.max(o.maxTilt, c.tilt || 0); if (!o.outAt && o.brokeAt && !G.Walk.ride) { o.outAt = i / 60; o.out = { y: c.y, wet: G.Drive.sunk(c) }; } if (o.outAt && i / 60 > o.outAt + 4) break; } - const W = G.Walk, n = G.Drive.find(W.p); Object.assign(o, { y: c.y, bottom: G.Drive.bed(c.x, c.z, c.y + 1), top: y0, offered: !!n && n.u === c, hole: cells(), holes: G.Ice.holes.size, wet: W.wet, roof: !W.wet && W.p.y > c.y + 6 && Math.hypot(W.p.x - c.x, W.p.z - c.z) < c.len / 2 }); + const W = G.Walk, n = G.Drive.find(W.p); Object.assign(o, { y: c.y, bottom: G.Ground.drop(c.x, c.z, c.y + 1, 72), top: y0, offered: !!n && n.u === c, hole: cells(), holes: G.Ice.holes.size, wet: W.wet, roof: !W.wet && W.p.y > c.y + 6 && Math.hypot(W.p.x - c.x, W.p.z - c.z) < c.len / 2 }); return o; }); console.log(JSON.stringify(mon)); diff --git a/tools/law.test.mjs b/tools/law.test.mjs index cb7e7e6de..21c29fe8a 100644 --- a/tools/law.test.mjs +++ b/tools/law.test.mjs @@ -136,7 +136,7 @@ try { // 5. the chase by car: the officers get back in, the car follows the player at the wheel, they are caught once they stop { const r = await ev(`(() => { const W = G.Walk, L = G.Law, w = W.w; if (W.ride) { L.let = 1; G.Drive.exit(true); L.let = 0; } L.reset(w); - const [gx, gz] = L.gate(), c = G.Drive.own('car_sport', null, gx, L.ground(gx, gz), gz, Math.PI / 2, 0); G.Town.place(c, 0); G.Drive.enter({ u: c, n: 0, now: 1 }); L.wanted(); L.next = 1; + const [gx, gz] = L.gate(), c = G.Drive.own('car_sport', null, gx, G.Ground.road(gx, gz), gz, Math.PI / 2, 0); G.Town.place(c, 0); G.Drive.enter({ u: c, n: 0, now: 1 }); L.wanted(); L.next = 1; let chase = 0, best = 1e9; const wet = () => { const R = W.ride && W.ride.car || c; for (let d = 0; d <= 60; d += 10) { const x = R.x + Math.sin(R.yaw) * d, z = R.z + Math.cos(R.yaw) * d; if (w.T.at(x, z) < w.T.wl + .5) return true; } return false; }; // (it brakes before the water: a chase by car, not by boat) for (let i = 0; i < 120 * 30 && !(chase && i > 30 * 30); i++) { const R = W.ride && W.ride.car || c; G.Drive.tank = 1, W.joy = [0, !wet() ? -1 : R.v > .5 ? 1 : 0]; W.update(1 / 30); for (const q of L.cars) if (q.lg && q.lg.k === 'chase') chase = 1; } G.Drive.tank = 1, W.joy = [0, 0]; window.HC = c; window.HB = best; window.HG = [gx, gz]; return { chase } })()`); @@ -164,7 +164,7 @@ try { const r = await ev(`(() => { const W = G.Walk, L = G.Law, w = W.w, p = W.p; L.reset(w); p.fly = false; p.x = 60; p.z = -3; p.y = gy(60, -3) + 1; run(1); const b = G.Fauna.make(G.Lib.byId.dragon, p.x + 2, p.y + 12, p.z + 9, 2.4), u = G.Drive.mount(b); G.Drive.enter({ u, n: 0, now: 1 }); run(1); W.keys = { KeyW: true }; p.pitch = .5; run(4); L.wanted(); L.next = 1; let d = 1e9; const tr = []; // (tr: where the first helicopter was every 5 s, for a failure) - for (let i = 0; i < 40 * 30; i++) { W.keys = { KeyW: true }; p.yaw += .006; p.pitch = p.y - L.ground(p.x, p.z) < 70 ? .15 : -.05; W.update(1 / 30); if (i > 30 * 30) for (const h of L.air) d = Math.min(d, Math.hypot(h.x - p.x, h.z - p.z)); const h = L.air[0]; if (h && i % 150 === 0) tr.push([Math.round(h.x - p.x), Math.round(h.y - p.y), Math.round(h.z - p.z), Math.round(h.v), +(h.blk || 0).toFixed(1)]); } + for (let i = 0; i < 40 * 30; i++) { W.keys = { KeyW: true }; p.yaw += .006; p.pitch = p.y - G.Ground.road(p.x, p.z) < 70 ? .15 : -.05; W.update(1 / 30); if (i > 30 * 30) for (const h of L.air) d = Math.min(d, Math.hypot(h.x - p.x, h.z - p.z)); const h = L.air[0]; if (h && i % 150 === 0) tr.push([Math.round(h.x - p.x), Math.round(h.y - p.y), Math.round(h.z - p.z), Math.round(h.v), +(h.blk || 0).toFixed(1)]); } W.keys = {}; return { m: L.m, n: L.air.length, d: Math.round(d), cars: L.cars.length, tr } })()`); assert.equal(r.m, 'air', 'flying: ' + JSON.stringify(r)); assert(r.n >= 1 && r.d < 150, 'a helicopter keeps close: ' + JSON.stringify(r)); assert.equal(r.cars, 0, 'no cars after a dragon'); console.log(`on a dragon: ${r.n} helicopter(s), the nearest within ${r.d} cells`); @@ -190,7 +190,7 @@ try { // around: nothing; the player's own car is theirs to blow up { const r = await ev(`(() => { const W = G.Walk, w = W.w, L = G.Law, p = W.p, f0 = L.folks, out = {}; if (W.ride) { L.let = 1; G.Drive.exit(true); L.let = 0; } W.keys = {}; - const [gx, gz] = L.gate(), x = gx - 60.5, z = gz + .5, y = L.ground(x, z); + const [gx, gz] = L.gate(), x = gx - 60.5, z = gz + .5, y = G.Ground.road(x, z); const one = (k, wit0, mine) => { L.reset(w); G.Evt.reset(); let wit = wit0; L.folks = (a, b, r) => wit.filter(c => Math.hypot(c.x - a, c.z - b) < r); const TC = G.Town.cars, away = TC.filter(o => Math.hypot(o.x - x, o.z - z) < 80); for (const o of away) TC.splice(TC.indexOf(o), 1); // passing traffic stays out of it const h0 = G.Hist.at, c = mine ? G.Drive.own('car', null, x, y, z, Math.PI / 2, 0) : G.Town.build('car', x, z, Math.PI / 2, { solo: 1, seed: 7 }); if (G.Town.cars.indexOf(c) < 0) G.Town.cars.push(c); c.y = y; c.mode = 'park'; c.v = 0; G.Town.place(c, 0); @@ -210,12 +210,12 @@ try { // no jump. (The helicopter is put in its orbit over the player and one of its team next to them: the arrest itself is case 4) { await ev(`(() => { const W = G.Walk, L = G.Law, w = W.w, p = W.p; if (W.ride) { L.let = 1; G.Drive.exit(true); L.let = 0; } L.reset(w); W.keys = {}; - const [gx, gz] = L.gate(); p.fly = false; p.x = gx + 6; p.z = gz; p.y = L.ground(p.x, p.z) + 1; run(1); L.wanted(); L.sta = L.station(p.x, p.z); L.next = 1e9; - const H = L.copter('orbit'); L.H = H; H.x = p.x + 40; H.z = p.z; H.y = L.ground(p.x, p.z) + 115; H.a = 0; L.swat(H, 0); const o = H.sw.pop(); o.x = p.x + 1; o.z = p.z; o.y = L.ground(o.x, o.z); L.cops.push(o); - window.M10 = { up: 0, inH: 0, cars: 0, land: null, sta: L.sta && [L.sta.x, L.sta.z], g0: [p.x, p.z] }; const l0 = window.L0 = L.landed; L.landed = function (h) { M10.land = [h.x, h.z, h.y - L.ground(h.x, h.z), G.Walk.p.x, G.Walk.p.z]; return l0.call(this, h); }; + const [gx, gz] = L.gate(); p.fly = false; p.x = gx + 6; p.z = gz; p.y = G.Ground.road(p.x, p.z) + 1; run(1); L.wanted(); L.sta = L.station(p.x, p.z); L.next = 1e9; + const H = L.copter('orbit'); L.H = H; H.x = p.x + 40; H.z = p.z; H.y = G.Ground.road(p.x, p.z) + 115; H.a = 0; L.swat(H, 0); const o = H.sw.pop(); o.x = p.x + 1; o.z = p.z; o.y = G.Ground.road(o.x, o.z); L.cops.push(o); + window.M10 = { up: 0, inH: 0, cars: 0, land: null, sta: L.sta && [L.sta.x, L.sta.z], g0: [p.x, p.z] }; const l0 = window.L0 = L.landed; L.landed = function (h) { M10.land = [h.x, h.z, h.y - G.Ground.road(h.x, h.z), G.Walk.p.x, G.Walk.p.z]; return l0.call(this, h); }; L.arrest(o); return 1 })()`); const t0 = Date.now(); - while (await ev(`(() => { const L = G.Law, p = G.Walk.p; for (let i = 0; i < 90; i++) { G.Walk.update(1 / 30); M10.up = Math.max(M10.up, p.y - L.ground(p.x, p.z)); M10.inH = M10.inH || L.inH; if (L.car && !M10.land) M10.cars++; if (L.st === 4) break; } return L.st })()`) !== 4) { + while (await ev(`(() => { const L = G.Law, p = G.Walk.p; for (let i = 0; i < 90; i++) { G.Walk.update(1 / 30); M10.up = Math.max(M10.up, p.y - G.Ground.road(p.x, p.z)); M10.inH = M10.inH || L.inH; if (L.car && !M10.land) M10.cars++; if (L.st === 4) break; } return L.st })()`) !== 4) { if (Date.now() - t0 > 900000) throw new Error('timed out: the helicopter ride ' + JSON.stringify(await ev('M10')) + ' st ' + await ev('G.Law.st') + ' H ' + await ev('G.Law.H && [G.Law.H.k, Math.round(G.Law.H.x), Math.round(G.Law.H.z), Math.round(G.Law.H.y)]')); await sleep(200); } diff --git a/tools/leak.soak.mjs b/tools/leak.soak.mjs index 41e4e7f3e..86a6647f7 100644 --- a/tools/leak.soak.mjs +++ b/tools/leak.soak.mjs @@ -292,7 +292,7 @@ const SC = { p.fly = true; p.x = ROAD.x; p.z = ROAD.z; p.y = w.T.at(p.x, p.z) + 20; await LOAD(15000); let B = R.snap(w.T, ROAD.x, ROAD.z, 200); if (!B) return 'lost the road'; const dir = i % 2 ? 1 : -1, at = k => { const r = B.r, j = Math.max(0, Math.min(r.n - 1, Math.floor(B.i) + k * dir)); return [r.px[j], r.pz[j]]; }; - const [tx, tz] = at(2), yaw = Math.atan2(tx - B.x, tz - B.z), y = G.Town.ground(B.x, B.z, w.T.at(B.x, B.z) + 4) ?? w.T.at(B.x, B.z) + 1; + const [tx, tz] = at(2), yaw = Math.atan2(tx - B.x, tz - B.z), y = G.Ground.at(B.x, B.z, w.T.at(B.x, B.z) + 4) ?? w.T.at(B.x, B.z) + 1; const c = D.own('car', null, B.x, y, B.z, yaw, 0); if (!c) return 'no car'; p.fly = false; D.enter({ u: c, n: 0, now: 1 }); RUN(() => !D.tr, 5); if (W.ride !== c) return 'not inside'; let dist = 0, stuck = 0, vm = 0; const t0 = performance.now(); diff --git a/tools/navkeep.test.mjs b/tools/navkeep.test.mjs index 33af8e8f7..8e54dabce 100644 --- a/tools/navkeep.test.mjs +++ b/tools/navkeep.test.mjs @@ -4,7 +4,7 @@ // lifted her on top each time); the next drop found no floor within reach around the pillar and Nav.out put her on the nearest floor // at all, a roof 4.6 cells away across the empty air. The top of the own column comes before that last resort now. const { load } = await import('./city.mjs'); -const X = load(['71_nav'], {}, 'X.Nav = Nav;'); +const X = load(['71_ground', '71_nav'], {}, 'X.Nav = Nav;'); const { Nav } = X; const fail = m => { console.log('FAIL: ' + m); process.exit(1); }; // a world of cells: ground below y 0, plus whatever a scene adds diff --git a/tools/pax.test.mjs b/tools/pax.test.mjs index ef4f22cc5..0475490c9 100644 --- a/tools/pax.test.mjs +++ b/tools/pax.test.mjs @@ -89,7 +89,7 @@ try { const placed = await host.evaluate(() => { const p = G.Walk.p, D = G.Drive, T = G.Town; for (let r = 8; r < 90; r += 3) for (let k = 0; k < 16; k++) { - const a = k / 16 * Math.PI * 2, x = p.x + Math.cos(a) * r, z = p.z + Math.sin(a) * r, y = T.ground(x, z, p.y + 2); if (y == null) continue; + const a = k / 16 * Math.PI * 2, x = p.x + Math.cos(a) * r, z = p.z + Math.sin(a) * r, y = G.Ground.at(x, z, p.y + 2); if (y == null) continue; const c = D.own('car', null, x, y, z, a, 0); if (!c) continue; if (D.worldFree(c, x, z, a, 1.4) && [10, 20, 30].every(d => D.worldFree(c, x + Math.sin(a) * d, z + Math.cos(a) * d, a, 3))) { window.HC = c; D.enter({ u: c, n: 0, now: 1 }); return [x, y, z, a]; } T.cars.splice(T.cars.indexOf(c), 1); diff --git a/tools/plan.lib.mjs b/tools/plan.lib.mjs index fd70165fe..f4a9aced9 100644 --- a/tools/plan.lib.mjs +++ b/tools/plan.lib.mjs @@ -5,7 +5,7 @@ import vm from 'node:vm'; import { VM_FAST } from './vmfast.mjs'; import { fileURLToPath } from 'node:url'; export const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); -export const PLAN_FILES = ['00_util', '08_mats', '10_vox', '30_world', '31_terrain', '33_flora', '33_species', '40_house', '41_villa', '42_plan']; +export const PLAN_FILES = ['00_util', '08_mats', '09_core', '10_vox', '30_world', '31_terrain', '33_flora', '33_species', '40_house', '41_villa', '42_plan']; export function loadPlans() { const stub = new Proxy(function () {}, { get: (t, k) => k === Symbol.toPrimitive ? () => '' : stub, apply: () => stub, construct: () => stub }); const ctx = vm.createContext({ console, Math, document: stub, navigator: stub, localStorage: stub, window: stub, MutationObserver: stub, Image: stub, performance, BUILD: { n: 0 }, sessionStorage: stub, setInterval: () => 0, clearInterval: () => 0, addEventListener: () => 0, location: stub, fetch: stub, requestAnimationFrame: () => 0, tr: (ru, en) => en, trk: (ru, en) => en, loc: s => s, setTimeout }); diff --git a/tools/ramp.test.mjs b/tools/ramp.test.mjs index 7f07ea210..6001b7a74 100644 --- a/tools/ramp.test.mjs +++ b/tools/ramp.test.mjs @@ -38,8 +38,8 @@ const STRIP = `(()=>{ const W = G.Walk, w = W.w, D = G.Drive, S = G.Shape, R = { const LINK = z => `(()=>{ const W = G.Walk, p = W.p; if (!p.fly) W.act('fly'); Object.assign(p, { x: -643, z: ${z}, y: W.w.T.at(-643, ${z}) + 12, vy: 0 }); return 1 })()`; const SCAN = `(()=>{ const w = G.Walk.w, T = w.T, lk = T.link, R = { gw: T.gw, nshp: w.nshp || 0 }; if (!lk) { console.log('LINK none'); return 1; } let cells = 0, shaped = 0, jump = 0, at = null, n = 0; - for (let z = lk.z1 + 24; z <= -60; z++) for (let x = lk.x - lk.w + 2; x < lk.x + lk.w - 2; x++) { if (!G.Town.loaded(x, z)) continue; const g = G.Town.ground(x + .5, z + .5, T.at(x, z) + 2); if (g == null) continue; cells++; const id = w.get(x, Math.floor(g), z); if (id && w.shp && w.shp[id]) shaped++; } - for (const lx of [lk.x - 4.5, lk.x + 4.5]) { let prev = null; for (let z = lk.z1 + 24; z <= -60; z += .1) { if (!G.Town.loaded(lx, z)) { prev = null; continue; } const g = G.Town.ground(lx, z, T.at(lx, z) + 2); if (g == null) { prev = null; continue; } n++; if (prev != null && Math.abs(g - prev) > jump) { jump = Math.abs(g - prev); at = [lx, +z.toFixed(1)]; } prev = g; } } + for (let z = lk.z1 + 24; z <= -60; z++) for (let x = lk.x - lk.w + 2; x < lk.x + lk.w - 2; x++) { if (!G.Town.loaded(x, z)) continue; const g = G.Ground.at(x + .5, z + .5, T.at(x, z) + 2); if (g == null) continue; cells++; const id = w.get(x, Math.floor(g), z); if (id && w.shp && w.shp[id]) shaped++; } + for (const lx of [lk.x - 4.5, lk.x + 4.5]) { let prev = null; for (let z = lk.z1 + 24; z <= -60; z += .1) { if (!G.Town.loaded(lx, z)) { prev = null; continue; } const g = G.Ground.at(lx, z, T.at(lx, z) + 2); if (g == null) { prev = null; continue; } n++; if (prev != null && Math.abs(g - prev) > jump) { jump = Math.abs(g - prev); at = [lx, +z.toFixed(1)]; } prev = g; } } Object.assign(R, { cells, shaped, share: +(shaped / Math.max(1, cells)).toFixed(2), jump: +jump.toFixed(2), at, n }); console.log('LINK ' + JSON.stringify(R)); return 1 })()`; const steps = [...game(TOWN, 20261139), STRIP, LINK(-120), LOAD, LINK(-260), LOAD, LINK(-400), LOAD, LINK(-260), LOAD, SCAN]; const out = execFileSync('node', ['tools/shot.mjs', ...steps], { encoding: 'utf8', maxBuffer: 1 << 26, timeout: 40 * 60e3 }); diff --git a/tools/roomy.test.mjs b/tools/roomy.test.mjs index 26e01f8d8..609db3f66 100644 --- a/tools/roomy.test.mjs +++ b/tools/roomy.test.mjs @@ -16,7 +16,7 @@ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const [GH, GL] = /GENV = \{ gh: (\d+), gl: (\d+)/.exec(fs.readFileSync(path.join(ROOT, 'src/game/75_seed.js'), 'utf8')).slice(1).map(Number); const stub = new Proxy(function () {}, { get: (t, k) => k === Symbol.toPrimitive ? () => '' : stub, apply: () => stub, construct: () => stub }); const ctx = vm.createContext({ console, Math, document: stub, navigator: stub, localStorage: stub, window: stub, MutationObserver: stub, Image: stub, performance, BUILD: { n: 0 }, sessionStorage: stub, setInterval: () => 0, clearInterval: () => 0, addEventListener: () => 0, location: stub, fetch: stub, requestAnimationFrame: () => 0, tr: (ru, en) => en, trk: (ru, en) => en, loc: s => s, setTimeout , treeId: (L, id) => id}); -const code = ['00_util', '08_mats', '10_vox', '30_world', '31_terrain', '33_flora', '33_species', '40_house', '41_villa', '42_plan'].map(f => fs.readFileSync(path.join(ROOT, 'src/game', f + '.js'), 'utf8')).join('\n'); +const code = ['00_util', '08_mats', '09_core', '10_vox', '30_world', '31_terrain', '33_flora', '33_species', '40_house', '41_villa', '42_plan'].map(f => fs.readFileSync(path.join(ROOT, 'src/game', f + '.js'), 'utf8')).join('\n'); vm.runInContext(VM_FAST + code + '\n;globalThis.T = { genPlan, buildHouse, HTYPES };', ctx); const { genPlan, buildHouse, HTYPES } = ctx.T; const TYPES = Object.keys(HTYPES).filter(k => !HTYPES[k].vil), AREAS = [0, 60, 120, 160, 240, 320, 480], OUTS = ['shed', 'hut', 'bath', 'green', 'gazebo', 'glass']; diff --git a/tools/rules/ratchet.json b/tools/rules/ratchet.json index 74bf80195..14ab298ab 100644 --- a/tools/rules/ratchet.json +++ b/tools/rules/ratchet.json @@ -1,2 +1,2 @@ { "movers.debt": 12, "movers.namechecks": 144, - "split.enter": 8, "split.ground": 11, "split.free": 7, "split.sit": 3, "split.path": 3, "split.row": 4, "split.harm": 3, "split.scan": 18, "split.gravity": 10 } + "split.enter": 8, "split.ground": 0, "split.free": 7, "split.sit": 3, "split.path": 3, "split.row": 4, "split.harm": 3, "split.scan": 7, "split.gravity": 10 } diff --git a/tools/scoot.test.mjs b/tools/scoot.test.mjs index e432188b1..f9461b766 100644 --- a/tools/scoot.test.mjs +++ b/tools/scoot.test.mjs @@ -31,7 +31,7 @@ try { window.scoot = (want, x, z, yaw) => { const W = G.Walk, p = W.p, T = G.Town; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.night = false; T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; let c = null; for (let s = 1; s < 200 && !c; s++) { const q = T.build('scoot', x, z, yaw, { solo: 1, seed: s * 7919 }); if (q && q.id === want) c = q; } - T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 2, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; return c; }; window.go = (n, thr, st) => { const W = G.Walk; G.Drive.tank = 1, W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); G.Drive.tank = 1, W.joy = [0, 0]; return HC.v; }; diff --git a/tools/shape.test.mjs b/tools/shape.test.mjs index a2c959128..b8ad342b6 100644 --- a/tools/shape.test.mjs +++ b/tools/shape.test.mjs @@ -1,6 +1,6 @@ // Shaped blocks of road ramps (src/game/10_shape.js) without a browser: node tools/shape.test.mjs // The height inside a shape, the fit of a cell to the heights of its corners, the faces the mesher makes (they face out, the top of a -// ramp is one unbroken surface) and the walkable top that Town.ground / Walk read. +// ramp is one unbroken surface) and the walkable top that Ground.at / Walk read. import fs from 'node:fs'; import path from 'node:path'; import vm from 'node:vm'; diff --git a/tools/share.test.mjs b/tools/share.test.mjs index 35f7ad70b..845122b4f 100644 --- a/tools/share.test.mjs +++ b/tools/share.test.mjs @@ -30,7 +30,7 @@ try { await page.evaluate(() => { const N = G.Net, D = G.Drive, T = G.Town, W = G.Walk, p = W.p; W.night = false; if (G.Fp) G.Fp.on = false; T.carT = 1e9; T.routeT = 1e9; N.role = 'host'; N.pid = 0; window.sent = []; N.cast = o => { sent.push(JSON.parse(JSON.stringify(o))); }; - window.spot = skip => { for (let r = 10; r < 140; r += 3) for (let k = 0; k < 16; k++) { const a = k / 16 * Math.PI * 2, x = p.x + Math.cos(a) * r, z = p.z + Math.sin(a) * r, y = T.ground(x, z, p.y + 2); if (y == null || skip && skip.some(s => Math.hypot(x - s[0], z - s[2]) < 16)) continue; + window.spot = skip => { for (let r = 10; r < 140; r += 3) for (let k = 0; k < 16; k++) { const a = k / 16 * Math.PI * 2, x = p.x + Math.cos(a) * r, z = p.z + Math.sin(a) * r, y = G.Ground.at(x, z, p.y + 2); if (y == null || skip && skip.some(s => Math.hypot(x - s[0], z - s[2]) < 16)) continue; const c = D.own('car', null, x, y, z, a, 0); if (!c) continue; const good = D.worldFree(c, x, z, a, 1.4) && [8, 16].every(d => D.worldFree(c, x + Math.sin(a) * d, z + Math.cos(a) * d, a, 3)); T.cars.splice(T.cars.indexOf(c), 1); if (good) return [x, y, z, a]; } return null; }; window.run = n => { for (let i = 0; i < n; i++) { W.update(1 / 30); N.tick(1 / 30); } return 1; }; window.player = (id, n) => { N.addPlayer({ id, n, u: n, z: '', me: G.Me.random() }); return N.players.get(id); }; diff --git a/tools/shots/143.mjs b/tools/shots/143.mjs index 5c79bb9f9..de0f337c1 100644 --- a/tools/shots/143.mjs +++ b/tools/shots/143.mjs @@ -9,7 +9,7 @@ export default { start: [...game({ ...TOWN, site: ['town', 'forest'] }, 20261129, true), `(()=>{const W=G.Walk,p=W.p,F=G.Fire,w=W.w; W.night=false; F.tap({x:-136,z:-537}); const f=F.list[0]; for(let i=0;i<30;i++) W.update(1/30); F.call('fire',f.ev,{name:'Anna'}); const k=F.park(f); p.fly=true; p.x=k.x-k.ux*8+k.uz*16; p.z=k.z-k.uz*8-k.ux*16; p.y=f.y+12; p.vy=0; p.yaw=Math.atan2(k.x-k.ux*12-p.x,k.z-k.uz*12-p.z); p.pitch=-.45; return F.list.length})()`, 'wait:9000', `(()=>{${PRE} const bark=w.B.bark, seen=new Set(); let n=0; - for(let s=23;s<=24.51;s+=.5) for(let a=-34;a<=34;a+=.5){ const X=Math.floor(k.x-k.ux*s+k.uz*a), Z=Math.floor(k.z-k.uz*s-k.ux*a), q=X+'_'+Z; if(seen.has(q)) continue; seen.add(q); const g=T.ground(X+.5,Z+.5,Math.floor(w.T.at(X,Z))+1); if(g==null) continue; for(let y=g;yc.call); return n+' '+bark+' len '+(e&&e.len)+' wid '+(e&&e.wid)})()`, 'wait:6000', 'G.Quality.lock=8; 1'], shots: [ { name: 'firefighters-jump-the-trunk', title: 'A fallen trunk three blocks high lies across the way to the fire: the firefighters jump onto it instead of standing in front of it', steps: [ diff --git a/tools/shots/157.mjs b/tools/shots/157.mjs index 3bd641cf7..ccb10080a 100644 --- a/tools/shots/157.mjs +++ b/tools/shots/157.mjs @@ -4,11 +4,11 @@ import { game, TOWN } from './lib.mjs'; // car(kind, x, z, yaw, seed): a vehicle on the street with the player at the wheel. go(n, thr, st): n frames with the joystick held. // cam(yaw, pitch): the third person view. sheet(list of [item, colours]): pictures of models side by side over the game; sheet() takes them away. const LIB = `window.row = (kinds, x0, z, dx, yaw, seed0) => { const T = G.Town, W = G.Walk; T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; W.night = false; - kinds.forEach((k, i) => { const x = x0 + i * dx, c = T.build(k, x, z, yaw, { solo: 1, seed: seed0 + i * 7919 }); if (!c) return; T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); window.GY = c.y; }); + kinds.forEach((k, i) => { const x = x0 + i * dx, c = T.build(k, x, z, yaw, { solo: 1, seed: seed0 + i * 7919 }); if (!c) return; T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); window.GY = c.y; }); return T.cars.length; }; window.look = (x, y, z, yaw, pitch) => { const W = G.Walk, p = W.p; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (W.tp) W.act('tp'); if (!p.fly) W.act('fly'); Object.assign(p, { x, y, z, vy: 0, yaw, pitch }); return 1; }; window.car = (kind, x, z, yaw, seed) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.night = false; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; - const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; window.go = (n, thr, st) => { const W = G.Walk; W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); W.joy = [0, 0]; return HC.v.toFixed(1); }; window.cam = (yaw, pitch) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); p.yaw = yaw; p.pitch = pitch; return 1; }; diff --git a/tools/shots/169.mjs b/tools/shots/169.mjs index e716a43ec..dbcb90719 100644 --- a/tools/shots/169.mjs +++ b/tools/shots/169.mjs @@ -3,7 +3,7 @@ import { game, TOWN } from './lib.mjs'; const set = js => `(()=>{ const W = G.Walk, p = W.p, F = G.Fp; ${js}; return 1 })()`; // a fixed look, so that the pictures do not depend on the random character of a fresh profile const LOOK = set(`G.Me.q = G.Me.fix({ b: 2, h: 1, f: 0, g: 0, t: 0, s: 0, o: 0, x: 0, c: ['#f2c9a0', '#5a3a22', '#e8604c', '#3a5fa8', '#f4f4f0', '#1b1b1f', '#d8443c', '#1b1b1f', '#feae34'] }); G.Me.apply(true); W.setZoom(0); W.night = false; p.pitch = 0; G.Build.blk = { m: 1, c: '#b8443c' }`); -const CAR = `(()=>{ const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; const c = T.build('car', -40, -13.5, Math.PI / 2, { solo: 1, seed: 900 }); T.cars.push(c); const g = T.ground(-40, -13.5, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: -37, y: c.y, z: -13.5, vy: 0, yaw: Math.PI / 2, pitch: -.1, ground: true }); G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = Math.PI / 2; p.pitch = -.3; return 1 })()`; +const CAR = `(()=>{ const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; const c = T.build('car', -40, -13.5, Math.PI / 2, { solo: 1, seed: 900 }); T.cars.push(c); const g = G.Ground.at(-40, -13.5, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: -37, y: c.y, z: -13.5, vy: 0, yaw: Math.PI / 2, pitch: -.1, ground: true }); G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = Math.PI / 2; p.pitch = -.3; return 1 })()`; export default { start: [...game({ ...TOWN, site: ['town'] }, 20261129), LOOK, 'wait:4000'], shots: [ diff --git a/tools/shots/176.mjs b/tools/shots/176.mjs index 812544e95..1a8be2c35 100644 --- a/tools/shots/176.mjs +++ b/tools/shots/176.mjs @@ -5,7 +5,7 @@ export default { start: [...game({ ...TOWN, site: ['town'] }, 20261129, true), 'wait:4000'], shots: [ { name: 'animals-run-from-a-player', title: 'Playing together: the animals are the same on every device, and the shy ones run from whichever player is the nearest', steps: ['G.Net.open(); 1', 'until:G.Net.role === "host"', 'G.Net.close(); 1', - `(()=>{ const N=G.Net,W=G.Walk,p=W.p,F=G.Fauna, ok=(x,z)=>{ const y=F.loaded(x,z)?F.drop(x,Math.floor(F.w.T.at(x,z))+8,z):null; return y!=null&&!F.water(x,y+1,z)&&!F.water(x,y,z)?y:null }; let M=null; for(let r=14;r<60&&!M;r+=4) for(let a=0;a<6.28&&!M;a+=.4){ const x=p.x+Math.cos(a)*r, z=p.z+Math.sin(a)*r; let n=0; for(let k=0;k<8;k++) if(ok(x+Math.cos(k*.8)*7,z+Math.sin(k*.8)*7)!=null) n++; if(n===8&&ok(x,z)!=null) M=[x,ok(x,z),z]; } if(!M) return 'no place'; window.MX=M; N.addPlayer({id:1,u:'U1',n:'Mila',z:'🐼',me:{h:1}}); const a=new Float32Array(9); a[1]=M[0]; a[2]=M[1]; a[3]=M[2]; N.players.get(1).to=a; N.ui(); p.fly=true; p.x=M[0]-13; p.z=M[2]+9; p.y=M[1]+7; p.yaw=Math.atan2(13,-9); p.pitch=-.35; return M.join() })()`, 'wait:6000', - `(()=>{ const F=G.Fauna,L=G.Lib.byId, it=L.rabbit||L.deer||L.chicken, out=[]; for(let i=0;i<6;i++){ const an=i*1.05, x=MX[0]+Math.cos(an)*6, z=MX[2]+Math.sin(an)*6, y=F.drop(x,MX[1]+6,z); if(y==null) continue; const c=F.make(it,x,y,z,an,null,false); c.wait=0; out.push(c.it.id); } return out.join() })()`, 'wait:2500'] }, + `(()=>{ const N=G.Net,W=G.Walk,p=W.p,F=G.Fauna, ok=(x,z)=>{ const y=F.loaded(x,z)?G.Ground.drop(x, z, Math.floor(F.w.T.at(x,z))+8, 14):null; return y!=null&&!F.water(x,y+1,z)&&!F.water(x,y,z)?y:null }; let M=null; for(let r=14;r<60&&!M;r+=4) for(let a=0;a<6.28&&!M;a+=.4){ const x=p.x+Math.cos(a)*r, z=p.z+Math.sin(a)*r; let n=0; for(let k=0;k<8;k++) if(ok(x+Math.cos(k*.8)*7,z+Math.sin(k*.8)*7)!=null) n++; if(n===8&&ok(x,z)!=null) M=[x,ok(x,z),z]; } if(!M) return 'no place'; window.MX=M; N.addPlayer({id:1,u:'U1',n:'Mila',z:'🐼',me:{h:1}}); const a=new Float32Array(9); a[1]=M[0]; a[2]=M[1]; a[3]=M[2]; N.players.get(1).to=a; N.ui(); p.fly=true; p.x=M[0]-13; p.z=M[2]+9; p.y=M[1]+7; p.yaw=Math.atan2(13,-9); p.pitch=-.35; return M.join() })()`, 'wait:6000', + `(()=>{ const F=G.Fauna,L=G.Lib.byId, it=L.rabbit||L.deer||L.chicken, out=[]; for(let i=0;i<6;i++){ const an=i*1.05, x=MX[0]+Math.cos(an)*6, z=MX[2]+Math.sin(an)*6, y=G.Ground.drop(x, z, MX[1]+6, 14); if(y==null) continue; const c=F.make(it,x,y,z,an,null,false); c.wait=0; out.push(c.it.id); } return out.join() })()`, 'wait:2500'] }, ], }; diff --git a/tools/shots/255.mjs b/tools/shots/255.mjs index 7184ba9fc..94be6a5b4 100644 --- a/tools/shots/255.mjs +++ b/tools/shots/255.mjs @@ -16,7 +16,7 @@ export default { start: [...game({ ...TOWN, site: ['town'] }, 20261129, true), LIB, day, 'wait:4000'], shots: [ { name: 'chase-car', title: 'You drive off: the patrol car follows you along the roads and across the fields, and pulls up right behind you', steps: [ - '(()=>{ const W = G.Walk, L = G.Law; L.reset(W.w); const [gx, gz] = L.gate(), c = G.Drive.own("car", null, gx, L.ground(gx, gz), gz, Math.PI / 2, 0); G.Town.place(c, 0); G.Drive.enter({ u: c, n: 0, now: 1 }); window.HC = c; L.wanted(); L.next = 1; return 1 })()', + '(()=>{ const W = G.Walk, L = G.Law; L.reset(W.w); const [gx, gz] = L.gate(), c = G.Drive.own("car", null, gx, G.Ground.road(gx, gz), gz, Math.PI / 2, 0); G.Town.place(c, 0); G.Drive.enter({ u: c, n: 0, now: 1 }); window.HC = c; L.wanted(); L.next = 1; return 1 })()', '(()=>{ const W = G.Walk, L = G.Law, near = () => L.cars.find(q => !q.hid && q.lg && q.lg.k === "chase" && Math.hypot(q.x - HC.x, q.z - HC.z) < 45); for (let i = 0; i < 150 * 30 && !near(); i++) { W.joy = [0, i < 40 * 30 ? -.7 : 0]; W.update(1 / 30); } W.joy = [0, 0]; return !!near() })()', '(()=>{ const L = G.Law, q = L.cars.filter(q => !q.hid).sort((a, b) => Math.hypot(a.x - HC.x, a.z - HC.z) - Math.hypot(b.x - HC.x, b.z - HC.z))[0]; L.hold = 1; off(); return shoot((q.x + HC.x) / 2, HC.y + 2, (q.z + HC.z) / 2, 42, side(HC, q), 15) })()', LOAD, 'wait:12000'] }, { name: 'police-station', title: 'Caught: the patrol car takes you to the police station of the nearest town along the roads', steps: [ @@ -26,7 +26,7 @@ export default { 'back()', '(()=>{ const W = G.Walk, L = G.Law, w = W.w, T = w.T, p = W.p; off(); L.reset(w); let at = null; for (let r = 20; r < 900 && !at; r += 10) for (let a = 0; a < 64; a++) { const x = Math.round(40 + Math.sin(a / 64 * 6.283) * r), z = Math.round(-40 + Math.cos(a / 64 * 6.283) * r); if (T.wl - T.at(x, z) > 6) { at = [x, z]; break; } } if (!at) return 0; p.fly = false; p.x = at[0] + .5; p.z = at[1] + .5; T.at(p.x, p.z); p.y = T.wl - 2; p.vy = 0; TK(1); L.wanted(); L.next = 1; return TK(90, () => { const b = L.cars.find(c => c.boat); return b && Math.hypot(b.x - p.x, b.z - p.z) < 60; }) })()', '(()=>{ const p = G.Walk.p, b = G.Law.cars.find(c => c.boat); return shoot((b.x + p.x) / 2, b.y + 2, (b.z + p.z) / 2, 46, side(p, b), 16) })()', LOAD, 'wait:12000'] }, { name: 'chase-heli', title: 'You fly away on a dragon: a police helicopter takes off from the station and keeps close, off to your side', steps: [ - 'back()', '(()=>{ const W = G.Walk, L = G.Law, p = W.p; off(); L.reset(W.w); p.fly = false; p.x = 60; p.z = -3; p.y = L.ground(60, -3) + 1; TK(1); const b = G.Fauna.make(G.Lib.byId.dragon, p.x + 2, p.y + 12, p.z + 9, 2.4), u = G.Drive.mount(b); G.Drive.enter({ u, n: 0, now: 1 }); TK(1); W.keys = { KeyW: true }; p.pitch = .5; TK(4); L.wanted(); L.next = 1; for (let i = 0; i < 40 * 30; i++) { W.keys = { KeyW: true }; p.yaw += .004; p.pitch = p.y - L.ground(p.x, p.z) < 60 ? .15 : -.05; W.update(1 / 30); } return L.air.length })()', + 'back()', '(()=>{ const W = G.Walk, L = G.Law, p = W.p; off(); L.reset(W.w); p.fly = false; p.x = 60; p.z = -3; p.y = G.Ground.road(60, -3) + 1; TK(1); const b = G.Fauna.make(G.Lib.byId.dragon, p.x + 2, p.y + 12, p.z + 9, 2.4), u = G.Drive.mount(b); G.Drive.enter({ u, n: 0, now: 1 }); TK(1); W.keys = { KeyW: true }; p.pitch = .5; TK(4); L.wanted(); L.next = 1; for (let i = 0; i < 40 * 30; i++) { W.keys = { KeyW: true }; p.yaw += .004; p.pitch = p.y - G.Ground.road(p.x, p.z) < 60 ? .15 : -.05; W.update(1 / 30); } return L.air.length })()', // the dragon and its rider stay in the air as pictures (copies among the police bodies); the real dragon, let go, is put away '(()=>{ const W = G.Walk, L = G.Law, p = W.p, u = W.ride, h = L.air[0]; if (!u || !h) return 0; L.hold = 1; W.keys = {}; L.units.push(Object.assign({}, u)); if (W.me) L.units.push(Object.assign({}, W.me)); window.P0 = { x: p.x, y: p.y, z: p.z, yaw: p.yaw }; off(); const F = G.Fauna.list, i = F.findIndex(b => b.it.id === "dragon" && Math.hypot(b.x - u.x, b.z - u.z) < 40); if (i >= 0) F.splice(i, 1); return shoot((u.x + h.x) / 2, (u.y + h.y) / 2, (u.z + h.z) / 2, 80, side(u, h), 12) })()', LOAD, 'wait:15000'] }, ], diff --git a/tools/shots/283.mjs b/tools/shots/283.mjs index 9521b7943..45556eda4 100644 --- a/tools/shots/283.mjs +++ b/tools/shots/283.mjs @@ -6,7 +6,7 @@ const LIB = S157.start.find(s => s.startsWith('window.row')); const LOCK = `window.lock = a => { for (const c of G.Town.cars) { c.wa = a; G.Town.place(c, 0); } return G.Town.cars.length; }; 1`; // tow(kind, seed): a vehicle with a trailer behind, the player at the wheel (seeds are tried until the trailer comes) const TOW = `window.tow = (kind, x, z, yaw) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.night = false; T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; - let c = null; for (let s = 1; s < 400 && !(c && c.units.length > 1); s++) c = T.build(kind, x, z, yaw, { seed: s * 7919 }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + let c = null; for (let s = 1; s < 400 && !(c && c.units.length > 1); s++) c = T.build(kind, x, z, yaw, { seed: s * 7919 }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.units.length; }; 1`.replace(/\n/g, ' '); export default { start: [...game({ ...TOWN, site: ['town'] }, 20261129), LIB, LOCK, TOW, '(()=>{ G.Quality.lock = 7; return 1 })()', 'wait:8000'], diff --git a/tools/shots/292.mjs b/tools/shots/292.mjs index 0ad17b954..db99fbbe3 100644 --- a/tools/shots/292.mjs +++ b/tools/shots/292.mjs @@ -14,14 +14,14 @@ export default { shots: [ { name: 'push-car', title: 'A car stands in the way of a patrol car: it slows down, stops, and after a second pushes the car aside, the way the player does', steps: [ // a parked car on the home street and a patrol car coming along it - `(()=>{ const W = G.Walk, L = G.Law, w = W.w; L.reset(w); L.wanted(); L.next = 1e9; const [gx, gz] = L.gate(), y = L.ground(gx, gz); + `(()=>{ const W = G.Walk, L = G.Law, w = W.w; L.reset(w); L.wanted(); L.next = 1e9; const [gx, gz] = L.gate(), y = G.Ground.road(gx, gz); const k = G.Drive.own('car', null, gx + 40, y, gz, Math.PI / 2, 0); G.Town.place(k, 0); window.PK = k; window.PK0 = [k.x, k.z]; const c = L.make('car_police', gx - 40, gz, Math.PI / 2); c.y = y; G.Town.place(c, 0); G.Town.cars.push(c); L.cars.push(c); window.PC = c; c.lg = { k: 'leave', l: G.Navi.line([[gx - 40, gz], [gx + 160, gz]]), s: 0, V: 40 }; c.gen = 1; return 1 })()`, 'TK(12, () => Math.hypot(PK.x - PK0[0], PK.z - PK0[1]) > 3)', '(()=>{ const c = PC, k = PK; return shoot((c.x + k.x) / 2, c.y + 2, (c.z + k.z) / 2, 38, Math.atan2(k.x - c.x, k.z - c.z) + 1.9, 18) })()', LOAD, 'wait:12000'] }, { name: 'ride-full', title: 'Caught: the ride to the station is driven the whole way, through the town, with no black moment', steps: [ - `(()=>{ back(); const W = G.Walk, L = G.Law, w = W.w; off(); L.reset(w); const p = W.p; p.fly = false; const [gx, gz] = L.gate(); p.x = gx; p.z = gz + 14; p.y = L.ground(p.x, p.z) + 1; TK(1); L.wanted(); L.next = 1e9; L.send(); return 1 })()`, + `(()=>{ back(); const W = G.Walk, L = G.Law, w = W.w; off(); L.reset(w); const p = W.p; p.fly = false; const [gx, gz] = L.gate(); p.x = gx; p.z = gz + 14; p.y = G.Ground.road(p.x, p.z) + 1; TK(1); L.wanted(); L.next = 1e9; L.send(); return 1 })()`, 'until:(()=>{ G.Law.TK = TK(3, () => G.Law.cops.length || G.Law.cars.some(c => c.lg && c.lg.done)); const L = G.Law; if (!L.cops.length && L.cars[0] && L.cars[0].lg && L.cars[0].lg.done) L.out(L.cars[0]); return L.cops.length > 0 })()', '(()=>{ const L = G.Law; L.arrest(L.cops[0]); return 1 })()', // a third of the way to the station, in steps with real time between them for the land to load on the way diff --git a/tools/shots/294.mjs b/tools/shots/294.mjs index b08b7728e..2fc1f6fca 100644 --- a/tools/shots/294.mjs +++ b/tools/shots/294.mjs @@ -5,7 +5,7 @@ import { game, TOWN, LOAD } from './lib.mjs'; // spot(): a place near home where a car stands free and can roll ahead → [x, y, z, yaw] const SETUP = `(()=>{ const N = G.Net, D = G.Drive, T = G.Town, W = G.Walk, p = W.p; W.night = false; G.Fp && (G.Fp.on = false); N.role = 'host'; N.pid = 0; - window.spot = (from, skip) => { for (let r = 10; r < 120; r += 3) for (let k = 0; k < 16; k++) { const a = k / 16 * Math.PI * 2, x = from[0] + Math.cos(a) * r, z = from[1] + Math.sin(a) * r, y = T.ground(x, z, p.y + 2); if (y == null || skip && Math.hypot(x - skip[0], z - skip[2]) < 16) continue; + window.spot = (from, skip) => { for (let r = 10; r < 120; r += 3) for (let k = 0; k < 16; k++) { const a = k / 16 * Math.PI * 2, x = from[0] + Math.cos(a) * r, z = from[1] + Math.sin(a) * r, y = G.Ground.at(x, z, p.y + 2); if (y == null || skip && Math.hypot(x - skip[0], z - skip[2]) < 16) continue; const c = D.own('car', null, x, y, z, a, 0); if (!c) continue; const ok = D.worldFree(c, x, z, a, 1.4) && [8, 16].every(d => D.worldFree(c, x + Math.sin(a) * d, z + Math.cos(a) * d, a, 3)); T.cars.splice(T.cars.indexOf(c), 1); if (ok) return [x, y, z, a]; } return null; }; window.run = s => { for (let i = 0; i < 60 * s; i++) { W.update(1 / 60); N.tick(1 / 60); } return 1; }; return 1 })()`.replace(/\n/g, ' '); // I drive my car, Mila (player 5) sits next to me; the third-person camera looks at the car from her side diff --git a/tools/shots/314.mjs b/tools/shots/314.mjs index 3faf8463c..a8b480e90 100644 --- a/tools/shots/314.mjs +++ b/tools/shots/314.mjs @@ -12,7 +12,7 @@ export default { shots: [ { name: 'ride-after-update', title: 'The game was updated during the ride home: the player is still on the back seat of the police car, and it drives on', steps: [ // what the new build reads back (Ent 'law', the player's own rows), restored once the town is there - `(()=>{ const W = G.Walk, L = G.Law, w = W.w, K = G.Ent.kinds.law; off(); L.reset(w); const p = W.p; p.fly = false; const [gx, gz] = L.gate(); p.x = gx + 260; p.z = gz + 30; p.y = L.ground(p.x, p.z) + 1; TK(1); + `(()=>{ const W = G.Walk, L = G.Law, w = W.w, K = G.Ent.kinds.law; off(); L.reset(w); const p = W.p; p.fly = false; const [gx, gz] = L.gate(); p.x = gx + 260; p.z = gz + 30; p.y = G.Ground.road(p.x, p.z) + 1; TK(1); K.load([{ s: 5 }], 2, w); return 1 })()`, 'until:(()=>{ TK(.1); return !G.Law.pend })()', 'until:(()=>{ TK(2); const c = G.Law.car; return c && c.lg && c.lg.l && c.lg.s > 60 })()', diff --git a/tools/shots/318.mjs b/tools/shots/318.mjs index 82c37663d..edc4e705e 100644 --- a/tools/shots/318.mjs +++ b/tools/shots/318.mjs @@ -2,7 +2,7 @@ import { game, TOWN } from './lib.mjs'; // car(kind, x, z, yaw, seed): a vehicle on the street with the player at the wheel; go(n): n frames with the gas held; cam(yaw, pitch): third person const LIB = `window.car = (kind, x, z, yaw, seed) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.night = false; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; - const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; window.go = (n, thr, st) => { const W = G.Walk; W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); W.joy = [0, 0]; return HC.v.toFixed(1); }; window.cam = (yaw, pitch) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); p.yaw = yaw; p.pitch = pitch; return 1; }; 1`.replace(/\n/g, ' '); diff --git a/tools/shots/331.mjs b/tools/shots/331.mjs index 9d85c3016..14dff4afc 100644 --- a/tools/shots/331.mjs +++ b/tools/shots/331.mjs @@ -3,7 +3,7 @@ // newcomer (player 5) is placed where spawnFor puts a joining player. The real join between two browsers is tools/pax.test.mjs. import { game, TOWN, LOAD } from './lib.mjs'; const SETUP = `(()=>{ const N = G.Net, D = G.Drive, T = G.Town, W = G.Walk, p = W.p; W.night = false; G.Fp && (G.Fp.on = false); N.role = 'host'; N.pid = 0; - window.spot = from => { for (let r = 10; r < 120; r += 3) for (let k = 0; k < 16; k++) { const a = k / 16 * Math.PI * 2, x = from[0] + Math.cos(a) * r, z = from[1] + Math.sin(a) * r, y = T.ground(x, z, p.y + 2); if (y == null) continue; + window.spot = from => { for (let r = 10; r < 120; r += 3) for (let k = 0; k < 16; k++) { const a = k / 16 * Math.PI * 2, x = from[0] + Math.cos(a) * r, z = from[1] + Math.sin(a) * r, y = G.Ground.at(x, z, p.y + 2); if (y == null) continue; const c = D.own('car', null, x, y, z, a, 0); if (!c) continue; const ok = D.worldFree(c, x, z, a, 1.4) && [8, 16].every(d => D.worldFree(c, x + Math.sin(a) * d, z + Math.cos(a) * d, a, 3)); T.cars.splice(T.cars.indexOf(c), 1); if (ok) return [x, y, z, a]; } return null; }; window.run = s => { for (let i = 0; i < 60 * s; i++) { W.update(1 / 60); N.tick(1 / 60); } return 1; }; return 1 })()`.replace(/\n/g, ' '); // I sit in my car; Mila joins: the spot the owner gives her is on the ground beside the car, and she stands there on foot diff --git a/tools/shots/334.mjs b/tools/shots/334.mjs index 0918a101b..12356d6f1 100644 --- a/tools/shots/334.mjs +++ b/tools/shots/334.mjs @@ -8,7 +8,7 @@ const LIB = `window.step = n => { for (let i = 0; i < n; i++) { G.Walk.update(1 window.oasis = () => { const W = G.Walk, p = W.p, T = W.w.T, L = T.lairs(p.x - 400, p.z - 400, p.x + 400, p.z + 400, []).filter(l => l.kind === 'oasis'); L.sort((a, b) => Math.hypot(a.x - p.x, a.z - p.z) - Math.hypot(b.x - p.x, b.z - p.z)); window.OA = L[0]; W.night = false; G.Fp && (G.Fp.on = false); p.fly = true; Object.assign(p, { x: OA.x - 24, z: OA.z - 24, y: OA.y + 16, vy: 0 }); p.yaw = Math.PI / 4; p.pitch = -.42; return L.length; }; window.camel = () => { const W = G.Walk, p = W.p, F = G.Fauna, c = F.list.filter(c => c.it.id === 'camel' && c.home === OA)[0] || F.list.find(c => c.it.id === 'camel'); window.CM = c; - const x = OA.x - 26, z = OA.z - 30, y = F.drop(x, OA.y + 14, z); Object.assign(c, { x, y, z, tx: x, ty: y, tz: z, hx: x, hz: z, go: false, wait: 1e9, kn: 0, yaw: Math.PI / 2 + .3 }); + const x = OA.x - 26, z = OA.z - 30, y = G.Ground.drop(x, z, OA.y + 14, 14); Object.assign(c, { x, y, z, tx: x, ty: y, tz: z, hx: x, hz: z, go: false, wait: 1e9, kn: 0, yaw: Math.PI / 2 + .3 }); p.fly = false; Object.assign(p, { x: c.x + Math.cos(c.yaw) * 5, z: c.z - Math.sin(c.yaw) * 5, y: c.y + .3, vy: 0 }); p.yaw = Math.atan2(c.x - p.x, c.z - p.z) - .35; p.pitch = -.12; return !!c; }; window.hc = () => G.Walk.ride && G.Walk.ride.car; window.ride = (n, st) => { const W = G.Walk; W.joy = [st || 0, -1]; step(n); W.joy = [0, 0]; return 1; }; @@ -17,7 +17,7 @@ window.side = (a, pt, z) => { const W = G.Walk, p = W.p, c = hc() || CM; W.tp = window.mid = f => { G.Walk.act('ride'); let n = 0; while (G.Drive.tr && G.Drive.tr.t < f * G.Drive.tr.T && n++ < 600) step(1); return 1; }; window.hold = on => { clearInterval(window.hI); if (!on) return 1; const T = G.Drive.tr, t = T.t; window.hI = setInterval(() => { T.t = t - 1 / 60; }, 2); return 1; }; window.mila = n => { const N = G.Net, W = G.Walk, p = W.p; if (!N.players.get(6)) { N.role = 'host'; N.pid = 0; N.addPlayer({ id: 6, n: 'Mila', u: 'mila', z: '🦊', me: G.Me.random(), v: [['camel', null, 37, [1]]] }); window.MX = { x: p.x + 4, z: p.z + 16, yaw: Math.PI / 2 }; } - const pl = N.players.get(6), F = G.Fauna; for (let i = 0; i < n; i++) { MX.x += Math.sin(MX.yaw); MX.z += Math.cos(MX.yaw); const y = F.drop(MX.x, p.y + 12, MX.z) || p.y, a = new Float32Array(14); + const pl = N.players.get(6), F = G.Fauna; for (let i = 0; i < n; i++) { MX.x += Math.sin(MX.yaw); MX.z += Math.cos(MX.yaw); const y = G.Ground.drop(MX.x, MX.z, p.y + 12, 14) || p.y, a = new Float32Array(14); a[1] = MX.x; a[2] = y + 9; a[3] = MX.z; a[4] = MX.yaw; a[6] = 0; a[7] = 1 << 3 | 64; a[8] = 1; a[9] = MX.x; a[10] = y; a[11] = MX.z; a[12] = MX.yaw; pl.vt = performance.now() - 1000 / 30; N.got(pl, a); step(2); } return pl.vn; }; 1`.replace(/\n/g, ' '); const MOUNT = `(()=>{ G.Walk.act('ride'); return 1 })()`; export default { @@ -31,6 +31,6 @@ export default { { name: 'camel-sway-behind', title: '🐪 From behind: the roll of the pace', steps: ['pin(0)', 'ride(12)', 'pin(1)', 'side(3.14, -.08)', 'wait:15000'] }, { name: 'camel-first-person', title: '👀 In first person the horizon sways with the saddle, the neck nods ahead', steps: ['pin(0)', `(()=>{ G.Walk.tp = 0; return 1 })()`, 'ride(30)', 'pin(1)', `(()=>{ G.Walk.p.yaw = hc().yaw; G.Walk.p.pitch = -.12; return 1 })()`, 'wait:15000'] }, { name: 'camel-from-above', title: '🎮 Riding a camel in play from above on the big map', steps: ['pin(0)', `(()=>{ const B = G.BigMap; if (!B.on) G.Walk.act('bmplay'); else if (!B.play) B.setPlay(true); return 1 })()`, 'ride(60, .3)', 'wait:25000'] }, - { name: 'camel-friend', title: '👥 Playing together: a friend rides past on a camel, swaying and in the saddle', steps: [`(()=>{ const B = G.BigMap; if (B.on) B.close(); return 1 })()`, `(()=>{ hc().v = 0; G.Drive.exit(true); return 1 })()`, 'step(20)', `(()=>{ const p = G.Walk.p; p.x -= 8; p.z -= 14; p.y = G.Fauna.drop(p.x, p.y + 12, p.z) || p.y; return 1 })()`, 'step(10)', 'mila(40)', `(()=>{ const W = G.Walk, p = W.p; W.tp = 0; p.yaw = Math.atan2(MX.x - p.x, MX.z - p.z) + .1; p.pitch = -.05; return 1 })()`, 'mila(1)', 'wait:15000'] }, + { name: 'camel-friend', title: '👥 Playing together: a friend rides past on a camel, swaying and in the saddle', steps: [`(()=>{ const B = G.BigMap; if (B.on) B.close(); return 1 })()`, `(()=>{ hc().v = 0; G.Drive.exit(true); return 1 })()`, 'step(20)', `(()=>{ const p = G.Walk.p; p.x -= 8; p.z -= 14; p.y = G.Ground.drop(p.x, p.z, p.y + 12, 14) || p.y; return 1 })()`, 'step(10)', 'mila(40)', `(()=>{ const W = G.Walk, p = W.p; W.tp = 0; p.yaw = Math.atan2(MX.x - p.x, MX.z - p.z) + .1; p.pitch = -.05; return 1 })()`, 'mila(1)', 'wait:15000'] }, ], }; diff --git a/tools/shots/350.mjs b/tools/shots/350.mjs index ab39a10a1..9d9652019 100644 --- a/tools/shots/350.mjs +++ b/tools/shots/350.mjs @@ -2,7 +2,7 @@ import { game, TOWN } from './lib.mjs'; // car(kind, x, z, yaw, seed): a vehicle on the street with the player at the wheel; go(n): n frames with the gas held; cam(yaw, pitch): third person const LIB = `window.car = (kind, x, z, yaw, seed) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.night = false; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; - const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; window.go = (n, thr, st) => { const W = G.Walk; W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); W.joy = [0, 0]; return HC.v.toFixed(1); }; window.cam = (yaw, pitch) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); p.yaw = yaw; p.pitch = pitch; return 1; }; 1`.replace(/\n/g, ' '); diff --git a/tools/shots/358.mjs b/tools/shots/358.mjs index 496057525..c8ce389da 100644 --- a/tools/shots/358.mjs +++ b/tools/shots/358.mjs @@ -18,6 +18,6 @@ export default { start: [...game(TOWN, 20261139, true), LIB, day, 'wait:4000'], shots: [ { name: 'taxi-lamp', title: 'A street lamp (a modern one, the "cross") put on the street right in front of the taxi, a little off the middle: the taxi sees the post one cell thin and stops short of it, its nose clear of the post (before, the post passed through the car)', steps: [ - '(()=>{ const [x, z] = TOWNAT(); CALL(x, z); RUN(() => G.Taxi.st === 2, 120); TP(0); BOARD(); RUN(() => G.Taxi.car && G.Taxi.car.lg && G.Taxi.car.lg.s > 150 && G.Taxi.car.v > 10, 120); const c = G.Taxi.car, L = c.lg, w = G.Walk.w, a = G.Navi.at(L.l, L.s + 70), nx = Math.cos(a.yaw), nz = -Math.sin(a.yaw), X = Math.floor(a.x + nx * 1.5), Z = Math.floor(a.z + nz * 1.5), y0 = G.Law.ground(X + .5, Z + .5, c.y + 4), k = w.bid(G.MAT.metal, "#2b2d33"), lit = w.bid(G.MAT.glow, "#ffe9a0"), h = y0 + 22; for (let y = y0; y <= h; y++) w.set(X, y, Z, k); for (let d = -2; d <= 2; d++) w.set(X + d, h + 1, Z, k); for (const d of [-2, -1, 1, 2]) w.set(X + d, h, Z, lit); window.LAMP = [X + .5, Z + .5]; RUN(() => Math.hypot(c.x - LAMP[0], c.z - LAMP[1]) < 13 || G.Taxi.st !== 3, 60); return AIM(Math.atan2(LAMP[0] - c.x, LAMP[1] - c.z) + .5, -.35, 2) })()', LOAD, 'wait:20000'] }, + '(()=>{ const [x, z] = TOWNAT(); CALL(x, z); RUN(() => G.Taxi.st === 2, 120); TP(0); BOARD(); RUN(() => G.Taxi.car && G.Taxi.car.lg && G.Taxi.car.lg.s > 150 && G.Taxi.car.v > 10, 120); const c = G.Taxi.car, L = c.lg, w = G.Walk.w, a = G.Navi.at(L.l, L.s + 70), nx = Math.cos(a.yaw), nz = -Math.sin(a.yaw), X = Math.floor(a.x + nx * 1.5), Z = Math.floor(a.z + nz * 1.5), y0 = G.Ground.road(X + .5, Z + .5, c.y + 4), k = w.bid(G.MAT.metal, "#2b2d33"), lit = w.bid(G.MAT.glow, "#ffe9a0"), h = y0 + 22; for (let y = y0; y <= h; y++) w.set(X, y, Z, k); for (let d = -2; d <= 2; d++) w.set(X + d, h + 1, Z, k); for (const d of [-2, -1, 1, 2]) w.set(X + d, h, Z, lit); window.LAMP = [X + .5, Z + .5]; RUN(() => Math.hypot(c.x - LAMP[0], c.z - LAMP[1]) < 13 || G.Taxi.st !== 3, 60); return AIM(Math.atan2(LAMP[0] - c.x, LAMP[1] - c.z) + .5, -.35, 2) })()', LOAD, 'wait:20000'] }, ], }; diff --git a/tools/shots/360.mjs b/tools/shots/360.mjs index a0d2d2ed9..e7573414d 100644 --- a/tools/shots/360.mjs +++ b/tools/shots/360.mjs @@ -4,7 +4,7 @@ import { game, TOWN } from './lib.mjs'; // cam(dy, pitch): the third person view turned dy from the heading of the scooter. off(): the player gets off and the world runs 2 s. const LIB = `window.scoot = (want, x, z, yaw) => { const W = G.Walk, p = W.p, T = G.Town; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (p.fly) W.act('fly'); W.night = false; T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; let c = null; for (let s = 1; s < 200 && !c; s++) { const q = T.build('scoot', x, z, yaw, { solo: 1, seed: s * 7919 }); if (q && q.id === want) c = q; } - T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 2, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0 }); G.Drive.end(); return c.id; }; window.go = (n, thr, st) => { const W = G.Walk; W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); W.joy = [0, 0]; return HC.v.toFixed(1); }; window.cam = (dy, pitch) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); p.yaw = HC.yaw + dy; p.pitch = pitch; return 1; }; diff --git a/tools/shots/367.mjs b/tools/shots/367.mjs index 702be65e4..c1966f6fc 100644 --- a/tools/shots/367.mjs +++ b/tools/shots/367.mjs @@ -6,7 +6,7 @@ import { game, TOWN } from './lib.mjs'; // car(kind, body, x, z, yaw): a car of that body with the player at the wheel; go(n, thr, st): n frames with the joystick held; // tip(n): the joystick full to the side with the throttle off until the car lifts its wheels; cam(yaw, pitch): the third person view. // sheet(list of [item, colours]): pictures of models side by side over the game; sheet() takes them away. -const LIB = `window.park = (kinds, x0, z, dx, yaw, seed0) => { const T = G.Town, W = G.Walk, Y = W.w.meta.spawn.y + 2, gr = (x, z) => T.ground(x, z, Y), g0 = gr(x0, z); let x = x0; T.carT = 1e9; T.routeT = 1e9; W.night = false; +const LIB = `window.park = (kinds, x0, z, dx, yaw, seed0) => { const T = G.Town, W = G.Walk, Y = W.w.meta.spawn.y + 2, gr = (x, z) => G.Ground.at(x, z, Y), g0 = gr(x0, z); let x = x0; T.carT = 1e9; T.routeT = 1e9; W.night = false; kinds.forEach((k, i) => { for (let t = 0; t < 60 && ![-11, -5, 0, 5, 11].every(d => [-6, 0, 6].every(e => gr(x + d, z + e) === g0)); t++) x += 2; const c = T.build(k, x, z, yaw, { solo: 1, seed: seed0 + i * 7919 }); if (!c) return; T.cars.push(c); c.y = g0; c.mode = 'park'; c.v = 0; T.place(c, 0); window.GY = c.y; x += dx; }); return T.cars.length; }; @@ -14,7 +14,7 @@ window.view = (tx, tz, ox, oy, oz) => look(tx + ox, GY + oy, tz + oz, Math.atan2 window.look = (x, y, z, yaw, pitch) => { const W = G.Walk, p = W.p; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (W.tp) W.act('tp'); if (!p.fly) W.act('fly'); Object.assign(p, { x, y, z, vy: 0, yaw, pitch }); return 1; }; window.seedFor = (k, b) => { for (let s = 1; s < 20000; s++) if (G.CAR.look(k, (Math.imul(s, 2654435761) >>> 9) % 40)[1] === b) return s; return 1; }; window.car = (kind, b, x, z, yaw) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.night = false; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; - const c = T.build(kind, x, z, yaw, { solo: 1, seed: seedFor(kind, b) }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed: seedFor(kind, b) }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; window.go = (n, thr, st) => { const W = G.Walk; W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); W.joy = [0, 0]; return HC.v.toFixed(1); }; window.tip = (n, to) => { const W = G.Walk; W.joy = [1, 0]; for (let i = 0; i < n && (HC.tp || 0) < to; i++) W.update(1 / 60); return (HC.tp || 0).toFixed(2); }; diff --git a/tools/shots/369.mjs b/tools/shots/369.mjs index 68073fdcb..083abbc8f 100644 --- a/tools/shots/369.mjs +++ b/tools/shots/369.mjs @@ -6,15 +6,15 @@ import { game, TOWN } from './lib.mjs'; // the camera flies there. car(kind, x, z, yaw, seed): a vehicle on the street with the player at the wheel. go(n, thr, st): n frames with the // joystick held. drake(x, z, yaw): the player in the saddle of a dragon. cam(yaw, pitch, zoom): the third person view. fp(): back to the first person view. const LIB = `G.Fp.on = true; window.row = (kinds, x0, z, dx, yaw, seed0, col) => { const T = G.Town, W = G.Walk; T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; W.night = false; - kinds.forEach((k, i) => { const x = x0 + i * dx, c = T.build(k, x, z, yaw, { solo: 1, seed: seed0 + i * 7919, col }); if (!c) return; T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); window.GY = c.y; }); + kinds.forEach((k, i) => { const x = x0 + i * dx, c = T.build(k, x, z, yaw, { solo: 1, seed: seed0 + i * 7919, col }); if (!c) return; T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); window.GY = c.y; }); return T.cars.length; }; window.steer = k => { for (const c of G.Town.cars) { c.wa = -k * G.Vcls.get(c).sa; c.steer = k; c.wk = 1; G.Town.place(c, 0); } return 1; }; window.look = (x, y, z, yaw, pitch) => { const W = G.Walk, p = W.p; G.Fp.on = false; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (W.tp) W.act('tp'); if (!p.fly) W.act('fly'); Object.assign(p, { x, y, z, vy: 0, yaw, pitch }); return 1; }; window.car = (kind, x, z, yaw, seed) => { const W = G.Walk, p = W.p, T = G.Town; G.Fp.on = true; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.tpD = 0; W.night = false; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; - const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; window.drake = (x, z, yaw) => { const W = G.Walk, p = W.p, T = G.Town; G.Fp.on = true; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.tpD = 0; W.night = false; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.cars.length = 0; - const g = T.ground(x, z, W.w.meta.spawn.y + 2), y = g == null ? Math.floor(W.w.meta.spawn.y) : g, u = G.Drive.dragon(x, y, z, yaw, 1); Object.assign(p, { x: x + 4, y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = u; G.Drive.enter({ u, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return !!u; }; + const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2), y = g == null ? Math.floor(W.w.meta.spawn.y) : g, u = G.Drive.dragon(x, y, z, yaw, 1); Object.assign(p, { x: x + 4, y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = u; G.Drive.enter({ u, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return !!u; }; window.go = (n, thr, st) => { const W = G.Walk; W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); W.joy = [0, 0]; return HC.v.toFixed(1); }; window.cam = (yaw, pitch, zoom) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); W.tpZ = zoom || 1; p.yaw = yaw; p.pitch = pitch; return 1; }; window.fp = pitch => { const W = G.Walk; if (W.tp) W.act('tp'); W.tpD = 0; W.p.pitch = pitch; return 1; }; 1`.replace(/\n/g, ' '); diff --git a/tools/shots/372.mjs b/tools/shots/372.mjs index 4a0c6ed61..9117bbd8c 100644 --- a/tools/shots/372.mjs +++ b/tools/shots/372.mjs @@ -4,14 +4,14 @@ import { game, TOWN } from './lib.mjs'; // car(kind, x, z, yaw, seed): a vehicle on the street with the player at the wheel; go(n, thr, st): n frames with the pedals and the wheel; // cam(yaw, pitch, zoom): third person around the car; night(h): the clock at hour h (21.5 = after dusk), the sky settled at once const LIB = `window.car = (kind, x, z, yaw, seed) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.rdN = 1e9; T.cars.length = 0; - const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; window.go = (n, thr, st) => { const W = G.Walk; G.Drive.tank = 1, W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); G.Drive.tank = 1, W.joy = [0, 0]; return HC.v.toFixed(1) + ' lt ' + HC.lt; }; window.hold = (n, thr, st) => { const W = G.Walk; G.Drive.tank = 1, W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); return HC.v.toFixed(1) + ' lt ' + HC.lt; }; window.cam = (yaw, pitch, z) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); p.yaw = yaw; p.pitch = pitch; if (z != null) W.setZoom(z); return 1; }; window.eye = (x, y, z, yaw, pitch) => { const W = G.Walk, p = W.p; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (W.tp) W.act('tp'); if (!p.fly) W.act('fly'); Object.assign(p, { x, y, z, vy: 0, yaw, pitch }); return 1; }; window.night = h => { const W = G.Walk; W.dayT = h < 21 && h >= 7 ? (h - 7) / 14 * 1080 : 1080 + ((h - 21 + 24) % 24) / 10 * 360; G.Life.h = h; G.Sky.t = null; G.Sky.tick(0, W.dayT); return G.Render.day.toFixed(2); }; -window.other = (kind, x, z, yaw, seed, mode) => { const T = G.Town, c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, G.Walk.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(G.Walk.w.meta.spawn.y) : g; c.mode = mode || 'park'; c.v = 0; T.place(c, 0); return c; }; 1`.replace(/\n/g, ' '); +window.other = (kind, x, z, yaw, seed, mode) => { const T = G.Town, c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, G.Walk.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(G.Walk.w.meta.spawn.y) : g; c.mode = mode || 'park'; c.v = 0; T.place(c, 0); return c; }; 1`.replace(/\n/g, ' '); export default { start: [...game({ ...TOWN, site: ['town'] }, 20261129), LIB, '(()=>{ G.Quality.lock = 7; return 1 })()', 'wait:8000'], shots: [ diff --git a/tools/shots/375.mjs b/tools/shots/375.mjs index d3b7d97ca..54da1b2ef 100644 --- a/tools/shots/375.mjs +++ b/tools/shots/375.mjs @@ -15,7 +15,7 @@ const KIT = ['spy_brass', 'bino_field', 'kal_classic', 'tele_tri', 'sq_blast', ' export default { scenes: [ { id: 'home', start: [...game(TOWN, SEED, true)], shots: [ - { name: 'art-nest', title: 'Things lie in homes: the crosshair on a thing on a piece of furniture, the green button offers to take it', steps: [`(()=>{${PRE} G.Wx.setMode(1); W.setZoom(0); run(.1); const EY=W.eyeY-p.y; A.scan(); const L=[...A.units.values()].filter(u=>u.src==='h'); for(const u of L){ for(let i=0;i<16;i++){const a=i*.4,x=u.x-Math.sin(a)*3,z=u.z-Math.cos(a)*3,f=A.floor(x,u.y+1,z); if(f==null||w.solid(Math.floor(x),f+1,Math.floor(z))||w.solid(Math.floor(x),f+6,Math.floor(z))) continue; const e=[x,f+EY,z],d=[u.x-e[0],u.y+.4-e[1],u.z-e[2]],l=Math.hypot(...d),h=w.raycast(e[0],e[1],e[2],d[0]/l,d[1]/l,d[2]/l,l,0); if(h&&h.t{const W=G.Walk,u=G.__u; W.aim(); G.Art.tick(.01); W.refreshActs(); return (W.focus()||{}).a})()`, 'wait:4000'] }, + { name: 'art-nest', title: 'Things lie in homes: the crosshair on a thing on a piece of furniture, the green button offers to take it', steps: [`(()=>{${PRE} G.Wx.setMode(1); W.setZoom(0); run(.1); const EY=W.eyeY-p.y; A.scan(); const L=[...A.units.values()].filter(u=>u.src==='h'); for(const u of L){ for(let i=0;i<16;i++){const a=i*.4,x=u.x-Math.sin(a)*3,z=u.z-Math.cos(a)*3,f=G.Ground.drop(x, z, u.y+1, 12); if(f==null||w.solid(Math.floor(x),f+1,Math.floor(z))||w.solid(Math.floor(x),f+6,Math.floor(z))) continue; const e=[x,f+EY,z],d=[u.x-e[0],u.y+.4-e[1],u.z-e[2]],l=Math.hypot(...d),h=w.raycast(e[0],e[1],e[2],d[0]/l,d[1]/l,d[2]/l,l,0); if(h&&h.t{const W=G.Walk,u=G.__u; W.aim(); G.Art.tick(.01); W.refreshActs(); return (W.focus()||{}).a})()`, 'wait:4000'] }, { name: 'art-bag', title: 'The backpack (🎒, key I): everything found, as many as you like', steps: [`(()=>{${PRE} for(const s of ${JSON.stringify(KIT)}) A.add(s); UI.toggle(); return A.bag.length})()`, 'wait:5000'] }, { name: 'art-chest', title: 'A chest opened: what is inside follows from the world, things move in and out', steps: [`(()=>{${PRE} UI.close(); const u=A.spawn('shot-chest','chest',p.x+Math.sin(p.yaw)*3,p.y,p.z+Math.cos(p.yaw)*3,p.yaw+3.14,'g'); UI.open(u); return A.inside('shot-chest').join()})()`, 'wait:5000'] }, { name: 'art-map', title: 'A treasure map: the land around the cache, the cross and how far it is', steps: [`(()=>{${PRE} UI.close(); UI.map('tmap@'+A.mapFor('shot')); return 1})()`, 'wait:4000'] }, diff --git a/tools/shots/379.mjs b/tools/shots/379.mjs index 834b1df7f..e2709bfdd 100644 --- a/tools/shots/379.mjs +++ b/tools/shots/379.mjs @@ -4,14 +4,14 @@ import { game, TOWN } from './lib.mjs'; // car(kind, x, z, yaw, seed): a vehicle on the street with the player at the wheel; go(n, thr, st): n frames with the pedals and the wheel; // cam(yaw, pitch, zoom): third person around the car; night(h): the clock at hour h (21.5 = after dusk), the sky settled at once const LIB = `window.car = (kind, x, z, yaw, seed) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.rdN = 1e9; T.cars.length = 0; - const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; window.go = (n, thr, st) => { const W = G.Walk; W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); W.joy = [0, 0]; return HC.v.toFixed(1) + ' lt ' + HC.lt; }; window.hold = (n, thr, st) => { const W = G.Walk; W.joy = [st || 0, thr == null ? -1 : thr]; for (let i = 0; i < n; i++) W.update(1 / 60); return HC.v.toFixed(1) + ' lt ' + HC.lt; }; window.cam = (yaw, pitch, z) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); p.yaw = yaw; p.pitch = pitch; if (z != null) W.setZoom(z); return 1; }; window.eye = (x, y, z, yaw, pitch) => { const W = G.Walk, p = W.p; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (W.tp) W.act('tp'); if (!p.fly) W.act('fly'); Object.assign(p, { x, y, z, vy: 0, yaw, pitch }); return 1; }; window.night = h => { const W = G.Walk; W.dayT = h < 21 && h >= 7 ? (h - 7) / 14 * 1080 : 1080 + ((h - 21 + 24) % 24) / 10 * 360; G.Life.h = h; G.Sky.t = null; G.Sky.tick(0, W.dayT); return G.Render.day.toFixed(2); }; -window.other = (kind, x, z, yaw, seed, mode) => { const T = G.Town, c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, G.Walk.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(G.Walk.w.meta.spawn.y) : g; c.mode = mode || 'park'; c.v = 0; T.place(c, 0); return c; }; 1`.replace(/\n/g, ' '); +window.other = (kind, x, z, yaw, seed, mode) => { const T = G.Town, c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, G.Walk.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(G.Walk.w.meta.spawn.y) : g; c.mode = mode || 'park'; c.v = 0; T.place(c, 0); return c; }; 1`.replace(/\n/g, ' '); export default { start: [...game({ ...TOWN, site: ['town'] }, 20261129), LIB, '(()=>{ G.Quality.lock = 7; return 1 })()', 'wait:8000'], shots: [ diff --git a/tools/shots/384.mjs b/tools/shots/384.mjs index bca62ebea..93b6bccd0 100644 --- a/tools/shots/384.mjs +++ b/tools/shots/384.mjs @@ -5,8 +5,8 @@ const LIB = `window.RUN = (n) => { const W = G.Walk, w = W.w; for (let i = 0; i window.ITEM = (id) => { const W = G.Walk, p = W.p; return W.w.insts.filter(i => i && i.it.id === id).sort((a, b) => Math.hypot(a.x - p.x, a.z - p.z) - Math.hypot(b.x - p.x, b.z - p.z))[0]; }; window.SPOT = () => { const W = G.Walk, w = W.w, T = w.T, p = W.p, D = G.Drive; for (let r = 6; r < 160; r += 2) for (let a = 0; a < 48; a++) { const x = Math.floor(p.x + Math.cos(a / 48 * 6.283) * r), z = Math.floor(p.z + Math.sin(a / 48 * 6.283) * r); - if (T.road(x, z) !== 1) continue; const y = D.floor(x + .5, z + .5, p.y + 6); - for (const [dx, dz] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) { let ok = true; for (let i = -8; i <= 70 && ok; i++) { const X = x + dx * i, Z = z + dz * i; const k = T.road(X, Z), k2 = T.road(X - dz * 3, Z + dx * 3); ok = (k === 1 || k === 4) && (k2 === 1 || k2 === 4) && D.floor(X + .5, Z + .5, y + 3) === y; } if (ok) return (window.S = { x: x + .5, z: z + .5, y, dx, dz, yaw: Math.atan2(dx, dz) }) && 'road ' + [x, z, dx, dz]; } } + if (T.road(x, z) !== 1) continue; const y = G.Ground.under(x + .5, z + .5, p.y + 6); + for (const [dx, dz] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) { let ok = true; for (let i = -8; i <= 70 && ok; i++) { const X = x + dx * i, Z = z + dz * i; const k = T.road(X, Z), k2 = T.road(X - dz * 3, Z + dx * 3); ok = (k === 1 || k === 4) && (k2 === 1 || k2 === 4) && G.Ground.under(X + .5, Z + .5, y + 3) === y; } if (ok) return (window.S = { x: x + .5, z: z + .5, y, dx, dz, yaw: Math.atan2(dx, dz) }) && 'road ' + [x, z, dx, dz]; } } return 'no road'; }; window.RIDE = (id, u0, v0) => { const W = G.Walk, D = G.Drive, p = W.p; if (W.ride) { const o = W.ride; o.v = 0; D.exit(true); D.halt = 0; RUN(2); } const it = ITEM(id); if (!it) return 'no ' + id; p.fly = false; p.x = it.x + 1; p.z = it.z + 1; p.y = it.y; D.enter({ inst: it, n: 0, now: 1 }); const c = W.ride; if (!c) return 'not on it'; diff --git a/tools/shots/388.mjs b/tools/shots/388.mjs index 2b4bb24ed..1ab83250e 100644 --- a/tools/shots/388.mjs +++ b/tools/shots/388.mjs @@ -5,7 +5,7 @@ import { game, TOWN } from './lib.mjs'; // hook(): the 🪝 button; go(n, thr, st): n frames with the joystick held; cam(yaw, pitch): the third person view; sheet(): models side by side. const LIB = `window.tow = (back, pit) => { const T = G.Town, W = G.Walk, w = W.w, D = G.Drive, H = G.Hitch, R = G.dbg.ROAD, p = W.p, z = R.ln[1], x0 = w.T.lx / 2 + 30, Y = w.meta.spawn.y + 2; if (W.ride) { D.exit(true); D.end(); } for (const i of w.insts.slice()) if (i && i.id === 'car_tow') w.removeInst(i); H.reset(); T.cars.length = 0; T.carT = 1e9; T.routeT = 1e9; W.night = false; if (p.fly) W.act('fly'); - const g = T.ground(x0, z, Y), bx = x0 - back; window.GY = g; + const g = G.Ground.at(x0, z, Y), bx = x0 - back; window.GY = g; if (pit) { const water = w.bid(G.MAT.water, '#3a7ab8'); for (let x = bx - 16; x <= bx + 16; x++) for (let q = z - 7; q <= z + 7; q++) { const d = Math.min(3, Math.floor(Math.min(x - bx + 16, bx + 16 - x) / 2) + 1); for (let y = g - d; y < g; y++) w.set(x, y, q, y < g - 1 ? water : 0); } } const b = T.build('car', bx, z, Math.PI / 2, { solo: 1, seed: 4242 }); T.cars.push(b); b.y = pit ? g - 3 : g; b.mode = 'park'; b.v = 0; b.empty = true; T.place(b, 0); const a = D.own('car_tow', null, x0, g, z, Math.PI / 2, 0); a.y = g; T.place(a, 0); Object.assign(p, { x: x0, y: g, z: z + 5, vy: 0, yaw: Math.PI / 2, pitch: -.1 }); D.enter({ u: a, n: 0, now: 1 }); D.end(); diff --git a/tools/shots/391.mjs b/tools/shots/391.mjs index 43e75ca64..900d3d010 100644 --- a/tools/shots/391.mjs +++ b/tools/shots/391.mjs @@ -22,7 +22,7 @@ const BASE = '(G,U)=>{const B=G.__Q.B, f=B.foot, c=[[B.x0+3,B.z0+3],[B.x1-3,B.z0 const PASS = '(G,U)=>{const Q=G.__Q, d=Q.d, [x,z]=d.pt(d.mid-.5,-Q.K+1), [bx,bz]=d.pt(d.mid-.5,0); return [x, z, U.F+.2, Math.atan2(bx-x,bz-z), .25]}'; // the police: a patrol car by the manhole, its crew saw the player go down (seen) or stands far off (unseen) const COPS = (dx, see, t = 2.2) => `(()=>{const L=G.Law,W=G.Walk,p=W.p,M=G.__M,U=G.__U; if(W.ride){L.let=1; G.Drive.exit(true); L.let=0;} L.reset(W.w); G.Under.reset(); p.fly=false; p.x=M.x+.5; p.z=M.z+.5; p.y=U.gy+.2; p.vy=0; L.wanted(); L.next=1e9; - const c=L.make('car_police',M.x+${dx},M.z,0); c.y=L.ground(c.x,c.z); G.Town.cars.push(c); L.cars.push(c); L.out(c); G.Under.toggle(); for(let i=0;i<60*${t};i++) W.update(1/60); return [G.Under.known, G.Under.inn, L.cops.length].join(' ')})()`; + const c=L.make('car_police',M.x+${dx},M.z,0); c.y=G.Ground.road(c.x,c.z); G.Town.cars.push(c); L.cars.push(c); L.out(c); G.Under.toggle(); for(let i=0;i<60*${t};i++) W.update(1/60); return [G.Under.known, G.Under.inn, L.cops.length].join(' ')})()`; const RUN = (secs, cond) => `(()=>{const W=G.Walk; for(let i=0;i<60*${secs};i++){ W.update(1/60); if(${cond || 'false'}) break; } return [G.Law.st, G.Law.cops.filter(o=>G.Under.under(o)).length, G.Law.hunters(), G.Walk.p.y.toFixed(1)].join(' ')})()`; // the nearest town with service tunnels (a town of wide streets has collectors only) const FIND2 = `(()=>{const W=G.Walk,w=W.w,all=[]; for(let gz=-6;gz<=6;gz++)for(let gx=-6;gx<=6;gx++){const q=G.Settle.cell(w.T,gx,gz).s; if(q&&q.kind>=1) all.push(q);} all.sort((a,b)=>Math.hypot(a.x,a.z)-Math.hypot(b.x,b.z)); W.night=false; diff --git a/tools/shots/396.mjs b/tools/shots/396.mjs index 2b9e7778b..0317b58f1 100644 --- a/tools/shots/396.mjs +++ b/tools/shots/396.mjs @@ -4,13 +4,13 @@ import { game, TOWN } from './lib.mjs'; // car(kind, x, z, yaw, seed): a vehicle with the player at the wheel; cam(yaw, pitch): third person; mix(): the manners of everybody; // crowd(): the car 16 cells behind the busiest spot among the people, facing it; honk(): the horn held 0.4 s, the manners of those who step aside const LIB = `window.car = (kind, x, z, yaw, seed) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); W.night = false; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; - const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; window.cam = (yaw, pitch) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); p.yaw = yaw; p.pitch = pitch; return 1; }; window.run = s => { const W = G.Walk; for (let i = 0; i < s * 60; i++) W.update(1 / 60); return 1; }; window.mix = () => { const M = G.Mind, h = {}; for (const c of M.bodies()) { const k = M.manner(c, 1234); h[k] = (h[k] || 0) + 1; } return JSON.stringify(h); }; window.line = () => { const T = G.Town, L = T.ppl.filter(c => c.inst && c.inst.hip && !c.dog); let i = 0; - for (const c of L) { const x = -26 + (i % 4) * 3.2 + (i >> 2) * 1.6, z = -13.5 + ((i * 5) % 7 - 3) * 1.1; c.hide = false; c.x = x; c.z = z; const g = T.ground(x, z, HC.y + 4); c.y = g == null ? HC.y : g; c.yaw = -Math.PI / 2 + (i % 3 - 1) * .8; c.steps = [{ t: 'wait', s: 120 }]; c.cur = null; c.pause = 0; c.dg = null; c.gait = 0; i++; } + for (const c of L) { const x = -26 + (i % 4) * 3.2 + (i >> 2) * 1.6, z = -13.5 + ((i * 5) % 7 - 3) * 1.1; c.hide = false; c.x = x; c.z = z; const g = G.Ground.at(x, z, HC.y + 4); c.y = g == null ? HC.y : g; c.yaw = -Math.PI / 2 + (i % 3 - 1) * .8; c.steps = [{ t: 'wait', s: 120 }]; c.cur = null; c.pause = 0; c.dg = null; c.gait = 0; i++; } return L.length + ' people on the road'; }; window.fake = () => { G.Walk.keys.horn = false; G.Drive.exit(true); G.Drive.end(); const p = G.Walk.p; p.x = -30; p.z = -2; HC.mode = 'lane'; HC.v = 0; HC.wq = G.Town.ppl.find(c => c.inst && c.inst.hip && !c.dog); G.Pilot.honk(HC, { patience: 0, aggr: .9 }, 0); return 1; }; window.honk = () => { G.Walk.keys.horn = true; run(.4); G.Walk.keys.horn = false; const out = []; for (const c of G.Mind.bodies()) if (c.dg && c.dg.m) out.push(c.dg.m); return out.join(' '); }; 1`.replace(/\n/g, ' '); diff --git a/tools/shots/399.mjs b/tools/shots/399.mjs index 318192808..b6faefda5 100644 --- a/tools/shots/399.mjs +++ b/tools/shots/399.mjs @@ -17,7 +17,7 @@ window.sheet = (L, px) => { const old = document.getElementById('sheet'); if (ol d.style.cssText = 'position:fixed;inset:0;z-index:99999;background:#8fb8d8;display:flex;flex-wrap:wrap;align-content:center;justify-content:center'; for (const [it, sl] of L) { const i = new Image(); i.src = G.Thumb.render(it, sl, px); i.style.cssText = 'width:' + px + 'px;height:' + px + 'px'; d.appendChild(i); } document.body.appendChild(d); return L.length; }; 1`.replace(/\n/g, ' '); const TOWNLIB = `window.pull = () => { const T = G.Town, W = G.Walk, w = W.w, D = G.Drive, R = G.dbg.ROAD, p = W.p, z = R.ln[1], x0 = w.T.lx / 2 + 40, Y = w.meta.spawn.y + 2; clr(); T.cars.length = 0; - const g = T.ground(x0, z, Y), a = D.own('car', null, x0, g, z, Math.PI / 2, 0); a.y = g; T.place(a, 0); Object.assign(p, { x: x0, y: g, z: z + 5, vy: 0, yaw: Math.PI / 2, pitch: -.1 }); D.enter({ u: a, n: 0, now: 1 }); D.end(); + const g = G.Ground.at(x0, z, Y), a = D.own('car', null, x0, g, z, Math.PI / 2, 0); a.y = g; T.place(a, 0); Object.assign(p, { x: x0, y: g, z: z + 5, vy: 0, yaw: Math.PI / 2, pitch: -.1 }); D.enter({ u: a, n: 0, now: 1 }); D.end(); const it = G.Lib.byId.caravan, L = it.model.size[2] / 4, cx = x0 - a.len / 2 - .7 - (L / 2 - .4), q0 = G.dbg.makeInst(it, 0, g, 0, 3, null, 0, 0), d = q0.d; const i = G.dbg.makeInst(it, Math.round(cx - d[0] / 2), g, Math.round(z - d[2] / 2), 3, null, 0, 0); w.addInst(i); window.HC = a; for (let k = 0; k < 30; k++) W.update(1 / 60); return [Math.round(a.x), i.x, i.z]; }; window.street = () => { const T = G.Town, W = G.Walk, R = G.dbg.ROAD, z = R.ln[1] - 3, x = W.w.T.lx / 2 - 30; clr(); T.cars.length = 0; diff --git a/tools/shots/417.mjs b/tools/shots/417.mjs index 17c2492fc..bf2ea778c 100644 --- a/tools/shots/417.mjs +++ b/tools/shots/417.mjs @@ -7,18 +7,18 @@ import { game, TOWN, LOAD } from './lib.mjs'; // brigade(t): the fire brigade called to it, its engine stopped 34 cells short of the tree (only for the picture: it stands there) const LIB = `window.run = n => { const W = G.Walk; for (let i = 0; i < n; i++) W.update(1 / 60); return 1; }; window.crane = (kind, x, z, yaw, seed, col) => { const W = G.Walk, p = W.p, T = G.Town; if (p.fly) W.act('fly'); if (W.tp) W.act('tp'); if (W.ride) { G.Drive.exit(true); G.Drive.end(); } T.carT = 1e9; T.routeT = 1e9; T.rdN = 1e9; T.cars.length = 0; - const c = T.build(kind, x, z, yaw, { solo: 1, seed, col }); T.cars.push(c); const g = T.ground(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); + const c = T.build(kind, x, z, yaw, { solo: 1, seed, col }); T.cars.push(c); const g = G.Ground.at(x, z, W.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(W.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); Object.assign(p, { x: x + 3, y: c.y, z, vy: 0, yaw, pitch: -.1, ground: true }); window.HC = c; G.Drive.enter({ u: c, n: 0, now: 1 }); G.Drive.end(); p.yaw = yaw; return c.id; }; -window.other = (kind, x, z, yaw, seed, col) => { const T = G.Town, c = T.build(kind, x, z, yaw, { solo: 1, seed, col }); T.cars.push(c); const g = T.ground(x, z, G.Walk.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(G.Walk.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); return c; }; +window.other = (kind, x, z, yaw, seed, col) => { const T = G.Town, c = T.build(kind, x, z, yaw, { solo: 1, seed, col }); T.cars.push(c); const g = G.Ground.at(x, z, G.Walk.w.meta.spawn.y + 2); c.y = g == null ? Math.floor(G.Walk.w.meta.spawn.y) : g; c.mode = 'park'; c.v = 0; T.place(c, 0); return c; }; window.cam = (yaw, pitch, z) => { const W = G.Walk, p = W.p; if (!W.tp) W.act('tp'); p.yaw = yaw; p.pitch = pitch; if (z != null) W.setZoom(z); return 1; }; window.aim = (x, y, z) => { G.Arm.at = [x, y, z]; return 1; }; -window.pile = (x, z, n) => { const w = G.Walk.w, M = G.MAT, g = G.Town.ground(x, z, 90), ids = ['#9a4a32', '#b0603e', '#7c7a74', '#c9c3b6'].map(c => w.bid(c === '#7c7a74' ? M.concrete : M.brick, c)); let k = 0; +window.pile = (x, z, n) => { const w = G.Walk.w, M = G.MAT, g = G.Ground.at(x, z, 90), ids = ['#9a4a32', '#b0603e', '#7c7a74', '#c9c3b6'].map(c => w.bid(c === '#7c7a74' ? M.concrete : M.brick, c)); let k = 0; for (let dx = 0; dx < n; dx++) for (let dz = 0; dz < n; dz++) { const h = 1 + ((dx * 7 + dz * 3) % 3 === 0 ? 1 : 0) + (dx > 0 && dz > 0 && dx < n - 1 && dz < n - 1 ? 1 : 0); for (let dy = 0; dy < h; dy++) { w.set(x + dx, g + dy, z + dz, ids[(dx * 5 + dz * 3 + dy) % 4]); k++; } } window.PG = g; return k; }; window.tree = (k = 0) => { const W = G.Walk, T = W.w.T, t = T.smalls(-500, -500, 500, 500, []).filter(t => !G.Law.own(t.x, t.z) && !t.palm).sort((a, b) => Math.hypot(a.x, a.z) - Math.hypot(b.x, b.z))[k]; G.Fire.tap({ x: t.x, y: Math.floor(T.at(t.x, t.z)), z: t.z }); window.TT = t; window.FF = G.Fire.list[G.Fire.list.length - 1]; return t.x + ',' + t.z; }; window.brigade = () => { const W = G.Walk, T = W.w.T, Tn = G.Town, t = TT; G.Law.reset(W.w); G.Fire.call('fire', { f: FF }); const eng = () => [...Tn.calls.values()][0]; for (let i = 0; i < 600 && !eng(); i++) W.update(1 / 30); const c = eng(); if (!c) return 0; window.EC = c; const sc = Tn._sc || (Tn._sc = Tn.stepCall); Tn.stepCall = function (c2, dt, p) { if (c2 !== EC) return sc.call(this, c2, dt, p); c2.cAt = 1; c2.v = 0; c2.ct += dt; c2.inst = Math.floor(performance.now() / 200) % 2 ? c2.instB : c2.instA; }; - c.x = t.x - 34; c.z = t.z + 6; c.yaw = Math.PI / 2; const g = Tn.ground(c.x, c.z, T.at(c.x, c.z) + 20); c.y = g == null ? Math.ceil(T.at(c.x, c.z)) : g; Tn.place(c, 0); return 1; }; + c.x = t.x - 34; c.z = t.z + 6; c.yaw = Math.PI / 2; const g = G.Ground.at(c.x, c.z, T.at(c.x, c.z) + 20); c.y = g == null ? Math.ceil(T.at(c.x, c.z)) : g; Tn.place(c, 0); return 1; }; window.roofAt = (x0, z0, x1, z1) => { const w = G.Walk.w; let b = null; for (let x = x0; x <= x1; x += 2) for (let z = z0; z <= z1; z += 2) for (let y = 110; y > 40; y--) if (w.solid(x, y, z) && w.pm[w.get(x, y, z)] !== G.MAT.leaves) { if (!b || y > b[1]) b = [x + .5, y + 1, z + .5]; break; } return b; }; window.look = (tx, ty, tz, d, ang, up) => { const W = G.Walk, p = W.p; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (W.tp) W.act('tp'); W.setZoom(0); if (!p.fly) W.act('fly'); const x = tx + Math.sin(ang) * d, z = tz + Math.cos(ang) * d, y = ty + up; Object.assign(p, { x, y, z, vy: 0, yaw: Math.atan2(tx - x, tz - z), pitch: Math.atan2(-up, d) }); return 1; }; 1`.replace(/\n/g, ' '); const day = '(()=>{ G.Walk.dayT = 420; G.Fp.on = false; return 1 })()'; diff --git a/tools/shots/423.mjs b/tools/shots/423.mjs index 7533ab733..b506c67ef 100644 --- a/tools/shots/423.mjs +++ b/tools/shots/423.mjs @@ -8,7 +8,7 @@ const PRE = `const W=G.Walk,p=W.p,w=W.w,F=G.Fauna,E=G.Etho,Lb=G.Lib.byId,WL0=w.T + `free=(x,y,z)=>!w.get(Math.floor(x),Math.floor(y),Math.floor(z)),` + `look=(c,d,up,a0)=>{for(let k=0;k<48;k++){const a=(a0==null?c.yaw+.9:a0)+k*.53,dd=d*(k<16?1:k<32?.7:.5),x=c.x+Math.sin(a)*dd,z=c.z+Math.cos(a)*dd,y=c.y+c.ht*.5+up-8;let ok=free(x,y+8,z)&&free(x,y+9,z)&&free(x,y+7,z);` + `for(let t=.04;ok&&t<.88;t+=.04){if(!free(x+(c.x-x)*t,y+8+(c.y+c.ht*.5-y-8)*t,z+(c.z-z)*t))ok=false}if(ok){p.fly=true;p.x=x;p.y=y;p.z=z;p.vy=0;p.yaw=Math.atan2(c.x-x,c.z-z);p.pitch=Math.atan2(c.y+c.ht*.5-(y+8),dd);W.eyeY=y+8;return 1}}return 0},` - + `mk=(id,x,z,own)=>{const g=Math.floor(w.T.at(x,z)),y=F.drop(x,g+10,z);const c=own?F.adopt(Lb[id],x,y==null?g:y,z,0):F.make(Lb[id],x,y==null?g:y,z,0,null,false);c.hx=c.x;c.hy=c.y;c.hz=c.z;return c},` + + `mk=(id,x,z,own)=>{const g=Math.floor(w.T.at(x,z)),y=G.Ground.drop(x, z, g+10, 14);const c=own?F.adopt(Lb[id],x,y==null?g:y,z,0):F.make(Lb[id],x,y==null?g:y,z,0,null,false);c.hx=c.x;c.hy=c.y;c.hz=c.z;return c},` + `tick=s=>{for(let i=0;i{const y0=c.y;for(let k=0;k<24;k++){E.left=1;E.reach(c,k%4===3&&c.y-y0=h&&!c.j&&(!out||!roof))return c.y-y0;}return c.y-y0},` + `rare=sp=>{const L=w.T.rares(p.x-30000,p.z-30000,p.x+30000,p.z+30000,[]).filter(l=>l.sp===sp).sort((a,b)=>Math.hypot(a.x-75,a.z-100)-Math.hypot(b.x-75,b.z-100));return L[0]},` @@ -21,7 +21,7 @@ export default { scenes: [ { id: 'etho', start: [...game(TOWN, 20261129), '(()=>{ G.Fp.on = false; G.Wx.setMode(1); return 1 })()'], shots: [ { name: 'cat-furniture', note: 2, title: 'The house cat jumps onto the furniture and sits up high, indoors', steps: S(`SETH(11); const c=F.list.find(k=>k.it.id==='pet_cat'&&k.own); p.x=c.x+40; p.z=c.z+40; const h=up(c,3); c.pin=1; c.gait=0; return JSON.stringify({h,ok:look(c,5,2)||look(c,3,1),c:pos(c)})`) }, - { name: 'cat-fence', note: 2, title: 'Outdoors: a cat up on a fence, and the dog that chased it barks below', steps: S(`const s=w.meta.spawn,c=mk('pet_cat',s.x+6,s.z-5,1),d=F.list.find(k=>k.it.id==='pet_dog'&&k.own); p.x=c.x+40; const h=up(c,3,'perch',1); c.pin=1; c.gait=0; if(d){d.x=c.x+1;d.z=c.z+3.5;d.y=F.drop(d.x,c.y+2,d.z)||d.y;d.yaw=Math.atan2(c.x-d.x,c.z-d.z);d.em='bay';d.nod=0;d.lie=0;d.pin=1;d.gait=0;} return JSON.stringify({h,ok:look(c,11,5),c:pos(c)})`) }, + { name: 'cat-fence', note: 2, title: 'Outdoors: a cat up on a fence, and the dog that chased it barks below', steps: S(`const s=w.meta.spawn,c=mk('pet_cat',s.x+6,s.z-5,1),d=F.list.find(k=>k.it.id==='pet_dog'&&k.own); p.x=c.x+40; const h=up(c,3,'perch',1); c.pin=1; c.gait=0; if(d){d.x=c.x+1;d.z=c.z+3.5;d.y=G.Ground.drop(d.x, d.z, c.y+2, 14)||d.y;d.yaw=Math.atan2(c.x-d.x,c.z-d.z);d.em='bay';d.nod=0;d.lie=0;d.pin=1;d.gait=0;} return JSON.stringify({h,ok:look(c,11,5),c:pos(c)})`) }, { name: 'hedgehog-ball', note: 3, title: 'A hedgehog rolls into a ball when a person comes close', steps: S(`const s=w.meta.spawn,c=mk('hedgehog',s.x-6,s.z+9); p.fly=false; p.x=c.x+3; p.z=c.z; p.y=c.y; tick(2); c.pin=1; return JSON.stringify({em:c.em,sq:c.sq,ok:look(c,4,2,1.2),c:pos(c)})`) }, ] }, // wild animals away from the house, a session of its own @@ -30,8 +30,8 @@ export default { ] }, // the rare homes of the creatures of fairy tales: far away from the house (km), a session of their own { id: 'tale', start: [...game(TOWN, 20261129), '(()=>{ G.Fp.on = false; G.Wx.setMode(1); return 1 })()'], shots: [ - { name: 'dragon-hoard', note: 8, title: 'A dragon by its hoard: a cave with gold high in the mountains, one per several km² of the world', steps: [...RARE('dragon', 10), LOAD, ...S(`const l=G.__l,dc=[1,0,-1,0][l.d],ds=[0,1,0,-1][l.d]; F.settle(p); for(let i=0;i<240;i++)F.update(1/60,p); const c=F.list.find(k=>k.it.id==='dragon'&&k.home&&k.home.key===l.key)||mk('dragon',l.x+dc*20,l.z+ds*20); c.x=l.x+.5+dc*14; c.z=l.z+.5+ds*14; c.y=F.drop(c.x,l.y+14,c.z)||l.y; c.yaw=Math.atan2(dc,ds)+.7; c.go=false; c.pin=1; c.gait=0; if(!look(c,46,16,Math.atan2(dc,ds)+.3)){const cx=l.x+dc*44-ds*12,cz=l.z+ds*44+dc*12; fly(cx,cz,0,l.x+dc*8,l.z+ds*8,l.y+2); p.y=Math.max(p.y,l.y+22); W.eyeY=p.y+8; p.pitch=Math.atan2(l.y+2-p.y-8,Math.hypot(l.x+dc*8-cx,l.z+ds*8-cz));} return JSON.stringify({c:pos(c),home:!!c.home})`), LOAD, 'wait:15000'] }, - { name: 'unicorn-glade', note: 8, title: 'A unicorn on its glade in a ring of flowers', steps: [...RARE('unicorn', 9), LOAD, ...S(`const l=G.__l; F.settle(p); for(let i=0;i<240;i++)F.update(1/60,p); const c=F.list.find(k=>k.it.id==='unicorn'&&k.home&&k.home.key===l.key)||mk('unicorn',l.x+.5,l.z+.5); c.x=l.x+1.5; c.z=l.z+.5; c.y=F.drop(c.x,l.y+8,c.z)||l.y; c.go=false; c.pin=1; c.gait=0; look(c,16,5)||fly(l.x+17,l.z+6,7,l.x,l.z,l.y+2); return JSON.stringify({c:pos(c),home:!!c.home})`), LOAD, 'wait:15000'] }, + { name: 'dragon-hoard', note: 8, title: 'A dragon by its hoard: a cave with gold high in the mountains, one per several km² of the world', steps: [...RARE('dragon', 10), LOAD, ...S(`const l=G.__l,dc=[1,0,-1,0][l.d],ds=[0,1,0,-1][l.d]; F.settle(p); for(let i=0;i<240;i++)F.update(1/60,p); const c=F.list.find(k=>k.it.id==='dragon'&&k.home&&k.home.key===l.key)||mk('dragon',l.x+dc*20,l.z+ds*20); c.x=l.x+.5+dc*14; c.z=l.z+.5+ds*14; c.y=G.Ground.drop(c.x, c.z, l.y+14, 14)||l.y; c.yaw=Math.atan2(dc,ds)+.7; c.go=false; c.pin=1; c.gait=0; if(!look(c,46,16,Math.atan2(dc,ds)+.3)){const cx=l.x+dc*44-ds*12,cz=l.z+ds*44+dc*12; fly(cx,cz,0,l.x+dc*8,l.z+ds*8,l.y+2); p.y=Math.max(p.y,l.y+22); W.eyeY=p.y+8; p.pitch=Math.atan2(l.y+2-p.y-8,Math.hypot(l.x+dc*8-cx,l.z+ds*8-cz));} return JSON.stringify({c:pos(c),home:!!c.home})`), LOAD, 'wait:15000'] }, + { name: 'unicorn-glade', note: 8, title: 'A unicorn on its glade in a ring of flowers', steps: [...RARE('unicorn', 9), LOAD, ...S(`const l=G.__l; F.settle(p); for(let i=0;i<240;i++)F.update(1/60,p); const c=F.list.find(k=>k.it.id==='unicorn'&&k.home&&k.home.key===l.key)||mk('unicorn',l.x+.5,l.z+.5); c.x=l.x+1.5; c.z=l.z+.5; c.y=G.Ground.drop(c.x, c.z, l.y+8, 14)||l.y; c.go=false; c.pin=1; c.gait=0; look(c,16,5)||fly(l.x+17,l.z+6,7,l.x,l.z,l.y+2); return JSON.stringify({c:pos(c),home:!!c.home})`), LOAD, 'wait:15000'] }, { name: 'fairy-ring', note: 8, title: 'At night fairies circle over a fairy ring of glowing mushrooms', steps: [...RARE('fairy', 22), LOAD, ...S(`const l=G.__l; F.settle(p); for(let i=0;i<300;i++)F.update(1/60,p); const ff=F.list.filter(k=>k.it.id==='fairy'&&k.home&&k.home.key===l.key); ff.forEach((c,i)=>{const a=i*2.1;c.x=l.x+.5+Math.sin(a)*3;c.z=l.z+.5+Math.cos(a)*3;c.y=l.y+2+i*.7;c.yaw=a+1.6;c.go=false;c.pin=1;}); fly(l.x+10,l.z+4,4,l.x,l.z,l.y+1); return JSON.stringify({n:ff.length,c:ff.map(pos)})`), LOAD, 'wait:15000'] }, ] }, ], diff --git a/tools/shots/426.mjs b/tools/shots/426.mjs index 6581b6b2d..bc25f6e89 100644 --- a/tools/shots/426.mjs +++ b/tools/shots/426.mjs @@ -3,7 +3,7 @@ // does). The real exchange between two browsers is tools/pax.test.mjs. import { game, TOWN, LOAD } from './lib.mjs'; const SETUP = `(()=>{ const N = G.Net, D = G.Drive, T = G.Town, W = G.Walk, p = W.p; W.night = false; G.Fp && (G.Fp.on = false); N.role = 'host'; N.pid = 0; N.cast = () => {}; T.carT = 1e9; T.routeT = 1e9; - window.spot = skip => { for (let r = 10; r < 140; r += 3) for (let k = 0; k < 16; k++) { const a = k / 16 * Math.PI * 2, x = p.x + Math.cos(a) * r, z = p.z + Math.sin(a) * r, y = T.ground(x, z, p.y + 2); if (y == null || skip && Math.hypot(x - skip[0], z - skip[2]) < 20) continue; + window.spot = skip => { for (let r = 10; r < 140; r += 3) for (let k = 0; k < 16; k++) { const a = k / 16 * Math.PI * 2, x = p.x + Math.cos(a) * r, z = p.z + Math.sin(a) * r, y = G.Ground.at(x, z, p.y + 2); if (y == null || skip && Math.hypot(x - skip[0], z - skip[2]) < 20) continue; const c = D.own('car', null, x, y, z, a, 0); if (!c) continue; const ok = D.worldFree(c, x, z, a, 1.4) && [8, 16].every(d => D.worldFree(c, x + Math.sin(a) * d, z + Math.cos(a) * d, a, 3)); T.cars.splice(T.cars.indexOf(c), 1); if (ok) return [x, y, z, a]; } return null; }; window.run = s => { for (let i = 0; i < 30 * s; i++) { W.update(1 / 30); N.tick(1 / 30); } return 1; }; window.player = (id, n, z) => { N.addPlayer({ id, n, u: n, z, me: G.Me.random() }); return N.players.get(id); }; diff --git a/tools/shots/428.mjs b/tools/shots/428.mjs index 6be982235..f72863b12 100644 --- a/tools/shots/428.mjs +++ b/tools/shots/428.mjs @@ -16,7 +16,7 @@ export default { shots: [ { name: 'pilot-push', title: 'A patrol car is driven by the same physics as the player\'s car: it brakes for a car in its way, then pushes it aside with its bumper', steps: [ // a parked car on the home street and a patrol car coming along it - `(()=>{ const W = G.Walk, L = G.Law, w = W.w; L.reset(w); L.wanted(); L.next = 1e9; const [gx, gz] = L.gate(), y = L.ground(gx, gz); + `(()=>{ const W = G.Walk, L = G.Law, w = W.w; L.reset(w); L.wanted(); L.next = 1e9; const [gx, gz] = L.gate(), y = G.Ground.road(gx, gz); const k = G.Drive.own('car', null, gx + 40, y, gz, Math.PI / 2, 0); G.Town.place(k, 0); window.PK = k; window.PK0 = [k.x, k.z]; const c = L.make('car_police', gx - 40, gz, Math.PI / 2); c.y = y; G.Town.place(c, 0); G.Town.cars.push(c); L.cars.push(c); window.PC = c; c.lg = { k: 'leave', l: G.Navi.line([[gx - 40, gz], [gx + 160, gz]]), s: 0, V: 40 }; c.gen = 1; return 1 })()`, @@ -30,12 +30,12 @@ export default { { name: 'car-blast-police', title: 'A parked car blown up in front of a passer-by: destroying a car is a crime, they phone the police', steps: [ // the same place as the law test: a stranger's car on the home street, the charge next to it, a passer-by watching the player set it `(()=>{ const W = G.Walk, w = W.w, L = G.Law, p = W.p; back(); off(); L.reset(w); G.Evt.reset(); if (W.tp) W.act('tp'); p.fly = false; - const [gx, gz] = L.gate(), x = gx - 60.5, z = gz + .5, y = L.ground(x, z), TC = G.Town.cars; + const [gx, gz] = L.gate(), x = gx - 60.5, z = gz + .5, y = G.Ground.road(x, z), TC = G.Town.cars; for (const o of TC.filter(o => !o.own && Math.hypot(o.x - x, o.z - z) < 80)) TC.splice(TC.indexOf(o), 1); const c = G.Town.build('car', x, z, Math.PI / 2, { solo: 1, seed: 7 }); if (TC.indexOf(c) < 0) TC.push(c); c.y = y; c.mode = 'park'; c.v = 0; G.Town.place(c, 0); window.BCC = c; const wit = [{ x: x + 20, z, name: 'Witness' }]; window.F0 = L.folks; L.folks = (a, b, r) => wit.filter(q => Math.hypot(q.x - a, q.z - b) < r); - Object.assign(p, { x: x + 14, z, y: L.ground(x + 14, z) + 1, vy: 0, yaw: -Math.PI / 2, pitch: -.1 }); TK(.5); - const bx = Math.floor(x) + 3, bz = Math.floor(z); let by = Math.ceil(L.ground(bx, bz)) + 2; while (!w.get(bx, by - 1, bz) && by > 0) by--; by--; + Object.assign(p, { x: x + 14, z, y: G.Ground.road(x + 14, z) + 1, vy: 0, yaw: -Math.PI / 2, pitch: -.1 }); TK(.5); + const bx = Math.floor(x) + 3, bz = Math.floor(z); let by = Math.ceil(G.Ground.road(bx, bz)) + 2; while (!w.get(bx, by - 1, bz) && by > 0) by--; by--; G.Boom.last = -1e9; G.Boom.setPow(6); G.Boom.put({ x: bx, y: by, z: bz, nx: 0, ny: 1, nz: 0, id: w.get(bx, by, bz) }); wit.length = 0; window.BC = [x, y, z]; return [bx, by, bz] })()`.replace(/\n/g, ' '), 'TK(30, () => G.Law.st)', '(()=>{ G.Law.folks = F0; return shoot(BC[0], BC[1] + 2, BC[2], 26, -.9, 30) })()', LOAD, 'wait:9000', '(()=>{ return [G.Law.st, +(BCC.dmg || 0).toFixed(2), G.Law.cars.length] })()'] }, diff --git a/tools/shots/435.mjs b/tools/shots/435.mjs index 2b5570880..d9fcdaf56 100644 --- a/tools/shots/435.mjs +++ b/tools/shots/435.mjs @@ -6,7 +6,7 @@ import { game, TOWN, LOAD } from './lib.mjs'; const AIM = (x, z, dy, tx, tz, tdy) => `(()=>{ const W=G.Walk,p=W.p,T=W.w.T; W.night=false; if(W.ride){ G.Drive.exit(true); G.Drive.end(); } if(W.tp) W.act('tp'); if(!p.fly) W.act('fly'); const y=T.at(${x},${z})+${dy}, ty=T.at(${tx},${tz})+${tdy}; Object.assign(p,{x:${x},y,z:${z},vy:0,yaw:Math.atan2(${tx}-(${x}),${tz}-(${z})),pitch:Math.atan2(ty-y,Math.hypot(${tx}-(${x}),${tz}-(${z})))}); return 1 })()`; const SETTLE = [LOAD, 'wait:20000', LOAD, 'wait:8000']; // the player's car on the right lane of the link road going up, seen from behind (third person) -const CAR = `(()=>{ const W=G.Walk,p=W.p,D=G.Drive,T=W.w.T; G.Town.carT=1e9; if(p.fly) W.act('fly'); const x=-647.5,z=-120,y=G.Town.ground(x,z,T.at(x,z)+2); const c=D.own('car',null,x,y,z,Math.PI,0); c.y=y; Object.assign(p,{x:x+3,y,z,vy:0,ground:true}); D.enter({u:c,n:0,now:1}); D.end(); W.joy=[0,-.5]; for(let i=0;i<60*2.5;i++) W.update(1/60); W.joy=[0,-.25]; if(!W.tp) W.act('tp'); p.yaw=Math.PI; p.pitch=-.12; return 'car at '+c.z.toFixed(0)+' tilt '+(c.tilt*180/Math.PI).toFixed(1) })()`; +const CAR = `(()=>{ const W=G.Walk,p=W.p,D=G.Drive,T=W.w.T; G.Town.carT=1e9; if(p.fly) W.act('fly'); const x=-647.5,z=-120,y=G.Ground.at(x,z,T.at(x,z)+2); const c=D.own('car',null,x,y,z,Math.PI,0); c.y=y; Object.assign(p,{x:x+3,y,z,vy:0,ground:true}); D.enter({u:c,n:0,now:1}); D.end(); W.joy=[0,-.5]; for(let i=0;i<60*2.5;i++) W.update(1/60); W.joy=[0,-.25]; if(!W.tp) W.act('tp'); p.yaw=Math.PI; p.pitch=-.12; return 'car at '+c.z.toFixed(0)+' tilt '+(c.tilt*180/Math.PI).toFixed(1) })()`; export default { start: game(TOWN, 20261139), shots: [ diff --git a/tools/shots/438.mjs b/tools/shots/438.mjs index 2774e4619..69b6c6e7b 100644 --- a/tools/shots/438.mjs +++ b/tools/shots/438.mjs @@ -11,15 +11,15 @@ export default { start: [...game({ ...TOWN, site: ['town'] }, 20261129, true), LIB, day, 'wait:4000'], shots: [ { name: 'swat-rope', title: 'Caught by the SWAT team: no patrol car, their helicopter pulls the player up on the rope', steps: [ - `(()=>{ const W = G.Walk, L = G.Law, w = W.w, p = W.p; L.reset(w); W.keys = {}; const [gx, gz] = L.gate(); p.fly = false; p.x = gx + 6; p.z = gz; p.y = L.ground(p.x, p.z) + 1; TK(1); - L.wanted(); L.sta = L.station(p.x, p.z); L.next = 1e9; const H = L.copter('orbit'); L.H = H; H.x = p.x + 40; H.z = p.z; H.y = L.ground(p.x, p.z) + 115; H.a = 0; L.swat(H, 0); - const o = H.sw.pop(); o.x = p.x + 1; o.z = p.z; o.y = L.ground(o.x, o.z); L.cops.push(o); L.arrest(o); return TK(90, () => !L.inH && p.y - L.ground(p.x, p.z) > 14) })()`.replace(/\n/g, ' '), + `(()=>{ const W = G.Walk, L = G.Law, w = W.w, p = W.p; L.reset(w); W.keys = {}; const [gx, gz] = L.gate(); p.fly = false; p.x = gx + 6; p.z = gz; p.y = G.Ground.road(p.x, p.z) + 1; TK(1); + L.wanted(); L.sta = L.station(p.x, p.z); L.next = 1e9; const H = L.copter('orbit'); L.H = H; H.x = p.x + 40; H.z = p.z; H.y = G.Ground.road(p.x, p.z) + 115; H.a = 0; L.swat(H, 0); + const o = H.sw.pop(); o.x = p.x + 1; o.z = p.z; o.y = G.Ground.road(o.x, o.z); L.cops.push(o); L.arrest(o); return TK(90, () => !L.inH && p.y - G.Ground.road(p.x, p.z) > 14) })()`.replace(/\n/g, ' '), '(()=>{ const p = G.Walk.p; return shoot(p.x, p.y + 4, p.z, 40, 2.2, -2) })()', LOAD, 'wait:9000'] }, { name: 'swat-fly', title: 'On board: the helicopter flies the player over the town to the police station', steps: [ 'back()', '(()=>{ const L = G.Law; return TK(120, () => L.inH && L.H && L.H.k === "go" && L.sta && Math.hypot(L.H.x - L.sta.x, L.H.z - L.sta.z) < 220) })()', '(()=>{ const H = G.Law.H; return shoot(H.x, H.y, H.z, 34, H.a + 2.4, 8) })()', LOAD, 'wait:9000'] }, { name: 'swat-land', title: 'It lands right at the station, and from there it is the cell', steps: [ - 'back()', '(()=>{ const L = G.Law; return TK(240, () => L.H && L.H.k === "land" && L.H.y - L.ground(L.H.x, L.H.z) < 8) })()', + 'back()', '(()=>{ const L = G.Law; return TK(240, () => L.H && L.H.k === "land" && L.H.y - G.Ground.road(L.H.x, L.H.z) < 8) })()', '(()=>{ const H = G.Law.H, S = G.Law.sta; shoot(H.x, H.y, H.z, 14, 2.6, 120); return JSON.stringify([H.pad && H.pad.map(Math.round), Math.round(S.x), Math.round(S.z)]) })()', LOAD, 'wait:9000'] }, { name: 'jail-cell', title: 'The holding cell is four times the floor it was, and its bars are whole: a barred door in a steel frame', steps: [ 'back()', '(()=>{ return TK(120, () => G.Law.st === 4) })()', 'TK(1)', diff --git a/tools/shots/439.mjs b/tools/shots/439.mjs index f37b1f90b..7b9897e38 100644 --- a/tools/shots/439.mjs +++ b/tools/shots/439.mjs @@ -5,7 +5,7 @@ import S400 from './417.mjs'; // engine(x, z): a fire engine of the street parked there (EC); stand(x, z): the player on foot there, looking at the burning tree (TT); // the rest (run, aim, tree, look, cam…) as in 400.mjs const LIB = `window.engine = (x, z) => { const T = G.Town, W = G.Walk; T.carT = 1e9; T.routeT = 1e9; T.rdN = 1e9; T.cars.length = 0; const c = other('car_fire', x, z, Math.PI / 2, 5, '#c8281e'); window.EC = c; return c.id; }; -window.stand = (x, z) => { const W = G.Walk, p = W.p, T = W.w.T; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (p.fly) W.act('fly'); const g = G.Town.ground(x, z, T.at(x, z) + 20); Object.assign(p, { x, y: g == null ? Math.ceil(T.at(x, z)) : g, z, vy: 0, ground: true }); +window.stand = (x, z) => { const W = G.Walk, p = W.p, T = W.w.T; if (W.ride) { G.Drive.exit(true); G.Drive.end(); } if (p.fly) W.act('fly'); const g = G.Ground.at(x, z, T.at(x, z) + 20); Object.assign(p, { x, y: g == null ? Math.ceil(T.at(x, z)) : g, z, vy: 0, ground: true }); if (window.TT) { p.yaw = Math.atan2(TT.x - x, TT.z - z); p.pitch = -.05; } return 1; }; 1`.replace(/\n/g, ' '); export default { start: [...S400.start, LIB], diff --git a/tools/shots/464.mjs b/tools/shots/464.mjs index 0dc6d4527..55dfafd8d 100644 --- a/tools/shots/464.mjs +++ b/tools/shots/464.mjs @@ -18,7 +18,7 @@ window.ramp = () => { const W = G.Walk, w = W.w, s = w.meta.spawn; G.Town.carT = window.RB = [r.x - r.dz * r.sl, r.z + r.dx * r.sl, r.dx, r.dz]; if (!W.p.fly) W.act('fly'); Object.assign(W.p, { x: RB[0] - r.dx * 30 + .5, z: RB[1] - r.dz * 30 + .5, y: w.T.at(RB[0] - r.dx * 30, RB[1] - r.dz * 30) + 20, vy: 0 }); return [r.x, r.z, r.sl]; }; window.place = back => { const W = G.Walk, w = W.w, T = G.Town, D = G.Drive, [x0, z0, dx, dz] = RB, yaw = Math.atan2(-dx, -dz), p = W.p; if (p.fly) W.act('fly'); const top = (x, z) => { let y = Math.ceil(w.T.at(x, z)) + 30; for (; y > 1 && !w.get(x, y, z); y--); return y; }; - const at = k => { const x = x0 - dx * k + .5, z = z0 - dz * k + .5; return [x, T.ground(x, z, top(Math.floor(x), Math.floor(z)) + 3), z]; }; + const at = k => { const x = x0 - dx * k + .5, z = z0 - dz * k + .5; return [x, G.Ground.at(x, z, top(Math.floor(x), Math.floor(z)) + 3), z]; }; const ti = G.Lib.byId.trailer_boat, TL = ti.model.size[2] / 4, cl = G.Lib.byId.car_xl.model.size[2] / 4, C = at(back + TL + 1 + cl / 2); const a = D.own('car_xl', null, C[0], C[1], C[2], yaw, 0); a.y = C[1]; T.place(a, 0); Object.assign(p, { x: C[0] + 4, y: C[1], z: C[2], vy: 0, yaw, pitch: -.1 }); D.enter({ u: a, n: 0, now: 1 }); D.end(); const n = ((Math.round(-yaw / (Math.PI / 4)) % 8) + 8) % 8, r = n >> 1, h = n & 1, Q = at(back + TL / 2 + .3), d = G.dbg.makeInst(ti, 0, 0, 0, r, null, 0, h).d; diff --git a/tools/shots/465.mjs b/tools/shots/465.mjs index a0fe8caec..89cf18964 100644 --- a/tools/shots/465.mjs +++ b/tools/shots/465.mjs @@ -10,7 +10,7 @@ const AT = (target, d, h, a, secs = 6) => `(()=>{ const W = G.Walk, w = W.w, p = const BOAT = `G => { const m = G.Walk.w.T.moor(); return m ? [m.x, m.z] : [] }`; const RENT = `G => { const p = G.Walk.p, r = G.Rent.near(p.x, p.z, 1500).sort((a, b) => Math.hypot(a.x - p.x, a.z - p.z) - Math.hypot(b.x - p.x, b.z - p.z))[0]; return r ? [r.x + r.dx * (r.b + 9), r.z + r.dz * (r.b + 9)] : [] }`; // a car parked against the house wall; the player gets in and out at the side of the wall: out onto free floor round the car, not into the wall -const OUT = `(()=>{ const T = G.Town, W = G.Walk, w = W.w, p = W.p, D = G.Drive, R = G.dbg.ROAD, z = R.ln[1], x = w.T.lx / 2 + 30, g = T.ground(x, z, w.meta.spawn.y + 2); W.night = false; if (p.fly) W.act('fly'); +const OUT = `(()=>{ const T = G.Town, W = G.Walk, w = W.w, p = W.p, D = G.Drive, R = G.dbg.ROAD, z = R.ln[1], x = w.T.lx / 2 + 30, g = G.Ground.at(x, z, w.meta.spawn.y + 2); W.night = false; if (p.fly) W.act('fly'); const c = T.build('car', x, z, Math.PI / 2, { solo: 1, seed: 4242 }); c.y = g; c.mode = 'park'; c.v = 0; c.empty = true; T.place(c, 0); G.Occ.add(c, 'fit'); const B = G.Occ.box(c.units[0]), wz = Math.floor(c.z + Math.max(-B[2], B[3]) + .6), st = w.bid(G.MAT.stone, '#9a9a9a'); for (let a = -12; a <= 12; a++) for (let y = g; y < g + 12; y++) w.set(Math.floor(c.x) + a, y, wz, st); // a wall right at the driver's door, a touch off the body Object.assign(p, { x: c.x, y: g, z: c.z - 5 }); D.enter({ u: c, n: 0, now: 1 }); D.exit(1); c.mode = 'park'; c.v = 0; for (let i = 0; i < 30; i++) W.update(1 / 60); diff --git a/tools/shots/469.mjs b/tools/shots/469.mjs index 46d84cf5a..799c06a71 100644 --- a/tools/shots/469.mjs +++ b/tools/shots/469.mjs @@ -11,8 +11,8 @@ export default { start: [...game({ ...TOWN, site: ['town'] }, 20261129, true), LIB, day, 'wait:4000'], shots: [ { name: 'heli-lean', note: 1, title: 'The SWAT helicopter flies by the physics of a helicopter: nose down to speed up, leaning into the turn', steps: [ - `(()=>{ const W = G.Walk, L = G.Law, w = W.w, p = W.p; L.reset(w); W.keys = {}; const [gx, gz] = L.gate(); p.fly = false; p.x = gx + 6; p.z = gz; p.y = L.ground(p.x, p.z) + 1; TK(1); - L.wanted(); L.sta = L.station(p.x, p.z); L.next = 1e9; const H = L.copter('in'); L.H = H; H.x = p.x + 700; H.z = p.z + 300; H.y = L.ground(H.x, H.z) + 115; G.Rotor.init(H); + `(()=>{ const W = G.Walk, L = G.Law, w = W.w, p = W.p; L.reset(w); W.keys = {}; const [gx, gz] = L.gate(); p.fly = false; p.x = gx + 6; p.z = gz; p.y = G.Ground.road(p.x, p.z) + 1; TK(1); + L.wanted(); L.sta = L.station(p.x, p.z); L.next = 1e9; const H = L.copter('in'); L.H = H; H.x = p.x + 700; H.z = p.z + 300; H.y = G.Ground.road(H.x, H.z) + 115; G.Rotor.init(H); return TK(40, () => H.v > 90 && Math.abs(H.bank) > .08) })()`.replace(/\n/g, ' '), '(()=>{ const H = G.Law.H; return shoot(H.x, H.y + 4, H.z, 38, H.yaw + Math.PI / 2, 2) + "," + [H.v, H.tilt, H.bank].map(v => v.toFixed(2)) })()', LOAD, 'wait:9000'] }, { name: 'heli-hover', note: 1, title: "Over the player it brakes nose up and hovers on its pilot's controls, then the team goes down the ropes", steps: [ diff --git a/tools/shots/479.mjs b/tools/shots/479.mjs index fb3840d47..3d5950910 100644 --- a/tools/shots/479.mjs +++ b/tools/shots/479.mjs @@ -9,7 +9,7 @@ const GO = `(()=>{ const { Walk, Span } = G, w = Walk.w, T = w.T, p = Walk.p; Wa window._br = { X0: R.px[m], Z0: R.pz[m], ux, uz, ry, nx: Math.cos(ry), nz: -Math.sin(ry), w: R.w, y: B.y }; p.fly = true; p.x = R.px[m]; p.z = R.pz[m]; p.y = B.y + 30; p.vy = 0; return 1 })()`; const THERE = `until:(()=>{ const { X0, Z0, ux, uz, nx, nz } = window._br, L = G.Town.loaded; return L(X0, Z0) && L(X0 + nx * 24, Z0 + nz * 24) && L(X0 + ux * 60, Z0 + uz * 60) && L(X0 - ux * 40, Z0 - uz * 40) })()`; const TAXI = `(()=>{ const { Walk, Town, Taxi, Navi, Occ, RNG } = G, { X0, Z0, ux, uz, ry, nx, nz, w: hw } = window._br; - if (Taxi.car) Taxi.drop(); const c = Town.build('car_taxi', X0, Z0, ry, { R: RNG(5), seed: 5, solo: true, col: '#f2c230' }); Object.assign(c, { mode: 'taxi', ghost: true, v: 8, edge: false, dir: 1, empty: false, hid: 0 }); c.x = X0; c.z = Z0; c.yaw = ry; c.y = Taxi.gnd(X0, Z0); Town.place(c, 0); Town.cars.push(c); + if (Taxi.car) Taxi.drop(); const c = Town.build('car_taxi', X0, Z0, ry, { R: RNG(5), seed: 5, solo: true, col: '#f2c230' }); Object.assign(c, { mode: 'taxi', ghost: true, v: 8, edge: false, dir: 1, empty: false, hid: 0 }); c.x = X0; c.z = Z0; c.yaw = ry; c.y = G.Ground.road(X0, Z0); Town.place(c, 0); Town.cars.push(c); Taxi.car = c; Taxi.st = 3; c.lo = hw - c.wid / 2 - 3; const l = Navi.line([[X0 - ux * 40, Z0 - uz * 40], [X0 + ux * 120, Z0 + uz * 120]]), L = c.lg = { k: 'go', l, s: 40, V: 30, o: [X0 - ux * 40, Z0 - uz * 40] }; const ah = Town.ahead; Town.ahead = () => 1e9; let side = 0; try { for (let f = 0; f < 50; f++) { c.rnd = { o: hw + 6, s: L.s + 200 }; c.wt = 0; c.v = Math.max(c.v, 6); const q = Occ.pose(c); Taxi.drive0(c, 1 / 30); Occ.keep(c, q, 1 / 30); side = Math.max(side, (c.x - X0) * nx + (c.z - Z0) * nz); } } finally { Town.ahead = ah; } diff --git a/tools/shots/485.mjs b/tools/shots/485.mjs index 2eec1013f..fb1351458 100644 --- a/tools/shots/485.mjs +++ b/tools/shots/485.mjs @@ -6,11 +6,11 @@ const W = +(process.env.SW || 1280), H = +(process.env.SH || 800); // a parked car near the spawn with four doors; a townsperson walks to its back door on the kerb side, the door opens and they get in by it // (Drive.board: the same steps as the player's); f: how far into the step (0 standing beside the car, 1 in the seat) const DOOR = f => `(()=>{ const p = G.Walk.p, D = G.Drive, w = G.Walk.w; let c = window.DC; - if (!c) { let at = null; for (let r = 8; r < 90 && !at; r += 3) for (let a = 0; a < 6.28 && !at; a += .2) { const x = p.x + Math.sin(a) * r, z = p.z + Math.cos(a) * r, k = w.T.road(x, z), g = G.Town.ground(x, z, p.y + 4); if (k === 1 && g != null && Math.abs(g - p.y) < 6) at = [x, g, z]; } + if (!c) { let at = null; for (let r = 8; r < 90 && !at; r += 3) for (let a = 0; a < 6.28 && !at; a += .2) { const x = p.x + Math.sin(a) * r, z = p.z + Math.cos(a) * r, k = w.T.road(x, z), g = G.Ground.at(x, z, p.y + 4); if (k === 1 && g != null && Math.abs(g - p.y) < 6) at = [x, g, z]; } if (!at) return 'no road'; c = G.Town.build('car', at[0], at[2], 0, { solo: 1, seed: 7 }); if (!c) return 'no car'; c.mode = 'park'; c.v = 0; c.y = at[1]; G.Town.place(c, 0); G.Town.cars.push(c); } window.DC = c; const u = c.units[0]; let o = window.DP || G.Town.ppl.slice().sort((a, b) => Math.hypot(a.x - c.x, a.z - c.z) - Math.hypot(b.x - c.x, b.z - c.z))[0]; if (!o || Math.hypot(o.x - c.x, o.z - c.z) > 60) { o = G.Life.person(G.RNG(5), 'a', 'f', '#c89a7a', c.x, c.z); if (!o) return 'nobody'; G.Town.ppl.push(o); } window.DP = o; - const [x, z] = D.beside(u, 3, 3), at = [x, G.Town.ground(x, z, u.y + 2) || u.y, z], q = D.body(u, ...D.seatAB(u, 3), 2), B = D.board(u, 3, 'in', at, q), [, b] = D.seatAB(u, 3), sd = b >= 0 ? 1 : -1; + const [x, z] = D.beside(u, 3, 3), at = [x, G.Ground.at(x, z, u.y + 2) || u.y, z], q = D.body(u, ...D.seatAB(u, 3), 2), B = D.board(u, 3, 'in', at, q), [, b] = D.seatAB(u, 3), sd = b >= 0 ? 1 : -1; const s = Math.sin(u.yaw), k = Math.cos(u.yaw), ex = u.x + k * sd * 22 - s * 14, ez = u.z - s * sd * 22 - k * 14; eyeAt(ex, u.y + 9, ez, u.x, u.y + 3, u.z); return run(Math.round(${f} * B.T * 30), () => { B.t = 0; D.through(B, ${f} * B.T, o); o.yaw = Math.atan2(q[0] - o.x, q[2] - o.z); o.gait = 0; }) && 'car ' + u.id + ' door ' + D.door(u, 3); })()`.replace(/\n/g, ' '); const scene = (id, shots) => ({ id, w: W, h: H, dpr: 1, start, shots }); diff --git a/tools/shots/486.mjs b/tools/shots/486.mjs new file mode 100644 index 000000000..0750f21c8 --- /dev/null +++ b/tools/shots/486.mjs @@ -0,0 +1,16 @@ +// build 486: one ground for everybody (src/game/71_ground.js). The link road from the home street of seed 20261139 climbs to the town along +// x = -643 as a ramp of shaped blocks (build 435), 1.2 cells up every 10. A parked car and a police car are put on it by the one call every +// vehicle now makes (Ground.road): they stand on the sloped top, 81.75 and 86.25 cells high, pitched with the road. +import { game, TOWN, LOAD } from './lib.mjs'; +const AIM = (x, z, dy, tx, tz, tdy) => `(()=>{ const W=G.Walk,p=W.p,T=W.w.T; W.night=false; if(W.ride){ G.Drive.exit(true); G.Drive.end(); } if(W.tp) W.act('tp'); if(!p.fly) W.act('fly'); const y=T.at(${x},${z})+${dy}, ty=T.at(${tx},${tz})+${tdy}; Object.assign(p,{x:${x},y,z:${z},vy:0,yaw:Math.atan2(${tx}-(${x}),${tz}-(${z})),pitch:Math.atan2(ty-y,Math.hypot(${tx}-(${x}),${tz}-(${z})))}); return 1 })()`; +const SETTLE = [LOAD, 'wait:20000', LOAD, 'wait:8000']; +const PUT = `(()=>{ const { Town, Ground } = G; Town.carT = 1e9; if (window._gr) return 'kept'; + const car = (id, x, z, seed) => { const c = Town.build(id, x, z, Math.PI, { solo: 1, seed }); if (!c) return null; c.mode = 'park'; c.v = 0; c.y = Ground.road(x, z); Town.place(c, 0); Town.cars.push(c); return c; }; + const a = car('car', -645.5, -212, 7), b = car('car_police', -640.5, -250, 3); + window._gr = [a, b]; return [a && a.y.toFixed(2), b && b.y.toFixed(2)].join(' ') })()`.replace(/\n/g, ' '); +export default { + start: game(TOWN, 20261139), + shots: [ + { name: 'ground-ramp', note: 1, title: 'One ground for everybody: a parked car and a police car put on the road ramp stand on its sloped top, pitched with the road, both by the same finder', steps: [AIM(-606, -231, 5, -643, -231, 1.5), ...SETTLE, PUT, 'wait:4000'] }, + ], +}; diff --git a/tools/slip.test.mjs b/tools/slip.test.mjs index a41a200ec..3d972b2e5 100644 --- a/tools/slip.test.mjs +++ b/tools/slip.test.mjs @@ -70,7 +70,7 @@ const PAGE = () => { const setup = (back, keep) => { if (keep) { if (W.ride) { D.exit(true); D.end(); } H.reset(); for (const c of T.cars.slice()) if (c.own || c.slip) T.cars.splice(T.cars.indexOf(c), 1); S.boats = []; for (const i of w.insts.slice()) if (i && /^(car_xl|trailer_boat)$/.test(i.id)) w.removeInst(i); } else clear(); const [x0, z0, dx, dz] = B, yaw = Math.atan2(-dx, -dz), p = W.p; - const at = k => { const x = x0 - dx * k + .5, z = z0 - dz * k + .5; return [x, T.ground(x, z, top(Math.floor(x), Math.floor(z)) + 3), z]; }; + const at = k => { const x = x0 - dx * k + .5, z = z0 - dz * k + .5; return [x, G.Ground.at(x, z, top(Math.floor(x), Math.floor(z)) + 3), z]; }; const it = G.Lib.byId.car_xl, cl = it.model.size[2] / 4, kc = back + TL + 1 + cl / 2, C = at(kc); const a = D.own('car_xl', null, C[0], C[1], C[2], yaw, 0); a.y = C[1]; T.place(a, 0); Object.assign(p, { x: C[0] + 4, y: C[1], z: C[2], vy: 0, yaw, pitch: -.1 }); D.enter({ u: a, n: 0, now: 1 }); D.end(); if (keep) { a.y += 2; run(60); } // on a slope it settles onto its wheels const n = ((Math.round(-yaw / (Math.PI / 4)) % 8) + 8) % 8, r = n >> 1, h = n & 1, ti = G.Lib.byId.trailer_boat, Q = at(back + TL / 2 + .3), q0 = G.dbg.makeInst(ti, 0, 0, 0, r, null, 0, h), d = q0.d; diff --git a/tools/split.test.mjs b/tools/split.test.mjs index eafdec5d1..8cf317132 100644 --- a/tools/split.test.mjs +++ b/tools/split.test.mjs @@ -4,8 +4,10 @@ // a network row, damage) must have one code path that every actor goes through: the player, a resident, a taxi, the police, a repair crew. // An actor adds agency (what it wants and when), never a second way of doing the thing itself. // This test is the inventory of the second ways still in the code and a ratchet that only lets their number go down: -// 1. every entry of SPLIT names a function that still exists (when one is folded into the shared way, delete its entry and lower the number); -// 2. the detectors (loops that scan down a column for the ground, places that integrate gravity) count no more than the ratchet says; +// 1. every entry of SPLIT names a function that still exists (when one is folded into the shared way, delete its entry and lower the number), +// and a function that was folded in (`gone`) does not come back; +// 2. the detectors (loops that scan down a column for the ground, places that integrate gravity) count no more than the ratchet says; the +// file of a shared way is not counted (`home`: the column is walked in 71_ground.js and nowhere else); // 3. tools/rules/ratchet.json: split. and split. may only go down. import fs from 'node:fs'; import path from 'node:path'; @@ -33,14 +35,11 @@ const SPLIT = { }, ground: { seen: 'the height a foot or a wheel stands on (ground, floor, bridge deck)', - rule: 'one finder of the standing height at (x, z) near y, for people, animals and wheels alike', - shared: [], - apart: [ - '72_fauna.js:drop — animals', '74_town.js:ground — town cars and walkers', '76_life.js:floor — residents at home and outside', - '78_drive.js:floor — the player\'s vehicle', '78_roll.js:ground — rolling things', '79_arm.js:floor — crane loads', - '79_art.js:floor — dropped art', '79_law.js:ground — police', '79_taxi.js:gnd — the taxi', '79_train.js:floor — station platforms', - '79_farm.js:ground — farm machines', - ], + rule: 'Ground (71_ground.js): the one finder of the standing height at (x, z) near y, for people, animals and wheels alike; who asks says what it needs as data (GROUND)', + shared: ['71_ground.js:at', '71_ground.js:drop', '71_ground.js:top', '71_ground.js:sky', '71_ground.js:land', '71_ground.js:under', '71_ground.js:road', '71_ground.js:cell', '71_ground.js:roof', '71_ground.js:room'], + apart: [], + // the finders that were folded in (build 486): none may come back under its old name + gone: ['72_fauna.js:drop', '74_town.js:ground', '78_drive.js:floor', '78_drive.js:bed', '78_roll.js:top', '78_rotor.js:floor', '79_arm.js:floor', '79_art.js:floor', '79_law.js:ground', '79_taxi.js:gnd'], }, free: { seen: 'whether a body can stand or move to a place', @@ -78,7 +77,10 @@ const SPLIT = { }; // detectors: second ways that are written inline rather than as a named function const DETECT = { - scan: { seen: 'loops that walk down a column to find the ground', re: /\b[yY]--\)\s*\{?\s*if\s*\(\s*!?\s*\w*\.?(?:solid|get)\(/g }, + // (until build 486 it only saw a loop whose body began with `if (w.solid(` and counted 18; all of those went into Ground. The wider form + // also sees a body that begins with `const id = w.get(`: the 7 left ask something else of the column (the soil under plants, the water + // over a swimmer, every floor of it for a jump) and are next) + scan: { seen: 'loops that walk down a column of blocks', home: '71_ground.js', re: /for \((?:let )?\w*[yY]\w* ?=[^;\n]*;[^;\n]*; ?\w*[yY]\w*--\)[^\n]{0,120}?(?:solid\(|\.get\()/g }, gravity: { seen: 'places that integrate gravity', re: /\bvy\s*-=\s*[^;\n]*\b(?:dt|q|h)\b/g }, }; @@ -86,10 +88,26 @@ const bad = [], say = s => bad.push(s), fn = (f, n) => new RegExp(`^\\s*${n}\\s* const count = {}; for (const [k, C] of Object.entries(SPLIT)) { for (const e of [...C.shared, ...C.apart]) { const [f, n] = e.split(' — ')[0].split(':'); if (!files.includes(f)) say(`${k}: ${f} does not exist (${e})`); else if (!fn(f, n)) say(`${k}: no function ${n} in ${f}: if it went into the shared way, delete its entry in SPLIT and lower split.${k}`); } + for (const e of C.gone || []) { const [f, n] = e.split(':'); if (files.includes(f) && fn(f, n)) say(`${k}: ${f} has a function ${n} again: it was folded into the shared way (${C.shared[0].split(':')[0]}), go through that`); } count['split.' + k] = C.apart.length; } +// A function that is gone is not called from the tools either. Tests and screenshot recipes reach the game through `G` and one-letter +// names of its modules (`const T = G.Town` … `T.ground(x, z, y)`), which no check of the game's own source sees: build 486 took +// Town.ground away and a test that still called it through such a name failed only in the whole run. +{ + const here = path.join(ROOT, 'tools'), root = ROOT, tools = [...fs.readdirSync(here).filter(f => f.endsWith('.mjs')).map(f => path.join(here, f)), ...fs.readdirSync(path.join(here, 'shots')).filter(f => f.endsWith('.mjs')).map(f => path.join(here, 'shots', f))]; + const own = new Set(['split.test.mjs', 'ground.test.mjs']); // this list, and the old finders kept as the reference the new one is compared with + for (const [k, C] of Object.entries(SPLIT)) for (const e of C.gone || []) { + const [f, n] = e.split(':'), M = f.slice(3, -3).replace(/^./, c => c.toUpperCase()); + for (const t of tools) { + if (own.has(path.basename(t))) continue; + const s = fs.readFileSync(t, 'utf8'), names = new Set([M, ...[...s.matchAll(new RegExp(`(? m[1])]); + for (const a of names) if (new RegExp(`(? f.endsWith('.js')).sort(), stem = f => f.replace(/\.js$/, ''); +const strip = s => s.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:\\])\/\/[^\n]*/g, '$1').replace(/'(?:[^'\\\n]|\\.)*'/g, "''").replace(/"(?:[^"\\\n]|\\.)*"/g, '""').replace(/`(?:[^`\\]|\\.)*`/g, '``'); +// the names each file declares at the top level, and the names each file needs while it loads: what stands on a top-level line of the +// form `const A = …;` outside any function body (an arrow or a `function` on the line is code that runs later; an object literal that +// goes on over the next lines holds methods, which run later too) +const decl = {}, owner = {}, need = {}; +for (const f of files) { + const s = strip(fs.readFileSync(path.join(SRC, f), 'utf8')); decl[f] = new Set(); need[f] = new Map(); + for (const m of s.matchAll(/^(?:const|let|var|function\*?|class|async function)\s+([A-Za-z_$][\w$]*)/gm)) { decl[f].add(m[1]); if (!owner[m[1]]) owner[m[1]] = f; } + for (const m of s.matchAll(/^(?:const|let|var)\s+([^\n]*);[ \t]*$/gm)) { + const line = m[1]; if (/=>|\bfunction\b|\bclass\b/.test(line)) continue; + for (const part of line.split(/,\s*(?=[A-Za-z_$][\w$]*\s*=)/)) { const q = /^([A-Za-z_$][\w$]*)\s*=(.*)$/s.exec(part.trim()); if (!q) continue; decl[f].add(q[1]); if (!owner[q[1]]) owner[q[1]] = f; need[f].set(q[1], q[2]); } + } +} +const names = Object.keys(owner), isName = new Set(names); +const tools = []; +for (const d of ['tools', 'tools/gen']) for (const f of fs.readdirSync(path.join(ROOT, d))) if (f.endsWith('.mjs')) tools.push(path.join(d, f)); +const bad = []; let lists = 0; +for (const t of tools) { + if (t === 'tools/srclist.test.mjs') continue; + const text = fs.readFileSync(path.join(ROOT, t), 'utf8'); + for (const m of text.matchAll(/\[\s*((?:'\d\d_\w+'\s*,\s*){2,}'\d\d_\w+'\s*,?)\s*\]/g)) { + const list = [...m[1].matchAll(/'(\d\d_\w+)'/g)].map(q => q[1] + '.js').filter(f => files.includes(f)); if (list.length < 3 || list[0] !== '00_util.js') continue; // (a list that does not begin at the bottom adds files to a loader of its own: tools/gen/load.mjs and the like) + lists++; + const have = new Set(); for (const f of list) for (const n of decl[f]) have.add(n); + for (const f of list) for (const [name, expr] of need[f]) for (const q of expr.matchAll(/(?= f) continue; // (a name of a later file is not there yet when this line runs: not a load-time need) + if (new RegExp('(? /^const (clamp|lerp|TAU)\b/.test(l)).join('\n') + '\nvar Town = {}, Kin = {}, DRIVE_STEP = 2; // (78_drive.js)\n' + fs.readFileSync(path.join(ROOT, 'src/game/78_susp.js'), 'utf8') + '\nglobalThis.X = { Susp, SUSP, Town, Kin };', ctx); -const { Susp, SUSP, Town, Kin } = ctx.X; +vm.runInContext(VM_FAST + fs.readFileSync(path.join(ROOT, 'src/game/00_util.js'), 'utf8').split('\n').filter(l => /^const (clamp|lerp|TAU)\b/.test(l)).join('\n') + '\nvar Ground = {}, Kin = {}, DRIVE_STEP = 2; // (71_ground.js, 73_kin.js, 78_drive.js)\n' + fs.readFileSync(path.join(ROOT, 'src/game/78_susp.js'), 'utf8') + '\nglobalThis.X = { Susp, SUSP, Ground, Kin };', ctx); +const { Susp, SUSP, Ground, Kin } = ctx.X; let H = () => 0; // the height of the column under (x, z): the ground is the top of it -Town.ground = (x, z, y) => { const h = H(Math.floor(x), Math.floor(z)); return h > Math.floor(y) + 3 ? null : h < y - 72 ? null : h; }; +Ground.at = (x, z, y) => { const h = H(Math.floor(x), Math.floor(z)); return h > Math.floor(y) + 3 ? null : h < y - 72 ? null : h; }; Kin.geo = () => ({ wb: 13, af: 6, ar: -7, st: true }); // a saloon of the game (4.5 m long, 2.3 m wide) const car = (o = {}) => ({ x: .5, y: 0, z: 0, yaw: 0, v: 0, len: 22.5, wid: 11.5, it: { model: { size: [46, 29, 90] } }, veh: { wr: o.wr || 6 }, ...o }); const deg = r => r * 180 / Math.PI; diff --git a/tools/taxi.pose.test.mjs b/tools/taxi.pose.test.mjs index c067fa308..3098de3d1 100644 --- a/tools/taxi.pose.test.mjs +++ b/tools/taxi.pose.test.mjs @@ -30,7 +30,7 @@ const r = await page.evaluate(() => { const { Walk, Town, Taxi, Navi, Nav, Law, RNG } = G, p = Walk.p, x0 = Math.round(p.x), z0 = Math.round(G.dbg.ROAD.ln[1]), out = { fin: true, hit: 0, maxdx: 0 }; Taxi.drop(); const c = Town.build('car_taxi', x0, z0, Math.PI / 2, { R: RNG(7), seed: 7, solo: true, col: '#f2c230' }); - Object.assign(c, { mode: 'taxi', ghost: true, v: 10, edge: false, dir: 1, empty: false, hid: 0 }); c.y = Law.ground(x0, z0); Town.place(c, 0); Town.cars.push(c); + Object.assign(c, { mode: 'taxi', ghost: true, v: 10, edge: false, dir: 1, empty: false, hid: 0 }); c.y = Ground.road(x0, z0); Town.place(c, 0); Town.cars.push(c); Taxi.car = c; Taxi.st = 3; const l = Navi.line([[x0 - 20, z0], [x0 + 300, z0]]), L = c.lg = { k: 'go', l, s: 20, V: 40, o: [x0 - 20, z0] }; // somebody standing on the way just ahead of the bumper diff --git a/tools/truss.test.mjs b/tools/truss.test.mjs index a8e744ce0..66da8e92f 100644 --- a/tools/truss.test.mjs +++ b/tools/truss.test.mjs @@ -32,7 +32,7 @@ const r = await page.evaluate(async () => { const X0 = R.px[m], Z0 = R.pz[m]; out.at = [Math.round(X0), Math.round(Z0)]; out.w = R.w; p.fly = true; p.x = X0; p.z = Z0; p.y = B.y + 30; for (let t = performance.now(); performance.now() - t < 90000;) { w.update(p.x, p.y, p.z, 200, w.fx, w.fz); if (w._idle && Town.loaded(X0 + nx * 20, Z0 + nz * 20) && Town.loaded(X0 + ux * 40, Z0 + uz * 40) && Town.loaded(X0 - ux * 40, Z0 - uz * 40)) break; await new Promise(r => setTimeout(r, 0)); } - const gnd = (x, z) => Taxi.gnd(x, z); + const gnd = (x, z) => G.Ground.road(x, z); const taxi = () => { const c = Town.build('car_taxi', X0, Z0, ry, { R: RNG(5), seed: 5, solo: true, col: '#f2c230' }); Object.assign(c, { mode: 'taxi', ghost: true, v: 0, edge: false, dir: 1, empty: false, hid: 0 }); c.x = X0; c.z = Z0; c.yaw = ry; c.y = gnd(X0, Z0); c.tilt = 0; Town.place(c, 0); return c; }; // 1. the guard and the body agree, across the deck { const c = taxi(), y = c.y; diff --git a/tools/ugcop.test.mjs b/tools/ugcop.test.mjs index 5148129b1..18c9c09f6 100644 --- a/tools/ugcop.test.mjs +++ b/tools/ugcop.test.mjs @@ -34,7 +34,7 @@ try { window.load = () => { const p = W.p, t = performance.now(); w.fogR = Math.min(w.fogR || 200, 200); for (; !w._idle && performance.now() - t < 8000;) w.update(p.x, p.y, p.z, 200, w.fx, w.fz); return w._idle; }; window.mhTop = () => { const p = W.p; if (W.ride) { L.let = 1; G.Drive.exit(true); L.let = 0; } L.reset(w); U0.reset(); p.fly = false; p.x = M.x; p.z = M.z; p.y = U.gy + .5; p.vy = 0; p.yaw = 0; p.pitch = -.3; return 1; }; // a patrol car at (dx, dz) from the manhole, its two officers out on the street - window.crew = (dx, dz) => { const c = L.make('car_police', M.x + dx, M.z + dz, 0); c.y = L.ground(c.x, c.z); G.Town.cars.push(c); L.cars.push(c); L.out(c); return L.cops.length; }; + window.crew = (dx, dz) => { const c = L.make('car_police', M.x + dx, M.z + dz, 0); c.y = G.Ground.road(c.x, c.z); G.Town.cars.push(c); L.cars.push(c); L.out(c); return L.cops.length; }; window.downs = () => L.cops.filter(o => U0.under(o)).length; return { name: s.name, gw: w.opt && w.opt.gw, M: [M.x, M.z, M.how], gy: U.gy, F: U.F, n: [U.E.length, U.M.length, U.C.length, U.B.length, U.Q.length] }; })()`); diff --git a/tools/villa.test.mjs b/tools/villa.test.mjs index fe8b3bdff..fb8462bda 100644 --- a/tools/villa.test.mjs +++ b/tools/villa.test.mjs @@ -15,7 +15,7 @@ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const [GH, GL] = /GENV = \{ gh: (\d+), gl: (\d+)/.exec(fs.readFileSync(path.join(ROOT, 'src/game/75_seed.js'), 'utf8')).slice(1).map(Number); const stub = new Proxy(function () {}, { get: (t, k) => k === Symbol.toPrimitive ? () => '' : stub, apply: () => stub, construct: () => stub }); const ctx = vm.createContext({ console, Math, document: stub, navigator: stub, localStorage: stub, window: stub, MutationObserver: stub, Image: stub, performance, BUILD: { n: 0 }, sessionStorage: stub, setInterval: () => 0, clearInterval: () => 0, addEventListener: () => 0, location: stub, fetch: stub, requestAnimationFrame: () => 0, tr: (ru, en) => en, trk: (ru, en) => en, loc: s => s, setTimeout }); -const code = ['00_util', '08_mats', '10_vox', '30_world', '31_terrain', '32_land', '33_flora', '33_species', '40_house', '41_villa', '42_plan'].map(f => fs.readFileSync(path.join(ROOT, 'src/game', f + '.js'), 'utf8')).join('\n'); +const code = ['00_util', '08_mats', '09_core', '10_vox', '30_world', '31_terrain', '32_land', '33_flora', '33_species', '40_house', '41_villa', '42_plan'].map(f => fs.readFileSync(path.join(ROOT, 'src/game', f + '.js'), 'utf8')).join('\n'); vm.runInContext(VM_FAST + code + '\n;globalThis.T = { genPlan, buildHouse, HTYPES, GY, FH, MAT };', ctx); const { genPlan, buildHouse, HTYPES, GY, FH } = ctx.T; const TYPES = Object.keys(HTYPES).filter(k => HTYPES[k].vil), AREAS = [0, 80, 120, 160, 240, 320, 480]; diff --git a/tools/wasm/town.prof.mjs b/tools/wasm/town.prof.mjs index bc462e6a6..b20ddf319 100644 --- a/tools/wasm/town.prof.mjs +++ b/tools/wasm/town.prof.mjs @@ -1,5 +1,5 @@ // Where the CPU goes in a busy town, standing and riding fast through it (taxi: the real car physics of every driver), with the -// voxel physics (Drive.worldFree / buried / free, Town.ground, Land.get / solid) and the meshing measured apart. +// voxel physics (Drive.worldFree / buried / free, Ground.at, Land.get / solid) and the meshing measured apart. // node tools/wasm/town.prof.mjs [html] (html: best a MINIFY=0 build, so the names in the CPU profile are readable) // Env: SEED (20261139), SEC (seconds per scenario, 10), SCEN (town,taxi), OUT (/tmp/townprof), PRE (JS run in the page first: an A/B // switch such as "G.Core.on=false"), NOWORK=1 (no far-tile workers), TAXI (x,z of the mark relative to the player, default 700,500). @@ -40,7 +40,7 @@ await page.evaluate(() => { for (const k of ['meshChunk', 'gen', 'buildGroup', 'remesh', 'lodPump', 'lodTile', 'lightTick', 'modPump', 'populate', 'trim']) wrap(L, k, 'land.' + k); wrap(L, 'update', 'land.update (rest)'); for (const k of ['worldFree', 'buried', 'free', 'glide', 'shove', 'phys', 'pilot', 'step', 'horse']) wrap(D, k, 'drive.' + k); - for (const k of ['ground']) wrap(G.Town, k, 'town.' + k); + for (const k of ['at']) wrap(G.Ground, k, 'ground.' + k); for (const k of ['update', 'tick']) wrap(G.Town, k, 'town.' + k); wrap(G.Taxi, 'drive', 'taxi.drive'); wrap(G.Pilot, 'step', 'pilot.step'); for (const o of ['Folk', 'Fauna', 'Life', 'Sim', 'Law', 'Fix', 'Lock']) if (G[o]) for (const k of ['tick', 'update']) wrap(G[o], k, o.toLowerCase() + '.' + k); @@ -80,22 +80,22 @@ const measure = async (name, js) => { for (const [k, v] of m.list.slice(0, 30)) out.push(` ${k.slice(0, 54).padEnd(54)} ${v.toFixed(0).padStart(6)} ms ${(v / fr).toFixed(3).padStart(8)} ms/frame`); console.log(out.join('\n')); report[name] = { r, st, wall, top: m.list.slice(0, 60) }; }; -// the voxel queries of the frames as they came (Land.solid, Land.get, Town.ground with their arguments), recorded for a few seconds of +// the voxel queries of the frames as they came (Land.solid, Land.get, Ground.at with their arguments), recorded for a few seconds of // the scenario and replayed on the frozen world: ns per query now and with other lookups of the column const QBENCH = async () => page.evaluate(async () => { - const w = G.Walk.w, L = Object.getPrototypeOf(w), T = G.Town, S0 = L.solid, G0 = L.get, TG = T.ground, rs = [], rg = [], rt = []; + const w = G.Walk.w, L = Object.getPrototypeOf(w), T = G.Ground, S0 = L.solid, G0 = L.get, TG = T.at, rs = [], rg = [], rt = []; L.solid = function (x, y, z) { if (rs.length < 3e6) rs.push(x, y, z, this.veh | 0); return S0.call(this, x, y, z); }; L.get = function (x, y, z) { if (rg.length < 3e6) rg.push(x, y, z); return G0.call(this, x, y, z); }; - T.ground = function (x, z, y) { if (rt.length < 3e6) rt.push(x, z, y, w.veh | 0); return TG.call(this, x, z, y); }; + T.at = function (x, z, y, o) { if (!o && rt.length < 3e6) rt.push(x, z, y, w.veh | 0); return TG.call(this, x, z, y, o); }; const t0 = performance.now(); let n = 0; while (performance.now() - t0 < 4000) { const t1 = performance.now(); n += RUN(() => performance.now() - t1 > 250, 1); await new Promise(r => setTimeout(r, 20)); } - L.solid = S0; L.get = G0; T.ground = TG; + L.solid = S0; L.get = G0; T.at = TG; const S = Int32Array.from(rs), Gq = Int32Array.from(rg), Tq = Float64Array.from(rt), res = { frames: n, solid: S.length / 4 / n, get: Gq.length / 3 / n, ground: Tq.length / 4 / n }; // replays: the same calls in the same order, best of 5 const best = f => { let b = 1e9, r; for (let k = 0; k < 5; k++) { const t = performance.now(); r = f(); b = Math.min(b, performance.now() - t); } return [b, r]; }; const play = () => ({ solid: best(() => { let s = 0; for (let i = 0; i < S.length; i += 4) { w.veh = S[i + 3]; s += w.solid(S[i], S[i + 1], S[i + 2]) ? 1 : 0; } w.veh = 0; return s; }), get: best(() => { let s = 0; for (let i = 0; i < Gq.length; i += 3) s += w.get(Gq[i], Gq[i + 1], Gq[i + 2]); return s; }), - ground: best(() => { let s = 0; for (let i = 0; i < Tq.length; i += 4) { w.veh = Tq[i + 3]; const g = T.ground(Tq[i], Tq[i + 1], Tq[i + 2]); s += g == null ? -1 : g; } w.veh = 0; return s; }), + ground: best(() => { let s = 0; for (let i = 0; i < Tq.length; i += 4) { w.veh = Tq[i + 3]; const g = T.at(Tq[i], Tq[i + 1], Tq[i + 2]); s += g == null ? -1 : g; } w.veh = 0; return s; }), }); const ns = (r, len, k) => +(r[0] * 1e6 / (len / k)).toFixed(1); const show = (p, tag) => ({ tag, solid: ns(p.solid, S.length, 4), get: ns(p.get, Gq.length, 3), ground: ns(p.ground, Tq.length, 4), sums: [p.solid[1], p.get[1], p.ground[1]] }); diff --git a/version.json b/version.json index 6249b7217..61a5a7418 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"n":485,"t":1796246743425,"kb":1765,"h":"e6733ecd43e6ca1211abd9b5d3549f3452c86610c4e6364e9e71b93669e9ad64","hc":"bdfe3eeb4384ebfc92d210e23c128a83f452166be4cf795acd4da0648d5db745","len":4068447,"items":1180,"notes":[[485,["🚪 Такси открывает ту дверь, через которую ты садишься: тебе даётся свободное заднее место с твоей стороны, а вход и выход идут через проём двери этого места, а не сквозь кузов. Это общее правило для всех: жители у своих машин, полицейские и строители тоже садятся и выходят через дверь своего места, и она открывается","🧩 Всё, что движется, теперь в одном реестре: у каждого тела одна физика и один агент, а особая работа такси, полиции и ремонтников идёт задачей поверх общего агента, без обхода правил. Что ещё идёт в обход, записано с тредом-владельцем, и тест-храповик не даёт этому расти","🔎 Одно понятие, один путь: тест нашёл 67 мест, где одно и то же (посадка в транспорт, высота земли под ногой, «помещается ли тело», падение, сидение, маршрут, строка по сети, урон) сделано отдельно для разных персонажей. Их число теперь может только уменьшаться, посадка уже общая","🏷️ Код спрашивает, что за транспорт (летает, плавает, на нём едут верхом), а не как он называется: 74 архетипа вместо списков имён","🧪 Новые тесты: movers.test (реестр и храповик), split.test (вторые пути по понятиям), board.test (дверь своего места, место в такси с твоей стороны)"],["🚪 A taxi opens the door you get in by: you are given the free back seat on your side, and getting in and out goes through the opening of that seat's door rather than through the body. One rule for everybody: residents at their cars, police officers and builders also get in and out by the door of their seat, and it opens","🧩 Everything that moves is in one register now: each body has one physics and one agent, and the special jobs of taxis, police and repair crews are tasks on top of the shared agent, never a way round the rules. Whatever still takes a way round is listed with the thread that owns it, and a ratchet test keeps it from growing","🔎 One concept, one way: a test found 67 places where the same thing (getting into a vehicle, the ground under a foot, whether a body fits, falling, sitting, a route, a network row, damage) is done separately for different characters. Their number can only go down now; getting in is already shared","🏷️ The code asks what a vehicle is (flies, floats, ridden) instead of what it is called: 74 archetypes instead of lists of names","🧪 New tests: movers.test (the register and the ratchet), split.test (second ways by concept), board.test (the door of your seat, the taxi seat on your side)"]],[484,["📱 Телефоны получили помощника: мир теперь строит отдельный поток и на телефоне. Раньше поток считался как 400 МБ памяти, и телефону не доставалось ни одного; замер показал 30–45 МБ","⏱️ На iPhone с медленным в 4 раза процессором (эмуляция) земля вокруг после прыжка на 60 км готова за 11 с вместо 40, а вся земля за 53 с (раньше не успевала), памяти занято не больше","🧠 Поток живёт в классе памяти своей страницы: на телефоне он держит меньше планов городов, а картинка та же байт в байт. Если страница падала от нехватки памяти, потоков становится меньше","🏘️ Исправлено: города с жилыми посёлками (сборка 481) не строились, план такого города падал с ошибкой, и земля над ним не появлялась. Новый тест находит любое необъявленное имя во всём коде игры"],["📱 Phones got a helper: the world is now built by a thread of its own on a phone too. A thread used to be counted as 400 MB of memory, so a phone got none; measured, it takes 30–45 MB","⏱️ On an iPhone with a 4× slower processor (emulated) the land around after a 60 km jump is ready in 11 s instead of 40, and the whole land in 53 s (it did not finish before), with no more memory taken","🧠 The thread lives in its page's memory class: on a phone it keeps fewer town plans, and the picture is the same byte for byte. A page that ran out of memory gets fewer threads","🏘️ Fixed: towns with estates (build 481) were not built, the plan of such a town threw an error and the land over it never came. A new test finds any undeclared name in the whole code of the game"]],[483,["🚤 Катер снова спускается с прицепа: кнопка 🚤 в машине пропала, когда лодки стали проверять воду под каждой клеткой корпуса. Теперь место за кормой спрашивают у самого катера, а не у коробки его длины"],["🚤 The motorboat launches from its trailer again: the 🚤 button in the car had gone when hulls began to check the water under every cell of the body. The place astern is now asked of the boat itself, not of a box of its length"]],[482,["🧨 Взрыв мощности 14 на телефоне берёт разом около 145 МБ памяти вместо 235 и оставляет после себя около 55 МБ вместо 100: списки клеток теперь в плотных массивах, запись для отмены занимает 10 байт на клетку вместо 16, а шаг отмены больше не держит в памяти все клетки шара. Воронка та же, одна отмена по-прежнему возвращает всё"],["🧨 A power-14 blast on a phone takes about 145 MB at once instead of 235 and keeps about 55 MB instead of 100: the cell lists are packed arrays now, the undo record takes 10 bytes a cell instead of 16, and the undo step no longer holds every cell of the ball in memory. The crater is the same, and one undo still brings everything back"]],[481,["🏘️ Посёлки с участками, как их строят по брошюрам и нормам: таунхаусы с парковкой у входа и садиком за домом (как в Дубае и Подмосковье), таунхаусы с гаражами на заднем проезде (США, английские мьюз), террасы с палисадниками и общими стоянками (Англия, Нидерланды, Германия), американский пригород с газонами и гаражами, коттеджный посёлок за глухим забором с охраной","🥒 Садовые товарищества (СНТ): участки от 6 соток на гравийных проездах, сетка между соседями, дом в 5 м от улицы, грядки, теплица, сарай, туалет в глубине участка, бочка для воды. У ворот сторожка, правление, водонапорная башня, пожарный пруд, контейнерная площадка и магазин","🥕 Немецкие садовые колонии (Kleingarten) с беседками, где не живут, клубом с пивной и стоянкой у входа, и кампунги: дома на сваях среди фруктовых деревьев, молельный дом и лавка","🚪 У каждого посёлка ворота с улицы, внутри проезды, тупики не длиннее 150 м с разворотной площадкой, общие площадки у въезда: детская, бассейн, клуб, сквер, гостевая парковка. Каждый дом на одну семью, и в нём живут люди","🗺️ Где они стоят: деревня в новых мирах может целиком быть таким посёлком (примерно каждая пятая), а небольшие посёлки встают и в городах у улицы, тогда боковые проезды упираются в их забор. Размеры настоящие: участок не ужимается, чтобы влезть","🧪 Новый тест estate.test: все 8 типов строятся, размеры участков по нормам, от ворот можно дойти до каждой двери, тупики и куски заборов в пределах, улицы города остаются одной сетью. Это в новых мирах"],["🏘️ Estates of plots, laid out the way the brochures and the norms build them: townhouses with a parking pad at the door and a garden behind (as in Dubai and around Moscow), rear-loaded townhouses with garages on a back alley (US, British mews), terraces with front gardens and parking courts (England, the Netherlands, Germany), an American suburb of lawns and garages, a cottage village behind a solid fence with a guard","🥒 Dacha partnerships (СНТ): plots from 600 m² on gravel passages, mesh fences between neighbours, the house 5 m back from the lane, beds, a greenhouse, a shed, the privy at the back, a water barrel. At the gate a guard hut, the board, a water tower, a fire pond, a bin pad and a shop","🥕 German allotments (Kleingarten) with arbours nobody lives in, a club house with a pub and a car park at the entrance, and kampongs: houses on stilts among fruit trees, a prayer hall and a warung","🚪 Every estate has a gate from a street, lanes inside, dead ends no longer than 150 m with a turning head, and the shared things at the entrance: a playground, a pool, a club, a green, guest parking. Every house is one family’s, and people live in it","🗺️ Where they stand: a village of a new world may be one whole estate (about one in five), and small estates stand inside towns beside a street, where the side lanes now end at their fence. The sizes are real: a plot is never squeezed to fit","🧪 A new test, estate.test: all 8 kinds are built, plot sizes keep to the norms, every door can be walked to from the gate, dead ends and fence pieces stay within bounds, a town’s streets stay one network. This is in new worlds"]],[480,["🌾 Трава, цветы, посевы и камыш отклоняются от идущего целым стеблем: стебель наклоняется вокруг своего основания, кубики остаются кубиками и не растягиваются. Высокие растения (подсолнух, камыш до 12 клеток) наклоняются целиком, вместе с головкой и листьями","👣 Пешком тоже остаются следы: под ногами трава ложится, земля темнеет, на снегу, песке и грязи остаются отпечатки. Тропу оставляют все, кто достаточно тяжёл: ты, жители, рабочие, полиция, собаки, олени и коровы, но не кошка и не курица. В игре вдвоём твои следы видят все","🌱 Всё примятое отрастает: следы ног, колеи, след днища машины, сбитые грибы, борозды плуга и покос возвращаются по мировым часам, по клетке в минуту, пока земля не станет ровно такой, какой её создал генератор","🧪 Новый тест trample.test: наклон стебля проверяется настоящим шейдером (расстояния между вершинами не меняются), следы ног, отрастание и полное возвращение земли к сгенерированной"],["🌾 Grass, flowers, crops and reeds lean away from a walker as whole stems: a stem tilts about its foot, its cubes stay cubes and never stretch. Tall plants (a sunflower, reeds up to 12 cells) tilt as one piece, head and leaves with them","👣 Walking leaves a trail too: the grass under the feet lies down and the ground darkens, snow, sand and mud keep footprints. Everyone heavy enough leaves one: you, townsfolk, workers, police, dogs, deer and cows, but not a cat or a hen. Playing together, everyone sees your trail","🌱 Whatever is pressed grows back: footprints, ruts, the mark of a car body, knocked mushrooms, plough furrows and mown strips return by the world clock, a cell a minute, until the land is exactly what the generator made","🧪 A new test, trample.test: the tilt of a stem is checked with the real shader (no distance between its vertices changes), foot trails, regrowth and the land coming back to the generated one"]]]} \ No newline at end of file +{"n":486,"t":1796249082460,"kb":1765,"h":"4e201998bd5057cbe271fa54259dc3d828829ff7787964d2178e7dda97958a03","hc":"da840edb6eb63f98488523464f1ac7e799cba6f324c0a1513848fc7ec1d8e87f","len":4067272,"items":1180,"notes":[[486,["🌍 Одна земля для всех: высоту, на которой стоит нога, лапа или колесо, теперь находит один модуль. Раньше её искали 11 модулей, каждый по-своему, и ещё 18 циклов шли вниз по колонке блоков вручную: один знал наклон пандуса, другой нет, один проваливался сквозь воду, другой вставал на неё","🛣️ Что видно: перевернувшаяся машина лежит на наклонной поверхности пандуса, а не на клетке под ним; полицейская машина и грузовик ремонтников, появляясь под настилом моста, встают на настил, а не внутрь него (как уже умело такси); самолёт и машина вдали больше не считают траву и колосья полом","🧪 Новый тест ground.test: смысл на колонках, собранных вручную (ступень, стена, яма, брод, пандус, пещера под холмом, плита без места под ней), и 60 000 случайных колонок, где новый модуль обязан ответить так же, как прежние искатели, сохранённые в тесте дословно","🔎 Мест, где одно и то же сделано по-разному, стало 45 вместо 67. Счётчик циклов по колонке стал строже и нашёл ещё 7, которых раньше не видел: они следующие"],["🌍 One ground for everybody: the height a foot, a paw or a wheel stands on is now found by one module. Eleven modules used to look for it, each in its own way, and eighteen more loops walked down a column of blocks by hand: one knew the slope of a ramp and the next did not, one fell through water and the next stood on it","🛣️ What shows: a car that rolled over lies on the sloped top of a ramp, not on the cell under it; a police car and a builders' truck that appear under a bridge deck stand on the deck, not inside it (as the taxi already did); a plane and a car far away no longer take grass and crops for a floor","🧪 A new test, ground.test: the meaning on columns built by hand (a step, a wall, a pit, a ford, a ramp, a cave under a hill, a slab with no room under it), and 60,000 random columns where the new module must answer as the old finders did, kept in the test word for word","🔎 The places where one thing is done in different ways are down to 45 from 67. The counter of column loops got stricter and found 7 more it had not seen: they are next"]],[485,["🚪 Такси открывает ту дверь, через которую ты садишься: тебе даётся свободное заднее место с твоей стороны, а вход и выход идут через проём двери этого места, а не сквозь кузов. Это общее правило для всех: жители у своих машин, полицейские и строители тоже садятся и выходят через дверь своего места, и она открывается","🧩 Всё, что движется, теперь в одном реестре: у каждого тела одна физика и один агент, а особая работа такси, полиции и ремонтников идёт задачей поверх общего агента, без обхода правил. Что ещё идёт в обход, записано с тредом-владельцем, и тест-храповик не даёт этому расти","🔎 Одно понятие, один путь: тест нашёл 67 мест, где одно и то же (посадка в транспорт, высота земли под ногой, «помещается ли тело», падение, сидение, маршрут, строка по сети, урон) сделано отдельно для разных персонажей. Их число теперь может только уменьшаться, посадка уже общая","🏷️ Код спрашивает, что за транспорт (летает, плавает, на нём едут верхом), а не как он называется: 74 архетипа вместо списков имён","🧪 Новые тесты: movers.test (реестр и храповик), split.test (вторые пути по понятиям), board.test (дверь своего места, место в такси с твоей стороны)"],["🚪 A taxi opens the door you get in by: you are given the free back seat on your side, and getting in and out goes through the opening of that seat's door rather than through the body. One rule for everybody: residents at their cars, police officers and builders also get in and out by the door of their seat, and it opens","🧩 Everything that moves is in one register now: each body has one physics and one agent, and the special jobs of taxis, police and repair crews are tasks on top of the shared agent, never a way round the rules. Whatever still takes a way round is listed with the thread that owns it, and a ratchet test keeps it from growing","🔎 One concept, one way: a test found 67 places where the same thing (getting into a vehicle, the ground under a foot, whether a body fits, falling, sitting, a route, a network row, damage) is done separately for different characters. Their number can only go down now; getting in is already shared","🏷️ The code asks what a vehicle is (flies, floats, ridden) instead of what it is called: 74 archetypes instead of lists of names","🧪 New tests: movers.test (the register and the ratchet), split.test (second ways by concept), board.test (the door of your seat, the taxi seat on your side)"]],[484,["📱 Телефоны получили помощника: мир теперь строит отдельный поток и на телефоне. Раньше поток считался как 400 МБ памяти, и телефону не доставалось ни одного; замер показал 30–45 МБ","⏱️ На iPhone с медленным в 4 раза процессором (эмуляция) земля вокруг после прыжка на 60 км готова за 11 с вместо 40, а вся земля за 53 с (раньше не успевала), памяти занято не больше","🧠 Поток живёт в классе памяти своей страницы: на телефоне он держит меньше планов городов, а картинка та же байт в байт. Если страница падала от нехватки памяти, потоков становится меньше","🏘️ Исправлено: города с жилыми посёлками (сборка 481) не строились, план такого города падал с ошибкой, и земля над ним не появлялась. Новый тест находит любое необъявленное имя во всём коде игры"],["📱 Phones got a helper: the world is now built by a thread of its own on a phone too. A thread used to be counted as 400 MB of memory, so a phone got none; measured, it takes 30–45 MB","⏱️ On an iPhone with a 4× slower processor (emulated) the land around after a 60 km jump is ready in 11 s instead of 40, and the whole land in 53 s (it did not finish before), with no more memory taken","🧠 The thread lives in its page's memory class: on a phone it keeps fewer town plans, and the picture is the same byte for byte. A page that ran out of memory gets fewer threads","🏘️ Fixed: towns with estates (build 481) were not built, the plan of such a town threw an error and the land over it never came. A new test finds any undeclared name in the whole code of the game"]],[483,["🚤 Катер снова спускается с прицепа: кнопка 🚤 в машине пропала, когда лодки стали проверять воду под каждой клеткой корпуса. Теперь место за кормой спрашивают у самого катера, а не у коробки его длины"],["🚤 The motorboat launches from its trailer again: the 🚤 button in the car had gone when hulls began to check the water under every cell of the body. The place astern is now asked of the boat itself, not of a box of its length"]],[482,["🧨 Взрыв мощности 14 на телефоне берёт разом около 145 МБ памяти вместо 235 и оставляет после себя около 55 МБ вместо 100: списки клеток теперь в плотных массивах, запись для отмены занимает 10 байт на клетку вместо 16, а шаг отмены больше не держит в памяти все клетки шара. Воронка та же, одна отмена по-прежнему возвращает всё"],["🧨 A power-14 blast on a phone takes about 145 MB at once instead of 235 and keeps about 55 MB instead of 100: the cell lists are packed arrays now, the undo record takes 10 bytes a cell instead of 16, and the undo step no longer holds every cell of the ball in memory. The crater is the same, and one undo still brings everything back"]],[481,["🏘️ Посёлки с участками, как их строят по брошюрам и нормам: таунхаусы с парковкой у входа и садиком за домом (как в Дубае и Подмосковье), таунхаусы с гаражами на заднем проезде (США, английские мьюз), террасы с палисадниками и общими стоянками (Англия, Нидерланды, Германия), американский пригород с газонами и гаражами, коттеджный посёлок за глухим забором с охраной","🥒 Садовые товарищества (СНТ): участки от 6 соток на гравийных проездах, сетка между соседями, дом в 5 м от улицы, грядки, теплица, сарай, туалет в глубине участка, бочка для воды. У ворот сторожка, правление, водонапорная башня, пожарный пруд, контейнерная площадка и магазин","🥕 Немецкие садовые колонии (Kleingarten) с беседками, где не живут, клубом с пивной и стоянкой у входа, и кампунги: дома на сваях среди фруктовых деревьев, молельный дом и лавка","🚪 У каждого посёлка ворота с улицы, внутри проезды, тупики не длиннее 150 м с разворотной площадкой, общие площадки у въезда: детская, бассейн, клуб, сквер, гостевая парковка. Каждый дом на одну семью, и в нём живут люди","🗺️ Где они стоят: деревня в новых мирах может целиком быть таким посёлком (примерно каждая пятая), а небольшие посёлки встают и в городах у улицы, тогда боковые проезды упираются в их забор. Размеры настоящие: участок не ужимается, чтобы влезть","🧪 Новый тест estate.test: все 8 типов строятся, размеры участков по нормам, от ворот можно дойти до каждой двери, тупики и куски заборов в пределах, улицы города остаются одной сетью. Это в новых мирах"],["🏘️ Estates of plots, laid out the way the brochures and the norms build them: townhouses with a parking pad at the door and a garden behind (as in Dubai and around Moscow), rear-loaded townhouses with garages on a back alley (US, British mews), terraces with front gardens and parking courts (England, the Netherlands, Germany), an American suburb of lawns and garages, a cottage village behind a solid fence with a guard","🥒 Dacha partnerships (СНТ): plots from 600 m² on gravel passages, mesh fences between neighbours, the house 5 m back from the lane, beds, a greenhouse, a shed, the privy at the back, a water barrel. At the gate a guard hut, the board, a water tower, a fire pond, a bin pad and a shop","🥕 German allotments (Kleingarten) with arbours nobody lives in, a club house with a pub and a car park at the entrance, and kampongs: houses on stilts among fruit trees, a prayer hall and a warung","🚪 Every estate has a gate from a street, lanes inside, dead ends no longer than 150 m with a turning head, and the shared things at the entrance: a playground, a pool, a club, a green, guest parking. Every house is one family’s, and people live in it","🗺️ Where they stand: a village of a new world may be one whole estate (about one in five), and small estates stand inside towns beside a street, where the side lanes now end at their fence. The sizes are real: a plot is never squeezed to fit","🧪 A new test, estate.test: all 8 kinds are built, plot sizes keep to the norms, every door can be walked to from the gate, dead ends and fence pieces stay within bounds, a town’s streets stay one network. This is in new worlds"]]]} \ No newline at end of file