Add GameDojo game environments (part 2)
Browse filesUpload the local game environment package into environments/. English runtime text only. Bytecode caches and internal handoff paths are not included.
This view is limited to 50 files because it contains too many changes. See raw diff
- environments/games/web/games/minecraft_remake/index.html +86 -0
- environments/games/web/games/minecraft_remake/manifest.json +79 -0
- environments/games/web/games/minecraft_remake/play.js +338 -0
- environments/games/web/games/minecraft_remake/style.css +44 -0
- environments/games/web/games/nfsmw_remake/compact_actions.json +269 -0
- environments/games/web/games/nfsmw_remake/cops.js +158 -0
- environments/games/web/games/nfsmw_remake/draw.js +166 -0
- environments/games/web/games/nfsmw_remake/game.js +167 -0
- environments/games/web/games/nfsmw_remake/index.html +7 -0
- environments/games/web/games/nfsmw_remake/manifest.json +55 -0
- environments/games/web/games/nfsmw_remake/modes_drag.js +113 -0
- environments/games/web/games/nfsmw_remake/modes_knockout.js +57 -0
- environments/games/web/games/nfsmw_remake/modes_pursuit.js +437 -0
- environments/games/web/games/nfsmw_remake/modes_speedtrap.js +62 -0
- environments/games/web/games/nfsmw_remake/modes_tollbooth.js +41 -0
- environments/games/web/games/nfsmw_remake/nfscore.js +237 -0
- environments/games/web/games/nfsmw_remake/page.js +135 -0
- environments/games/web/games/nfsmw_remake/renderer3d.js +385 -0
- environments/games/web/games/nfsmw_remake/rivals.js +66 -0
- environments/games/web/games/nfsmw_remake/scripted.js +147 -0
- environments/games/web/games/quake2_remake/compact_actions.json +165 -0
- environments/games/web/games/quake2_remake/draw.js +95 -0
- environments/games/web/games/quake2_remake/game.js +292 -0
- environments/games/web/games/quake2_remake/index.html +7 -0
- environments/games/web/games/quake2_remake/input-hold.js +30 -0
- environments/games/web/games/quake2_remake/manifest.json +45 -0
- environments/games/web/games/quake2_remake/q2core.js +264 -0
- environments/games/web/games/quake2_remake/q2monsters.js +1181 -0
- environments/games/web/games/quake2_remake/q2player.js +852 -0
- environments/games/web/games/quake2_remake/renderer3d.js +503 -0
- environments/games/web/games/quake2_remake/scripted.js +308 -0
- environments/games/web/games/sekiro_remake/app3d.js +78 -0
- environments/games/web/games/sekiro_remake/compact_actions.json +1135 -0
- environments/games/web/games/sekiro_remake/draw.js +70 -0
- environments/games/web/games/sekiro_remake/game.js +0 -0
- environments/games/web/games/sekiro_remake/index.html +7 -0
- environments/games/web/games/sekiro_remake/manifest.json +33 -0
- environments/games/web/games/sekiro_remake/renderer3d.js +666 -0
- environments/games/web/games/sekiro_remake/style3d.css +1 -0
- environments/games/web/games/soulknight_remake/compact_actions.json +176 -0
- environments/games/web/games/soulknight_remake/draw.js +853 -0
- environments/games/web/games/soulknight_remake/game.js +0 -0
- environments/games/web/games/soulknight_remake/index.html +7 -0
- environments/games/web/games/soulknight_remake/manifest.json +31 -0
- environments/games/web/games/terraria_remake/arena.js +9 -0
- environments/games/web/games/terraria_remake/art/scenes.js +119 -0
- environments/games/web/games/terraria_remake/body_adventurer.js +147 -0
- environments/games/web/games/terraria_remake/bosses/brain_of_cthulhu.js +131 -0
- environments/games/web/games/terraria_remake/bosses/eater_of_worlds.js +170 -0
- environments/games/web/games/terraria_remake/bosses/eye_of_cthulhu.js +125 -0
environments/games/web/games/minecraft_remake/index.html
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 6 |
+
<link rel="icon" href="data:,">
|
| 7 |
+
<title>Minecraft · Voxel Arena</title>
|
| 8 |
+
<link rel="stylesheet" href="style.css">
|
| 9 |
+
</head>
|
| 10 |
+
<body data-game="minecraft_remake">
|
| 11 |
+
<main>
|
| 12 |
+
<header>
|
| 13 |
+
<div><h1>Minecraft · Voxel Arena</h1>
|
| 14 |
+
<p>Java Edition 1.21 combat subset · Six boss arenas · Three public difficulty tiers · ModernGL rendering · 60 Hz · Recording and replay · Rules <code id="rules">minecraft-arena@7</code></p></div>
|
| 15 |
+
<a href="../../index.html">Back to Game Lobby</a>
|
| 16 |
+
</header>
|
| 17 |
+
<div class="layout">
|
| 18 |
+
<section>
|
| 19 |
+
<div class="stage" id="stage">
|
| 20 |
+
<img id="view" width="854" height="480" alt="Game screen rendered by the local Python server" draggable="false">
|
| 21 |
+
<div id="capture" tabindex="0" aria-label="Game screen: click to use keyboard and mouse controls"></div>
|
| 22 |
+
<div id="overlay"><div id="overlay-text">Select a boss to start</div></div>
|
| 23 |
+
<div id="offline" hidden>
|
| 24 |
+
<h2>Local game server is not running</h2>
|
| 25 |
+
<p>This Minecraft remake uses Python simulation and ModernGL rendering. Start the server from the project root:</p>
|
| 26 |
+
<pre id="launch">python games/prototype/bossbench/play_server.py</pre>
|
| 27 |
+
<button id="retry">Retry connection</button>
|
| 28 |
+
</div>
|
| 29 |
+
</div>
|
| 30 |
+
<div class="toolbar">
|
| 31 |
+
<button id="start" class="primary">Start Challenge / Restart</button>
|
| 32 |
+
<button id="pause">Pause</button>
|
| 33 |
+
<button id="step">Step (200 ms)</button>
|
| 34 |
+
<button id="demo">Scripted Demo</button>
|
| 35 |
+
<button id="export">Export Replay</button>
|
| 36 |
+
<button id="import">Import and Replay</button>
|
| 37 |
+
<input id="file" type="file" accept=".json,application/json" hidden>
|
| 38 |
+
</div>
|
| 39 |
+
<div class="mobile" aria-label="Touch controls">
|
| 40 |
+
<button data-key="W">W forward</button><button data-key="A">A left</button><button data-key="S">S backward</button><button data-key="D">D right</button>
|
| 41 |
+
<button data-key="Space">Jump</button><button data-key="Shift">Sprint</button><button data-key="LMB">Attack</button><button data-key="RMB">Draw bow</button>
|
| 42 |
+
<button data-wheel="1">Switch weapon</button>
|
| 43 |
+
</div>
|
| 44 |
+
<p id="status" role="status">Connecting to local server…</p>
|
| 45 |
+
<p class="note">Every 200 ms, your input becomes a standard action packet: six 33 ms key windows, each with up to four keys plus mouse movement. The packet goes to the same simulation as <code>make_policy_env</code>. Pausing stops the world. Replays use <code>bossbench/policy-replay@1</code>; import simulates each packet again and checks the final-state hash. Scripted Demo is a reference controller that reads internal state, not a trained model; it does not start RL training.</p>
|
| 46 |
+
</section>
|
| 47 |
+
<aside>
|
| 48 |
+
<div>
|
| 49 |
+
<h2>Select Challenge</h2>
|
| 50 |
+
<label for="case">Boss</label><select id="case"></select>
|
| 51 |
+
<label for="weapon">Starting weapon (two hotbar slots; switch with the mouse wheel)</label>
|
| 52 |
+
<select id="weapon"><option value="sword" selected>Sword</option><option value="bow">Bow</option></select>
|
| 53 |
+
<label for="camera">View</label>
|
| 54 |
+
<select id="camera"><option value="first" selected>First person</option><option value="third">Third person</option></select>
|
| 55 |
+
<label for="difficulty">Difficulty (three public tiers)</label>
|
| 56 |
+
<select id="difficulty"><option value="easy">Easy</option><option value="normal" selected>Normal</option><option value="hard">Hard</option></select>
|
| 57 |
+
<p class="hint" id="tier-hint">Reference script target: about one minute</p>
|
| 58 |
+
<label for="seed">Seed</label><input id="seed" type="number" min="0" max="4294967295" value="1" step="1">
|
| 59 |
+
</div>
|
| 60 |
+
<div class="panel" id="hudpanel">
|
| 61 |
+
<div class="row"><span>Time</span><b id="time">0.0 s</b></div>
|
| 62 |
+
<div class="row"><span>Native rate</span><b id="hz">60 Hz</b></div>
|
| 63 |
+
<div class="row"><span>Difficulty</span><b id="tier">—</b></div>
|
| 64 |
+
<div class="row"><span>Health</span><b id="php">20 / 20</b></div>
|
| 65 |
+
<div class="row"><span>Weapon</span><b id="wpn">Sword</b></div>
|
| 66 |
+
<div class="row"><span>Boss</span><b id="bname">—</b></div>
|
| 67 |
+
<div class="row"><span>Boss Health</span><b id="bhp">—</b></div>
|
| 68 |
+
<div class="row"><span>Phase</span><b id="bphase">—</b></div>
|
| 69 |
+
</div>
|
| 70 |
+
<h2>Controls</h2>
|
| 71 |
+
<dl id="controls">
|
| 72 |
+
<dt>W A S D</dt><dd>Move (one direction at a time; W takes priority)</dd>
|
| 73 |
+
<dt>Mouse</dt><dd>Click the screen to lock the mouse. Move left or right to turn and up or down to pitch the view; there is no aim assist. Arrow keys also turn and pitch.</dd>
|
| 74 |
+
<dt>Space / Shift</dt><dd>Jump / Sprint (while holding W)</dd>
|
| 75 |
+
<dt>left mouse button / J</dt><dd>Sword: each press swings once. Let the cooldown fill before swinging again; a falling attack at full charge deals a 1.5× critical hit. With a bow equipped, this is a punch.</dd>
|
| 76 |
+
<dt>right mouse button / K</dt><dd>Bow: hold to draw and release to fire (one second for a fully charged critical arrow)</dd>
|
| 77 |
+
<dt>Mouse wheel / Q / 1 2</dt><dd>Switch between sword and bow (switching resets the attack cooldown)</dd>
|
| 78 |
+
<dt>Esc / P</dt><dd>Pause; losing window focus pauses automatically</dd>
|
| 79 |
+
</dl>
|
| 80 |
+
</aside>
|
| 81 |
+
</div>
|
| 82 |
+
<footer></footer>
|
| 83 |
+
</main>
|
| 84 |
+
<script src="play.js"></script>
|
| 85 |
+
</body>
|
| 86 |
+
</html>
|
environments/games/web/games/minecraft_remake/manifest.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/game-manifest@1",
|
| 3 |
+
"engine": "python",
|
| 4 |
+
"game": "minecraft_remake",
|
| 5 |
+
"title": "Minecraft: Voxel Arena",
|
| 6 |
+
"dimension": "3d",
|
| 7 |
+
"native_hz": 60,
|
| 8 |
+
"max_seconds": {
|
| 9 |
+
"3d/minecraft_iron_golem": 300,
|
| 10 |
+
"3d/minecraft_zombie": 90,
|
| 11 |
+
"3d/minecraft_ender_dragon": 300,
|
| 12 |
+
"3d/minecraft_wither": 300,
|
| 13 |
+
"3d/minecraft_warden": 300,
|
| 14 |
+
"3d/minecraft_skeleton": 300,
|
| 15 |
+
"3d/minecraft_zombie_leader": 300
|
| 16 |
+
},
|
| 17 |
+
"renderer": "moderngl",
|
| 18 |
+
"rules": "minecraft-arena@7",
|
| 19 |
+
"tiers": {
|
| 20 |
+
"easy": 0.0,
|
| 21 |
+
"normal": 0.5,
|
| 22 |
+
"hard": 1.0
|
| 23 |
+
},
|
| 24 |
+
"tiers_source": "prototype/bossbench/mc4d.py TIERS (read by bossbench.make_policy_env and the play server)",
|
| 25 |
+
"cases": [
|
| 26 |
+
"3d/minecraft_iron_golem",
|
| 27 |
+
"3d/minecraft_ender_dragon",
|
| 28 |
+
"3d/minecraft_wither",
|
| 29 |
+
"3d/minecraft_warden",
|
| 30 |
+
"3d/minecraft_skeleton",
|
| 31 |
+
"3d/minecraft_zombie_leader"
|
| 32 |
+
],
|
| 33 |
+
"retired_cases": {
|
| 34 |
+
"3d/minecraft_zombie": "2026-11-10 user request: remove the green-skinned grappler. It remains registered in FORMAL_CASES under frozen @4 rules, but is excluded from the benchmark list (scope.BENCH_RETIRED). Its media was moved to archived history."
|
| 35 |
+
},
|
| 36 |
+
"formal_cases": [
|
| 37 |
+
"3d/minecraft_iron_golem",
|
| 38 |
+
"3d/minecraft_zombie",
|
| 39 |
+
"3d/minecraft_ender_dragon",
|
| 40 |
+
"3d/minecraft_wither"
|
| 41 |
+
],
|
| 42 |
+
"formal_note": "FORMAL_CASES (prototype/bossbench/scope.py): their rules stay exactly @4 (difficulty tables, behaviour, arena, kit, time limit, observation layout); d = 0.5 of each was evaluated 16 times in reports/mc-bow-comparison-20261020. 3d/minecraft_zombie stays exactly as in @4 and is reported \"uncalibrated\" against the tier windows (1.4-3.2 s fights); the user decided on 2026-11-04 to keep it at @4 (no re-calibration).",
|
| 43 |
+
"round_20261102_scenes": [
|
| 44 |
+
"3d/minecraft_iron_golem",
|
| 45 |
+
"3d/minecraft_ender_dragon",
|
| 46 |
+
"3d/minecraft_wither"
|
| 47 |
+
],
|
| 48 |
+
"round_20261103_scenes": [
|
| 49 |
+
"3d/minecraft_warden",
|
| 50 |
+
"3d/minecraft_skeleton",
|
| 51 |
+
"3d/minecraft_zombie_leader"
|
| 52 |
+
],
|
| 53 |
+
"kits": {
|
| 54 |
+
"diamond": "diamond sword 7 + full diamond armor 20 / 8 (flung giant, green-skinned grappler, purple-breathing flyer, triple-headed floating cannon, shockwave beast)",
|
| 55 |
+
"iron": "iron sword 6 + full iron armor 15 / 0 (mobile archer, summoner)",
|
| 56 |
+
"source": "prototype/bossbench/mc4d.py KITS / SCENE_KIT (the same on every tier)"
|
| 57 |
+
},
|
| 58 |
+
"options": {
|
| 59 |
+
"weapon": [
|
| 60 |
+
"sword",
|
| 61 |
+
"bow"
|
| 62 |
+
],
|
| 63 |
+
"camera": [
|
| 64 |
+
"first",
|
| 65 |
+
"third"
|
| 66 |
+
]
|
| 67 |
+
},
|
| 68 |
+
"play_page": "web/games/minecraft_remake/index.html",
|
| 69 |
+
"server": "prototype/bossbench/play_server.py",
|
| 70 |
+
"launch": "powershell -NoProfile -ExecutionPolicy Bypass -File web/games/minecraft_remake/run_server.ps1",
|
| 71 |
+
"url": "http://127.0.0.1:8765/",
|
| 72 |
+
"simulation": [
|
| 73 |
+
"prototype/bossbench/mc4d.py",
|
| 74 |
+
"prototype/bossbench/mcskin.py",
|
| 75 |
+
"prototype/bossbench/rig.py"
|
| 76 |
+
],
|
| 77 |
+
"scripted_controller": "bossbench.mc_scripted.scripted(case) -> packet text (prototype/bossbench/mc_scripted.py)",
|
| 78 |
+
"golden": "prototype/tests/mc4d_golden_20261107_arena7.json (rules minecraft-arena@7); frozen guards: mc4d_golden_20261103_arena6.json (@6), mc4d_golden_20261103.json (@5), mc4d_golden_20261102.json (@4), mc4d_golden_20261031.json (@3), mc4d_golden.json (@1, MD5 e778e5d30f6941ab44a91c86da8bd115)"
|
| 79 |
+
}
|
environments/games/web/games/minecraft_remake/play.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Minecraft remake play page client: samples real keyboard/mouse input into standard 200 ms packets
|
| 2 |
+
(6 hold sets of <= 4 keys + mouse dx dy dz), sends them to the local Python play server, and plays back the
|
| 3 |
+
6 frames per packet that the real ModernGL renderer returns. The page itself simulates nothing. */
|
| 4 |
+
(function () {
|
| 5 |
+
'use strict';
|
| 6 |
+
const $ = s => document.querySelector(s);
|
| 7 |
+
const KEYS = ['W', 'A', 'S', 'D', 'Space', 'Shift', 'J', 'K', 'L', 'Q', 'E', 'R', 'LMB', 'RMB'];
|
| 8 |
+
const CODE = {KeyW: 'W', KeyA: 'A', KeyS: 'S', KeyD: 'D', Space: 'Space', ShiftLeft: 'Shift', ShiftRight: 'Shift',
|
| 9 |
+
KeyJ: 'J', KeyK: 'RMB'};
|
| 10 |
+
const SUB_MS = 200 / 6;
|
| 11 |
+
const view = $('#view'), capture = $('#capture');
|
| 12 |
+
let API = '', sid = null, meta = null, state = null, running = false, mode = 'idle'; // idle | play | demo | replay
|
| 13 |
+
let down = new Set(), taps = new Set(), mouse = [0, 0, 0], subs = [], timer = null;
|
| 14 |
+
let queue = [], sending = false, clock0 = 0, subsDone = 0;
|
| 15 |
+
let frames = [], lastShown = 0, replayQueue = [], replayExpect = null, pending = false, epoch = 0;
|
| 16 |
+
|
| 17 |
+
function status(text) { $('#status').textContent = text; }
|
| 18 |
+
function overlay(text) {
|
| 19 |
+
$('#overlay').hidden = !text;
|
| 20 |
+
$('#overlay-text').textContent = text || '';
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
// ------------------------------------------------------------------ server connection
|
| 24 |
+
async function api(path, body) {
|
| 25 |
+
const opt = body === undefined ? {} : {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(body)};
|
| 26 |
+
const r = await fetch(API + path, opt);
|
| 27 |
+
const data = await r.json();
|
| 28 |
+
if (!r.ok) throw Error(data.error || r.statusText);
|
| 29 |
+
return data;
|
| 30 |
+
}
|
| 31 |
+
async function connect() {
|
| 32 |
+
const bases = location.protocol.startsWith('http') && location.port === '8765' ? [''] :
|
| 33 |
+
['', 'http://127.0.0.1:8765'];
|
| 34 |
+
for (const base of bases) {
|
| 35 |
+
try {
|
| 36 |
+
const r = await fetch(base + '/api/meta', {cache: 'no-store'});
|
| 37 |
+
if (!r.ok) continue;
|
| 38 |
+
meta = await r.json();
|
| 39 |
+
API = base;
|
| 40 |
+
$('#offline').hidden = true;
|
| 41 |
+
$('#rules').textContent = meta.rules;
|
| 42 |
+
const sel = $('#case');
|
| 43 |
+
if (!sel.options.length) for (const c of meta.cases) {
|
| 44 |
+
const o = document.createElement('option');
|
| 45 |
+
o.value = c.id; o.textContent = c.name; sel.appendChild(o);
|
| 46 |
+
}
|
| 47 |
+
tierControl();
|
| 48 |
+
$('#hz').textContent = meta.native_hz + ' Hz';
|
| 49 |
+
status('Connected to local server (' + meta.rules + ' · ' + meta.native_hz + ' Hz). Select a boss, then click Start Challenge.');
|
| 50 |
+
overlay('Select a boss to start');
|
| 51 |
+
return true;
|
| 52 |
+
} catch (e) { /* try next */ }
|
| 53 |
+
}
|
| 54 |
+
$('#offline').hidden = false;
|
| 55 |
+
overlay('');
|
| 56 |
+
status('Could not connect. Start the local Python server using the command shown on screen.');
|
| 57 |
+
return false;
|
| 58 |
+
}
|
| 59 |
+
$('#retry').onclick = connect;
|
| 60 |
+
|
| 61 |
+
// ------------------------------------------------------------------ public difficulty: three tiers (2026-11-02)
|
| 62 |
+
// Rebuilt from the server's declaration (mc4d.TIERS via /api/meta), the same source make_policy_env reads, so the
|
| 63 |
+
// page can never offer a difficulty the public interface does not. Each option shows the meeting's target window.
|
| 64 |
+
function tierControl() {
|
| 65 |
+
const sel = $('#difficulty'), keep = sel.value || meta.default_tier;
|
| 66 |
+
if (!meta.tiers || !meta.tiers.length) return;
|
| 67 |
+
sel.textContent = '';
|
| 68 |
+
for (const t of meta.tiers) {
|
| 69 |
+
const o = document.createElement('option');
|
| 70 |
+
o.value = t.name; o.textContent = t.label + '(d=' + t.difficulty + ')';
|
| 71 |
+
o.selected = t.name === keep; sel.appendChild(o);
|
| 72 |
+
}
|
| 73 |
+
tierHint();
|
| 74 |
+
}
|
| 75 |
+
function tierInfo(name) { return meta && meta.tiers ? meta.tiers.find(t => t.name === name) : null; }
|
| 76 |
+
function tierHint() {
|
| 77 |
+
const t = tierInfo($('#difficulty').value);
|
| 78 |
+
$('#tier-hint').textContent = t ? 'Reference script target: ' + t.target_seconds[0] + '–' + t.target_seconds[1] + ' seconds to win' : '';
|
| 79 |
+
}
|
| 80 |
+
$('#difficulty').onchange = tierHint;
|
| 81 |
+
|
| 82 |
+
// ------------------------------------------------------------------ input sampling
|
| 83 |
+
function heldNow() {
|
| 84 |
+
const all = new Set([...down, ...taps]);
|
| 85 |
+
taps.clear();
|
| 86 |
+
const out = [];
|
| 87 |
+
for (const k of ['W', 'S', 'A', 'D']) if (all.has(k)) { out.push(k); break; }
|
| 88 |
+
for (const k of ['Space', 'Shift', 'LMB', 'J', 'RMB']) if (all.has(k) && out.length < 4) out.push(k);
|
| 89 |
+
return out;
|
| 90 |
+
}
|
| 91 |
+
function packetText(sets, m) {
|
| 92 |
+
const mx = m.map((v, i) => Math.max(i === 2 ? -5 : -1000, Math.min(i === 2 ? 5 : 1000, Math.round(v))));
|
| 93 |
+
return '<|action_start|> ' + mx.join(' ') + ' ; ' + sets.map(s => s.join(',')).join(' ; ') + ' <|action_end|>';
|
| 94 |
+
}
|
| 95 |
+
function takePacket() {
|
| 96 |
+
while (subs.length < 6) subs.push(heldNow());
|
| 97 |
+
const p = packetText(subs, mouse);
|
| 98 |
+
subs = []; mouse = [0, 0, 0];
|
| 99 |
+
return p;
|
| 100 |
+
}
|
| 101 |
+
// Wall-clock scheduler: one hold set per 33.3 ms of real time, whatever the timer jitter, so the world runs at
|
| 102 |
+
// real speed; packets go out in order, one request at a time (a lagging server gets up to 5 per request).
|
| 103 |
+
function sampleClock() {
|
| 104 |
+
if (!running || mode !== 'play') return;
|
| 105 |
+
const due = Math.floor((performance.now() - clock0) / SUB_MS);
|
| 106 |
+
if (due - subsDone > 18) subsDone = due - 6; // tab stalled: drop the backlog instead of a burst
|
| 107 |
+
while (subsDone < due) {
|
| 108 |
+
if (arrows.has('ArrowLeft')) mouse[0] -= 7;
|
| 109 |
+
if (arrows.has('ArrowRight')) mouse[0] += 7;
|
| 110 |
+
if (arrows.has('ArrowUp')) mouse[1] -= 4;
|
| 111 |
+
if (arrows.has('ArrowDown')) mouse[1] += 4;
|
| 112 |
+
subs.push(heldNow());
|
| 113 |
+
subsDone++;
|
| 114 |
+
if (subs.length >= 6) queue.push(takePacket());
|
| 115 |
+
}
|
| 116 |
+
pump();
|
| 117 |
+
}
|
| 118 |
+
async function pump() {
|
| 119 |
+
if (sending || !queue.length || !sid) return;
|
| 120 |
+
sending = true;
|
| 121 |
+
const batch = queue.splice(0, 5), my = epoch;
|
| 122 |
+
try {
|
| 123 |
+
const r = await api('/api/step', {sid, packets: batch, frames: true});
|
| 124 |
+
if (my === epoch) accept(r);
|
| 125 |
+
} catch (e) { status('Server error: ' + e.message); pause(); }
|
| 126 |
+
finally { sending = false; if (queue.length && my === epoch) pump(); }
|
| 127 |
+
}
|
| 128 |
+
function lock() {
|
| 129 |
+
try { const p = capture.requestPointerLock && capture.requestPointerLock(); if (p && p.catch) p.catch(() => {}); } catch (e) { /* headless */ }
|
| 130 |
+
}
|
| 131 |
+
document.addEventListener('pointerlockchange', () => {
|
| 132 |
+
if (document.pointerLockElement !== capture && running && mode === 'play') {
|
| 133 |
+
pause(); status('Mouse unlocked (Esc) · Paused. Click Resume to continue.');
|
| 134 |
+
}
|
| 135 |
+
});
|
| 136 |
+
const arrows = new Set();
|
| 137 |
+
window.addEventListener('keydown', e => {
|
| 138 |
+
if (['INPUT', 'SELECT', 'TEXTAREA'].includes(document.activeElement.tagName)) return;
|
| 139 |
+
if (e.code === 'Escape' || e.code === 'KeyP') { if (running) pause(); return; }
|
| 140 |
+
if (e.code.startsWith('Arrow')) { arrows.add(e.code); e.preventDefault(); return; }
|
| 141 |
+
if (e.code === 'KeyQ' || e.code === 'Digit1' || e.code === 'Digit2') {
|
| 142 |
+
const want = e.code === 'Digit1' ? 'sword' : e.code === 'Digit2' ? 'bow' : null;
|
| 143 |
+
if (!want || (state && state.player.weapon !== want)) mouse[2] += 1;
|
| 144 |
+
e.preventDefault(); return;
|
| 145 |
+
}
|
| 146 |
+
const k = CODE[e.code];
|
| 147 |
+
if (k) { e.preventDefault(); down.add(k); taps.add(k); }
|
| 148 |
+
});
|
| 149 |
+
window.addEventListener('keyup', e => {
|
| 150 |
+
if (e.code.startsWith('Arrow')) arrows.delete(e.code);
|
| 151 |
+
const k = CODE[e.code];
|
| 152 |
+
if (k) down.delete(k);
|
| 153 |
+
});
|
| 154 |
+
capture.addEventListener('contextmenu', e => e.preventDefault());
|
| 155 |
+
capture.addEventListener('pointerdown', e => {
|
| 156 |
+
capture.focus();
|
| 157 |
+
if (running && mode === 'play' && document.pointerLockElement !== capture) lock();
|
| 158 |
+
const k = e.button === 2 ? 'RMB' : e.button === 0 ? 'LMB' : null;
|
| 159 |
+
if (k) { down.add(k); taps.add(k); }
|
| 160 |
+
e.preventDefault();
|
| 161 |
+
});
|
| 162 |
+
window.addEventListener('pointerup', e => { down.delete(e.button === 2 ? 'RMB' : 'LMB'); });
|
| 163 |
+
window.addEventListener('mousemove', e => {
|
| 164 |
+
if (document.pointerLockElement === capture) { mouse[0] += e.movementX; mouse[1] += e.movementY; }
|
| 165 |
+
else if (e.buttons && e.target === capture) { mouse[0] += e.movementX; mouse[1] += e.movementY; }
|
| 166 |
+
});
|
| 167 |
+
capture.addEventListener('wheel', e => { e.preventDefault(); mouse[2] += e.deltaY > 0 ? 1 : -1; }, {passive: false});
|
| 168 |
+
document.querySelectorAll('[data-key]').forEach(b => {
|
| 169 |
+
b.onpointerdown = e => { e.preventDefault(); b.setPointerCapture(e.pointerId); down.add(b.dataset.key); taps.add(b.dataset.key); };
|
| 170 |
+
b.onpointerup = b.onpointercancel = () => down.delete(b.dataset.key);
|
| 171 |
+
});
|
| 172 |
+
document.querySelectorAll('[data-wheel]').forEach(b => { b.onclick = () => { mouse[2] += 1; }; });
|
| 173 |
+
function releaseAll() { down.clear(); taps.clear(); arrows.clear(); }
|
| 174 |
+
window.addEventListener('blur', () => { releaseAll(); if (running && mode === 'play') { pause(); status('Window lost focus · Paused. Click Resume to continue.'); } });
|
| 175 |
+
document.addEventListener('visibilitychange', () => { if (document.hidden) { releaseAll(); if (running) pause(); } });
|
| 176 |
+
|
| 177 |
+
// ------------------------------------------------------------------ stepping and frames
|
| 178 |
+
function accept(r) {
|
| 179 |
+
state = r.state || r;
|
| 180 |
+
if (r.frames && r.frames.length) {
|
| 181 |
+
if (frames.length > 12) frames = frames.slice(-6); // keep latency bounded
|
| 182 |
+
frames.push(...r.frames);
|
| 183 |
+
}
|
| 184 |
+
panel();
|
| 185 |
+
if (state.outcome) finish();
|
| 186 |
+
}
|
| 187 |
+
function showFrames(now) {
|
| 188 |
+
if (frames.length && now - lastShown >= SUB_MS - 2) {
|
| 189 |
+
view.src = frames.shift();
|
| 190 |
+
lastShown = now;
|
| 191 |
+
}
|
| 192 |
+
requestAnimationFrame(showFrames);
|
| 193 |
+
}
|
| 194 |
+
requestAnimationFrame(showFrames);
|
| 195 |
+
async function still() {
|
| 196 |
+
if (!sid) return;
|
| 197 |
+
const r = await api('/api/still', {sid});
|
| 198 |
+
frames = [r.frame];
|
| 199 |
+
state = r.state; panel();
|
| 200 |
+
}
|
| 201 |
+
function panel() {
|
| 202 |
+
if (!state) return;
|
| 203 |
+
const p = state.player, b = state.boss;
|
| 204 |
+
$('#time').textContent = state.t.toFixed(1) + ' / ' + state.max_seconds + ' s';
|
| 205 |
+
const o = state.options || {}, tier = tierInfo(o.resolved_from_tier);
|
| 206 |
+
$('#tier').textContent = tier ? tier.label + ' · d=' + o.difficulty : 'd=' + o.difficulty;
|
| 207 |
+
$('#php').textContent = p.hp.toFixed(1) + ' / ' + p.max_hp + (p.wither_effect_s > 0 ? ' (Wither damage for ' + p.wither_effect_s.toFixed(0) + 's)' : '');
|
| 208 |
+
$('#wpn').textContent = (p.kit === 'iron' ? 'Iron ' : 'Diamond ') + (p.weapon === 'sword' ? 'sword ' + Math.round(p.attack_charge * 100) + '%' :
|
| 209 |
+
'Bow ' + (p.bow_drawing ? Math.round(p.bow_charge * 100) + '%' : 'ready') + ' · Hits ' + p.arrows_hit + '/' + p.arrows_fired);
|
| 210 |
+
$('#bname').textContent = b.name;
|
| 211 |
+
$('#bhp').textContent = b.hp.toFixed(1) + ' / ' + b.max_hp;
|
| 212 |
+
$('#bphase').textContent = b.phase + (b.armored ? ' · Half-health armor' : '') + (b.crystals !== null ? ' · Crystals ' + b.crystals : '') +
|
| 213 |
+
(b.minions !== null && b.minions !== undefined ? ' · Minions ' + b.minions : '') +
|
| 214 |
+
(b.darkness_s ? ' · Darkness ' + b.darkness_s.toFixed(0) + 's' : '');
|
| 215 |
+
}
|
| 216 |
+
function finish() {
|
| 217 |
+
stopLoop();
|
| 218 |
+
// Show the terminal frame at once: frames play back ~0.2 s behind the simulation, so the result overlay would
|
| 219 |
+
// otherwise sit on a frame where the boss still has health left.
|
| 220 |
+
if (frames.length) { view.src = frames[frames.length - 1]; frames = []; }
|
| 221 |
+
window.__bbOutcome = state.outcome; // read by web/tools/bench_media.py ui
|
| 222 |
+
const label = {win: 'Victory', loss: 'Failure', timeout: 'Time up'}[state.outcome] || state.outcome;
|
| 223 |
+
overlay(label + ' · ' + state.t.toFixed(2) + ' seconds');
|
| 224 |
+
if (mode === 'replay' && replayExpect) verifyReplay();
|
| 225 |
+
else status('Match over: ' + label + ' · ' + state.packets + ' action packets. You can export the replay.');
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// ------------------------------------------------------------------ loop control
|
| 229 |
+
function stopLoop() { running = false; clearInterval(timer); timer = null; $('#pause').textContent = 'Resume'; }
|
| 230 |
+
function startLoop() {
|
| 231 |
+
if (!sid || (state && state.outcome)) return;
|
| 232 |
+
running = true; $('#pause').textContent = 'Pause'; overlay('');
|
| 233 |
+
clearInterval(timer);
|
| 234 |
+
if (mode === 'play') { subs = []; mouse = [0, 0, 0]; clock0 = performance.now(); subsDone = 0; timer = setInterval(sampleClock, 8); }
|
| 235 |
+
else timer = setInterval(tickAuto, 200);
|
| 236 |
+
}
|
| 237 |
+
function pause() { stopLoop(); releaseAll(); if (document.pointerLockElement) document.exitPointerLock(); overlay(state && state.outcome ? $('#overlay-text').textContent : 'Paused'); }
|
| 238 |
+
async function tickAuto() {
|
| 239 |
+
if (pending || !running) return;
|
| 240 |
+
pending = true;
|
| 241 |
+
const my = epoch;
|
| 242 |
+
try {
|
| 243 |
+
if (mode === 'demo') {
|
| 244 |
+
const r = await api('/api/scripted', {sid, n: 1, frames: true});
|
| 245 |
+
if (my === epoch) accept(r);
|
| 246 |
+
} else if (mode === 'replay') {
|
| 247 |
+
if (!replayQueue.length) { if (state && !state.outcome) { stopLoop(); verifyReplay(); } }
|
| 248 |
+
else { const r = await api('/api/step', {sid, packets: [replayQueue.shift()], frames: true}); if (my === epoch) accept(r); }
|
| 249 |
+
}
|
| 250 |
+
} catch (e) { status('Server error: ' + e.message); stopLoop(); }
|
| 251 |
+
finally { pending = false; }
|
| 252 |
+
}
|
| 253 |
+
async function newSession(caseId, useMode, tier) {
|
| 254 |
+
if (!meta && !(await connect())) return false;
|
| 255 |
+
epoch++; stopLoop(); frames = []; replayQueue = []; replayExpect = null; queue = []; window.__bbOutcome = null;
|
| 256 |
+
if (sid) api('/api/close', {sid}).catch(() => {});
|
| 257 |
+
const body = {case: caseId || $('#case').value, seed: Number($('#seed').value), tier: tier || $('#difficulty').value,
|
| 258 |
+
weapon: $('#weapon').value, camera: $('#camera').value};
|
| 259 |
+
$('#case').value = body.case;
|
| 260 |
+
$('#difficulty').value = body.tier; tierHint();
|
| 261 |
+
const r = await api('/api/new', body);
|
| 262 |
+
sid = r.sid; state = r.state; mode = useMode; panel();
|
| 263 |
+
await still();
|
| 264 |
+
return true;
|
| 265 |
+
}
|
| 266 |
+
$('#start').onclick = async () => {
|
| 267 |
+
try {
|
| 268 |
+
if (!(await newSession(null, 'play'))) return;
|
| 269 |
+
status('Match in progress: click the screen to lock the mouse (Esc unlocks and pauses). One action packet every 200 ms.');
|
| 270 |
+
capture.focus(); startLoop();
|
| 271 |
+
} catch (e) { status('Unable to start: ' + e.message); }
|
| 272 |
+
};
|
| 273 |
+
$('#pause').onclick = () => {
|
| 274 |
+
if (running) pause();
|
| 275 |
+
else if (sid && state && !state.outcome) { startLoop(); capture.focus(); if (mode === 'play') lock(); }
|
| 276 |
+
};
|
| 277 |
+
$('#step').onclick = async () => {
|
| 278 |
+
if (!sid || (state && state.outcome)) return;
|
| 279 |
+
if (running) pause();
|
| 280 |
+
overlay('Step');
|
| 281 |
+
const sets = Array.from({length: 6}, () => heldNow());
|
| 282 |
+
if (mode === 'demo') { accept(await api('/api/scripted', {sid, n: 1, frames: true})); }
|
| 283 |
+
else if (mode === 'replay') { if (replayQueue.length) accept(await api('/api/step', {sid, packets: [replayQueue.shift()], frames: true})); }
|
| 284 |
+
else { const p = packetText(sets, mouse); mouse = [0, 0, 0]; accept(await api('/api/step', {sid, packets: [p], frames: true})); }
|
| 285 |
+
};
|
| 286 |
+
async function demo(caseId, tier) {
|
| 287 |
+
if (!(await newSession(caseId, 'demo', tier))) return false;
|
| 288 |
+
status('Scripted Demo: a reference controller reads internal state and emits valid 200 ms action packets.');
|
| 289 |
+
startLoop();
|
| 290 |
+
return true;
|
| 291 |
+
}
|
| 292 |
+
$('#demo').onclick = () => demo(null).catch(e => status('Demo failed: ' + e.message));
|
| 293 |
+
$('#export').onclick = async () => {
|
| 294 |
+
if (!sid) { status('No match is available to export yet.'); return; }
|
| 295 |
+
const data = await api('/api/replay?sid=' + sid);
|
| 296 |
+
const blob = new Blob([JSON.stringify(data, null, 1)], {type: 'application/json'});
|
| 297 |
+
const a = document.createElement('a');
|
| 298 |
+
a.href = URL.createObjectURL(blob);
|
| 299 |
+
a.download = data.case_id.replace('/', '__') + '-seed' + data.engine_seed + '.replay.json';
|
| 300 |
+
a.click(); setTimeout(() => URL.revokeObjectURL(a.href), 1000);
|
| 301 |
+
status('Exported ' + data.steps + ' action packets (' + data.rules + ') · Final-state hash: ' + data.final_hash.slice(0, 12));
|
| 302 |
+
};
|
| 303 |
+
$('#import').onclick = () => $('#file').click();
|
| 304 |
+
$('#file').onchange = async e => {
|
| 305 |
+
const file = e.target.files[0]; e.target.value = '';
|
| 306 |
+
if (!file) return;
|
| 307 |
+
try {
|
| 308 |
+
if (file.size > 12e6) throw Error('Replay must be 12 MB or smaller');
|
| 309 |
+
await importReplay(JSON.parse(await file.text()));
|
| 310 |
+
} catch (err) { status('Import failed: ' + err.message); }
|
| 311 |
+
};
|
| 312 |
+
async function importReplay(data) {
|
| 313 |
+
if (!meta && !(await connect())) return;
|
| 314 |
+
epoch++; stopLoop(); frames = [];
|
| 315 |
+
const r = await api('/api/import', {replay: data});
|
| 316 |
+
if (sid) api('/api/close', {sid}).catch(() => {});
|
| 317 |
+
sid = r.sid; state = r.state; mode = 'replay'; panel();
|
| 318 |
+
replayQueue = data.packets.slice(); replayExpect = r.expect;
|
| 319 |
+
$('#case').value = data.case_id;
|
| 320 |
+
await still();
|
| 321 |
+
status('Replay rules verified (' + data.rules + ') · Playing back ' + replayQueue.length + ' action packets…');
|
| 322 |
+
startLoop();
|
| 323 |
+
}
|
| 324 |
+
async function verifyReplay() {
|
| 325 |
+
const v = await api('/api/verify', {sid});
|
| 326 |
+
const ok = v.final_hash === replayExpect.final_hash && v.outcome === replayExpect.outcome && v.ticks === replayExpect.ticks;
|
| 327 |
+
status('Replay finished: ' + ({win: 'Victory', loss: 'Failure', timeout: 'Time up'}[v.outcome] || 'Replay ended before the match concluded') + ' · ' + v.ticks + ' ticks · ' + (ok ? 'Final-state hash matches ✓' : 'Final state differs from replay ✗ (' + v.final_hash.slice(0, 10) + ' vs ' + String(replayExpect.final_hash).slice(0, 10) + ')'));
|
| 328 |
+
replayExpect = null;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
// ------------------------------------------------------------------ harness hook (web/tools/bench_media.py ui)
|
| 332 |
+
window.bossbenchUI = {
|
| 333 |
+
demo: (caseId, tier) => demo(caseId, tier),
|
| 334 |
+
start: (caseId, tier) => newSession(caseId, 'play', tier).then(() => { startLoop(); return true; }),
|
| 335 |
+
state: () => state, connected: () => !!meta,
|
| 336 |
+
};
|
| 337 |
+
connect();
|
| 338 |
+
})();
|
environments/games/web/games/minecraft_remake/style.css
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root{color-scheme:dark;--paper:#ece6d6;--muted:#a7b3a2;--accent:#8fd16a;--bg:#1b1f17;--panel:#262c21;--edge:#4a5940;--warn:#e7b35d}
|
| 2 |
+
*{box-sizing:border-box}
|
| 3 |
+
body{margin:0;background:var(--bg) radial-gradient(circle at 20% -10%,#2f3a26 0,transparent 55%);color:var(--paper);font:15px/1.6 'Segoe UI','Microsoft YaHei',sans-serif}
|
| 4 |
+
main{max-width:1180px;margin:auto;padding:24px 24px 40px}
|
| 5 |
+
header{display:flex;gap:24px;align-items:baseline;justify-content:space-between;margin-bottom:18px}
|
| 6 |
+
h1{font-family:Georgia,'Microsoft YaHei',serif;font-size:29px;font-weight:600;line-height:1.3;margin:6px 0;letter-spacing:.5px}
|
| 7 |
+
header p{margin:0;color:var(--muted);font-size:13px}
|
| 8 |
+
code{font-family:Consolas,monospace;font-size:12px;color:var(--accent)}
|
| 9 |
+
a{color:var(--accent)}
|
| 10 |
+
a:focus-visible,button:focus-visible,input:focus-visible,select:focus-visible,#capture:focus-visible{outline:3px solid var(--accent);outline-offset:3px}
|
| 11 |
+
.layout{display:grid;grid-template-columns:minmax(0,854px) 240px;gap:20px}
|
| 12 |
+
.stage{position:relative;align-self:start;border:2px solid #10130d;box-shadow:0 0 0 1px var(--edge);background:#0b0d09;aspect-ratio:854/480}
|
| 13 |
+
#view{display:block;width:100%;height:100%;image-rendering:pixelated;user-select:none}
|
| 14 |
+
#capture{position:absolute;inset:0;cursor:crosshair;touch-action:none}
|
| 15 |
+
#overlay{pointer-events:none;position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#0d110a55}
|
| 16 |
+
#overlay[hidden]{display:none}
|
| 17 |
+
#overlay div{padding:12px 25px;background:#141a10ee;text-align:center;border:2px solid var(--edge);font-size:22px;font-family:Georgia,'Microsoft YaHei',serif}
|
| 18 |
+
#offline{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;padding:28px 40px;background:#12160fef;font-size:14px}
|
| 19 |
+
#offline[hidden]{display:none}
|
| 20 |
+
#offline h2{margin:0 0 8px;font-size:20px;color:var(--warn)}
|
| 21 |
+
#offline pre{white-space:pre-wrap;background:#0a0c08;border:1px solid var(--edge);padding:10px 12px;font:13px Consolas,monospace;color:#d8f0c4}
|
| 22 |
+
.toolbar{display:flex;flex-wrap:wrap;gap:9px;padding:12px;background:var(--panel);border:1px solid var(--edge);border-top:0}
|
| 23 |
+
button,select,input{font:inherit;border:1px solid var(--edge);border-radius:2px;background:#30382a;color:var(--paper);padding:7px 10px}
|
| 24 |
+
button{cursor:pointer;box-shadow:inset 0 -3px 0 #1d2318}
|
| 25 |
+
button:hover{border-color:var(--accent)}
|
| 26 |
+
button.primary{background:#5d8f3c;color:#0f140b;font-weight:700;box-shadow:inset 0 -3px 0 #3d6524}
|
| 27 |
+
select,input[type=number]{width:100%}
|
| 28 |
+
aside label{display:block;margin:12px 0 5px;color:var(--muted);font-size:13px}
|
| 29 |
+
.hint{margin:5px 0 0;color:var(--muted);font-size:12px}
|
| 30 |
+
aside h2{font-size:17px;margin:18px 0 10px}
|
| 31 |
+
aside>div:first-child h2{margin-top:0}
|
| 32 |
+
.panel{margin-top:16px;padding:10px 12px;background:var(--panel);border:1px solid var(--edge)}
|
| 33 |
+
.row{display:flex;justify-content:space-between;gap:10px;font-size:13px;color:var(--muted)}
|
| 34 |
+
.row b{color:var(--paper);font-weight:600;text-align:right}
|
| 35 |
+
dl{margin:8px 0}
|
| 36 |
+
dt{color:var(--accent);font-family:Consolas,monospace;font-size:12px}
|
| 37 |
+
dd{margin:0 0 10px;font-size:13px;color:var(--muted)}
|
| 38 |
+
#status{min-height:28px;margin:10px 0;color:var(--warn);font-size:13px;overflow-wrap:anywhere}
|
| 39 |
+
.note{color:var(--muted);font-size:13px}
|
| 40 |
+
.mobile{display:none;gap:6px;flex-wrap:wrap;padding:10px;background:var(--panel);border:1px solid var(--edge);border-top:0}
|
| 41 |
+
.mobile button{flex:1 1 22%;padding:12px 4px}
|
| 42 |
+
footer{border-top:1px solid var(--edge);margin-top:25px;padding-top:14px;display:flex;gap:18px;flex-wrap:wrap;font-size:13px}
|
| 43 |
+
@media (max-width:900px){.layout{grid-template-columns:1fr}main{padding:14px}header{flex-direction:column;gap:6px}.mobile{display:flex}}
|
| 44 |
+
@media (pointer:coarse){.mobile{display:flex}}
|
environments/games/web/games/nfsmw_remake/compact_actions.json
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/compact-actions@1",
|
| 3 |
+
"game": "nfsmw_remake",
|
| 4 |
+
"version": "nfsmw-compact@1",
|
| 5 |
+
"note": "Four heads, 4 x 13 x 2 x 6 = 624 actions, each held for one 200 ms packet (6 sub-steps of 2 native ticks). No mouse: this game reads none. Pedal and steering are duty cycles over the 6 sub-steps because the car model integrates them: the wheel slews towards the key held and back to centre at the same rate (nfscore.js carStep), so a steering key held for 3 of 6 sub-steps keeps the current angle, 4 or 6 winds it on, 2 lets it come back slowly, none returns it to centre. Options chosen from the reference controller (harness/duty_stats.js: 16001 packets, all six events x three tiers x seeds 1-2) and tested by projecting every reference packet onto this set (harness/compact_sim.js, the same projection as compact.py): versions with 11 steering options lost speed-trap hard 4->2 and the final normal 3->2; the 2/6 ease options brought them back.",
|
| 6 |
+
"heads": [
|
| 7 |
+
{
|
| 8 |
+
"name": "pedal",
|
| 9 |
+
"options": [
|
| 10 |
+
{
|
| 11 |
+
"label": "none"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"label": "throttle_light",
|
| 15 |
+
"note": "the reference's corner exit: drive force limited by the friction circle",
|
| 16 |
+
"subs": [
|
| 17 |
+
[],
|
| 18 |
+
[],
|
| 19 |
+
[],
|
| 20 |
+
[],
|
| 21 |
+
[],
|
| 22 |
+
[
|
| 23 |
+
"W"
|
| 24 |
+
]
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"label": "throttle",
|
| 29 |
+
"keys": [
|
| 30 |
+
"W"
|
| 31 |
+
]
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"label": "brake",
|
| 35 |
+
"keys": [
|
| 36 |
+
"S"
|
| 37 |
+
]
|
| 38 |
+
}
|
| 39 |
+
],
|
| 40 |
+
"note": "full throttle 65% of the reference packets, brake 16%, one sub-step in six 11% (corner exits, where the friction circle leaves little drive). A half throttle option was tried and dropped: it changed no result (v6 vs v7)."
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"name": "steer",
|
| 44 |
+
"options": [
|
| 45 |
+
{
|
| 46 |
+
"label": "none"
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"label": "left_tap",
|
| 50 |
+
"note": "drag series: A and D are lane changes on a press (modes_drag.js input), so one press per packet",
|
| 51 |
+
"tap": [
|
| 52 |
+
"A"
|
| 53 |
+
]
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"label": "left_ease",
|
| 57 |
+
"subs": [
|
| 58 |
+
[],
|
| 59 |
+
[],
|
| 60 |
+
[
|
| 61 |
+
"A"
|
| 62 |
+
],
|
| 63 |
+
[],
|
| 64 |
+
[
|
| 65 |
+
"A"
|
| 66 |
+
],
|
| 67 |
+
[]
|
| 68 |
+
]
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"label": "left_hold",
|
| 72 |
+
"subs": [
|
| 73 |
+
[
|
| 74 |
+
"A"
|
| 75 |
+
],
|
| 76 |
+
[],
|
| 77 |
+
[
|
| 78 |
+
"A"
|
| 79 |
+
],
|
| 80 |
+
[],
|
| 81 |
+
[
|
| 82 |
+
"A"
|
| 83 |
+
],
|
| 84 |
+
[]
|
| 85 |
+
]
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"label": "left_hold_late",
|
| 89 |
+
"subs": [
|
| 90 |
+
[],
|
| 91 |
+
[
|
| 92 |
+
"A"
|
| 93 |
+
],
|
| 94 |
+
[],
|
| 95 |
+
[
|
| 96 |
+
"A"
|
| 97 |
+
],
|
| 98 |
+
[],
|
| 99 |
+
[
|
| 100 |
+
"A"
|
| 101 |
+
]
|
| 102 |
+
]
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"label": "left_more",
|
| 106 |
+
"subs": [
|
| 107 |
+
[
|
| 108 |
+
"A"
|
| 109 |
+
],
|
| 110 |
+
[
|
| 111 |
+
"A"
|
| 112 |
+
],
|
| 113 |
+
[],
|
| 114 |
+
[
|
| 115 |
+
"A"
|
| 116 |
+
],
|
| 117 |
+
[],
|
| 118 |
+
[
|
| 119 |
+
"A"
|
| 120 |
+
]
|
| 121 |
+
]
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"label": "left_full",
|
| 125 |
+
"keys": [
|
| 126 |
+
"A"
|
| 127 |
+
]
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"label": "right_tap",
|
| 131 |
+
"tap": [
|
| 132 |
+
"D"
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"label": "right_ease",
|
| 137 |
+
"subs": [
|
| 138 |
+
[],
|
| 139 |
+
[],
|
| 140 |
+
[
|
| 141 |
+
"D"
|
| 142 |
+
],
|
| 143 |
+
[],
|
| 144 |
+
[
|
| 145 |
+
"D"
|
| 146 |
+
],
|
| 147 |
+
[]
|
| 148 |
+
]
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"label": "right_hold",
|
| 152 |
+
"subs": [
|
| 153 |
+
[
|
| 154 |
+
"D"
|
| 155 |
+
],
|
| 156 |
+
[],
|
| 157 |
+
[
|
| 158 |
+
"D"
|
| 159 |
+
],
|
| 160 |
+
[],
|
| 161 |
+
[
|
| 162 |
+
"D"
|
| 163 |
+
],
|
| 164 |
+
[]
|
| 165 |
+
]
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
"label": "right_hold_late",
|
| 169 |
+
"subs": [
|
| 170 |
+
[],
|
| 171 |
+
[
|
| 172 |
+
"D"
|
| 173 |
+
],
|
| 174 |
+
[],
|
| 175 |
+
[
|
| 176 |
+
"D"
|
| 177 |
+
],
|
| 178 |
+
[],
|
| 179 |
+
[
|
| 180 |
+
"D"
|
| 181 |
+
]
|
| 182 |
+
]
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"label": "right_more",
|
| 186 |
+
"subs": [
|
| 187 |
+
[
|
| 188 |
+
"D"
|
| 189 |
+
],
|
| 190 |
+
[
|
| 191 |
+
"D"
|
| 192 |
+
],
|
| 193 |
+
[],
|
| 194 |
+
[
|
| 195 |
+
"D"
|
| 196 |
+
],
|
| 197 |
+
[],
|
| 198 |
+
[
|
| 199 |
+
"D"
|
| 200 |
+
]
|
| 201 |
+
]
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
"label": "right_full",
|
| 205 |
+
"keys": [
|
| 206 |
+
"D"
|
| 207 |
+
]
|
| 208 |
+
}
|
| 209 |
+
],
|
| 210 |
+
"note": "left_tap / right_tap: one press per packet, the lane change of the drag series (modes_drag.js reads pressed A / D there). The duty options steer everywhere else."
|
| 211 |
+
},
|
| 212 |
+
{
|
| 213 |
+
"name": "nitrous",
|
| 214 |
+
"options": [
|
| 215 |
+
{
|
| 216 |
+
"label": "none"
|
| 217 |
+
},
|
| 218 |
+
{
|
| 219 |
+
"label": "nitrous",
|
| 220 |
+
"note": "only burns while the throttle is down (nfscore.js carStep)",
|
| 221 |
+
"keys": [
|
| 222 |
+
"Shift"
|
| 223 |
+
]
|
| 224 |
+
}
|
| 225 |
+
],
|
| 226 |
+
"note": "only burns while the throttle is down (nfscore.js carStep: engaged needs thr > 0)"
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"name": "press",
|
| 230 |
+
"note": "J (slow motion), K / L (gears, drag series only) and R (reset) act on a press (pressed.has in game.js), so each is one press at the start of the packet. The handbrake is held, and it shares this head because a handbrake turn and a gear change or a reset are never wanted in the same 200 ms.",
|
| 231 |
+
"options": [
|
| 232 |
+
{
|
| 233 |
+
"label": "none"
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"label": "shift_up",
|
| 237 |
+
"tap": [
|
| 238 |
+
"K"
|
| 239 |
+
]
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
"label": "shift_down",
|
| 243 |
+
"tap": [
|
| 244 |
+
"L"
|
| 245 |
+
]
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"label": "slowmo",
|
| 249 |
+
"tap": [
|
| 250 |
+
"J"
|
| 251 |
+
]
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"label": "reset",
|
| 255 |
+
"tap": [
|
| 256 |
+
"R"
|
| 257 |
+
]
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"label": "handbrake",
|
| 261 |
+
"note": "held, not a press: carStep reads it every tick. The reference controller never uses it; kept because it is a basic control of the event. It shares this head with the single presses because a handbrake turn and a gear change or a reset are never wanted in the same 200 ms",
|
| 262 |
+
"keys": [
|
| 263 |
+
"Space"
|
| 264 |
+
]
|
| 265 |
+
}
|
| 266 |
+
]
|
| 267 |
+
}
|
| 268 |
+
]
|
| 269 |
+
}
|
environments/games/web/games/nfsmw_remake/cops.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Police. Rules read from AI/Common/AIPursuit.cpp unless noted (all values in the VLT pursuitlevels table are approximations, by tier):
|
| 2 |
+
- busted meter: :1887-1940, up while a cop sees the player, the player is under BustSpeed and the nearest cop is within 15 m, down twice
|
| 3 |
+
as fast otherwise, busted above 5 (kBustedTimeout, kBustedCopDistance :1607-8; Sim/Common/Simulation.cpp:345 for the task rates);
|
| 4 |
+
- during a manual-reset flash the distance is x6 and the rate x4 (:1895-1909);
|
| 5 |
+
- sight: 150 m ahead of the cop, 50 m behind it, and the world ray must be clear (AIVehicleCopCar.cpp:88-168), helicopter 250 m (AIVehicleHelicopter.cpp:114);
|
| 6 |
+
- evade: more than 7 s unseen, then (unseen + hidden time) / evadetimeout reaches 1 (:2027-2061); seen again, it decays x0.93 per task (:2097);
|
| 7 |
+
- roadblocks: a request every 8-12 s with a probability (:2459-2507); a roadblock's cops join the chase after a spike hit (SpikesHit :2791);
|
| 8 |
+
- formations: FOLLOW, ROLLING_BLOCK, BOX_IN, PIT (:976-1010), cops within 60 m qualify (kFormationCandidateDistance :1221);
|
| 9 |
+
- spikes: a tyre over the strip punctures and blows 0.5 s later (DamageRacer.cpp:12), grip x0.3 (SuspensionRacer.cpp:1569);
|
| 10 |
+
- destroying cops: bonus multiplier up to 3 inside DestroyCopBonusTime (IncNumCopsDestroyed :917).
|
| 11 |
+
A cop is a free body, not on rails: with sight it drives straight at its slot (sight means the straight line is clear), without sight it follows
|
| 12 |
+
the route towards where the player was last seen. All decisions draw from the game RNG, and the controller never copies the game. */
|
| 13 |
+
(function (root) {
|
| 14 |
+
'use strict';
|
| 15 |
+
const M = root.NfsmwGame, C = M.C, N = root.NativeBench, clamp = C.clamp, P = C.PLAYER;
|
| 16 |
+
const BUST_MAX = 5, BUST_DIST = 15, FRONT_LOS = 150, REAR_LOS = 50, HELI_LOS = 250, EVADE_AFTER = 7, RESET_DIST = 6, RESET_RATE = 4, RECYCLE_DIST = 320, RECYCLE_S = 6, BARRIER_R = 2.6, BARRIER_KEEP = 0.62;
|
| 17 |
+
const wrapTo = (R, v, ref) => { if (!R.loop) return v; let ds = (v - ref) % R.L; if (ds > R.L / 2) ds -= R.L; else if (ds < -R.L / 2) ds += R.L; return ref + ds; };
|
| 18 |
+
M.wrapTo = wrapTo;
|
| 19 |
+
// o: copsMax, top, grip, accel, spawnGap, formations, rbChance, spikeChance, heli, heliAfter, heliFuel, heliGap, bustKph
|
| 20 |
+
M.initPolice = (g, o) => {
|
| 21 |
+
g.pol = Object.assign({ bust: 0, seen: 0, sinceSeen: 0, evade: 0, spawnT: o.spawnGap, rbT: 9, formT: 4, formation: 'FOLLOW', pursuitT: 0, destroyed: 0, bonusT: 0, bonusMult: 1, lockT: 0, lastS: g.s, heliT: o.heliAfter, combo: 0, sawNow: 1, inSight: 1 }, o);
|
| 22 |
+
g.cops = []; g.props = []; g.blocks = []; g.heli = null; g.puncT = 0; g.punc = 0;
|
| 23 |
+
};
|
| 24 |
+
M.spawnCop = (g, s, lat, dir, state = 'chase', h) => {
|
| 25 |
+
const R = g.route, a = C.routeAt(R, s, lat), c = { x: a.x, y: a.y, h: h !== undefined ? h : dir > 0 ? a.h : a.h + Math.PI, v: state === 'rb' ? 0 : 20, s, lat, hp: 100, state, chasing: state === 'chase' ? 1 : 0, dead: 0, gone: 0, slot: g.cops.length, sees: 0, hitT: 0, deadT: 0, lostT: 0 };
|
| 26 |
+
g.cops.push(c); return c;
|
| 27 |
+
};
|
| 28 |
+
const destroy = (g, c, why) => {
|
| 29 |
+
c.dead = 1; c.chasing = 0; c.deadT = 4; const p = g.pol; p.destroyed++;
|
| 30 |
+
p.bonusMult = p.bonusT > 0 ? Math.min(3, p.bonusMult + 1) : 1; p.bonusT = 8; p.combo = p.bonusMult;
|
| 31 |
+
g.events.push({ type: 'cop_destroyed', why, mult: p.bonusMult });
|
| 32 |
+
};
|
| 33 |
+
M.destroyCop = destroy;
|
| 34 |
+
// Slot offsets in the player's frame: [metres ahead, metres to the left]. Numbers are original: the formation classes' tables are VLT-driven.
|
| 35 |
+
const SLOTS = { FOLLOW: [[-11, -2.5], [-11, 2.5], [-22, 0], [-30, -4], [-30, 4]], ROLLING_BLOCK: [[14, -3.2], [14, 3.2], [24, 0], [-12, 0], [-22, 3]], BOX_IN: [[-6, -4.2], [-6, 4.2], [12, 0], [-14, 0], [-22, 0]], PIT: [[-3, -3.4], [-3, 3.4], [-12, 0], [-22, 3], [-22, -3]] };
|
| 36 |
+
function stepCop(g, c, wdt, losTick) {
|
| 37 |
+
const p = g.pol, R = g.route, car = g.car;
|
| 38 |
+
if (c.deadT > 0) { c.deadT -= wdt; c.v = Math.max(0, c.v - 12 * wdt); c.x += Math.cos(c.h) * c.v * wdt; c.y += Math.sin(c.h) * c.v * wdt; if (c.deadT <= 0) c.gone = 1; return; }
|
| 39 |
+
const dx = car.x - c.x, dy = car.y - c.y, dist = Math.hypot(dx, dy);
|
| 40 |
+
c.s = C.routeNear(R, c.x, c.y, wrapTo(R, c.s, g.s), 30, 30); c.lat = C.routeLat(R, c.x, c.y, c.s);
|
| 41 |
+
if (losTick) { const dot = (Math.cos(c.h) * dx + Math.sin(c.h) * dy) / (dist || 1); c.sees = (dist < REAR_LOS || (dist < FRONT_LOS && dot > 0)) && C.lineClear(c.x, c.y, car.x, car.y) ? 1 : 0; }
|
| 42 |
+
if (c.state === 'rb') { // parked across the road; joins in once the player is past or a strip was hit
|
| 43 |
+
if (g.s - c.s > 12 || c.join) { c.state = 'chase'; c.chasing = 1; }
|
| 44 |
+
else return;
|
| 45 |
+
}
|
| 46 |
+
let tx, ty;
|
| 47 |
+
if (c.sees && dist < 60) { // in formation (kFormationCandidateDistance)
|
| 48 |
+
const slots = SLOTS[p.formation], sl = slots[c.slot % slots.length], ch = Math.cos(car.h), sh = Math.sin(car.h), lead = C.speed(car) * 0.25;
|
| 49 |
+
tx = car.x + ch * (sl[0] + lead) - sh * sl[1]; ty = car.y + sh * (sl[0] + lead) + ch * sl[1];
|
| 50 |
+
if (p.formation === 'PIT' && (c.slot % slots.length) < 2 && dist < 9) { tx = car.x + ch * lead; ty = car.y + sh * lead; } // the ram itself
|
| 51 |
+
} else if (c.sees) { const lead = C.speed(car) * 0.35; tx = car.x + Math.cos(car.h) * lead; ty = car.y + Math.sin(car.h) * lead; }
|
| 52 |
+
else { // search: along the route towards the last known position (the route is where the sim keeps its cops)
|
| 53 |
+
const dS = wrapTo(R, p.lastS, c.s) - c.s, dirn = dS >= 0 ? 1 : -1, a = C.routeAt(R, c.s + dirn * Math.max(10, c.v * 0.6), clamp(c.lat, -3, 3)); tx = a.x; ty = a.y;
|
| 54 |
+
}
|
| 55 |
+
let want = Math.atan2(ty - c.y, tx - c.x) - c.h; want = Math.atan2(Math.sin(want), Math.cos(want));
|
| 56 |
+
const grip = P.grip * p.grip, rate = grip / Math.max(c.v, 6);
|
| 57 |
+
c.h += clamp(want, -rate * wdt, rate * wdt);
|
| 58 |
+
// Speed: the road's limit ahead, its class top, and the gap to its slot when it has sight (it has to hold station, not overshoot).
|
| 59 |
+
const prof = C.profile(R, grip, P.aero, P.brake * 0.9, p.top); let lim = Math.min(C.profileAt(R, prof, c.s + c.v * 0.3), C.profileAt(R, prof, c.s - c.v * 0.3));
|
| 60 |
+
if (Math.abs(want) > 0.9) lim = Math.min(lim, 12);
|
| 61 |
+
if (!c.sees) lim = Math.min(lim, p.searchTop);
|
| 62 |
+
else if (dist < 60) { const sd = Math.hypot(tx - c.x, ty - c.y), ahead = Math.cos(want) > 0; lim = Math.min(lim, Math.max(4, C.speed(car) + (ahead ? clamp(sd * 0.5, -6, p.close) : -6))); }
|
| 63 |
+
if (c.v > lim) c.v = Math.max(lim, c.v - P.brake * 0.9 * wdt);
|
| 64 |
+
else c.v = Math.min(lim, c.v + Math.max(0.5, C.driveAt(c.v) * p.accel - P.drag * c.v * c.v - P.roll) * wdt);
|
| 65 |
+
c.x += Math.cos(c.h) * c.v * wdt; c.y += Math.sin(c.h) * c.v * wdt;
|
| 66 |
+
const q = C.road(c.x, c.y), over = q.d + 1.2; if (over > 0) { c.x -= q.nx * over; c.y -= q.ny * over; c.v *= 1 - Math.min(0.4, 2 * wdt); }
|
| 67 |
+
}
|
| 68 |
+
// Contact with the player: equal masses along the normal, closing speed scrapes the cop's damage (DamageVehicle::OnImpact; the table is VLT).
|
| 69 |
+
function contact(g, c) {
|
| 70 |
+
const car = g.car, dx = car.x - c.x, dy = car.y - c.y, d2 = dx * dx + dy * dy, R2 = M.carRadius * 2; if (d2 >= R2 * R2) return;
|
| 71 |
+
const d = Math.max(0.01, Math.sqrt(d2)), nx = dx / d, ny = dy / d, cvx = Math.cos(c.h) * c.v, cvy = Math.sin(c.h) * c.v, rel = (car.vx - cvx) * nx + (car.vy - cvy) * ny, push = R2 - d;
|
| 72 |
+
car.x += nx * push * 0.5; car.y += ny * push * 0.5; c.x -= nx * push * 0.5; c.y -= ny * push * 0.5;
|
| 73 |
+
if (rel >= 0) return;
|
| 74 |
+
const j = -0.75 * rel; car.vx += nx * j; car.vy += ny * j; c.v = Math.max(0, c.v - j * (Math.cos(c.h) * -nx + Math.sin(c.h) * -ny) * -1); if (c.v > 90) c.v = 90;
|
| 75 |
+
if (c.hitT <= 0 && -rel > 3) {
|
| 76 |
+
c.hitT = 0.4; g.lastHit = 0.25; g.hits++; const dmg = -rel * g.pol.copFrail; c.hp -= dmg;
|
| 77 |
+
if (c.state === 'rb') { c.join = 1; for (const o of g.cops) if (o.state === 'rb') o.join = 1; }
|
| 78 |
+
g.events.push({ type: 'cop_contact', speed: -rel, hp: c.hp });
|
| 79 |
+
if (c.hp <= 0) destroy(g, c, 'ram');
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
const spawnAway = (g) => {
|
| 83 |
+
const p = g.pol, R = g.route, ahead = (p.sawNow || p.aheadBlind) && N.rand(g) < p.aheadChance, S = g.s + (ahead ? 320 + N.rand(g) * 120 : -(210 + N.rand(g) * 90)), lat = (N.rand(g) < 0.5 ? -1 : 1) * R.halfW * 0.4;
|
| 84 |
+
if (!R.loop && (S < 20 || S > R.L - 20)) return;
|
| 85 |
+
const c = M.spawnCop(g, S, lat, ahead ? -1 : 1, 'chase');
|
| 86 |
+
c.slot = p.nextSlot = (p.nextSlot || 0) + 1;
|
| 87 |
+
};
|
| 88 |
+
function stepRoadblocks(g, wdt) {
|
| 89 |
+
const p = g.pol, R = g.route; p.rbT -= wdt;
|
| 90 |
+
// AIPursuit.cpp:2459: a request every 8-12 s; the probability and the spike chance are the heat level's VLT values (approximations).
|
| 91 |
+
if (p.rbT <= 0) {
|
| 92 |
+
p.rbT = 8 + N.rand(g) * 4;
|
| 93 |
+
if (!g.props.some(x => x.type === 'barrier') && p.rbChance > 0 && N.rand(g) < p.rbChance && C.speed(g.car) > 15 && !p.lockT) {
|
| 94 |
+
const S = g.s + Math.max(180, C.speed(g.car) * 5.5), a = C.routeAt(R, S), h = a.h, kN = Math.abs(a.k); if (kN < 0.012) {
|
| 95 |
+
const hw = R.halfW, gapSide = N.rand(g) < 0.5 ? -1 : 1, gapW = p.rbGap, block = []; for (let l = -hw + 1.8; l < hw - 1.6; l += 4.3) if (gapSide * l < hw - gapW || Math.abs(l) < 0) block.push(l);
|
| 96 |
+
block.forEach((l, i) => { if (i % 2 === 0) { const c = M.spawnCop(g, S, l, 1, 'rb', h + Math.PI / 2); c.slot = i; } else { const b = C.routeAt(R, S, l); g.props.push({ type: 'barrier', x: b.x, y: b.y, h: h + Math.PI / 2, s: S, lat: l, ttl: 40 }); } g.blocks.push({ s: S, lat: l }); });
|
| 97 |
+
if (N.rand(g) < p.spikeChance) { const S2 = S - 26, side = -gapSide, L = hw + 3, l0 = gapSide * (hw - gapW) + side * 0 - gapSide * L / 2, b = C.routeAt(R, S2, l0); g.props.push({ type: 'spike', x: b.x, y: b.y, h: h, s: S2, lat: l0, len: L, ttl: 40 }); }
|
| 98 |
+
g.events.push({ type: 'roadblock', s: S, gap: gapSide });
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
for (const o of g.props) if (o.ttl !== undefined) { o.ttl -= wdt; if (o.ttl <= 0 || g.s - wrapTo(R, o.s, g.s) > 160) o.gone = 1; }
|
| 103 |
+
g.props = g.props.filter(o => !o.gone);
|
| 104 |
+
g.blocks = g.blocks.filter(b => g.s - wrapTo(R, b.s, g.s) < 40);
|
| 105 |
+
for (const o of g.props) if (o.type === 'barrier' && !o.gone) { const dx = g.car.x - o.x, dy = g.car.y - o.y; if (dx * dx + dy * dy < BARRIER_R * BARRIER_R) { const v = C.speed(g.car); g.car.vx *= BARRIER_KEEP; g.car.vy *= BARRIER_KEEP; o.gone = 1; g.hits++; g.lastHit = 0.3; g.events.push({ type: 'barrier', speed: v }); for (const k of g.cops) if (k.state === 'rb') k.join = 1; } }
|
| 106 |
+
// Spikes: wheels are ±0.9 m off the centreline; each side over the strip is two tyres, punctured now and blown 0.5 s later.
|
| 107 |
+
const c = g.car;
|
| 108 |
+
for (const o of g.props) if (o.type === 'spike' && !o.used) {
|
| 109 |
+
const a = C.routeAt(R, o.s), ds = (c.x - a.x) * Math.cos(a.h) + (c.y - a.y) * Math.sin(a.h);
|
| 110 |
+
if (Math.abs(ds) < C.speed(c) * wdt + 0.6) { let n = 0; for (const w of [-0.9, 0.9]) if (Math.abs(g.lat + w - o.lat) < o.len / 2) n += 2; if (n && !g.flash) { o.used = 1; g.punc = Math.max(g.punc, n); g.puncT = 0.5; for (const k of g.cops) if (k.state === 'rb') k.join = 1; g.events.push({ type: 'spikes', tyres: n }); } }
|
| 111 |
+
}
|
| 112 |
+
if (g.puncT > 0) { g.puncT -= wdt; if (g.puncT <= 0) c.tires = Math.max(c.tires, g.punc); }
|
| 113 |
+
}
|
| 114 |
+
function stepHeli(g, wdt) {
|
| 115 |
+
const p = g.pol, car = g.car; if (!p.heli) return;
|
| 116 |
+
if (!g.heli) { p.heliT -= wdt; if (p.heliT <= 0 && !p.lockT) { g.heli = { x: car.x - Math.cos(car.h) * 200, y: car.y - Math.sin(car.h) * 200, z: 34, h: car.h, fuel: p.heliFuel, sees: 0, gone: 0 }; g.events.push({ type: 'helicopter' }); } return; }
|
| 117 |
+
const h = g.heli, sp = C.speed(car), lead = sp * 0.4 + 30, ch = Math.cos(car.h), sh = Math.sin(car.h), tx = car.x + ch * lead, ty = car.y + sh * lead, dx = tx - h.x, dy = ty - h.y, d = Math.hypot(dx, dy) || 1, v = Math.min(85, d * 1.4); // AIActionHeliPursuit.cpp:26,leadDist
|
| 118 |
+
h.x += dx / d * v * wdt; h.y += dy / d * v * wdt; h.h = Math.atan2(dy, dx); h.fuel -= wdt; h.sees = Math.hypot(car.x - h.x, car.y - h.y) < HELI_LOS ? 1 : 0;
|
| 119 |
+
if (h.fuel <= 0) { g.heli = null; p.heliT = p.heliGap; g.events.push({ type: 'helicopter_leaves' }); }
|
| 120 |
+
}
|
| 121 |
+
// Returns nothing; updates sight, the bust meter, spawns and contacts. evadeOn: whether the evade meter runs (pursuit only).
|
| 122 |
+
M.stepPolice = (g, wdt, evadeOn) => {
|
| 123 |
+
const p = g.pol, car = g.car, R = g.route, losTick = g.t % 4 === 0;
|
| 124 |
+
if (p.bonusT > 0) p.bonusT = Math.max(0, p.bonusT - wdt);
|
| 125 |
+
if (p.lockT > 0) p.lockT = Math.max(0, p.lockT - wdt);
|
| 126 |
+
p.formT -= wdt; if (p.formT <= 0) { p.formT = 9 + N.rand(g) * 6; p.formation = p.formations[Math.floor(N.rand(g) * p.formations.length) % p.formations.length]; }
|
| 127 |
+
let seen = 0, near = Infinity;
|
| 128 |
+
for (const c of g.cops) { if (c.gone) continue; c.hitT = Math.max(0, c.hitT - wdt); stepCop(g, c, wdt, losTick); if (!c.dead && c.state !== 'rb') { if (c.sees) seen = 1; near = Math.min(near, Math.hypot(car.x - c.x, car.y - c.y)); } contact(g, c); }
|
| 129 |
+
// Out of sight and far behind for a while: gone, so the slot can spawn a cop that can still engage (RemoveUnwantedVehicles / StartFlee; the distances are approximations).
|
| 130 |
+
for (const c of g.cops) { if (c.dead || c.state === 'rb') continue; const far = !c.sees && Math.hypot(car.x - c.x, car.y - c.y) > RECYCLE_DIST; c.lostT = far ? c.lostT + wdt : 0; if (c.lostT > RECYCLE_S) c.gone = 1; }
|
| 131 |
+
g.cops = g.cops.filter(c => !c.gone);
|
| 132 |
+
for (let i = 0; i < g.cops.length; i++) for (let j = i + 1; j < g.cops.length; j++) { const a = g.cops[i], b = g.cops[j]; if (a.dead || b.dead) continue; const dx = a.x - b.x, dy = a.y - b.y, d2 = dx * dx + dy * dy; if (d2 < 10 && d2 > 1e-4 && a.state !== 'rb' && b.state !== 'rb') { const d = Math.sqrt(d2), pu = (3.2 - d) * 0.5; a.x += dx / d * pu; a.y += dy / d * pu; b.x -= dx / d * pu; b.y -= dy / d * pu; } }
|
| 133 |
+
stepHeli(g, wdt); if (g.heli && g.heli.sees) seen = 1;
|
| 134 |
+
stepRoadblocks(g, wdt);
|
| 135 |
+
p.sawNow = seen;
|
| 136 |
+
const active = g.cops.filter(c => !c.dead && c.state !== 'rb').length;
|
| 137 |
+
p.spawnT -= wdt; if (p.spawnT <= 0 && active < p.copsMax && !p.lockT) { p.spawnT = p.spawnGap; spawnAway(g); }
|
| 138 |
+
// Bust meter (AIPursuit.cpp:1889-1940, the flash rules at :1895-1909).
|
| 139 |
+
const flashing = g.flash > 0, bdist = BUST_DIST * (flashing ? RESET_DIST : 1), slow = flashing || C.speed(car) < p.bustSpeed;
|
| 140 |
+
if (seen) { p.seen += wdt; p.sinceSeen = 0; p.lastS = g.s; p.pursuitT += wdt; } else p.sinceSeen += wdt;
|
| 141 |
+
// mIsPerpInSight is "a cop saw the perp within the last 7 s" (AIPursuit.cpp:2000), not "a cop sees the perp now".
|
| 142 |
+
p.inSight = p.sinceSeen < EVADE_AFTER ? 1 : 0;
|
| 143 |
+
p.bust = Math.max(0, p.bust + (p.inSight && slow && near < bdist ? (flashing ? RESET_RATE : 1) : -2) * wdt);
|
| 144 |
+
if (evadeOn) {
|
| 145 |
+
if (seen) p.evade *= Math.pow(0.93, wdt * 15);
|
| 146 |
+
else if (p.sinceSeen > EVADE_AFTER) p.evade = Math.max(p.evade, Math.min(1, p.sinceSeen / p.evadeTimeout));
|
| 147 |
+
}
|
| 148 |
+
if (p.bust > BUST_MAX) { p.bust = BUST_MAX; g.lose('busted'); }
|
| 149 |
+
};
|
| 150 |
+
M.BUST_MAX = BUST_MAX;
|
| 151 |
+
M.bustHp = g => Math.round((BUST_MAX - g.pol.bust) * 10);
|
| 152 |
+
// Road users for the controller: decided poses only.
|
| 153 |
+
M.copUsers = (g, R, out) => {
|
| 154 |
+
const add = (s, lat, vs, cop, vl = 0) => out.push({ s: wrapTo(R, s, g.s), lat, vs, r: 2, cop, vl });
|
| 155 |
+
for (const c of g.cops) { if (c.gone) continue; const dh = c.h - C.routeAt(R, c.s).h, still = c.dead || c.state === 'rb'; add(c.s, c.lat, still ? 0 : c.v * Math.cos(dh), still ? 0 : 1, still ? 0 : c.v * Math.sin(dh)); }
|
| 156 |
+
for (const o of g.props) if (o.type === 'barrier') add(o.s, o.lat, 0); else if (o.type === 'spike' && !o.used) for (let l = -o.len / 2; l <= o.len / 2 + 0.01; l += 2) add(o.s, o.lat + l, 0);
|
| 157 |
+
};
|
| 158 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/draw.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* NFS Most Wanted events - Module.draw: the WebGL chase view plus an original Canvas 2D HUD (speed, gear, nitrous and Speedbreaker
|
| 2 |
+
gauges, route minimap, event panel). BossBench additions: both public health bars, fight timer and the native tick rate.
|
| 3 |
+
Read-only on the game state.
|
| 4 |
+
2026-11-08: what the agent needs from the picture alone.
|
| 5 |
+
- Threat telegraphs: a warning strip when a roadblock or spike strip is on the road ahead, when a cop holds a ramming slot
|
| 6 |
+
beside the car, when the helicopter's light is on the car, when the bust meter rises; edge arrows for cops and rivals
|
| 7 |
+
outside the picture (behind, round a corner); a frame around the rear-view mirror when a cop is in it.
|
| 8 |
+
- The drag series' manual box: a tachometer with the shift window (the perfect-shift band of carStep) and a light that turns
|
| 9 |
+
green there, the launch band during staging, and the keys to press. A player who only holds W knew none of this.
|
| 10 |
+
- HUD panels keep to the screen edges and are smaller, so more of the road and the cars stays visible.
|
| 11 |
+
Everything here is drawn from state the simulation already decided this tick; nothing is written back. */
|
| 12 |
+
(function (root) {
|
| 13 |
+
'use strict';
|
| 14 |
+
const M = root.NfsmwGame, C = M.C, R = M.R3;
|
| 15 |
+
const W = 854, H = 480;
|
| 16 |
+
const panel = (c, x, y, w, h, a = 0.58) => { c.fillStyle = `rgba(10,14,22,${a})`; c.beginPath(); c.roundRect(x, y, w, h, 6); c.fill(); };
|
| 17 |
+
const bar = (c, x, y, w, h, v, col, back = 'rgba(255,255,255,.14)') => { c.fillStyle = back; c.fillRect(x, y, w, h); c.fillStyle = col; c.fillRect(x, y, w * C.clamp(v, 0, 1), h); };
|
| 18 |
+
const LABEL = { time: 'Time expired', gap: 'Rival pulled away', blown: 'Engine blown', totaled: 'Crash wreck', busted: 'Busted', knocked: 'Eliminated in last place', score: 'Lost on total score' };
|
| 19 |
+
// HUD rectangles [x0, y0, x1, y1]; the view metric counts a target under one of these as not visible.
|
| 20 |
+
const RECT = { tier: [8, 8, 150, 46], event: [158, 8, 696, 46], clock: [704, 8, 846, 46], speedo: [708, 392, 846, 472], map: [10, 372, 108, 470], tach: [708, 352, 846, 382] };
|
| 21 |
+
M.hudRects = Object.values(RECT);
|
| 22 |
+
const FONT = '"Microsoft YaHei",Consolas,sans-serif';
|
| 23 |
+
function minimap(g, c) {
|
| 24 |
+
const R0 = g.route, size = 98, x0 = RECT.map[0], y0 = RECT.map[1], big = R0.name === 'downtown', span = R0.name === 'strip' ? 700 : big ? 200 : 460, k = size / 2 / span;
|
| 25 |
+
panel(c, x0, y0, size, size, 0.62); c.save(); c.beginPath(); c.rect(x0, y0, size, size); c.clip();
|
| 26 |
+
const car = g.car, tx = u => x0 + size / 2 + (u - car.x) * k, ty = v => y0 + size / 2 - (v - car.y) * k;
|
| 27 |
+
c.lineWidth = Math.max(2.4, 8 * k * 6); c.strokeStyle = 'rgba(190,200,215,.28)';
|
| 28 |
+
for (const st of C.streets) { c.beginPath(); st.forEach((p, i) => i ? c.lineTo(tx(p[0]), ty(p[1])) : c.moveTo(tx(p[0]), ty(p[1]))); c.stroke(); }
|
| 29 |
+
c.strokeStyle = 'rgba(245,240,225,.85)'; c.beginPath(); for (let i = 0; i <= R0.n; i += 6) { const u = i % R0.n; const px = tx(R0.x[u]), py = ty(R0.y[u]); i ? c.lineTo(px, py) : c.moveTo(px, py); } if (R0.loop) c.closePath(); c.stroke();
|
| 30 |
+
const dot = (x, y, col, r = 3) => { c.fillStyle = col; c.beginPath(); c.arc(tx(x), ty(y), r, 0, 7); c.fill(); };
|
| 31 |
+
for (const gt of g.gates || []) if (!gt.done) { const a = C.routeAt(R0, gt.s !== undefined ? gt.s : g.s0 + gt.at); dot(a.x, a.y, gt.kind === 'trap' ? '#ffb037' : '#7dff9a', 3.2); }
|
| 32 |
+
for (const r of g.rivals) if (!r.gone) dot(r.x, r.y, r.name === 'champion' ? '#ff4a3a' : '#ffffff');
|
| 33 |
+
for (const b of g.breakers || []) if (!(b.rearm > 0)) dot(b.x, b.y, '#ff8a3c', 3);
|
| 34 |
+
for (const p of g.cops) if (!p.gone && !p.dead) dot(p.x, p.y, (g.t >> 4) % 2 ? '#4a8cff' : '#ff4a5a');
|
| 35 |
+
for (const p of g.props || []) if (!p.gone && p.type !== 'cone') dot(p.x, p.y, p.type === 'spike' ? '#ffd020' : '#ffe030', 2.4);
|
| 36 |
+
if (g.heli && !g.heli.gone) dot(g.heli.x, g.heli.y, '#ffffff', 2.6);
|
| 37 |
+
c.translate(tx(car.x), ty(car.y)); c.rotate(-car.h); c.fillStyle = '#ffb060'; c.beginPath(); c.moveTo(7, 0); c.lineTo(-4, 4); c.lineTo(-4, -4); c.closePath(); c.fill(); c.restore();
|
| 38 |
+
}
|
| 39 |
+
// ---- telegraphs: everything here is a fact the sim decided already (a placed prop, a cop's position, the formation) ----
|
| 40 |
+
const warnings = [];
|
| 41 |
+
function threats(g, info) {
|
| 42 |
+
warnings.length = 0; info.warn = []; info.arrows = []; info.flames = []; info.cover = [];
|
| 43 |
+
const car = g.car, R = g.route, sp = Math.max(C.speed(car), 5), ch = Math.cos(car.h), sh = Math.sin(car.h);
|
| 44 |
+
if (g.outcome) return;
|
| 45 |
+
// roadblock / spikes on the road ahead (cops.js places them max(180, 5.5 v) m ahead; the original 250 m)
|
| 46 |
+
let rb = null, sk = null;
|
| 47 |
+
for (const p of g.props || []) { if (p.gone || p.used) continue; const ds = M.wrapTo ? M.wrapTo(R, p.s, g.s) - g.s : p.s - g.s; if (ds <= 0 || ds > 320) continue; if (p.type === 'spike') { if (!sk || ds < sk.ds) sk = { ds, p }; } else if (p.type === 'barrier') { if (!rb || ds < rb.ds) rb = { ds, p }; } }
|
| 48 |
+
if (rb) { warnings.push({ col: '#ffb020', text: `Roadblock ahead: ${Math.round(rb.ds)} m (${(rb.ds / sp).toFixed(1)} s)` }); info.warn.push('roadblock'); }
|
| 49 |
+
if (sk) { warnings.push({ col: '#ffd020', text: `Spike strip: ${Math.round(sk.ds)} m · on the ${sk.p.lat > 0 ? 'left' : 'right'} side` }); info.warn.push('spikes'); }
|
| 50 |
+
// ramming formation: a cop with sight inside 12 m while PIT or BOX_IN is the formation
|
| 51 |
+
if (g.pol) {
|
| 52 |
+
const close = g.cops.filter(k => !k.dead && !k.gone && k.state !== 'rb' && k.sees && Math.hypot(k.x - car.x, k.y - car.y) < 12);
|
| 53 |
+
if (close.length && (g.pol.formation === 'PIT' || g.pol.formation === 'BOX_IN')) { const k = close[0], side = (-(k.x - car.x) * sh + (k.y - car.y) * ch) > 0 ? 'left' : 'right'; warnings.push({ col: '#ff4a5a', text: g.pol.formation === 'PIT' ? `Police car ${side} rear ready to ram` : 'Police car box-in' }); info.warn.push('pit'); }
|
| 54 |
+
if (g.heli && !g.heli.gone && g.heli.sees) { warnings.push({ col: '#cfe0ff', text: 'Helicopter spotlight locked on' }); info.warn.push('heli'); }
|
| 55 |
+
if (g.pol.bust > 0.03) info.warn.push('bust');
|
| 56 |
+
}
|
| 57 |
+
// edge arrows: cops within 160 m and rivals within 200 m that are not in the main picture
|
| 58 |
+
const sc = R3sc(g);
|
| 59 |
+
const arrow = (kind, ref, x, y, col) => {
|
| 60 |
+
if (!sc) return; const p = sc.project(x, y, 0.8); const inside = p.front && p.x > 8 && p.x < W - 8 && p.y > 50 && p.y < H - 8; if (inside) return;
|
| 61 |
+
// direction in the car's frame -> a point on an ellipse around the screen centre
|
| 62 |
+
const dx = x - car.x, dy = y - car.y, fwd = dx * ch + dy * sh, left = -dx * sh + dy * ch, ang = Math.atan2(-left, fwd); // 0 = ahead, +pi/2 = right
|
| 63 |
+
info.arrows.push({ kind, ref, ang, dist: Math.hypot(dx, dy), col });
|
| 64 |
+
};
|
| 65 |
+
g.cops.forEach((k, i) => { if (!k.gone && !k.dead && Math.hypot(k.x - car.x, k.y - car.y) < 160) arrow('cop', i, k.x, k.y, (g.t >> 3) % 2 ? '#ff4a5a' : '#4a8cff'); });
|
| 66 |
+
g.rivals.forEach((r, i) => { if (!r.gone && !r.out && Math.hypot(r.x - car.x, r.y - car.y) < 200) arrow('rival', i, r.x, r.y, r.name === 'champion' ? '#ff4a3a' : '#ffffff'); });
|
| 67 |
+
g.rivals.forEach((r, i) => { if (!r.gone && !r.out && (r.nosT > 0 || r.trapNos > 0) && r.nos > 0.02) info.flames.push(i); });
|
| 68 |
+
if (g.heli && !g.heli.gone) arrow('heli', 0, g.heli.x, g.heli.y, '#e8f0ff');
|
| 69 |
+
}
|
| 70 |
+
let cur = null; const R3sc = () => cur; // the scene this frame was rendered with (R3.render returns it)
|
| 71 |
+
function drawArrows(c, info) {
|
| 72 |
+
// one arrow per side of the screen at most: overlapping arrows (two rivals right behind) read as one, the nearest wins
|
| 73 |
+
const drawn = [];
|
| 74 |
+
for (const a of [...info.arrows].sort((p, q) => p.dist - q.dist)) {
|
| 75 |
+
const s = Math.sin(a.ang), co = Math.cos(a.ang), x = W / 2 + s * 380, y = H / 2 + 24 - co * 200;
|
| 76 |
+
let cx = C.clamp(x, 26, W - 26), cy = C.clamp(y, 64, H - 70);
|
| 77 |
+
if (cy >= H - 100 && Math.abs(cx - W / 2) < 130) cx = W / 2 + (s >= 0 ? 130 : -130); // behind: either side of the car, not over it
|
| 78 |
+
if (cy > 350 && (cx < 122 || cx > 696)) cy = 350; // clear of the minimap and the speedometer
|
| 79 |
+
if (drawn.some(d => Math.hypot(d[0] - cx, d[1] - cy) < 34)) continue; drawn.push([cx, cy]);
|
| 80 |
+
const near = C.clamp(1 - a.dist / 160, 0.25, 1), size = 9 + 9 * near;
|
| 81 |
+
c.save(); c.translate(cx, cy); c.rotate(a.ang); c.globalAlpha = 0.55 + 0.45 * near; c.fillStyle = 'rgba(0,0,0,.6)'; c.beginPath(); c.moveTo(0, -size - 3); c.lineTo(size * 0.85 + 3, size * 0.6 + 2); c.lineTo(-size * 0.85 - 3, size * 0.6 + 2); c.closePath(); c.fill();
|
| 82 |
+
c.fillStyle = a.col; c.beginPath(); c.moveTo(0, -size); c.lineTo(size * 0.85, size * 0.6); c.lineTo(-size * 0.85, size * 0.6); c.closePath(); c.fill(); c.restore();
|
| 83 |
+
c.globalAlpha = 1; c.font = 'bold 10px Consolas,monospace'; c.fillStyle = '#ffffff'; c.textAlign = 'center'; c.fillText(Math.round(a.dist) + 'm', cx, cy + (cy > H / 2 ? -14 : 22)); c.textAlign = 'left';
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
// One row at the bottom centre, on the road just in front of the bumper: the horizon band (y 150-190), where a roadblock
|
| 87 |
+
// 200 m ahead appears, stays clear.
|
| 88 |
+
function drawWarnings(c, g) {
|
| 89 |
+
if (!warnings.length) return;
|
| 90 |
+
c.font = `bold 14px ${FONT}`; const widths = warnings.map(w => c.measureText(w.text).width + 30), total = widths.reduce((a, b) => a + b, 0) + 8 * (warnings.length - 1), y = H - 32;
|
| 91 |
+
let x = W / 2 - total / 2;
|
| 92 |
+
M.hudInfo.cover.push([x, y, x + total, y + 24]);
|
| 93 |
+
for (const [i, w] of warnings.entries()) {
|
| 94 |
+
const tw = widths[i], on = (g.t >> 3) % 2 === 0;
|
| 95 |
+
c.fillStyle = 'rgba(10,10,14,.72)'; c.beginPath(); c.roundRect(x, y, tw, 24, 4); c.fill(); c.strokeStyle = w.col; c.lineWidth = on ? 3 : 1.5; c.stroke();
|
| 96 |
+
c.fillStyle = w.col; c.beginPath(); c.moveTo(x + 9, y + 18); c.lineTo(x + 15, y + 6); c.lineTo(x + 21, y + 18); c.closePath(); c.fill(); c.fillStyle = '#111'; c.fillRect(x + 14.2, y + 10, 1.6, 4.5);
|
| 97 |
+
c.fillStyle = '#ffffff'; c.textAlign = 'left'; c.fillText(w.text, x + 25, y + 17); x += tw + 8;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
// mirror frame (renderer3d draws the mirror image itself); red border while a cop is in it
|
| 101 |
+
function mirrorFrame(c, g) {
|
| 102 |
+
const sc = R3sc(g); if (!sc || !sc.mirrorOn) return; const [x0, y0, x1, y1] = sc.mirrorRect;
|
| 103 |
+
const copIn = g.cops.some(k => { if (k.gone || k.dead) return false; const dx = k.x - g.car.x, dy = k.y - g.car.y, fwd = dx * Math.cos(g.car.h) + dy * Math.sin(g.car.h); return fwd < 0 && Math.hypot(dx, dy) < 120; });
|
| 104 |
+
c.strokeStyle = copIn && (g.t >> 3) % 2 ? '#ff4a5a' : 'rgba(230,236,245,.85)'; c.lineWidth = 2.5; c.strokeRect(x0 - 1, y0 - 1, x1 - x0 + 2, y1 - y0 + 2);
|
| 105 |
+
c.font = `10px ${FONT}`; c.fillStyle = 'rgba(230,236,245,.85)'; c.fillText('Rearview mirror', x0 + 3, y1 + 11);
|
| 106 |
+
}
|
| 107 |
+
// tachometer: fraction of the current gear's top speed (carStep's u), shift band 0.88-0.99, limiter at 1
|
| 108 |
+
function tach(g, c) {
|
| 109 |
+
const car = g.car, [x, y, x1, y1] = RECT.tach, w = x1 - x, h = y1 - y, staging = g.pre > 0 && g.rev !== undefined;
|
| 110 |
+
const fwd = Math.max(0, car.vx * Math.cos(car.h) + car.vy * Math.sin(car.h)), u = staging ? g.rev : C.clamp(fwd / C.TOPS[car.gear], 0, 1.05);
|
| 111 |
+
const band = staging ? [0.62, 0.86] : [0.88, 0.99], inBand = u >= band[0] && u <= band[1];
|
| 112 |
+
panel(c, x, y, w, h, 0.7); const bx = x + 6, bw = w - 12, by = y + 6;
|
| 113 |
+
c.fillStyle = 'rgba(255,255,255,.12)'; c.fillRect(bx, by, bw, 9);
|
| 114 |
+
c.fillStyle = 'rgba(90,255,140,.55)'; c.fillRect(bx + bw * band[0], by, bw * (band[1] - band[0]), 9);
|
| 115 |
+
if (!staging) { c.fillStyle = 'rgba(255,70,60,.55)'; c.fillRect(bx + bw * 0.99, by, bw * 0.01 + 2, 9); }
|
| 116 |
+
c.fillStyle = inBand ? '#7dff9a' : u > band[1] ? '#ff5a4a' : '#ffd08a'; c.fillRect(bx, by + 2, bw * C.clamp(u, 0, 1), 5);
|
| 117 |
+
c.font = `bold 11px ${FONT}`; c.fillStyle = inBand ? '#7dff9a' : '#c6d0dc';
|
| 118 |
+
c.fillText(staging ? (inBand ? 'Launch RPM ✓ Hold steady' : g.rev < band[0] ? 'Hold W to raise RPM into the green zone' : 'RPM too high; release W briefly') : car.gear >= 5 ? 'Top gear · Stay below the redline' : inBand ? '▶ Press K to upshift' : u > band[1] ? 'Press K to upshift now!' : `RPM → Green zone: press K`, bx, by + 21);
|
| 119 |
+
if (inBand && !staging && car.gear < 5 && (g.t >> 2) % 2) { c.strokeStyle = '#7dff9a'; c.lineWidth = 2; c.strokeRect(x + 1, y + 1, w - 2, h - 2); }
|
| 120 |
+
}
|
| 121 |
+
M.draw = function (g, c) {
|
| 122 |
+
const sc = R.render(g, c), info = {}; cur = sc;
|
| 123 |
+
M.hudInfo = info;
|
| 124 |
+
const car = g.car, kmh = C.speed(car) * 3.6, h = g.health(), hud = (M.MODES[g.key].hud || (() => ({ label: '', detail: '' })))(g);
|
| 125 |
+
threats(g, info);
|
| 126 |
+
// knockout: the mode's text measures the last rival still in, and after the win none is left ( 11-06 item 7)
|
| 127 |
+
if (g.key === 'knockout' && g.outcome === 'win') hud.detail = `${g.laps} / ${g.laps} laps · All rivals eliminated`;
|
| 128 |
+
if (g.sb) { const v = c.createRadialGradient(W / 2, H / 2, 150, W / 2, H / 2, 520); v.addColorStop(0, 'rgba(120,170,255,0)'); v.addColorStop(1, 'rgba(70,110,220,.42)'); c.fillStyle = v; c.fillRect(0, 0, W, H); }
|
| 129 |
+
// hit: a red vignette at the edges, not a full-screen wash, so the road stays readable
|
| 130 |
+
if (g.lastHit > 0) { const v = c.createRadialGradient(W / 2, H / 2, 170, W / 2, H / 2, 500); v.addColorStop(0, 'rgba(220,40,30,0)'); v.addColorStop(1, `rgba(220,40,30,${Math.min(0.75, g.lastHit * 1.6)})`); c.fillStyle = v; c.fillRect(0, 0, W, H); }
|
| 131 |
+
if (g.flash > 0 && (g.t >> 3) % 2) { c.fillStyle = 'rgba(255,255,255,.1)'; c.fillRect(0, 0, W, H); }
|
| 132 |
+
mirrorFrame(c, g);
|
| 133 |
+
info.cover.push(RECT.tier, RECT.event, RECT.clock, RECT.speedo, RECT.map); if (g.manual) info.cover.push(RECT.tach); if (sc && sc.mirrorOn) info.cover.push(sc.mirrorRect);
|
| 134 |
+
// event panel: boss_hp and player_hp under their event-specific names
|
| 135 |
+
const [ex0, ey0, ex1] = RECT.event; panel(c, ex0, ey0, ex1 - ex0, 38);
|
| 136 |
+
c.font = `bold 12px ${FONT}`; c.fillStyle = '#f2ecdc'; c.textAlign = 'left'; c.fillText(hud.label || '', ex0 + 8, ey0 + 14);
|
| 137 |
+
c.font = `11px ${FONT}`; c.fillStyle = '#c6d0dc'; c.textAlign = 'right'; c.fillText(hud.detail || '', ex1 - 8, ey0 + 14); c.textAlign = 'left';
|
| 138 |
+
bar(c, ex0 + 8, ey0 + 20, ex1 - ex0 - 16, 5, h[3] ? h[2] / h[3] : 0, '#ff8a3c');
|
| 139 |
+
bar(c, ex0 + 8, ey0 + 28, ex1 - ex0 - 16, 5, h[1] ? h[0] / h[1] : 0, h[0] / (h[1] || 1) < 0.25 ? '#ff4a3a' : '#5bd18a');
|
| 140 |
+
// clock and tier
|
| 141 |
+
const [cx0, cy0, cx1] = RECT.clock; panel(c, cx0, cy0, cx1 - cx0, 38); c.textAlign = 'right'; c.font = 'bold 16px Consolas,monospace'; c.fillStyle = '#f2ecdc'; c.fillText((g.t / M.hz).toFixed(1) + ' s', cx1 - 8, cy0 + 18);
|
| 142 |
+
c.font = 'bold 10px Consolas,monospace'; c.fillStyle = '#9fd0ff'; c.fillText(M.hz + 'Hz · tick ' + g.t, cx1 - 8, cy0 + 32); c.textAlign = 'left';
|
| 143 |
+
const [tx0, ty0, tx1] = RECT.tier; panel(c, tx0, ty0, tx1 - tx0, 38); c.font = 'bold 11px Consolas,monospace'; c.fillStyle = '#ffd08a'; c.fillText((g.tier || '').toUpperCase() + ' d=' + g.d, tx0 + 8, ty0 + 16); c.fillStyle = '#b8c2cc'; c.font = '10px Consolas,monospace'; c.fillText(M.version, tx0 + 8, ty0 + 30);
|
| 144 |
+
// speedometer
|
| 145 |
+
const [sx0, sy0, sx1, sy1] = RECT.speedo; panel(c, sx0, sy0, sx1 - sx0, sy1 - sy0); c.textAlign = 'right'; c.font = 'bold 32px Consolas,monospace'; c.fillStyle = '#ffffff'; c.fillText(String(Math.round(kmh)), sx1 - 40, sy0 + 34);
|
| 146 |
+
c.font = '10px Consolas,monospace'; c.fillStyle = '#a8b4c0'; c.fillText('KM/H', sx1 - 8, sy0 + 34);
|
| 147 |
+
c.font = 'bold 18px Consolas,monospace'; c.fillStyle = car.over ? '#ff5a4a' : '#ffd08a'; c.textAlign = 'center'; c.fillText(String(car.gear + 1), sx0 + 14, sy0 + 26); c.textAlign = 'left';
|
| 148 |
+
c.font = '9px Consolas,monospace'; c.fillStyle = '#9fc8ff'; c.fillText('NOS', sx0 + 6, sy0 + 52); bar(c, sx0 + 34, sy0 + 45, sx1 - sx0 - 42, 7, car.nos, car.nosOn ? '#bfe4ff' : '#4aa0ff');
|
| 149 |
+
c.fillStyle = '#ffd08a'; c.fillText('SLOW', sx0 + 6, sy0 + 64); bar(c, sx0 + 34, sy0 + 57, sx1 - sx0 - 42, 7, g.sbMeter, g.sb ? '#ffffff' : '#ffb84a');
|
| 150 |
+
if (g.manual) { c.fillStyle = '#ff9a7a'; c.fillText('HEAT', sx0 + 6, sy0 + 76); bar(c, sx0 + 34, sy0 + 70, sx1 - sx0 - 42, 6, car.heat, car.heat > 0.6 ? '#ff4a3a' : '#ffa14a'); }
|
| 151 |
+
if (g.manual) tach(g, c);
|
| 152 |
+
minimap(g, c);
|
| 153 |
+
if (M.MODES[g.key].hudExtra) M.MODES[g.key].hudExtra(g, c, { panel, bar, W, H });
|
| 154 |
+
drawArrows(c, info); drawWarnings(c, g);
|
| 155 |
+
if (g.pre > 0) {
|
| 156 |
+
c.font = 'bold 54px Consolas,monospace'; c.textAlign = 'center'; c.fillStyle = '#ffe28a'; c.fillText(String(Math.ceil(g.pre)), W / 2, 210);
|
| 157 |
+
if (g.manual) { c.font = `bold 14px ${FONT}`; c.fillStyle = '#ffffff'; c.fillText('Manual gears: K upshift · L downshift · A / D change lanes', W / 2, 238); }
|
| 158 |
+
c.textAlign = 'left';
|
| 159 |
+
}
|
| 160 |
+
if (g.outcome) { c.fillStyle = 'rgba(0,0,0,.42)'; c.fillRect(0, H / 2 - 44, W, 88); c.font = 'bold 36px "Microsoft YaHei",sans-serif'; c.textAlign = 'center'; c.fillStyle = g.outcome === 'win' ? '#7dff9a' : '#ff6a5a'; c.fillText(g.outcome === 'win' ? 'Challenge complete' : g.outcome === 'timeout' ? 'Time up' : (LABEL[g.lossReason] || 'Challenge Failed'), W / 2, H / 2 + 13); c.textAlign = 'left'; }
|
| 161 |
+
return sc;
|
| 162 |
+
};
|
| 163 |
+
M.renderStatus = ctx => R.status(ctx);
|
| 164 |
+
M.renderMetrics = ctx => R.metrics(ctx);
|
| 165 |
+
M.closeRenderer = ctx => R.close(ctx);
|
| 166 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/game.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Need for Speed: Most Wanted (2005) events, rules nfsmw-arena@2 - the module: cases, tiers, the tick, the health mapping.
|
| 2 |
+
A race has no health bars, so the public contract maps onto the event's own win and loss conditions:
|
| 3 |
+
boss_hp is what is left of the event (route metres from a high-water mark, so it never jumps back), and player_hp
|
| 4 |
+
is what the opponent still needs to beat you (clock, gap, score margin, bust meter). See
|
| 5 |
+
Independent reimplementation; facts read from the CC0 decompilation dbalatoni13/nfsmw@80993f3 are cited as file:line
|
| 6 |
+
in that repository. All art is procedural; no game data (VLT attributes, models, textures, audio, maps) is used. */
|
| 7 |
+
(function (root) {
|
| 8 |
+
'use strict';
|
| 9 |
+
const N = root.NativeBench, M = root.NfsmwGame, C = M.C;
|
| 10 |
+
const HZ = 60, DT = 1 / HZ;
|
| 11 |
+
// Tiers are one fight at three paces: event length, opponent skill, traffic and police pressure all scale continuously.
|
| 12 |
+
// The original has no mode gate on these values (GRace.h: Easy/Medium/Hard is a per-event parameter), so hard stays 0.85.
|
| 13 |
+
const TIERS = { easy: 0.2, normal: 0.5, hard: 0.85 };
|
| 14 |
+
// Piecewise linear through the three tier values, extrapolated beyond them, so any d in [0,1] is a valid fight.
|
| 15 |
+
const tierValue = (d, [e, n, h]) => d <= TIERS.normal ? n + (e - n) * (TIERS.normal - d) / (TIERS.normal - TIERS.easy) : n + (h - n) * (d - TIERS.normal) / (TIERS.hard - TIERS.normal);
|
| 16 |
+
const tierOf = d => d <= (TIERS.easy + TIERS.normal) / 2 ? 'easy' : d <= (TIERS.normal + TIERS.hard) / 2 ? 'normal' : 'hard';
|
| 17 |
+
M.MODES = M.MODES || {};
|
| 18 |
+
|
| 19 |
+
const CASES = [
|
| 20 |
+
{ id: 'nfsmw/tollbooth', name: 'Tollbooth Race (Coastal Highway)' },
|
| 21 |
+
{ id: 'nfsmw/drag', name: 'Drag Series (Highway 99)' },
|
| 22 |
+
{ id: 'nfsmw/speedtrap', name: 'Speed Trap (Coastal Highway)' },
|
| 23 |
+
{ id: 'nfsmw/knockout', name: 'Lap Knockout (Downtown Night Race)' },
|
| 24 |
+
{ id: 'nfsmw/pursuit', name: 'Police Pursuit (Bounty + Escape)' },
|
| 25 |
+
{ id: 'nfsmw/street_champion', name: 'Street Champion Showdown (Multi-leg Race + Police)' },
|
| 26 |
+
];
|
| 27 |
+
Object.assign(M, {
|
| 28 |
+
id: 'nfsmw_remake', version: 'nfsmw-arena@2', hz: HZ, maxSeconds: 300, dimension: '3d', renderer: 'webgl-nfsmw',
|
| 29 |
+
title: 'Need for Speed: Most Wanted · Street Challenges', cases: CASES, tiers: TIERS, tierValue, tierOf, DT,
|
| 30 |
+
controls: {
|
| 31 |
+
'W': 'throttle', 'S': 'brake; reverse at low speed', 'A / D': 'Steer left / right (steering increases while held and decreases at higher speed)', 'Space': 'Handbrake (drift)',
|
| 32 |
+
'Shift': 'nitrous', 'J': 'Toggle slow motion (time slows and downforce increases)', 'K / L': 'Manual upshift / downshift in drag races (A / D change lanes)', 'R': 'Reset onto the route (easier to bust during the 2-second flashing period)',
|
| 33 |
+
},
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
// SB: world time scale is in the ITimeManager data (not in the repository), approximation 0.45; the handling side is
|
| 37 |
+
// SuspensionRacer.cpp:936 Tweak_GameBreakerExtraGs (-2 g of extra downforce) with a 1/3 s physics ramp-out (:937).
|
| 38 |
+
const SB_SCALE = 0.45, SB_GRIP = 2 * 9.81, SB_RAMP = 1 / 3, SB_SECONDS = 6;
|
| 39 |
+
const RESET_INVULN = 2; // ResetCar.cpp:26 Tweak_ResetInvulnerablitiyTime
|
| 40 |
+
|
| 41 |
+
class Game {
|
| 42 |
+
constructor(id, seed, d) {
|
| 43 |
+
this.id = id; this.key = id.split('/')[1]; this.d = d; this.tier = tierOf(d);
|
| 44 |
+
this.t = 0; this.outcome = null; this.events = []; this.seed = seed;
|
| 45 |
+
// The multiply decorrelates neighbouring seeds; xorshift has a fixed point at zero.
|
| 46 |
+
this.rng = (Math.imul((seed >>> 0) + 1, 2654435761) >>> 0) || 1;
|
| 47 |
+
this.pre = 1.2; this.clock = 0; // staging countdown; event clock in world seconds
|
| 48 |
+
this.sb = 0; this.sbMeter = 1; this.sbRamp = 0; // Speedbreaker
|
| 49 |
+
this.flash = 0; this.resets = 0; this.hits = 0; this.nearMisses = 0; this.manual = 0; this.lastHit = 0;
|
| 50 |
+
this.slowT = 0; this.s = 0; this.s0 = 0; this.prog = 0; this.total = 1; this.lat = 0; this.offRoute = 0;
|
| 51 |
+
this.traffic = []; this.rivals = []; this.cops = []; this.props = []; this.gates = []; this.status = '';
|
| 52 |
+
const mode = M.MODES[this.key]; if (!mode) throw Error('Unknown event ' + id);
|
| 53 |
+
this.routeKey = mode.route(d);
|
| 54 |
+
mode.init(this, d);
|
| 55 |
+
this.camH = this.car.h; this.heldBrake = 0; this.flashT = 0; this.heli = null;
|
| 56 |
+
}
|
| 57 |
+
get route() { return C.routes[this.routeKey]; }
|
| 58 |
+
placeCar(s, lat, speed = 0) {
|
| 59 |
+
const a = C.routeAt(this.route, s, lat), c = C.newCar(a.x, a.y, a.h);
|
| 60 |
+
c.vx = Math.cos(a.h) * speed; c.vy = Math.sin(a.h) * speed;
|
| 61 |
+
this.car = c; this.s = s; this.lat = lat;
|
| 62 |
+
}
|
| 63 |
+
update(keys, pressed) {
|
| 64 |
+
const mode = M.MODES[this.key], car = this.car;
|
| 65 |
+
this.heldBrake = keys.has('S') ? 1 : 0;
|
| 66 |
+
// Chase camera: lags the heading (state only the renderer reads; it cannot affect the simulation).
|
| 67 |
+
{ let dh = car.h - this.camH; dh = Math.atan2(Math.sin(dh), Math.cos(dh)); this.camH += dh * Math.min(1, DT * 5.5); }
|
| 68 |
+
if (this.lastHit > 0) this.lastHit = Math.max(0, this.lastHit - DT);
|
| 69 |
+
if (this.flash > 0) this.flash = Math.max(0, this.flash - DT);
|
| 70 |
+
if (pressed.has('J') && (this.sb || this.sbMeter > 0.05)) { this.sb = this.sb ? 0 : 1; if (!this.sb) this.sbRamp = SB_RAMP; this.events.push({ type: this.sb ? 'slowmo_on' : 'slowmo_off' }); }
|
| 71 |
+
if (this.sb) { this.sbMeter = Math.max(0, this.sbMeter - DT / SB_SECONDS); if (this.sbMeter <= 0) { this.sb = 0; this.sbRamp = SB_RAMP; } }
|
| 72 |
+
else if (this.sbRamp > 0) this.sbRamp = Math.max(0, this.sbRamp - DT);
|
| 73 |
+
const wdt = DT * (this.sb ? SB_SCALE : 1);
|
| 74 |
+
if (this.pre > 0) { // staging: the world runs, the car is held at the line
|
| 75 |
+
this.pre = Math.max(0, this.pre - DT);
|
| 76 |
+
if (mode.staging) mode.staging(this, keys, pressed, DT);
|
| 77 |
+
M.stepTraffic(this, wdt); if (mode.idle) mode.idle(this, wdt);
|
| 78 |
+
return;
|
| 79 |
+
}
|
| 80 |
+
if (pressed.has('R')) this.resetCar();
|
| 81 |
+
const speed = C.speed(car), fwd = car.vx * Math.cos(car.h) + car.vy * Math.sin(car.h);
|
| 82 |
+
const inp = {
|
| 83 |
+
thr: keys.has('W') ? 1 : 0, brk: keys.has('S'), steer: (keys.has('A') ? 1 : 0) - (keys.has('D') ? 1 : 0), hb: keys.has('Space'), nos: keys.has('Shift'),
|
| 84 |
+
up: this.manual && pressed.has('K'), down: this.manual && pressed.has('L'), manual: !!this.manual, reverse: keys.has('S') && fwd < 2 && speed < 6,
|
| 85 |
+
sbGrip: this.sb ? SB_GRIP : SB_GRIP * this.sbRamp / SB_RAMP,
|
| 86 |
+
};
|
| 87 |
+
if (mode.input) mode.input(this, inp, keys, pressed);
|
| 88 |
+
C.carStep(car, inp, wdt, this.P || C.PLAYER);
|
| 89 |
+
if (car.hit > 3) { this.hits++; if (car.hit > 6) this.lastHit = 0.4; this.events.push({ type: 'wall', speed: car.hit }); }
|
| 90 |
+
if (!this.sb && speed > 35) this.sbMeter = Math.min(1, this.sbMeter + wdt * 0.02);
|
| 91 |
+
this.slowT = C.speed(car) < 2 ? this.slowT + DT : 0;
|
| 92 |
+
this.clock += wdt;
|
| 93 |
+
this.trackProgress();
|
| 94 |
+
M.stepTraffic(this, wdt);
|
| 95 |
+
mode.tick(this, wdt);
|
| 96 |
+
}
|
| 97 |
+
// Progress is route distance from a high-water mark, inside a short window so a junction can't jump to another leg.
|
| 98 |
+
trackProgress() {
|
| 99 |
+
const R = this.route, c = this.car;
|
| 100 |
+
this.s = C.routeNear(R, c.x, c.y, this.s);
|
| 101 |
+
this.lat = C.routeLat(R, c.x, c.y, this.s);
|
| 102 |
+
this.offRoute = Math.abs(this.lat) > R.halfW + 3 ? 1 : 0;
|
| 103 |
+
if (!this.offRoute && this.s - this.s0 > this.prog) this.prog = Math.min(this.total, this.s - this.s0);
|
| 104 |
+
}
|
| 105 |
+
resetCar() {
|
| 106 |
+
const s = this.s0 + this.prog, a = C.routeAt(this.route, s, 0), keep = this.car;
|
| 107 |
+
Object.assign(keep, { x: a.x, y: a.y, h: a.h, vx: 0, vy: 0, r: 0, steer: 0, gear: 0, clutch: 0, tires: 0 }); // tyres: approximation, see SOURCES.md
|
| 108 |
+
this.s = s; this.lat = 0; this.slowT = 0; this.flash = RESET_INVULN; this.resets++;
|
| 109 |
+
this.events.push({ type: 'reset' });
|
| 110 |
+
}
|
| 111 |
+
win() { if (!this.outcome) { this.outcome = 'win'; this.events.push({ type: 'win' }); } }
|
| 112 |
+
lose(why) { if (!this.outcome) { this.outcome = 'loss'; this.lossReason = why; this.events.push({ type: 'loss', why }); } }
|
| 113 |
+
health() { return M.MODES[this.key].health(this); }
|
| 114 |
+
}
|
| 115 |
+
Object.assign(M, { Game, DT, copyGame: g => Object.assign(Object.create(Game.prototype), N.copy(g)) });
|
| 116 |
+
|
| 117 |
+
// ---------------- traffic (AIActionTraffic: stays in lane at the speed limit, does not race, does not dodge) ----------------
|
| 118 |
+
const carRadius = 1.6;
|
| 119 |
+
M.carRadius = carRadius;
|
| 120 |
+
M.spawnTraffic = (g, n, opt = {}) => {
|
| 121 |
+
g.trafficOpt = { ahead: opt.ahead || 420, spread: opt.spread || 620, opposing: opt.opposing === undefined ? 0.35 : opt.opposing, lanes: opt.lanes || null };
|
| 122 |
+
for (let i = 0; i < n; i++) {
|
| 123 |
+
const t = { s: 0, lat: 0, dir: 1, v: 0, x: 0, y: 0, h: 0, crash: 0, vx: 0, vy: 0, nm: 0, paint: i % 6 };
|
| 124 |
+
placeTraffic(g, t, g.s + 90 + (g.trafficOpt.spread + g.trafficOpt.ahead) * (i + N.rand(g)) / n);
|
| 125 |
+
g.traffic.push(t);
|
| 126 |
+
}
|
| 127 |
+
};
|
| 128 |
+
const lanesOf = (R, dir) => dir > 0 ? [-R.halfW * 0.25, -R.halfW * 0.72] : [R.halfW * 0.25, R.halfW * 0.72];
|
| 129 |
+
function placeTraffic(g, t, s) {
|
| 130 |
+
const R = g.route, o = g.trafficOpt;
|
| 131 |
+
t.dir = N.rand(g) < o.opposing ? -1 : 1; t.nm = 0; t.crash = 0; t.vx = 0; t.vy = 0;
|
| 132 |
+
const lanes = o.lanes || lanesOf(R, t.dir); t.lat = lanes[Math.floor(N.rand(g) * lanes.length) % lanes.length];
|
| 133 |
+
t.v = t.dir * (17 + N.rand(g) * 9); t.s = s;
|
| 134 |
+
if (!R.loop) t.s = C.clamp(s, 40, R.L - 40);
|
| 135 |
+
const a = C.routeAt(R, t.s, t.lat); t.x = a.x; t.y = a.y; t.h = t.dir > 0 ? a.h : a.h + Math.PI;
|
| 136 |
+
}
|
| 137 |
+
M.stepTraffic = (g, wdt) => {
|
| 138 |
+
const R = g.route, c = g.car;
|
| 139 |
+
for (const t of g.traffic) {
|
| 140 |
+
if (t.crash) { // knocked out of lane: a free body that coasts to a stop
|
| 141 |
+
t.x += t.vx * wdt; t.y += t.vy * wdt; const f = Math.max(0, 1 - 1.6 * wdt); t.vx *= f; t.vy *= f; t.h += t.crash * wdt; t.crash *= f;
|
| 142 |
+
const q = C.road(t.x, t.y), over = q.d + 1.2; if (over > 0) { t.x -= q.nx * over; t.y -= q.ny * over; t.vx = 0; t.vy = 0; }
|
| 143 |
+
t.s = C.routeNear(R, t.x, t.y, t.s, 10, 10); t.lat = C.routeLat(R, t.x, t.y, t.s);
|
| 144 |
+
} else {
|
| 145 |
+
t.s += t.v * wdt; const a = C.routeAt(R, t.s, t.lat); t.x = a.x; t.y = a.y; t.h = t.dir > 0 ? a.h : a.h + Math.PI;
|
| 146 |
+
}
|
| 147 |
+
const rel = t.s - g.s;
|
| 148 |
+
if (rel < -140 || rel > g.trafficOpt.ahead + g.trafficOpt.spread + 60 || (!R.loop && (t.s < 30 || t.s > R.L - 30))) { placeTraffic(g, t, g.s + g.trafficOpt.ahead + N.rand(g) * g.trafficOpt.spread); continue; }
|
| 149 |
+
const dx = c.x - t.x, dy = c.y - t.y, dist2 = dx * dx + dy * dy;
|
| 150 |
+
if (dist2 < 30 && !t.nm && C.speed(c) > 25) { const d = Math.sqrt(dist2); if (d > carRadius * 2 + 0.4 && d < 4.6) { t.nm = 1; g.nearMisses++; g.sbMeter = Math.min(1, g.sbMeter + 0.04); } }
|
| 151 |
+
if (dist2 < (carRadius * 2) * (carRadius * 2)) M.bump(g, t, dx, dy, dist2, 0.8);
|
| 152 |
+
}
|
| 153 |
+
};
|
| 154 |
+
// Player against a lighter body: momentum exchange along the contact normal. Returns the closing speed.
|
| 155 |
+
M.bump = (g, o, dx, dy, dist2, mass) => {
|
| 156 |
+
const c = g.car, d = Math.max(0.01, Math.sqrt(dist2)), nx = dx / d, ny = dy / d;
|
| 157 |
+
const moving = o.v !== undefined && !o.crash, ovx = moving ? Math.cos(o.h) * Math.abs(o.v) : o.vx, ovy = moving ? Math.sin(o.h) * Math.abs(o.v) : o.vy;
|
| 158 |
+
const rel = (c.vx - ovx) * nx + (c.vy - ovy) * ny, push = carRadius * 2 - d;
|
| 159 |
+
c.x += nx * push * 0.6; c.y += ny * push * 0.6;
|
| 160 |
+
if (rel >= 0) return 0;
|
| 161 |
+
const j = -(1.3) * rel * mass / (1 + mass);
|
| 162 |
+
c.vx += nx * j; c.vy += ny * j; c.r += ((nx * c.vy - ny * c.vx) > 0 ? 1 : -1) * Math.min(0.8, -rel * 0.02);
|
| 163 |
+
o.vx = ovx - nx * j / mass * 1.0; o.vy = ovy - ny * j / mass * 1.0; if (o.v !== undefined && !o.crash) o.crash = nx * Math.sin(o.h) - ny * Math.cos(o.h) > 0 ? 0.8 : -0.8;
|
| 164 |
+
if (-rel > 4) { g.hits++; g.lastHit = 0.4; g.events.push({ type: 'crash', speed: -rel }); }
|
| 165 |
+
return -rel;
|
| 166 |
+
};
|
| 167 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/index.html
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="data:,"><title>Need for Speed: Most Wanted · Street Challenges(nfsmw-arena@2)</title><link rel="stylesheet" href="../_native/style.css"><style>body[data-game=nfsmw_remake]{--bg:#161a20;--panel:#222831;--edge:#4b5563;--accent:#ff9a4a}body[data-game=nfsmw_remake] #overlay{display:none!important}#nfs-panel{position:absolute;left:0;top:0;width:100%;aspect-ratio:854/480;display:flex;align-items:center;justify-content:center;background:rgba(6,10,16,.5);cursor:pointer;z-index:2}#nfs-panel[hidden]{display:none}.nfs-card{background:#10161eee;border:1px solid var(--edge);border-radius:6px;padding:14px 22px 12px;max-width:560px;text-align:center;cursor:default;box-shadow:0 8px 30px #0008}.nfs-card h2{margin:2px 0 6px;font-size:22px}.nfs-card h2.win{color:#7dff9a}.nfs-card h2.loss{color:#ff7a66}.nfs-card ul{text-align:left;margin:6px 0 10px;padding-left:20px;font-size:13px;color:var(--muted)}.nfs-card .tip{color:#ffd08a;font-size:13px;margin:6px 0}.nfs-card .row{display:flex;gap:10px;justify-content:center;margin:8px 0 4px}.nfs-card .small{font-size:12px;color:var(--muted);margin:4px 0 0}#nfs-panel{overflow:hidden}@media(max-width:900px){.nfs-card{padding:6px 10px;max-width:96%;max-height:100%;overflow:hidden}.nfs-card h2{font-size:16px;margin:0 0 2px}.nfs-card ul,.nfs-card .small{display:none}.nfs-card p{font-size:12px;margin:2px 0}.nfs-card .row{margin:4px 0 0}.nfs-card button{padding:4px 8px;font-size:13px}}</style></head><body><main>
|
| 3 |
+
<header><div><h1>Need for Speed: Most Wanted · Street Challenges</h1><p>2005 original rules, independently recreated from CC0 decompilation · Native 60 Hz · Third-person WebGL · Original procedural city</p></div><a href="../../index.html">Back to Game Lobby</a></header>
|
| 4 |
+
<div class="layout"><section><div class="stage"><canvas width="854" height="480" tabindex="0" aria-label="Game Screen"></canvas><div id="nfs-panel"><div class="nfs-card"></div></div><div id="overlay"><div>Select an event, then start the challenge</div></div><div class="toolbar"><button id="start" class="primary">Start Challenge / Restart</button><button id="pause">Resume</button><button id="step">Step</button><button id="demo">Scripted Demo</button><button id="sample">Example Replay</button></div></div><div class="mobile"><button data-key="A">← left</button><button data-key="W">Accelerate</button><button data-key="D">right →</button><button data-key="S">Brake</button><button data-key="Space">Handbrake</button><button data-key="Shift">Nitrous</button><button data-key="J">Slow motion</button><button data-key="R">Reset</button></div><p id="status" role="status"></p><div class="toolbar"><button id="export">Export Current Replay</button><button id="import">Import and Replay</button><input id="file" type="file" accept=".json,application/json"></div><p class="note">Replays save inputs and the seed, then simulate the match again and verify the final state. Scripted Demo reads internal state for verification; it does not start RL training.</p></section>
|
| 5 |
+
<aside><div><h2>Select Challenge</h2><label for="case">Event</label><select id="case"></select><label for="seed">Seed</label><input id="seed" type="number" min="0" max="4294967295" value="1" step="1"></div><div><label for="difficulty">Difficulty</label><select id="difficulty"></select><p class="note">The three tiers vary the pace of the same event: route length, rival skill, traffic, and police pressure all increase.</p><p class="note">The two top bars show event progress: orange is the remaining event objective (boss_hp, which only decreases); green is your remaining margin (player_hp, based on time, distance, or the bust meter).</p></div><dl></dl></aside></div>
|
| 6 |
+
<footer></footer></main>
|
| 7 |
+
<script src="../_native/runtime.js"></script><script src="../_boss3d/vendor/three.min.js"></script><script src="nfscore.js"></script><script src="game.js"></script><script src="rivals.js"></script><script src="modes_tollbooth.js"></script><script src="modes_drag.js"></script><script src="modes_speedtrap.js"></script><script src="modes_knockout.js"></script><script src="cops.js"></script><script src="modes_pursuit.js"></script><script src="scripted.js"></script><script src="renderer3d.js"></script><script src="draw.js"></script><script>window.GAME_MODULE=window.NfsmwGame;</script><script src="../_native/shell.js"></script><script src="page.js"></script></body></html>
|
environments/games/web/games/nfsmw_remake/manifest.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/game-manifest@1",
|
| 3 |
+
"engine": "independent",
|
| 4 |
+
"game": "nfsmw_remake",
|
| 5 |
+
"module": "NfsmwGame",
|
| 6 |
+
"title": "Need for Speed Most Wanted: Street Challenges",
|
| 7 |
+
"dimension": "3d",
|
| 8 |
+
"native_hz": 60,
|
| 9 |
+
"max_seconds": 300,
|
| 10 |
+
"renderer": "webgl-nfsmw",
|
| 11 |
+
"rules": "nfsmw-arena@2",
|
| 12 |
+
"cases": [
|
| 13 |
+
"nfsmw/tollbooth",
|
| 14 |
+
"nfsmw/drag",
|
| 15 |
+
"nfsmw/speedtrap",
|
| 16 |
+
"nfsmw/knockout",
|
| 17 |
+
"nfsmw/pursuit",
|
| 18 |
+
"nfsmw/street_champion"
|
| 19 |
+
],
|
| 20 |
+
"scripts": [
|
| 21 |
+
"_native/runtime.js",
|
| 22 |
+
"_boss3d/vendor/three.min.js",
|
| 23 |
+
"nfsmw_remake/nfscore.js",
|
| 24 |
+
"nfsmw_remake/game.js",
|
| 25 |
+
"nfsmw_remake/rivals.js",
|
| 26 |
+
"nfsmw_remake/modes_tollbooth.js",
|
| 27 |
+
"nfsmw_remake/modes_drag.js",
|
| 28 |
+
"nfsmw_remake/modes_speedtrap.js",
|
| 29 |
+
"nfsmw_remake/modes_knockout.js",
|
| 30 |
+
"nfsmw_remake/cops.js",
|
| 31 |
+
"nfsmw_remake/modes_pursuit.js",
|
| 32 |
+
"nfsmw_remake/scripted.js",
|
| 33 |
+
"nfsmw_remake/renderer3d.js",
|
| 34 |
+
"nfsmw_remake/draw.js"
|
| 35 |
+
],
|
| 36 |
+
"sim_scripts": [
|
| 37 |
+
"_native/runtime.js",
|
| 38 |
+
"nfsmw_remake/nfscore.js",
|
| 39 |
+
"nfsmw_remake/game.js",
|
| 40 |
+
"nfsmw_remake/rivals.js",
|
| 41 |
+
"nfsmw_remake/modes_tollbooth.js",
|
| 42 |
+
"nfsmw_remake/modes_drag.js",
|
| 43 |
+
"nfsmw_remake/modes_speedtrap.js",
|
| 44 |
+
"nfsmw_remake/modes_knockout.js",
|
| 45 |
+
"nfsmw_remake/cops.js",
|
| 46 |
+
"nfsmw_remake/modes_pursuit.js",
|
| 47 |
+
"nfsmw_remake/scripted.js"
|
| 48 |
+
],
|
| 49 |
+
"play_page": "web/games/nfsmw_remake/index.html",
|
| 50 |
+
"scripted_controller": "NfsmwGame.scripted(game) -> {holds:[6 key arrays], mouse:[0,0,0]}; pure car-model look-ahead, others extrapolated at constant speed (NfsmwGame.oracle is an alias)",
|
| 51 |
+
"tests": [
|
| 52 |
+
"nfsmw_remake/tests/mechanics.js"
|
| 53 |
+
],
|
| 54 |
+
"source": "https://github.com/dbalatoni13/nfsmw/tree/80993f35224c61d2f1b135beba76c6f8234c7940 (CC0-1.0)"
|
| 55 |
+
}
|
environments/games/web/games/nfsmw_remake/modes_drag.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Drag (GRace.h kRaceType_Drag), run as a series the way a Blacklist rival is fought (Wikipedia: "win against the racer in a
|
| 2 |
+
successive series of races"). Rules that exist only here, all from the decompilation:
|
| 3 |
+
- manual gearbox with a perfect-shift bonus (EngineRacer EPerfectShift; the window width is VLT, approximation);
|
| 4 |
+
- over-rev heat, EngineRacer.cpp:1340-1345: +0.45/s on the limiter, -0.1/s otherwise, torque -25% from 0.6, blown at 1;
|
| 5 |
+
- the car steers itself and the driver changes lanes (AIVehicle.cpp IsDragSteering, ChangeDragLanes);
|
| 6 |
+
- total on hard contact, DamageDragster.cpp: above 100 mph, losing more than 40 mph in one impact destroys the car;
|
| 7 |
+
- launch: GetPerfectLaunchRange, EngineRacer.cpp:127-135 (a band a quarter of the rev range below the redline).
|
| 8 |
+
boss_hp = metres left in the whole series; player_hp = metres the rival still needs in this heat. */
|
| 9 |
+
(function (root) {
|
| 10 |
+
'use strict';
|
| 11 |
+
const M = root.NfsmwGame, C = M.C, clamp = C.clamp;
|
| 12 |
+
const MPH = C.MPH, KILL_SPEED = 100 * MPH, KILL_DELTA = 40 * MPH, STAGE = 2.5; // AIActionRace.cpp:99 Tweak_UnstageTime
|
| 13 |
+
const LANES = [-7.5, -2.5, 2.5, 7.5], REV_UP = 1.5, REV_DOWN = 1.1, LAUNCH = [0.62, 0.86], START_S = 60, LANE_RATE = 7, LANE_GAIN = 2.2;
|
| 14 |
+
const startHeat = g => {
|
| 15 |
+
const lane = g.heat % 2 ? 2 : 1, rl = g.heat % 2 ? 1 : 2;
|
| 16 |
+
g.placeCar(START_S, LANES[lane]); g.s0 = START_S; g.lane = lane; g.pre = STAGE; g.rev = 0; g.prevV = 0; g.heatProg = 0;
|
| 17 |
+
g.gates = [{ s: START_S + g.heatLen, at: g.heatLen, done: 0 }];
|
| 18 |
+
g.rivals = [M.newRival(g, { s: START_S, lat: LANES[rl], skill: clamp(g.rivalSkill + M.formOf(g), 0, 1), drag: true, paint: 1 })];
|
| 19 |
+
g.traffic = []; M.spawnTraffic(g, g.trafficN, { opposing: 0, lanes: LANES, spread: Math.max(0, g.heatLen - 240), ahead: 140 });
|
| 20 |
+
// highwater across heats: every heat restarts the car at the line, and prog is measured from heatBase
|
| 21 |
+
g.prog = 0; g.total = g.heatLen;
|
| 22 |
+
};
|
| 23 |
+
M.MODES.drag = {
|
| 24 |
+
route: () => 'strip',
|
| 25 |
+
init(g, d) {
|
| 26 |
+
g.P = Object.assign({}, C.PLAYER, { overheat: true });
|
| 27 |
+
g.manual = 1; g.noGlue = 1;
|
| 28 |
+
g.heats = Math.round(M.tierValue(d, [1, 2, 6])); g.heatLen = M.tierValue(d, [1000, 1500, 1500]); g.seriesLen = g.heats * g.heatLen;
|
| 29 |
+
g.rivalSkill = M.tierValue(d, [0.2, 0.5, 0.8]); g.trafficN = Math.round(M.tierValue(d, [3, 6, 10]));
|
| 30 |
+
g.heat = 0; g.launch = 0;
|
| 31 |
+
startHeat(g);
|
| 32 |
+
},
|
| 33 |
+
staging(g, keys, pressed, dt) {
|
| 34 |
+
g.rev = clamp(g.rev + (keys.has('W') ? REV_UP : -REV_DOWN) * dt, 0, 1);
|
| 35 |
+
if (g.pre <= 0) { const inBand = g.rev >= LAUNCH[0] && g.rev <= LAUNCH[1]; g.launch = inBand ? 1 : 0; if (inBand) { g.car.bonus = 1.2; g.events.push({ type: 'perfect_launch' }); } else if (g.rev > LAUNCH[1]) g.car.clutch = 0.45; }
|
| 36 |
+
g.prevV = 0;
|
| 37 |
+
},
|
| 38 |
+
idle(g) { for (const r of g.rivals) { const a = C.routeAt(g.route, r.s, r.lat); r.x = a.x; r.y = a.y; r.h = a.h; } },
|
| 39 |
+
input(g, inp, keys, pressed) {
|
| 40 |
+
if (pressed.has('A') && g.lane < LANES.length - 1) g.lane++;
|
| 41 |
+
if (pressed.has('D') && g.lane > 0) g.lane--;
|
| 42 |
+
// Lane keeper: the driver has no wheel here (IsDragSteering), a fixed servo turns the lane error into steering.
|
| 43 |
+
const R = g.route, c = g.car, a = C.routeAt(R, g.s), lat = C.routeLat(R, c.x, c.y, g.s), v = Math.max(C.speed(c), 6);
|
| 44 |
+
let dh = c.h - a.h; dh = Math.atan2(Math.sin(dh), Math.cos(dh));
|
| 45 |
+
// Lateral error -> a heading limited to LANE_RATE across the road -> the yaw rate that reaches it -> the wheel for that rate.
|
| 46 |
+
const lim = LANE_RATE / v, want = clamp((LANES[g.lane] - lat) * LANE_GAIN / v, -lim, lim), full = v * Math.tan(C.steerRange(v / C.MPH) * Math.PI / 180) / C.PLAYER.wheelbase;
|
| 47 |
+
inp.steer = clamp((want - dh) * 3 / full, -1, 1); inp.hb = false;
|
| 48 |
+
},
|
| 49 |
+
tick(g, wdt) {
|
| 50 |
+
const c = g.car, v = C.speed(c);
|
| 51 |
+
if (g.prevV > KILL_SPEED && g.prevV - v > KILL_DELTA) return g.lose('totaled');
|
| 52 |
+
g.prevV = v;
|
| 53 |
+
if (c.blown) return g.lose('blown');
|
| 54 |
+
for (const r of g.rivals) M.stepRival(g, r, wdt);
|
| 55 |
+
const rv = g.rivals[0];
|
| 56 |
+
if (g.prog >= g.heatLen) {
|
| 57 |
+
g.events.push({ type: 'heat_won', heat: g.heat, gap: g.heatLen - rv.prog });
|
| 58 |
+
g.heat++;
|
| 59 |
+
if (g.heat >= g.heats) return g.win();
|
| 60 |
+
startHeat(g);
|
| 61 |
+
return;
|
| 62 |
+
}
|
| 63 |
+
if (rv.prog >= g.heatLen) g.lose('gap');
|
| 64 |
+
},
|
| 65 |
+
health(g) {
|
| 66 |
+
const rv = g.rivals[0], left = Math.max(0, g.heatLen - rv.prog), done = g.outcome === 'win' ? g.seriesLen : g.heat * g.heatLen + g.prog;
|
| 67 |
+
return [g.outcome === 'loss' ? 0 : left, g.heatLen, Math.max(0, g.seriesLen - done), g.seriesLen];
|
| 68 |
+
},
|
| 69 |
+
hud(g) { const rv = g.rivals[0]; return { label: 'Drag Race', detail: `Heat ${Math.min(g.heat + 1, g.heats)} / ${g.heats} · Rival needs ${Math.max(0, g.heatLen - rv.prog).toFixed(0)} m · ${g.pre > 0 ? 'RPM ' + Math.round(g.rev * 100) + '%' : 'Gear ' + (g.car.gear + 1)}` }; },
|
| 70 |
+
// Reference: launch inside the band, shift inside the window, change lanes for traffic, nitrous when nothing is close.
|
| 71 |
+
scripted(g) {
|
| 72 |
+
const holds = [[], [], [], [], [], []], c = g.car;
|
| 73 |
+
if (g.pre > 0) { // feather the throttle so the revs sit in the launch band when the lights go
|
| 74 |
+
let rev = g.rev, left = g.pre;
|
| 75 |
+
for (let i = 0; i < 6; i++) { const on = rev < (LAUNCH[0] + LAUNCH[1]) / 2 - 0.02 && left < 1.2; if (on) holds[i].push('W'); rev = clamp(rev + (on ? REV_UP : -REV_DOWN) * (2 / 60), 0, 1); left -= 2 / 60; }
|
| 76 |
+
return { holds, mouse: [0, 0, 0] };
|
| 77 |
+
}
|
| 78 |
+
const P = g.P, k = M.ctl.copyCar(c), fwd0 = Math.max(0, c.vx * Math.cos(c.h) + c.vy * Math.sin(c.h)); let press = -1;
|
| 79 |
+
// After a hit the box is still in a tall gear with almost no drive: one gear down per packet until the revs are useful.
|
| 80 |
+
const lug = c.gear > 0 && c.clutch <= 0 && fwd0 < C.TOPS[c.gear - 1] * 0.8;
|
| 81 |
+
for (let i = 0; i < 6; i++) {
|
| 82 |
+
const u = Math.max(0, k.vx * Math.cos(k.h) + k.vy * Math.sin(k.h)) / C.TOPS[k.gear];
|
| 83 |
+
if (press < 0 && k.gear < 5 && u >= 0.9) press = i;
|
| 84 |
+
C.carStep(k, { thr: 1, brk: false, steer: 0, hb: false, nos: false, manual: true, up: false, down: false, sbGrip: 0 }, 1 / 30, P);
|
| 85 |
+
}
|
| 86 |
+
// Lane plan: for each lane and a short wait before moving, the time until first contact with anything on the road.
|
| 87 |
+
const users = M.ctl.roadUsers(g, g.route), v = C.speed(c), lane = g.lane, HORIZON_S = 6, STAY_S = 3.4;
|
| 88 |
+
const contact = (target, wait) => {
|
| 89 |
+
// The same first-order lane servo the car runs (rate capped, gain LANE_GAIN), started 0.2 s late for the wheel to slew.
|
| 90 |
+
let lat = g.lat;
|
| 91 |
+
for (let t = 0.1; t < HORIZON_S; t += 0.1) {
|
| 92 |
+
if (t > wait + 0.2) lat += clamp((LANES[target] - lat) * LANE_GAIN, -LANE_RATE, LANE_RATE) * 0.1;
|
| 93 |
+
const sp = g.s + v * t;
|
| 94 |
+
for (const o of users) { const ds = o.s + o.vs * t - sp, ds0 = o.s + o.vs * (t - 0.1) - (g.s + v * (t - 0.1)); if (o.s > g.s + 1 && Math.abs(o.lat - lat) < 3.6 && ((ds > 1 && ds < 6.5) || (ds0 > 1 && ds <= 1))) return t; }
|
| 95 |
+
}
|
| 96 |
+
return HORIZON_S;
|
| 97 |
+
};
|
| 98 |
+
const here = contact(lane, 0);
|
| 99 |
+
let bestT = here, go = lane;
|
| 100 |
+
// Stay put until contact is near: a move costs nothing only if nothing else is decided on the way. Then take the lane
|
| 101 |
+
// that stays clear longest, nearer lanes first on a tie. A wrong late move is cheaper than weaving through everything.
|
| 102 |
+
if (here < STAY_S) { let bs = here; for (let l = 0; l < LANES.length; l++) { if (l === lane) continue; const t = contact(l, 0), v2 = t - 0.25 * Math.abs(l - lane); if (t > here + 0.5 && v2 > bs) { bs = v2; bestT = t; go = l; } } }
|
| 103 |
+
const move = Math.sign(go - lane);
|
| 104 |
+
// A blocked lane with nowhere to go: braking costs seconds on this gearing, a total above 100 mph costs the event.
|
| 105 |
+
const blocked = bestT < 0.8 && !move, coast = bestT < 1.2 && !move;
|
| 106 |
+
// Top gear on the limiter only cooks the engine (EngineRacer.cpp:1340): lift until the speed is back under it.
|
| 107 |
+
const onLimiter = c.gear === 5 && Math.max(0, c.vx * Math.cos(c.h) + c.vy * Math.sin(c.h)) >= C.TOPS[5] * 0.995;
|
| 108 |
+
const nos = c.nos > 0.02 && v > 30 && here > 3 && c.clutch <= 0 && !c.over && v < C.TOPS[5] * 0.97;
|
| 109 |
+
for (let i = 0; i < 6; i++) { if (blocked) holds[i].push('S'); else if (!onLimiter && !coast) holds[i].push('W'); if (nos && !blocked) holds[i].push('Shift'); if (i === press && !lug) holds[i].push('K'); if (i === 0 && lug) holds[i].push('L'); if (i === 0 && move) holds[i].push(move > 0 ? 'A' : 'D'); }
|
| 110 |
+
return { holds, mouse: [0, 0, 0] };
|
| 111 |
+
},
|
| 112 |
+
};
|
| 113 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/modes_knockout.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Lap Knockout (GRace.h kRaceType_Knockout; GRaceStatus.h GRacerInfo::KnockOut, mKnockedOut). A short downtown circuit at night:
|
| 2 |
+
when every car but one has finished the lap, that last car is out. One lap per rival, so the field sets the length.
|
| 3 |
+
boss_hp = route metres left in the whole event; player_hp = metres the slowest remaining rival still needs to finish this
|
| 4 |
+
lap (at 0 every rival is home and the player is the one knocked out). The field and the circuit are original: race data is VLT. */
|
| 5 |
+
(function (root) {
|
| 6 |
+
'use strict';
|
| 7 |
+
const M = root.NfsmwGame, C = M.C, S0 = 40, ROW = 9;
|
| 8 |
+
M.MODES.knockout = {
|
| 9 |
+
route: () => 'downtown',
|
| 10 |
+
init(g, d) {
|
| 11 |
+
const R = g.route, field = Math.round(M.tierValue(d, [1, 2, 5]));
|
| 12 |
+
// The grid is short of the line, so lap 1 is partial and its length is part of the event's pace.
|
| 13 |
+
const first = Math.min(R.L, M.tierValue(d, [420, 520, 694])), start = R.L - first + S0;
|
| 14 |
+
g.L = R.L; g.first = first; g.laps = field; g.total = first + (field - 1) * R.L; g.lap = 0; g.s0 = start; g.placeCar(start, -2.2);
|
| 15 |
+
const lo = M.tierValue(d, [0.12, 0.2, 0.3]), hi = M.tierValue(d, [0.12, 0.34, 0.62]);
|
| 16 |
+
g.rivals = [];
|
| 17 |
+
// Two columns, a full row apart: the player is alone on the last row. Skill runs from the back of the grid to the front, as a Blacklist field does.
|
| 18 |
+
for (let i = 0; i < field; i++) {
|
| 19 |
+
const r = M.newRival(g, { s: start + ROW * (Math.floor(i / 2) + 1), lat: i % 2 ? -2.2 : 2.2, skill: C.clamp((field > 1 ? C.lerp(lo, hi, i / (field - 1)) : lo) + M.formOf(g), 0, 1), paint: i % 4 });
|
| 20 |
+
r.s0 = start; r.prog = r.s - start; g.rivals.push(r);
|
| 21 |
+
}
|
| 22 |
+
g.gates = [{ s: R.L + S0, at: 0, kind: 'line', keep: 1, done: 0 }];
|
| 23 |
+
M.spawnTraffic(g, Math.round(M.tierValue(d, [0, 2, 3])), { ahead: 120, spread: 260, opposing: 0 });
|
| 24 |
+
},
|
| 25 |
+
idle() {},
|
| 26 |
+
tick(g, wdt) {
|
| 27 |
+
const alive = g.rivals.filter(r => !r.out);
|
| 28 |
+
for (const r of alive) M.stepRival(g, r, wdt);
|
| 29 |
+
// Rivals ride rails, so they part sideways here rather than drive through each other.
|
| 30 |
+
for (let i = 0; i < alive.length; i++) for (let j = i + 1; j < alive.length; j++) {
|
| 31 |
+
const a = alive[i], b = alive[j], ds = a.s - b.s, dl = a.lat - b.lat;
|
| 32 |
+
if (Math.abs(ds) < 6 && Math.abs(dl) < 3.2) { const push = (dl >= 0 ? 1 : -1) * 2.4 * wdt, e = g.route.halfW - 2.1; a.lat = C.clamp(a.lat + push, -e, e); b.lat = C.clamp(b.lat - push, -e, e); if (Math.abs(ds) < 4.4 && a.v !== b.v) { const back = ds < 0 ? a : b; back.v = Math.max(0, back.v - 6 * wdt); } }
|
| 33 |
+
}
|
| 34 |
+
const end = g.first + g.lap * g.L, pending = alive.filter(r => r.prog < end), youIn = g.prog >= end;
|
| 35 |
+
if (!youIn && pending.length === 0) return g.lose('knocked');
|
| 36 |
+
// <= 1, not === 1: two rivals crossing on the same tick take pending from 2 to 0, and the last car still goes out.
|
| 37 |
+
if (youIn && pending.length <= 1) {
|
| 38 |
+
const out = pending[0] || alive.reduce((a, b) => b.prog < a.prog ? b : a); out.out = 1; out.gone = 1; g.events.push({ type: 'knockout', lap: g.lap }); g.lap++;
|
| 39 |
+
if (g.rivals.every(r => r.out)) { g.prog = g.total; g.win(); }
|
| 40 |
+
}
|
| 41 |
+
},
|
| 42 |
+
health(g) {
|
| 43 |
+
const end = g.first + g.lap * g.L; let worst = 0;
|
| 44 |
+
for (const r of g.rivals) if (!r.out) worst = Math.max(worst, end - r.prog);
|
| 45 |
+
// A win knocks out the last rival, so no rival is left to measure: player_hp stays full rather than reading as a loss.
|
| 46 |
+
return [g.outcome === 'loss' ? 0 : g.outcome === 'win' ? g.L : C.clamp(worst, 0, g.L), g.L, g.outcome === 'win' ? 0 : Math.max(0, g.total - g.prog), g.total];
|
| 47 |
+
},
|
| 48 |
+
hud(g) { const alive = g.rivals.filter(r => !r.out); const place = 1 + alive.filter(r => r.prog > g.prog).length; return { label: 'Lap Knockout', detail: `Lap ${Math.min(g.lap + 1, g.laps)} / ${g.laps} · Place ${place} / ${alive.length + 1} · Last-place rival needs ${M.MODES.knockout.health(g)[0].toFixed(0)} m` }; }, // draw.js calls hud unbound: no `this`
|
| 49 |
+
// Reference: a tighter line, and slow motion (J, the public Speedbreaker key: +2 g of downforce) only while it would brake,
|
| 50 |
+
// for a corner or for a car ahead. Seeds 1-32: normal 22 -> 32, hard 24 -> 32.
|
| 51 |
+
scripted(g) {
|
| 52 |
+
const opt = { margin: 0.96 }, pk = M.ctl.drive(g, opt);
|
| 53 |
+
if (g.pre <= 0) { const why = M.ctl.planDrive(g, opt).why, want = why === 'speed' || why === 'contact'; if (want !== !!g.sb && (g.sb || g.sbMeter > 0.15) && pk.holds[0].length < 4) pk.holds[0].push('J'); }
|
| 54 |
+
return pk;
|
| 55 |
+
},
|
| 56 |
+
};
|
| 57 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/modes_pursuit.js
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Free-roam pursuit (AI/Common/AIPursuit.cpp, rules listed in cops.js). The event is the Blacklist's own gate: raise a bounty, then get away.
|
| 2 |
+
Bounty accrues only while a cop can see the player (:1920 AddToPendingRepPointsNormal runs inside the in-sight branch) and in lumps for
|
| 3 |
+
destroying cops, with the multiplier up to 3 (:917). Then the evade meter must fill. Clearing a stage raises the heat: after the lock-out
|
| 4 |
+
(:2061 LockoutCops) a new pursuit starts at the next level. The heat values are VLT data, so every number below is an approximation.
|
| 5 |
+
Pursuit Breakers: EPursuitBreaker exists in the decompilation, the placement and radius are map data; here two per lap, original.
|
| 6 |
+
boss_hp = stages x 200 minus bounty and evade progress, both from high-water marks, so it never jumps back; player_hp = the bust meter. */
|
| 7 |
+
(function (root) {
|
| 8 |
+
'use strict';
|
| 9 |
+
const M = root.NfsmwGame, C = M.C, N = root.NativeBench, clamp = C.clamp;
|
| 10 |
+
const BOUNTY_UNITS = 100, EVADE_UNITS = 100, S0 = 5560, BREAKER_R = 46;
|
| 11 |
+
const heat = (g, d) => {
|
| 12 |
+
const lvl = g.stage / Math.max(1, g.stages - 1); // inside the event the heat climbs a little, tier sets the base
|
| 13 |
+
return { copsMax: Math.round(M.tierValue(d, [2, 3, 5])) + (g.stage > 1 ? 1 : 0), top: M.tierValue(d, [52, 66, 70]) + lvl * 4 };
|
| 14 |
+
};
|
| 15 |
+
const startStage = (g, d) => {
|
| 16 |
+
const p = g.pol, h = heat(g, d);
|
| 17 |
+
p.copsMax = h.copsMax; p.top = h.top; p.seen = 0; p.sinceSeen = 0; p.evade = 0; p.lockT = g.stage ? 3 : 0; p.spawnT = g.stage ? 3.5 : p.spawnGap;
|
| 18 |
+
g.stageBounty = 0; g.stageEvadeHW = 0;
|
| 19 |
+
if (!g.stage) { const c = M.spawnCop(g, g.s - 85, 2, 1); c.slot = 0; c.v = 34; }
|
| 20 |
+
else g.events.push({ type: 'heat_up', stage: g.stage });
|
| 21 |
+
};
|
| 22 |
+
// ---------------- Reference controllers for these two events (2026-11-11 recalibration). Only these two events call them; the shared
|
| 23 |
+
// planDrive / drive in scripted.js are untouched. Read decided state only (poses, timers, the episode seed), never the live RNG: the
|
| 24 |
+
// champion's look-ahead rolls copies forward in a fixed independent scenario. Both keep a little memory per game object (WeakMap); a
|
| 25 |
+
// repeated call on the same state returns the same packet (tests/leak_probe.js asks five times per packet).
|
| 26 |
+
|
| 27 |
+
// Pursuit. The strategy follows whether this heat level brings a helicopter (g.pol.heli, fixed when the pursuit starts; the HUD shows
|
| 28 |
+
// helicopter once one is up). In the block's tight corners the cops lose sight within seconds, so without a helicopter (250 m sight) the bounty
|
| 29 |
+
// stops growing there: d = 0.65-0.7 timed out 8/8 when the switch was the stage count instead.
|
| 30 |
+
// - no helicopter: the 11-06 controller. While bounty is owed, hold station just ahead of the chase so it keeps sight; once the 7 s in-sight
|
| 31 |
+
// grace (cops.js inSight, AIPursuit.cpp:2000) covers what is owed with 5 s to spare, or the bounty is full, run on the racing line with
|
| 32 |
+
// nitrous, through any Pursuit Breaker with a cop near. Same rule at every tier (the 11-06 version started early on easy only).
|
| 33 |
+
// - helicopter: the downtown block, ported from the 600-hour dataset pipeline's tools/trajectory_dataset/pursuit_recovery_source_v87.js
|
| 34 |
+
// (read-only there; its route table, path smoothing and follower, config speed 42, owed 34, lane spread 3). Into the block by one of
|
| 35 |
+
// five connector streets, laps of its tight corners until the stage clears, back out to the coast between stages.
|
| 36 |
+
// Added to both: blown tyres are reset once no chasing cop is within 95 m (11-06 rule); on the block, a cop within 6 m with the car under
|
| 37 |
+
// BustSpeed + 2 means it is pinned, so it floors it instead of braking for the corner.
|
| 38 |
+
const pursuitPolicy = (() => {
|
| 39 |
+
const HIDE = true, HIDE_GAP = 175, HIDE_SEE = 520, SPEED = 42, OWED = 34, REENTER_OWED = 8, LANE_SPREAD = 3, EARLY_MARGIN = 5, RESET_NEAR = 95, UNPIN_R = 6, FAR_COP = 110, MID_COP = 70, TOP_FAR = 20, TOP_MID = 30;
|
| 40 |
+
const memory = new WeakMap();
|
| 41 |
+
function choice(g) { let n = g.seed ^ Math.imul(g.stage + 1, 0x9e3779b1); n = Math.imul(n ^ (n >>> 16), 0x21f0aaad); n = Math.imul(n ^ (n >>> 15), 0x735a2d97); return ((n ^ (n >>> 15)) >>> 0) / 4294967296; }
|
| 42 |
+
const lane = g => (choice(g) - 0.5) * 2 * LANE_SPREAD;
|
| 43 |
+
// Connector streets from the coast road into the downtown block (nfscore.js STREETS), outer end first.
|
| 44 |
+
const routes = [[[0, -520], [0, -80]], [[420, -520], [420, 3], [46, 3]], [[-400, -520], [-400, 0], [-85, 0]], [[0, 400], [0, 80]], [[-400, 560], [-400, 0], [-85, 0]]];
|
| 45 |
+
const nearestCop = g => { let near = Infinity; for (const k of g.cops) if (!k.dead && k.state !== 'rb') near = Math.min(near, Math.hypot(g.car.x - k.x, g.car.y - k.y)); return near; };
|
| 46 |
+
function sixSteer(c, target, sp, scale) {
|
| 47 |
+
const rate = (sp < 15 ? 7 : sp < 40 ? 5 : 3.6) * scale / 30, keys = []; let st = c.steer;
|
| 48 |
+
for (let i = 0; i < 6; i++) { let k0 = 0, error = Infinity; for (const k of [0, 1, -1]) { const n = st + clamp(k - st, -rate, rate), e = Math.abs(n - target); if (e < error) { error = e; k0 = k; } } keys.push(k0); st += clamp(k0 - st, -rate, rate); }
|
| 49 |
+
return keys;
|
| 50 |
+
}
|
| 51 |
+
// Drop collinear points, then round each corner with the largest arc (16, 12, 8 m) that stays on the road.
|
| 52 |
+
function smooth(points) {
|
| 53 |
+
const sparse = [points[0]];
|
| 54 |
+
for (let i = 1; i < points.length - 1; i++) {
|
| 55 |
+
const a = sparse[sparse.length - 1], b = points[i], c = points[i + 1], ux = b[0] - a[0], uy = b[1] - a[1], vx = c[0] - b[0], vy = c[1] - b[1], L = Math.hypot(ux, uy) * Math.hypot(vx, vy);
|
| 56 |
+
if (L < 0.01) continue;
|
| 57 |
+
if (Math.abs(ux * vy - uy * vx) / L < 0.01 && (ux * vx + uy * vy) / L > 0.999) continue;
|
| 58 |
+
sparse.push(b);
|
| 59 |
+
}
|
| 60 |
+
sparse.push(points[points.length - 1]); points = sparse;
|
| 61 |
+
const out = [points[0]];
|
| 62 |
+
for (let i = 1; i < points.length - 1; i++) {
|
| 63 |
+
const a = points[i - 1], b = points[i], c = points[i + 1], la = Math.hypot(b[0] - a[0], b[1] - a[1]), lc = Math.hypot(c[0] - b[0], c[1] - b[1]);
|
| 64 |
+
if (la < 30 || lc < 30) { out.push(b); continue; }
|
| 65 |
+
const ux = (a[0] - b[0]) / la, uy = (a[1] - b[1]) / la, vx = (c[0] - b[0]) / lc, vy = (c[1] - b[1]) / lc;
|
| 66 |
+
const theta = Math.acos(clamp(ux * vx + uy * vy, -1, 1)); if (theta < 0.3 || theta > 2.9) { out.push(b); continue; }
|
| 67 |
+
let arc = null;
|
| 68 |
+
for (const radius of [16, 12, 8]) {
|
| 69 |
+
const tangent = radius / Math.tan(theta / 2); if (tangent > Math.min(la, lc) * 0.4) continue;
|
| 70 |
+
const hl = Math.hypot(ux + vx, uy + vy), distance = radius / Math.sin(theta / 2), cx = b[0] + (ux + vx) / hl * distance, cy = b[1] + (uy + vy) / hl * distance;
|
| 71 |
+
const ax = b[0] + ux * tangent, ay = b[1] + uy * tangent, angle = Math.atan2(ay - cy, ax - cx), sign = -Math.sign(ux * vy - uy * vx), sweep = Math.PI - theta;
|
| 72 |
+
const n = Math.ceil(radius * sweep / 2), candidate = [];
|
| 73 |
+
for (let j = 0; j <= n; j++) { const t = angle + sign * sweep * j / n; candidate.push([cx + Math.cos(t) * radius, cy + Math.sin(t) * radius]); }
|
| 74 |
+
if (candidate.every(p => C.road(p[0], p[1]).d < -1.8)) { arc = candidate; break; }
|
| 75 |
+
}
|
| 76 |
+
out.push(...(arc || [b]));
|
| 77 |
+
}
|
| 78 |
+
out.push(points[points.length - 1]); return out;
|
| 79 |
+
}
|
| 80 |
+
// Pure pursuit along mem.points, speed limited by the path's curvature and the tyres; null at the end of the path.
|
| 81 |
+
function follow(g, mem) {
|
| 82 |
+
if (mem.rawPoints !== mem.points) { mem.points = smooth(mem.points); mem.rawPoints = mem.points; }
|
| 83 |
+
const c = g.car, sp = C.speed(c), points = mem.points; let i = mem.i;
|
| 84 |
+
while (i < points.length - 1) { const a = points[i], b = points[i + 1], dx = b[0] - a[0], dy = b[1] - a[1], l2 = dx * dx + dy * dy; const t = ((c.x - a[0]) * dx + (c.y - a[1]) * dy) / l2; if (t > 1 || Math.hypot(c.x - b[0], c.y - b[1]) < 3.5) { i++; continue; } break; }
|
| 85 |
+
mem.i = i;
|
| 86 |
+
if (i >= points.length - 1) return null;
|
| 87 |
+
const a = points[i], b = points[i + 1], dx = b[0] - a[0], dy = b[1] - a[1], length = Math.hypot(dx, dy);
|
| 88 |
+
const t = clamp(((c.x - a[0]) * dx + (c.y - a[1]) * dy) / (length * length), 0, 1), remaining = length * (1 - t);
|
| 89 |
+
let look = Math.max(5, sp * 0.45), x = a[0] + dx * t, y = a[1] + dy * t, j = i;
|
| 90 |
+
while (look > 0 && j < points.length - 1) { const dest = points[j + 1], d = Math.hypot(dest[0] - x, dest[1] - y); if (d >= look) { x += (dest[0] - x) * look / d; y += (dest[1] - y) * look / d; break; } look -= d; x = dest[0]; y = dest[1]; j++; }
|
| 91 |
+
const lag = 0.1 * (g.sb ? 0.45 : 1); let angle = Math.atan2(y - c.y - c.vy * lag, x - c.x - c.vx * lag) - c.h - c.r * lag; angle = Math.atan2(Math.sin(angle), Math.cos(angle));
|
| 92 |
+
const L = Math.max(3, Math.hypot(x - c.x, y - c.y)), kappa = 2 * Math.sin(angle) / L;
|
| 93 |
+
const nose = C.road(c.x + Math.cos(c.h) * 3.2, c.y + Math.sin(c.h) * 3.2).d > -0.5;
|
| 94 |
+
if (sp < 7 && (Math.abs(angle) > 0.9 || nose)) {
|
| 95 |
+
const clear = C.road(c.x - Math.cos(c.h) * 3.5, c.y - Math.sin(c.h) * 3.5).d < -0.6, side = angle > 0 ? 1 : -1;
|
| 96 |
+
const pk = M.ctl.toPacket({ keys: sixSteer(c, clear ? -side : side, sp, g.sb ? 0.45 : 1), thr: clear ? 0 : 6, brk: clear, nos: false });
|
| 97 |
+
if (g.sb) pk.holds[0].push('J'); return pk;
|
| 98 |
+
}
|
| 99 |
+
const target = clamp(Math.atan(kappa * C.PLAYER.wheelbase) / (C.steerRange(sp / C.MPH) * Math.PI / 180), -1, 1);
|
| 100 |
+
const end = !mem.continuous && i + 1 === points.length - 1;
|
| 101 |
+
let future = SPEED, ds = -length * t, upcoming = 0;
|
| 102 |
+
const grip = (C.PLAYER.grip + (g.sb ? 19.62 : 0)) * C.tireFactor(c) * 0.78;
|
| 103 |
+
for (let k = i; k < points.length - 2 && ds < 150; k++) {
|
| 104 |
+
const a = points[k], b = points[k + 1], c0 = points[k + 2], d1 = Math.hypot(b[0] - a[0], b[1] - a[1]), d2 = Math.hypot(c0[0] - b[0], c0[1] - b[1]), d3 = Math.hypot(c0[0] - a[0], c0[1] - a[1]);
|
| 105 |
+
ds += d1; const curv = Math.abs(2 * ((b[0] - a[0]) * (c0[1] - b[1]) - (b[1] - a[1]) * (c0[0] - b[0])) / Math.max(0.001, d1 * d2 * d3));
|
| 106 |
+
if (ds < sp * 1.5 + 10) upcoming = Math.max(upcoming, curv);
|
| 107 |
+
if (curv > 0.0001) future = Math.min(future, Math.sqrt(grip / curv + 2 * 8 * Math.max(0, ds - 6)));
|
| 108 |
+
}
|
| 109 |
+
const limit = Math.min(future, Math.sqrt(grip / (Math.abs(kappa) + 0.0001)), end ? Math.sqrt(2 * 8 * Math.max(0, remaining - 3)) : SPEED);
|
| 110 |
+
const brk = sp > limit + 0.8, keys = sixSteer(c, brk ? target / 1.45 : target, sp, g.sb ? 0.45 : 1);
|
| 111 |
+
const spare = Math.max(0, 1 - sp * sp * Math.abs(kappa) / grip);
|
| 112 |
+
const thr = Math.max(1, Math.min(6, Math.round(6 * spare / 0.55)));
|
| 113 |
+
let pinned = false; for (const k of g.cops) if (!k.dead && k.state !== 'rb' && Math.hypot(c.x - k.x, c.y - k.y) < UNPIN_R) pinned = true;
|
| 114 |
+
pinned = pinned && sp < g.pol.bustSpeed + 2;
|
| 115 |
+
const pk = pinned ? M.ctl.toPacket({ keys: sixSteer(c, target, sp, g.sb ? 0.45 : 1), thr: 6, brk: false, nos: c.nos > 0.02 }) : M.ctl.toPacket({ keys, thr: brk ? 0 : thr, brk, nos: false });
|
| 116 |
+
const want = (upcoming > 0.035 || Math.abs(angle) > 0.3) && sp > 10;
|
| 117 |
+
if (want !== !!g.sb && (g.sb || g.sbMeter > 0.2) && pk.holds[0].length < 4) pk.holds[0].push('J');
|
| 118 |
+
return pk;
|
| 119 |
+
}
|
| 120 |
+
const nearestS = (R, x, y) => { let best = 0, dist = Infinity; for (let i = 0; i < R.n; i++) { const d = Math.hypot(R.x[i] - x, R.y[i] - y); if (d < dist) { dist = d; best = i * R.ds; } } return best; };
|
| 121 |
+
// One lap of the downtown block starting at the point nearest (x, y). routeAt returns one shared object: copy before the next call.
|
| 122 |
+
function lapFrom(x, y) { const R = C.routes.downtown, best = nearestS(R, x, y), pts = []; for (let s = 4; s < R.L + 4; s += 4) { const p = C.routeAt(R, best + s); pts.push([p.x, p.y]); } const last = C.routeAt(R, best); pts.push([last.x, last.y]); return pts; }
|
| 123 |
+
function startReturn(g, mem, escape, entryS) {
|
| 124 |
+
const join = { ...C.routeAt(g.route, entryS + 35) };
|
| 125 |
+
mem.points = [[g.car.x, g.car.y], ...escape.slice(0, -1).reverse(), [join.x, join.y]]; mem.i = 0; mem.mode = 'return'; mem.continuous = false; mem.returnPending = false;
|
| 126 |
+
mem.escape = escape; mem.entryS = entryS;
|
| 127 |
+
}
|
| 128 |
+
// One heat stage: the 11-06 coast run.
|
| 129 |
+
function coastRun(g, owed, p) {
|
| 130 |
+
const R = g.route, nearest = nearestCop(g), opt = { ram: true }, covered = 7 - p.sinceSeen - EARLY_MARGIN > owed;
|
| 131 |
+
// Hide: bounty full, nobody sees the car, and a roadblock is already set up ahead (g.blocks, decided state). Driving past it re-sights the
|
| 132 |
+
// car (50 m all round, AIVehicleCopCar.cpp:88-89) and restarts the 7 s + evade clock; instead stop HIDE_GAP m short of it, outside its
|
| 133 |
+
// 150 m view, and let the evade meter run. A car under 15 m/s draws no new roadblock (cops.js stepRoadblocks).
|
| 134 |
+
if (HIDE && owed <= 0 && !p.sawNow) { let ahead = Infinity; for (const b of g.blocks) { const ds = M.wrapTo(R, b.s, g.s) - g.s; if (ds > 0 && ds < ahead) ahead = ds; }
|
| 135 |
+
if (ahead < HIDE_SEE) { const room = ahead - HIDE_GAP, sp = C.speed(g.car); if (room < 3) return M.ctl.toPacket({ thr: 0, brk: sp > 2, nos: false }); return M.ctl.drive(g, { ram: true, nos: false, top: Math.max(4, Math.sqrt(2 * 8 * Math.max(0, room - 3))) }); } }
|
| 136 |
+
if (owed > 0 && !covered) { opt.nos = false; if (nearest > FAR_COP || !p.sawNow) opt.top = TOP_FAR; else if (nearest > MID_COP) opt.top = TOP_MID; }
|
| 137 |
+
if (owed <= 0 || covered) for (const b of g.breakers) { const ds = M.wrapTo(R, b.s, g.s) - g.s; if (ds > 0 && ds < 130 && !b.rearm && nearest < 90) opt.lat = b.lat; }
|
| 138 |
+
return M.ctl.drive(g, opt);
|
| 139 |
+
}
|
| 140 |
+
return function policy(g) {
|
| 141 |
+
let mem = memory.get(g); if (!mem) { mem = { stage: g.stage, mode: 'coast' }; memory.set(g, mem); }
|
| 142 |
+
if (g.car.tires > 0 && g.flash <= 0 && nearestCop(g) > RESET_NEAR) { mem.mode = 'coast'; mem.reenter = mem.reenter || g.bountyNeed - g.stageBounty > 0; return { holds: [['R'], [], [], [], [], []], mouse: [0, 0, 0] }; }
|
| 143 |
+
const owed = g.bountyNeed - g.stageBounty, p = g.pol;
|
| 144 |
+
if (!g.pol.heli) return coastRun(g, owed, p);
|
| 145 |
+
if (g.stage !== mem.stage) {
|
| 146 |
+
mem.stage = g.stage;
|
| 147 |
+
if (mem.mode === 'city') mem.returnPending = false;
|
| 148 |
+
else if (mem.mode !== 'coast') startReturn(g, mem, mem.escape, mem.entryS);
|
| 149 |
+
}
|
| 150 |
+
if (mem.mode === 'city') {
|
| 151 |
+
const pk = follow(g, mem); if (pk) return pk;
|
| 152 |
+
if (mem.returnPending) { startReturn(g, mem, mem.escape, mem.entryS); return follow(g, mem); }
|
| 153 |
+
mem.points = [[g.car.x, g.car.y], ...mem.cityPoints]; mem.i = 0; return follow(g, mem);
|
| 154 |
+
}
|
| 155 |
+
if (mem.mode === 'return' || mem.mode === 'inside') {
|
| 156 |
+
if (mem.mode === 'inside' && mem.i >= mem.points.length - 2) mem.continuous = true;
|
| 157 |
+
const pk = follow(g, mem); if (pk) return pk;
|
| 158 |
+
mem.continuous = false; mem.mode = 'coast';
|
| 159 |
+
}
|
| 160 |
+
if (mem.mode === 'coast' && owed <= (mem.reenter ? REENTER_OWED : OWED)) {
|
| 161 |
+
mem.reenter = false;
|
| 162 |
+
const R = g.route, choices = routes.map(points => { const best = nearestS(R, points[0][0], points[0][1]); let ds = (best - g.s) % R.L; if (ds < 30) ds += R.L; return { points, s: g.s + ds, ds }; });
|
| 163 |
+
const ranked = choices.sort((a, b) => a.ds - b.ds), options = ranked.filter(r => r.ds < ranked[0].ds + 1100).slice(0, 3);
|
| 164 |
+
const target = options[Math.min(options.length - 1, Math.floor(choice(g) * options.length))];
|
| 165 |
+
mem.escape = target.points.map(q => q.slice()); mem.entryS = target.s; mem.mode = 'approach';
|
| 166 |
+
}
|
| 167 |
+
if (mem.mode === 'approach') {
|
| 168 |
+
const distance = mem.entryS - g.s;
|
| 169 |
+
if (distance < 100) {
|
| 170 |
+
const approach = { ...C.routeAt(g.route, mem.entryS - 150) }, end = mem.escape[mem.escape.length - 1];
|
| 171 |
+
mem.cityPoints = lapFrom(end[0], end[1]);
|
| 172 |
+
mem.points = [[approach.x, approach.y], ...mem.escape, ...mem.cityPoints]; mem.i = 0; mem.mode = 'city'; mem.continuous = true;
|
| 173 |
+
return follow(g, mem);
|
| 174 |
+
}
|
| 175 |
+
return M.ctl.drive(g, { ram: true, lat: lane(g), margin: 0.9, top: Math.min(70, Math.sqrt(12 * 12 + 2 * 8 * Math.max(0, distance - 12))) });
|
| 176 |
+
}
|
| 177 |
+
return M.ctl.drive(g, { ram: true, lat: lane(g), margin: 0.9 });
|
| 178 |
+
};
|
| 179 |
+
})();
|
| 180 |
+
|
| 181 |
+
// Street champion. Ported from the dataset pipeline's tools/trajectory_dataset/street_interaction_source_v42.js (read-only there). v42
|
| 182 |
+
// replaced the page's M.ctl with a modified copy of scripted.js; here that copy is private to this event. Kept from v42: lane choice with
|
| 183 |
+
// hysteresis, Speedbreaker grip in the racing line and friction circle, and each packet picks one of nine driving choices by rolling copies
|
| 184 |
+
// of the game 120 ticks forward with the RNG set to one fixed scenario (never the live RNG). Added: blown tyres are reset once no chasing
|
| 185 |
+
// cop is within 95 m (the 11-06 rule v42 dropped), and a roadblock already placed ahead (g.blocks, decided state) adds its widest gap as a
|
| 186 |
+
// candidate lane and pulls the score towards it: a 2 s rollout cannot see a block 300 m away, and at 55 m/s the car cannot cross the
|
| 187 |
+
// road in the 2 s it does see (seeds 4, 8, 13, 22, 24 hard: busted or out-run behind a block).
|
| 188 |
+
const championPolicy = (() => {
|
| 189 |
+
const HOLD_SETS = 6, DT = 1 / 60, CONTACT = 3.5, RESET_NEAR = 95, GAP_AHEAD = 360, GAP_CLEAR = 3.3, GAP_EDGE = 1.6, GAP_PULL = 8;
|
| 190 |
+
const laneMem = new WeakMap();
|
| 191 |
+
function laneTarget(g, R, S, others, speed, base) {
|
| 192 |
+
const edge = R.halfW - 2.2, prev = laneMem.get(g) ?? g.lat;
|
| 193 |
+
const lanes = [clamp(prev, -edge, edge), base, -edge, edge, -edge * .5, 0, edge * .5];
|
| 194 |
+
let best = lanes[0], bs = -Infinity;
|
| 195 |
+
for (const lat of lanes) {
|
| 196 |
+
let sc = -Math.abs(lat - prev) * 3 - .15 * Math.abs(lat - base);
|
| 197 |
+
for (const o of others) {
|
| 198 |
+
const ds = o.s - S; if (ds < -10 || ds > 200) continue;
|
| 199 |
+
const closing = speed - o.vs, tt = closing > 1 ? Math.max(0, ds) / closing : ds < 30 ? 0.5 : 99;
|
| 200 |
+
if (tt > 4) continue;
|
| 201 |
+
const gap = Math.abs(o.lat + (o.vl || 0) * Math.min(tt, 1) - lat);
|
| 202 |
+
if (gap < 3.8) sc -= (3.8 - gap) * (5 - tt) * 5;
|
| 203 |
+
}
|
| 204 |
+
if (sc > bs) { bs = sc; best = lat; }
|
| 205 |
+
}
|
| 206 |
+
laneMem.set(g, best); return best;
|
| 207 |
+
}
|
| 208 |
+
function roadUsers(g, R) {
|
| 209 |
+
const out = [], L = R.L;
|
| 210 |
+
const near = v => { if (!R.loop) return v; let ds = (v - g.s) % L; if (ds > L / 2) ds -= L; else if (ds < -L / 2) ds += L; return Math.abs(v - g.s) <= L / 2 ? v : g.s + ds; };
|
| 211 |
+
for (const t of g.traffic) out.push({ s: near(t.s), lat: t.lat, vs: t.crash ? 0 : t.v, r: 2 });
|
| 212 |
+
for (const r of g.rivals) if (!r.out) out.push({ s: near(r.s), lat: r.lat, vs: r.v, r: 2, a: r.v < 25 ? 5 : 0 });
|
| 213 |
+
M.copUsers(g, R, out);
|
| 214 |
+
return out;
|
| 215 |
+
}
|
| 216 |
+
const lines = new Map();
|
| 217 |
+
function racingLine(R, P, grip, brake, top) {
|
| 218 |
+
let L = lines.get(R.name);
|
| 219 |
+
if (!L) {
|
| 220 |
+
const n = R.n, lat = new Float64Array(n), edge = R.halfW - 2.4, wrap = i => R.loop ? (i + n) % n : Math.max(0, Math.min(n - 1, i)), K = Math.max(2, Math.round(10 / R.ds));
|
| 221 |
+
const nx = i => -Math.sin(R.h[i]), ny = i => Math.cos(R.h[i]), px = i => R.x[i] + nx(i) * lat[i], py = i => R.y[i] + ny(i) * lat[i];
|
| 222 |
+
for (let it = 0; it < 400; it++) for (let i = 0; i < n; i++) { const a = wrap(i - K), b = wrap(i + K), tx = (px(a) + px(b)) / 2 - px(i), ty = (py(a) + py(b)) / 2 - py(i); lat[i] = clamp(lat[i] + 0.5 * (tx * nx(i) + ty * ny(i)), -edge, edge); }
|
| 223 |
+
const kap = new Float64Array(n);
|
| 224 |
+
for (let i = 0; i < n; i++) { const a = wrap(i - K), b = wrap(i + K), x1 = px(i) - px(a), y1 = py(i) - py(a), x2 = px(b) - px(i), y2 = py(b) - py(i), l1 = Math.hypot(x1, y1), l2 = Math.hypot(x2, y2), l3 = Math.hypot(x1 + x2, y1 + y2); kap[i] = l1 && l2 && l3 ? Math.abs(2 * (x1 * y2 - y1 * x2) / (l1 * l2 * l3)) : 0; }
|
| 225 |
+
L = { lat, kap, prof: new Map() }; lines.set(R.name, L);
|
| 226 |
+
}
|
| 227 |
+
const key = [grip, brake, top].map(v => v.toFixed(3)).join('|'); let v = L.prof.get(key);
|
| 228 |
+
if (!v) {
|
| 229 |
+
v = new Float64Array(R.n);
|
| 230 |
+
for (let i = 0; i < R.n; i++) v[i] = L.kap[i] > P.aero + 1e-5 ? Math.min(top, Math.sqrt(grip / (L.kap[i] - P.aero))) : top;
|
| 231 |
+
for (let p = 0; p < (R.loop ? 2 : 1); p++) for (let i = R.n - 1; i >= 0; i--) { const j = i + 1 < R.n ? i + 1 : R.loop ? 0 : i, lim = Math.sqrt(v[j] * v[j] + 2 * brake * R.ds); if (lim < v[i]) v[i] = lim; }
|
| 232 |
+
L.prof.set(key, v);
|
| 233 |
+
}
|
| 234 |
+
return { lat: L.lat, prof: v };
|
| 235 |
+
}
|
| 236 |
+
const lineLat = (R, lat, s) => { let i = Math.round(s / R.ds); if (R.loop) { i %= R.n; if (i < 0) i += R.n; } else i = clamp(i, 0, R.n - 1); return lat[i]; };
|
| 237 |
+
function contactTime(g, others, S, speed, lat) {
|
| 238 |
+
const rate = 4, HORIZON_S = 3;
|
| 239 |
+
for (let t = 0.1; t < HORIZON_S; t += 0.1) {
|
| 240 |
+
const dl = lat - g.lat, l = g.lat + Math.sign(dl) * Math.min(Math.abs(dl), rate * t), sp = S + speed * t;
|
| 241 |
+
for (const o of others) {
|
| 242 |
+
if (o.s <= S) continue;
|
| 243 |
+
const ol = o.lat + (o.vl || 0) * Math.min(t, 2), ds = o.s + o.vs * t + 0.5 * (o.a || 0) * t * t - sp, t0 = t - 0.1, ds0 = o.s + o.vs * t0 + 0.5 * (o.a || 0) * t0 * t0 - (S + speed * t0);
|
| 244 |
+
if (Math.abs(ol - l) < CONTACT && ((ds > 0 && Math.hypot(ds, ol - l) < CONTACT) || (ds0 > 0 && ds <= 0))) return t;
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
return HORIZON_S;
|
| 248 |
+
}
|
| 249 |
+
function steerKeys(c, target, speed, wscale) {
|
| 250 |
+
const rate = (speed < 15 ? 7 : speed < 40 ? 5 : 3.6) * wscale * 2 * DT, out = []; let st = c.steer;
|
| 251 |
+
for (let i = 0; i < HOLD_SETS; i++) {
|
| 252 |
+
let best = 0, bd = Infinity;
|
| 253 |
+
for (const k of [0, 1, -1]) { const n = st + clamp(k - st, -rate, rate), e = Math.abs(n - target); if (e < bd - 1e-9) { bd = e; best = k; } }
|
| 254 |
+
out.push(best); st += clamp(best - st, -rate, rate);
|
| 255 |
+
}
|
| 256 |
+
return out;
|
| 257 |
+
}
|
| 258 |
+
function planDrive(g, opt = {}) {
|
| 259 |
+
const R = g.route, c = g.car, P = g.P || C.PLAYER, S = g.s, speed = C.speed(c), tire = C.tireFactor(c);
|
| 260 |
+
const margin = opt.margin || 0.92, top = opt.top || C.TOPS[5], wscale = g.sb ? 0.45 : 1;
|
| 261 |
+
const line = racingLine(R, P, (P.grip + 19.62 * (g.sb ? 1 : g.sbRamp / (1 / 3))) * tire * margin, P.brake * 0.8, top), prof = line.prof;
|
| 262 |
+
const others = roadUsers(g, R), base = opt.lat !== undefined ? opt.lat : lineLat(R, line.lat, S + speed * 0.8), lat = opt.fixedLane ? base : laneTarget(g, R, S, others, speed, base), onLine = lat === base && opt.lat === undefined;
|
| 263 |
+
const lag = 0.1 * wscale, px = c.x + c.vx * lag, py = c.y + c.vy * lag, ph = c.h + c.r * lag, Ld = Math.max(7, speed * 0.62);
|
| 264 |
+
const sNear = C.routeNear(R, px, py, S, 8, 16), aim = C.routeAt(R, sNear + Ld, onLine ? lineLat(R, line.lat, sNear + Ld) : lat);
|
| 265 |
+
let alpha = Math.atan2(aim.y - py, aim.x - px) - ph; alpha = Math.atan2(Math.sin(alpha), Math.cos(alpha));
|
| 266 |
+
const far = C.routeAt(R, S + 18, lat); let off = Math.atan2(far.y - c.y, far.x - c.x) - c.h; off = Math.atan2(Math.sin(off), Math.cos(off));
|
| 267 |
+
const nose = C.road(c.x + Math.cos(c.h) * 3.2, c.y + Math.sin(c.h) * 3.2).d > -0.5;
|
| 268 |
+
if (speed < 7 && (Math.abs(off) > 0.9 || nose)) {
|
| 269 |
+
const clearBehind = C.road(c.x - Math.cos(c.h) * 3.5, c.y - Math.sin(c.h) * 3.5).d < -0.6, side = off > 0 ? 1 : -1;
|
| 270 |
+
return { keys: steerKeys(c, clearBehind ? -side : side, speed, wscale), thr: clearBehind ? 0 : HOLD_SETS, brk: clearBehind, nos: false, lat, contact: 3, why: 'recover' };
|
| 271 |
+
}
|
| 272 |
+
const kappa = 2 * Math.sin(alpha) / Ld, delta = Math.atan(kappa * P.wheelbase), range = C.steerRange(speed / C.MPH) * Math.PI / 180;
|
| 273 |
+
const vlim = Math.min(C.profileAt(R, prof, S + speed * 0.2), C.profileAt(R, prof, S + speed * 0.45));
|
| 274 |
+
const contact = contactTime(g, opt.ram ? others.filter(o => !o.cop) : others, S, speed, lat), over = speed > vlim + 0.8, brk = over || contact < 0.8, coast = !brk && contact < 1.2;
|
| 275 |
+
const grip = (P.grip + 19.62 * (g.sb ? 1 : g.sbRamp / (1 / 3)) + P.aero * speed * speed) * tire, ay = speed * speed * Math.abs(kappa), spare = Math.max(0, 1 - ay / grip);
|
| 276 |
+
const allowed = spare / 0.55 * grip * 1.1, drive = Math.max(1, C.driveAt(speed) * P.accel), thr = coast ? 0 : Math.round(HOLD_SETS * clamp(allowed / drive, 0.17, 1));
|
| 277 |
+
const nos = !brk && !coast && (opt.forceNos ? c.nos > 0.02 && speed > 12 : c.nos > 0.02 && speed > 18 && opt.nos !== false && thr === HOLD_SETS && C.profileAt(R, prof, S + speed * 1.8) > speed + 8);
|
| 278 |
+
return { keys: steerKeys(c, clamp(delta / range, -1, 1), speed, wscale), thr: brk ? 0 : thr, brk, nos, lat, contact, why: over ? 'speed' : contact < 0.8 ? 'contact' : coast ? 'coast' : 'drive' };
|
| 279 |
+
}
|
| 280 |
+
function toPacket(plan) {
|
| 281 |
+
const holds = [];
|
| 282 |
+
for (let i = 0; i < HOLD_SETS; i++) {
|
| 283 |
+
const h = [], k = plan.keys ? plan.keys[i] : 0;
|
| 284 |
+
if (plan.brk) h.push('S'); else if (plan.thr >= HOLD_SETS || Math.floor((i + 1) * plan.thr / HOLD_SETS) > Math.floor(i * plan.thr / HOLD_SETS)) h.push('W');
|
| 285 |
+
if (k) h.push(k > 0 ? 'A' : 'D');
|
| 286 |
+
if (plan.nos) h.push('Shift');
|
| 287 |
+
holds.push(h);
|
| 288 |
+
}
|
| 289 |
+
return { holds, mouse: [0, 0, 0] };
|
| 290 |
+
}
|
| 291 |
+
function packet(g, choice) {
|
| 292 |
+
if (g.pre > .21) return toPacket({ thr: HOLD_SETS, brk: false, nos: false });
|
| 293 |
+
const opt = { ram: true, margin: 1.02 }; if (choice.lat !== null) { opt.lat = choice.lat; opt.fixedLane = true; }
|
| 294 |
+
const p = planDrive(g, opt), sp = C.speed(g.car);
|
| 295 |
+
if (choice.gas && p.why !== 'recover') { p.brk = false; p.thr = 6; p.nos = g.car.nos > .02 && sp > 18; }
|
| 296 |
+
const pk = toPacket(p);
|
| 297 |
+
const sb = choice.sb === undefined ? (sp > 18 && (p.why === 'speed' || Math.abs(g.car.steer) > .65)) : choice.sb;
|
| 298 |
+
if (sb !== !!g.sb && (g.sb || g.sbMeter > .2) && pk.holds[0].length < 4) pk.holds[0].push('J');
|
| 299 |
+
return pk;
|
| 300 |
+
}
|
| 301 |
+
// Keys held at the end of the last packet, kept per game tick so a repeated call on one state starts every rollout from the same keys.
|
| 302 |
+
const heldMem = new WeakMap();
|
| 303 |
+
const heldBefore = g => { const m = heldMem.get(g); return !m ? [] : m.t === g.t ? m.prev : m.next; };
|
| 304 |
+
const heldAfter = (g, next) => heldMem.set(g, { t: g.t, prev: heldBefore(g), next });
|
| 305 |
+
function session(g, held) {
|
| 306 |
+
const s = Object.create(N.Session.prototype); s.module = M; s.game = M.copyGame(g);
|
| 307 |
+
s.game.rng = 2463534242; s.game.seed = 0; s.held = held.slice(); s.inputs = []; s.recording = false; s.events = []; // one fixed scenario, not the live draws
|
| 308 |
+
return s;
|
| 309 |
+
}
|
| 310 |
+
// The widest free stretch across the next roadblock within GAP_AHEAD m: between parked cars, barriers and the road edges.
|
| 311 |
+
function roadblockGap(g) {
|
| 312 |
+
const R = g.route, hw = R.halfW; let S = Infinity;
|
| 313 |
+
for (const b of g.blocks) { const bs = M.wrapTo(R, b.s, g.s); if (bs > g.s + 3 && bs < S) S = bs; }
|
| 314 |
+
if (S === Infinity || S - g.s > GAP_AHEAD) return null;
|
| 315 |
+
const occ = []; for (const b of g.blocks) if (Math.abs(M.wrapTo(R, b.s, g.s) - S) < 1) occ.push([b.lat - GAP_CLEAR, b.lat + GAP_CLEAR]);
|
| 316 |
+
occ.sort((x, y) => x[0] - y[0]);
|
| 317 |
+
let lo = -hw + GAP_EDGE, best = null; const hi = hw - GAP_EDGE;
|
| 318 |
+
for (const [x, y] of occ) { if (x > lo && (!best || Math.min(x, hi) - lo > best[1] - best[0])) best = [lo, Math.min(x, hi)]; lo = Math.max(lo, y); }
|
| 319 |
+
if (hi > lo && (!best || hi - lo > best[1] - best[0])) best = [lo, hi];
|
| 320 |
+
return best && best[1] > best[0] ? { s: S, lat: (best[0] + best[1]) / 2 } : null;
|
| 321 |
+
}
|
| 322 |
+
return function policy(g) {
|
| 323 |
+
if (g.car.tires > 0 && g.flash <= 0) {
|
| 324 |
+
let near = Infinity; for (const k of g.cops) if (!k.dead && k.state !== 'rb') near = Math.min(near, Math.hypot(g.car.x - k.x, g.car.y - k.y));
|
| 325 |
+
if (near > RESET_NEAR) { heldAfter(g, []); return { holds: [['R'], [], [], [], [], []], mouse: [0, 0, 0] }; }
|
| 326 |
+
}
|
| 327 |
+
const held = heldBefore(g), edge = g.route.halfW - 2.6;
|
| 328 |
+
const choices = [{ lat: null }, { lat: g.lat }, { lat: -edge * .85 }, { lat: edge * .85 }, { lat: -edge * .4 }, { lat: edge * .4 },
|
| 329 |
+
{ lat: null, gas: true }, { lat: g.lat, gas: true }, { lat: null, sb: true }];
|
| 330 |
+
const gap = roadblockGap(g); if (gap) choices.push({ lat: gap.lat }, { lat: gap.lat, gas: true });
|
| 331 |
+
let best = null, bestScore = -Infinity;
|
| 332 |
+
for (const choice of choices) {
|
| 333 |
+
const s = session(g, held), first = packet(s.game, choice); let proximity = 0;
|
| 334 |
+
for (let t = 0; t < 120 && !s.game.outcome; t += 12) {
|
| 335 |
+
s.packet(t === 0 ? first : packet(s.game, choice));
|
| 336 |
+
const z = s.game, sp = C.speed(z.car);
|
| 337 |
+
for (const cop of z.cops) if (!cop.dead && !cop.gone) { const d = Math.hypot(z.car.x - cop.x, z.car.y - cop.y); proximity = Math.max(proximity, Math.max(0, 4 - d) * (sp < 15 ? 3 : 1)); }
|
| 338 |
+
}
|
| 339 |
+
const z = s.game, road = C.routeAt(z.route, z.s), a = N.angle(z.car.h - road.h);
|
| 340 |
+
const score = (z.prog - g.prog) * 3 + C.speed(z.car) * .65 - (z.hits - g.hits) * 8
|
| 341 |
+
- (z.pol.bust - g.pol.bust) * 90 - (z.car.tires - g.car.tires) * 200 - proximity * 12
|
| 342 |
+
- Math.max(0, Math.abs(z.lat) - edge) * 10 - a * a * 5 + (z.car.nos - g.car.nos) * 8
|
| 343 |
+
+ (z.outcome === 'win' ? 100000 : 0) - (z.outcome && z.outcome !== 'win' ? 100000 : 0)
|
| 344 |
+
- (gap && z.s < gap.s ? Math.abs(z.lat - gap.lat) * GAP_PULL : 0);
|
| 345 |
+
if (score > bestScore) { bestScore = score; best = first; }
|
| 346 |
+
}
|
| 347 |
+
heldAfter(g, best.holds[5].slice().sort()); return best;
|
| 348 |
+
};
|
| 349 |
+
})();
|
| 350 |
+
|
| 351 |
+
M.MODES.pursuit = {
|
| 352 |
+
route: () => 'coast',
|
| 353 |
+
init(g, d) {
|
| 354 |
+
g.s0 = S0; g.total = 1e9; g.pre = 0; g.placeCar(S0, -2.5, 34); g.car.gear = 3; // spotted at speed: a pursuit has no starting grid
|
| 355 |
+
g.stages = Math.round(M.tierValue(d, [1, 1, 3])); g.stage = 0; g.diff = d;
|
| 356 |
+
g.bountyNeed = M.tierValue(d, [10, 32, 34]); g.prog = 0;
|
| 357 |
+
M.initPolice(g, { copsMax: 2, top: 60, grip: M.tierValue(d, [0.78, 0.85, 0.92]), accel: M.tierValue(d, [0.8, 0.95, 1.05]), spawnGap: M.tierValue(d, [12, 9, 7]), formations: d < 0.35 ? ['FOLLOW'] : d < 0.7 ? ['FOLLOW', 'ROLLING_BLOCK', 'PIT'] : ['FOLLOW', 'ROLLING_BLOCK', 'BOX_IN', 'PIT'],
|
| 358 |
+
rbChance: M.tierValue(d, [0, 0.45, 0.7]), spikeChance: M.tierValue(d, [0, 0.25, 0.5]), rbGap: M.tierValue(d, [8, 7, 6]), heli: d > 0.7, heliAfter: 30, heliFuel: 22, heliGap: 30, bustSpeed: M.tierValue(d, [7, 10, 13]), searchTop: M.tierValue(d, [34, 42, 50]), close: M.tierValue(d, [8, 11, 14]), copFrail: 3.2, aheadChance: M.tierValue(d, [0.25, 0.35, 0.45]), evadeTimeout: M.tierValue(d, [8, 13, 15]) });
|
| 359 |
+
g.breakers = []; const R = g.route;
|
| 360 |
+
for (const off of [500, 1500, 2600, 3600, 4600]) { for (const side of [1]) { const s = (S0 + off) % R.L, a = C.routeAt(R, s, side * (R.halfW - 1.5)); g.breakers.push({ s, lat: side * (R.halfW - 2.5), x: a.x, y: a.y, h: a.h, fired: 0, rearm: 0 }); } }
|
| 361 |
+
g.bountyTotal = 0;
|
| 362 |
+
startStage(g, d);
|
| 363 |
+
M.spawnTraffic(g, Math.round(M.tierValue(d, [4, 7, 10])));
|
| 364 |
+
},
|
| 365 |
+
idle(g) { for (const c of g.cops) { const a = C.routeAt(g.route, c.s, c.lat); c.x = a.x; c.y = a.y; c.h = a.h; } },
|
| 366 |
+
tick(g, wdt) {
|
| 367 |
+
const p = g.pol, R = g.route, before = p.destroyed;
|
| 368 |
+
M.stepPolice(g, wdt, g.stageBounty >= g.bountyNeed);
|
| 369 |
+
if (g.outcome) return;
|
| 370 |
+
// Pursuit Breaker: driving through the structure brings it down on whatever is around it.
|
| 371 |
+
for (const b of g.breakers) {
|
| 372 |
+
if (b.rearm > 0) b.rearm -= wdt;
|
| 373 |
+
const bs = M.wrapTo(R, b.s, g.s);
|
| 374 |
+
if (!b.rearm && Math.abs(g.s - bs) < C.speed(g.car) * wdt + 2 && Math.abs(g.lat - b.lat) < 3.4) {
|
| 375 |
+
b.rearm = 60; g.events.push({ type: 'trap_collapse' });
|
| 376 |
+
for (const c of g.cops) if (!c.dead && c.state !== 'rb' && Math.hypot(c.x - b.x, c.y - b.y) < BREAKER_R) M.destroyCop(g, c, 'breaker');
|
| 377 |
+
for (const t of g.traffic) if (!t.crash && Math.hypot(t.x - b.x, t.y - b.y) < 14) { t.crash = 0.6; t.vx = Math.cos(t.h) * Math.abs(t.v) * 0.4; t.vy = Math.sin(t.h) * Math.abs(t.v) * 0.4; }
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
// Bounty: seconds in sight, plus a lump per destroyed cop x the multiplier.
|
| 381 |
+
if (g.stageBounty < g.bountyNeed) {
|
| 382 |
+
if (p.inSight) g.stageBounty += wdt;
|
| 383 |
+
if (p.destroyed > before) g.stageBounty += 1.5 * p.bonusMult * (p.destroyed - before);
|
| 384 |
+
g.stageBounty = Math.min(g.bountyNeed, g.stageBounty);
|
| 385 |
+
}
|
| 386 |
+
g.stageEvadeHW = Math.max(g.stageEvadeHW, g.stageBounty >= g.bountyNeed ? p.evade : 0);
|
| 387 |
+
if (p.evade >= 1 && g.stageBounty >= g.bountyNeed) {
|
| 388 |
+
g.events.push({ type: 'evaded', stage: g.stage }); g.stage++;
|
| 389 |
+
if (g.stage >= g.stages) return g.win();
|
| 390 |
+
for (const c of g.cops) c.gone = 1; g.cops = [];
|
| 391 |
+
p.evade = 0; startStage(g, g.diff);
|
| 392 |
+
}
|
| 393 |
+
},
|
| 394 |
+
health(g) {
|
| 395 |
+
const total = g.stages * (BOUNTY_UNITS + EVADE_UNITS);
|
| 396 |
+
if (g.outcome === 'win') return [M.bustHp(g), 50, 0, total];
|
| 397 |
+
const done = g.stage * (BOUNTY_UNITS + EVADE_UNITS) + BOUNTY_UNITS * g.stageBounty / g.bountyNeed + EVADE_UNITS * g.stageEvadeHW;
|
| 398 |
+
return [g.outcome === 'loss' ? 0 : M.bustHp(g), 50, Math.max(0, total - done), total];
|
| 399 |
+
},
|
| 400 |
+
hud(g) { const p = g.pol, s = Math.min(g.stage + 1, g.stages); return { label: 'Police pursuit', detail: `Heat ${s} / ${g.stages} · Bounty ${(100 * g.stageBounty / g.bountyNeed).toFixed(0)}% · Escape ${(100 * p.evade).toFixed(0)}% · Cops ${g.cops.filter(c => !c.dead).length}${g.heli ? ' · Helicopter' : ''}` }; },
|
| 401 |
+
// Reference controller: pursuitPolicy above.
|
| 402 |
+
scripted(g) { return pursuitPolicy(g); },
|
| 403 |
+
hudExtra(g, c, u) { const p = g.pol; if (p.bust > 0.03) { c.font = 'bold 13px "Microsoft YaHei",sans-serif'; c.fillStyle = '#ff6a5a'; c.textAlign = 'center'; c.fillText('Busted ' + Math.round(100 * p.bust / M.BUST_MAX) + '%', u.W / 2, 78); c.textAlign = 'left'; } },
|
| 404 |
+
};
|
| 405 |
+
// Razor. GRace kRaceType_P2P with GetIsPursuitRace: the rival and the police at once. Wikipedia: the rematch is "another 5-street racing pink
|
| 406 |
+
// slip". Streets are legs of the route here; the player must keep ahead of Razor while the chase is on.
|
| 407 |
+
// boss_hp = route metres left; player_hp = the lesser of Razor's remaining share and the bust meter's, per mille.
|
| 408 |
+
M.MODES.street_champion = {
|
| 409 |
+
route: () => 'coast',
|
| 410 |
+
init(g, d) {
|
| 411 |
+
const S = 1500; g.s0 = S; g.total = Math.max(120, M.tierValue(d, [920, 2500, 7000])); g.legs = Math.max(1, Math.round(M.tierValue(d, [1, 2, 5]))); /* floors: d < 0.05 extrapolated to a negative route and 0 streets */ g.placeCar(S, -2.2);
|
| 412 |
+
g.rivals = [M.newRival(g, { s: S + 9, lat: 2.2, skill: C.clamp(M.tierValue(d, [0.1, 0.3, 0.5]) + M.formOf(g), 0, 1), paint: 3, name: 'champion' })];
|
| 413 |
+
g.rivals[0].s0 = S; g.rivals[0].prog = 9; g.glue = 0.7;
|
| 414 |
+
M.initPolice(g, { copsMax: Math.round(M.tierValue(d, [1, 2, 4])), top: M.tierValue(d, [56, 62, 66]), grip: M.tierValue(d, [0.75, 0.82, 0.9]), accel: M.tierValue(d, [0.75, 0.9, 1]), spawnGap: M.tierValue(d, [16, 12, 9]), formations: d < 0.35 ? ['FOLLOW'] : ['FOLLOW', 'ROLLING_BLOCK', 'PIT'], rbChance: M.tierValue(d, [0, 0.35, 0.6]), spikeChance: M.tierValue(d, [0, 0.15, 0.4]), rbGap: M.tierValue(d, [8, 7.5, 6.5]), heli: false, heliAfter: 1e6, heliFuel: 0, heliGap: 1e6, bustSpeed: M.tierValue(d, [6, 9, 12]), searchTop: 40, close: M.tierValue(d, [6, 9, 12]), copFrail: 3.2, aheadChance: M.tierValue(d, [0.2, 0.5, 0.6]), aheadBlind: 1, evadeTimeout: 1e9 });
|
| 415 |
+
g.gates = []; for (let i = 1; i <= g.legs; i++) g.gates.push({ at: g.total * i / g.legs, done: 0, kind: 'line' });
|
| 416 |
+
g.next = 0;
|
| 417 |
+
M.spawnTraffic(g, Math.round(M.tierValue(d, [5, 8, 11])));
|
| 418 |
+
},
|
| 419 |
+
idle(g) { for (const r of g.rivals) { const a = C.routeAt(g.route, r.s, r.lat); r.x = a.x; r.y = a.y; r.h = a.h; } },
|
| 420 |
+
tick(g, wdt) {
|
| 421 |
+
const r = g.rivals[0];
|
| 422 |
+
M.stepRival(g, r, wdt); M.stepPolice(g, wdt, false);
|
| 423 |
+
if (g.outcome) return;
|
| 424 |
+
while (g.next < g.gates.length && g.prog >= g.gates[g.next].at) { g.gates[g.next].done = 1; g.next++; g.events.push({ type: 'leg', leg: g.next }); }
|
| 425 |
+
if (g.prog >= g.total) return g.win();
|
| 426 |
+
if (r.prog >= g.total) g.lose('gap');
|
| 427 |
+
},
|
| 428 |
+
health(g) {
|
| 429 |
+
const r = g.rivals[0], a = clamp((g.total - r.prog) / g.total, 0, 1), b = M.bustHp(g) / 50, hp = g.outcome === 'loss' ? 0 : Math.round(Math.min(a, b) * 1000);
|
| 430 |
+
return [hp, 1000, g.outcome === 'win' ? 0 : Math.max(0, g.total - g.prog), g.total];
|
| 431 |
+
},
|
| 432 |
+
hud(g) { const r = g.rivals[0], lead = g.prog - r.prog; return { label: 'Street Champion Showdown', detail: `Leg ${Math.min(g.next + 1, g.legs)} / ${g.legs} · ${lead >= 0 ? 'Ahead by' : 'Behind by'} ${Math.abs(lead).toFixed(0)} m · Cops ${g.cops.filter(c => !c.dead).length}` }; },
|
| 433 |
+
scripted(g) { return championPolicy(g); },
|
| 434 |
+
hudExtra(g, c, u) { M.MODES.pursuit.hudExtra(g, c, u); },
|
| 435 |
+
};
|
| 436 |
+
void N;
|
| 437 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/modes_speedtrap.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Speed Trap (GRace.h kRaceType_SpeedTrap). Crossing order does not matter: "each checkpoint's total speed is accumulated to
|
| 2 |
+
determine the winner" (Wikipedia). The speed at each camera is what counts, so the driver saves nitrous for the camera, and the
|
| 3 |
+
rival does the same (AIActionRace.cpp CheckSpeedTraps: nitrous 1-3 s ahead by skill, Tweak_SpeedTrapSkillBoost :50), with
|
| 4 |
+
half the usual catch-up glue (AIVehicle.cpp:2053 Tweak_SpeedTrapCatchupGlue 0.5). GRaceStatus.h keeps one speed per trap.
|
| 5 |
+
boss_hp = route metres left to the last camera; player_hp = cushion + score lead over the traps both cars have crossed. The
|
| 6 |
+
camera positions and the cushion are original (the race database is VLT data): cameras sit on the fastest ground nearby. */
|
| 7 |
+
(function (root) {
|
| 8 |
+
'use strict';
|
| 9 |
+
const M = root.NfsmwGame, C = M.C, P = C.PLAYER, KMH = 3.6, S0 = 900;
|
| 10 |
+
M.MODES.speedtrap = {
|
| 11 |
+
route: () => 'coast',
|
| 12 |
+
init(g, d) {
|
| 13 |
+
const R = g.route, v = C.profile(R, P.grip, P.aero, P.brake, C.TOPS[5]);
|
| 14 |
+
g.total = M.tierValue(d, [900, 3100, 7800]); g.s0 = S0; g.placeCar(S0, -2.1); g.glue = 0.5;
|
| 15 |
+
const count = Math.max(2, Math.round(g.total / 480)), reach = C.reachable(R, v, S0, g.total + 100, P);
|
| 16 |
+
g.gates = [];
|
| 17 |
+
for (let i = 1; i <= count; i++) {
|
| 18 |
+
let at = g.total * i / count;
|
| 19 |
+
if (i < count) { let best = at, bv = -1; for (let x = at - 150; x <= at + 150; x += 6) { const u = reach[Math.round(x / R.ds)]; if (u > bv) { bv = u; best = x; } } at = best; }
|
| 20 |
+
g.gates.push({ at, kind: 'trap', done: 0, you: 0, them: 0, themDone: 0 });
|
| 21 |
+
}
|
| 22 |
+
// Pretraining engineering target from the existing deterministic vehicle/route
|
| 23 |
+
// reachability profile. No policy, sampled rival score or evaluation result is used.
|
| 24 |
+
// Freeze once at reset; keep health(), HUD, finish and win/loss rules unchanged.
|
| 25 |
+
g.reward_target_version = 'speedtrap-reachable-profile@1';
|
| 26 |
+
g.reward_target_cameras = g.gates.map(t => Math.round(reach[Math.round(t.at / R.ds)] * KMH * 1e6) / 1e6);
|
| 27 |
+
g.reward_target_score = Math.round(g.reward_target_cameras.reduce((a,b) => a+b, 0) * 1e6) / 1e6;
|
| 28 |
+
if (!Number.isFinite(g.reward_target_score) || g.reward_target_score <= 0) throw Error('invalid fixed speedtrap target');
|
| 29 |
+
g.next = 0; g.rNext = 0; g.you = 0; g.them = 0; g.flashT = 0; g.cushion = M.tierValue(d, [130, 95, 70]);
|
| 30 |
+
g.rivals = [M.newRival(g, { s: S0, lat: 2.1, skill: C.clamp(M.tierValue(d, [0.15, 0.42, 0.68]) + M.formOf(g), 0, 1), paint: 2 })];
|
| 31 |
+
M.spawnTraffic(g, Math.round(M.tierValue(d, [6, 9, 13])));
|
| 32 |
+
},
|
| 33 |
+
idle() {},
|
| 34 |
+
lead(g) { let lead = 0; for (let i = 0; i < g.gates.length; i++) { const t = g.gates[i]; if (t.done && t.themDone) lead += t.you - t.them; } return lead; },
|
| 35 |
+
tick(g, wdt) {
|
| 36 |
+
if (g.flashT > 0) g.flashT = Math.max(0, g.flashT - wdt);
|
| 37 |
+
const r = g.rivals[0];
|
| 38 |
+
while (g.rNext < g.gates.length && r.prog >= g.gates[g.rNext].at) { const t = g.gates[g.rNext]; t.them = r.v * KMH; t.themDone = 1; g.them += t.them; g.rNext++; }
|
| 39 |
+
if (g.rNext < g.gates.length) { const ahead = g.gates[g.rNext].at - r.prog, tt = ahead / Math.max(r.v, 5); if (tt < C.lerp(1, 3, r.skill)) r.trapNos = 0.2; }
|
| 40 |
+
M.stepRival(g, r, wdt);
|
| 41 |
+
while (g.next < g.gates.length && g.prog >= g.gates[g.next].at) { const t = g.gates[g.next]; t.done = 1; t.keep = 0; t.you = C.speed(g.car) * KMH; g.you += t.you; g.next++; g.flashT = 0.15; g.events.push({ type: 'speedtrap', kmh: t.you }); }
|
| 42 |
+
if (g.next >= g.gates.length) {
|
| 43 |
+
// The player's last camera ends the event. Cameras the rival has not reached yet are scored at the speed it would carry there.
|
| 44 |
+
let them = g.them; for (let i = g.rNext; i < g.gates.length; i++) them += M.projectRival(g, r, g.s0 + g.gates[i].at) * KMH;
|
| 45 |
+
g.themFinal = them;
|
| 46 |
+
if (g.you >= them) g.win(); else g.lose('score');
|
| 47 |
+
return;
|
| 48 |
+
}
|
| 49 |
+
if (g.cushion + this.lead(g) <= 0) g.lose('score');
|
| 50 |
+
},
|
| 51 |
+
health(g) {
|
| 52 |
+
const max = g.cushion * 2, hp = g.outcome === 'loss' ? 0 : C.clamp(g.cushion + this.lead(g), 0, max);
|
| 53 |
+
return [hp, max, g.outcome === 'win' ? 0 : Math.max(0, g.total - g.prog), g.total];
|
| 54 |
+
},
|
| 55 |
+
hud(g) { return { label: 'Speed Trap', detail: `Checkpoint ${Math.min(g.next + 1, g.gates.length)} / ${g.gates.length} · You: ${g.you.toFixed(0)} · Rival: ${g.them.toFixed(0)} km/h` }; },
|
| 56 |
+
// Reference: drive the line, and spend nitrous only in the last seconds before a camera.
|
| 57 |
+
scripted(g) {
|
| 58 |
+
const v = Math.max(C.speed(g.car), 5), t = g.gates[g.next], ahead = t ? (t.at - g.prog) / v : 99;
|
| 59 |
+
return M.ctl.drive(g, ahead < 2.8 ? { forceNos: true } : { nos: false });
|
| 60 |
+
},
|
| 61 |
+
};
|
| 62 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/modes_tollbooth.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Tollbooth (GRace.h kRaceType_Tollbooth): a solo run against the clock. Each gate grants more time and leftover seconds
|
| 2 |
+
carry over (Wikipedia, "Need for Speed: Most Wanted (2005)": "a checkpoint-styled solo race, in which players must hit
|
| 3 |
+
a set of checkpoints, each one within a set amount of time"; GRaceStatus.h NotifyTollboothCrossed counts them).
|
| 4 |
+
boss_hp = route metres left to the last gate; player_hp = clock in tenths of a second. The gate timings live in the
|
| 5 |
+
game's race database (VLT), so the allowance here is an approximation: slack x the car's own ideal time. */
|
| 6 |
+
(function (root) {
|
| 7 |
+
'use strict';
|
| 8 |
+
const M = root.NfsmwGame, C = M.C;
|
| 9 |
+
const P = C.PLAYER, TOP = C.TOPS[5];
|
| 10 |
+
M.MODES.tollbooth = {
|
| 11 |
+
route: () => 'coast',
|
| 12 |
+
init(g, d) {
|
| 13 |
+
const R = g.route, S0 = 3640;
|
| 14 |
+
g.total = M.tierValue(d, [860, 3250, 8000]);
|
| 15 |
+
g.s0 = S0; g.placeCar(S0, -2.1);
|
| 16 |
+
const slack = M.tierValue(d, [1.55, 1.34, 1.2]), v = C.profile(R, P.grip, P.aero, P.brake, TOP), spacing = 620;
|
| 17 |
+
const count = Math.max(2, Math.round(g.total / spacing));
|
| 18 |
+
g.gates = [];
|
| 19 |
+
let at = 0;
|
| 20 |
+
for (let i = 1; i <= count; i++) { const end = g.total * i / count; g.gates.push({ at: end, grant: C.driveTime(R, v, S0 + at, end - at, P, i === 1 ? 0 : 30) * slack, done: 0 }); at = end; }
|
| 21 |
+
g.next = 0; g.bank = g.gates[0].grant + 3; g.bankMax = g.bank;
|
| 22 |
+
M.spawnTraffic(g, Math.round(M.tierValue(d, [7, 11, 16])));
|
| 23 |
+
},
|
| 24 |
+
idle() {},
|
| 25 |
+
tick(g, wdt) {
|
| 26 |
+
g.bank -= wdt;
|
| 27 |
+
while (g.next < g.gates.length && g.prog >= g.gates[g.next].at) {
|
| 28 |
+
const gate = g.gates[g.next]; gate.done = 1; g.next++;
|
| 29 |
+
g.events.push({ type: 'gate', left: g.bank });
|
| 30 |
+
if (g.next < g.gates.length) { g.bank += g.gates[g.next].grant; g.bankMax = Math.max(g.bankMax, g.bank); }
|
| 31 |
+
}
|
| 32 |
+
if (g.prog >= g.total) return g.win();
|
| 33 |
+
if (g.bank <= 0) { g.bank = 0; g.lose('time'); }
|
| 34 |
+
},
|
| 35 |
+
health(g) {
|
| 36 |
+
const left = Math.max(0, g.total - g.prog);
|
| 37 |
+
return [Math.max(0, g.outcome === 'loss' ? 0 : Math.round(g.bank * 10)), Math.ceil(g.bankMax * 10), g.outcome === 'win' ? 0 : left, g.total];
|
| 38 |
+
},
|
| 39 |
+
hud(g) { return { label: 'Tollbooth', detail: `Gate ${Math.min(g.next + 1, g.gates.length)} / ${g.gates.length} · Time left: ${g.bank.toFixed(1)} s` }; },
|
| 40 |
+
};
|
| 41 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/nfscore.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Need for Speed: Most Wanted (2005) events, rules nfsmw-arena@1 - world and vehicle core.
|
| 2 |
+
Original procedural city: the roads are a union of capsules around authored polylines, so a car is free inside the
|
| 3 |
+
union and everything outside is a wall; sight lines sample the same function. Routes are rounded polylines sampled
|
| 4 |
+
every 2 m and measured along their own length (progress is route distance, never distance to a target).
|
| 5 |
+
Vehicle rules read from the CC0 decompilation dbalatoni13/nfsmw@80993f3 are cited inline; values that live in the
|
| 6 |
+
game's VLT data (mass, torque, grip) are not in that repository and are original approximations (see SOURCES.md).
|
| 7 |
+
Nothing here touches a game's RNG: every function is pure except for the car it is handed. */
|
| 8 |
+
(function (root) {
|
| 9 |
+
'use strict';
|
| 10 |
+
const M = root.NfsmwGame = root.NfsmwGame || {}, C = M.C = {};
|
| 11 |
+
const q4 = v => Math.round(v * 1e4) / 1e4; // static geometry is rounded once so trig ULPs cannot reach a replay
|
| 12 |
+
const clamp = (v, a, b) => v < a ? a : v > b ? b : v;
|
| 13 |
+
C.clamp = clamp; C.lerp = (a, b, t) => a + (b - a) * t;
|
| 14 |
+
C.MPH = 0.44704; C.KPH = 1 / 3.6;
|
| 15 |
+
|
| 16 |
+
// ---------------- authored routes: [x, y, corner radius] (original layout) ----------------
|
| 17 |
+
const ROUTES = {
|
| 18 |
+
// Coastal loop: the 1.5 km highway along the south shore, sweepers in the east, a chicane in the north, hills west.
|
| 19 |
+
coast: { loop: true, width: 17, pts: [[-760, -520, 90], [860, -520, 220], [980, -120, 160], [760, 260, 120], [820, 520, 100], [300, 560, 80], [220, 400, 45], [-60, 400, 45], [-140, 560, 70], [-620, 560, 120], [-820, 260, 90], [-640, 60, 70], [-860, -140, 90]] },
|
| 20 |
+
// Downtown block: the short circuit for the knockout, four fast corners and an inner chicane.
|
| 21 |
+
downtown: { loop: true, width: 15, pts: [[-85, -80, 26], [90, -80, 22], [90, -22, 15], [46, -22, 13], [46, 28, 13], [90, 28, 15], [90, 80, 22], [-85, 80, 26]] },
|
| 22 |
+
// Highway 99 drag strip: dead straight, four lanes, not connected to the city.
|
| 23 |
+
strip: { loop: false, width: 22, pts: [[-1500, -1000, 0], [1500, -1000, 0]] },
|
| 24 |
+
};
|
| 25 |
+
// Cross streets: never raced, they are what the pursuit is about (sight breaks, cops arriving from the side).
|
| 26 |
+
const STREETS = [
|
| 27 |
+
[[0, -520], [0, -80]], [[0, 80], [0, 400]], [[46, 3], [420, 3], [420, 260], [760, 260]], [[-85, 0], [-400, 0], [-400, 60], [-640, 60]],
|
| 28 |
+
[[420, 0], [420, -520]], [[-400, 0], [-400, -520]], [[420, 260], [300, 560]], [[-400, 60], [-400, 560]],
|
| 29 |
+
];
|
| 30 |
+
const STREET_W = 13, DS = 2;
|
| 31 |
+
|
| 32 |
+
function buildRoute(name, def) {
|
| 33 |
+
const P = def.pts, n = P.length; // each corner becomes a tangent arc between two straights
|
| 34 |
+
const corner = i => {
|
| 35 |
+
const [x, y, r] = P[i], a = P[(i + n - 1) % n], b = P[(i + 1) % n];
|
| 36 |
+
const ax = a[0] - x, ay = a[1] - y, bx = b[0] - x, by = b[1] - y, la = Math.hypot(ax, ay), lb = Math.hypot(bx, by);
|
| 37 |
+
const ux = ax / la, uy = ay / la, vx = bx / lb, vy = by / lb, cos = clamp(ux * vx + uy * vy, -1, 1), th = Math.acos(cos);
|
| 38 |
+
const t = r / Math.tan(th / 2);
|
| 39 |
+
if (t > Math.min(la, lb) * 0.5 + 1e-6) throw Error(`${name}: corner ${i} radius too large`);
|
| 40 |
+
const hx = ux + vx, hy = uy + vy, hl = Math.hypot(hx, hy), dist = r / Math.sin(th / 2);
|
| 41 |
+
const cx = x + hx / hl * dist, cy = y + hy / hl * dist, sx = x + ux * t, sy = y + uy * t, ex = x + vx * t, ey = y + vy * t;
|
| 42 |
+
const turn = -Math.sign(ux * vy - uy * vx); // +1 = counter-clockwise
|
| 43 |
+
return { sx, sy, ex, ey, cx, cy, r, sweep: Math.PI - th, turn };
|
| 44 |
+
};
|
| 45 |
+
const out = { x: [], y: [], h: [], k: [] };
|
| 46 |
+
const push = (x, y, h, k) => { out.x.push(q4(x)); out.y.push(q4(y)); out.h.push(q4(h)); out.k.push(Math.round(k * 1e7) / 1e7); };
|
| 47 |
+
const dense = []; // 0.25 m polyline with curvature, resampled to DS below
|
| 48 |
+
const line = (ax, ay, bx, by) => { const L = Math.hypot(bx - ax, by - ay), m = Math.max(1, Math.ceil(L / 0.25)), h = Math.atan2(by - ay, bx - ax); for (let i = 0; i < m; i++) dense.push([ax + (bx - ax) * i / m, ay + (by - ay) * i / m, h, 0]); };
|
| 49 |
+
if (def.loop) {
|
| 50 |
+
const cs = P.map((_, i) => corner(i));
|
| 51 |
+
for (let i = 0; i < n; i++) {
|
| 52 |
+
const c = cs[i], d = cs[(i + 1) % n], a0 = Math.atan2(c.sy - c.cy, c.sx - c.cx), m = Math.max(1, Math.ceil(c.r * c.sweep / 0.25));
|
| 53 |
+
for (let j = 0; j < m; j++) { const a = a0 + c.turn * c.sweep * j / m; dense.push([c.cx + Math.cos(a) * c.r, c.cy + Math.sin(a) * c.r, a + c.turn * Math.PI / 2, c.turn / c.r]); }
|
| 54 |
+
line(c.ex, c.ey, d.sx, d.sy);
|
| 55 |
+
}
|
| 56 |
+
} else { for (let i = 0; i + 1 < n; i++) line(P[i][0], P[i][1], P[i + 1][0], P[i + 1][1]); dense.push([P[n - 1][0], P[n - 1][1], dense[dense.length - 1][2], 0]); }
|
| 57 |
+
let acc = 0, next = 0, last = dense[0];
|
| 58 |
+
dense.forEach((p, i) => { if (i) acc += Math.hypot(p[0] - last[0], p[1] - last[1]); last = p; while (acc >= next - 1e-9) { push(p[0], p[1], p[2], p[3]); next += DS; } });
|
| 59 |
+
const L = out.x.length * DS;
|
| 60 |
+
return { name, loop: !!def.loop, width: def.width, halfW: def.width / 2, ds: DS, n: out.x.length, L, x: out.x, y: out.y, h: out.h, k: out.k };
|
| 61 |
+
}
|
| 62 |
+
C.routes = {}; for (const [k, d] of Object.entries(ROUTES)) C.routes[k] = buildRoute(k, d);
|
| 63 |
+
// Route position (s is unbounded on a loop). Writes to a shared scratch object: copy the fields you keep.
|
| 64 |
+
const at = { x: 0, y: 0, h: 0, k: 0, nx: 0, ny: 0 };
|
| 65 |
+
C.routeAt = (R, s, lat = 0) => {
|
| 66 |
+
let u = s / R.ds; if (R.loop) { u %= R.n; if (u < 0) u += R.n; } else u = clamp(u, 0, R.n - 1.0001);
|
| 67 |
+
const i = Math.floor(u), f = u - i, j = (i + 1) % R.n;
|
| 68 |
+
let dh = R.h[j] - R.h[i]; if (dh > Math.PI) dh -= 2 * Math.PI; else if (dh < -Math.PI) dh += 2 * Math.PI;
|
| 69 |
+
at.h = R.h[i] + dh * f; at.k = R.k[i]; at.nx = -Math.sin(at.h); at.ny = Math.cos(at.h);
|
| 70 |
+
at.x = R.x[i] + (R.x[j] - R.x[i]) * f + at.nx * lat; at.y = R.y[i] + (R.y[j] - R.y[i]) * f + at.ny * lat;
|
| 71 |
+
return at;
|
| 72 |
+
};
|
| 73 |
+
// Nearest route distance within a window around a guess: junctions can never teleport progress to another leg.
|
| 74 |
+
C.routeNear = (R, x, y, guess, back = 40, fwd = 60) => {
|
| 75 |
+
let best = guess, bd = Infinity;
|
| 76 |
+
const g0 = Math.round(guess / R.ds) * R.ds;
|
| 77 |
+
for (let s = g0 - back; s <= g0 + fwd; s += R.ds) {
|
| 78 |
+
if (!R.loop && (s < 0 || s > R.L)) continue;
|
| 79 |
+
let u = Math.round(s / R.ds); if (R.loop) { u %= R.n; if (u < 0) u += R.n; } else u = clamp(u, 0, R.n - 1);
|
| 80 |
+
const dx = x - R.x[u], dy = y - R.y[u], d = dx * dx + dy * dy; if (d < bd) { bd = d; best = s; }
|
| 81 |
+
}
|
| 82 |
+
// refine inside the winning 2 m cell with the segment projection
|
| 83 |
+
const a = C.routeAt(R, best), ax = Math.cos(a.h), ay = Math.sin(a.h);
|
| 84 |
+
return best + clamp((x - a.x) * ax + (y - a.y) * ay, -R.ds, R.ds);
|
| 85 |
+
};
|
| 86 |
+
C.routeLat = (R, x, y, s) => { const a = C.routeAt(R, s); return (x - a.x) * a.nx + (y - a.y) * a.ny; };
|
| 87 |
+
|
| 88 |
+
// ---------------- the road union: 10 m grid of candidate capsules ----------------
|
| 89 |
+
const SEGS = []; const addPoly = (pts, hw, closed) => { const m = closed ? pts.length : pts.length - 1; for (let i = 0; i < m; i++) { const a = pts[i], b = pts[(i + 1) % pts.length]; SEGS.push({ ax: a[0], ay: a[1], bx: b[0], by: b[1], hw }); } };
|
| 90 |
+
for (const R of Object.values(C.routes)) { const pts = []; const step = R.name === 'strip' ? 50 : R.name === 'downtown' ? 2 : 4; for (let i = 0; i < R.n; i += step) pts.push([R.x[i], R.y[i]]); if (!R.loop) pts.push([R.x[R.n - 1], R.y[R.n - 1]]); addPoly(pts, R.halfW, R.loop); }
|
| 91 |
+
for (const st of STREETS) addPoly(st, STREET_W / 2, false);
|
| 92 |
+
C.streets = STREETS; C.streetW = STREET_W;
|
| 93 |
+
const CELL = 10, X0 = -1560, Y0 = -1060, NX = 310, NY = 180, GRID = new Array(NX * NY);
|
| 94 |
+
SEGS.forEach((g, gi) => {
|
| 95 |
+
const pad = g.hw + CELL * 1.5, x0 = Math.floor((Math.min(g.ax, g.bx) - pad - X0) / CELL), x1 = Math.floor((Math.max(g.ax, g.bx) + pad - X0) / CELL), y0 = Math.floor((Math.min(g.ay, g.by) - pad - Y0) / CELL), y1 = Math.floor((Math.max(g.ay, g.by) + pad - Y0) / CELL);
|
| 96 |
+
for (let j = Math.max(0, y0); j <= Math.min(NY - 1, y1); j++) for (let i = Math.max(0, x0); i <= Math.min(NX - 1, x1); i++) { const px = X0 + (i + 0.5) * CELL, py = Y0 + (j + 0.5) * CELL, dx = g.bx - g.ax, dy = g.by - g.ay, t = clamp(((px - g.ax) * dx + (py - g.ay) * dy) / (dx * dx + dy * dy || 1), 0, 1); if (Math.hypot(px - g.ax - t * dx, py - g.ay - t * dy) <= pad) { const c = i + j * NX; (GRID[c] || (GRID[c] = [])).push(gi); } }
|
| 97 |
+
});
|
| 98 |
+
// d > 0 means d metres outside the union; (nx, ny) points from the road centre towards the car.
|
| 99 |
+
const hit = { d: 0, nx: 0, ny: 0 };
|
| 100 |
+
C.road = (x, y) => {
|
| 101 |
+
const i = Math.floor((x - X0) / CELL), j = Math.floor((y - Y0) / CELL);
|
| 102 |
+
hit.d = 99; hit.nx = 0; hit.ny = 0;
|
| 103 |
+
if (i < 0 || j < 0 || i >= NX || j >= NY) return hit;
|
| 104 |
+
const c = GRID[i + j * NX]; if (!c) return hit;
|
| 105 |
+
for (let k = 0; k < c.length; k++) {
|
| 106 |
+
const g = SEGS[c[k]], dx = g.bx - g.ax, dy = g.by - g.ay, t = clamp(((x - g.ax) * dx + (y - g.ay) * dy) / (dx * dx + dy * dy || 1), 0, 1), px = x - g.ax - t * dx, py = y - g.ay - t * dy, l = Math.sqrt(px * px + py * py), d = l - g.hw;
|
| 107 |
+
if (d < hit.d) { hit.d = d; if (l > 1e-6) { hit.nx = px / l; hit.ny = py / l; } else { hit.nx = 0; hit.ny = 0; } }
|
| 108 |
+
}
|
| 109 |
+
return hit;
|
| 110 |
+
};
|
| 111 |
+
C.onRoad = (x, y, margin = 0) => C.road(x, y).d < -margin;
|
| 112 |
+
// Sight line: buildings stand everywhere the road is not (AIVehicleCopCar::CanSeeTarget's world ray, sampled).
|
| 113 |
+
C.lineClear = (ax, ay, bx, by) => { const L = Math.hypot(bx - ax, by - ay), m = Math.ceil(L / 5); for (let i = 1; i < m; i++) if (C.road(ax + (bx - ax) * i / m, ay + (by - ay) * i / m).d > 2) return false; return true; };
|
| 114 |
+
C.bounds = { X0, Y0, NX, NY, CELL };
|
| 115 |
+
|
| 116 |
+
// ---------------- vehicle ----------------
|
| 117 |
+
const lookup = (tab, v, max) => { const u = clamp(v / max, 0, 1) * (tab.length - 1), i = Math.min(tab.length - 2, Math.floor(u)); return tab[i] + (tab[i + 1] - tab[i]) * (u - i); };
|
| 118 |
+
// SuspensionRacer.cpp:1077 SteeringRangeData, degrees over 0..160 mph; :1072 BrakeSteeringRangeMultiplier 1.45.
|
| 119 |
+
const STEER_RANGE = [40, 20, 10, 5.5, 4.5, 3.25, 2.9, 2.9, 2.9, 2.9], BRAKE_STEER = 1.45;
|
| 120 |
+
// Approximation (VLT transmission/engine data is not in the repository): an original six-speed road car.
|
| 121 |
+
const TOPS = [17, 30, 43, 55, 67, 84], DRIVE = [10.5, 8.2, 6.4, 5.0, 4.0, 3.1];
|
| 122 |
+
const PLAYER = { wheelbase: 2.7, grip: 12.5, aero: 0.0012, drag: 0.00039, roll: 0.25, brake: 13, accel: 1, radius: 1.5, nosBoost: 0.35, nosSeconds: 6, overheat: false };
|
| 123 |
+
C.PLAYER = PLAYER; C.TOPS = TOPS;
|
| 124 |
+
C.newCar = (x, y, h) => ({ x, y, h, vx: 0, vy: 0, r: 0, steer: 0, gear: 0, clutch: 0, bonus: 0, perfect: 0, nos: 1, nosOn: 0, heat: 0, blown: 0, tires: 0, hit: 0, drift: 0, over: 0 });
|
| 125 |
+
const NOS_MIN_MPH = 10; // EngineRacer.cpp:926 Tweak_MinSpeedForNosMPH; half of it keeps nitrous engaged (:950)
|
| 126 |
+
// Over-rev heat, EngineRacer.cpp:1340-1345: +0.45/s on the limiter, -0.1/s otherwise, blown at 1, -25% torque from 0.6.
|
| 127 |
+
const HEAT_UP = 0.45, HEAT_DOWN = -0.1, HEAT_PENALTY = 0.6, HEAT_TORQUE = 0.75;
|
| 128 |
+
const CLUTCH = 0.25, CLUTCH_FIRST = 0.05; // EngineRacer.cpp:34-35
|
| 129 |
+
C.steerRange = mph => lookup(STEER_RANGE, mph, 160);
|
| 130 |
+
C.tireFactor = c => 1 - 0.7 * (c.tires / 4); // SuspensionRacer.cpp:1569 Tweak_BlownTireTraction 0.3 on all four
|
| 131 |
+
// One step. inp: {thr, brk, steer in [-1,1] (+ = left), hb, nos, up, down, manual, reverse, sbGrip}. dt is world time.
|
| 132 |
+
C.carStep = (c, inp, dt, P = PLAYER) => {
|
| 133 |
+
const ch = Math.cos(c.h), sh = Math.sin(c.h);
|
| 134 |
+
let vf = c.vx * ch + c.vy * sh, vl = -c.vx * sh + c.vy * ch;
|
| 135 |
+
const speed = Math.hypot(vf, vl), mph = speed / C.MPH, tire = C.tireFactor(c);
|
| 136 |
+
// steering: input slews, range comes from the speed table
|
| 137 |
+
const rate = speed < 15 ? 7 : speed < 40 ? 5 : 3.6, want = clamp(inp.steer, -1, 1);
|
| 138 |
+
c.steer += clamp(want - c.steer, -rate * dt, rate * dt);
|
| 139 |
+
const range = lookup(STEER_RANGE, mph, 160) * (inp.hb || inp.brk ? BRAKE_STEER : 1), delta = c.steer * range * Math.PI / 180;
|
| 140 |
+
const grip0 = (P.grip + P.aero * speed * speed + (inp.sbGrip || 0)) * tire;
|
| 141 |
+
let target = vf * Math.tan(delta) / P.wheelbase, rmax = grip0 * 1.05 / Math.max(speed, 3);
|
| 142 |
+
if (inp.hb) rmax *= 1.9;
|
| 143 |
+
target = clamp(target, -rmax, rmax);
|
| 144 |
+
c.r += (target - c.r) * Math.min(1, dt * 9);
|
| 145 |
+
c.h += c.r * dt;
|
| 146 |
+
// gearbox and drive
|
| 147 |
+
if (c.clutch > 0) c.clutch = Math.max(0, c.clutch - dt);
|
| 148 |
+
if (c.bonus > 0) c.bonus = Math.max(0, c.bonus - dt);
|
| 149 |
+
const u = Math.max(vf, 0) / TOPS[c.gear];
|
| 150 |
+
if (inp.manual) {
|
| 151 |
+
if (inp.up && c.gear < 5) { const perfect = u >= 0.88 && u <= 0.99; c.clutch = perfect ? CLUTCH_FIRST : CLUTCH; if (perfect) { c.bonus = 1; c.perfect++; } c.gear++; }
|
| 152 |
+
else if (inp.down && c.gear > 0) { c.gear--; c.clutch = CLUTCH; }
|
| 153 |
+
} else if (c.clutch <= 0) {
|
| 154 |
+
if (u > 0.97 && c.gear < 5) { c.clutch = c.gear === 0 ? CLUTCH_FIRST : CLUTCH; c.gear++; }
|
| 155 |
+
else if (c.gear > 0 && vf < TOPS[c.gear - 1] * 0.82) c.gear--;
|
| 156 |
+
}
|
| 157 |
+
// nitrous, EngineRacer::DoNos
|
| 158 |
+
let boost = 1;
|
| 159 |
+
const engaged = !!inp.nos && inp.thr > 0 && c.nos > 0 && !c.blown && (mph >= NOS_MIN_MPH || (c.nosOn && mph >= NOS_MIN_MPH / 2));
|
| 160 |
+
if (engaged) { c.nos = Math.max(0, c.nos - dt / P.nosSeconds); boost = 1 + P.nosBoost; c.nosOn = 1; }
|
| 161 |
+
else { c.nosOn = 0; if (speed > 10) c.nos = Math.min(1, c.nos + dt * (speed > 50 ? 0.07 : 0.035)); }
|
| 162 |
+
const uNow = Math.max(vf, 0) / TOPS[c.gear], limiter = uNow >= 1;
|
| 163 |
+
c.over = limiter && inp.thr > 0 ? 1 : 0;
|
| 164 |
+
if (P.overheat && c.gear > 0) { c.heat = Math.max(0, c.heat + (c.over ? HEAT_UP : HEAT_DOWN) * dt); if (c.heat >= 1) c.blown = 1; }
|
| 165 |
+
let drive = 0;
|
| 166 |
+
if (!c.blown && c.clutch <= 0 && inp.thr > 0) {
|
| 167 |
+
const curve = uNow < 0.35 ? 0.75 + 0.25 * uNow / 0.35 : uNow < 0.9 ? 1 : uNow < 1 ? 1 - (uNow - 0.9) * 2 : 0;
|
| 168 |
+
drive = DRIVE[c.gear] * curve * inp.thr * boost * P.accel * tire * (c.heat > HEAT_PENALTY ? HEAT_TORQUE : 1) * (c.bonus > 0 ? 1.1 : 1);
|
| 169 |
+
}
|
| 170 |
+
// re-express velocity in the turned frame; rear tyres scrub the lateral part (handbrake drops them)
|
| 171 |
+
const ch2 = Math.cos(c.h), sh2 = Math.sin(c.h);
|
| 172 |
+
vf = c.vx * ch2 + c.vy * sh2; vl = -c.vx * sh2 + c.vy * ch2;
|
| 173 |
+
let ax = drive - P.drag * vf * Math.abs(vf) - P.roll * (Math.abs(vf) > 0.2 ? Math.sign(vf) : 0);
|
| 174 |
+
if (inp.brk) { if (vf > 0.3) ax -= P.brake * tire; else if (inp.reverse) ax -= 4.5; }
|
| 175 |
+
if (inp.hb && Math.abs(vf) > 0.3) ax -= 6 * Math.sign(vf);
|
| 176 |
+
const longLim = grip0 * 1.1; ax = clamp(ax, -longLim, longLim);
|
| 177 |
+
const used = Math.min(0.75, Math.abs(ax) / longLim * 0.55), latCap = grip0 * (inp.hb ? 0.42 : 1) * (1 - used);
|
| 178 |
+
vf += ax * dt;
|
| 179 |
+
if (inp.brk && !inp.reverse && vf < 0) vf = 0;
|
| 180 |
+
const dl = clamp(vl, -latCap * dt, latCap * dt); vl -= dl;
|
| 181 |
+
c.drift = Math.abs(vl) > 2.5 ? 1 : 0;
|
| 182 |
+
if (c.drift) vf -= Math.sign(vf) * Math.min(Math.abs(vf), 0.8 * dt);
|
| 183 |
+
c.vx = vf * ch2 - vl * sh2; c.vy = vf * sh2 + vl * ch2;
|
| 184 |
+
c.x += c.vx * dt; c.y += c.vy * dt;
|
| 185 |
+
// walls: everything outside the road union
|
| 186 |
+
const q = C.road(c.x, c.y), over = q.d + 1;
|
| 187 |
+
c.hit = 0;
|
| 188 |
+
if (over > 0) {
|
| 189 |
+
c.x -= q.nx * over; c.y -= q.ny * over;
|
| 190 |
+
const vn = c.vx * q.nx + c.vy * q.ny;
|
| 191 |
+
if (vn > 0) {
|
| 192 |
+
c.vx -= 1.25 * vn * q.nx; c.vy -= 1.25 * vn * q.ny;
|
| 193 |
+
const scrub = 1 - Math.min(0.3, vn * 0.012); c.vx *= scrub; c.vy *= scrub; c.hit = vn; if (vn > 3) c.r *= 0.3;
|
| 194 |
+
} else { c.vx *= 1 - 0.3 * dt; c.vy *= 1 - 0.3 * dt; }
|
| 195 |
+
}
|
| 196 |
+
};
|
| 197 |
+
C.speed = c => Math.hypot(c.vx, c.vy);
|
| 198 |
+
// Point-mass speed profile along a route: curvature limit with a backward braking pass. grip follows
|
| 199 |
+
// AIActionRace::GetPotentialSpeed (grip scaled by skill); the player's controller uses the player's own numbers.
|
| 200 |
+
const profiles = new Map();
|
| 201 |
+
C.profile = (R, grip, aero, brake, top) => {
|
| 202 |
+
const key = R.name + '|' + [grip, aero, brake, top].map(v => v.toFixed(3)).join('|');
|
| 203 |
+
let v = profiles.get(key); if (v) return v;
|
| 204 |
+
v = new Float64Array(R.n);
|
| 205 |
+
// Curvature is taken over +-6 m: a car starts turning before the arc begins and has not finished when it ends.
|
| 206 |
+
for (let i = 0; i < R.n; i++) {
|
| 207 |
+
let k = 0; for (let j = -3; j <= 3; j++) { const m = R.loop ? (i + j + R.n) % R.n : clamp(i + j, 0, R.n - 1); k = Math.max(k, Math.abs(R.k[m])); }
|
| 208 |
+
// k * v^2 = grip + aero v^2 -> v^2 = grip / (k - aero)
|
| 209 |
+
v[i] = k > aero + 1e-5 ? Math.min(top, Math.sqrt(grip / (k - aero))) : top;
|
| 210 |
+
}
|
| 211 |
+
const passes = R.loop ? 2 : 1;
|
| 212 |
+
for (let p = 0; p < passes; p++) for (let i = R.n - 1; i >= 0; i--) {
|
| 213 |
+
const j = i + 1 < R.n ? i + 1 : R.loop ? 0 : i;
|
| 214 |
+
const lim = Math.sqrt(v[j] * v[j] + 2 * brake * R.ds); if (lim < v[i]) v[i] = lim;
|
| 215 |
+
}
|
| 216 |
+
profiles.set(key, v); return v;
|
| 217 |
+
};
|
| 218 |
+
// Drive force at a speed in the gear an automatic box would hold: the same curve as carStep. Rivals and estimates use it.
|
| 219 |
+
C.driveAt = u => { let gear = 0; while (gear < 5 && u > TOPS[gear] * 0.97) gear++; const un = u / TOPS[gear], curve = un < 0.35 ? 0.75 + 0.25 * un / 0.35 : un < 0.9 ? 1 : Math.max(0, 1 - (un - 0.9) * 2); return DRIVE[gear] * curve; };
|
| 220 |
+
// Speed a car can actually carry along a stretch: forward pass over the limits. The profile alone reads top speed on the exit of any corner.
|
| 221 |
+
C.reachable = (R, v, s0, len, P = PLAYER, v0 = 0) => {
|
| 222 |
+
const out = []; let u = v0;
|
| 223 |
+
for (let s = 0; s <= len; s += R.ds) { const a = Math.max(0, C.driveAt(u) * P.accel - P.drag * u * u - P.roll); u = Math.min(C.profileAt(R, v, s0 + s), Math.sqrt(u * u + 2 * a * R.ds)); out.push(u); }
|
| 224 |
+
return out;
|
| 225 |
+
};
|
| 226 |
+
// Time for the car to cover a stretch: the profile's corner and braking limits with the gearbox's acceleration on top.
|
| 227 |
+
C.driveTime = (R, v, s0, len, P = PLAYER, v0 = 0) => {
|
| 228 |
+
let t = 0, u = v0;
|
| 229 |
+
for (let s = 0; s < len; s += R.ds) {
|
| 230 |
+
const vmax = C.profileAt(R, v, s0 + s), a = Math.max(0.2, C.driveAt(u) * P.accel - P.drag * u * u - P.roll);
|
| 231 |
+
u = Math.min(vmax, Math.sqrt(u * u + 2 * a * R.ds));
|
| 232 |
+
t += R.ds / Math.max(u, 3);
|
| 233 |
+
}
|
| 234 |
+
return t;
|
| 235 |
+
};
|
| 236 |
+
C.profileAt = (R, v, s) => { let i = Math.round(s / R.ds); if (R.loop) { i %= R.n; if (i < 0) i += R.n; } else i = clamp(i, 0, R.n - 1); return v[i]; };
|
| 237 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/page.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Page-only layer for the human play page. Not listed in manifest.json: the public interface, the recordings and the source
|
| 2 |
+
fingerprint never load it, so nothing here can change a fight. The shared shell (_native/shell.js) owns the loop, the session,
|
| 3 |
+
the keys, and since 2026-11-08 also: restart after a result (click on the picture, Enter, R; not after a replay), focus back
|
| 4 |
+
to the picture after a button, a frame loop that survives a throw from M.draw (pause + reason in the status bar), and the
|
| 5 |
+
Module.pointerLock opt-out. This file only adds what the shell does not do ("only one race"):
|
| 6 |
+
- a panel over the picture before a race, while paused and after the result, with buttons that stay on the picture
|
| 7 |
+
(retry / next event), the event's control hints, and a hint for the reason a race was lost;
|
| 8 |
+
- N for the next event, Enter to start from the idle panel and to resume from the pause panel;
|
| 9 |
+
- focus back to the picture after picking an event or a tier in the lists, and when a game key is pressed on a button;
|
| 10 |
+
- pointer lock off (this game never uses the mouse; a locked cursor could not reach the buttons);
|
| 11 |
+
- a new 3D scene after a renderer failure: the shell pauses the race, but the old scene keeps its dead WebGL context.
|
| 12 |
+
It drives the shell only through its own buttons, so a race started here is exactly a race started from the toolbar.
|
| 13 |
+
Restart keys and clicks are never handled twice: Enter / R after a result are the shell's (its capture listener runs first
|
| 14 |
+
and stops the event), and the panel covers the canvas, so the shell's canvas click and the panel's click never both fire. */
|
| 15 |
+
(function () {
|
| 16 |
+
'use strict';
|
| 17 |
+
const M = window.GAME_MODULE, $ = s => document.querySelector(s), canvas = $('canvas'), panel = $('#nfs-panel');
|
| 18 |
+
if (!M || !canvas || !panel) return;
|
| 19 |
+
M.pointerLock = false; // read by the shell's double-click handler (shell.js, 2026-11-08)
|
| 20 |
+
let game = null, resultAt = 0, shown = '', broken = null, retryAt = 0;
|
| 21 |
+
const HINT = {
|
| 22 |
+
tollbooth: ['Passing a tollbooth adds time; you lose when the timer reaches zero', 'Release W or tap S before turns; use Shift for nitrous on straights'],
|
| 23 |
+
drag: ['Manual gears: press K to upshift when the RPM needle reaches green (L downshifts)', 'Hold W during the countdown to keep RPM in the green launch zone', 'Use A / D to change lanes and avoid traffic. Staying in the red zone blows the engine; a high-speed crash totals the car'],
|
| 24 |
+
speedtrap: ['Your speed is added at each checkpoint; beat the rival’s total to win', 'Use nitrous (Shift) 2–3 seconds before a speed checkpoint'],
|
| 25 |
+
knockout: ['The last-place driver is eliminated each lap; stay ahead', 'J toggles slow motion for stronger grip; use it before entering a turn'],
|
| 26 |
+
pursuit: ['Build the required bounty while police can see you, then lose them', 'The escape meter starts filling after seven seconds out of sight; nearby cops can bust you at low speed', 'Drive through orange pursuit breakers to crush nearby police cars'],
|
| 27 |
+
street_champion: ['Reach the final leg’s finish before your rival', 'Avoid arrest too: keep moving and never stop beside police cars'],
|
| 28 |
+
};
|
| 29 |
+
const TIP = {
|
| 30 |
+
'drag|gap': 'Drag races use manual gears: press K when RPM enters green. Holding only W leaves you in first gear.',
|
| 31 |
+
'drag|blown': 'Staying in the red zone overheats and blows the engine. Upshift with K promptly or release W briefly.',
|
| 32 |
+
'drag|totaled': 'A high-speed collision totals the car. Change lanes with A / D before reaching traffic.',
|
| 33 |
+
'tollbooth|time': 'Ease off the throttle before turns and use nitrous (Shift) on straights. Hitting walls wastes the most time.',
|
| 34 |
+
'speedtrap|score': 'Save nitrous for speed checkpoints and cross each one as fast as possible.',
|
| 35 |
+
'knockout|knocked': 'Press J before a turn for slow motion, better grip, and easier passing.',
|
| 36 |
+
'pursuit|busted': 'The bust meter rises only when police are close and you are moving slowly. Keep moving and use orange pursuit breakers.',
|
| 37 |
+
'street_champion|busted': 'The bust meter rises only when police are close and you are moving slowly. Keep your speed up.',
|
| 38 |
+
'street_champion|gap': 'Your rival uses nitrous. Hold Shift on straights and take the inside line through turns.',
|
| 39 |
+
};
|
| 40 |
+
const LOSS = { time: 'Time expired', gap: 'Rival reached the finish first', blown: 'Engine blown', totaled: 'Crash wreck', busted: 'Busted', knocked: 'Eliminated in last place', score: 'Lost on total score' };
|
| 41 |
+
const nameOf = id => (M.cases.find(c => c.id === id) || { name: id }).name;
|
| 42 |
+
const running = () => $('#pause').textContent === 'Pause';
|
| 43 |
+
// Replay or race: the shell keeps that in a closure. Its status line says which one started (a replay: 'Replay verified…';
|
| 44 |
+
// a race or the demo: 'Recording this match…' / 'Scripted demo running…'), so a flag follows only those two kinds of message; anything else the
|
| 45 |
+
// status shows later (an export, an error) leaves it alone. After a replay the shell does not restart on Enter / R or on a
|
| 46 |
+
// click, so neither does the panel. (2026-11-08: reading the status text directly broke after an export rewrote it.)
|
| 47 |
+
let inReplay = false;
|
| 48 |
+
new MutationObserver(() => { const t = $('#status').textContent; if (/^Replay verified/.test(t)) inReplay = true; else if (/^(Recording this match|Scripted demo running)/.test(t)) inReplay = false; })
|
| 49 |
+
.observe($('#status'), { childList: true, characterData: true, subtree: true });
|
| 50 |
+
const replayMode = () => inReplay;
|
| 51 |
+
// A different event picked in the list after a result or while paused: the panel offers that event, not the old race.
|
| 52 |
+
const state = () => !game ? 'idle' : running() ? 'run' : $('#case').value !== game.id ? 'idle' : game.outcome ? 'result' : game.t > 0 ? 'paused' : 'idle';
|
| 53 |
+
const again = () => $('#start').click();
|
| 54 |
+
const resume = () => $('#pause').click();
|
| 55 |
+
function next() { const s = $('#case'); s.selectedIndex = (s.selectedIndex + 1) % s.options.length; s.dispatchEvent(new Event('change')); again(); }
|
| 56 |
+
const esc = s => String(s).replace(/[&<>]/g, ch => ({ '&': '&', '<': '<', '>': '>' })[ch]);
|
| 57 |
+
|
| 58 |
+
// ---- renderer failure (WebGL context lost). The shell catches a throw from M.draw and pauses the race with the reason in the
|
| 59 |
+
// status bar; the old scene, though, keeps its dead context and would fail on every frame. Here the scene is closed so the
|
| 60 |
+
// next draw builds a new one with a new context, at most once a second, and the error is passed on to the shell. ----
|
| 61 |
+
const draw0 = M.draw;
|
| 62 |
+
let lastT = -1;
|
| 63 |
+
M.draw = function (g, ctx) {
|
| 64 |
+
const advanced = g === game && g.t !== lastT; // the race ran since the last picture of this game
|
| 65 |
+
game = g; lastT = g.t;
|
| 66 |
+
if (broken && performance.now() < retryAt) {
|
| 67 |
+
paintBroken(ctx);
|
| 68 |
+
// Resumed before the new scene is up: pause again through the shell's own lost-focus path (it pauses only a running race).
|
| 69 |
+
if (advanced) { window.dispatchEvent(new Event('blur')); $('#status').textContent = 'Rebuilding 3D scene. Please wait before resuming.'; }
|
| 70 |
+
return;
|
| 71 |
+
}
|
| 72 |
+
try {
|
| 73 |
+
draw0.call(this, g, ctx);
|
| 74 |
+
if (broken) { broken = null; shown = ''; $('#status').textContent = '3D scene restored. Press Enter or click Resume to continue.'; }
|
| 75 |
+
} catch (e) {
|
| 76 |
+
broken = String(e && e.message || e).slice(0, 120); retryAt = performance.now() + 1000; shown = '';
|
| 77 |
+
try { M.closeRenderer(ctx); } catch (_) { /* a lost context cannot be cleaned further */ }
|
| 78 |
+
paintBroken(ctx);
|
| 79 |
+
throw e; // the shell's frame loop catches it: it pauses the race and shows the reason
|
| 80 |
+
}
|
| 81 |
+
};
|
| 82 |
+
function paintBroken(ctx) {
|
| 83 |
+
ctx.fillStyle = '#0b1016'; ctx.fillRect(0, 0, 854, 480); ctx.fillStyle = '#ffd08a'; ctx.font = 'bold 20px "Microsoft YaHei",sans-serif'; ctx.textAlign = 'center';
|
| 84 |
+
ctx.fillText('Screen error. Rebuilding 3D scene…', 427, 220); ctx.font = '13px Consolas,monospace'; ctx.fillStyle = '#a8b4c0'; ctx.fillText(broken || '', 427, 250); ctx.textAlign = 'left';
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
function render(st) {
|
| 88 |
+
const k = st === 'idle' ? ($('#case').value || '').split('/')[1] : game.key, title = st === 'idle' ? nameOf($('#case').value) : nameOf(game.id);
|
| 89 |
+
const hints = (HINT[k] || []).map(h => `<li>${esc(h)}</li>`).join(''), base = '<li>W accelerate · S brake / reverse · A / D steer · Space handbrake · Shift nitrous · J slow motion · R reset</li>';
|
| 90 |
+
let html = '';
|
| 91 |
+
if (st === 'idle') html = `<h2>${esc(title)}</h2><ul>${hints}${base}</ul><div class="row"><button data-act="again" class="primary">Start race (Enter)</button></div><p class="small">You can also click the screen to start</p>`;
|
| 92 |
+
else if (st === 'paused') html = `<h2>${broken ? 'Screen error; paused' : 'Paused'}</h2>${broken ? '<p class="tip">The 3D scene is rebuilding. When the picture returns, press Enter or click Resume.</p>' : ''}<ul>${hints}${base}</ul><div class="row"><button data-act="resume" class="primary">Resume (Enter)</button><button data-act="again">Restart this event</button></div>`;
|
| 93 |
+
else if (st === 'result' && replayMode()) {
|
| 94 |
+
html = `<h2>Replay Finished</h2><p>${esc(title)} · ${(game.t / M.hz).toFixed(2)} seconds · Result: ${esc(game.outcome)}</p><div class="row"><button data-act="again" class="primary">Play this event</button><button data-act="next">Next event (N)</button></div>`;
|
| 95 |
+
} else if (st === 'result') {
|
| 96 |
+
const win = game.outcome === 'win', why = game.lossReason, tip = !win && TIP[k + '|' + why];
|
| 97 |
+
html = `<h2 class="${win ? 'win' : 'loss'}">${win ? 'Challenge complete' : game.outcome === 'timeout' ? 'Time up' : esc(LOSS[why] || 'Challenge Failed')}</h2><p>${esc(title)} · ${(game.t / M.hz).toFixed(2)} seconds</p>${tip ? `<p class="tip">Tip: ${esc(tip)}</p>` : ''}<div class="row"><button data-act="again" class="primary">Try again (Enter / R)</button><button data-act="next">Next event (N)</button></div><p class="small">You can also click anywhere on the screen to retry</p>`;
|
| 98 |
+
}
|
| 99 |
+
panel.querySelector('.nfs-card').innerHTML = html;
|
| 100 |
+
}
|
| 101 |
+
function tick() {
|
| 102 |
+
const st = state();
|
| 103 |
+
if (st === 'result' && !resultAt) resultAt = performance.now();
|
| 104 |
+
if (st !== 'result') resultAt = 0;
|
| 105 |
+
const tag = [st, $('#case').value, game && game.id, game && game.outcome, game && game.lossReason, !!broken, replayMode()].join('|');
|
| 106 |
+
if (tag !== shown) { shown = tag; panel.hidden = st === 'run'; if (st !== 'run') render(st); }
|
| 107 |
+
requestAnimationFrame(tick);
|
| 108 |
+
}
|
| 109 |
+
panel.addEventListener('click', e => {
|
| 110 |
+
const b = e.target.closest('button'), st = state();
|
| 111 |
+
if (b) { const a = b.dataset.act; if (a === 'again') again(); else if (a === 'next') next(); else if (a === 'resume') resume(); return; }
|
| 112 |
+
if (e.target.closest('.nfs-card') && st !== 'result') return;
|
| 113 |
+
if (st === 'result' && (replayMode() || performance.now() - resultAt < 600)) return; // after a replay: buttons only; and never a click meant for the race
|
| 114 |
+
if (st === 'paused') resume(); else again();
|
| 115 |
+
});
|
| 116 |
+
// A game key while a button has focus (reached with Tab): the shell ignores keys on a BUTTON, so the key would be lost. Move the
|
| 117 |
+
// focus to the picture first; this capture listener runs before the shell's own key listener, which then sees the canvas.
|
| 118 |
+
// Enter and Space keep their button meaning.
|
| 119 |
+
const GAME_KEYS = new Set(['KeyW', 'KeyA', 'KeyS', 'KeyD', 'ShiftLeft', 'ShiftRight', 'KeyJ', 'KeyK', 'KeyL', 'KeyQ', 'KeyE', 'KeyR', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']);
|
| 120 |
+
window.addEventListener('keydown', e => { const a = document.activeElement; if (a && a.tagName === 'BUTTON' && GAME_KEYS.has(e.code)) canvas.focus(); }, true);
|
| 121 |
+
// Enter / R after a result are the shell's; N (next event), Enter on the idle panel and Enter on the pause panel are added here.
|
| 122 |
+
window.addEventListener('keydown', e => {
|
| 123 |
+
const tag = document.activeElement && document.activeElement.tagName;
|
| 124 |
+
if (tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA' || (tag === 'BUTTON' && (e.code === 'Enter' || e.code === 'Space')) || e.repeat) return;
|
| 125 |
+
const st = state(), enter = e.code === 'Enter' || e.code === 'NumpadEnter';
|
| 126 |
+
let act = null;
|
| 127 |
+
if (st === 'result' && e.code === 'KeyN' && performance.now() - resultAt >= 600) act = next;
|
| 128 |
+
else if (st === 'idle' && enter) act = again;
|
| 129 |
+
else if (st === 'paused' && enter) act = resume;
|
| 130 |
+
if (act) { e.preventDefault(); e.stopImmediatePropagation(); act(); }
|
| 131 |
+
}, true);
|
| 132 |
+
for (const id of ['#case', '#difficulty']) $(id).addEventListener('change', () => { shown = ''; canvas.focus(); });
|
| 133 |
+
$('#seed').addEventListener('change', () => { shown = ''; }); // typing a seed: keep the focus in the box
|
| 134 |
+
requestAnimationFrame(tick);
|
| 135 |
+
})();
|
environments/games/web/games/nfsmw_remake/renderer3d.js
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* NFS Most Wanted events - WebGL renderer (three.js r160, vendored): third-person chase view of an original procedural city.
|
| 2 |
+
Everything is built from code at start-up: road ribbons from the route samples, barriers along the real collision edge of
|
| 3 |
+
the road union (what you see is what you hit), instanced buildings, palms, lamps, and original low-poly cars. A render is a
|
| 4 |
+
pure function of the game state; the only local randomness is a fixed-seed generator for scenery. No original game art.
|
| 5 |
+
2026-11-08: police light bars on every live cop (roadblocks flash too), blinking barrier
|
| 6 |
+
lamps and spike-strip beacons, rival markers and rival nitrous flames, a light column over the next gate, glossy paint,
|
| 7 |
+
car head/tail light glows, street-lamp halos at night, sparks on impact, tyre smoke while sliding, camera shake on a hit,
|
| 8 |
+
the helicopter's spot on the ground. Particles are placed from the current state only (no history), so a frame is still a
|
| 9 |
+
pure function of the game state and the page, the recordings and the agent see the same picture. */
|
| 10 |
+
(function (root) {
|
| 11 |
+
'use strict';
|
| 12 |
+
const T = root.THREE, M = root.NfsmwGame, C = M && M.C;
|
| 13 |
+
if (!T || !M) return;
|
| 14 |
+
const R3 = M.R3 = {}, byCanvas = new WeakMap();
|
| 15 |
+
const STYLE = { // sky top, sky mid, horizon, sun colour, sun [azimuth, elevation], hemisphere sky/ground/intensity, sun intensity, fog, window glow, lamp glow
|
| 16 |
+
tollbooth: { sky: ['#2a4f8c', '#e8926a', '#ffd9a0'], sun: 0xffc48a, dir: [-0.75, 0.18], hemi: [0xffe2c4, 0x51402f, 1.25], sunI: 2.6, fog: [0xefb48c, 240, 1300], win: 0.55, lamp: 0.5 },
|
| 17 |
+
drag: { sky: ['#2f74c8', '#8fc3ea', '#e6f1f2'], sun: 0xfff4e0, dir: [0.4, 0.7], hemi: [0xdcebff, 0x8a8066, 1.5], sunI: 2.5, fog: [0xd6e6ee, 500, 2400], win: 0, lamp: 0 },
|
| 18 |
+
speedtrap: { sky: ['#3c6fb4', '#a7c6dc', '#f4e6cf'], sun: 0xffedd0, dir: [0.7, 0.42], hemi: [0xe7eeff, 0x6f6a52, 1.4], sunI: 2.5, fog: [0xdfe2d8, 320, 1600], win: 0.05, lamp: 0 },
|
| 19 |
+
knockout: { sky: ['#070b1e', '#17204a', '#5a3b66'], sun: 0x9fb4ff, dir: [0.3, 0.6], hemi: [0x5f6fa8, 0x201a26, 1.15], sunI: 0.75, fog: [0x2a2542, 90, 620], win: 1.5, lamp: 1.5 },
|
| 20 |
+
pursuit: { sky: ['#141a44', '#7a3f73', '#ff9a62'], sun: 0xff9d73, dir: [-0.6, 0.08], hemi: [0xb09ac8, 0x2b2430, 1.15], sunI: 1.5, fog: [0x8a5a70, 170, 950], win: 1.15, lamp: 1.2 },
|
| 21 |
+
street_champion: { sky: ['#222a3e', '#6e7a8c', '#d9cdb4'], sun: 0xffe2bc, dir: [0.8, 0.22], hemi: [0xc6d0dc, 0x4c4a44, 1.3], sunI: 1.6, fog: [0xaeb0ac, 170, 1000], win: 0.5, lamp: 0.6 },
|
| 22 |
+
};
|
| 23 |
+
const rngOf = seed => () => { seed = (seed + 0x6D2B79F5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
|
| 24 |
+
const canvasTex = (w, h, paint, repeat, srgb = true) => { const c = document.createElement('canvas'); c.width = w; c.height = h; paint(c.getContext('2d'), w, h); const t = new T.CanvasTexture(c); if (repeat) t.wrapS = t.wrapT = T.RepeatWrapping; t.anisotropy = 4; if (srgb) t.colorSpace = T.SRGBColorSpace; return t; };
|
| 25 |
+
const qv = (x, y, z, v) => (v || new T.Vector3()).set(x, z, -y); // sim (x, y, up) -> three (x, up, -y); heading h is rotation.y
|
| 26 |
+
const speckle = (q, w, h, n, a, seed) => { const r = rngOf(seed); for (let i = 0; i < n; i++) { const v = r() < 0.5 ? 255 : 0; q.fillStyle = `rgba(${v},${v},${v},${a * r()})`; q.fillRect(r() * w, r() * h, 1 + r() * 2, 1 + r() * 2); } };
|
| 27 |
+
// Non-indexed merge with per-part vertex colours: every car is one draw call.
|
| 28 |
+
function merge(parts) {
|
| 29 |
+
let n = 0; const list = parts.map(([g, col]) => { const q = g.index ? g.toNonIndexed() : g; n += q.attributes.position.count; return [q, new T.Color(col)]; });
|
| 30 |
+
const pos = new Float32Array(n * 3), nor = new Float32Array(n * 3), colr = new Float32Array(n * 3); let o = 0;
|
| 31 |
+
for (const [q, c] of list) { const m = q.attributes.position.count; pos.set(q.attributes.position.array, o * 3); nor.set(q.attributes.normal.array, o * 3); for (let i = 0; i < m; i++) { colr[(o + i) * 3] = c.r; colr[(o + i) * 3 + 1] = c.g; colr[(o + i) * 3 + 2] = c.b; } o += m; }
|
| 32 |
+
const g = new T.BufferGeometry(); g.setAttribute('position', new T.BufferAttribute(pos, 3)); g.setAttribute('normal', new T.BufferAttribute(nor, 3)); g.setAttribute('color', new T.BufferAttribute(colr, 3)); return g;
|
| 33 |
+
}
|
| 34 |
+
const moved = (g, x, y, z, rx = 0, ry = 0, rz = 0) => { const q = g.clone(); if (rx || ry || rz) q.rotateX(rx).rotateY(ry).rotateZ(rz); q.translate(x, y, z); q.computeVertexNormals(); return q; };
|
| 35 |
+
const boxG = (x, y, z, w, h, d) => moved(new T.BoxGeometry(w, h, d), x, y, z);
|
| 36 |
+
// Side profile extruded across the car; +X is forward. L = length, W = width. `pts` run around the silhouette.
|
| 37 |
+
const profile = (pts, W) => { const s = new T.Shape(); pts.forEach((p, i) => i ? s.lineTo(p[0], p[1]) : s.moveTo(p[0], p[1])); const g = new T.ExtrudeGeometry(s, { depth: W, bevelEnabled: false, curveSegments: 1 }); g.translate(0, 0, -W / 2); g.computeVertexNormals(); return g; };
|
| 38 |
+
const CAR_SHAPES = {
|
| 39 |
+
// Original wedge coupe, fastback sedan, tall van, police interceptor: silhouettes drawn for this project, no real vehicle.
|
| 40 |
+
coupe: { w: 1.86, body: [[-2.2, 0.34], [2.25, 0.3], [2.3, 0.56], [1.05, 0.82], [-1.9, 0.92], [-2.25, 0.86]], glass: [[0.82, 0.8], [0.05, 1.2], [-0.95, 1.2], [-1.75, 0.9]], wing: true },
|
| 41 |
+
sedan: { w: 1.82, body: [[-2.3, 0.34], [2.25, 0.34], [2.3, 0.68], [1.0, 0.9], [-1.9, 0.96], [-2.32, 0.9]], glass: [[0.92, 0.88], [0.2, 1.38], [-1.2, 1.38], [-1.85, 0.94]] },
|
| 42 |
+
van: { w: 1.95, body: [[-2.5, 0.38], [2.4, 0.38], [2.45, 0.9], [1.75, 1.08], [1.35, 1.9], [-2.5, 2.0]], glass: [[1.74, 1.06], [1.36, 1.72], [0.4, 1.76], [0.4, 1.06]] },
|
| 43 |
+
cop: { w: 1.88, body: [[-2.35, 0.34], [2.35, 0.32], [2.4, 0.66], [1.05, 0.9], [-1.95, 0.96], [-2.35, 0.9]], glass: [[0.9, 0.88], [0.2, 1.34], [-1.15, 1.34], [-1.88, 0.94]] },
|
| 44 |
+
};
|
| 45 |
+
function carGeometry(kind) {
|
| 46 |
+
const S = CAR_SHAPES[kind], W = S.w, parts = [[profile(S.body, W), 0xffffff], [profile(S.glass, W - 0.14), 0x1c2733]];
|
| 47 |
+
parts.push([boxG(0, 0.26, 0, 4.1, 0.14, W - 0.1), 0x15151a]);
|
| 48 |
+
for (const [x, z] of [[1.42, W / 2 - 0.12], [1.42, -W / 2 + 0.12], [-1.42, W / 2 - 0.12], [-1.42, -W / 2 + 0.12]]) { parts.push([moved(new T.CylinderGeometry(0.36, 0.36, 0.26, 12), x, 0.36, z, Math.PI / 2), 0x121215]); parts.push([moved(new T.CylinderGeometry(0.2, 0.2, 0.27, 8), x, 0.36, z, Math.PI / 2), 0xb9bdc4]); }
|
| 49 |
+
if (S.wing) { parts.push([boxG(-2.05, 1.14, 0, 0.42, 0.05, W - 0.1), 0xffffff]); parts.push([boxG(-2.05, 1.0, 0.62, 0.2, 0.26, 0.06), 0x24242a], [boxG(-2.05, 1.0, -0.62, 0.2, 0.26, 0.06), 0x24242a]); }
|
| 50 |
+
if (kind === 'cop') { parts.push([boxG(0.1, 0.66, W / 2 + 0.002, 1.7, 0.42, 0.01), 0xf4f4f4], [boxG(0.1, 0.66, -W / 2 - 0.002, 1.7, 0.42, 0.01), 0xf4f4f4]); parts.push([boxG(-0.45, 1.42, 0, 0.3, 0.1, 1.2), 0x22232a]); parts.push([boxG(2.42, 0.42, 0, 0.12, 0.34, W * 0.7), 0x18181c]); }
|
| 51 |
+
// 2026-11-08 details: side mirrors, a dark lower body line, front splitter, twin exhaust tips, number plate recess (original shapes)
|
| 52 |
+
if (kind !== 'van') {
|
| 53 |
+
const tip = new T.CylinderGeometry(0.07, 0.07, 0.16, 8);
|
| 54 |
+
parts.push([boxG(0.62, 0.86, W / 2 + 0.08, 0.16, 0.1, 0.16), 0x15151a], [boxG(0.62, 0.86, -W / 2 - 0.08, 0.16, 0.1, 0.16), 0x15151a]);
|
| 55 |
+
parts.push([boxG(0, 0.37, W / 2 - 0.02, 3.4, 0.1, 0.06), 0x202024], [boxG(0, 0.37, -W / 2 + 0.02, 3.4, 0.1, 0.06), 0x202024]);
|
| 56 |
+
parts.push([boxG(2.26, 0.3, 0, 0.18, 0.05, W - 0.2), 0x121214]);
|
| 57 |
+
parts.push([moved(tip, -2.3, 0.36, 0.42, 0, 0, Math.PI / 2), 0xc8ccd2], [moved(tip, -2.3, 0.36, -0.42, 0, 0, Math.PI / 2), 0xc8ccd2]);
|
| 58 |
+
parts.push([boxG(-2.26, 0.56, 0, 0.03, 0.14, 0.5), 0xe8e8e0]);
|
| 59 |
+
}
|
| 60 |
+
return merge(parts);
|
| 61 |
+
}
|
| 62 |
+
function lampGeometry(kind) {
|
| 63 |
+
const W = CAR_SHAPES[kind].w, x = kind === 'van' ? 2.42 : 2.3, y = kind === 'van' ? 0.72 : 0.5, b = kind === 'van' ? -2.52 : -2.3, by = kind === 'van' ? 0.95 : 0.74;
|
| 64 |
+
return merge([[boxG(x, y, W * 0.34, 0.06, 0.13, 0.4), 0xfff4d0], [boxG(x, y, -W * 0.34, 0.06, 0.13, 0.4), 0xfff4d0], [boxG(b, by, W * 0.32, 0.06, 0.12, 0.5), 0xff2614], [boxG(b, by, -W * 0.32, 0.06, 0.12, 0.5), 0xff2614]]);
|
| 65 |
+
}
|
| 66 |
+
const PAINT = [0x2c6fd1, 0xc33a2c, 0xd9d9d6, 0x1f2024, 0x4c8c5a, 0xd9a73a];
|
| 67 |
+
class Scene {
|
| 68 |
+
constructor(canvas) {
|
| 69 |
+
this.canvas = canvas; this.res = []; this.times = []; this.ready = false; this.error = null; this.closed = false; this.pools = {}; this.skies = {};
|
| 70 |
+
this.view = document.createElement('canvas'); this.view.width = 854; this.view.height = 480;
|
| 71 |
+
const r = this.renderer = new T.WebGLRenderer({ canvas: this.view, antialias: true, preserveDrawingBuffer: true, powerPreference: 'low-power' });
|
| 72 |
+
r.setPixelRatio(1); r.setSize(854, 480, false); r.outputColorSpace = T.SRGBColorSpace; r.toneMapping = T.ACESFilmicToneMapping; r.toneMappingExposure = 1.0;
|
| 73 |
+
this.view.addEventListener('webglcontextlost', e => { e.preventDefault(); this.ready = false; this.error = 'WebGL context lost'; });
|
| 74 |
+
this.world = new T.Scene(); this.world.fog = new T.Fog(0xffffff, 200, 1200);
|
| 75 |
+
this.camera = new T.PerspectiveCamera(58, 854 / 480, 0.5, 3200);
|
| 76 |
+
// Rear-view mirror: a second camera on the roof looking back, drawn into a strip at the top centre of the same frame.
|
| 77 |
+
// Shown only where something can come from behind (police events, rivals); MIRROR is that strip in canvas pixels.
|
| 78 |
+
this.mirrorCam = new T.PerspectiveCamera(50, 260 / 62, 0.5, 3200); this.mirrorRect = [297, 64, 557, 126]; this.mirrorOn = false;
|
| 79 |
+
this.hemi = new T.HemisphereLight(0xffffff, 0x444444, 1); this.world.add(this.hemi);
|
| 80 |
+
this.sun = new T.DirectionalLight(0xffffff, 2); this.world.add(this.sun);
|
| 81 |
+
this.buildSky(); this.buildGround(); this.buildRoads(); this.buildCity(); this.buildCars(); this.buildProps(); this.buildFx(); this.buildChevrons();
|
| 82 |
+
}
|
| 83 |
+
keep(x) { this.res.push(x); return x; }
|
| 84 |
+
lam(o) { return this.keep(new T.MeshLambertMaterial(o)); }
|
| 85 |
+
paint(color) { return this.keep(new T.MeshPhongMaterial({ color, vertexColors: true, shininess: 60, specular: 0x4a4a4a })); }
|
| 86 |
+
basic(o) { return this.keep(new T.MeshBasicMaterial(o)); }
|
| 87 |
+
buildSky() { this.sky = new T.Mesh(this.keep(new T.SphereGeometry(2600, 20, 12)), this.basic({ side: T.BackSide, fog: false, depthWrite: false })); this.sky.renderOrder = -10; this.world.add(this.sky); }
|
| 88 |
+
skyTex(key) {
|
| 89 |
+
if (this.skies[key]) return this.skies[key];
|
| 90 |
+
const st = STYLE[key], t = canvasTex(1024, 512, (q, w, h) => {
|
| 91 |
+
const g = q.createLinearGradient(0, 0, 0, h / 2); g.addColorStop(0, st.sky[0]); g.addColorStop(0.72, st.sky[1]); g.addColorStop(1, st.sky[2]); q.fillStyle = g; q.fillRect(0, 0, w, h);
|
| 92 |
+
const sx = ((Math.atan2(st.dir[0], Math.sqrt(1 - st.dir[0] * st.dir[0])) / (2 * Math.PI) + 1.0) % 1) * w, sy = h / 2 - st.dir[1] * h * 0.5, c = new T.Color(st.sun).getStyle();
|
| 93 |
+
for (const ox of [-w, 0, w]) { const glow = q.createRadialGradient(sx + ox, sy, 2, sx + ox, sy, 170); glow.addColorStop(0, 'rgba(255,250,235,.95)'); glow.addColorStop(0.08, c.replace('rgb', 'rgba').replace(')', ',.65)')); glow.addColorStop(1, 'rgba(255,200,150,0)'); q.fillStyle = glow; q.fillRect(0, 0, w, h / 2); }
|
| 94 |
+
const rr = rngOf(key.length * 977 + 5); const nightly = st.win > 1;
|
| 95 |
+
if (nightly) for (let i = 0; i < 260; i++) { q.fillStyle = `rgba(255,255,255,${0.2 + rr() * 0.7})`; q.fillRect(rr() * w, rr() * h * 0.36, 1, 1); }
|
| 96 |
+
for (let i = 0; i < 44; i++) { const cx = rr() * w, cy = h * (0.2 + rr() * 0.26), cw = 40 + rr() * 150; q.fillStyle = nightly ? 'rgba(120,110,160,.08)' : 'rgba(255,240,226,.14)'; for (let j = 0; j < 7; j++) { q.beginPath(); q.ellipse(cx + (rr() - 0.5) * cw, cy + (rr() - 0.5) * 7, cw * (0.2 + rr() * 0.3), 3 + rr() * 6, 0, 0, 7); q.fill(); } }
|
| 97 |
+
for (const [base, amp, col] of [[0.5, 26, st.sky[1]], [0.502, 14, st.sky[0]]]) { q.fillStyle = col; q.globalAlpha = 0.55; q.beginPath(); q.moveTo(0, h); for (let x = 0; x <= w; x += 6) q.lineTo(x, h * base - amp * (0.55 + 0.45 * Math.sin(x * 0.012 + base * 40) * Math.sin(x * 0.031))); q.lineTo(w, h); q.fill(); q.globalAlpha = 1; }
|
| 98 |
+
q.fillStyle = st.sky[2]; q.fillRect(0, h / 2, w, h / 2);
|
| 99 |
+
});
|
| 100 |
+
return (this.skies[key] = this.keep(t));
|
| 101 |
+
}
|
| 102 |
+
buildGround() {
|
| 103 |
+
const grass = this.keep(canvasTex(256, 256, (q, w, h) => { q.fillStyle = '#6d7a52'; q.fillRect(0, 0, w, h); speckle(q, w, h, 3200, 0.16, 7); for (let i = 0; i < 12; i++) { q.fillStyle = 'rgba(120,108,70,.1)'; q.beginPath(); q.arc(i * 37 % w, i * 91 % h, 20 + i * 2, 0, 7); q.fill(); } }, true)); grass.repeat.set(70, 40);
|
| 104 |
+
const land = new T.Mesh(this.keep(new T.PlaneGeometry(3600, 1650)), this.lam({ map: grass })); land.rotation.x = -Math.PI / 2; qv(0, 280, -0.06, land.position); this.world.add(land);
|
| 105 |
+
const sand = new T.Mesh(this.keep(new T.PlaneGeometry(3600, 26)), this.lam({ color: 0xd8c394 })); sand.rotation.x = -Math.PI / 2; qv(0, -558, -0.05, sand.position); this.world.add(sand);
|
| 106 |
+
this.seaTex = this.keep(canvasTex(256, 256, (q, w, h) => { q.fillStyle = '#2d6f8f'; q.fillRect(0, 0, w, h); const r = rngOf(9); for (let i = 0; i < 240; i++) { q.fillStyle = `rgba(190,232,240,${0.04 + r() * 0.1})`; q.fillRect(r() * w, r() * h, 8 + r() * 34, 1); } }, true)); this.seaTex.repeat.set(26, 8);
|
| 107 |
+
const sea = new T.Mesh(this.keep(new T.PlaneGeometry(4400, 1700)), this.lam({ map: this.seaTex })); sea.rotation.x = -Math.PI / 2; qv(0, -1410, -1.4, sea.position); this.world.add(sea);
|
| 108 |
+
}
|
| 109 |
+
// A ribbon following samples [x, y]; `sides` gives the half width. v runs along the road in metres / tile length.
|
| 110 |
+
ribbon(pts, hw, closed, z, tile) {
|
| 111 |
+
const n = pts.length, N = closed ? n + 1 : n, pos = new Float32Array(N * 6), nor = new Float32Array(N * 6), uv = new Float32Array(N * 4), idx = []; let along = 0;
|
| 112 |
+
for (let i = 0; i < N; i++) {
|
| 113 |
+
const p = pts[i % n], a = pts[(i - 1 + n) % n], b = pts[(i + 1) % n], f = !closed && i === 0 ? p : a, t = !closed && i === n - 1 ? p : b, dx = t[0] - f[0], dy = t[1] - f[1], l = Math.hypot(dx, dy) || 1, nx = -dy / l, ny = dx / l;
|
| 114 |
+
if (i) along += Math.hypot(p[0] - pts[(i - 1) % n][0], p[1] - pts[(i - 1) % n][1]);
|
| 115 |
+
pos.set([p[0] + nx * hw, z, -(p[1] + ny * hw), p[0] - nx * hw, z, -(p[1] - ny * hw)], i * 6); nor.set([0, 1, 0, 0, 1, 0], i * 6); uv.set([0, along / tile, 1, along / tile], i * 4);
|
| 116 |
+
if (i < N - 1) idx.push(i * 2, i * 2 + 1, i * 2 + 2, i * 2 + 1, i * 2 + 3, i * 2 + 2);
|
| 117 |
+
}
|
| 118 |
+
const g = new T.BufferGeometry(); g.setAttribute('position', new T.BufferAttribute(pos, 3)); g.setAttribute('normal', new T.BufferAttribute(nor, 3)); g.setAttribute('uv', new T.BufferAttribute(uv, 2)); g.setIndex(idx); return this.keep(g);
|
| 119 |
+
}
|
| 120 |
+
buildRoads() {
|
| 121 |
+
const asphalt = (lanes, edge, yellow = true) => this.keep(canvasTex(256, 512, (q, w, h) => {
|
| 122 |
+
q.fillStyle = '#34363b'; q.fillRect(0, 0, w, h); speckle(q, w, h, 5200, 0.09, lanes * 13 + 1);
|
| 123 |
+
for (let i = 0; i < 3; i++) { q.fillStyle = 'rgba(16,16,18,.18)'; q.fillRect(w * (0.2 + i * 0.3), 0, 12, h); }
|
| 124 |
+
q.fillStyle = '#d8d6cc'; q.fillRect(edge, 0, 4, h); q.fillRect(w - edge - 4, 0, 4, h);
|
| 125 |
+
if (yellow) { q.fillStyle = '#d6a32e'; q.fillRect(w / 2 - 5, 0, 3, h); q.fillRect(w / 2 + 2, 0, 3, h); } else { q.fillStyle = '#d8d6cc'; for (let y = 0; y < h; y += 256) q.fillRect(w / 2 - 2, y, 4, 128); }
|
| 126 |
+
q.fillStyle = '#d8d6cc'; for (let k = 1; k < lanes; k++) { const u = (w / 2) * k / lanes; for (let y = 0; y < h; y += 256) { q.fillRect(w / 2 + u - 2, y, 4, 128); q.fillRect(w / 2 - u - 2, y, 4, 128); } }
|
| 127 |
+
}, true));
|
| 128 |
+
const walkTex = this.keep(canvasTex(64, 64, (q, w, h) => { q.fillStyle = '#9d9a90'; q.fillRect(0, 0, w, h); speckle(q, w, h, 300, 0.1, 3); q.fillStyle = 'rgba(40,40,40,.28)'; q.fillRect(0, 0, w, 1); }, true));
|
| 129 |
+
const walkMat = this.lam({ map: walkTex }), wallTex = this.keep(canvasTex(128, 32, (q, w, h) => { q.fillStyle = '#b7b4aa'; q.fillRect(0, 0, w, h); speckle(q, w, h, 300, 0.1, 21); q.fillStyle = 'rgba(30,30,32,.55)'; q.fillRect(0, h - 5, w, 5); for (let i = 0; i < 8; i++) { q.fillStyle = i % 2 ? '#c8452c' : '#e8e4da'; q.fillRect(i * 16, 2, 16, 6); } }, true));
|
| 130 |
+
const wallMat = this.lam({ map: wallTex }), wallPos = [], wallUv = [], wallIdx = [];
|
| 131 |
+
const wall = (ax, ay, bx, by, len) => { const n = wallPos.length / 3, h = 1.05, low = -1.5; wallPos.push(ax, low, -ay, bx, low, -by, bx, h, -by, ax, h, -ay); wallUv.push(0, 0, len / 8, 0, len / 8, 1, 0, 1); wallIdx.push(n, n + 1, n + 2, n, n + 2, n + 3, n, n + 2, n + 1, n, n + 3, n + 2); };
|
| 132 |
+
const edge = (pts, hw, closed) => {
|
| 133 |
+
for (let i = 0; i + (closed ? 0 : 1) < pts.length; i++) {
|
| 134 |
+
const p = pts[i], q = pts[(i + 1) % pts.length], dx = q[0] - p[0], dy = q[1] - p[1], l = Math.hypot(dx, dy) || 1, nx = -dy / l, ny = dx / l, mx = (p[0] + q[0]) / 2, my = (p[1] + q[1]) / 2;
|
| 135 |
+
for (const sgn of [1, -1]) if (C.road(mx + sgn * nx * (hw + 0.45), my + sgn * ny * (hw + 0.45)).d > 0.1) wall(p[0] + sgn * nx * hw, p[1] + sgn * ny * hw, q[0] + sgn * nx * hw, q[1] + sgn * ny * hw, l);
|
| 136 |
+
}
|
| 137 |
+
};
|
| 138 |
+
for (const R of Object.values(C.routes)) {
|
| 139 |
+
const step = R.name === 'strip' ? 50 : 3, pts = []; for (let i = 0; i < R.n; i += step) pts.push([R.x[i], R.y[i]]); if (!R.loop) pts.push([R.x[R.n - 1], R.y[R.n - 1]]);
|
| 140 |
+
const tile = R.name === 'strip' ? 24 : 16, mesh = new T.Mesh(this.ribbon(pts, R.halfW, R.loop, R.name === 'downtown' ? 0.024 : 0.02, tile), this.lam({ map: asphalt(2, 9, R.name !== 'strip') })); this.world.add(mesh);
|
| 141 |
+
if (R.name !== 'strip') { const w = new T.Mesh(this.ribbon(pts, R.halfW + 4.5, R.loop, 0.006, 4), walkMat); this.world.add(w); }
|
| 142 |
+
edge(pts, R.halfW, R.loop);
|
| 143 |
+
}
|
| 144 |
+
const stMat = this.lam({ map: asphalt(1, 7) });
|
| 145 |
+
for (const st of C.streets) {
|
| 146 |
+
const pts = []; for (let i = 0; i + 1 < st.length; i++) { const a = st[i], b = st[i + 1], L = Math.hypot(b[0] - a[0], b[1] - a[1]), m = Math.ceil(L / 6); for (let j = 0; j < m; j++) pts.push([a[0] + (b[0] - a[0]) * j / m, a[1] + (b[1] - a[1]) * j / m]); } pts.push(st[st.length - 1]);
|
| 147 |
+
this.world.add(new T.Mesh(this.ribbon(pts, C.streetW / 2, false, 0.012, 16), stMat)); this.world.add(new T.Mesh(this.ribbon(pts, C.streetW / 2 + 4, false, 0.004, 4), walkMat)); edge(pts, C.streetW / 2, false);
|
| 148 |
+
}
|
| 149 |
+
const g = new T.BufferGeometry(); g.setAttribute('position', new T.BufferAttribute(new Float32Array(wallPos), 3)); g.setAttribute('uv', new T.BufferAttribute(new Float32Array(wallUv), 2)); g.setIndex(wallIdx); g.computeVertexNormals(); this.keep(g); this.world.add(new T.Mesh(g, wallMat));
|
| 150 |
+
}
|
| 151 |
+
buildCity() {
|
| 152 |
+
const r = rngOf(20051116), towers = { low: [], mid: [], tall: [] }, palms = [], lamps = [];
|
| 153 |
+
const facade = (cols, rows, lit, base) => { const paint = emit => (q, w, h) => { const rr = rngOf(cols * 31 + rows); q.fillStyle = emit ? '#000' : base; q.fillRect(0, 0, w, h); const cw = w / cols, ch = h / rows; for (let j = 0; j < rows; j++) for (let i = 0; i < cols; i++) { const on = rr() < lit; q.fillStyle = emit ? (on ? (rr() < 0.3 ? '#a8d8ff' : '#ffd48a') : '#000') : (on ? '#5a6878' : '#2c3644'); q.fillRect(i * cw + cw * 0.18, j * ch + ch * 0.2, cw * 0.64, ch * 0.6); } if (!emit) { q.fillStyle = '#3a3a3e'; q.fillRect(w - 8, 0, 8, 8); } else { q.fillStyle = '#000'; q.fillRect(w - 8, 0, 8, 8); } }; return this.lam({ map: this.keep(canvasTex(256, 256, paint(false))), emissive: 0xffffff, emissiveMap: this.keep(canvasTex(256, 256, paint(true))), emissiveIntensity: 1 }); };
|
| 154 |
+
const X = C.bounds.X0, Y = C.bounds.Y0;
|
| 155 |
+
for (let y = -500; y < 960; y += 34) for (let x = -1320; x < 1320; x += 34) {
|
| 156 |
+
const px = x + (r() - 0.5) * 12, py = y + (r() - 0.5) * 12, w = 16 + r() * 16, d = 16 + r() * 16, gap = C.road(px, py).d - Math.hypot(w, d) / 2 - 4.5; if (gap < 0) continue;
|
| 157 |
+
if (C.road(px, py).d > 150) continue;
|
| 158 |
+
const down = Math.max(0, 1 - Math.hypot(px, py) / 480), h = 7 + r() * 10 + r() * r() * 90 * down + (r() < 0.04 ? 30 : 0);
|
| 159 |
+
(h < 16 ? towers.low : h < 36 ? towers.mid : towers.tall).push([px, py, w, h, d, r()]);
|
| 160 |
+
}
|
| 161 |
+
const box = new T.BoxGeometry(1, 1, 1); box.translate(0, 0.5, 0); const uv = box.attributes.uv; for (const i of [8, 9, 10, 11, 12, 13, 14, 15]) uv.setXY(i, 0.995, 0.995); this.keep(box);
|
| 162 |
+
this.mats = { win: [] }; const mk = (list, mat) => { const m = new T.InstancedMesh(box, mat, list.length), o = new T.Object3D(), c = new T.Color(); list.forEach((b, i) => { qv(b[0], b[1], 0, o.position); o.rotation.y = 0; o.scale.set(b[2], b[3], b[4]); o.updateMatrix(); m.setMatrixAt(i, o.matrix); c.setHSL(0.07 + b[5] * 0.1, 0.12 + b[5] * 0.18, 0.46 + b[5] * 0.34); m.setColorAt(i, c); }); this.world.add(m); this.mats.win.push(mat); this.keep(m); };
|
| 163 |
+
mk(towers.low, facade(4, 3, 0.45, '#b9ad98')); mk(towers.mid, facade(6, 8, 0.4, '#a8a39a')); mk(towers.tall, facade(8, 22, 0.42, '#8f9aa8'));
|
| 164 |
+
const R = C.routes.coast;
|
| 165 |
+
for (let i = 0; i < R.n; i += 9) { const a = C.routeAt(R, i * R.ds), side = i % 18 ? 1 : -1, off = R.halfW + 2.6; const lx = a.x + a.nx * side * off, ly = a.y + a.ny * side * off; if (C.road(lx, ly).d > 0.6) (a.y < -300 || a.x > 700 ? palms : lamps).push([lx, ly, side * a.h]); }
|
| 166 |
+
for (const key of ['downtown']) { const D = C.routes[key]; for (let i = 0; i < D.n; i += 12) { const a = C.routeAt(D, i * D.ds), off = D.halfW + 2.2; for (const s of [1, -1]) { const lx = a.x + a.nx * s * off, ly = a.y + a.ny * s * off; if (C.road(lx, ly).d > 0.6) lamps.push([lx, ly, 0]); } } }
|
| 167 |
+
const inst = (geo, mat, list, sy = 1) => { const m = new T.InstancedMesh(this.keep(geo), mat, list.length), o = new T.Object3D(); list.forEach((p, i) => { qv(p[0], p[1], 0, o.position); o.rotation.y = p[2] || 0; const k = 0.85 + ((i * 7) % 5) * 0.08; o.scale.set(k, k * sy, k); o.updateMatrix(); m.setMatrixAt(i, o.matrix); }); this.world.add(this.keep(m)); return m; };
|
| 168 |
+
const trunk = new T.CylinderGeometry(0.16, 0.3, 9, 6); trunk.translate(0, 4.5, 0); inst(trunk, this.lam({ color: 0x705a40 }), palms);
|
| 169 |
+
const fronds = []; for (let k = 0; k < 7; k++) { const g = new T.ConeGeometry(0.62, 4.6, 4); g.translate(0, 2.3, 0); g.rotateZ(-1.9); g.rotateY(k * Math.PI * 2 / 7); g.translate(0, 9, 0); fronds.push(g); } inst(merge(fronds.map(g => [g, 0xffffff])), this.lam({ color: 0x4a7a3c, vertexColors: true }), palms);
|
| 170 |
+
const pole = new T.CylinderGeometry(0.07, 0.1, 7.5, 5); pole.translate(0, 3.75, 0); inst(pole, this.lam({ color: 0x45484e }), lamps);
|
| 171 |
+
const head = new T.BoxGeometry(0.5, 0.12, 0.28); head.translate(0, 7.5, 0); this.lampMat = this.basic({ color: 0xffdca0 }); inst(head, this.lampMat, lamps); this.lampSpots = lamps;
|
| 172 |
+
const haloTex = this.keep(canvasTex(64, 64, (q, w, h) => { const g = q.createRadialGradient(32, 32, 1, 32, 32, 32); g.addColorStop(0, 'rgba(255,255,255,1)'); g.addColorStop(0.4, 'rgba(255,255,255,.28)'); g.addColorStop(1, 'rgba(255,255,255,0)'); q.fillStyle = g; q.fillRect(0, 0, w, h); })); this.haloTex = haloTex;
|
| 173 |
+
}
|
| 174 |
+
buildCars() {
|
| 175 |
+
this.carGeo = {}; this.lampGeo = {}; for (const k of Object.keys(CAR_SHAPES)) { this.carGeo[k] = this.keep(carGeometry(k)); this.lampGeo[k] = this.keep(lampGeometry(k)); }
|
| 176 |
+
this.lampMatCar = this.basic({ vertexColors: true });
|
| 177 |
+
this.shadowTex = this.keep(canvasTex(64, 64, (q, w, h) => { const g = q.createRadialGradient(32, 32, 6, 32, 32, 32); g.addColorStop(0, 'rgba(0,0,0,.62)'); g.addColorStop(0.7, 'rgba(0,0,0,.38)'); g.addColorStop(1, 'rgba(0,0,0,0)'); q.fillStyle = g; q.fillRect(0, 0, w, h); }));
|
| 178 |
+
this.shadowMat = this.basic({ map: this.shadowTex, transparent: true, depthWrite: false }); this.shadowGeo = this.keep(new T.PlaneGeometry(5.6, 2.9)); this.shadowGeo.rotateX(-Math.PI / 2);
|
| 179 |
+
this.paints = PAINT.map(c => this.paint(c));
|
| 180 |
+
this.playerMat = this.paint(0xe8701f); this.rivalMat = this.paint(0xc8cdd8); this.copMat = this.paint(0x17181d);
|
| 181 |
+
// Police light bar: two lamps per cop, swapped between a lit and a dark material every 8 ticks (red and blue out of phase).
|
| 182 |
+
this.barMat = { r1: this.basic({ color: 0xff2a3a }), r0: this.basic({ color: 0x3a0c10 }), b1: this.basic({ color: 0x3a78ff }), b0: this.basic({ color: 0x0c1438 }) };
|
| 183 |
+
this.barGeo = this.keep(new T.BoxGeometry(0.34, 0.13, 0.52));
|
| 184 |
+
this.halo = col => this.keep(new T.SpriteMaterial({ map: this.haloTex, color: col, blending: T.AdditiveBlending, depthWrite: false, transparent: true, fog: false }));
|
| 185 |
+
this.player = this.spawnCar('coupe', this.playerMat);
|
| 186 |
+
const flame = this.basic({ color: 0x7fc4ff, transparent: true, opacity: 0.85, blending: T.AdditiveBlending, depthWrite: false }); const cone = new T.ConeGeometry(0.13, 1.1, 8); cone.rotateZ(Math.PI / 2); this.keep(cone); this.flames = [0.45, -0.45].map(z => { const m = new T.Mesh(cone, flame); m.position.set(-2.82, 0.55, z); m.visible = false; this.player.add(m); return m; });
|
| 187 |
+
const brk = this.basic({ color: 0xff3020 }); this.brake = new T.Mesh(this.keep(new T.BoxGeometry(0.03, 0.09, 1.5)), brk); this.brake.position.set(-2.34, 0.76, 0); this.player.add(this.brake);
|
| 188 |
+
}
|
| 189 |
+
spawnCar(kind, mat) {
|
| 190 |
+
const g = new T.Group(); g.add(new T.Mesh(this.carGeo[kind], mat)); g.add(new T.Mesh(this.lampGeo[kind], this.lampMatCar)); const s = new T.Mesh(this.shadowGeo, this.shadowMat); s.position.y = 0.05; g.add(s);
|
| 191 |
+
if (kind === 'cop') { const r = new T.Mesh(this.barGeo, this.barMat.r1), b = new T.Mesh(this.barGeo, this.barMat.b0); r.position.set(-0.45, 1.5, 0.3); b.position.set(-0.45, 1.5, -0.3); g.add(r, b); g.userData.bar = [r, b]; }
|
| 192 |
+
this.world.add(g); return g;
|
| 193 |
+
}
|
| 194 |
+
pool(name, make) { return this.pools[name] || (this.pools[name] = { list: [], make, used: 0 }); }
|
| 195 |
+
take(p) { if (p.used === p.list.length) p.list.push(p.make()); const o = p.list[p.used++]; o.visible = true; return o; }
|
| 196 |
+
buildProps() {
|
| 197 |
+
const steel = this.lam({ color: 0x585c63 }), glow = this.basic({ color: 0x7dff9a }), red = this.basic({ color: 0xff4632 }), amber = this.basic({ color: 0xffb037 });
|
| 198 |
+
const col = this.keep(new T.BoxGeometry(0.7, 8, 0.7)); col.translate(0, 4, 0); const beam = this.keep(new T.BoxGeometry(0.9, 0.9, 1)), strip = this.keep(new T.BoxGeometry(0.2, 0.5, 1)), cone = this.keep(new T.ConeGeometry(0.35, 0.9, 8)), rail = this.keep(new T.BoxGeometry(0.5, 0.9, 3)), spike = this.keep(new T.BoxGeometry(0.9, 0.1, 1)), tooth = this.keep(new T.ConeGeometry(0.1, 0.34, 4));
|
| 199 |
+
this.gateMake = kind => { const g = new T.Group(), hw = 10; const a = new T.Mesh(col, steel); a.position.z = hw; const b = new T.Mesh(col, steel); b.position.z = -hw; const top = new T.Mesh(beam, steel); top.position.y = 8; top.scale.z = hw * 2 + 0.7; const bar = new T.Mesh(strip, glow); bar.position.set(-0.55, 8, 0); bar.scale.z = hw * 2 - 1; g.add(a, b, top, bar); g.userData.bar = bar; this.world.add(g); return g; };
|
| 200 |
+
this.redDark = this.basic({ color: 0x401010 });
|
| 201 |
+
this.barrierMake = () => { const g = new T.Group(); const m = new T.Mesh(rail, this.lam({ color: 0xe8d030 })); m.position.y = 0.45; g.add(m); const l = new T.Mesh(this.keep(new T.BoxGeometry(0.1, 0.15, 2.6)), red); l.position.set(0.28, 0.75, 0); g.add(l); g.userData.lamp = l; g.userData.red = red; this.world.add(g); return g; };
|
| 202 |
+
const hazard = this.keep(canvasTex(64, 16, (q, w, h) => { q.fillStyle = '#e8c020'; q.fillRect(0, 0, w, h); q.fillStyle = '#18181a'; for (let x = -16; x < w; x += 16) { q.beginPath(); q.moveTo(x, h); q.lineTo(x + 8, 0); q.lineTo(x + 16, 0); q.lineTo(x + 8, h); q.fill(); } }, true));
|
| 203 |
+
this.spikeMake = () => { const g = new T.Group(); const m = new T.Mesh(spike, this.lam({ map: hazard })); m.position.y = 0.06; g.add(m); g.userData.base = m; const teeth = new T.InstancedMesh(tooth, this.lam({ color: 0xe8ecf2, emissive: 0x303438 }), 16); g.add(teeth); g.userData.teeth = teeth; this.keep(teeth); this.world.add(g); return g; };
|
| 204 |
+
this.haloMake = () => { const s = new T.Sprite(this.halo(0xffffff)); this.world.add(s); return s; };
|
| 205 |
+
this.coneMake = () => { const m = new T.Mesh(cone, this.lam({ color: 0xff7a1e })); this.world.add(m); return m; };
|
| 206 |
+
this.lightAmber = amber;
|
| 207 |
+
}
|
| 208 |
+
// ---- effects: three point clouds rebuilt per frame (one draw call each), sprites for markers, a beacon, light pools ----
|
| 209 |
+
buildFx() {
|
| 210 |
+
const pts = (n, size, blending, opacity) => { const g = this.keep(new T.BufferGeometry()); g.setAttribute('position', new T.BufferAttribute(new Float32Array(n * 3), 3)); g.setAttribute('color', new T.BufferAttribute(new Float32Array(n * 3), 3)); g.setDrawRange(0, 0); const m = new T.Points(g, this.keep(new T.PointsMaterial({ size, map: this.haloTex, vertexColors: true, transparent: true, opacity, depthWrite: false, blending, fog: false }))); m.frustumCulled = false; m.renderOrder = 5; this.world.add(m); return { m, g, n, used: 0 }; };
|
| 211 |
+
this.glow = pts(260, 1.5, T.AdditiveBlending, 1); this.spark = pts(80, 0.42, T.AdditiveBlending, 1); this.smoke = pts(60, 3.2, T.NormalBlending, 0.38);
|
| 212 |
+
const lamps = this.lampSpots || []; this.lampHalo = pts(lamps.length, 3.6, T.AdditiveBlending, 0.55); for (const l of lamps) this.pushPt(this.lampHalo, l[0], l[1], 7.35, 1, 0.82, 0.55); this.flushPts(this.lampHalo);
|
| 213 |
+
// rival marker: a downward chevron, constant size on screen
|
| 214 |
+
const chev = this.keep(canvasTex(64, 64, (q, w, h) => { q.fillStyle = 'rgba(0,0,0,.55)'; q.beginPath(); q.moveTo(6, 10); q.lineTo(58, 10); q.lineTo(32, 56); q.closePath(); q.fill(); q.fillStyle = '#ffffff'; q.beginPath(); q.moveTo(12, 14); q.lineTo(52, 14); q.lineTo(32, 48); q.closePath(); q.fill(); }));
|
| 215 |
+
this.markerMake = () => { const sp = new T.Sprite(this.keep(new T.SpriteMaterial({ map: chev, sizeAttenuation: false, depthWrite: false, transparent: true, fog: false }))); sp.scale.set(0.045, 0.045, 1); sp.renderOrder = 6; this.world.add(sp); return sp; };
|
| 216 |
+
// next-gate beacon: a tall additive column that rises above the roofs
|
| 217 |
+
const beamTex = this.keep(canvasTex(8, 128, (q, w, h) => { const g = q.createLinearGradient(0, 0, 0, h); g.addColorStop(0, 'rgba(255,255,255,0)'); g.addColorStop(0.5, 'rgba(255,255,255,.55)'); g.addColorStop(1, 'rgba(255,255,255,.9)'); q.fillStyle = g; q.fillRect(0, 0, w, h); }));
|
| 218 |
+
this.beaconMake = () => { const m = new T.Mesh(this.keep(new T.CylinderGeometry(1.1, 1.1, 70, 10, 1, true)), this.keep(new T.MeshBasicMaterial({ map: beamTex, color: 0x7dff9a, transparent: true, opacity: 0.5, depthWrite: false, side: T.DoubleSide, fog: false }))); m.position.y = 35; const g = new T.Group(); g.add(m); g.userData.beam = m; this.world.add(g); return g; };
|
| 219 |
+
// rival nitrous flame
|
| 220 |
+
const cone = this.keep(new T.ConeGeometry(0.13, 1.1, 8)); cone.rotateZ(Math.PI / 2); const flame = this.basic({ color: 0x7fc4ff, transparent: true, opacity: 0.85, blending: T.AdditiveBlending, depthWrite: false });
|
| 221 |
+
this.rflameMake = () => { const g = new T.Group(); for (const z of [0.45, -0.45]) { const m = new T.Mesh(cone, flame); m.position.set(-2.82, 0.55, z); g.add(m); } this.world.add(g); return g; };
|
| 222 |
+
// light pools on the road: player headlights at night, the helicopter's searchlight
|
| 223 |
+
const pool = this.keep(canvasTex(64, 64, (q, w, h) => { const g = q.createRadialGradient(32, 32, 2, 32, 32, 32); g.addColorStop(0, 'rgba(255,255,255,.75)'); g.addColorStop(1, 'rgba(255,255,255,0)'); q.fillStyle = g; q.fillRect(0, 0, w, h); }));
|
| 224 |
+
const quad = this.keep(new T.PlaneGeometry(1, 1)); quad.rotateX(-Math.PI / 2);
|
| 225 |
+
this.headPool = new T.Mesh(quad, this.keep(new T.MeshBasicMaterial({ map: pool, color: 0xfff0c8, transparent: true, opacity: 0.28, blending: T.AdditiveBlending, depthWrite: false }))); this.headPool.scale.set(12, 1, 22); this.headPool.visible = false; this.world.add(this.headPool);
|
| 226 |
+
this.heliSpot = new T.Mesh(quad, this.keep(new T.MeshBasicMaterial({ map: pool, color: 0xd8e8ff, transparent: true, opacity: 0.7, blending: T.AdditiveBlending, depthWrite: false }))); this.heliSpot.scale.set(18, 1, 18); this.heliSpot.visible = false; this.world.add(this.heliSpot);
|
| 227 |
+
}
|
| 228 |
+
pushPt(p, x, y, z, r, g, b) { if (p.used >= p.n) return; const i = p.used++; const a = p.g.attributes.position.array, c = p.g.attributes.color.array; a[i * 3] = x; a[i * 3 + 1] = z; a[i * 3 + 2] = -y; c[i * 3] = r; c[i * 3 + 1] = g; c[i * 3 + 2] = b; }
|
| 229 |
+
flushPts(p) { p.g.setDrawRange(0, p.used); p.g.attributes.position.needsUpdate = true; p.g.attributes.color.needsUpdate = true; }
|
| 230 |
+
// head and tail lights of one car in world space; night sets how strong the headlights read
|
| 231 |
+
carLights(x, y, h, kind, braking, night) {
|
| 232 |
+
const ch = Math.cos(h), sh = Math.sin(h), W = CAR_SHAPES[kind].w * 0.34, f = kind === 'van' ? 2.5 : 2.36, b = kind === 'van' ? -2.56 : -2.36, fy = kind === 'van' ? 0.72 : 0.5, by = kind === 'van' ? 0.95 : 0.74;
|
| 233 |
+
for (const s of [1, -1]) {
|
| 234 |
+
const lx = -sh * W * s, ly = ch * W * s;
|
| 235 |
+
if (night > 0) this.pushPt(this.glow, x + ch * f + lx, y + sh * f + ly, fy, night, night * 0.94, night * 0.78);
|
| 236 |
+
const k = braking ? 1 : 0.42; this.pushPt(this.glow, x + ch * b + lx, y + sh * b + ly, by, k, k * 0.1, k * 0.06);
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
drawFx(g, st) {
|
| 240 |
+
const night = st.lamp > 0 ? Math.min(1, 0.45 + st.lamp * 0.35) : 0.18, c = g.car, sp = C.speed(c), t = g.t;
|
| 241 |
+
this.glow.used = 0; this.spark.used = 0; this.smoke.used = 0;
|
| 242 |
+
this.carLights(c.x, c.y, c.h, 'coupe', g.heldBrake || sp < 0.5, night);
|
| 243 |
+
for (const o of g.traffic) this.carLights(o.x, o.y, o.h, o.paint % 6 === 3 ? 'van' : 'sedan', o.crash, night * 0.8);
|
| 244 |
+
for (const r of g.rivals) if (!r.gone) this.carLights(r.x, r.y, r.h, 'coupe', 0, night * 0.9);
|
| 245 |
+
for (const k of g.cops) if (!k.gone) this.carLights(k.x, k.y, k.h, 'cop', k.state === 'rb', k.dead ? 0 : night * 0.9);
|
| 246 |
+
for (const k of g.cops) if (k.dead && !k.gone) for (let i = 0; i < 5; i++) { const gr = 0.2 + i * 0.05; this.pushPt(this.smoke, k.x + Math.sin(i * 2.1 + t * 0.05) * 0.5, k.y + Math.cos(i * 1.7 + t * 0.04) * 0.5, 1.2 + i * 0.9 + ((t * 0.04 + i * 0.3) % 1), gr, gr, gr); }
|
| 247 |
+
// nitrous glow behind the player's exhausts
|
| 248 |
+
if (c.nosOn) { const ch = Math.cos(c.h), sh = Math.sin(c.h); for (let i = 1; i <= 4; i++) this.pushPt(this.glow, c.x - ch * (2.6 + i * 0.55), c.y - sh * (2.6 + i * 0.55), 0.55, 0.35, 0.6, 1); }
|
| 249 |
+
// sparks: a hit sets lastHit (0.25-0.4 s); 14 sparks thrown from the front corners along fixed pseudo-random paths
|
| 250 |
+
if (g.lastHit > 0) {
|
| 251 |
+
const age = 0.4 - g.lastHit, ch = Math.cos(c.h), sh = Math.sin(c.h);
|
| 252 |
+
for (let i = 0; i < 14; i++) { const u = Math.sin(i * 12.9898 + (t >> 4) * 78.233) * 43758.5453, r1 = u - Math.floor(u), r2 = (u * 7.13) - Math.floor(u * 7.13), side = i % 2 ? 1 : -1, sx = 2.1, sy = side * 0.9, a = c.h + side * (0.6 + r1 * 1.2) + Math.PI * (r2 < 0.3 ? 1 : 0), v = 6 + r2 * 9, d = v * age;
|
| 253 |
+
this.pushPt(this.spark, c.x + ch * sx - sh * sy + Math.cos(a) * d, c.y + sh * sx + ch * sy + Math.sin(a) * d, 0.4 + 3 * age - 9 * age * age + r1 * 0.3, 1, 0.75 + r2 * 0.25, 0.3); }
|
| 254 |
+
}
|
| 255 |
+
// tyre smoke while the rear slides (carStep drift); puffs trail back along the velocity
|
| 256 |
+
if (c.drift && sp > 4) { const vx = c.vx / sp, vy = c.vy / sp, ch = Math.cos(c.h), sh = Math.sin(c.h); for (let i = 0; i < 8; i++) for (const s of [1, -1]) { const back = 1.4 + i * 1.1, lx = -sh * 0.8 * s, ly = ch * 0.8 * s, gr = 0.62 + i * 0.03; this.pushPt(this.smoke, c.x - ch * 1.4 + lx - vx * back, c.y - sh * 1.4 + ly - vy * back, 0.5 + i * 0.12, gr, gr, gr); } }
|
| 257 |
+
this.flushPts(this.glow); this.flushPts(this.spark); this.flushPts(this.smoke);
|
| 258 |
+
this.lampHalo.m.visible = st.lamp > 0;
|
| 259 |
+
this.headPool.visible = st.lamp > 0; if (this.headPool.visible) { qv(c.x + Math.cos(c.h) * 9, c.y + Math.sin(c.h) * 9, 0.05, this.headPool.position); this.headPool.rotation.y = c.h; }
|
| 260 |
+
const hl = g.heli; this.heliSpot.visible = !!(hl && !hl.gone && hl.sees); if (this.heliSpot.visible) qv(c.x + (hl.x - c.x) * 0.15, c.y + (hl.y - c.y) * 0.15, 0.06, this.heliSpot.position);
|
| 261 |
+
}
|
| 262 |
+
// Corner boards: a red board with white chevrons on the outside wall of every corner tighter than 90 m, one every 9 m of arc,
|
| 263 |
+
// facing the car that is about to turn. They are what shows where the road goes when the road itself is behind a building.
|
| 264 |
+
buildChevrons() {
|
| 265 |
+
const tex = dir => this.keep(canvasTex(128, 64, (q, w, h) => { q.fillStyle = '#c8261c'; q.fillRect(0, 0, w, h); q.fillStyle = '#ffffff'; q.fillRect(0, 0, w, 4); q.fillRect(0, h - 4, w, 4);
|
| 266 |
+
for (let i = 0; i < 3; i++) { const x0 = 18 + i * 34; q.beginPath(); if (dir < 0) { q.moveTo(x0 + 20, 10); q.lineTo(x0, h / 2); q.lineTo(x0 + 20, h - 10); q.lineTo(x0 + 30, h - 10); q.lineTo(x0 + 10, h / 2); q.lineTo(x0 + 30, 10); } else { q.moveTo(x0, 10); q.lineTo(x0 + 20, h / 2); q.lineTo(x0, h - 10); q.lineTo(x0 + 10, h - 10); q.lineTo(x0 + 30, h / 2); q.lineTo(x0 + 10, 10); } q.closePath(); q.fill(); } }));
|
| 267 |
+
const geo = this.keep(new T.PlaneGeometry(2.6, 1.3)); geo.translate(0, 2.0, 0);
|
| 268 |
+
const post = this.keep(new T.BoxGeometry(0.12, 1.4, 0.12)); post.translate(0, 0.7, 0);
|
| 269 |
+
const lists = { left: [], right: [] }; this.chevrons = [];
|
| 270 |
+
for (const R of [C.routes.coast, C.routes.downtown]) {
|
| 271 |
+
for (let i = 0; i < R.n; i += Math.max(1, Math.round(9 / R.ds))) {
|
| 272 |
+
const k = R.k[i]; if (Math.abs(k) < 1 / 90) continue;
|
| 273 |
+
const a = C.routeAt(R, i * R.ds), out = k > 0 ? -1 : 1, lat = out * (R.halfW + 0.7), x = a.x + a.nx * lat, y = a.y + a.ny * lat;
|
| 274 |
+
if (C.road(x, y).d < 0.1) continue; // another road joins here: no wall, no board
|
| 275 |
+
(k > 0 ? lists.left : lists.right).push([x, y, a.h]); this.chevrons.push({ x, y, s: i * R.ds, route: R.name });
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
const o = new T.Object3D();
|
| 279 |
+
for (const [side, list] of Object.entries(lists)) {
|
| 280 |
+
if (!list.length) continue;
|
| 281 |
+
const board = new T.InstancedMesh(geo, this.basic({ map: tex(side === 'left' ? -1 : 1), side: T.DoubleSide }), list.length), legs = new T.InstancedMesh(post, this.lam({ color: 0x3a3c40 }), list.length);
|
| 282 |
+
list.forEach((p, j) => { qv(p[0], p[1], 0, o.position); o.rotation.set(0, p[2] - Math.PI / 2, 0); o.updateMatrix(); board.setMatrixAt(j, o.matrix); legs.setMatrixAt(j, o.matrix); });
|
| 283 |
+
this.world.add(this.keep(board), this.keep(legs));
|
| 284 |
+
}
|
| 285 |
+
}
|
| 286 |
+
// Screen position of a sim point with the frame's camera: {x, y} in canvas pixels, front = in front of the camera.
|
| 287 |
+
project(x, y, z) { const v = qv(x, y, z, this.tmpV || (this.tmpV = new T.Vector3())); v.applyMatrix4(this.camera.matrixWorldInverse); const front = v.z < -0.3; qv(x, y, z, v).project(this.camera); return { x: (v.x * 0.5 + 0.5) * 854, y: (-v.y * 0.5 + 0.5) * 480, front }; }
|
| 288 |
+
breakerMake() { const g = new T.Group(), steel = this.lam({ color: 0x8a5a30 }), red = this.basic({ color: 0xff5a2a }); for (const [x, z] of [[-1.8, -1.8], [1.8, -1.8], [-1.8, 1.8], [1.8, 1.8]]) { const m = new T.Mesh(this.keep(new T.BoxGeometry(0.4, 9, 0.4)), steel); m.position.set(x, 4.5, z); g.add(m); } const top = new T.Mesh(this.keep(new T.BoxGeometry(5, 1.6, 5)), steel); top.position.y = 9.5; g.add(top); const sign = new T.Mesh(this.keep(new T.BoxGeometry(5.2, 0.5, 5.2)), red); sign.position.y = 8.5; g.add(sign); this.world.add(g); return g; }
|
| 289 |
+
// ---------------- per-frame ----------------
|
| 290 |
+
placeCar(o, x, y, h, lift = 0) { qv(x, y, lift, o.position); o.rotation.y = h; }
|
| 291 |
+
drawProps(g) {
|
| 292 |
+
for (const p of Object.values(this.pools)) { for (const o of p.list) o.visible = false; p.used = 0; }
|
| 293 |
+
const R = g.route;
|
| 294 |
+
const blink = (g.t >> 3) % 2 === 0, nextGate = (g.gates || []).find(q => !q.done);
|
| 295 |
+
if (nextGate && !g.outcome) { const gs = nextGate.s !== undefined ? nextGate.s : g.s0 + nextGate.at, ds = R.loop && M.wrapTo ? M.wrapTo(R, gs, g.s) - g.s : gs - g.s; if (ds > 12 && ds < 900) { const a = C.routeAt(R, g.s + ds), o = this.take(this.pool('beacon', () => this.beaconMake())); this.placeCar(o, a.x, a.y, a.h); o.userData.beam.material.color.setHex(nextGate.kind === 'trap' ? 0xffb037 : nextGate.kind === 'line' ? 0xffffff : 0x7dff9a); } }
|
| 296 |
+
for (const gate of g.gates || []) {
|
| 297 |
+
const a = C.routeAt(R, (gate.s !== undefined ? gate.s : g.s0 + gate.at)); if (gate.done && !gate.keep) continue;
|
| 298 |
+
const o = this.take(this.pool(gate.kind === 'trap' ? 'gateT' : 'gate', () => this.gateMake(gate.kind === 'trap' ? 'trap' : 'toll')));
|
| 299 |
+
this.placeCar(o, a.x, a.y, a.h); const bar = o.userData.bar; bar.material.color.setHex(gate.kind === 'trap' ? (g.flashT > 0 ? 0xffffff : 0xffb037) : (gate.next ? 0x7dff9a : 0x7dff9a));
|
| 300 |
+
}
|
| 301 |
+
for (const t of g.traffic) { const o = this.take(this.pool('tr' + (t.paint % 6), () => this.spawnCar(t.paint % 6 === 3 ? 'van' : 'sedan', this.paints[t.paint % 6]))); this.placeCar(o, t.x, t.y, t.h); }
|
| 302 |
+
for (const r of g.rivals) {
|
| 303 |
+
if (r.gone) continue; const o = this.take(this.pool('rv' + (r.paint || 0), () => this.spawnCar('coupe', this.paint([0x9fb0c8, 0xb0242c, 0x28402c, 0x4b3d84][(r.paint || 0) % 4])))); this.placeCar(o, r.x, r.y, r.h);
|
| 304 |
+
// marker: the champion red, every other rival white; nitrous flames while its boost runs (rivals.js nosT / trapNos)
|
| 305 |
+
const mk = this.take(this.pool('marker', () => this.markerMake())); qv(r.x, r.y, 2.5, mk.position); mk.material.color.setHex(r.name === 'champion' ? 0xff4a3a : 0xffffff);
|
| 306 |
+
if ((r.nosT > 0 || r.trapNos > 0) && r.nos > 0.02 && !r.out) { const f = this.take(this.pool('rflame', () => this.rflameMake())); this.placeCar(f, r.x, r.y, r.h); f.scale.set(1 + ((g.t * 7) % 3) * 0.2, 1, 1); }
|
| 307 |
+
}
|
| 308 |
+
for (const c of g.cops) {
|
| 309 |
+
if (c.gone) continue; const o = this.take(this.pool('cop', () => this.spawnCar('cop', this.copMat))); this.placeCar(o, c.x, c.y, c.h);
|
| 310 |
+
const live = !c.dead, ph = (c.slot || 0) % 2 ? !blink : blink, bar = o.userData.bar; bar[0].material = live && ph ? this.barMat.r1 : this.barMat.r0; bar[1].material = live && !ph ? this.barMat.b1 : this.barMat.b0;
|
| 311 |
+
if (live) { const s = this.take(this.pool('halo', () => this.haloMake())); qv(c.x, c.y, 1.7, s.position); s.scale.setScalar(c.state === 'rb' ? 6 : 4.4); s.material.color.setHex(ph ? 0xff2a3a : 0x3a70ff); }
|
| 312 |
+
}
|
| 313 |
+
for (const b of g.breakers || []) { if (b.rearm > 0) continue; const o = this.take(this.pool('breaker', () => this.breakerMake())); this.placeCar(o, b.x, b.y, b.h); }
|
| 314 |
+
for (const p of g.props) {
|
| 315 |
+
if (p.gone) continue; const a = { x: p.x, y: p.y, h: p.h || 0 };
|
| 316 |
+
if (p.type === 'spike') { const o = this.take(this.pool('spike', () => this.spikeMake())), L = p.len || 14; this.placeCar(o, a.x, a.y, a.h); o.userData.base.scale.z = L; const t = o.userData.teeth, m = new T.Object3D(); for (let i = 0; i < 16; i++) { m.position.set((i % 2) * 0.3 - 0.15, 0.2, (i / 15 - 0.5) * L); m.updateMatrix(); t.setMatrixAt(i, m.matrix); } t.instanceMatrix.needsUpdate = true;
|
| 317 |
+
if (!p.used) for (const e of [-1, 1]) { const b = this.take(this.pool('halo', () => this.haloMake())), ex = a.x - Math.sin(a.h) * e * (L / 2 + 0.6), ey = a.y + Math.cos(a.h) * e * (L / 2 + 0.6); qv(ex, ey, 0.5, b.position); b.scale.setScalar(blink ? 3.4 : 1.6); b.material.color.setHex(0xffb020); } }
|
| 318 |
+
else if (p.type === 'barrier') { const o = this.take(this.pool('barrier', () => this.barrierMake())); this.placeCar(o, a.x, a.y, a.h, p.lift || 0); o.rotation.x = p.spin || 0; o.userData.lamp.material = blink ? o.userData.red : this.redDark; }
|
| 319 |
+
else if (p.type === 'cone') { const o = this.take(this.pool('cone', () => this.coneMake())); qv(a.x, a.y, 0.45, o.position); }
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
render(g, ctx) {
|
| 323 |
+
if (this.closed || this.renderer.getContext().isContextLost()) { this.ready = false; this.error = this.closed ? '3D renderer is closed' : 'WebGL context lost'; throw Error(this.error); }
|
| 324 |
+
const t0 = performance.now();
|
| 325 |
+
try {
|
| 326 |
+
const key = g.key, st = STYLE[key] || STYLE.tollbooth, c = g.car;
|
| 327 |
+
if (this.key !== key) {
|
| 328 |
+
this.key = key; this.world.fog.color.setHex(st.fog[0]); this.world.fog.near = st.fog[1]; this.world.fog.far = st.fog[2];
|
| 329 |
+
this.hemi.color.setHex(st.hemi[0]); this.hemi.groundColor.setHex(st.hemi[1]); this.hemi.intensity = st.hemi[2]; this.sun.color.setHex(st.sun); this.sun.intensity = st.sunI;
|
| 330 |
+
this.sun.position.set(st.dir[0], Math.max(0.12, st.dir[1]) + 0.25, -0.5); this.sky.material.map = this.skyTex(key); this.sky.material.needsUpdate = true;
|
| 331 |
+
for (const m of this.mats.win) m.emissiveIntensity = st.win; this.lampMat.color.setHex(st.lamp > 0 ? 0xffdca0 : 0x77767a);
|
| 332 |
+
}
|
| 333 |
+
this.seaTex.offset.x = g.t * 0.0006; this.seaTex.offset.y = g.t * 0.0003;
|
| 334 |
+
this.placeCar(this.player, c.x, c.y, c.h); const sp = C.speed(c);
|
| 335 |
+
// Body motion: roll outward in a turn (local +X is forward, so YXZ order makes x roll and z pitch), nose dive under braking.
|
| 336 |
+
// (Before 2026-11-08 this set rotation.z from the steering, which pitched the nose instead of rolling the body.)
|
| 337 |
+
this.player.rotation.order = 'YXZ'; this.player.rotation.x = C.clamp(c.r * sp * 0.006, -0.07, 0.07); this.player.rotation.z = g.heldBrake && sp > 3 ? -0.022 : c.nosOn ? 0.012 : 0;
|
| 338 |
+
this.flames.forEach(f => { f.visible = !!c.nosOn; f.scale.set(1 + ((g.t * 7) % 3) * 0.2, 1, 1); });
|
| 339 |
+
this.brake.visible = g.heldBrake || sp < 0.5;
|
| 340 |
+
this.drawProps(g); this.drawHeli(g); this.drawFx(g, st);
|
| 341 |
+
const yaw = g.camH === undefined ? c.h : g.camH, back = 6.6 + Math.min(1.8, sp * 0.022), up = 2.45 + Math.min(0.5, sp * 0.006);
|
| 342 |
+
qv(c.x - Math.cos(yaw) * back, c.y - Math.sin(yaw) * back, up, this.camera.position);
|
| 343 |
+
const hit = Math.max(0, g.lastHit || 0), shake = (c.nosOn ? 0.03 * Math.sin(g.t * 1.7) : 0) + hit * 0.5 * Math.sin(g.t * 2.9);
|
| 344 |
+
if (hit > 0) { this.camera.position.x += hit * 0.35 * Math.sin(g.t * 3.7); this.camera.position.y += hit * 0.25 * Math.cos(g.t * 4.3); }
|
| 345 |
+
this.camera.lookAt(qv(c.x + Math.cos(yaw) * 7, c.y + Math.sin(yaw) * 7, 1.15 + shake));
|
| 346 |
+
this.camera.fov = 58 + Math.min(16, sp * 0.2) + (c.nosOn ? 4 : 0) - (g.sb ? 5 : 0); this.camera.updateProjectionMatrix();
|
| 347 |
+
this.sky.position.copy(this.camera.position);
|
| 348 |
+
this.renderer.setScissorTest(false); this.renderer.setViewport(0, 0, 854, 480);
|
| 349 |
+
this.renderer.render(this.world, this.camera);
|
| 350 |
+
this.mirrorOn = !!(g.cops.length || g.rivals.length || g.pol);
|
| 351 |
+
if (this.mirrorOn) {
|
| 352 |
+
const [x0, y0, x1, y1] = this.mirrorRect, mh = c.h;
|
| 353 |
+
qv(c.x + Math.cos(mh) * 0.4, c.y + Math.sin(mh) * 0.4, 1.75, this.mirrorCam.position);
|
| 354 |
+
this.mirrorCam.lookAt(qv(c.x - Math.cos(mh) * 30, c.y - Math.sin(mh) * 30, 0.9));
|
| 355 |
+
this.mirrorCam.updateMatrixWorld(); this.sky.position.copy(this.mirrorCam.position);
|
| 356 |
+
const vy = 480 - y1; this.renderer.setViewport(x0, vy, x1 - x0, y1 - y0); this.renderer.setScissor(x0, vy, x1 - x0, y1 - y0); this.renderer.setScissorTest(true);
|
| 357 |
+
// the player's own car, its light glows and the particles sit right in front of the mirror camera: hidden for this pass
|
| 358 |
+
const fx = [this.player, this.glow.m, this.spark.m, this.smoke.m, this.headPool], was = fx.map(o => o.visible); fx.forEach(o => { o.visible = false; });
|
| 359 |
+
this.renderer.render(this.world, this.mirrorCam); fx.forEach((o, i) => { o.visible = was[i]; });
|
| 360 |
+
this.renderer.setScissorTest(false); this.renderer.setViewport(0, 0, 854, 480); this.sky.position.copy(this.camera.position);
|
| 361 |
+
}
|
| 362 |
+
ctx.drawImage(this.view, 0, 0, 854, 480);
|
| 363 |
+
this.times.push(performance.now() - t0); if (this.times.length > 120) this.times.shift();
|
| 364 |
+
this.ready = true; this.error = null;
|
| 365 |
+
} catch (e) { this.ready = false; this.error = String(e && e.stack || e); throw e; }
|
| 366 |
+
}
|
| 367 |
+
drawHeli(g) {
|
| 368 |
+
if (!g.heli || g.heli.gone) { if (this.heliObj) this.heliObj.visible = false; return; }
|
| 369 |
+
if (!this.heliObj) {
|
| 370 |
+
const H = this.heliObj = new T.Group(), body = this.lam({ color: 0x1c2230, vertexColors: true });
|
| 371 |
+
H.add(new T.Mesh(this.keep(merge([[moved(new T.SphereGeometry(1.5, 10, 8), 0.6, 0, 0), 0xffffff], [moved(new T.BoxGeometry(4.2, 0.5, 0.45), -2.4, 0.2, 0), 0xffffff], [boxG(-4.5, 0.75, 0, 0.5, 1.2, 0.12), 0xffffff], [boxG(0.4, -1.45, 0.9, 2.8, 0.1, 0.12), 0x777777], [boxG(0.4, -1.45, -0.9, 2.8, 0.1, 0.12), 0x777777], [moved(new T.SphereGeometry(0.9, 8, 6), 1.5, 0.15, 0), 0x223a55]])), body));
|
| 372 |
+
const rotor = this.heliRotor = new T.Mesh(this.keep(new T.BoxGeometry(9, 0.05, 0.3)), this.lam({ color: 0x26282c })); rotor.position.y = 1.65; H.add(rotor);
|
| 373 |
+
const beam = this.heliBeam = new T.Mesh(this.keep(new T.ConeGeometry(4.5, 26, 16, 1, true)), this.basic({ color: 0xd8e8ff, transparent: true, opacity: 0.13, blending: T.AdditiveBlending, depthWrite: false, side: T.DoubleSide })); beam.position.y = -13.5; H.add(beam); this.world.add(H);
|
| 374 |
+
}
|
| 375 |
+
const h = g.heli; this.heliObj.visible = true; qv(h.x, h.y, h.z, this.heliObj.position); this.heliObj.rotation.y = h.h; this.heliRotor.rotation.y = g.t * 1.1;
|
| 376 |
+
this.heliBeam.visible = !!h.sees;
|
| 377 |
+
}
|
| 378 |
+
metrics() { const s = [...this.times].sort((a, b) => a - b), i = this.renderer.info; return { renderer: 'webgl-nfsmw', drawCalls: i.render.calls, triangles: i.render.triangles, samples: s.length, cpuRenderMsP50: s.length ? s[Math.floor((s.length - 1) * 0.5)] : null, cpuRenderMsP95: s.length ? s[Math.floor((s.length - 1) * 0.95)] : null }; }
|
| 379 |
+
close() { if (this.closed) return; this.closed = true; this.ready = false; for (const r of this.res) r.dispose && r.dispose(); this.renderer.dispose(); this.renderer.forceContextLoss(); this.res = []; }
|
| 380 |
+
}
|
| 381 |
+
R3.render = (g, ctx) => { let s = byCanvas.get(ctx.canvas); if (!s || s.closed) { s = new Scene(ctx.canvas); byCanvas.set(ctx.canvas, s); } s.render(g, ctx); return s; };
|
| 382 |
+
R3.status = ctx => { const s = ctx && byCanvas.get(ctx.canvas); if (s && !s.closed && s.renderer.getContext().isContextLost()) { s.ready = false; s.error = 'WebGL context lost'; } return { renderer: 'webgl-nfsmw', kind: 'perspective', ready: !!(s && s.ready && !s.closed), error: s ? s.error : null }; };
|
| 383 |
+
R3.metrics = ctx => { const s = ctx && byCanvas.get(ctx.canvas); return s && !s.closed ? s.metrics() : null; };
|
| 384 |
+
R3.close = ctx => { const s = ctx && byCanvas.get(ctx.canvas); if (s) { s.close(); byCanvas.delete(ctx.canvas); } };
|
| 385 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/rivals.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Rival racers. The driver model is AIActionRace with its own skill tables (AI/Actions/AIActionRace.cpp): speed scale {0.85, 1},
|
| 2 |
+
acceleration scale {0.65, 1} (drag {0.82, 1}), catch-up acceleration table {1, 1.33, 1.66, 2} (:70), nitrous availability
|
| 3 |
+
{0.33, 1} (:42-43), on for 2-4 s (:38-39) and off for 20-4 s by skill (:36-37), speed-trap nitrous 1-3 s ahead (:40-41).
|
| 4 |
+
Catch-up gain by skill {0.33, 0.66, 1} and slow-down {1, 1, 0.66} are AI/Common/AIVehicle.cpp:2053-2059; the error scale
|
| 5 |
+
that feeds them lives in GRaceStatus::ComputeCatchUpSkill (body not in the repository), so the gaps below are approximations.
|
| 6 |
+
A rival rides route coordinates (s, lat), so it can never leave the road or get lost. Nothing here reads the RNG. */
|
| 7 |
+
(function (root) {
|
| 8 |
+
'use strict';
|
| 9 |
+
const M = root.NfsmwGame, C = M.C, P = C.PLAYER, lerp = C.lerp, clamp = C.clamp;
|
| 10 |
+
const tableAt = (t, x) => { const u = clamp(x, 0, 1) * (t.length - 1), i = Math.min(t.length - 2, Math.floor(u)); return t[i] + (t[i + 1] - t[i]) * (u - i); };
|
| 11 |
+
// A rival's form on the day: drawn once at the start of a heat from the game RNG, so a seed is a different race, not a relabelled one.
|
| 12 |
+
M.formOf = g => (root.NativeBench.rand(g) - 0.5) * 0.06;
|
| 13 |
+
M.newRival = (g, o) => {
|
| 14 |
+
const a = C.routeAt(g.route, o.s, o.lat);
|
| 15 |
+
return { s: o.s, s0: o.s, lat: o.lat, latGoal: o.lat, v: 0, x: a.x, y: a.y, h: a.h, skill: o.skill, drag: !!o.drag, paint: o.paint || 0, out: 0, gone: 0,
|
| 16 |
+
nos: lerp(0.33, 1, o.skill), nosT: 0, nosCool: 2, trapNos: 0, prog: 0, finished: 0, top: o.top || 84, grip: o.grip || lerp(0.74, 0.98, o.skill), name: o.name || '' };
|
| 17 |
+
};
|
| 18 |
+
// Speed a rival would carry past a route point, integrated from where it is now: its own limits and drive, no glue, no nitrous,
|
| 19 |
+
// no traffic. Used only to score a camera the event ended before it reached.
|
| 20 |
+
M.projectRival = (g, r, target) => {
|
| 21 |
+
const R = g.route, accelScale = lerp(0.65, 1, r.skill), prof = C.profile(R, P.grip * r.grip, P.aero, P.brake * 0.9, r.top * lerp(0.85, 1, r.skill));
|
| 22 |
+
let v = r.v;
|
| 23 |
+
for (let s = r.s; s < target; s += R.ds) { const a = Math.max(0, C.driveAt(v) * accelScale - P.drag * v * v - P.roll); v = Math.min(C.profileAt(R, prof, s + R.ds), Math.sqrt(v * v + 2 * a * R.ds)); }
|
| 24 |
+
return v;
|
| 25 |
+
};
|
| 26 |
+
M.stepRival = (g, r, wdt) => {
|
| 27 |
+
if (r.out || r.finished) r.v = Math.max(0, r.v - 7 * wdt);
|
| 28 |
+
const R = g.route, skill = r.skill, speedScale = lerp(0.85, 1, skill), accelScale = r.drag ? lerp(0.82, 1, skill) : lerp(0.65, 1, skill);
|
| 29 |
+
const prof = C.profile(R, P.grip * r.grip, P.aero, P.brake * 0.9, r.top * speedScale), vlim = Math.min(C.profileAt(R, prof, r.s + r.v * 0.25), C.profileAt(R, prof, r.s + r.v * 0.5));
|
| 30 |
+
// Catch-up glue: acceleration up to x2 when behind the player, a gentler speed limit when ahead (it never parks and waits).
|
| 31 |
+
const gap = (g.s - g.s0) - (r.s - r.s0), glue = g.glue === undefined ? 1 : g.glue, behind = glue * clamp(gap / 120, 0, 1) * tableAt([0.33, 0.66, 1], skill), ahead = glue * clamp(-gap / 240, 0, 1) * tableAt([1, 1, 0.66], skill);
|
| 32 |
+
const catchup = g.noGlue ? 1 : tableAt([1, 1.33, 1.66, 2], behind), limit = vlim * (g.noGlue ? 1 : 1 - 0.1 * ahead);
|
| 33 |
+
// Nitrous: skill sets how often and how much; a coming speed trap overrides the cool-down (CheckSpeedTraps).
|
| 34 |
+
if (r.nosT > 0) r.nosT -= wdt; else if (r.nosCool > 0) r.nosCool -= wdt;
|
| 35 |
+
const trapNear = r.trapNos > 0 && r.nos > 0.02;
|
| 36 |
+
if (!r.out && r.nosT <= 0 && r.nosCool <= 0 && r.nos > 0.02 && r.v > 10 && limit > r.v + 5) { r.nosT = lerp(2, 4, skill); r.nosCool = lerp(20, 4, skill); }
|
| 37 |
+
const on = (r.nosT > 0 || trapNear) && r.nos > 0 && r.v < limit - 1 && !r.out && !r.finished;
|
| 38 |
+
if (on) r.nos = Math.max(0, r.nos - wdt / P.nosSeconds);
|
| 39 |
+
if (r.trapNos > 0) r.trapNos -= wdt;
|
| 40 |
+
if (!r.out && !r.finished) {
|
| 41 |
+
if (r.v > limit) r.v = Math.max(limit, r.v - P.brake * 0.9 * wdt);
|
| 42 |
+
else { const a = C.driveAt(r.v) * accelScale * catchup * (on ? 1 + P.nosBoost : 1) - P.drag * r.v * r.v - P.roll; r.v = Math.min(limit, r.v + Math.max(0, a) * wdt); }
|
| 43 |
+
}
|
| 44 |
+
r.s += r.v * wdt;
|
| 45 |
+
// Lane: separation from the player and from traffic within two seconds; otherwise back to its own line.
|
| 46 |
+
const edge = R.halfW - 2.1;
|
| 47 |
+
if (!g.laneLocked) {
|
| 48 |
+
let goal = r.latGoal;
|
| 49 |
+
const clear = lat => { for (const t of g.traffic) { let ds = t.s - r.s; if (R.loop) { ds %= R.L; if (ds > R.L / 2) ds -= R.L; else if (ds < -R.L / 2) ds += R.L; } const cl = r.v - t.v; if (ds > -6 && ds < 8 + Math.max(cl, 0) * 2 && Math.abs(t.lat - lat) < 3.6) return false; } for (const b of g.blocks || []) { const ds = b.s - r.s; if (ds > -6 && ds < 10 + r.v * 2 && Math.abs(b.lat - lat) < 3.6) return false; } const ds = g.s - r.s; return !(ds > -6 && ds < 14 && Math.abs(g.lat - lat) < 3.4); };
|
| 50 |
+
if (!clear(r.lat)) { let best = r.lat, bd = Infinity; for (let lat = -edge; lat <= edge + 1e-6; lat += edge / 2.5) if (clear(lat) && Math.abs(lat - r.lat) < bd) { bd = Math.abs(lat - r.lat); best = lat; } goal = best; }
|
| 51 |
+
const rate = Math.min(4.2, 0.6 + r.v * 0.09), dl = clamp(goal - r.lat, -rate * wdt, rate * wdt); r.lat = clamp(r.lat + dl, -edge, edge);
|
| 52 |
+
}
|
| 53 |
+
const a = C.routeAt(R, r.s, r.lat); r.x = a.x; r.y = a.y; r.h = a.h;
|
| 54 |
+
r.prog = r.s - r.s0;
|
| 55 |
+
// Contact. A rail car takes the impulse as a speed change and a sideways shove.
|
| 56 |
+
if (r.gone || g.pre > 0) return;
|
| 57 |
+
for (const t of g.traffic) { if (t.crash) continue; const dx = r.x - t.x, dy = r.y - t.y; if (dx * dx + dy * dy < 9) { r.v *= 0.55; t.crash = r.lat > t.lat ? -0.8 : 0.8; t.vx = Math.cos(t.h) * Math.abs(t.v); t.vy = Math.sin(t.h) * Math.abs(t.v); g.events.push({ type: 'rival_crash' }); } }
|
| 58 |
+
const c = g.car, dx = c.x - r.x, dy = c.y - r.y, d2 = dx * dx + dy * dy, R2 = M.carRadius * 2;
|
| 59 |
+
if (d2 < R2 * R2) {
|
| 60 |
+
const d = Math.max(0.01, Math.sqrt(d2)), nx = dx / d, ny = dy / d, rvx = Math.cos(r.h) * r.v, rvy = Math.sin(r.h) * r.v, rel = (c.vx - rvx) * nx + (c.vy - rvy) * ny, push = R2 - d;
|
| 61 |
+
c.x += nx * push * 0.5; c.y += ny * push * 0.5;
|
| 62 |
+
const nl = -Math.sin(r.h) * nx + Math.cos(r.h) * ny; r.lat = clamp(r.lat - nl * push * 0.5, -edge, edge);
|
| 63 |
+
if (rel < 0) { const j = -0.65 * rel; c.vx += nx * j; c.vy += ny * j; r.v = Math.max(0, r.v - (Math.cos(r.h) * nx + Math.sin(r.h) * ny) * j); if (-rel > 4) { g.hits++; g.lastHit = 0.4; g.events.push({ type: 'rival_contact', speed: -rel }); } }
|
| 64 |
+
}
|
| 65 |
+
};
|
| 66 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/nfsmw_remake/scripted.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* The standard scripted reference controller (BossBench, not part of the original game). NfsmwGame.scripted(game) runs once per
|
| 2 |
+
200 ms packet. It reads already-decided state (poses, speeds, gates) and looks ahead only with the pure car model on a
|
| 3 |
+
copy of the player's car: other vehicles are extrapolated at constant speed, so it has no channel to a future random
|
| 4 |
+
draw at all (tests/leak_probe.js swaps the live RNG and checks the packet does not change).
|
| 5 |
+
Scoring is speed-weighted route progress minus wall and traffic risk. Never distance to a target (a target switch would
|
| 6 |
+
punish reaching it). Deterministic: no Math.random, no clock. */
|
| 7 |
+
(function (root) {
|
| 8 |
+
'use strict';
|
| 9 |
+
const M = root.NfsmwGame, C = M.C, N = root.NativeBench;
|
| 10 |
+
const PACKET_TICKS = 12, HOLD_SETS = 6, DT = 1 / 60;
|
| 11 |
+
// Cars collide as two circles (game.js carRadius 1.6, 3.2 m between centres). A car alongside at 3.3 m is passing, not crashing.
|
| 12 |
+
const CONTACT = 3.5, LANE_GAP = 3.7;
|
| 13 |
+
// Duty-cycle steering: digital keys held for k of the 6 hold sets. The wheel slews towards the key and back to centre at
|
| 14 |
+
// the same rate, so duty 3 holds whatever angle it has, above 3 winds on, below 3 unwinds.
|
| 15 |
+
const STEER = [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6];
|
| 16 |
+
const copyCar = c => Object.assign({}, c);
|
| 17 |
+
|
| 18 |
+
// Same input mapping as Game.update; `plan` = {steer duty, thr, brk, hb, nos}. Mutates c.
|
| 19 |
+
function rollout(g, c, plan, ticks, P, wscale) {
|
| 20 |
+
for (let i = 0; i < ticks; i++) {
|
| 21 |
+
const set = Math.floor(i * HOLD_SETS / PACKET_TICKS) % HOLD_SETS, on = set < Math.abs(plan.duty);
|
| 22 |
+
C.carStep(c, { thr: plan.thr, brk: plan.brk, steer: on ? Math.sign(plan.duty) : 0, hb: plan.hb, nos: plan.nos, manual: false, sbGrip: 0 }, DT * wscale, P);
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
// Lateral target for the next stretch: keep off traffic that will be alongside, otherwise hold the racing line.
|
| 26 |
+
function laneTarget(g, R, S, others, speed, base) {
|
| 27 |
+
const edge = R.halfW - 2.2, lanes = [base, -edge * 0.75, edge * 0.75, -edge * 0.35, edge * 0.35, -edge, edge];
|
| 28 |
+
let best = base, bs = -Infinity;
|
| 29 |
+
for (const lat of lanes) {
|
| 30 |
+
let sc = -Math.abs(lat - g.lat) * 0.5 - Math.abs(lat - base) * 0.2;
|
| 31 |
+
for (const o of others) {
|
| 32 |
+
const ds = o.s - S; if (ds < -8 || ds > 200) continue; // a car behind the door mirrors is not a reason to change lane
|
| 33 |
+
// A car close ahead at matching speed blocks the lane however small the closing speed is.
|
| 34 |
+
const closing = speed - o.vs, tt = ds < 30 && ds > -8 ? Math.max(0, ds) / Math.max(closing, 8) : closing > 1 ? ds / closing : 99; if (tt > 5) continue;
|
| 35 |
+
const gap = Math.abs(o.lat + (o.vl || 0) * Math.min(tt, 2) - lat); if (gap < LANE_GAP) sc -= (LANE_GAP - gap) * (6 - tt) * 2.4;
|
| 36 |
+
}
|
| 37 |
+
if (sc > bs) { bs = sc; best = lat; }
|
| 38 |
+
}
|
| 39 |
+
return best;
|
| 40 |
+
}
|
| 41 |
+
// Decided state of everything on the road, projected onto route coordinates.
|
| 42 |
+
function roadUsers(g, R) {
|
| 43 |
+
const out = [], L = R.L;
|
| 44 |
+
// On a circuit every position is one lap from itself: put each car on the player's lap so distances are real.
|
| 45 |
+
const near = v => { if (!R.loop) return v; let ds = (v - g.s) % L; if (ds > L / 2) ds -= L; else if (ds < -L / 2) ds += L; return Math.abs(v - g.s) <= L / 2 ? v : g.s + ds; };
|
| 46 |
+
for (const t of g.traffic) out.push({ s: near(t.s), lat: t.lat, vs: t.crash ? 0 : t.v, r: 2 });
|
| 47 |
+
for (const r of g.rivals) if (!r.out) out.push({ s: near(r.s), lat: r.lat, vs: r.v, r: 2, a: r.v < 25 ? 5 : 0 }); // a car pulling away is not a parked car
|
| 48 |
+
if (M.copUsers) M.copUsers(g, R, out);
|
| 49 |
+
return out;
|
| 50 |
+
}
|
| 51 |
+
// Minimum-curvature line: an elastic band pulled tight between the road edges. Controller-only and a pure function of the route, so
|
| 52 |
+
// it is cached outside the game state. Returns the lateral offset per sample and the speed profile on that line's own curvature.
|
| 53 |
+
const lines = new Map();
|
| 54 |
+
function racingLine(R, P, grip, brake, top) {
|
| 55 |
+
let L = lines.get(R.name);
|
| 56 |
+
if (!L) {
|
| 57 |
+
const n = R.n, lat = new Float64Array(n), edge = R.halfW - 2.4, wrap = i => R.loop ? (i + n) % n : Math.max(0, Math.min(n - 1, i)), K = Math.max(2, Math.round(10 / R.ds));
|
| 58 |
+
const nx = i => -Math.sin(R.h[i]), ny = i => Math.cos(R.h[i]), px = i => R.x[i] + nx(i) * lat[i], py = i => R.y[i] + ny(i) * lat[i];
|
| 59 |
+
for (let it = 0; it < 400; it++) for (let i = 0; i < n; i++) { const a = wrap(i - K), b = wrap(i + K), tx = (px(a) + px(b)) / 2 - px(i), ty = (py(a) + py(b)) / 2 - py(i); lat[i] = C.clamp(lat[i] + 0.5 * (tx * nx(i) + ty * ny(i)), -edge, edge); }
|
| 60 |
+
const kap = new Float64Array(n);
|
| 61 |
+
for (let i = 0; i < n; i++) { const a = wrap(i - K), b = wrap(i + K), x1 = px(i) - px(a), y1 = py(i) - py(a), x2 = px(b) - px(i), y2 = py(b) - py(i), l1 = Math.hypot(x1, y1), l2 = Math.hypot(x2, y2), l3 = Math.hypot(x1 + x2, y1 + y2); kap[i] = l1 && l2 && l3 ? Math.abs(2 * (x1 * y2 - y1 * x2) / (l1 * l2 * l3)) : 0; }
|
| 62 |
+
L = { lat, kap, prof: new Map() }; lines.set(R.name, L);
|
| 63 |
+
}
|
| 64 |
+
const key = [grip, brake, top].map(v => v.toFixed(3)).join('|'); let v = L.prof.get(key);
|
| 65 |
+
if (!v) {
|
| 66 |
+
v = new Float64Array(R.n);
|
| 67 |
+
for (let i = 0; i < R.n; i++) v[i] = L.kap[i] > P.aero + 1e-5 ? Math.min(top, Math.sqrt(grip / (L.kap[i] - P.aero))) : top;
|
| 68 |
+
for (let p = 0; p < (R.loop ? 2 : 1); p++) for (let i = R.n - 1; i >= 0; i--) { const j = i + 1 < R.n ? i + 1 : R.loop ? 0 : i, lim = Math.sqrt(v[j] * v[j] + 2 * brake * R.ds); if (lim < v[i]) v[i] = lim; }
|
| 69 |
+
L.prof.set(key, v);
|
| 70 |
+
}
|
| 71 |
+
return { lat: L.lat, prof: v };
|
| 72 |
+
}
|
| 73 |
+
const lineLat = (R, lat, s) => { let i = Math.round(s / R.ds); if (R.loop) { i %= R.n; if (i < 0) i += R.n; } else i = C.clamp(i, 0, R.n - 1); return lat[i]; };
|
| 74 |
+
// Speed comes from the profile, steering from pure pursuit on the wanted line. Nothing here scores "slower is safer".
|
| 75 |
+
// First contact on the way to a lane, in route coordinates, with the other cars at their current speed.
|
| 76 |
+
function contactTime(g, others, S, speed, lat) {
|
| 77 |
+
const rate = 4, HORIZON_S = 3;
|
| 78 |
+
for (let t = 0.1; t < HORIZON_S; t += 0.1) {
|
| 79 |
+
const dl = lat - g.lat, l = g.lat + Math.sign(dl) * Math.min(Math.abs(dl), rate * t), sp = S + speed * t;
|
| 80 |
+
for (const o of others) {
|
| 81 |
+
if (o.s <= S) continue;
|
| 82 |
+
const ol = o.lat + (o.vl || 0) * Math.min(t, 2), ds = o.s + o.vs * t + 0.5 * (o.a || 0) * t * t - sp, t0 = t - 0.1, ds0 = o.s + o.vs * t0 + 0.5 * (o.a || 0) * t0 * t0 - (S + speed * t0);
|
| 83 |
+
// Inside the window now, or it went from ahead of the bumper to behind it during this step: sampling alone misses a fast closing car.
|
| 84 |
+
if (Math.abs(ol - l) < CONTACT && ((ds > 0 && Math.hypot(ds, ol - l) < CONTACT) || (ds0 > 0 && ds <= 0))) return t;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
return HORIZON_S;
|
| 88 |
+
}
|
| 89 |
+
// The wheel slews towards the key held and back to centre (nfscore carStep), so a target angle is tracked one substep at a time.
|
| 90 |
+
function steerKeys(c, target, speed, wscale) {
|
| 91 |
+
const rate = (speed < 15 ? 7 : speed < 40 ? 5 : 3.6) * wscale * 2 * DT, out = []; let st = c.steer;
|
| 92 |
+
for (let i = 0; i < HOLD_SETS; i++) {
|
| 93 |
+
let best = 0, bd = Infinity;
|
| 94 |
+
for (const k of [0, 1, -1]) { const n = st + C.clamp(k - st, -rate, rate), e = Math.abs(n - target); if (e < bd - 1e-9) { bd = e; best = k; } }
|
| 95 |
+
out.push(best); st += C.clamp(best - st, -rate, rate);
|
| 96 |
+
}
|
| 97 |
+
return out;
|
| 98 |
+
}
|
| 99 |
+
function planDrive(g, opt = {}) {
|
| 100 |
+
const R = g.route, c = g.car, P = g.P || C.PLAYER, S = g.s, speed = C.speed(c), tire = C.tireFactor(c);
|
| 101 |
+
const margin = opt.margin || 0.92, top = opt.top || C.TOPS[5], wscale = g.sb ? 0.45 : 1;
|
| 102 |
+
const line = racingLine(R, P, P.grip * tire * margin, P.brake * 0.8, top), prof = line.prof;
|
| 103 |
+
const others = roadUsers(g, R), base = opt.lat !== undefined ? opt.lat : lineLat(R, line.lat, S + speed * 0.8), lat = laneTarget(g, R, S, others, speed, base), onLine = lat === base && opt.lat === undefined;
|
| 104 |
+
// Pure pursuit from where the car will be when this packet lands, at a lookahead that grows with speed.
|
| 105 |
+
const lag = 0.1 * wscale, px = c.x + c.vx * lag, py = c.y + c.vy * lag, ph = c.h + c.r * lag, Ld = Math.max(7, speed * 0.62);
|
| 106 |
+
const sNear = C.routeNear(R, px, py, S, 8, 16), aim = C.routeAt(R, sNear + Ld, onLine ? lineLat(R, line.lat, sNear + Ld) : lat);
|
| 107 |
+
let alpha = Math.atan2(aim.y - py, aim.x - px) - ph; alpha = Math.atan2(Math.sin(alpha), Math.cos(alpha));
|
| 108 |
+
// Nose in a wall or a cop, too slow for the front wheels to turn it: back out on opposite lock (or, with a wall behind, full lock forward).
|
| 109 |
+
const far = C.routeAt(R, S + 18, lat); let off = Math.atan2(far.y - c.y, far.x - c.x) - c.h; off = Math.atan2(Math.sin(off), Math.cos(off));
|
| 110 |
+
const nose = C.road(c.x + Math.cos(c.h) * 3.2, c.y + Math.sin(c.h) * 3.2).d > -0.5;
|
| 111 |
+
if (speed < 7 && (Math.abs(off) > 0.9 || nose)) {
|
| 112 |
+
const clearBehind = C.road(c.x - Math.cos(c.h) * 3.5, c.y - Math.sin(c.h) * 3.5).d < -0.6, side = off > 0 ? 1 : -1;
|
| 113 |
+
return { keys: steerKeys(c, clearBehind ? -side : side, speed, wscale), thr: clearBehind ? 0 : HOLD_SETS, brk: clearBehind, nos: false, lat, contact: 3, why: 'recover' };
|
| 114 |
+
}
|
| 115 |
+
const kappa = 2 * Math.sin(alpha) / Ld, delta = Math.atan(kappa * P.wheelbase), range = C.steerRange(speed / C.MPH) * Math.PI / 180;
|
| 116 |
+
const vlim = Math.min(C.profileAt(R, prof, S + speed * 0.2), C.profileAt(R, prof, S + speed * 0.45));
|
| 117 |
+
// In a chase, slowing down is what a rolling block wants: a moving cop is steered round or rammed, never braked for.
|
| 118 |
+
const contact = contactTime(g, opt.ram ? others.filter(o => !o.cop) : others, S, speed, lat), over = speed > vlim + 0.8, brk = over || contact < 0.8, coast = !brk && contact < 1.2;
|
| 119 |
+
// Friction circle (carStep): drive force eats lateral capacity, so in a corner the throttle is only what the tyres can spare.
|
| 120 |
+
const grip = (P.grip + P.aero * speed * speed) * tire, ay = speed * speed * Math.abs(kappa), spare = Math.max(0, 1 - ay / grip);
|
| 121 |
+
const allowed = spare / 0.55 * grip * 1.1, drive = Math.max(1, C.driveAt(speed) * P.accel), thr = coast ? 0 : Math.round(HOLD_SETS * C.clamp(allowed / drive, 0.17, 1));
|
| 122 |
+
const nos = !brk && !coast && (opt.forceNos ? c.nos > 0.02 && speed > 12 : c.nos > 0.02 && speed > 18 && opt.nos !== false && thr === HOLD_SETS && C.profileAt(R, prof, S + speed * 1.8) > speed + 8);
|
| 123 |
+
return { keys: steerKeys(c, C.clamp(delta / range, -1, 1), speed, wscale), thr: brk ? 0 : thr, brk, nos, lat, contact, why: over ? 'speed' : contact < 0.8 ? 'contact' : coast ? 'coast' : 'drive' };
|
| 124 |
+
}
|
| 125 |
+
function toPacket(plan, extra = []) {
|
| 126 |
+
const holds = [];
|
| 127 |
+
for (let i = 0; i < HOLD_SETS; i++) {
|
| 128 |
+
const h = [], k = plan.keys ? plan.keys[i] : 0;
|
| 129 |
+
// Throttle is spread evenly through the packet: both ticks of a set see the same keys.
|
| 130 |
+
if (plan.brk) h.push('S'); else if (plan.thr >= HOLD_SETS || Math.floor((i + 1) * plan.thr / HOLD_SETS) > Math.floor(i * plan.thr / HOLD_SETS)) h.push('W');
|
| 131 |
+
if (k) h.push(k > 0 ? 'A' : 'D');
|
| 132 |
+
if (plan.nos) h.push('Shift');
|
| 133 |
+
for (const [key, set] of extra) if (set === i && h.length < 4) h.push(key);
|
| 134 |
+
holds.push(h);
|
| 135 |
+
}
|
| 136 |
+
return { holds, mouse: [0, 0, 0] };
|
| 137 |
+
}
|
| 138 |
+
// Staging, then the line. Pinned for a while: the original's manual reset, which costs the speed that was left, so never a first resort.
|
| 139 |
+
const drive = (g, opt) => { if (g.pre > 0.21) return toPacket({ thr: HOLD_SETS, brk: false, nos: false }); let cop = Infinity; for (const k of g.cops) if (!k.dead && !k.gone) cop = Math.min(cop, Math.hypot(g.car.x - k.x, g.car.y - k.y)); return toPacket(planDrive(g, opt), g.slowT > 2.5 && cop > 90 ? [['R', 0]] : []); }; // a reset near a cop flashes the car: bust distance x6, rate x4 (AIPursuit.cpp:1895-1909)
|
| 140 |
+
M.ctl = { planDrive, toPacket, rollout, roadUsers, copyCar, drive };
|
| 141 |
+
M.scripted = function (g) {
|
| 142 |
+
const mode = M.MODES[g.key];
|
| 143 |
+
if (mode.scripted) return mode.scripted(g); // an event with its own rules plans its own staging too
|
| 144 |
+
return drive(g, {});
|
| 145 |
+
};
|
| 146 |
+
M.oracle = M.scripted;
|
| 147 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/quake2_remake/compact_actions.json
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/compact-actions@1",
|
| 3 |
+
"game": "quake2_remake",
|
| 4 |
+
"version": "quake2-compact@1",
|
| 5 |
+
"note": "ViZDoom-style button set: 8-way movement with run held (Shift, held in 100% of reference packets), yaw by fixed angles, a small pitch head (freelook), and one head for fire / late fire / jump / next weapon (never needed together). Late fire presses J only in sub-steps 5-6, the way the reference controller starts every burst. Previous weapon (R), crouch (L) and keyboard turn (Q/E) are left out: the weapon order cycles, so next alone reaches every weapon. One action = one 200 ms packet. Mouse: 1 count = m_yaw 0.022 x sensitivity 3 = 0.066 deg (same for pitch), so dx 152 = 10 deg; dy > 0 looks down. Sizes 9 x 7 x 3 x 5 = 945.",
|
| 6 |
+
"heads": [
|
| 7 |
+
{
|
| 8 |
+
"name": "move",
|
| 9 |
+
"options": [
|
| 10 |
+
{
|
| 11 |
+
"label": "none"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"label": "forward",
|
| 15 |
+
"keys": [
|
| 16 |
+
"W",
|
| 17 |
+
"Shift"
|
| 18 |
+
]
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"label": "back",
|
| 22 |
+
"keys": [
|
| 23 |
+
"S",
|
| 24 |
+
"Shift"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"label": "left",
|
| 29 |
+
"keys": [
|
| 30 |
+
"A",
|
| 31 |
+
"Shift"
|
| 32 |
+
]
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"label": "right",
|
| 36 |
+
"keys": [
|
| 37 |
+
"D",
|
| 38 |
+
"Shift"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"label": "forward_left",
|
| 43 |
+
"keys": [
|
| 44 |
+
"W",
|
| 45 |
+
"A",
|
| 46 |
+
"Shift"
|
| 47 |
+
]
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"label": "forward_right",
|
| 51 |
+
"keys": [
|
| 52 |
+
"W",
|
| 53 |
+
"D",
|
| 54 |
+
"Shift"
|
| 55 |
+
]
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"label": "back_left",
|
| 59 |
+
"keys": [
|
| 60 |
+
"S",
|
| 61 |
+
"A",
|
| 62 |
+
"Shift"
|
| 63 |
+
]
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"label": "back_right",
|
| 67 |
+
"keys": [
|
| 68 |
+
"S",
|
| 69 |
+
"D",
|
| 70 |
+
"Shift"
|
| 71 |
+
]
|
| 72 |
+
}
|
| 73 |
+
]
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"name": "turn",
|
| 77 |
+
"options": [
|
| 78 |
+
{
|
| 79 |
+
"label": "none"
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"label": "left_3",
|
| 83 |
+
"dx": -45
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"label": "right_3",
|
| 87 |
+
"dx": 45
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"label": "left_10",
|
| 91 |
+
"dx": -152
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"label": "right_10",
|
| 95 |
+
"dx": 152
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"label": "left_30",
|
| 99 |
+
"dx": -455
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"label": "right_30",
|
| 103 |
+
"dx": 455
|
| 104 |
+
}
|
| 105 |
+
]
|
| 106 |
+
},
|
| 107 |
+
{
|
| 108 |
+
"name": "pitch",
|
| 109 |
+
"options": [
|
| 110 |
+
{
|
| 111 |
+
"label": "none"
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"label": "up_2",
|
| 115 |
+
"dy": -30
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"label": "down_2",
|
| 119 |
+
"dy": 30
|
| 120 |
+
}
|
| 121 |
+
]
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"name": "action",
|
| 125 |
+
"options": [
|
| 126 |
+
{
|
| 127 |
+
"label": "none"
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"label": "fire",
|
| 131 |
+
"keys": [
|
| 132 |
+
"J"
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"label": "fire_late",
|
| 137 |
+
"subs": [
|
| 138 |
+
[],
|
| 139 |
+
[],
|
| 140 |
+
[],
|
| 141 |
+
[],
|
| 142 |
+
[
|
| 143 |
+
"J"
|
| 144 |
+
],
|
| 145 |
+
[
|
| 146 |
+
"J"
|
| 147 |
+
]
|
| 148 |
+
]
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"label": "jump",
|
| 152 |
+
"tap": [
|
| 153 |
+
"Space"
|
| 154 |
+
]
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"label": "next_weapon",
|
| 158 |
+
"tap": [
|
| 159 |
+
"K"
|
| 160 |
+
]
|
| 161 |
+
}
|
| 162 |
+
]
|
| 163 |
+
}
|
| 164 |
+
]
|
| 165 |
+
}
|
environments/games/web/games/quake2_remake/draw.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Quake II boss arenas - Module.draw: the WebGL first-person view plus a Canvas 2D HUD in the Quake II layout
|
| 2 |
+
(health / ammo / armor numbers along the bottom, pickup string, pain flash), with BossBench additions: boss name,
|
| 3 |
+
health bar and phase, fight timer, skill / tier and the native tick rate. Read-only on the game state. */
|
| 4 |
+
(function (root) {
|
| 5 |
+
'use strict';
|
| 6 |
+
const M = root.Quake2Game, Q = M.Q, R = M.R3;
|
| 7 |
+
const WEAPON_LABEL = { blaster: 'ENERGY PISTOL', shotgun: 'SHOTGUN', supershotgun: 'DOUBLE SHOTGUN', machinegun: 'MACHINEGUN', chaingun: 'CHAINGUN',
|
| 8 |
+
rocketlauncher: 'ROCKET LAUNCHER', hyperblaster: 'PULSE CANNON', railgun: 'COILGUN' };
|
| 9 |
+
const AMMO_LABEL = { shells: 'SHELLS', bullets: 'BULLETS', rockets: 'ROCKETS', cells: 'CELLS', slugs: 'SLUGS' };
|
| 10 |
+
const ITEM_LABEL = { health: 'Health', health_large: 'Large Health', stimpack: 'Med Injector', armor_shard: 'Armor Shard', armor_jacket: 'Jacket Armor',
|
| 11 |
+
armor_combat: 'Combat Armor', armor_body: 'Body Armor', ammo_shells: 'Shells', ammo_bullets: 'Bullets', ammo_cells: 'Cells', ammo_rockets: 'Rockets', ammo_slugs: 'Slugs' };
|
| 12 |
+
const MOVE_LABEL = {
|
| 13 |
+
monster_supertank: { attack1: 'Chain-gun burst', end_attack1: 'Chain-gun cooldown', attack2: 'Triple rockets', pain1: 'Hurt', pain2: 'Hurt', pain3: 'Hurt', death: 'Explosion' },
|
| 14 |
+
monster_boss2: { attack_pre_mg: 'Twin guns spin up', attack_mg: 'Twin machine guns', attack_post_mg: 'Machine guns wind down', attack_rocket: 'Rocket salvo', pain_light: 'Hurt', pain_heavy: 'Heavy hit', death: 'Crash' },
|
| 15 |
+
monster_jorg: { start_attack1: 'Twin chain guns spin up', attack1: 'Twin chain guns', end_attack1: 'Chain guns wind down', attack2: 'Energy orb', pain1: 'Hurt', pain2: 'Hurt', pain3: 'Heavy hit', death: 'Collapse' },
|
| 16 |
+
monster_makron: { sight: 'Leap out', attack3: 'Energy orb', attack4: 'Energy burst', attack5: 'Railgun aiming', pain4: 'Hurt', pain5: 'Hurt', pain6: 'Heavy hit', death2: 'Fall' },
|
| 17 |
+
monster_tank_commander: { attack_blast: 'Triple blaster shot', reattack_blast: 'Blaster follow-up', attack_post_blast: 'Weapon lowered', attack_pre_rocket: 'Rockets ready', attack_fire_rocket: 'Triple rockets',
|
| 18 |
+
attack_post_rocket: 'Rockets end', attack_chain: 'Chain-gun sweep', attack_strike: 'heavy punch', start_run: 'Launch', pain1: 'Hurt', pain2: 'Hurt', pain3: 'Heavy hit', death: 'Fall' },
|
| 19 |
+
monster_gladiator: { attack_melee: 'Blade slash', attack_gun: 'Railgun aiming', pain: 'Hurt', pain_air: 'Hurt', death: 'Fall' },
|
| 20 |
+
monster_mutant: { attack: 'Claw combo', jump: 'Pounce', pain1: 'Hurt', pain2: 'Hurt', pain3: 'Hurt', death1: 'Fall', death2: 'Fall' },
|
| 21 |
+
};
|
| 22 |
+
function panel(c, x, y, w, h) { c.fillStyle = 'rgba(14,12,10,0.62)'; c.fillRect(x, y, w, h); c.strokeStyle = 'rgba(180,150,90,0.45)'; c.lineWidth = 1; c.strokeRect(x + 0.5, y + 0.5, w - 1, h - 1); }
|
| 23 |
+
function bigNumber(c, value, x, y, color, label) {
|
| 24 |
+
c.textAlign = 'right'; c.font = 'bold 34px Consolas, "Courier New", monospace'; c.fillStyle = '#000a'; c.fillText(String(value), x + 2, y + 2);
|
| 25 |
+
c.fillStyle = color; c.fillText(String(value), x, y);
|
| 26 |
+
c.font = '11px Consolas, monospace'; c.fillStyle = '#c8b88a'; c.fillText(label, x, y + 14); c.textAlign = 'left';
|
| 27 |
+
}
|
| 28 |
+
M.draw = function (g, c) {
|
| 29 |
+
R.render(g, c);
|
| 30 |
+
const p = g.ents[1], W = 854, H = 480;
|
| 31 |
+
// pain / pickup blend (SV_CalcBlend damage_alpha, bonus_alpha)
|
| 32 |
+
if (p.damage_alpha > 0) { c.fillStyle = 'rgba(200,20,10,' + Math.min(0.55, p.damage_alpha) + ')'; c.fillRect(0, 0, W, H); }
|
| 33 |
+
if (p.bonus_alpha > 0) { c.fillStyle = 'rgba(255,230,120,' + Math.min(0.3, p.bonus_alpha) + ')'; c.fillRect(0, 0, W, H); }
|
| 34 |
+
if (p.health <= 0) { c.fillStyle = 'rgba(90,0,0,0.35)'; c.fillRect(0, 0, W, H); }
|
| 35 |
+
// crosshair
|
| 36 |
+
if (p.health > 0) { c.strokeStyle = 'rgba(255,240,200,0.85)'; c.lineWidth = 1.5; c.beginPath(); c.moveTo(W / 2 - 7, H / 2); c.lineTo(W / 2 - 2, H / 2); c.moveTo(W / 2 + 2, H / 2); c.lineTo(W / 2 + 7, H / 2);
|
| 37 |
+
c.moveTo(W / 2, H / 2 - 7); c.lineTo(W / 2, H / 2 - 2); c.moveTo(W / 2, H / 2 + 2); c.lineTo(W / 2, H / 2 + 7); c.stroke(); }
|
| 38 |
+
// direction of the last hit: relative yaw (Quake yaw grows to the left) -> rotation of an "ahead" marker
|
| 39 |
+
if (p.damage_alpha > 0.05 && p.damage_from_dir) {
|
| 40 |
+
const yaw = Math.atan2(p.damage_from_dir[1], p.damage_from_dir[0]) * 180 / Math.PI - p.v_angle[1], a = -yaw * Math.PI / 180;
|
| 41 |
+
c.save(); c.translate(W / 2, H / 2); c.rotate(a); c.fillStyle = 'rgba(255,60,40,' + Math.min(0.9, p.damage_alpha * 1.6) + ')';
|
| 42 |
+
c.beginPath(); c.moveTo(0, -120); c.lineTo(-14, -98); c.lineTo(14, -98); c.closePath(); c.fill(); c.restore();
|
| 43 |
+
}
|
| 44 |
+
// bottom status bar (Quake II order: ammo | health | armor)
|
| 45 |
+
panel(c, 8, H - 58, 838, 50);
|
| 46 |
+
const it = Q.ITEMS[p.weapon] || {}, ammo = it.ammo ? p.inv[it.ammo] : null;
|
| 47 |
+
bigNumber(c, ammo === null ? '--' : ammo, 120, H - 22, ammo !== null && ammo < 5 ? '#ff7050' : '#f0d070', it.ammo ? AMMO_LABEL[it.ammo] : 'NO AMMO');
|
| 48 |
+
bigNumber(c, Math.max(0, p.health), 300, H - 22, p.health < 25 ? '#ff5040' : '#f0d070', 'HEALTH');
|
| 49 |
+
const ak = Q.armorIndex(p);
|
| 50 |
+
bigNumber(c, ak ? p.inv[ak] : 0, 470, H - 22, '#9fd27a', ak ? ak.toUpperCase() + ' ARMOR' : 'ARMOR');
|
| 51 |
+
c.font = 'bold 13px Consolas, monospace'; c.fillStyle = '#e8dcb8'; c.fillText(WEAPON_LABEL[p.weapon] || '', 500, H - 36);
|
| 52 |
+
c.font = '11px Consolas, monospace'; c.fillStyle = '#a99e84';
|
| 53 |
+
const inv = Q.WEAPON_ORDER.filter(w => p.inv[w]).map(w => (w === p.weapon ? '[' : ' ') + WEAPON_LABEL[w].split(' ')[0].slice(0, 7) + (w === p.weapon ? ']' : ' ')).join('');
|
| 54 |
+
c.fillText(inv, 500, H - 19);
|
| 55 |
+
// clock: fight timer and the native tick rate (meeting rule: HUD shows the Hz)
|
| 56 |
+
panel(c, 676, 8, 170, 46); c.textAlign = 'right'; c.font = 'bold 18px Consolas, monospace'; c.fillStyle = '#f0e4c0';
|
| 57 |
+
c.fillText((g.t / M.hz).toFixed(1) + ' s', 838, 30); c.font = 'bold 12px Consolas, monospace'; c.fillStyle = '#9fd0ff'; c.fillText(M.hz + 'Hz · tick ' + g.t, 838, 46); c.textAlign = 'left';
|
| 58 |
+
// boss bar
|
| 59 |
+
const h = g.health(), bi = g.bossEnt(), b = g.ents[bi], def = Q.MONSTERS[b.classname] || {};
|
| 60 |
+
panel(c, 187, 8, 480, 46);
|
| 61 |
+
const frac = h[3] ? h[2] / h[3] : 0;
|
| 62 |
+
c.fillStyle = '#2a1410'; c.fillRect(197, 30, 460, 14);
|
| 63 |
+
c.fillStyle = b.classname === 'monster_makron' ? '#c040e0' : '#d23a20'; c.fillRect(197, 30, 460 * frac, 14);
|
| 64 |
+
if (g.bossClass === 'monster_jorg') { const split = g.makronHealth / h[3]; c.fillStyle = '#f2e6c0'; c.fillRect(197 + 460 * split - 1, 28, 2, 18); }
|
| 65 |
+
c.font = 'bold 14px "Segoe UI", "Microsoft YaHei", sans-serif'; c.fillStyle = '#f2e6c0';
|
| 66 |
+
const phase = g.bossClass === 'monster_jorg' ? (b.classname === 'monster_makron' ? 'Second form' : 'First form') : 'Single phase';
|
| 67 |
+
c.fillText((def.name || '') + ' · ' + phase, 197, 24);
|
| 68 |
+
const mv = (b.monsterinfo && MOVE_LABEL[b.classname] && MOVE_LABEL[b.classname][b.monsterinfo.currentmove]) || (b.deadflag ? 'Fall' : 'Chase');
|
| 69 |
+
c.textAlign = 'right'; c.font = '12px "Segoe UI", "Microsoft YaHei", sans-serif'; c.fillStyle = '#e8b070';
|
| 70 |
+
c.fillText(mv + ' ' + Math.ceil(h[2]) + ' / ' + h[3], 657, 24); c.textAlign = 'left';
|
| 71 |
+
// skill / tier tag
|
| 72 |
+
panel(c, 8, 8, 170, 46);
|
| 73 |
+
c.font = 'bold 12px Consolas, monospace'; c.fillStyle = '#f0d070'; c.fillText('QUAKE II · ' + M.skillNames[g.skill].toUpperCase(), 16, 26);
|
| 74 |
+
c.font = '11px Consolas, monospace'; c.fillStyle = '#a99e84'; c.fillText('skill ' + g.skill + (g.tier ? ' · tier ' + g.tier : '') + ' · d=' + g.d, 16, 44);
|
| 75 |
+
// pickup message (3 s, like STAT_PICKUP_STRING)
|
| 76 |
+
if (p.pickup && g.ms < p.pickup_time) { c.font = '14px "Segoe UI", sans-serif'; c.fillStyle = '#f2e6c0'; c.textAlign = 'center'; c.fillText(ITEM_LABEL[p.pickup] || p.pickup, W / 2, H - 70); c.textAlign = 'left'; }
|
| 77 |
+
// telegraphs: railguns lock the shot ahead of time (Makron one frame, Gladiator 0.4 s); the Mutant's leap
|
| 78 |
+
const tele = (text, color) => { c.font = 'bold 15px "Segoe UI", "Microsoft YaHei", sans-serif'; c.fillStyle = color; c.textAlign = 'center'; c.fillText(text, W / 2, 78); c.textAlign = 'left'; };
|
| 79 |
+
const mvName = b.monsterinfo && !b.deadflag ? b.monsterinfo.currentmove : null;
|
| 80 |
+
if (b.classname === 'monster_makron' && mvName === 'attack5' && b.frame >= 235 && b.frame <= 242) tele(b.frame >= 241 ? 'Railgun locked on! Strafe!' : 'Railgun charging', '#7fc8ff');
|
| 81 |
+
if (b.classname === 'monster_gladiator' && mvName === 'attack_gun' && b.frame <= 48) tele('Railgun aimed at your previous position — strafe!', '#7fc8ff');
|
| 82 |
+
if (b.classname === 'monster_mutant' && mvName === 'jump' && b.frame <= 4) tele('Pounce!', '#ff9a60');
|
| 83 |
+
if (b.classname === 'monster_tank_commander' && mvName === 'attack_chain') tele('Chain-gun sweep: get behind cover', '#ffd070');
|
| 84 |
+
// result banner: above the centre, where the play page puts its own result box over the canvas
|
| 85 |
+
if (g.outcome) {
|
| 86 |
+
c.fillStyle = 'rgba(8,6,4,0.55)'; c.fillRect(0, 96, W, 80);
|
| 87 |
+
c.textAlign = 'center'; c.font = 'bold 30px "Segoe UI", "Microsoft YaHei", sans-serif';
|
| 88 |
+
c.fillStyle = g.outcome === 'win' ? '#f0d070' : '#ff6a50';
|
| 89 |
+
c.fillText(g.outcome === 'win' ? 'Boss defeated · ' + (g.t / M.hz).toFixed(1) + ' s' : g.outcome === 'loss' ? 'You died' : 'Time up', W / 2, 147); c.textAlign = 'left';
|
| 90 |
+
}
|
| 91 |
+
};
|
| 92 |
+
M.renderStatus = ctx => R.status(ctx);
|
| 93 |
+
M.renderMetrics = ctx => R.metrics(ctx);
|
| 94 |
+
M.closeRenderer = ctx => R.close(ctx);
|
| 95 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/quake2_remake/game.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Quake II (1997) boss arenas, rules q2-arena@4 - the BossBench module: cases, tiers, original arenas, the server
|
| 2 |
+
frame (sv_main.c SV_Frame -> SV_RunGameFrame -> g_main.c G_RunFrame) and the public declaration.
|
| 3 |
+
Native clock (q2-arena@3, 2026-11-06): 60 Hz, the original client at cl_maxfps 60. One BossBench tick = one host
|
| 4 |
+
frame of 16/17 ms: one usercmd (ClientThink -> Pmove, cmd.msec 16/17) and entity physics for that slice. Game
|
| 5 |
+
logic keeps the original 10 Hz server frame (g_local.h FRAMETIME 0.1): thinks fire on nextthink in ms, and the
|
| 6 |
+
server-frame parts run on every sixth tick. A 200 ms action packet is twelve ticks. See
|
| 7 |
+
Independent reimplementation from id Software's GPL-2.0 source release (commit
|
| 8 |
+
372afde46e7defc9dd2d719a1732b8ace1fa096e). Arenas, items placement and loadouts are original; all art is
|
| 9 |
+
procedural; no game data (pak, models, textures, sounds, maps) is used. */
|
| 10 |
+
(function (root) {
|
| 11 |
+
'use strict';
|
| 12 |
+
const N = root.NativeBench, M = root.Quake2Game, Q = M.Q;
|
| 13 |
+
const { copy3 } = Q;
|
| 14 |
+
|
| 15 |
+
// ---------------- public tiers (2026-11-02) ----------------
|
| 16 |
+
// Tiers on Quake II's skill cvar: easy = skill 0 Easy (the player takes half damage, the default M_CheckAttack
|
| 17 |
+
// chance is halved), normal = skill 1 Medium, hard = skill 3 Hard+ (no boss pain animations and a 5 s pain lock-out:
|
| 18 |
+
// the only skill rule that raises the aggression of every boss; it includes the skill >= 2 rules: attack chance
|
| 19 |
+
// doubled, the Super Tank and the Tank Commander ignore pain while firing, the Tank Commander refires). d in [0.6, 0.8)
|
| 20 |
+
// is skill 2 Hard. All of this is the original game's own skill cvar with its own parameters, the same fight on every
|
| 21 |
+
// tier, so hard stays at 0.9. Boss spawn health per tier is a BossBench extension (Quake II never scales monster
|
| 22 |
+
// health), calibrated to the script windows, which are the criterion (easy 20-30 s, normal 45-90 s, hard 150-240 s; the
|
| 23 |
+
// meeting's ~500 health is only an order of magnitude): anchors at the three tier values, linear between them, held outside.
|
| 24 |
+
const TIERS = { easy: 0.15, normal: 0.45, hard: 0.9 }, TIER_D = [TIERS.easy, TIERS.normal, TIERS.hard];
|
| 25 |
+
const HEALTH = {
|
| 26 |
+
monster_supertank: [650, 4500, 10400],
|
| 27 |
+
monster_boss2: [620, 5000, 12500],
|
| 28 |
+
monster_jorg: [260, 2700, 6600],
|
| 29 |
+
monster_makron: [220, 2250, 5500],
|
| 30 |
+
monster_tank_commander: [750, 5000, 10500],
|
| 31 |
+
monster_gladiator: [780, 5000, 14000],
|
| 32 |
+
monster_mutant: [800, 5500, 13000],
|
| 33 |
+
};
|
| 34 |
+
const SKILL_NAMES = ['Easy', 'Medium', 'Hard', 'Hard+'];
|
| 35 |
+
const skillOf = d => d < 0.3 ? 0 : d < 0.6 ? 1 : d < 0.8 ? 2 : 3;
|
| 36 |
+
const tierOf = d => Object.keys(TIERS).find(t => Math.abs(TIERS[t] - d) < 1e-9) || null;
|
| 37 |
+
function healthOf(classname, d) {
|
| 38 |
+
const h = HEALTH[classname];
|
| 39 |
+
if (d <= TIER_D[0]) return h[0];
|
| 40 |
+
if (d >= TIER_D[2]) return h[2];
|
| 41 |
+
const k = d <= TIER_D[1] ? 0 : 1, f = (d - TIER_D[k]) / (TIER_D[k + 1] - TIER_D[k]);
|
| 42 |
+
return Math.round(h[k] + (h[k + 1] - h[k]) * f);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
// ---------------- original arenas (Quake II map units, z up; brushes are axis-aligned boxes) ----------------
|
| 46 |
+
const B = (x0, y0, z0, x1, y1, z1, mat, extra) => Object.assign({ mins: [x0, y0, z0], maxs: [x1, y1, z1], contents: Q.CONTENTS_SOLID, mat }, extra || {});
|
| 47 |
+
function shell(w, h, height, opts) { // floor, four walls, ceiling (sky or roof)
|
| 48 |
+
const t = 64, out = [B(-t, -t, -t, w + t, h + t, 0, opts.floor || 'floor')];
|
| 49 |
+
out.push(B(-t, -t, 0, 0, h + t, height, opts.wall || 'wall'), B(w, -t, 0, w + t, h + t, height, opts.wall || 'wall'));
|
| 50 |
+
out.push(B(0, -t, 0, w, 0, height, opts.wall || 'wall'), B(0, h, 0, w, h + t, height, opts.wall || 'wall'));
|
| 51 |
+
out.push(B(-t, -t, height, w + t, h + t, height + t, opts.sky ? 'sky' : 'roof', opts.sky ? { sky: true } : null));
|
| 52 |
+
return out;
|
| 53 |
+
}
|
| 54 |
+
const ARENAS = {
|
| 55 |
+
// Super Tank: a walled Strogg supply yard under an open sky; crate stacks and two pylons give cover against the
|
| 56 |
+
// hitscan chaingun, the open middle lets the rockets be side-stepped.
|
| 57 |
+
supertank: {
|
| 58 |
+
title: 'Walled supply yard (original layout)', size: [1664, 1664, 384], sky: 'dusk',
|
| 59 |
+
brushes: () => [...shell(1664, 1664, 384, { sky: true, wall: 'wall' }),
|
| 60 |
+
B(360, 520, 0, 456, 616, 96, 'crate'), B(1208, 520, 0, 1304, 616, 96, 'crate'),
|
| 61 |
+
B(360, 1048, 0, 456, 1144, 96, 'crate'), B(1208, 1048, 0, 1304, 1144, 96, 'crate'),
|
| 62 |
+
B(392, 552, 96, 456, 616, 160, 'crate'), B(1208, 1080, 96, 1272, 1144, 160, 'crate'),
|
| 63 |
+
B(768, 780, 0, 896, 884, 320, 'pylon'),
|
| 64 |
+
B(96, 760, 0, 160, 904, 64, 'tech'), B(1504, 760, 0, 1568, 904, 64, 'tech'),
|
| 65 |
+
B(560, 300, 0, 736, 340, 80, 'barrier'), B(928, 300, 0, 1104, 340, 80, 'barrier'),
|
| 66 |
+
],
|
| 67 |
+
player: { origin: [832, 200, 24], yaw: 90 },
|
| 68 |
+
boss: { classname: 'monster_supertank', origin: [832, 1430, 0], yaw: 270 },
|
| 69 |
+
loadout: { weapons: ['blaster', 'shotgun', 'supershotgun', 'machinegun', 'rocketlauncher'], weapon: 'rocketlauncher',
|
| 70 |
+
ammo: { shells: 100, bullets: 200, rockets: 50 }, armor: ['combat', 50] },
|
| 71 |
+
items: [['health_large', 160, 160], ['health_large', 1504, 160], ['health', 160, 1504], ['health', 1504, 1504],
|
| 72 |
+
['health_large', 408, 832], ['health_large', 1256, 832], ['health', 832, 230], ['armor_jacket', 832, 1300],
|
| 73 |
+
['ammo_rockets', 120, 832], ['ammo_rockets', 1544, 832], ['ammo_rockets', 832, 1544], ['ammo_rockets', 600, 120], ['ammo_rockets', 1064, 120],
|
| 74 |
+
['ammo_shells', 832, 120], ['ammo_bullets', 120, 1200], ['ammo_bullets', 1544, 1200], ['armor_shard', 408, 680], ['armor_shard', 1256, 680],
|
| 75 |
+
['armor_shard', 408, 984], ['armor_shard', 1256, 984], ['stimpack', 640, 160], ['stimpack', 1024, 160]],
|
| 76 |
+
},
|
| 77 |
+
// Hornet: a tall hangar bay; the boss flies at the player's eye level, cargo blocks can hide the player from
|
| 78 |
+
// the twin machineguns but not from rockets over the top.
|
| 79 |
+
hornet: {
|
| 80 |
+
title: 'Hangar bay (original layout)', size: [1792, 1792, 512], sky: 'none',
|
| 81 |
+
brushes: () => [...shell(1792, 1792, 512, { sky: false, wall: 'hangar' }),
|
| 82 |
+
B(380, 640, 0, 572, 736, 128, 'cargo'), B(1220, 640, 0, 1412, 736, 128, 'cargo'),
|
| 83 |
+
B(380, 1056, 0, 572, 1152, 128, 'cargo'), B(1220, 1056, 0, 1412, 1152, 128, 'cargo'),
|
| 84 |
+
B(832, 832, 0, 960, 960, 512, 'pylon'),
|
| 85 |
+
B(0, 1600, 0, 1792, 1792, 48, 'tech'),
|
| 86 |
+
],
|
| 87 |
+
player: { origin: [896, 220, 24], yaw: 90 },
|
| 88 |
+
boss: { classname: 'monster_boss2', origin: [896, 1380, 72], yaw: 270 },
|
| 89 |
+
loadout: { weapons: ['blaster', 'machinegun', 'chaingun', 'hyperblaster', 'railgun'], weapon: 'chaingun',
|
| 90 |
+
ammo: { bullets: 200, cells: 200, slugs: 50 }, armor: ['combat', 50] },
|
| 91 |
+
items: [['health_large', 160, 160], ['health_large', 1632, 160], ['health', 160, 896], ['health', 1632, 896],
|
| 92 |
+
['ammo_bullets', 896, 120], ['ammo_bullets', 896, 1500], ['ammo_slugs', 120, 520], ['ammo_slugs', 1672, 520], ['ammo_slugs', 120, 1300], ['ammo_slugs', 1672, 1300],
|
| 93 |
+
['ammo_cells', 896, 600], ['ammo_cells', 300, 900],
|
| 94 |
+
['armor_shard', 476, 600], ['armor_shard', 1316, 600], ['stimpack', 680, 160], ['stimpack', 1112, 160]],
|
| 95 |
+
},
|
| 96 |
+
// Jorg + Makron: the final showdown chamber; four broad pillars for the chaingun stream, enough room for the
|
| 97 |
+
// 160-unit Jorg to walk around them and for BFG orbs to be outrun.
|
| 98 |
+
makron: {
|
| 99 |
+
title: 'Final showdown chamber (original layout)', size: [1920, 1920, 448], sky: 'none',
|
| 100 |
+
brushes: () => [...shell(1920, 1920, 448, { sky: false, wall: 'strogg' }),
|
| 101 |
+
B(480, 480, 0, 640, 640, 448, 'pillar'), B(1280, 480, 0, 1440, 640, 448, 'pillar'),
|
| 102 |
+
B(480, 1280, 0, 640, 1440, 448, 'pillar'), B(1280, 1280, 0, 1440, 1440, 448, 'pillar'),
|
| 103 |
+
B(864, 864, 0, 1056, 1056, 24, 'dais'),
|
| 104 |
+
],
|
| 105 |
+
player: { origin: [960, 200, 24], yaw: 90 },
|
| 106 |
+
boss: { classname: 'monster_jorg', origin: [960, 1560, 0], yaw: 270 },
|
| 107 |
+
loadout: { weapons: ['blaster', 'supershotgun', 'chaingun', 'rocketlauncher', 'hyperblaster', 'railgun'], weapon: 'railgun',
|
| 108 |
+
ammo: { shells: 50, bullets: 200, rockets: 50, cells: 200, slugs: 50 }, armor: ['body', 100] },
|
| 109 |
+
items: [['health_large', 160, 160], ['health_large', 1760, 160], ['health_large', 160, 1760], ['health_large', 1760, 1760],
|
| 110 |
+
['health', 960, 140], ['ammo_slugs', 300, 960], ['ammo_slugs', 1620, 960], ['ammo_rockets', 960, 360], ['ammo_cells', 960, 1760],
|
| 111 |
+
['armor_shard', 560, 720], ['armor_shard', 1360, 720], ['armor_shard', 560, 1200], ['armor_shard', 1360, 1200],
|
| 112 |
+
['stimpack', 760, 160], ['stimpack', 1160, 160]],
|
| 113 |
+
},
|
| 114 |
+
// Tank Commander: a Strogg factory floor. Machine blocks stop the chaingun sweep (19 hitscan bullets of 20 fired
|
| 115 |
+
// along a fixed +-40 degree arc), the open aisles leave room to side-step blaster bolts and rockets.
|
| 116 |
+
tank_commander: {
|
| 117 |
+
title: 'Factory floor (original layout)', size: [1792, 1792, 448], sky: 'none',
|
| 118 |
+
brushes: () => [...shell(1792, 1792, 448, { sky: false, wall: 'factory' }),
|
| 119 |
+
B(352, 560, 0, 608, 688, 160, 'machine'), B(1184, 560, 0, 1440, 688, 160, 'machine'),
|
| 120 |
+
B(352, 1104, 0, 608, 1232, 160, 'machine'), B(1184, 1104, 0, 1440, 1232, 160, 'machine'),
|
| 121 |
+
B(832, 832, 0, 960, 960, 448, 'pylon'),
|
| 122 |
+
B(640, 320, 0, 800, 352, 72, 'barrier'), B(992, 320, 0, 1152, 352, 72, 'barrier'),
|
| 123 |
+
],
|
| 124 |
+
player: { origin: [896, 180, 24], yaw: 90 },
|
| 125 |
+
boss: { classname: 'monster_tank_commander', origin: [896, 1500, 24], yaw: 270 },
|
| 126 |
+
loadout: { weapons: ['blaster', 'shotgun', 'supershotgun', 'machinegun', 'chaingun', 'rocketlauncher'], weapon: 'rocketlauncher',
|
| 127 |
+
ammo: { shells: 100, bullets: 200, rockets: 50 }, armor: ['combat', 50] },
|
| 128 |
+
items: [['health_large', 160, 160], ['health_large', 1632, 160], ['health', 160, 1632], ['health', 1632, 1632],
|
| 129 |
+
['health_large', 480, 896], ['health_large', 1312, 896], ['ammo_rockets', 120, 896], ['ammo_rockets', 1672, 896],
|
| 130 |
+
['ammo_rockets', 896, 1672], ['ammo_rockets', 560, 120], ['ammo_rockets', 1232, 120], ['ammo_bullets', 896, 120],
|
| 131 |
+
['ammo_shells', 480, 1400], ['ammo_shells', 1312, 1400], ['armor_shard', 480, 760], ['armor_shard', 1312, 760],
|
| 132 |
+
['armor_shard', 480, 1032], ['armor_shard', 1312, 1032], ['stimpack', 720, 200], ['stimpack', 1072, 200]],
|
| 133 |
+
},
|
| 134 |
+
// Gladiator: an open-sky fighting pit. A ring of six columns breaks the railgun's line (aimed at the spot the
|
| 135 |
+
// player stood on 0.4 s before the shot); the floor is flat so the cleaver can always be out-run.
|
| 136 |
+
gladiator: {
|
| 137 |
+
title: 'Fighting pit (original layout)', size: [1664, 1664, 384], sky: 'dusk',
|
| 138 |
+
brushes: () => [...shell(1664, 1664, 384, { sky: true, wall: 'arena' }),
|
| 139 |
+
B(800, 400, 0, 864, 464, 320, 'column'), B(800, 1200, 0, 864, 1264, 320, 'column'),
|
| 140 |
+
B(456, 600, 0, 520, 664, 320, 'column'), B(1144, 600, 0, 1208, 664, 320, 'column'),
|
| 141 |
+
B(456, 1000, 0, 520, 1064, 320, 'column'), B(1144, 1000, 0, 1208, 1064, 320, 'column'),
|
| 142 |
+
B(96, 96, 0, 224, 224, 64, 'arena'), B(1440, 96, 0, 1568, 224, 64, 'arena'),
|
| 143 |
+
B(96, 1440, 0, 224, 1568, 64, 'arena'), B(1440, 1440, 0, 1568, 1568, 64, 'arena'),
|
| 144 |
+
],
|
| 145 |
+
player: { origin: [832, 180, 24], yaw: 90 },
|
| 146 |
+
boss: { classname: 'monster_gladiator', origin: [832, 1480, 32], yaw: 270 },
|
| 147 |
+
loadout: { weapons: ['blaster', 'shotgun', 'supershotgun', 'chaingun', 'rocketlauncher', 'hyperblaster'], weapon: 'rocketlauncher',
|
| 148 |
+
ammo: { shells: 50, bullets: 200, rockets: 50, cells: 200 }, armor: ['combat', 50] },
|
| 149 |
+
items: [['health_large', 300, 300], ['health_large', 1364, 300], ['health', 300, 1364], ['health', 1364, 1364],
|
| 150 |
+
['health_large', 832, 832], ['ammo_rockets', 120, 832], ['ammo_rockets', 1544, 832], ['ammo_rockets', 832, 1544],
|
| 151 |
+
['ammo_rockets', 600, 120], ['ammo_rockets', 1064, 120], ['ammo_cells', 832, 640], ['ammo_cells', 832, 1024],
|
| 152 |
+
['ammo_bullets', 640, 832], ['ammo_bullets', 1024, 832], ['armor_shard', 488, 760], ['armor_shard', 1176, 760],
|
| 153 |
+
['armor_shard', 488, 904], ['armor_shard', 1176, 904], ['stimpack', 640, 200], ['stimpack', 1024, 200]],
|
| 154 |
+
},
|
| 155 |
+
// Mutant: a containment lab. No ranged attack: the mutant claws at 80 units and leaps (600 forward, 250 up) from
|
| 156 |
+
// 100 units out; the long benches (48 high: above the 18 step, above its 39-unit leap) and the pillars are what the
|
| 157 |
+
// player kites it around.
|
| 158 |
+
mutant: {
|
| 159 |
+
title: 'Containment lab (original layout)', size: [1920, 1600, 384], sky: 'none',
|
| 160 |
+
brushes: () => [...shell(1920, 1600, 384, { sky: false, wall: 'lab' }),
|
| 161 |
+
B(480, 560, 0, 864, 624, 48, 'bench'), B(1056, 560, 0, 1440, 624, 48, 'bench'),
|
| 162 |
+
B(480, 976, 0, 864, 1040, 48, 'bench'), B(1056, 976, 0, 1440, 1040, 48, 'bench'),
|
| 163 |
+
B(272, 768, 0, 368, 864, 384, 'column'), B(1552, 768, 0, 1648, 864, 384, 'column'),
|
| 164 |
+
B(912, 768, 0, 1008, 832, 384, 'column'),
|
| 165 |
+
],
|
| 166 |
+
player: { origin: [960, 200, 24], yaw: 90 },
|
| 167 |
+
boss: { classname: 'monster_mutant', origin: [960, 1380, 32], yaw: 270 },
|
| 168 |
+
loadout: { weapons: ['blaster', 'shotgun', 'supershotgun', 'machinegun', 'chaingun'], weapon: 'supershotgun',
|
| 169 |
+
ammo: { shells: 100, bullets: 200 }, armor: ['combat', 50] },
|
| 170 |
+
items: [['health_large', 160, 160], ['health_large', 1760, 160], ['health', 160, 1440], ['health', 1760, 1440],
|
| 171 |
+
['health_large', 960, 700], ['ammo_shells', 120, 800], ['ammo_shells', 1800, 800], ['ammo_shells', 960, 1480],
|
| 172 |
+
['ammo_shells', 640, 120], ['ammo_shells', 1280, 120], ['ammo_bullets', 640, 1480], ['ammo_bullets', 1280, 1480],
|
| 173 |
+
['armor_shard', 672, 800], ['armor_shard', 1248, 800], ['stimpack', 800, 200], ['stimpack', 1120, 200]],
|
| 174 |
+
},
|
| 175 |
+
};
|
| 176 |
+
for (const [key, a] of Object.entries(ARENAS)) { a.key = key; Q.worlds[key] = { brushes: a.brushes() }; }
|
| 177 |
+
const caseKey = id => id.split('/')[1];
|
| 178 |
+
// 60 Hz clock (q2-arena@3): tick t ends at floor(t * 100 / 6) ms, so host frames are 16, 17, 17 ms and every sixth
|
| 179 |
+
// tick lands exactly on a 100 ms server frame.
|
| 180 |
+
const HZ = 60, msAt = t => Math.floor(t * 100 / 6);
|
| 181 |
+
const STARTER = { weapons: ['blaster', 'shotgun'], weapon: 'shotgun', ammo: { shells: 50 }, armor: null };
|
| 182 |
+
|
| 183 |
+
const CASES = [
|
| 184 |
+
{ id: 'quake2/supertank', name: 'Tracked Gun Carrier' },
|
| 185 |
+
{ id: 'quake2/hornet', name: 'Flying Gunship' },
|
| 186 |
+
{ id: 'quake2/makron', name: 'Twin-Cannon Mech → Armoured Pilot' },
|
| 187 |
+
{ id: 'quake2/tank_commander', name: 'Chain-Gun Heavy Trooper' },
|
| 188 |
+
{ id: 'quake2/gladiator', name: 'Blade-Arm Gunner' },
|
| 189 |
+
{ id: 'quake2/mutant', name: 'Clawed Pouncer' },
|
| 190 |
+
];
|
| 191 |
+
Object.assign(M, {
|
| 192 |
+
id: 'quake2_remake', version: 'q2-arena@4', hz: HZ, maxSeconds: 300, dimension: '3d', renderer: 'webgl-quake2',
|
| 193 |
+
title: 'Quake II · Boss Arena', cases: CASES, tiers: TIERS, pointerLock: true,
|
| 194 |
+
controls: {
|
| 195 |
+
'W / S': 'Forward / backward (cl_forwardspeed 200; Pmove maximum 300)', 'A / D': 'Strafe left / right', 'Shift': 'Run (+speed doubles movement input, capped by pm_maxspeed 300)',
|
| 196 |
+
'mouse dx / dy': 'Turn / pitch (freelook; sensitivity 3 × m_yaw 0.022 = 0.066° per count; pitch ±89°)', 'Q / E': 'Turn left / right with keyboard (cl_yawspeed 140°/s)',
|
| 197 |
+
'Space': 'Jump (+moveup; takeoff speed 270)', 'L': 'Crouch (+movedown; speed capped at 100)', 'J / LMB': 'Fire (hold for repeated shots)',
|
| 198 |
+
'K / RMB / wheel up': 'Next weapon (weapnext)', 'R / wheel down': 'Previous weapon (weapprev)',
|
| 199 |
+
},
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
+
class Game {
|
| 203 |
+
constructor(id, seed, d) {
|
| 204 |
+
this.id = id; this.key = caseKey(id); this.d = d; this.skill = skillOf(d); this.tier = tierOf(d);
|
| 205 |
+
this.t = 0; this.framenum = 0; this.ms = 0; this.dt = 0; this.outcome = null; this.events = []; this.fx = []; this.damageLog = [];
|
| 206 |
+
this.rnd = seed >>> 0; this.ai = { enemy_vis: false, enemy_infront: false, enemy_range: 0, enemy_yaw: 0 };
|
| 207 |
+
this.sight_entity = -1; this.sight_entity_framenum = -10; this.sound_entity = -1; this.sound_entity_framenum = -10; this.sound2_entity = -1; this.sound2_entity_framenum = -10;
|
| 208 |
+
this.sight_client = -1; this.bossKilled = 0; this.fxSeq = 0;
|
| 209 |
+
const a = ARENAS[this.key];
|
| 210 |
+
// Edict layout of a single-player level: 0 world, 1 the client, 2..9 the body queue (SP_worldspawn), then the
|
| 211 |
+
// map entities in map order, then the eight player trail markers (PlayerTrail_Init at the end of SpawnEntities).
|
| 212 |
+
this.ents = [Object.assign(Q.blankEdict(), { classname: 'worldspawn', solid: Q.SOLID_BSP, movetype: 'push' }), { inuse: false, freetime: 0, classname: 'client', solid: 0 }];
|
| 213 |
+
for (let k = 0; k < 8; k++) { const i = Q.spawn(this); this.ents[i].classname = 'bodyque'; }
|
| 214 |
+
// ED_SpawnEntities inhibits entities by SPAWNFLAG_NOT_EASY / _NOT_MEDIUM / _NOT_HARD (skill 2 and 3 are hard).
|
| 215 |
+
const inhibit = this.skill === 0 ? 256 : this.skill === 1 ? 512 : 1024;
|
| 216 |
+
for (const [type, x, y, flags] of a.items) if (!((flags || 0) & inhibit)) Q.spawnItem(this, type, [x, y, 15]);
|
| 217 |
+
this.bossClass = a.boss.classname;
|
| 218 |
+
this.makronHealth = healthOf('monster_makron', d);
|
| 219 |
+
const final = a.boss.classname !== 'monster_jorg';
|
| 220 |
+
this.boss = Q.spawnMonster(this, a.boss.classname, a.boss.origin, a.boss.yaw, { health: healthOf(a.boss.classname, d), engage: true, final });
|
| 221 |
+
this.bossMax = this.ents[this.boss].health + (final ? 0 : this.makronHealth);
|
| 222 |
+
for (let k = 0; k < 8; k++) { const i = Q.spawn(this); this.ents[i].classname = 'player_trail'; }
|
| 223 |
+
Q.playerTrailInit(this);
|
| 224 |
+
// skill 0 starts with Quake II's new-game inventory (InitClientPersistant: Blaster, 100 health, no armor) plus
|
| 225 |
+
// the first weapon of unit 1, the Shotgun with 50 shells; higher skills carry the arena kit (BossBench practice
|
| 226 |
+
// loadouts).
|
| 227 |
+
const L = this.skill === 0 ? STARTER : a.loadout, inv = { jacket: 0, combat: 0, body: 0, shells: 0, bullets: 0, rockets: 0, cells: 0, slugs: 0 };
|
| 228 |
+
for (const w of L.weapons) inv[w] = 1;
|
| 229 |
+
Object.assign(inv, L.ammo); if (L.armor) inv[L.armor[0]] = L.armor[1];
|
| 230 |
+
Q.spawnPlayer(this, { origin: a.player.origin, yaw: a.player.yaw, inventory: inv, weapon: L.weapon });
|
| 231 |
+
}
|
| 232 |
+
// One native tick (60 Hz, q2-arena@3): a host frame of 16 or 17 ms (SV_Frame draws one rand() per host frame),
|
| 233 |
+
// the client's usercmd for it (ClientThink -> Pmove with cmd.msec 16/17, the original client at cl_maxfps 60),
|
| 234 |
+
// then entity physics for this slice of time. Thinks still fire on their nextthink in ms, so monster frames, AI
|
| 235 |
+
// and weapon frames keep the original 100 ms server frame; the server-frame-only parts (ClientBeginServerFrame,
|
| 236 |
+
// AI_SetSightClient, old_origin, ClientEndServerFrame) run on the tick that crosses a 100 ms boundary.
|
| 237 |
+
update(keys, pressed, mouse) {
|
| 238 |
+
const prevMs = this.ms, nextMs = msAt(this.t + 1), frame = nextMs % Q.FRAMETIME_MS === 0;
|
| 239 |
+
this.dt = (nextMs - prevMs) / 1000;
|
| 240 |
+
this.fx = this.fx.filter(f => nextMs - f.t0 < (f.life || 300));
|
| 241 |
+
if (this.damageLog.length > 64) this.damageLog = this.damageLog.slice(-64);
|
| 242 |
+
Q.rand(this);
|
| 243 |
+
const p = this.ents[1];
|
| 244 |
+
if (p.health > 0) {
|
| 245 |
+
this.framenum = Math.floor(prevMs / Q.FRAMETIME_MS); // usercmds run before the tick advances level.time
|
| 246 |
+
const cmd = Q.buildUsercmd(this, keys, pressed, mouse, nextMs - prevMs);
|
| 247 |
+
Q.clientThink(this, cmd);
|
| 248 |
+
}
|
| 249 |
+
this.ms = nextMs; this.framenum = Math.floor(nextMs / Q.FRAMETIME_MS);
|
| 250 |
+
if (frame) this.sight_client = p.inuse && p.health > 0 ? 1 : -1; // AI_SetSightClient (one client)
|
| 251 |
+
for (let i = 0; i < this.ents.length; i++) {
|
| 252 |
+
const e = this.ents[i];
|
| 253 |
+
if (!e.inuse) continue;
|
| 254 |
+
if (frame) e.old_origin = copy3(e.origin);
|
| 255 |
+
if (i === 0) continue;
|
| 256 |
+
if (i === 1) { if (frame) Q.clientBeginServerFrame(this); continue; }
|
| 257 |
+
if (e.movetype === 'step') Q.physicsStep(this, i);
|
| 258 |
+
else if (e.movetype === 'flymissile' || e.movetype === 'toss' || e.movetype === 'bounce') Q.physicsToss(this, i);
|
| 259 |
+
else Q.runThink(this, i);
|
| 260 |
+
}
|
| 261 |
+
if (frame) Q.clientEndServerFrame(this);
|
| 262 |
+
if (!this.outcome && p.health <= 0) this.outcome = 'loss';
|
| 263 |
+
else if (!this.outcome && this.bossKilled) this.outcome = 'win';
|
| 264 |
+
}
|
| 265 |
+
health() {
|
| 266 |
+
const p = this.ents[1];
|
| 267 |
+
let boss = 0;
|
| 268 |
+
for (const e of this.ents) if (e.inuse && e.svflags & Q.SVF_MONSTER && e.deadflag !== Q.DEAD_DEAD) boss += Math.max(0, e.health);
|
| 269 |
+
if (this.bossClass === 'monster_jorg' && !this.ents.some(e => e.inuse && e.classname === 'monster_makron')) {
|
| 270 |
+
const jorg = this.ents[this.boss];
|
| 271 |
+
boss = (jorg.inuse && jorg.classname === 'monster_jorg' && jorg.deadflag !== Q.DEAD_DEAD ? Math.max(0, jorg.health) : 0) + this.makronHealth;
|
| 272 |
+
}
|
| 273 |
+
// Stimpacks ignore max_health (HEALTH_IGNORE_MAX), so health can exceed 100; the reported maximum follows it so
|
| 274 |
+
// the normalized value stays in [0, 1] as the engine contract requires.
|
| 275 |
+
return [Math.max(0, p.health), Math.max(100, p.health), boss, this.bossMax];
|
| 276 |
+
}
|
| 277 |
+
bossEnt() { // the boss currently fighting (Makron once he has been spawned)
|
| 278 |
+
const mak = this.ents.findIndex(e => e.inuse && e.classname === 'monster_makron');
|
| 279 |
+
return mak >= 0 ? mak : this.boss;
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
// Cosmetic effects live in the state so renders are a pure function of it; they never touch the RNG.
|
| 283 |
+
Q.fx = (g, kind, origin, normal, extra) => {
|
| 284 |
+
const life = { tracer: 100, rail: 900, explosion: 500, blood: 300, puff: 300, spark: 250, mflash: 100, gibs: 1600, railcharge: 800, blasterhit: 250, bfgblast: 600 }[kind] || 300;
|
| 285 |
+
g.fx.push(Object.assign({ kind, o: copy3(origin), n: normal ? copy3(normal) : null, t0: g.ms, life, id: g.fxSeq++ }, extra || {}));
|
| 286 |
+
if (g.fx.length > 160) g.fx.splice(0, g.fx.length - 160);
|
| 287 |
+
};
|
| 288 |
+
Object.assign(M, {
|
| 289 |
+
msAt, Game, arenas: ARENAS, health: HEALTH, skillOf, tierOf, healthOf, skillNames: SKILL_NAMES,
|
| 290 |
+
copyGame: g => Object.assign(Object.create(Game.prototype), N.copy(g)),
|
| 291 |
+
});
|
| 292 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/quake2_remake/index.html
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="data:,"><title>Quake II · Boss Arena(q2-arena@4)</title><link rel="stylesheet" href="../_native/style.css"><style>body[data-game=quake2_remake]{--bg:#1c1a17;--panel:#2a2621;--edge:#5d5340;--accent:#d8b060}</style></head><body><main>
|
| 3 |
+
<header><div><h1>Quake II · Boss Arena</h1><p>1997 original rules, independently recreated from id Software GPL source · 60 Hz simulation (10 Hz server frames) · First-person WebGL</p></div><a href="../../index.html">Back to Game Lobby</a></header>
|
| 4 |
+
<div class="layout"><section><div class="stage"><canvas width="854" height="480" tabindex="0" aria-label="Game Screen"></canvas><div id="overlay"><div>Select a boss to start</div></div><div class="toolbar"><button id="start" class="primary">Start Challenge / Restart</button><button id="pause">Resume</button><button id="step">Step</button><button id="demo">Scripted Demo</button><button id="sample">Example Replay</button></div></div><div class="mobile"><button data-key="Q">⟲ Turn left</button><button data-key="W">↑</button><button data-key="E">Turn right ⟳</button><button data-key="A">← Strafe</button><button data-key="S">↓</button><button data-key="D">Strafe →</button><button data-key="Space">Jump</button><button data-key="J">Fire</button><button data-key="K">Switch weapon</button><button data-key="Shift">Run</button></div><p id="status" role="status"></p><div class="toolbar"><button id="export">Export Current Replay</button><button id="import">Import and Replay</button><input id="file" type="file" accept=".json,application/json"></div><p class="note">Replays save inputs and the seed, then simulate the match again and verify the final state. Scripted Demo reads internal state for verification; it does not start RL training.</p></section>
|
| 5 |
+
<aside><div><h2>Select Challenge</h2><label for="case">Boss</label><select id="case"></select><label for="seed">Seed</label><input id="seed" type="number" min="0" max="4294967295" value="1" step="1"></div><div><label for="difficulty">Difficulty</label><select id="difficulty"></select><p class="note">Easy matches original skill 0 (player damage halved), Normal skill 1, and Hard skill 3 (Hard+: bosses skip pain animations). Each tier also has a boss health setting.</p><p class="note">Click the screen to enable the keyboard, or double-click to lock the mouse for free look. Esc pauses. Player movement updates every 1/60 second; monsters and weapons update on original 0.1-second server frames.</p><p class="note">Rules tips: rockets splash within 120 units and deal half damage to you. The crawler tank’s chain gun and the twin-cannon mech’s guns hit instantly; break line of sight behind cover. The armored pilot’s railgun locks onto your position one frame before firing, while the blade-armed gunner aims at where you were 0.4 seconds earlier; strafe when you see the red aiming line. Energy orbs fire lasers within 256 units, so keep your distance. The armored chain-gunner sweeps from +40° to −32° and back; hide behind the machine. The clawed mutant has no ranged attack: it claws within 80 units and pounces from beyond 100 units with a 600-unit initial charge. Use the long table and pillars to create distance.</p></div><dl></dl></aside></div>
|
| 6 |
+
<footer></footer></main>
|
| 7 |
+
<script src="../_native/runtime.js"></script><script src="../_boss3d/vendor/three.min.js"></script><script src="q2core.js"></script><script src="q2player.js"></script><script src="q2monsters.js"></script><script src="game.js"></script><script src="scripted.js"></script><script src="renderer3d.js"></script><script src="draw.js"></script><script src="input-hold.js"></script><script>window.GAME_MODULE=window.Quake2Game;</script><script src="../_native/shell.js"></script></body></html>
|
environments/games/web/games/quake2_remake/input-hold.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* The shared shell (_native/shell.js) latches a tapped key only until the next macrotask, so a tap released before
|
| 2 |
+
the next native tick is lost. Since q2-arena@3 the tick is 16.7 ms (60 Hz), so a 20 ms minimum hold is enough:
|
| 3 |
+
this page delays every key / pointer release until 20 ms after the press. Page input only: the rules, the policy interface and recordings are
|
| 4 |
+
unaffected (a recording stores the keys each tick actually saw). */
|
| 5 |
+
(function () {
|
| 6 |
+
'use strict';
|
| 7 |
+
const HOLD = 20, down = new Map(), pdown = new Map();
|
| 8 |
+
const tracked = e => /^(Key[WASDJKLQER]|Space|ShiftLeft|ShiftRight|Arrow(Up|Down|Left|Right))$/.test(e.code);
|
| 9 |
+
const late = new WeakSet();
|
| 10 |
+
window.addEventListener('keydown', e => { if (tracked(e) && !down.has(e.code)) down.set(e.code, performance.now()); }, true);
|
| 11 |
+
window.addEventListener('keyup', e => {
|
| 12 |
+
if (late.has(e) || !tracked(e)) return;
|
| 13 |
+
const t0 = down.get(e.code); down.delete(e.code);
|
| 14 |
+
const wait = t0 === undefined ? 0 : HOLD - (performance.now() - t0);
|
| 15 |
+
if (wait <= 0) return;
|
| 16 |
+
e.stopImmediatePropagation(); e.preventDefault();
|
| 17 |
+
const target = e.target || window;
|
| 18 |
+
setTimeout(() => { const ev = new KeyboardEvent('keyup', { code: e.code, key: e.key, bubbles: true, cancelable: true }); late.add(ev); target.dispatchEvent(ev); }, wait);
|
| 19 |
+
}, true);
|
| 20 |
+
window.addEventListener('pointerdown', e => { pdown.set(e.pointerId, performance.now()); }, true);
|
| 21 |
+
window.addEventListener('pointerup', e => {
|
| 22 |
+
if (late.has(e)) return;
|
| 23 |
+
const t0 = pdown.get(e.pointerId); pdown.delete(e.pointerId);
|
| 24 |
+
const wait = t0 === undefined ? 0 : HOLD - (performance.now() - t0);
|
| 25 |
+
if (wait <= 0) return;
|
| 26 |
+
e.stopImmediatePropagation();
|
| 27 |
+
const target = e.target || window;
|
| 28 |
+
setTimeout(() => { const ev = new PointerEvent('pointerup', { bubbles: true, button: e.button, pointerId: e.pointerId }); late.add(ev); target.dispatchEvent(ev); }, wait);
|
| 29 |
+
}, true);
|
| 30 |
+
})();
|
environments/games/web/games/quake2_remake/manifest.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/game-manifest@1",
|
| 3 |
+
"engine": "independent",
|
| 4 |
+
"game": "quake2_remake",
|
| 5 |
+
"module": "Quake2Game",
|
| 6 |
+
"title": "Quake II: Boss Arena",
|
| 7 |
+
"dimension": "3d",
|
| 8 |
+
"native_hz": 60,
|
| 9 |
+
"max_seconds": 300,
|
| 10 |
+
"renderer": "webgl-quake2",
|
| 11 |
+
"rules": "q2-arena@4",
|
| 12 |
+
"cases": [
|
| 13 |
+
"quake2/supertank",
|
| 14 |
+
"quake2/hornet",
|
| 15 |
+
"quake2/makron",
|
| 16 |
+
"quake2/tank_commander",
|
| 17 |
+
"quake2/gladiator",
|
| 18 |
+
"quake2/mutant"
|
| 19 |
+
],
|
| 20 |
+
"scripts": [
|
| 21 |
+
"_native/runtime.js",
|
| 22 |
+
"_boss3d/vendor/three.min.js",
|
| 23 |
+
"quake2_remake/q2core.js",
|
| 24 |
+
"quake2_remake/q2player.js",
|
| 25 |
+
"quake2_remake/q2monsters.js",
|
| 26 |
+
"quake2_remake/game.js",
|
| 27 |
+
"quake2_remake/scripted.js",
|
| 28 |
+
"quake2_remake/renderer3d.js",
|
| 29 |
+
"quake2_remake/draw.js"
|
| 30 |
+
],
|
| 31 |
+
"sim_scripts": [
|
| 32 |
+
"_native/runtime.js",
|
| 33 |
+
"quake2_remake/q2core.js",
|
| 34 |
+
"quake2_remake/q2player.js",
|
| 35 |
+
"quake2_remake/q2monsters.js",
|
| 36 |
+
"quake2_remake/game.js",
|
| 37 |
+
"quake2_remake/scripted.js"
|
| 38 |
+
],
|
| 39 |
+
"play_page": "web/games/quake2_remake/index.html",
|
| 40 |
+
"scripted_controller": "Quake2Game.scripted(game) -> {holds:[6 key arrays], mouse:[dx,dy,0]}; deterministic look-ahead on copies (Quake2Game.oracle is an alias)",
|
| 41 |
+
"tests": [
|
| 42 |
+
"quake2_remake/tests/mechanics.js"
|
| 43 |
+
],
|
| 44 |
+
"source": "https://github.com/id-Software/Quake-2/tree/372afde46e7defc9dd2d719a1732b8ace1fa096e (GPL-2.0)"
|
| 45 |
+
}
|
environments/games/web/games/quake2_remake/q2core.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Quake II (1997) boss arenas - core rules: units, Win32 CRT rand(), Quake II vector/angle helpers, the
|
| 2 |
+
axis-aligned brush world, box traces with CM_ClipBoxToBrush semantics and the edict slot allocator.
|
| 3 |
+
Independent JavaScript reimplementation written from id Software's GPL-2.0 source release
|
| 4 |
+
(github.com/id-Software/Quake-2, commit 372afde46e7defc9dd2d719a1732b8ace1fa096e): q_shared.c (AngleVectors,
|
| 5 |
+
anglemod), g_utils.c (vectoyaw, vectoangles, G_ProjectSource, G_Spawn, findradius), qcommon/cmodel.c
|
| 6 |
+
(CM_ClipBoxToBrush, CM_TestBoxInBrush), server/sv_world.c (SV_Trace, SV_ClipMoveToEntities). No engine code is
|
| 7 |
+
copied. Game data (pak files, models, textures, sounds, maps) is not part of the GPL release and none is used. */
|
| 8 |
+
(function (root) {
|
| 9 |
+
'use strict';
|
| 10 |
+
const M = root.Quake2Game = root.Quake2Game || {};
|
| 11 |
+
const Q = M.Q = M.Q || {};
|
| 12 |
+
|
| 13 |
+
// ---------------- constants (q_shared.h / g_local.h) ----------------
|
| 14 |
+
Q.FRAMETIME_MS = 100; // g_local.h FRAMETIME 0.1, sv_main.c sv.time = framenum*100
|
| 15 |
+
Q.CONTENTS_SOLID = 1; Q.CONTENTS_WINDOW = 2; Q.CONTENTS_LAVA = 8; Q.CONTENTS_SLIME = 16; Q.CONTENTS_WATER = 32;
|
| 16 |
+
Q.CONTENTS_PLAYERCLIP = 0x10000; Q.CONTENTS_MONSTERCLIP = 0x20000; Q.CONTENTS_MONSTER = 0x2000000; Q.CONTENTS_DEADMONSTER = 0x4000000;
|
| 17 |
+
Q.MASK_SOLID = Q.CONTENTS_SOLID | Q.CONTENTS_WINDOW;
|
| 18 |
+
Q.MASK_PLAYERSOLID = Q.CONTENTS_SOLID | Q.CONTENTS_PLAYERCLIP | Q.CONTENTS_WINDOW | Q.CONTENTS_MONSTER;
|
| 19 |
+
Q.MASK_MONSTERSOLID = Q.CONTENTS_SOLID | Q.CONTENTS_MONSTERCLIP | Q.CONTENTS_WINDOW | Q.CONTENTS_MONSTER;
|
| 20 |
+
Q.MASK_SHOT = Q.CONTENTS_SOLID | Q.CONTENTS_MONSTER | Q.CONTENTS_WINDOW | Q.CONTENTS_DEADMONSTER;
|
| 21 |
+
Q.MASK_OPAQUE = Q.CONTENTS_SOLID | Q.CONTENTS_SLIME | Q.CONTENTS_LAVA;
|
| 22 |
+
Q.MASK_WATER = Q.CONTENTS_WATER | Q.CONTENTS_LAVA | Q.CONTENTS_SLIME;
|
| 23 |
+
Q.SOLID_NOT = 0; Q.SOLID_TRIGGER = 1; Q.SOLID_BBOX = 2; Q.SOLID_BSP = 3;
|
| 24 |
+
Q.SVF_NOCLIENT = 1; Q.SVF_DEADMONSTER = 2; Q.SVF_MONSTER = 4;
|
| 25 |
+
Q.FL_FLY = 1; Q.FL_SWIM = 2; Q.FL_IMMUNE_LASER = 4; Q.FL_PARTIALGROUND = 256; Q.FL_NO_KNOCKBACK = 2048;
|
| 26 |
+
Q.DAMAGE_NO = 0; Q.DAMAGE_YES = 1; Q.DAMAGE_AIM = 2;
|
| 27 |
+
Q.DAMAGE_RADIUS = 1; Q.DAMAGE_NO_ARMOR = 2; Q.DAMAGE_ENERGY = 4; Q.DAMAGE_NO_KNOCKBACK = 8; Q.DAMAGE_BULLET = 16;
|
| 28 |
+
Q.DEAD_NO = 0; Q.DEAD_DYING = 1; Q.DEAD_DEAD = 2;
|
| 29 |
+
Q.STEPSIZE = 18; Q.MELEE_DISTANCE = 80; Q.DIST_EPSILON = 0.03125;
|
| 30 |
+
Q.RANGE_MELEE = 0; Q.RANGE_NEAR = 1; Q.RANGE_MID = 2; Q.RANGE_FAR = 3;
|
| 31 |
+
Q.SV_GRAVITY = 800; Q.SV_MAXVELOCITY = 2000; Q.SV_STOPSPEED = 100; Q.SV_FRICTION = 6;
|
| 32 |
+
Q.YAW = 1; Q.PITCH = 0; Q.ROLL = 2;
|
| 33 |
+
|
| 34 |
+
// ---------------- Win32 CRT rand() (the shipped 1997 build is MSVC; Quake II never calls srand) ----------------
|
| 35 |
+
// holdrand = holdrand * 214013 + 2531011; return (holdrand >> 16) & 0x7fff. The BossBench engine seed is the
|
| 36 |
+
// initial holdrand. random() and crandom() are the g_local.h macros.
|
| 37 |
+
Q.rand = g => { g.rnd = (Math.imul(g.rnd, 214013) + 2531011) >>> 0; return (g.rnd >>> 16) & 0x7fff; };
|
| 38 |
+
Q.random = g => (Q.rand(g) & 0x7fff) / 0x7fff;
|
| 39 |
+
Q.crandom = g => 2 * (Q.random(g) - 0.5);
|
| 40 |
+
Q.drawRand = (g, n) => { for (let i = 0; i < n; i++) Q.rand(g); }; // RNG draws of cosmetic effects (debris/gibs)
|
| 41 |
+
|
| 42 |
+
// ---------------- vectors (vec3_t as [x, y, z]) ----------------
|
| 43 |
+
// Deterministic trigonometry. Math.sin / Math.cos / Math.atan2 can differ in the last bit between V8 builds
|
| 44 |
+
// (Node vs Chrome, measured in this project), and the simulation must replay bit-identically in Node
|
| 45 |
+
// (calibration, page example recordings) and in the browser (harness, play page). These are fdlibm's kernels
|
| 46 |
+
// (k_sin.c, k_cos.c, s_atan.c, e_atan2.c) evaluated with + - * / only, Cody-Waite range reduction for |x| < 2^20.
|
| 47 |
+
const PIO2_1 = 1.57079632673412561417e+00, PIO2_1T = 6.07710050650619224932e-11, INVPIO2 = 6.36619772367581382433e-01;
|
| 48 |
+
const S1 = -1.66666666666666324348e-01, S2 = 8.33333333332248946124e-03, S3 = -1.98412698298579493134e-04,
|
| 49 |
+
S4 = 2.75573137070700676789e-06, S5 = -2.50507602534068634195e-08, S6 = 1.58969099521155010221e-10;
|
| 50 |
+
const C1 = 4.16666666666666019037e-02, C2 = -1.38888888888741095749e-03, C3 = 2.48015872894767294178e-05,
|
| 51 |
+
C4 = -2.75573143513906633035e-07, C5 = 2.08757232129817482790e-09, C6 = -1.13596475577881948265e-11;
|
| 52 |
+
const ksin = x => { const z = x * x; return x + x * z * (S1 + z * (S2 + z * (S3 + z * (S4 + z * (S5 + z * S6))))); };
|
| 53 |
+
const kcos = x => { const z = x * x; return 1 - 0.5 * z + z * z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6))))); };
|
| 54 |
+
function reduce(x) { const k = Math.round(x * INVPIO2); return [k & 3, (x - k * PIO2_1) - k * PIO2_1T]; }
|
| 55 |
+
Q.sin = x => { const [q, r] = reduce(x); return q === 0 ? ksin(r) : q === 1 ? kcos(r) : q === 2 ? -ksin(r) : -kcos(r); };
|
| 56 |
+
Q.cos = x => { const [q, r] = reduce(x); return q === 0 ? kcos(r) : q === 1 ? -ksin(r) : q === 2 ? -kcos(r) : ksin(r); };
|
| 57 |
+
const ATANHI = [4.63647609000806093515e-01, 7.85398163397448278999e-01, 9.82793723247329054082e-01, 1.57079632679489655800e+00];
|
| 58 |
+
const ATANLO = [2.26987774529616870924e-17, 3.06161699786838301793e-17, 1.39033110312309984516e-17, 6.12323399573676603587e-17];
|
| 59 |
+
const AT = [3.33333333333329318027e-01, -1.99999999998764832476e-01, 1.42857142725034663711e-01, -1.11111104054623557880e-01,
|
| 60 |
+
9.09088713343650656196e-02, -7.69187620504482999495e-02, 6.66107313738753120669e-02, -5.83357013379057348645e-02,
|
| 61 |
+
4.97687799461593236017e-02, -3.65315727442169155270e-02, 1.62858201153657823623e-02];
|
| 62 |
+
function atan(x) {
|
| 63 |
+
const neg = x < 0; let a = neg ? -x : x, id = -1;
|
| 64 |
+
if (a !== a) return a;
|
| 65 |
+
if (a >= 7.378697629483821e+19) return neg ? -(ATANHI[3] + ATANLO[3]) : ATANHI[3] + ATANLO[3]; // >= 2^66
|
| 66 |
+
if (a < 0.4375) { if (a < 1.862645149230957e-09) return x; }
|
| 67 |
+
else if (a < 1.1875) { if (a < 0.6875) { id = 0; a = (2 * a - 1) / (2 + a); } else { id = 1; a = (a - 1) / (a + 1); } }
|
| 68 |
+
else if (a < 2.4375) { id = 2; a = (a - 1.5) / (1 + 1.5 * a); }
|
| 69 |
+
else { id = 3; a = -1 / a; }
|
| 70 |
+
const z = a * a, w = z * z;
|
| 71 |
+
const s1 = z * (AT[0] + w * (AT[2] + w * (AT[4] + w * (AT[6] + w * (AT[8] + w * AT[10])))));
|
| 72 |
+
const s2 = w * (AT[1] + w * (AT[3] + w * (AT[5] + w * (AT[7] + w * AT[9]))));
|
| 73 |
+
if (id < 0) { const r = a - a * (s1 + s2); return neg ? -r : r; }
|
| 74 |
+
const r = ATANHI[id] - ((a * (s1 + s2) - ATANLO[id]) - a);
|
| 75 |
+
return neg ? -r : r;
|
| 76 |
+
}
|
| 77 |
+
const PI = 3.1415926535897931160e+00, PI_LO = 1.2246467991473531772e-16;
|
| 78 |
+
Q.atan2 = (y, x) => {
|
| 79 |
+
if (x !== x || y !== y) return NaN;
|
| 80 |
+
if (y === 0) return (x > 0 || (x === 0 && 1 / x > 0)) ? y : (1 / y > 0 ? PI : -PI);
|
| 81 |
+
if (x === 0) return y > 0 ? PI / 2 : -PI / 2;
|
| 82 |
+
const z = atan(Math.abs(y / x));
|
| 83 |
+
if (x > 0) return y > 0 ? z : -z;
|
| 84 |
+
return y > 0 ? PI - (z - PI_LO) : (z - PI_LO) - PI;
|
| 85 |
+
};
|
| 86 |
+
const DEG = Math.PI / 180;
|
| 87 |
+
Q.add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
| 88 |
+
Q.sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
| 89 |
+
Q.scale = (a, s) => [a[0] * s, a[1] * s, a[2] * s];
|
| 90 |
+
Q.ma = (a, s, b) => [a[0] + s * b[0], a[1] + s * b[1], a[2] + s * b[2]]; // VectorMA
|
| 91 |
+
Q.dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
| 92 |
+
Q.len = a => Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
|
| 93 |
+
Q.cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
| 94 |
+
Q.norm = a => { const l = Q.len(a); return l ? [a[0] / l, a[1] / l, a[2] / l] : [0, 0, 0]; }; // VectorNormalize
|
| 95 |
+
Q.eq = (a, b) => a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
| 96 |
+
Q.copy3 = a => [a[0], a[1], a[2]];
|
| 97 |
+
Q.angleVectors = angles => {
|
| 98 |
+
const y = angles[1] * DEG, p = angles[0] * DEG, r = angles[2] * DEG;
|
| 99 |
+
const sy = Q.sin(y), cy = Q.cos(y), sp = Q.sin(p), cp = Q.cos(p), sr = Q.sin(r), cr = Q.cos(r);
|
| 100 |
+
return {
|
| 101 |
+
forward: [cp * cy, cp * sy, -sp],
|
| 102 |
+
right: [-1 * sr * sp * cy + -1 * cr * -sy, -1 * sr * sp * sy + -1 * cr * cy, -1 * sr * cp],
|
| 103 |
+
up: [cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp],
|
| 104 |
+
};
|
| 105 |
+
};
|
| 106 |
+
// anglemod: 16-bit wrap; vectoyaw / vectoangles truncate to whole degrees exactly as g_utils.c does.
|
| 107 |
+
Q.anglemod = a => (360 / 65536) * (Math.trunc(a * (65536 / 360)) & 65535);
|
| 108 |
+
Q.vectoyaw = v => {
|
| 109 |
+
if (v[0] === 0) return v[1] > 0 ? 90 : v[1] < 0 ? -90 : 0;
|
| 110 |
+
let yaw = Math.trunc(Q.atan2(v[1], v[0]) * 180 / Math.PI);
|
| 111 |
+
if (yaw < 0) yaw += 360;
|
| 112 |
+
return yaw;
|
| 113 |
+
};
|
| 114 |
+
Q.vectoangles = v => {
|
| 115 |
+
let yaw, pitch;
|
| 116 |
+
if (v[1] === 0 && v[0] === 0) { yaw = 0; pitch = v[2] > 0 ? 90 : 270; }
|
| 117 |
+
else {
|
| 118 |
+
if (v[0]) yaw = Math.trunc(Q.atan2(v[1], v[0]) * 180 / Math.PI); else yaw = v[1] > 0 ? 90 : -90;
|
| 119 |
+
if (yaw < 0) yaw += 360;
|
| 120 |
+
const forward = Math.sqrt(v[0] * v[0] + v[1] * v[1]);
|
| 121 |
+
pitch = Math.trunc(Q.atan2(v[2], forward) * 180 / Math.PI);
|
| 122 |
+
if (pitch < 0) pitch += 360;
|
| 123 |
+
}
|
| 124 |
+
return [-pitch, yaw, 0];
|
| 125 |
+
};
|
| 126 |
+
Q.projectSource = (point, d, forward, right) => [ // G_ProjectSource
|
| 127 |
+
point[0] + forward[0] * d[0] + right[0] * d[1],
|
| 128 |
+
point[1] + forward[1] * d[0] + right[1] * d[1],
|
| 129 |
+
point[2] + forward[2] * d[0] + right[2] * d[1] + d[2]];
|
| 130 |
+
Q.ANGLE2SHORT = x => { const s = Math.trunc(x * 65536 / 360) & 65535; return s > 32767 ? s - 65536 : s; };
|
| 131 |
+
Q.SHORT2ANGLE = x => x * (360 / 65536);
|
| 132 |
+
|
| 133 |
+
// ---------------- world: axis-aligned brushes ----------------
|
| 134 |
+
// A brush is {mins, maxs, contents, mat}. The world of a case is static, so it is kept outside the game state
|
| 135 |
+
// (looked up by case key) and never copied or hashed per tick.
|
| 136 |
+
Q.worlds = {};
|
| 137 |
+
// CM_ClipBoxToBrush on the six axial planes of one box brush, with the trace box pushed into each plane.
|
| 138 |
+
function clipBoxToBox(tr, start, end, mins, maxs, bmin, bmax, contents, isPoint, sky) {
|
| 139 |
+
let enterfrac = -1, leavefrac = 1, clip = -1, getout = false, startout = false;
|
| 140 |
+
for (let k = 0; k < 6; k++) {
|
| 141 |
+
const axis = k >> 1, positive = (k & 1) === 0;
|
| 142 |
+
let dist = positive ? bmax[axis] : -bmin[axis];
|
| 143 |
+
if (!isPoint) dist -= positive ? mins[axis] : -maxs[axis];
|
| 144 |
+
const d1 = (positive ? start[axis] : -start[axis]) - dist, d2 = (positive ? end[axis] : -end[axis]) - dist;
|
| 145 |
+
if (d2 > 0) getout = true;
|
| 146 |
+
if (d1 > 0) startout = true;
|
| 147 |
+
if (d1 > 0 && d2 >= d1) return false; // completely in front of this face
|
| 148 |
+
if (d1 <= 0 && d2 <= 0) continue;
|
| 149 |
+
if (d1 > d2) { const f = (d1 - Q.DIST_EPSILON) / (d1 - d2); if (f > enterfrac) { enterfrac = f; clip = k; } }
|
| 150 |
+
else { const f = (d1 + Q.DIST_EPSILON) / (d1 - d2); if (f < leavefrac) leavefrac = f; }
|
| 151 |
+
}
|
| 152 |
+
if (!startout) { tr.startsolid = true; if (!getout) tr.allsolid = true; return true; }
|
| 153 |
+
if (enterfrac < leavefrac && enterfrac > -1 && enterfrac < tr.fraction) {
|
| 154 |
+
if (enterfrac < 0) enterfrac = 0;
|
| 155 |
+
tr.fraction = enterfrac; const axis = clip >> 1, n = [0, 0, 0]; n[axis] = (clip & 1) === 0 ? 1 : -1;
|
| 156 |
+
tr.normal = n; tr.contents = contents; tr.sky = !!sky; return true;
|
| 157 |
+
}
|
| 158 |
+
return false;
|
| 159 |
+
}
|
| 160 |
+
// CM_TestBoxInBrush (start == end): inside unless outside some pushed plane.
|
| 161 |
+
function testBoxInBox(tr, p, mins, maxs, bmin, bmax, contents) {
|
| 162 |
+
for (let axis = 0; axis < 3; axis++) {
|
| 163 |
+
if (p[axis] + mins[axis] - bmax[axis] > 0) return false; // pushed +axis plane: dot(p) - (bmax - mins)
|
| 164 |
+
if (bmin[axis] - (p[axis] + maxs[axis]) > 0) return false;
|
| 165 |
+
}
|
| 166 |
+
tr.startsolid = tr.allsolid = true; tr.fraction = 0; tr.contents = contents; return true;
|
| 167 |
+
}
|
| 168 |
+
function boxTrace(brushes, start, mins, maxs, end, mask) {
|
| 169 |
+
const tr = { fraction: 1, startsolid: false, allsolid: false, normal: [0, 0, 0], contents: 0, ent: 0, sky: false };
|
| 170 |
+
const isPoint = !mins[0] && !mins[1] && !mins[2] && !maxs[0] && !maxs[1] && !maxs[2];
|
| 171 |
+
const position = start[0] === end[0] && start[1] === end[1] && start[2] === end[2];
|
| 172 |
+
for (const b of brushes) {
|
| 173 |
+
if (!(b.contents & mask)) continue;
|
| 174 |
+
if (position) { if (testBoxInBox(tr, start, mins, maxs, b.mins, b.maxs, b.contents)) return tr; continue; }
|
| 175 |
+
clipBoxToBox(tr, start, end, mins, maxs, b.mins, b.maxs, b.contents, isPoint, b.sky);
|
| 176 |
+
if (!tr.fraction) return tr; // CM_TraceToLeaf stops once something is hit at 0
|
| 177 |
+
}
|
| 178 |
+
return tr;
|
| 179 |
+
}
|
| 180 |
+
const Z3 = [0, 0, 0];
|
| 181 |
+
// SV_Trace: world first, then SOLID_BBOX edicts (owner/passent rules of SV_ClipMoveToEntities).
|
| 182 |
+
Q.trace = (g, start, mins, maxs, end, passent, mask) => {
|
| 183 |
+
mins = mins || Z3; maxs = maxs || Z3;
|
| 184 |
+
const tr = boxTrace(Q.worlds[g.key].brushes, start, mins, maxs, end, mask);
|
| 185 |
+
if (tr.fraction !== 0 && (mask & (Q.CONTENTS_MONSTER | Q.CONTENTS_DEADMONSTER))) {
|
| 186 |
+
const pass = passent >= 0 ? g.ents[passent] : null;
|
| 187 |
+
for (let i = 1; i < g.ents.length; i++) {
|
| 188 |
+
const e = g.ents[i];
|
| 189 |
+
if (!e.inuse || e.solid !== Q.SOLID_BBOX || i === passent) continue;
|
| 190 |
+
if (tr.allsolid) break;
|
| 191 |
+
if (pass && (e.owner === passent || pass.owner === i)) continue;
|
| 192 |
+
if (!(mask & Q.CONTENTS_DEADMONSTER) && (e.svflags & Q.SVF_DEADMONSTER)) continue;
|
| 193 |
+
if (!(mask & Q.CONTENTS_MONSTER)) continue;
|
| 194 |
+
const t2 = { fraction: 1, startsolid: false, allsolid: false, normal: [0, 0, 0], contents: 0, ent: i };
|
| 195 |
+
const bmin = Q.add(e.origin, e.mins), bmax = Q.add(e.origin, e.maxs);
|
| 196 |
+
if (start[0] === end[0] && start[1] === end[1] && start[2] === end[2]) testBoxInBox(t2, start, mins, maxs, bmin, bmax, Q.CONTENTS_MONSTER);
|
| 197 |
+
else clipBoxToBox(t2, start, end, mins, maxs, bmin, bmax, Q.CONTENTS_MONSTER, !mins[0] && !mins[1] && !mins[2] && !maxs[0] && !maxs[1] && !maxs[2]);
|
| 198 |
+
if (t2.allsolid || t2.startsolid || t2.fraction < tr.fraction) {
|
| 199 |
+
const wasStart = tr.startsolid;
|
| 200 |
+
tr.fraction = t2.fraction; tr.normal = t2.normal; tr.contents = t2.contents; tr.ent = i; tr.allsolid = t2.allsolid; tr.sky = false;
|
| 201 |
+
tr.startsolid = wasStart || t2.startsolid;
|
| 202 |
+
} else if (t2.startsolid) tr.startsolid = true;
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
tr.endpos = tr.fraction === 1 ? Q.copy3(end) : [start[0] + tr.fraction * (end[0] - start[0]), start[1] + tr.fraction * (end[1] - start[1]), start[2] + tr.fraction * (end[2] - start[2])];
|
| 206 |
+
return tr;
|
| 207 |
+
};
|
| 208 |
+
Q.pointcontents = (g, p) => {
|
| 209 |
+
let c = 0;
|
| 210 |
+
for (const b of Q.worlds[g.key].brushes)
|
| 211 |
+
if (p[0] >= b.mins[0] && p[0] <= b.maxs[0] && p[1] >= b.mins[1] && p[1] <= b.maxs[1] && p[2] >= b.mins[2] && p[2] <= b.maxs[2]) c |= b.contents;
|
| 212 |
+
return c;
|
| 213 |
+
};
|
| 214 |
+
// SV_LinkEdict absolute bounds, expanded by one unit on every side.
|
| 215 |
+
Q.absmin = e => [e.origin[0] + e.mins[0] - 1, e.origin[1] + e.mins[1] - 1, e.origin[2] + e.mins[2] - 1];
|
| 216 |
+
Q.absmax = e => [e.origin[0] + e.maxs[0] + 1, e.origin[1] + e.maxs[1] + 1, e.origin[2] + e.maxs[2] + 1];
|
| 217 |
+
Q.boxesOverlap = (a, b) => {
|
| 218 |
+
const amin = Q.absmin(a), amax = Q.absmax(a), bmin = Q.absmin(b), bmax = Q.absmax(b);
|
| 219 |
+
return amin[0] <= bmax[0] && amax[0] >= bmin[0] && amin[1] <= bmax[1] && amax[1] >= bmin[1] && amin[2] <= bmax[2] && amax[2] >= bmin[2];
|
| 220 |
+
};
|
| 221 |
+
Q.center = e => [e.origin[0] + (e.mins[0] + e.maxs[0]) * 0.5, e.origin[1] + (e.mins[1] + e.maxs[1]) * 0.5, e.origin[2] + (e.mins[2] + e.maxs[2]) * 0.5];
|
| 222 |
+
// findradius: inuse, not SOLID_NOT, centre of the box within rad.
|
| 223 |
+
Q.findradius = (g, org, rad) => {
|
| 224 |
+
const out = [];
|
| 225 |
+
for (let i = 1; i < g.ents.length; i++) {
|
| 226 |
+
const e = g.ents[i];
|
| 227 |
+
if (!e.inuse || e.solid === Q.SOLID_NOT) continue;
|
| 228 |
+
if (Q.len(Q.sub(org, Q.center(e))) > rad) continue;
|
| 229 |
+
out.push(i);
|
| 230 |
+
}
|
| 231 |
+
return out;
|
| 232 |
+
};
|
| 233 |
+
|
| 234 |
+
// ---------------- edicts ----------------
|
| 235 |
+
// Slot 0 is the world, slot 1 the player (maxclients 1). G_Spawn reuses a free slot freed more than 0.5 s ago
|
| 236 |
+
// (or at level start); the slot index decides the think order inside G_RunFrame.
|
| 237 |
+
Q.blankEdict = () => ({
|
| 238 |
+
inuse: true, classname: '', origin: [0, 0, 0], old_origin: [0, 0, 0], velocity: [0, 0, 0], avelocity: [0, 0, 0], angles: [0, 0, 0],
|
| 239 |
+
mins: [0, 0, 0], maxs: [0, 0, 0], solid: Q.SOLID_NOT, clipmask: 0, svflags: 0, flags: 0, movetype: 'none', owner: -1, enemy: -1,
|
| 240 |
+
takedamage: 0, health: 0, max_health: 0, mass: 0, deadflag: 0, think: null, nextthink: 0, touch: null, groundentity: -1,
|
| 241 |
+
freetime: 0, viewheight: 0, frame: 0, dmg: 0, radius_dmg: 0, dmg_radius: 0, count: 0, spawnflags: 0, gravity: 1, waterlevel: 0, linkcount: 0,
|
| 242 |
+
});
|
| 243 |
+
Q.spawn = g => {
|
| 244 |
+
for (let i = 2; i < g.ents.length; i++) {
|
| 245 |
+
const e = g.ents[i];
|
| 246 |
+
if (!e.inuse && (e.freetime < 2000 || g.ms - e.freetime > 500)) { g.ents[i] = Q.blankEdict(); return i; }
|
| 247 |
+
}
|
| 248 |
+
g.ents.push(Q.blankEdict()); return g.ents.length - 1;
|
| 249 |
+
};
|
| 250 |
+
Q.freeEdict = (g, i) => { g.ents[i] = { inuse: false, freetime: g.ms, classname: 'freed', solid: Q.SOLID_NOT }; };
|
| 251 |
+
// SV_RunThink: nextthink in ms; think when nextthink <= level.time (+1 ms tolerance of the 0.001 s epsilon).
|
| 252 |
+
Q.runThink = (g, i) => {
|
| 253 |
+
const e = g.ents[i];
|
| 254 |
+
if (!e.nextthink || e.nextthink <= 0 || e.nextthink > g.ms + 1) return true;
|
| 255 |
+
e.nextthink = 0;
|
| 256 |
+
const fn = Q.THINK[e.think];
|
| 257 |
+
if (!fn) throw Error('NULL think ' + e.think);
|
| 258 |
+
fn(g, i);
|
| 259 |
+
return false;
|
| 260 |
+
};
|
| 261 |
+
Q.THINK = { G_FreeEdict: (g, i) => Q.freeEdict(g, i) };
|
| 262 |
+
Q.TOUCH = {};
|
| 263 |
+
Q.event = (g, type, data) => { g.events.push(Object.assign({ type, t: g.t }, data || {})); };
|
| 264 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/quake2_remake/q2monsters.js
ADDED
|
@@ -0,0 +1,1181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Quake II (1997) boss arenas - monsters: the monster framework (g_monster.c M_MoveFrame, monster_think,
|
| 2 |
+
monster_start_go, M_CheckGround, monster_fire_*; g_ai.c ai_stand / ai_run / ai_charge / ai_move,
|
| 3 |
+
ai_checkattack, M_CheckAttack, FoundTarget / HuntTarget, visible / infront / range; m_move.c SV_movestep for
|
| 4 |
+
walking and flying monsters, M_CheckBottom, M_ChangeYaw, SV_StepDirection, SV_NewChaseDir, M_MoveToGoal;
|
| 5 |
+
g_phys.c SV_Physics_Step / SV_FlyMove; g_combat.c M_ReactToDamage) and the six boss fights of this game:
|
| 6 |
+
Super Tank (m_supertank.c, models/monsters/boss1), Hornet (m_boss2.c, boss2), Jorg + Makron (m_boss31.c /
|
| 7 |
+
m_boss32.c, boss3), Tank Commander (m_tank.c), Gladiator (m_gladiator.c) and Mutant (m_mutant.c). Move tables keep the original absolute frame numbers (m_*.h) because the code tests them.
|
| 8 |
+
Independent reimplementation from the GPL-2.0 source release, commit 372afde46e7defc9dd2d719a1732b8ace1fa096e. */
|
| 9 |
+
(function (root) {
|
| 10 |
+
'use strict';
|
| 11 |
+
const M = root.Quake2Game, Q = M.Q;
|
| 12 |
+
const { add, sub, scale, ma, dot, len, norm, copy3 } = Q;
|
| 13 |
+
const AI_STAND_GROUND = 1, AI_TEMP_STAND_GROUND = 2, AI_SOUND_TARGET = 4, AI_LOST_SIGHT = 8, AI_PURSUIT_LAST_SEEN = 16,
|
| 14 |
+
AI_PURSUE_NEXT = 32, AI_PURSUE_TEMP = 64, AI_HOLD_FRAME = 128, AI_GOOD_GUY = 256, AI_BRUTAL = 512, AI_DUCKED = 2048, AI_COMBAT_POINT = 4096;
|
| 15 |
+
const AS_STRAIGHT = 1, AS_SLIDING = 2, AS_MELEE = 3, AS_MISSILE = 4;
|
| 16 |
+
Q.AS = { AS_STRAIGHT, AS_SLIDING, AS_MELEE, AS_MISSILE };
|
| 17 |
+
|
| 18 |
+
// ---------------- move tables ----------------
|
| 19 |
+
// name: [firstframe, lastframe, frames, endfunc]; frame token <ai><dist>[:<think>][x<count>], ai s/w/r/c/m/t/n.
|
| 20 |
+
const AI_OF = { s: 'stand', w: 'walk', r: 'run', c: 'charge', m: 'move', t: 'turn', n: null };
|
| 21 |
+
function moves(spec) {
|
| 22 |
+
const out = {};
|
| 23 |
+
for (const [name, [first, last, frames, end]] of Object.entries(spec)) {
|
| 24 |
+
const list = [];
|
| 25 |
+
for (const tok of frames.trim().split(/\s+/)) {
|
| 26 |
+
const m = /^([swrcmtn])(-?\d+(?:\.\d+)?)(?::(\w+?))?(?:x(\d+))?$/.exec(tok);
|
| 27 |
+
if (!m) throw Error('bad frame token ' + tok);
|
| 28 |
+
for (let n = Number(m[4] || 1); n > 0; n--) list.push([AI_OF[m[1]], Number(m[2]), m[3] && m[3] !== 'NULL' ? m[3] : null]);
|
| 29 |
+
}
|
| 30 |
+
if (list.length !== last - first + 1) throw Error('frame count ' + name);
|
| 31 |
+
out[name] = { first, last, frames: list, end };
|
| 32 |
+
}
|
| 33 |
+
return out;
|
| 34 |
+
}
|
| 35 |
+
const DEFS = Q.MONSTERS = {};
|
| 36 |
+
|
| 37 |
+
// ---------------- helpers (g_ai.c) ----------------
|
| 38 |
+
const eye = e => [e.origin[0], e.origin[1], e.origin[2] + e.viewheight];
|
| 39 |
+
Q.visible = (g, self, other) => {
|
| 40 |
+
const tr = Q.trace(g, eye(g.ents[self]), null, null, eye(g.ents[other]), self, Q.MASK_OPAQUE);
|
| 41 |
+
return tr.fraction === 1.0;
|
| 42 |
+
};
|
| 43 |
+
Q.visiblePoint = (g, self, point) => Q.trace(g, eye(g.ents[self]), null, null, point, self, Q.MASK_OPAQUE).fraction === 1.0;
|
| 44 |
+
Q.infront = (g, self, other) => {
|
| 45 |
+
const s = g.ents[self], forward = Q.angleVectors(s.angles).forward;
|
| 46 |
+
return dot(norm(sub(g.ents[other].origin, s.origin)), forward) > 0.3;
|
| 47 |
+
};
|
| 48 |
+
Q.range = (g, self, other) => {
|
| 49 |
+
const l = len(sub(g.ents[self].origin, g.ents[other].origin));
|
| 50 |
+
return l < Q.MELEE_DISTANCE ? Q.RANGE_MELEE : l < 500 ? Q.RANGE_NEAR : l < 1000 ? Q.RANGE_MID : Q.RANGE_FAR;
|
| 51 |
+
};
|
| 52 |
+
const link = (g, i) => { g.ents[i].linkcount++; };
|
| 53 |
+
const def = e => DEFS[e.classname];
|
| 54 |
+
const setMove = (e, name) => { e.monsterinfo.currentmove = name; };
|
| 55 |
+
const call = (g, i, fn, ...args) => { const f = def(g.ents[i])[fn]; if (f) f(g, i, ...args); };
|
| 56 |
+
|
| 57 |
+
// ---------------- movement (m_move.c) ----------------
|
| 58 |
+
function checkBottom(g, i) {
|
| 59 |
+
const e = g.ents[i], mins = add(e.origin, e.mins), maxs = add(e.origin, e.maxs);
|
| 60 |
+
let easy = true;
|
| 61 |
+
for (let x = 0; x <= 1 && easy; x++) for (let y = 0; y <= 1; y++) {
|
| 62 |
+
const p = [x ? maxs[0] : mins[0], y ? maxs[1] : mins[1], mins[2] - 1];
|
| 63 |
+
if (Q.pointcontents(g, p) !== Q.CONTENTS_SOLID) { easy = false; break; }
|
| 64 |
+
}
|
| 65 |
+
if (easy) return true;
|
| 66 |
+
const start = [(mins[0] + maxs[0]) * 0.5, (mins[1] + maxs[1]) * 0.5, mins[2]], stop = [start[0], start[1], start[2] - 2 * Q.STEPSIZE];
|
| 67 |
+
let tr = Q.trace(g, start, null, null, stop, i, Q.MASK_MONSTERSOLID);
|
| 68 |
+
if (tr.fraction === 1.0) return false;
|
| 69 |
+
const mid = tr.endpos[2];
|
| 70 |
+
for (let x = 0; x <= 1; x++) for (let y = 0; y <= 1; y++) {
|
| 71 |
+
const s = [x ? maxs[0] : mins[0], y ? maxs[1] : mins[1], mins[2]], t = [s[0], s[1], stop[2]];
|
| 72 |
+
tr = Q.trace(g, s, null, null, t, i, Q.MASK_MONSTERSOLID);
|
| 73 |
+
if (tr.fraction === 1.0 || mid - tr.endpos[2] > Q.STEPSIZE) return false;
|
| 74 |
+
}
|
| 75 |
+
return true;
|
| 76 |
+
}
|
| 77 |
+
function movestep(g, i, move, relink) {
|
| 78 |
+
const e = g.ents[i], oldorg = copy3(e.origin);
|
| 79 |
+
if (e.flags & (Q.FL_SWIM | Q.FL_FLY)) {
|
| 80 |
+
for (let k = 0; k < 2; k++) {
|
| 81 |
+
const neworg = add(e.origin, move);
|
| 82 |
+
if (k === 0 && e.enemy >= 0) {
|
| 83 |
+
if (e.goalentity < 0) e.goalentity = e.enemy;
|
| 84 |
+
const goal = g.ents[e.goalentity], dz = e.origin[2] - goal.origin[2];
|
| 85 |
+
if (goal.client) { if (dz > 40) neworg[2] -= 8; if (dz < 30) neworg[2] += 8; }
|
| 86 |
+
else { if (dz > 8) neworg[2] -= 8; else if (dz > 0) neworg[2] -= dz; else if (dz < -8) neworg[2] += 8; else neworg[2] += dz; }
|
| 87 |
+
}
|
| 88 |
+
const tr = Q.trace(g, e.origin, e.mins, e.maxs, neworg, i, Q.MASK_MONSTERSOLID);
|
| 89 |
+
if (tr.fraction === 1) { e.origin = copy3(tr.endpos); if (relink) link(g, i); return true; }
|
| 90 |
+
if (e.enemy < 0) break;
|
| 91 |
+
}
|
| 92 |
+
return false;
|
| 93 |
+
}
|
| 94 |
+
const stepsize = (e.monsterinfo.aiflags & 0) ? 1 : Q.STEPSIZE;
|
| 95 |
+
const neworg = add(e.origin, move); neworg[2] += stepsize;
|
| 96 |
+
const end = copy3(neworg); end[2] -= stepsize * 2;
|
| 97 |
+
let tr = Q.trace(g, neworg, e.mins, e.maxs, end, i, Q.MASK_MONSTERSOLID);
|
| 98 |
+
if (tr.allsolid) return false;
|
| 99 |
+
if (tr.startsolid) {
|
| 100 |
+
neworg[2] -= stepsize;
|
| 101 |
+
tr = Q.trace(g, neworg, e.mins, e.maxs, end, i, Q.MASK_MONSTERSOLID);
|
| 102 |
+
if (tr.allsolid || tr.startsolid) return false;
|
| 103 |
+
}
|
| 104 |
+
if (tr.fraction === 1) {
|
| 105 |
+
if (e.flags & Q.FL_PARTIALGROUND) { e.origin = add(e.origin, move); if (relink) link(g, i); e.groundentity = -1; return true; }
|
| 106 |
+
return false; // walked off an edge
|
| 107 |
+
}
|
| 108 |
+
e.origin = copy3(tr.endpos);
|
| 109 |
+
if (!checkBottom(g, i)) {
|
| 110 |
+
if (e.flags & Q.FL_PARTIALGROUND) { if (relink) link(g, i); return true; }
|
| 111 |
+
e.origin = oldorg; return false;
|
| 112 |
+
}
|
| 113 |
+
e.flags &= ~Q.FL_PARTIALGROUND;
|
| 114 |
+
e.groundentity = tr.ent;
|
| 115 |
+
if (relink) link(g, i);
|
| 116 |
+
return true;
|
| 117 |
+
}
|
| 118 |
+
Q.changeYaw = (g, i) => { // M_ChangeYaw
|
| 119 |
+
const e = g.ents[i], current = Q.anglemod(e.angles[1]), ideal = e.ideal_yaw;
|
| 120 |
+
if (current === ideal) return;
|
| 121 |
+
let move = ideal - current; const speed = e.yaw_speed;
|
| 122 |
+
if (ideal > current) { if (move >= 180) move -= 360; } else { if (move <= -180) move += 360; }
|
| 123 |
+
if (move > 0) { if (move > speed) move = speed; } else { if (move < -speed) move = -speed; }
|
| 124 |
+
e.angles[1] = Q.anglemod(current + move);
|
| 125 |
+
};
|
| 126 |
+
function stepDirection(g, i, yaw, dist) {
|
| 127 |
+
const e = g.ents[i];
|
| 128 |
+
e.ideal_yaw = yaw; Q.changeYaw(g, i);
|
| 129 |
+
const r = yaw * Math.PI * 2 / 360, move = [Q.cos(r) * dist, Q.sin(r) * dist, 0], old = copy3(e.origin);
|
| 130 |
+
if (movestep(g, i, move, false)) {
|
| 131 |
+
const delta = e.angles[1] - e.ideal_yaw;
|
| 132 |
+
if (delta > 45 && delta < 315) e.origin = old; // not turned far enough, so don't take the step
|
| 133 |
+
link(g, i);
|
| 134 |
+
return true;
|
| 135 |
+
}
|
| 136 |
+
link(g, i);
|
| 137 |
+
return false;
|
| 138 |
+
}
|
| 139 |
+
function newChaseDir(g, i, goal, dist) {
|
| 140 |
+
const e = g.ents[i];
|
| 141 |
+
if (goal < 0) return;
|
| 142 |
+
const olddir = Q.anglemod(Math.trunc(e.ideal_yaw / 45) * 45), turnaround = Q.anglemod(olddir - 180);
|
| 143 |
+
const gorg = g.ents[goal].origin, deltax = gorg[0] - e.origin[0], deltay = gorg[1] - e.origin[1], d = [0, 0, 0];
|
| 144 |
+
d[1] = deltax > 10 ? 0 : deltax < -10 ? 180 : -1;
|
| 145 |
+
d[2] = deltay < -10 ? 270 : deltay > 10 ? 90 : -1;
|
| 146 |
+
if (d[1] !== -1 && d[2] !== -1) {
|
| 147 |
+
const tdir = d[1] === 0 ? (d[2] === 90 ? 45 : 315) : (d[2] === 90 ? 135 : 215);
|
| 148 |
+
if (tdir !== turnaround && stepDirection(g, i, tdir, dist)) return;
|
| 149 |
+
}
|
| 150 |
+
if (((Q.rand(g) & 3) & 1) || Math.abs(Math.trunc(deltay)) > Math.abs(Math.trunc(deltax))) { const t = d[1]; d[1] = d[2]; d[2] = t; }
|
| 151 |
+
if (d[1] !== -1 && d[1] !== turnaround && stepDirection(g, i, d[1], dist)) return;
|
| 152 |
+
if (d[2] !== -1 && d[2] !== turnaround && stepDirection(g, i, d[2], dist)) return;
|
| 153 |
+
if (olddir !== -1 && stepDirection(g, i, olddir, dist)) return;
|
| 154 |
+
if (Q.rand(g) & 1) { for (let t = 0; t <= 315; t += 45) if (t !== turnaround && stepDirection(g, i, t, dist)) return; }
|
| 155 |
+
else { for (let t = 315; t >= 0; t -= 45) if (t !== turnaround && stepDirection(g, i, t, dist)) return; }
|
| 156 |
+
if (turnaround !== -1 && stepDirection(g, i, turnaround, dist)) return;
|
| 157 |
+
e.ideal_yaw = olddir; // can't move
|
| 158 |
+
if (!checkBottom(g, i)) e.flags |= Q.FL_PARTIALGROUND;
|
| 159 |
+
}
|
| 160 |
+
function closeEnough(g, i, goal, dist) {
|
| 161 |
+
const e = g.ents[i], t = g.ents[goal], amin = Q.absmin(e), amax = Q.absmax(e), gmin = Q.absmin(t), gmax = Q.absmax(t);
|
| 162 |
+
for (let k = 0; k < 3; k++) { if (gmin[k] > amax[k] + dist) return false; if (gmax[k] < amin[k] - dist) return false; }
|
| 163 |
+
return true;
|
| 164 |
+
}
|
| 165 |
+
function moveToGoal(g, i, dist) {
|
| 166 |
+
const e = g.ents[i], goal = e.goalentity;
|
| 167 |
+
if (e.groundentity < 0 && !(e.flags & (Q.FL_FLY | Q.FL_SWIM))) return;
|
| 168 |
+
if (e.enemy >= 0 && closeEnough(g, i, e.enemy, dist)) return;
|
| 169 |
+
if ((Q.rand(g) & 3) === 1 || !stepDirection(g, i, e.ideal_yaw, dist)) { if (g.ents[i].inuse) newChaseDir(g, i, goal, dist); }
|
| 170 |
+
}
|
| 171 |
+
const walkmove = (g, i, yaw, dist) => {
|
| 172 |
+
const e = g.ents[i];
|
| 173 |
+
if (e.groundentity < 0 && !(e.flags & (Q.FL_FLY | Q.FL_SWIM))) return false;
|
| 174 |
+
const r = yaw * Math.PI * 2 / 360;
|
| 175 |
+
return movestep(g, i, [Q.cos(r) * dist, Q.sin(r) * dist, 0], true);
|
| 176 |
+
};
|
| 177 |
+
Q.walkmove = walkmove;
|
| 178 |
+
function checkGround(g, i) { // M_CheckGround
|
| 179 |
+
const e = g.ents[i];
|
| 180 |
+
if (e.flags & (Q.FL_SWIM | Q.FL_FLY)) return;
|
| 181 |
+
if (e.velocity[2] > 100) { e.groundentity = -1; return; }
|
| 182 |
+
const point = [e.origin[0], e.origin[1], e.origin[2] - 0.25];
|
| 183 |
+
const tr = Q.trace(g, e.origin, e.mins, e.maxs, point, i, Q.MASK_MONSTERSOLID);
|
| 184 |
+
if (tr.normal[2] < 0.7 && !tr.startsolid) { e.groundentity = -1; return; }
|
| 185 |
+
if (!tr.startsolid && !tr.allsolid) { e.origin = copy3(tr.endpos); e.groundentity = tr.ent; e.velocity[2] = 0; }
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
// ---------------- AI (g_ai.c) ----------------
|
| 189 |
+
function foundTarget(g, i) {
|
| 190 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 191 |
+
if (g.ents[e.enemy].client) { g.sight_entity = i; g.sight_entity_framenum = g.framenum; }
|
| 192 |
+
e.show_hostile = g.ms + 1000;
|
| 193 |
+
mi.last_sighting = copy3(g.ents[e.enemy].origin); mi.trail_time = g.ms;
|
| 194 |
+
huntTarget(g, i);
|
| 195 |
+
}
|
| 196 |
+
function huntTarget(g, i) {
|
| 197 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 198 |
+
e.goalentity = e.enemy;
|
| 199 |
+
if (mi.aiflags & AI_STAND_GROUND) call(g, i, 'stand'); else call(g, i, 'run');
|
| 200 |
+
e.ideal_yaw = Q.vectoyaw(sub(g.ents[e.enemy].origin, e.origin));
|
| 201 |
+
if (!(mi.aiflags & AI_STAND_GROUND)) mi.attack_finished = g.ms + 1000; // AttackFinished (self, 1)
|
| 202 |
+
}
|
| 203 |
+
// FindTarget: the sight entity (a monster that just found the player), the player's own noise (firing, jumping),
|
| 204 |
+
// impact noise for idle monsters, else the sight client checked by range / visibility / facing. Arena light is
|
| 205 |
+
// above light_level 5 everywhere, the arena is one PHS / area, and no monster here is an ambusher.
|
| 206 |
+
function findTarget(g, i) {
|
| 207 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 208 |
+
let client, heardit = false;
|
| 209 |
+
if (g.sight_entity_framenum >= g.framenum - 1) {
|
| 210 |
+
client = g.sight_entity;
|
| 211 |
+
if (g.ents[client].enemy === e.enemy) return false;
|
| 212 |
+
} else if (g.sound_entity_framenum >= g.framenum - 1) { client = g.sound_entity; heardit = true; }
|
| 213 |
+
else if (e.enemy < 0 && g.sound2_entity_framenum >= g.framenum - 1) { client = g.sound2_entity; heardit = true; }
|
| 214 |
+
else { client = g.sight_client; if (client < 0) return false; }
|
| 215 |
+
const c = g.ents[client];
|
| 216 |
+
if (!c || !c.inuse) return false;
|
| 217 |
+
if (client === e.enemy) return true;
|
| 218 |
+
if (c.client) { /* FL_NOTARGET is never set */ }
|
| 219 |
+
else if (c.svflags & Q.SVF_MONSTER) { if (c.enemy < 0) return false; }
|
| 220 |
+
else if (!heardit) return false;
|
| 221 |
+
if (!heardit) {
|
| 222 |
+
const r = Q.range(g, i, client);
|
| 223 |
+
if (r === Q.RANGE_FAR) return false;
|
| 224 |
+
if (!Q.visible(g, i, client)) return false;
|
| 225 |
+
if (r === Q.RANGE_NEAR) { if ((c.show_hostile || 0) < g.ms && !Q.infront(g, i, client)) return false; }
|
| 226 |
+
else if (r === Q.RANGE_MID) { if (!Q.infront(g, i, client)) return false; }
|
| 227 |
+
e.enemy = client;
|
| 228 |
+
if (c.classname !== 'player_noise') {
|
| 229 |
+
mi.aiflags &= ~AI_SOUND_TARGET;
|
| 230 |
+
if (!g.ents[e.enemy].client) {
|
| 231 |
+
e.enemy = g.ents[e.enemy].enemy;
|
| 232 |
+
if (e.enemy < 0 || !g.ents[e.enemy].client) { e.enemy = -1; return false; }
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
} else {
|
| 236 |
+
const temp = sub(c.origin, e.origin);
|
| 237 |
+
if (len(temp) > 1000) return false; // too far to hear
|
| 238 |
+
e.ideal_yaw = Q.vectoyaw(temp); Q.changeYaw(g, i);
|
| 239 |
+
mi.aiflags |= AI_SOUND_TARGET;
|
| 240 |
+
e.enemy = client;
|
| 241 |
+
}
|
| 242 |
+
foundTarget(g, i);
|
| 243 |
+
if (!(mi.aiflags & AI_SOUND_TARGET)) call(g, i, 'sight');
|
| 244 |
+
return true;
|
| 245 |
+
}
|
| 246 |
+
const AIF = {
|
| 247 |
+
stand(g, i, dist) {
|
| 248 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 249 |
+
if (dist) walkmove(g, i, e.angles[1], dist);
|
| 250 |
+
if (mi.aiflags & AI_STAND_GROUND) {
|
| 251 |
+
if (e.enemy >= 0) {
|
| 252 |
+
e.ideal_yaw = Q.vectoyaw(sub(g.ents[e.enemy].origin, e.origin));
|
| 253 |
+
if (e.angles[1] !== e.ideal_yaw && (mi.aiflags & AI_TEMP_STAND_GROUND)) { mi.aiflags &= ~(AI_STAND_GROUND | AI_TEMP_STAND_GROUND); call(g, i, 'run'); }
|
| 254 |
+
Q.changeYaw(g, i);
|
| 255 |
+
aiCheckAttack(g, i, 0);
|
| 256 |
+
} else findTarget(g, i);
|
| 257 |
+
return;
|
| 258 |
+
}
|
| 259 |
+
if (findTarget(g, i)) return;
|
| 260 |
+
// pausetime is set far ahead in every path here, so the walk branch never runs; idle sounds do not exist.
|
| 261 |
+
},
|
| 262 |
+
walk(g, i, dist) { moveToGoal(g, i, dist); findTarget(g, i); },
|
| 263 |
+
turn(g, i, dist) { if (dist) walkmove(g, i, g.ents[i].angles[1], dist); if (findTarget(g, i)) return; Q.changeYaw(g, i); },
|
| 264 |
+
move(g, i, dist) { walkmove(g, i, g.ents[i].angles[1], dist); },
|
| 265 |
+
charge(g, i, dist) {
|
| 266 |
+
const e = g.ents[i];
|
| 267 |
+
e.ideal_yaw = Q.vectoyaw(sub(g.ents[e.enemy].origin, e.origin));
|
| 268 |
+
Q.changeYaw(g, i);
|
| 269 |
+
if (dist) walkmove(g, i, e.angles[1], dist);
|
| 270 |
+
},
|
| 271 |
+
run(g, i, dist) { aiRun(g, i, dist); },
|
| 272 |
+
};
|
| 273 |
+
// M_CheckAttack (default) with the skill scaling of the attack chance.
|
| 274 |
+
Q.M_CheckAttack = (g, i) => {
|
| 275 |
+
const e = g.ents[i], mi = e.monsterinfo, en = g.ents[e.enemy];
|
| 276 |
+
if (en.health > 0) {
|
| 277 |
+
const tr = Q.trace(g, eye(e), null, null, eye(en), i, Q.CONTENTS_SOLID | Q.CONTENTS_MONSTER | Q.CONTENTS_SLIME | Q.CONTENTS_LAVA | Q.CONTENTS_WINDOW);
|
| 278 |
+
if (tr.ent !== e.enemy) return false;
|
| 279 |
+
}
|
| 280 |
+
if (g.ai.enemy_range === Q.RANGE_MELEE) {
|
| 281 |
+
if (g.skill === 0 && (Q.rand(g) & 3)) return false;
|
| 282 |
+
mi.attack_state = def(e).melee ? AS_MELEE : AS_MISSILE; return true;
|
| 283 |
+
}
|
| 284 |
+
if (!def(e).attack) return false;
|
| 285 |
+
if (g.ms < mi.attack_finished) return false;
|
| 286 |
+
if (g.ai.enemy_range === Q.RANGE_FAR) return false;
|
| 287 |
+
let chance;
|
| 288 |
+
if (mi.aiflags & AI_STAND_GROUND) chance = 0.4;
|
| 289 |
+
else if (g.ai.enemy_range === Q.RANGE_NEAR) chance = 0.1;
|
| 290 |
+
else if (g.ai.enemy_range === Q.RANGE_MID) chance = 0.02;
|
| 291 |
+
else return false;
|
| 292 |
+
if (g.skill === 0) chance *= 0.5; else if (g.skill >= 2) chance *= 2;
|
| 293 |
+
if (Q.random(g) < chance) { mi.attack_state = AS_MISSILE; mi.attack_finished = g.ms + 2000 * Q.random(g); return true; }
|
| 294 |
+
if (e.flags & Q.FL_FLY) mi.attack_state = Q.random(g) < 0.3 ? AS_SLIDING : AS_STRAIGHT;
|
| 295 |
+
return false;
|
| 296 |
+
};
|
| 297 |
+
// Boss2_CheckAttack / Jorg_CheckAttack / Makron_CheckAttack share one shape: no skill scaling, own chances.
|
| 298 |
+
function bossCheckAttack(near, mid) {
|
| 299 |
+
return (g, i) => {
|
| 300 |
+
const e = g.ents[i], mi = e.monsterinfo, en = g.ents[e.enemy];
|
| 301 |
+
if (en.health > 0) {
|
| 302 |
+
const tr = Q.trace(g, eye(e), null, null, eye(en), i, Q.CONTENTS_SOLID | Q.CONTENTS_MONSTER | Q.CONTENTS_SLIME | Q.CONTENTS_LAVA);
|
| 303 |
+
if (tr.ent !== e.enemy) return false;
|
| 304 |
+
}
|
| 305 |
+
const range = Q.range(g, i, e.enemy);
|
| 306 |
+
e.ideal_yaw = Q.vectoyaw(sub(en.origin, e.origin));
|
| 307 |
+
if (range === Q.RANGE_MELEE) { mi.attack_state = def(e).melee ? AS_MELEE : AS_MISSILE; return true; }
|
| 308 |
+
if (!def(e).attack) return false;
|
| 309 |
+
if (g.ms < mi.attack_finished) return false;
|
| 310 |
+
if (range === Q.RANGE_FAR) return false;
|
| 311 |
+
let chance;
|
| 312 |
+
if (mi.aiflags & AI_STAND_GROUND) chance = 0.4;
|
| 313 |
+
else if (range === Q.RANGE_NEAR) chance = near;
|
| 314 |
+
else if (range === Q.RANGE_MID) chance = mid;
|
| 315 |
+
else return false;
|
| 316 |
+
if (Q.random(g) < chance) { mi.attack_state = AS_MISSILE; mi.attack_finished = g.ms + 2000 * Q.random(g); return true; }
|
| 317 |
+
if (e.flags & Q.FL_FLY) mi.attack_state = Q.random(g) < 0.3 ? AS_SLIDING : AS_STRAIGHT;
|
| 318 |
+
return false;
|
| 319 |
+
};
|
| 320 |
+
}
|
| 321 |
+
const facingIdeal = e => { const d = Q.anglemod(e.angles[1] - e.ideal_yaw); return !(d > 45 && d < 315); };
|
| 322 |
+
function aiCheckAttack(g, i, dist) {
|
| 323 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 324 |
+
if (e.goalentity >= 0 && (mi.aiflags & AI_SOUND_TARGET)) {
|
| 325 |
+
if (g.ms - (g.ents[e.enemy].teleport_time || 0) > 5000) {
|
| 326 |
+
if (e.goalentity === e.enemy) e.goalentity = -1; // no movetarget in these arenas
|
| 327 |
+
mi.aiflags &= ~AI_SOUND_TARGET;
|
| 328 |
+
if (mi.aiflags & AI_TEMP_STAND_GROUND) mi.aiflags &= ~(AI_STAND_GROUND | AI_TEMP_STAND_GROUND);
|
| 329 |
+
} else { e.show_hostile = g.ms + 1000; return false; }
|
| 330 |
+
}
|
| 331 |
+
g.ai.enemy_vis = false;
|
| 332 |
+
const en = e.enemy >= 0 ? g.ents[e.enemy] : null;
|
| 333 |
+
// hesDeadJim: AI_BRUTAL monsters (the Tank) keep going until the enemy is below -80; a player_noise target has
|
| 334 |
+
// no health either.
|
| 335 |
+
const dead = !en || !en.inuse || (en.health || 0) <= ((mi.aiflags & AI_BRUTAL) ? -80 : 0);
|
| 336 |
+
if (dead) {
|
| 337 |
+
e.enemy = -1;
|
| 338 |
+
if (e.oldenemy >= 0 && g.ents[e.oldenemy].inuse && g.ents[e.oldenemy].health > 0) { e.enemy = e.oldenemy; e.oldenemy = -1; huntTarget(g, i); }
|
| 339 |
+
else { mi.pausetime = g.ms + 100000000000; call(g, i, 'stand'); return true; }
|
| 340 |
+
}
|
| 341 |
+
e.show_hostile = g.ms + 1000;
|
| 342 |
+
g.ai.enemy_vis = Q.visible(g, i, e.enemy);
|
| 343 |
+
if (g.ai.enemy_vis) { mi.search_time = g.ms + 5000; mi.last_sighting = copy3(g.ents[e.enemy].origin); }
|
| 344 |
+
g.ai.enemy_infront = Q.infront(g, i, e.enemy);
|
| 345 |
+
g.ai.enemy_range = Q.range(g, i, e.enemy);
|
| 346 |
+
g.ai.enemy_yaw = Q.vectoyaw(sub(g.ents[e.enemy].origin, e.origin));
|
| 347 |
+
if (mi.attack_state === AS_MISSILE) { // ai_run_missile
|
| 348 |
+
e.ideal_yaw = g.ai.enemy_yaw; Q.changeYaw(g, i);
|
| 349 |
+
if (facingIdeal(e)) { call(g, i, 'attack'); mi.attack_state = AS_STRAIGHT; }
|
| 350 |
+
return true;
|
| 351 |
+
}
|
| 352 |
+
if (mi.attack_state === AS_MELEE) {
|
| 353 |
+
e.ideal_yaw = g.ai.enemy_yaw; Q.changeYaw(g, i);
|
| 354 |
+
if (facingIdeal(e)) { call(g, i, 'melee'); mi.attack_state = AS_STRAIGHT; }
|
| 355 |
+
return true;
|
| 356 |
+
}
|
| 357 |
+
if (!g.ai.enemy_vis) return false;
|
| 358 |
+
return (def(e).checkattack || Q.M_CheckAttack)(g, i);
|
| 359 |
+
}
|
| 360 |
+
function aiRun(g, i, dist) {
|
| 361 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 362 |
+
if (mi.aiflags & AI_SOUND_TARGET) {
|
| 363 |
+
if (len(sub(e.origin, g.ents[e.enemy].origin)) < 64) { mi.aiflags |= AI_STAND_GROUND | AI_TEMP_STAND_GROUND; call(g, i, 'stand'); return; }
|
| 364 |
+
moveToGoal(g, i, dist);
|
| 365 |
+
if (!findTarget(g, i)) return;
|
| 366 |
+
}
|
| 367 |
+
if (aiCheckAttack(g, i, dist)) return;
|
| 368 |
+
if (mi.attack_state === AS_SLIDING) { // ai_run_slide
|
| 369 |
+
e.ideal_yaw = g.ai.enemy_yaw; Q.changeYaw(g, i);
|
| 370 |
+
const ofs = mi.lefty ? 90 : -90;
|
| 371 |
+
if (walkmove(g, i, e.ideal_yaw + ofs, dist)) return;
|
| 372 |
+
mi.lefty = 1 - mi.lefty;
|
| 373 |
+
walkmove(g, i, e.ideal_yaw - ofs, dist);
|
| 374 |
+
return;
|
| 375 |
+
}
|
| 376 |
+
if (g.ai.enemy_vis) {
|
| 377 |
+
moveToGoal(g, i, dist);
|
| 378 |
+
mi.aiflags &= ~AI_LOST_SIGHT;
|
| 379 |
+
mi.last_sighting = copy3(g.ents[e.enemy].origin); mi.trail_time = g.ms;
|
| 380 |
+
mi.stall_pos = copy3(e.origin); mi.stall_t = g.ms; mi.chase_until = 0;
|
| 381 |
+
return;
|
| 382 |
+
}
|
| 383 |
+
// BossBench engagement rule (not in Quake II; meeting rule "a boss must never stop pursuing"): the lost-sight
|
| 384 |
+
// pursuit below can ping-pong between two course-correction targets when a large boss is flush against a pillar,
|
| 385 |
+
// and since every PURSUE_NEXT renews search_time the original 20 s fallback never fires. If the boss has neither
|
| 386 |
+
// seen the player nor moved 48 units for 3 s, it takes that original fallback early: 2 s of M_MoveToGoal straight
|
| 387 |
+
// at its enemy (SV_NewChaseDir steps around the obstacle).
|
| 388 |
+
if (mi.chase_until > g.ms) { moveToGoal(g, i, dist); return; }
|
| 389 |
+
if (!mi.stall_pos || len(sub(e.origin, mi.stall_pos)) > 48) { mi.stall_pos = copy3(e.origin); mi.stall_t = g.ms; }
|
| 390 |
+
else if (g.ms - mi.stall_t >= 3000) {
|
| 391 |
+
mi.chase_until = g.ms + 2000; mi.stall_pos = null;
|
| 392 |
+
mi.aiflags &= ~(AI_LOST_SIGHT | AI_PURSUIT_LAST_SEEN | AI_PURSUE_NEXT | AI_PURSUE_TEMP);
|
| 393 |
+
Q.event(g, 'boss_unstick', { classname: e.classname });
|
| 394 |
+
moveToGoal(g, i, dist);
|
| 395 |
+
return;
|
| 396 |
+
}
|
| 397 |
+
if (mi.search_time && g.ms > mi.search_time + 20000) { moveToGoal(g, i, dist); mi.search_time = 0; return; }
|
| 398 |
+
// Lost sight: chase last_sighting, then the player trail, with the course correction traces.
|
| 399 |
+
const save = e.goalentity, tempgoal = Q.spawn(g);
|
| 400 |
+
e.goalentity = tempgoal;
|
| 401 |
+
let fresh = false;
|
| 402 |
+
if (!(mi.aiflags & AI_LOST_SIGHT)) { mi.aiflags |= AI_LOST_SIGHT | AI_PURSUIT_LAST_SEEN; mi.aiflags &= ~(AI_PURSUE_NEXT | AI_PURSUE_TEMP); fresh = true; }
|
| 403 |
+
if (mi.aiflags & AI_PURSUE_NEXT) {
|
| 404 |
+
mi.aiflags &= ~AI_PURSUE_NEXT;
|
| 405 |
+
mi.search_time = g.ms + 5000;
|
| 406 |
+
let marker = null;
|
| 407 |
+
if (mi.aiflags & AI_PURSUE_TEMP) { mi.aiflags &= ~AI_PURSUE_TEMP; mi.last_sighting = copy3(mi.saved_goal); fresh = true; }
|
| 408 |
+
else if (mi.aiflags & AI_PURSUIT_LAST_SEEN) { mi.aiflags &= ~AI_PURSUIT_LAST_SEEN; marker = Q.trailPick(g, i, true); }
|
| 409 |
+
else marker = Q.trailPick(g, i, false);
|
| 410 |
+
if (marker) { mi.last_sighting = copy3(marker.origin); mi.trail_time = marker.timestamp; e.angles[1] = e.ideal_yaw = marker.yaw; fresh = true; }
|
| 411 |
+
}
|
| 412 |
+
let d1 = len(sub(e.origin, mi.last_sighting));
|
| 413 |
+
if (d1 <= dist) { mi.aiflags |= AI_PURSUE_NEXT; dist = d1; }
|
| 414 |
+
g.ents[tempgoal].origin = copy3(mi.last_sighting);
|
| 415 |
+
if (fresh) {
|
| 416 |
+
let tr = Q.trace(g, e.origin, e.mins, e.maxs, mi.last_sighting, i, Q.MASK_PLAYERSOLID);
|
| 417 |
+
if (tr.fraction < 1) {
|
| 418 |
+
const v = sub(g.ents[tempgoal].origin, e.origin);
|
| 419 |
+
d1 = len(v);
|
| 420 |
+
let center = tr.fraction;
|
| 421 |
+
const d2 = d1 * ((center + 1) / 2);
|
| 422 |
+
e.angles[1] = e.ideal_yaw = Q.vectoyaw(v);
|
| 423 |
+
const av = Q.angleVectors(e.angles);
|
| 424 |
+
let left_target = Q.projectSource(e.origin, [d2, -16, 0], av.forward, av.right);
|
| 425 |
+
tr = Q.trace(g, e.origin, e.mins, e.maxs, left_target, i, Q.MASK_PLAYERSOLID);
|
| 426 |
+
const left = tr.fraction;
|
| 427 |
+
let right_target = Q.projectSource(e.origin, [d2, 16, 0], av.forward, av.right);
|
| 428 |
+
tr = Q.trace(g, e.origin, e.mins, e.maxs, right_target, i, Q.MASK_PLAYERSOLID);
|
| 429 |
+
const right = tr.fraction;
|
| 430 |
+
center = (d1 * center) / d2;
|
| 431 |
+
if (left >= center && left > right) {
|
| 432 |
+
if (left < 1) left_target = Q.projectSource(e.origin, [d2 * left * 0.5, -16, 0], av.forward, av.right);
|
| 433 |
+
mi.saved_goal = copy3(mi.last_sighting); mi.aiflags |= AI_PURSUE_TEMP;
|
| 434 |
+
g.ents[tempgoal].origin = copy3(left_target); mi.last_sighting = copy3(left_target);
|
| 435 |
+
e.angles[1] = e.ideal_yaw = Q.vectoyaw(sub(g.ents[tempgoal].origin, e.origin));
|
| 436 |
+
} else if (right >= center && right > left) {
|
| 437 |
+
if (right < 1) right_target = Q.projectSource(e.origin, [d2 * right * 0.5, 16, 0], av.forward, av.right);
|
| 438 |
+
mi.saved_goal = copy3(mi.last_sighting); mi.aiflags |= AI_PURSUE_TEMP;
|
| 439 |
+
g.ents[tempgoal].origin = copy3(right_target); mi.last_sighting = copy3(right_target);
|
| 440 |
+
e.angles[1] = e.ideal_yaw = Q.vectoyaw(sub(g.ents[tempgoal].origin, e.origin));
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
}
|
| 444 |
+
moveToGoal(g, i, dist);
|
| 445 |
+
Q.freeEdict(g, tempgoal);
|
| 446 |
+
if (g.ents[i].inuse) g.ents[i].goalentity = save;
|
| 447 |
+
}
|
| 448 |
+
// M_ReactToDamage: the player is the only other combatant; damage from the monster itself is ignored.
|
| 449 |
+
Q.reactToDamage = (g, targ, attacker) => {
|
| 450 |
+
const t = g.ents[targ], a = g.ents[attacker];
|
| 451 |
+
if (!a || (!a.client && !(a.svflags & Q.SVF_MONSTER))) return;
|
| 452 |
+
if (attacker === targ || attacker === t.enemy) return;
|
| 453 |
+
if (a.client) {
|
| 454 |
+
t.monsterinfo.aiflags &= ~AI_SOUND_TARGET;
|
| 455 |
+
if (t.enemy >= 0 && g.ents[t.enemy].client) {
|
| 456 |
+
if (Q.visible(g, targ, t.enemy)) { t.oldenemy = attacker; return; }
|
| 457 |
+
t.oldenemy = t.enemy;
|
| 458 |
+
}
|
| 459 |
+
t.enemy = attacker;
|
| 460 |
+
if (!(t.monsterinfo.aiflags & AI_DUCKED)) foundTarget(g, targ);
|
| 461 |
+
}
|
| 462 |
+
};
|
| 463 |
+
Q.AI_DUCKED = AI_DUCKED;
|
| 464 |
+
Q.monsterPain = (g, i, attacker, kick, damage) => call(g, i, 'pain', attacker, kick, damage);
|
| 465 |
+
Q.monsterDie = (g, i, inflictor, attacker, damage, point) => call(g, i, 'die', inflictor, attacker, damage, point);
|
| 466 |
+
// monster_death_use: fliers drop out of the air; the case decides what the death triggers (Makron's spawn, the win).
|
| 467 |
+
Q.monsterDeathUse = (g, i) => {
|
| 468 |
+
const e = g.ents[i];
|
| 469 |
+
e.flags &= ~(Q.FL_FLY | Q.FL_SWIM);
|
| 470 |
+
e.monsterinfo.aiflags &= AI_GOOD_GUY;
|
| 471 |
+
Q.event(g, 'boss_killed', { classname: e.classname });
|
| 472 |
+
if (e.final) g.bossKilled = g.t + 1;
|
| 473 |
+
};
|
| 474 |
+
|
| 475 |
+
// ---------------- framework (g_monster.c) ----------------
|
| 476 |
+
function moveFrame(g, i) {
|
| 477 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 478 |
+
let move = def(e).moves[mi.currentmove];
|
| 479 |
+
e.nextthink = g.ms + Q.FRAMETIME_MS;
|
| 480 |
+
if (mi.nextframe && mi.nextframe >= move.first && mi.nextframe <= move.last) { e.frame = mi.nextframe; mi.nextframe = 0; }
|
| 481 |
+
else {
|
| 482 |
+
if (e.frame === move.last && move.end) {
|
| 483 |
+
call(g, i, move.end);
|
| 484 |
+
move = def(e).moves[mi.currentmove];
|
| 485 |
+
if (e.svflags & Q.SVF_DEADMONSTER) return;
|
| 486 |
+
}
|
| 487 |
+
if (e.frame < move.first || e.frame > move.last) { mi.aiflags &= ~AI_HOLD_FRAME; e.frame = move.first; }
|
| 488 |
+
else if (!(mi.aiflags & AI_HOLD_FRAME)) { e.frame++; if (e.frame > move.last) e.frame = move.first; }
|
| 489 |
+
}
|
| 490 |
+
const [ai, dist, think] = move.frames[e.frame - move.first];
|
| 491 |
+
if (ai) AIF[ai](g, i, (mi.aiflags & AI_HOLD_FRAME) ? 0 : dist * mi.scale);
|
| 492 |
+
if (think && g.ents[i].inuse) call(g, i, think);
|
| 493 |
+
}
|
| 494 |
+
Q.THINK.monster_think = (g, i) => {
|
| 495 |
+
moveFrame(g, i);
|
| 496 |
+
const e = g.ents[i];
|
| 497 |
+
if (!e.inuse) return;
|
| 498 |
+
if (e.linkcount !== e.monsterinfo.linkcount) { e.monsterinfo.linkcount = e.linkcount; checkGround(g, i); }
|
| 499 |
+
};
|
| 500 |
+
// SV_Physics_Step: gravity, fly / ground friction and SV_FlyMove for a monster with velocity, then think. At 60 Hz
|
| 501 |
+
// (q2-arena@3) the physics runs every host frame with that frame's length (g.dt); the think still fires on its
|
| 502 |
+
// nextthink, i.e. every 100 ms server frame. lerp keeps the displacement of the last think for the renderer, which
|
| 503 |
+
// spreads it over the next 100 ms like the original client (cl_ents.c lerpfrac); it never feeds back into the rules.
|
| 504 |
+
// Friction in SV_Physics_Step is speed * (1 - frametime * friction) once per 100 ms server frame (x0.4 on the
|
| 505 |
+
// ground, x0.8 for a flier's vertical speed). Applied per 16/17 ms host frame it keeps the per-second decay with
|
| 506 |
+
// k^(ms/100) (precomputed, so Node and the browser agree bit for bit); below stopspeed the original subtracts a
|
| 507 |
+
// constant per second, which the linear form already keeps.
|
| 508 |
+
const FRICTION_K = { 16: [0.86363373567437107, 0.96492686487423818], 17: [0.85575648417344741, 0.96277609334680192] };
|
| 509 |
+
const frictionK = (g, fly) => { const k = FRICTION_K[Math.round(g.dt * 1000)]; if (!k) throw Error('host frame ' + g.dt); return k[fly ? 1 : 0]; };
|
| 510 |
+
Q.physicsStep = (g, i) => {
|
| 511 |
+
let e = g.ents[i];
|
| 512 |
+
if (e.groundentity < 0) checkGround(g, i);
|
| 513 |
+
for (let k = 0; k < 3; k++) e.velocity[k] = Math.max(-Q.SV_MAXVELOCITY, Math.min(Q.SV_MAXVELOCITY, e.velocity[k]));
|
| 514 |
+
const wasonground = e.groundentity >= 0, ft = g.dt;
|
| 515 |
+
if (!wasonground && !(e.flags & Q.FL_FLY)) e.velocity[2] -= e.gravity * Q.SV_GRAVITY * ft;
|
| 516 |
+
if ((e.flags & Q.FL_FLY) && e.velocity[2] !== 0) {
|
| 517 |
+
const speed = Math.abs(e.velocity[2]), control = speed < Q.SV_STOPSPEED ? Q.SV_STOPSPEED : speed;
|
| 518 |
+
let ns = speed < Q.SV_STOPSPEED ? speed - ft * control * Q.SV_FRICTION / 3 : speed * frictionK(g, true); if (ns < 0) ns = 0; e.velocity[2] *= ns / speed;
|
| 519 |
+
}
|
| 520 |
+
if (e.velocity[0] || e.velocity[1] || e.velocity[2]) {
|
| 521 |
+
if ((wasonground || (e.flags & (Q.FL_SWIM | Q.FL_FLY))) && !(e.health <= 0 && !checkBottom(g, i))) {
|
| 522 |
+
const speed = Math.sqrt(e.velocity[0] ** 2 + e.velocity[1] ** 2);
|
| 523 |
+
if (speed) {
|
| 524 |
+
const control = speed < Q.SV_STOPSPEED ? Q.SV_STOPSPEED : speed;
|
| 525 |
+
let ns = speed < Q.SV_STOPSPEED ? speed - ft * control * Q.SV_FRICTION : speed * frictionK(g, false); if (ns < 0) ns = 0; ns /= speed;
|
| 526 |
+
e.velocity[0] *= ns; e.velocity[1] *= ns;
|
| 527 |
+
}
|
| 528 |
+
}
|
| 529 |
+
flyMove(g, i, ft, (e.svflags & Q.SVF_MONSTER) ? Q.MASK_MONSTERSOLID : Q.MASK_SOLID);
|
| 530 |
+
link(g, i);
|
| 531 |
+
if (!g.ents[i].inuse) return;
|
| 532 |
+
}
|
| 533 |
+
const before = copy3(g.ents[i].origin);
|
| 534 |
+
if (Q.runThink(g, i) || !g.ents[i].inuse) return;
|
| 535 |
+
const after = g.ents[i].origin;
|
| 536 |
+
g.ents[i].lerp = [before[0] - after[0], before[1] - after[1], before[2] - after[2], g.ms];
|
| 537 |
+
};
|
| 538 |
+
function flyMove(g, i, time, mask) { // SV_FlyMove
|
| 539 |
+
const e = g.ents[i], primal = copy3(e.velocity), planes = [];
|
| 540 |
+
let original = copy3(e.velocity), time_left = time;
|
| 541 |
+
e.groundentity = -1;
|
| 542 |
+
for (let bump = 0; bump < 4; bump++) {
|
| 543 |
+
const end = [0, 1, 2].map(k => e.origin[k] + time_left * e.velocity[k]);
|
| 544 |
+
const tr = Q.trace(g, e.origin, e.mins, e.maxs, end, i, mask);
|
| 545 |
+
if (tr.allsolid) { e.velocity = [0, 0, 0]; return 3; }
|
| 546 |
+
if (tr.fraction > 0) { e.origin = copy3(tr.endpos); original = copy3(e.velocity); planes.length = 0; }
|
| 547 |
+
if (tr.fraction === 1) break;
|
| 548 |
+
if (tr.normal[2] > 0.7 && tr.ent === 0) e.groundentity = 0;
|
| 549 |
+
Q.impact(g, i, tr);
|
| 550 |
+
if (!g.ents[i].inuse) break;
|
| 551 |
+
time_left -= time_left * tr.fraction;
|
| 552 |
+
if (planes.length >= 5) { e.velocity = [0, 0, 0]; return 3; }
|
| 553 |
+
planes.push(tr.normal);
|
| 554 |
+
let k;
|
| 555 |
+
for (k = 0; k < planes.length; k++) {
|
| 556 |
+
const backoff = dot(original, planes[k]), nv = [0, 1, 2].map(c => { const v = original[c] - planes[k][c] * backoff; return v > -0.1 && v < 0.1 ? 0 : v; });
|
| 557 |
+
let j;
|
| 558 |
+
for (j = 0; j < planes.length; j++) if (j !== k && !Q.eq(planes[k], planes[j]) && dot(nv, planes[j]) < 0) break;
|
| 559 |
+
if (j === planes.length) { e.velocity = nv; break; }
|
| 560 |
+
}
|
| 561 |
+
if (k === planes.length) {
|
| 562 |
+
if (planes.length !== 2) { e.velocity = [0, 0, 0]; return 7; }
|
| 563 |
+
const dir = Q.cross(planes[0], planes[1]); e.velocity = scale(dir, dot(dir, e.velocity));
|
| 564 |
+
}
|
| 565 |
+
if (dot(e.velocity, primal) <= 0) { e.velocity = [0, 0, 0]; return 0; }
|
| 566 |
+
}
|
| 567 |
+
return 0;
|
| 568 |
+
}
|
| 569 |
+
// Spawn: SP_monster_* + monster_start; the first think is walkmonster_start_go / flymonster_start_go.
|
| 570 |
+
Q.spawnMonster = (g, classname, origin, yaw, opts) => {
|
| 571 |
+
const i = Q.spawn(g), e = g.ents[i], d = DEFS[classname];
|
| 572 |
+
Object.assign(e, {
|
| 573 |
+
classname, origin: copy3(origin), old_origin: copy3(origin), angles: [0, yaw, 0], ideal_yaw: yaw, mins: copy3(d.mins), maxs: copy3(d.maxs),
|
| 574 |
+
movetype: 'step', solid: Q.SOLID_BBOX, health: opts.health, gib_health: d.gib_health, mass: d.mass, flags: d.fly ? Q.FL_FLY : 0,
|
| 575 |
+
svflags: Q.SVF_MONSTER, takedamage: Q.DAMAGE_AIM, clipmask: Q.MASK_MONSTERSOLID, yaw_speed: 0, viewheight: 0, final: !!opts.final,
|
| 576 |
+
goalentity: -1, oldenemy: -1, movetarget: -1, show_hostile: 0, pain_debounce_time: 0, skinnum: 0, pos1: [0, 0, 0], count: 0,
|
| 577 |
+
think: d.fly ? 'flymonster_start_go' : 'walkmonster_start_go', nextthink: g.ms + Q.FRAMETIME_MS,
|
| 578 |
+
monsterinfo: { currentmove: d.startMove || 'stand', nextframe: 0, aiflags: 0, scale: 1, pausetime: 0, attack_finished: 0, attack_state: 0, lefty: 0,
|
| 579 |
+
search_time: 0, trail_time: 0, last_sighting: [0, 0, 0], saved_goal: [0, 0, 0], linkcount: 0, idle_time: 0,
|
| 580 |
+
stall_pos: null, stall_t: 0, chase_until: 0 },
|
| 581 |
+
});
|
| 582 |
+
if (d.immuneLaser) e.flags |= Q.FL_IMMUNE_LASER;
|
| 583 |
+
e.max_health = e.health;
|
| 584 |
+
const mv = d.moves[e.monsterinfo.currentmove];
|
| 585 |
+
e.frame = mv.first + (Q.rand(g) % (mv.last - mv.first + 1)); // monster_start picks a random first frame
|
| 586 |
+
if (opts.engage) e.engage = true;
|
| 587 |
+
return i;
|
| 588 |
+
};
|
| 589 |
+
function dropToFloor(g, i) { // M_droptofloor: lift one unit, trace 256 down, rest DIST_EPSILON above the floor
|
| 590 |
+
const e = g.ents[i];
|
| 591 |
+
e.origin[2] += 1;
|
| 592 |
+
const end = copy3(e.origin); end[2] -= 256;
|
| 593 |
+
const tr = Q.trace(g, e.origin, e.mins, e.maxs, end, i, Q.MASK_MONSTERSOLID);
|
| 594 |
+
if (tr.fraction === 1 || tr.allsolid) return;
|
| 595 |
+
e.origin = copy3(tr.endpos); link(g, i);
|
| 596 |
+
checkGround(g, i);
|
| 597 |
+
}
|
| 598 |
+
function startGo(g, i, fly) {
|
| 599 |
+
const e = g.ents[i];
|
| 600 |
+
if (!fly) { if (g.ms < 1000) dropToFloor(g, i); } else walkmove(g, i, 0, 0);
|
| 601 |
+
if (!e.yaw_speed) e.yaw_speed = fly ? 10 : 20;
|
| 602 |
+
e.viewheight = 25;
|
| 603 |
+
if (e.health <= 0) return; // monster_start_go: killed before it ever thought
|
| 604 |
+
e.monsterinfo.pausetime = 100000000000; call(g, i, 'stand');
|
| 605 |
+
e.think = 'monster_think'; e.nextthink = g.ms + Q.FRAMETIME_MS;
|
| 606 |
+
// monster_use by the arena trigger: an alerted boss hunts the player from the first frame.
|
| 607 |
+
if (e.engage && g.ents[1].health > 0) { e.enemy = 1; foundTarget(g, i); }
|
| 608 |
+
}
|
| 609 |
+
Q.THINK.walkmonster_start_go = (g, i) => startGo(g, i, false);
|
| 610 |
+
Q.THINK.flymonster_start_go = (g, i) => startGo(g, i, true);
|
| 611 |
+
// Muzzle helpers (G_ProjectSource with monster_flash_offset, monster yaw only).
|
| 612 |
+
const muzzle = (e, ofs) => { const av = Q.angleVectors(e.angles); return Q.projectSource(e.origin, ofs, av.forward, av.right); };
|
| 613 |
+
const aimAt = (g, start, target) => norm(sub(target, start));
|
| 614 |
+
const enemyEye = (g, e, lag) => { const en = g.ents[e.enemy], t = ma(en.origin, lag, en.velocity); t[2] += en.viewheight; return t; };
|
| 615 |
+
function flash(g, i, weapon, at, extra) { Q.fx(g, 'mflash', at, null, Object.assign({ weapon, owner: i }, extra || {})); }
|
| 616 |
+
Q.monsterFireBullet = (g, i, start, dir, damage, kick) => Q.fireBullet(g, i, start, dir, damage, kick, 300, 500, 'monster');
|
| 617 |
+
Q.monsterFireRocket = (g, i, start, dir, damage, speed) => Q.fireRocket(g, i, start, dir, damage, speed, damage + 20, damage);
|
| 618 |
+
// BossExplode: nine explosions a frame apart around the body, then the gibs (cosmetic; their RNG draws kept).
|
| 619 |
+
Q.THINK.BossExplode = (g, i) => {
|
| 620 |
+
const e = g.ents[i];
|
| 621 |
+
e.think = 'BossExplode';
|
| 622 |
+
const org = copy3(e.origin); org[2] += 24 + (Q.rand(g) & 15);
|
| 623 |
+
const OFS = [[-24, -24], [24, 24], [24, -24], [-24, 24], [-48, -48], [48, 48], [-48, 48], [48, -48]];
|
| 624 |
+
const n = e.count++;
|
| 625 |
+
if (n < 8) {
|
| 626 |
+
org[0] += OFS[n][0]; org[1] += OFS[n][1];
|
| 627 |
+
Q.fx(g, 'explosion', org, null, { big: true });
|
| 628 |
+
e.nextthink = g.ms + Q.FRAMETIME_MS;
|
| 629 |
+
return;
|
| 630 |
+
}
|
| 631 |
+
// case 8: four meat chunks, eight metal chunks, the chest, then the boss itself becomes the gear head.
|
| 632 |
+
for (let k = 0; k < 4; k++) Q.throwGib(g, i, 'meat', 500, true);
|
| 633 |
+
for (let k = 0; k < 8; k++) Q.throwGib(g, i, 'metal', 500, false);
|
| 634 |
+
Q.throwGib(g, i, 'chest', 500, true);
|
| 635 |
+
Q.throwHead(g, i, 'gear', 500, false);
|
| 636 |
+
g.ents[i].deadflag = Q.DEAD_DEAD; g.ents[i].gibbed = true;
|
| 637 |
+
Q.fx(g, 'gibs', Q.center(g.ents[i]), null, { size: 64 });
|
| 638 |
+
};
|
| 639 |
+
function bossDead(mins, maxs) {
|
| 640 |
+
return (g, i) => { const e = g.ents[i]; e.mins = mins; e.maxs = maxs; e.movetype = 'toss'; e.svflags |= Q.SVF_DEADMONSTER; e.nextthink = 0; };
|
| 641 |
+
}
|
| 642 |
+
const stand = (g, i) => setMove(g.ents[i], 'stand');
|
| 643 |
+
const runOrStand = (g, i) => setMove(g.ents[i], (g.ents[i].monsterinfo.aiflags & AI_STAND_GROUND) ? 'stand' : 'run');
|
| 644 |
+
const debounced = (g, e) => g.ms < e.pain_debounce_time;
|
| 645 |
+
const sound = () => {};
|
| 646 |
+
|
| 647 |
+
// ================= Super Tank (m_supertank.c) =================
|
| 648 |
+
DEFS.monster_supertank = {
|
| 649 |
+
name: 'Tracked Gun Carrier', health: 1500, gib_health: -500, mass: 800, mins: [-64, -64, 0], maxs: [64, 64, 112], gibs: 13,
|
| 650 |
+
moves: moves({
|
| 651 |
+
stand: [194, 253, 's0x60', null],
|
| 652 |
+
run: [128, 145, 'r12:TreadSound r12x17', null],
|
| 653 |
+
forward: [128, 145, 'w4:TreadSound w4x17', null],
|
| 654 |
+
pain3: [172, 175, 'm0x4', 'run'], pain2: [168, 171, 'm0x4', 'run'], pain1: [164, 167, 'm0x4', 'run'],
|
| 655 |
+
death: [98, 121, 'm0x23 m0:BossExplode', 'dead'],
|
| 656 |
+
attack2: [20, 46, 'c0x7 c0:supertankRocket m0x2 m0:supertankRocket m0x2 m0:supertankRocket m0x13', 'run'],
|
| 657 |
+
attack1: [0, 5, 'c0:supertankMachineGunx6', 'reattack1'],
|
| 658 |
+
end_attack1: [6, 19, 'm0x14', 'run'],
|
| 659 |
+
}),
|
| 660 |
+
stand, walk: (g, i) => setMove(g.ents[i], 'forward'), run: runOrStand, TreadSound: sound,
|
| 661 |
+
reattack1(g, i) {
|
| 662 |
+
const e = g.ents[i];
|
| 663 |
+
if (Q.visible(g, i, e.enemy)) setMove(e, Q.random(g) < 0.9 ? 'attack1' : 'end_attack1'); else setMove(e, 'end_attack1');
|
| 664 |
+
},
|
| 665 |
+
pain(g, i, other, kick, damage) {
|
| 666 |
+
const e = g.ents[i];
|
| 667 |
+
if (e.health < e.max_health / 2) e.skinnum = 1;
|
| 668 |
+
if (debounced(g, e)) return;
|
| 669 |
+
if (damage <= 25 && Q.random(g) < 0.2) return; // lessen the chance of pain frames
|
| 670 |
+
if (g.skill >= 2 && e.frame >= 20 && e.frame <= 33) return; // no pain while firing rockets
|
| 671 |
+
e.pain_debounce_time = g.ms + 3000;
|
| 672 |
+
if (g.skill === 3) return; // no pain anims in nightmare
|
| 673 |
+
setMove(e, damage <= 10 ? 'pain1' : damage <= 25 ? 'pain2' : 'pain3');
|
| 674 |
+
},
|
| 675 |
+
supertankRocket(g, i) {
|
| 676 |
+
const e = g.ents[i];
|
| 677 |
+
const ofs = e.frame === 27 ? [16.0, -22.5, 91.2] : e.frame === 30 ? [16.0, -33.4, 86.7] : [16.0, -42.8, 83.3];
|
| 678 |
+
const start = muzzle(e, ofs);
|
| 679 |
+
Q.monsterFireRocket(g, i, start, aimAt(g, start, enemyEye(g, e, 0)), 50, 500);
|
| 680 |
+
flash(g, i, 'rocket', start);
|
| 681 |
+
},
|
| 682 |
+
supertankMachineGun(g, i) {
|
| 683 |
+
const e = g.ents[i], av = Q.angleVectors([0, e.angles[1], 0]);
|
| 684 |
+
const start = Q.projectSource(e.origin, [30.0, 30.0, 88.5], av.forward, av.right);
|
| 685 |
+
let forward = av.forward;
|
| 686 |
+
if (e.enemy >= 0) forward = aimAt(g, start, enemyEye(g, e, 0));
|
| 687 |
+
Q.monsterFireBullet(g, i, start, forward, 6, 4);
|
| 688 |
+
flash(g, i, 'mg', start);
|
| 689 |
+
},
|
| 690 |
+
attack(g, i) {
|
| 691 |
+
const e = g.ents[i], range = len(sub(g.ents[e.enemy].origin, e.origin));
|
| 692 |
+
if (range <= 160) setMove(e, 'attack1');
|
| 693 |
+
else setMove(e, Q.random(g) < 0.3 ? 'attack1' : 'attack2'); // fire rockets more often at distance
|
| 694 |
+
},
|
| 695 |
+
die(g, i) { const e = g.ents[i]; e.deadflag = Q.DEAD_DEAD; e.takedamage = Q.DAMAGE_NO; e.count = 0; setMove(e, 'death'); },
|
| 696 |
+
dead: bossDead([-60, -60, 0], [60, 60, 72]),
|
| 697 |
+
BossExplode: (g, i) => Q.THINK.BossExplode(g, i),
|
| 698 |
+
};
|
| 699 |
+
|
| 700 |
+
// ================= Hornet (m_boss2.c) =================
|
| 701 |
+
DEFS.monster_boss2 = {
|
| 702 |
+
name: 'Flying Gunship', health: 2000, gib_health: -200, mass: 1000, mins: [-56, -56, 0], maxs: [56, 56, 80], fly: true, immuneLaser: true, gibs: 13,
|
| 703 |
+
moves: moves({
|
| 704 |
+
stand: [0, 20, 's0x21', null],
|
| 705 |
+
walk: [50, 69, 'w8x20', null],
|
| 706 |
+
run: [50, 69, 'r8x20', null],
|
| 707 |
+
attack_pre_mg: [70, 78, 'c1x8 c1:boss2_attack_mg', null],
|
| 708 |
+
attack_mg: [79, 84, 'c1:Boss2MachineGunx5 c1:boss2_reattack_mg', null],
|
| 709 |
+
attack_post_mg: [85, 88, 'c1x4', 'run'],
|
| 710 |
+
attack_rocket: [89, 109, 'c1x12 m-20:Boss2Rocket c1x8', 'run'],
|
| 711 |
+
pain_heavy: [110, 127, 'm0x18', 'run'],
|
| 712 |
+
pain_light: [128, 131, 'm0x4', 'run'],
|
| 713 |
+
death: [132, 180, 'm0x48 m0:BossExplode', 'dead'],
|
| 714 |
+
}),
|
| 715 |
+
stand, walk: (g, i) => setMove(g.ents[i], 'walk'), run: runOrStand,
|
| 716 |
+
checkattack: bossCheckAttack(0.8, 0.8),
|
| 717 |
+
attack(g, i) {
|
| 718 |
+
const e = g.ents[i], range = len(sub(g.ents[e.enemy].origin, e.origin));
|
| 719 |
+
if (range <= 125) setMove(e, 'attack_pre_mg'); else setMove(e, Q.random(g) <= 0.6 ? 'attack_pre_mg' : 'attack_rocket');
|
| 720 |
+
},
|
| 721 |
+
boss2_attack_mg: (g, i) => setMove(g.ents[i], 'attack_mg'),
|
| 722 |
+
boss2_reattack_mg(g, i) {
|
| 723 |
+
const e = g.ents[i];
|
| 724 |
+
if (Q.infront(g, i, e.enemy)) setMove(e, Q.random(g) <= 0.7 ? 'attack_mg' : 'attack_post_mg'); else setMove(e, 'attack_post_mg');
|
| 725 |
+
},
|
| 726 |
+
Boss2MachineGun(g, i) {
|
| 727 |
+
const e = g.ents[i];
|
| 728 |
+
for (const ofs of [[32, -40, 70], [32, 40, 70]]) { // boss2_firebullet_left, then _right
|
| 729 |
+
const start = muzzle(e, ofs);
|
| 730 |
+
Q.monsterFireBullet(g, i, start, aimAt(g, start, enemyEye(g, e, -0.2)), 6, 4);
|
| 731 |
+
flash(g, i, 'mg', start);
|
| 732 |
+
}
|
| 733 |
+
},
|
| 734 |
+
Boss2Rocket(g, i) {
|
| 735 |
+
const e = g.ents[i];
|
| 736 |
+
for (const ofs of [[22.0, 16.0, 10.0], [22.0, 8.0, 10.0], [22.0, -8.0, 10.0], [22.0, -16.0, 10.0]]) {
|
| 737 |
+
const start = muzzle(e, ofs);
|
| 738 |
+
Q.monsterFireRocket(g, i, start, aimAt(g, start, enemyEye(g, e, 0)), 50, 500);
|
| 739 |
+
flash(g, i, 'rocket', start);
|
| 740 |
+
}
|
| 741 |
+
},
|
| 742 |
+
pain(g, i, other, kick, damage) {
|
| 743 |
+
const e = g.ents[i];
|
| 744 |
+
if (e.health < e.max_health / 2) e.skinnum = 1;
|
| 745 |
+
if (debounced(g, e)) return;
|
| 746 |
+
e.pain_debounce_time = g.ms + 3000;
|
| 747 |
+
setMove(e, damage < 30 ? 'pain_light' : 'pain_heavy');
|
| 748 |
+
},
|
| 749 |
+
die(g, i) { const e = g.ents[i]; e.deadflag = Q.DEAD_DEAD; e.takedamage = Q.DAMAGE_NO; e.count = 0; setMove(e, 'death'); },
|
| 750 |
+
dead: bossDead([-56, -56, 0], [56, 56, 80]),
|
| 751 |
+
BossExplode: (g, i) => Q.THINK.BossExplode(g, i),
|
| 752 |
+
};
|
| 753 |
+
|
| 754 |
+
// ================= Jorg (m_boss31.c), first form of the final boss =================
|
| 755 |
+
DEFS.monster_jorg = {
|
| 756 |
+
name: 'Twin-Cannon Mech', health: 3000, gib_health: -2000, mass: 1000, mins: [-80, -80, 0], maxs: [80, 80, 140], gibs: 13,
|
| 757 |
+
moves: moves({
|
| 758 |
+
stand: [112, 162, 's0:jorg_idle s0x32 s19 s11:jorg_step_left s0x2 s6 s9:jorg_step_right s0x7 s-2 s-17:jorg_step_left s0 s-12 s-14:jorg_step_right', null],
|
| 759 |
+
run: [168, 181, 'r17:jorg_step_left r0x3 r12 r8 r10 r33:jorg_step_right r0x3 r9x3', null],
|
| 760 |
+
walk: [168, 181, 'w17 w0x3 w12 w8 w10 w33 w0x3 w9x3', null],
|
| 761 |
+
pain3: [87, 111, 'm-28 m-6 m-3:jorg_step_left m-9 m0:jorg_step_right m0x3 m-7 m1 m-11 m-4 m0x2 m10 m11 m0 m10 m3 m10 m7:jorg_step_left m17 m0x2 m0:jorg_step_right', 'run'],
|
| 762 |
+
pain2: [84, 86, 'm0x3', 'run'], pain1: [81, 83, 'm0x3', 'run'],
|
| 763 |
+
death: [31, 80, 'm0x48 m0:MakronToss m0:BossExplode', 'dead'],
|
| 764 |
+
attack2: [18, 30, 'c0x6 c0:jorgBFG m0x6', 'run'],
|
| 765 |
+
start_attack1: [0, 7, 'c0x8', 'attack1'],
|
| 766 |
+
attack1: [8, 13, 'c0:jorg_firebulletx6', 'reattack1'],
|
| 767 |
+
end_attack1: [14, 17, 'm0x4', 'run'],
|
| 768 |
+
}),
|
| 769 |
+
stand, walk: (g, i) => setMove(g.ents[i], 'walk'), run: runOrStand, jorg_idle: sound, jorg_step_left: sound, jorg_step_right: sound,
|
| 770 |
+
checkattack: bossCheckAttack(0.4, 0.2),
|
| 771 |
+
attack(g, i) { setMove(g.ents[i], Q.random(g) <= 0.75 ? 'start_attack1' : 'attack2'); },
|
| 772 |
+
attack1: (g, i) => setMove(g.ents[i], 'attack1'),
|
| 773 |
+
reattack1(g, i) {
|
| 774 |
+
const e = g.ents[i];
|
| 775 |
+
if (Q.visible(g, i, e.enemy)) setMove(e, Q.random(g) < 0.9 ? 'attack1' : 'end_attack1'); else setMove(e, 'end_attack1');
|
| 776 |
+
},
|
| 777 |
+
jorg_firebullet(g, i) {
|
| 778 |
+
const e = g.ents[i];
|
| 779 |
+
for (const ofs of [[78.5, -47.1, 96], [78.5, 46.7, 96]]) { // jorg_firebullet_left, then _right
|
| 780 |
+
const start = muzzle(e, ofs);
|
| 781 |
+
Q.monsterFireBullet(g, i, start, aimAt(g, start, enemyEye(g, e, -0.2)), 6, 4);
|
| 782 |
+
flash(g, i, 'mg', start);
|
| 783 |
+
}
|
| 784 |
+
},
|
| 785 |
+
jorgBFG(g, i) {
|
| 786 |
+
const e = g.ents[i], start = muzzle(e, [6.3, -9, 111.2]);
|
| 787 |
+
Q.fireBFG(g, i, start, aimAt(g, start, enemyEye(g, e, 0)), 50, 300, 200);
|
| 788 |
+
flash(g, i, 'bfg', start);
|
| 789 |
+
},
|
| 790 |
+
pain(g, i, other, kick, damage) {
|
| 791 |
+
const e = g.ents[i];
|
| 792 |
+
if (e.health < e.max_health / 2) e.skinnum = 1;
|
| 793 |
+
if (debounced(g, e)) return;
|
| 794 |
+
if (damage <= 40 && Q.random(g) <= 0.6) return;
|
| 795 |
+
if (e.frame >= 0 && e.frame <= 7 && Q.random(g) <= 0.005) return;
|
| 796 |
+
if (e.frame >= 8 && e.frame <= 13 && Q.random(g) <= 0.00005) return;
|
| 797 |
+
if (e.frame >= 18 && e.frame <= 25 && Q.random(g) <= 0.005) return;
|
| 798 |
+
e.pain_debounce_time = g.ms + 3000;
|
| 799 |
+
if (g.skill === 3) return;
|
| 800 |
+
if (damage <= 50) setMove(e, 'pain1'); else if (damage <= 100) setMove(e, 'pain2'); else if (Q.random(g) <= 0.3) setMove(e, 'pain3');
|
| 801 |
+
},
|
| 802 |
+
die(g, i) { const e = g.ents[i]; e.deadflag = Q.DEAD_DEAD; e.takedamage = Q.DAMAGE_NO; e.count = 0; setMove(e, 'death'); },
|
| 803 |
+
dead: bossDead([-60, -60, 0], [60, 60, 72]),
|
| 804 |
+
MakronToss(g, i) { // spawn Makron 0.8 s later at Jorg's origin
|
| 805 |
+
const k = Q.spawn(g), t = g.ents[k];
|
| 806 |
+
Object.assign(t, { classname: 'makron_spawner', origin: copy3(g.ents[i].origin), think: 'MakronSpawn', nextthink: g.ms + 800 });
|
| 807 |
+
},
|
| 808 |
+
BossExplode: (g, i) => Q.THINK.BossExplode(g, i),
|
| 809 |
+
};
|
| 810 |
+
// MakronSpawn: SP_monster_makron on the spawner edict, then jump at the player (400 forward, 200 up).
|
| 811 |
+
Q.THINK.MakronSpawn = (g, i) => {
|
| 812 |
+
const origin = copy3(g.ents[i].origin), d = DEFS.monster_makron, e = g.ents[i];
|
| 813 |
+
Object.assign(e, Q.blankEdict(), {
|
| 814 |
+
classname: 'monster_makron', origin, old_origin: copy3(origin), mins: copy3(d.mins), maxs: copy3(d.maxs), movetype: 'step', solid: Q.SOLID_BBOX,
|
| 815 |
+
health: g.makronHealth, gib_health: d.gib_health, mass: d.mass, svflags: Q.SVF_MONSTER, takedamage: Q.DAMAGE_AIM, clipmask: Q.MASK_MONSTERSOLID,
|
| 816 |
+
final: true, goalentity: -1, oldenemy: -1, movetarget: -1, show_hostile: 0, pain_debounce_time: 0, skinnum: 0, pos1: [0, 0, 0], count: 0,
|
| 817 |
+
yaw_speed: 0, viewheight: 0, think: 'walkmonster_start_go', nextthink: g.ms + Q.FRAMETIME_MS, angles: [0, 0, 0], ideal_yaw: 0,
|
| 818 |
+
monsterinfo: { currentmove: 'sight', nextframe: 0, aiflags: 0, scale: 1, pausetime: 0, attack_finished: 0, attack_state: 0, lefty: 0,
|
| 819 |
+
search_time: 0, trail_time: 0, last_sighting: [0, 0, 0], saved_goal: [0, 0, 0], linkcount: 0, idle_time: 0,
|
| 820 |
+
stall_pos: null, stall_t: 0, chase_until: 0 },
|
| 821 |
+
});
|
| 822 |
+
e.max_health = e.health;
|
| 823 |
+
const mv = d.moves.sight; e.frame = mv.first + (Q.rand(g) % (mv.last - mv.first + 1));
|
| 824 |
+
const p = g.ents[1];
|
| 825 |
+
if (p.health <= 0) return;
|
| 826 |
+
let vec = sub(p.origin, e.origin);
|
| 827 |
+
e.angles[1] = Q.vectoyaw(vec); // ideal_yaw stays 0 until HuntTarget
|
| 828 |
+
vec = norm(vec);
|
| 829 |
+
e.velocity = scale(vec, 400); e.velocity[2] = 200; e.groundentity = -1;
|
| 830 |
+
Q.event(g, 'makron_spawn');
|
| 831 |
+
};
|
| 832 |
+
|
| 833 |
+
// ================= Makron (m_boss32.c), second form =================
|
| 834 |
+
const MAKRON_BLASTER = [[-3.6, -24.1, 59.5], [-1.6, -19.3, 59.5], [-0.1, -14.4, 59.5], [2.0, -7.6, 59.5], [3.4, 1.3, 59.5], [3.7, 11.1, 59.5],
|
| 835 |
+
[-0.3, 22.3, 59.5], [-6, 33, 59.5], [-9.3, 36.4, 59.5], [-7, 35, 59.5], [-2.1, 29, 59.5], [3.9, 17.3, 59.5], [6.1, 5.8, 59.5], [5.9, -4.4, 59.5],
|
| 836 |
+
[4.2, -14.1, 59.5], [2.4, -18.8, 59.5], [-1.8, -25.5, 59.5]];
|
| 837 |
+
DEFS.monster_makron = {
|
| 838 |
+
name: 'Armored Pilot', health: 3000, gib_health: -2000, mass: 500, mins: [-30, -30, 0], maxs: [30, 30, 90], gibs: 5, startMove: 'sight',
|
| 839 |
+
moves: moves({
|
| 840 |
+
stand: [414, 473, 's0x60', null],
|
| 841 |
+
run: [477, 486, 'r3:makron_step_left r12 r8x2 r8:makron_step_right r6 r12 r9 r6 r12', null],
|
| 842 |
+
walk: [477, 486, 'r3:makron_step_left r12 r8x2 r8:makron_step_right r6 r12 r9 r6 r12', null],
|
| 843 |
+
pain6: [387, 413, 'm0x15 m0:makron_popup m0x7 m0:makron_taunt m0x3', 'run'],
|
| 844 |
+
pain5: [383, 386, 'm0x4', 'run'], pain4: [379, 382, 'm0x4', 'run'],
|
| 845 |
+
death2: [251, 345, 'm-15 m3 m-12 m0:makron_step_left m0x11 m11 m12 m11:makron_step_right m0x15 m5 m7 m6:makron_step_left m0x2 m-1 m2 m0x13 m-6 m-4 m-6:makron_step_right m-4 m-4:makron_step_left m0x4 m-2 m-5 m-3:makron_step_right m-8 m-3:makron_step_left m-7 m-4 m-4:makron_step_right m-6 m-7 m0:makron_step_left m0x12 m-2 m0x2 m2 m0 m27:makron_hit m26 m0:makron_brainsplorch m0x2', 'dead'],
|
| 846 |
+
sight: [188, 200, 'm0x13', 'run'],
|
| 847 |
+
attack3: [201, 208, 'c0x3 c0:makronBFG m0x4', 'run'],
|
| 848 |
+
attack4: [209, 234, 'c0x4 m0:MakronHyperblasterx17 m0x5', 'run'],
|
| 849 |
+
attack5: [235, 250, 'c0:makron_prerailgun c0x6 c0:MakronSaveloc m0:MakronRailgun m0x7', 'run'],
|
| 850 |
+
}),
|
| 851 |
+
stand, walk: (g, i) => setMove(g.ents[i], 'walk'), run: runOrStand, sight: (g, i) => setMove(g.ents[i], 'sight'),
|
| 852 |
+
makron_step_left: sound, makron_step_right: sound, makron_popup: sound, makron_hit: sound, makron_brainsplorch: sound,
|
| 853 |
+
makron_taunt: (g) => { Q.random(g); }, makron_prerailgun: (g, i) => Q.fx(g, 'railcharge', g.ents[i].origin, null, { owner: i }),
|
| 854 |
+
checkattack: bossCheckAttack(0.4, 0.2),
|
| 855 |
+
attack(g, i) {
|
| 856 |
+
const r = Q.random(g), e = g.ents[i];
|
| 857 |
+
setMove(e, r <= 0.3 ? 'attack3' : r <= 0.6 ? 'attack4' : 'attack5');
|
| 858 |
+
},
|
| 859 |
+
makronBFG(g, i) {
|
| 860 |
+
const e = g.ents[i], start = muzzle(e, [17, -19.5, 62.9]);
|
| 861 |
+
Q.fireBFG(g, i, start, aimAt(g, start, enemyEye(g, e, 0)), 50, 300, 300);
|
| 862 |
+
flash(g, i, 'bfg', start);
|
| 863 |
+
},
|
| 864 |
+
MakronSaveloc(g, i) { const e = g.ents[i], en = g.ents[e.enemy]; e.pos1 = copy3(en.origin); e.pos1[2] += en.viewheight; },
|
| 865 |
+
MakronRailgun(g, i) {
|
| 866 |
+
const e = g.ents[i], start = muzzle(e, [-17.3, 7.8, 72.4]);
|
| 867 |
+
Q.fireRail(g, i, start, norm(sub(e.pos1, start)), 50, 100);
|
| 868 |
+
flash(g, i, 'rail', start);
|
| 869 |
+
},
|
| 870 |
+
MakronHyperblaster(g, i) {
|
| 871 |
+
const e = g.ents[i], start = muzzle(e, MAKRON_BLASTER[e.frame - 213]);
|
| 872 |
+
const dir = [0, 0, 0];
|
| 873 |
+
if (e.enemy >= 0) { const v = enemyEye(g, e, 0); dir[0] = Q.vectoangles(sub(v, start))[0]; }
|
| 874 |
+
dir[1] = e.frame <= 221 ? e.angles[1] - 10 * (e.frame - 221) : e.angles[1] + 10 * (e.frame - 229);
|
| 875 |
+
Q.fireBlaster(g, i, start, Q.angleVectors(dir).forward, 15, 1000, 'blaster', false);
|
| 876 |
+
flash(g, i, 'blaster', start);
|
| 877 |
+
},
|
| 878 |
+
pain(g, i, other, kick, damage) {
|
| 879 |
+
const e = g.ents[i];
|
| 880 |
+
if (e.health < e.max_health / 2) e.skinnum = 1;
|
| 881 |
+
if (debounced(g, e)) return;
|
| 882 |
+
if (damage <= 25 && Q.random(g) < 0.2) return;
|
| 883 |
+
e.pain_debounce_time = g.ms + 3000;
|
| 884 |
+
if (g.skill === 3) return;
|
| 885 |
+
if (damage <= 40) setMove(e, 'pain4');
|
| 886 |
+
else if (damage <= 110) setMove(e, 'pain5');
|
| 887 |
+
else if (damage <= 150) { // C's dangling else: the 0.35 retry belongs to this branch, >150 gives no pain
|
| 888 |
+
if (Q.random(g) <= 0.45) setMove(e, 'pain6'); else if (Q.random(g) <= 0.35) setMove(e, 'pain6');
|
| 889 |
+
}
|
| 890 |
+
},
|
| 891 |
+
die(g, i) {
|
| 892 |
+
const e = g.ents[i];
|
| 893 |
+
if (e.deadflag === Q.DEAD_DEAD) return;
|
| 894 |
+
e.deadflag = Q.DEAD_DEAD; e.takedamage = Q.DAMAGE_YES; setMove(e, 'death2');
|
| 895 |
+
},
|
| 896 |
+
dead: bossDead([-60, -60, 0], [60, 60, 72]),
|
| 897 |
+
};
|
| 898 |
+
|
| 899 |
+
// ---------------- shared helpers of the three unit monsters ----------------
|
| 900 |
+
// fire_hit (g_weapon.c), the melee hit of the Gladiator and the Mutant. Kept as in the source: `dir` is not
|
| 901 |
+
// normalized before VectorMA, so the trace runs from the attacker's origin far past the enemy along that line.
|
| 902 |
+
Q.fireHit = (g, i, aim, damage, kick) => {
|
| 903 |
+
const self = g.ents[i], en = g.ents[self.enemy];
|
| 904 |
+
let dir = sub(en.origin, self.origin);
|
| 905 |
+
let range = len(dir);
|
| 906 |
+
if (range > aim[0]) return false;
|
| 907 |
+
aim = copy3(aim);
|
| 908 |
+
if (aim[1] > self.mins[0] && aim[1] < self.maxs[0]) range -= en.maxs[0]; // straight on: back up to the box edge
|
| 909 |
+
else aim[1] = aim[1] < 0 ? en.mins[0] : en.maxs[0]; // side hit: out to the box edge
|
| 910 |
+
let point = ma(self.origin, range, dir);
|
| 911 |
+
const tr = Q.trace(g, self.origin, null, null, point, i, Q.MASK_SHOT);
|
| 912 |
+
let target = tr.ent;
|
| 913 |
+
if (tr.fraction < 1) {
|
| 914 |
+
const h = g.ents[tr.ent];
|
| 915 |
+
if (!h.takedamage) return false;
|
| 916 |
+
if ((h.svflags & Q.SVF_MONSTER) || h.client) target = self.enemy; // whatever it hits, it hits the enemy
|
| 917 |
+
}
|
| 918 |
+
const av = Q.angleVectors(self.angles);
|
| 919 |
+
point = ma(ma(ma(self.origin, range, av.forward), aim[1], av.right), aim[2], av.up);
|
| 920 |
+
dir = sub(point, en.origin);
|
| 921 |
+
Q.damage(g, target, i, i, dir, point, [0, 0, 0], damage, Math.trunc(kick / 2), Q.DAMAGE_NO_KNOCKBACK, 'hit');
|
| 922 |
+
const t = g.ents[target];
|
| 923 |
+
if (!(t.svflags & Q.SVF_MONSTER) && !t.client) return false;
|
| 924 |
+
// the special knockback: from the hit point towards the middle of the enemy's absolute box
|
| 925 |
+
const mid = [Q.absmin(en)[0] + 0.5 * (en.maxs[0] - en.mins[0]), Q.absmin(en)[1] + 0.5 * (en.maxs[1] - en.mins[1]), Q.absmin(en)[2] + 0.5 * (en.maxs[2] - en.mins[2])];
|
| 926 |
+
en.velocity = ma(en.velocity, kick, norm(sub(mid, point)));
|
| 927 |
+
if (en.velocity[2] > 0) en.groundentity = -1;
|
| 928 |
+
Q.fx(g, 'slash', point, null, { owner: i });
|
| 929 |
+
return true;
|
| 930 |
+
};
|
| 931 |
+
// Regular (non-boss) death: gib below gib_health, else the death move; the corpse can still take damage.
|
| 932 |
+
function unitDie(gibs, deathMove) {
|
| 933 |
+
return (g, i, inflictor, attacker, damage) => {
|
| 934 |
+
const e = g.ents[i];
|
| 935 |
+
if (e.health <= e.gib_health) {
|
| 936 |
+
for (const [kind, n, organic] of gibs.body) for (let k = 0; k < n; k++) Q.throwGib(g, i, kind, damage, organic);
|
| 937 |
+
Q.throwHead(g, i, gibs.head[0], damage, gibs.head[1]);
|
| 938 |
+
e.deadflag = Q.DEAD_DEAD; e.gibbed = true;
|
| 939 |
+
Q.fx(g, 'gibs', Q.center(e), null, { size: 32 });
|
| 940 |
+
return;
|
| 941 |
+
}
|
| 942 |
+
if (e.deadflag === Q.DEAD_DEAD) return;
|
| 943 |
+
e.deadflag = Q.DEAD_DEAD; e.takedamage = Q.DAMAGE_YES;
|
| 944 |
+
setMove(e, typeof deathMove === 'function' ? deathMove(g, e) : deathMove);
|
| 945 |
+
};
|
| 946 |
+
}
|
| 947 |
+
// M_FlyCheck / M_FliesOn / M_FliesOff: flies around a corpse (an effect, with its own random draws).
|
| 948 |
+
function flyCheck(g, i) {
|
| 949 |
+
const e = g.ents[i];
|
| 950 |
+
if (Q.random(g) > 0.5) return;
|
| 951 |
+
e.think = 'M_FliesOn'; e.nextthink = g.ms + 5000 + 10000 * Q.random(g);
|
| 952 |
+
}
|
| 953 |
+
Q.THINK.M_FliesOn = (g, i) => { const e = g.ents[i]; e.flies = true; e.think = 'M_FliesOff'; e.nextthink = g.ms + 60000; };
|
| 954 |
+
Q.THINK.M_FliesOff = (g, i) => { g.ents[i].flies = false; };
|
| 955 |
+
|
| 956 |
+
// ================= Tank Commander (m_tank.c, monster_tank_commander: the Tank with 1000 health, skin 2) =================
|
| 957 |
+
const TANK_MG = [[22.9, -0.7, 25.3], [22.2, 6.2, 22.3], [19.4, 13.1, 18.6], [19.4, 18.8, 18.6], [17.9, 25.0, 18.6], [14.1, 30.5, 20.6],
|
| 958 |
+
[9.3, 35.3, 22.1], [4.7, 38.4, 22.1], [-1.1, 40.4, 24.1], [-6.5, 41.2, 24.1], [3.2, 40.1, 24.7], [11.7, 36.7, 26.0], [18.9, 31.3, 26.0],
|
| 959 |
+
[24.4, 24.4, 26.4], [27.1, 17.1, 27.2], [28.5, 9.1, 28.0], [27.1, 2.2, 28.0], [24.9, -2.8, 28.0], [21.6, -7.0, 26.4]];
|
| 960 |
+
DEFS.monster_tank_commander = {
|
| 961 |
+
name: 'Chain-Gun Heavy Trooper', health: 1000, gib_health: -225, mass: 500, mins: [-32, -32, -16], maxs: [32, 32, 72], skin: 2,
|
| 962 |
+
moves: moves({
|
| 963 |
+
stand: [0, 29, 's0x30', null],
|
| 964 |
+
start_walk: [30, 33, 'w0 w6x2 w11:tank_footstep', 'walk'],
|
| 965 |
+
walk: [34, 49, 'w4 w5 w3 w2 w5x2 w4 w4:tank_footstep w3 w5 w4 w5 w7x2 w6 w6:tank_footstep', null],
|
| 966 |
+
start_run: [30, 33, 'r0 r6x2 r11:tank_footstep', 'run'],
|
| 967 |
+
run: [34, 49, 'r4 r5 r3 r2 r5x2 r4 r4:tank_footstep r3 r5 r4 r5 r7x2 r6 r6:tank_footstep', null],
|
| 968 |
+
pain1: [197, 200, 'm0x4', 'run'], pain2: [201, 205, 'm0x5', 'run'],
|
| 969 |
+
pain3: [206, 221, 'm-7 m0x3 m2 m0x2 m3 m0 m2 m0x5 m0:tank_footstep', 'run'],
|
| 970 |
+
attack_blast: [55, 70, 'c0x4 c-1 c-2 c-1x2 c0 c0:TankBlaster c0x2 c0:TankBlaster c0x2 c0:TankBlaster', 'reattack_blaster'],
|
| 971 |
+
reattack_blast: [65, 70, 'c0x2 c0:TankBlaster c0x2 c0:TankBlaster', 'reattack_blaster'],
|
| 972 |
+
attack_post_blast: [71, 76, 'm0x2 m2 m3 m2 m-2:tank_footstep', 'run'],
|
| 973 |
+
attack_strike: [77, 114, 'm3 m2x2 m1 m6 m7 m9:tank_footstep m2 m1 m2 m2:tank_footstep m2 m0x4 m-2x2 m0:tank_windup m0x6 m0:TankStrike m0 m-1x5 m-3 m-10x2 m-2 m-3 m-2:tank_footstep', 'poststrike'],
|
| 974 |
+
attack_pre_rocket: [115, 135, 'c0x11 c1 c2 c7x2 c7:tank_footstep c0x4 c-3', 'doattack_rocket'],
|
| 975 |
+
attack_fire_rocket: [136, 144, 'c-3 c0 c0:TankRocket c0x2 c0:TankRocket c0x2 c-1:TankRocket', 'refire_rocket'],
|
| 976 |
+
attack_post_rocket: [145, 167, 'c0 c-1x2 c0 c2 c3 c4 c2 c0x3 c-9 c-8 c-7 c-1 c-1:tank_footstep c0x7', 'run'],
|
| 977 |
+
attack_chain: [168, 196, 'c0x5 n0:TankMachineGunx19 c0x5', 'run'],
|
| 978 |
+
death: [222, 253, 'm-7 m-2x2 m1 m3 m6 m1x2 m2 m0x3 m-2 m0x2 m-3 m0x6 m-4 m-6 m-4 m-5 m-7 m-15:tank_thud m-5 m0x3', 'dead'],
|
| 979 |
+
}),
|
| 980 |
+
stand, walk: (g, i) => setMove(g.ents[i], 'walk'), sight: sound,
|
| 981 |
+
tank_footstep: sound, tank_thud: sound, tank_windup: sound, TankStrike: sound,
|
| 982 |
+
// tank_run: AI_BRUTAL against a client; from walk / start_run straight into run, otherwise via start_run.
|
| 983 |
+
run(g, i) {
|
| 984 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 985 |
+
if (e.enemy >= 0 && g.ents[e.enemy].client) mi.aiflags |= AI_BRUTAL; else mi.aiflags &= ~AI_BRUTAL;
|
| 986 |
+
if (mi.aiflags & AI_STAND_GROUND) { setMove(e, 'stand'); return; }
|
| 987 |
+
setMove(e, mi.currentmove === 'walk' || mi.currentmove === 'start_run' ? 'run' : 'start_run');
|
| 988 |
+
},
|
| 989 |
+
pain(g, i, other, kick, damage) {
|
| 990 |
+
const e = g.ents[i];
|
| 991 |
+
if (e.health < e.max_health / 2) e.skinnum |= 1;
|
| 992 |
+
if (damage <= 10) return;
|
| 993 |
+
if (debounced(g, e)) return;
|
| 994 |
+
if (damage <= 30 && Q.random(g) > 0.2) return;
|
| 995 |
+
if (g.skill >= 2 && ((e.frame >= 115 && e.frame <= 144) || (e.frame >= 55 && e.frame <= 70))) return; // not while attacking
|
| 996 |
+
e.pain_debounce_time = g.ms + 3000;
|
| 997 |
+
if (g.skill === 3) return;
|
| 998 |
+
setMove(e, damage <= 30 ? 'pain1' : damage <= 60 ? 'pain2' : 'pain3');
|
| 999 |
+
},
|
| 1000 |
+
TankBlaster(g, i) {
|
| 1001 |
+
const e = g.ents[i], ofs = e.frame === 64 ? [20.7, -18.5, 28.7] : e.frame === 67 ? [16.6, -21.5, 30.1] : [11.8, -23.9, 32.1];
|
| 1002 |
+
const start = muzzle(e, ofs);
|
| 1003 |
+
Q.fireBlaster(g, i, start, sub(enemyEye(g, e, 0), start), 30, 800, 'blaster', false);
|
| 1004 |
+
flash(g, i, 'blaster', start);
|
| 1005 |
+
},
|
| 1006 |
+
TankRocket(g, i) {
|
| 1007 |
+
const e = g.ents[i], ofs = e.frame === 138 ? [6.2, 29.1, 49.1] : e.frame === 141 ? [6.9, 23.8, 49.1] : [8.3, 17.8, 49.5];
|
| 1008 |
+
const start = muzzle(e, ofs);
|
| 1009 |
+
Q.monsterFireRocket(g, i, start, aimAt(g, start, enemyEye(g, e, 0)), 50, 550);
|
| 1010 |
+
flash(g, i, 'rocket', start);
|
| 1011 |
+
},
|
| 1012 |
+
// The chaingun sweep: pitch at the enemy's eye, yaw by frame from +40 to -32 and back to +40 degrees off the facing
|
| 1013 |
+
// it had when the burst started (the 19 firing frames have no AI function, so the Tank does not turn meanwhile).
|
| 1014 |
+
TankMachineGun(g, i) {
|
| 1015 |
+
const e = g.ents[i], start = muzzle(e, TANK_MG[e.frame - 173]), dir = [0, 0, 0];
|
| 1016 |
+
if (e.enemy >= 0) dir[0] = Q.vectoangles(sub(enemyEye(g, e, 0), start))[0];
|
| 1017 |
+
dir[1] = e.frame <= 182 ? e.angles[1] - 8 * (e.frame - 178) : e.angles[1] + 8 * (e.frame - 186);
|
| 1018 |
+
Q.monsterFireBullet(g, i, start, Q.angleVectors(dir).forward, 20, 4);
|
| 1019 |
+
flash(g, i, 'mg', start);
|
| 1020 |
+
},
|
| 1021 |
+
reattack_blaster(g, i) { // skill >= 2 only: 60 % another two bolts while the enemy is visible and alive
|
| 1022 |
+
const e = g.ents[i];
|
| 1023 |
+
if (g.skill >= 2 && Q.visible(g, i, e.enemy) && g.ents[e.enemy].health > 0 && Q.random(g) <= 0.6) { setMove(e, 'reattack_blast'); return; }
|
| 1024 |
+
setMove(e, 'attack_post_blast');
|
| 1025 |
+
},
|
| 1026 |
+
doattack_rocket: (g, i) => setMove(g.ents[i], 'attack_fire_rocket'),
|
| 1027 |
+
refire_rocket(g, i) { // skill >= 2 only: 40 % another volley
|
| 1028 |
+
const e = g.ents[i];
|
| 1029 |
+
if (g.skill >= 2 && g.ents[e.enemy].health > 0 && Q.visible(g, i, e.enemy) && Q.random(g) <= 0.4) { setMove(e, 'attack_fire_rocket'); return; }
|
| 1030 |
+
setMove(e, 'attack_post_rocket');
|
| 1031 |
+
},
|
| 1032 |
+
poststrike(g, i) { g.ents[i].enemy = -1; DEFS.monster_tank_commander.run(g, i); },
|
| 1033 |
+
attack(g, i) {
|
| 1034 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 1035 |
+
if (g.ents[e.enemy].health < 0) { setMove(e, 'attack_strike'); mi.aiflags &= ~AI_BRUTAL; return; }
|
| 1036 |
+
const range = len(sub(g.ents[e.enemy].origin, e.origin)), r = Q.random(g);
|
| 1037 |
+
if (range <= 125) setMove(e, r < 0.4 ? 'attack_chain' : 'attack_blast');
|
| 1038 |
+
else if (range <= 250) setMove(e, r < 0.5 ? 'attack_chain' : 'attack_blast');
|
| 1039 |
+
else if (r < 0.33) setMove(e, 'attack_chain');
|
| 1040 |
+
else if (r < 0.66) { setMove(e, 'attack_pre_rocket'); e.pain_debounce_time = g.ms + 5000; } // no pain for a while
|
| 1041 |
+
else setMove(e, 'attack_blast');
|
| 1042 |
+
},
|
| 1043 |
+
die: unitDie({ body: [['meat', 1, true], ['metal', 4, false], ['chest', 1, true]], head: ['gear', false] }, 'death'),
|
| 1044 |
+
dead: bossDead([-16, -16, -16], [16, 16, 0]),
|
| 1045 |
+
};
|
| 1046 |
+
|
| 1047 |
+
// ================= Gladiator (m_gladiator.c) =================
|
| 1048 |
+
DEFS.monster_gladiator = {
|
| 1049 |
+
name: 'Blade-Arm Gunner', health: 400, gib_health: -175, mass: 400, mins: [-32, -32, -24], maxs: [32, 32, 64],
|
| 1050 |
+
moves: moves({
|
| 1051 |
+
stand: [0, 6, 's0x7', null],
|
| 1052 |
+
walk: [7, 22, 'w15 w7 w6 w5 w2 w0 w2 w8 w12 w8 w5x2 w2x2 w1 w8', null],
|
| 1053 |
+
run: [23, 28, 'r23 r14x2 r21 r12 r13', null],
|
| 1054 |
+
attack_melee: [29, 45, 'c0x4 c0:gladiator_cleaver_swing c0 c0:GaldiatorMelee c0x3 c0:gladiator_cleaver_swing c0x2 c0:GaldiatorMelee c0x3', 'run'],
|
| 1055 |
+
attack_gun: [46, 54, 'c0x3 c0:GladiatorGun c0x5', 'run'],
|
| 1056 |
+
pain: [55, 60, 'm0x6', 'run'],
|
| 1057 |
+
pain_air: [83, 89, 'm0x7', 'run'],
|
| 1058 |
+
death: [61, 82, 'm0x22', 'dead'],
|
| 1059 |
+
}),
|
| 1060 |
+
stand, walk: (g, i) => setMove(g.ents[i], 'walk'), run: runOrStand, sight: sound, gladiator_cleaver_swing: sound,
|
| 1061 |
+
melee: (g, i) => setMove(g.ents[i], 'attack_melee'),
|
| 1062 |
+
GaldiatorMelee(g, i) { Q.fireHit(g, i, [Q.MELEE_DISTANCE, g.ents[i].mins[0], -4], 20 + (Q.rand(g) % 5), 300); },
|
| 1063 |
+
// gladiator_attack: nothing inside MELEE_DISTANCE + 32 (a small safe zone); otherwise the eye position is saved
|
| 1064 |
+
// NOW and the railgun fires along it on the fourth frame of attack_gun (0.4 s later).
|
| 1065 |
+
attack(g, i) {
|
| 1066 |
+
const e = g.ents[i], en = g.ents[e.enemy];
|
| 1067 |
+
if (len(sub(e.origin, en.origin)) <= Q.MELEE_DISTANCE + 32) return;
|
| 1068 |
+
e.pos1 = copy3(en.origin); e.pos1[2] += en.viewheight;
|
| 1069 |
+
setMove(e, 'attack_gun');
|
| 1070 |
+
},
|
| 1071 |
+
GladiatorGun(g, i) {
|
| 1072 |
+
const e = g.ents[i], start = muzzle(e, [30.0, 18.0, 28.0]);
|
| 1073 |
+
Q.fireRail(g, i, start, norm(sub(e.pos1, start)), 50, 100);
|
| 1074 |
+
flash(g, i, 'rail', start);
|
| 1075 |
+
},
|
| 1076 |
+
pain(g, i, other, kick, damage) {
|
| 1077 |
+
const e = g.ents[i];
|
| 1078 |
+
if (e.health < e.max_health / 2) e.skinnum = 1;
|
| 1079 |
+
if (debounced(g, e)) {
|
| 1080 |
+
if (e.velocity[2] > 100 && e.monsterinfo.currentmove === 'pain') setMove(e, 'pain_air');
|
| 1081 |
+
return;
|
| 1082 |
+
}
|
| 1083 |
+
e.pain_debounce_time = g.ms + 3000;
|
| 1084 |
+
Q.random(g); // which pain sound
|
| 1085 |
+
if (g.skill === 3) return;
|
| 1086 |
+
setMove(e, e.velocity[2] > 100 ? 'pain_air' : 'pain');
|
| 1087 |
+
},
|
| 1088 |
+
die: unitDie({ body: [['bone', 2, true], ['meat', 4, true]], head: ['head', true] }, 'death'),
|
| 1089 |
+
dead: bossDead([-16, -16, -24], [16, 16, -8]),
|
| 1090 |
+
};
|
| 1091 |
+
|
| 1092 |
+
// ================= Mutant (m_mutant.c) =================
|
| 1093 |
+
function mutantCheckJump(g, i) {
|
| 1094 |
+
const e = g.ents[i], en = g.ents[e.enemy], esize = en.maxs[2] - en.mins[2], emin = Q.absmin(en)[2];
|
| 1095 |
+
if (Q.absmin(e)[2] > emin + 0.75 * esize) return false;
|
| 1096 |
+
if (Q.absmax(e)[2] < emin + 0.25 * esize) return false;
|
| 1097 |
+
const d = Math.sqrt((e.origin[0] - en.origin[0]) ** 2 + (e.origin[1] - en.origin[1]) ** 2);
|
| 1098 |
+
if (d < 100) return false;
|
| 1099 |
+
if (d > 100 && Q.random(g) < 0.9) return false;
|
| 1100 |
+
return true;
|
| 1101 |
+
}
|
| 1102 |
+
DEFS.monster_mutant = {
|
| 1103 |
+
name: 'Clawed Pouncer', health: 300, gib_health: -120, mass: 300, mins: [-32, -32, -24], maxs: [32, 32, 48],
|
| 1104 |
+
moves: moves({
|
| 1105 |
+
stand: [62, 112, 's0x51', null],
|
| 1106 |
+
start_walk: [126, 129, 'w5x2 w-2 w1', 'mutant_walk_loop'],
|
| 1107 |
+
walk: [130, 141, 'w3 w1 w5 w10 w13 w10 w0 w5 w6 w16 w15 w6', null],
|
| 1108 |
+
run: [56, 61, 'r40 r40:mutant_step r24 r5:mutant_step r17 r10', null],
|
| 1109 |
+
attack: [8, 14, 'c0x2 c0:mutant_hit_left c0x2 c0:mutant_hit_right c0:mutant_check_refire', 'run'],
|
| 1110 |
+
jump: [0, 7, 'c0 c17 c15:mutant_jump_takeoff c15 c15:mutant_check_landing c0 c3 c0', 'run'],
|
| 1111 |
+
pain1: [34, 38, 'm4 m-3 m-8 m2 m5', 'run'], pain2: [39, 44, 'm-24 m11 m5 m-2 m6 m4', 'run'],
|
| 1112 |
+
pain3: [45, 55, 'm-22 m3x2 m2 m1x2 m6 m3 m2 m0 m1', 'run'],
|
| 1113 |
+
death1: [15, 23, 'm0x9', 'dead'], death2: [24, 33, 'm0x10', 'dead'],
|
| 1114 |
+
}),
|
| 1115 |
+
stand, walk: (g, i) => setMove(g.ents[i], 'start_walk'), mutant_walk_loop: (g, i) => setMove(g.ents[i], 'walk'), run: runOrStand,
|
| 1116 |
+
sight: sound,
|
| 1117 |
+
mutant_step: g => { Q.rand(g); }, // (rand() + 1) % 3 picks a footstep sound
|
| 1118 |
+
melee: (g, i) => setMove(g.ents[i], 'attack'),
|
| 1119 |
+
mutant_hit_left(g, i) { Q.fireHit(g, i, [Q.MELEE_DISTANCE, g.ents[i].mins[0], 8], 10 + (Q.rand(g) % 5), 100); },
|
| 1120 |
+
mutant_hit_right(g, i) { Q.fireHit(g, i, [Q.MELEE_DISTANCE, g.ents[i].maxs[0], 8], 10 + (Q.rand(g) % 5), 100); },
|
| 1121 |
+
mutant_check_refire(g, i) { // claw again while in melee range (and half the time anyway on skill 3)
|
| 1122 |
+
const e = g.ents[i], en = e.enemy >= 0 ? g.ents[e.enemy] : null;
|
| 1123 |
+
if (!en || !en.inuse || en.health <= 0) return;
|
| 1124 |
+
if ((g.skill === 3 && Q.random(g) < 0.5) || Q.range(g, i, e.enemy) === Q.RANGE_MELEE) e.monsterinfo.nextframe = 8;
|
| 1125 |
+
},
|
| 1126 |
+
attack: (g, i) => setMove(g.ents[i], 'jump'),
|
| 1127 |
+
// The leap: 600 forward and 250 up from the facing at takeoff; AI_DUCKED suppresses pain until it lands.
|
| 1128 |
+
mutant_jump_takeoff(g, i) {
|
| 1129 |
+
const e = g.ents[i], forward = Q.angleVectors(e.angles).forward;
|
| 1130 |
+
e.origin[2] += 1;
|
| 1131 |
+
e.velocity = scale(forward, 600); e.velocity[2] = 250;
|
| 1132 |
+
e.groundentity = -1;
|
| 1133 |
+
e.monsterinfo.aiflags |= AI_DUCKED;
|
| 1134 |
+
e.monsterinfo.attack_finished = g.ms + 3000;
|
| 1135 |
+
e.touch = 'mutant_jump_touch';
|
| 1136 |
+
Q.event(g, 'mutant_leap');
|
| 1137 |
+
},
|
| 1138 |
+
mutant_check_landing(g, i) { // hold this frame until landing; after 3 s in the air jump again
|
| 1139 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 1140 |
+
if (e.groundentity >= 0) { mi.attack_finished = 0; mi.aiflags &= ~AI_DUCKED; return; }
|
| 1141 |
+
mi.nextframe = g.ms > mi.attack_finished ? 1 : 4;
|
| 1142 |
+
},
|
| 1143 |
+
checkattack(g, i) { // mutant_checkattack: melee range first, then the 10 % leap check
|
| 1144 |
+
const e = g.ents[i], mi = e.monsterinfo;
|
| 1145 |
+
if (e.enemy < 0 || g.ents[e.enemy].health <= 0) return false;
|
| 1146 |
+
if (Q.range(g, i, e.enemy) === Q.RANGE_MELEE) { mi.attack_state = AS_MELEE; return true; }
|
| 1147 |
+
if (mutantCheckJump(g, i)) { mi.attack_state = AS_MISSILE; return true; }
|
| 1148 |
+
return false;
|
| 1149 |
+
},
|
| 1150 |
+
pain(g, i) {
|
| 1151 |
+
const e = g.ents[i];
|
| 1152 |
+
if (e.health < e.max_health / 2) e.skinnum = 1;
|
| 1153 |
+
if (debounced(g, e)) return;
|
| 1154 |
+
e.pain_debounce_time = g.ms + 3000;
|
| 1155 |
+
if (g.skill === 3) return;
|
| 1156 |
+
const r = Q.random(g);
|
| 1157 |
+
setMove(e, r < 0.33 ? 'pain1' : r < 0.66 ? 'pain2' : 'pain3');
|
| 1158 |
+
},
|
| 1159 |
+
die: unitDie({ body: [['bone', 2, true], ['meat', 4, true]], head: ['head', true] }, (g, e) => { e.skinnum = 1; return Q.random(g) < 0.5 ? 'death1' : 'death2'; }),
|
| 1160 |
+
dead(g, i) {
|
| 1161 |
+
const e = g.ents[i];
|
| 1162 |
+
e.mins = [-16, -16, -24]; e.maxs = [16, 16, -8]; e.movetype = 'toss'; e.svflags |= Q.SVF_DEADMONSTER;
|
| 1163 |
+
flyCheck(g, i);
|
| 1164 |
+
},
|
| 1165 |
+
};
|
| 1166 |
+
// mutant_jump_touch: a hit at more than 400 u/s does 40 + 10 * random() with as much knockback.
|
| 1167 |
+
Q.TOUCH.mutant_jump_touch = (g, i, other, plane) => {
|
| 1168 |
+
const e = g.ents[i];
|
| 1169 |
+
if (e.health <= 0) { e.touch = null; return; }
|
| 1170 |
+
if (other > 0 && g.ents[other].takedamage && len(e.velocity) > 400) {
|
| 1171 |
+
const normal = norm(e.velocity), point = ma(e.origin, e.maxs[0], normal);
|
| 1172 |
+
const damage = Math.trunc(40 + 10 * Q.random(g));
|
| 1173 |
+
Q.damage(g, other, i, i, e.velocity, point, normal, damage, damage, 0, 'mutant_leap');
|
| 1174 |
+
}
|
| 1175 |
+
if (!checkBottom(g, i)) {
|
| 1176 |
+
if (e.groundentity >= 0) { e.monsterinfo.nextframe = 1; e.touch = null; }
|
| 1177 |
+
return;
|
| 1178 |
+
}
|
| 1179 |
+
e.touch = null;
|
| 1180 |
+
};
|
| 1181 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/quake2_remake/q2player.js
ADDED
|
@@ -0,0 +1,852 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Quake II (1997) boss arenas - the player: client input (cl_input.c CL_BaseMove, in_win.c IN_MouseMove),
|
| 2 |
+
player movement (qcommon/pmove.c Pmove), ClientThink / ClientBeginServerFrame (p_client.c), ClientEndServerFrame
|
| 3 |
+
(p_view.c falling damage, damage feedback), weapons (p_weapon.c Weapon_Generic and the eight weapons used here),
|
| 4 |
+
projectiles and hitscan (g_weapon.c), damage (g_combat.c T_Damage / T_RadiusDamage / CheckArmor / CanDamage) and
|
| 5 |
+
items (g_items.c armor, health, ammo). Independent reimplementation from the GPL-2.0 source release, commit
|
| 6 |
+
372afde46e7defc9dd2d719a1732b8ace1fa096e; see q2core.js. */
|
| 7 |
+
(function (root) {
|
| 8 |
+
'use strict';
|
| 9 |
+
const M = root.Quake2Game, Q = M.Q;
|
| 10 |
+
const { add, sub, scale, ma, dot, len, norm, copy3 } = Q;
|
| 11 |
+
|
| 12 |
+
// ---------------- pmove.c constants and client cvar defaults (cl_main.c) ----------------
|
| 13 |
+
const PM = { stopspeed: 100, maxspeed: 300, duckspeed: 100, accelerate: 10, airaccelerate: 0, friction: 6 };
|
| 14 |
+
const PMF_DUCKED = 1, PMF_JUMP_HELD = 2, PMF_ON_GROUND = 4, PMF_TIME_WATERJUMP = 8, PMF_TIME_LAND = 16, PMF_TIME_TELEPORT = 32;
|
| 15 |
+
const CL = { forwardspeed: 200, sidespeed: 200, upspeed: 200, yawspeed: 140, anglespeedkey: 1.5, sensitivity: 3, m_yaw: 0.022, m_pitch: 0.022 };
|
| 16 |
+
const MIN_STEP_NORMAL = 0.7, STOP_EPSILON = 0.1, MAX_CLIP_PLANES = 5;
|
| 17 |
+
Q.PM = PM; Q.CL = CL;
|
| 18 |
+
const PLAYER_MINS = [-16, -16, -24], PLAYER_MAXS = [16, 16, 32];
|
| 19 |
+
|
| 20 |
+
// ---------------- items (g_items.c itemlist order; weapnext walks down the list, weapprev up) ----------------
|
| 21 |
+
const ITEMS = {
|
| 22 |
+
blaster: { index: 7, kind: 'weapon', name: 'Energy Pistol', ammo: null, quantity: 0 },
|
| 23 |
+
shotgun: { index: 8, kind: 'weapon', name: 'Shotgun', ammo: 'shells', quantity: 1 },
|
| 24 |
+
supershotgun: { index: 9, kind: 'weapon', name: 'Double Shotgun', ammo: 'shells', quantity: 2 },
|
| 25 |
+
machinegun: { index: 10, kind: 'weapon', name: 'Machinegun', ammo: 'bullets', quantity: 1 },
|
| 26 |
+
chaingun: { index: 11, kind: 'weapon', name: 'Chaingun', ammo: 'bullets', quantity: 1 },
|
| 27 |
+
rocketlauncher: { index: 14, kind: 'weapon', name: 'Rocket Launcher', ammo: 'rockets', quantity: 1 },
|
| 28 |
+
hyperblaster: { index: 15, kind: 'weapon', name: 'Pulse Cannon', ammo: 'cells', quantity: 1 },
|
| 29 |
+
railgun: { index: 16, kind: 'weapon', name: 'Coilgun', ammo: 'slugs', quantity: 1 },
|
| 30 |
+
};
|
| 31 |
+
const WEAPON_ORDER = Object.keys(ITEMS).sort((a, b) => ITEMS[a].index - ITEMS[b].index);
|
| 32 |
+
const AMMO_MAX = { bullets: 200, shells: 100, rockets: 50, cells: 200, slugs: 50 };
|
| 33 |
+
const AMMO_PICKUP = { shells: 10, bullets: 50, cells: 50, rockets: 5, slugs: 10 };
|
| 34 |
+
// gitem_armor_t: base_count, max_count, normal_protection, energy_protection. ArmorIndex checks jacket, combat, body.
|
| 35 |
+
const ARMOR = { jacket: [25, 50, 0.30, 0.00], combat: [50, 100, 0.60, 0.30], body: [100, 200, 0.80, 0.60] };
|
| 36 |
+
const ARMOR_ORDER = ['jacket', 'combat', 'body'];
|
| 37 |
+
Q.ITEMS = ITEMS; Q.ARMOR = ARMOR; Q.AMMO_MAX = AMMO_MAX; Q.WEAPON_ORDER = WEAPON_ORDER;
|
| 38 |
+
Q.armorIndex = p => ARMOR_ORDER.find(a => p.inv[a] > 0) || null;
|
| 39 |
+
|
| 40 |
+
// ---------------- player spawn (PutClientInServer + ChangeWeapon) ----------------
|
| 41 |
+
Q.spawnPlayer = (g, spec) => {
|
| 42 |
+
const p = g.ents[1] = Q.blankEdict();
|
| 43 |
+
Object.assign(p, {
|
| 44 |
+
classname: 'player', client: true, origin: copy3(spec.origin), old_origin: copy3(spec.origin), mins: copy3(PLAYER_MINS), maxs: copy3(PLAYER_MAXS),
|
| 45 |
+
viewheight: 22, health: 100, max_health: 100, mass: 200, takedamage: Q.DAMAGE_AIM, solid: Q.SOLID_BBOX, clipmask: Q.MASK_PLAYERSOLID,
|
| 46 |
+
movetype: 'walk', pain_debounce_time: 0, air_finished: 12000,
|
| 47 |
+
viewangles: [0, spec.yaw, 0], v_angle: [0, spec.yaw, 0],
|
| 48 |
+
pm: { origin: spec.origin.map(v => Math.trunc(v * 8)), velocity: [0, 0, 0], flags: 0, time: 0 }, old_pmove: null,
|
| 49 |
+
buttons: 0, oldbuttons: 0, latched: 0, weapon_thunk: false, inv: Object.assign({}, spec.inventory),
|
| 50 |
+
weapon: null, newweapon: spec.weapon, lastweapon: null, weaponstate: 0, gunframe: 0, machinegun_shots: 0,
|
| 51 |
+
kick_angles: [0, 0, 0], kick_origin: [0, 0, 0], oldvelocity: [0, 0, 0], damage_blood: 0, damage_armor: 0, damage_knockback: 0,
|
| 52 |
+
damage_from: [0, 0, 0], damage_alpha: 0, bonus_alpha: 0, fall_value: 0, fall_time: 0, mynoise: -1, mynoise2: -1, pickup: null, pickup_time: 0, fired: 0,
|
| 53 |
+
});
|
| 54 |
+
changeWeapon(g, p);
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
// ---------------- client side: usercmd from held keys and the per-tick mouse delta ----------------
|
| 58 |
+
// keys: Set of held key names, pressed: newly pressed keys, mouse: [dx, dy, dz] for this tick. msec is this host
|
| 59 |
+
// frame (16 or 17 ms at 60 Hz, q2-arena@3): one usercmd per client frame, as the original client at cl_maxfps 60.
|
| 60 |
+
Q.buildUsercmd = (g, keys, pressed, mouse, msec) => {
|
| 61 |
+
const p = g.ents[1], frametime = msec / 1000, speed = keys.has('Shift');
|
| 62 |
+
// CL_AdjustAngles: keyboard turning, cl_yawspeed 140 deg/s, x1.5 with the speed key held.
|
| 63 |
+
const turn = (speed ? frametime * CL.anglespeedkey : frametime) * CL.yawspeed;
|
| 64 |
+
if (keys.has('E')) p.viewangles[1] -= turn;
|
| 65 |
+
if (keys.has('Q')) p.viewangles[1] += turn;
|
| 66 |
+
// IN_MouseMove with freelook: yaw -= m_yaw*sensitivity*dx, pitch += m_pitch*sensitivity*dy.
|
| 67 |
+
p.viewangles[1] -= CL.m_yaw * CL.sensitivity * (mouse[0] || 0);
|
| 68 |
+
p.viewangles[0] += CL.m_pitch * CL.sensitivity * (mouse[1] || 0);
|
| 69 |
+
p.viewangles[1] = ((p.viewangles[1] % 360) + 360) % 360; // client angles stay unquantized; ANGLE2SHORT wraps
|
| 70 |
+
// CL_ClampPitch (delta_angles are zero here): +-89 degrees.
|
| 71 |
+
if (p.viewangles[0] > 89) p.viewangles[0] = 89;
|
| 72 |
+
if (p.viewangles[0] < -89) p.viewangles[0] = -89;
|
| 73 |
+
const cmd = { msec, buttons: 0, angles: p.viewangles.map(Q.ANGLE2SHORT), forwardmove: 0, sidemove: 0, upmove: 0 };
|
| 74 |
+
if (keys.has('D')) cmd.sidemove += CL.sidespeed;
|
| 75 |
+
if (keys.has('A')) cmd.sidemove -= CL.sidespeed;
|
| 76 |
+
if (keys.has('Space')) cmd.upmove += CL.upspeed;
|
| 77 |
+
if (keys.has('L')) cmd.upmove -= CL.upspeed;
|
| 78 |
+
if (keys.has('W')) cmd.forwardmove += CL.forwardspeed;
|
| 79 |
+
if (keys.has('S')) cmd.forwardmove -= CL.forwardspeed;
|
| 80 |
+
if (speed) { cmd.forwardmove *= 2; cmd.sidemove *= 2; cmd.upmove *= 2; } // (in_speed ^ cl_run 0)
|
| 81 |
+
if (keys.has('J') || keys.has('LMB')) cmd.buttons |= 1; // BUTTON_ATTACK
|
| 82 |
+
// Console commands bound to keys arrive before the move: weapnext (K / RMB / wheel up), weapprev (R / wheel down).
|
| 83 |
+
const next = pressed.has('K') || pressed.has('RMB') || (mouse[2] || 0) > 0, prev = pressed.has('R') || (mouse[2] || 0) < 0;
|
| 84 |
+
if (next) Q.cmdWeapCycle(g, -1); else if (prev) Q.cmdWeapCycle(g, +1);
|
| 85 |
+
return cmd;
|
| 86 |
+
};
|
| 87 |
+
// Cmd_WeapNext_f / Cmd_WeapPrev_f walk itemlist away from the current weapon and call Use_Weapon on every owned
|
| 88 |
+
// weapon; the loop only stops when it comes back to pers.weapon (Use_Weapon sets newweapon, not weapon), so the
|
| 89 |
+
// last successful use wins: weapnext ends on the nearest higher-index weapon (wrapping), weapprev on the nearest
|
| 90 |
+
// lower one. dir -1 = weapnext, +1 = weapprev (the order the C loop visits indices).
|
| 91 |
+
Q.cmdWeapCycle = (g, dir) => {
|
| 92 |
+
const p = g.ents[1];
|
| 93 |
+
if (!p.weapon || p.health <= 0) return;
|
| 94 |
+
const cur = WEAPON_ORDER.indexOf(p.weapon), n = WEAPON_ORDER.length;
|
| 95 |
+
for (let k = 1; k < n; k++) {
|
| 96 |
+
const w = WEAPON_ORDER[(cur + dir * k + n * 2) % n];
|
| 97 |
+
if (p.inv[w]) useWeapon(g, p, w);
|
| 98 |
+
}
|
| 99 |
+
};
|
| 100 |
+
function useWeapon(g, p, w) { // Use_Weapon
|
| 101 |
+
if (w === p.weapon) return;
|
| 102 |
+
const it = ITEMS[w];
|
| 103 |
+
if (it.ammo && (!p.inv[it.ammo] || p.inv[it.ammo] < it.quantity)) return;
|
| 104 |
+
p.newweapon = w;
|
| 105 |
+
}
|
| 106 |
+
Q.useWeapon = useWeapon;
|
| 107 |
+
|
| 108 |
+
// ---------------- Pmove ----------------
|
| 109 |
+
function pmTrace(g, start, mins, maxs, end) { return Q.trace(g, start, mins, maxs, end, 1, Q.MASK_PLAYERSOLID); }
|
| 110 |
+
function clipVelocity(v, n, overbounce) {
|
| 111 |
+
const backoff = dot(v, n) * overbounce, out = [0, 0, 0];
|
| 112 |
+
for (let i = 0; i < 3; i++) { out[i] = v[i] - n[i] * backoff; if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON) out[i] = 0; }
|
| 113 |
+
return out;
|
| 114 |
+
}
|
| 115 |
+
function stepSlideMove_(g, pm, pml) {
|
| 116 |
+
const primal = copy3(pml.velocity), planes = [];
|
| 117 |
+
let time_left = pml.frametime;
|
| 118 |
+
for (let bump = 0; bump < 4; bump++) {
|
| 119 |
+
const end = [0, 1, 2].map(i => pml.origin[i] + time_left * pml.velocity[i]);
|
| 120 |
+
const tr = pmTrace(g, pml.origin, pm.mins, pm.maxs, end);
|
| 121 |
+
if (tr.allsolid) { pml.velocity[2] = 0; return; }
|
| 122 |
+
if (tr.fraction > 0) { pml.origin = copy3(tr.endpos); planes.length = 0; }
|
| 123 |
+
if (tr.fraction === 1) break;
|
| 124 |
+
if (pm.touch.length < 32) pm.touch.push(tr.ent);
|
| 125 |
+
time_left -= time_left * tr.fraction;
|
| 126 |
+
if (planes.length >= MAX_CLIP_PLANES) { pml.velocity = [0, 0, 0]; break; }
|
| 127 |
+
planes.push(tr.normal);
|
| 128 |
+
let i;
|
| 129 |
+
for (i = 0; i < planes.length; i++) {
|
| 130 |
+
pml.velocity = clipVelocity(pml.velocity, planes[i], 1.01);
|
| 131 |
+
let j;
|
| 132 |
+
for (j = 0; j < planes.length; j++) if (j !== i && dot(pml.velocity, planes[j]) < 0) break;
|
| 133 |
+
if (j === planes.length) break;
|
| 134 |
+
}
|
| 135 |
+
if (i === planes.length) {
|
| 136 |
+
if (planes.length !== 2) { pml.velocity = [0, 0, 0]; break; }
|
| 137 |
+
const dir = Q.cross(planes[0], planes[1]); pml.velocity = scale(dir, dot(dir, pml.velocity));
|
| 138 |
+
}
|
| 139 |
+
if (dot(pml.velocity, primal) <= 0) { pml.velocity = [0, 0, 0]; break; }
|
| 140 |
+
}
|
| 141 |
+
if (pm.s.time) pml.velocity = primal;
|
| 142 |
+
}
|
| 143 |
+
function stepSlideMove(g, pm, pml) {
|
| 144 |
+
const start_o = copy3(pml.origin), start_v = copy3(pml.velocity);
|
| 145 |
+
stepSlideMove_(g, pm, pml);
|
| 146 |
+
const down_o = copy3(pml.origin), down_v = copy3(pml.velocity);
|
| 147 |
+
const up = copy3(start_o); up[2] += Q.STEPSIZE;
|
| 148 |
+
let tr = pmTrace(g, up, pm.mins, pm.maxs, up);
|
| 149 |
+
if (tr.allsolid) return; // can't step up
|
| 150 |
+
pml.origin = up; pml.velocity = copy3(start_v);
|
| 151 |
+
stepSlideMove_(g, pm, pml);
|
| 152 |
+
const down = copy3(pml.origin); down[2] -= Q.STEPSIZE;
|
| 153 |
+
tr = pmTrace(g, pml.origin, pm.mins, pm.maxs, down);
|
| 154 |
+
if (!tr.allsolid) pml.origin = copy3(tr.endpos);
|
| 155 |
+
const down_dist = (down_o[0] - start_o[0]) ** 2 + (down_o[1] - start_o[1]) ** 2;
|
| 156 |
+
const up_dist = (pml.origin[0] - start_o[0]) ** 2 + (pml.origin[1] - start_o[1]) ** 2;
|
| 157 |
+
if (down_dist > up_dist || tr.normal[2] < MIN_STEP_NORMAL) { pml.origin = down_o; pml.velocity = down_v; return; }
|
| 158 |
+
pml.velocity[2] = down_v[2];
|
| 159 |
+
}
|
| 160 |
+
function friction(pm, pml) {
|
| 161 |
+
const v = pml.velocity, speed = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
| 162 |
+
if (speed < 1) { v[0] = 0; v[1] = 0; return; }
|
| 163 |
+
let drop = 0;
|
| 164 |
+
// SV_Trace always reports a ground surface (CM_BoxTrace starts from nullsurface); no slick surfaces here.
|
| 165 |
+
if (pm.groundentity >= 0) { const control = speed < PM.stopspeed ? PM.stopspeed : speed; drop += control * PM.friction * pml.frametime; }
|
| 166 |
+
let newspeed = speed - drop; if (newspeed < 0) newspeed = 0; newspeed /= speed;
|
| 167 |
+
v[0] *= newspeed; v[1] *= newspeed; v[2] *= newspeed;
|
| 168 |
+
}
|
| 169 |
+
function accelerate(pml, wishdir, wishspeed, accel) {
|
| 170 |
+
const currentspeed = dot(pml.velocity, wishdir), addspeed = wishspeed - currentspeed;
|
| 171 |
+
if (addspeed <= 0) return;
|
| 172 |
+
let accelspeed = accel * pml.frametime * wishspeed; if (accelspeed > addspeed) accelspeed = addspeed;
|
| 173 |
+
for (let i = 0; i < 3; i++) pml.velocity[i] += accelspeed * wishdir[i];
|
| 174 |
+
}
|
| 175 |
+
function airMove(g, pm, pml) {
|
| 176 |
+
const fmove = pm.cmd.forwardmove, smove = pm.cmd.sidemove;
|
| 177 |
+
let wishvel = [pml.forward[0] * fmove + pml.right[0] * smove, pml.forward[1] * fmove + pml.right[1] * smove, 0];
|
| 178 |
+
let wishspeed = len(wishvel); const wishdir = norm(wishvel);
|
| 179 |
+
const maxspeed = (pm.s.flags & PMF_DUCKED) ? PM.duckspeed : PM.maxspeed;
|
| 180 |
+
if (wishspeed > maxspeed) { wishvel = scale(wishvel, maxspeed / wishspeed); wishspeed = maxspeed; }
|
| 181 |
+
if (pm.groundentity >= 0) {
|
| 182 |
+
pml.velocity[2] = 0;
|
| 183 |
+
accelerate(pml, wishdir, wishspeed, PM.accelerate);
|
| 184 |
+
pml.velocity[2] = 0; // gravity > 0
|
| 185 |
+
if (!pml.velocity[0] && !pml.velocity[1]) return;
|
| 186 |
+
stepSlideMove(g, pm, pml);
|
| 187 |
+
} else {
|
| 188 |
+
accelerate(pml, wishdir, wishspeed, 1); // pm_airaccelerate 0
|
| 189 |
+
pml.velocity[2] -= Q.SV_GRAVITY * pml.frametime;
|
| 190 |
+
stepSlideMove(g, pm, pml);
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
function catagorizePosition(g, pm, pml) {
|
| 194 |
+
const point = [pml.origin[0], pml.origin[1], pml.origin[2] - 0.25];
|
| 195 |
+
if (pml.velocity[2] > 180) { pm.s.flags &= ~PMF_ON_GROUND; pm.groundentity = -1; }
|
| 196 |
+
else {
|
| 197 |
+
const tr = pmTrace(g, pml.origin, pm.mins, pm.maxs, point);
|
| 198 |
+
pml.groundsurface = tr.fraction < 1 || tr.startsolid;
|
| 199 |
+
if (tr.normal[2] < 0.7 && !tr.startsolid) { pm.groundentity = -1; pm.s.flags &= ~PMF_ON_GROUND; }
|
| 200 |
+
else {
|
| 201 |
+
pm.groundentity = tr.ent;
|
| 202 |
+
if (pm.s.flags & PMF_TIME_WATERJUMP) { pm.s.flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); pm.s.time = 0; }
|
| 203 |
+
if (!(pm.s.flags & PMF_ON_GROUND)) {
|
| 204 |
+
pm.s.flags |= PMF_ON_GROUND;
|
| 205 |
+
if (pml.velocity[2] < -200) { pm.s.flags |= PMF_TIME_LAND; pm.s.time = pml.velocity[2] < -400 ? 25 : 18; }
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
if (pm.touch.length < 32) pm.touch.push(tr.ent);
|
| 209 |
+
}
|
| 210 |
+
pm.waterlevel = 0;
|
| 211 |
+
}
|
| 212 |
+
function checkJump(pm, pml) {
|
| 213 |
+
if (pm.s.flags & PMF_TIME_LAND) return;
|
| 214 |
+
if (pm.cmd.upmove < 10) { pm.s.flags &= ~PMF_JUMP_HELD; return; }
|
| 215 |
+
if (pm.s.flags & PMF_JUMP_HELD) return;
|
| 216 |
+
if (pm.groundentity < 0) return;
|
| 217 |
+
pm.s.flags |= PMF_JUMP_HELD; pm.groundentity = -1;
|
| 218 |
+
pml.velocity[2] += 270; if (pml.velocity[2] < 270) pml.velocity[2] = 270;
|
| 219 |
+
}
|
| 220 |
+
function checkDuck(g, pm, pml) {
|
| 221 |
+
pm.mins = [-16, -16, -24]; pm.maxs = [16, 16, 32];
|
| 222 |
+
if (pm.cmd.upmove < 0 && (pm.s.flags & PMF_ON_GROUND)) pm.s.flags |= PMF_DUCKED;
|
| 223 |
+
else if (pm.s.flags & PMF_DUCKED) { const tr = pmTrace(g, pml.origin, pm.mins, [16, 16, 32], pml.origin); if (!tr.allsolid) pm.s.flags &= ~PMF_DUCKED; }
|
| 224 |
+
if (pm.s.flags & PMF_DUCKED) { pm.maxs[2] = 4; pm.viewheight = -2; } else { pm.maxs[2] = 32; pm.viewheight = 22; }
|
| 225 |
+
}
|
| 226 |
+
const goodPosition = (g, pm) => { const o = pm.s.origin.map(v => v * 0.125); return !pmTrace(g, o, pm.mins, pm.maxs, o).allsolid; };
|
| 227 |
+
function snapPosition(g, pm, pml) {
|
| 228 |
+
const JITTER = [0, 4, 1, 2, 3, 5, 6, 7], sign = [0, 0, 0];
|
| 229 |
+
pm.s.velocity = pml.velocity.map(v => Math.trunc(v * 8));
|
| 230 |
+
for (let i = 0; i < 3; i++) {
|
| 231 |
+
sign[i] = pml.origin[i] >= 0 ? 1 : -1;
|
| 232 |
+
pm.s.origin[i] = Math.trunc(pml.origin[i] * 8);
|
| 233 |
+
if (pm.s.origin[i] * 0.125 === pml.origin[i]) sign[i] = 0;
|
| 234 |
+
}
|
| 235 |
+
const base = copy3(pm.s.origin);
|
| 236 |
+
for (let j = 0; j < 8; j++) {
|
| 237 |
+
const bits = JITTER[j]; pm.s.origin = copy3(base);
|
| 238 |
+
for (let i = 0; i < 3; i++) if (bits & (1 << i)) pm.s.origin[i] += sign[i];
|
| 239 |
+
if (goodPosition(g, pm)) return;
|
| 240 |
+
}
|
| 241 |
+
pm.s.origin = copy3(pml.previous_origin);
|
| 242 |
+
}
|
| 243 |
+
function initialSnapPosition(g, pm, pml) {
|
| 244 |
+
const OFS = [0, -1, 1], base = copy3(pm.s.origin);
|
| 245 |
+
for (let z = 0; z < 3; z++) for (let y = 0; y < 3; y++) for (let x = 0; x < 3; x++) {
|
| 246 |
+
pm.s.origin = [base[0] + OFS[x], base[1] + OFS[y], base[2] + OFS[z]];
|
| 247 |
+
if (goodPosition(g, pm)) { pml.origin = pm.s.origin.map(v => v * 0.125); pml.previous_origin = copy3(pm.s.origin); return; }
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
function pmove(g, pm) {
|
| 251 |
+
pm.touch = []; pm.viewangles = [0, 0, 0]; pm.viewheight = 0; pm.groundentity = -1; pm.waterlevel = 0;
|
| 252 |
+
const pml = { origin: pm.s.origin.map(v => v * 0.125), velocity: pm.s.velocity.map(v => v * 0.125), previous_origin: copy3(pm.s.origin), frametime: pm.cmd.msec * 0.001, groundsurface: false };
|
| 253 |
+
// PM_ClampAngles (delta_angles 0)
|
| 254 |
+
pm.viewangles = pm.cmd.angles.map(Q.SHORT2ANGLE);
|
| 255 |
+
if (pm.viewangles[0] > 89 && pm.viewangles[0] < 180) pm.viewangles[0] = 89;
|
| 256 |
+
else if (pm.viewangles[0] < 271 && pm.viewangles[0] >= 180) pm.viewangles[0] = 271;
|
| 257 |
+
let av = Q.angleVectors(pm.viewangles); pml.forward = av.forward; pml.right = av.right;
|
| 258 |
+
checkDuck(g, pm, pml);
|
| 259 |
+
if (pm.snapinitial) initialSnapPosition(g, pm, pml);
|
| 260 |
+
catagorizePosition(g, pm, pml);
|
| 261 |
+
if (pm.s.time) {
|
| 262 |
+
let msec = pm.cmd.msec >> 3; if (!msec) msec = 1;
|
| 263 |
+
if (msec >= pm.s.time) { pm.s.flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); pm.s.time = 0; } else pm.s.time -= msec;
|
| 264 |
+
}
|
| 265 |
+
checkJump(pm, pml);
|
| 266 |
+
friction(pm, pml);
|
| 267 |
+
const angles = copy3(pm.viewangles);
|
| 268 |
+
if (angles[0] > 180) angles[0] -= 360;
|
| 269 |
+
angles[0] /= 3;
|
| 270 |
+
av = Q.angleVectors(angles); pml.forward = av.forward; pml.right = av.right;
|
| 271 |
+
airMove(g, pm, pml);
|
| 272 |
+
catagorizePosition(g, pm, pml);
|
| 273 |
+
snapPosition(g, pm, pml);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
// ---------------- ClientThink ----------------
|
| 277 |
+
Q.clientThink = (g, cmd) => {
|
| 278 |
+
const p = g.ents[1];
|
| 279 |
+
const pm = { s: { origin: p.origin.map(v => Math.trunc(v * 8)), velocity: p.velocity.map(v => Math.trunc(v * 8)), flags: p.pm.flags, time: p.pm.time }, cmd };
|
| 280 |
+
pm.snapinitial = !p.old_pmove || JSON.stringify(p.old_pmove) !== JSON.stringify(pm.s);
|
| 281 |
+
pmove(g, pm);
|
| 282 |
+
p.pm = { origin: copy3(pm.s.origin), velocity: copy3(pm.s.velocity), flags: pm.s.flags, time: pm.s.time };
|
| 283 |
+
p.old_pmove = JSON.parse(JSON.stringify(p.pm));
|
| 284 |
+
p.origin = pm.s.origin.map(v => v * 0.125); p.velocity = pm.s.velocity.map(v => v * 0.125);
|
| 285 |
+
p.mins = copy3(pm.mins); p.maxs = copy3(pm.maxs);
|
| 286 |
+
if (p.groundentity >= 0 && pm.groundentity < 0 && cmd.upmove >= 10) { Q.playerNoise(g, p.origin, 'self'); Q.event(g, 'jump'); }
|
| 287 |
+
p.viewheight = pm.viewheight; p.groundentity = pm.groundentity;
|
| 288 |
+
p.v_angle = copy3(pm.viewangles);
|
| 289 |
+
touchTriggers(g, 1);
|
| 290 |
+
const seen = new Set();
|
| 291 |
+
for (const other of pm.touch) {
|
| 292 |
+
if (other <= 0 || seen.has(other)) continue; seen.add(other);
|
| 293 |
+
const o = g.ents[other];
|
| 294 |
+
if (o && o.inuse && o.touch && Q.TOUCH[o.touch]) Q.TOUCH[o.touch](g, other, 1, null);
|
| 295 |
+
}
|
| 296 |
+
p.oldbuttons = p.buttons; p.buttons = cmd.buttons; p.latched |= p.buttons & ~p.oldbuttons;
|
| 297 |
+
if ((p.latched & 1) && !p.weapon_thunk) { p.weapon_thunk = true; thinkWeapon(g); }
|
| 298 |
+
};
|
| 299 |
+
function touchTriggers(g, i) { // G_TouchTriggers for the player: item triggers overlapping the absolute box
|
| 300 |
+
const e = g.ents[i];
|
| 301 |
+
for (let k = 1; k < g.ents.length; k++) {
|
| 302 |
+
const t = g.ents[k];
|
| 303 |
+
if (!t.inuse || t.solid !== Q.SOLID_TRIGGER || !t.touch) continue;
|
| 304 |
+
if (Q.boxesOverlap(e, t)) Q.TOUCH[t.touch](g, k, i, null);
|
| 305 |
+
if (!e.inuse) return;
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// ---------------- ClientBeginServerFrame / ClientEndServerFrame ----------------
|
| 310 |
+
Q.clientBeginServerFrame = g => {
|
| 311 |
+
const p = g.ents[1];
|
| 312 |
+
if (!p.weapon_thunk) thinkWeapon(g); else p.weapon_thunk = false;
|
| 313 |
+
if (p.deadflag) return;
|
| 314 |
+
if (!Q.visiblePoint(g, 1, Q.trailLastSpot(g).origin)) Q.playerTrailAdd(g, p.old_origin);
|
| 315 |
+
p.latched = 0;
|
| 316 |
+
};
|
| 317 |
+
Q.clientEndServerFrame = g => {
|
| 318 |
+
const p = g.ents[1];
|
| 319 |
+
fallingDamage(g, p);
|
| 320 |
+
damageFeedback(g, p);
|
| 321 |
+
// SV_CalcBlend drops the flashes after P_DamageFeedback added to them.
|
| 322 |
+
p.damage_alpha = Math.max(0, p.damage_alpha - 0.06); p.bonus_alpha = Math.max(0, p.bonus_alpha - 0.1);
|
| 323 |
+
p.oldvelocity = copy3(p.velocity);
|
| 324 |
+
p.kick_origin = [0, 0, 0]; p.kick_angles = [0, 0, 0];
|
| 325 |
+
};
|
| 326 |
+
function fallingDamage(g, p) { // P_FallingDamage
|
| 327 |
+
let delta;
|
| 328 |
+
if (p.oldvelocity[2] < 0 && p.velocity[2] > p.oldvelocity[2] && p.groundentity < 0) delta = p.oldvelocity[2];
|
| 329 |
+
else { if (p.groundentity < 0) return; delta = p.velocity[2] - p.oldvelocity[2]; }
|
| 330 |
+
delta = delta * delta * 0.0001;
|
| 331 |
+
if (delta < 15) return;
|
| 332 |
+
p.fall_value = Math.min(40, delta * 0.5); p.fall_time = g.ms + 300;
|
| 333 |
+
if (delta > 30) {
|
| 334 |
+
p.pain_debounce_time = g.ms;
|
| 335 |
+
let damage = Math.trunc((delta - 30) / 2); if (damage < 1) damage = 1;
|
| 336 |
+
Q.damage(g, 1, 0, 0, [0, 0, 1], p.origin, [0, 0, 0], damage, 0, 0, 'falling');
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
function damageFeedback(g, p) { // P_DamageFeedback: screen flash, and one rand() for the pain sound
|
| 340 |
+
let count = p.damage_blood + p.damage_armor;
|
| 341 |
+
if (!count) return;
|
| 342 |
+
if (count < 10) count = 10; // always make a visible effect
|
| 343 |
+
if (g.ms > p.pain_debounce_time) { Q.rand(g); p.pain_debounce_time = g.ms + 700; }
|
| 344 |
+
if (p.damage_alpha < 0) p.damage_alpha = 0;
|
| 345 |
+
p.damage_alpha = Math.min(0.6, Math.max(0.2, p.damage_alpha + count * 0.01));
|
| 346 |
+
p.damage_from_dir = sub(p.damage_from, p.origin);
|
| 347 |
+
p.damage_blood = 0; p.damage_armor = 0; p.damage_knockback = 0;
|
| 348 |
+
}
|
| 349 |
+
// PlayerNoise: the first call spawns the two player noise edicts (they hold slots in the edict list). Weapon
|
| 350 |
+
// and self noise (firing, jumping) go to mynoise / level.sound_entity, impact noise to mynoise2 / sound2_entity.
|
| 351 |
+
Q.playerNoise = (g, where, type) => {
|
| 352 |
+
const p = g.ents[1];
|
| 353 |
+
if (p.mynoise < 0) {
|
| 354 |
+
for (const k of ['mynoise', 'mynoise2']) { p[k] = Q.spawn(g); Object.assign(g.ents[p[k]], { classname: 'player_noise', svflags: Q.SVF_NOCLIENT, owner: 1, mins: [-8, -8, -8], maxs: [8, 8, 8], solid: Q.SOLID_NOT }); }
|
| 355 |
+
}
|
| 356 |
+
const n = type === 'impact' ? p.mynoise2 : p.mynoise;
|
| 357 |
+
if (type === 'impact') { g.sound2_entity = n; g.sound2_entity_framenum = g.framenum; } else { g.sound_entity = n; g.sound_entity_framenum = g.framenum; }
|
| 358 |
+
g.ents[n].origin = copy3(where || p.origin); g.ents[n].teleport_time = g.ms;
|
| 359 |
+
};
|
| 360 |
+
|
| 361 |
+
// ---------------- weapons ----------------
|
| 362 |
+
const READY = 0, ACTIVATING = 1, DROPPING = 2, FIRING = 3;
|
| 363 |
+
// Weapon_Generic(FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST, pause, fire)
|
| 364 |
+
const WDEF = {
|
| 365 |
+
blaster: { frames: [4, 8, 52, 55], pause: [19, 32], fire: [5], fn: 'blaster' },
|
| 366 |
+
shotgun: { frames: [7, 18, 36, 39], pause: [22, 28, 34], fire: [8, 9], fn: 'shotgun' },
|
| 367 |
+
supershotgun: { frames: [6, 17, 57, 61], pause: [29, 42, 57], fire: [7], fn: 'supershotgun' },
|
| 368 |
+
machinegun: { frames: [3, 5, 45, 49], pause: [23, 45], fire: [4, 5], fn: 'machinegun' },
|
| 369 |
+
chaingun: { frames: [4, 31, 61, 64], pause: [38, 43, 51, 61], fire: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], fn: 'chaingun' },
|
| 370 |
+
rocketlauncher: { frames: [4, 12, 50, 54], pause: [25, 33, 42, 50], fire: [5], fn: 'rocket' },
|
| 371 |
+
hyperblaster: { frames: [5, 20, 49, 53], pause: [], fire: [6, 7, 8, 9, 10, 11], fn: 'hyperblaster' },
|
| 372 |
+
railgun: { frames: [3, 18, 56, 61], pause: [56], fire: [4], fn: 'railgun' },
|
| 373 |
+
};
|
| 374 |
+
Q.WDEF = WDEF;
|
| 375 |
+
function changeWeapon(g, p) {
|
| 376 |
+
p.lastweapon = p.weapon; p.weapon = p.newweapon; p.newweapon = null; p.machinegun_shots = 0;
|
| 377 |
+
if (!p.weapon) return;
|
| 378 |
+
p.weaponstate = ACTIVATING; p.gunframe = 0;
|
| 379 |
+
}
|
| 380 |
+
function noAmmoWeaponChange(g, p) {
|
| 381 |
+
const has = (w, ammo, n = 1) => p.inv[w] && p.inv[ammo] >= n;
|
| 382 |
+
p.newweapon = has('railgun', 'slugs') ? 'railgun' : has('hyperblaster', 'cells') ? 'hyperblaster' : has('chaingun', 'bullets') ? 'chaingun'
|
| 383 |
+
: has('machinegun', 'bullets') ? 'machinegun' : has('supershotgun', 'shells', 2) ? 'supershotgun' : has('shotgun', 'shells') ? 'shotgun' : 'blaster';
|
| 384 |
+
}
|
| 385 |
+
function thinkWeapon(g) {
|
| 386 |
+
const p = g.ents[1];
|
| 387 |
+
if (p.health < 1) { p.newweapon = null; changeWeapon(g, p); }
|
| 388 |
+
if (p.weapon) weaponGeneric(g, p, WDEF[p.weapon]);
|
| 389 |
+
}
|
| 390 |
+
function weaponGeneric(g, p, w) {
|
| 391 |
+
const [ACT_LAST, FIRE_LAST, IDLE_LAST, DEACT_LAST] = w.frames;
|
| 392 |
+
const FIRE_FIRST = ACT_LAST + 1, IDLE_FIRST = FIRE_LAST + 1, DEACT_FIRST = IDLE_LAST + 1;
|
| 393 |
+
if (p.deadflag) return;
|
| 394 |
+
if (p.weaponstate === DROPPING) { if (p.gunframe === DEACT_LAST) { changeWeapon(g, p); return; } p.gunframe++; return; }
|
| 395 |
+
if (p.weaponstate === ACTIVATING) { if (p.gunframe === ACT_LAST) { p.weaponstate = READY; p.gunframe = IDLE_FIRST; return; } p.gunframe++; return; }
|
| 396 |
+
if (p.newweapon && p.weaponstate !== FIRING) { p.weaponstate = DROPPING; p.gunframe = DEACT_FIRST; return; }
|
| 397 |
+
if (p.weaponstate === READY) {
|
| 398 |
+
if ((p.latched | p.buttons) & 1) {
|
| 399 |
+
p.latched &= ~1;
|
| 400 |
+
const it = ITEMS[p.weapon];
|
| 401 |
+
if (!it.ammo || p.inv[it.ammo] >= it.quantity) { p.gunframe = FIRE_FIRST; p.weaponstate = FIRING; }
|
| 402 |
+
else { if (g.ms >= p.pain_debounce_time) p.pain_debounce_time = g.ms + 1000; noAmmoWeaponChange(g, p); }
|
| 403 |
+
} else {
|
| 404 |
+
if (p.gunframe === IDLE_LAST) { p.gunframe = IDLE_FIRST; return; }
|
| 405 |
+
for (const f of w.pause) if (p.gunframe === f && (Q.rand(g) & 15)) return;
|
| 406 |
+
p.gunframe++; return;
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
if (p.weaponstate === FIRING) {
|
| 410 |
+
let fired = false;
|
| 411 |
+
for (const f of w.fire) if (p.gunframe === f) { FIRE[w.fn](g, p); fired = true; break; }
|
| 412 |
+
if (!fired) p.gunframe++;
|
| 413 |
+
if (p.gunframe === IDLE_FIRST + 1) p.weaponstate = READY;
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
// P_ProjectSource (right handed), from the eye height.
|
| 417 |
+
const projectSource = (p, offset, forward, right) => Q.projectSource(p.origin, offset, forward, right);
|
| 418 |
+
const FIRE = {
|
| 419 |
+
blaster(g, p) { blasterFire(g, p, [0, 0, 0], 10, false, 'blaster'); p.gunframe++; },
|
| 420 |
+
hyperblaster(g, p) {
|
| 421 |
+
if (!(p.buttons & 1)) p.gunframe++;
|
| 422 |
+
else {
|
| 423 |
+
if (!p.inv.cells) { if (g.ms >= p.pain_debounce_time) p.pain_debounce_time = g.ms + 1000; noAmmoWeaponChange(g, p); }
|
| 424 |
+
else {
|
| 425 |
+
const rotation = (p.gunframe - 5) * 2 * Math.PI / 6;
|
| 426 |
+
blasterFire(g, p, [-4 * Q.sin(rotation), 0, 4 * Q.cos(rotation)], 20, true, 'hyperblaster');
|
| 427 |
+
p.inv.cells--;
|
| 428 |
+
}
|
| 429 |
+
p.gunframe++;
|
| 430 |
+
if (p.gunframe === 12 && p.inv.cells) p.gunframe = 6;
|
| 431 |
+
}
|
| 432 |
+
},
|
| 433 |
+
machinegun(g, p) {
|
| 434 |
+
if (!(p.buttons & 1)) { p.machinegun_shots = 0; p.gunframe++; return; }
|
| 435 |
+
p.gunframe = p.gunframe === 5 ? 4 : 5;
|
| 436 |
+
if (p.inv.bullets < 1) { p.gunframe = 6; if (g.ms >= p.pain_debounce_time) p.pain_debounce_time = g.ms + 1000; noAmmoWeaponChange(g, p); return; }
|
| 437 |
+
for (let i = 1; i < 3; i++) { p.kick_origin[i] = Q.crandom(g) * 0.35; p.kick_angles[i] = Q.crandom(g) * 0.7; }
|
| 438 |
+
p.kick_origin[0] = Q.crandom(g) * 0.35; p.kick_angles[0] = p.machinegun_shots * -1.5;
|
| 439 |
+
p.machinegun_shots = Math.min(9, p.machinegun_shots + 1);
|
| 440 |
+
const av = Q.angleVectors(add(p.v_angle, p.kick_angles));
|
| 441 |
+
const start = projectSource(p, [0, 8, p.viewheight - 8], av.forward, av.right);
|
| 442 |
+
Q.fireBullet(g, 1, start, av.forward, 8, 2, 300, 500, 'machinegun');
|
| 443 |
+
Q.playerNoise(g, start, 'weapon'); muzzle(g, p, 'machinegun'); p.inv.bullets--;
|
| 444 |
+
},
|
| 445 |
+
chaingun(g, p) {
|
| 446 |
+
if (p.gunframe === 14 && !(p.buttons & 1)) { p.gunframe = 32; return; }
|
| 447 |
+
else if (p.gunframe === 21 && (p.buttons & 1) && p.inv.bullets) p.gunframe = 15;
|
| 448 |
+
else p.gunframe++;
|
| 449 |
+
let shots = p.gunframe <= 9 ? 1 : p.gunframe <= 14 ? ((p.buttons & 1) ? 2 : 1) : 3;
|
| 450 |
+
if (p.inv.bullets < shots) shots = p.inv.bullets;
|
| 451 |
+
if (!shots) { if (g.ms >= p.pain_debounce_time) p.pain_debounce_time = g.ms + 1000; noAmmoWeaponChange(g, p); return; }
|
| 452 |
+
for (let i = 0; i < 3; i++) { p.kick_origin[i] = Q.crandom(g) * 0.35; p.kick_angles[i] = Q.crandom(g) * 0.7; }
|
| 453 |
+
for (let i = 0; i < shots; i++) {
|
| 454 |
+
const av = Q.angleVectors(p.v_angle), r = 7 + Q.crandom(g) * 4, u = Q.crandom(g) * 4;
|
| 455 |
+
const start = projectSource(p, [0, r, u + p.viewheight - 8], av.forward, av.right);
|
| 456 |
+
Q.fireBullet(g, 1, start, av.forward, 8, 2, 300, 500, 'chaingun');
|
| 457 |
+
}
|
| 458 |
+
Q.playerNoise(g, p.origin, 'weapon'); muzzle(g, p, 'chaingun'); p.inv.bullets -= shots;
|
| 459 |
+
},
|
| 460 |
+
shotgun(g, p) {
|
| 461 |
+
if (p.gunframe === 9) { p.gunframe++; return; }
|
| 462 |
+
const av = Q.angleVectors(p.v_angle);
|
| 463 |
+
p.kick_origin = scale(av.forward, -2); p.kick_angles[0] = -2;
|
| 464 |
+
const start = projectSource(p, [0, 8, p.viewheight - 8], av.forward, av.right);
|
| 465 |
+
Q.fireShotgun(g, 1, start, av.forward, 4, 8, 500, 500, 12, 'shotgun');
|
| 466 |
+
p.gunframe++; Q.playerNoise(g, start, 'weapon'); muzzle(g, p, 'shotgun'); p.inv.shells--;
|
| 467 |
+
},
|
| 468 |
+
supershotgun(g, p) {
|
| 469 |
+
const av = Q.angleVectors(p.v_angle);
|
| 470 |
+
p.kick_origin = scale(av.forward, -2); p.kick_angles[0] = -2;
|
| 471 |
+
const start = projectSource(p, [0, 8, p.viewheight - 8], av.forward, av.right);
|
| 472 |
+
let f = Q.angleVectors([p.v_angle[0], p.v_angle[1] - 5, p.v_angle[2]]).forward;
|
| 473 |
+
Q.fireShotgun(g, 1, start, f, 6, 12, 1000, 500, 10, 'sshotgun');
|
| 474 |
+
f = Q.angleVectors([p.v_angle[0], p.v_angle[1] + 5, p.v_angle[2]]).forward;
|
| 475 |
+
Q.fireShotgun(g, 1, start, f, 6, 12, 1000, 500, 10, 'sshotgun');
|
| 476 |
+
p.gunframe++; Q.playerNoise(g, start, 'weapon'); muzzle(g, p, 'supershotgun'); p.inv.shells -= 2;
|
| 477 |
+
},
|
| 478 |
+
rocket(g, p) {
|
| 479 |
+
const damage = 100 + Math.trunc(Q.random(g) * 20.0);
|
| 480 |
+
const av = Q.angleVectors(p.v_angle);
|
| 481 |
+
p.kick_origin = scale(av.forward, -2); p.kick_angles[0] = -1;
|
| 482 |
+
const start = projectSource(p, [8, 8, p.viewheight - 8], av.forward, av.right);
|
| 483 |
+
Q.fireRocket(g, 1, start, av.forward, damage, 650, 120, 120);
|
| 484 |
+
p.gunframe++; Q.playerNoise(g, start, 'weapon'); muzzle(g, p, 'rocketlauncher'); p.inv.rockets--;
|
| 485 |
+
},
|
| 486 |
+
railgun(g, p) {
|
| 487 |
+
const av = Q.angleVectors(p.v_angle);
|
| 488 |
+
p.kick_origin = scale(av.forward, -3); p.kick_angles[0] = -3;
|
| 489 |
+
const start = projectSource(p, [0, 7, p.viewheight - 8], av.forward, av.right);
|
| 490 |
+
Q.fireRail(g, 1, start, av.forward, 150, 250);
|
| 491 |
+
p.gunframe++; Q.playerNoise(g, start, 'weapon'); muzzle(g, p, 'railgun'); p.inv.slugs--;
|
| 492 |
+
},
|
| 493 |
+
};
|
| 494 |
+
function blasterFire(g, p, g_offset, damage, hyper, effect) {
|
| 495 |
+
const av = Q.angleVectors(p.v_angle);
|
| 496 |
+
const start = projectSource(p, add([24, 8, p.viewheight - 8], g_offset), av.forward, av.right);
|
| 497 |
+
p.kick_origin = scale(av.forward, -2); p.kick_angles[0] = -1;
|
| 498 |
+
Q.fireBlaster(g, 1, start, av.forward, damage, 1000, effect, hyper);
|
| 499 |
+
Q.playerNoise(g, start, 'weapon'); muzzle(g, p, hyper ? 'hyperblaster' : 'blaster');
|
| 500 |
+
}
|
| 501 |
+
function muzzle(g, p, weapon) { p.fired = g.ms; p.firedWeapon = weapon; }
|
| 502 |
+
|
| 503 |
+
// ---------------- hitscan and projectiles (g_weapon.c) ----------------
|
| 504 |
+
// check_dodge: skill 0 skips three out of four checks; no monster here has a dodge function.
|
| 505 |
+
function checkDodge(g, self) { if (g.skill === 0 && Q.random(g) > 0.25) return; }
|
| 506 |
+
function fireLead(g, self, start, aimdir, damage, kick, hspread, vspread, mod) {
|
| 507 |
+
const se = g.ents[self];
|
| 508 |
+
let tr = Q.trace(g, se.origin, null, null, start, self, Q.MASK_SHOT);
|
| 509 |
+
let end = null;
|
| 510 |
+
if (!(tr.fraction < 1.0)) {
|
| 511 |
+
const av = Q.angleVectors(Q.vectoangles(aimdir));
|
| 512 |
+
const r = Q.crandom(g) * hspread, u = Q.crandom(g) * vspread;
|
| 513 |
+
end = ma(ma(ma(start, 8192, av.forward), r, av.right), u, av.up);
|
| 514 |
+
tr = Q.trace(g, start, null, null, end, self, Q.MASK_SHOT);
|
| 515 |
+
}
|
| 516 |
+
if (tr.fraction < 1.0 && !tr.sky) {
|
| 517 |
+
const hit = g.ents[tr.ent];
|
| 518 |
+
if (tr.ent > 0 && hit.takedamage) Q.damage(g, tr.ent, self, self, aimdir, tr.endpos, tr.normal, damage, kick, Q.DAMAGE_BULLET, mod);
|
| 519 |
+
else { Q.fx(g, 'puff', tr.endpos, tr.normal); if (g.ents[self].client) Q.playerNoise(g, tr.endpos, 'impact'); }
|
| 520 |
+
}
|
| 521 |
+
Q.fx(g, 'tracer', start, null, { to: tr.endpos, from: self === 1 ? 'player' : 'monster' });
|
| 522 |
+
}
|
| 523 |
+
Q.fireBullet = (g, self, start, aimdir, damage, kick, hspread, vspread, mod) => fireLead(g, self, start, aimdir, damage, kick, hspread, vspread, mod);
|
| 524 |
+
Q.fireShotgun = (g, self, start, aimdir, damage, kick, hspread, vspread, count, mod) => { for (let i = 0; i < count; i++) fireLead(g, self, start, aimdir, damage, kick, hspread, vspread, mod); };
|
| 525 |
+
Q.fireBlaster = (g, self, start, dir, damage, speed, effect, hyper) => {
|
| 526 |
+
dir = norm(dir);
|
| 527 |
+
const i = Q.spawn(g), b = g.ents[i];
|
| 528 |
+
Object.assign(b, { classname: 'bolt', svflags: Q.SVF_DEADMONSTER, origin: copy3(start), old_origin: copy3(start), angles: Q.vectoangles(dir), velocity: scale(dir, speed),
|
| 529 |
+
movetype: 'flymissile', clipmask: Q.MASK_SHOT, solid: Q.SOLID_BBOX, effect, owner: self, touch: 'blaster_touch', nextthink: g.ms + 2000, think: 'G_FreeEdict', dmg: damage, spawnflags: hyper ? 1 : 0 });
|
| 530 |
+
if (g.ents[self].client) checkDodge(g, self);
|
| 531 |
+
const tr = Q.trace(g, g.ents[self].origin, null, null, b.origin, i, Q.MASK_SHOT);
|
| 532 |
+
if (tr.fraction < 1.0) { b.origin = ma(b.origin, -10, dir); Q.TOUCH.blaster_touch(g, i, tr.ent, null); }
|
| 533 |
+
};
|
| 534 |
+
Q.TOUCH.blaster_touch = (g, i, other, plane, sky) => {
|
| 535 |
+
const b = g.ents[i];
|
| 536 |
+
if (other === b.owner) return;
|
| 537 |
+
if (sky) { Q.freeEdict(g, i); return; }
|
| 538 |
+
if (g.ents[b.owner] && g.ents[b.owner].client) Q.playerNoise(g, b.origin, 'impact');
|
| 539 |
+
const o = g.ents[other];
|
| 540 |
+
if (other > 0 && o.takedamage) Q.damage(g, other, i, b.owner, b.velocity, b.origin, plane || [0, 0, 0], b.dmg, 1, Q.DAMAGE_ENERGY, b.spawnflags & 1 ? 'hyperblaster' : 'blaster');
|
| 541 |
+
else Q.fx(g, 'blasterhit', b.origin, plane);
|
| 542 |
+
Q.freeEdict(g, i);
|
| 543 |
+
};
|
| 544 |
+
Q.fireRocket = (g, self, start, dir, damage, speed, damage_radius, radius_damage) => {
|
| 545 |
+
const i = Q.spawn(g), r = g.ents[i];
|
| 546 |
+
Object.assign(r, { classname: 'rocket', origin: copy3(start), old_origin: copy3(start), movedir: copy3(dir), angles: Q.vectoangles(dir), velocity: scale(dir, speed),
|
| 547 |
+
movetype: 'flymissile', clipmask: Q.MASK_SHOT, solid: Q.SOLID_BBOX, effect: 'rocket', owner: self, touch: 'rocket_touch', nextthink: g.ms + 8000000 / speed, think: 'G_FreeEdict',
|
| 548 |
+
dmg: damage, radius_dmg: radius_damage, dmg_radius: damage_radius });
|
| 549 |
+
if (g.ents[self].client) checkDodge(g, self);
|
| 550 |
+
};
|
| 551 |
+
Q.TOUCH.rocket_touch = (g, i, other, plane, sky) => {
|
| 552 |
+
const r = g.ents[i];
|
| 553 |
+
if (other === r.owner) return;
|
| 554 |
+
if (sky) { Q.freeEdict(g, i); return; }
|
| 555 |
+
if (g.ents[r.owner] && g.ents[r.owner].client) Q.playerNoise(g, r.origin, 'impact');
|
| 556 |
+
const o = g.ents[other];
|
| 557 |
+
if (other > 0 && o.takedamage) Q.damage(g, other, i, r.owner, r.velocity, r.origin, plane || [0, 0, 0], r.dmg, 0, 0, 'rocket');
|
| 558 |
+
else if (other === 0) { let n = Q.rand(g) % 5; while (n--) Q.throwDebris(g, i, 2, r.origin); } // single player only
|
| 559 |
+
Q.radiusDamage(g, i, r.owner, r.radius_dmg, other, r.dmg_radius, 'r_splash');
|
| 560 |
+
Q.fx(g, 'explosion', ma(r.origin, -0.02, r.velocity), null, { big: r.dmg > 60 });
|
| 561 |
+
Q.freeEdict(g, i);
|
| 562 |
+
};
|
| 563 |
+
Q.fireRail = (g, self, start, aimdir, damage, kick) => {
|
| 564 |
+
const end = ma(start, 8192, aimdir);
|
| 565 |
+
let from = copy3(start), ignore = self, tr = null;
|
| 566 |
+
const mask = Q.MASK_SHOT;
|
| 567 |
+
let guard = 0;
|
| 568 |
+
while (ignore >= 0 && guard++ < 16) {
|
| 569 |
+
tr = Q.trace(g, from, null, null, end, ignore, mask);
|
| 570 |
+
const hit = g.ents[tr.ent];
|
| 571 |
+
if (tr.ent > 0 && (hit.svflags & Q.SVF_MONSTER || hit.client)) ignore = tr.ent; else ignore = -1;
|
| 572 |
+
if (tr.ent !== self && tr.ent > 0 && hit.takedamage) Q.damage(g, tr.ent, self, self, aimdir, tr.endpos, tr.normal, damage, kick, 0, 'railgun');
|
| 573 |
+
from = copy3(tr.endpos);
|
| 574 |
+
if (tr.fraction === 1) break;
|
| 575 |
+
}
|
| 576 |
+
if (g.ents[self].client) Q.playerNoise(g, tr.endpos, 'impact');
|
| 577 |
+
Q.fx(g, 'rail', start, null, { to: tr.endpos, from: self === 1 ? 'player' : 'monster' });
|
| 578 |
+
};
|
| 579 |
+
Q.fireBFG = (g, self, start, dir, damage, speed, damage_radius) => {
|
| 580 |
+
const i = Q.spawn(g), b = g.ents[i];
|
| 581 |
+
Object.assign(b, { classname: 'bfg blast', origin: copy3(start), old_origin: copy3(start), movedir: copy3(dir), angles: Q.vectoangles(dir), velocity: scale(dir, speed),
|
| 582 |
+
movetype: 'flymissile', clipmask: Q.MASK_SHOT, solid: Q.SOLID_BBOX, effect: 'bfg', owner: self, touch: 'bfg_touch', radius_dmg: damage, dmg_radius: damage_radius,
|
| 583 |
+
think: 'bfg_think', nextthink: g.ms + Q.FRAMETIME_MS, lasers: [] });
|
| 584 |
+
if (g.ents[self].client) checkDodge(g, self);
|
| 585 |
+
};
|
| 586 |
+
Q.TOUCH.bfg_touch = (g, i, other, plane, sky) => {
|
| 587 |
+
const b = g.ents[i];
|
| 588 |
+
if (other === b.owner) return;
|
| 589 |
+
if (sky) { Q.freeEdict(g, i); return; }
|
| 590 |
+
const o = g.ents[other];
|
| 591 |
+
if (other > 0 && o.takedamage) Q.damage(g, other, i, b.owner, b.velocity, b.origin, plane || [0, 0, 0], 200, 0, 0, 'bfg_blast');
|
| 592 |
+
Q.radiusDamage(g, i, b.owner, 200, other, 100, 'bfg_blast');
|
| 593 |
+
b.solid = Q.SOLID_NOT; b.touch = null;
|
| 594 |
+
b.origin = ma(b.origin, -0.1, b.velocity); b.velocity = [0, 0, 0];
|
| 595 |
+
b.effect = 'bfgexplode'; b.frame = 0; b.think = 'bfg_explode'; b.nextthink = g.ms + Q.FRAMETIME_MS; b.enemy = other; b.lasers = [];
|
| 596 |
+
Q.fx(g, 'bfgblast', b.origin);
|
| 597 |
+
};
|
| 598 |
+
Q.THINK.bfg_explode = (g, i) => {
|
| 599 |
+
const b = g.ents[i];
|
| 600 |
+
if (b.frame === 0) {
|
| 601 |
+
for (const k of Q.findradius(g, b.origin, b.dmg_radius)) {
|
| 602 |
+
const e = g.ents[k];
|
| 603 |
+
if (!e.takedamage || k === b.owner) continue;
|
| 604 |
+
if (!Q.canDamage(g, k, i) || !Q.canDamage(g, k, b.owner)) continue;
|
| 605 |
+
const dist = len(sub(b.origin, Q.center(e)));
|
| 606 |
+
const points = b.radius_dmg * (1.0 - Math.sqrt(dist / b.dmg_radius));
|
| 607 |
+
Q.damage(g, k, i, b.owner, b.velocity, e.origin, [0, 0, 0], Math.trunc(points), 0, Q.DAMAGE_ENERGY, 'bfg_effect');
|
| 608 |
+
}
|
| 609 |
+
}
|
| 610 |
+
b.nextthink = g.ms + Q.FRAMETIME_MS; b.frame++;
|
| 611 |
+
if (b.frame === 5) b.think = 'G_FreeEdict';
|
| 612 |
+
};
|
| 613 |
+
Q.THINK.bfg_think = (g, i) => {
|
| 614 |
+
const b = g.ents[i], dmg = 10;
|
| 615 |
+
b.lasers = [];
|
| 616 |
+
for (const k of Q.findradius(g, b.origin, 256)) {
|
| 617 |
+
const e = g.ents[k];
|
| 618 |
+
if (k === i || k === b.owner || !e.takedamage) continue;
|
| 619 |
+
if (!(e.svflags & Q.SVF_MONSTER) && !e.client) continue;
|
| 620 |
+
const point = Q.center(e), dir = norm(sub(point, b.origin));
|
| 621 |
+
let ignore = i, start = copy3(b.origin), end = ma(start, 2048, dir), tr = null, guard = 0;
|
| 622 |
+
while (guard++ < 8) {
|
| 623 |
+
tr = Q.trace(g, start, null, null, end, ignore, Q.CONTENTS_SOLID | Q.CONTENTS_MONSTER | Q.CONTENTS_DEADMONSTER);
|
| 624 |
+
if (tr.fraction === 1 && tr.ent === 0) break;
|
| 625 |
+
const h = g.ents[tr.ent];
|
| 626 |
+
if (tr.ent > 0 && h.takedamage && !(h.flags & Q.FL_IMMUNE_LASER) && tr.ent !== b.owner) Q.damage(g, tr.ent, i, b.owner, dir, tr.endpos, [0, 0, 0], dmg, 1, Q.DAMAGE_ENERGY, 'bfg_laser');
|
| 627 |
+
if (tr.ent <= 0 || (!(h.svflags & Q.SVF_MONSTER) && !h.client)) break;
|
| 628 |
+
ignore = tr.ent; start = copy3(tr.endpos);
|
| 629 |
+
}
|
| 630 |
+
b.lasers.push(tr.endpos);
|
| 631 |
+
}
|
| 632 |
+
b.nextthink = g.ms + Q.FRAMETIME_MS;
|
| 633 |
+
};
|
| 634 |
+
// SV_Physics_Toss for MOVETYPE_FLYMISSILE (no gravity), MOVETYPE_TOSS and MOVETYPE_BOUNCE (gibs, debris).
|
| 635 |
+
Q.physicsToss = (g, i) => {
|
| 636 |
+
Q.runThink(g, i);
|
| 637 |
+
let e = g.ents[i];
|
| 638 |
+
if (!e.inuse) return;
|
| 639 |
+
if (e.velocity[2] > 0) e.groundentity = -1;
|
| 640 |
+
if (e.groundentity >= 0) return;
|
| 641 |
+
for (let k = 0; k < 3; k++) e.velocity[k] = Math.max(-Q.SV_MAXVELOCITY, Math.min(Q.SV_MAXVELOCITY, e.velocity[k]));
|
| 642 |
+
const ft = g.dt; // 60 Hz host frame (q2-arena@3)
|
| 643 |
+
if (e.movetype !== 'flymissile') e.velocity[2] -= e.gravity * Q.SV_GRAVITY * ft;
|
| 644 |
+
e.angles = add(e.angles, scale(e.avelocity, ft));
|
| 645 |
+
const move = scale(e.velocity, ft);
|
| 646 |
+
const start = copy3(e.origin), end = add(start, move);
|
| 647 |
+
for (let retry = 0; retry < 2; retry++) {
|
| 648 |
+
const tr = Q.trace(g, start, e.mins, e.maxs, end, i, e.clipmask || Q.MASK_SOLID);
|
| 649 |
+
e.origin = copy3(tr.endpos);
|
| 650 |
+
if (tr.fraction !== 1.0) {
|
| 651 |
+
impact(g, i, tr);
|
| 652 |
+
if (!g.ents[i].inuse) return;
|
| 653 |
+
e = g.ents[i];
|
| 654 |
+
if (tr.ent > 0 && !g.ents[tr.ent].inuse) { e.origin = copy3(start); continue; }
|
| 655 |
+
e.velocity = clipVelocity(e.velocity, tr.normal, e.movetype === 'bounce' ? 1.5 : 1);
|
| 656 |
+
if (tr.normal[2] > 0.7 && (e.velocity[2] < 60 || e.movetype !== 'bounce')) { e.groundentity = tr.ent; e.velocity = [0, 0, 0]; e.avelocity = [0, 0, 0]; }
|
| 657 |
+
}
|
| 658 |
+
break;
|
| 659 |
+
}
|
| 660 |
+
};
|
| 661 |
+
// g_misc.c ThrowGib / ThrowHead / ThrowDebris: real edicts (they hold slots and draw the same rand() calls).
|
| 662 |
+
function velocityForDamage(g, damage) {
|
| 663 |
+
const v = [100.0 * Q.crandom(g), 100.0 * Q.crandom(g), 200.0 + 100.0 * Q.random(g)];
|
| 664 |
+
return scale(v, damage < 50 ? 0.7 : 1.2);
|
| 665 |
+
}
|
| 666 |
+
const clipGibVelocity = v => [Math.max(-300, Math.min(300, v[0])), Math.max(-300, Math.min(300, v[1])), Math.max(200, Math.min(500, v[2]))];
|
| 667 |
+
Q.throwGib = (g, self, kind, damage, organic) => {
|
| 668 |
+
const s = g.ents[self], size = scale(sub(s.maxs, s.mins), 0.5), base = add(Q.absmin(s), size);
|
| 669 |
+
const i = Q.spawn(g), e = g.ents[i];
|
| 670 |
+
e.classname = 'gib'; e.gib = kind;
|
| 671 |
+
e.origin = [base[0] + Q.crandom(g) * size[0], base[1] + Q.crandom(g) * size[1], base[2] + Q.crandom(g) * size[2]];
|
| 672 |
+
e.old_origin = copy3(e.origin);
|
| 673 |
+
Object.assign(e, { solid: Q.SOLID_NOT, flags: Q.FL_NO_KNOCKBACK, takedamage: Q.DAMAGE_YES, movetype: organic ? 'toss' : 'bounce', touch: organic ? 'gib_touch' : null });
|
| 674 |
+
e.velocity = clipGibVelocity(ma(s.velocity, organic ? 0.5 : 1.0, velocityForDamage(g, damage)));
|
| 675 |
+
e.avelocity = [Q.random(g) * 600, Q.random(g) * 600, Q.random(g) * 600];
|
| 676 |
+
e.think = 'G_FreeEdict'; e.nextthink = g.ms + 10000 + Q.random(g) * 10000;
|
| 677 |
+
};
|
| 678 |
+
Q.throwHead = (g, self, kind, damage, organic) => {
|
| 679 |
+
const e = g.ents[self];
|
| 680 |
+
Object.assign(e, { skinnum: 0, frame: 0, mins: [0, 0, 0], maxs: [0, 0, 0], solid: Q.SOLID_NOT, flags: e.flags | Q.FL_NO_KNOCKBACK, takedamage: Q.DAMAGE_YES,
|
| 681 |
+
movetype: organic ? 'toss' : 'bounce', touch: organic ? 'gib_touch' : null, classname: 'gib', gib: kind, head: true });
|
| 682 |
+
e.svflags &= ~Q.SVF_MONSTER;
|
| 683 |
+
e.velocity = clipGibVelocity(ma(e.velocity, organic ? 0.5 : 1.0, velocityForDamage(g, damage)));
|
| 684 |
+
e.avelocity = [0, Q.crandom(g) * 600, 0];
|
| 685 |
+
e.think = 'G_FreeEdict'; e.nextthink = g.ms + 10000 + Q.random(g) * 10000;
|
| 686 |
+
};
|
| 687 |
+
Q.TOUCH.gib_touch = (g, i) => { const e = g.ents[i]; if (e.groundentity < 0) return; e.touch = null; };
|
| 688 |
+
Q.throwDebris = (g, self, speed, origin) => {
|
| 689 |
+
const s = g.ents[self], i = Q.spawn(g), e = g.ents[i];
|
| 690 |
+
const v = [100 * Q.crandom(g), 100 * Q.crandom(g), 100 + 100 * Q.crandom(g)];
|
| 691 |
+
Object.assign(e, { classname: 'debris', origin: copy3(origin), old_origin: copy3(origin), velocity: ma(s.velocity, speed, v), movetype: 'bounce', solid: Q.SOLID_NOT, takedamage: Q.DAMAGE_YES });
|
| 692 |
+
e.avelocity = [Q.random(g) * 600, Q.random(g) * 600, Q.random(g) * 600];
|
| 693 |
+
e.think = 'G_FreeEdict'; e.nextthink = g.ms + 5000 + Q.random(g) * 5000; e.flags = 0;
|
| 694 |
+
};
|
| 695 |
+
function impact(g, i, tr) { // SV_Impact
|
| 696 |
+
const e1 = g.ents[i], e2 = g.ents[tr.ent];
|
| 697 |
+
if (e1.touch && e1.solid !== Q.SOLID_NOT) Q.TOUCH[e1.touch](g, i, tr.ent, tr.normal, tr.sky);
|
| 698 |
+
if (tr.ent > 0 && e2.inuse && e2.touch && e2.solid !== Q.SOLID_NOT && g.ents[i].inuse) Q.TOUCH[e2.touch](g, tr.ent, i, null, false);
|
| 699 |
+
}
|
| 700 |
+
Q.impact = impact;
|
| 701 |
+
|
| 702 |
+
// ---------------- damage (g_combat.c) ----------------
|
| 703 |
+
Q.canDamage = (g, targ, inflictor) => {
|
| 704 |
+
const t = g.ents[targ], from = g.ents[inflictor].origin;
|
| 705 |
+
const test = d => Q.trace(g, from, null, null, d, inflictor, Q.MASK_SOLID).fraction === 1.0;
|
| 706 |
+
if (test(t.origin)) return true;
|
| 707 |
+
for (const [dx, dy] of [[15, 15], [15, -15], [-15, 15], [-15, -15]]) if (test([t.origin[0] + dx, t.origin[1] + dy, t.origin[2]])) return true;
|
| 708 |
+
return false;
|
| 709 |
+
};
|
| 710 |
+
function checkArmor(g, ent, damage, dflags) {
|
| 711 |
+
if (!damage || !ent.client || (dflags & Q.DAMAGE_NO_ARMOR)) return 0;
|
| 712 |
+
const a = Q.armorIndex(ent);
|
| 713 |
+
if (!a) return 0;
|
| 714 |
+
let save = Math.ceil(((dflags & Q.DAMAGE_ENERGY) ? ARMOR[a][3] : ARMOR[a][2]) * damage);
|
| 715 |
+
if (save >= ent.inv[a]) save = ent.inv[a];
|
| 716 |
+
if (!save) return 0;
|
| 717 |
+
ent.inv[a] -= save;
|
| 718 |
+
return save;
|
| 719 |
+
}
|
| 720 |
+
Q.damage = (g, targ, inflictor, attacker, dir, point, normal, damage, knockback, dflags, mod) => {
|
| 721 |
+
const t = g.ents[targ];
|
| 722 |
+
if (!t.takedamage) return;
|
| 723 |
+
if (g.skill === 0 && t.client) { damage = Math.trunc(damage * 0.5); if (!damage) damage = 1; } // easy mode takes half damage
|
| 724 |
+
dir = norm(dir);
|
| 725 |
+
const a = g.ents[attacker];
|
| 726 |
+
if (!(dflags & Q.DAMAGE_RADIUS) && (t.svflags & Q.SVF_MONSTER) && a && a.client && t.enemy < 0 && t.health > 0) damage *= 2;
|
| 727 |
+
if (t.flags & Q.FL_NO_KNOCKBACK) knockback = 0;
|
| 728 |
+
if (!(dflags & Q.DAMAGE_NO_KNOCKBACK) && knockback && t.movetype !== 'none') {
|
| 729 |
+
const mass = t.mass < 50 ? 50 : t.mass;
|
| 730 |
+
const kvel = scale(dir, (t.client && attacker === targ ? 1600.0 : 500.0) * knockback / mass);
|
| 731 |
+
t.velocity = add(t.velocity, kvel);
|
| 732 |
+
}
|
| 733 |
+
let take = damage;
|
| 734 |
+
const asave = checkArmor(g, t, take, dflags); // no power armor, god mode or invulnerability in these arenas
|
| 735 |
+
take -= asave;
|
| 736 |
+
if (asave) Q.fx(g, 'spark', point, normal);
|
| 737 |
+
g.damageLog.push([targ, attacker, take, asave, mod]);
|
| 738 |
+
if (take) {
|
| 739 |
+
Q.fx(g, (t.svflags & Q.SVF_MONSTER) || t.client ? 'blood' : 'spark', point, normal);
|
| 740 |
+
t.health -= take;
|
| 741 |
+
if (t.health <= 0) {
|
| 742 |
+
if ((t.svflags & Q.SVF_MONSTER) || t.client) t.flags |= Q.FL_NO_KNOCKBACK;
|
| 743 |
+
killed(g, targ, inflictor, attacker, take, point);
|
| 744 |
+
return;
|
| 745 |
+
}
|
| 746 |
+
}
|
| 747 |
+
if (t.svflags & Q.SVF_MONSTER) {
|
| 748 |
+
Q.reactToDamage(g, targ, attacker);
|
| 749 |
+
// AI_DUCKED (the Mutant in mid-leap) suppresses the pain reaction
|
| 750 |
+
if (!(t.monsterinfo.aiflags & Q.AI_DUCKED) && take) { Q.monsterPain(g, targ, attacker, knockback, take); if (g.skill === 3) g.ents[targ].pain_debounce_time = g.ms + 5000; }
|
| 751 |
+
}
|
| 752 |
+
if (t.client) { t.damage_blood += take; t.damage_armor += asave; t.damage_knockback += knockback; t.damage_from = copy3(point); }
|
| 753 |
+
};
|
| 754 |
+
function killed(g, targ, inflictor, attacker, damage, point) {
|
| 755 |
+
const t = g.ents[targ];
|
| 756 |
+
if (t.health < -999) t.health = -999;
|
| 757 |
+
t.enemy = attacker;
|
| 758 |
+
if (t.client) { t.deadflag = Q.DEAD_DEAD; t.takedamage = Q.DAMAGE_NO; Q.event(g, 'player_die'); return; }
|
| 759 |
+
if ((t.svflags & Q.SVF_MONSTER) && t.deadflag !== Q.DEAD_DEAD) { t.touch = null; Q.monsterDeathUse(g, targ); }
|
| 760 |
+
Q.monsterDie(g, targ, inflictor, attacker, damage, point);
|
| 761 |
+
}
|
| 762 |
+
Q.radiusDamage = (g, inflictor, attacker, damage, ignore, radius, mod) => {
|
| 763 |
+
const inf = g.ents[inflictor];
|
| 764 |
+
for (const k of Q.findradius(g, inf.origin, radius)) {
|
| 765 |
+
if (k === ignore) continue;
|
| 766 |
+
const e = g.ents[k];
|
| 767 |
+
if (!e.takedamage) continue;
|
| 768 |
+
let points = damage - 0.5 * len(sub(inf.origin, Q.center(e)));
|
| 769 |
+
if (k === attacker) points *= 0.5;
|
| 770 |
+
if (points > 0 && Q.canDamage(g, k, inflictor)) {
|
| 771 |
+
const dir = sub(e.origin, inf.origin);
|
| 772 |
+
Q.damage(g, k, inflictor, attacker, dir, inf.origin, [0, 0, 0], Math.trunc(points), Math.trunc(points), Q.DAMAGE_RADIUS, mod);
|
| 773 |
+
}
|
| 774 |
+
}
|
| 775 |
+
};
|
| 776 |
+
|
| 777 |
+
// ---------------- items (Touch_Item) ----------------
|
| 778 |
+
Q.spawnItem = (g, type, origin) => {
|
| 779 |
+
const i = Q.spawn(g), e = g.ents[i];
|
| 780 |
+
Object.assign(e, { classname: type, item: type, origin: copy3(origin), mins: [-15, -15, -15], maxs: [15, 15, 15], solid: Q.SOLID_TRIGGER, touch: 'Touch_Item', movetype: 'toss', groundentity: 0 }); // droptofloor done
|
| 781 |
+
return i;
|
| 782 |
+
};
|
| 783 |
+
const PICKUP = {
|
| 784 |
+
health: (p) => healthPickup(p, 10, false), health_large: (p) => healthPickup(p, 25, false), stimpack: (p) => healthPickup(p, 2, true),
|
| 785 |
+
armor_shard: (p) => { const a = Q.armorIndex(p); if (!a) p.inv.jacket = 2; else p.inv[a] += 2; return true; },
|
| 786 |
+
armor_jacket: p => armorPickup(p, 'jacket'), armor_combat: p => armorPickup(p, 'combat'), armor_body: p => armorPickup(p, 'body'),
|
| 787 |
+
ammo_shells: p => ammoPickup(p, 'shells'), ammo_bullets: p => ammoPickup(p, 'bullets'), ammo_cells: p => ammoPickup(p, 'cells'),
|
| 788 |
+
ammo_rockets: p => ammoPickup(p, 'rockets'), ammo_slugs: p => ammoPickup(p, 'slugs'),
|
| 789 |
+
};
|
| 790 |
+
Q.PICKUP = PICKUP;
|
| 791 |
+
function healthPickup(p, count, ignoreMax) {
|
| 792 |
+
if (!ignoreMax && p.health >= p.max_health) return false;
|
| 793 |
+
p.health += count;
|
| 794 |
+
if (!ignoreMax && p.health > p.max_health) p.health = p.max_health;
|
| 795 |
+
return true;
|
| 796 |
+
}
|
| 797 |
+
function armorPickup(p, kind) { // Pickup_Armor with salvage
|
| 798 |
+
const old = Q.armorIndex(p), info = ARMOR[kind];
|
| 799 |
+
if (!old) { p.inv[kind] = info[0]; return true; }
|
| 800 |
+
const oldinfo = ARMOR[old];
|
| 801 |
+
if (info[2] > oldinfo[2]) {
|
| 802 |
+
const salvagecount = Math.trunc((oldinfo[2] / info[2]) * p.inv[old]);
|
| 803 |
+
let newcount = info[0] + salvagecount; if (newcount > info[1]) newcount = info[1];
|
| 804 |
+
p.inv[old] = 0; p.inv[kind] = newcount;
|
| 805 |
+
} else {
|
| 806 |
+
const salvagecount = Math.trunc((info[2] / oldinfo[2]) * info[0]);
|
| 807 |
+
let newcount = p.inv[old] + salvagecount; if (newcount > oldinfo[1]) newcount = oldinfo[1];
|
| 808 |
+
if (p.inv[old] >= newcount) return false;
|
| 809 |
+
p.inv[old] = newcount;
|
| 810 |
+
}
|
| 811 |
+
return true;
|
| 812 |
+
}
|
| 813 |
+
function ammoPickup(p, ammo) {
|
| 814 |
+
if (p.inv[ammo] === AMMO_MAX[ammo]) return false;
|
| 815 |
+
p.inv[ammo] = Math.min(AMMO_MAX[ammo], (p.inv[ammo] || 0) + AMMO_PICKUP[ammo]);
|
| 816 |
+
return true;
|
| 817 |
+
}
|
| 818 |
+
// Touch_Item. Health and armor are single-player items: taken once, then freed (G_FreeEdict), never respawned
|
| 819 |
+
// (q2-arena@4, 2026-11-07: a respawning medkit lets a player stand and trade hits with the boss). Ammo keeps the
|
| 820 |
+
// deathmatch timer (SetRespawn 30 s, original DoRespawn) so a three-minute fight cannot run out of rounds; ammo
|
| 821 |
+
// heals nothing. q2-arena@1-3 also respawned health (30 s) and armor (20 s).
|
| 822 |
+
const RESPAWN = { ammo_shells: 30, ammo_bullets: 30, ammo_cells: 30, ammo_rockets: 30, ammo_slugs: 30 };
|
| 823 |
+
Q.TOUCH.Touch_Item = (g, i, other) => {
|
| 824 |
+
const it = g.ents[i], p = g.ents[other];
|
| 825 |
+
if (!p.client || p.health < 1) return;
|
| 826 |
+
if (!PICKUP[it.item](p)) return;
|
| 827 |
+
p.bonus_alpha = 0.25; p.pickup = it.item; p.pickup_time = g.ms + 3000;
|
| 828 |
+
Q.event(g, 'pickup', { item: it.item });
|
| 829 |
+
if (!RESPAWN[it.item]) { Q.freeEdict(g, i); return; }
|
| 830 |
+
it.svflags |= Q.SVF_NOCLIENT; it.solid = Q.SOLID_NOT; it.nextthink = g.ms + RESPAWN[it.item] * 1000; it.think = 'DoRespawn';
|
| 831 |
+
};
|
| 832 |
+
Q.THINK.DoRespawn = (g, i) => { const it = g.ents[i]; it.svflags &= ~Q.SVF_NOCLIENT; it.solid = Q.SOLID_TRIGGER; Q.event(g, 'item_respawn', { item: it.item }); };
|
| 833 |
+
|
| 834 |
+
// ---------------- player trail (p_trail.c) ----------------
|
| 835 |
+
Q.playerTrailInit = g => { g.trail = { head: 0, spots: Array.from({ length: 8 }, () => ({ origin: [0, 0, 0], timestamp: 0, yaw: 0 })) }; };
|
| 836 |
+
Q.playerTrailAdd = (g, spot) => {
|
| 837 |
+
const tr = g.trail, prev = tr.spots[(tr.head - 1) & 7];
|
| 838 |
+
tr.spots[tr.head] = { origin: copy3(spot), timestamp: g.ms, yaw: Q.vectoyaw(sub(spot, prev.origin)) };
|
| 839 |
+
tr.head = (tr.head + 1) & 7;
|
| 840 |
+
};
|
| 841 |
+
Q.trailLastSpot = g => g.trail.spots[(g.trail.head - 1) & 7];
|
| 842 |
+
Q.trailPick = (g, self, first) => {
|
| 843 |
+
const tr = g.trail, mi = g.ents[self].monsterinfo;
|
| 844 |
+
let marker = tr.head;
|
| 845 |
+
for (let n = 8; n; n--) { if (tr.spots[marker].timestamp <= mi.trail_time) marker = (marker + 1) & 7; else break; }
|
| 846 |
+
if (!first) return tr.spots[marker];
|
| 847 |
+
if (Q.visiblePoint(g, self, tr.spots[marker].origin)) return tr.spots[marker];
|
| 848 |
+
const prev = tr.spots[(marker - 1) & 7];
|
| 849 |
+
if (Q.visiblePoint(g, self, prev.origin)) return prev;
|
| 850 |
+
return tr.spots[marker];
|
| 851 |
+
};
|
| 852 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/quake2_remake/renderer3d.js
ADDED
|
@@ -0,0 +1,503 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Quake II boss arenas - original procedural 3D art on Three.js r160 (MIT, shared read-only vendor copy in
|
| 2 |
+
web/games/_boss3d/vendor). First-person perspective from the player's eye with Quake II's 90 degree horizontal
|
| 3 |
+
field of view. Rendering is a pure function of the game state: it never writes the simulation and never draws
|
| 4 |
+
gameplay RNG; animation time comes from the state's tick counter. No Quake II models, skins or textures are used. */
|
| 5 |
+
(function (root) {
|
| 6 |
+
'use strict';
|
| 7 |
+
const T = root.THREE, M = root.Quake2Game, Q = M && M.Q;
|
| 8 |
+
if (!T) throw Error('Three.js is missing (web/games/_boss3d/vendor/three.min.js)');
|
| 9 |
+
const R = M.R3 = {};
|
| 10 |
+
const S = 1 / 32; // one Quake II unit = 1/32 scene unit
|
| 11 |
+
const byCanvas = new WeakMap();
|
| 12 |
+
const DEG = Math.PI / 180;
|
| 13 |
+
const qv = (x, y, z, out) => (out || new T.Vector3()).set(x * S, z * S, -y * S); // Quake (x fwd, y left, z up) -> three
|
| 14 |
+
function hash(x, y, s) { let n = Math.imul(x + 374761393 * s, 668265263) ^ Math.imul(y + s, 2246822519); n = Math.imul(n ^ (n >>> 13), 1274126177); return ((n ^ (n >>> 16)) >>> 0) / 4294967295; }
|
| 15 |
+
|
| 16 |
+
// ---------------- procedural textures (deterministic, generated once per scene) ----------------
|
| 17 |
+
function canvasTex(w, h, paint, opts = {}) {
|
| 18 |
+
const c = document.createElement('canvas'); c.width = w; c.height = h;
|
| 19 |
+
const q = c.getContext('2d'); paint(q, w, h);
|
| 20 |
+
const t = new T.CanvasTexture(c); t.colorSpace = T.SRGBColorSpace; t.wrapS = t.wrapT = T.RepeatWrapping; t.anisotropy = 2;
|
| 21 |
+
if (opts.nearest) { t.magFilter = T.NearestFilter; }
|
| 22 |
+
return t;
|
| 23 |
+
}
|
| 24 |
+
function noiseFill(q, w, h, base, amp, seed, grain = 1) {
|
| 25 |
+
const im = q.createImageData(w, h);
|
| 26 |
+
for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {
|
| 27 |
+
const n = (hash(Math.floor(x / grain), Math.floor(y / grain), seed) - 0.5) * amp + (hash(x >> 3, y >> 3, seed + 7) - 0.5) * amp * 0.6;
|
| 28 |
+
const i = (y * w + x) * 4; im.data[i] = base[0] + n; im.data[i + 1] = base[1] + n; im.data[i + 2] = base[2] + n * 0.9; im.data[i + 3] = 255;
|
| 29 |
+
}
|
| 30 |
+
q.putImageData(im, 0, 0);
|
| 31 |
+
}
|
| 32 |
+
const rivets = (q, xs, ys, col) => { q.fillStyle = col; for (const x of xs) for (const y of ys) { q.fillRect(x - 2, y - 2, 4, 4); } };
|
| 33 |
+
const PAINT = {
|
| 34 |
+
floor(q, w, h) { noiseFill(q, w, h, [74, 70, 62], 26, 3); q.strokeStyle = '#2b2925'; q.lineWidth = 3; for (let k = 0; k <= w; k += 64) { q.beginPath(); q.moveTo(k, 0); q.lineTo(k, h); q.stroke(); q.beginPath(); q.moveTo(0, k); q.lineTo(w, k); q.stroke(); }
|
| 35 |
+
q.strokeStyle = '#5c584e'; q.lineWidth = 1; for (let k = 8; k < w; k += 16) { q.beginPath(); q.moveTo(k, 0); q.lineTo(k, h); q.stroke(); } rivets(q, [6, 58, 70, 122, 134, 186, 198, 250], [6, 58, 70, 122, 134, 186, 198, 250], '#8e8778'); },
|
| 36 |
+
wall(q, w, h) { noiseFill(q, w, h, [96, 72, 52], 30, 11); q.fillStyle = '#3a2b20'; for (let y = 0; y < h; y += 64) q.fillRect(0, y, w, 5); q.fillStyle = '#6e5440';
|
| 37 |
+
for (let x = 0; x < w; x += 128) q.fillRect(x + 60, 0, 8, h); rivets(q, [12, 116, 140, 244], [14, 50, 78, 114, 142, 178, 206, 242], '#b29470'); q.fillStyle = 'rgba(40,24,12,.35)'; q.fillRect(0, h - 40, w, 40); },
|
| 38 |
+
crate(q, w, h) { noiseFill(q, w, h, [72, 82, 58], 22, 21); q.strokeStyle = '#3a4430'; q.lineWidth = 10; q.strokeRect(5, 5, w - 10, h - 10); q.lineWidth = 8; q.beginPath(); q.moveTo(10, 10); q.lineTo(w - 10, h - 10); q.moveTo(w - 10, 10); q.lineTo(10, h - 10); q.stroke();
|
| 39 |
+
q.fillStyle = '#c9b34a'; q.font = 'bold 34px monospace'; q.fillText('S-7', w * 0.36, h * 0.56); },
|
| 40 |
+
pylon(q, w, h) { noiseFill(q, w, h, [104, 100, 92], 24, 31); for (let x = -h; x < w; x += 40) { q.fillStyle = '#d9a722'; q.beginPath(); q.moveTo(x, h); q.lineTo(x + 20, h); q.lineTo(x + 60, h - 40); q.lineTo(x + 40, h - 40); q.fill(); }
|
| 41 |
+
q.fillStyle = '#2a2826'; q.fillRect(0, h - 44, w, 4); q.fillStyle = '#5b5852'; for (let y = 16; y < h - 50; y += 48) q.fillRect(0, y, w, 4); },
|
| 42 |
+
tech(q, w, h) { noiseFill(q, w, h, [46, 52, 58], 18, 41); q.fillStyle = '#1a1f24'; q.fillRect(20, 30, w - 40, 90); q.fillRect(20, 150, w - 40, 70);
|
| 43 |
+
for (let k = 0; k < 9; k++) { q.fillStyle = k % 3 ? '#2fa36b' : '#7be0a8'; q.fillRect(30 + k * 22, 44 + (k * 37 % 50), 14, 8); } q.fillStyle = '#d9a722'; q.fillRect(0, 0, w, 8); },
|
| 44 |
+
techGlow(q, w, h) { q.fillStyle = '#000'; q.fillRect(0, 0, w, h); for (let k = 0; k < 9; k++) { q.fillStyle = k % 3 ? '#1c7a4c' : '#5ce9a0'; q.fillRect(30 + k * 22, 44 + (k * 37 % 50), 14, 8); } q.fillStyle = '#123'; q.fillRect(20, 150, w - 40, 70); },
|
| 45 |
+
hangar(q, w, h) { noiseFill(q, w, h, [78, 86, 94], 20, 51); q.fillStyle = '#2f353b'; for (let y = 0; y < h; y += 128) q.fillRect(0, y, w, 6); for (let x = 0; x < w; x += 128) q.fillRect(x, 0, 6, h);
|
| 46 |
+
q.fillStyle = '#c99a2a'; q.fillRect(0, h - 26, w, 10); rivets(q, [16, 112, 144, 240], [16, 112, 144, 240], '#a9b3bb'); },
|
| 47 |
+
cargo(q, w, h) { noiseFill(q, w, h, [150, 78, 34], 22, 61); for (let x = 0; x < w; x += 16) { q.fillStyle = x % 32 ? 'rgba(0,0,0,.18)' : 'rgba(255,220,180,.08)'; q.fillRect(x, 0, 8, h); }
|
| 48 |
+
q.strokeStyle = '#4a2a14'; q.lineWidth = 8; q.strokeRect(4, 4, w - 8, h - 8); q.fillStyle = '#efe3c8'; q.font = 'bold 26px monospace'; q.fillText('CRG 4410', 40, 70); },
|
| 49 |
+
strogg(q, w, h) { noiseFill(q, w, h, [104, 66, 58], 30, 71); q.fillStyle = '#3e2420'; for (let y = 24; y < h; y += 64) q.fillRect(0, y, w, 10); q.fillStyle = '#a06a58';
|
| 50 |
+
for (let x = 16; x < w; x += 64) { q.fillRect(x, 0, 6, h); q.fillRect(x + 12, 0, 3, h); } rivets(q, [40, 104, 168, 232], [8, 72, 136, 200], '#b5806a'); },
|
| 51 |
+
pillar(q, w, h) { noiseFill(q, w, h, [92, 80, 78], 24, 81); q.fillStyle = '#3a3032'; for (let x = 0; x < w; x += 64) q.fillRect(x, 0, 10, h); q.fillStyle = '#ff7a1a'; for (let y = 40; y < h; y += 96) q.fillRect(0, y, w, 6); },
|
| 52 |
+
pillarGlow(q, w, h) { q.fillStyle = '#000'; q.fillRect(0, 0, w, h); q.fillStyle = '#ff6a10'; for (let y = 40; y < h; y += 96) q.fillRect(0, y, w, 6); },
|
| 53 |
+
dais(q, w, h) { noiseFill(q, w, h, [66, 58, 56], 22, 91); q.strokeStyle = '#a3241a'; q.lineWidth = 6; q.beginPath(); q.arc(w / 2, h / 2, w * 0.4, 0, Math.PI * 2); q.stroke(); q.lineWidth = 3; q.beginPath(); q.arc(w / 2, h / 2, w * 0.28, 0, Math.PI * 2); q.stroke();
|
| 54 |
+
for (let k = 0; k < 6; k++) { const a = k * Math.PI / 3; q.beginPath(); q.moveTo(w / 2 + Math.cos(a) * w * 0.28, h / 2 + Math.sin(a) * w * 0.28); q.lineTo(w / 2 + Math.cos(a) * w * 0.4, h / 2 + Math.sin(a) * w * 0.4); q.stroke(); } },
|
| 55 |
+
roof(q, w, h) { noiseFill(q, w, h, [40, 40, 44], 16, 101); q.fillStyle = '#1b1b1e'; for (let k = 0; k < w; k += 128) { q.fillRect(k, 0, 8, h); q.fillRect(0, k, w, 8); } q.fillStyle = '#e8dcb0'; q.fillRect(48, 48, 32, 32); q.fillRect(176, 176, 32, 32); },
|
| 56 |
+
roofGlow(q, w, h) { q.fillStyle = '#000'; q.fillRect(0, 0, w, h); q.fillStyle = '#c9b98a'; q.fillRect(48, 48, 32, 32); q.fillRect(176, 176, 32, 32); },
|
| 57 |
+
metal(q, w, h) { noiseFill(q, w, h, [92, 92, 96], 22, 111); q.fillStyle = '#3c3c40'; q.fillRect(0, h / 2 - 3, w, 6); rivets(q, [10, w - 10], [10, h - 10], '#b8b8bc'); },
|
| 58 |
+
factory(q, w, h) { noiseFill(q, w, h, [96, 92, 84], 24, 131); q.fillStyle = '#4a4640'; for (let y = 0; y < h; y += 64) q.fillRect(0, y, w, 6);
|
| 59 |
+
for (let x = 0; x < w; x += 128) { q.fillStyle = '#d9a722'; q.fillRect(x + 8, h - 30, 48, 10); q.fillStyle = '#2a2826'; q.fillRect(x + 56, h - 30, 48, 10); } rivets(q, [24, 104, 152, 232], [24, 88, 152, 216], '#c0b8a6'); },
|
| 60 |
+
machine(q, w, h) { noiseFill(q, w, h, [70, 84, 92], 20, 141); q.fillStyle = '#1e262c'; q.fillRect(24, 24, w - 48, h - 48); q.fillStyle = '#ff8a2a';
|
| 61 |
+
for (let k = 0; k < 6; k++) q.fillRect(40 + k * 30, 40, 18, 6); q.fillStyle = '#5ad0ff'; q.fillRect(40, h - 70, w - 80, 8); q.strokeStyle = '#9aa8b0'; q.lineWidth = 4; q.strokeRect(8, 8, w - 16, h - 16); },
|
| 62 |
+
machineGlow(q, w, h) { q.fillStyle = '#000'; q.fillRect(0, 0, w, h); q.fillStyle = '#ff8a2a'; for (let k = 0; k < 6; k++) q.fillRect(40 + k * 30, 40, 18, 6); q.fillStyle = '#5ad0ff'; q.fillRect(40, h - 70, w - 80, 8); },
|
| 63 |
+
arena(q, w, h) { noiseFill(q, w, h, [124, 104, 80], 26, 151); q.fillStyle = '#6a5440'; for (let y = 0; y < h; y += 48) { const o = (y / 48 % 2) * 64; for (let x = -64 + o; x < w; x += 128) q.fillRect(x, y, 4, 48); q.fillRect(0, y, w, 4); } },
|
| 64 |
+
column(q, w, h) { noiseFill(q, w, h, [150, 138, 120], 20, 161); q.fillStyle = 'rgba(60,44,30,.35)'; for (let x = 0; x < w; x += 32) q.fillRect(x, 0, 8, h); q.fillStyle = '#7a3020'; q.fillRect(0, 16, w, 10); q.fillRect(0, h - 26, w, 10); },
|
| 65 |
+
lab(q, w, h) { noiseFill(q, w, h, [176, 184, 176], 14, 171); q.fillStyle = '#7a8a86'; for (let y = 0; y < h; y += 64) q.fillRect(0, y, w, 3); for (let x = 0; x < w; x += 64) q.fillRect(x, 0, 3, h);
|
| 66 |
+
q.fillStyle = '#3a8a5a'; q.fillRect(0, h - 40, w, 14); q.fillStyle = '#d8d040'; for (let x = 0; x < w; x += 32) q.fillRect(x, h - 44, 16, 4); },
|
| 67 |
+
bench(q, w, h) { noiseFill(q, w, h, [130, 140, 146], 16, 181); q.fillStyle = '#3c464c'; q.fillRect(0, 0, w, 10); q.fillStyle = '#60c890'; for (let k = 0; k < 4; k++) q.fillRect(20 + k * 56, 30, 34, 20); },
|
| 68 |
+
flesh(q, w, h) { noiseFill(q, w, h, [120, 62, 58], 36, 121, 2); q.strokeStyle = 'rgba(60,20,20,.6)'; q.lineWidth = 3; for (let k = 0; k < 10; k++) { q.beginPath(); q.moveTo(hash(k, 1, 9) * w, 0); q.bezierCurveTo(hash(k, 2, 9) * w, h * 0.3, hash(k, 3, 9) * w, h * 0.7, hash(k, 4, 9) * w, h); q.stroke(); } },
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
// Box geometry with world-scaled UVs (one texture tile = 128 Quake units) so walls never stretch.
|
| 72 |
+
function brushGeometry(b) {
|
| 73 |
+
const [x0, y0, z0] = b.mins, [x1, y1, z1] = b.maxs, pos = [], uv = [], nor = [], idx = [];
|
| 74 |
+
const face = (corners, n, ua, va) => {
|
| 75 |
+
const base = pos.length / 3;
|
| 76 |
+
for (const c of corners) { const p = qv(c[0], c[1], c[2]); pos.push(p.x, p.y, p.z); uv.push(c[ua] / 128, c[va] / 128); nor.push(n.x, n.y, n.z); }
|
| 77 |
+
idx.push(base, base + 1, base + 2, base, base + 2, base + 3);
|
| 78 |
+
};
|
| 79 |
+
const N = (x, y, z) => qv(x / S, y / S, z / S).normalize();
|
| 80 |
+
face([[x0, y0, z1], [x1, y0, z1], [x1, y1, z1], [x0, y1, z1]], N(0, 0, 1), 0, 1); // top
|
| 81 |
+
face([[x0, y1, z0], [x1, y1, z0], [x1, y0, z0], [x0, y0, z0]], N(0, 0, -1), 0, 1); // bottom
|
| 82 |
+
face([[x0, y0, z0], [x1, y0, z0], [x1, y0, z1], [x0, y0, z1]], N(0, -1, 0), 0, 2); // -y
|
| 83 |
+
face([[x1, y1, z0], [x0, y1, z0], [x0, y1, z1], [x1, y1, z1]], N(0, 1, 0), 0, 2); // +y
|
| 84 |
+
face([[x0, y1, z0], [x0, y0, z0], [x0, y0, z1], [x0, y1, z1]], N(-1, 0, 0), 1, 2); // -x
|
| 85 |
+
face([[x1, y0, z0], [x1, y1, z0], [x1, y1, z1], [x1, y0, z1]], N(1, 0, 0), 1, 2); // +x
|
| 86 |
+
const geo = new T.BufferGeometry();
|
| 87 |
+
geo.setAttribute('position', new T.Float32BufferAttribute(pos, 3)); geo.setAttribute('uv', new T.Float32BufferAttribute(uv, 2));
|
| 88 |
+
geo.setAttribute('normal', new T.Float32BufferAttribute(nor, 3)); geo.setIndex(idx);
|
| 89 |
+
// Inward faces of the arena shell are what the camera sees; render both sides.
|
| 90 |
+
return geo;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// ---------------- the scene ----------------
|
| 94 |
+
const ARENA_STYLE = {
|
| 95 |
+
supertank: { fog: 0x2c2420, near: 900, far: 3400, hemi: [0xffd2a6, 0x3a2a20, 1.35], sun: [0xffb070, 1.6, [-0.5, 1, 0.35]], sky: ['#1c1424', '#5a2e3a', '#d0773a'], lamps: [] },
|
| 96 |
+
hornet: { fog: 0x161b20, near: 700, far: 3000, hemi: [0xb9cde0, 0x282624, 1.15], sun: null, sky: null, lamps: [[896, 900, 470, 0xfff2d2, 1.6, 2400], [300, 300, 300, 0xffb050, 1.0, 1200], [1500, 1500, 300, 0x9fd0ff, 1.0, 1200]] },
|
| 97 |
+
makron: { fog: 0x2a1a16, near: 1100, far: 3600, hemi: [0xffd0c0, 0x4a3028, 2.3], sun: null, sky: null, lamps: [[960, 960, 420, 0xff7a4a, 2.4, 2600], [560, 560, 300, 0xff9a50, 1.4, 1300], [1360, 1360, 300, 0xff9a50, 1.4, 1300], [560, 1360, 300, 0xffc890, 1.2, 1300], [1360, 560, 300, 0xffc890, 1.2, 1300]] },
|
| 98 |
+
tank_commander: { fog: 0x24201c, near: 1000, far: 3400, hemi: [0xffe2c0, 0x3a342c, 2.0], sun: null, sky: null, lamps: [[896, 896, 420, 0xffd8a0, 2.0, 2600], [480, 620, 300, 0xff9a40, 1.2, 1200], [1312, 620, 300, 0xff9a40, 1.2, 1200], [480, 1170, 300, 0x9ad0ff, 1.2, 1200], [1312, 1170, 300, 0x9ad0ff, 1.2, 1200]] },
|
| 99 |
+
gladiator: { fog: 0x3a2a22, near: 1200, far: 3400, hemi: [0xffd8b0, 0x4a3426, 1.5], sun: [0xffb070, 1.6, [0.4, 1, -0.3]], sky: ['#241828', '#6a3a3a', '#e08a4a'], lamps: [] },
|
| 100 |
+
mutant: { fog: 0x1e2624, near: 1100, far: 3400, hemi: [0xe0fff0, 0x2a3430, 1.9], sun: null, sky: null, lamps: [[960, 800, 360, 0xd8fff0, 2.0, 2400], [480, 400, 300, 0x8affc0, 1.0, 1200], [1440, 400, 300, 0x8affc0, 1.0, 1200], [480, 1200, 300, 0xfff0c0, 1.0, 1200], [1440, 1200, 300, 0xfff0c0, 1.0, 1200]] },
|
| 101 |
+
};
|
| 102 |
+
class Scene {
|
| 103 |
+
constructor(key, canvas) {
|
| 104 |
+
this.key = key; this.canvas = canvas; this.resources = []; this.times = []; this.ready = false; this.error = null; this.closed = false;
|
| 105 |
+
this.view = document.createElement('canvas'); this.view.width = 854; this.view.height = 480;
|
| 106 |
+
this.renderer = new T.WebGLRenderer({ canvas: this.view, antialias: true, preserveDrawingBuffer: true, powerPreference: 'low-power' });
|
| 107 |
+
this.renderer.setPixelRatio(1); this.renderer.setSize(854, 480, false); this.renderer.outputColorSpace = T.SRGBColorSpace;
|
| 108 |
+
this.renderer.toneMapping = T.ACESFilmicToneMapping; this.renderer.toneMappingExposure = 1.15; this.renderer.autoClear = false; this.renderer.info.autoReset = false;
|
| 109 |
+
this.view.addEventListener('webglcontextlost', e => { e.preventDefault(); this.ready = false; this.error = 'WebGL context lost'; });
|
| 110 |
+
const st = ARENA_STYLE[key];
|
| 111 |
+
this.world = new T.Scene(); this.world.fog = new T.Fog(st.fog, st.near * S, st.far * S);
|
| 112 |
+
this.world.background = st.sky ? this.keep(canvasTex(8, 256, (q, w, h) => { const gr = q.createLinearGradient(0, 0, 0, h); gr.addColorStop(0, st.sky[0]); gr.addColorStop(0.55, st.sky[1]); gr.addColorStop(1, st.sky[2]); q.fillStyle = gr; q.fillRect(0, 0, w, h); })) : new T.Color(st.fog);
|
| 113 |
+
// Quake II fov 90 is horizontal: vertical = 2*atan(tan(45)*480/854) = 58.7 degrees.
|
| 114 |
+
this.camera = new T.PerspectiveCamera(2 * Math.atan(Math.tan(45 * DEG) * 480 / 854) / DEG, 854 / 480, 2 * S, 6000 * S);
|
| 115 |
+
this.world.add(new T.HemisphereLight(st.hemi[0], st.hemi[1], st.hemi[2]));
|
| 116 |
+
if (st.sun) { const sun = new T.DirectionalLight(st.sun[0], st.sun[1]); sun.position.set(st.sun[2][0], st.sun[2][1], st.sun[2][2]); this.world.add(sun); }
|
| 117 |
+
for (const [x, y, z, c, i, d] of st.lamps) { const l = new T.PointLight(c, i, d * S, 1.2); qv(x, y, z, l.position); this.world.add(l); }
|
| 118 |
+
this.flashLight = new T.PointLight(0xffc070, 0, 500 * S, 1.5); this.world.add(this.flashLight);
|
| 119 |
+
this.boomLight = new T.PointLight(0xff8a30, 0, 600 * S, 1.4); this.world.add(this.boomLight);
|
| 120 |
+
this.tex = {}; this.mat = {};
|
| 121 |
+
const tex = name => this.tex[name] || (this.tex[name] = this.keep(canvasTex(256, 256, PAINT[name])));
|
| 122 |
+
const lam = (name, color = 0xffffff, glow) => { const m = new T.MeshLambertMaterial({ map: tex(name), color, side: T.DoubleSide }); if (glow) { m.emissive = new T.Color(0xffffff); m.emissiveMap = tex(glow); m.emissiveIntensity = 1.3; } return this.keep(m); };
|
| 123 |
+
this.mat.brush = { floor: lam('floor'), wall: lam('wall'), crate: lam('crate'), pylon: lam('pylon'), tech: lam('tech', 0xffffff, 'techGlow'), hangar: lam('hangar'), cargo: lam('cargo'),
|
| 124 |
+
strogg: lam('strogg'), pillar: lam('pillar', 0xffffff, 'pillarGlow'), dais: lam('dais'), roof: lam('roof', 0xffffff, 'roofGlow'), barrier: lam('pylon', 0xc8c4bc),
|
| 125 |
+
factory: lam('factory'), machine: lam('machine', 0xffffff, 'machineGlow'), arena: lam('arena'), column: lam('column'), lab: lam('lab'), bench: lam('bench') };
|
| 126 |
+
for (const b of Q.worlds[key].brushes) {
|
| 127 |
+
if (b.sky) continue;
|
| 128 |
+
const mesh = new T.Mesh(this.keep(brushGeometry(b)), this.mat.brush[b.mat] || this.mat.brush.wall);
|
| 129 |
+
this.world.add(mesh);
|
| 130 |
+
}
|
| 131 |
+
this.buildShared(); this.buildBosses(); this.buildWeapons();
|
| 132 |
+
}
|
| 133 |
+
keep(r) { this.resources.push(r); return r; }
|
| 134 |
+
std(color, opts = {}) { return this.keep(new T.MeshLambertMaterial(Object.assign({ color }, opts))); }
|
| 135 |
+
glow(color, opacity = 1) { return this.keep(new T.MeshBasicMaterial({ color, transparent: opacity < 1, opacity, depthWrite: opacity >= 1, blending: opacity < 1 ? T.AdditiveBlending : T.NormalBlending, fog: false })); }
|
| 136 |
+
buildShared() {
|
| 137 |
+
const G = this.geo = {
|
| 138 |
+
box: this.keep(new T.BoxGeometry(1, 1, 1)), sphere: this.keep(new T.SphereGeometry(1, 14, 10)), lowSphere: this.keep(new T.SphereGeometry(1, 8, 6)),
|
| 139 |
+
cyl: this.keep(new T.CylinderGeometry(1, 1, 1, 12)), cyl6: this.keep(new T.CylinderGeometry(1, 1, 1, 6)), cone: this.keep(new T.ConeGeometry(1, 1, 10)),
|
| 140 |
+
ico: this.keep(new T.IcosahedronGeometry(1, 0)), ring: this.keep(new T.TorusGeometry(1, 0.06, 6, 24)), plane: this.keep(new T.PlaneGeometry(1, 1)),
|
| 141 |
+
};
|
| 142 |
+
const pool = (n, make) => { const out = []; for (let k = 0; k < n; k++) { const o = make(); o.visible = false; this.world.add(o); out.push(o); } return out; };
|
| 143 |
+
this.mats = {
|
| 144 |
+
rocketBody: this.std(0x5b5f58), flame: this.glow(0xffa040, 0.9), smoke: this.keep(new T.MeshBasicMaterial({ color: 0x8a8580, transparent: true, opacity: 0.32, depthWrite: false })),
|
| 145 |
+
bolt: this.glow(0xffe060, 0.95), boltCore: this.glow(0xfff8d0), bfg: this.glow(0x5cff6a, 0.85), bfgCore: this.glow(0xe8ffe0), bfgHalo: this.keep(new T.MeshBasicMaterial({ color: 0x40ff60, transparent: true, opacity: 0.08, depthWrite: false, wireframe: true })),
|
| 146 |
+
boom: this.glow(0xff8a30, 0.8), boomCore: this.glow(0xfff0b0, 0.9), blood: this.keep(new T.MeshBasicMaterial({ color: 0x8a0d08, transparent: true, opacity: 0.8, depthWrite: false })),
|
| 147 |
+
puff: this.keep(new T.MeshBasicMaterial({ color: 0x9a948a, transparent: true, opacity: 0.6, depthWrite: false })), spark: this.glow(0xffd070, 0.9),
|
| 148 |
+
meat: this.std(0x7a1c16), gibMetal: this.std(0x6a6a70), debris: this.std(0x4a4440), mflash: this.glow(0xffd890, 0.95), warn: this.glow(0xff2a20, 0.65),
|
| 149 |
+
tracer: this.keep(new T.LineBasicMaterial({ color: 0xffe0a0, transparent: true, opacity: 0.55 })), railCore: this.keep(new T.LineBasicMaterial({ color: 0xe8f4ff, transparent: true, opacity: 0.9 })),
|
| 150 |
+
railSpiral: this.keep(new T.LineBasicMaterial({ color: 0x3a7cff, transparent: true, opacity: 0.9 })), laser: this.keep(new T.LineBasicMaterial({ color: 0x6aff70, transparent: true, opacity: 0.85 })),
|
| 151 |
+
aimLine: this.keep(new T.LineBasicMaterial({ color: 0xff3020, transparent: true, opacity: 0.85 })),
|
| 152 |
+
};
|
| 153 |
+
this.rockets = pool(24, () => { const g = new T.Group(); const body = new T.Mesh(G.cyl, this.mats.rocketBody); body.scale.set(2.2 * S, 18 * S, 2.2 * S); body.rotation.z = Math.PI / 2; g.add(body);
|
| 154 |
+
const fl = new T.Mesh(G.cone, this.mats.flame); fl.scale.set(3.4 * S, 14 * S, 3.4 * S); fl.rotation.z = Math.PI / 2; fl.position.x = -15 * S; g.add(fl);
|
| 155 |
+
for (let k = 0; k < 4; k++) { const sm = new T.Mesh(G.lowSphere, this.mats.smoke); sm.position.x = -(28 + k * 16) * S; sm.scale.setScalar((4 + k * 2.2) * S); g.add(sm); } return g; });
|
| 156 |
+
this.bolts = pool(48, () => { const g = new T.Group(); const a = new T.Mesh(G.sphere, this.mats.bolt); a.scale.set(16 * S, 3.2 * S, 3.2 * S); g.add(a); const c = new T.Mesh(G.sphere, this.mats.boltCore); c.scale.set(9 * S, 1.6 * S, 1.6 * S); g.add(c); return g; });
|
| 157 |
+
this.bfgs = pool(4, () => { const g = new T.Group(); const a = new T.Mesh(G.sphere, this.mats.bfg); a.scale.setScalar(14 * S); g.add(a); const c = new T.Mesh(G.sphere, this.mats.bfgCore); c.scale.setScalar(7 * S); g.add(c);
|
| 158 |
+
const h = new T.Mesh(G.lowSphere, this.mats.bfgHalo); h.scale.setScalar(256 * S); g.add(h); return g; });
|
| 159 |
+
this.booms = pool(24, () => { const g = new T.Group(); const a = new T.Mesh(G.ico, this.mats.boom); g.add(a); const c = new T.Mesh(G.sphere, this.mats.boomCore); c.scale.setScalar(0.5); g.add(c); return g; });
|
| 160 |
+
this.puffs = pool(64, () => new T.Mesh(G.lowSphere, this.mats.puff));
|
| 161 |
+
this.gibs = pool(40, () => new T.Mesh(G.ico, this.mats.meat));
|
| 162 |
+
this.flashes = pool(12, () => new T.Mesh(G.sphere, this.mats.mflash));
|
| 163 |
+
const lines = (n, mat, pts) => pool(n, () => { const geo = this.keep(new T.BufferGeometry()); geo.setAttribute('position', new T.BufferAttribute(new Float32Array(pts * 3), 3)); return new T.Line(geo, mat); });
|
| 164 |
+
this.tracers = lines(40, this.mats.tracer, 2); this.railCores = lines(6, this.mats.railCore, 2); this.railSpirals = lines(6, this.mats.railSpiral, 96);
|
| 165 |
+
this.lasers = lines(12, this.mats.laser, 2); this.aimLines = lines(2, this.mats.aimLine, 2);
|
| 166 |
+
this.items = {};
|
| 167 |
+
const itemMat = { health: this.std(0xe8e4dc), health_large: this.std(0xf2eee6), stimpack: this.std(0xd0f0ff), armor_shard: this.glow(0x4ae07a, 0.95), armor_jacket: this.std(0x6e7b4a),
|
| 168 |
+
armor_combat: this.std(0x8a8f96), armor_body: this.std(0xc0a246), ammo_shells: this.std(0xa0382a), ammo_bullets: this.std(0xb89a34), ammo_rockets: this.std(0x3c5a34), ammo_cells: this.std(0x3a6aa8), ammo_slugs: this.std(0x5a6a5a) };
|
| 169 |
+
this.itemMat = itemMat; this.crossMat = this.glow(0xd01818);
|
| 170 |
+
}
|
| 171 |
+
// ---------------- boss models (original silhouettes after the Quake II designs) ----------------
|
| 172 |
+
// Quake-local position (fwd, left, up) and sizes in units; rx rolls about forward, ry turns a vertical cylinder to
|
| 173 |
+
// point forward (three z), rz yaws about up.
|
| 174 |
+
part(parent, geo, mat, x, y, z, sx, sy, sz, rx = 0, ry = 0, rz = 0) {
|
| 175 |
+
const m = new T.Mesh(geo, mat); qv(x, y, z, m.position); m.scale.set(sx * S, sz * S, sy * S); m.rotation.set(rx, rz, ry); parent.add(m); return m;
|
| 176 |
+
}
|
| 177 |
+
group(parent, x = 0, y = 0, z = 0) { const g = new T.Group(); qv(x, y, z, g.position); parent.add(g); return g; }
|
| 178 |
+
buildBosses() {
|
| 179 |
+
const G = this.geo, P = this.part.bind(this);
|
| 180 |
+
const steel = this.std(0x9a9ea6), dark = this.std(0x4a4d52), rust = this.std(0xa06a44), olive = this.std(0x76844f), flesh = this.std(0xc07a62, { map: this.keep(canvasTex(128, 128, PAINT.flesh)) });
|
| 181 |
+
const red = this.glow(0xff3010), amber = this.glow(0xffa030), green = this.glow(0x60ff70), cyan = this.glow(0x60c8ff), purple = this.std(0x7a5a88);
|
| 182 |
+
this.bossMats = { steel, dark, rust, olive, flesh, red, amber, green, cyan };
|
| 183 |
+
this.models = {};
|
| 184 |
+
// Super Tank (boss1): tracked base, armoured hull, chaingun arm on the right, triple rocket pod on the left.
|
| 185 |
+
{ const root = new T.Group(), m = { root }; this.world.add(root);
|
| 186 |
+
for (const s of [1, -1]) { const tr = this.group(root, 0, s * 44, 0); P(tr, G.box, dark, 0, 0, 22, 132, 34, 44); for (let k = -2; k <= 2; k++) P(tr, G.cyl, steel, k * 26, 0, 18, 13, 13, 37, Math.PI / 2, 0, 0); m['tread' + (s > 0 ? 'L' : 'R')] = tr; }
|
| 187 |
+
const hull = this.group(root, 0, 0, 44); P(hull, G.box, olive, 0, 0, 16, 104, 80, 32); P(hull, G.box, steel, 46, 0, 10, 16, 70, 18); m.hull = hull;
|
| 188 |
+
const torso = this.group(hull, -6, 0, 32); P(torso, G.box, olive, 0, 0, 20, 66, 62, 40); P(torso, G.box, dark, 0, 0, 42, 40, 40, 8); P(torso, G.box, rust, 18, 0, 34, 20, 24, 18);
|
| 189 |
+
m.eye = P(torso, G.box, red, 29, 0, 36, 3, 14, 4); m.torso = torso;
|
| 190 |
+
const gun = this.group(torso, 30, -30, 12); P(gun, G.cyl, dark, 0, 0, 0, 16, 16, 30, 0, Math.PI / 2, 0); for (let k = 0; k < 6; k++) { const a = k * Math.PI / 3; P(gun, G.cyl6, steel, 26, Math.cos(a) * 4.5, Math.sin(a) * 4.5, 2.6, 2.6, 34, 0, Math.PI / 2, 0); } m.gun = gun;
|
| 191 |
+
const pod = this.group(torso, 12, 32, 18); P(pod, G.box, rust, 0, 0, 0, 30, 30, 22); for (let k = 0; k < 3; k++) P(pod, G.cyl, dark, 12, -10 + k * 10, 2, 6, 6, 20, 0, Math.PI / 2, 0); m.podGlow = P(pod, G.box, amber, 16, 0, 2, 2, 28, 10); m.pod = pod;
|
| 192 |
+
this.models.monster_supertank = m; }
|
| 193 |
+
// Hornet (boss2): flying insectoid gunship, two wing pairs, twin machinegun pods, rocket rack under the nose.
|
| 194 |
+
{ const root = new T.Group(), m = { root }; this.world.add(root);
|
| 195 |
+
const body = this.group(root, 0, 0, 40); P(body, G.sphere, rust, 0, 0, 0, 62, 34, 24); P(body, G.sphere, flesh, -40, 0, -4, 46, 26, 22); P(body, G.sphere, dark, 34, 0, 4, 26, 22, 18);
|
| 196 |
+
m.eyes = [P(body, G.sphere, red, 52, 8, 8, 4, 4, 4), P(body, G.sphere, red, 52, -8, 8, 4, 4, 4)];
|
| 197 |
+
for (const s of [1, -1]) { P(body, G.cyl, steel, 22, s * 40, 30, 7, 7, 34, 0, Math.PI / 2, 0); P(body, G.box, dark, 6, s * 30, 22, 24, 20, 10); }
|
| 198 |
+
for (let k = 0; k < 4; k++) P(body, G.cyl, dark, 22, [16, 8, -8, -16][k], -24, 4, 4, 22, 0, Math.PI / 2, 0);
|
| 199 |
+
m.wings = []; const wingMat = this.keep(new T.MeshLambertMaterial({ color: 0x9fb2a0, transparent: true, opacity: 0.55, side: T.DoubleSide }));
|
| 200 |
+
for (const s of [1, -1]) for (const f of [12, -18]) { const w = this.group(body, f, s * 22, 18); const blade = P(w, G.box, wingMat, 0, s * 44, 0, 34, 88, 1.5); m.wings.push({ w, s, f }); }
|
| 201 |
+
for (const s of [1, -1]) for (const f of [20, 0, -20]) P(body, G.cyl6, dark, f, s * 18, -26, 2.5, 2.5, 22, s * 0.4, 0, 0);
|
| 202 |
+
m.body = body; this.models.monster_boss2 = m; }
|
| 203 |
+
// Jorg (boss3 walker): huge bipedal mech with twin chainguns and the Makron rider on top.
|
| 204 |
+
{ const root = new T.Group(), m = { root }; this.world.add(root);
|
| 205 |
+
m.legs = [];
|
| 206 |
+
for (const s of [1, -1]) { const hip = this.group(root, -6, s * 46, 78); const thigh = P(hip, G.box, steel, 0, 0, -18, 34, 30, 44); const knee = this.group(hip, 0, 0, -38);
|
| 207 |
+
P(knee, G.box, dark, 8, 0, -16, 30, 26, 40); const foot = P(knee, G.box, steel, 14, 0, -38, 56, 36, 10); m.legs.push({ hip, knee, s }); }
|
| 208 |
+
const body = this.group(root, 0, 0, 84); P(body, G.box, steel, 0, 0, 22, 112, 104, 44); P(body, G.box, dark, 0, 0, 48, 80, 72, 12); P(body, G.box, rust, 50, 0, 18, 18, 60, 30);
|
| 209 |
+
m.vents = P(body, G.box, amber, 58, 0, 24, 2, 40, 6);
|
| 210 |
+
for (const s of [1, -1]) { const arm = this.group(body, 40, s * 47, 12); P(arm, G.box, dark, 0, 0, 0, 40, 26, 30); for (let k = 0; k < 4; k++) { const a = k * Math.PI / 2 + 0.785; P(arm, G.cyl6, steel, 34, Math.cos(a) * 7, Math.sin(a) * 7, 4, 4, 44, 0, Math.PI / 2, 0); } m['arm' + (s > 0 ? 'L' : 'R')] = arm; }
|
| 211 |
+
m.bfg = P(body, G.sphere, green, 6, -9, 27, 9, 9, 9);
|
| 212 |
+
const rider = this.group(body, -10, 0, 54); P(rider, G.box, purple, 0, 0, 14, 22, 30, 30); P(rider, G.sphere, flesh, 0, 0, 36, 10, 10, 12); P(rider, G.box, dark, 6, 18, 18, 14, 10, 26); m.rider = rider;
|
| 213 |
+
m.body = body; this.models.monster_jorg = m; }
|
| 214 |
+
// Makron: armoured cyborg; railgun on the right arm, BFG / hyperblaster cannon on the left.
|
| 215 |
+
{ const root = new T.Group(), m = { root }; this.world.add(root);
|
| 216 |
+
m.legs = [];
|
| 217 |
+
for (const s of [1, -1]) { const hip = this.group(root, 0, s * 12, 46); P(hip, G.box, dark, 0, 0, -10, 16, 14, 26); const knee = this.group(hip, 0, 0, -24); P(knee, G.box, steel, 2, 0, -10, 14, 12, 24); P(knee, G.box, dark, 6, 0, -22, 24, 16, 6); m.legs.push({ hip, knee, s }); }
|
| 218 |
+
const torso = this.group(root, 0, 0, 48); P(torso, G.box, purple, 0, 0, 14, 28, 38, 30); P(torso, G.box, steel, 2, 0, 30, 22, 30, 10); P(torso, G.sphere, flesh, 4, 0, 42, 9, 9, 11); m.eyes = P(torso, G.box, red, 12, 0, 43, 2, 10, 3);
|
| 219 |
+
const rail = this.group(torso, -6, -8, 24); P(rail, G.box, dark, 0, 0, 0, 22, 12, 12); P(rail, G.cyl, steel, 22, 0, 0, 5, 5, 34, 0, Math.PI / 2, 0); m.railGlow = P(rail, G.cyl, cyan, 22, 0, 0, 2.5, 2.5, 36, 0, Math.PI / 2, 0); m.rail = rail;
|
| 220 |
+
const cannon = this.group(torso, 8, 20, 14); P(cannon, G.box, rust, 0, 0, 0, 26, 14, 16); P(cannon, G.cyl, dark, 16, 0, 0, 9, 9, 16, 0, Math.PI / 2, 0); m.cannonGlow = P(cannon, G.sphere, green, 25, 0, 0, 6, 6, 6); m.cannon = cannon;
|
| 221 |
+
m.torso = torso; this.models.monster_makron = m; }
|
| 222 |
+
// Tank Commander: a heavy biped (box -32..32 x -16..72), blaster on the right forearm, chaingun on the left, a
|
| 223 |
+
// rocket pack on the shoulder; skin 2 is the commander's darker red plating.
|
| 224 |
+
{ const root = new T.Group(), m = { root }; this.world.add(root); const plate = this.std(0x8a3a2c), plateD = this.std(0x5a2a22);
|
| 225 |
+
m.legs = [];
|
| 226 |
+
for (const s of [1, -1]) { const hip = this.group(root, 0, s * 16, 22); P(hip, G.box, plateD, 0, 0, -10, 22, 18, 26); const knee = this.group(hip, 0, 0, -22); P(knee, G.box, steel, 4, 0, -8, 18, 16, 20); P(knee, G.box, dark, 10, 0, -16, 34, 22, 8); m.legs.push({ hip, knee, s }); }
|
| 227 |
+
const torso = this.group(root, 0, 0, 26); P(torso, G.box, plate, 0, 0, 18, 46, 56, 38); P(torso, G.box, plateD, -8, 0, 40, 34, 44, 12); P(torso, G.sphere, flesh, 14, 0, 44, 8, 9, 9); m.eye = P(torso, G.box, red, 22, 0, 46, 2, 10, 3);
|
| 228 |
+
const mgArm = this.group(torso, 8, 34, 14); P(mgArm, G.box, dark, 0, 0, 0, 30, 14, 14); const mg = this.group(mgArm, 22, 0, 0); for (let k = 0; k < 6; k++) { const a = k * Math.PI / 3; P(mg, G.cyl6, steel, 14, Math.cos(a) * 3.5, Math.sin(a) * 3.5, 2.2, 2.2, 26, 0, Math.PI / 2, 0); } m.mg = mg; m.mgArm = mgArm;
|
| 229 |
+
const blast = this.group(torso, 10, -32, 12); P(blast, G.box, steel, 0, 0, 0, 34, 14, 14); m.blastGlow = P(blast, G.sphere, amber, 18, 0, 0, 5, 5, 5);
|
| 230 |
+
const pod = this.group(torso, -14, 20, 46); P(pod, G.box, plateD, 0, 0, 0, 24, 20, 18); for (let k = 0; k < 3; k++) P(pod, G.cyl, dark, 8, -6 + k * 6, 2, 3.5, 3.5, 14, 0, Math.PI / 2, 0); m.podGlow = P(pod, G.box, amber, 14, 0, 2, 2, 18, 8); m.pod = pod;
|
| 231 |
+
m.torso = torso; this.models.monster_tank_commander = m; }
|
| 232 |
+
// Gladiator: a lanky biped (box -32..32 x -24..64) with a cleaver on the right arm and a railgun on the left.
|
| 233 |
+
{ const root = new T.Group(), m = { root }; this.world.add(root); const hide = this.std(0x8a7a5a), armour = this.std(0x5a6a74);
|
| 234 |
+
m.legs = [];
|
| 235 |
+
for (const s of [1, -1]) { const hip = this.group(root, 0, s * 12, 6); P(hip, G.box, armour, 0, 0, -14, 12, 12, 28); const knee = this.group(hip, 0, 0, -26); P(knee, G.box, dark, 4, 0, -2, 12, 10, 10); m.legs.push({ hip, knee, s }); }
|
| 236 |
+
const torso = this.group(root, 0, 0, 8); P(torso, G.box, hide, 0, 0, 22, 26, 34, 34); P(torso, G.box, armour, 4, 0, 34, 22, 40, 12); P(torso, G.sphere, flesh, 6, 0, 48, 8, 8, 10); P(torso, G.box, red, 13, 0, 50, 2, 8, 2);
|
| 237 |
+
const cleaver = this.group(torso, 6, -26, 30); P(cleaver, G.box, armour, 0, 0, -8, 10, 10, 22); P(cleaver, G.box, steel, 14, 0, -18, 30, 3, 18); m.cleaver = cleaver;
|
| 238 |
+
const rail = this.group(torso, 8, 24, 26); P(rail, G.box, dark, 0, 0, 0, 22, 10, 10); P(rail, G.cyl, steel, 18, 0, 0, 3.5, 3.5, 26, 0, Math.PI / 2, 0); m.railGlow = P(rail, G.cyl, cyan, 18, 0, 0, 2.5, 2.5, 28, 0, Math.PI / 2, 0);
|
| 239 |
+
m.torso = torso; this.models.monster_gladiator = m; }
|
| 240 |
+
// Mutant: a hunched quadruped-ish brute (box -32..32 x -24..48), long clawed arms, no weapon.
|
| 241 |
+
{ const root = new T.Group(), m = { root }; this.world.add(root); const skin = this.std(0xd8a882), bone = this.std(0xf4ead0);
|
| 242 |
+
m.legs = [];
|
| 243 |
+
for (const s of [1, -1]) { const hip = this.group(root, -10, s * 16, -2); P(hip, G.box, skin, 0, 0, -10, 14, 14, 24); P(hip, G.box, bone, 6, 0, -22, 18, 12, 4); m.legs.push({ hip, s }); }
|
| 244 |
+
const body = this.group(root, 0, 0, 4); P(body, G.sphere, skin, 0, 0, 18, 30, 26, 20); P(body, G.sphere, skin, 18, 0, 30, 16, 16, 14); P(body, G.sphere, flesh, 30, 0, 34, 9, 10, 9); P(body, G.box, red, 38, 4, 36, 2, 3, 2); P(body, G.box, red, 38, -4, 36, 2, 3, 2);
|
| 245 |
+
for (let k = 0; k < 5; k++) P(body, G.cone, bone, -10 + k * 7, 0, 36 - k * 1.5, 3, 3, 8);
|
| 246 |
+
for (const s of [1, -1]) { const arm = this.group(body, 16, s * 24, 28); P(arm, G.box, skin, 6, 0, -12, 10, 10, 28); for (let k = -1; k <= 1; k++) P(arm, G.cone, bone, 12, k * 3, -28, 2, 2, 10, Math.PI, 0, 0); m[s > 0 ? 'armL' : 'armR'] = arm; }
|
| 247 |
+
m.body = body; this.models.monster_mutant = m; }
|
| 248 |
+
for (const m of Object.values(this.models)) m.root.visible = false;
|
| 249 |
+
}
|
| 250 |
+
buildWeapons() { // first-person view models, drawn in their own pass over the world
|
| 251 |
+
this.vscene = new T.Scene(); this.vcam = new T.PerspectiveCamera(52, 854 / 480, 0.01, 10);
|
| 252 |
+
this.vscene.add(new T.HemisphereLight(0xfff0e0, 0x302820, 1.5)); const key = new T.DirectionalLight(0xffffff, 1.2); key.position.set(-0.4, 1, 0.6); this.vscene.add(key);
|
| 253 |
+
const G = this.geo, dark = this.std(0x2a2b2e), steel = this.std(0x7a7d82), brass = this.std(0x9a7a3a), wood = this.std(0x5a3c24), blue = this.glow(0x6ab8ff), orange = this.glow(0xffa040);
|
| 254 |
+
const box = (g, x, y, z, sx, sy, sz, m) => { const o = new T.Mesh(G.box, m); o.position.set(x, y, z); o.scale.set(sx, sy, sz); g.add(o); return o; };
|
| 255 |
+
const tube = (g, x, y, z, r, l, m) => { const o = new T.Mesh(G.cyl, m); o.position.set(x, y, z); o.scale.set(r, l, r); o.rotation.x = Math.PI / 2; g.add(o); return o; };
|
| 256 |
+
const W = this.vweapons = {};
|
| 257 |
+
const mk = (name, build) => { const g = new T.Group(), inner = new T.Group(); build(inner); inner.scale.setScalar(0.62); g.add(inner); g.userData.spin = inner.userData.spin; g.visible = false; this.vscene.add(g); W[name] = g; };
|
| 258 |
+
mk('blaster', g => { box(g, 0, 0, 0, 0.07, 0.09, 0.26, dark); tube(g, 0, 0.02, -0.17, 0.022, 0.12, steel); box(g, 0, -0.08, 0.06, 0.05, 0.12, 0.07, wood); box(g, 0, 0.055, -0.02, 0.03, 0.02, 0.12, orange); });
|
| 259 |
+
mk('shotgun', g => { tube(g, 0, 0.02, -0.12, 0.022, 0.5, steel); box(g, 0, -0.01, 0.1, 0.06, 0.07, 0.24, wood); box(g, 0, -0.025, -0.12, 0.05, 0.035, 0.18, wood); });
|
| 260 |
+
mk('supershotgun', g => { tube(g, -0.022, 0.02, -0.12, 0.022, 0.5, steel); tube(g, 0.022, 0.02, -0.12, 0.022, 0.5, steel); box(g, 0, -0.01, 0.12, 0.08, 0.08, 0.22, wood); });
|
| 261 |
+
mk('machinegun', g => { box(g, 0, 0, 0, 0.07, 0.08, 0.34, dark); tube(g, 0, 0.01, -0.24, 0.018, 0.16, steel); box(g, 0, -0.09, -0.02, 0.04, 0.12, 0.05, brass); });
|
| 262 |
+
mk('chaingun', g => { const spin = new T.Group(); for (let k = 0; k < 6; k++) { const a = k * Math.PI / 3; tube(spin, Math.cos(a) * 0.035, Math.sin(a) * 0.035, -0.18, 0.012, 0.42, steel); } g.add(spin); g.userData.spin = spin; box(g, 0, -0.02, 0.1, 0.12, 0.12, 0.2, dark); });
|
| 263 |
+
mk('rocketlauncher', g => { tube(g, 0, 0.03, -0.08, 0.055, 0.6, this.std(0x44523a)); box(g, 0, -0.06, 0.08, 0.06, 0.1, 0.12, dark); tube(g, 0, 0.03, -0.39, 0.06, 0.03, steel); });
|
| 264 |
+
mk('hyperblaster', g => { const spin = new T.Group(); for (let k = 0; k < 4; k++) { const a = k * Math.PI / 2; tube(spin, Math.cos(a) * 0.03, Math.sin(a) * 0.03, -0.2, 0.012, 0.38, steel); } g.add(spin); g.userData.spin = spin; box(g, 0, -0.03, 0.08, 0.1, 0.1, 0.2, dark); box(g, 0, 0.06, 0.06, 0.04, 0.02, 0.16, orange); });
|
| 265 |
+
mk('railgun', g => { box(g, 0, 0, -0.06, 0.07, 0.07, 0.6, dark); tube(g, 0, 0.0, -0.06, 0.03, 0.62, blue); box(g, 0, -0.07, 0.12, 0.05, 0.1, 0.1, steel); });
|
| 266 |
+
this.vflash = new T.Mesh(G.sphere, this.glow(0xffd890, 0.9)); this.vflash.scale.setScalar(0.045); this.vflash.visible = false; this.vscene.add(this.vflash);
|
| 267 |
+
}
|
| 268 |
+
// ---------------- per-frame update ----------------
|
| 269 |
+
render(g, ctx) {
|
| 270 |
+
if (this.closed || this.renderer.getContext().isContextLost()) { this.ready = false; this.error = this.closed ? '3D renderer is closed' : 'WebGL context lost'; throw Error(this.error); }
|
| 271 |
+
const t0 = performance.now();
|
| 272 |
+
try {
|
| 273 |
+
const p = g.ents[1], time = g.ms / 1000;
|
| 274 |
+
const eye = [p.origin[0], p.origin[1], p.origin[2] + (p.viewheight || 22)];
|
| 275 |
+
const ang = p.health > 0 ? p.v_angle : [-15, p.v_angle[1], 40];
|
| 276 |
+
qv(eye[0], eye[1], eye[2] - (p.health > 0 ? 0 : 16), this.camera.position);
|
| 277 |
+
const cp = Math.cos(ang[0] * DEG), sp = Math.sin(ang[0] * DEG), cy = Math.cos(ang[1] * DEG), sy = Math.sin(ang[1] * DEG);
|
| 278 |
+
const look = qv(eye[0] + cp * cy * 100, eye[1] + cp * sy * 100, eye[2] - sp * 100);
|
| 279 |
+
this.camera.up.set(0, 1, 0); this.camera.lookAt(look);
|
| 280 |
+
this.camera.rotateZ(-(ang[2] || 0) * DEG);
|
| 281 |
+
this.updateBosses(g, time); this.updateMissiles(g, time); this.updateFx(g, time); this.updateItems(g, time);
|
| 282 |
+
this.renderer.info.reset(); this.renderer.clear(); this.renderer.render(this.world, this.camera);
|
| 283 |
+
this.updateViewWeapon(g, p, time);
|
| 284 |
+
this.renderer.clearDepth(); this.renderer.render(this.vscene, this.vcam);
|
| 285 |
+
ctx.drawImage(this.view, 0, 0, 854, 480);
|
| 286 |
+
this.times.push(performance.now() - t0); if (this.times.length > 120) this.times.shift();
|
| 287 |
+
this.ready = true; this.error = null;
|
| 288 |
+
} catch (e) { this.ready = false; this.error = String(e && e.stack || e); throw e; }
|
| 289 |
+
}
|
| 290 |
+
updateBosses(g, time) {
|
| 291 |
+
for (const m of Object.values(this.models)) m.root.visible = false;
|
| 292 |
+
for (let i = 2; i < g.ents.length; i++) {
|
| 293 |
+
const e = g.ents[i];
|
| 294 |
+
if (!e.inuse || !this.models[e.classname] || e.gibbed) continue;
|
| 295 |
+
const m = this.models[e.classname], def = Q.MONSTERS[e.classname], mi = e.monsterinfo || {}, mv = def.moves[mi.currentmove] || def.moves.stand;
|
| 296 |
+
const f = Math.max(0, e.frame - mv.first), n = mv.last - mv.first + 1, ph = f / n, move = mi.currentmove || 'stand';
|
| 297 |
+
// A monster moves its ai_run distance on its 100 ms think; the original client spreads that step over the next
|
| 298 |
+
// server frame (cl_ents.c lerpfrac). The state keeps the step as e.lerp, read-only here.
|
| 299 |
+
const lf = e.lerp ? Math.max(0, 1 - (g.ms - e.lerp[3]) / Q.FRAMETIME_MS) : 0, lo = lf ? e.lerp : [0, 0, 0];
|
| 300 |
+
m.root.visible = true; qv(e.origin[0] + lo[0] * lf, e.origin[1] + lo[1] * lf, e.origin[2] + lo[2] * lf, m.root.position); m.root.rotation.set(0, e.angles[1] * DEG, 0);
|
| 301 |
+
const dying = e.deadflag === Q.DEAD_DEAD, hurt = e.skinnum === 1;
|
| 302 |
+
if (e.classname === 'monster_supertank') {
|
| 303 |
+
const walk = move === 'run' || move === 'forward';
|
| 304 |
+
m.treadL.position.y = (walk ? Math.sin(ph * Math.PI * 4) * 1.2 : 0) * S; m.treadR.position.y = (walk ? -Math.sin(ph * Math.PI * 4) * 1.2 : 0) * S;
|
| 305 |
+
m.torso.rotation.y = move.startsWith('pain') ? Math.sin(ph * Math.PI) * 0.18 : 0;
|
| 306 |
+
m.gun.rotation.x = move === 'attack1' ? time * 9 : 0;
|
| 307 |
+
const charging = move === 'attack2' && e.frame >= 20 && e.frame < 34;
|
| 308 |
+
m.pod.rotation.z = charging ? -0.25 : 0; m.podGlow.visible = charging; m.podGlow.material.opacity = 1;
|
| 309 |
+
m.hull.rotation.z = dying ? Math.min(1, ph * 1.3) * 0.3 : 0; m.root.position.y -= dying ? ph * 22 * S : 0;
|
| 310 |
+
m.eye.visible = !dying;
|
| 311 |
+
} else if (e.classname === 'monster_boss2') {
|
| 312 |
+
for (const w of m.wings) w.w.rotation.x = w.s * (Math.sin(time * 38 + w.f) * 0.5 + 0.2);
|
| 313 |
+
const pitch = move === 'attack_rocket' ? -0.12 : move.startsWith('pain') ? Math.sin(ph * Math.PI) * 0.3 : 0;
|
| 314 |
+
m.body.rotation.z = pitch + (dying ? -ph * 0.8 : 0); m.body.rotation.x = Math.sin(time * 2.1) * 0.05 + (dying ? ph * 0.6 : 0);
|
| 315 |
+
m.body.position.y = (40 + Math.sin(time * 3) * 2) * S;
|
| 316 |
+
} else if (e.classname === 'monster_jorg') {
|
| 317 |
+
const walk = move === 'run' || move === 'walk';
|
| 318 |
+
for (const L of m.legs) { const a = walk ? Math.sin(ph * Math.PI * 2 + (L.s > 0 ? 0 : Math.PI)) : 0; L.hip.rotation.z = a * 0.35; L.knee.rotation.z = -Math.max(0, a) * 0.5; }
|
| 319 |
+
const fire = move === 'attack1' || move === 'start_attack1';
|
| 320 |
+
m.armL.rotation.x = fire ? time * 6 : 0; m.armR.rotation.x = fire ? -time * 6 : 0;
|
| 321 |
+
m.bfg.visible = !dying; m.bfg.scale.setScalar((move === 'attack2' && e.frame < 25 ? 9 + (e.frame - 18) * 1.6 : 6) * S);
|
| 322 |
+
m.body.rotation.z = move.startsWith('pain') ? Math.sin(ph * Math.PI) * 0.12 : dying ? Math.min(1, ph * 1.2) * 0.35 : 0;
|
| 323 |
+
m.root.position.y -= dying ? Math.max(0, ph - 0.5) * 50 * S : 0;
|
| 324 |
+
m.rider.visible = !(dying && e.frame >= 79);
|
| 325 |
+
} else if (e.classname === 'monster_makron') {
|
| 326 |
+
const walk = move === 'run' || move === 'walk';
|
| 327 |
+
for (const L of m.legs) { const a = walk ? Math.sin(ph * Math.PI * 2 + (L.s > 0 ? 0 : Math.PI)) : 0; L.hip.rotation.z = a * 0.5; L.knee.rotation.z = -Math.max(0, a) * 0.6; }
|
| 328 |
+
const railCharge = move === 'attack5' && e.frame <= 243, sweep = move === 'attack4' && e.frame >= 213 && e.frame <= 229, bfgCharge = move === 'attack3' && e.frame <= 204;
|
| 329 |
+
m.railGlow.visible = railCharge; m.railGlow.scale.set(2.5 * S * (1 + (e.frame - 235) * 0.12), 36 * S, 2.5 * S * (1 + (e.frame - 235) * 0.12));
|
| 330 |
+
m.rail.rotation.z = railCharge ? 0.1 : 0;
|
| 331 |
+
m.cannon.rotation.y = sweep ? (e.frame <= 221 ? -(221 - e.frame) * 10 : (229 - e.frame) * 10) * DEG : 0;
|
| 332 |
+
m.cannonGlow.visible = bfgCharge || sweep; m.cannonGlow.scale.setScalar((bfgCharge ? 6 + (e.frame - 201) * 2 : 4) * S);
|
| 333 |
+
m.torso.rotation.z = move === 'sight' ? Math.sin(ph * Math.PI) * -0.2 : move.startsWith('pain') ? Math.sin(ph * Math.PI) * 0.25 : dying ? Math.min(1, ph * 1.4) * 1.2 : 0;
|
| 334 |
+
m.root.position.y -= dying ? Math.max(0, ph - 0.6) * 40 * S : 0;
|
| 335 |
+
} else if (e.classname === 'monster_tank_commander') {
|
| 336 |
+
const walk = move === 'run' || move === 'start_run' || move === 'walk';
|
| 337 |
+
for (const L of m.legs) { const a = walk ? Math.sin(ph * Math.PI * 2 + (L.s > 0 ? 0 : Math.PI)) : 0; L.hip.rotation.z = a * 0.4; L.knee.rotation.z = -Math.max(0, a) * 0.5; }
|
| 338 |
+
m.mg.rotation.x = move === 'attack_chain' ? time * 12 : 0;
|
| 339 |
+
m.mgArm.rotation.y = move === 'attack_chain' && e.frame >= 173 && e.frame <= 191 ? (e.frame <= 182 ? -(e.frame - 178) * 8 : (e.frame - 186) * 8) * DEG : 0;
|
| 340 |
+
m.blastGlow.visible = move === 'attack_blast' || move === 'reattack_blast';
|
| 341 |
+
const pre = move === 'attack_pre_rocket' || move === 'attack_fire_rocket'; m.podGlow.visible = pre; m.pod.rotation.z = pre ? -0.3 : 0;
|
| 342 |
+
m.torso.rotation.z = move.startsWith('pain') ? Math.sin(ph * Math.PI) * 0.2 : dying ? Math.min(1, ph * 1.3) * 0.9 : 0;
|
| 343 |
+
m.root.position.y -= dying ? Math.max(0, ph - 0.5) * 30 * S : 0;
|
| 344 |
+
} else if (e.classname === 'monster_gladiator') {
|
| 345 |
+
const walk = move === 'run' || move === 'walk';
|
| 346 |
+
for (const L of m.legs) { const a = walk ? Math.sin(ph * Math.PI * 2 + (L.s > 0 ? 0 : Math.PI)) : 0; L.hip.rotation.z = a * 0.6; L.knee.rotation.z = -Math.max(0, a) * 0.7; }
|
| 347 |
+
const swing = move === 'attack_melee', railing = move === 'attack_gun' && e.frame <= 49;
|
| 348 |
+
m.cleaver.rotation.z = swing ? Math.sin(ph * Math.PI * 4) * 1.1 : 0.2;
|
| 349 |
+
const charge = 1 + Math.max(0, Math.min(3, e.frame - 46)) * 0.35; m.railGlow.visible = railing; m.railGlow.scale.set(2.5 * S * charge, 30 * S, 2.5 * S * charge);
|
| 350 |
+
m.torso.rotation.z = move.startsWith('pain') ? Math.sin(ph * Math.PI) * 0.3 : dying ? Math.min(1, ph * 1.4) * 1.3 : 0;
|
| 351 |
+
m.root.position.y -= dying ? Math.max(0, ph - 0.6) * 40 * S : 0;
|
| 352 |
+
} else if (e.classname === 'monster_mutant') {
|
| 353 |
+
const walk = move === 'run' || move === 'walk' || move === 'start_walk';
|
| 354 |
+
for (const L of m.legs) { const a = walk ? Math.sin(ph * Math.PI * 2 + (L.s > 0 ? 0 : Math.PI)) : 0; L.hip.rotation.z = a * 0.7; }
|
| 355 |
+
const claw = move === 'attack', leap = move === 'jump';
|
| 356 |
+
m.armL.rotation.z = claw ? Math.sin(ph * Math.PI * 2) * 1.2 : leap ? -1.2 : 0.3; m.armR.rotation.z = claw ? -Math.sin(ph * Math.PI * 2 + 1) * 1.2 : leap ? -1.2 : 0.3;
|
| 357 |
+
m.body.rotation.z = leap ? -0.5 : move.startsWith('pain') ? Math.sin(ph * Math.PI) * 0.4 : dying ? Math.min(1, ph * 1.5) * 1.4 : 0;
|
| 358 |
+
m.root.position.y -= dying ? Math.max(0, ph - 0.5) * 30 * S : 0;
|
| 359 |
+
}
|
| 360 |
+
for (const mat of [this.bossMats.red]) mat.color.setHex(hurt ? 0xff8040 : 0xff3010);
|
| 361 |
+
}
|
| 362 |
+
// Railgun aim lines once the target point is locked (Makron: MakronSaveloc on frame 242, fires on 243; Gladiator:
|
| 363 |
+
// gladiator_attack saves pos1 in the tick it picks attack_gun, still on the previous move's frame, and fires on frame
|
| 364 |
+
// 49, four ticks later). The line is the exact shot line.
|
| 365 |
+
for (const l of this.aimLines) l.visible = false;
|
| 366 |
+
let ai = 0;
|
| 367 |
+
for (let i = 2; i < g.ents.length && ai < this.aimLines.length; i++) {
|
| 368 |
+
const e = g.ents[i];
|
| 369 |
+
if (!e.inuse || e.deadflag || !e.monsterinfo) continue;
|
| 370 |
+
let ofs = null;
|
| 371 |
+
if (e.classname === 'monster_makron' && e.monsterinfo.currentmove === 'attack5' && e.frame === 242) ofs = [-17.3, 7.8, 72.4];
|
| 372 |
+
else if (e.classname === 'monster_gladiator' && e.monsterinfo.currentmove === 'attack_gun' && e.frame <= 48) ofs = [30.0, 18.0, 28.0];
|
| 373 |
+
if (!ofs) continue;
|
| 374 |
+
const av = Q.angleVectors(e.angles), start = Q.projectSource(e.origin, ofs, av.forward, av.right), dir = Q.norm(Q.sub(e.pos1, start)), end = Q.ma(start, 2400, dir);
|
| 375 |
+
this.setLine(this.aimLines[ai++], start, end);
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
setLine(line, a, b) {
|
| 379 |
+
const arr = line.geometry.attributes.position.array, A = qv(a[0], a[1], a[2]), Bv = qv(b[0], b[1], b[2]);
|
| 380 |
+
arr[0] = A.x; arr[1] = A.y; arr[2] = A.z; arr[3] = Bv.x; arr[4] = Bv.y; arr[5] = Bv.z;
|
| 381 |
+
line.geometry.attributes.position.needsUpdate = true; line.geometry.computeBoundingSphere(); line.visible = true;
|
| 382 |
+
}
|
| 383 |
+
orient(obj, origin, vel) {
|
| 384 |
+
qv(origin[0], origin[1], origin[2], obj.position);
|
| 385 |
+
const yaw = Math.atan2(vel[1], vel[0]), pitch = Math.atan2(vel[2], Math.hypot(vel[0], vel[1]));
|
| 386 |
+
obj.rotation.set(0, yaw, pitch, 'YZX');
|
| 387 |
+
}
|
| 388 |
+
updateMissiles(g, time) {
|
| 389 |
+
let r = 0, b = 0, f = 0, l = 0;
|
| 390 |
+
for (const o of [...this.rockets, ...this.bolts, ...this.bfgs, ...this.lasers]) o.visible = false;
|
| 391 |
+
for (let i = 2; i < g.ents.length; i++) {
|
| 392 |
+
const e = g.ents[i];
|
| 393 |
+
if (!e.inuse) continue;
|
| 394 |
+
if (e.classname === 'rocket' && r < this.rockets.length) { const o = this.rockets[r++]; this.orient(o, e.origin, e.velocity); o.visible = true; }
|
| 395 |
+
else if (e.classname === 'bolt' && b < this.bolts.length) { const o = this.bolts[b++]; this.orient(o, e.origin, e.velocity); o.visible = true; }
|
| 396 |
+
else if (e.classname === 'bfg blast' && f < this.bfgs.length) {
|
| 397 |
+
const o = this.bfgs[f++]; qv(e.origin[0], e.origin[1], e.origin[2], o.position); o.visible = true;
|
| 398 |
+
const exploding = e.think === 'bfg_explode' || e.effect === 'bfgexplode';
|
| 399 |
+
o.children[0].scale.setScalar((exploding ? 40 + (e.frame || 0) * 30 : 14 + Math.sin(time * 20) * 2) * S); o.children[2].visible = !exploding;
|
| 400 |
+
for (const end of e.lasers || []) if (l < this.lasers.length) this.setLine(this.lasers[l++], e.origin, end);
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
updateFx(g, time) {
|
| 405 |
+
let bo = 0, pu = 0, tr = 0, rc = 0, gi = 0, fl = 0;
|
| 406 |
+
for (const o of [...this.booms, ...this.puffs, ...this.tracers, ...this.railCores, ...this.railSpirals, ...this.gibs, ...this.flashes]) o.visible = false;
|
| 407 |
+
let flash = 0, boom = 0, flashPos = null, boomPos = null;
|
| 408 |
+
for (const fx of g.fx) {
|
| 409 |
+
const age = (g.ms - fx.t0) / fx.life;
|
| 410 |
+
if (age < 0 || age > 1) continue;
|
| 411 |
+
if (fx.kind === 'explosion' && bo < this.booms.length) {
|
| 412 |
+
const o = this.booms[bo++], s = (fx.big ? 70 : 48) * (0.35 + age * 0.8);
|
| 413 |
+
qv(fx.o[0], fx.o[1], fx.o[2], o.position); o.scale.setScalar(s * S); o.rotation.set(fx.id, fx.id * 1.3, 0); o.visible = true;
|
| 414 |
+
o.children[0].material.opacity = 0.85 * (1 - age); if (1 - age > boom) { boom = 1 - age; boomPos = fx.o; }
|
| 415 |
+
} else if ((fx.kind === 'blood' || fx.kind === 'puff' || fx.kind === 'spark' || fx.kind === 'blasterhit') && pu < this.puffs.length) {
|
| 416 |
+
const o = this.puffs[pu++]; qv(fx.o[0], fx.o[1], fx.o[2] + age * 10, o.position); o.scale.setScalar((fx.kind === 'blood' ? 5 : 3.5) * (1 + age) * S);
|
| 417 |
+
o.material = fx.kind === 'blood' ? this.mats.blood : fx.kind === 'puff' ? this.mats.puff : this.mats.spark; o.visible = true;
|
| 418 |
+
} else if (fx.kind === 'tracer' && fx.from === 'monster' && tr < this.tracers.length) {
|
| 419 |
+
this.setLine(this.tracers[tr++], fx.o, fx.to);
|
| 420 |
+
} else if (fx.kind === 'rail' && rc < this.railCores.length) {
|
| 421 |
+
this.setLine(this.railCores[rc], fx.o, fx.to);
|
| 422 |
+
const sp = this.railSpirals[rc++], arr = sp.geometry.attributes.position.array, d = Q.sub(fx.to, fx.o), L = Q.len(d), dir = Q.norm(d);
|
| 423 |
+
const side = Q.norm(Q.cross(dir, Math.abs(dir[2]) < 0.9 ? [0, 0, 1] : [1, 0, 0])), up = Q.cross(side, dir), n = arr.length / 3, v = new T.Vector3();
|
| 424 |
+
for (let k = 0; k < n; k++) { const t = k / (n - 1), a = t * L / 18, rr = 5 + age * 6, p = Q.ma(Q.ma(Q.ma(fx.o, t * L, dir), Math.cos(a) * rr, side), Math.sin(a) * rr, up); qv(p[0], p[1], p[2], v); arr[k * 3] = v.x; arr[k * 3 + 1] = v.y; arr[k * 3 + 2] = v.z; }
|
| 425 |
+
sp.geometry.attributes.position.needsUpdate = true; sp.geometry.computeBoundingSphere(); sp.visible = true;
|
| 426 |
+
sp.material.opacity = 0.9 * (1 - age); this.railCores[rc - 1].material.opacity = 0.9 * (1 - age);
|
| 427 |
+
} else if (fx.kind === 'mflash' && fl < this.flashes.length) {
|
| 428 |
+
const o = this.flashes[fl++]; qv(fx.o[0], fx.o[1], fx.o[2], o.position); o.scale.setScalar((fx.weapon === 'bfg' ? 14 : fx.weapon === 'rocket' ? 9 : 6) * S); o.visible = true;
|
| 429 |
+
flash = 1; flashPos = fx.o;
|
| 430 |
+
} else if (fx.kind === 'railcharge' && fl < this.flashes.length) {
|
| 431 |
+
const e = g.ents[fx.owner]; if (!e || !e.inuse) continue;
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
for (let i = 2; i < g.ents.length && gi < this.gibs.length; i++) {
|
| 435 |
+
const e = g.ents[i];
|
| 436 |
+
if (!e.inuse || (e.classname !== 'gib' && e.classname !== 'debris')) continue;
|
| 437 |
+
const o = this.gibs[gi++]; qv(e.origin[0], e.origin[1], e.origin[2], o.position); o.rotation.set(e.angles[0] * DEG, e.angles[1] * DEG, e.angles[2] * DEG);
|
| 438 |
+
o.scale.setScalar((e.classname === 'debris' ? 3 : e.head ? 9 : e.gib === 'chest' ? 8 : 5) * S);
|
| 439 |
+
o.material = e.classname === 'debris' ? this.mats.debris : e.gib === 'metal' || e.gib === 'gear' ? this.mats.gibMetal : this.mats.meat; o.visible = true;
|
| 440 |
+
}
|
| 441 |
+
this.flashLight.intensity = flash ? 2.2 : 0; if (flashPos) qv(flashPos[0], flashPos[1], flashPos[2], this.flashLight.position);
|
| 442 |
+
this.boomLight.intensity = boom * 3.2; if (boomPos) qv(boomPos[0], boomPos[1], boomPos[2] + 24, this.boomLight.position);
|
| 443 |
+
}
|
| 444 |
+
updateItems(g, time) {
|
| 445 |
+
const seen = new Set();
|
| 446 |
+
for (let i = 2; i < g.ents.length; i++) {
|
| 447 |
+
const e = g.ents[i];
|
| 448 |
+
if (!e.inuse || e.solid !== Q.SOLID_TRIGGER || !e.item) continue;
|
| 449 |
+
let o = this.items[i];
|
| 450 |
+
if (!o || o.userData.item !== e.item) { if (o) this.world.remove(o); o = this.items[i] = this.itemModel(e.item); this.world.add(o); }
|
| 451 |
+
seen.add(String(i)); o.visible = true;
|
| 452 |
+
qv(e.origin[0], e.origin[1], e.origin[2] - 6 + Math.sin(time * 2.4 + i) * 3, o.position); o.rotation.y = time * 1.6 + i;
|
| 453 |
+
}
|
| 454 |
+
for (const k of Object.keys(this.items)) if (!seen.has(k)) this.items[k].visible = false;
|
| 455 |
+
}
|
| 456 |
+
itemModel(item) {
|
| 457 |
+
const g = new T.Group(); g.userData.item = item; const G = this.geo, m = this.itemMat[item] || this.itemMat.health;
|
| 458 |
+
const add = (geo, mat, x, y, z, sx, sy, sz) => { const o = new T.Mesh(geo, mat); o.position.set(x * S, z * S, -y * S); o.scale.set(sx * S, sz * S, sy * S); g.add(o); return o; };
|
| 459 |
+
if (item.startsWith('health') || item === 'stimpack') {
|
| 460 |
+
const s = item === 'health_large' ? 1.3 : item === 'stimpack' ? 0.55 : 1;
|
| 461 |
+
add(G.box, m, 0, 0, 0, 22 * s, 16 * s, 14 * s); add(G.box, this.crossMat, 0, 0, 7.5 * s, 14 * s, 4 * s, 1); add(G.box, this.crossMat, 0, 0, 7.5 * s, 4 * s, 14 * s, 1);
|
| 462 |
+
} else if (item === 'armor_shard') { add(G.ico, m, 0, 0, 2, 7, 7, 10); }
|
| 463 |
+
else if (item.startsWith('armor')) { add(G.box, m, 0, 0, 0, 10, 26, 24); add(G.box, m, 4, 0, 10, 8, 30, 6); }
|
| 464 |
+
else { add(G.box, m, 0, 0, 0, 18, 14, 12); add(G.box, this.std(0xd8d0b0), 0, 0, 6.5, 12, 10, 1); }
|
| 465 |
+
return g;
|
| 466 |
+
}
|
| 467 |
+
updateViewWeapon(g, p, time) {
|
| 468 |
+
for (const w of Object.values(this.vweapons)) w.visible = false;
|
| 469 |
+
this.vflash.visible = false;
|
| 470 |
+
if (p.health <= 0 || !p.weapon) return;
|
| 471 |
+
const w = this.vweapons[p.weapon]; if (!w) return;
|
| 472 |
+
const def = Q.WDEF[p.weapon], [act, fireLast, idleLast, deact] = def.frames;
|
| 473 |
+
let drop = 0;
|
| 474 |
+
if (p.weaponstate === 2) drop = (p.gunframe - idleLast) / Math.max(1, deact - idleLast);
|
| 475 |
+
else if (p.weaponstate === 1) drop = 1 - p.gunframe / Math.max(1, act);
|
| 476 |
+
const speed = Math.hypot(p.velocity[0], p.velocity[1]), bob = p.groundentity >= 0 ? Math.min(1, speed / 300) : 0;
|
| 477 |
+
const since = g.ms - (p.fired || -9999), recoil = since >= 0 && since < 200 ? (1 - since / 200) : 0;
|
| 478 |
+
w.visible = true;
|
| 479 |
+
w.position.set(0.15 + Math.cos(time * 7.5) * 0.008 * bob, -0.13 - drop * 0.25 + Math.abs(Math.sin(time * 7.5)) * 0.008 * bob, -0.34 + recoil * 0.035);
|
| 480 |
+
w.rotation.set(recoil * 0.12, 0, 0);
|
| 481 |
+
if (w.userData.spin && p.weaponstate === 3) w.userData.spin.rotation.z = time * 14;
|
| 482 |
+
if (since >= 0 && since < 100) { this.vflash.visible = true; this.vflash.position.set(0.15, -0.11 - drop * 0.25, -0.55); this.vflash.scale.setScalar(0.03); }
|
| 483 |
+
}
|
| 484 |
+
metrics() {
|
| 485 |
+
const sorted = [...this.times].sort((a, b) => a - b), info = this.renderer.info;
|
| 486 |
+
return { renderer: 'webgl-quake2', drawCalls: info.render.calls, triangles: info.render.triangles, samples: sorted.length,
|
| 487 |
+
cpuRenderMsP50: sorted.length ? sorted[Math.floor((sorted.length - 1) * 0.5)] : null, cpuRenderMsP95: sorted.length ? sorted[Math.floor((sorted.length - 1) * 0.95)] : null };
|
| 488 |
+
}
|
| 489 |
+
close() { if (this.closed) return; this.closed = true; this.ready = false; for (const r of this.resources) r.dispose && r.dispose(); this.renderer.dispose(); this.renderer.forceContextLoss(); this.resources = []; }
|
| 490 |
+
}
|
| 491 |
+
R.render = (g, ctx) => {
|
| 492 |
+
let m = byCanvas.get(ctx.canvas); if (!m) { m = new Map(); byCanvas.set(ctx.canvas, m); }
|
| 493 |
+
let s = m.get(g.key); if (!s || s.closed) { s = new Scene(g.key, ctx.canvas); m.set(g.key, s); }
|
| 494 |
+
s.render(g, ctx); m.last = s; return s;
|
| 495 |
+
};
|
| 496 |
+
R.status = ctx => {
|
| 497 |
+
const m = ctx && byCanvas.get(ctx.canvas); let ready = false, error = null;
|
| 498 |
+
if (m) for (const s of m.values()) { if (!s.closed && s.renderer.getContext().isContextLost()) { s.ready = false; s.error = 'WebGL context lost'; } ready = ready || (s.ready && !s.closed); error = error || s.error; }
|
| 499 |
+
return { renderer: 'webgl-quake2', kind: 'perspective', ready, error };
|
| 500 |
+
};
|
| 501 |
+
R.metrics = ctx => { const m = ctx && byCanvas.get(ctx.canvas); return m && m.last && !m.last.closed ? m.last.metrics() : null; };
|
| 502 |
+
R.close = ctx => { const m = ctx && byCanvas.get(ctx.canvas); if (!m) return; for (const s of m.values()) s.close(); byCanvas.delete(ctx.canvas); };
|
| 503 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/quake2_remake/scripted.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Quake II boss arenas - the standard scripted reference controller (BossBench, not part of the original game).
|
| 2 |
+
Quake2Game.scripted(game) is called once per 200 ms packet with the live simulation. It reads privileged state,
|
| 3 |
+
looks ahead on deep copies (M.copyGame never touches the live RNG or state), and returns only legal packets:
|
| 4 |
+
six hold sets of at most four keys and one mouse delta. Deterministic: no Math.random, no clock.
|
| 5 |
+
At 60 Hz (q2-arena@3) a packet is twelve ticks, two per hold set; the controller holds its move keys in all six
|
| 6 |
+
sets and taps weapon keys in sets 1-3 so the press lands on the first tick and is released after 100 ms. */
|
| 7 |
+
(function (root) {
|
| 8 |
+
'use strict';
|
| 9 |
+
const N = root.NativeBench, M = root.Quake2Game, Q = M.Q;
|
| 10 |
+
const MOUSE_DEG = Q.CL.m_yaw * Q.CL.sensitivity; // 0.066 degrees per mouse count
|
| 11 |
+
const memory = new WeakMap();
|
| 12 |
+
const angleDiff = a => ((a % 360) + 540) % 360 - 180;
|
| 13 |
+
const MOVES = [[], ['W'], ['S'], ['A'], ['D'], ['W', 'A'], ['W', 'D'], ['S', 'A'], ['S', 'D']];
|
| 14 |
+
const SPEED = { rocketlauncher: 650, hyperblaster: 1000, blaster: 1000 };
|
| 15 |
+
const LOOK = Math.round(1.4 * M.hz); // look-ahead per candidate move: 1.4 s (14 ticks at @2)
|
| 16 |
+
M.LOOK_K = 1; // blinded futures per candidate move (see M.scripted)
|
| 17 |
+
|
| 18 |
+
// The copies get their own rand() state, so the controller plans with the rules but without knowing the live dice
|
| 19 |
+
// (bullet spread, the boss's next attack choice): it cannot dodge by reading the future RNG. Since q2-arena@3 the
|
| 20 |
+
// copy's state is a function of the tick only, not of the live holdrand: with it derived from the live value the
|
| 21 |
+
// packet still depended on the real dice (leak probe: decision invariance 0.63-0.75, tools/leak60.js).
|
| 22 |
+
function simulate(g, keys, mouseTicks, ticks, k = 0) {
|
| 23 |
+
const h = M.copyGame(g), ks = new Set(keys), none = new Set();
|
| 24 |
+
let x = Math.imul((g.t + 0x9e3779b9 + Math.imul(k, 0x632be5ab)) >>> 0, 0x85ebca6b) >>> 0; x ^= x >>> 13; x = Math.imul(x, 0xc2b2ae35) >>> 0; x ^= x >>> 16;
|
| 25 |
+
h.rnd = x >>> 0;
|
| 26 |
+
// At 60 Hz the shared per-tick quantize (a walk over the whole state) was 87 % of the controller's time; the copy is
|
| 27 |
+
// a plan, not a replay, so it is quantized once at the end (still deterministic; off by micro-units at most).
|
| 28 |
+
for (let t = 0; t < ticks && !h.outcome; t++) {
|
| 29 |
+
h.events = [];
|
| 30 |
+
h.update(ks, none, mouseTicks[t] || [0, 0, 0]); // the turn happens in the first packet only
|
| 31 |
+
h.t++;
|
| 32 |
+
}
|
| 33 |
+
N.quantize(h);
|
| 34 |
+
return h;
|
| 35 |
+
}
|
| 36 |
+
const center = e => Q.center(e);
|
| 37 |
+
const eyeOf = p => [p.origin[0], p.origin[1], p.origin[2] + p.viewheight];
|
| 38 |
+
function lineOfFire(g, from, to, boss) {
|
| 39 |
+
const tr = Q.trace(g, from, null, null, to, 1, Q.MASK_SHOT);
|
| 40 |
+
return tr.ent === boss || tr.fraction === 1;
|
| 41 |
+
}
|
| 42 |
+
// Weapon wanted for this target: highest-value weapon with ammo whose range rule holds.
|
| 43 |
+
function wantWeapon(g, p, b, dist) {
|
| 44 |
+
const has = (w, ammo, n = 1) => p.inv[w] && (!ammo || p.inv[ammo] >= n);
|
| 45 |
+
const surface = dist - (b.maxs[0] || 0);
|
| 46 |
+
const order = [];
|
| 47 |
+
if (b.classname === 'monster_supertank') {
|
| 48 |
+
// Rockets from RANGE_MID, then the machinegun from mid range; the shotguns are the last resort: their range puts
|
| 49 |
+
// the player in RANGE_NEAR (attack checks 5x as often) or inside 160 units (always the chaingun).
|
| 50 |
+
if (surface > 150) order.push(['rocketlauncher', 'rockets']);
|
| 51 |
+
order.push(['machinegun', 'bullets'], ['supershotgun', 'shells', 2], ['shotgun', 'shells']);
|
| 52 |
+
} else if (b.classname === 'monster_boss2') {
|
| 53 |
+
// Railgun first: hitscan 150 suits peek-shoot-hide against a flier (rockets and bolts miss it often).
|
| 54 |
+
order.push(['railgun', 'slugs'], ['chaingun', 'bullets'], ['hyperblaster', 'cells']);
|
| 55 |
+
} else if (b.classname === 'monster_jorg') {
|
| 56 |
+
if (dist < 800) order.push(['chaingun', 'bullets', 20]);
|
| 57 |
+
order.push(['hyperblaster', 'cells'], ['railgun', 'slugs']);
|
| 58 |
+
if (surface > 190) order.push(['rocketlauncher', 'rockets']);
|
| 59 |
+
} else if (b.classname === 'monster_tank_commander') {
|
| 60 |
+
// Rockets from range (750 health per hit-set is a lot of 8-damage bullets); the chaingun when it is close.
|
| 61 |
+
if (surface > 150) order.push(['rocketlauncher', 'rockets']);
|
| 62 |
+
order.push(['chaingun', 'bullets', 20], ['supershotgun', 'shells', 2], ['machinegun', 'bullets']);
|
| 63 |
+
} else if (b.classname === 'monster_gladiator') {
|
| 64 |
+
// Keep outside the cleaver: rockets and the hyperblaster from mid range.
|
| 65 |
+
if (surface > 150) order.push(['rocketlauncher', 'rockets']);
|
| 66 |
+
order.push(['hyperblaster', 'cells'], ['chaingun', 'bullets', 20], ['supershotgun', 'shells', 2]);
|
| 67 |
+
} else if (b.classname === 'monster_mutant') {
|
| 68 |
+
// No ranged attack to answer: shotguns at close range, the chaingun while kiting.
|
| 69 |
+
if (dist < 420) order.push(['supershotgun', 'shells', 2]);
|
| 70 |
+
order.push(['chaingun', 'bullets', 20], ['machinegun', 'bullets'], ['supershotgun', 'shells', 2]);
|
| 71 |
+
} else {
|
| 72 |
+
order.push(['railgun', 'slugs'], ['hyperblaster', 'cells'], ['chaingun', 'bullets']);
|
| 73 |
+
if (surface > 190) order.push(['rocketlauncher', 'rockets']);
|
| 74 |
+
}
|
| 75 |
+
order.push(['machinegun', 'bullets'], ['shotgun', 'shells'], ['supershotgun', 'shells', 2], ['blaster', null]);
|
| 76 |
+
for (const [w, ammo, n] of order) if (has(w, ammo, n || 1)) return w;
|
| 77 |
+
return 'blaster';
|
| 78 |
+
}
|
| 79 |
+
// Hitscan streams that keep firing while the boss can see the player: the counter is to break line of sight. The
|
| 80 |
+
// Hornet's 0.9 s pre-mg windup deals no damage, so the controller keeps shooting through it and hides on attack_mg.
|
| 81 |
+
const STREAM = { monster_supertank: ['attack1'], monster_boss2: ['attack_mg'], monster_jorg: ['start_attack1', 'attack1'],
|
| 82 |
+
monster_tank_commander: ['attack_chain'] };
|
| 83 |
+
const PREFERRED = {
|
| 84 |
+
monster_supertank: [['rocketlauncher', 'rockets'], ['machinegun', 'bullets']],
|
| 85 |
+
monster_boss2: [['railgun', 'slugs'], ['chaingun', 'bullets'], ['hyperblaster', 'cells']],
|
| 86 |
+
monster_jorg: [['chaingun', 'bullets'], ['hyperblaster', 'cells'], ['railgun', 'slugs'], ['rocketlauncher', 'rockets']],
|
| 87 |
+
monster_makron: [['railgun', 'slugs'], ['hyperblaster', 'cells'], ['chaingun', 'bullets'], ['rocketlauncher', 'rockets']],
|
| 88 |
+
monster_tank_commander: [['rocketlauncher', 'rockets'], ['chaingun', 'bullets']],
|
| 89 |
+
monster_gladiator: [['rocketlauncher', 'rockets'], ['hyperblaster', 'cells'], ['chaingun', 'bullets']],
|
| 90 |
+
monster_mutant: [['supershotgun', 'shells'], ['chaingun', 'bullets']],
|
| 91 |
+
};
|
| 92 |
+
// Cover spots: points beside the arena's cover brushes (not the shell) that the boss's eye cannot see.
|
| 93 |
+
function hiddenSpots(g, b) {
|
| 94 |
+
const be = [b.origin[0], b.origin[1], b.origin[2] + b.viewheight], out = [], brushes = Q.worlds[g.key].brushes;
|
| 95 |
+
for (let k = 6; k < brushes.length; k++) {
|
| 96 |
+
const br = brushes[k];
|
| 97 |
+
if (br.maxs[2] < 64) continue; // too low to hide behind
|
| 98 |
+
const cx = (br.mins[0] + br.maxs[0]) / 2, cy = (br.mins[1] + br.maxs[1]) / 2;
|
| 99 |
+
for (const [px, py] of [[br.mins[0] - 40, cy], [br.maxs[0] + 40, cy], [cx, br.mins[1] - 40], [cx, br.maxs[1] + 40],
|
| 100 |
+
[br.mins[0] - 40, br.mins[1] - 40], [br.maxs[0] + 40, br.mins[1] - 40], [br.mins[0] - 40, br.maxs[1] + 40], [br.maxs[0] + 40, br.maxs[1] + 40]]) {
|
| 101 |
+
const pt = [px, py, br.mins[2] + 24];
|
| 102 |
+
if (Q.pointcontents(g, pt) & Q.CONTENTS_SOLID) continue;
|
| 103 |
+
if (Q.trace(g, be, null, null, [px, py, pt[2] + 22], -1, Q.MASK_OPAQUE).fraction < 1) out.push(pt);
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
return out;
|
| 107 |
+
}
|
| 108 |
+
// Stalemate breaker (5 s without sight, while the normal seek after 1 s has not found the boss): the nearest point the
|
| 109 |
+
// player can walk to in a straight line from which the boss's eye is visible now. Without it, player and boss can
|
| 110 |
+
// mirror each other on the two sides of a full-height pillar (each one's distance term only matches the other's
|
| 111 |
+
// position along the pillar, and a 1.4 s straight look-ahead never comes out of it).
|
| 112 |
+
function sightSpot(g, b, p) {
|
| 113 |
+
const be = [b.origin[0], b.origin[1], b.origin[2] + b.viewheight];
|
| 114 |
+
let best = null, bestD = 1e9;
|
| 115 |
+
for (const r of [96, 192, 288, 384]) {
|
| 116 |
+
for (let k = 0; k < 16; k++) {
|
| 117 |
+
const a = k * Math.PI / 8, pt = [p.origin[0] + Q.cos(a) * r, p.origin[1] + Q.sin(a) * r, p.origin[2]];
|
| 118 |
+
if (r >= bestD) continue;
|
| 119 |
+
if (Q.trace(g, p.origin, [-16, -16, -24], [16, 16, 32], pt, 1, Q.MASK_SOLID).fraction < 1) continue;
|
| 120 |
+
if (Q.trace(g, [pt[0], pt[1], pt[2] + p.viewheight], null, null, be, -1, Q.MASK_OPAQUE).fraction < 1) continue;
|
| 121 |
+
best = pt; bestD = r;
|
| 122 |
+
}
|
| 123 |
+
if (best) break;
|
| 124 |
+
}
|
| 125 |
+
return best;
|
| 126 |
+
}
|
| 127 |
+
// The boss's view of a candidate player position: eye-to-eye trace through the world only.
|
| 128 |
+
const seenBy = (g, b, q) => Q.trace(g, [b.origin[0], b.origin[1], b.origin[2] + b.viewheight], null, null, [q.origin[0], q.origin[1], q.origin[2] + q.viewheight], -1, Q.MASK_OPAQUE).fraction === 1;
|
| 129 |
+
function threats(h) { // enemy projectiles and BFG orbs near the player at the end of a look-ahead
|
| 130 |
+
const p = h.ents[1]; let s = 0;
|
| 131 |
+
for (const e of h.ents) {
|
| 132 |
+
if (!e.inuse || e.owner === 1 || e.owner < 0) continue;
|
| 133 |
+
if (e.classname === 'rocket') {
|
| 134 |
+
const v = Q.norm(e.velocity), rel = Q.sub(p.origin, e.origin), along = Q.dot(rel, v);
|
| 135 |
+
if (along > 0) { const off = Q.len(Q.sub(rel, Q.scale(v, along))); s += Math.max(0, 110 - off) * (along < 700 ? 1 : 0.3); }
|
| 136 |
+
} else if (e.classname === 'bfg blast') {
|
| 137 |
+
const dd = Q.len(Q.sub(p.origin, e.origin)); s += Math.max(0, 420 - dd) * 2.5;
|
| 138 |
+
} else if (e.classname === 'bolt') {
|
| 139 |
+
const v = Q.norm(e.velocity), rel = Q.sub(p.origin, e.origin), along = Q.dot(rel, v);
|
| 140 |
+
if (along > 0) { const off = Q.len(Q.sub(rel, Q.scale(v, along))); s += Math.max(0, 60 - off) * 0.5; }
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
return s;
|
| 144 |
+
}
|
| 145 |
+
M.scripted = function (g) {
|
| 146 |
+
const noop = { holds: Array.from({ length: 6 }, () => []), mouse: [0, 0, 0] };
|
| 147 |
+
const p = g.ents[1];
|
| 148 |
+
if (g.outcome || p.health <= 0) return noop;
|
| 149 |
+
// Memory across packets (hysteresis, time out of sight) is rolled once per tick, so asking twice about the same
|
| 150 |
+
// state gives the same packet; a new episode (tick 0) starts fresh.
|
| 151 |
+
let mem = memory.get(g);
|
| 152 |
+
if (!mem || (g.t === 0 && mem.t !== 0)) { mem = { t: -1, move: 0, unseen: 0, base: null }; memory.set(g, mem); }
|
| 153 |
+
if (mem.t !== g.t) { mem.base = { move: mem.move, unseen: mem.unseen }; mem.t = g.t; }
|
| 154 |
+
const bi = g.bossEnt(), b = g.ents[bi];
|
| 155 |
+
const alive = b && b.inuse && (b.svflags & Q.SVF_MONSTER) && b.deadflag !== Q.DEAD_DEAD && b.health > 0;
|
| 156 |
+
const eye = eyeOf(p);
|
| 157 |
+
let dx = 0, dy = 0, fire = false, want = p.weapon, dist = 1e9;
|
| 158 |
+
if (alive) {
|
| 159 |
+
const c = center(b);
|
| 160 |
+
dist = Q.len(Q.sub(c, p.origin));
|
| 161 |
+
want = wantWeapon(g, p, b, dist);
|
| 162 |
+
// Aim: the centre of the body, led by the boss's last-frame motion for projectile weapons.
|
| 163 |
+
let aim = [c[0], c[1], b.origin[2] + (b.maxs[2] - b.mins[2]) * 0.45];
|
| 164 |
+
const speed = SPEED[p.weapon];
|
| 165 |
+
if (speed) { const vel = Q.scale(Q.sub(b.origin, b.old_origin), 10), tf = Q.len(Q.sub(aim, eye)) / speed; aim = Q.ma(aim, tf, vel); }
|
| 166 |
+
const dvec = Q.sub(aim, eye), yaw = Q.atan2(dvec[1], dvec[0]) * 180 / Math.PI;
|
| 167 |
+
// Machinegun climb: each held shot adds machinegun_shots * -1.5 degrees of pitch kick; pull down to match.
|
| 168 |
+
const climb = p.weapon === 'machinegun' && (p.buttons & 1) ? Math.min(9, p.machinegun_shots + 0.5) * 1.5 : 0;
|
| 169 |
+
const pitch = -Q.atan2(dvec[2], Math.sqrt(dvec[0] * dvec[0] + dvec[1] * dvec[1])) * 180 / Math.PI + climb;
|
| 170 |
+
const dyaw = angleDiff(yaw - p.viewangles[1]), dpitch = pitch - p.viewangles[0];
|
| 171 |
+
dx = Math.max(-1000, Math.min(1000, Math.round(-dyaw / MOUSE_DEG)));
|
| 172 |
+
dy = Math.max(-1000, Math.min(1000, Math.round(dpitch / MOUSE_DEG)));
|
| 173 |
+
const residual = Math.abs(dyaw + dx * MOUSE_DEG) + Math.abs(dpitch - dy * MOUSE_DEG);
|
| 174 |
+
const radius = Math.max(b.maxs[0], 24), tol = Q.atan2(radius * 0.8, Math.max(1, dist)) * 180 / Math.PI;
|
| 175 |
+
const clear = lineOfFire(g, eye, aim, bi);
|
| 176 |
+
const selfSplash = p.weapon === 'rocketlauncher' && dist - b.maxs[0] < 170;
|
| 177 |
+
// Pellet spread is +-hspread/8192 radians (shotgun 500, super shotgun 1000 plus +-5 degrees per barrel): against
|
| 178 |
+
// the 128-unit Super Tank or 160-unit Jorg most pellets still land at 900 units, against Makron (60) they do not.
|
| 179 |
+
const outOfRange = /shotgun/.test(p.weapon) && dist > (b.maxs[0] >= 60 ? 1000 : 640);
|
| 180 |
+
fire = clear && residual < tol + 2 && !selfSplash && !outOfRange && Math.abs(dyaw) < 60;
|
| 181 |
+
}
|
| 182 |
+
// Weapon switch: tap weapnext / weapprev toward the wanted weapon when idle.
|
| 183 |
+
let tap = null;
|
| 184 |
+
const switching = !!p.newweapon || p.weaponstate === 1 || p.weaponstate === 2;
|
| 185 |
+
if (!switching && want && want !== p.weapon && p.weaponstate !== 3) {
|
| 186 |
+
const owned = Q.WEAPON_ORDER.filter(w => p.inv[w]), cur = owned.indexOf(p.weapon), tgt = owned.indexOf(want);
|
| 187 |
+
if (tgt >= 0) tap = ((tgt - cur + owned.length) % owned.length) <= owned.length / 2 ? 'K' : 'R';
|
| 188 |
+
}
|
| 189 |
+
// Movement: one-second look-ahead per candidate move on copies; score survival, damage, range and threats.
|
| 190 |
+
const fireKeys = fire ? ['J'] : [];
|
| 191 |
+
const PT = M.hz / 5, mouseTicks = Array.from({ length: PT }, () => [dx / PT, dy / PT, 0]); // the packet's split
|
| 192 |
+
const hp0 = p.health + armor(p) * 0.6, boss0 = g.health()[2];
|
| 193 |
+
// Super Tank: rockets from the edge of RANGE_FAR. M_CheckAttack never attacks at >= 1000 units and only at 0.02
|
| 194 |
+
// per frame (x2 on hard) in RANGE_MID, against 0.1 (x2) in RANGE_NEAR; the tank walks 120 u/s, the player runs 300.
|
| 195 |
+
const stBand = p.weapon === 'rocketlauncher' ? [880, 1250] : [650, 1000];
|
| 196 |
+
const band = !alive ? [400, 900] : b.classname === 'monster_supertank' ? stBand : /shotgun/.test(p.weapon) ? [170, 380]
|
| 197 |
+
: b.classname === 'monster_boss2' ? [260, 620] : b.classname === 'monster_jorg' ? [360, 760]
|
| 198 |
+
: b.classname === 'monster_tank_commander' ? (p.weapon === 'rocketlauncher' ? [560, 900] : [300, 600])
|
| 199 |
+
: b.classname === 'monster_gladiator' ? [420, 780] : b.classname === 'monster_mutant' ? [200, 420] : [320, 700];
|
| 200 |
+
let best = 0, bestScore = -Infinity;
|
| 201 |
+
const stream = alive && (STREAM[b.classname] || []).includes(b.monsterinfo.currentmove);
|
| 202 |
+
const fragile = p.health + armor(p) * 0.6 < 70;
|
| 203 |
+
// Hiding is a tactic, not a plan: after 1 s without line of sight (and no burst in progress) the controller goes
|
| 204 |
+
// looking for the boss; cover is only taken while a hitscan burst is actually running.
|
| 205 |
+
const visNow = alive && Q.visible(g, bi, 1);
|
| 206 |
+
mem.unseen = visNow ? 0 : mem.base.unseen + 1;
|
| 207 |
+
const seek = alive && mem.unseen >= 5 && !fragile && !(STREAM[b.classname] || []).includes(b.monsterinfo.currentmove);
|
| 208 |
+
const spot = seek && mem.unseen >= 25 ? sightSpot(g, b, p) : null;
|
| 209 |
+
// Against hitscan bosses stay within a short dash of cover at all times (peek, shoot, step back): the burst only
|
| 210 |
+
// continues while the boss can see the player at its reattack check.
|
| 211 |
+
const hitscanBoss = alive && STREAM[b.classname];
|
| 212 |
+
const spots = alive && (stream || fragile || hitscanBoss) ? hiddenSpots(g, b) : [];
|
| 213 |
+
// Ammo the preferred weapons of this fight are short of (below half of the carry limit); the main weapon first.
|
| 214 |
+
const needAmmo = [];
|
| 215 |
+
if (alive) for (const [w, ammo] of PREFERRED[b.classname] || []) if (p.inv[w] && p.inv[ammo] < Q.AMMO_MAX[ammo] / 2) needAmmo.push('ammo_' + ammo);
|
| 216 |
+
const main = alive && (PREFERRED[b.classname] || []).find(([w]) => p.inv[w]);
|
| 217 |
+
const lowMain = !!main && p.inv[main[1]] < Q.AMMO_MAX[main[1]] * 0.5;
|
| 218 |
+
// Out of the preferred weapons' ammo (while owning one of them): only the close-range fallbacks are left, so
|
| 219 |
+
// restocking comes first. The easy kit owns none of them and is never starving.
|
| 220 |
+
const owned = alive ? (PREFERRED[b.classname] || []).filter(([w]) => p.inv[w]) : [];
|
| 221 |
+
const starving = owned.length > 0 && !owned.some(([w, ammo]) => p.inv[ammo] >= 6);
|
| 222 |
+
for (let m = 0; m < MOVES.length; m++) {
|
| 223 |
+
const keys = ['Shift', ...MOVES[m], ...fireKeys];
|
| 224 |
+
const scores = [];
|
| 225 |
+
for (let k = 0; k < M.LOOK_K; k++) {
|
| 226 |
+
const h = simulate(g, keys, mouseTicks, LOOK, k), q = h.ents[1];
|
| 227 |
+
let score = -(hp0 - (q.health + armor(q) * 0.6)) * 25 + (boss0 - h.health()[2]) * 0.4;
|
| 228 |
+
if (h.outcome === 'loss' || q.health <= 0) score -= 1e6;
|
| 229 |
+
if (h.outcome === 'win') score += 1e5;
|
| 230 |
+
if (alive) {
|
| 231 |
+
const hb = h.ents[h.bossEnt()], nd = Q.len(Q.sub(Q.center(hb), q.origin));
|
| 232 |
+
const seen = hb.inuse && hb.health > 0 && Q.visible(h, 1, h.bossEnt());
|
| 233 |
+
if (!starving) score -= Math.max(0, band[0] - nd) * 0.5 + Math.max(0, nd - band[1]) * 0.25;
|
| 234 |
+
else score -= Math.max(0, 480 - nd) * 1.0; // restocking: stay out of RANGE_NEAR / the chaingun
|
| 235 |
+
if (seen) score += stream ? -90 : fragile ? 5 : (/shotgun/.test(p.weapon) && b.maxs[0] < 60 && nd > 640 ? -30 : 20);
|
| 236 |
+
if (seek) { if (seen) score += 80; score -= nd * 0.04; if (spot) score -= Math.sqrt((spot[0] - q.origin[0]) ** 2 + (spot[1] - q.origin[1]) ** 2) * 0.25; }
|
| 237 |
+
// During a hitscan stream the live boss does not move (attack1 is ai_charge 0): judge cover against it too.
|
| 238 |
+
if (stream && !seenBy(h, b, q)) score += 60;
|
| 239 |
+
if (spots.length) {
|
| 240 |
+
let near = 1e9; for (const s of spots) near = Math.min(near, Math.sqrt((s[0] - q.origin[0]) ** 2 + (s[1] - q.origin[1]) ** 2));
|
| 241 |
+
score -= stream || fragile ? near * (stream ? 0.4 : 0.08) : seek ? 0 : Math.max(0, near - 140) * 0.06;
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
score -= threats(h) * 1.5;
|
| 245 |
+
// Room to manoeuvre: free distance in eight directions (corners trap the player in a hitscan stream).
|
| 246 |
+
let room = 0;
|
| 247 |
+
for (let k = 0; k < 8; k++) {
|
| 248 |
+
const a = k * Math.PI / 4, to = [q.origin[0] + Q.cos(a) * 200, q.origin[1] + Q.sin(a) * 200, q.origin[2]];
|
| 249 |
+
room += Q.trace(h, q.origin, [-16, -16, -24], [16, 16, 32], to, 1, Q.MASK_SOLID).fraction;
|
| 250 |
+
}
|
| 251 |
+
score -= (8 - room) * 14;
|
| 252 |
+
if (m === mem.base.move) score += 6;
|
| 253 |
+
if (q.health < 90 || armor(q) < 40) {
|
| 254 |
+
// Health and armor pickups (and the ones about to respawn): strong pull when hurt, a mild one otherwise.
|
| 255 |
+
let near = 1e9;
|
| 256 |
+
for (const e of h.ents) {
|
| 257 |
+
if (!e.inuse || !e.item) continue;
|
| 258 |
+
const useful = /health/.test(e.item) ? q.health < 100 : e.item === 'stimpack' || (e.item === 'armor_shard' && armor(q) < 100);
|
| 259 |
+
if (!useful) continue;
|
| 260 |
+
const soon = e.solid !== Q.SOLID_TRIGGER && e.think === 'DoRespawn' && e.nextthink - h.ms < 3000;
|
| 261 |
+
if (e.solid === Q.SOLID_TRIGGER || soon) near = Math.min(near, Q.len(Q.sub(e.origin, q.origin)) + (soon ? 60 : 0));
|
| 262 |
+
}
|
| 263 |
+
// Like the ammo boxes below: a health or armor item taken inside the look-ahead is gone from the floor (q2-arena@4
|
| 264 |
+
// frees it), so "nearest item" would measure the next one and punish the move that heals. Taking one counts as
|
| 265 |
+
// distance 0 plus a bonus that grows with the damage taken.
|
| 266 |
+
let healed = 0;
|
| 267 |
+
for (let k = 0; k < h.ents.length && k < g.ents.length; k++) {
|
| 268 |
+
const ge = g.ents[k], he = h.ents[k];
|
| 269 |
+
if (ge.inuse && ge.solid === Q.SOLID_TRIGGER && /^(health|stimpack|armor)/.test(ge.item || '') && !(he.inuse && he.item === ge.item && he.solid === Q.SOLID_TRIGGER)) healed++;
|
| 270 |
+
}
|
| 271 |
+
if (healed) score += (q.health < 50 ? 160 : q.health < 80 ? 60 : 20) * healed;
|
| 272 |
+
else if (near < 1e9) score -= near * (q.health < 50 ? 0.2 : q.health < 80 ? 0.08 : 0.03);
|
| 273 |
+
}
|
| 274 |
+
if (needAmmo.length) {
|
| 275 |
+
// Boxes on the floor, and boxes that respawn within the next 3 s (waiting next to them is the restock).
|
| 276 |
+
let near = 1e9;
|
| 277 |
+
for (const e of h.ents) {
|
| 278 |
+
if (!e.inuse || !needAmmo.includes(e.item)) continue;
|
| 279 |
+
const soon = e.solid !== Q.SOLID_TRIGGER && e.think === 'DoRespawn' && e.nextthink - h.ms < 3000;
|
| 280 |
+
if (e.solid === Q.SOLID_TRIGGER || soon) near = Math.min(near, Q.len(Q.sub(e.origin, q.origin)) + (soon ? 60 : 0));
|
| 281 |
+
}
|
| 282 |
+
// A box taken inside the look-ahead has left the floor, so "nearest box" would then measure the next one and
|
| 283 |
+
// punish the very move that restocks: taking a needed box counts as distance 0 plus a bonus.
|
| 284 |
+
let taken = 0;
|
| 285 |
+
for (let k = 0; k < h.ents.length && k < g.ents.length; k++) if (needAmmo.includes(h.ents[k].item) && h.ents[k].solid !== Q.SOLID_TRIGGER && g.ents[k].solid === Q.SOLID_TRIGGER) taken++;
|
| 286 |
+
// During a hitscan burst cover beats restocking (the burst stops at the first reattack check without sight).
|
| 287 |
+
if (taken) score += stream ? 30 : starving ? 200 : lowMain ? 120 : 40;
|
| 288 |
+
else if (near < 1e9) score -= near * (stream ? 0.03 : starving ? 0.5 : lowMain ? 0.22 : 0.07);
|
| 289 |
+
}
|
| 290 |
+
scores.push(score);
|
| 291 |
+
}
|
| 292 |
+
// Several blinded futures per move (M.LOOK_K): half the worst, half the mean, so one lucky draw cannot pick a move.
|
| 293 |
+
const score = scores.length > 1 ? 0.5 * Math.min(...scores) + 0.5 * scores.reduce((x, y) => x + y, 0) / scores.length : scores[0];
|
| 294 |
+
if (score > bestScore) { bestScore = score; best = m; }
|
| 295 |
+
}
|
| 296 |
+
mem.move = best;
|
| 297 |
+
const holds = Array.from({ length: 6 }, (_, k) => {
|
| 298 |
+
const ks = ['Shift', ...MOVES[best]];
|
| 299 |
+
// A new press fires at once inside ClientThink while the packet's turn is still under way (60 Hz); start it on hold
|
| 300 |
+
// set 5 (turn 2/3 done), close to the 10 Hz packet whose first sample came half-way. Held fire stays in every set.
|
| 301 |
+
if (tap && k < 3) ks.push(tap); else if (fire && (k >= 4 || (p.buttons & 1))) ks.push('J');
|
| 302 |
+
return ks.slice(0, 4);
|
| 303 |
+
});
|
| 304 |
+
return { holds, mouse: [dx, dy, 0] };
|
| 305 |
+
};
|
| 306 |
+
const armor = p => p.inv.jacket + p.inv.combat + p.inv.body;
|
| 307 |
+
M.oracle = M.scripted;
|
| 308 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/sekiro_remake/app3d.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Human play and exact native-input recording. Game state is owned by each module. */
|
| 2 |
+
(function () {
|
| 3 |
+
'use strict';
|
| 4 |
+
const N=NativeBench, M=window.GAME_MODULE, $=s=>document.querySelector(s), canvas=$('canvas'), context=canvas.getContext('2d');
|
| 5 |
+
let session=new N.Session(M,M.cases[0].id,1,.5),running=false,last=0,accumulator=0;
|
| 6 |
+
// A key pressed and released between two ticks stays latched until one tick has sampled it (same rule as
|
| 7 |
+
// _native/shell.js since 2026-11-01), so fast taps, macro keys and Playwright press() are never lost. Until 2026-11-09 this
|
| 8 |
+
// page released the key on a setTimeout(0), which can run before the next tick and drop the tap; now it is the tick that releases it.
|
| 9 |
+
const held=new Set(),pending=new Set(),releaseAfterTick=new Set(),pointerHeld=new Map(),touchHeld=new Map(); let mouse=[0,0,0],replay=null,replayIndex=0,automatic=false,script=null,scriptTick=0;
|
| 10 |
+
const keys={KeyW:'W',KeyA:'A',KeyS:'S',KeyD:'D',Space:'Space',ShiftLeft:'Shift',ShiftRight:'Shift',KeyJ:'J',KeyK:'K',KeyL:'L',KeyQ:'Q',KeyE:'E',KeyR:'R',ArrowUp:'W',ArrowDown:'S',ArrowLeft:'A',ArrowRight:'D'};
|
| 11 |
+
document.body.dataset.game=M.id;
|
| 12 |
+
// Public difficulty = three tiers (2026-11-02): rebuilt from Module.tiers when the game declares it.
|
| 13 |
+
if(M.tiers&&$('#difficulty')){const sel=$('#difficulty'),names={easy:'Easy',normal:'Normal',hard:'Hard'};sel.textContent='';
|
| 14 |
+
for(const t of ['easy','normal','hard']){const op=document.createElement('option');op.value=String(M.tiers[t]);op.textContent=names[t]+'(d='+M.tiers[t]+')';if(t==='normal')op.selected=true;sel.append(op);}}
|
| 15 |
+
for(const def of M.cases){const option=document.createElement('option');option.value=def.id;option.textContent=def.name;$('#case').append(option);}
|
| 16 |
+
const controls=Array.isArray(M.controls)?M.controls.map(value=>['',value]):Object.entries(M.controls);
|
| 17 |
+
for(const [key,value]of controls){const dt=document.createElement('dt'),dd=document.createElement('dd');dt.textContent=key;dd.textContent=value;$('dl').append(dt,dd);}
|
| 18 |
+
function status(value){$('#status').textContent=value;}
|
| 19 |
+
function clear(){held.clear();pending.clear();releaseAfterTick.clear();pointerHeld.clear();touchHeld.clear();mouse=[0,0,0];accumulator=0;}
|
| 20 |
+
function inputKeys(){return [...new Set([...held,...[...pointerHeld.values()].flatMap(keys=>[...keys]),...touchHeld.values()])].filter(key=>N.keys.includes(key)).slice(0,4);}
|
| 21 |
+
function draw(){
|
| 22 |
+
M.draw(session.game,context);
|
| 23 |
+
$('#pause').textContent=running?'Pause':'Resume';
|
| 24 |
+
$('#overlay').hidden=running&&!session.game.outcome;
|
| 25 |
+
$('#overlay strong').textContent=session.game.outcome?{win:'Challenge Complete',loss:'Challenge Failed',timeout:'Time up'}[session.game.outcome]:replay?'Replay · Paused':session.game.t?'Paused':'Are You Ready?';
|
| 26 |
+
$('#overlay span').textContent=session.game.outcome?'Restart the challenge or export this replay':session.game.t?'Click the screen or press Resume to return to battle':'Click Start Challenge, then click the screen to lock the mouse and turn the camera';
|
| 27 |
+
}
|
| 28 |
+
function reset(id,seed,difficulty){running=false;automatic=false;replay=null;script=null;scriptTick=0;clear();session=new N.Session(M,id,seed,difficulty);draw();return session.snapshot();}
|
| 29 |
+
window.nativeAPI={reset,packet(packet){if(running)throw Error('Pause before a scripted packet');const value=session.packet(packet);draw();return value;},
|
| 30 |
+
state(){return session.snapshot();},recording(){return session.export();},
|
| 31 |
+
render(){draw();return canvas.toDataURL('image/png');},
|
| 32 |
+
renderMetrics(){return M.renderMetrics?M.renderMetrics(context):{};},
|
| 33 |
+
module(){return {id:M.id,hz:M.hz,version:M.version,cases:M.cases};}};
|
| 34 |
+
// PC-style mouse look (2026-11-09): the first click on the canvas during a fight locks the pointer, after which plain mouse
|
| 35 |
+
// movement turns the camera and the buttons stay attack / guard. Not on the start / resume buttons: while the pointer is
|
| 36 |
+
// locked every click goes to the canvas, so the toolbar would be unreachable until Esc. Dragging still works without a lock.
|
| 37 |
+
function lockPointer(){if(document.pointerLockElement===canvas||!canvas.requestPointerLock)return;try{const r=canvas.requestPointerLock();if(r&&r.catch)r.catch(()=>{});}catch(error){}}
|
| 38 |
+
document.addEventListener('pointerlockchange',()=>{if(document.pointerLockElement===canvas)status('Mouse locked · Press Esc to unlock');else if(running&&!automatic&&!replay){running=false;clear();status('Paused (mouse unlocked) · Click the screen to resume and lock the mouse');draw();}
|
| 39 |
+
else if(!running&&!automatic&&!replay&&!session.game.outcome&&session.game.t>0)status('Paused (Esc) · Click the screen to resume and lock the mouse');});
|
| 40 |
+
function start(useScript){try{reset($('#case').value,Number($('#seed').value),Number($('#difficulty').value));automatic=useScript;running=true;status(useScript?'Verification script running':'Battle started · Recording this match · Click the screen to lock the mouse; move it to turn the camera');canvas.focus();draw();}catch(error){status(error.message);}}
|
| 41 |
+
$('#start').onclick=()=>start(false);$('#demo').onclick=()=>start(true);
|
| 42 |
+
$('#pause').onclick=()=>{if(session.game.outcome)return;running=!running;clear();if(running)canvas.focus();draw();};
|
| 43 |
+
$('#step').onclick=()=>{running=false;if(replay)replayTick();else session.tick();draw();};
|
| 44 |
+
function openReplay(data){N.Session.import(M,data);reset(data.case,data.seed,data.difficulty);replay=data;replayIndex=0;running=true;$('#case').value=data.case;status('Replay verified · Starting playback');draw();}
|
| 45 |
+
$('#sample').onclick=()=>{try{const data=M.example?.[$('#case').value];if(!data)throw Error('No built-in replay for this challenge yet. Try Verify Script first.');openReplay(data);}catch(error){status(error.message);}};
|
| 46 |
+
function replayTick(){if(replayIndex<replay.inputs.length){const input=replay.inputs[replayIndex++];session.tick(input[0],input[1]);}if(replayIndex===replay.inputs.length){running=false;status('Replay finished · '+(N.hash(session.state())===replay.finalHash?'Final state matches':'Final state mismatch'));}}
|
| 47 |
+
$('#export').onclick=()=>{const data=session.export(),url=URL.createObjectURL(new Blob([JSON.stringify(data)],{type:'application/json'}));const link=document.createElement('a');link.href=url;link.download=M.id+'-'+session.seed+'.json';link.click();setTimeout(()=>URL.revokeObjectURL(url),1000);status('Current replay exported');};
|
| 48 |
+
$('#import').onclick=()=>$('#file').click();$('#file').onchange=async event=>{const file=event.target.files[0];if(!file)return;try{if(file.size>12e6)throw Error('Replay file is too large');openReplay(JSON.parse(await file.text()));}catch(error){status('Import failed: '+error.message);}event.target.value='';};
|
| 49 |
+
function release(){clear();if(running){running=false;status('Window lost focus · Battle paused');}draw();}
|
| 50 |
+
window.addEventListener('blur',release);document.addEventListener('visibilitychange',()=>{if(document.hidden)release();});
|
| 51 |
+
window.addEventListener('keydown',event=>{if(['INPUT','SELECT','BUTTON'].includes(document.activeElement.tagName))return;if(keys[event.code]){event.preventDefault();held.add(keys[event.code]);pending.add(keys[event.code]);releaseAfterTick.delete(keys[event.code]);}if(event.code==='Escape'){const wasRunning=running;running=false;clear();if(document.pointerLockElement===canvas)document.exitPointerLock?.();if(wasRunning&&!automatic&&!replay&&!session.game.outcome)status('Paused (Esc) · Click the screen to resume and lock the mouse');draw();}});
|
| 52 |
+
window.addEventListener('keyup',event=>{const key=keys[event.code];if(key){event.preventDefault();if(pending.has(key))releaseAfterTick.add(key);else held.delete(key);}});
|
| 53 |
+
canvas.oncontextmenu=event=>event.preventDefault();canvas.onpointerdown=event=>{if(event.button!==0&&event.button!==2)return;canvas.focus();
|
| 54 |
+
// A click on the canvas while the pointer is free re-locks it and resumes a paused fight; that click is not an attack.
|
| 55 |
+
if(document.pointerLockElement!==canvas&&!automatic&&!replay&&!session.game.outcome&&session.game.t>0&&!running){lockPointer();running=true;clear();draw();return;}
|
| 56 |
+
if(document.pointerLockElement!==canvas&&running&&!automatic&&!replay)lockPointer();const keys=pointerHeld.get(event.pointerId)||new Set();keys.add(event.button===2?'RMB':'LMB');pointerHeld.set(event.pointerId,keys);};
|
| 57 |
+
// Pointer Events emits pointerup only after the final mouse button is released.
|
| 58 |
+
// pointermove carries changes to the button mask for chorded mouse presses.
|
| 59 |
+
function syncMouse(event){if(event.pointerType==='mouse'&&pointerHeld.has(event.pointerId)){const keys=new Set();if(event.buttons&1)keys.add('LMB');if(event.buttons&2)keys.add('RMB');if(keys.size)pointerHeld.set(event.pointerId,keys);else pointerHeld.delete(event.pointerId);}}
|
| 60 |
+
window.addEventListener('pointermove',syncMouse);
|
| 61 |
+
window.addEventListener('pointerup',event=>{if(event.pointerType==='mouse')syncMouse(event);else pointerHeld.delete(event.pointerId);touchHeld.delete(event.pointerId);});
|
| 62 |
+
window.addEventListener('pointercancel',event=>{pointerHeld.delete(event.pointerId);touchHeld.delete(event.pointerId);});
|
| 63 |
+
canvas.onpointermove=event=>{if(event.buttons||document.pointerLockElement===canvas){mouse[0]+=event.movementX;mouse[1]+=event.movementY;}};
|
| 64 |
+
canvas.onwheel=event=>{event.preventDefault();mouse[2]+=Math.sign(event.deltaY);};
|
| 65 |
+
canvas.ondblclick=()=>canvas.requestPointerLock?.();
|
| 66 |
+
document.querySelectorAll('[data-key]').forEach(button=>{button.onpointerdown=event=>{event.preventDefault();button.setPointerCapture(event.pointerId);touchHeld.set(event.pointerId,button.dataset.key);};button.onpointerup=button.onpointercancel=event=>touchHeld.delete(event.pointerId);});
|
| 67 |
+
function frame(now){const delta=Math.min(.1,(now-last)/1000||0);last=now;const beforeTick=session.game.t,wasRunning=running;try{
|
| 68 |
+
if(running&&!session.game.outcome){accumulator+=delta;while(accumulator>=1/M.hz&&running&&!session.game.outcome){accumulator-=1/M.hz;
|
| 69 |
+
if(replay)replayTick();else if(automatic){const count=M.hz/5;if(scriptTick===0)script=(M.scripted||M.oracle).call(M,session.game);const sub=Math.ceil((scriptTick+1)*6/count)-1;session.tick(script.holds[sub],script.mouse.map(value=>value/count));scriptTick=(scriptTick+1)%count;}
|
| 70 |
+
else{session.tick(inputKeys(),mouse.map((value,index)=>N.clamp(value,index===2?-5:-1000,index===2?5:1000)));mouse=[0,0,0];pending.clear();for(const key of releaseAfterTick)held.delete(key);releaseAfterTick.clear();}}
|
| 71 |
+
if(session.game.outcome){running=false;status({win:'Challenge Complete',loss:'Challenge Failed',timeout:'Challenge Timed Out'}[session.game.outcome]+' · You can export or replay this match');}}
|
| 72 |
+
if(session.game.t!==beforeTick||running!==wasRunning)draw();
|
| 73 |
+
}catch(error){running=false;clear();status('Runtime error: '+error.message);$('#overlay').hidden=false;$('#overlay strong').textContent='Unable to resume right now';$('#overlay span').textContent=error.message;}
|
| 74 |
+
requestAnimationFrame(frame);
|
| 75 |
+
}
|
| 76 |
+
window.addEventListener('pagehide',()=>M.closeRenderer?.(context));
|
| 77 |
+
draw();requestAnimationFrame(frame);
|
| 78 |
+
})();
|
environments/games/web/games/sekiro_remake/compact_actions.json
ADDED
|
@@ -0,0 +1,1135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/compact-actions@1",
|
| 3 |
+
"game": "sekiro_remake",
|
| 4 |
+
"version": "sekiro-compact@1",
|
| 5 |
+
"heads": [
|
| 6 |
+
{
|
| 7 |
+
"name": "move",
|
| 8 |
+
"options": [
|
| 9 |
+
{
|
| 10 |
+
"label": "none"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"label": "forward",
|
| 14 |
+
"keys": [
|
| 15 |
+
"W"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"label": "forward_start",
|
| 20 |
+
"subs": [
|
| 21 |
+
[
|
| 22 |
+
"W"
|
| 23 |
+
],
|
| 24 |
+
[
|
| 25 |
+
"W"
|
| 26 |
+
],
|
| 27 |
+
[
|
| 28 |
+
"W"
|
| 29 |
+
],
|
| 30 |
+
[],
|
| 31 |
+
[],
|
| 32 |
+
[]
|
| 33 |
+
]
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"label": "forward_end",
|
| 37 |
+
"subs": [
|
| 38 |
+
[],
|
| 39 |
+
[],
|
| 40 |
+
[],
|
| 41 |
+
[
|
| 42 |
+
"W"
|
| 43 |
+
],
|
| 44 |
+
[
|
| 45 |
+
"W"
|
| 46 |
+
],
|
| 47 |
+
[
|
| 48 |
+
"W"
|
| 49 |
+
]
|
| 50 |
+
]
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"label": "forward_tap",
|
| 54 |
+
"subs": [
|
| 55 |
+
[
|
| 56 |
+
"W"
|
| 57 |
+
],
|
| 58 |
+
[],
|
| 59 |
+
[],
|
| 60 |
+
[],
|
| 61 |
+
[],
|
| 62 |
+
[]
|
| 63 |
+
]
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"label": "back",
|
| 67 |
+
"keys": [
|
| 68 |
+
"S"
|
| 69 |
+
]
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"label": "left",
|
| 73 |
+
"keys": [
|
| 74 |
+
"A"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"label": "right",
|
| 79 |
+
"keys": [
|
| 80 |
+
"D"
|
| 81 |
+
]
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"label": "back_left",
|
| 85 |
+
"keys": [
|
| 86 |
+
"S",
|
| 87 |
+
"A"
|
| 88 |
+
]
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"label": "back_right",
|
| 92 |
+
"keys": [
|
| 93 |
+
"S",
|
| 94 |
+
"D"
|
| 95 |
+
]
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"label": "turn_left_30",
|
| 99 |
+
"dx": -175
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"label": "turn_right_30",
|
| 103 |
+
"dx": 175
|
| 104 |
+
}
|
| 105 |
+
]
|
| 106 |
+
},
|
| 107 |
+
{
|
| 108 |
+
"name": "act",
|
| 109 |
+
"options": [
|
| 110 |
+
{
|
| 111 |
+
"label": "none"
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"label": "attack_0",
|
| 115 |
+
"subs": [
|
| 116 |
+
[
|
| 117 |
+
"J"
|
| 118 |
+
],
|
| 119 |
+
[],
|
| 120 |
+
[],
|
| 121 |
+
[],
|
| 122 |
+
[],
|
| 123 |
+
[]
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"label": "attack_1",
|
| 128 |
+
"subs": [
|
| 129 |
+
[],
|
| 130 |
+
[
|
| 131 |
+
"J"
|
| 132 |
+
],
|
| 133 |
+
[],
|
| 134 |
+
[],
|
| 135 |
+
[],
|
| 136 |
+
[]
|
| 137 |
+
]
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"label": "attack_2",
|
| 141 |
+
"subs": [
|
| 142 |
+
[],
|
| 143 |
+
[],
|
| 144 |
+
[
|
| 145 |
+
"J"
|
| 146 |
+
],
|
| 147 |
+
[],
|
| 148 |
+
[],
|
| 149 |
+
[]
|
| 150 |
+
]
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"label": "attack_3",
|
| 154 |
+
"subs": [
|
| 155 |
+
[],
|
| 156 |
+
[],
|
| 157 |
+
[],
|
| 158 |
+
[
|
| 159 |
+
"J"
|
| 160 |
+
],
|
| 161 |
+
[],
|
| 162 |
+
[]
|
| 163 |
+
]
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"label": "attack_4",
|
| 167 |
+
"subs": [
|
| 168 |
+
[],
|
| 169 |
+
[],
|
| 170 |
+
[],
|
| 171 |
+
[],
|
| 172 |
+
[
|
| 173 |
+
"J"
|
| 174 |
+
],
|
| 175 |
+
[]
|
| 176 |
+
]
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"label": "attack_5",
|
| 180 |
+
"subs": [
|
| 181 |
+
[],
|
| 182 |
+
[],
|
| 183 |
+
[],
|
| 184 |
+
[],
|
| 185 |
+
[],
|
| 186 |
+
[
|
| 187 |
+
"J"
|
| 188 |
+
]
|
| 189 |
+
]
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"label": "deflect_0",
|
| 193 |
+
"subs": [
|
| 194 |
+
[
|
| 195 |
+
"RMB"
|
| 196 |
+
],
|
| 197 |
+
[],
|
| 198 |
+
[],
|
| 199 |
+
[],
|
| 200 |
+
[],
|
| 201 |
+
[]
|
| 202 |
+
]
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"label": "deflect_1",
|
| 206 |
+
"subs": [
|
| 207 |
+
[],
|
| 208 |
+
[
|
| 209 |
+
"RMB"
|
| 210 |
+
],
|
| 211 |
+
[],
|
| 212 |
+
[],
|
| 213 |
+
[],
|
| 214 |
+
[]
|
| 215 |
+
]
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
"label": "deflect_2",
|
| 219 |
+
"subs": [
|
| 220 |
+
[],
|
| 221 |
+
[],
|
| 222 |
+
[
|
| 223 |
+
"RMB"
|
| 224 |
+
],
|
| 225 |
+
[],
|
| 226 |
+
[],
|
| 227 |
+
[]
|
| 228 |
+
]
|
| 229 |
+
},
|
| 230 |
+
{
|
| 231 |
+
"label": "deflect_3",
|
| 232 |
+
"subs": [
|
| 233 |
+
[],
|
| 234 |
+
[],
|
| 235 |
+
[],
|
| 236 |
+
[
|
| 237 |
+
"RMB"
|
| 238 |
+
],
|
| 239 |
+
[],
|
| 240 |
+
[]
|
| 241 |
+
]
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"label": "deflect_4",
|
| 245 |
+
"subs": [
|
| 246 |
+
[],
|
| 247 |
+
[],
|
| 248 |
+
[],
|
| 249 |
+
[],
|
| 250 |
+
[
|
| 251 |
+
"RMB"
|
| 252 |
+
],
|
| 253 |
+
[]
|
| 254 |
+
]
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
"label": "deflect_5",
|
| 258 |
+
"subs": [
|
| 259 |
+
[],
|
| 260 |
+
[],
|
| 261 |
+
[],
|
| 262 |
+
[],
|
| 263 |
+
[],
|
| 264 |
+
[
|
| 265 |
+
"RMB"
|
| 266 |
+
]
|
| 267 |
+
]
|
| 268 |
+
},
|
| 269 |
+
{
|
| 270 |
+
"label": "deflect_attack_0_1",
|
| 271 |
+
"subs": [
|
| 272 |
+
[
|
| 273 |
+
"RMB"
|
| 274 |
+
],
|
| 275 |
+
[
|
| 276 |
+
"J"
|
| 277 |
+
],
|
| 278 |
+
[],
|
| 279 |
+
[],
|
| 280 |
+
[],
|
| 281 |
+
[]
|
| 282 |
+
]
|
| 283 |
+
},
|
| 284 |
+
{
|
| 285 |
+
"label": "deflect_attack_0_2",
|
| 286 |
+
"subs": [
|
| 287 |
+
[
|
| 288 |
+
"RMB"
|
| 289 |
+
],
|
| 290 |
+
[],
|
| 291 |
+
[
|
| 292 |
+
"J"
|
| 293 |
+
],
|
| 294 |
+
[],
|
| 295 |
+
[],
|
| 296 |
+
[]
|
| 297 |
+
]
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"label": "deflect_attack_0_3",
|
| 301 |
+
"subs": [
|
| 302 |
+
[
|
| 303 |
+
"RMB"
|
| 304 |
+
],
|
| 305 |
+
[],
|
| 306 |
+
[],
|
| 307 |
+
[
|
| 308 |
+
"J"
|
| 309 |
+
],
|
| 310 |
+
[],
|
| 311 |
+
[]
|
| 312 |
+
]
|
| 313 |
+
},
|
| 314 |
+
{
|
| 315 |
+
"label": "deflect_attack_0_4",
|
| 316 |
+
"subs": [
|
| 317 |
+
[
|
| 318 |
+
"RMB"
|
| 319 |
+
],
|
| 320 |
+
[],
|
| 321 |
+
[],
|
| 322 |
+
[],
|
| 323 |
+
[
|
| 324 |
+
"J"
|
| 325 |
+
],
|
| 326 |
+
[]
|
| 327 |
+
]
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"label": "deflect_attack_0_5",
|
| 331 |
+
"subs": [
|
| 332 |
+
[
|
| 333 |
+
"RMB"
|
| 334 |
+
],
|
| 335 |
+
[],
|
| 336 |
+
[],
|
| 337 |
+
[],
|
| 338 |
+
[],
|
| 339 |
+
[
|
| 340 |
+
"J"
|
| 341 |
+
]
|
| 342 |
+
]
|
| 343 |
+
},
|
| 344 |
+
{
|
| 345 |
+
"label": "deflect_attack_1_2",
|
| 346 |
+
"subs": [
|
| 347 |
+
[],
|
| 348 |
+
[
|
| 349 |
+
"RMB"
|
| 350 |
+
],
|
| 351 |
+
[
|
| 352 |
+
"J"
|
| 353 |
+
],
|
| 354 |
+
[],
|
| 355 |
+
[],
|
| 356 |
+
[]
|
| 357 |
+
]
|
| 358 |
+
},
|
| 359 |
+
{
|
| 360 |
+
"label": "deflect_attack_1_3",
|
| 361 |
+
"subs": [
|
| 362 |
+
[],
|
| 363 |
+
[
|
| 364 |
+
"RMB"
|
| 365 |
+
],
|
| 366 |
+
[],
|
| 367 |
+
[
|
| 368 |
+
"J"
|
| 369 |
+
],
|
| 370 |
+
[],
|
| 371 |
+
[]
|
| 372 |
+
]
|
| 373 |
+
},
|
| 374 |
+
{
|
| 375 |
+
"label": "deflect_attack_1_4",
|
| 376 |
+
"subs": [
|
| 377 |
+
[],
|
| 378 |
+
[
|
| 379 |
+
"RMB"
|
| 380 |
+
],
|
| 381 |
+
[],
|
| 382 |
+
[],
|
| 383 |
+
[
|
| 384 |
+
"J"
|
| 385 |
+
],
|
| 386 |
+
[]
|
| 387 |
+
]
|
| 388 |
+
},
|
| 389 |
+
{
|
| 390 |
+
"label": "deflect_attack_1_5",
|
| 391 |
+
"subs": [
|
| 392 |
+
[],
|
| 393 |
+
[
|
| 394 |
+
"RMB"
|
| 395 |
+
],
|
| 396 |
+
[],
|
| 397 |
+
[],
|
| 398 |
+
[],
|
| 399 |
+
[
|
| 400 |
+
"J"
|
| 401 |
+
]
|
| 402 |
+
]
|
| 403 |
+
},
|
| 404 |
+
{
|
| 405 |
+
"label": "deflect_attack_2_3",
|
| 406 |
+
"subs": [
|
| 407 |
+
[],
|
| 408 |
+
[],
|
| 409 |
+
[
|
| 410 |
+
"RMB"
|
| 411 |
+
],
|
| 412 |
+
[
|
| 413 |
+
"J"
|
| 414 |
+
],
|
| 415 |
+
[],
|
| 416 |
+
[]
|
| 417 |
+
]
|
| 418 |
+
},
|
| 419 |
+
{
|
| 420 |
+
"label": "deflect_attack_2_4",
|
| 421 |
+
"subs": [
|
| 422 |
+
[],
|
| 423 |
+
[],
|
| 424 |
+
[
|
| 425 |
+
"RMB"
|
| 426 |
+
],
|
| 427 |
+
[],
|
| 428 |
+
[
|
| 429 |
+
"J"
|
| 430 |
+
],
|
| 431 |
+
[]
|
| 432 |
+
]
|
| 433 |
+
},
|
| 434 |
+
{
|
| 435 |
+
"label": "deflect_attack_2_5",
|
| 436 |
+
"subs": [
|
| 437 |
+
[],
|
| 438 |
+
[],
|
| 439 |
+
[
|
| 440 |
+
"RMB"
|
| 441 |
+
],
|
| 442 |
+
[],
|
| 443 |
+
[],
|
| 444 |
+
[
|
| 445 |
+
"J"
|
| 446 |
+
]
|
| 447 |
+
]
|
| 448 |
+
},
|
| 449 |
+
{
|
| 450 |
+
"label": "deflect_attack_3_4",
|
| 451 |
+
"subs": [
|
| 452 |
+
[],
|
| 453 |
+
[],
|
| 454 |
+
[],
|
| 455 |
+
[
|
| 456 |
+
"RMB"
|
| 457 |
+
],
|
| 458 |
+
[
|
| 459 |
+
"J"
|
| 460 |
+
],
|
| 461 |
+
[]
|
| 462 |
+
]
|
| 463 |
+
},
|
| 464 |
+
{
|
| 465 |
+
"label": "deflect_attack_3_5",
|
| 466 |
+
"subs": [
|
| 467 |
+
[],
|
| 468 |
+
[],
|
| 469 |
+
[],
|
| 470 |
+
[
|
| 471 |
+
"RMB"
|
| 472 |
+
],
|
| 473 |
+
[],
|
| 474 |
+
[
|
| 475 |
+
"J"
|
| 476 |
+
]
|
| 477 |
+
]
|
| 478 |
+
},
|
| 479 |
+
{
|
| 480 |
+
"label": "deflect_attack_4_5",
|
| 481 |
+
"subs": [
|
| 482 |
+
[],
|
| 483 |
+
[],
|
| 484 |
+
[],
|
| 485 |
+
[],
|
| 486 |
+
[
|
| 487 |
+
"RMB"
|
| 488 |
+
],
|
| 489 |
+
[
|
| 490 |
+
"J"
|
| 491 |
+
]
|
| 492 |
+
]
|
| 493 |
+
},
|
| 494 |
+
{
|
| 495 |
+
"label": "deflect_0_4",
|
| 496 |
+
"subs": [
|
| 497 |
+
[
|
| 498 |
+
"RMB"
|
| 499 |
+
],
|
| 500 |
+
[],
|
| 501 |
+
[],
|
| 502 |
+
[],
|
| 503 |
+
[
|
| 504 |
+
"RMB"
|
| 505 |
+
],
|
| 506 |
+
[]
|
| 507 |
+
]
|
| 508 |
+
},
|
| 509 |
+
{
|
| 510 |
+
"label": "deflect_0_5",
|
| 511 |
+
"subs": [
|
| 512 |
+
[
|
| 513 |
+
"RMB"
|
| 514 |
+
],
|
| 515 |
+
[],
|
| 516 |
+
[],
|
| 517 |
+
[],
|
| 518 |
+
[],
|
| 519 |
+
[
|
| 520 |
+
"RMB"
|
| 521 |
+
]
|
| 522 |
+
]
|
| 523 |
+
},
|
| 524 |
+
{
|
| 525 |
+
"label": "deflect_2_4",
|
| 526 |
+
"subs": [
|
| 527 |
+
[],
|
| 528 |
+
[],
|
| 529 |
+
[
|
| 530 |
+
"RMB"
|
| 531 |
+
],
|
| 532 |
+
[],
|
| 533 |
+
[
|
| 534 |
+
"RMB"
|
| 535 |
+
],
|
| 536 |
+
[]
|
| 537 |
+
]
|
| 538 |
+
},
|
| 539 |
+
{
|
| 540 |
+
"label": "deflect_2_5",
|
| 541 |
+
"subs": [
|
| 542 |
+
[],
|
| 543 |
+
[],
|
| 544 |
+
[
|
| 545 |
+
"RMB"
|
| 546 |
+
],
|
| 547 |
+
[],
|
| 548 |
+
[],
|
| 549 |
+
[
|
| 550 |
+
"RMB"
|
| 551 |
+
]
|
| 552 |
+
]
|
| 553 |
+
},
|
| 554 |
+
{
|
| 555 |
+
"label": "deflect_3_5",
|
| 556 |
+
"subs": [
|
| 557 |
+
[],
|
| 558 |
+
[],
|
| 559 |
+
[],
|
| 560 |
+
[
|
| 561 |
+
"RMB"
|
| 562 |
+
],
|
| 563 |
+
[],
|
| 564 |
+
[
|
| 565 |
+
"RMB"
|
| 566 |
+
]
|
| 567 |
+
]
|
| 568 |
+
},
|
| 569 |
+
{
|
| 570 |
+
"label": "step_alt_0",
|
| 571 |
+
"subs": [
|
| 572 |
+
[
|
| 573 |
+
"Shift"
|
| 574 |
+
],
|
| 575 |
+
[],
|
| 576 |
+
[
|
| 577 |
+
"Shift"
|
| 578 |
+
],
|
| 579 |
+
[],
|
| 580 |
+
[
|
| 581 |
+
"Shift"
|
| 582 |
+
],
|
| 583 |
+
[]
|
| 584 |
+
]
|
| 585 |
+
},
|
| 586 |
+
{
|
| 587 |
+
"label": "step_alt_1",
|
| 588 |
+
"subs": [
|
| 589 |
+
[],
|
| 590 |
+
[
|
| 591 |
+
"Shift"
|
| 592 |
+
],
|
| 593 |
+
[],
|
| 594 |
+
[
|
| 595 |
+
"Shift"
|
| 596 |
+
],
|
| 597 |
+
[],
|
| 598 |
+
[
|
| 599 |
+
"Shift"
|
| 600 |
+
]
|
| 601 |
+
]
|
| 602 |
+
},
|
| 603 |
+
{
|
| 604 |
+
"label": "deflect_2_4_5",
|
| 605 |
+
"subs": [
|
| 606 |
+
[],
|
| 607 |
+
[],
|
| 608 |
+
[
|
| 609 |
+
"RMB"
|
| 610 |
+
],
|
| 611 |
+
[],
|
| 612 |
+
[
|
| 613 |
+
"RMB"
|
| 614 |
+
],
|
| 615 |
+
[
|
| 616 |
+
"RMB"
|
| 617 |
+
]
|
| 618 |
+
]
|
| 619 |
+
},
|
| 620 |
+
{
|
| 621 |
+
"label": "step_0",
|
| 622 |
+
"subs": [
|
| 623 |
+
[
|
| 624 |
+
"Shift"
|
| 625 |
+
],
|
| 626 |
+
[],
|
| 627 |
+
[],
|
| 628 |
+
[],
|
| 629 |
+
[],
|
| 630 |
+
[]
|
| 631 |
+
]
|
| 632 |
+
},
|
| 633 |
+
{
|
| 634 |
+
"label": "step_1",
|
| 635 |
+
"subs": [
|
| 636 |
+
[],
|
| 637 |
+
[
|
| 638 |
+
"Shift"
|
| 639 |
+
],
|
| 640 |
+
[],
|
| 641 |
+
[],
|
| 642 |
+
[],
|
| 643 |
+
[]
|
| 644 |
+
]
|
| 645 |
+
},
|
| 646 |
+
{
|
| 647 |
+
"label": "step_2",
|
| 648 |
+
"subs": [
|
| 649 |
+
[],
|
| 650 |
+
[],
|
| 651 |
+
[
|
| 652 |
+
"Shift"
|
| 653 |
+
],
|
| 654 |
+
[],
|
| 655 |
+
[],
|
| 656 |
+
[]
|
| 657 |
+
]
|
| 658 |
+
},
|
| 659 |
+
{
|
| 660 |
+
"label": "step_3",
|
| 661 |
+
"subs": [
|
| 662 |
+
[],
|
| 663 |
+
[],
|
| 664 |
+
[],
|
| 665 |
+
[
|
| 666 |
+
"Shift"
|
| 667 |
+
],
|
| 668 |
+
[],
|
| 669 |
+
[]
|
| 670 |
+
]
|
| 671 |
+
},
|
| 672 |
+
{
|
| 673 |
+
"label": "step_4",
|
| 674 |
+
"subs": [
|
| 675 |
+
[],
|
| 676 |
+
[],
|
| 677 |
+
[],
|
| 678 |
+
[],
|
| 679 |
+
[
|
| 680 |
+
"Shift"
|
| 681 |
+
],
|
| 682 |
+
[]
|
| 683 |
+
]
|
| 684 |
+
},
|
| 685 |
+
{
|
| 686 |
+
"label": "jump_0",
|
| 687 |
+
"subs": [
|
| 688 |
+
[
|
| 689 |
+
"Space"
|
| 690 |
+
],
|
| 691 |
+
[],
|
| 692 |
+
[],
|
| 693 |
+
[],
|
| 694 |
+
[],
|
| 695 |
+
[]
|
| 696 |
+
]
|
| 697 |
+
},
|
| 698 |
+
{
|
| 699 |
+
"label": "jump_1",
|
| 700 |
+
"subs": [
|
| 701 |
+
[],
|
| 702 |
+
[
|
| 703 |
+
"Space"
|
| 704 |
+
],
|
| 705 |
+
[],
|
| 706 |
+
[],
|
| 707 |
+
[],
|
| 708 |
+
[]
|
| 709 |
+
]
|
| 710 |
+
},
|
| 711 |
+
{
|
| 712 |
+
"label": "jump_2",
|
| 713 |
+
"subs": [
|
| 714 |
+
[],
|
| 715 |
+
[],
|
| 716 |
+
[
|
| 717 |
+
"Space"
|
| 718 |
+
],
|
| 719 |
+
[],
|
| 720 |
+
[],
|
| 721 |
+
[]
|
| 722 |
+
]
|
| 723 |
+
},
|
| 724 |
+
{
|
| 725 |
+
"label": "jump_3",
|
| 726 |
+
"subs": [
|
| 727 |
+
[],
|
| 728 |
+
[],
|
| 729 |
+
[],
|
| 730 |
+
[
|
| 731 |
+
"Space"
|
| 732 |
+
],
|
| 733 |
+
[],
|
| 734 |
+
[]
|
| 735 |
+
]
|
| 736 |
+
},
|
| 737 |
+
{
|
| 738 |
+
"label": "jump_4",
|
| 739 |
+
"subs": [
|
| 740 |
+
[],
|
| 741 |
+
[],
|
| 742 |
+
[],
|
| 743 |
+
[],
|
| 744 |
+
[
|
| 745 |
+
"Space"
|
| 746 |
+
],
|
| 747 |
+
[]
|
| 748 |
+
]
|
| 749 |
+
},
|
| 750 |
+
{
|
| 751 |
+
"label": "jump_5",
|
| 752 |
+
"subs": [
|
| 753 |
+
[],
|
| 754 |
+
[],
|
| 755 |
+
[],
|
| 756 |
+
[],
|
| 757 |
+
[],
|
| 758 |
+
[
|
| 759 |
+
"Space"
|
| 760 |
+
]
|
| 761 |
+
]
|
| 762 |
+
},
|
| 763 |
+
{
|
| 764 |
+
"label": "jump_kick_0",
|
| 765 |
+
"subs": [
|
| 766 |
+
[
|
| 767 |
+
"Space"
|
| 768 |
+
],
|
| 769 |
+
[],
|
| 770 |
+
[
|
| 771 |
+
"Space"
|
| 772 |
+
],
|
| 773 |
+
[],
|
| 774 |
+
[],
|
| 775 |
+
[]
|
| 776 |
+
]
|
| 777 |
+
},
|
| 778 |
+
{
|
| 779 |
+
"label": "jump_kick_1",
|
| 780 |
+
"subs": [
|
| 781 |
+
[],
|
| 782 |
+
[
|
| 783 |
+
"Space"
|
| 784 |
+
],
|
| 785 |
+
[],
|
| 786 |
+
[
|
| 787 |
+
"Space"
|
| 788 |
+
],
|
| 789 |
+
[],
|
| 790 |
+
[]
|
| 791 |
+
]
|
| 792 |
+
},
|
| 793 |
+
{
|
| 794 |
+
"label": "jump_kick_2",
|
| 795 |
+
"subs": [
|
| 796 |
+
[],
|
| 797 |
+
[],
|
| 798 |
+
[
|
| 799 |
+
"Space"
|
| 800 |
+
],
|
| 801 |
+
[],
|
| 802 |
+
[
|
| 803 |
+
"Space"
|
| 804 |
+
],
|
| 805 |
+
[]
|
| 806 |
+
]
|
| 807 |
+
},
|
| 808 |
+
{
|
| 809 |
+
"label": "jump_kick_3",
|
| 810 |
+
"subs": [
|
| 811 |
+
[],
|
| 812 |
+
[],
|
| 813 |
+
[],
|
| 814 |
+
[
|
| 815 |
+
"Space"
|
| 816 |
+
],
|
| 817 |
+
[],
|
| 818 |
+
[
|
| 819 |
+
"Space"
|
| 820 |
+
]
|
| 821 |
+
]
|
| 822 |
+
},
|
| 823 |
+
{
|
| 824 |
+
"label": "jump_attack_0_1",
|
| 825 |
+
"subs": [
|
| 826 |
+
[
|
| 827 |
+
"Space"
|
| 828 |
+
],
|
| 829 |
+
[
|
| 830 |
+
"J"
|
| 831 |
+
],
|
| 832 |
+
[],
|
| 833 |
+
[],
|
| 834 |
+
[],
|
| 835 |
+
[]
|
| 836 |
+
]
|
| 837 |
+
},
|
| 838 |
+
{
|
| 839 |
+
"label": "jump_attack_0_2",
|
| 840 |
+
"subs": [
|
| 841 |
+
[
|
| 842 |
+
"Space"
|
| 843 |
+
],
|
| 844 |
+
[],
|
| 845 |
+
[
|
| 846 |
+
"J"
|
| 847 |
+
],
|
| 848 |
+
[],
|
| 849 |
+
[],
|
| 850 |
+
[]
|
| 851 |
+
]
|
| 852 |
+
},
|
| 853 |
+
{
|
| 854 |
+
"label": "jump_attack_0_3",
|
| 855 |
+
"subs": [
|
| 856 |
+
[
|
| 857 |
+
"Space"
|
| 858 |
+
],
|
| 859 |
+
[],
|
| 860 |
+
[],
|
| 861 |
+
[
|
| 862 |
+
"J"
|
| 863 |
+
],
|
| 864 |
+
[],
|
| 865 |
+
[]
|
| 866 |
+
]
|
| 867 |
+
},
|
| 868 |
+
{
|
| 869 |
+
"label": "jump_attack_1_2",
|
| 870 |
+
"subs": [
|
| 871 |
+
[],
|
| 872 |
+
[
|
| 873 |
+
"Space"
|
| 874 |
+
],
|
| 875 |
+
[
|
| 876 |
+
"J"
|
| 877 |
+
],
|
| 878 |
+
[],
|
| 879 |
+
[],
|
| 880 |
+
[]
|
| 881 |
+
]
|
| 882 |
+
},
|
| 883 |
+
{
|
| 884 |
+
"label": "jump_attack_1_3",
|
| 885 |
+
"subs": [
|
| 886 |
+
[],
|
| 887 |
+
[
|
| 888 |
+
"Space"
|
| 889 |
+
],
|
| 890 |
+
[],
|
| 891 |
+
[
|
| 892 |
+
"J"
|
| 893 |
+
],
|
| 894 |
+
[],
|
| 895 |
+
[]
|
| 896 |
+
]
|
| 897 |
+
},
|
| 898 |
+
{
|
| 899 |
+
"label": "jump_attack_1_4",
|
| 900 |
+
"subs": [
|
| 901 |
+
[],
|
| 902 |
+
[
|
| 903 |
+
"Space"
|
| 904 |
+
],
|
| 905 |
+
[],
|
| 906 |
+
[],
|
| 907 |
+
[
|
| 908 |
+
"J"
|
| 909 |
+
],
|
| 910 |
+
[]
|
| 911 |
+
]
|
| 912 |
+
},
|
| 913 |
+
{
|
| 914 |
+
"label": "jump_attack_2_3",
|
| 915 |
+
"subs": [
|
| 916 |
+
[],
|
| 917 |
+
[],
|
| 918 |
+
[
|
| 919 |
+
"Space"
|
| 920 |
+
],
|
| 921 |
+
[
|
| 922 |
+
"J"
|
| 923 |
+
],
|
| 924 |
+
[],
|
| 925 |
+
[]
|
| 926 |
+
]
|
| 927 |
+
},
|
| 928 |
+
{
|
| 929 |
+
"label": "jump_attack_2_4",
|
| 930 |
+
"subs": [
|
| 931 |
+
[],
|
| 932 |
+
[],
|
| 933 |
+
[
|
| 934 |
+
"Space"
|
| 935 |
+
],
|
| 936 |
+
[],
|
| 937 |
+
[
|
| 938 |
+
"J"
|
| 939 |
+
],
|
| 940 |
+
[]
|
| 941 |
+
]
|
| 942 |
+
},
|
| 943 |
+
{
|
| 944 |
+
"label": "jump_attack_2_5",
|
| 945 |
+
"subs": [
|
| 946 |
+
[],
|
| 947 |
+
[],
|
| 948 |
+
[
|
| 949 |
+
"Space"
|
| 950 |
+
],
|
| 951 |
+
[],
|
| 952 |
+
[],
|
| 953 |
+
[
|
| 954 |
+
"J"
|
| 955 |
+
]
|
| 956 |
+
]
|
| 957 |
+
},
|
| 958 |
+
{
|
| 959 |
+
"label": "jump_attack_3_4",
|
| 960 |
+
"subs": [
|
| 961 |
+
[],
|
| 962 |
+
[],
|
| 963 |
+
[],
|
| 964 |
+
[
|
| 965 |
+
"Space"
|
| 966 |
+
],
|
| 967 |
+
[
|
| 968 |
+
"J"
|
| 969 |
+
],
|
| 970 |
+
[]
|
| 971 |
+
]
|
| 972 |
+
},
|
| 973 |
+
{
|
| 974 |
+
"label": "jump_attack_3_5",
|
| 975 |
+
"subs": [
|
| 976 |
+
[],
|
| 977 |
+
[],
|
| 978 |
+
[],
|
| 979 |
+
[
|
| 980 |
+
"Space"
|
| 981 |
+
],
|
| 982 |
+
[],
|
| 983 |
+
[
|
| 984 |
+
"J"
|
| 985 |
+
]
|
| 986 |
+
]
|
| 987 |
+
},
|
| 988 |
+
{
|
| 989 |
+
"label": "jump_attack_4_5",
|
| 990 |
+
"subs": [
|
| 991 |
+
[],
|
| 992 |
+
[],
|
| 993 |
+
[],
|
| 994 |
+
[],
|
| 995 |
+
[
|
| 996 |
+
"Space"
|
| 997 |
+
],
|
| 998 |
+
[
|
| 999 |
+
"J"
|
| 1000 |
+
]
|
| 1001 |
+
]
|
| 1002 |
+
},
|
| 1003 |
+
{
|
| 1004 |
+
"label": "guard_hold_2",
|
| 1005 |
+
"subs": [
|
| 1006 |
+
[
|
| 1007 |
+
"RMB"
|
| 1008 |
+
],
|
| 1009 |
+
[
|
| 1010 |
+
"RMB"
|
| 1011 |
+
],
|
| 1012 |
+
[],
|
| 1013 |
+
[],
|
| 1014 |
+
[],
|
| 1015 |
+
[]
|
| 1016 |
+
]
|
| 1017 |
+
},
|
| 1018 |
+
{
|
| 1019 |
+
"label": "guard_hold_3",
|
| 1020 |
+
"subs": [
|
| 1021 |
+
[
|
| 1022 |
+
"RMB"
|
| 1023 |
+
],
|
| 1024 |
+
[
|
| 1025 |
+
"RMB"
|
| 1026 |
+
],
|
| 1027 |
+
[
|
| 1028 |
+
"RMB"
|
| 1029 |
+
],
|
| 1030 |
+
[],
|
| 1031 |
+
[],
|
| 1032 |
+
[]
|
| 1033 |
+
]
|
| 1034 |
+
},
|
| 1035 |
+
{
|
| 1036 |
+
"label": "guard_hold_6",
|
| 1037 |
+
"subs": [
|
| 1038 |
+
[
|
| 1039 |
+
"RMB"
|
| 1040 |
+
],
|
| 1041 |
+
[
|
| 1042 |
+
"RMB"
|
| 1043 |
+
],
|
| 1044 |
+
[
|
| 1045 |
+
"RMB"
|
| 1046 |
+
],
|
| 1047 |
+
[
|
| 1048 |
+
"RMB"
|
| 1049 |
+
],
|
| 1050 |
+
[
|
| 1051 |
+
"RMB"
|
| 1052 |
+
],
|
| 1053 |
+
[
|
| 1054 |
+
"RMB"
|
| 1055 |
+
]
|
| 1056 |
+
]
|
| 1057 |
+
},
|
| 1058 |
+
{
|
| 1059 |
+
"label": "guard_hold_late",
|
| 1060 |
+
"subs": [
|
| 1061 |
+
[],
|
| 1062 |
+
[],
|
| 1063 |
+
[],
|
| 1064 |
+
[
|
| 1065 |
+
"RMB"
|
| 1066 |
+
],
|
| 1067 |
+
[
|
| 1068 |
+
"RMB"
|
| 1069 |
+
],
|
| 1070 |
+
[
|
| 1071 |
+
"RMB"
|
| 1072 |
+
]
|
| 1073 |
+
]
|
| 1074 |
+
},
|
| 1075 |
+
{
|
| 1076 |
+
"label": "run",
|
| 1077 |
+
"keys": [
|
| 1078 |
+
"Shift"
|
| 1079 |
+
]
|
| 1080 |
+
},
|
| 1081 |
+
{
|
| 1082 |
+
"label": "heal_0",
|
| 1083 |
+
"subs": [
|
| 1084 |
+
[
|
| 1085 |
+
"Q"
|
| 1086 |
+
],
|
| 1087 |
+
[],
|
| 1088 |
+
[],
|
| 1089 |
+
[],
|
| 1090 |
+
[],
|
| 1091 |
+
[]
|
| 1092 |
+
]
|
| 1093 |
+
},
|
| 1094 |
+
{
|
| 1095 |
+
"label": "heal_2",
|
| 1096 |
+
"subs": [
|
| 1097 |
+
[],
|
| 1098 |
+
[],
|
| 1099 |
+
[
|
| 1100 |
+
"Q"
|
| 1101 |
+
],
|
| 1102 |
+
[],
|
| 1103 |
+
[],
|
| 1104 |
+
[]
|
| 1105 |
+
]
|
| 1106 |
+
},
|
| 1107 |
+
{
|
| 1108 |
+
"label": "heal_4",
|
| 1109 |
+
"subs": [
|
| 1110 |
+
[],
|
| 1111 |
+
[],
|
| 1112 |
+
[],
|
| 1113 |
+
[],
|
| 1114 |
+
[
|
| 1115 |
+
"Q"
|
| 1116 |
+
],
|
| 1117 |
+
[]
|
| 1118 |
+
]
|
| 1119 |
+
},
|
| 1120 |
+
{
|
| 1121 |
+
"label": "revive",
|
| 1122 |
+
"tap": [
|
| 1123 |
+
"R"
|
| 1124 |
+
]
|
| 1125 |
+
},
|
| 1126 |
+
{
|
| 1127 |
+
"label": "lock_toggle",
|
| 1128 |
+
"tap": [
|
| 1129 |
+
"E"
|
| 1130 |
+
]
|
| 1131 |
+
}
|
| 1132 |
+
]
|
| 1133 |
+
}
|
| 1134 |
+
]
|
| 1135 |
+
}
|
environments/games/web/games/sekiro_remake/draw.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Sekiro HUD drawn over the WebGL frame: boss name, deathblow markers and vitality at the top left, posture gauges
|
| 2 |
+
* growing from the centre (boss at the top, Sekiro at the bottom), Sekiro's vitality, resurrection nodes, gourd and
|
| 3 |
+
* ailment gauges at the bottom left, the red perilous kanji above Sekiro, the deathblow mark on the target, the blue lock-on
|
| 4 |
+
* reticle (only while locked) and an edge arrow toward an off-screen boss, native Hz. */
|
| 5 |
+
(function(root){
|
| 6 |
+
'use strict';const M=root.SekiroGame,B=root.Boss3D,clamp=(x,a,b)=>Math.max(a,Math.min(b,x));
|
| 7 |
+
const TIER_NAMES={easy:'Easy',normal:'Normal',hard:'Hard'};
|
| 8 |
+
function font(c,size,weight='',serif=false){c.font=`${weight} ${size}px ${serif?'"Noto Serif SC","Songti SC","SimSun","Microsoft YaHei",serif':'"Segoe UI","Microsoft YaHei",sans-serif'}`;}
|
| 9 |
+
function text(c,s,x,y,size,color,align='left',o={}){font(c,size,o.weight||'',o.serif);c.textAlign=align;c.textBaseline='alphabetic';
|
| 10 |
+
if(o.glow){c.shadowColor=o.glow;c.shadowBlur=o.blur||12;}c.fillStyle='rgba(6,8,10,.75)';c.fillText(s,x+1,y+1.5);c.fillStyle=color;c.fillText(s,x,y);c.shadowBlur=0;}
|
| 11 |
+
function bar(c,x,y,w,h,v,fill,back='rgba(10,12,14,.72)'){c.fillStyle=back;c.fillRect(x,y,w,h);c.fillStyle=fill;c.fillRect(x+1,y+1,Math.max(0,(w-2)*clamp(v,0,1)),h-2);
|
| 12 |
+
c.strokeStyle='rgba(220,205,170,.55)';c.lineWidth=1;c.strokeRect(x+.5,y+.5,w-1,h-1);}
|
| 13 |
+
// Posture grows outward from the middle; it turns hotter as it nears a break and darker while low vitality slows recovery.
|
| 14 |
+
function posture(c,cx,y,w,h,v,slow,flash){if(v<=0.002)return;const half=w/2*clamp(v,0,1);c.fillStyle='rgba(10,10,12,.7)';c.fillRect(cx-w/2,y,w,h);
|
| 15 |
+
const hot=v>.85&&flash,col=hot?'#ff4f1f':v>.6?'#f08a2a':'#e6b143';const g=c.createLinearGradient(cx-half,0,cx+half,0);g.addColorStop(0,col);g.addColorStop(.5,'#ffe5a0');g.addColorStop(1,col);
|
| 16 |
+
c.fillStyle=g;c.fillRect(cx-half,y+1,half*2,h-2);if(slow){c.fillStyle='rgba(120,20,10,.35)';c.fillRect(cx-half,y+1,half*2,h-2);}
|
| 17 |
+
c.fillStyle='rgba(255,240,200,.9)';c.fillRect(cx-1,y-2,2,h+4);c.strokeStyle='rgba(230,200,150,.5)';c.strokeRect(cx-w/2+.5,y+.5,w-1,h-1);}
|
| 18 |
+
function dot(c,x,y,r,full,color){c.beginPath();c.arc(x,y,r,0,Math.PI*2);c.fillStyle=full?color:'rgba(30,26,26,.85)';c.fill();c.lineWidth=1.5;c.strokeStyle=full?'rgba(255,190,170,.9)':'rgba(140,120,118,.8)';c.stroke();}
|
| 19 |
+
// Lock-on aids, drawn in 2D over the frame so walls and pillars never hide them (as zelda_oot_remake/draw.js reticle / edgeArrow).
|
| 20 |
+
// Cool blue, so the lock never reads as the red deathblow dot or the red perilous kanji; the ring sits at the deathblow height and circles that dot.
|
| 21 |
+
const LOCK='#8fdcff',PI2=Math.PI*2;
|
| 22 |
+
function reticle(c,x,y,r,a,dot){c.save();c.translate(x,y);c.lineWidth=4;c.strokeStyle='rgba(8,12,20,.85)';c.beginPath();c.arc(0,0,r,0,PI2);c.stroke();
|
| 23 |
+
c.lineWidth=2;c.strokeStyle=LOCK;c.beginPath();c.arc(0,0,r,0,PI2);c.stroke();
|
| 24 |
+
for(let i=0;i<4;i++){c.save();c.rotate(a+i*PI2/4);c.beginPath();c.moveTo(0,-r-2);c.lineTo(-5,-r-11);c.lineTo(5,-r-11);c.closePath();c.fillStyle=LOCK;c.fill();c.lineWidth=1.2;c.strokeStyle='rgba(8,12,20,.85)';c.stroke();c.restore();}
|
| 25 |
+
if(dot){c.beginPath();c.arc(0,0,3,0,PI2);c.fillStyle=LOCK;c.fill();c.lineWidth=1.2;c.strokeStyle='rgba(8,12,20,.85)';c.stroke();}c.restore();}
|
| 26 |
+
function edgeArrow(c,ax,ay,col,label){const m=36,k=Math.min((427-m)/Math.max(1e-6,Math.abs(ax)),(240-m)/Math.max(1e-6,Math.abs(ay))),x=427+ax*k,y=240+ay*k,a=Math.atan2(ay,ax);
|
| 27 |
+
c.save();c.translate(x,y);c.rotate(a);c.beginPath();c.moveTo(18,0);c.lineTo(-10,-13);c.lineTo(-4,0);c.lineTo(-10,13);c.closePath();c.fillStyle=col;c.fill();c.lineWidth=2.5;c.strokeStyle='rgba(8,12,20,.92)';c.stroke();c.restore();
|
| 28 |
+
text(c,label,x-Math.cos(a)*30,y-Math.sin(a)*30+5,12,col,'center');}
|
| 29 |
+
function gourd(c,x,y){c.fillStyle='#9a5a28';c.beginPath();c.arc(x,y+5,6.5,0,Math.PI*2);c.arc(x,y-4,4.5,0,Math.PI*2);c.fill();c.fillStyle='#d9b56a';c.fillRect(x-1.5,y-12,3,4);c.fillStyle='rgba(255,240,200,.3)';c.beginPath();c.arc(x-2,y+3,2,0,Math.PI*2);c.fill();}
|
| 30 |
+
M.draw=function(g,c){const scene=B.render('sekiro',g,c),p=g.player,b=g.boss,kind=g.kind||'genichiro',K=M.bosses[kind],tm=g.t/M.hz;
|
| 31 |
+
// ---- boss: deathblow markers, name and vitality (top left)
|
| 32 |
+
const [shown,left]=K.markers(b),name=K.names[Math.min(K.names.length-1,(b.phase||1)-1)];
|
| 33 |
+
for(let i=0;i<shown;i++)dot(c,34+i*19,30,6.5,i<left,'#d23a2c');
|
| 34 |
+
text(c,name,34+shown*19+4,36,18,'#eee4cf','left',{serif:true});
|
| 35 |
+
bar(c,30,44,300,6,b.state==='dead'?0:(b.hp||0)/(b.maxHp||1),'#c8402f');
|
| 36 |
+
// ---- boss posture (top centre)
|
| 37 |
+
const regenSlow=(b.hp||0)/(b.maxHp||1)<.8;posture(c,427,62,330,7,(b.posture||0)/(b.maxPosture||1),regenSlow,Math.floor(g.t/6)%2===0);
|
| 38 |
+
// ---- Sekiro: resurrection nodes, vitality, ailments, gourd (bottom left); posture (bottom centre)
|
| 39 |
+
const lives=p.nodes??0;for(let i=0;i<2;i++){dot(c,36+i*17,410,5.5,i<lives,p.resurrectionLocked?'#7f6a78':'#e08aa0');}
|
| 40 |
+
if(p.resurrectionLocked&&lives>0){c.strokeStyle='#1a1214';c.lineWidth=3;c.beginPath();c.moveTo(30,414);c.lineTo(62,405);c.stroke();text(c,'Resurrection sealed',70,414,11,'#c9b0bb');}
|
| 41 |
+
bar(c,30,422,236,8,(p.hp||0)/(p.maxHp||1),p.poisoned>0?'#7d9a3a':'#c7392f');
|
| 42 |
+
let gy=416;for(const [v,label,col] of [[p.poison||0,'Poison',p.poisoned>0?'#a8d050':'#7da040'],[p.terror||0,'Terror','#9b1a2a'],...(p.burn!==undefined?[[p.burning>0?100:p.burn,'Burn',p.burning>0?'#ff7a2a':'#d4602a']]:[])]){if(v<=0.5&&!(label==='Poison'&&p.poisoned>0))continue;gy-=13;text(c,label,272,gy+8,11,col);bar(c,286,gy,70,6,label==='Poison'&&p.poisoned>0?1:v/100,col);}
|
| 43 |
+
gourd(c,40,452);text(c,'× '+(p.gourds??0),52,458,14,'#e8d9b8');
|
| 44 |
+
posture(c,427,446,300,7,(p.posture||0)/(p.maxPosture||100),(p.hp||0)/(p.maxHp||1)<.5,Math.floor(g.t/6)%2===0);
|
| 45 |
+
// ---- perilous kanji above Sekiro, deathblow mark on the target
|
| 46 |
+
if(scene&&b.perilous&&b.telegraph&&!p.dead){const s=scene.project(p.x,(p.y||0)+2.05,p.z),pulse=1+.08*Math.sin(g.t*.5);
|
| 47 |
+
c.save();c.globalAlpha=.85;const rg=c.createRadialGradient(s.x,s.y-14,2,s.x,s.y-14,36*pulse);rg.addColorStop(0,'rgba(255,40,20,.55)');rg.addColorStop(1,'rgba(255,40,20,0)');c.fillStyle=rg;c.fillRect(s.x-40,s.y-56,80,84);c.restore();
|
| 48 |
+
text(c,'PERIL',s.x,s.y,Math.round(40*pulse),'#ff3b26','center',{weight:'bold',serif:true,glow:'rgba(255,40,10,.9)',blur:14});}
|
| 49 |
+
// Lock reticle while locked; when the boss is out of the picture (behind the camera, or past an edge) an arrow at the edge points to it.
|
| 50 |
+
if(scene&&b.state!=='dead'&&!g.outcome&&!p.dead){const h=kind==='ape'?2.1:kind==='gyoubu'?2.7:kind==='demon'?3.6:1.2,s=scene.project(b.x,(b.y||0)+h,b.z),on=s.visible&&s.x>8&&s.x<846&&s.y>8&&s.y<472;
|
| 51 |
+
if(on&&g.lockOn)reticle(c,s.x,s.y,20,g.t*.04,!b.deathblowAvailable);
|
| 52 |
+
else if(!on){const yaw=g.cameraYaw||0,dx=b.x-p.x,dz=b.z-p.z,right=-dx*Math.cos(yaw)+dz*Math.sin(yaw),ahead=dx*Math.sin(yaw)+dz*Math.cos(yaw);
|
| 53 |
+
// In front: the projected direction; behind the camera the projection flips, so use the camera frame (screen-right, and down for behind).
|
| 54 |
+
const [ax,ay]=s.visible&&ahead>0?[s.x-427,s.y-240]:[right,-ahead];edgeArrow(c,ax,ay,g.lockOn?LOCK:'#ffcf8a',g.lockOn?'Lock':'Boss');}}
|
| 55 |
+
if(scene&&b.deathblowAvailable){const h=kind==='ape'?2.1:kind==='gyoubu'?2.7:kind==='demon'?3.6:1.2,s=scene.project(b.x,(b.y||0)+h,b.z),r=7+Math.sin(g.t*.25)*1.5;
|
| 56 |
+
c.beginPath();c.arc(s.x,s.y,r+7,0,Math.PI*2);c.strokeStyle='rgba(255,60,40,.5)';c.lineWidth=2;c.stroke();c.beginPath();c.arc(s.x,s.y,r,0,Math.PI*2);c.fillStyle='#e0261c';c.shadowColor='#ff3020';c.shadowBlur=12;c.fill();c.shadowBlur=0;}
|
| 57 |
+
if(p.lightning>0&&!p.dead){const s=scene?scene.project(p.x,(p.y||0)+2.2,p.z):{x:427,y:200};text(c,'Lightning strike',s.x,s.y,20,'#ffe39a','center',{weight:'bold',glow:'rgba(255,220,120,.9)'});}
|
| 58 |
+
// ---- Shinobi Execution banner (the guardian ape's first one is a deception, S14)
|
| 59 |
+
const banner=(b.executing>0&&(b.phase===b.bars||kind==='ape'))||g.outcome==='win'||(b.state==='dead'&&(b.deadTicks||0)>110);
|
| 60 |
+
if(banner){const u=g.outcome==='win'?1:clamp(b.state==='dead'?((b.deadTicks||0)-110)/40:(58-(b.executing||0))/14,0,1);c.save();c.globalAlpha=u;
|
| 61 |
+
c.fillStyle='rgba(0,0,0,.35)';c.fillRect(0,196,854,92);text(c,'DEATHBLOW',427,262,62,'#e9e2d2','center',{weight:'bold',serif:true,glow:'rgba(180,20,20,.9)',blur:18});
|
| 62 |
+
text(c,kind==='isshin'?'FINAL EXECUTION':'EXECUTION',427,282,12,'#c9b9a0','center');c.restore();}
|
| 63 |
+
if(p.dead&&!g.outcome){c.fillStyle='rgba(30,0,0,.28)';c.fillRect(0,0,854,480);text(c,'DEAD',427,252,92,'#c7261e','center',{weight:'bold',serif:true,glow:'rgba(200,0,0,.8)',blur:20});
|
| 64 |
+
text(c,p.terrorDeath?'Killed by terror · Cannot resurrect':lives>0&&!p.resurrectionLocked?'Press R to resurrect':'Cannot resurrect',427,296,17,'#efe0d1','center');}
|
| 65 |
+
// ---- clock, tier and native rate (bottom right)
|
| 66 |
+
const tierName=Object.entries(M.tiers).find(([,v])=>Math.abs(v-g.d)<1e-9)?.[0];
|
| 67 |
+
text(c,`${M.hz}Hz`,826,442,13,'#e8c983','right',{weight:'bold'});text(c,(tierName?TIER_NAMES[tierName]+' · ':'d='+(+g.d).toFixed(2)+' · ')+tm.toFixed(1)+'s',826,460,12,'#d6d2c6','right');
|
| 68 |
+
};
|
| 69 |
+
M.renderStatus=ctx=>B.status('sekiro',ctx);M.renderMetrics=ctx=>B.metrics('sekiro',ctx);M.closeRenderer=ctx=>B.close('sekiro',ctx);
|
| 70 |
+
})(window);
|
environments/games/web/games/sekiro_remake/game.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
environments/games/web/games/sekiro_remake/index.html
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="data:,"><title>Sekiro · Six Bosses</title><link rel="stylesheet" href="style3d.css"></head><body><main>
|
| 2 |
+
<header><div><div class="eyebrow">Sekiro · Shadows Die Twice</div><h1>Sekiro · Six Bosses</h1><p>Face six foes: a bow-and-blade swordsman, a deceptive guardian ape, an illusion-wielding shinobi, a sword-and-spear master, a mounted general, and a flame behemoth. Read their attacks and break their posture.</p></div><a href="../../index.html">Back to Game Lobby ↗</a></header>
|
| 3 |
+
<div class="layout"><section><div class="stage"><canvas width="854" height="480" tabindex="0" aria-label="Sekiro 3D battle screen"></canvas><div id="overlay"><div><strong>Are You Ready?</strong><span>Click Start Challenge</span></div></div><div class="toolbar"><button id="start" class="primary">Start Challenge / Restart</button><button id="pause">Resume</button><button id="step">Step</button><button id="demo">Verify Script</button><button id="sample">Winning Replay</button></div></div>
|
| 4 |
+
<div class="mobile"><button data-key="W">↑</button><button data-key="A">←</button><button data-key="S">↓</button><button data-key="D">→</button><button data-key="J">Attack</button><button data-key="K">Block</button><button data-key="Shift">Dodge</button><button data-key="Space">Jump</button><button data-key="Q">Heal</button><button data-key="E">Lock</button><button data-key="R">Resurrect</button></div><p id="status" role="status"></p><div class="toolbar record-toolbar"><button id="export">Export Current Replay</button><button id="import">Import and Replay</button><input id="file" type="file" accept=".json,application/json"></div><p class="note">Verify Script reads game state to check the mechanics. Replays save real inputs and simulate the full battle again.</p></section>
|
| 5 |
+
<aside><div><h2>Challenge Settings</h2><label for="case">Boss</label><select id="case"></select><label for="seed">Seed</label><input id="seed" type="number" min="0" max="4294967295" step="1" value="1"></div><div><label for="difficulty">Difficulty Tier</label><select id="difficulty"><option value="0.2">Easy</option><option value="0.5" selected>Normal</option><option value="0.8">Hard</option></select><p class="note">After starting, click the screen to lock the mouse; move it to turn the camera. Left click attacks, right click blocks, and E locks onto the boss. Esc unlocks the mouse and pauses; click the screen to resume and relock. If pointer lock is unavailable, hold a mouse button and drag to turn the camera.</p></div><dl></dl></aside></div>
|
| 6 |
+
<footer></footer></main>
|
| 7 |
+
<script src="../_native/runtime.js"></script><script src="../_boss3d/vendor/three.min.js"></script><script src="renderer3d.js"></script><script src="game.js"></script><script src="draw.js"></script><script>window.GAME_MODULE=SekiroGame;</script><script src="app3d.js"></script></body></html>
|
environments/games/web/games/sekiro_remake/manifest.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/game-manifest@1",
|
| 3 |
+
"engine": "independent",
|
| 4 |
+
"game": "sekiro_remake",
|
| 5 |
+
"module": "SekiroGame",
|
| 6 |
+
"title": "Sekiro: Archer Swordsman / Valley Ape / Thread Ninja / Veteran Swordsman / Mounted Spearman / Blazing Beast",
|
| 7 |
+
"dimension": "3d",
|
| 8 |
+
"native_hz": 60,
|
| 9 |
+
"max_seconds": 300,
|
| 10 |
+
"renderer": "webgl-boss3d",
|
| 11 |
+
"rules": "sekiro@12",
|
| 12 |
+
"cases": [
|
| 13 |
+
"sekiro/genichiro",
|
| 14 |
+
"sekiro/guardian_ape",
|
| 15 |
+
"sekiro/lady_butterfly",
|
| 16 |
+
"sekiro/isshin",
|
| 17 |
+
"sekiro/gyoubu",
|
| 18 |
+
"sekiro/demon"
|
| 19 |
+
],
|
| 20 |
+
"scripts": [
|
| 21 |
+
"_native/runtime.js",
|
| 22 |
+
"_boss3d/vendor/three.min.js",
|
| 23 |
+
"sekiro_remake/renderer3d.js",
|
| 24 |
+
"sekiro_remake/game.js",
|
| 25 |
+
"sekiro_remake/draw.js"
|
| 26 |
+
],
|
| 27 |
+
"sim_scripts": [
|
| 28 |
+
"_native/runtime.js",
|
| 29 |
+
"sekiro_remake/game.js"
|
| 30 |
+
],
|
| 31 |
+
"play_page": "web/games/sekiro_remake/index.html",
|
| 32 |
+
"scripted_controller": "SekiroGame.scripted(game) -> {holds:[6 key arrays], mouse:[dx,dy,dz]} (deep-copy lookahead, deterministic; .oracle is an alias)"
|
| 33 |
+
}
|
environments/games/web/games/sekiro_remake/renderer3d.js
ADDED
|
@@ -0,0 +1,666 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Sekiro renderer: original low-poly Three.js art (r160, MIT, vendored under _boss3d/vendor). Characters are rigid
|
| 2 |
+
* skinned meshes (one draw call each) posed from the simulation's action clocks; arenas are merged static meshes.
|
| 3 |
+
* Rendering is a pure function of the game state: it never writes game state and never draws from the game RNG. */
|
| 4 |
+
(function(root){
|
| 5 |
+
'use strict';
|
| 6 |
+
const T=root.THREE,B=root.Boss3D={};
|
| 7 |
+
if(!T)throw Error('Offline Three.js renderer library is missing');
|
| 8 |
+
const byCanvas=new WeakMap(),clamp=(x,a,b)=>Math.max(a,Math.min(b,x)),lerp=(a,b,u)=>a+(b-a)*u,
|
| 9 |
+
smooth=u=>{u=clamp(u,0,1);return u*u*(3-2*u);},band=(t,a,b)=>smooth((t-a)/(b-a)),v3=(x,y,z)=>new T.Vector3(x,y,z),items=a=>Array.isArray(a)?a:[];
|
| 10 |
+
const M4=(x=0,y=0,z=0,rx=0,ry=0,rz=0,sx=1,sy=sx,sz=sx)=>new T.Matrix4().compose(v3(x,y,z),new T.Quaternion().setFromEuler(new T.Euler(rx,ry,rz)),v3(sx,sy,sz));
|
| 11 |
+
const MY=(x,y,z,yaw,pitch,sx,sy,sz)=>new T.Matrix4().compose(v3(x,y,z),new T.Quaternion().setFromEuler(new T.Euler(pitch,yaw,0,'YXZ')),v3(sx,sy,sz));
|
| 12 |
+
function hash(a,b=0){let n=Math.imul(a|0,374761393)^Math.imul(b|0,668265263);n=Math.imul(n^(n>>>13),1274126177);return ((n^(n>>>16))>>>0)/4294967296;}
|
| 13 |
+
// Template primitives, used only on the CPU while merging (never uploaded).
|
| 14 |
+
const P={box:new T.BoxGeometry(1,1,1),ball:new T.IcosahedronGeometry(1,1),gem:new T.IcosahedronGeometry(1,0),oct:new T.OctahedronGeometry(1,0),
|
| 15 |
+
cyl:(rt,rb,h,s=7)=>new T.CylinderGeometry(rt,rb,h,s,1),cone:(r,h,s=7)=>new T.ConeGeometry(r,h,s,1),disc:new T.CylinderGeometry(1,1,1,12,1)};
|
| 16 |
+
// Mesher: merges primitives with per-face colours (slight jitter gives faceted fabric/fur/stone) and optional bone index.
|
| 17 |
+
class Mesher{
|
| 18 |
+
constructor(){this.p=[];this.c=[];this.k=[];}
|
| 19 |
+
add(geo,color,m,bone=0,jitter=0){const g=geo.index?geo.toNonIndexed():geo.clone();g.applyMatrix4(m);const a=g.attributes.position.array,base=new T.Color(color),col=new T.Color();
|
| 20 |
+
for(let i=0;i<a.length;i+=9){const j=jitter?(hash(this.p.length+i,7)-.5)*jitter:0;col.copy(base).offsetHSL(0,0,j);
|
| 21 |
+
for(let v=0;v<9;v+=3){this.p.push(a[i+v],a[i+v+1],a[i+v+2]);this.c.push(col.r,col.g,col.b);this.k.push(bone);}}
|
| 22 |
+
g.dispose();return this;}
|
| 23 |
+
geometry(skinned){const g=new T.BufferGeometry(),n=this.p.length/3;g.setAttribute('position',new T.Float32BufferAttribute(this.p,3));g.setAttribute('color',new T.Float32BufferAttribute(this.c,3));
|
| 24 |
+
if(skinned){const idx=new Uint16Array(n*4),w=new Float32Array(n*4);for(let i=0;i<n;i++){idx[i*4]=this.k[i];w[i*4]=1;}g.setAttribute('skinIndex',new T.Uint16BufferAttribute(idx,4));g.setAttribute('skinWeight',new T.Float32BufferAttribute(w,4));}
|
| 25 |
+
g.computeVertexNormals();g.computeBoundingSphere();return g;}
|
| 26 |
+
}
|
| 27 |
+
const seg=(len,r0,r1,s=7)=>{const g=P.cyl(r0,r1,len,s);g.translate(0,-len/2,0);return g;};
|
| 28 |
+
function canvasTexture(size,paint,repeat=1){const c=document.createElement('canvas');c.width=c.height=size;paint(c.getContext('2d'),size);const t=new T.CanvasTexture(c);t.colorSpace=T.SRGBColorSpace;t.wrapS=t.wrapT=T.RepeatWrapping;t.repeat.set(repeat,repeat);t.anisotropy=4;return t;}
|
| 29 |
+
function glowTexture(){return canvasTexture(64,(q,s)=>{const g=q.createRadialGradient(s/2,s/2,0,s/2,s/2,s/2);for(let i=0;i<=16;i++){const r=i/16,v=(r<.25?1-r*1.8:.55*(1-r)/.75)*(1-r*r*r*r);g.addColorStop(r,'rgba(255,255,255,'+v.toFixed(4)+')');}q.fillStyle=g;q.fillRect(0,0,s,s);});}
|
| 30 |
+
|
| 31 |
+
/* ------------------------------------------------------------------ humanoid rig */
|
| 32 |
+
const HUMAN=[['root',null,[0,0,0]],['hips','root',[0,.94,0]],['spine','hips',[0,.12,0]],['chest','spine',[0,.22,0]],['neck','chest',[0,.24,0]],['head','neck',[0,.08,0]],
|
| 33 |
+
['lSh','chest',[.2,.17,0]],['lEl','lSh',[0,-.29,0]],['lWr','lEl',[0,-.25,0]],['rSh','chest',[-.2,.17,0]],['rEl','rSh',[0,-.29,0]],['rWr','rEl',[0,-.25,0]],
|
| 34 |
+
['lHip','hips',[.1,-.03,0]],['lKnee','lHip',[0,-.44,0]],['lAnk','lKnee',[0,-.42,0]],['rHip','hips',[-.1,-.03,0]],['rKnee','rHip',[0,-.44,0]],['rAnk','rKnee',[0,-.42,0]],
|
| 35 |
+
['blade','rWr',[0,-.07,.02]],['scab','hips',[.17,.02,-.04]],['tool','lWr',[0,-.06,.03]],['back','chest',[0,.06,-.16]],['tail','head',[0,.1,-.1]],['armor','chest',[0,0,0]],['skirt','hips',[0,0,0]],['sodeL','lSh',[0,0,0]],['sodeR','rSh',[0,0,0]]];
|
| 36 |
+
function rig(bonesSpec){const bones={},list=[];for(const [name,parent,o] of bonesSpec){const b=new T.Bone();b.name=name;b.position.set(...o);if(parent)bones[parent].add(b);bones[name]=b;list.push(b);}
|
| 37 |
+
list[0].updateMatrixWorld(true);return {bones,list};}
|
| 38 |
+
function skinned(scene,r,build,{scale=1,roughness=.82,metalness=.05,shadow=true}={}){const m=new Mesher(),idx=n=>r.list.indexOf(r.bones[n]);
|
| 39 |
+
build((bone,geo,color,mat,jitter=0)=>{const bm=r.bones[bone].matrixWorld;m.add(geo,color,new T.Matrix4().multiplyMatrices(bm,mat),idx(bone),jitter);});
|
| 40 |
+
const geo=scene.keep(m.geometry(true)),mat=scene.keep(new T.MeshStandardMaterial({vertexColors:true,flatShading:true,roughness,metalness}));
|
| 41 |
+
const mesh=new T.SkinnedMesh(geo,mat);mesh.add(r.list[0]);mesh.updateMatrixWorld(true);mesh.bind(new T.Skeleton(r.list));mesh.frustumCulled=false;mesh.castShadow=shadow;mesh.receiveShadow=false;
|
| 42 |
+
const holder=new T.Group();holder.add(mesh);holder.scale.setScalar(scale);return {holder,mesh,bones:r.bones,mat};}
|
| 43 |
+
// Shared limb kit for the three humans.
|
| 44 |
+
function limbs(add,c){
|
| 45 |
+
add('lSh',seg(.3,.072,.06),c.sleeveL,M4(),.06);add('rSh',seg(.3,.072,.06),c.sleeveR,M4(),.06);
|
| 46 |
+
add('lEl',seg(.26,.058,.046),c.foreL,M4(),.04);add('rEl',seg(.26,.058,.046),c.foreR,M4(),.04);
|
| 47 |
+
add('lWr',P.ball,c.handL,M4(0,-.05,0,0,0,0,.05,.065,.045));add('rWr',P.ball,c.handR,M4(0,-.05,0,0,0,0,.05,.065,.045));
|
| 48 |
+
for(const s of ['l','r']){add(s+'Hip',seg(.45,c.thighR||.1,c.thighR2||.085),c.thigh,M4(),.05);add(s+'Knee',seg(.42,.07,.055),c.shin,M4(),.04);
|
| 49 |
+
add(s+'Ank',P.box,c.foot,M4(0,-.05,.06,0,0,0,.1,.07,.24),.03);}
|
| 50 |
+
}
|
| 51 |
+
function katana(add,bone,steel=0xd9dde2){add(bone,P.box,0x17171a,M4(0,.1,0,0,0,0,.032,.24,.032));add(bone,P.disc,0x2a2622,M4(0,-.025,0,0,0,0,.06,.018,.06));
|
| 52 |
+
add(bone,P.box,steel,M4(0,-.5,0,0,0,0,.012,.92,.034));add(bone,P.cone(.018,.07,4),steel,M4(0,-.995,0,Math.PI,0,0,1,1,.5));}
|
| 53 |
+
function sekiroModel(scene){const r=rig(HUMAN),c={sleeveL:0x3a3631,sleeveR:0x403b35,foreL:0x6e5b3a,foreR:0x3b3733,handL:0x4a4a4f,handR:0xb89377,thigh:0x3c3833,shin:0x9a9182,foot:0x2a2622,thighR:.12,thighR2:.115};
|
| 54 |
+
return skinned(scene,r,add=>{
|
| 55 |
+
add('hips',P.box,0x37332e,M4(0,-.02,0,0,0,0,.34,.18,.22),.04);add('spine',P.box,0x2f2c29,M4(0,.04,0,0,0,0,.32,.16,.2),.04);add('spine',P.box,0x1e1c1b,M4(0,.0,0,0,0,0,.34,.06,.22));
|
| 56 |
+
add('chest',P.box,0x403a33,M4(0,.1,0,0,0,0,.4,.3,.23),.05);add('chest',P.box,0x8b8476,M4(.05,.16,.112,0,0,.5,.05,.24,.02));add('chest',P.box,0x8b8476,M4(-.05,.16,.112,0,0,-.5,.05,.24,.02));
|
| 57 |
+
// ash scarf wrapped at the neck, its tail streaming behind
|
| 58 |
+
add('chest',P.cyl(.14,.17,.13,8),0xa69f92,M4(0,.27,-.01),.08);add('back',P.box,0xa69f92,M4(.06,-.14,0,.25,0,.15,.12,.34,.025),.08);add('back',P.box,0x989183,M4(-.04,-.22,-.02,.35,0,-.1,.09,.38,.02),.08);
|
| 59 |
+
add('neck',P.cyl(.05,.055,.1,6),0xb08c70,M4(0,.03,0));add('head',P.ball,0xb89377,M4(0,.1,.01,0,0,0,.1,.12,.105),.03);
|
| 60 |
+
add('head',P.ball,0x1c1917,M4(0,.165,-.04,0,0,0,.108,.085,.1),.06);add('head',P.box,0x1c1917,M4(0,.12,-.085,0,0,0,.17,.12,.06),.06);add('head',P.box,0x1c1917,M4(0,.22,-.07,-.5,0,0,.08,.1,.06),.06);add('tail',P.cone(.045,.22,5),0x1c1917,M4(0,.04,-.04,-2.2,0,0),.06);
|
| 61 |
+
add('head',P.box,0x241d1a,M4(.035,.115,.105,0,0,0,.028,.012,.01));add('head',P.box,0x241d1a,M4(-.035,.115,.105,0,0,0,.028,.012,.01));
|
| 62 |
+
limbs(add,c);
|
| 63 |
+
// Shinobi prosthetic: brass and iron bands over the left forearm
|
| 64 |
+
for(let i=0;i<3;i++)add('lEl',P.cyl(.064,.064,.03,8),i%2?0x4b4c52:0x8d7442,M4(0,-.06-i*.07,0));
|
| 65 |
+
katana(add,'blade');add('scab',P.box,0x141416,M4(0,0,0,0,0,0,.035,.9,.045),0);add('tool',P.ball,0x8a5a2b,M4(0,-.04,.02,0,0,0,.06,.08,.06));
|
| 66 |
+
},{roughness:.86});}
|
| 67 |
+
function genichiroModel(scene){const r=rig(HUMAN),c={sleeveL:0xd4d0c6,sleeveR:0xd4d0c6,foreL:0x23232a,foreR:0x23232a,handL:0xb68c71,handR:0xb68c71,thigh:0x1b1b20,shin:0x26262c,foot:0x161618,thighR:.115,thighR2:.105};
|
| 68 |
+
return skinned(scene,r,add=>{
|
| 69 |
+
add('hips',P.box,0x1d1d22,M4(0,-.02,0,0,0,0,.35,.18,.23),.03);add('spine',P.box,0xd6d1c4,M4(0,.04,0,0,0,0,.32,.16,.2),.03);add('spine',P.box,0x2a2730,M4(0,0,0,0,0,0,.34,.06,.22));
|
| 70 |
+
add('chest',P.box,0xd6d1c4,M4(0,.1,0,0,0,0,.39,.3,.23),.03);add('chest',P.box,0x1d1d22,M4(0,.13,.115,0,0,0,.08,.22,.01));
|
| 71 |
+
add('neck',P.cyl(.05,.056,.1,6),0xb38a6f,M4(0,.03,0));add('head',P.ball,0xb68c71,M4(0,.1,.01,0,0,0,.1,.125,.105),.03);
|
| 72 |
+
add('head',P.ball,0x121214,M4(0,.165,-.045,0,0,0,.11,.085,.1),.05);add('head',P.box,0x121214,M4(0,.11,-.09,0,0,0,.18,.13,.06),.05);add('tail',P.box,0x121214,M4(0,-.1,-.02,.3,0,0,.06,.32,.04),.05);
|
| 73 |
+
add('head',P.box,0x2a1d1a,M4(.035,.115,.105,0,0,0,.03,.012,.01));add('head',P.box,0x2a1d1a,M4(-.035,.115,.105,0,0,0,.03,.012,.01));
|
| 74 |
+
limbs(add,c);katana(add,'blade');add('scab',P.box,0x101012,M4(0,0,0,0,0,0,.036,.92,.046));
|
| 75 |
+
// black lacquered armour with crimson lacing (removed for the Way of Tomoe)
|
| 76 |
+
add('armor',P.box,0x18181c,M4(0,.1,.005,0,0,0,.43,.31,.26),.04);add('armor',P.box,0x18181c,M4(0,.27,.0,0,0,0,.36,.06,.24),.04);
|
| 77 |
+
for(let i=0;i<4;i++)add('armor',P.box,0x8a2424,M4(0,-.01+i*.075,.133,0,0,0,.41,.014,.004));
|
| 78 |
+
for(const [bone,s] of [['sodeL',1],['sodeR',-1]])for(let i=0;i<3;i++)add(bone,P.box,i%2?0x22222a:0x18181c,M4(s*.07,-.04-i*.075,0,0,0,s*.25,.05,.09,.24),.03),add(bone,P.box,0x8a2424,M4(s*.095,-.08-i*.075,0,0,0,s*.25,.004,.012,.24));
|
| 79 |
+
for(const [x,z,ry] of [[0,.12,0],[0,-.12,0],[.15,0,1.57],[-.15,0,1.57]])for(let i=0;i<2;i++)add('skirt',P.box,i?0x7c2222:0x18181c,M4(x,-.14-i*.1,z,ry?0:(z>0?-.12:.12),ry,ry?(x>0?.12:-.12):0,.2,i?.012:.12,.03));
|
| 80 |
+
// the great bow: in the left hand for shots, slung across the back otherwise
|
| 81 |
+
for(const bone of ['tool','back'])for(let i=-5;i<=5;i++){const a=i*.19,y=Math.sin(a)*.75,z=(Math.cos(a)-1)*.22;add(bone,P.box,0x221a14,M4(0,y+(bone==='back'?.05:0),z,-a,0,0,.022,.15,.03));}
|
| 82 |
+
add('tool',P.box,0xe8e2d4,M4(0,0,-.26,0,0,0,.004,1.45,.004));
|
| 83 |
+
},{roughness:.6,metalness:.15});}
|
| 84 |
+
function isshinModel(scene){const r=rig([...HUMAN,['spear','rWr',[0,-.07,.02]],['gun','rWr',[0,-.07,.02]]]),c={sleeveL:0xc9c3b4,sleeveR:0xc9c3b4,foreL:0xa98a6e,foreR:0xa98a6e,handL:0xa98a6e,handR:0xa98a6e,thigh:0x34343c,shin:0x2b2b33,foot:0x1c1c20,thighR:.13,thighR2:.125};
|
| 85 |
+
return skinned(scene,r,add=>{
|
| 86 |
+
add('hips',P.box,0x2d2d35,M4(0,-.02,0,0,0,0,.36,.2,.25),.03);add('spine',P.box,0xa98a6e,M4(0,.04,0,0,0,0,.3,.16,.19),.03);add('spine',P.box,0x7a2a26,M4(0,-.04,0,0,0,0,.33,.07,.22));
|
| 87 |
+
// the robe worn off the left shoulder over a bare, scarred chest
|
| 88 |
+
add('chest',P.box,0xa98a6e,M4(0,.1,0,0,0,0,.38,.3,.22),.03);add('chest',P.box,0xc9c3b4,M4(-.09,.1,.005,0,0,0,.22,.31,.235),.04);add('chest',P.box,0x8d6f58,M4(.08,.14,.113,0,0,.7,.012,.2,.004));
|
| 89 |
+
add('neck',P.cyl(.052,.058,.1,6),0xa98a6e,M4(0,.03,0));add('head',P.ball,0xad8e72,M4(0,.1,.01,0,0,0,.1,.125,.105),.03);
|
| 90 |
+
// long white hair tied back, heavy brows and beard
|
| 91 |
+
add('head',P.ball,0xe6e3da,M4(0,.165,-.04,0,0,0,.115,.09,.105),.05);add('head',P.box,0xe6e3da,M4(0,.11,-.09,0,0,0,.19,.15,.06),.05);add('tail',P.box,0xe6e3da,M4(0,-.2,-.03,.25,0,0,.09,.52,.05),.06);
|
| 92 |
+
add('head',P.box,0xe6e3da,M4(0,.035,.09,.25,0,0,.1,.09,.04),.05);add('head',P.box,0xe6e3da,M4(.035,.118,.105,0,0,0,.038,.016,.012));add('head',P.box,0xe6e3da,M4(-.035,.118,.105,0,0,0,.038,.016,.012));
|
| 93 |
+
limbs(add,c);katana(add,'blade');add('scab',P.box,0x1a1416,M4(0,0,0,0,0,0,.036,.92,.046));
|
| 94 |
+
// wide hakama
|
| 95 |
+
for(const [x,z,ry] of [[0,.13,0],[0,-.13,0],[.17,0,1.57],[-.17,0,1.57]])for(let i=0;i<2;i++)add('skirt',P.box,i?0x26262d:0x34343c,M4(x,-.16-i*.17,z,ry?0:(z>0?-.1:.1),ry,ry?(x>0?.1:-.1):0,.24,.2,.03),.03);
|
| 96 |
+
// the long spear: held in the right hand, slung across the back between its moves
|
| 97 |
+
for(const [bone,o] of [['spear',[0,-.65,0]],['back',[0,0,0]]]){const tilt=bone==='back'?.5:0;
|
| 98 |
+
add(bone,P.box,0x3a2a1c,M4(o[0],o[1],o[2],0,0,tilt,.024,2.0,.024),.04);add(bone,P.box,0xd9dde2,M4(o[0]+Math.sin(tilt)*1.12,o[1]-Math.cos(tilt)*1.12,o[2],0,0,tilt,.012,.3,.05));add(bone,P.box,0xd9dde2,M4(o[0]+Math.sin(tilt)*1.02,o[1]-Math.cos(tilt)*1.02,o[2],0,0,tilt+1.57,.012,.26,.03));}
|
| 99 |
+
// the matchlock pistol
|
| 100 |
+
add('gun',P.box,0x2a1e16,M4(0,-.02,.02,0,0,0,.05,.13,.06));add('gun',P.box,0x24242a,M4(0,-.26,.03,0,0,0,.03,.42,.03));add('gun',P.box,0x8d7442,M4(0,-.1,.03,0,0,0,.042,.03,.042));
|
| 101 |
+
},{roughness:.72,metalness:.08});}
|
| 102 |
+
function gyoubuModel(scene){const r=rig([...HUMAN,['spear','rWr',[0,-.07,.02]],['hBody','root',[0,1.32,0]],['hNeck','hBody',[0,.12,.72]],['hFL','hBody',[.2,-.1,.62]],['hFR','hBody',[-.2,-.1,.62]],['hBL','hBody',[.2,-.1,-.62]],['hBR','hBody',[-.2,-.1,-.62]]]),c={sleeveL:0x3a1416,sleeveR:0x3a1416,foreL:0x2a2024,foreR:0x2a2024,handL:0x8d6f58,handR:0x8d6f58,thigh:0x2d2226,shin:0x241c20,foot:0x151214,thighR:.12,thighR2:.1};
|
| 103 |
+
return skinned(scene,r,add=>{
|
| 104 |
+
// the rider: lacquered armour over crimson, a horned helm and a heavy beard
|
| 105 |
+
add('hips',P.box,0x2d2226,M4(0,-.02,0,0,0,0,.36,.2,.25),.03);add('spine',P.box,0x4a1a1c,M4(0,.04,0,0,0,0,.33,.17,.21),.03);add('chest',P.box,0x1f1c20,M4(0,.1,0,0,0,0,.42,.32,.26),.04);
|
| 106 |
+
for(let i=0;i<3;i++)add('chest',P.box,0x8a2424,M4(0,.0+i*.09,.134,0,0,0,.4,.016,.004));
|
| 107 |
+
add('neck',P.cyl(.055,.06,.1,6),0x8d6f58,M4(0,.03,0));add('head',P.ball,0x94745c,M4(0,.1,.01,0,0,0,.11,.13,.11),.03);add('head',P.box,0x141214,M4(0,.03,.08,.2,0,0,.13,.11,.05),.05);
|
| 108 |
+
add('head',P.ball,0x1a181c,M4(0,.17,0,0,0,0,.135,.085,.13),.04);add('head',P.box,0x1a181c,M4(0,.13,-.02,0,0,0,.34,.018,.3));for(const s of [1,-1])add('head',P.cone(.03,.26,5),0xb09050,M4(s*.11,.29,.03,0,0,-s*.42));
|
| 109 |
+
limbs(add,c);katana(add,'blade');add('scab',P.box,0x141214,M4(0,0,0,0,0,0,.036,.92,.046));
|
| 110 |
+
// the long spear
|
| 111 |
+
add('spear',P.box,0x2c2118,M4(0,-.75,0,0,0,0,.028,2.5,.028),.04);add('spear',P.box,0xd9dde2,M4(0,-2.14,0,0,0,0,.014,.34,.06));add('spear',P.box,0xd9dde2,M4(0,-2.02,0,0,0,1.57,.014,.34,.035));
|
| 112 |
+
// Onikage: a big dark horse with a red harness
|
| 113 |
+
add('hBody',P.box,0x201a1a,M4(0,0,0,0,0,0,.46,.5,1.5),.05);add('hBody',P.box,0x2a2120,M4(0,.04,-.62,0,0,0,.48,.52,.42),.05);add('hBody',P.box,0x6e1a1c,M4(0,.27,-.05,0,0,0,.5,.06,.62),.03);
|
| 114 |
+
add('hBody',P.box,0x141010,M4(0,.12,-.92,-.5,0,0,.08,.08,.62),.06);
|
| 115 |
+
add('hNeck',P.box,0x201a1a,M4(0,.22,.14,-.75,0,0,.2,.34,.7),.05);add('hNeck',P.box,0x141010,M4(0,.36,.02,-.75,0,0,.05,.3,.66),.06);add('hNeck',P.box,0x241d1c,M4(0,.54,.5,.35,0,0,.18,.2,.46),.05);for(const s of [1,-1])add('hNeck',P.cone(.03,.13,4),0x201a1a,M4(s*.06,.7,.36));add('hNeck',P.box,0x6e1a1c,M4(0,.56,.5,.35,0,0,.2,.03,.3));
|
| 116 |
+
for(const [bone,s] of [['hFL',1],['hFR',-1],['hBL',1],['hBR',-1]]){add(bone,seg(.62,.075,.05),0x201a1a,M4(),.05);add(bone,seg(.56,.05,.04),0x1a1515,M4(0,-.58,0),.05);add(bone,P.box,0x0e0c0c,M4(0,-1.14,.02,0,0,0,.09,.07,.13));}
|
| 117 |
+
},{roughness:.68,metalness:.1});}
|
| 118 |
+
function butterflyModel(scene){const r=rig(HUMAN),c={sleeveL:0x574263,sleeveR:0x574263,foreL:0x574263,foreR:0x574263,handL:0xd8c2ad,handR:0xd8c2ad,thigh:0x382b40,shin:0xe9e3d8,foot:0xe9e3d8,thighR:.1,thighR2:.09};
|
| 119 |
+
return skinned(scene,r,add=>{
|
| 120 |
+
add('hips',P.box,0x4b3956,M4(0,-.02,0,0,0,0,.3,.17,.2),.05);add('spine',P.box,0x8a7d9a,M4(0,.03,0,0,0,0,.31,.14,.2),.04);
|
| 121 |
+
add('chest',P.box,0x574263,M4(0,.09,0,0,0,0,.33,.26,.2),.06);add('chest',P.box,0xcfc6d4,M4(.04,.15,.1,0,0,.5,.04,.2,.02));add('chest',P.box,0xcfc6d4,M4(-.04,.15,.1,0,0,-.5,.04,.2,.02));
|
| 122 |
+
// butterfly crests on the sleeves and back
|
| 123 |
+
for(const [b,x] of [['lSh',.07],['rSh',-.07]])add(b,P.oct,0xe0ccff,M4(x,-.16,0,0,0,.8,.05,.035,.02));add('back',P.oct,0xe0ccff,M4(0,-.08,-.01,0,0,.8,.1,.06,.02));add('hips',P.oct,0xe0ccff,M4(.12,-.06,.1,0,0,.8,.05,.03,.02));
|
| 124 |
+
add('neck',P.cyl(.045,.05,.09,6),0xd2bba6,M4(0,.03,0));add('head',P.ball,0xd8c2ad,M4(0,.1,.01,0,0,0,.092,.112,.098),.03);
|
| 125 |
+
add('head',P.ball,0xe8e6e2,M4(0,.16,-.04,0,0,0,.1,.08,.095),.05);add('head',P.box,0xe8e6e2,M4(0,.11,-.08,0,0,0,.16,.11,.05),.05);add('tail',P.ball,0xe8e6e2,M4(0,.04,-.04,0,0,0,.075,.065,.07),.05);add('tail',P.box,0x8d6a2c,M4(0,.05,-.05,0,0,1.3,.008,.18,.008));
|
| 126 |
+
add('head',P.box,0x5a4038,M4(.03,.11,.095,0,0,0,.024,.01,.01));add('head',P.box,0x5a4038,M4(-.03,.11,.095,0,0,0,.024,.01,.01));
|
| 127 |
+
limbs(add,c);
|
| 128 |
+
for(const b of ['blade','tool'])add(b,P.box,0x2c2c32,M4(0,-.14,0,0,0,0,.016,.22,.03));
|
| 129 |
+
},{scale:.93,roughness:.8});}
|
| 130 |
+
// Guardian Ape: hunched white beast (S14: white fur, a red scar across the left eye, a nodachi through the neck).
|
| 131 |
+
const APE_BONES=[['root',null,[0,0,0]],['hips','root',[0,1.25,0]],['spine','hips',[0,.42,.12]],['chest','spine',[0,.5,.1]],['neck','chest',[0,.46,.42]],['head','neck',[0,.16,.22]],
|
| 132 |
+
['lSh','chest',[.62,.28,.05]],['lEl','lSh',[0,-.78,0]],['lWr','lEl',[0,-.72,0]],['rSh','chest',[-.62,.28,.05]],['rEl','rSh',[0,-.78,0]],['rWr','rEl',[0,-.72,0]],
|
| 133 |
+
['lHip','hips',[.32,-.08,0]],['lKnee','lHip',[0,-.6,0]],['lAnk','lKnee',[0,-.55,0]],['rHip','hips',[-.32,-.08,0]],['rKnee','rHip',[0,-.6,0]],['rAnk','rKnee',[0,-.55,0]],
|
| 134 |
+
['neckBlade','neck',[0,.06,0]],['blade','rWr',[0,-.16,0]],['held','lWr',[0,-.2,.1]],['stump','neck',[0,.04,.04]]];
|
| 135 |
+
function apeModel(scene){const r=rig(APE_BONES),fur=0xdedbd0,furD=0xbdb8ab,skin=0x8f4336;
|
| 136 |
+
return skinned(scene,r,add=>{
|
| 137 |
+
add('hips',P.ball,furD,M4(0,.05,0,0,0,0,.52,.42,.46),.12);add('spine',P.ball,fur,M4(0,.12,0,0,0,0,.66,.55,.55),.12);add('chest',P.ball,fur,M4(0,.12,0,0,0,0,.82,.62,.62),.12);
|
| 138 |
+
add('chest',P.ball,0xc9a99a,M4(0,.0,.38,0,0,0,.45,.4,.2),.06);
|
| 139 |
+
for(let i=0;i<14;i++){const a=i/14*Math.PI*2;add('neck',P.cone(.14,.5,5),i%2?fur:furD,M4(Math.sin(a)*.35,.05,Math.cos(a)*.3-.05,Math.cos(a)*.9,0,-Math.sin(a)*.9),.15);}
|
| 140 |
+
add('head',P.ball,fur,M4(0,.12,-.02,0,0,0,.33,.32,.32),.12);add('head',P.ball,skin,M4(0,.08,.2,0,0,0,.22,.2,.16),.05);
|
| 141 |
+
add('head',P.box,0x2a1713,M4(.09,.15,.33,0,0,0,.05,.02,.02));add('head',P.box,0x2a1713,M4(-.09,.15,.33,0,0,0,.05,.02,.02));add('head',P.box,0xb3201a,M4(.1,.16,.34,0,0,1.1,.016,.13,.012));
|
| 142 |
+
add('head',P.box,0x3b1b16,M4(0,-.02,.32,0,0,0,.12,.03,.03));
|
| 143 |
+
for(const s of ['l','r']){add(s+'Sh',P.ball,fur,M4(0,-.05,0,0,0,0,.3,.3,.3),.12);add(s+'Sh',seg(.8,.24,.19),fur,M4(),.14);add(s+'El',seg(.72,.18,.15),furD,M4(),.14);
|
| 144 |
+
add(s+'Wr',P.ball,0x4a3b35,M4(0,-.1,.02,0,0,0,.17,.14,.2),.06);
|
| 145 |
+
add(s+'Hip',seg(.6,.26,.2),fur,M4(),.14);add(s+'Knee',seg(.55,.18,.14),furD,M4(),.14);add(s+'Ank',P.box,0x4a3b35,M4(0,-.06,.12,0,0,0,.22,.12,.4),.05);}
|
| 146 |
+
// the nodachi through its neck (phase 1) and the same blade in its right hand (headless phase)
|
| 147 |
+
add('neckBlade',P.box,0xcfd3d8,M4(0,0,0,0,0,1.5,.04,2.4,.1));add('neckBlade',P.box,0x2b2018,M4(-1.25,.02,0,0,0,1.5,.06,.4,.06));
|
| 148 |
+
add('blade',P.box,0xcfd3d8,M4(0,-1.3,.0,0,0,0,.05,2.6,.12));add('blade',P.box,0x2b2018,M4(0,.05,0,0,0,0,.07,.42,.07));
|
| 149 |
+
add('held',P.ball,fur,M4(0,0,0,0,0,0,.3,.28,.28),.12);add('held',P.ball,skin,M4(0,-.04,.18,0,0,0,.2,.18,.14),.05);add('held',P.box,0xb3201a,M4(.08,.02,.31,0,0,1.1,.016,.12,.012));
|
| 150 |
+
add('stump',P.cyl(.24,.27,.12,8),0x7d1414,M4(0,0,0),.1);for(let i=0;i<6;i++)add('stump',P.ball,i%2?0x2a1712:0x4d2a1d,M4(Math.sin(i*1.1)*.05,.1+i*.07,Math.cos(i*1.3)*.04,0,0,0,.06,.045,.06));
|
| 151 |
+
},{roughness:.95});}
|
| 152 |
+
|
| 153 |
+
// The Demon of Hatred: a hulking burnt-red ogre with a horned head, a fire-wreathed left arm and a ragged cape (original procedural art).
|
| 154 |
+
const DEMON_BONES=APE_BONES.filter(([n])=>!['neckBlade','blade','held','stump'].includes(n)).map(([n,p,o])=>[n,p,n==='hips'?[0,1.9,0]:n==='lKnee'||n==='rKnee'?[0,-.9,0]:n==='lAnk'||n==='rAnk'?[0,-.85,0]:n==='lEl'||n==='rEl'?[0,-1.05,0]:n==='lWr'||n==='rWr'?[0,-.95,0]:n==='lSh'?[.85,.4,.05]:n==='rSh'?[-.85,.4,.05]:n==='chest'?[0,.6,.1]:n==='spine'?[0,.5,.1]:o]).concat([['flame','lWr',[0,-.2,0]],['cape','chest',[0,.3,-.4]]]);
|
| 155 |
+
function demonModel(scene){const r=rig(DEMON_BONES),skin=0x9a4634,dark=0x5a3026,horn=0xe6d6b0,ash=0x6a5e56;
|
| 156 |
+
return skinned(scene,r,add=>{
|
| 157 |
+
add('hips',P.ball,dark,M4(0,.05,0,0,0,0,.7,.5,.58),.1);add('spine',P.ball,skin,M4(0,.12,0,0,0,0,.85,.62,.66),.12);add('chest',P.ball,skin,M4(0,.15,0,0,0,0,1.05,.75,.78),.12);
|
| 158 |
+
for(let i=0;i<5;i++)add('chest',P.box,0x1d1210,M4(-.4+i*.2,.1,.68,0,0,(i-2)*.25,.04,.5,.04));
|
| 159 |
+
add('neck',P.ball,skin,M4(0,.1,.1,0,0,0,.42,.38,.42),.1);add('head',P.ball,0x6a3026,M4(0,.15,.1,0,0,0,.4,.36,.4),.1);add('head',P.box,0x1a0d0b,M4(0,.02,.42,0,0,0,.36,.12,.1));
|
| 160 |
+
for(const s of [1,-1]){add('head',P.box,0xffb040,M4(s*.14,.2,.46,0,0,0,.08,.035,.02));add('head',P.cone(.1,.62,5),horn,M4(s*.3,.42,0,-.3,0,-s*.7),.05);add('head',P.cone(.06,.32,5),horn,M4(s*.18,.48,.18,.4,0,-s*.3),.04);}
|
| 161 |
+
for(let i=0;i<9;i++){const a=(i/8-.5)*2.2;add('head',P.cone(.1,.5,4),0xd8d0c0,M4(Math.sin(a)*.38,.25-Math.abs(a)*.08,-.22,-.9-Math.abs(a)*.2,0,-a*.6),.12);}
|
| 162 |
+
for(const s of ['l','r']){add(s+'Sh',P.ball,skin,M4(0,-.05,0,0,0,0,.42,.42,.42),.1);add(s+'Sh',seg(1.05,.3,.24),s==='l'?0x3a1610:skin,M4(),.12);add(s+'El',seg(.95,.24,.19),s==='l'?0x241008:dark,M4(),.12);
|
| 163 |
+
add(s+'Wr',P.ball,0x1d100c,M4(0,-.14,.03,0,0,0,.24,.2,.28),.06);for(let k=0;k<3;k++)add(s+'Wr',P.cone(.04,.22,4),horn,M4((k-1)*.1,-.36,.1,.3,0,0));
|
| 164 |
+
add(s+'Hip',seg(.9,.32,.26),dark,M4(),.12);add(s+'Knee',seg(.85,.24,.2),skin,M4(),.12);add(s+'Ank',P.box,0x1d100c,M4(0,-.08,.16,0,0,0,.34,.16,.56),.05);}
|
| 165 |
+
// the burning left arm: glowing cracks and a crown of flame at the fist
|
| 166 |
+
for(let i=0;i<6;i++)add('lEl',P.box,0xff7a2a,M4(Math.sin(i*1.7)*.18,-.15-i*.13,.18,0,0,i*.4,.03,.16,.02));
|
| 167 |
+
for(let i=0;i<7;i++){const a=i/7*Math.PI*2;add('flame',P.cone(.12,.55,5),i%2?0xff9a32:0xffd060,M4(Math.sin(a)*.14,.1,Math.cos(a)*.14,Math.cos(a)*.5,0,-Math.sin(a)*.5));}
|
| 168 |
+
for(let i=0;i<5;i++)add('cape',P.box,i%2?ash:0x2a2420,M4(-.6+i*.3,-.9,0,.15,0,(i-2)*.08,.32,1.8,.04),.15);
|
| 169 |
+
},{roughness:.9});}
|
| 170 |
+
/* ------------------------------------------------------------------ poses */
|
| 171 |
+
const J=['hips','spine','chest','neck','head','lSh','lEl','lWr','rSh','rEl','rWr','lHip','lKnee','lAnk','rHip','rKnee','rAnk','blade'];
|
| 172 |
+
const pose=o=>{const p={y:0,lean:0};for(const j of J)p[j]=o[j]||[0,0,0];if('y' in o)p.y=o.y;return p;};
|
| 173 |
+
function mixPose(a,b,u){if(u<=0)return a;if(u>=1)return b;const p={y:lerp(a.y,b.y,u)};for(const j of J)p[j]=[lerp(a[j][0],b[j][0],u),lerp(a[j][1],b[j][1],u),lerp(a[j][2],b[j][2],u)];return p;}
|
| 174 |
+
const add3=(p,j,v)=>{p[j]=[p[j][0]+v[0],p[j][1]+v[1],p[j][2]+v[2]];};
|
| 175 |
+
// Shared human poses. Arms hang along -Y; negative shoulder X raises an arm forward; the blade runs along the hand.
|
| 176 |
+
const H={
|
| 177 |
+
stance:pose({y:-.05,spine:[.1,0,0],chest:[.04,.2,0],head:[-.06,-.15,0],rSh:[-.45,0,-.28],rEl:[-.75,0,0],rWr:[-.85,0,0],lSh:[-.35,0,.2],lEl:[-.9,0,0],
|
| 178 |
+
lHip:[-.32,0,.06],lKnee:[.5,0,0],lAnk:[-.18,0,0],rHip:[.15,0,-.08],rKnee:[.4,0,0],rAnk:[-.25,0,0]}),
|
| 179 |
+
guard:pose({y:-.08,spine:[.12,0,0],chest:[.05,.35,0],head:[-.05,-.3,0],rSh:[-1.25,0,-.15],rEl:[-1.05,0,0],rWr:[-.25,0,1.35],lSh:[-.9,0,.25],lEl:[-1.3,0,0],
|
| 180 |
+
lHip:[-.35,0,.06],lKnee:[.55,0,0],lAnk:[-.2,0,0],rHip:[.2,0,-.08],rKnee:[.45,0,0],rAnk:[-.25,0,0]}),
|
| 181 |
+
raise:pose({y:-.04,spine:[-.05,0,0],chest:[-.05,.55,0],head:[0,-.4,0],rSh:[-2.55,0,-.35],rEl:[-.55,0,0],rWr:[-.2,0,0],lSh:[-.6,0,.3],lEl:[-.8,0,0],
|
| 182 |
+
lHip:[-.3,0,.06],lKnee:[.4,0,0],lAnk:[-.15,0,0],rHip:[.25,0,-.08],rKnee:[.35,0,0],rAnk:[-.2,0,0]}),
|
| 183 |
+
cut:pose({y:-.12,spine:[.3,0,0],chest:[.15,-.65,0],head:[-.1,.45,0],rSh:[-.75,0,.55],rEl:[-.15,0,0],rWr:[-.25,0,0],lSh:[-.2,0,.45],lEl:[-.5,0,0],
|
| 184 |
+
lHip:[-.6,0,.06],lKnee:[.7,0,0],lAnk:[-.15,0,0],rHip:[.35,0,-.08],rKnee:[.25,0,0],rAnk:[-.3,0,0]}),
|
| 185 |
+
backRaise:pose({y:-.05,chest:[0,-.6,0],head:[0,.45,0],rSh:[-1.6,0,.9],rEl:[-1.2,0,0],rWr:[-.3,0,0],lSh:[-.4,0,.3],lEl:[-.7,0,0],lHip:[-.3,0,.06],lKnee:[.4,0,0],rHip:[.2,0,-.08],rKnee:[.35,0,0]}),
|
| 186 |
+
backCut:pose({y:-.1,spine:[.2,0,0],chest:[.1,.7,0],head:[-.05,-.45,0],rSh:[-1.25,0,-1.0],rEl:[-.2,0,0],rWr:[-.3,0,0],lSh:[-.3,0,.3],lEl:[-.6,0,0],lHip:[-.5,0,.06],lKnee:[.6,0,0],rHip:[.3,0,-.08],rKnee:[.3,0,0]}),
|
| 187 |
+
pull:pose({y:-.1,spine:[.2,0,0],chest:[.1,.6,0],head:[-.05,-.5,0],rSh:[-.25,0,-.35],rEl:[-1.7,0,0],rWr:[-1.35,0,0],lSh:[-.8,0,.3],lEl:[-.9,0,0],lHip:[-.45,0,.06],lKnee:[.65,0,0],rHip:[.35,0,-.08],rKnee:[.45,0,0],rAnk:[-.3,0,0]}),
|
| 188 |
+
lunge:pose({y:-.2,spine:[.35,0,0],chest:[.15,-.25,0],head:[-.2,.2,0],rSh:[-1.55,0,0],rEl:[-.05,0,0],rWr:[-1.55,0,0],lSh:[.3,0,.35],lEl:[-.3,0,0],lHip:[-.95,0,.06],lKnee:[1.0,0,0],lAnk:[-.1,0,0],rHip:[.55,0,-.08],rKnee:[.15,0,0],rAnk:[-.3,0,0]}),
|
| 189 |
+
low:pose({y:-.42,spine:[.55,0,0],chest:[.15,.5,0],head:[-.35,-.4,0],rSh:[-.5,0,-.9],rEl:[-.2,0,0],rWr:[-1.4,0,0],lSh:[-.4,0,.4],lEl:[-.6,0,0],lHip:[-1.1,0,.2],lKnee:[1.45,0,0],lAnk:[-.35,0,0],rHip:[.3,0,-.3],rKnee:[1.2,0,0],rAnk:[-.2,0,0]}),
|
| 190 |
+
lowCut:pose({y:-.42,spine:[.55,0,0],chest:[.15,-.75,0],head:[-.35,.4,0],rSh:[-.6,0,.95],rEl:[-.1,0,0],rWr:[-1.45,0,0],lSh:[-.2,0,.6],lEl:[-.4,0,0],lHip:[-1.1,0,.2],lKnee:[1.45,0,0],lAnk:[-.35,0,0],rHip:[.3,0,-.3],rKnee:[1.2,0,0],rAnk:[-.2,0,0]}),
|
| 191 |
+
overhead:pose({y:0,spine:[-.15,0,0],chest:[-.1,0,0],head:[.1,0,0],rSh:[-2.9,0,-.1],rEl:[-.2,0,0],rWr:[-.3,0,0],lSh:[-2.8,0,.1],lEl:[-.3,0,0],lHip:[-.2,0,.06],lKnee:[.3,0,0],rHip:[.1,0,-.06],rKnee:[.3,0,0]}),
|
| 192 |
+
chop:pose({y:-.25,spine:[.6,0,0],chest:[.2,0,0],head:[-.4,0,0],rSh:[-1.1,0,-.05],rEl:[-.1,0,0],rWr:[-.6,0,0],lSh:[-1.1,0,.05],lEl:[-.1,0,0],lHip:[-.8,0,.06],lKnee:[.9,0,0],rHip:[.4,0,-.06],rKnee:[.3,0,0]}),
|
| 193 |
+
reach:pose({y:-.15,spine:[.45,0,0],chest:[.1,-.3,0],head:[-.3,.2,0],lSh:[-1.5,0,.1],lEl:[-.1,0,0],rSh:[-.2,0,-.3],rEl:[-.5,0,0],rWr:[-.8,0,0],lHip:[-.9,0,.06],lKnee:[.9,0,0],rHip:[.5,0,-.06],rKnee:[.2,0,0]}),
|
| 194 |
+
kick:pose({y:-.02,spine:[-.2,0,0],chest:[-.1,.2,0],rSh:[-.4,0,-.5],rEl:[-.6,0,0],rWr:[-.8,0,0],lSh:[-.4,0,.5],lEl:[-.6,0,0],lHip:[-1.45,0,.05],lKnee:[.1,0,0],lAnk:[.4,0,0],rHip:[.15,0,-.05],rKnee:[.3,0,0]}),
|
| 195 |
+
draw:pose({y:-.02,chest:[0,-.95,0],head:[0,.9,0],lSh:[-1.55,0,.1],lEl:[0,0,0],lWr:[0,0,0],rSh:[-1.5,0,-.3],rEl:[-2.3,0,0],lHip:[-.25,0,.15],lKnee:[.25,0,0],rHip:[.2,0,-.15],rKnee:[.25,0,0]}),
|
| 196 |
+
release:pose({y:-.02,chest:[0,-.95,0],head:[0,.9,0],lSh:[-1.55,0,.1],lEl:[0,0,0],rSh:[-1.2,0,-1.1],rEl:[-.6,0,0],lHip:[-.25,0,.15],lKnee:[.25,0,0],rHip:[.2,0,-.15],rKnee:[.25,0,0]}),
|
| 197 |
+
tuck:pose({y:.1,spine:[.3,0,0],chest:[.1,0,0],rSh:[-1.2,0,-.4],rEl:[-1.0,0,0],rWr:[-.5,0,0],lSh:[-1.0,0,.4],lEl:[-1.1,0,0],lHip:[-1.4,0,.1],lKnee:[1.9,0,0],rHip:[-1.0,0,-.1],rKnee:[1.7,0,0]}),
|
| 198 |
+
hurt:pose({y:-.06,spine:[-.25,0,0],chest:[-.2,.2,0],head:[-.35,0,.15],rSh:[-.2,0,-.7],rEl:[-.4,0,0],rWr:[-.5,0,0],lSh:[-.2,0,.7],lEl:[-.4,0,0],lHip:[.1,0,.1],lKnee:[.3,0,0],rHip:[.35,0,-.1],rKnee:[.3,0,0]}),
|
| 199 |
+
kneel:pose({y:-.48,spine:[.55,0,0],chest:[.25,.1,0],head:[.45,0,0],rSh:[-.25,0,-.25],rEl:[-.4,0,0],rWr:[-.2,0,0],lSh:[-.1,0,.25],lEl:[-.4,0,0],lHip:[-1.45,0,.1],lKnee:[1.5,0,0],lAnk:[-.1,0,0],rHip:[.25,0,-.1],rKnee:[1.75,0,0],rAnk:[.3,0,0]}),
|
| 200 |
+
drink:pose({y:-.03,spine:[-.05,0,0],chest:[-.1,.1,0],head:[-.45,0,0],lSh:[-1.9,0,.5],lEl:[-1.8,0,0],rSh:[-.3,0,-.25],rEl:[-.4,0,0],rWr:[-.6,0,0],lHip:[-.15,0,.06],lKnee:[.2,0,0],rHip:[.1,0,-.06],rKnee:[.2,0,0]}),
|
| 201 |
+
cast:pose({y:-.02,chest:[-.1,-.3,0],head:[-.2,.3,0],rSh:[-2.6,0,-.4],rEl:[-.3,0,0],lSh:[-.9,0,.4],lEl:[-.6,0,0],lHip:[-.2,0,.06],lKnee:[.2,0,0],rHip:[.1,0,-.06],rKnee:[.2,0,0]}),
|
| 202 |
+
spread:pose({y:-.02,spine:[-.15,0,0],chest:[-.2,0,0],head:[-.4,0,0],rSh:[-.4,0,-1.4],rEl:[-.2,0,0],lSh:[-.4,0,1.4],lEl:[-.2,0,0],lHip:[-.1,0,.1],rHip:[-.1,0,-.1]}),
|
| 203 |
+
hover:pose({y:0,spine:[.1,0,0],chest:[0,0,0],head:[.3,0,0],rSh:[-.9,0,-.9],rEl:[-.6,0,0],rWr:[-.5,0,0],lSh:[-.9,0,.9],lEl:[-.6,0,0],lHip:[-1.2,0,.25],lKnee:[1.6,0,0],rHip:[-.2,0,-.2],rKnee:[.6,0,0]}),
|
| 204 |
+
aim:pose({y:-.04,chest:[0,-.5,0],head:[0,.45,0],rSh:[-1.55,0,.2],rEl:[0,0,0],rWr:[-1.5,0,0],lSh:[-.35,0,.3],lEl:[-.7,0,0],lHip:[-.3,0,.1],lKnee:[.35,0,0],rHip:[.2,0,-.1],rKnee:[.3,0,0]}),
|
| 205 |
+
dead:pose({y:-.9,spine:[-.2,0,0],head:[-.3,.5,0],rSh:[-.1,0,-1.3],lSh:[-.2,0,1.1],lHip:[-.2,0,.2],lKnee:[.3,0,0],rHip:[.1,0,-.2],rKnee:[.5,0,0]})
|
| 206 |
+
};
|
| 207 |
+
const ISSHIN_SPEAR=/^(spear_|lightning_|three_thrust|retreat_sweep|stomp|double_disc|leap_slam)/;
|
| 208 |
+
function walkCycle(p,phase,amount,run){if(amount<=0)return p;const s=Math.sin(phase),c=Math.cos(phase),a=amount*(run?1.15:.75);const q={...p};
|
| 209 |
+
add3(q,'lHip',[-s*a,0,0]);add3(q,'rHip',[s*a,0,0]);add3(q,'lKnee',[Math.max(0,c)*a*1.1,0,0]);add3(q,'rKnee',[Math.max(0,-c)*a*1.1,0,0]);
|
| 210 |
+
add3(q,'lSh',[s*a*.5,0,0]);add3(q,'chest',[0,s*a*.18,0]);q.y=p.y+Math.abs(c)*.035*amount-(run?.05:0);if(run)add3(q,'spine',[.18,0,0]);return q;}
|
| 211 |
+
// Melee timeline for a move: windup -> strike -> follow-through around each contact tick; alternate fore/back hands.
|
| 212 |
+
function strikePose(base,hits,t,o={}){let p=base;const W=o.wind||12,F=o.follow||10;
|
| 213 |
+
for(let i=0;i<hits.length;i++){const h=hits[i],k=h.t;if(t<k-W-4||t>k+F+6)continue;const back=(o.alternate!==false)&&i%2===1;
|
| 214 |
+
const type=h.type||'slash',raise=type==='thrust'?H.pull:type==='sweep'?H.low:type==='slam'?H.overhead:type==='grab'?H.stance:type==='kick'?H.stance:back?H.backRaise:H.raise;
|
| 215 |
+
const hitP=type==='thrust'?H.lunge:type==='sweep'?H.lowCut:type==='slam'?H.chop:type==='grab'?H.reach:type==='kick'?H.kick:back?H.backCut:H.cut;
|
| 216 |
+
if(t<k-2)p=mixPose(p,raise,band(t,k-W-4,k-W+3));else if(t<k+2)p=mixPose(raise,hitP,band(t,k-2,k+1));else p=mixPose(hitP,base,band(t,k+F*.4,k+F+6));}
|
| 217 |
+
return p;}
|
| 218 |
+
function applyPose(rigObj,p,extra={}){const b=rigObj.bones;for(const j of J)if(b[j]&&p[j])b[j].rotation.set(p[j][0],p[j][1],p[j][2]);b.hips.position.y=(extra.hipY??.94)+p.y;}
|
| 219 |
+
|
| 220 |
+
/* ------------------------------------------------------------------ scene */
|
| 221 |
+
class Scene{
|
| 222 |
+
constructor(canvas){
|
| 223 |
+
this.canvas=canvas;this.resources=new Set();this.times=[];this.ready=false;this.error=null;this.closed=false;this.kind=null;this.arenas={};
|
| 224 |
+
this.view=document.createElement('canvas');this.view.width=854;this.view.height=480;
|
| 225 |
+
this.renderer=new T.WebGLRenderer({canvas:this.view,alpha:false,antialias:true,preserveDrawingBuffer:true,powerPreference:'low-power'});
|
| 226 |
+
this.renderer.setPixelRatio(1);this.renderer.setSize(854,480,false);this.renderer.outputColorSpace=T.SRGBColorSpace;
|
| 227 |
+
this.renderer.toneMapping=T.ACESFilmicToneMapping;this.renderer.toneMappingExposure=1.1;
|
| 228 |
+
this.renderer.shadowMap.enabled=true;this.renderer.shadowMap.type=T.PCFSoftShadowMap;this.renderer.info.autoReset=false;
|
| 229 |
+
this.view.addEventListener('webglcontextlost',e=>{e.preventDefault();this.ready=false;this.error='WebGL context lost';});
|
| 230 |
+
this.world=new T.Scene();this.world.fog=new T.Fog(0xb0a9a3,30,90);
|
| 231 |
+
this.camera=new T.PerspectiveCamera(50,854/480,.1,260);
|
| 232 |
+
this.hemi=new T.HemisphereLight(0xd8e2f0,0x5a4a3c,1.4);this.world.add(this.hemi);
|
| 233 |
+
this.sun=new T.DirectionalLight(0xffe2b5,2.6);this.sun.castShadow=true;this.sun.shadow.mapSize.set(1024,1024);
|
| 234 |
+
const sc=this.sun.shadow.camera;sc.left=-14;sc.right=14;sc.top=14;sc.bottom=-14;sc.near=1;sc.far=80;this.sun.shadow.bias=-.0006;this.sun.shadow.normalBias=.03;
|
| 235 |
+
this.world.add(this.sun);this.world.add(this.sun.target);
|
| 236 |
+
this.flashLight=new T.PointLight(0xffe7b0,0,40,1.6);this.world.add(this.flashLight);
|
| 237 |
+
this.glowTex=this.keep(glowTexture());
|
| 238 |
+
this.mats={add:this.keep(new T.MeshBasicMaterial({color:0xffffff,transparent:true,opacity:1,blending:T.AdditiveBlending,depthWrite:false,fog:false})),
|
| 239 |
+
soft:this.keep(new T.MeshBasicMaterial({color:0xffffff,transparent:true,opacity:.55,depthWrite:false})),
|
| 240 |
+
solid:this.keep(new T.MeshStandardMaterial({color:0xffffff,roughness:.6,metalness:.2,flatShading:true})),
|
| 241 |
+
glow:this.keep(new T.MeshBasicMaterial({map:this.glowTex,color:0xffffff,transparent:true,blending:T.AdditiveBlending,depthWrite:false,fog:false})),
|
| 242 |
+
ghost:this.keep(new T.MeshStandardMaterial({color:0x9fd8ff,emissive:0x4a8cc8,emissiveIntensity:.7,transparent:true,opacity:.42,roughness:.4,flatShading:true,depthWrite:false}))};
|
| 243 |
+
this.geo={box:this.keep(new T.BoxGeometry(1,1,1)),ball:this.keep(new T.IcosahedronGeometry(1,0)),ring:this.keep(new T.TorusGeometry(1,.035,4,40)),quad:this.keep(new T.PlaneGeometry(1,1)),
|
| 244 |
+
wing:this.keep((()=>{const g=new T.BufferGeometry();g.setAttribute('position',new T.Float32BufferAttribute([0,0,0,.5,.1,.35,.55,.05,-.15, 0,0,0,-.5,.1,.35,-.55,.05,-.15],3));g.computeVertexNormals();return g;})())};
|
| 245 |
+
this.player=sekiroModel(this);this.world.add(this.player.holder);
|
| 246 |
+
this.bosses={genichiro:genichiroModel(this),ape:apeModel(this),butterfly:butterflyModel(this),isshin:isshinModel(this),gyoubu:gyoubuModel(this),demon:demonModel(this)};for(const m of Object.values(this.bosses)){m.holder.visible=false;this.world.add(m.holder);}
|
| 247 |
+
const sev=new Mesher();sev.add(P.ball,0xdedbd0,M4(0,0,0,0,0,0,.33,.32,.32),0,.12);sev.add(P.ball,0x8f4336,M4(0,-.04,.2,0,0,0,.22,.2,.16),0,.05);sev.add(P.box,0xb3201a,M4(.1,.04,.34,0,0,1.1,.016,.13,.012));sev.add(P.disc,0x7d1414,M4(0,-.3,0,0,0,0,.22,.04,.22));
|
| 248 |
+
this.severed=new T.Mesh(this.keep(sev.geometry()),this.material(0xffffff,{vertex:true,roughness:.95}));this.severed.castShadow=true;this.severed.visible=false;this.world.add(this.severed);
|
| 249 |
+
this.ghosts=[];const ghostGeo=this.keep((()=>{const m=new Mesher();m.add(P.cyl(.16,.26,.95,6),0xffffff,M4(0,.6,0));m.add(P.ball,0xffffff,M4(0,1.22,.05,0,0,0,.13,.15,.13));m.add(P.cone(.36,.16,8),0xffffff,M4(0,1.36,.03));
|
| 250 |
+
m.add(seg(.55,.05,.04),0xffffff,M4(.2,1.0,.08,-1.2,0,.2));m.add(P.box,0xffffff,M4(.22,.85,.6,-.2,0,0,.02,.04,.4));return m.geometry();})());
|
| 251 |
+
for(let i=0;i<6;i++){const g=new T.Mesh(ghostGeo,this.mats.ghost);g.visible=false;this.world.add(g);this.ghosts.push(g);}
|
| 252 |
+
this.pool=(geo,mat,n)=>{const m=new T.InstancedMesh(geo,mat,n);m.count=0;m.frustumCulled=false;m.instanceColor=new T.InstancedBufferAttribute(new Float32Array(n*3),3);this.world.add(m);this.keep(m);return m;};
|
| 253 |
+
this.fx={spark:this.pool(this.geo.box,this.mats.add,96),flash:this.pool(this.geo.quad,this.mats.glow,24),blood:this.pool(this.geo.ball,this.keep(new T.MeshBasicMaterial({color:0xffffff})),64),
|
| 254 |
+
bolt:this.pool(this.geo.box,this.mats.add,90),proj:this.pool(this.geo.box,this.mats.solid,48),wings:this.pool(this.geo.wing,this.keep(new T.MeshBasicMaterial({color:0xffffff,side:T.DoubleSide,transparent:true,opacity:.9,blending:T.AdditiveBlending,depthWrite:false,fog:false})),64),
|
| 255 |
+
puff:this.pool(this.geo.ball,this.keep(new T.MeshBasicMaterial({color:0xffffff,transparent:true,opacity:.28,depthWrite:false})),48),rings:this.pool(this.geo.ring,this.mats.add,10),
|
| 256 |
+
mote:this.pool(this.geo.ball,this.mats.add,90),leaf:this.pool(this.geo.quad,this.keep(new T.MeshBasicMaterial({color:0xffffff,side:T.DoubleSide})),40),flame:this.pool(this.keep(new T.ConeGeometry(1,1,6)),this.keep(new T.MeshBasicMaterial({color:0xffffff})),260)};
|
| 257 |
+
this.dummy=new T.Object3D();this.tmp=new T.Color();
|
| 258 |
+
// Sword trails: a ribbon per fighter, rebuilt from the pose clock (past ticks are re-evaluated, no history kept).
|
| 259 |
+
this.trails=[0,1].map(()=>{const g=this.keep(new T.BufferGeometry()),n=6;g.setAttribute('position',new T.BufferAttribute(new Float32Array(n*2*3),3).setUsage(T.DynamicDrawUsage));
|
| 260 |
+
g.setAttribute('color',new T.BufferAttribute(new Float32Array(n*2*4),4).setUsage(T.DynamicDrawUsage));const ix=[];for(let i=0;i<n-1;i++){const a=i*2;ix.push(a,a+1,a+2,a+1,a+3,a+2);}g.setIndex(ix);
|
| 261 |
+
const m=new T.Mesh(g,this.keep(new T.MeshBasicMaterial({vertexColors:true,transparent:true,side:T.DoubleSide,depthWrite:false,fog:false})));m.frustumCulled=false;m.visible=false;m.renderOrder=3;this.world.add(m);return {mesh:m,n};});
|
| 262 |
+
this.threads=null;
|
| 263 |
+
}
|
| 264 |
+
keep(x){this.resources.add(x);return x;}
|
| 265 |
+
material(color,o={}){return this.keep(new T.MeshStandardMaterial({color,roughness:o.roughness??.9,metalness:o.metalness??0,flatShading:o.flat??true,map:o.map?this.keep(o.map):null,vertexColors:!!o.vertex,transparent:!!o.transparent,opacity:o.opacity??1,emissive:o.emissive??0x000000,emissiveIntensity:o.emissiveIntensity??1,side:o.side??T.FrontSide,depthWrite:o.depthWrite??true}));}
|
| 266 |
+
static(group,mesher,mat,shadow=true){const m=new T.Mesh(this.keep(mesher.geometry()),mat);m.receiveShadow=shadow;m.castShadow=false;group.add(m);return m;}
|
| 267 |
+
sky(group,top,mid,low,sunDir,sunColor){const tex=this.keep(canvasTexture(256,(q,s)=>{const g=q.createLinearGradient(0,0,0,s);g.addColorStop(0,top);g.addColorStop(.55,mid);g.addColorStop(1,low);q.fillStyle=g;q.fillRect(0,0,s,s);
|
| 268 |
+
for(let i=0;i<26;i++){const y=s*(.35+hash(i,3)*.4),x=hash(i,5)*s,w=s*(.2+hash(i,9)*.5);q.fillStyle=`rgba(255,240,225,${.05+hash(i,11)*.08})`;q.beginPath();q.ellipse(x,y,w,4+hash(i,13)*9,0,0,Math.PI*2);q.fill();q.beginPath();q.ellipse(x-s,y,w,4+hash(i,13)*9,0,0,Math.PI*2);q.fill();}}));
|
| 269 |
+
tex.wrapT=T.ClampToEdgeWrapping;tex.repeat.set(1,1);const dome=new T.Mesh(this.keep(new T.SphereGeometry(200,24,12,0,Math.PI*2,0,Math.PI*.62)),this.keep(new T.MeshBasicMaterial({map:tex,side:T.BackSide,fog:false,depthWrite:false})));
|
| 270 |
+
dome.rotation.x=0;dome.position.y=-30;group.add(dome);
|
| 271 |
+
if(sunDir){const sun=new T.Sprite(this.keep(new T.SpriteMaterial({map:this.glowTex,color:sunColor,transparent:true,blending:T.AdditiveBlending,depthWrite:false,fog:false})));sun.position.copy(sunDir.clone().multiplyScalar(170));sun.scale.setScalar(55);group.add(sun);}
|
| 272 |
+
return dome;}
|
| 273 |
+
|
| 274 |
+
/* ---------------- arenas */
|
| 275 |
+
arena(kind){if(this.arenas[kind])return this.arenas[kind];const group=new T.Group();group.visible=false;this.world.add(group);
|
| 276 |
+
const a=kind==='genichiro'?this.castleTop(group):kind==='ape'?this.wateringHole(group):kind==='isshin'?this.silvergrass(group):kind==='gyoubu'?this.castleGate(group):kind==='demon'?this.burningGate(group):this.audienceChamber(group);a.group=group;this.arenas[kind]=a;return a;}
|
| 277 |
+
castleTop(group){
|
| 278 |
+
const stone=this.material(0xffffff,{map:canvasTexture(512,(q,s)=>{q.fillStyle='#4a4641';q.fillRect(0,0,s,s);const n=8,w=s/n;
|
| 279 |
+
for(let y=0;y<n;y++)for(let x=-1;x<n;x++){const v=128+Math.round(hash(x+9,y)*46);q.fillStyle=`rgb(${v},${v-5},${v-12})`;q.fillRect(x*w+3+(y%2)*w/2,y*w+3,w-6,w-6);}
|
| 280 |
+
for(let i=0;i<900;i++){q.fillStyle=`rgba(40,36,30,${hash(i,2)*.12})`;q.fillRect(hash(i,3)*s,hash(i,4)*s,2,2);}},3),roughness:.95});
|
| 281 |
+
const floor=new T.Mesh(this.keep(new T.BoxGeometry(17.2,.4,13.2)),stone);floor.position.y=-.2;floor.receiveShadow=true;group.add(floor);
|
| 282 |
+
const wood=new Mesher(),roof=new Mesher(),wall=new Mesher(),gold=new Mesher(),far=new Mesher();
|
| 283 |
+
// timber railing around the terrace
|
| 284 |
+
for(const z of [-6.45,6.45]){wood.add(P.box,0x3a2a22,M4(0,.82,z,0,0,0,17,.1,.12),0,.05);wood.add(P.box,0x3a2a22,M4(0,.4,z,0,0,0,17,.07,.08),0,.05);for(let x=-8.4;x<=8.4;x+=1.4)wood.add(P.box,0x2e211b,M4(x,.42,z,0,0,0,.13,.86,.13),0,.05);}
|
| 285 |
+
for(const x of [-8.45,8.45]){wood.add(P.box,0x3a2a22,M4(x,.82,0,0,0,0,.12,.1,13),0,.05);wood.add(P.box,0x3a2a22,M4(x,.4,0,0,0,0,.08,.07,13),0,.05);for(let z=-5.6;z<=5.6;z+=1.4)wood.add(P.box,0x2e211b,M4(x,.42,z,0,0,0,.13,.86,.13),0,.05);}
|
| 286 |
+
wood.add(P.box,0x2b1f19,M4(0,-.5,0,0,0,0,17.6,.14,13.6),0,.03);
|
| 287 |
+
// kawara roof skirts falling away on four sides, upturned at the corners
|
| 288 |
+
// eaves slope outward and down from the terrace edge (ry faces outward)
|
| 289 |
+
const skirt=(cx,cz,len,ry)=>{for(let k=0;k<4;k++){const out=.9+k*1.15,y=-.42-k*.5,ox=cx+Math.sin(ry)*out,oz=cz+Math.cos(ry)*out;roof.add(P.box,0x34414c,MY(ox,y,oz,ry,.42,len+k*2.3,.16,1.3),0,.05);
|
| 290 |
+
for(let i=-len/2-k;i<=len/2+k;i+=.6)roof.add(P.box,0x27313a,MY(ox+Math.cos(ry)*i,y+.1,oz-Math.sin(ry)*i,ry,.42,.08,.09,1.3),0,.03);}};
|
| 291 |
+
skirt(0,6.6,17,0);skirt(0,-6.6,17,Math.PI);skirt(8.6,0,13,Math.PI/2);skirt(-8.6,0,13,-Math.PI/2);
|
| 292 |
+
for(const [x,z] of [[-9.4,-7.2],[9.4,-7.2],[-9.4,7.2],[9.4,7.2]]){const yaw=Math.atan2(x,z);roof.add(P.box,0x34414c,MY(x,-.75,z,yaw,.5,1.6,.2,3.2),0,.04);gold.add(P.cone(.16,.7,5),0xc99a45,MY(x*1.12,-.2,z*1.12,yaw,-.9,1,1,1),0,.08);}
|
| 293 |
+
// gold shachihoko on the ridge ends of the keep roof below
|
| 294 |
+
for(const s of [-1,1]){gold.add(P.ball,0xd2a24c,M4(s*8.9,-1.2,-8.9,0,0,s*.3,.28,.5,.22),0,.08);gold.add(P.cone(.2,.5,5),0xd2a24c,M4(s*8.9,-.7,-9.05,-.6,0,0),0,.08);}
|
| 295 |
+
// lower castle tiers and the town, stepping away below the keep
|
| 296 |
+
for(let i=0;i<9;i++){const a=-1.2+i*.3,r=26+(i%3)*6,x=Math.sin(a)*r,z=-Math.cos(a)*r,y=-9-(i%3)*3,w=4+hash(i,1)*3;
|
| 297 |
+
wall.add(P.box,0xd7d1c2,M4(x,y,z,0,a,0,w,2.4,w*.7),0,.03);roof.add(P.cone(w*.86,1.7,4),0x2f3b45,M4(x,y+2.0,z,0,a+Math.PI/4,0,1,1,.75),0,.04);
|
| 298 |
+
for(let k=-1;k<=1;k++)wall.add(P.box,0x24201c,M4(x+Math.cos(a)*k*w*.3,y+.2,z+Math.sin(a)*k*w*.3,0,a,0,.5,.7,w*.72),0,.02);}
|
| 299 |
+
for(let i=0;i<40;i++){const a=hash(i,21)*Math.PI*2,r=48+hash(i,22)*40,y=-22+hash(i,23)*4;far.add(P.box,0x6f6c6a,M4(Math.sin(a)*r,y,Math.cos(a)*r,0,a,0,3+hash(i,24)*4,2.5,3),0,.08);}
|
| 300 |
+
const mats={wood:this.material(0xffffff,{vertex:true,roughness:.92}),roof:this.material(0xffffff,{vertex:true,roughness:.7,metalness:.1}),wall:this.material(0xffffff,{vertex:true}),gold:this.material(0xffffff,{vertex:true,roughness:.35,metalness:.75}),far:this.material(0xffffff,{vertex:true,roughness:1})};
|
| 301 |
+
this.static(group,wood,mats.wood);this.static(group,roof,mats.roof);this.static(group,wall,mats.wall,false);this.static(group,gold,mats.gold,false);this.static(group,far,mats.far,false);
|
| 302 |
+
this.ridges(group,[0x5b6475,0x75808f,0x98a0ad],[46,70,100],-14,18);
|
| 303 |
+
const sunDir=v3(-.82,.3,-.2).normalize();this.sky(group,'#3d5470','#c9a98f','#f2c58f',sunDir,0xffc98a);
|
| 304 |
+
return {sun:v3(-.72,.62,.3).normalize(),sunColor:0xffd09a,sunI:2.7,hemiSky:0xc8d4e8,hemiGround:0x6a5444,hemiI:1.45,fog:0xc4a994,fogNear:28,fogFar:120,exposure:1.05,shadowR:11,leaves:true};}
|
| 305 |
+
ridges(group,colors,radii,base,height){for(let layer=0;layer<colors.length;layer++){const m=new Mesher(),rad=radii[layer],h=height+layer*4;
|
| 306 |
+
const pt=i=>{const a=i*Math.PI/32,k=.45+.16*Math.sin(a*3+layer*1.7)+.12*Math.sin(a*7+1)+.08*Math.cos(a*13);return [Math.sin(a)*rad,base+h*k,Math.cos(a)*rad];};
|
| 307 |
+
const geo=new T.BufferGeometry(),pos=[];for(let i=0;i<64;i++){const p=pt(i),q=pt(i+1);pos.push(p[0],base-30,p[2],p[0],p[1],p[2],q[0],q[1],q[2],p[0],base-30,p[2],q[0],q[1],q[2],q[0],base-30,q[2]);}
|
| 308 |
+
geo.setAttribute('position',new T.Float32BufferAttribute(pos,3));geo.computeVertexNormals();const mesh=new T.Mesh(this.keep(geo),this.material(colors[layer],{side:T.DoubleSide,roughness:1}));group.add(mesh);}}
|
| 309 |
+
wateringHole(group){
|
| 310 |
+
const ground=this.material(0xffffff,{map:canvasTexture(512,(q,s)=>{q.fillStyle='#5e6a45';q.fillRect(0,0,s,s);for(let i=0;i<2600;i++){const v=hash(i,1);q.fillStyle=v<.5?`rgba(90,104,60,${.5})`:`rgba(120,110,80,${.35})`;q.fillRect(hash(i,2)*s,hash(i,3)*s,3+hash(i,4)*6,2+hash(i,5)*4);}},6),roughness:1});
|
| 311 |
+
const floor=new T.Mesh(this.keep(new T.CylinderGeometry(20,20,.4,48)),ground);floor.position.y=-.2;floor.receiveShadow=true;group.add(floor);
|
| 312 |
+
const water=new T.Mesh(this.keep(new T.CircleGeometry(9.5,48)),this.material(0x3f7f86,{transparent:true,opacity:.62,roughness:.12,metalness:.3,flat:false}));water.rotation.x=-Math.PI/2;water.position.y=.03;water.receiveShadow=true;group.add(water);
|
| 313 |
+
const rock=new Mesher(),grass=new Mesher(),tree=new Mesher(),lotus=new Mesher();
|
| 314 |
+
for(let i=0;i<34;i++){const a=i/34*Math.PI*2+hash(i,1)*.2,r=16.5+hash(i,2)*3,h=7+hash(i,3)*12,w=2.6+hash(i,4)*2.5;rock.add(P.gem,i%3?0x6a665e:0x5d5a52,M4(Math.sin(a)*r,h/2-1,Math.cos(a)*r,hash(i,5),a,hash(i,6)*.3,w,h/2,w*.8),0,.12);
|
| 315 |
+
if(i%2)grass.add(P.cone(.9,1.6,5),0x4e6b38,M4(Math.sin(a)*(r-1.2),h*.8,Math.cos(a)*(r-1.2),0,a,.4),0,.12);}
|
| 316 |
+
for(let i=0;i<220;i++){const a=hash(i,7)*Math.PI*2,r=9.6+hash(i,8)*5.2;grass.add(P.cone(.07+hash(i,9)*.05,.5+hash(i,10)*.9,3),hash(i,11)<.5?0x7f9a4a:0x99a35a,M4(Math.sin(a)*r,.3,Math.cos(a)*r,(hash(i,12)-.5)*.5,a,(hash(i,13)-.5)*.5),0,.15);}
|
| 317 |
+
for(let i=0;i<14;i++){const a=hash(i,14)*Math.PI*2,r=10+hash(i,15)*4;rock.add(P.gem,0x77736a,M4(Math.sin(a)*r,.1,Math.cos(a)*r,hash(i,16),hash(i,17),0,.4+hash(i,18)*.7,.3+hash(i,19)*.4,.5),0,.1);}
|
| 318 |
+
for(let i=0;i<16;i++){const a=hash(i,24)*Math.PI*2,r=2+hash(i,25)*6.5;lotus.add(P.disc,0x4f7a3c,M4(Math.sin(a)*r,.05,Math.cos(a)*r,0,0,0,.35,.02,.35));if(i%3===0)lotus.add(P.cone(.12,.18,6),0xe7c6d4,M4(Math.sin(a)*r,.16,Math.cos(a)*r));}
|
| 319 |
+
// a great tree leaning over the pool, hung with vines
|
| 320 |
+
tree.add(seg(11,.9,1.3,8),0x4c3b2c,M4(-11,11,-9,.12,0,.18),0,.1);for(let i=0;i<9;i++)tree.add(P.gem,0x3d5a31,M4(-9+hash(i,30)*5-2.5,10.5+hash(i,31)*2,-7.5+hash(i,32)*4-2,hash(i,33),hash(i,34),0,2.4,1.6,2.4),0,.12);
|
| 321 |
+
for(let i=0;i<7;i++)tree.add(P.box,0x3e5a2e,M4(-8.5+i*.9,7.5,-6.4+i*.3,0,0,0,.05,4+hash(i,35)*2,.05));
|
| 322 |
+
const mats={rock:this.material(0xffffff,{vertex:true}),grass:this.material(0xffffff,{vertex:true,side:T.DoubleSide}),tree:this.material(0xffffff,{vertex:true}),lotus:this.material(0xffffff,{vertex:true})};
|
| 323 |
+
this.static(group,rock,mats.rock);this.static(group,grass,mats.grass,false);this.static(group,tree,mats.tree);this.static(group,lotus,mats.lotus,false);
|
| 324 |
+
this.ridges(group,[0x55604f,0x6b7766,0x8a9586],[34,52,80],-4,16);
|
| 325 |
+
const sunDir=v3(.35,.85,-.4).normalize();this.sky(group,'#7d98a8','#c5cfc9','#e4e5d6',sunDir,0xfff1d2);
|
| 326 |
+
return {sun:sunDir,sunColor:0xfff0d6,sunI:2.4,hemiSky:0xdde8e4,hemiGround:0x4e5a3c,hemiI:1.35,fog:0xb7c2b5,fogNear:24,fogFar:95,exposure:1.0,shadowR:16,water};}
|
| 327 |
+
audienceChamber(group){
|
| 328 |
+
const planks=this.material(0xffffff,{map:canvasTexture(512,(q,s)=>{for(let y=0;y<16;y++){const v=58+Math.round(hash(y,1)*22);q.fillStyle=`rgb(${v+16},${v},${v-12})`;q.fillRect(0,y*s/16,s,s/16-2);
|
| 329 |
+
for(let i=0;i<30;i++){q.fillStyle=`rgba(20,12,8,${hash(i,y)*.25})`;q.fillRect(hash(i,y+5)*s,y*s/16+hash(i,y+9)*s/16,30+hash(i,y+3)*60,1);}}},3),roughness:.55});
|
| 330 |
+
const floor=new T.Mesh(this.keep(new T.BoxGeometry(19.6,.3,15.6)),planks);floor.position.y=-.15;floor.receiveShadow=true;group.add(floor);
|
| 331 |
+
const wood=new Mesher(),paper=new Mesher(),dark=new Mesher(),fire=new Mesher();
|
| 332 |
+
const pillars=[-6.6,-2.2,2.2,6.6].flatMap(x=>[[x,-4.6],[x,4.6]]);
|
| 333 |
+
for(const [x,z] of pillars){wood.add(P.cyl(.42,.46,5.6,10),0x6d3d2c,M4(x,2.8,z),0,.05);wood.add(P.cyl(.47,.5,.09,10),0x2a1a12,M4(x,1.0,z));wood.add(P.cyl(.47,.5,.09,10),0x2a1a12,M4(x,3.0,z));wood.add(P.cyl(.47,.5,.09,10),0x2a1a12,M4(x,4.9,z));wood.add(P.box,0x2b1a14,M4(x,.12,z,0,0,0,1.1,.24,1.1));wood.add(P.box,0x3a2219,M4(x,5.45,z,0,0,0,1.0,.3,1.0));}
|
| 334 |
+
for(const z of [-4.6,4.6])wood.add(P.box,0x4a281d,M4(0,5.3,z,0,0,0,19.4,.42,.5));for(const x of [-6.6,-2.2,2.2,6.6])wood.add(P.box,0x4a281d,M4(x,5.55,0,0,0,0,.45,.4,15.4));
|
| 335 |
+
dark.add(P.box,0x1b120e,M4(0,5.95,0,0,0,0,19.8,.2,15.8));
|
| 336 |
+
// shoji walls lit from behind by the burning estate; some panels burnt through
|
| 337 |
+
for(const z of [-7.75,7.75])for(let x=-9;x<9;x+=1.5){const burnt=hash(Math.round(x*3),z>0?1:2)<.22;(burnt?fire:paper).add(P.box,burnt?0xff7a2a:0xe7b98a,M4(x+.75,2.3,z,0,0,0,1.38,3.8,.04));
|
| 338 |
+
wood.add(P.box,0x2a1a12,M4(x,2.3,z,0,0,0,.08,4.6,.1));for(let y=.5;y<4.3;y+=.6)wood.add(P.box,0x2a1a12,M4(x+.75,y,z,0,0,0,1.5,.04,.06));}
|
| 339 |
+
for(const x of [-9.75,9.75])for(let z=-7.5;z<7.5;z+=1.5){paper.add(P.box,0xd9a679,M4(x,2.3,z+.75,0,0,0,.04,3.8,1.38));wood.add(P.box,0x2a1a12,M4(x,2.3,z,0,0,0,.1,4.6,.08));}
|
| 340 |
+
for(const s of [-1,1])wood.add(P.box,0x2a1a12,M4(0,4.35,s*7.7,0,0,0,19.6,.25,.2));
|
| 341 |
+
const mats={wood:this.material(0xffffff,{vertex:true,roughness:.7}),paper:this.material(0xffffff,{vertex:true,emissive:0xff9a4a,emissiveIntensity:.42,roughness:1}),dark:this.material(0xffffff,{vertex:true}),fire:this.keep(new T.MeshBasicMaterial({vertexColors:true,fog:false}))};
|
| 342 |
+
this.static(group,wood,mats.wood);this.static(group,paper,mats.paper,false);this.static(group,dark,mats.dark,false);const f=new T.Mesh(this.keep(fire.geometry()),mats.fire);group.add(f);
|
| 343 |
+
// illusory strands between the pillar tops (S17: she walks on threads strung around the hall)
|
| 344 |
+
const lines=[];const tops=pillars.map(([x,z])=>[x,4.6,z]);for(let i=0;i<tops.length;i++)for(let j=i+1;j<tops.length;j++){const d=Math.hypot(tops[i][0]-tops[j][0],tops[i][2]-tops[j][2]);if(d<4.5||Math.abs(d-9.2)<.1&&tops[i][0]===tops[j][0])lines.push(...tops[i],...tops[j]);}
|
| 345 |
+
for(const [i,j] of [[0,3],[2,5],[4,7]])lines.push(tops[i][0],3.9,tops[i][2],tops[j][0],4.3,tops[j][2]);
|
| 346 |
+
const lg=this.keep(new T.BufferGeometry());lg.setAttribute('position',new T.Float32BufferAttribute(lines,3));group.add(new T.LineSegments(lg,this.keep(new T.LineBasicMaterial({color:0xdfe8ff,transparent:true,opacity:.28,fog:false}))));
|
| 347 |
+
const fireLights=[[-4,3,-8.6],[5,3,8.6],[9.8,2.6,-3]].map(p=>{const l=new T.PointLight(0xff8a3a,6,14,1.4);l.position.set(...p);group.add(l);return l;});
|
| 348 |
+
return {sun:v3(.3,1,.25).normalize(),sunColor:0xb4c2ee,sunI:2.1,hemiSky:0x7a7fa6,hemiGround:0x4a2e20,hemiI:1.9,fog:0x231915,fogNear:14,fogFar:44,exposure:1.3,shadowR:12,fireLights,embers:true,background:0x140d0b};}
|
| 349 |
+
|
| 350 |
+
/* ---------------- per-frame */
|
| 351 |
+
// Original set for the final duel: a wide field of silver grass under a low sun, cliffs and a far castle (S27).
|
| 352 |
+
silvergrass(group){
|
| 353 |
+
const ground=this.material(0xffffff,{map:canvasTexture(512,(q,s)=>{q.fillStyle='#8d8a6a';q.fillRect(0,0,s,s);for(let i=0;i<3000;i++){const v=hash(i,1);q.fillStyle=v<.5?'rgba(170,165,125,.45)':'rgba(92,92,66,.4)';q.fillRect(hash(i,2)*s,hash(i,3)*s,2+hash(i,4)*7,1+hash(i,5)*2);}},6),roughness:1});
|
| 354 |
+
const floor=new T.Mesh(this.keep(new T.CylinderGeometry(60,60,.4,48)),ground);floor.position.y=-.2;floor.receiveShadow=true;group.add(floor);
|
| 355 |
+
const grass=new Mesher(),rock=new Mesher(),far=new Mesher();
|
| 356 |
+
// low trampled tufts inside the fighting circle, full stems with pale plumes outside it
|
| 357 |
+
for(let i=0;i<150;i++){const a=hash(i,6)*Math.PI*2,r=2+hash(i,7)*10.6;grass.add(P.cone(.05+hash(i,8)*.04,.22+hash(i,9)*.2,3),hash(i,10)<.5?0xa8a47c:0x8f9068,M4(Math.sin(a)*r,.13,Math.cos(a)*r,(hash(i,11)-.5)*.5,a,(hash(i,12)-.5)*.5),0,.12);}
|
| 358 |
+
for(let i=0;i<620;i++){const a=hash(i,13)*Math.PI*2,r=13.4+hash(i,14)*hash(i,14)*24,h=.9+hash(i,15)*1.1,x=Math.sin(a)*r,z=Math.cos(a)*r,lean=.15+hash(i,16)*.3;
|
| 359 |
+
grass.add(P.cone(.028,h,3),hash(i,17)<.5?0xc2bd8c:0xaeb07f,M4(x,h/2,z,0,a,lean),0,.1);grass.add(P.gem,hash(i,18)<.6?0xf6f1e2:0xe8e1c8,M4(x+Math.sin(lean)*h*.5,h+.02,z,lean,a,0,.03,.13,.03),0,.06);}
|
| 360 |
+
for(let i=0;i<30;i++){const a=i/30*Math.PI*2+hash(i,19)*.2,r=52+hash(i,20)*10,h=5+hash(i,21)*8,w=4+hash(i,22)*4;rock.add(P.gem,i%3?0x9a9586:0xa8a292,M4(Math.sin(a)*r,h/2-1,Math.cos(a)*r,hash(i,23),a,hash(i,24)*.3,w,h/2,w*.8),0,.12);}
|
| 361 |
+
// the far castle keep on its rise, as a silhouette
|
| 362 |
+
for(let i=0;i<4;i++){const w=9-i*1.7,y=11+i*2.8;far.add(P.box,0x4a4b52,M4(-40,y,-74,0,0,0,w,2.3,w));far.add(P.box,0x33343a,M4(-40,y+1.35,-74,0,0,0,w*1.3,.45,w*1.3));}far.add(P.box,0x55565a,M4(-40,4,-74,0,0,0,18,10,18),0,.05);
|
| 363 |
+
const mats={grass:this.material(0xffffff,{vertex:true,side:T.DoubleSide}),rock:this.material(0xffffff,{vertex:true}),far:this.material(0xffffff,{vertex:true})};
|
| 364 |
+
this.static(group,grass,mats.grass,false);this.static(group,rock,mats.rock);this.static(group,far,mats.far);
|
| 365 |
+
this.ridges(group,[0x62687a,0x7b8294,0x9da3b1],[60,84,120],-6,20);
|
| 366 |
+
const sunDir=v3(-.55,.6,-.55).normalize();this.sky(group,'#7d8aa3','#d6b89a','#f0d7ae',sunDir,0xffe2b0);
|
| 367 |
+
return {sun:sunDir,sunColor:0xffe7c4,sunI:2.3,hemiSky:0xdde0e6,hemiGround:0x6f6c50,hemiI:1.3,fog:0xd8c9ad,fogNear:22,fogFar:92,exposure:1,shadowR:15,plumes:true};}
|
| 368 |
+
// Original set: a wide packed-earth yard before a castle gate at dusk, low walls, a burning brazier ring and far ridges (S31 names only "a large arena").
|
| 369 |
+
castleGate(group){
|
| 370 |
+
const ground=this.material(0xffffff,{map:canvasTexture(512,(q,s)=>{q.fillStyle='#6d5f4a';q.fillRect(0,0,s,s);for(let i=0;i<3200;i++){q.fillStyle=hash(i,1)<.5?'rgba(120,104,82,.45)':'rgba(70,60,46,.4)';q.fillRect(hash(i,2)*s,hash(i,3)*s,2+hash(i,4)*6,1+hash(i,5)*3);}},8),roughness:1});
|
| 371 |
+
const floor=new T.Mesh(this.keep(new T.CylinderGeometry(70,70,.4,48)),ground);floor.position.y=-.2;floor.receiveShadow=true;group.add(floor);
|
| 372 |
+
const wall=new Mesher(),wood=new Mesher(),roof=new Mesher(),fire=new Mesher();
|
| 373 |
+
for(let i=0;i<40;i++){const a=i/40*Math.PI*2,r=23,x=Math.sin(a)*r,z=Math.cos(a)*r;wall.add(P.box,i%2?0x8a8476:0x7c7668,M4(x,1.1,z,0,a,0,3.9,2.2,.9),0,.08);roof.add(P.box,0x2e2c30,M4(x,2.35,z,0,a,0,4.3,.25,1.5),0,.05);}
|
| 374 |
+
// the gate across the far side, in timber with a tiled roof
|
| 375 |
+
wood.add(P.box,0x3a2a20,M4(0,3.4,-23.4,0,0,0,9,6.8,1.2),0,.05);wood.add(P.box,0x241a14,M4(0,2.6,-22.7,0,0,0,5,5.2,.3),0,.05);for(const x of [-3.6,3.6])wood.add(P.box,0x2c2018,M4(x,3.4,-22.6,0,0,0,.6,6.8,.6));roof.add(P.box,0x26252a,M4(0,7.2,-23.4,0,0,0,12,.7,3.2));roof.add(P.box,0x1f1e22,M4(0,7.9,-23.4,0,0,0,8,.6,2));
|
| 376 |
+
for(let i=0;i<8;i++){const a=(i+.5)/8*Math.PI*2,x=Math.sin(a)*21,z=Math.cos(a)*21;wood.add(P.cyl(.14,.2,1.5,6),0x2c2420,M4(x,.75,z),0,.05);fire.add(P.cone(.17,.42,6),0xff8a3a,M4(x,1.66,z));}
|
| 377 |
+
const mats={wall:this.material(0xffffff,{vertex:true}),wood:this.material(0xffffff,{vertex:true}),roof:this.material(0xffffff,{vertex:true}),fire:this.keep(new T.MeshBasicMaterial({vertexColors:true}))};
|
| 378 |
+
this.static(group,wall,mats.wall);this.static(group,wood,mats.wood);this.static(group,roof,mats.roof);this.static(group,fire,mats.fire,false);
|
| 379 |
+
this.ridges(group,[0x4f4a58,0x635c68,0x847a80],[60,84,120],-6,20);
|
| 380 |
+
const sunDir=v3(.5,.5,-.7).normalize();this.sky(group,'#58607c','#c79a84','#efc79a',sunDir,0xffd8a8);
|
| 381 |
+
return {sun:sunDir,sunColor:0xffdcb8,sunI:2.2,hemiSky:0xd6d6e4,hemiGround:0x5e5240,hemiI:1.25,fog:0xc9b49c,fogNear:30,fogFar:130,exposure:1,shadowR:18};}
|
| 382 |
+
// The gate yard again, burning: the same wall ring, charred timber, fires everywhere, a red sky and embers (S36).
|
| 383 |
+
burningGate(group){
|
| 384 |
+
const ground=this.material(0xffffff,{map:canvasTexture(512,(q,s)=>{q.fillStyle='#5a4636';q.fillRect(0,0,s,s);for(let i=0;i<3200;i++){q.fillStyle=hash(i,1)<.5?'rgba(96,70,52,.45)':'rgba(28,20,16,.45)';q.fillRect(hash(i,2)*s,hash(i,3)*s,2+hash(i,4)*6,1+hash(i,5)*3);}},8),roughness:1});
|
| 385 |
+
const floor=new T.Mesh(this.keep(new T.CylinderGeometry(70,70,.4,48)),ground);floor.position.y=-.2;floor.receiveShadow=true;group.add(floor);
|
| 386 |
+
const wall=new Mesher(),wood=new Mesher(),roof=new Mesher(),fire=new Mesher();
|
| 387 |
+
for(let i=0;i<40;i++){const a=i/40*Math.PI*2,r=21,x=Math.sin(a)*r,z=Math.cos(a)*r;wall.add(P.box,i%2?0x4e4842:0x423c38,M4(x,1.1,z,0,a,0,3.4,2.2,.9),0,.08);if(i%3)roof.add(P.box,0x1c1a1c,M4(x,2.35,z,0,a,.06*(i%4-1.5),3.8,.25,1.5),0,.05);
|
| 388 |
+
if(i%4===1)for(let k=0;k<3;k++)fire.add(P.cone(.35-k*.08,1.2+k*.3,6),k%2?0xff7a2a:0xffb84a,M4(x*.98+k*.3-.3,2.9+k*.3,z*.98));}
|
| 389 |
+
wood.add(P.box,0x241a14,M4(0,3.4,-21.4,0,0,0,9,6.8,1.2),0,.05);wood.add(P.box,0x140e0a,M4(0,2.6,-20.7,0,0,0,5,5.2,.3),0,.05);for(const x of [-3.6,3.6])wood.add(P.box,0x1c140e,M4(x,3.4,-20.6,0,0,0,.6,6.8,.6));roof.add(P.box,0x1a191c,M4(0,7.2,-21.4,.06,0,.05,12,.7,3.2));
|
| 390 |
+
for(let i=0;i<9;i++){const x=-4+i,h=1+hash(i,7)*1.6;fire.add(P.cone(.5,h+.6,6),i%2?0xff6a20:0xffa840,M4(x,7.6+h*.3,-21.4));}
|
| 391 |
+
for(let i=0;i<10;i++){const a=(i+.5)/10*Math.PI*2,x=Math.sin(a)*18.4,z=Math.cos(a)*18.4;wood.add(P.box,0x1a120e,M4(x,.4,z,.2,a,.3,1.6,.3,.3),0,.05);fire.add(P.cone(.3,.9+hash(i,3)*.6,6),0xff8a3a,M4(x,.9,z));}
|
| 392 |
+
const mats={wall:this.material(0xffffff,{vertex:true}),wood:this.material(0xffffff,{vertex:true}),roof:this.material(0xffffff,{vertex:true}),fire:this.keep(new T.MeshBasicMaterial({vertexColors:true}))};
|
| 393 |
+
this.static(group,wall,mats.wall);this.static(group,wood,mats.wood);this.static(group,roof,mats.roof);this.static(group,fire,mats.fire,false);
|
| 394 |
+
this.ridges(group,[0x2a1c1c,0x3a2424,0x52302a],[60,84,120],-6,20);
|
| 395 |
+
const sunDir=v3(-.4,.45,-.8).normalize();this.sky(group,'#1e1014','#7a2a1c','#e0743a',sunDir,0xff9a50);
|
| 396 |
+
return {sun:sunDir,sunColor:0xffb27a,sunI:1.8,hemiSky:0xe0a890,hemiGround:0x6a4030,hemiI:1.6,fog:0x5a3428,fogNear:30,fogFar:120,exposure:1.2,shadowR:18,embersWide:true};}
|
| 397 |
+
setArena(kind){if(this.kind===kind)return;for(const [k,a] of Object.entries(this.arenas))a.group.visible=false;const a=this.arena(kind);a.group.visible=true;this.kind=kind;
|
| 398 |
+
for(const [k,m] of Object.entries(this.bosses))m.holder.visible=k===kind;
|
| 399 |
+
this.world.background=a.background!=null?new T.Color(a.background):null;this.world.fog.color.set(a.fog);this.world.fog.near=a.fogNear;this.world.fog.far=a.fogFar;
|
| 400 |
+
this.hemi.color.set(a.hemiSky);this.hemi.groundColor.set(a.hemiGround);this.sun.color.set(a.sunColor);this.renderer.toneMappingExposure=a.exposure;
|
| 401 |
+
const sc=this.sun.shadow.camera;sc.left=-a.shadowR;sc.right=a.shadowR;sc.top=a.shadowR;sc.bottom=-a.shadowR;sc.updateProjectionMatrix();}
|
| 402 |
+
place(pool,i,pos,scale,rot,color){if(i>=pool.instanceMatrix.count)return i;const d=this.dummy;d.position.set(pos[0],pos[1],pos[2]);
|
| 403 |
+
if(Array.isArray(scale))d.scale.set(scale[0],scale[1],scale[2]);else d.scale.setScalar(scale);if(rot&&rot.isQuaternion)d.quaternion.copy(rot);else d.rotation.set(...(rot||[0,0,0]));
|
| 404 |
+
d.updateMatrix();pool.setMatrixAt(i,d.matrix);pool.setColorAt(i,this.tmp.set(color??0xffffff));return i+1;}
|
| 405 |
+
dir(dx,dy,dz){const a=v3(dx,dy,dz);if(a.lengthSq()<1e-12)return new T.Quaternion();return new T.Quaternion().setFromUnitVectors(v3(0,0,1),a.normalize());}
|
| 406 |
+
link(pool,i,a,b,w,color){const dx=b[0]-a[0],dy=b[1]-a[1],dz=b[2]-a[2];return this.place(pool,i,[(a[0]+b[0])/2,(a[1]+b[1])/2,(a[2]+b[2])/2],[w,w,Math.hypot(dx,dy,dz)],this.dir(dx,dy,dz),color);}
|
| 407 |
+
finish(pool,n){pool.count=n;pool.instanceMatrix.needsUpdate=true;if(pool.instanceColor)pool.instanceColor.needsUpdate=true;}
|
| 408 |
+
playerPose(p,tm){const a=String(p.action||''),t=Number(p.actionTick||0);let q=H.stance;
|
| 409 |
+
const moving=a==='walk'||a==='run';
|
| 410 |
+
if(p.dead)q=H.dead;
|
| 411 |
+
else if(a==='posture_break'||a==='safety_roll')q=mixPose(H.hurt,H.kneel,band(t,0,8));
|
| 412 |
+
else if(a==='hurt')q=mixPose(H.hurt,H.stance,band(t,6,16));
|
| 413 |
+
else if(a==='heal')q=mixPose(H.stance,H.drink,band(t,0,10)*(1-band(t,56,66)));
|
| 414 |
+
else if(a==='revive')q=mixPose(H.kneel,H.stance,band(t,10,48));
|
| 415 |
+
else if(a==='deathblow')q=t<26?mixPose(H.pull,H.lunge,band(t,12,20)):mixPose(H.lunge,H.cut,band(t,30,44));
|
| 416 |
+
else if(p.charge>0)q=mixPose(H.stance,H.pull,band(p.charge,0,8));
|
| 417 |
+
else if(p.attackTick>=0)q=p.attackKind==='thrust'?(p.attackTick<10?mixPose(H.pull,H.lunge,band(p.attackTick,6,10)):mixPose(H.lunge,H.stance,band(p.attackTick,18,34))):
|
| 418 |
+
(p.attackTick<5?mixPose(H.stance,H.raise,band(p.attackTick,0,4)):p.attackTick<9?mixPose(H.raise,H.cut,band(p.attackTick,5,8)):mixPose(H.cut,H.stance,band(p.attackTick,12,25)));
|
| 419 |
+
else if(p.y>0)q=p.stomped&&p.vy>0?H.kick:H.tuck;
|
| 420 |
+
else if(p.dodgeTicks>0)q=mixPose(H.stance,H.low,.45);
|
| 421 |
+
else if(p.guarding)q=p.guardAge<6?mixPose(H.guard,H.backCut,.35*(1-p.guardAge/6)):H.guard;
|
| 422 |
+
if(moving&&!p.guarding)q=walkCycle(q,tm*(a==='run'?13:9),1,a==='run');else if(moving)q=walkCycle(q,tm*7,.5,false);
|
| 423 |
+
return q;}
|
| 424 |
+
posePlayer(g){const p=g.player,m=this.player,a=String(p.action||''),t=Number(p.actionTick||0),tm=g.t/60;
|
| 425 |
+
applyPose(m,this.playerPose(p,tm));const b=m.bones;b.sodeL.scale.setScalar(.001);b.sodeR.scale.setScalar(.001);b.tool.scale.setScalar(a==='heal'?1:.001);b.blade.scale.setScalar(1);b.scab.rotation.set(.5,0,.2);b.back.rotation.set(.3+Math.sin(tm*3)*.08,0,0);
|
| 426 |
+
const dead=p.dead?1:0,lie=dead?-1.45*band(t,0,24):0;
|
| 427 |
+
m.holder.position.set(p.x||0,(p.y||0)+(dead?.12:0),p.z||0);m.holder.rotation.set(0,p.yaw||0,0);m.mesh.rotation.set(lie,0,0);
|
| 428 |
+
return m;}
|
| 429 |
+
humanPose(g,b,moves,kind){const a=String(b.action||''),mv=moves?.[a],t=Number(b.state==='attack'?b.moveTick:b.actionTick||0),tm=g.t/60;let q=H.stance,tool=false;
|
| 430 |
+
if(b.state==='execution'||b.action==='deathblow')q=mixPose(H.kneel,H.dead,band(t,20,50));
|
| 431 |
+
else if(b.state==='deathblow'||a==='posture_break')q=mixPose(H.hurt,H.kneel,band(t,0,10));
|
| 432 |
+
else if(a==='stagger'||a==='rising')q=a==='rising'&&kind==='genichiro'?mixPose(H.kneel,H.stance,band(t,4,36)):H.hurt;
|
| 433 |
+
else if(b.state==='attack'&&mv){
|
| 434 |
+
const bow=/bow|volley|charged|quick_bow|opening/.test(a)&&kind==='genichiro';
|
| 435 |
+
if(bow&&(mv.shots||[]).length&&!(a==='bow_roll'&&t>46)&&!(a==='opening'&&t>30)){tool=true;const shot=(mv.shots||[]).find(s=>t<=s+10)??mv.shots.at(-1);q=t<shot-1?mixPose(H.stance,H.draw,band(t,shot-26,shot-12)):mixPose(H.release,H.stance,band(t,shot+4,shot+16));}
|
| 436 |
+
else if(a.startsWith('lightning')){q=t<16?mixPose(H.stance,H.low,band(t,0,10)):t<98?H.overhead:mixPose(H.overhead,H.chop,band(t,98,101));}
|
| 437 |
+
else if(a==='tomoe_awaken')q=mixPose(H.spread,H.stance,band(t,46,70));
|
| 438 |
+
else if(a==='isshin_emerge')q=mixPose(H.kneel,H.stance,band(t,34,84));
|
| 439 |
+
else if(kind==='isshin'&&mv.gun){const at=mv.gun.find(x=>t<=x+7)??mv.gun.at(-1);q=mixPose(H.stance,H.aim,band(t,at-14,at-6)*(1-band(t,at+8,at+16)));}
|
| 440 |
+
else if(kind==='isshin'&&(mv.waves||mv.stomp))q=strikePose(H.stance,[...mv.hits,...(mv.waves||[]).map(([at,w])=>({t:at,type:w==='v'?'slam':'sweep'})),...(mv.stomp||[]).map(at=>({t:at,type:'slam'}))].sort((x,y)=>x.t-y.t),t,{wind:12,follow:10});
|
| 441 |
+
else if(kind==='butterfly'&&(a==='thread_up'||a==='thread_hover'||a==='waltz'))q=H.hover;
|
| 442 |
+
else if(kind==='butterfly'&&(a==='illusion'||a==='dispel'))q=mixPose(H.stance,H.cast,band(t,8,24)*(1-band(t,40,56)));
|
| 443 |
+
else if(kind==='butterfly'&&a==='kunai_throw'||mv.kunai&&!mv.hits.length){const k=(mv.kunai||[]).find(([s])=>t<=s+8);q=k?mixPose(H.backRaise,H.cut,band(t,k[0]-4,k[0])):H.stance;}
|
| 444 |
+
else q=strikePose(H.stance,mv.hits,t,{wind:kind==='butterfly'?8:12,follow:kind==='butterfly'?7:10});
|
| 445 |
+
if(kind==='butterfly'&&(a==='leg_drop'||a==='three_strike')&&b.y>.3)q=mixPose(q,H.tuck,.6);
|
| 446 |
+
if(kind==='butterfly'&&a==='sweep')q=mixPose(q,H.low,.7);
|
| 447 |
+
}
|
| 448 |
+
const moving=kind!=='gyoubu'&&b.state==='idle'&&Math.hypot((g.player.x||0)-(b.x||0),(g.player.z||0)-(b.z||0))>2.4;if(moving)q=walkCycle(q,tm*8,.8,false);
|
| 449 |
+
if(kind==='gyoubu'){q={...q,y:.72+(q.y||0)*.25,lHip:[-.95,0,.75],rHip:[-.95,0,-.75],lKnee:[1.25,0,0],rKnee:[1.25,0,0],lAnk:[-.3,0,0],rAnk:[-.3,0,0]};}
|
| 450 |
+
return {q,tool};}
|
| 451 |
+
poseHuman(g,m,b,moves,kind){const a=String(b.action||''),t=Number(b.state==='attack'?b.moveTick:b.actionTick||0),tm=g.t/60,{q,tool}=this.humanPose(g,b,moves,kind);
|
| 452 |
+
applyPose(m,q);const bones=m.bones;bones.tool.scale.setScalar(tool?1:.001);if(kind==='genichiro')bones.tool.rotation.set(tool?1.45:0,0,0);
|
| 453 |
+
if(kind==='genichiro'){const armored=b.form_id!=='tomoe'||(a==='tomoe_awaken'&&t<40);for(const n of ['armor','skirt','sodeL','sodeR'])bones[n].scale.setScalar(armored?1:.001);bones.back.scale.setScalar(tool?.001:1);}
|
| 454 |
+
if(kind!=='genichiro'){bones.tool.scale.setScalar(1);bones.back.scale.setScalar(1);bones.sodeL.scale.setScalar(.001);bones.sodeR.scale.setScalar(.001);}
|
| 455 |
+
// Which weapon he holds follows the move: spear, matchlock or katana; the slung spear appears with his second life (S27).
|
| 456 |
+
if(kind==='isshin'){const st=b.state==='attack',spear=st&&ISSHIN_SPEAR.test(a),gun=st&&/^(quad_shot|quick_gun)$/.test(a);bones.spear.scale.setScalar(spear?1:.001);bones.gun.scale.setScalar(gun?1:.001);bones.blade.scale.setScalar(spear||gun?.001:1);bones.back.scale.setScalar((b.phase||1)>=3&&!spear?1:.001);bones.active=spear?bones.spear:null;}
|
| 457 |
+
if(kind==='gyoubu'){bones.blade.scale.setScalar(.001);bones.back.scale.setScalar(.001);bones.tool.scale.setScalar(.001);bones.active=bones.spear;
|
| 458 |
+
const mv=root.SekiroGame?.bosses?.gyoubu?.moves?.[a],run=b.state==='attack'&&(mv?.ride||mv?.away)?1:b.state==='idle'?.35:0,ph=tm*(run>.5?15:7),amp=run>.5?.75:.28*run/.35;
|
| 459 |
+
for(const [n,o] of [['hFL',0],['hBR',.4],['hFR',1.6],['hBL',2]])bones[n].rotation.set(Math.sin(ph+o)*amp,0,0);bones.hBody.rotation.set((b.y||0)>.3?-.28:Math.sin(ph*2)*.03*run,0,0);bones.hBody.position.y=1.32+Math.abs(Math.sin(ph))*.07*run;bones.hNeck.rotation.set(Math.sin(ph)*.1*run,0,0);}
|
| 460 |
+
bones.scab.rotation.set(.5,0,.2);bones.tail.rotation.set(.2+Math.sin(tm*2.5)*.06,0,0);
|
| 461 |
+
const lie=(b.state==='execution'?-1.4*band(t,24,50):0);m.holder.position.set(b.x||0,b.y||0,b.z||0);m.holder.rotation.set(0,b.yaw||0,0);m.mesh.rotation.set(lie,0,0);
|
| 462 |
+
const flash=(b.flash||0)/8;m.mat.emissive.setRGB(.3*flash,.25*flash,.25*flash);m.mat.emissiveIntensity=1;
|
| 463 |
+
return {};}
|
| 464 |
+
poseApe(g,m,b){applyPose(m,this.apePose(g,b),{hipY:1.25});const bn=m.bones,head=b.form_id==='headless';
|
| 465 |
+
const off=head||b.state==='dead';bn.head.scale.setScalar(off?.001:1);bn.neckBlade.scale.setScalar(off?.001:1);bn.blade.scale.setScalar(head?1:.001);bn.held.scale.setScalar(head?1:.001);bn.stump.scale.setScalar(off?1:.001);
|
| 466 |
+
m.holder.position.set(b.x||0,b.y||0,b.z||0);m.holder.rotation.set(0,b.yaw||0,0);
|
| 467 |
+
// the severed head lies beside the body during the false Shinobi Execution (S14)
|
| 468 |
+
this.severed.visible=b.state==='dead';if(this.severed.visible){const s=Math.sin(b.yaw||0),c=Math.cos(b.yaw||0);this.severed.position.set((b.x||0)+s*1.8+c*.8,.28,(b.z||0)+c*1.8-s*.8);this.severed.rotation.set(.4,(b.yaw||0)+2.2,.5);}
|
| 469 |
+
const flash=(b.flash||0)/8;m.mat.emissive.setRGB(.3*flash,.25*flash,.25*flash);
|
| 470 |
+
return {};}
|
| 471 |
+
// The demon stands upright on the ape-style rig; each move gets a readable key pose from its hit times.
|
| 472 |
+
poseDemon(g,m,b){const a=String(b.action||''),mv=root.SekiroGame?.bosses?.demon?.moves?.[a],t=Number(b.state==='attack'?b.moveTick:b.actionTick||0),tm=g.t/60;
|
| 473 |
+
const q={hips:[.15,0,0],spine:[.12,0,0],chest:[.08,0,0],neck:[-.2,0,0],head:[-.1,0,0],lSh:[-.3,0,.35],lEl:[-.5,0,0],lWr:[0,0,0],rSh:[-.25,0,-.35],rEl:[-.4,0,0],rWr:[0,0,0],lHip:[-.25,0,.12],lKnee:[.4,0,0],lAnk:[-.15,0,0],rHip:[-.25,0,-.12],rKnee:[.4,0,0],rAnk:[-.15,0,0],y:-.1};
|
| 474 |
+
const set=(j,x,y,z)=>{q[j]=[x,y,z];},ad=(j,x,y,z)=>{q[j]=[q[j][0]+x,q[j][1]+y,q[j][2]+z];};
|
| 475 |
+
if(b.state==='idle'){const s=Math.sin(tm*4);ad('lHip',-s*.25,0,0);ad('rHip',s*.25,0,0);ad('chest',Math.abs(s)*.05,0,0);}
|
| 476 |
+
if(b.state==='attack'&&mv){const hits=mv.hits||[],near=hits.find(h=>t>=h.t-20&&t<=h.t+12);
|
| 477 |
+
const arm=(side,u,v)=>{ad(side+'Sh',-2.6*u+2.4*v,0,0);ad(side+'El',-.4*u,0,0);ad('chest',0,(side==='l'?1:-1)*(.5*u-1.0*v),0);};
|
| 478 |
+
if(near){const u=band(t,near.t-18,near.t-4),v=band(t,near.t-3,near.t+1);
|
| 479 |
+
if(near.type==='slam'&&/stomp/.test(a)){const side=a==='double_stomp'&&hits.indexOf(near)===1?'r':a==='double_stomp'?'l':'r';ad(side+'Hip',-1.3*u+1.3*v,0,0);ad(side+'Knee',1.0*u-1.0*v,0,0);}
|
| 480 |
+
else if(a==='headbutt'){ad('chest',-.6*u+1.1*v,0,0);ad('neck',-.4*u+.6*v,0,0);}
|
| 481 |
+
else if(near.type==='sweep'){set('rSh',-.5,0,-.2);ad('hips',.7*u,0,0);ad('rSh',-.8*u,0,-1.2*u+1.6*v);}
|
| 482 |
+
else arm(near.noDeflect||a==='whip_slam'?'l':'r',u,v);}
|
| 483 |
+
if(mv.ride&&t>=mv.ride[0]&&t<mv.ride[1]){set('hips',.9,0,0);set('rSh',-.4,0,-.2);set('rEl',0,0,0);const s=Math.sin(t*.6);ad('lHip',-s*.6,0,0);ad('rHip',s*.6,0,0);}
|
| 484 |
+
if(mv.leap){const air=(b.y||0)>.3;if(air){set('lHip',-1.4,0,.3);set('rHip',-1.4,0,-.3);set('lKnee',1.6,0,0);set('rKnee',1.6,0,0);set('lSh',-2.4,0,.6);set('rSh',-2.4,0,-.6);}else if(t<mv.leap[0]){const u=band(t,10,mv.leap[0]);q.y-=.5*u;ad('lKnee',.9*u,0,0);ad('rKnee',.9*u,0,0);}}
|
| 485 |
+
if(mv.lobs||mv.homing){set('lSh',-2.8+Math.sin(t*.25)*.4,0,.4);set('rSh',-2.8-Math.sin(t*.25)*.4,0,-.4);}
|
| 486 |
+
if(mv.shots||mv.waves){const at=(mv.shots||mv.waves).find(x=>t<=x+8)??0;const u=band(t,at-20,at-4),v=band(t,at-3,at+1);if(mv.waves){ad('rHip',-1.6*u+1.0*v,0,-.8*u);}else arm('l',u,v);}
|
| 487 |
+
if(a==='fire_ring'&&t<84){set('lSh',-1.2,0,1.4);set('rSh',-1.2,0,-1.4);ad('chest',0,Math.sin(t*.3)*.4,0);}
|
| 488 |
+
if(a==='crouch'){set('hips',.9,0,0);q.y=-.9;set('lSh',-1.6,0,.4);set('rSh',-1.6,0,-.4);ad('lKnee',1.2,0,0);ad('rKnee',1.2,0,0);}
|
| 489 |
+
}
|
| 490 |
+
if(b.state==='stunned')ad('chest',-.35,0,0);
|
| 491 |
+
if(b.state==='deathblow'){ad('chest',.6,0,0);q.y-=.5;ad('lKnee',.8,0,0);ad('rKnee',.8,0,0);}
|
| 492 |
+
if(b.state==='dead'||b.state==='execution'){set('hips',1.4,0,0);set('lSh',-2.6,0,.6);set('rSh',-2.6,0,-.6);q.y=-1.5;}
|
| 493 |
+
applyPose(m,q,{hipY:1.9});const bn=m.bones;bn.flame.scale.setScalar(1+Math.sin(tm*14)*.12);bn.cape.rotation.set(.2+Math.sin(tm*2)*.06,0,0);
|
| 494 |
+
m.holder.position.set(b.x||0,b.y||0,b.z||0);m.holder.rotation.set(0,b.yaw||0,0);
|
| 495 |
+
const flash=(b.flash||0)/8;m.mat.emissive.setRGB(.3*flash,.25*flash,.25*flash);return {};}
|
| 496 |
+
apePose(g,b){const a=String(b.action||''),mv=root.SekiroGame?.bosses?.ape?.moves?.[a],t=Number(b.state==='attack'?b.moveTick:b.actionTick||0),tm=g.t/60,head=b.form_id==='headless';
|
| 497 |
+
const q={hips:[0,0,0],spine:[0,0,0],chest:[0,0,0],neck:[0,0,0],head:[0,0,0],lSh:[0,0,0],lEl:[0,0,0],lWr:[0,0,0],rSh:[0,0,0],rEl:[0,0,0],rWr:[0,0,0],lHip:[0,0,0],lKnee:[0,0,0],lAnk:[0,0,0],rHip:[0,0,0],rKnee:[0,0,0],rAnk:[0,0,0],y:0};
|
| 498 |
+
const set=(j,x,y,z)=>{q[j]=[x,y,z];},ad=(j,x,y,z)=>{q[j]=[q[j][0]+x,q[j][1]+y,q[j][2]+z];};
|
| 499 |
+
// quadruped base: body pitched forward onto the knuckles; headless form stands hunched upright
|
| 500 |
+
if(!head){set('hips',.9,0,0);set('spine',.25,0,0);set('chest',.1,0,0);set('neck',-.85,0,0);set('head',-.25,0,0);set('lSh',-.95,0,.08);set('rSh',-.95,0,-.08);set('lEl',.2,0,0);set('rEl',.2,0,0);
|
| 501 |
+
set('lHip',-.95,0,.12);set('rHip',-.95,0,-.12);set('lKnee',1.35,0,0);set('rKnee',1.35,0,0);set('lAnk',-.4,0,0);set('rAnk',-.4,0,0);q.y=-.22;}
|
| 502 |
+
else{set('hips',.25,0,0);set('spine',.2,0,0);set('chest',.1,0,0);set('lSh',-.5,0,.25);set('lEl',-.9,0,0);set('rSh',-.6,0,-.25);set('rEl',-.4,0,0);set('rWr',-.6,0,0);
|
| 503 |
+
set('lHip',-.45,0,.1);set('rHip',-.25,0,-.1);set('lKnee',.7,0,0);set('rKnee',.6,0,0);set('lAnk',-.25,0,0);q.y=-.15;}
|
| 504 |
+
const moving=b.state==='idle'&&!head;if(moving){const s=Math.sin(tm*7),c=Math.cos(tm*7);ad('lSh',s*.45,0,0);ad('rSh',-s*.45,0,0);ad('lHip',-s*.4,0,0);ad('rHip',s*.4,0,0);q.y+=Math.abs(c)*.08;}
|
| 505 |
+
if(head&&b.state==='idle'){const s=Math.sin(tm*5);ad('lHip',-s*.25,0,0);ad('rHip',s*.25,0,0);}
|
| 506 |
+
if(b.state==='attack'&&mv){
|
| 507 |
+
const hits=mv.hits||[],near=hits.find(h=>t>=h.t-16&&t<=h.t+10);
|
| 508 |
+
if(!head&&(a==='slam_combo'||a==='swipe_leap'&&t<50)&&near){const i=hits.indexOf(near),side=i%2?'l':'r',u=band(t,near.t-14,near.t-4),v=band(t,near.t-3,near.t);
|
| 509 |
+
ad('hips',-.75*u+.5*v,0,0);ad('chest',-.2*u,0,0);ad(side+'Sh',-2.4*u+2.6*v,0,0);ad(side+'El',-.3*u,0,0);}
|
| 510 |
+
if(a==='swipe_leap'&&t>=50){const u=band(t,56,72),v=band(t,80,84);ad('hips',-.6*u+.4*v,0,0);ad('lSh',-2.6*u+2.4*v,0,0);ad('rSh',-2.6*u+2.4*v,0,0);}
|
| 511 |
+
if(a==='swipe_grab'){const u=band(t,20,34),v=band(t,36,44);ad('hips',.2*u,0,0);ad('rSh',-.6*u-.6*v,0,0);ad('rSh',0,0,-1.2*u+1.6*v);ad('chest',0,.6*u-1.2*v,0);}
|
| 512 |
+
if(a==='belly_flop'){const air=b.y>.4;if(air){set('hips',1.5,0,0);set('lSh',-2.2,0,1.0);set('rSh',-2.2,0,-1.0);set('lHip',-.2,0,.4);set('rHip',-.2,0,-.4);set('lKnee',.4,0,0);set('rKnee',.4,0,0);}
|
| 513 |
+
if(t>=58){set('hips',1.55,0,0);set('lSh',-2.9,0,.8);set('rSh',-2.9,0,-.8);q.y=-.55;}}
|
| 514 |
+
if(a==='back_thrash'&&t>=10){set('hips',-1.45,0,0);set('spine',-.1,0,0);set('neck',.3,0,0);q.y=-.65;const s=Math.sin(t*.55);set('lSh',-1.5+s*.9,0,.9);set('rSh',-1.5-s*.9,0,-.9);set('lHip',-1.2-s*.5,0,.3);set('rHip',-1.2+s*.5,0,-.3);set('lKnee',.8,0,0);set('rKnee',.8,0,0);}
|
| 515 |
+
if(a==='fart'){ad('hips',.3,0,0);ad('lKnee',.4,0,0);ad('rKnee',.4,0,0);q.y-=.15;}
|
| 516 |
+
if(a==='flee_poo'&&t>=44){set('hips',.2,0,0);ad('rSh',-2.6*band(t,48,62)+2.2*band(t,64,70),0,0);}
|
| 517 |
+
if(a==='roar'&&t>=20){set('hips',.15,0,0);set('chest',-.3,0,0);set('neck',-.2,0,0);set('head',-.5,0,0);set('lSh',-1.2,0,1.1);set('rSh',-1.2,0,-1.1);set('lHip',-.4,0,.1);set('rHip',-.4,0,-.1);set('lKnee',.6,0,0);set('rKnee',.6,0,0);q.y=-.1;}
|
| 518 |
+
if((a==='bound'||a==='roll_away')&&b.y>.3){set('lHip',-1.6,0,.2);set('rHip',-1.6,0,-.2);set('lKnee',1.8,0,0);set('rKnee',1.8,0,0);set('lSh',-2.2,0,0);set('rSh',-2.2,0,0);}
|
| 519 |
+
if(a==='sword4'&&near){const i=hits.indexOf(near),dir=i%3===0?1:-1,u=band(t,near.t-14,near.t-3),v=band(t,near.t-3,near.t+2);set('rSh',-1.4,0,-.4);set('rEl',-.2,0,0);ad('chest',0,dir*(.9*u-1.8*v),0);ad('spine',0,dir*(.5*u-1.0*v),0);}
|
| 520 |
+
if(a==='diving_lunge'){if(t<40){set('rSh',-1.6-.8*band(t,10,24)+1.2*band(t,30,36),0,-.3);ad('hips',.6*band(t,18,36),0,0);}else{set('hips',1.5,0,0);q.y=-.9+.6*band(t,108,124);set('rSh',-2.6,0,-.6);set('lSh',-2.4,0,.6);}}
|
| 521 |
+
if(a==='jump_sweep'){set('rSh',-1.0,0,-1.2);if(b.y>.3){set('lHip',-1.2,0,.2);set('rHip',-1.0,0,-.2);set('lKnee',1.4,0,0);set('rKnee',1.4,0,0);}ad('chest',0,-1.4*band(t,48,54),0);}
|
| 522 |
+
if(a==='overhead_slam'){const u=band(t,8,40),v=band(t,52,56);set('rSh',-3.0*u+1.7*v,0,-.15);set('rEl',-.3*u,0,0);ad('spine',-.2*u+.8*v,0,0);}
|
| 523 |
+
if(mv.scream){const u=band(t,mv.scream.from-40,mv.scream.from-8);set('lSh',-1.6-1.0*u,0,.2);set('lEl',-1.6*u,0,0);if(t>=mv.scream.from&&t<mv.scream.to){ad('chest',-.35,Math.sin(t*.9)*.05,0);set('rSh',-.6,0,-1.0);}}
|
| 524 |
+
if(a==='headless_rise'){const u=band(t,20,120);set('hips',1.3*(1-u)+.25*u,0,0);q.y=-.8*(1-u)-.15*u;}
|
| 525 |
+
}
|
| 526 |
+
if(b.state==='stunned'){if(a==='flinch_small'){ad('chest',-.35,0,0);ad('neck',-.3,0,0);}if(a==='flinch_big'){set('hips',-.2,0,0);set('chest',-.5,0,0);set('lSh',-.4,0,1.3);set('rSh',-.4,0,-1.3);q.y=-.2;}if(a==='neck_exposed'){set('hips',1.35,0,0);q.y=-.7;}if(a==='stagger'){ad('chest',-.3,0,0);}}
|
| 527 |
+
if(b.state==='deathblow')ad('chest',.5,0,0),q.y-=.3;
|
| 528 |
+
if(b.state==='dead'||b.state==='execution'){set('hips',1.5,0,.4);set('lSh',-2.6,0,.6);set('rSh',-2.6,0,-.6);q.y=-.95;}
|
| 529 |
+
return q;}
|
| 530 |
+
bladePoints(m,len=1.0){const b=m.bones.active||m.bones.blade;b.updateWorldMatrix(true,false);const base=v3(0,-len*.62,0).applyMatrix4(b.matrixWorld),tip=v3(0,-len,0).applyMatrix4(b.matrixWorld);return [base,tip];}
|
| 531 |
+
// samples(k) re-poses the model k ticks earlier, so the ribbon is a pure function of the current state.
|
| 532 |
+
trail(i,m,active,color,samples){const tr=this.trails[i];if(!active){tr.mesh.visible=false;return;}tr.mesh.visible=true;const pos=tr.mesh.geometry.attributes.position,col=tr.mesh.geometry.attributes.color;
|
| 533 |
+
const hist=[];for(let k=0;k<tr.n;k++){if(!samples(k))break;hist.push(this.bladePoints(m,active.len||1));}samples(0);if(!hist.length){tr.mesh.visible=false;return;}
|
| 534 |
+
const c=new T.Color(color);for(let k=0;k<tr.n;k++){const h=hist[Math.min(k,hist.length-1)],f=Math.pow(1-k/Math.max(1,hist.length),1.3)*active.alpha*.5;pos.setXYZ(k*2,h[0].x,h[0].y,h[0].z);pos.setXYZ(k*2+1,h[1].x,h[1].y,h[1].z);col.setXYZW(k*2,c.r,c.g,c.b,f*.15);col.setXYZW(k*2+1,c.r,c.g,c.b,f);}
|
| 535 |
+
pos.needsUpdate=true;col.needsUpdate=true;}
|
| 536 |
+
effects(g,cam){
|
| 537 |
+
let sp=0,fl=0,bl=0,bo=0,pr=0,wi=0,pu=0,ri=0,mo=0,le=0,fm=0;const p=g.player||{},b=g.boss||{},tm=g.t/60,camQ=cam.quaternion,kind=g.kind;
|
| 538 |
+
for(const fx of items(g.effects)){const age=(fx.maxLife||15)-(fx.life||0),u=age/(fx.maxLife||15),k=fx.type||'';
|
| 539 |
+
if(k==='deflect'||k==='boss_deflect'||k==='mikiri'){// bright clash: streak sparks and a hot flash between the blades
|
| 540 |
+
const cx=(fx.x+(k==='deflect'?(b.x-p.x)*.18:0)),cz=(fx.z+(k==='deflect'?(b.z-p.z)*.18:0)),cy=(fx.y||1)+.45;
|
| 541 |
+
fl=this.place(this.fx.flash,fl,[cx,cy,cz],(1.4-u)*(k==='mikiri'?2.4:1.8),camQ,k==='mikiri'?0xffe0b0:0xfff1c8);
|
| 542 |
+
for(let i=0;i<14;i++){const a=hash(i,fx.life|0+3)*Math.PI*2,e=hash(i,7)*1.2-.3,r=.15+u*(1.4+hash(i,9));sp=this.link(this.fx.spark,sp,[cx+Math.cos(a)*r*.6,cy+e*r*.6,cz+Math.sin(a)*r*.6],[cx+Math.cos(a)*r,cy+e*r,cz+Math.sin(a)*r],.02*(1-u)+.005,i%3?0xffc46a:0xfff3d6);}}
|
| 543 |
+
if(k==='block'||k==='boss_block'){fl=this.place(this.fx.flash,fl,[fx.x,(fx.y||1)+.45,fx.z],(1-u)*.9,camQ,0xb8c4d0);for(let i=0;i<6;i++){const a=hash(i,fx.life|0)*Math.PI*2,r=.1+u*.6;sp=this.link(this.fx.spark,sp,[fx.x,fx.y+.45,fx.z],[fx.x+Math.cos(a)*r,fx.y+.45+r*.3,fx.z+Math.sin(a)*r],.012,0xd8dde6);}}
|
| 544 |
+
if(k==='cut'||k==='illusion_cut'){for(let i=0;i<10;i++){const a=hash(i,fx.life|0+11)*Math.PI*2,r=.2+u*(.6+hash(i,4)),y=(fx.y||1)+.3+hash(i,5)*.5-u*u*.9;bl=this.place(this.fx.blood,bl,[fx.x+Math.cos(a)*r,y,fx.z+Math.sin(a)*r],.06*(1-u)+.02,null,k==='cut'?0x8e0f12:0x9fd8ff);}}
|
| 545 |
+
if(k==='stomp_wave'){const r=1+u*5.4;for(let i=0;i<24;i++){const a0=i/24*Math.PI*2,a1=(i+1)/24*Math.PI*2;bo=this.link(this.fx.bolt,bo,[fx.x+Math.sin(a0)*r,.2,fx.z+Math.cos(a0)*r],[fx.x+Math.sin(a1)*r,.2,fx.z+Math.cos(a1)*r],.026*(1-u)+.008,0xd8d0b8);}fl=this.place(this.fx.flash,fl,[fx.x,.5,fx.z],2.6*(1-u),camQ,0xfff0d0);}
|
| 546 |
+
if(k==='stomp'){fl=this.place(this.fx.flash,fl,[fx.x,(fx.y||1)+.6,fx.z],1.2*(1-u),camQ,0xffffff);}
|
| 547 |
+
if(k==='lightning_catch'||k==='shock'){for(let i=0;i<8;i++){const a=hash(i,fx.life|0)*Math.PI*2;sp=this.link(this.fx.spark,sp,[p.x,(p.y||0)+1.1,p.z],[p.x+Math.cos(a)*.7,(p.y||0)+1.1+hash(i,3)-.4,p.z+Math.sin(a)*.7],.02,0xffe08a);}}
|
| 548 |
+
if(k==='lightning_return'){let last=[p.x,(p.y||0)+1.5,p.z];for(let i=1;i<=7;i++){const s=i/7,j=i===7?0:(hash(i,fx.life|0)-.5)*.6,next=[p.x+(b.x-p.x)*s+j,(p.y||0)+1.5+((b.y||0)+1.2-(p.y||0)-1.5)*s+j*.5,p.z+(b.z-p.z)*s-j];bo=this.link(this.fx.bolt,bo,last,next,.05,0xfff0b8);last=next;}}
|
| 549 |
+
}
|
| 550 |
+
// Lightning of Tomoe: the bolt meets the blade overhead, then strikes along the cut (S05).
|
| 551 |
+
if(b.state==='attack'&&String(b.action).startsWith('lightning')){const t=b.moveTick;if(t>=54&&t<100){const tip=this.bladePoints(this.bosses[kind==='isshin'?'isshin':'genichiro'],kind==='isshin'?1.75:1)[1];let last=[tip.x+Math.sin(t)*.4,tip.y+14,tip.z];
|
| 552 |
+
for(let i=1;i<=8;i++){const s=i/8,j=i===8?0:(hash(i,t>>1)-.5)*1.2,next=[tip.x+j*(1-s),tip.y+14*(1-s),tip.z+j*(1-s)*.6];bo=this.link(this.fx.bolt,bo,last,next,.07,0xfff1c2);last=next;}
|
| 553 |
+
fl=this.place(this.fx.flash,fl,[tip.x,tip.y,tip.z],1.6+Math.sin(t*.7)*.4,camQ,0xffe9a0);}}
|
| 554 |
+
if(p.lightning>0){for(let i=0;i<6;i++){const a=hash(i,g.t>>1)*Math.PI*2;sp=this.link(this.fx.spark,sp,[p.x,(p.y||0)+1,p.z],[p.x+Math.cos(a)*.5,(p.y||0)+1+hash(i,g.t)-.5,p.z+Math.sin(a)*.5],.018,0xffe08a);}}
|
| 555 |
+
for(const h of items(g.hazards)){const k=h.type;
|
| 556 |
+
if(k==='arrow'||k==='lightning_arrow'||k==='kunai'){const q=this.dir(h.vx,h.vy,h.vz);pr=this.place(this.fx.proj,pr,[h.x,h.y,h.z],k==='kunai'?[.03,.03,.26]:[.025,.025,.75],q,k==='kunai'?0x2b2c33:h.charged?0xb38b52:0x8a6a44);
|
| 557 |
+
if(k==='lightning_arrow'){fl=this.place(this.fx.flash,fl,[h.x,h.y,h.z],.9,camQ,0xffe39a);}}
|
| 558 |
+
else if(k==='bullet'){const q=this.dir(h.vx,h.vy,h.vz);pr=this.place(this.fx.proj,pr,[h.x,h.y,h.z],[.03,.03,.3],q,0xffd27a);fl=this.place(this.fx.flash,fl,[h.x,h.y,h.z],h.age<4?1.1:.4,camQ,0xffc46a);}
|
| 559 |
+
else if(k==='wave'){// a force wave: a standing crescent (vertical) or a wide flat disc (horizontal)
|
| 560 |
+
const fx0=Math.cos(h.yaw),fz0=-Math.sin(h.yaw),n=7,w=h.wide?1.5:.55,tall=h.wide?.12:1.15;let last=null;
|
| 561 |
+
for(let i=0;i<=n;i++){const v=i/n*2-1,bow=1-v*v,pt=[h.x+fx0*v*w+Math.sin(h.yaw)*bow*.35,h.y+(h.wide?0:v*tall),h.z+fz0*v*w+Math.cos(h.yaw)*bow*.35];if(last)bo=this.link(this.fx.bolt,bo,last,pt,h.wide?.05:.04,h.burn?0xff9a40:0xdff3ff);last=pt;}
|
| 562 |
+
fl=this.place(this.fx.flash,fl,[h.x,h.y,h.z],h.wide?1.4:1,camQ,h.burn?0xff8a30:0xbfe6ff);}
|
| 563 |
+
else if(k==='ring'){const u=1-h.life/18,r=h.radius*(.25+u*.75);for(let i=0;i<24;i++){const a0=i/24*Math.PI*2,a1=(i+1)/24*Math.PI*2;bo=this.link(this.fx.bolt,bo,[h.x+Math.sin(a0)*r,.7,h.z+Math.cos(a0)*r],[h.x+Math.sin(a1)*r,.7,h.z+Math.cos(a1)*r],.028*(1-u)+.008,0xdff3ff);}}
|
| 564 |
+
else if(k==='mortal_arc'){// the black Mortal Blade's reach: a dark crimson sweep along its arc
|
| 565 |
+
const u=1-h.life/18;let last=null;for(let i=0;i<=8;i++){const a=(h.yaw||0)+(i/8-.5)*3,r=h.radius*(.45+u*.55),pt=[h.x+Math.sin(a)*r,.9+Math.sin(i/8*Math.PI)*.5,h.z+Math.cos(a)*r];if(last)pr=this.link(this.fx.proj,pr,last,pt,.14*(1-u)+.02,i%2?0x8e1016:0x2a0a10);last=pt;}}
|
| 566 |
+
else if(k==='rope_line'){const a=h.yaw||0;pr=this.link(this.fx.proj,pr,[h.x,h.y,h.z],[h.x+Math.sin(a)*h.radius,h.y-.8,h.z+Math.cos(a)*h.radius],.03,0x2c2118);pr=this.place(this.fx.proj,pr,[h.x+Math.sin(a)*h.radius,h.y-.8,h.z+Math.cos(a)*h.radius],[.05,.05,.34],this.dir(Math.sin(a),0,Math.cos(a)),0xd9dde2);}
|
| 567 |
+
else if(k==='fire'){const life=Math.min(1,(h.life||0)/30,(h.age||0)/6);for(let i=0;i<4;i++){const a=i*1.6+h.x,r=(h.radius||1)*.45,fy=.25+(.5+.5*Math.sin(g.t*.4+i*2))*.5;
|
| 568 |
+
fm=this.place(this.fx.flame,fm,[h.x+Math.cos(a)*r,fy*.5*life,h.z+Math.sin(a)*r],[.26*life,fy*1.3*life,.26*life],[0,a,0],i%2?0xff7a2a:0xffb040);}}
|
| 569 |
+
else if(k==='fireball'||k==='fire_shot'){pr=this.place(this.fx.proj,pr,[h.x,h.y,h.z],[(h.radius||.35)*1.3,(h.radius||.35)*1.3,(h.radius||.35)*1.3],[h.age*.3,h.age*.2,0],0xff8a2a);
|
| 570 |
+
fl=this.place(this.fx.flash,fl,[h.x,h.y,h.z],(h.radius||.35)*3.2,camQ,0xffa040);}
|
| 571 |
+
else if(k==='fire_ring'){const life=Math.min(1,(h.life||0)/40,(h.age||0)/12),n=64;for(let i=0;i<n;i++){const a=i/n*Math.PI*2,fy=.9+.5*Math.sin(g.t*.3+i*1.3);
|
| 572 |
+
fm=this.place(this.fx.flame,fm,[h.x+Math.sin(a)*h.radius,fy*.5*life,h.z+Math.cos(a)*h.radius],[.3,fy*life,.3],[0,a,0],i%2?0xff6a20:0xffb848);}}
|
| 573 |
+
else if(k==='poo')pr=this.place(this.fx.proj,pr,[h.x,h.y,h.z],[.32,.28,.34],[h.age*.3,h.age*.2,0],0x4a3520);
|
| 574 |
+
else if(k==='butterfly'){const flap=Math.sin((g.t+h.x*9)*.9)*.6,yaw=Math.atan2(h.vx||0,h.vz||1),s=h.swarm?.32:.22;const q=new T.Quaternion().setFromEuler(new T.Euler(0,yaw,0));
|
| 575 |
+
for(const side of [1]){wi=this.place(this.fx.wings,wi,[h.x,h.y,h.z],[s,s*(1+flap*.3),s],q,h.swarm?0xc8a8ff:0x9fd2ff);}fl=this.place(this.fx.flash,fl,[h.x,h.y,h.z],h.swarm?.55:.4,camQ,0x9a7cff);}
|
| 576 |
+
else if(k==='gas'){const life=h.life/300;for(let i=0;i<7;i++){const a=i*.9+h.age*.01,r=h.radius*(.3+.5*hash(i,2));pu=this.place(this.fx.puff,pu,[h.x+Math.cos(a)*r,.6+hash(i,3)*.9+h.age*.002,h.z+Math.sin(a)*r],(1.1+hash(i,4)*.8)*Math.min(1,h.age/20)*(.6+.4*life),null,0x8a8a4a);}}
|
| 577 |
+
else if(k==='lightning_line'||k==='lightning_arc'){const life=(h.life||0)/14;for(let i=0;i<5;i++){const a=(h.yaw||0)+(k==='lightning_arc'?(i-2)*.6:0),d=(h.radius||8)*(.2+i*.18);
|
| 578 |
+
bo=this.link(this.fx.bolt,bo,[h.x+Math.sin(a)*d,.2,h.z+Math.cos(a)*d],[h.x+Math.sin(a)*d+(hash(i,g.t)-.5),2.5*life,h.z+Math.cos(a)*d],.06*life,0xffe9b0);}}
|
| 579 |
+
}
|
| 580 |
+
// Genichiro drawing the black blade, and the blood-black swirl of Isshin's emergence
|
| 581 |
+
if(b.state==='attack'&&b.action==='mortal_blade'&&b.moveTick<62){const t=b.moveTick;for(let i=0;i<4;i++){const a=t*.2+i*1.57,r=.5+band(t,0,50)*.7;sp=this.link(this.fx.spark,sp,[b.x+Math.cos(a)*r,.5+i*.3,b.z+Math.sin(a)*r],[b.x+Math.cos(a+.5)*r,.8+i*.3,b.z+Math.sin(a+.5)*r],.03,0xa01420);}}
|
| 582 |
+
if(b.state==='attack'&&b.action==='isshin_emerge'){const t=b.moveTick;for(let i=0;i<14;i++){const a=t*.12+i*.45,r=1.7-band(t,0,70)*1.2,y=i*.17;bo=this.link(this.fx.bolt,bo,[b.x+Math.cos(a)*r,y,b.z+Math.sin(a)*r],[b.x+Math.cos(a+.45)*r,y+.17,b.z+Math.sin(a+.45)*r],.04,i%2?0xa01420:0x4a0a14);}fl=this.place(this.fx.flash,fl,[b.x,1,b.z],band(t,50,80)*(1-band(t,84,96))*4,camQ,0xfff0d0);}
|
| 583 |
+
// blood scream: dark red shockwave rings from the headless ape (terror, S14/S20)
|
| 584 |
+
const mv=root.SekiroGame?.bosses?.ape?.moves?.[b.action];if(kind==='ape'&&b.state==='attack'&&mv?.scream){const t=b.moveTick,s=mv.scream;if(t>=s.from&&t<s.to)for(let i=0;i<3;i++){const ph=((t-s.from)*.05+i/3)%1;
|
| 585 |
+
ri=this.place(this.fx.rings,ri,[b.x,.6+ph*.8,b.z],[s.radius*ph,s.radius*ph,s.radius*ph],[Math.PI/2,0,0],0xa0141a);}}
|
| 586 |
+
// atmosphere: maple leaves on the castle wind, embers in the burning hall, motes over the pool
|
| 587 |
+
const ar=this.arenas[kind];
|
| 588 |
+
if(ar?.leaves)for(let i=0;i<26;i++){const s=(tm*(.6+hash(i,1)*.5)+hash(i,2)*30)%30,x=-20+s*1.4+hash(i,3)*6,z=-10+hash(i,4)*20,y=6-((tm*.8+hash(i,5)*12)%12);if(Math.hypot(x-cam.position.x,y-cam.position.y,z-cam.position.z)<4)continue;le=this.place(this.fx.leaf,le,[x,y,z],.09,[tm*2+i,tm*1.3+i,0],i%3?0xb2382a:0xd2652e);}
|
| 589 |
+
if(ar?.plumes)for(let i=0;i<40;i++){const s=(tm*(.8+hash(i,1)*.7)+hash(i,2)*40)%40,x=-20+s+hash(i,3)*6,z=-16+hash(i,4)*32,y=.5+hash(i,5)*3+Math.sin(tm+i)*.25;mo=this.place(this.fx.mote,mo,[x,y,z],.022+hash(i,6)*.02,null,0xf2ecd8);}
|
| 590 |
+
if(ar?.embersWide)for(let i=0;i<70;i++){const y=((tm*(.6+hash(i,1)*.7)+hash(i,2)*9)%9),x=-16+hash(i,3)*32+Math.sin(tm+i)*.6,z=-16+hash(i,4)*32;mo=this.place(this.fx.mote,mo,[x,y,z],.03+hash(i,5)*.03,null,i%4?0xff8a3a:0xffd27a);}
|
| 591 |
+
if(ar?.embers)for(let i=0;i<60;i++){const y=((tm*(.5+hash(i,1)*.6)+hash(i,2)*6)%6),x=-9+hash(i,3)*18+Math.sin(tm+i)*.4,z=-7+hash(i,4)*14;mo=this.place(this.fx.mote,mo,[x,y,z],.025+hash(i,5)*.03,null,i%4?0xff8a3a:0xffd27a);}
|
| 592 |
+
if(ar?.water)for(let i=0;i<30;i++){const x=Math.sin(i*2.4)*(2+hash(i,1)*6),z=Math.cos(i*2.4)*(2+hash(i,1)*6),y=.6+((tm*.2+hash(i,2))%1)*2.5;mo=this.place(this.fx.mote,mo,[x,y,z],.02,null,0xfff7d0);}
|
| 593 |
+
// spirit illusions of villagers (phase 2 of the butterfly fight)
|
| 594 |
+
const ms=items(g.minions);for(let i=0;i<this.ghosts.length;i++){const q=ms[i],gh=this.ghosts[i];if(!q){gh.visible=false;continue;}gh.visible=true;
|
| 595 |
+
const fade=q.alive?Math.min(1,(q.age||0)/20):Math.max(0,(q.fade||0)/24);gh.position.set(q.x,(q.y||0)+Math.sin((g.t+i*20)*.08)*.06,q.z);gh.rotation.set(q.state==='attack'?.25*band(q.t,20,34):0,q.yaw||0,0);
|
| 596 |
+
gh.scale.set(1,1,1).multiplyScalar(.8+.2*fade);}
|
| 597 |
+
this.mats.ghost.opacity=.4;
|
| 598 |
+
for(const [pool,n] of [[this.fx.spark,sp],[this.fx.flash,fl],[this.fx.blood,bl],[this.fx.bolt,bo],[this.fx.proj,pr],[this.fx.wings,wi],[this.fx.puff,pu],[this.fx.rings,ri],[this.fx.mote,mo],[this.fx.leaf,le],[this.fx.flame,fm]])this.finish(pool,n);
|
| 599 |
+
}
|
| 600 |
+
render(g,ctx){
|
| 601 |
+
if(this.closed||this.renderer.getContext().isContextLost()){this.ready=false;this.error=this.closed?'3D renderer is closed':'WebGL context lost';throw Error(this.error);}const start=performance.now();
|
| 602 |
+
try{const kind=g.kind||'genichiro';this.setArena(kind);const ar=this.arenas[kind],p=g.player||{},b=g.boss||{},tm=g.t/60;
|
| 603 |
+
const form=kind==='isshin'&&(b.phase||1)===1?'genichiro':kind,model=this.bosses[form];this.posePlayer(g);
|
| 604 |
+
if(kind==='isshin'){this.bosses.genichiro.holder.visible=form==='genichiro';this.bosses.isshin.holder.visible=form==='isshin';}
|
| 605 |
+
if(kind==='ape')this.poseApe(g,model,b);else if(kind==='demon')this.poseDemon(g,model,b);else this.poseHuman(g,model,b,root.SekiroGame?.bosses?.[kind]?.moves,form);
|
| 606 |
+
// light rig follows the fighters so the single shadow map stays sharp
|
| 607 |
+
const cx=(p.x+b.x)/2,cz=(p.z+b.z)/2;this.sun.position.set(cx+ar.sun.x*30,ar.sun.y*30,cz+ar.sun.z*30);this.sun.target.position.set(cx,0,cz);
|
| 608 |
+
let sunI=ar.sunI,hemiI=ar.hemiI,flash=0;
|
| 609 |
+
// Isshin's lightning bar brings the storm over the field.
|
| 610 |
+
if(kind==='isshin'&&(b.phase||1)===4){hemiI*=.62;sunI*=.45;}
|
| 611 |
+
if(kind==='genichiro'||kind==='isshin'){const tomoe=kind==='genichiro'&&b.form_id==='tomoe';hemiI*=tomoe?.8:1;sunI*=tomoe?.7:1;
|
| 612 |
+
if(b.state==='attack'&&String(b.action).startsWith('lightning')){const t=b.moveTick;flash=t>=54&&t<102?(.5+.5*Math.sin(t*.9))*(t>96?2:1):0;}
|
| 613 |
+
for(const h of items(g.hazards))if(h.type==='lightning_line'||h.type==='lightning_arc')flash=Math.max(flash,(h.life||0)/14*2.5);}
|
| 614 |
+
if(ar.fireLights)ar.fireLights.forEach((l,i)=>{l.intensity=5+Math.sin(tm*7+i*2)*1.2+Math.sin(tm*13+i)*.7;});
|
| 615 |
+
if(ar.water)ar.water.material.color.setHSL(.51,.36,.36+Math.sin(tm*.8)*.02);
|
| 616 |
+
this.sun.intensity=sunI;this.hemi.intensity=hemiI;this.flashLight.intensity=flash*9;this.flashLight.position.set(b.x||0,6,b.z||0);
|
| 617 |
+
// Lock-on camera: behind and to the right of Sekiro, framing the target; pulled back and up for the ape.
|
| 618 |
+
const yaw=g.cameraYaw??Math.atan2((b.x||0)-(p.x||0),(b.z||0)-(p.z||0)),fx=Math.sin(yaw),fz=Math.cos(yaw),rx=-Math.cos(yaw),rz=Math.sin(yaw);
|
| 619 |
+
const sep=Math.hypot((b.x||0)-(p.x||0),(b.z||0)-(p.z||0)),big=kind==='ape'||kind==='gyoubu'||kind==='demon',huge=kind==='demon',air=Math.max(0,(b.y||0)-(p.y||0));
|
| 620 |
+
const orbit=clamp(.9-sep*.08,.3,.8)*(big?.75:1),dist=clamp(3.6+sep*.17,3.8,5.5)+(big?2.2:0)+(huge?1.6:0),height=2.1+sep*.05+(big?1.4:0)+(huge?.9:0)+(p.y||0)*.6;
|
| 621 |
+
// an airborne target (leaps, threads, lightning) pulls the camera back and up so both stay in frame
|
| 622 |
+
const lift=clamp(air-.6,0,3.4),ox=Math.sin(yaw-orbit),oz=Math.cos(yaw-orbit);let pos=v3(p.x-ox*(dist+lift*.55),height+lift*.3,p.z-oz*(dist+lift*.55));
|
| 623 |
+
const bodyH=huge?2.6:big?(b.form_id==='headless'?2.0:1.8):1.15;const wy=air>1?.52:.6;let look=v3(lerp(p.x,b.x,.62),lerp((p.y||0)+1.0,(b.y||0)+bodyH,wy),lerp(p.z,b.z,.62));
|
| 624 |
+
if(kind==='butterfly'){pos.x=clamp(pos.x,-9.3,9.3);pos.z=clamp(pos.z,-7.3,7.3);pos.y=Math.min(pos.y,5.0);
|
| 625 |
+
// a pillar in the way: raise the eye and shorten the boom instead of looking through timber
|
| 626 |
+
for(const q of g.arena?.pillars||[]){const dx=pos.x-p.x,dz=pos.z-p.z,len=Math.hypot(dx,dz)||1,t=clamp(((q.x-p.x)*dx+(q.z-p.z)*dz)/(len*len),0,1),cx=p.x+dx*t,cz=p.z+dz*t;
|
| 627 |
+
// a pillar blocks the line of sight: shorten the boom towards Sekiro, then keep the eye out of any column
|
| 628 |
+
if(Math.hypot(cx-q.x,cz-q.z)<q.r+.6){pos.set(p.x+dx*t*.62,Math.max(pos.y,2.9),p.z+dz*t*.62);break;}
|
| 629 |
+
const ex=pos.x-q.x,ez=pos.z-q.z,ed=Math.hypot(ex,ez);if(ed<q.r+.45){pos.x=q.x+ex/(ed||1)*(q.r+.45);pos.z=q.z+ez/(ed||1)*(q.r+.45);}}}
|
| 630 |
+
if(kind==='ape'){const r=Math.hypot(pos.x,pos.z);if(r>15){pos.x*=15/r;pos.z*=15/r;}}
|
| 631 |
+
// a side angle during a deathblow; a little shake on clashes
|
| 632 |
+
if(b.executing>0||(p.action==='deathblow')){const u=band(p.actionTick||0,0,10);pos.lerp(v3(cx+rx*(big?6:3.8)-fx*1.2,big?2.6:1.7,cz+rz*(big?6:3.8)-fz*1.2),u);look.lerp(v3(cx,big?1.6:1.15,cz),u);}
|
| 633 |
+
let shake=0;for(const fx2 of items(g.effects))if(/deflect|mikiri|stomp/.test(fx2.type||''))shake=Math.max(shake,(fx2.life||0)/(fx2.maxLife||15));
|
| 634 |
+
if(p.hurt>0)shake=Math.max(shake,p.hurt/12*.7);if(shake){pos.x+=Math.sin(g.t*1.7)*.04*shake;pos.y+=Math.cos(g.t*2.3)*.04*shake;}
|
| 635 |
+
if(g.view){pos=v3(...g.view.pos);look=v3(...g.view.look);}
|
| 636 |
+
this.camera.position.copy(pos);this.camera.lookAt(look);this.camera.updateMatrixWorld();
|
| 637 |
+
this.effects(g,this.camera);
|
| 638 |
+
// sword trails while blades are swinging
|
| 639 |
+
const pa=p.attackTick>=(p.attackKind==='thrust'?8:5)&&p.attackTick<=(p.attackKind==='thrust'?12:10)?{alpha:.7,len:1.0}:null;
|
| 640 |
+
this.trail(0,this.player,pa,0xdfe9ff,k=>{if(p.attackTick-k<(p.attackKind==='thrust'?7:4))return false;applyPose(this.player,this.playerPose({...p,attackTick:p.attackTick-k,actionTick:(p.actionTick||0)-k},(g.t-k)/60));return true;});
|
| 641 |
+
const mv=root.SekiroGame?.bosses?.[kind]?.moves?.[b.action],swing=b.state==='attack'&&mv&&(mv.hits||[]).some(h=>b.moveTick>=h.t&&b.moveTick<=h.t+4&&h.type!=='grab'&&h.type!=='kick'&&h.type!=='lightning');
|
| 642 |
+
const bossBlade=kind==='ape'?(b.form_id==='headless'?{alpha:.7,len:2.7}:null):kind==='genichiro'?{alpha:.75,len:1}:kind==='isshin'?(model.bones.active?null:{alpha:.75,len:1}):kind==='gyoubu'||kind==='demon'?null:{alpha:.5,len:.3};
|
| 643 |
+
const moves=root.SekiroGame?.bosses?.[kind]?.moves;
|
| 644 |
+
const hitT=(mv?.hits||[]).filter(h=>h.t<=b.moveTick).map(h=>h.t).pop()??0;
|
| 645 |
+
this.trail(1,model,swing&&bossBlade?bossBlade:null,kind==='genichiro'&&b.form_id==='tomoe'?0xffe7a0:0xffffff,k=>{if(b.moveTick-k<hitT-3)return false;const bk={...b,moveTick:b.moveTick-k,actionTick:(b.actionTick||0)-k};
|
| 646 |
+
if(kind==='ape')applyPose(model,this.apePose({...g,t:g.t-k},bk),{hipY:1.25});else applyPose(model,this.humanPose({...g,t:g.t-k},bk,moves,form).q);return true;});
|
| 647 |
+
this.renderer.info.reset();this.renderer.render(this.world,this.camera);ctx.drawImage(this.view,0,0,854,480);
|
| 648 |
+
this.times.push(performance.now()-start);if(this.times.length>120)this.times.shift();this.ready=true;this.error=null;
|
| 649 |
+
}catch(e){this.ready=false;this.error=String(e);throw e;}
|
| 650 |
+
}
|
| 651 |
+
project(x,y,z){const v=v3(x,y,z).project(this.camera);return {x:(v.x+1)*427,y:(1-v.y)*240,visible:v.z<1&&v.z>-1};}
|
| 652 |
+
metrics(){
|
| 653 |
+
const info=this.renderer.info,sorted=[...this.times].sort((a,b)=>a-b);let geometryBytes=0,textureBytes=0;
|
| 654 |
+
for(const r of this.resources){if(r.isBufferGeometry){for(const a of Object.values(r.attributes))geometryBytes+=a.array.byteLength;if(r.index)geometryBytes+=r.index.array.byteLength;}if(r.isTexture&&r.image)textureBytes+=(r.image.width||0)*(r.image.height||0)*4;if(r.isInstancedMesh)geometryBytes+=r.instanceMatrix.array.byteLength;}
|
| 655 |
+
return {renderer:'webgl-boss3d',webglVersion:this.renderer.capabilities.isWebGL2?2:1,drawCalls:info.render.calls,triangles:info.render.triangles,geometries:info.memory.geometries,textures:info.memory.textures,geometryBytes,textureBytes,shadowMapBytes:1024*1024*4,canvasBytes:854*480*4,resourceBytesEstimate:geometryBytes+textureBytes+1024*1024*4+854*480*8,staticAssetBytes:669884,renderSamples:sorted.length,cpuRenderMsP50:sorted.length?sorted[Math.floor((sorted.length-1)*.5)]:null,cpuRenderMsP95:sorted.length?sorted[Math.floor((sorted.length-1)*.95)]:null,shadows:'one 1024x1024 directional map; fighters cast',postprocess:false,arena:this.kind};
|
| 656 |
+
}
|
| 657 |
+
close(){if(this.closed)return;this.closed=true;this.ready=false;this.resources.forEach(r=>r.dispose?.());this.renderer.dispose();this.renderer.forceContextLoss();this.resources.clear();}
|
| 658 |
+
}
|
| 659 |
+
B.render=function(style,g,ctx){let m=byCanvas.get(ctx.canvas);if(!m){m=new Map();byCanvas.set(ctx.canvas,m);}let scene=m.get(style);if(!scene||scene.closed){scene=new Scene(ctx.canvas);m.set(style,scene);}scene.render(g,ctx);return scene;};
|
| 660 |
+
B.scene=function(style,ctx){return ctx&&byCanvas.get(ctx.canvas)?.get(style)||null;};
|
| 661 |
+
B.status=function(style,ctx){const s=ctx&&byCanvas.get(ctx.canvas)?.get(style);if(s&&!s.closed&&s.renderer.getContext().isContextLost()){s.ready=false;s.error='WebGL context lost';}return {renderer:'webgl-boss3d',kind:'perspective',ready:!!s?.ready&&!s.closed,error:s?.error||null};};
|
| 662 |
+
B.metrics=function(style,ctx){const s=ctx&&byCanvas.get(ctx.canvas)?.get(style);return s?s.metrics():null;};
|
| 663 |
+
B.close=function(style,ctx){const m=ctx&&byCanvas.get(ctx.canvas),s=m?.get(style);if(s){s.close();m.delete(style);}};
|
| 664 |
+
B.bar=function(c,x,y,w,h,value,color){c.fillStyle='rgba(12,20,29,.8)';c.fillRect(x,y,w,h);c.fillStyle=color;c.fillRect(x+1,y+1,(w-2)*clamp(value,0,1),h-2);c.strokeStyle='rgba(229,210,169,.6)';c.strokeRect(x+.5,y+.5,w-1,h-1);};
|
| 665 |
+
B.text=function(c,text,x,y,size=16,color='#f3ead9',align='left'){c.font=size+'px "Segoe UI","Microsoft YaHei",sans-serif';c.textAlign=align;c.fillStyle='rgba(8,15,23,.8)';c.fillText(text,x+1,y+1);c.fillStyle=color;c.fillText(text,x,y);};
|
| 666 |
+
})(window);
|
environments/games/web/games/sekiro_remake/style3d.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
:root{color-scheme:dark;--bg:#14191a;--panel:#1d2425;--edge:#354141;--text:#ebe7dc;--muted:#a5b2ad;--accent:#dfb676}*{box-sizing:border-box}body{margin:0;background:radial-gradient(ellipse at top,#29312b,transparent 60%),var(--bg);color:var(--text);font:14px/1.7 'Segoe UI','Microsoft YaHei',sans-serif}body[data-game=genshin_remake]{--bg:#101822;--panel:#1b2530;--edge:#374754;--accent:#baacff;background:radial-gradient(ellipse at top,#2b2942,transparent 60%),var(--bg)}main{max-width:1220px;margin:auto;padding:28px 24px 40px}header{display:flex;align-items:center;justify-content:space-between;margin-bottom:22px;gap:20px}.eyebrow{color:var(--accent);font-size:11px;letter-spacing:2.5px;text-transform:uppercase}h1{font:500 32px/1.35 Georgia,'Microsoft YaHei',serif;letter-spacing:1px;margin:6px 0}header p{color:var(--muted);margin:0;font-size:13px}a{color:var(--accent);text-decoration:none}a:hover{text-decoration:underline}.layout{display:grid;grid-template-columns:minmax(0,854px) 245px;gap:24px;align-items:start}.stage{position:relative;border:1px solid var(--edge);box-shadow:0 22px 55px #0005;background:#111b1c}canvas{display:block;width:100%;aspect-ratio:854/480;touch-action:none;outline:none}canvas:focus-visible{outline:2px solid var(--accent);outline-offset:3px}#overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#10171b30;pointer-events:none}#overlay[hidden]{display:none}#overlay div{background:#111b23de;padding:19px 32px;border:1px solid #9ba6a655;max-width:80%;text-align:center}#overlay strong{font:500 24px Georgia,'Microsoft YaHei',serif;display:block}#overlay span{display:block;color:var(--muted);font-size:12px;margin-top:7px}.toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:12px;background:var(--panel);border-top:1px solid var(--edge)}button,select,input{font:inherit;background:var(--panel);color:var(--text);border:1px solid var(--edge);border-radius:4px;padding:7px 11px}button{cursor:pointer}button:hover{border-color:var(--accent);background:#ffffff09}button.primary{background:var(--accent);color:var(--bg);font-weight:600}button:focus-visible,select:focus-visible,input:focus-visible,a:focus-visible{outline:2px solid var(--accent);outline-offset:3px}aside{padding:19px;border:1px solid var(--edge);background:var(--panel)}h2{font-size:16px;margin:0 0 8px}label{display:block;font-size:12px;color:var(--muted);margin:12px 0 5px}select,input{width:100%}dl{border-top:1px solid var(--edge);padding-top:16px;margin:18px 0 0}dt{color:var(--accent);font:12px/1.8 Consolas,monospace}dd{color:var(--muted);font-size:12px;margin:0 0 10px}.note{color:var(--muted);font-size:12px}#status{min-height:25px;margin:10px 0;color:var(--accent);overflow-wrap:anywhere}.record-toolbar{border:1px solid var(--edge);padding:10px;background:transparent}.record-toolbar button{font-size:12px}#file{display:none}.mobile{display:none}footer{display:flex;flex-wrap:wrap;gap:22px;border-top:1px solid var(--edge);margin-top:28px;padding-top:15px;font-size:12px}@media(max-width:950px){main{padding:14px}.layout{grid-template-columns:1fr}aside{display:grid;grid-template-columns:1fr 1fr;gap:0 18px}aside dl,aside .note{grid-column:1/-1}dl{columns:2}.mobile{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}.mobile button{min-width:45px;touch-action:none}header{align-items:start}h1{font-size:26px}}@media(max-width:500px){header{display:block}header a{font-size:12px}aside{padding:14px}#overlay div{padding:14px 20px}#overlay strong{font-size:19px}.toolbar{gap:6px;padding:8px}button{font-size:12px}h1{font-size:25px}}
|
environments/games/web/games/soulknight_remake/compact_actions.json
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/compact-actions@1",
|
| 3 |
+
"game": "soulknight_remake",
|
| 4 |
+
"version": "soulknight-compact@1",
|
| 5 |
+
"heads": [
|
| 6 |
+
{
|
| 7 |
+
"name": "move",
|
| 8 |
+
"options": [
|
| 9 |
+
{
|
| 10 |
+
"label": "none"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"label": "right",
|
| 14 |
+
"keys": [
|
| 15 |
+
"D"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"label": "down_right",
|
| 20 |
+
"keys": [
|
| 21 |
+
"S",
|
| 22 |
+
"D"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"label": "down",
|
| 27 |
+
"keys": [
|
| 28 |
+
"S"
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"label": "down_left",
|
| 33 |
+
"keys": [
|
| 34 |
+
"S",
|
| 35 |
+
"A"
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"label": "left",
|
| 40 |
+
"keys": [
|
| 41 |
+
"A"
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"label": "up_left",
|
| 46 |
+
"keys": [
|
| 47 |
+
"W",
|
| 48 |
+
"A"
|
| 49 |
+
]
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"label": "up",
|
| 53 |
+
"keys": [
|
| 54 |
+
"W"
|
| 55 |
+
]
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"label": "up_right",
|
| 59 |
+
"keys": [
|
| 60 |
+
"W",
|
| 61 |
+
"D"
|
| 62 |
+
]
|
| 63 |
+
}
|
| 64 |
+
]
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"name": "aim",
|
| 68 |
+
"options": [
|
| 69 |
+
{
|
| 70 |
+
"label": "none"
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"label": "right_40",
|
| 74 |
+
"dx": 40,
|
| 75 |
+
"dy": 0
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"label": "down_right_40",
|
| 79 |
+
"dx": 28,
|
| 80 |
+
"dy": 28
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"label": "down_40",
|
| 84 |
+
"dx": 0,
|
| 85 |
+
"dy": 40
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"label": "down_left_40",
|
| 89 |
+
"dx": -28,
|
| 90 |
+
"dy": 28
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"label": "left_40",
|
| 94 |
+
"dx": -40,
|
| 95 |
+
"dy": 0
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"label": "up_left_40",
|
| 99 |
+
"dx": -28,
|
| 100 |
+
"dy": -28
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"label": "up_40",
|
| 104 |
+
"dx": 0,
|
| 105 |
+
"dy": -40
|
| 106 |
+
},
|
| 107 |
+
{
|
| 108 |
+
"label": "up_right_40",
|
| 109 |
+
"dx": 28,
|
| 110 |
+
"dy": -28
|
| 111 |
+
}
|
| 112 |
+
]
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"name": "act",
|
| 116 |
+
"options": [
|
| 117 |
+
{
|
| 118 |
+
"label": "none"
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"label": "fire",
|
| 122 |
+
"keys": [
|
| 123 |
+
"J"
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"label": "fire_skill",
|
| 128 |
+
"subs": [
|
| 129 |
+
[
|
| 130 |
+
"J",
|
| 131 |
+
"K"
|
| 132 |
+
],
|
| 133 |
+
[
|
| 134 |
+
"J"
|
| 135 |
+
],
|
| 136 |
+
[
|
| 137 |
+
"J"
|
| 138 |
+
],
|
| 139 |
+
[
|
| 140 |
+
"J"
|
| 141 |
+
],
|
| 142 |
+
[
|
| 143 |
+
"J"
|
| 144 |
+
],
|
| 145 |
+
[
|
| 146 |
+
"J"
|
| 147 |
+
]
|
| 148 |
+
]
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"label": "switch",
|
| 152 |
+
"subs": [
|
| 153 |
+
[
|
| 154 |
+
"Q"
|
| 155 |
+
],
|
| 156 |
+
[
|
| 157 |
+
"J"
|
| 158 |
+
],
|
| 159 |
+
[
|
| 160 |
+
"J"
|
| 161 |
+
],
|
| 162 |
+
[
|
| 163 |
+
"J"
|
| 164 |
+
],
|
| 165 |
+
[
|
| 166 |
+
"J"
|
| 167 |
+
],
|
| 168 |
+
[
|
| 169 |
+
"J"
|
| 170 |
+
]
|
| 171 |
+
]
|
| 172 |
+
}
|
| 173 |
+
]
|
| 174 |
+
}
|
| 175 |
+
]
|
| 176 |
+
}
|
environments/games/web/games/soulknight_remake/draw.js
ADDED
|
@@ -0,0 +1,853 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Soul Knight arena renderer (read-only). Procedural pixel art: every sprite is painted at
|
| 2 |
+
* art resolution, alpha-thresholded, given a 1-art-pixel outline and blitted at 2x without
|
| 3 |
+
* smoothing. Never mutates the game object or consumes game RNG; screen shake and decorations
|
| 4 |
+
* use hashes of the tick / tile coordinates, so a frame is a pure function of the state.
|
| 5 |
+
*/
|
| 6 |
+
(function (root) {
|
| 7 |
+
'use strict';
|
| 8 |
+
const M = root.SoulKnightGame, TAU = Math.PI * 2, R = M.room, TILE = M.tile;
|
| 9 |
+
const FONT = "'Microsoft YaHei','PingFang SC','Noto Sans CJK SC','Noto Sans SC',sans-serif";
|
| 10 |
+
const cache = new Map();
|
| 11 |
+
const hash = (a, b) => { let h = (Math.imul(a | 0, 73856093) ^ Math.imul(b | 0, 19349663) ^ 0x5bd1e995) >>> 0; h = Math.imul(h ^ (h >>> 15), 2246822519) >>> 0; h = Math.imul(h ^ (h >>> 13), 3266489917) >>> 0; return ((h ^ (h >>> 16)) >>> 0) / 4294967296; };
|
| 12 |
+
const mk = (w, h) => { const c = document.createElement('canvas'); c.width = w; c.height = h; return c; };
|
| 13 |
+
// cached art lives in software-backed canvases: the harness reads every captured frame back (toDataURL), which
|
| 14 |
+
// moves the frame canvas to software; GPU-backed sources would then cost a GPU->CPU copy per drawImage
|
| 15 |
+
const ctx2d = c => c.getContext('2d', { willReadFrequently: true });
|
| 16 |
+
const poly = (x, pts) => { x.beginPath(); x.moveTo(pts[0][0], pts[0][1]); for (let i = 1; i < pts.length; i++) x.lineTo(pts[i][0], pts[i][1]); x.closePath(); x.fill(); };
|
| 17 |
+
const ell = (x, col, cx, cy, rx, ry, rot) => { x.fillStyle = col; x.beginPath(); x.ellipse(cx, cy, rx, ry, rot || 0, 0, TAU); x.fill(); };
|
| 18 |
+
const starPath = (x, cx, cy, r1, r2, n, rot) => { x.beginPath(); for (let i = 0; i < n * 2; i++) { const a = (rot || -Math.PI / 2) + i * Math.PI / n, r = i % 2 ? r2 : r1; x.lineTo(cx + Math.cos(a) * r, cy + Math.sin(a) * r); } x.closePath(); };
|
| 19 |
+
|
| 20 |
+
// ---------- sprite pipeline ----------
|
| 21 |
+
function sprite(key, w, h, paint, outline) {
|
| 22 |
+
let s = cache.get(key);
|
| 23 |
+
if (s) return s;
|
| 24 |
+
const c = mk(w + 2, h + 2), x = ctx2d(c);
|
| 25 |
+
x.translate(1, 1); paint(x); x.setTransform(1, 0, 0, 1, 0, 0);
|
| 26 |
+
const img = x.getImageData(0, 0, c.width, c.height), d = img.data, n = c.width * c.height, cw = c.width;
|
| 27 |
+
const solid = new Uint8Array(n);
|
| 28 |
+
for (let i = 0; i < n; i++) { const on = d[i * 4 + 3] >= 110; d[i * 4 + 3] = on ? 255 : 0; solid[i] = on; }
|
| 29 |
+
if (outline !== false) {
|
| 30 |
+
const oc = outline || [18, 14, 26];
|
| 31 |
+
for (let y = 0; y < c.height; y++) for (let xx = 0; xx < cw; xx++) {
|
| 32 |
+
const i = y * cw + xx;
|
| 33 |
+
if (solid[i]) continue;
|
| 34 |
+
if ((xx > 0 && solid[i - 1]) || (xx < cw - 1 && solid[i + 1]) || (y > 0 && solid[i - cw]) || (y < c.height - 1 && solid[i + cw])) {
|
| 35 |
+
d[i * 4] = oc[0]; d[i * 4 + 1] = oc[1]; d[i * 4 + 2] = oc[2]; d[i * 4 + 3] = 255;
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
x.putImageData(img, 0, 0);
|
| 40 |
+
const f = mk(c.width, c.height), fx = ctx2d(f);
|
| 41 |
+
fx.drawImage(c, 0, 0); fx.globalCompositeOperation = 'source-atop'; fx.fillStyle = '#ffffff'; fx.fillRect(0, 0, f.width, f.height);
|
| 42 |
+
s = { c, f, w: c.width, h: c.height };
|
| 43 |
+
cache.set(key, s);
|
| 44 |
+
return s;
|
| 45 |
+
}
|
| 46 |
+
function fromMatrix(key, rows, pal) {
|
| 47 |
+
const w = Math.max(...rows.map(r => r.length));
|
| 48 |
+
return sprite(key, w, rows.length, x => { rows.forEach((row, y) => { for (let i = 0; i < row.length; i++) { const col = pal[row[i]]; if (col) { x.fillStyle = col; x.fillRect(i, y, 1, 1); } } }); });
|
| 49 |
+
}
|
| 50 |
+
// anchor = bottom centre at (x, y) in screen px, k = pixel scale
|
| 51 |
+
function blit(c, s, x, y, k, flip, flash, alpha) {
|
| 52 |
+
const w = s.w * k, h = s.h * k;
|
| 53 |
+
c.save(); c.translate(Math.round(x), Math.round(y));
|
| 54 |
+
if (flip) c.scale(-1, 1);
|
| 55 |
+
if (alpha !== undefined) c.globalAlpha = alpha;
|
| 56 |
+
c.drawImage(s.c, -Math.round(w / 2), -h, w, h);
|
| 57 |
+
if (flash) { c.globalAlpha = (alpha === undefined ? 1 : alpha) * (flash === true ? 0.7 : flash); c.drawImage(s.f, -Math.round(w / 2), -h, w, h); }
|
| 58 |
+
c.restore();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
// ---------- characters ----------
|
| 62 |
+
const KPAL = { w: '#f2f6fa', s: '#c4cdd8', g: '#8d98a8', d: '#5d6676', v: '#222a3a', e: '#ffe46b', r: '#e5483f', R: '#a52f2c', b: '#3b4152' };
|
| 63 |
+
const KBODY = ['....wwss....', '...wssssg...', '..wsssssgg..', '..sssvvvvg..', '..ssvvvevg..', '..gssvvvvg..', '..ggsssssg..',
|
| 64 |
+
'.rrrrrrrrRR.', '..RRrssgRR..', '.Rsswsssggd.', '..ssssssggd.', '..ssssssgd..', '..gsgggsgd..'];
|
| 65 |
+
const KLEGS = [['...gd..gd...', '...bb..bb...', '..bbb..bbb..'], ['..gd....gd..', '..bb....bb..', '.bbb....bbb.']];
|
| 66 |
+
const knight = f => fromMatrix('knight' + f, KBODY.concat(KLEGS[f]), KPAL);
|
| 67 |
+
|
| 68 |
+
function paintGP(x, angry) {
|
| 69 |
+
const fe = ['#e8833a', '#f6d65a'];
|
| 70 |
+
for (let i = 0; i < 5; i++) { x.fillStyle = fe[i % 2]; const bx = 6 + i * 3; poly(x, [[bx, 8], [bx + 1.5, Math.abs(i - 2) * 1.2], [bx + 3, 8]]); }
|
| 71 |
+
x.fillStyle = '#4f9a3f'; poly(x, [[8, 9], [0, 5], [8, 14]]); poly(x, [[18, 9], [26, 5], [18, 14]]);
|
| 72 |
+
x.fillStyle = '#d98b8b'; poly(x, [[7, 10], [3, 7], [7, 12]]); poly(x, [[19, 10], [23, 7], [19, 12]]);
|
| 73 |
+
ell(x, '#5fae4a', 13, 11.5, 6.5, 5.5); ell(x, '#88d06a', 11, 9.5, 3.5, 2.4);
|
| 74 |
+
x.fillStyle = '#f2c94c'; x.fillRect(6, 6, 14, 2); x.fillStyle = '#e04a4a'; x.fillRect(12, 6, 2, 2);
|
| 75 |
+
x.fillStyle = angry ? '#ff3020' : '#ffd23a'; x.fillRect(9, 10, 3, 2); x.fillRect(15, 10, 3, 2);
|
| 76 |
+
x.fillStyle = '#16181c'; x.fillRect(11, 10, 1, 2); x.fillRect(17, 10, 1, 2);
|
| 77 |
+
if (angry) { x.fillRect(9, 9, 3, 1); x.fillRect(15, 9, 3, 1); }
|
| 78 |
+
x.fillStyle = '#2a1414'; x.fillRect(10, 14, 7, 1); x.fillStyle = '#f4efe6'; x.fillRect(11, 14, 1, 1); x.fillRect(15, 14, 1, 1);
|
| 79 |
+
x.fillStyle = '#6c3fa0'; poly(x, [[8, 16], [18, 16], [22, 29], [4, 29]]);
|
| 80 |
+
x.fillStyle = '#4a2a73'; poly(x, [[15, 16], [18, 16], [22, 29], [16, 29]]);
|
| 81 |
+
x.fillStyle = '#9a6ad0'; poly(x, [[8, 16], [10, 16], [7, 29], [4, 29]]);
|
| 82 |
+
x.fillStyle = '#f2c94c'; x.fillRect(4, 27, 18, 2); x.fillRect(12, 17, 2, 10);
|
| 83 |
+
x.fillStyle = '#7a4a2a'; x.fillRect(7, 21, 12, 2);
|
| 84 |
+
x.fillStyle = '#f4efe6'; x.fillRect(9, 16, 2, 1); x.fillRect(12, 17, 2, 1); x.fillRect(15, 16, 2, 1);
|
| 85 |
+
ell(x, '#5fae4a', 5, 21, 2, 2); ell(x, '#5fae4a', 21, 21, 2, 2);
|
| 86 |
+
}
|
| 87 |
+
function paintCT(x, angry) {
|
| 88 |
+
x.fillStyle = '#7a5230'; x.fillRect(11, 37, 6, 8); x.fillRect(21, 37, 6, 8);
|
| 89 |
+
x.fillStyle = '#5a3a20'; x.fillRect(15, 37, 2, 8); x.fillRect(25, 37, 2, 8);
|
| 90 |
+
x.fillStyle = '#a0703f'; x.fillRect(11, 37, 2, 8); x.fillRect(21, 37, 2, 8);
|
| 91 |
+
for (const [top, bot, hw] of [[6, 16, 8], [14, 27, 12], [22, 39, 16]]) {
|
| 92 |
+
x.fillStyle = angry ? '#2c5f30' : '#2d6a3a'; poly(x, [[19, top - 5], [19 - hw, bot], [19 + hw, bot]]);
|
| 93 |
+
x.fillStyle = angry ? '#3b7c3e' : '#3f8f4c'; poly(x, [[19, top - 5], [19 - hw, bot], [17, bot]]);
|
| 94 |
+
x.fillStyle = '#eef6fb'; poly(x, [[19, top - 5], [19 - hw * 0.55, top + 3], [19 - hw * 0.25, top + 1], [19, top + 4], [19 + hw * 0.3, top + 1], [19 + hw * 0.55, top + 3]]);
|
| 95 |
+
x.fillStyle = '#d6e8f3'; x.fillRect(19 - hw + 2, bot - 1, hw * 2 - 4, 1);
|
| 96 |
+
}
|
| 97 |
+
x.fillStyle = '#16181c'; x.fillRect(14, 28, 3, 3); x.fillRect(22, 28, 3, 3);
|
| 98 |
+
x.fillStyle = angry ? '#ff3a2a' : '#ffffff'; x.fillRect(15, 28, 1, 1); x.fillRect(23, 28, 1, 1);
|
| 99 |
+
if (angry) { x.fillStyle = '#16181c'; x.fillRect(13, 26, 2, 1); x.fillRect(15, 27, 2, 1); x.fillRect(24, 26, 2, 1); x.fillRect(22, 27, 2, 1); }
|
| 100 |
+
x.fillStyle = '#5a2a1a'; x.fillRect(17, 32, 5, 2);
|
| 101 |
+
x.fillStyle = '#d7303a'; x.fillRect(8, 35, 23, 3); x.fillStyle = '#f4f4f4'; for (let i = 9; i < 31; i += 4) x.fillRect(i, 35, 2, 3);
|
| 102 |
+
x.fillStyle = '#d7303a'; x.fillRect(26, 38, 4, 6); x.fillStyle = '#a32028'; x.fillRect(28, 38, 2, 6);
|
| 103 |
+
for (const [ox, oy, oc] of [[12, 21, '#ff4a4a'], [26, 19, '#ffd23a'], [16, 12, '#5ac8ff'], [24, 25, '#ff4a4a'], [10, 31, '#ffd23a'], [29, 30, '#5ac8ff'], [20, 8, '#ff4a4a']]) {
|
| 104 |
+
x.fillStyle = oc; x.fillRect(ox, oy, 2, 2); x.fillStyle = '#ffffff'; x.fillRect(ox, oy, 1, 1);
|
| 105 |
+
}
|
| 106 |
+
x.fillStyle = '#ffd23f'; starPath(x, 19, 3, 4, 1.8, 5); x.fill();
|
| 107 |
+
}
|
| 108 |
+
function paintDS(x, open) {
|
| 109 |
+
const cx = 22, cy = 21;
|
| 110 |
+
for (let i = 0; i < 6; i++) { const a = i * TAU / 6 + 0.3; ell(x, i % 2 ? '#2f7a3f' : '#46a052', cx + Math.cos(a) * 13, cy + 7 + Math.sin(a) * 8, 8.5, 4.5, a); }
|
| 111 |
+
if (!open) {
|
| 112 |
+
ell(x, '#7a2f8f', cx, cy - 2, 12, 14); ell(x, '#a24bb8', cx - 3, cy - 4, 7, 10); ell(x, '#c77ad8', cx - 5, cy - 8, 2.5, 3.5);
|
| 113 |
+
x.fillStyle = '#4e1a60'; x.fillRect(cx - 1, cy - 15, 2, 26); x.fillRect(cx - 7, cy - 10, 1, 18); x.fillRect(cx + 6, cy - 10, 1, 18);
|
| 114 |
+
x.fillStyle = '#f2d24a'; for (const [sx, sy] of [[cx - 6, cy - 5], [cx + 3, cy - 8], [cx + 7, cy + 2], [cx - 4, cy + 5], [cx + 2, cy]]) x.fillRect(sx, sy, 2, 2);
|
| 115 |
+
x.fillStyle = '#c86ad8'; x.fillRect(cx - 4, cy - 20, 1, 5); x.fillRect(cx, cy - 21, 1, 6); x.fillRect(cx + 3, cy - 20, 1, 5);
|
| 116 |
+
} else {
|
| 117 |
+
for (let i = 0; i < 6; i++) { const a = i * TAU / 6 - Math.PI / 2; ell(x, i % 2 ? '#c2459a' : '#e06ab8', cx + Math.cos(a) * 11, cy + Math.sin(a) * 10, 8.5, 5, a); ell(x, '#f7a0d8', cx + Math.cos(a) * 13, cy + Math.sin(a) * 12, 3, 1.6, a); }
|
| 118 |
+
ell(x, '#4e1240', cx, cy, 9, 9);
|
| 119 |
+
ell(x, '#8fd65a', cx, cy, 6.5, 6.5); ell(x, '#b8f08a', cx - 2, cy - 2, 3, 2.5);
|
| 120 |
+
x.fillStyle = '#ffffff'; x.fillRect(cx - 3, cy - 4, 6, 4); x.fillStyle = '#e02a2a'; x.fillRect(cx - 1, cy - 3, 2, 2);
|
| 121 |
+
x.fillStyle = '#16181c'; x.fillRect(cx - 4, cy + 2, 8, 2); x.fillStyle = '#f4efe6'; for (let i = -3; i < 4; i += 2) x.fillRect(cx + i, cy + 2, 1, 1);
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
// ---------- 11-02 expansion bosses (original art; half-resolution art blitted at 2x like every other sprite) ----------
|
| 125 |
+
function paintGS(x, angry) { // Grand Slime 36x28: wobbling red-pink jelly with a crown; enraged = darker, angry brows
|
| 126 |
+
const body = angry ? '#d8344a' : '#ef5a6a', dark = angry ? '#9a1a30' : '#c23a4c', light = angry ? '#f27a88' : '#ff9aa6';
|
| 127 |
+
ell(x, dark, 18, 17.5, 17, 10.5);
|
| 128 |
+
ell(x, body, 18, 17, 16.5, 10);
|
| 129 |
+
ell(x, light, 13, 13, 6, 3.5); ell(x, '#ffd8de', 10, 12, 2, 1.2);
|
| 130 |
+
x.fillStyle = dark; for (const [dx, h] of [[5, 2], [11, 3], [25, 3], [31, 2]]) x.fillRect(dx, 25, 1.5, h);
|
| 131 |
+
x.fillStyle = '#16181c'; x.fillRect(12, 15, 2, 3); x.fillRect(22, 15, 2, 3);
|
| 132 |
+
x.fillStyle = '#ffffff'; x.fillRect(12, 15, 1, 1); x.fillRect(22, 15, 1, 1);
|
| 133 |
+
if (angry) { x.fillStyle = '#16181c'; x.fillRect(11, 13, 4, 1); x.fillRect(21, 13, 4, 1); }
|
| 134 |
+
x.fillStyle = '#4a1018'; x.fillRect(15, 21, 6, 1); x.fillStyle = '#f4efe6'; x.fillRect(16, 21, 1, 1); x.fillRect(19, 21, 1, 1);
|
| 135 |
+
x.fillStyle = '#f2c94c'; poly(x, [[12, 7.5], [13, 2], [15, 5], [18, 1], [21, 5], [23, 2], [24, 7.5]]);
|
| 136 |
+
x.fillStyle = '#c99a2a'; x.fillRect(12, 6, 12, 1.5); x.fillStyle = '#5ac8ff'; x.fillRect(17, 3.5, 2, 1.5);
|
| 137 |
+
}
|
| 138 |
+
function paintVL(x, angry) { // Varkolyn Leader 18x32: tall void alien in a hooded cloak, swirl mark on the leg
|
| 139 |
+
const cloak = angry ? '#5a2a8a' : '#3e2a6a', trim = angry ? '#c46aff' : '#8a6ad8';
|
| 140 |
+
x.fillStyle = cloak; poly(x, [[6, 10], [12, 10], [16, 31], [2, 31]]);
|
| 141 |
+
x.fillStyle = '#2a1a4a'; poly(x, [[9, 10], [12, 10], [16, 31], [10, 31]]);
|
| 142 |
+
x.fillStyle = trim; x.fillRect(2, 30, 14, 1); x.fillRect(8.5, 11, 1, 18);
|
| 143 |
+
ell(x, '#1a1030', 9, 6, 6, 6); ell(x, '#2a1a4a', 9, 5.5, 5.5, 5.5);
|
| 144 |
+
ell(x, '#9ff4c8', 9, 7, 3.5, 2.6);
|
| 145 |
+
x.fillStyle = angry ? '#ff3a6a' : '#16181c'; x.fillRect(6.5, 6, 1.5, 1.5); x.fillRect(10, 6, 1.5, 1.5);
|
| 146 |
+
x.strokeStyle = angry ? '#ff6af0' : '#6af0ff'; x.lineWidth = 0.8; x.beginPath(); x.arc(5.5, 22, 1.8, 0, 5.2); x.stroke();
|
| 147 |
+
x.fillStyle = '#6ad8b0'; x.fillRect(1, 15, 2, 2); x.fillRect(15, 15, 2, 2);
|
| 148 |
+
}
|
| 149 |
+
function paintVS(x, angry) { // Volcanic Sandworm 22x40: armoured segmented worm rearing out of the ground
|
| 150 |
+
const plate = angry ? '#d0602a' : '#b06a3a', dark = '#5a2a14', glow = angry ? '#ffd04a' : '#ff8a3a';
|
| 151 |
+
for (let i = 0; i < 5; i++) {
|
| 152 |
+
const y = 36 - i * 6.5, w = 6.8 - i * 0.3;
|
| 153 |
+
ell(x, dark, 11, y + 0.5, w + 0.5, 3); ell(x, plate, 11, y, w, 2.7);
|
| 154 |
+
x.fillStyle = glow; x.fillRect(11 - w + 1.5, y - 0.5, 1, 1); x.fillRect(11 + w - 2.5, y - 0.5, 1, 1);
|
| 155 |
+
}
|
| 156 |
+
ell(x, dark, 11, 6, 8, 5); ell(x, plate, 11, 5.5, 7.5, 4.5);
|
| 157 |
+
x.fillStyle = '#2a0e06'; poly(x, [[6, 6], [16, 6], [13, 10], [9, 10]]);
|
| 158 |
+
x.fillStyle = '#f4efe6'; for (const dx of [7.5, 10, 12.5, 15]) poly(x, [[dx - 0.6, 6], [dx + 0.6, 6], [dx, 7.8]]);
|
| 159 |
+
x.fillStyle = glow; x.fillRect(6, 2, 2, 1); x.fillRect(14, 2, 2, 1);
|
| 160 |
+
}
|
| 161 |
+
const bossSprite = (kind, alt) => kind === 'goblin_priest' ? sprite('gp' + alt, 26, 30, x => paintGP(x, alt))
|
| 162 |
+
: kind === 'christmas_treant' ? sprite('ct' + alt, 38, 46, x => paintCT(x, alt))
|
| 163 |
+
: kind === 'grand_slime' ? sprite('gs' + alt, 36, 28, x => paintGS(x, alt))
|
| 164 |
+
: kind === 'varkolyn_leader' ? sprite('vl' + alt, 18, 32, x => paintVL(x, alt))
|
| 165 |
+
: kind === 'volcanic_sandworm' ? sprite('vs' + alt, 22, 40, x => paintVS(x, alt))
|
| 166 |
+
: sprite('ds' + alt, 44, 42, x => paintDS(x, alt));
|
| 167 |
+
// minions: slime 10x8 (body = hit circle), tentacle 10x18 (body = hit capsule [-16, 0] r 10)
|
| 168 |
+
const minionSprite = (kind, f) => kind === 'slime' ? sprite('slime' + f, 10, 8, x => {
|
| 169 |
+
ell(x, '#c23a4c', 5, 4.5, 5, 3.5 - f * 0.4); ell(x, '#ef5a6a', 5, 4, 4.5, 3 - f * 0.4); ell(x, '#ff9aa6', 3.5, 2.8, 1.5, 0.9);
|
| 170 |
+
x.fillStyle = '#16181c'; x.fillRect(3, 4, 1, 1.5); x.fillRect(6, 4, 1, 1.5);
|
| 171 |
+
}) : sprite('tent' + f, 10, 18, x => {
|
| 172 |
+
for (let i = 0; i < 5; i++) { const y = 16 - i * 3, w = 4.5 - i * 0.5, o = Math.sin(i * 0.9 + f * 1.4) * 0.8; ell(x, i % 2 ? '#5a2a8a' : '#7a3aaa', 5 + o, y, w, 2); }
|
| 173 |
+
ell(x, '#c46aff', 5, 2.5, 2.2, 2.2); x.fillStyle = '#e8fff4'; x.fillRect(4.5, 1.8, 1, 1);
|
| 174 |
+
});
|
| 175 |
+
|
| 176 |
+
// ---------- props ----------
|
| 177 |
+
const PROPS = {
|
| 178 |
+
tepee: () => sprite('tepee', 36, 30, x => {
|
| 179 |
+
x.fillStyle = '#c9a36a'; poly(x, [[18, 3], [1, 30], [35, 30]]); x.fillStyle = '#a8814a'; poly(x, [[18, 3], [26, 30], [35, 30]]);
|
| 180 |
+
x.fillStyle = '#8a3a2a'; for (const y of [12, 18, 24]) { const hw = (y - 3) * 17 / 27; x.fillRect(18 - hw, y, hw * 2, 2); }
|
| 181 |
+
x.fillStyle = '#f2c94c'; for (const y of [15, 21]) { const hw = (y - 3) * 17 / 27; for (let i = -hw + 2; i < hw - 1; i += 4) x.fillRect(18 + i, y, 2, 1); }
|
| 182 |
+
x.fillStyle = '#2e2014'; poly(x, [[18, 15], [13, 30], [23, 30]]);
|
| 183 |
+
x.fillStyle = '#6a4a2a'; x.fillRect(15, 0, 1, 7); x.fillRect(20, 0, 1, 7); x.fillRect(17, 0, 1, 6);
|
| 184 |
+
}),
|
| 185 |
+
totem: () => sprite('totem', 12, 28, x => {
|
| 186 |
+
x.fillStyle = '#8a5a2a'; x.fillRect(3, 2, 6, 26); x.fillStyle = '#6a4220'; x.fillRect(7, 2, 2, 26);
|
| 187 |
+
x.fillStyle = '#c84a3a'; x.fillRect(0, 9, 12, 3); x.fillStyle = '#e8833a'; x.fillRect(0, 9, 3, 1); x.fillRect(9, 9, 3, 1);
|
| 188 |
+
x.fillStyle = '#f2c94c'; x.fillRect(4, 4, 1, 2); x.fillRect(7, 4, 1, 2); x.fillStyle = '#2a1a10'; x.fillRect(4, 16, 4, 2); x.fillRect(4, 21, 4, 1);
|
| 189 |
+
x.fillStyle = '#3a8acf'; x.fillRect(4, 13, 4, 1); x.fillStyle = '#5a3a1a'; x.fillRect(2, 0, 8, 2);
|
| 190 |
+
}),
|
| 191 |
+
torch: () => sprite('torch', 6, 14, x => { x.fillStyle = '#6a4a2a'; x.fillRect(2, 4, 2, 10); x.fillStyle = '#4a3220'; x.fillRect(1, 3, 4, 2); }),
|
| 192 |
+
stone: () => sprite('stone', 24, 30, x => {
|
| 193 |
+
x.fillStyle = '#7d8a8f'; x.fillRect(0, 6, 24, 24); x.fillStyle = '#a2afb3'; x.fillRect(0, 0, 24, 8);
|
| 194 |
+
x.fillStyle = '#5f6b70'; x.fillRect(0, 26, 24, 4); x.fillRect(20, 7, 4, 23);
|
| 195 |
+
x.fillStyle = '#4f8a3f'; x.fillRect(0, 0, 24, 2); x.fillRect(2, 2, 6, 2); x.fillRect(14, 2, 5, 1); x.fillRect(0, 8, 2, 5);
|
| 196 |
+
x.fillStyle = '#56626a'; x.fillRect(6, 14, 5, 1); x.fillRect(10, 15, 1, 4); x.fillRect(15, 20, 4, 1); x.fillRect(4, 22, 1, 3);
|
| 197 |
+
}),
|
| 198 |
+
tree: () => sprite('tree', 24, 38, x => {
|
| 199 |
+
x.fillStyle = '#6b4527'; x.fillRect(10, 30, 4, 8);
|
| 200 |
+
for (const [top, bot, hw] of [[2, 14, 6], [9, 22, 9], [16, 31, 12]]) {
|
| 201 |
+
x.fillStyle = '#2b6236'; poly(x, [[12, top - 2], [12 - hw, bot], [12 + hw, bot]]); x.fillStyle = '#3a8046'; poly(x, [[12, top - 2], [12 - hw, bot], [11, bot]]);
|
| 202 |
+
x.fillStyle = '#eef6fb'; poly(x, [[12, top - 2], [12 - hw * 0.5, top + 4], [12, top + 3], [12 + hw * 0.5, top + 4]]); x.fillRect(12 - hw + 1, bot - 1, hw * 2 - 2, 1);
|
| 203 |
+
}
|
| 204 |
+
}),
|
| 205 |
+
crate: d => sprite('crate' + d, 12, 14, x => {
|
| 206 |
+
x.fillStyle = '#d29a52'; x.fillRect(0, 0, 12, 4); x.fillStyle = '#aa763c'; x.fillRect(0, 3, 12, 11);
|
| 207 |
+
x.fillStyle = '#7a4f24'; x.fillRect(0, 3, 12, 1); x.fillRect(0, 13, 12, 1); x.fillRect(0, 3, 1, 11); x.fillRect(11, 3, 1, 11);
|
| 208 |
+
x.fillStyle = '#8a5a2a'; for (let i = 0; i < 9; i++) x.fillRect(1 + i, 4 + i, 2, 1);
|
| 209 |
+
if (d) { x.fillStyle = '#3a2410'; x.fillRect(3, 6, 1, 3); x.fillRect(4, 8, 2, 1); x.fillRect(8, 5, 1, 2); x.fillRect(7, 10, 2, 1); }
|
| 210 |
+
}),
|
| 211 |
+
// Grand Slime room: smiling-face boxes (doc) and weapon crates
|
| 212 |
+
smile: d => sprite('smile' + d, 12, 14, x => {
|
| 213 |
+
x.fillStyle = '#e8c070'; x.fillRect(0, 0, 12, 4); x.fillStyle = '#c99a4a'; x.fillRect(0, 3, 12, 11);
|
| 214 |
+
x.fillStyle = '#8a6224'; x.fillRect(0, 3, 12, 1); x.fillRect(0, 13, 12, 1); x.fillRect(0, 3, 1, 11); x.fillRect(11, 3, 1, 11);
|
| 215 |
+
x.fillStyle = '#3a2410'; x.fillRect(3, 6, 2, 2); x.fillRect(7, 6, 2, 2); x.fillRect(3, 10, 6, 1); x.fillRect(2, 9, 1, 1); x.fillRect(9, 9, 1, 1);
|
| 216 |
+
if (d) { x.fillRect(5, 4, 1, 2); x.fillRect(9, 11, 2, 1); }
|
| 217 |
+
}),
|
| 218 |
+
wcrate: d => sprite('wcrate' + d, 14, 14, x => {
|
| 219 |
+
x.fillStyle = '#8a94a2'; x.fillRect(0, 0, 14, 4); x.fillStyle = '#5a6270'; x.fillRect(0, 3, 14, 11);
|
| 220 |
+
x.fillStyle = '#2f343c'; x.fillRect(0, 3, 14, 1); x.fillRect(0, 13, 14, 1); x.fillStyle = '#f2c94c'; x.fillRect(5, 6, 4, 3); x.fillRect(6, 9, 2, 2);
|
| 221 |
+
if (d) { x.fillStyle = '#1a1e24'; x.fillRect(2, 5, 1, 3); x.fillRect(11, 10, 2, 1); }
|
| 222 |
+
}),
|
| 223 |
+
// Volcanic Sandworm room: one pillar (doc)
|
| 224 |
+
pillar: () => sprite('pillar', 24, 34, x => {
|
| 225 |
+
x.fillStyle = '#4a3a34'; x.fillRect(1, 6, 22, 28); x.fillStyle = '#6a544a'; x.fillRect(1, 6, 6, 28);
|
| 226 |
+
x.fillStyle = '#2a1e1a'; x.fillRect(17, 6, 6, 28); x.fillStyle = '#8a7060'; x.fillRect(0, 0, 24, 7); x.fillStyle = '#a88a74'; x.fillRect(0, 0, 24, 2);
|
| 227 |
+
x.fillStyle = '#ff7a2a'; x.fillRect(8, 14, 2, 8); x.fillRect(10, 20, 4, 2); x.fillRect(13, 22, 2, 6); x.fillStyle = '#ffd04a'; x.fillRect(8, 15, 1, 5);
|
| 228 |
+
})
|
| 229 |
+
};
|
| 230 |
+
const WEAPON_ART = {
|
| 231 |
+
pistol: () => sprite('w-pistol', 9, 6, x => { x.fillStyle = '#9aa3ad'; x.fillRect(0, 0, 9, 3); x.fillStyle = '#d4dbe2'; x.fillRect(1, 0, 7, 1); x.fillStyle = '#4a3a2a'; x.fillRect(1, 3, 3, 3); }),
|
| 232 |
+
rifle: () => sprite('w-rifle', 16, 6, x => { x.fillStyle = '#5a6270'; x.fillRect(3, 0, 13, 3); x.fillStyle = '#8a94a2'; x.fillRect(4, 0, 11, 1); x.fillStyle = '#7a5230'; x.fillRect(0, 1, 4, 3); x.fillStyle = '#2f343c'; x.fillRect(7, 3, 3, 3); x.fillRect(4, 3, 2, 2); }),
|
| 233 |
+
sword: () => sprite('w-sword', 22, 7, x => { x.fillStyle = '#d8e0e8'; x.fillRect(6, 2, 16, 3); x.fillStyle = '#ffffff'; x.fillRect(7, 2, 14, 1); x.fillStyle = '#9aa6b2'; x.fillRect(6, 4, 15, 1); x.fillStyle = '#c9a227'; x.fillRect(4, 0, 2, 7); x.fillStyle = '#7a4a2a'; x.fillRect(0, 2, 4, 3); })
|
| 234 |
+
};
|
| 235 |
+
const ICONS = {
|
| 236 |
+
hp: () => fromMatrix('i-hp', ['.RR.RR.', 'RrrRrrR', 'RrwrrrR', '.RrrrR.', '..RrR..', '...R...'], { R: '#b5282c', r: '#ff5050', w: '#ffc0c0' }),
|
| 237 |
+
armor: () => fromMatrix('i-armor', ['SSSSSSS', 'SwsssgS', 'SsssssS', '.SsssS.', '..SsS..', '...S...'], { S: '#6b7686', s: '#c4cdd8', w: '#ffffff', g: '#9aa4b2' }),
|
| 238 |
+
energy: () => fromMatrix('i-energy', ['...B...', '..BwB..', '.BbbbB.', 'BbbbbbB', '.BbbbB.', '..BbB..', '...B...'], { B: '#2a6ad0', b: '#5ab4ff', w: '#e0f4ff' }),
|
| 239 |
+
angry: () => fromMatrix('i-angry', ['.R...R.', 'RrR.RrR', '.RrrrR.', '..RrR..', '.RrrrR.', 'RrR.RrR', '.R...R.'], { R: '#a01818', r: '#ff3a3a' }),
|
| 240 |
+
orb: () => sprite('i-orb', 6, 7, x => { x.fillStyle = '#3a8aff'; poly(x, [[3, 0], [6, 3.5], [3, 7], [0, 3.5]]); x.fillStyle = '#bfe4ff'; x.fillRect(2, 2, 1, 2); })
|
| 241 |
+
};
|
| 242 |
+
|
| 243 |
+
// ---------- bullets (screen resolution, cached) ----------
|
| 244 |
+
function bulletSprite(kind, r) {
|
| 245 |
+
const key = 'b' + kind + r;
|
| 246 |
+
let s = cache.get(key);
|
| 247 |
+
if (s) return s;
|
| 248 |
+
const pad = 3, size = Math.ceil(r * 2 + pad * 2 + 6), c = mk(size, size), x = ctx2d(c), m = size / 2;
|
| 249 |
+
const disc = (rr, col) => ell(x, col, m, m, rr, rr);
|
| 250 |
+
if (kind === 'star') {
|
| 251 |
+
x.fillStyle = '#3a2a06'; starPath(x, m, m, r + 3, r * 0.5 + 2, 5); x.fill();
|
| 252 |
+
x.fillStyle = '#ffd43a'; starPath(x, m, m, r + 1, r * 0.5, 5); x.fill();
|
| 253 |
+
x.fillStyle = '#fff4b0'; starPath(x, m - 1, m - 1, r * 0.45, r * 0.2, 5); x.fill();
|
| 254 |
+
} else if (kind === 'cross') {
|
| 255 |
+
const arm = (w, h, col) => { x.fillStyle = col; x.fillRect(m - w / 2, m - h / 2, w, h); x.fillRect(m - h / 2, m - w / 2, h, w); };
|
| 256 |
+
arm(r * 2 + 4, r * 0.9 + 4, '#3a1406'); arm(r * 2, r * 0.9, '#ff8a2a'); arm(r * 1.1, r * 0.35, '#ffe0a0');
|
| 257 |
+
} else if (kind === 'bubble') {
|
| 258 |
+
disc(r + 2, 'rgba(58,20,70,0.85)'); disc(r, 'rgba(226,128,236,0.75)'); disc(r - 2, 'rgba(250,190,255,0.55)'); ell(x, '#ffffff', m - r * 0.35, m - r * 0.35, 2, 1.6);
|
| 259 |
+
} else if (kind === 'homing') {
|
| 260 |
+
disc(r + 2, '#1a1640'); disc(r, '#6f74ff'); disc(r * 0.55, '#d4d6ff'); ell(x, '#ffffff', m - 1.5, m - 1.5, 1.4, 1.4);
|
| 261 |
+
} else if (kind === 'diamond' || kind === 'slam' || kind === 'petal') { // Grand Slime bullets
|
| 262 |
+
const col = kind === 'diamond' ? ['#3a0612', '#ff2a4a', '#ffd0d8'] : kind === 'petal' ? ['#3a1a06', '#ffb03a', '#fff0c0'] : ['#3a0612', '#ff5a6a', '#ffd0d8'];
|
| 263 |
+
if (kind === 'diamond') { x.fillStyle = col[0]; poly(x, [[m, m - r - 3], [m + r + 3, m], [m, m + r + 3], [m - r - 3, m]]); x.fillStyle = col[1]; poly(x, [[m, m - r], [m + r, m], [m, m + r], [m - r, m]]); x.fillStyle = col[2]; x.fillRect(m - 1.5, m - r * 0.5, 2, 3); }
|
| 264 |
+
else { disc(r + 2, col[0]); disc(r, col[1]); disc(r * 0.5, col[2]); }
|
| 265 |
+
} else if (kind === 'vorb') { // Varkolyn spiral emitter
|
| 266 |
+
disc(r + 3, '#12061e'); disc(r + 1, '#6a2aaa'); disc(r - 2, '#c46aff'); disc(r * 0.45, '#f6e0ff');
|
| 267 |
+
x.strokeStyle = '#f6e0ff'; x.lineWidth = 2; for (let i = 0; i < 4; i++) { const a = i * Math.PI / 2 + 0.4; x.beginPath(); x.moveTo(m + Math.cos(a) * (r - 4), m + Math.sin(a) * (r - 4)); x.lineTo(m + Math.cos(a) * (r + 1), m + Math.sin(a) * (r + 1)); x.stroke(); }
|
| 268 |
+
} else if (kind === 'shell' || kind === 'big') { // Sandworm explosive / big bullet
|
| 269 |
+
const col = kind === 'shell' ? ['#2a0e04', '#8a3a14', '#ffb04a'] : ['#2a0606', '#ff4a2a', '#ffd08a'];
|
| 270 |
+
disc(r + 2, col[0]); disc(r, col[1]); disc(r * 0.55, col[2]); x.fillStyle = '#fff4d0'; x.fillRect(m - r * 0.45, m - r * 0.45, 2, 2);
|
| 271 |
+
} else if (kind === 'bouncy') {
|
| 272 |
+
disc(r + 2, '#2a1006'); disc(r, '#ff8a2a'); disc(r * 0.5, '#fff0a0');
|
| 273 |
+
} else {
|
| 274 |
+
const col = kind === 'beam' ? ['#0f3a12', '#6dff4a', '#e0ffd0'] : kind === 'rail' ? ['#2a0f3a', '#c86aff', '#f6dcff'] : ['#2a0a10', '#ff5440', '#ffb070'];
|
| 275 |
+
disc(r + 2, col[0]); disc(r, col[1]); disc(r * 0.55, col[2]); ell(x, '#ffffff', m - r * 0.35, m - r * 0.35, Math.max(1, r * 0.25), Math.max(1, r * 0.25));
|
| 276 |
+
}
|
| 277 |
+
s = { c, m };
|
| 278 |
+
cache.set(key, s);
|
| 279 |
+
return s;
|
| 280 |
+
}
|
| 281 |
+
function capsule(c, x, y, a, len, w, cols) {
|
| 282 |
+
c.save(); c.translate(x, y); c.rotate(a);
|
| 283 |
+
c.fillStyle = cols[0]; c.beginPath(); c.ellipse(0, 0, len / 2 + 2, w / 2 + 2, 0, 0, TAU); c.fill();
|
| 284 |
+
c.fillStyle = cols[1]; c.beginPath(); c.ellipse(0, 0, len / 2, w / 2, 0, 0, TAU); c.fill();
|
| 285 |
+
c.fillStyle = cols[2]; c.beginPath(); c.ellipse(len * 0.12, -w * 0.12, len * 0.28, w * 0.22, 0, 0, TAU); c.fill();
|
| 286 |
+
c.restore();
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
// ---------- room background (cached per case) ----------
|
| 290 |
+
function background(kind) {
|
| 291 |
+
const key = 'bg' + kind;
|
| 292 |
+
let s = cache.get(key);
|
| 293 |
+
if (s) return s;
|
| 294 |
+
const c = mk(854, 480), x = ctx2d(c);
|
| 295 |
+
x.fillStyle = '#0a110d'; x.fillRect(0, 0, 854, 480);
|
| 296 |
+
// per-biome floor: Forest (green), Knight Kingdom (castle flagstone), Spaceship (steel deck), Volcano (basalt)
|
| 297 |
+
const theme = kind === 'christmas_treant' ? { a: '#5d8a58', b: '#567f51', lo: '#4a7046', hi: '#76a06e', snow: 0.2 }
|
| 298 |
+
: kind === 'devils_snare' ? { a: '#3f6a3d', b: '#3b6439', lo: '#30562f', hi: '#548752', snow: 0 }
|
| 299 |
+
: kind === 'grand_slime' ? { a: '#8a8072', b: '#80766a', lo: '#6c6458', hi: '#a09484', snow: 0, stone: 1, wall: ['#5a5048', '#665a50', '#7a6e62'], cap: ['#3a3430', '#4a423a', '#2a2622'] }
|
| 300 |
+
: kind === 'varkolyn_leader' ? { a: '#2c3440', b: '#283039', lo: '#1e252e', hi: '#3c4654', snow: 0, deck: 1, wall: ['#1e2a38', '#243244', '#34465c'], cap: ['#121a24', '#1a2430', '#0c1218'] }
|
| 301 |
+
: kind === 'volcanic_sandworm' ? { a: '#3a2a26', b: '#352622', lo: '#2a1e1a', hi: '#4a3630', snow: 0, lava: 1, wall: ['#2a1e1a', '#34261f', '#4a3428'], cap: ['#1a1210', '#2a1a14', '#120c0a'] }
|
| 302 |
+
: { a: '#4f7d3d', b: '#4a7639', lo: '#3f6630', hi: '#6a9a50', snow: 0 };
|
| 303 |
+
const cols = (R.x1 - R.x0) / TILE, rows = (R.y1 - R.y0) / TILE, forest = !theme.wall;
|
| 304 |
+
for (let r = 0; r < rows; r++) for (let q = 0; q < cols; q++) {
|
| 305 |
+
const X = R.x0 + q * TILE, Y = R.y0 + r * TILE;
|
| 306 |
+
x.fillStyle = (q + r) % 2 ? theme.a : theme.b; x.fillRect(X, Y, TILE, TILE);
|
| 307 |
+
for (let i = 0; i < 7; i++) { const u = hash(q * 7 + i, r * 13), v = hash(r * 11 + i, q * 5 + 3); x.fillStyle = u < 0.5 ? theme.lo : theme.hi; x.fillRect(X + Math.floor(u * 11) * 2, Y + Math.floor(v * 11) * 2, 2, 2); }
|
| 308 |
+
x.fillStyle = 'rgba(0,0,0,0.10)'; x.fillRect(X, Y + TILE - 2, TILE, 2); x.fillRect(X + TILE - 2, Y, 2, TILE);
|
| 309 |
+
const h = hash(q + 101, r + 37);
|
| 310 |
+
if (forest) {
|
| 311 |
+
if (h < 0.12) { x.fillStyle = theme.hi; const gx = X + 6 + Math.floor(hash(q, r + 5) * 6) * 2, gy = Y + 8 + Math.floor(hash(q + 3, r) * 4) * 2; x.fillRect(gx, gy, 2, 6); x.fillRect(gx - 3, gy + 2, 2, 4); x.fillRect(gx + 3, gy + 2, 2, 4); }
|
| 312 |
+
else if (h < 0.16) { const fc = ['#f2d24a', '#e86aa8', '#ffffff', '#7ac8ff'][Math.floor(hash(q, r) * 4)]; const fx = X + 8 + Math.floor(hash(r, q) * 4) * 2, fy = Y + 8; x.fillStyle = fc; x.fillRect(fx - 2, fy, 2, 2); x.fillRect(fx + 2, fy, 2, 2); x.fillRect(fx, fy - 2, 2, 2); x.fillRect(fx, fy + 2, 2, 2); x.fillStyle = '#e0a020'; x.fillRect(fx, fy, 2, 2); }
|
| 313 |
+
else if (h < 0.19) { x.fillStyle = '#7d8a7a'; x.fillRect(X + 10, Y + 12, 4, 2); x.fillStyle = '#a2ad9e'; x.fillRect(X + 10, Y + 12, 2, 1); }
|
| 314 |
+
} else if (theme.stone && h < 0.1) { x.fillStyle = '#5a5248'; x.fillRect(X + 4, Y + 10, 8, 1); x.fillRect(X + 11, Y + 10, 1, 6); }
|
| 315 |
+
else if (theme.deck) { x.fillStyle = '#3c4654'; x.fillRect(X + 2, Y + 2, 2, 2); x.fillRect(X + TILE - 4, Y + 2, 2, 2); x.fillRect(X + 2, Y + TILE - 4, 2, 2); x.fillRect(X + TILE - 4, Y + TILE - 4, 2, 2); if (h < 0.08) { x.fillStyle = '#5ac8ff'; x.fillRect(X + 8, Y + 11, 8, 2); } }
|
| 316 |
+
else if (theme.lava && h < 0.09) { x.fillStyle = '#ff6a2a'; x.fillRect(X + 6, Y + 8, 2, 6); x.fillRect(X + 8, Y + 12, 6, 2); x.fillStyle = '#ffc04a'; x.fillRect(X + 6, Y + 9, 1, 3); }
|
| 317 |
+
if (theme.snow && hash(q + 9, r + 77) < theme.snow) { x.fillStyle = 'rgba(240,248,255,0.85)'; const sx = X + Math.floor(hash(q, r + 9) * 6) * 2, sy = Y + Math.floor(hash(q + 4, r) * 6) * 2; x.fillRect(sx, sy, 10, 4); x.fillRect(sx + 2, sy - 2, 6, 2); x.fillRect(sx + 2, sy + 4, 8, 2); }
|
| 318 |
+
}
|
| 319 |
+
if (kind === 'devils_snare') { // moss ring around the stationary boss
|
| 320 |
+
for (let i = 0; i < 90; i++) { const a = hash(i, 3) * TAU, d = 50 + hash(i, 4) * 90; x.fillStyle = i % 3 ? '#2e5a2c' : '#5a8a3a'; x.fillRect(Math.round((427 + Math.cos(a) * d) / 2) * 2, Math.round((256 + Math.sin(a) * d) / 2) * 2, 4, 2); }
|
| 321 |
+
}
|
| 322 |
+
// walls: hedge caps + stone brick face at the top (later biomes: their own masonry colours)
|
| 323 |
+
const W = theme.wall || ['#4a584c', '#435046', '#5c6b5e'], C = theme.cap || ['#244d29', '#2f6234', '#1b3d20'];
|
| 324 |
+
const hedge = (X, Y, w, h) => { x.fillStyle = C[0]; x.fillRect(X, Y, w, h); for (let i = 0; i < w * h / 18; i++) { const u = hash(X + i, Y), v = hash(Y + i, X + 1); x.fillStyle = u < 0.5 ? C[1] : C[2]; x.fillRect(X + Math.floor(u * w / 2) * 2, Y + Math.floor(v * h / 2) * 2, 2, 2); } };
|
| 325 |
+
x.fillStyle = '#3e4a40'; x.fillRect(R.x0 - 12, 40, R.x1 - R.x0 + 24, 24);
|
| 326 |
+
x.save(); x.beginPath(); x.rect(R.x0 - 12, 40, R.x1 - R.x0 + 24, 24); x.clip();
|
| 327 |
+
for (let row = 0; row < 2; row++) for (let i = 0; i < 34; i++) {
|
| 328 |
+
const bx = R.x0 - 12 + i * 24 - (row ? 12 : 0), by = 40 + row * 12;
|
| 329 |
+
x.fillStyle = (i + row) % 3 ? W[0] : W[1]; x.fillRect(bx + 1, by + 1, 22, 10); x.fillStyle = W[2]; x.fillRect(bx + 1, by + 1, 22, 2);
|
| 330 |
+
}
|
| 331 |
+
x.restore();
|
| 332 |
+
x.fillStyle = '#2a332c'; x.fillRect(R.x0 - 12, 63, R.x1 - R.x0 + 24, 1);
|
| 333 |
+
hedge(R.x0 - 12, 26, R.x1 - R.x0 + 24, 14); hedge(R.x0 - 12, 26, 12, R.y1 - 26 + 10); hedge(R.x1, 26, 12, R.y1 - 26 + 10); hedge(R.x0 - 12, R.y1, R.x1 - R.x0 + 24, 8);
|
| 334 |
+
x.fillStyle = '#16301a'; x.fillRect(R.x0 - 12, 38, R.x1 - R.x0 + 24, 2);
|
| 335 |
+
const grd = x.createLinearGradient(0, R.y0, 0, R.y0 + 14); grd.addColorStop(0, 'rgba(0,0,0,0.35)'); grd.addColorStop(1, 'rgba(0,0,0,0)'); x.fillStyle = grd; x.fillRect(R.x0, R.y0, R.x1 - R.x0, 14);
|
| 336 |
+
x.fillStyle = 'rgba(0,0,0,0.25)'; x.fillRect(R.x0, R.y0, 6, R.y1 - R.y0); x.fillRect(R.x1 - 4, R.y0, 4, R.y1 - R.y0);
|
| 337 |
+
s = c;
|
| 338 |
+
cache.set(key, s);
|
| 339 |
+
return s;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
// ---------- helpers ----------
|
| 343 |
+
function txt(c, s, x, y, size, col, align, weight) {
|
| 344 |
+
c.font = (weight || 'bold') + ' ' + size + 'px ' + FONT; c.textAlign = align || 'left'; c.textBaseline = 'alphabetic';
|
| 345 |
+
c.lineJoin = 'round'; c.lineWidth = Math.max(2, size / 4); c.strokeStyle = '#0b0a10'; c.strokeText(s, x, y); c.fillStyle = col; c.fillText(s, x, y);
|
| 346 |
+
}
|
| 347 |
+
function panel(c, x, y, w, h) {
|
| 348 |
+
c.fillStyle = 'rgba(16,14,22,0.84)'; c.fillRect(x, y, w, h);
|
| 349 |
+
c.strokeStyle = '#06050a'; c.lineWidth = 2; c.strokeRect(x + 1, y + 1, w - 2, h - 2);
|
| 350 |
+
c.strokeStyle = 'rgba(150,140,170,0.45)'; c.lineWidth = 1; c.strokeRect(x + 3.5, y + 3.5, w - 7, h - 7);
|
| 351 |
+
}
|
| 352 |
+
function bar(c, x, y, w, h, v, max, fg, bg, label) {
|
| 353 |
+
c.fillStyle = '#06050a'; c.fillRect(x - 1, y - 1, w + 2, h + 2); c.fillStyle = bg; c.fillRect(x, y, w, h);
|
| 354 |
+
const f = Math.max(0, Math.min(1, v / max));
|
| 355 |
+
c.fillStyle = fg; c.fillRect(x, y, Math.round(w * f), h); c.fillStyle = 'rgba(255,255,255,0.28)'; c.fillRect(x, y, Math.round(w * f), 2);
|
| 356 |
+
if (label) txt(c, label, x + w / 2, y + h - 2, 11, '#ffffff', 'center');
|
| 357 |
+
}
|
| 358 |
+
const shadow = (c, x, y, rx, ry) => { c.fillStyle = 'rgba(0,0,0,0.28)'; c.beginPath(); c.ellipse(x, y, rx, ry, 0, 0, TAU); c.fill(); };
|
| 359 |
+
|
| 360 |
+
// ---------- world ----------
|
| 361 |
+
function drawKnight(c, g) {
|
| 362 |
+
const p = g.player, t = g.t;
|
| 363 |
+
const frame = p.moving && Math.floor(p.step / 8) % 2 ? 1 : 0, bob = p.moving && Math.floor(p.step / 8) % 2 ? -2 : 0;
|
| 364 |
+
const flip = p.face < 0, flash = t - p.hurtT < 5, blink = p.inv > 0 && Math.floor(t / 4) % 2 === 1;
|
| 365 |
+
shadow(c, p.x, p.y + 11, 10, 4);
|
| 366 |
+
if (p.dead > 0 || (p.hp <= 0)) {
|
| 367 |
+
c.save(); c.translate(p.x, p.y + 8); c.rotate(-Math.PI / 2); c.globalAlpha = 0.9; c.drawImage(knight(0).c, -14, -16, 28, 34); c.restore();
|
| 368 |
+
return;
|
| 369 |
+
}
|
| 370 |
+
if (p.dual > 0) { c.strokeStyle = 'rgba(255,210,80,' + (0.35 + 0.2 * Math.sin(t * 0.3)) + ')'; c.lineWidth = 2; c.beginPath(); c.ellipse(p.x, p.y + 11, 15, 6, 0, 0, TAU); c.stroke(); }
|
| 371 |
+
const wid = M.slots[p.slot], back = Math.sin(p.aimA) < -0.2;
|
| 372 |
+
if (back) drawWeapon(c, g, wid);
|
| 373 |
+
blit(c, knight(frame), p.x, p.y + 13 + bob, 2, flip, flash, blink ? 0.35 : undefined);
|
| 374 |
+
if (p.poison > 0) { c.fillStyle = 'rgba(90,220,70,0.25)'; c.fillRect(p.x - 12, p.y - 20, 24, 32); }
|
| 375 |
+
if (!back) drawWeapon(c, g, wid);
|
| 376 |
+
}
|
| 377 |
+
function drawWeapon(c, g, wid) {
|
| 378 |
+
const p = g.player, t = g.t, s = WEAPON_ART[wid](), a = p.aimA, flipY = Math.cos(a) < 0;
|
| 379 |
+
const one = (side, last) => {
|
| 380 |
+
c.save(); c.translate(p.x, p.y + 4); c.rotate(a); c.translate(4, side); if (flipY) c.scale(1, -1);
|
| 381 |
+
if (wid === 'sword') {
|
| 382 |
+
if (p.swing > 0 && p.swingKind !== 'knife') c.rotate(((p.swing / 8) - 0.5) * -2.2);
|
| 383 |
+
c.drawImage(s.c, -2, -s.h, s.w * 2, s.h * 2);
|
| 384 |
+
} else {
|
| 385 |
+
const kick = t - last < 3 ? -2 : 0;
|
| 386 |
+
c.drawImage(s.c, kick, -s.h + 1, s.w * 2, s.h * 2);
|
| 387 |
+
if (t - last < 3) { const mx = s.w * 2 + kick + 2; c.fillStyle = '#fff6c0'; c.fillRect(mx, -2, 8, 4); c.fillRect(mx + 2, -5, 4, 10); c.fillStyle = '#ffc23a'; c.fillRect(mx + 7, -1, 4, 2); }
|
| 388 |
+
}
|
| 389 |
+
c.restore();
|
| 390 |
+
};
|
| 391 |
+
one(0, p.lastShot);
|
| 392 |
+
if (p.dual > 0) one(7, p.lastCopy);
|
| 393 |
+
}
|
| 394 |
+
function drawSwing(c, g) {
|
| 395 |
+
const p = g.player;
|
| 396 |
+
if (p.swing <= 0 || p.dead > 0) return;
|
| 397 |
+
const knife = p.swingKind === 'knife', k = p.swing / (knife ? 10 : 8);
|
| 398 |
+
const reach = knife ? 24 : M.weapons.sword.reach, arc = knife ? 0.9 : M.weapons.sword.arc * Math.PI / 180;
|
| 399 |
+
c.save(); c.globalAlpha = 0.25 + 0.6 * k;
|
| 400 |
+
c.strokeStyle = '#ffffff'; c.lineWidth = knife ? 3 : 7; c.beginPath(); c.arc(p.x, p.y, reach - 4, p.swingA - arc, p.swingA + arc); c.stroke();
|
| 401 |
+
c.strokeStyle = knife ? '#ffd0a0' : '#9fd8ff'; c.lineWidth = knife ? 2 : 3; c.beginPath(); c.arc(p.x, p.y, reach - 10, p.swingA - arc * 0.85, p.swingA + arc * 0.85); c.stroke();
|
| 402 |
+
if (!knife) { c.globalAlpha *= 0.18; c.fillStyle = '#cfefff'; c.beginPath(); c.moveTo(p.x, p.y); c.arc(p.x, p.y, reach, p.swingA - arc, p.swingA + arc); c.closePath(); c.fill(); }
|
| 403 |
+
c.restore();
|
| 404 |
+
}
|
| 405 |
+
function drawBoss(c, g) {
|
| 406 |
+
const b = g.boss, t = g.t;
|
| 407 |
+
if (b.hp <= 0 && b.state !== 'dying') return;
|
| 408 |
+
// hit flash = light 2-tick tint (round 3: a 0.6 white overlay covered the boss in 11-15 % of video frames under sustained fire)
|
| 409 |
+
const dying = b.state === 'dying', since = t - b.flash, flash = since < 2 ? 0.32 : (dying && Math.floor(t / 4) % 2 === 0) ? 0.8 : 0;
|
| 410 |
+
let alpha = dying ? Math.min(1, b.deadT / 30) : undefined;
|
| 411 |
+
if (b.kind === 'goblin_priest') {
|
| 412 |
+
const s = bossSprite('goblin_priest', b.enraged), flip = b.face < 0, walk = (b.vx || b.vy) ? Math.floor(t / 10) % 2 * -2 : 0;
|
| 413 |
+
shadow(c, b.x, b.y + 18, 20, 6);
|
| 414 |
+
blit(c, s, b.x, b.y + 20 + walk, 2, flip, flash, alpha);
|
| 415 |
+
drawStaff(c, g);
|
| 416 |
+
} else if (b.kind === 'christmas_treant') {
|
| 417 |
+
const s = bossSprite('christmas_treant', b.enraged), charging = b.atk === 'charge' && b.vars.ph === 'dash';
|
| 418 |
+
shadow(c, b.x, b.y + 28, 30, 9);
|
| 419 |
+
c.save();
|
| 420 |
+
if (charging) {
|
| 421 |
+
c.translate(b.x, b.y + 30); c.rotate(Math.cos(b.vars.a) * 0.25); c.translate(-b.x, -(b.y + 30));
|
| 422 |
+
c.strokeStyle = 'rgba(255,255,255,0.55)'; c.lineWidth = 2;
|
| 423 |
+
for (let i = 0; i < 5; i++) { const o = (i - 2) * 12, ca = Math.cos(b.vars.a), sa = Math.sin(b.vars.a); c.beginPath(); c.moveTo(b.x - ca * 44 - sa * o, b.y - sa * 44 + ca * o); c.lineTo(b.x - ca * (70 + i * 6) - sa * o, b.y - sa * (70 + i * 6) + ca * o); c.stroke(); }
|
| 424 |
+
}
|
| 425 |
+
const stomp = (b.atk === 'waves' || b.atk === 'line' || b.atk === 'transform') && b.at % 30 < 8 ? 3 : 0;
|
| 426 |
+
blit(c, s, b.x, b.y + 32 + stomp, 2, b.face < 0, flash, alpha);
|
| 427 |
+
c.restore();
|
| 428 |
+
if ((b.atk === 'hold' && b.at >= 6 && b.at < 172) || (b.atk === 'throw' && b.at < 30)) drawLaserBall(c, b.x, b.y - 48, 16, t);
|
| 429 |
+
if (b.atk === 'homing' && b.at < 22) { c.fillStyle = 'rgba(160,170,255,0.5)'; c.beginPath(); c.arc(b.x, b.y - 58, 10 + b.at * 0.6, 0, TAU); c.fill(); }
|
| 430 |
+
} else if (b.kind === 'grand_slime') {
|
| 431 |
+
// sprite bottom-centre at y+20: the jelly body (art 1..55 x 7..43) spans the hurt capsule [-16, 2] r 28
|
| 432 |
+
const s = bossSprite('grand_slime', b.enraged), squash = 1 + 0.06 * Math.sin(t * 0.25) + ((b.atk === 'slam' || b.atk === 'goo') && b.at % 30 > 18 ? 0.12 : 0);
|
| 433 |
+
const swell = b.boom > 0 ? 1 + 0.18 * (1 - b.boom / M.SLIME_SWELL) : 1;
|
| 434 |
+
shadow(c, b.x, b.y + 20, 32, 8);
|
| 435 |
+
c.save(); c.translate(b.x, b.y + 17); c.scale(swell * squash, swell / squash); c.translate(-b.x, -(b.y + 17));
|
| 436 |
+
blit(c, s, b.x, b.y + 17, 2, b.face < 0, flash || (b.boom > 0 && Math.floor(t / 4) % 2 ? 0.5 : 0), alpha);
|
| 437 |
+
c.restore();
|
| 438 |
+
} else if (b.kind === 'varkolyn_leader') {
|
| 439 |
+
const s = bossSprite('varkolyn_leader', b.enraged), walk = (b.vx || b.vy) ? Math.floor(t / 10) % 2 * -2 : 0;
|
| 440 |
+
shadow(c, b.x, b.y + 8, 16, 5);
|
| 441 |
+
// shield: doc "becomes semi-transparent" while invulnerable in its pool
|
| 442 |
+
const a = b.shield > 0 ? 0.45 : alpha;
|
| 443 |
+
blit(c, s, b.x, b.y + 8 + walk, 2, b.face < 0, flash, a);
|
| 444 |
+
if (b.shield > 0) { c.strokeStyle = 'rgba(200,140,255,' + (0.5 + 0.3 * Math.sin(t * 0.4)) + ')'; c.lineWidth = 2; c.beginPath(); c.ellipse(b.x, b.y - 24, 22, 38, 0, 0, TAU); c.stroke(); }
|
| 445 |
+
if (b.atk === 'laser' && !b.vars.on) { // doc: raises its head, swirl mark glows before the chime -> laser
|
| 446 |
+
c.fillStyle = 'rgba(255,90,140,' + (0.3 + 0.3 * Math.sin(t * 0.8)) + ')'; c.beginPath(); c.arc(b.x, b.y - M.VARK_EYE, 10, 0, TAU); c.fill();
|
| 447 |
+
}
|
| 448 |
+
} else if (b.kind === 'volcanic_sandworm') {
|
| 449 |
+
const v = b.vars;
|
| 450 |
+
if (b.under) { // doc: "a dirt pile where the boss is burrowed. It will move and can serve as an indicator"
|
| 451 |
+
drawMound(c, b.x, b.y, t, v.ph === 'rise' ? 1 - v.c / M.WORM_RISE : 0);
|
| 452 |
+
} else {
|
| 453 |
+
const sink = v.ph === 'sink' ? 1 - v.c / Math.max(1, Math.round(M.WORM_SINK * (b.enraged ? 0.7 : 1))) : 0;
|
| 454 |
+
const tilt = (b.atk === 'explosive' || b.atk === 'spread') && b.at < 24 ? -0.12 * Math.min(1, b.at / 12) : 0;
|
| 455 |
+
shadow(c, b.x, b.y + 4, 24, 7);
|
| 456 |
+
c.save(); c.beginPath(); c.rect(b.x - 40, b.y - 120, 80, 126); c.clip();
|
| 457 |
+
c.translate(b.x, b.y + 4); c.rotate(tilt); c.translate(-b.x, -(b.y + 4));
|
| 458 |
+
blit(c, bossSprite('volcanic_sandworm', b.enraged), b.x, b.y + 4 + sink * 84, 2, b.face < 0, flash, alpha);
|
| 459 |
+
c.restore();
|
| 460 |
+
drawMound(c, b.x, b.y + 6, t, 0, true);
|
| 461 |
+
}
|
| 462 |
+
} else {
|
| 463 |
+
const s = bossSprite('devils_snare', b.enraged), pulse = (b.atk === 'bubbles' && b.at < 20) ? 1 + 0.08 * Math.sin(b.at * 0.8) : 1;
|
| 464 |
+
shadow(c, b.x, b.y + 38, 36, 10);
|
| 465 |
+
for (const tn of b.tentacles) drawTentacle(c, b, tn, t, b.atk === 'corner' && b.at < 22);
|
| 466 |
+
// anchor so the flower centre (art 22,21) sits exactly on the boss / hurt circle centre
|
| 467 |
+
c.save(); c.translate(b.x, b.y + 44); c.scale(pulse, pulse); c.translate(-b.x, -(b.y + 44));
|
| 468 |
+
blit(c, s, b.x, b.y + 44, 2, false, flash, alpha);
|
| 469 |
+
c.restore();
|
| 470 |
+
if (b.atk === 'beams' && b.at < 22) { c.fillStyle = 'rgba(110,255,80,0.25)'; c.beginPath(); c.arc(b.x, b.y, 36 + b.at, 0, TAU); c.fill(); }
|
| 471 |
+
}
|
| 472 |
+
const iconUp = ['grand_slime', 'varkolyn_leader', 'volcanic_sandworm'].includes(b.kind) ? -M.bosses[b.kind].hurt[0] + 30 : b.r * 1.7; // above the tall new sprites
|
| 473 |
+
if (b.enraged && !dying && !b.under) blit(c, ICONS.angry(), b.x + b.r * 0.8, b.y - iconUp + Math.sin(t * 0.2) * 2, 2);
|
| 474 |
+
}
|
| 475 |
+
function drawMound(c, x, y, t, rise, rim) { // Sandworm dirt mound (moving indicator) / ring of rubble at the hole
|
| 476 |
+
const n = rim ? 7 : 9, w = rim ? 26 : 22 + rise * 8;
|
| 477 |
+
for (let i = 0; i < n; i++) {
|
| 478 |
+
const a = i * TAU / n + (rim ? 0 : t * 0.05), j = rim ? 0 : Math.sin(t * 0.6 + i) * 1.5 * (1 + rise * 2);
|
| 479 |
+
ell(c, i % 2 ? '#5a3a24' : '#7a5232', x + Math.cos(a) * w * 0.6 + j, y + Math.sin(a) * w * 0.25, 7, 4);
|
| 480 |
+
}
|
| 481 |
+
if (!rim) { ell(c, '#3a2414', x, y, w * 0.5, w * 0.2); if (rise > 0) { c.fillStyle = 'rgba(255,140,60,' + (0.3 + 0.4 * rise) + ')'; c.beginPath(); c.ellipse(x, y, w * 0.4, w * 0.15, 0, 0, TAU); c.fill(); } }
|
| 482 |
+
}
|
| 483 |
+
function drawMinions(c, g) {
|
| 484 |
+
const t = g.t;
|
| 485 |
+
for (const m of g.minions) {
|
| 486 |
+
const e = m.emerge > 0 ? 1 - m.emerge / (m.kind === 'slime' ? 24 : 40) : 1, f = Math.floor(t / 10) % 2;
|
| 487 |
+
if (m.kind === 'slime') {
|
| 488 |
+
shadow(c, m.x, m.y + 8, 9, 3);
|
| 489 |
+
c.save(); if (e < 1) c.globalAlpha = 0.4 + 0.6 * e;
|
| 490 |
+
blit(c, minionSprite('slime', f), m.x, m.y + 9, 2, false, t - m.flash < 3 ? 0.5 : 0); c.restore();
|
| 491 |
+
} else {
|
| 492 |
+
// tentacle grows out of the floor (emerging = harmless, not yet firing)
|
| 493 |
+
shadow(c, m.x, m.y + 10, 10, 3);
|
| 494 |
+
c.save(); c.beginPath(); c.rect(m.x - 20, m.y - 40, 40, 62); c.clip();
|
| 495 |
+
blit(c, minionSprite('tentacle', f), m.x, m.y + 20 + (1 - e) * 40, 2, false, t - m.flash < 3 ? 0.5 : 0); c.restore();
|
| 496 |
+
if (e >= 1 && m.fire < 20) { c.fillStyle = 'rgba(196,106,255,' + (0.6 - m.fire * 0.025) + ')'; c.beginPath(); c.arc(m.x, m.y - 10, 8 + (20 - m.fire) * 0.5, 0, TAU); c.fill(); }
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
}
|
| 500 |
+
function drawStaff(c, g) {
|
| 501 |
+
const b = g.boss, front = b.face > 0 ? 1 : -1;
|
| 502 |
+
const hx = b.x + front * 18, top = b.y - 34;
|
| 503 |
+
c.fillStyle = '#1a120a'; c.fillRect(hx - 3, top - 2, 6, 58); c.fillStyle = '#8a5a2a'; c.fillRect(hx - 1, top, 3, 54); c.fillStyle = '#b07a40'; c.fillRect(hx - 1, top, 1, 54);
|
| 504 |
+
const col = { meteor: '#ff7a2a', orbs: '#6ad8ff', turrets: '#d0d8e0', stars: '#ffd43a' }[b.atk] || '#a8e68e';
|
| 505 |
+
const glow = b.state === 'cast' ? 9 + Math.sin(g.t * 0.5) * 2 : 6;
|
| 506 |
+
c.fillStyle = col; c.globalAlpha = 0.35; c.beginPath(); c.arc(hx, top - 4, glow + 5, 0, TAU); c.fill(); c.globalAlpha = 1;
|
| 507 |
+
c.fillStyle = '#16120a'; starPath(c, hx, top - 4, 9, 4, 5); c.fill(); c.fillStyle = col; starPath(c, hx, top - 4, 7, 3, 5); c.fill();
|
| 508 |
+
}
|
| 509 |
+
function drawTentacle(c, b, tn, t, glow) {
|
| 510 |
+
const n = 7;
|
| 511 |
+
for (let i = 0; i <= n; i++) {
|
| 512 |
+
const k = i / n, w = Math.sin(t * 0.12 + i * 0.9) * 5 * (1 - Math.abs(k - 0.5) * 2);
|
| 513 |
+
const dx = tn.x - b.x, dy = tn.y - b.y, L = Math.hypot(dx, dy) || 1;
|
| 514 |
+
const x = b.x + dx * k - dy / L * w, y = b.y + dy * k + dx / L * w, r = 9 - k * 2;
|
| 515 |
+
ell(c, '#24082c', x, y, r + 2, r + 2); ell(c, i % 2 ? '#7a2f8f' : '#9a45ad', x, y, r, r);
|
| 516 |
+
}
|
| 517 |
+
ell(c, '#24082c', tn.x, tn.y, tn.r + 2, tn.r + 2); ell(c, glow ? '#e88aff' : '#a24bb8', tn.x, tn.y, tn.r, tn.r); ell(c, '#d47ad8', tn.x - 4, tn.y - 4, 4, 3);
|
| 518 |
+
c.fillStyle = '#f4efe6'; for (let i = 0; i < 4; i++) { const a = i * Math.PI / 2 + t * 0.03; c.fillRect(tn.x + Math.cos(a) * (tn.r + 1) - 1, tn.y + Math.sin(a) * (tn.r + 1) - 1, 3, 3); }
|
| 519 |
+
}
|
| 520 |
+
function drawLaserBall(c, x, y, r, t) {
|
| 521 |
+
const gr = c.createRadialGradient(x, y, 2, x, y, r + 10);
|
| 522 |
+
gr.addColorStop(0, '#ffffff'); gr.addColorStop(0.45, '#9ff4ff'); gr.addColorStop(0.75, 'rgba(80,190,255,0.6)'); gr.addColorStop(1, 'rgba(80,190,255,0)');
|
| 523 |
+
c.fillStyle = gr; c.beginPath(); c.arc(x, y, r + 10, 0, TAU); c.fill();
|
| 524 |
+
c.strokeStyle = '#ffffff'; c.lineWidth = 2;
|
| 525 |
+
for (let i = 0; i < 4; i++) { const a = t * 0.25 + i * Math.PI / 2; c.beginPath(); c.moveTo(x + Math.cos(a) * (r - 4), y + Math.sin(a) * (r - 4)); c.lineTo(x + Math.cos(a) * (r + 6), y + Math.sin(a) * (r + 6)); c.stroke(); }
|
| 526 |
+
}
|
| 527 |
+
function drawShuriken(c, x, y, r, a) {
|
| 528 |
+
c.save(); c.translate(x, y); c.rotate(a);
|
| 529 |
+
c.fillStyle = '#14161c'; starPath(c, 0, 0, r + 2, r * 0.35 + 2, 4, 0); c.fill();
|
| 530 |
+
c.fillStyle = '#c0c8d4'; starPath(c, 0, 0, r, r * 0.35, 4, 0); c.fill();
|
| 531 |
+
c.fillStyle = '#5a6270'; c.fillRect(-2, -2, 4, 4);
|
| 532 |
+
c.restore();
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
function drawGround(c, g) {
|
| 536 |
+
const t = g.t, b = g.boss;
|
| 537 |
+
for (const tile of g.tiles) { // Grand Slime room: Slow (down arrows) / Boost (up arrows) tiles
|
| 538 |
+
const slow = tile.kind === 'slow';
|
| 539 |
+
c.fillStyle = slow ? 'rgba(90,60,140,0.55)' : 'rgba(40,140,200,0.5)'; c.fillRect(tile.x + 2, tile.y + 2, tile.w - 4, tile.h - 4);
|
| 540 |
+
c.strokeStyle = slow ? '#b08aff' : '#7ad8ff'; c.lineWidth = 2; c.strokeRect(tile.x + 3, tile.y + 3, tile.w - 6, tile.h - 6);
|
| 541 |
+
c.fillStyle = slow ? '#d8c4ff' : '#c8f4ff';
|
| 542 |
+
for (let i = 0; i < 2; i++) for (let j = 0; j < 2; j++) {
|
| 543 |
+
const x = tile.x + 12 + i * 24, y = tile.y + 12 + j * 24, s = slow ? 1 : -1, o = ((t * 0.5) % 8) * s;
|
| 544 |
+
poly(c, [[x - 6, y - 3 * s + o * 0.3], [x + 6, y - 3 * s + o * 0.3], [x, y + 5 * s + o * 0.3]]);
|
| 545 |
+
}
|
| 546 |
+
}
|
| 547 |
+
for (const pool of g.pools) {
|
| 548 |
+
const k = Math.min(1, pool.life / 30), purple = pool.purple;
|
| 549 |
+
if (pool.form > 0) { // forming: harmless; the dashed ring is the exact pool radius it will have
|
| 550 |
+
c.save(); c.globalAlpha = 0.85; c.strokeStyle = purple ? '#d48aff' : '#a8ff6a'; c.lineWidth = 2; c.setLineDash([5, 4]);
|
| 551 |
+
c.beginPath(); c.arc(pool.x, pool.y, pool.r, 0, TAU); c.stroke(); c.restore();
|
| 552 |
+
c.globalAlpha = 0.25 * (1 - pool.form / 24); ell(c, purple ? '#8a3ad0' : '#4ec23a', pool.x, pool.y, pool.r, pool.r); c.globalAlpha = 1;
|
| 553 |
+
continue;
|
| 554 |
+
}
|
| 555 |
+
c.globalAlpha = 0.5 * k; ell(c, purple ? '#7a2ac0' : '#4ec23a', pool.x, pool.y, pool.r, pool.r);
|
| 556 |
+
c.globalAlpha = 0.6 * k; c.strokeStyle = purple ? '#d48aff' : '#a8ff6a'; c.lineWidth = 2; c.beginPath(); c.arc(pool.x, pool.y, pool.r - 1, 0, TAU); c.stroke();
|
| 557 |
+
for (let i = 0; i < 6; i++) { const ph = (t * 0.04 + hash(i, pool.x | 0)) % 1, a = hash(i + 4, pool.y | 0) * TAU, d = hash(i, 9) * pool.r * 0.7; ell(c, purple ? '#f0c8ff' : '#c8ff9a', pool.x + Math.cos(a) * d, pool.y + Math.sin(a) * d - ph * 6, 2 + ph * 2, 2 + ph * 2); }
|
| 558 |
+
c.globalAlpha = 1;
|
| 559 |
+
}
|
| 560 |
+
// Grand Slime swell: the growing ring reaches the exact explosion radius when it bursts
|
| 561 |
+
if (b.kind === 'grand_slime' && b.boom > 0) {
|
| 562 |
+
const k = 1 - b.boom / M.SLIME_SWELL;
|
| 563 |
+
c.fillStyle = 'rgba(255,60,80,' + (0.10 + 0.22 * k) + ')'; c.beginPath(); c.arc(b.x, b.y, M.SLIME_BLAST * k, 0, TAU); c.fill();
|
| 564 |
+
c.strokeStyle = 'rgba(255,90,110,0.9)'; c.lineWidth = 2; c.beginPath(); c.arc(b.x, b.y, M.SLIME_BLAST, 0, TAU); c.stroke();
|
| 565 |
+
}
|
| 566 |
+
// Sandworm: shockwave rings (expanding, hit band drawn) and the burrow / surface warning radius
|
| 567 |
+
for (const q of g.quakes) {
|
| 568 |
+
const k = Math.min(1, q.age / q.total);
|
| 569 |
+
c.save(); c.globalAlpha = 1 - Math.max(0, (q.age - q.total) / 6); c.fillStyle = 'rgba(255,150,80,0.28)'; c.beginPath(); c.arc(q.x, q.y, q.rc, 0, TAU); c.fill();
|
| 570 |
+
c.strokeStyle = '#ffb06a'; c.lineWidth = 6; c.beginPath(); c.arc(q.x, q.y, q.rc, 0, TAU); c.stroke();
|
| 571 |
+
c.strokeStyle = '#7a3a14'; c.lineWidth = 2; c.beginPath(); c.arc(q.x, q.y, q.rc + 4, 0, TAU); c.stroke(); c.restore();
|
| 572 |
+
void k;
|
| 573 |
+
}
|
| 574 |
+
if (b.kind === 'volcanic_sandworm' && (b.vars.ph === 'sink' || b.vars.ph === 'rise' || b.vars.ph === 'peek')) {
|
| 575 |
+
c.save(); c.strokeStyle = 'rgba(255,150,80,0.85)'; c.lineWidth = 2; c.setLineDash([6, 5]);
|
| 576 |
+
c.beginPath(); c.arc(b.x, b.y, M.QUAKE_R, 0, TAU); c.stroke(); c.restore();
|
| 577 |
+
}
|
| 578 |
+
// Varkolyn laser: during the charge the whole swept arc is drawn (start edge bright, sweep direction arrow);
|
| 579 |
+
// while firing, the beam itself and the part of the arc still to be swept
|
| 580 |
+
if (b.atk === 'laser' && b.vars.a0 !== undefined) {
|
| 581 |
+
const v = b.vars, oy = b.y - M.VARK_EYE, end = v.a0 + v.dir * M.LASER_ARC, cur = v.on ? v.a : v.a0;
|
| 582 |
+
c.save(); c.globalAlpha = v.on ? 0.16 : 0.14 + 0.08 * Math.sin(t * 0.7); c.fillStyle = '#ff3a6a';
|
| 583 |
+
c.beginPath(); c.moveTo(b.x, oy); c.arc(b.x, oy, 1100, Math.min(cur, end), Math.max(cur, end)); c.closePath(); c.fill();
|
| 584 |
+
c.globalAlpha = 0.9; c.strokeStyle = v.on ? '#ffffff' : '#ff8aa8'; c.lineWidth = v.on ? M.LASER_W * 2 : 2;
|
| 585 |
+
if (!v.on) c.setLineDash([10, 6]);
|
| 586 |
+
c.beginPath(); c.moveTo(b.x, oy); c.lineTo(b.x + Math.cos(cur) * 1100, oy + Math.sin(cur) * 1100); c.stroke();
|
| 587 |
+
if (v.on) { c.strokeStyle = '#ff3a8a'; c.lineWidth = M.LASER_W * 2 + 6; c.globalAlpha = 0.35; c.stroke(); }
|
| 588 |
+
c.restore();
|
| 589 |
+
}
|
| 590 |
+
for (const m of g.meteors) {
|
| 591 |
+
const k = 1 - m.fall / m.total;
|
| 592 |
+
c.fillStyle = 'rgba(255,60,30,' + (0.12 + 0.22 * k) + ')'; c.beginPath(); c.arc(m.x, m.y, m.r * k, 0, TAU); c.fill();
|
| 593 |
+
c.strokeStyle = 'rgba(255,90,50,0.9)'; c.lineWidth = 2; c.beginPath(); c.arc(m.x, m.y, m.r, 0, TAU); c.stroke();
|
| 594 |
+
}
|
| 595 |
+
for (const L of g.lines) {
|
| 596 |
+
// upcoming nodes drawn at their real hit radius (11-02: 4 px dots hid an 18 px hazard), and only up to the
|
| 597 |
+
// first wall/obstacle, where game.js stops the line
|
| 598 |
+
const ca = Math.cos(L.a), sa = Math.sin(L.a);
|
| 599 |
+
c.lineWidth = 1.5;
|
| 600 |
+
for (let k = L.k + 1; k <= L.n; k++) {
|
| 601 |
+
const d = L.start + k * L.gap, x = L.x + ca * d, y = L.y + sa * d;
|
| 602 |
+
if (g.solidAt(x, y, 4, false)) break;
|
| 603 |
+
const near = k - L.k <= 2;
|
| 604 |
+
c.strokeStyle = near ? 'rgba(220,240,255,0.75)' : 'rgba(220,240,255,0.32)';
|
| 605 |
+
c.beginPath(); c.arc(x, y, M.NODE_R, 0, TAU); c.stroke();
|
| 606 |
+
c.fillStyle = near ? 'rgba(200,235,255,0.18)' : 'rgba(200,235,255,0.07)'; c.fill();
|
| 607 |
+
}
|
| 608 |
+
}
|
| 609 |
+
for (const n of g.nodes) {
|
| 610 |
+
const k = n.life / 14;
|
| 611 |
+
c.globalAlpha = Math.min(1, k * 1.6);
|
| 612 |
+
ell(c, 'rgba(190,230,255,0.35)', n.x, n.y, n.r, n.r);
|
| 613 |
+
for (let i = 0; i < 5; i++) {
|
| 614 |
+
const a = i * TAU / 5 + n.x * 0.1, sx = n.x + Math.cos(a) * n.r * 0.55, sy = n.y + Math.sin(a) * n.r * 0.55, hgt = 8 + 6 * k;
|
| 615 |
+
c.fillStyle = '#2a4a66'; poly(c, [[sx - 5, sy + 2], [sx, sy - hgt - 2], [sx + 5, sy + 2]]);
|
| 616 |
+
c.fillStyle = i % 2 ? '#dff4ff' : '#a8dcf6'; poly(c, [[sx - 3, sy], [sx, sy - hgt], [sx + 3, sy]]);
|
| 617 |
+
}
|
| 618 |
+
c.globalAlpha = 1;
|
| 619 |
+
}
|
| 620 |
+
if (b.atk === 'charge' && (b.vars.ph === 'aim' || b.vars.ph === 'dash')) {
|
| 621 |
+
// telegraph band = the exact swept ram capsule (game.js M.ramBand), centred on the capsule middle and
|
| 622 |
+
// starting behind the boss by the capsule's rear extent, so the drawn band always contains the hit area.
|
| 623 |
+
// Tracking: faint + dashed edges; locked (last M.RAM_LOCK ticks): bright solid edges; dash: faint trail.
|
| 624 |
+
const a = b.vars.a, ca = Math.cos(a), sa = Math.sin(a), h = M.bosses[b.kind].hurt, half = M.ramBand(b.kind, a), cy = b.y + (h[0] + h[1]) / 2;
|
| 625 |
+
const back = h[2] + M.RAM_PAD + (h[1] - h[0]) / 2 * Math.abs(sa), locked = b.vars.ph === 'aim' && b.vars.lock, dash = b.vars.ph === 'dash';
|
| 626 |
+
const L = M.ramReach(g) + back; // the band ends where this dash really ends (wall / dash length)
|
| 627 |
+
c.save(); c.translate(b.x, cy); c.rotate(a); c.fillStyle = '#ff3a2a';
|
| 628 |
+
c.globalAlpha = dash ? 0.14 : locked ? 0.30 + 0.10 * Math.sin(t * 1.3) : 0.13 + 0.05 * Math.sin(t * 0.6);
|
| 629 |
+
c.fillRect(-back, -half, L + back, half * 2);
|
| 630 |
+
if (locked) { c.globalAlpha = 0.95; c.fillStyle = '#ffd0c0'; c.fillRect(-back, -half, L + back, 3); c.fillRect(-back, half - 3, L + back, 3); }
|
| 631 |
+
else if (!dash) { c.globalAlpha = 0.7; for (let x = -back; x < L; x += 24) { c.fillRect(x, -half, 12, 2); c.fillRect(x, half - 2, 12, 2); } }
|
| 632 |
+
c.restore();
|
| 633 |
+
if (!dash) {
|
| 634 |
+
c.fillStyle = locked ? 'rgba(255,220,200,0.95)' : 'rgba(255,90,60,0.7)';
|
| 635 |
+
for (let i = 1; i <= 4; i++) { const d = 40 + i * 34 + (t % 12) * 2; if (d > L) break; const x = b.x + ca * d, y = b.y + sa * d; poly(c, [[x + ca * 10, y + sa * 10], [x - sa * 10, y + ca * 10], [x + sa * 10, y - ca * 10]]); }
|
| 636 |
+
}
|
| 637 |
+
}
|
| 638 |
+
if (b.atk === 'pull' && b.vars.on) {
|
| 639 |
+
c.strokeStyle = 'rgba(200,120,255,0.55)'; c.lineWidth = 3;
|
| 640 |
+
for (let i = 0; i < 3; i++) { const r = 60 + ((300 - (t * 4 + i * 100) % 300)); c.beginPath(); c.arc(b.x, b.y, r, 0, TAU); c.stroke(); }
|
| 641 |
+
}
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
function drawProjectiles(c, g) {
|
| 645 |
+
const t = g.t;
|
| 646 |
+
for (const o of g.orbs) {
|
| 647 |
+
c.fillStyle = 'rgba(110,220,255,0.35)'; c.beginPath(); c.arc(o.x, o.y, o.r + 6, 0, TAU); c.fill();
|
| 648 |
+
ell(c, '#10203a', o.x, o.y, o.r + 2, o.r + 2); ell(c, '#5ad0ff', o.x, o.y, o.r, o.r); ell(c, '#e0faff', o.x - 2, o.y - 2, o.r * 0.45, o.r * 0.45);
|
| 649 |
+
}
|
| 650 |
+
for (const q of g.turrets) drawShuriken(c, q.x, q.y, q.r, t * 0.2);
|
| 651 |
+
for (const q of g.carriers) drawShuriken(c, q.x, q.y, 11, t * 0.4);
|
| 652 |
+
for (const ball of g.balls) {
|
| 653 |
+
// blast-radius telegraph (11-02): the burst hurts within M.BLAST_R of the ball (body overlap), wider than its glow
|
| 654 |
+
c.save(); c.globalAlpha = 0.45 + 0.15 * Math.sin(t * 0.5); c.strokeStyle = '#9ff4ff'; c.lineWidth = 2; c.setLineDash([6, 5]);
|
| 655 |
+
c.beginPath(); c.arc(ball.x, ball.y, M.BLAST_R, 0, TAU); c.stroke(); c.restore();
|
| 656 |
+
drawLaserBall(c, ball.x, ball.y, ball.r, t);
|
| 657 |
+
}
|
| 658 |
+
for (const st of g.stars) { // Sandworm star turret: spinning cross, its four firing lanes drawn faintly
|
| 659 |
+
const lanes = st.shots > 0;
|
| 660 |
+
if (lanes) { c.save(); c.globalAlpha = 0.18; c.strokeStyle = '#ffd04a'; c.lineWidth = 6; for (let i = 0; i < 4; i++) { const a = st.a0 + i * Math.PI / 2; c.beginPath(); c.moveTo(st.x, st.y); c.lineTo(st.x + Math.cos(a) * 900, st.y + Math.sin(a) * 900); c.stroke(); } c.restore(); }
|
| 661 |
+
c.save(); c.translate(st.x, st.y); c.rotate(t * 0.15);
|
| 662 |
+
c.fillStyle = '#2a1406'; starPath(c, 0, 0, st.r + 3, st.r * 0.45 + 2, 4, 0); c.fill();
|
| 663 |
+
c.fillStyle = st.kind === 'long' ? '#ffd04a' : '#ff8a2a'; starPath(c, 0, 0, st.r, st.r * 0.45, 4, 0); c.fill();
|
| 664 |
+
c.restore();
|
| 665 |
+
}
|
| 666 |
+
for (const s of g.shots) {
|
| 667 |
+
const a = Math.atan2(s.vy, s.vx);
|
| 668 |
+
capsule(c, s.x, s.y, a, s.crit ? 14 : 11, s.crit ? 7 : 5, s.crit ? ['#4a1a00', '#ff9a2a', '#fff4c0'] : ['#3a2a00', '#ffd23a', '#fff8d0']);
|
| 669 |
+
}
|
| 670 |
+
for (const q of g.bullets) {
|
| 671 |
+
if (q.kind === 'beam') { capsule(c, q.x, q.y, Math.atan2(q.vy, q.vx), 18, 7, ['#0f3a12', '#6dff4a', '#e0ffd0']); continue; }
|
| 672 |
+
if (q.kind === 'rail') { capsule(c, q.x, q.y, Math.atan2(q.vy, q.vx), 22, 9, ['#2a0f3a', '#c86aff', '#f6dcff']); continue; }
|
| 673 |
+
if (q.kind === 'long') { capsule(c, q.x, q.y, Math.atan2(q.vy, q.vx), 16, 6, ['#3a1a04', '#ffb03a', '#fff0c0']); continue; }
|
| 674 |
+
if (q.blast) { // shells / big bullets: the blast radius rides with the projectile (== the explosion's hit radius)
|
| 675 |
+
c.save(); c.globalAlpha = q.kind === 'shell' ? 0.7 : 0.35; c.strokeStyle = q.kind === 'shell' ? '#ff8a3a' : '#ff6a4a'; c.lineWidth = q.kind === 'shell' ? 2 : 1; c.setLineDash([5, 4]);
|
| 676 |
+
c.beginPath(); c.arc(q.x, q.y, q.blast, 0, TAU); c.stroke(); c.restore();
|
| 677 |
+
}
|
| 678 |
+
if (q.kind === 'homing' && q.hover > 0) { c.globalAlpha = 0.5 + 0.5 * Math.sin(t * 0.5); }
|
| 679 |
+
const s = bulletSprite(q.kind, Math.round(q.r));
|
| 680 |
+
c.drawImage(s.c, Math.round(q.x - s.m), Math.round(q.y - s.m));
|
| 681 |
+
c.globalAlpha = 1;
|
| 682 |
+
}
|
| 683 |
+
for (const m of g.meteors) {
|
| 684 |
+
const h = m.fall * 5, x = m.x + m.fall * 1.5, y = m.y - h;
|
| 685 |
+
c.fillStyle = 'rgba(255,140,40,0.45)'; c.beginPath(); c.moveTo(x - 7, y); c.lineTo(x + 18, y - 40); c.lineTo(x + 7, y); c.fill();
|
| 686 |
+
ell(c, '#2a1206', x, y, 11, 11); ell(c, '#b4552a', x, y, 9, 9); ell(c, '#ffb04a', x - 2, y - 2, 4, 4);
|
| 687 |
+
}
|
| 688 |
+
for (const q of g.pickups) {
|
| 689 |
+
const s = ICONS.orb(), bob = Math.sin((t + q.x) * 0.15) * 2;
|
| 690 |
+
c.fillStyle = 'rgba(80,170,255,0.3)'; c.beginPath(); c.arc(q.x, q.y + bob - 6, 8, 0, TAU); c.fill();
|
| 691 |
+
blit(c, s, q.x, q.y + bob + 2, 2);
|
| 692 |
+
}
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
function drawFx(c, g) {
|
| 696 |
+
const t = g.t;
|
| 697 |
+
for (const f of g.fx) {
|
| 698 |
+
const age = t - f.t;
|
| 699 |
+
if (f.k === 'spark' && age < 8) {
|
| 700 |
+
c.strokeStyle = f.c ? '#bfe8ff' : '#fff2a0'; c.lineWidth = 2; const r = 3 + age * 1.5;
|
| 701 |
+
for (let i = 0; i < 4; i++) { const a = i * Math.PI / 2 + Math.PI / 4; c.beginPath(); c.moveTo(f.x + Math.cos(a) * r * 0.4, f.y + Math.sin(a) * r * 0.4); c.lineTo(f.x + Math.cos(a) * r, f.y + Math.sin(a) * r); c.stroke(); }
|
| 702 |
+
} else if (f.k === 'boom' && age < 18) {
|
| 703 |
+
const k = age / 18;
|
| 704 |
+
c.fillStyle = 'rgba(255,240,200,' + (0.6 * (1 - k)) + ')'; c.beginPath(); c.arc(f.x, f.y, f.r * (0.4 + k * 0.6), 0, TAU); c.fill();
|
| 705 |
+
c.strokeStyle = 'rgba(255,140,60,' + (1 - k) + ')'; c.lineWidth = 3; c.beginPath(); c.arc(f.x, f.y, f.r * (0.6 + k * 0.6), 0, TAU); c.stroke();
|
| 706 |
+
} else if (f.k === 'debris' && age < 22) {
|
| 707 |
+
for (let i = 0; i < 7; i++) { const a = hash(i, f.x | 0) * TAU, v = 1.5 + hash(f.y | 0, i) * 2.5; c.fillStyle = i % 2 ? '#aa763c' : '#7a4f24'; c.fillRect(f.x + Math.cos(a) * v * age - 2, f.y + Math.sin(a) * v * age + age * age * 0.05 - 2, 4, 3); }
|
| 708 |
+
} else if (f.k === 'num' && age < 40) {
|
| 709 |
+
c.globalAlpha = Math.min(1, (40 - age) / 14);
|
| 710 |
+
txt(c, String(f.v), f.x, f.y - age * 0.8, f.crit ? 19 : 14, f.crit ? '#ffd23a' : '#ffffff', 'center');
|
| 711 |
+
c.globalAlpha = 1;
|
| 712 |
+
} else if (f.k === 'pnum' && age < 36) {
|
| 713 |
+
c.globalAlpha = Math.min(1, (36 - age) / 12);
|
| 714 |
+
txt(c, '-' + f.v, f.x, f.y - age * 0.7, 14, f.s ? '#8aff6a' : '#ff5a5a', 'center');
|
| 715 |
+
c.globalAlpha = 1;
|
| 716 |
+
} else if (f.k === 'txt' && age < 44) {
|
| 717 |
+
c.globalAlpha = Math.min(1, (44 - age) / 14);
|
| 718 |
+
txt(c, f.s, f.x, f.y - age * 0.5, f.big ? 20 : 13, f.big ? '#ff6a4a' : '#d8dde4', 'center');
|
| 719 |
+
c.globalAlpha = 1;
|
| 720 |
+
}
|
| 721 |
+
}
|
| 722 |
+
const b = g.boss;
|
| 723 |
+
if (b.state === 'dying') for (let i = 0; i < 3; i++) {
|
| 724 |
+
const h1 = hash(Math.floor(t / 6) * 3 + i, 7), h2 = hash(i, Math.floor(t / 6)), x = b.x + (h1 - 0.5) * b.r * 2.4, y = b.y + (h2 - 0.6) * b.r * 2.4, k = (t % 6) / 6;
|
| 725 |
+
c.fillStyle = 'rgba(255,220,140,' + (0.8 - k * 0.6) + ')'; c.beginPath(); c.arc(x, y, 6 + k * 10, 0, TAU); c.fill();
|
| 726 |
+
}
|
| 727 |
+
}
|
| 728 |
+
|
| 729 |
+
function drawReticle(c, g) {
|
| 730 |
+
const p = g.player;
|
| 731 |
+
if (p.dead > 0 || g.outcome) return;
|
| 732 |
+
const x = Math.round(p.aimX), y = Math.round(p.aimY), manual = p.manual > 0;
|
| 733 |
+
c.strokeStyle = '#0b0a10'; c.lineWidth = 4;
|
| 734 |
+
const arms = () => { c.beginPath(); c.moveTo(x - 9, y); c.lineTo(x - 3, y); c.moveTo(x + 3, y); c.lineTo(x + 9, y); c.moveTo(x, y - 9); c.lineTo(x, y - 3); c.moveTo(x, y + 3); c.lineTo(x, y + 9); c.stroke(); };
|
| 735 |
+
arms(); c.strokeStyle = manual ? '#ffffff' : '#ffd23a'; c.lineWidth = 2; arms();
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
// ---------- HUD ----------
|
| 739 |
+
function drawHud(c, g) {
|
| 740 |
+
const p = g.player, b = g.boss, t = g.t, w = M.weapons[M.slots[p.slot]];
|
| 741 |
+
panel(c, 6, 4, 190, 60);
|
| 742 |
+
const rows = [['hp', p.hp, p.maxHp, '#e84848', '#4a1c22'], ['armor', p.armor, p.maxArmor, '#aab6c4', '#2c3240'], ['energy', p.energy, p.maxEnergy, '#3f9cff', '#1a2848']];
|
| 743 |
+
rows.forEach(([icon, v, max, fg, bg], i) => {
|
| 744 |
+
const y = 10 + i * 17;
|
| 745 |
+
blit(c, ICONS[icon](), 20, y + 15, 2);
|
| 746 |
+
bar(c, 34, y + 2, 120, 12, v, max, fg, bg, v + '/' + max);
|
| 747 |
+
});
|
| 748 |
+
if (p.armor < p.maxArmor && p.sinceHit < 180 && p.dead === 0) { c.fillStyle = 'rgba(170,182,196,0.6)'; c.fillRect(160, 30, Math.round(30 * p.sinceHit / 180), 3); }
|
| 749 |
+
if (p.poison > 0) { txt(c, 'Poisoned', 160, 28, 11, '#8aff6a'); }
|
| 750 |
+
// boss bar
|
| 751 |
+
const name = M.cases.find(q => q.id === g.id), bw = 330, bx = 427 - bw / 2;
|
| 752 |
+
panel(c, bx - 12, 4, bw + 24, 38);
|
| 753 |
+
txt(c, name.name + ' · ' + name.en, bx, 19, 12, '#f2e6c8');
|
| 754 |
+
txt(c, b.enraged ? 'Phase 2: Enraged' : 'Phase 1', bx + bw, 19, 11, b.enraged ? '#ff7a5a' : '#b8c0cc', 'right');
|
| 755 |
+
const pulse = b.enraged ? (Math.floor(t / 10) % 2 ? '#ff5a3a' : '#e83a2a') : '#d83a3a';
|
| 756 |
+
bar(c, bx, 24, bw, 11, b.hp, b.maxHp, pulse, '#3a1414', Math.ceil(b.hp) + ' / ' + b.maxHp);
|
| 757 |
+
c.fillStyle = '#f2e6c8'; c.fillRect(bx + bw / 2 - 1, 23, 2, 13);
|
| 758 |
+
const status = b.inv ? 'Invulnerable' : b.under ? 'Burrowed: cannot attack' : b.shield > 0 ? 'Poison-pool shield: immune' : b.boom > 0 ? 'Expanding: about to explode' : '';
|
| 759 |
+
if (status) txt(c, status, bx + bw / 2, 51, 11, b.boom > 0 ? '#ff8a8a' : '#d8dde4', 'center');
|
| 760 |
+
// doc (Grand Slime): enraged charge bar fills after 15 hits
|
| 761 |
+
if (b.kind === 'grand_slime' && b.enraged && b.boom === 0) { c.fillStyle = '#06050a'; c.fillRect(bx - 1, 37, bw + 2, 4); c.fillStyle = '#ff7a3a'; c.fillRect(bx, 38, Math.round(bw * b.charge / M.SLIME_HITS), 2); }
|
| 762 |
+
// timer + public tier + native clock (2026-11-02: every HUD shows the native Hz)
|
| 763 |
+
panel(c, 700, 4, 148, 38);
|
| 764 |
+
const sec = t / 60, mm = Math.floor(sec / 60), ss = (sec % 60).toFixed(1).padStart(4, '0'), lim = M.maxSeconds;
|
| 765 |
+
txt(c, '⏱ ' + mm + ':' + ss, 712, 23, 14, '#f2f2f2');
|
| 766 |
+
txt(c, '/ ' + Math.floor(lim / 60) + ':' + String(lim % 60).padStart(2, '0'), 840, 23, 10, '#a8b0bc', 'right', 'normal');
|
| 767 |
+
const tier = M.tierOf(g.d), TL = { easy: ['Easy EASY', '#7fe08a'], normal: ['Normal NORMAL', '#ffd23a'], hard: ['Hard HARD', '#ff6a4a'] }[tier] || ['Custom d=' + g.d.toFixed(2), '#c8d0dc'];
|
| 768 |
+
txt(c, TL[0], 712, 37, 10, TL[1], 'left');
|
| 769 |
+
txt(c, M.hz + 'Hz', 840, 37, 10, '#9fd8ff', 'right');
|
| 770 |
+
// bottom strip: hints, weapon card, skill
|
| 771 |
+
txt(c, 'WASD Move · J Attack · K Duplicate Weapon · Q Switch Weapon · Mouse aim', 12, 472, 11, '#c8d0c0', 'left', 'normal');
|
| 772 |
+
panel(c, 560, 452, 234, 27);
|
| 773 |
+
const art = WEAPON_ART[M.slots[p.slot]]();
|
| 774 |
+
c.drawImage(art.c, 572, 465 - art.h, art.w * 2, art.h * 2);
|
| 775 |
+
txt(c, w.name, 624, 470, 12, '#f2e6c8');
|
| 776 |
+
const lowE = w.cost > p.energy;
|
| 777 |
+
txt(c, '⚡' + w.cost, 712, 470, 12, lowE ? (Math.floor(t / 15) % 2 ? '#ff5a5a' : '#ffffff') : '#7ac0ff');
|
| 778 |
+
for (let i = 0; i < M.slots.length; i++) { c.fillStyle = i === p.slot ? '#ffd23a' : '#4a4658'; c.fillRect(746 + i * 13, 461, 9, 9); c.strokeStyle = '#06050a'; c.lineWidth = 1; c.strokeRect(746.5 + i * 13, 461.5, 9, 9); }
|
| 779 |
+
// skill button (Dual Wield)
|
| 780 |
+
const sx = 822, sy = 452, r = 14;
|
| 781 |
+
c.fillStyle = '#06050a'; c.beginPath(); c.arc(sx, sy, r + 3, 0, TAU); c.fill();
|
| 782 |
+
c.fillStyle = p.dual > 0 ? '#5a4410' : '#2a3a5a'; c.beginPath(); c.arc(sx, sy, r, 0, TAU); c.fill();
|
| 783 |
+
const pistol = WEAPON_ART.pistol();
|
| 784 |
+
c.save(); c.translate(sx, sy); c.rotate(-0.5); c.drawImage(pistol.c, -11, -9, pistol.w * 2, pistol.h * 2); c.rotate(1.0); c.drawImage(pistol.c, -11, -2, pistol.w * 2, pistol.h * 2); c.restore();
|
| 785 |
+
if (p.dual > 0) {
|
| 786 |
+
c.strokeStyle = '#ffd23a'; c.lineWidth = 3; c.beginPath(); c.arc(sx, sy, r + 1, -Math.PI / 2, -Math.PI / 2 + TAU * p.dual / 300); c.stroke();
|
| 787 |
+
txt(c, (p.dual / 60).toFixed(1), sx, sy + 5, 12, '#ffd23a', 'center');
|
| 788 |
+
} else if (p.skillCd > 0) {
|
| 789 |
+
c.fillStyle = 'rgba(0,0,0,0.6)'; c.beginPath(); c.moveTo(sx, sy); c.arc(sx, sy, r, -Math.PI / 2, -Math.PI / 2 + TAU * p.skillCd / 600); c.closePath(); c.fill();
|
| 790 |
+
txt(c, Math.ceil(p.skillCd / 60) + '', sx, sy + 5, 13, '#ffffff', 'center');
|
| 791 |
+
} else { c.strokeStyle = 'rgba(140,200,255,' + (0.5 + 0.4 * Math.sin(t * 0.2)) + ')'; c.lineWidth = 2; c.beginPath(); c.arc(sx, sy, r + 1, 0, TAU); c.stroke(); }
|
| 792 |
+
txt(c, 'K', sx + 12, sy + 16, 9, '#c8d0dc', 'center');
|
| 793 |
+
}
|
| 794 |
+
function drawResult(c, g) {
|
| 795 |
+
if (!g.outcome) return;
|
| 796 |
+
const map = { win: ['Victory: Boss Defeated', 'BOSS DEFEATED', '#ffd23a'], loss: ['Defeat: Gunner Down', 'GUNNER DOWN', '#ff5a4a'], timeout: ['Time up', 'TIME UP', '#d8dde4'] }[g.outcome];
|
| 797 |
+
const tier = { easy: 'Easy EASY', normal: 'Normal NORMAL', hard: 'Hard HARD' }[M.tierOf(g.d)] || 'd=' + g.d.toFixed(2);
|
| 798 |
+
// upper third (11-02): the shared play-page overlay box (_native/shell.js) sits at the stage centre and hid the
|
| 799 |
+
// second line of the old centred banner in the result screenshots
|
| 800 |
+
c.fillStyle = 'rgba(8,8,14,0.62)'; c.fillRect(0, 112, 854, 86);
|
| 801 |
+
c.fillStyle = map[2]; c.fillRect(0, 112, 854, 2); c.fillRect(0, 196, 854, 2);
|
| 802 |
+
txt(c, map[0], 427, 154, 30, map[2], 'center');
|
| 803 |
+
txt(c, map[1] + ' · ' + (g.t / 60).toFixed(2) + ' s · ' + tier + ' · Health ' + g.player.hp + '/' + g.player.maxHp, 427, 182, 13, '#e8e8f0', 'center', 'normal');
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
// Build every sprite variant once on the first frame (round 3 found an 81 ms hitch at the
|
| 807 |
+
// enrage tick when the enraged boss sprite and new bullet kinds were first painted mid-fight).
|
| 808 |
+
let warmed = false;
|
| 809 |
+
function warm() {
|
| 810 |
+
warmed = true;
|
| 811 |
+
for (const kind of ['goblin_priest', 'christmas_treant', 'devils_snare', 'grand_slime', 'varkolyn_leader', 'volcanic_sandworm']) { bossSprite(kind, false); bossSprite(kind, true); }
|
| 812 |
+
for (const f of [0, 1]) { minionSprite('slime', f); minionSprite('tentacle', f); }
|
| 813 |
+
knight(0); knight(1);
|
| 814 |
+
for (const k of Object.keys(PROPS)) { if (k === 'crate' || k === 'smile' || k === 'wcrate') { PROPS[k](0); PROPS[k](1); } else PROPS[k](); }
|
| 815 |
+
for (const k of Object.keys(WEAPON_ART)) WEAPON_ART[k]();
|
| 816 |
+
for (const k of Object.keys(ICONS)) ICONS[k]();
|
| 817 |
+
for (const [kind, r] of [['small', 4], ['small', 5], ['star', 7], ['cross', 9], ['bubble', 7], ['bubble', 8], ['homing', 6], ['beam', 5], ['rail', 6],
|
| 818 |
+
['slam', 5], ['diamond', 6], ['petal', 5], ['vorb', 13], ['shell', 11], ['big', 8], ['bouncy', 5]]) bulletSprite(kind, r);
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
M.draw = function (g, c) {
|
| 822 |
+
if (!warmed) warm();
|
| 823 |
+
c.save(); c.setTransform(1, 0, 0, 1, 0, 0); c.globalAlpha = 1; c.globalCompositeOperation = 'source-over'; c.imageSmoothingEnabled = false;
|
| 824 |
+
c.drawImage(background(g.kind), 0, 0);
|
| 825 |
+
const age = g.t - g.shake.t, sh = age >= 0 && age < 8 ? g.shake.a * (1 - age / 8) : 0;
|
| 826 |
+
const ox = Math.round(Math.sin(g.t * 12.9898) * sh), oy = Math.round(Math.cos(g.t * 78.233) * sh);
|
| 827 |
+
c.save(); c.translate(ox, oy);
|
| 828 |
+
c.beginPath(); c.rect(R.x0 - 12, 20, R.x1 - R.x0 + 24, R.y1 - 12); c.clip();
|
| 829 |
+
drawGround(c, g);
|
| 830 |
+
const items = [];
|
| 831 |
+
for (const o of g.obstacles) items.push([o.y + o.h, () => {
|
| 832 |
+
const cx = o.x + o.w / 2, by = o.y + o.h;
|
| 833 |
+
if (o.kind === 'torch') { blit(c, PROPS.torch(), cx, by + 2, 2); const fl = Math.sin(g.t * 0.6 + o.y) * 1.5; ell(c, 'rgba(255,170,60,0.35)', cx, by - 26, 10, 10); ell(c, '#ff8a2a', cx, by - 25 + fl * 0.3, 4, 6); ell(c, '#ffe08a', cx, by - 24, 2, 3); }
|
| 834 |
+
else { shadow(c, cx, by - 2, o.w / 2, 6); blit(c, PROPS[o.kind](), cx, by + 2, 2); }
|
| 835 |
+
}]);
|
| 836 |
+
// crate art: the Grand Slime room's boxes are smiling-face boxes (doc) and two weapon crates
|
| 837 |
+
const crateArt = g.kind === 'grand_slime' ? (cr => cr.kind === 'wcrate' ? PROPS.wcrate : PROPS.smile) : () => PROPS.crate;
|
| 838 |
+
for (const cr of g.crates) items.push([cr.y + cr.h, () => blit(c, crateArt(cr)(cr.hp < 6 ? 1 : 0), cr.x + cr.w / 2, cr.y + cr.h + 2, 2)]);
|
| 839 |
+
items.push([g.player.y + 10, () => drawKnight(c, g)]);
|
| 840 |
+
items.push([g.boss.y + g.boss.r * 0.8, () => drawBoss(c, g)]);
|
| 841 |
+
for (const m of g.minions) items.push([m.y + 8, () => drawMinions(c, { t: g.t, minions: [m] })]);
|
| 842 |
+
items.sort((a, b) => a[0] - b[0]);
|
| 843 |
+
for (const it of items) it[1]();
|
| 844 |
+
drawSwing(c, g);
|
| 845 |
+
drawProjectiles(c, g);
|
| 846 |
+
drawFx(c, g);
|
| 847 |
+
drawReticle(c, g);
|
| 848 |
+
c.restore();
|
| 849 |
+
drawHud(c, g);
|
| 850 |
+
drawResult(c, g);
|
| 851 |
+
c.restore();
|
| 852 |
+
};
|
| 853 |
+
})(typeof window === 'undefined' ? globalThis : window);
|
environments/games/web/games/soulknight_remake/game.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
environments/games/web/games/soulknight_remake/index.html
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="data:,"><title>Soul Knight: Dungeon Bosses</title><link rel="stylesheet" href="../_native/style.css"></head><body><main>
|
| 3 |
+
<header><div><h1>Soul Knight: Dungeon Bosses</h1><p>Six bosses · Armored Gunner · knight-arena@6 · 60 Hz · Easy/Normal/Hard · Recording and Replay</p></div><a href="../../index.html">Back to Game Lobby</a></header>
|
| 4 |
+
<div class="layout"><section><div class="stage"><canvas width="854" height="480" tabindex="0" aria-label="Game Screen"></canvas><div id="overlay"><div>Select a boss to start</div></div><div class="toolbar"><button id="start" class="primary">Start Challenge / Restart</button><button id="pause">Resume</button><button id="step">Step</button><button id="demo">Scripted Demo</button><button id="sample">Example Replay</button></div></div><div class="mobile"><button data-key="W">↑</button><button data-key="A">←</button><button data-key="S">↓</button><button data-key="D">→</button><button data-key="J">Attack</button><button data-key="K">Duplicate Weapon</button><button data-key="Q">Switch Weapon</button></div><p id="status" role="status"></p><div class="toolbar"><button id="export">Export Current Replay</button><button id="import">Import and Replay</button><input id="file" type="file" accept=".json,application/json"></div><p class="note">The gunner has 6 health, 5 armor, and 180 energy. Armor regenerates by 1 per second after 3 seconds without damage. Bosses enrage at half health. The blade can cut ordinary bullets, turrets, star turrets, and vortex shots, but not shockwaves, meteors, laser orbs, explosive shots, or beams. Hold the left mouse button and drag to aim manually, or double-click the screen to lock the pointer for free aim (Esc unlocks it). When the mouse is idle, auto-aim targets a visible boss. Replays save inputs and the seed for deterministic verification. The scripted demo reads internal state and emits only valid keyboard and mouse actions; it does not start RL training.</p></section>
|
| 5 |
+
<aside><div><h2>Select Challenge</h2><label for="case">Boss</label><select id="case"></select><label for="seed">Seed</label><input id="seed" type="number" min="0" max="4294967295" value="1" step="1"></div><div><label for="difficulty">Difficulty Tier (health / attack aggression / damage)</label><select id="difficulty"><option value="0.2">Easy (d=0.2)</option><option value="0.5" selected>Normal (d=0.5)</option><option value="0.8">Hard (d=0.8)</option></select><p class="note">Easy uses standard pacing and takes about 25 seconds. Normal bosses attack more often and take about one minute. Hard adds one damage to all attacks and sharply increases projectile speed; it takes about three minutes. Health is calibrated for these durations.</p><p class="note">Click the screen to enable the keyboard. Esc pauses; losing window focus also pauses. Double-click the screen to lock the mouse.</p></div><dl></dl></aside></div>
|
| 6 |
+
<footer></footer></main>
|
| 7 |
+
<script src="../_native/runtime.js"></script><script src="game.js"></script><script src="draw.js"></script><script>window.GAME_MODULE=window.SoulKnightGame;</script><script src="../_native/shell.js"></script></body></html>
|
environments/games/web/games/soulknight_remake/manifest.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "bossbench/game-manifest@1",
|
| 3 |
+
"engine": "independent",
|
| 4 |
+
"game": "soulknight_remake",
|
| 5 |
+
"module": "SoulKnightGame",
|
| 6 |
+
"title": "Soul Knight: Dungeon Bosses",
|
| 7 |
+
"dimension": "2d",
|
| 8 |
+
"native_hz": 60,
|
| 9 |
+
"max_seconds": 300,
|
| 10 |
+
"renderer": "canvas-native",
|
| 11 |
+
"rules": "knight-arena@6",
|
| 12 |
+
"cases": [
|
| 13 |
+
"soulknight/goblin_priest",
|
| 14 |
+
"soulknight/christmas_treant",
|
| 15 |
+
"soulknight/devils_snare",
|
| 16 |
+
"soulknight/grand_slime",
|
| 17 |
+
"soulknight/varkolyn_leader",
|
| 18 |
+
"soulknight/volcanic_sandworm"
|
| 19 |
+
],
|
| 20 |
+
"scripts": [
|
| 21 |
+
"_native/runtime.js",
|
| 22 |
+
"soulknight_remake/game.js",
|
| 23 |
+
"soulknight_remake/draw.js"
|
| 24 |
+
],
|
| 25 |
+
"sim_scripts": [
|
| 26 |
+
"_native/runtime.js",
|
| 27 |
+
"soulknight_remake/game.js"
|
| 28 |
+
],
|
| 29 |
+
"play_page": "web/games/soulknight_remake/index.html",
|
| 30 |
+
"scripted_controller": "SoulKnightGame.scripted(game) -> {holds:[6 key arrays], mouse:[dx,dy,dz]} (falls back to .oracle)"
|
| 31 |
+
}
|
environments/games/web/games/terraria_remake/arena.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Arena geometry, in game units (u). Origin = left wall surface / floor surface, y up.
|
| 2 |
+
// Scale: 1 u = 2 tiles = 32 px of the source game (a tile is 16 px); its 60 Hz tick is kept, so
|
| 3 |
+
// speed px/tick x 1.875 = u/s acceleration px/tick^2 x 112.5 = u/s^2
|
| 4 |
+
// 27 x 15 u = a 54 x 30 tile arena (engine/renderer.js: 30 px per u on screen, keep W <= 28).
|
| 5 |
+
// Platforms (one-way, like wooden platforms) are per case: BB.CASES[id].platforms = [[x0, x1, y], ...].
|
| 6 |
+
(function (g) {
|
| 7 |
+
var BB = g.BB;
|
| 8 |
+
BB.ARENA = { W: 27, H: 15 };
|
| 9 |
+
})(typeof window !== 'undefined' ? window : globalThis);
|
environments/games/web/games/terraria_remake/art/scenes.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(function(g){
|
| 2 |
+
var BB=g.BB,ART=BB.ART;
|
| 3 |
+
// Original procedural backdrops, cached once per case (bg + fg) plus a cached day/night alternate.
|
| 4 |
+
// Seeded by a fixed hash (ART.hash), never by the game RNG.
|
| 5 |
+
var H=ART.hash;
|
| 6 |
+
function sky(x,top,bottom){var gr=x.createLinearGradient(0,0,0,466);gr.addColorStop(0,top);gr.addColorStop(1,bottom);x.fillStyle=gr;x.fillRect(0,0,854,480);}
|
| 7 |
+
function hills(x,base,amp,col,seed,step){x.fillStyle=col;x.beginPath();x.moveTo(0,480);for(var px=0;px<=854;px+=step){x.lineTo(px,base-amp*(.5+.5*Math.sin(px*.011+seed))-amp*.35*H(seed+px));}x.lineTo(854,480);x.closePath();x.fill();}
|
| 8 |
+
function tree(x,px,base,h,trunk,leaf,leaf2){
|
| 9 |
+
x.fillStyle=trunk;x.fillRect(px-4,base-h,8,h);x.fillRect(px-9,base-6,18,6);
|
| 10 |
+
x.fillStyle=leaf;x.beginPath();x.arc(px,base-h,h*.32,0,Math.PI*2);x.arc(px-h*.22,base-h*.82,h*.24,0,Math.PI*2);x.arc(px+h*.22,base-h*.82,h*.24,0,Math.PI*2);x.fill();
|
| 11 |
+
x.fillStyle=leaf2;x.beginPath();x.arc(px-h*.08,base-h*1.06,h*.17,0,Math.PI*2);x.fill();
|
| 12 |
+
}
|
| 13 |
+
function stars(x,n,seed){for(var i=0;i<n;i++){var a=H(seed+i),b=H(seed+i*7.3);x.fillStyle=i%3?'rgba(220,230,255,.75)':'rgba(255,240,200,.9)';x.fillRect(Math.floor(a*850),Math.floor(b*260),i%7?1:2,i%7?1:2);}}
|
| 14 |
+
function moon(x,cx,cy,r){ART.glow(x,cx,cy,r*3.2,'200,215,255',.35);x.fillStyle='#ece6c9';x.beginPath();x.arc(cx,cy,r,0,Math.PI*2);x.fill();x.fillStyle='rgba(160,160,140,.35)';x.beginPath();x.arc(cx-r*.3,cy-r*.2,r*.22,0,Math.PI*2);x.arc(cx+r*.25,cy+r*.3,r*.15,0,Math.PI*2);x.fill();}
|
| 15 |
+
function sun(x,cx,cy,r){ART.glow(x,cx,cy,r*4,'255,230,160',.45);x.fillStyle='#fff1b8';x.beginPath();x.arc(cx,cy,r,0,Math.PI*2);x.fill();}
|
| 16 |
+
function ground(x,kind,V){
|
| 17 |
+
var y=V.sy(0);
|
| 18 |
+
var top=kind==='corruption'?'#7c6a8e':kind==='dungeon'?'#4d5f73':kind==='hive'?'#d9a03a':kind==='crimson'?'#a8323a':'#5aa04a',
|
| 19 |
+
dirt=kind==='corruption'?'#3f3347':kind==='dungeon'?'#2b3644':kind==='hive'?'#6e4a1c':kind==='crimson'?'#4a1c22':'#6b4a33';
|
| 20 |
+
x.fillStyle=dirt;x.fillRect(0,y,854,480-y);
|
| 21 |
+
for(var px=0;px<854;px+=15){x.fillStyle=H(px)>.5?'rgba(0,0,0,.12)':'rgba(255,255,255,.05)';x.fillRect(px,y+5,15,10);}
|
| 22 |
+
x.fillStyle=top;x.fillRect(0,y-2,854,6);
|
| 23 |
+
if(kind!=='dungeon'&&kind!=='hive')for(px=0;px<854;px+=6){var gh=2+Math.floor(H(px*3.1)*5);x.fillRect(px,y-2-gh,2,gh);}
|
| 24 |
+
}
|
| 25 |
+
// Honeycomb wall for the underground hive (original procedural pattern).
|
| 26 |
+
function honeycomb(x,top){
|
| 27 |
+
var r=19,hx=r*1.5,hy=r*Math.sqrt(3);
|
| 28 |
+
for(var col=0,cx=-r;cx<880;col++,cx+=hx)for(var cy=top+(col%2)*hy/2;cy<480;cy+=hy){
|
| 29 |
+
var s=H(col*13.7+cy);x.beginPath();
|
| 30 |
+
for(var k=0;k<6;k++){var a=k*Math.PI/3;x.lineTo(cx+Math.cos(a)*(r-1.5),cy+Math.sin(a)*(r-1.5));}
|
| 31 |
+
x.closePath();x.fillStyle=s>.86?'#6a4818':s>.5?'#3e2a10':'#35230c';x.fill();
|
| 32 |
+
x.strokeStyle='rgba(18,10,2,.7)';x.lineWidth=2;x.stroke();
|
| 33 |
+
if(s>.86){x.fillStyle='rgba(255,200,90,.12)';x.beginPath();x.arc(cx-4,cy-4,5,0,Math.PI*2);x.fill();}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
ART.scene=function(doc,id){
|
| 37 |
+
var bg=doc.createElement('canvas'),fg=doc.createElement('canvas');bg.width=fg.width=854;bg.height=fg.height=480;
|
| 38 |
+
var x=bg.getContext('2d'),V=BB.VIEW,kind=BB.CASES[id].arena;
|
| 39 |
+
var night=kind==='night',cave=kind==='dungeon'||kind==='hive',evil=kind==='corruption',crimson=kind==='crimson';
|
| 40 |
+
function paint(x,isNight){
|
| 41 |
+
if(kind==='hive'){
|
| 42 |
+
// underground hive: warm gradient, honeycomb wall, dripping honey and jungle vines (no day/night)
|
| 43 |
+
sky(x,'#140c04','#24170a');honeycomb(x,70);
|
| 44 |
+
x.fillStyle='rgba(10,6,2,.35)';x.fillRect(0,0,854,480);
|
| 45 |
+
for(var d=0;d<14;d++){var hx=30+d*62+H(d)*30,len=30+H(d+3)*90;x.fillStyle='rgba(190,120,30,.6)';x.fillRect(hx-2,60,4,len);x.beginPath();x.arc(hx,60+len,4,0,Math.PI*2);x.fill();}
|
| 46 |
+
for(d=0;d<9;d++){var vx=H(d+20)*854;x.strokeStyle='#2c4a1e';x.lineWidth=3;x.beginPath();x.moveTo(vx,40);x.quadraticCurveTo(vx+18,140,vx-6,180+H(d)*120);x.stroke();
|
| 47 |
+
x.fillStyle='#365f24';for(var l=0;l<5;l++){x.beginPath();x.ellipse(vx+6-l*2,70+l*28,6,3,.6,0,Math.PI*2);x.fill();}}
|
| 48 |
+
[[150,250],[700,250]].forEach(function(p){ART.glow(x,p[0],p[1],70,'255,170,60',.12);});
|
| 49 |
+
return;
|
| 50 |
+
}
|
| 51 |
+
if(crimson){
|
| 52 |
+
// crimson: blood-red sky, flesh hills, vertebra spires and veiny ground growths
|
| 53 |
+
sky(x,isNight?'#200a10':'#5a1f26',isNight?'#4a1820':'#8a3a3a');
|
| 54 |
+
if(isNight){stars(x,40,5);moon(x,690,84,20);}else sun(x,700,90,20);
|
| 55 |
+
hills(x,320,60,isNight?'#3a121a':'#6a2a30',2.7,6);
|
| 56 |
+
for(var i=0;i<8;i++){var sx=50+i*110+H(i+11)*40,sh=100+H(i+2)*120;
|
| 57 |
+
for(var v=0;v<sh;v+=14){x.fillStyle=isNight?'#4a1a20':'#7a3036';x.beginPath();x.ellipse(sx,466-v,10-v/sh*5,6,0,0,Math.PI*2);x.fill();}}
|
| 58 |
+
hills(x,380,40,isNight?'#30101a':'#5a2228',5.3,5);
|
| 59 |
+
for(i=0;i<20;i++){x.strokeStyle='rgba(200,60,70,.35)';x.lineWidth=1.5;var gx=H(i+30)*854,gy=380+H(i+31)*80;x.beginPath();x.moveTo(gx,gy);x.quadraticCurveTo(gx+12,gy-10,gx+26,gy-2);x.stroke();}
|
| 60 |
+
return;
|
| 61 |
+
}
|
| 62 |
+
if(kind==='dungeon'){
|
| 63 |
+
sky(x,'#121821','#1c2633');
|
| 64 |
+
// dungeon brick wall with pillars, windows and hanging chains
|
| 65 |
+
for(var y=96,row=0;y<466;y+=22,row++)for(var a=-30+(row%2)*26;a<854;a+=52){
|
| 66 |
+
var s=H(a*.37+y);x.fillStyle=s>.7?'#33415a':s>.35?'#2d3a50':'#283447';x.fillRect(a,y,50,20);
|
| 67 |
+
x.fillStyle='rgba(255,255,255,.04)';x.fillRect(a,y,50,2);}
|
| 68 |
+
[110,330,524,744].forEach(function(px){x.fillStyle='#1a2230';x.fillRect(px-20,96,40,370);x.fillStyle='#3d4c63';x.fillRect(px-26,90,52,10);x.fillRect(px-26,450,52,16);});
|
| 69 |
+
[220,634].forEach(function(px){x.fillStyle='#0b0f17';x.beginPath();x.moveTo(px-26,250);x.lineTo(px-26,170);x.arc(px,170,26,Math.PI,0);x.lineTo(px+26,250);x.closePath();x.fill();
|
| 70 |
+
ART.glow(x,px,190,40,'90,140,255',.18);});
|
| 71 |
+
for(var k=0;k<6;k++){var cx=70+k*150+H(k)*30;x.strokeStyle='#4b525c';x.lineWidth=2;x.setLineDash([3,2]);x.beginPath();x.moveTo(cx,96);x.lineTo(cx,96+40+H(k+9)*60);x.stroke();x.setLineDash([]);}
|
| 72 |
+
[[180,300],[680,300]].forEach(function(p){ART.glow(x,p[0],p[1],46,'255,170,80',.35);x.fillStyle='#ffcc6a';x.fillRect(p[0]-3,p[1]-6,6,9);x.fillStyle='#5a4632';x.fillRect(p[0]-5,p[1]+3,10,4);});
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
if(evil){
|
| 76 |
+
sky(x,isNight?'#1d1426':'#4a3a5c',isNight?'#3a2a44':'#7a6585');
|
| 77 |
+
if(isNight){stars(x,50,3);moon(x,120,78,18);}else sun(x,700,90,20);
|
| 78 |
+
hills(x,320,60,isNight?'#2c2036':'#4f3f5e',1.3,6);
|
| 79 |
+
// ebonstone spires and thorny dead trees
|
| 80 |
+
for(var i=0;i<9;i++){var px=40+i*100+H(i)*40,hgt=90+H(i+3)*120;x.fillStyle=isNight?'#231a2c':'#3d2f4a';x.beginPath();x.moveTo(px-26,466);x.lineTo(px-8,466-hgt);x.lineTo(px+4,466-hgt*.82);x.lineTo(px+26,466);x.closePath();x.fill();}
|
| 81 |
+
hills(x,380,40,isNight?'#2a1f33':'#46385a',4.1,5);
|
| 82 |
+
for(i=0;i<7;i++){var tx=60+i*125+H(i*2)*30,th=60+H(i+8)*40;x.strokeStyle=isNight?'#1a1220':'#2c2235';x.lineWidth=5;x.beginPath();x.moveTo(tx,466);x.lineTo(tx,466-th);x.stroke();
|
| 83 |
+
x.lineWidth=2;x.beginPath();x.moveTo(tx,466-th*.6);x.lineTo(tx-16,466-th*.85);x.moveTo(tx,466-th*.75);x.lineTo(tx+14,466-th);x.stroke();}
|
| 84 |
+
for(i=0;i<16;i++){x.fillStyle='rgba(180,140,220,.35)';x.fillRect(H(i+40)*854,140+H(i+60)*300,2,2);}
|
| 85 |
+
return;
|
| 86 |
+
}
|
| 87 |
+
if(isNight){sky(x,'#0e1830','#2c4468');stars(x,90,1);moon(x,700,90,22);}
|
| 88 |
+
else{sky(x,'#6fb6e6','#cfe8f2');sun(x,700,92,24);
|
| 89 |
+
for(var cl=0;cl<5;cl++){var ccx=60+cl*190+H(cl)*40,ccy=60+H(cl+4)*60;x.fillStyle='rgba(255,255,255,.75)';x.beginPath();x.ellipse(ccx,ccy,46,14,0,0,Math.PI*2);x.ellipse(ccx+24,ccy-8,30,12,0,0,Math.PI*2);x.fill();}}
|
| 90 |
+
hills(x,300,70,isNight?'#1d3042':'#8fb9b0',.4,6);
|
| 91 |
+
hills(x,350,50,isNight?'#1b3a35':'#5f9670',2.2,5);
|
| 92 |
+
for(var j=0;j<12;j++)tree(x,20+j*76+H(j)*30,466,90+H(j+5)*60,isNight?'#2a2620':'#5c3d27',isNight?'#1e4436':'#3f8a4a',isNight?'#2a5a46':'#5aa85c');
|
| 93 |
+
}
|
| 94 |
+
paint(x,night);
|
| 95 |
+
ground(x,kind,V);
|
| 96 |
+
var f=fg.getContext('2d');
|
| 97 |
+
(BB.CASES[id].platforms||[]).forEach(function(p){var x0=Math.round(V.sx(p[0])),w=Math.round((p[1]-p[0])*V.S),y=Math.round(V.sy(p[2]));
|
| 98 |
+
f.fillStyle='#4c3423';f.fillRect(x0,y,w,7);f.fillStyle='#c9925a';f.fillRect(x0,y,w,3);
|
| 99 |
+
for(var n=0;n<w;n+=16){f.fillStyle='#7b5434';f.fillRect(x0+n,y+3,2,4);}
|
| 100 |
+
f.fillStyle='#3a281a';f.fillRect(x0,y+7,4,4);f.fillRect(x0+w-4,y+7,4,4);
|
| 101 |
+
});
|
| 102 |
+
// side walls: framed stone columns
|
| 103 |
+
[V.OX-10,854-V.OX].forEach(function(a){var gr=f.createLinearGradient(a,0,a+10,0);gr.addColorStop(0,'#2c3a3a');gr.addColorStop(1,'#4f6260');f.fillStyle=gr;f.fillRect(a,90,10,380);f.fillStyle='#8b9f7c';f.fillRect(a-2,86,14,5);});
|
| 104 |
+
// cached alternate: the other side of dawn for outdoor arenas
|
| 105 |
+
var alternate=doc.createElement('canvas');alternate.width=854;alternate.height=480;
|
| 106 |
+
var ax=alternate.getContext('2d');
|
| 107 |
+
if(!cave){paint(ax,!night);ground(ax,kind,V);}else ax.drawImage(bg,0,0);
|
| 108 |
+
return {bg:bg,fg:fg,background:function(c){return cave||BB.TR.isDaytime(c)!==night?bg:alternate;}};
|
| 109 |
+
};
|
| 110 |
+
ART.ambient=function(x,id,t){
|
| 111 |
+
var kind=BB.CASES[id].arena;x.save();
|
| 112 |
+
if(kind==='corruption'){for(var n=0;n<14;n++){var px=(n*97+t*18*(1+n%3))%854,py=120+(n*53)%300+Math.sin(t*1.3+n)*10;x.globalAlpha=.35;x.fillStyle='#b38bd8';x.fillRect(px,py,2,2);}}
|
| 113 |
+
else if(kind==='crimson'){for(n=0;n<14;n++){px=(n*89+t*12*(1+n%3))%854;py=110+(n*61)%300+Math.sin(t*1.1+n)*12;x.globalAlpha=.35;x.fillStyle='#e0606a';x.fillRect(px,py,2,2);}}
|
| 114 |
+
else if(kind==='hive'){for(n=0;n<12;n++){px=60+(n*71)%740+Math.sin(t*.7+n)*14;py=430-((t*10+n*53)%330);x.globalAlpha=.4;x.fillStyle='#ffd25a';x.fillRect(px,py,2,2);}}
|
| 115 |
+
else if(kind==='dungeon'){for(n=0;n<10;n++){px=80+(n*83)%700+Math.sin(t*.4+n)*20;py=440-((t*14+n*60)%340);x.globalAlpha=.18;x.fillStyle='#9fb8d8';x.fillRect(px,py,2,2);}}
|
| 116 |
+
else{for(n=0;n<10;n++){px=80+((n*111+Math.sin(t*0.5+n)*24)%700);py=180+(n*43)%235+Math.sin(t+n)*9;x.globalAlpha=kind==='night'?.6:.3;x.fillStyle=kind==='night'?'#f4f19a':'#ffffff';x.fillRect(Math.round(px),Math.round(py),2,2);}}
|
| 117 |
+
x.restore();
|
| 118 |
+
};
|
| 119 |
+
})(typeof window!=='undefined'?window:globalThis);
|
environments/games/web/games/terraria_remake/body_adventurer.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Fixed arena loadout. Source physics and explicit arena equipment are distinguished in docs/player-fidelity.md.
|
| 2 |
+
(function (g) {
|
| 3 |
+
var BB = g.BB, TR = BB.TR;
|
| 4 |
+
var K = {W:20/32,H:42/32,RUN:6*TR.PX,BASE_RUN:3*TR.PX,ACC:0.08*TR.PG,DEC:0.2*TR.PG,
|
| 5 |
+
GRAV:0.4*TR.PG,JUMP:5.01*TR.PX,JUMP_TICKS:16,FALL:10*TR.PX,FLY:7.5,
|
| 6 |
+
WINGS:1.5,HP:200,DEF:12,SWORD:32,BOW:23,SWORD_CD:23/60,BOW_CD:20/60,INVUL:40/60,
|
| 7 |
+
ARROW_SPEED:31,ARROW_GRAV:3,ARROW_GRAV_DELAY:20,ARROW_LIFE:600/60,SWORD_REACH:2.15,SWORD_KB:5,BOW_KB:2};
|
| 8 |
+
function Adventurer() {}
|
| 9 |
+
var P = Adventurer.prototype;
|
| 10 |
+
P.id = 'terraria_adventurer'; P.NAIL = K.SWORD; P.HITSTOP = 0.08; P.multiTargetSlash=true;
|
| 11 |
+
P.keys = {left:'A',right:'D',jump:'Space',drop:'S',attack:'J|LMB',switchWeapon:'Q',bow:'E',sword:'RMB'};
|
| 12 |
+
P.manual = ['A/D move (dash speed capped at 6 px/tick); Space jumps with variable height, hold to continue flight; landing fully recharges flight',
|
| 13 |
+
'S drops through one-way platforms; arena wings fly for up to 1.5 seconds; hold Space to glide after flight expires',
|
| 14 |
+
'Mouse moves the crosshair; J/left mouse button uses the current weapon; Q switches sword/bow, E equips bow, right mouse button equips sword',
|
| 15 |
+
'Bow fires every 20 frames; sword swings every 23 frames in a fixed arc facing the player; bow aims with the mouse. The arena has fixed equipment and unlimited standard arrows.',
|
| 16 |
+
'Packet dx/dy are screen-pixel crosshair offsets (+dy moves down); dz is ignored. The crosshair resets to the arena center.'];
|
| 17 |
+
P.reset = function () {
|
| 18 |
+
this.x=4;this.y=0;this.vx=0;this.vy=0;this.facing=1;this.grounded=true;
|
| 19 |
+
this.hp=this.max_hp=K.HP;this.invul=0;this.knock=0;this.flight=K.WINGS;
|
| 20 |
+
this.mana=this.max_mana=20;this.jumpTicks=0;this.flying=false;this.gliding=false;
|
| 21 |
+
this.status={slow:0,bleeding:0,poisoned:0,confused:0,weak:0,broken_armor:0,cursed:0,darkness:0,silenced:0};this.poisonCounter=0;this.NAIL=K.SWORD;
|
| 22 |
+
this.aimX=16;this.aimY=5;this.weapon='bow';this.atkCd=0;this.atkT=0;
|
| 23 |
+
this.slashFacing=1;this.slashAngle=0;this.slashPreviousAngle=0;this.slashHits={};this.arrows=[];this.nextId=0;this.prev={};this.dropT=0;
|
| 24 |
+
};
|
| 25 |
+
P.box = function () { return {x:this.x,y:this.y+K.H/2,w:K.W,h:K.H}; };
|
| 26 |
+
P.hurtBox=P.box;
|
| 27 |
+
P.centre=function () {return {x:this.x,y:this.y+K.H/2};};
|
| 28 |
+
P.mouse=function (c, delta) {
|
| 29 |
+
this.aimX=BB.clamp(this.aimX+delta[0]/30,0.1,BB.ARENA.W-0.1);
|
| 30 |
+
this.aimY=BB.clamp(this.aimY-delta[1]/30,0.1,BB.ARENA.H-0.1);
|
| 31 |
+
};
|
| 32 |
+
P.pointerDelta=function (point,V) {
|
| 33 |
+
return [BB.clamp(Math.round(point[0]-V.sx(this.aimX)),-1000,1000),BB.clamp(Math.round(point[1]-V.sy(this.aimY)),-1000,1000),0];
|
| 34 |
+
};
|
| 35 |
+
P.slashBox=function () {
|
| 36 |
+
if(this.atkT<=0)return null;
|
| 37 |
+
var x=this.x,y=this.y+0.8,len=K.SWORD_REACH,half=0.09;
|
| 38 |
+
var lo=Math.min(this.slashPreviousAngle,this.slashAngle)-half,hi=Math.max(this.slashPreviousAngle,this.slashAngle)+half;
|
| 39 |
+
var pts=[[x,y],[x+Math.cos(lo)*len,y+Math.sin(lo)*len],
|
| 40 |
+
[x+Math.cos((lo+hi)/2)*len,y+Math.sin((lo+hi)/2)*len],[x+Math.cos(hi)*len,y+Math.sin(hi)*len]];
|
| 41 |
+
return {pts:pts,tink:pts,dir:'side',x:x+Math.cos(this.slashAngle),y:y+Math.sin(this.slashAngle)};
|
| 42 |
+
};
|
| 43 |
+
// Debuffs on the player (Debuffs Wiki): Slow halves horizontal speed; Bleeding has no effect left since natural
|
| 44 |
+
// regeneration was removed in r7 (it stopped regeneration in the source); Poisoned drains 2 life/s; Confused swaps left/right and up/down; Weak -4 defense, -10 %
|
| 45 |
+
// movement, -5.1 % melee damage; Broken Armor halves defense; Cursed blocks item use. Darkness / Silenced have
|
| 46 |
+
// no target in this loadout (no lighting, no mana weapon) and are only recorded.
|
| 47 |
+
var DEBUFFS={slow:1,bleeding:1,poisoned:1,confused:1,weak:1,broken_armor:1,cursed:1,darkness:1,silenced:1};
|
| 48 |
+
P.applyStatus=function(name,seconds){
|
| 49 |
+
if(DEBUFFS[name])this.status[name]=Math.max(this.status[name]||0,Math.max(0,seconds));
|
| 50 |
+
};
|
| 51 |
+
P.defense=function(){var d=K.DEF-(this.status.weak>0?4:0);return this.status.broken_armor>0?Math.floor(d/2):d;};
|
| 52 |
+
// r7 (2026-11-07): no natural health regeneration. The source regenerates over time (RT/eRT formula), which in a
|
| 53 |
+
// single-boss arena let a controller stand and trade hits. Life comes back only from dropped hearts.
|
| 54 |
+
// Poisoned: 2 life per second for players (Debuffs Wiki), applied as one point every 30 ticks.
|
| 55 |
+
P.updateLifeDrain=function(c){
|
| 56 |
+
if(this.status.poisoned>0&&this.hp>0){this.poisonCounter++;if(this.poisonCounter>=30){this.poisonCounter=0;this.hp=Math.max(0,this.hp-1);c.emit('poison_tick',this.x,this.y+K.H);}}
|
| 57 |
+
else this.poisonCounter=0;
|
| 58 |
+
};
|
| 59 |
+
P.update=function(c,i){
|
| 60 |
+
var dt=BB.DT,pv=this.prev,oldY=this.y;
|
| 61 |
+
function decay(v){return v<=dt+1e-9?0:v-dt;}
|
| 62 |
+
this.invul=decay(this.invul);this.atkCd=decay(this.atkCd);this.atkT=decay(this.atkT);this.dropT=decay(this.dropT);
|
| 63 |
+
for(var name in this.status)this.status[name]=decay(this.status[name]);
|
| 64 |
+
// Confused swaps the movement controls (left with right, jump/up with drop/down); attacks are unchanged.
|
| 65 |
+
if(this.status.confused>0)i=Object.assign({},i,{left:i.right,right:i.left,jump:i.drop,drop:i.jump});
|
| 66 |
+
if(this.status.cursed>0)i=Object.assign({},i,{attack:false,bow:false,sword:false});
|
| 67 |
+
if(this.atkT>0){
|
| 68 |
+
this.slashPreviousAngle=this.slashAngle;
|
| 69 |
+
var arc=2.2-3.3*(1-this.atkT/K.SWORD_CD);this.slashAngle=this.slashFacing>0?arc:Math.PI-arc;
|
| 70 |
+
}
|
| 71 |
+
this.knock*=0.89;
|
| 72 |
+
var dir=(i.right?1:0)-(i.left?1:0),slow=(this.status.slow>0?0.5:1)*(this.status.weak>0?0.9:1);
|
| 73 |
+
// Weak also lowers melee damage and melee speed by 5.1 %; the instance NAIL is what the engine deals per slash.
|
| 74 |
+
this.NAIL=this.status.weak>0?K.SWORD*0.949:K.SWORD;
|
| 75 |
+
this.vx=TR.playerHorizontal(this.vx,dir,K.BASE_RUN*slow,K.RUN*slow,K.ACC,K.DEC,true);
|
| 76 |
+
if(dir&&this.atkT<=0)this.facing=dir;
|
| 77 |
+
if(i.switchWeapon&&!pv.switchWeapon)this.weapon=this.weapon==='bow'?'sword':'bow';
|
| 78 |
+
if(i.drop&&this.y>0&&this.grounded){this.dropT=0.18;this.grounded=false;this.y=Math.max(0,this.y-0.06);this.jumpTicks=0;}
|
| 79 |
+
if(i.jump&&!pv.jump&&this.grounded&&!i.drop){this.jumpTicks=K.JUMP_TICKS;this.grounded=false;c.emit('jump',this.x,this.y);}
|
| 80 |
+
if(!i.jump)this.jumpTicks=0;
|
| 81 |
+
this.flying=false;this.gliding=false;
|
| 82 |
+
if(this.jumpTicks>0){this.vy=K.JUMP-K.GRAV*dt;this.jumpTicks--;}
|
| 83 |
+
else{
|
| 84 |
+
this.vy=Math.max(-K.FALL,this.vy-K.GRAV*dt);
|
| 85 |
+
if(i.jump&&!this.grounded&&this.flight>0){
|
| 86 |
+
this.flying=true;this.vy=Math.min(K.FLY,this.vy+60*dt);this.flight=decay(this.flight);
|
| 87 |
+
}else if(i.jump&&!this.grounded&&this.vy<0){this.gliding=true;this.vy=Math.max(this.vy,-K.FALL/3);}
|
| 88 |
+
}
|
| 89 |
+
this.x=BB.clamp(this.x+this.vx*dt,K.W/2,BB.ARENA.W-K.W/2);
|
| 90 |
+
this.y=Math.min(BB.ARENA.H-K.H,this.y+this.vy*dt);this.grounded=false;
|
| 91 |
+
if(this.y<=0){this.y=0;this.vy=0;this.grounded=true;}
|
| 92 |
+
if(this.vy<=0&&this.dropT<=0){
|
| 93 |
+
var landing=-Infinity;
|
| 94 |
+
TR.platforms(c).forEach(function(p){
|
| 95 |
+
if(this.x+K.W/2>p[0]&&this.x-K.W/2<p[1]&&oldY>=p[2]-0.001&&this.y<=p[2])landing=Math.max(landing,p[2]);
|
| 96 |
+
},this);
|
| 97 |
+
if(landing>-Infinity){this.y=landing;this.vy=0;this.grounded=true;}
|
| 98 |
+
}
|
| 99 |
+
if(this.grounded){this.flight=K.WINGS;this.jumpTicks=0;this.flying=false;this.gliding=false;}
|
| 100 |
+
if(this.y>=BB.ARENA.H-K.H&&this.vy>0){this.vy=0;this.jumpTicks=0;}
|
| 101 |
+
if((i.attack||i.bow||i.sword)&&this.atkCd<=0){
|
| 102 |
+
var weapon=i.bow?'bow':i.sword?'sword':this.weapon;
|
| 103 |
+
var b=this.centre(),a=Math.atan2(this.aimY-b.y,this.aimX-b.x);
|
| 104 |
+
this.facing=Math.cos(a)>=0?1:-1;
|
| 105 |
+
if(weapon==='bow'){
|
| 106 |
+
this.atkCd=K.BOW_CD;
|
| 107 |
+
this.arrows.push({id:++this.nextId,x:b.x,y:b.y,vx:Math.cos(a)*K.ARROW_SPEED,vy:Math.sin(a)*K.ARROW_SPEED,age:0,life:K.ARROW_LIFE});c.emit('arrow',b.x,b.y);
|
| 108 |
+
}else{
|
| 109 |
+
this.atkCd=K.SWORD_CD/(this.status.weak>0?0.949:1);this.atkT=K.SWORD_CD;this.slashFacing=this.facing;
|
| 110 |
+
this.slashAngle=this.facing>0?2.2:Math.PI-2.2;this.slashPreviousAngle=this.slashAngle;this.slashHits={};c.emit('slash',b.x,b.y);
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
this.arrows=this.arrows.filter(function(p){
|
| 114 |
+
var ox=p.x,oy=p.y;
|
| 115 |
+
p.age=(p.age||0)+1;if(p.age>=K.ARROW_GRAV_DELAY)p.vy=Math.max(-K.FALL,p.vy-K.ARROW_GRAV*dt);
|
| 116 |
+
p.x+=p.vx*dt;p.y+=p.vy*dt;p.life-=dt;
|
| 117 |
+
var shape={x0:ox,y0:oy,x1:p.x,y1:p.y,r:0.08};
|
| 118 |
+
if(TR.resolveArrow(c.boss,c,K.BOW,shape,p.vx>=0?1:-1))return false;
|
| 119 |
+
return p.life>0&&p.x>=0&&p.x<=BB.ARENA.W&&p.y>=0&&p.y<=BB.ARENA.H;
|
| 120 |
+
},this);
|
| 121 |
+
var slash=this.slashBox();
|
| 122 |
+
if(slash)TR.slashExtras(c.boss,c,this.NAIL,slash.pts,this.slashHits);
|
| 123 |
+
this.updateLifeDrain(c);
|
| 124 |
+
if(typeof TR.updatePickups==='function')TR.updatePickups(c);
|
| 125 |
+
this.prev={jump:!!i.jump,switchWeapon:!!i.switchWeapon};
|
| 126 |
+
};
|
| 127 |
+
P.onSlashContact=function () {};
|
| 128 |
+
P.hurt=function(c,base,fromX,hazard){
|
| 129 |
+
if(this.invul>0||this.hp<=0)return false;
|
| 130 |
+
var damage=TR.playerDamage(c,base,this.defense(),TR.defFactor(c));
|
| 131 |
+
this.hp=Math.max(0,this.hp-damage);this.invul=damage===1?K.INVUL/2:K.INVUL;
|
| 132 |
+
this.knock=this.x>fromX?4.5*TR.PX:-4.5*TR.PX;this.vx=this.knock;this.vy=3.5*TR.PX;this.grounded=false;this.jumpTicks=0;
|
| 133 |
+
if(hazard&&hazard.debuff&&c.rng.chance(hazard.debuffChance==null?1:hazard.debuffChance)){
|
| 134 |
+
var duration=hazard.debuffDuration;
|
| 135 |
+
if(Array.isArray(duration))duration=c.rng.uniform(duration[0],duration[1]);
|
| 136 |
+
this.applyStatus(hazard.debuff,+duration||0);
|
| 137 |
+
}
|
| 138 |
+
// A weighted debuff pool (Brain of Cthulhu Expert contacts): one roll picks one debuff and its duration range.
|
| 139 |
+
if(hazard&&hazard.debuffPool&&c.rng.chance(hazard.debuffChance==null?1:hazard.debuffChance)){
|
| 140 |
+
var pool=hazard.debuffPool,pick=pool[c.rng.pick(pool.map(function(e){return e[1];}))];
|
| 141 |
+
this.applyStatus(pick[0],c.rng.uniform(pick[2][0],pick[2][1]));
|
| 142 |
+
}
|
| 143 |
+
TR.emitHit(c,'player_hit',this.x,this.y+K.H,damage);return true;
|
| 144 |
+
};
|
| 145 |
+
P.state=function(){return TR.snapshot(this,{attacking:this.atkT>0,flight_max:K.WINGS});};
|
| 146 |
+
BB.Adventurer=Adventurer;BB.TR.BODY=K;
|
| 147 |
+
})(typeof window!=='undefined'?window:globalThis);
|
environments/games/web/games/terraria_remake/bosses/brain_of_cthulhu.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(function(g){
|
| 2 |
+
var BB=g.BB,TR=BB.TR,S=BB.SPECS.brain_of_cthulhu;
|
| 3 |
+
// Desktop 1.4.5.8 ordinary single-player Classic / Expert Brain of Cthulhu (aiStyle 54) and its Creepers.
|
| 4 |
+
// Published: brain 1250/2125 life, 30/54 damage, defense 14; 20 Creepers 100/170 life, 20/36 damage, defense 10,
|
| 5 |
+
// never respawn; the brain cannot be damaged until every Creeper is dead; a Creeper drops a heart 1/2 when the
|
| 6 |
+
// player is hurt; Expert contacts roll one debuff from a nine-entry pool (Creepers always, phase-2 brain 1/3);
|
| 7 |
+
// Expert phase 2 adds three mirror illusions around the player whose opacity rises as health drops.
|
| 8 |
+
// Unpublished (estimates): teleport and charge timing, speeds, orbit radius, the 1.4.4
|
| 9 |
+
// phase-1 safe radius.
|
| 10 |
+
var W=110/32,H=86/32;
|
| 11 |
+
// Expert contact debuff pool: [name, weight out of 81, duration range s] (Creeper / Brain of Cthulhu pages).
|
| 12 |
+
var POOL=[['poisoned',11,[5.23,10.4]],['darkness',11,[3,5.93]],['cursed',2,[.73,1.47]],['bleeding',11,[15,29.8]],
|
| 13 |
+
['confused',2,[1.5,2.97]],['slow',11,[5.23,10.4]],['weak',11,[11.23,22.33]],['silenced',11,[1.5,2.97]],['broken_armor',11,[9.73,19.37]]];
|
| 14 |
+
function Brain(){}
|
| 15 |
+
var P=Brain.prototype;TR.boss(P,S);
|
| 16 |
+
P.reset=function(c){
|
| 17 |
+
this.setup(c,20,9,W,H);this.expert=this.k.expert>=.5;
|
| 18 |
+
// Boss health is the published combined total (brain + 20 Creepers, 3250 / 5525), like the Eater's segment sum,
|
| 19 |
+
// so the HUD, verifier and reward count Creeper kills. The brain's own health is brainHp.
|
| 20 |
+
this.brainHp=this.brainMax=TR.paceHp(this,this.expert?2125:1250,10,this.pace.brainHp);this.dmg=TR.paceDmg(this,this.expert?54:30);this.defense=14;
|
| 21 |
+
this.creeperHp=TR.paceHp(this,this.expert?170:100);this.creeperDmg=TR.paceDmg(this,this.expert?36:20);
|
| 22 |
+
this.sourceProfile=this.expert?'desktop-expert':'desktop-classic';this.phase=1;this.fade=1;this.tpTimer=0;this.chargeTimer=1.2/this.pace.aggr;
|
| 23 |
+
this.knockbackResist=this.expert?.6:.55;
|
| 24 |
+
this.orbitAngle=0;this.illusions=[];this.illusionAlpha=0;
|
| 25 |
+
for(var i=0;i<20;i++){
|
| 26 |
+
// The 20 Creepers spawn on three rings around the brain, evenly spread (no cluster a single sword arc clears).
|
| 27 |
+
var a=i/20*Math.PI*2,r=2.2+(i%3)*.55;
|
| 28 |
+
this.minions.push({id:++this.nextId,kind:'creeper',x:this.x+TR.cos(a)*r,y:this.y+TR.sin(a)*r,vx:0,vy:0,w:34/32,h:34/32,
|
| 29 |
+
hp:this.creeperHp,max_hp:this.creeperHp,dmg:this.creeperDmg,defense:10,knockbackResist:this.expert?.28:.2,floating:true,
|
| 30 |
+
drop:'creeper_heart',slot:a,ring:r,st:'orbit',t:0,debuffPool:this.expert?POOL:null,debuffChance:1});
|
| 31 |
+
}
|
| 32 |
+
this.max_hp=this.brainMax+20*this.creeperHp;this.sync();
|
| 33 |
+
this.go(c,'idle',0,'creeper_charge');
|
| 34 |
+
};
|
| 35 |
+
P.sync=function(){this.hp=this.brainHp+this.minions.reduce(function(a,m){return a+(m.kind==='creeper'?Math.max(0,m.hp):0);},0);};
|
| 36 |
+
P.alive=function(){return this.minions.filter(function(m){return m.kind==='creeper'&&m.hp>0;});};
|
| 37 |
+
// Phase 1: invulnerable; a teleporting brain is not solid until it has mostly faded in.
|
| 38 |
+
P.hitTargets=function(){return this.phase===1||this.fade<.5||this.st==='dead'?[]:[{id:'brain',box:this.bodyBox()}];};
|
| 39 |
+
P.onNailHit=function(c,base,dir,f,id){
|
| 40 |
+
if(this.phase===1||this.fade<.5||this.brainHp<=0)return null;
|
| 41 |
+
var hit=TR.rollDetails(c,base,this.defense,.5,.04);this.brainHp=Math.max(0,this.brainHp-hit.damage);this.hitFlash=.12;
|
| 42 |
+
TR.emitHit(c,'boss_hit',this.x,this.y,hit.damage,hit.critical);this.sync();
|
| 43 |
+
if(!this.brainHp){this.hp=0;this.st='dead';this.minions=[];this.shots=[];c.emit('boss_dead',this.x,this.y);return 'flesh';}
|
| 44 |
+
// "The only boss that is affected by knockback" (Wiki trivia): phase-2 knockback resistance 55 % / 60 %
|
| 45 |
+
// (1.4.4). Arrow KB 2, sword KB 5; the push uses the shared NPC knockback rule on the brain's own velocity.
|
| 46 |
+
TR.enemyKnockback(c,this,hit.damage,hit.critical,{facing:f<0?-1:1,knockback:dir==='arrow'?TR.BODY.BOW_KB:TR.BODY.SWORD_KB});
|
| 47 |
+
return 'flesh';
|
| 48 |
+
};
|
| 49 |
+
P.teleport=function(c,near){
|
| 50 |
+
// A random spot around the player, away from the player and inside the arena (phase 1 keeps the safe radius).
|
| 51 |
+
var b=c.body.centre(),best=null;
|
| 52 |
+
for(var k=0;k<12;k++){
|
| 53 |
+
var a=c.rng.uniform(0,Math.PI*2),r=near?c.rng.uniform(5,8):c.rng.uniform(7,11),x=b.x+TR.cos(a)*r,y=b.y+Math.abs(TR.sin(a))*r*.8+1;
|
| 54 |
+
if(x>this.w/2&&x<BB.ARENA.W-this.w/2&&y>this.h/2+.5&&y<BB.ARENA.H-this.h/2){best={x:x,y:y};break;}
|
| 55 |
+
}
|
| 56 |
+
if(!best)best={x:BB.clamp(b.x+(c.rng.chance(.5)?6:-6),this.w/2,BB.ARENA.W-this.w/2),y:BB.clamp(b.y+5,this.h/2,BB.ARENA.H-this.h/2)};
|
| 57 |
+
this.x=best.x;this.y=best.y;this.vx=this.vy=0;this.fade=0;c.emit('brain_teleport',this.x,this.y);
|
| 58 |
+
};
|
| 59 |
+
P.updateCreepers=function(c,b){
|
| 60 |
+
var dt=BB.DT,self=this,alive=this.alive();
|
| 61 |
+
this.orbitAngle+=dt*(this.expert?1.6:1.2);
|
| 62 |
+
this.chargeTimer-=dt;
|
| 63 |
+
// One Creeper at a time throws itself at the player (Expert: two, and faster), then returns to the orbit.
|
| 64 |
+
if(this.chargeTimer<=0&&alive.length){
|
| 65 |
+
var idle=alive.filter(function(m){return m.st==='orbit';});
|
| 66 |
+
var n=Math.min(idle.length,this.expert?2:1);
|
| 67 |
+
for(var k=0;k<n;k++){var m=idle[c.rng.int(idle.length)];idle.splice(idle.indexOf(m),1);
|
| 68 |
+
var dx=b.x-m.x,dy=b.y-m.y,l=Math.hypot(dx,dy)||1,sp=(this.expert?13:10)*this.pace.speed;
|
| 69 |
+
m.st='charge';m.t=0;m.vx=dx/l*sp;m.vy=dy/l*sp;c.emit('creeper_charge',m.x,m.y);}
|
| 70 |
+
this.chargeTimer=(this.expert?.75:1.1)/this.pace.aggr;
|
| 71 |
+
}
|
| 72 |
+
this.minions=this.minions.filter(function(m){
|
| 73 |
+
if(m.hp<=0){if(!m.dropProcessed){m.dropProcessed=true;TR.dropCreeper(c,self,m);}c.emit('creeper_dead',m.x,m.y);return false;}
|
| 74 |
+
m.t+=dt;
|
| 75 |
+
if(m.st==='charge'){
|
| 76 |
+
m.x+=m.vx*dt;m.y+=m.vy*dt;
|
| 77 |
+
if(m.t>.9||m.x<m.w/2||m.x>BB.ARENA.W-m.w/2||m.y<m.h/2||m.y>BB.ARENA.H-m.h/2){m.st='return';m.t=0;}
|
| 78 |
+
m.x=BB.clamp(m.x,m.w/2,BB.ARENA.W-m.w/2);m.y=BB.clamp(m.y,m.h/2,BB.ARENA.H-m.h/2);
|
| 79 |
+
}else{
|
| 80 |
+
// Irregular circles around the brain: each Creeper has its own ring radius and a wobble.
|
| 81 |
+
var a=m.slot+self.orbitAngle,r=m.ring+TR.sin(self.orbitAngle*1.7+m.id)*.5;
|
| 82 |
+
var tx=self.x+TR.cos(a)*r,ty=self.y+TR.sin(a)*r;
|
| 83 |
+
TR.moveToward(m,tx,ty,(m.st==='return'?9:12)*self.pace.speed,m.st==='return'?30:60);
|
| 84 |
+
if(m.st==='return'&&Math.hypot(m.x-tx,m.y-ty)<.6)m.st='orbit';
|
| 85 |
+
}
|
| 86 |
+
return true;
|
| 87 |
+
});
|
| 88 |
+
};
|
| 89 |
+
P.update=function(c){
|
| 90 |
+
if(this.st==='dead')return;this.clock(c);var dt=BB.DT,b=c.body.centre();this.sync();
|
| 91 |
+
this.fade=Math.min(1,this.fade+dt/(this.phase===1?.6:.35));
|
| 92 |
+
if(this.phase===1){
|
| 93 |
+
// Translucent and invulnerable: drift toward the player, then teleport away in a random direction. The drift
|
| 94 |
+
// stops short of the player so the orbiting ring cannot simply sit on them: Creepers reach the player by
|
| 95 |
+
// charging (the source behaviour), not by the ring overlapping a player the brain is parked next to.
|
| 96 |
+
var bx=b.x,by=b.y+1.5,dd=Math.hypot(this.x-bx,this.y-by),keep=4.5;
|
| 97 |
+
if(dd>keep)TR.moveToward(this,bx,by,2.4*TR.PX*this.pace.speed,4);
|
| 98 |
+
else{this.vx*=.9;this.vy*=.9;this.x=BB.clamp(this.x+this.vx*dt,this.w/2,BB.ARENA.W-this.w/2);this.y=BB.clamp(this.y+this.vy*dt,this.h/2,BB.ARENA.H-this.h/2);}
|
| 99 |
+
this.tpTimer+=dt;
|
| 100 |
+
if(this.tpTimer>=(this.expert?4:5.5)/this.pace.aggr){this.tpTimer=0;this.teleport(c,false);}
|
| 101 |
+
this.updateCreepers(c,b);this.sync();
|
| 102 |
+
if(!this.alive().length){this.phase=2;this.tpTimer=0;this.go(c,'transform',.8,'teleport');c.emit('boss_escalate',this.x,this.y);}
|
| 103 |
+
return;
|
| 104 |
+
}
|
| 105 |
+
if(this.st==='transform'){this.vx=this.vy=0;if(this.timer<=0)this.go(c,'attack',0,'teleport');}
|
| 106 |
+
else{
|
| 107 |
+
// Phase 2: visible heart. It closes in "at a steady pace" (Wiki tip) and its illusions "spread away from the
|
| 108 |
+
// real Brain if the player is walking away" -- so a walking player outpaces it; its threat is the rapid
|
| 109 |
+
// teleports around the player. Chase 3 px/tick (Expert 4) is below the 3 px/tick-plus run speed once tier
|
| 110 |
+
// aggression is applied (r6 round 2: at 4.5 px/tick a movement-only beam search died by 33 s on hard).
|
| 111 |
+
if(this.fade>=1)TR.moveToward(this,b.x,b.y,(this.expert?4:3)*TR.PX*this.pace.speed,this.expert?12:8);
|
| 112 |
+
this.tpTimer+=dt;
|
| 113 |
+
if(this.tpTimer>=(this.expert?2.4:3.2)/this.pace.aggr){this.tpTimer=0;this.teleport(c,true);}
|
| 114 |
+
}
|
| 115 |
+
// Expert illusions mirror the brain through the player; opacity rises as the brain's own health drops.
|
| 116 |
+
if(this.expert){var dx=this.x-b.x,dy=this.y-b.y;
|
| 117 |
+
this.illusions=[{x:b.x-dx,y:b.y+dy},{x:b.x+dx,y:b.y-dy},{x:b.x-dx,y:b.y-dy}].map(function(p){
|
| 118 |
+
return {x:BB.clamp(p.x,.5,BB.ARENA.W-.5),y:BB.clamp(p.y,.5,BB.ARENA.H-.5)};});
|
| 119 |
+
this.illusionAlpha=.25+.75*(1-this.brainHp/this.brainMax);}
|
| 120 |
+
this.minions=this.minions.filter(function(m){return m.hp>0;});this.sync();
|
| 121 |
+
};
|
| 122 |
+
P.hazards=function(){
|
| 123 |
+
if(this.st==='dead')return [];
|
| 124 |
+
var out=[];
|
| 125 |
+
// A fading brain cannot touch the player; it becomes solid as it finishes appearing.
|
| 126 |
+
if(this.fade>=.5){var h={kind:this.phase===1?'brain':'brain_heart',box:this.bodyBox(),dmg:this.dmg,fromX:this.x};
|
| 127 |
+
if(this.expert&&this.phase===2){h.debuffPool=POOL;h.debuffChance=1/3;}out.push(h);}
|
| 128 |
+
return out.concat(TR.extraHazards(this));
|
| 129 |
+
};
|
| 130 |
+
BB.CASES['terraria/brain_of_cthulhu'] = TR.register('brain_of_cthulhu','Teleporting Flesh Brain',Brain,'crimson');
|
| 131 |
+
})(typeof window!=='undefined'?window:globalThis);
|
environments/games/web/games/terraria_remake/bosses/eater_of_worlds.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(function(g){
|
| 2 |
+
var BB=g.BB,TR=BB.TR,S=BB.SPECS.eater_of_worlds;
|
| 3 |
+
var EXPLOSIVES={grenade:1,sticky_grenade:1,bouncy_grenade:1,bomb:1,sticky_bomb:1,bouncy_bomb:1,
|
| 4 |
+
dynamite:1,sticky_dynamite:1,bouncy_dynamite:1,power_bomb:1,sticky_power_bomb:1,explosives:1,
|
| 5 |
+
explosive_bunny:1,confetti_grenade:1,bomb_fish:1,scarab_bomb:1,beenade:1,bee:1,giant_bee:1,tnt_barrel:1};
|
| 6 |
+
var EXPLOSIVE_IDS={30:1,397:1,517:1,28:1,37:1,516:1,29:1,470:1,637:1,1086:1,1087:1,
|
| 7 |
+
108:1,281:1,588:1,519:1,773:1,183:1,181:1,566:1,1002:1};
|
| 8 |
+
function snap(v){return Math.floor(v/TR.TILE)*TR.TILE;}
|
| 9 |
+
function Eater(){}
|
| 10 |
+
var P=Eater.prototype;TR.boss(P,S);
|
| 11 |
+
P.stats=function(type){
|
| 12 |
+
return {hp:TR.paceHp(this,this.expert?210:150,1),dmg:TR.paceDmg(this,this.expert?(type==='head'?48:type==='body'?21:18):(type==='head'?22:type==='body'?13:11)),
|
| 13 |
+
defense:(type==='head'?2:type==='body'?4:8)+(this.expert?2:0)};
|
| 14 |
+
};
|
| 15 |
+
P.reset=function(c){
|
| 16 |
+
this.setup(c,20,-1,1.375,1.375);this.expert=this.k.expert>=.5;this.segments=[];this.chains=[];
|
| 17 |
+
this.sourceProfile=this.expert?'desktop-expert':'desktop-classic';this.spacing=46/32;
|
| 18 |
+
// Tier aggression (tiers.js) scales top speed by sqrt(aggr) and steering by aggr; 1 at normal.
|
| 19 |
+
this.maxSpeed=16*(this.expert?1.2:1)*this.pace.speed;this.acceleration=(this.expert?16.875:7.875)*this.pace.aggr;
|
| 20 |
+
// The available reference gives ballistic peak heights (~31/44 tiles), rather than raw AI gravity.
|
| 21 |
+
// This approximation is constrained to those peaks; exact continuous steering remains documented.
|
| 22 |
+
this.airGravity=16*16/(31*TR.TILE*2);this.max_hp=0;
|
| 23 |
+
var n=Math.max(8,Math.round((this.expert?72:67)*this.pace.segments)),size=this.expert?1.2:1;
|
| 24 |
+
for(var i=0;i<n;i++){
|
| 25 |
+
var type=i===0?'head':i===n-1?'tail':'body',stats=this.stats(type);
|
| 26 |
+
this.segments.push({id:'seg'+i,x:20,y:-1,vx:0,vy:0,w:1.375*size,h:1.375*size,
|
| 27 |
+
hp:stats.hp,max_hp:stats.hp,dmg:stats.dmg,defense:stats.defense,type:type,visible:i===0,shotAttempts:0});
|
| 28 |
+
this.max_hp+=stats.hp;
|
| 29 |
+
}
|
| 30 |
+
this.hp=this.max_hp;this.rebuild(c);this.go(c,'recover',0,'burrow');
|
| 31 |
+
};
|
| 32 |
+
P.retype=function(s,type){
|
| 33 |
+
if(s.type===type)return;
|
| 34 |
+
var fraction=s.hp/s.max_hp,stats=this.stats(type);s.type=type;s.max_hp=stats.hp;
|
| 35 |
+
s.hp=Math.max(1,Math.floor(stats.hp*fraction));s.dmg=stats.dmg;s.defense=stats.defense;
|
| 36 |
+
if(type==='head'){s.vx=s.vy=0;s.visible=true;}
|
| 37 |
+
};
|
| 38 |
+
P.rebuild=function(c){
|
| 39 |
+
var self=this,old=this.chains||[],chains=[],run=[];
|
| 40 |
+
function finish(){
|
| 41 |
+
if(run.length===1){run[0].hp=0;if(TR.dropSegment)TR.dropSegment(c,self,run[0]);c.emit('lone_segment_dead',run[0].x,run[0].y);}
|
| 42 |
+
else if(run.length>1){
|
| 43 |
+
var first=run[0],prev=old.find(function(ch){return ch.ids[0]===first.id;}),newHead=first.type!=='head';
|
| 44 |
+
run.forEach(function(s,n){self.retype(s,n===0?'head':n===run.length-1?'tail':'body');});
|
| 45 |
+
// A surviving head keeps its momentum. Every new split head must fall and reach material first.
|
| 46 |
+
chains.push({ids:run.map(function(s){return s.id;}),st:prev?prev.st:'burrow',timer:0,digTimer:prev?prev.digTimer:0,
|
| 47 |
+
target:prev?prev.target:c.body.centre(),vx:prev?prev.vx:0,vy:prev?prev.vy:0,
|
| 48 |
+
forceFall:newHead||(!prev&&old.length>0)});
|
| 49 |
+
}run=[];
|
| 50 |
+
}
|
| 51 |
+
this.segments.forEach(function(s){if(s.hp>0)run.push(s);else finish();});finish();this.chains=chains;
|
| 52 |
+
this.hp=this.segments.reduce(function(a,s){return a+s.hp;},0);
|
| 53 |
+
if(!this.hp){this.st='dead';this.shots=[];c.emit('boss_dead',this.x,this.y);}
|
| 54 |
+
};
|
| 55 |
+
P.hitTargets=function(){
|
| 56 |
+
// Initial coiled segments are invisible but remain hittable, as in the source game.
|
| 57 |
+
return this.segments.filter(function(s){return s.hp>0&&s.y>-s.h/2;}).map(function(s){return {id:s.id,box:TR.box(s)};});
|
| 58 |
+
};
|
| 59 |
+
P.damageMultiplier=function(attack){
|
| 60 |
+
var kind=typeof attack==='string'?attack:attack&&(attack.kind||attack.projectileKind),
|
| 61 |
+
id=attack&&typeof attack==='object'?attack.projectileId:null;
|
| 62 |
+
if(kind==='molotov_fire'||kind==='obsidian_swordfish_fire')return .65;
|
| 63 |
+
return this.expert&&(EXPLOSIVES[kind]||EXPLOSIVE_IDS[id])?.2:1;
|
| 64 |
+
};
|
| 65 |
+
P.onNailHit=function(c,base,dir,f,id){
|
| 66 |
+
var s=this.segments.find(function(v){return v.id===id;});if(!s||s.hp<=0)return null;
|
| 67 |
+
var hit=TR.rollDetails(c,base*this.damageMultiplier(dir),s.defense,0.5,0.04),damage=hit.damage;
|
| 68 |
+
s.hp=Math.max(0,s.hp-damage);this.hitFlash=.12;TR.emitHit(c,'boss_hit',s.x,s.y,damage,hit.critical);
|
| 69 |
+
if(!s.hp){if(TR.dropSegment)TR.dropSegment(c,this,s);c.emit('worm_split',s.x,s.y);this.rebuild(c);}
|
| 70 |
+
else this.hp=this.segments.reduce(function(a,v){return a+v.hp;},0);
|
| 71 |
+
return 'flesh';
|
| 72 |
+
};
|
| 73 |
+
P.inMaterial=function(c,s){
|
| 74 |
+
var solid=function(x,y){return TR.solidAt?TR.solidAt(c,x,y,{platforms:true}):y<=0;};
|
| 75 |
+
return solid(s.x,s.y)||solid(s.x,s.y-s.h/2)||solid(s.x-s.w/2,s.y)||solid(s.x+s.w/2,s.y);
|
| 76 |
+
};
|
| 77 |
+
// Source worm steering (vanilla aiStyle 6, as mirrored by tModLoader ExampleMod WormHead): per-axis steps
|
| 78 |
+
// of `acceleration` toward the target direction, plus the source's anti-stall terms. When the head moves
|
| 79 |
+
// away from a nearly level/vertical target it curves along the other axis (x2 step); when it is slower than
|
| 80 |
+
// half its top speed it keeps pushing along its current sign. Without those terms a head below a target
|
| 81 |
+
// that is higher than its standing hop hovers at the surface forever (r4 bug).
|
| 82 |
+
// y is up here and down in the source, so a zero vertical velocity breaks toward "up" in both.
|
| 83 |
+
function toward(v,t,a){return v<t?v+a:v>t?v-a:v;}
|
| 84 |
+
P.steerToward=function(ch,dirX,dirY){
|
| 85 |
+
var speed=this.maxSpeed,acc=this.acceleration*BB.DT,len=Math.hypot(dirX,dirY),absX=Math.abs(dirX),absY=Math.abs(dirY),vx=ch.vx,vy=ch.vy;
|
| 86 |
+
if(len>0){dirX*=speed/len;dirY*=speed/len;}
|
| 87 |
+
if(len>0&&((vx>0&&dirX>0)||(vx<0&&dirX<0)||(vy>0&&dirY>0)||(vy<0&&dirY<0))){
|
| 88 |
+
vx=toward(vx,dirX,acc);vy=toward(vy,dirY,acc);
|
| 89 |
+
if(Math.abs(dirY)<speed*.2&&((vx>0&&dirX<0)||(vx<0&&dirX>0)))vy+=vy<0?-acc*2:acc*2;
|
| 90 |
+
if(Math.abs(dirX)<speed*.2&&((vy>0&&dirY<0)||(vy<0&&dirY>0)))vx+=vx>0?acc*2:-acc*2;
|
| 91 |
+
}else if(absX>absY){
|
| 92 |
+
vx=toward(vx,dirX,acc*1.1);
|
| 93 |
+
if(Math.abs(vx)+Math.abs(vy)<speed*.5)vy+=vy<0?-acc:acc;
|
| 94 |
+
}else{
|
| 95 |
+
// A zero-length direction (same tile) leaves vy unchanged, as the source's NaN comparison does.
|
| 96 |
+
if(len>0)vy=toward(vy,dirY,acc*1.1);
|
| 97 |
+
if(Math.abs(vx)+Math.abs(vy)<speed*.5)vx+=vx>0?acc:-acc;
|
| 98 |
+
}
|
| 99 |
+
ch.vx=vx;ch.vy=vy;
|
| 100 |
+
};
|
| 101 |
+
// Out of material: constant gravity (fitted to the published peaks, EOW-05) and the source's horizontal
|
| 102 |
+
// terms: a slow head keeps accelerating along its sign, a head at terminal fall turns toward the target,
|
| 103 |
+
// a fast-falling head loses horizontal speed. dirX is the raw tile-snapped distance, compared in source px.
|
| 104 |
+
P.fall=function(ch,dirX){
|
| 105 |
+
var speed=this.maxSpeed,acc=this.acceleration*BB.DT;
|
| 106 |
+
ch.vy=Math.max(-speed,ch.vy-this.airGravity*BB.DT);
|
| 107 |
+
if(Math.abs(ch.vx)+Math.abs(ch.vy)<speed*.4)ch.vx+=ch.vx<0?-acc*1.1:acc*1.1;
|
| 108 |
+
else if(ch.vy===-speed){var vpx=ch.vx/TR.PX,dpx=dirX*32;if(vpx<dpx)ch.vx+=acc;else if(vpx>dpx)ch.vx-=acc;}
|
| 109 |
+
else if(ch.vy<-4*TR.PX)ch.vx+=ch.vx<0?acc*.9:-acc*.9;
|
| 110 |
+
};
|
| 111 |
+
P.spitChance=function(s){return s.type==='head'?1/390+(1-s.hp/s.max_hp)*(1/90-1/390):s.type==='body'?1/900:0;};
|
| 112 |
+
P.spitAllowed=function(c,s){
|
| 113 |
+
if(s.hp<=0||s.type==='tail')return false;
|
| 114 |
+
var b=c.body.centre();
|
| 115 |
+
if(TR.lineOfSight&&!TR.lineOfSight(c,s.x,s.y,b.x,b.y))return false;
|
| 116 |
+
if(s.type==='body'&&(s.y<=0||(TR.backgroundWallAt&&TR.backgroundWallAt(c,s.x,s.y))))return false;
|
| 117 |
+
return true;
|
| 118 |
+
};
|
| 119 |
+
P.spit=function(c,s){
|
| 120 |
+
TR.shoot(this,c,s.x,s.y,7*TR.PX,'vile_spit',false);
|
| 121 |
+
var shot=this.shots[this.shots.length-1];shot.sourceSegment=s.id;shot.dmg=TR.paceDmg(this,64);shot.destructible=true;shot.solidCollision=true;shot.collidePlatforms=true;
|
| 122 |
+
// Eater-specific Vile Spit is an NPC attack and has no Weak debuff since Desktop 1.4.2.
|
| 123 |
+
// Its 7 px/tick motion corresponds to the Wiki's rounded 36 mph.
|
| 124 |
+
c.emit('vile_spit',s.x,s.y);
|
| 125 |
+
};
|
| 126 |
+
P.update=function(c){
|
| 127 |
+
if(this.st==='dead')return;this.clock(c);var dt=BB.DT,b=c.body.centre(),lookup={},self=this;
|
| 128 |
+
this.segments.forEach(function(s){lookup[s.id]=s;});
|
| 129 |
+
this.chains.forEach(function(ch){
|
| 130 |
+
var head=lookup[ch.ids[0]],material=self.inMaterial(c,head),distance=Math.hypot(head.x-b.x,head.y-b.y),
|
| 131 |
+
far=Math.abs(head.x-b.x)>62.5*TR.TILE||Math.abs(head.y-b.y)>62.5*TR.TILE;
|
| 132 |
+
ch.digTimer-=dt;
|
| 133 |
+
if(material&&distance<25&&ch.digTimer<=0){
|
| 134 |
+
c.emit('burrow_dig',head.x,head.y);ch.digTimer=BB.clamp(.1+distance*.026,.1,.75);
|
| 135 |
+
}
|
| 136 |
+
ch.target={x:b.x,y:b.y};
|
| 137 |
+
if(material)ch.forceFall=false;
|
| 138 |
+
// The source compares tile-snapped centres (16 px = TR.TILE).
|
| 139 |
+
var dirX=snap(b.x)-snap(head.x),dirY=snap(b.y)-snap(head.y);
|
| 140 |
+
if((material||far)&&!ch.forceFall){self.steerToward(ch,dirX,dirY);ch.st='burrow';}
|
| 141 |
+
// No artificial pause or telegraph: outside tiles a worm follows a ballistic fall.
|
| 142 |
+
else{self.fall(ch,dirX);ch.st='lunge';}
|
| 143 |
+
head.vx=ch.vx;head.vy=ch.vy;head.x+=ch.vx*dt;head.y+=ch.vy*dt;
|
| 144 |
+
// Finite benchmark world margins allow a long chain to turn underground off-screen.
|
| 145 |
+
if(head.x< -4){head.x=-4;ch.vx=Math.abs(ch.vx);}if(head.x>BB.ARENA.W+4){head.x=BB.ARENA.W+4;ch.vx=-Math.abs(ch.vx);}
|
| 146 |
+
if(head.y< -20){head.y=-20;ch.vy=Math.abs(ch.vy);}if(head.y>BB.ARENA.H+10){head.y=BB.ARENA.H+10;ch.vy=-Math.abs(ch.vy);}
|
| 147 |
+
for(var n=1;n<ch.ids.length;n++){
|
| 148 |
+
var prev=lookup[ch.ids[n-1]],s=lookup[ch.ids[n]],sx=prev.x-s.x,sy=prev.y-s.y,dist=Math.hypot(sx,sy);
|
| 149 |
+
var ox=s.x,oy=s.y;
|
| 150 |
+
if(dist>self.spacing){
|
| 151 |
+
s.x=prev.x-sx/dist*self.spacing;s.y=prev.y-sy/dist*self.spacing;s.visible=true;
|
| 152 |
+
}else if(s.visible&&dist>1e-9){s.x=prev.x-sx/dist*self.spacing;s.y=prev.y-sy/dist*self.spacing;}
|
| 153 |
+
s.vx=(s.x-ox)/dt;s.vy=(s.y-oy)/dt;
|
| 154 |
+
}
|
| 155 |
+
});
|
| 156 |
+
var leader=this.chains[0];
|
| 157 |
+
if(leader){var head=lookup[leader.ids[0]];this.x=head.x;this.y=head.y;this.vx=head.vx;this.vy=head.vy;
|
| 158 |
+
this.st=leader.st==='burrow'?'recover':'attack';this.timer=0;this.target=leader.target;}
|
| 159 |
+
if(this.expert)this.segments.forEach(function(s){
|
| 160 |
+
if(!self.spitAllowed(c,s))return;s.shotAttempts++;
|
| 161 |
+
if(c.rng.chance(self.spitChance(s)))self.spit(c,s);
|
| 162 |
+
});
|
| 163 |
+
};
|
| 164 |
+
P.hazards=function(){
|
| 165 |
+
return this.st==='dead'?[]:this.segments.filter(function(s){return s.hp>0&&s.y>-s.h/2;}).map(function(s){
|
| 166 |
+
return {kind:'worm_'+s.type,box:TR.box(s),dmg:s.dmg,fromX:s.x};
|
| 167 |
+
}).concat(TR.extraHazards(this));
|
| 168 |
+
};
|
| 169 |
+
BB.CASES['terraria/eater_of_worlds'] = TR.register('eater_of_worlds','Burrowing Great Worm',Eater,'corruption');
|
| 170 |
+
})(typeof window!=='undefined'?window:globalThis);
|
environments/games/web/games/terraria_remake/bosses/eye_of_cthulhu.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(function(g){
|
| 2 |
+
var BB=g.BB,TR=BB.TR,S=BB.SPECS.eye_of_cthulhu;
|
| 3 |
+
function Eye(){}
|
| 4 |
+
var P=Eye.prototype;TR.boss(P,S);
|
| 5 |
+
P.reset=function(c){
|
| 6 |
+
this.setup(c,20,10,110/32,110/32);
|
| 7 |
+
this.expert=this.k.expert>=0.5;this.easyScale=1;
|
| 8 |
+
this.hp=this.max_hp=TR.paceHp(this,this.expert?3640:2800);
|
| 9 |
+
this.dmg=TR.paceDmg(this,this.expert?30:15);this.defense=12;this.phaseAt=this.expert?0.65:0.5;
|
| 10 |
+
this.k.hp=this.max_hp;this.k.dmg=this.dmg;this.k.phase_at=this.phaseAt;
|
| 11 |
+
this.k.def_factor=this.expert?0.75:0.5;
|
| 12 |
+
this.cycleIndex=0;this.dashesLeft=0;this.spawnTimer=0;this.servantsThisHover=0;
|
| 13 |
+
this.servantsPerHover=this.expert?5:4;this.pendingChain=false;
|
| 14 |
+
this.transformFrames=0;this.rotation=0;this.dashAge=0;this.dashFrames=0;this.dashFramesTotal=0;this.chainLevel=0;
|
| 15 |
+
this.recoverFrames=0;this.despawned=false;this.dawnDeparting=false;
|
| 16 |
+
this.startHover(c);
|
| 17 |
+
};
|
| 18 |
+
P.startHover=function(c){
|
| 19 |
+
this.move=null;this.dashesLeft=0;this.pendingChain=false;
|
| 20 |
+
this.servantsThisHover=0;this.spawnTimer=1.8/this.pace.aggr;this.hoverFrames=0;
|
| 21 |
+
this.go(c,'idle',this.hoverLimit()/60);
|
| 22 |
+
};
|
| 23 |
+
// Tier aggression stretches hover and summon cadences and scales dash/hover speeds (tiers.js).
|
| 24 |
+
P.hoverLimit=function(){return Math.round((this.phase===1?600:this.expert?120:200)/this.pace.aggr);};
|
| 25 |
+
P.spawnServant=function(c,angle){
|
| 26 |
+
var b=c.body.centre(),dx=b.x-this.x,dy=b.y-this.y,l=Math.hypot(dx,dy)||1;
|
| 27 |
+
var vx=dx/l,vy=dy/l;
|
| 28 |
+
if(angle){var co=Math.cos(angle),si=Math.sin(angle),ox=vx;vx=ox*co-vy*si;vy=ox*si+vy*co;}
|
| 29 |
+
this.minions.push({id:++this.nextId,kind:'servant',x:this.x+vx*this.w/2,y:this.y+vy*this.h/2,
|
| 30 |
+
vx:vx*5*TR.PX*this.pace.speed,vy:vy*5*TR.PX*this.pace.speed,w:20/32,h:20/32,hp:this.expert?12:8,max_hp:this.expert?12:8,
|
| 31 |
+
dmg:TR.paceDmg(this,this.expert?24:12),defense:0,drop:'heart_star',floating:true,knockbackResist:this.expert?0.1:0});
|
| 32 |
+
c.emit('servant_spawn',this.x,this.y);
|
| 33 |
+
};
|
| 34 |
+
P.startDashes=function(c,chain){
|
| 35 |
+
this.move=chain?'chain_dash':'dash';this.dashesLeft=chain?5:3;
|
| 36 |
+
this.chainLevel=this.expert&&this.phase===2?(this.hp/this.max_hp<0.04?2:this.hp/this.max_hp<0.12?1:0):0;
|
| 37 |
+
this.launch(c);
|
| 38 |
+
};
|
| 39 |
+
P.launch=function(c){
|
| 40 |
+
var b=c.body.centre(),chain=this.move==='chain_dash';
|
| 41 |
+
if(chain)this.chainLevel=this.hp/this.max_hp<0.04?2:this.hp/this.max_hp<0.12?1:0;
|
| 42 |
+
// A charge commits to one vector. Only rapid charges lead the moving target.
|
| 43 |
+
var lead=chain?(this.chainLevel===2?0.25:0.12):0;
|
| 44 |
+
this.target={x:b.x+(c.body.vx||0)*lead,y:b.y+(c.body.vy||0)*lead};
|
| 45 |
+
var dx=this.target.x-this.x,dy=this.target.y-this.y,l=Math.hypot(dx,dy)||1;
|
| 46 |
+
var speed=(chain?(this.chainLevel===2?20:16):this.phase===2?6.8:6)*TR.PX*this.pace.speed;
|
| 47 |
+
if(!chain&&this.expert)speed*=1.15;
|
| 48 |
+
this.vx=dx/l*speed;this.vy=dy/l*speed;this.dashAge=0;this.dashFrames=0;
|
| 49 |
+
this.dashFramesTotal=chain?(this.chainLevel===2?21:this.chainLevel===1?29:39):150;
|
| 50 |
+
this.go(c,'attack',this.dashFramesTotal/60,this.move);
|
| 51 |
+
c.emit(chain?'eye_chain_roar':'eye_roar',this.x,this.y);
|
| 52 |
+
};
|
| 53 |
+
P.pauseCharges=function(c,frames){frames=Math.round(frames/this.pace.aggr);this.recoverFrames=frames;this.go(c,'recover',frames/60);};
|
| 54 |
+
P.updateServants=function(c,b){
|
| 55 |
+
this.minions=this.minions.filter(function(m){
|
| 56 |
+
if(m.hp<=0){if(TR.dropMinion)TR.dropMinion(c,this,m);return false;}
|
| 57 |
+
TR.moveToward(m,b.x,b.y,(this.expert?7:6)*TR.PX*this.pace.speed,12);return true;
|
| 58 |
+
},this);
|
| 59 |
+
};
|
| 60 |
+
P.updateArmor=function(){
|
| 61 |
+
if(this.phase===1){this.defense=12;this.dmg=TR.paceDmg(this,this.expert?30:15);return;}
|
| 62 |
+
var frac=this.hp/this.max_hp;
|
| 63 |
+
this.defense=this.expert&&frac<0.04?-30:this.expert&&frac<0.12?-15:0;
|
| 64 |
+
this.dmg=TR.paceDmg(this,this.expert?(frac<0.04?40:36):23);
|
| 65 |
+
};
|
| 66 |
+
P.onNailHit=function(c,base,dir,f,id){this.updateArmor();return TR.damageBoss(this,c,base,id);};
|
| 67 |
+
P.update=function(c){
|
| 68 |
+
if(this.st==='dead'||this.despawned)return;this.clock(c);var dt=BB.DT,b=c.body.centre();
|
| 69 |
+
if(TR.isDaytime&&TR.isDaytime(c)&&!this.dawnDeparting){
|
| 70 |
+
this.dawnDeparting=true;this.st='despawn';this.timer=1e9;this.stT=0;this.move=null;
|
| 71 |
+
this.vy=Math.max(4*TR.PX,this.vy);c.emit('eye_dawn_flee',this.x,this.y);
|
| 72 |
+
}
|
| 73 |
+
if(this.dawnDeparting){
|
| 74 |
+
// Night-only bosses depart upward rather than vanishing in place when dawn arrives.
|
| 75 |
+
this.vx*=0.98;this.vy=Math.min(10*TR.PX,this.vy+0.2*TR.PG*dt);
|
| 76 |
+
this.x+=this.vx*dt;this.y+=this.vy*dt;this.updateServants(c,b);
|
| 77 |
+
if(this.y-this.h/2>BB.ARENA.H){this.despawned=true;this.minions=[];this.shots=[];c.emit('eye_dawn_despawn',this.x,this.y);}
|
| 78 |
+
return;
|
| 79 |
+
}
|
| 80 |
+
// Mode gates are discrete. At exactly the threshold the original first form remains active.
|
| 81 |
+
if(this.phase===1&&this.hp/this.max_hp<this.phaseAt){
|
| 82 |
+
this.phase=2;this.dashesLeft=0;this.pendingChain=false;this.transformFrames=0;
|
| 83 |
+
this.vx=this.vy=0;this.go(c,'transform',200/60,'transform');
|
| 84 |
+
c.emit('boss_escalate',this.x,this.y);
|
| 85 |
+
if(this.expert){var count=4+c.rng.int(2);for(var s=0;s<count;s++)this.spawnServant(c,(s-(count-1)/2)*0.35);}
|
| 86 |
+
}
|
| 87 |
+
this.updateArmor();
|
| 88 |
+
if(this.st==='idle'){
|
| 89 |
+
this.hoverFrames++;
|
| 90 |
+
TR.moveToward(this,b.x,Math.min(BB.ARENA.H-this.h/2,b.y+200/32),(this.expert?7:5)*TR.PX*this.pace.speed,this.expert?18:9);
|
| 91 |
+
if(this.phase===1){
|
| 92 |
+
this.spawnTimer-=dt;
|
| 93 |
+
if(this.spawnTimer<=0&&this.servantsThisHover<this.servantsPerHover){
|
| 94 |
+
this.spawnServant(c,0);this.servantsThisHover++;this.spawnTimer=(this.expert?1.25:1.8)/this.pace.aggr;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
if(this.hoverFrames>=this.hoverLimit())this.startDashes(c,this.expert&&this.phase===2&&this.hp/this.max_hp<0.12);
|
| 98 |
+
}else if(this.st==='transform'){
|
| 99 |
+
this.vx=this.vy=0;this.transformFrames++;this.rotation+=Math.max(0,100-Math.abs(100-this.transformFrames))*0.005;
|
| 100 |
+
// The original Eye remains vulnerable during the transformation.
|
| 101 |
+
if(this.transformFrames>=200)this.startDashes(c,false);
|
| 102 |
+
}else if(this.st==='attack'){
|
| 103 |
+
this.dashFrames++;this.dashAge=this.dashFrames/60;
|
| 104 |
+
if(this.move==='dash'&&this.dashFrames>40){this.vx*=0.98;this.vy*=0.98;}
|
| 105 |
+
this.x=BB.clamp(this.x+this.vx*dt,this.w/2,BB.ARENA.W-this.w/2);
|
| 106 |
+
this.y=BB.clamp(this.y+this.vy*dt,this.h/2,BB.ARENA.H-this.h/2);
|
| 107 |
+
if(this.dashFrames>=this.dashFramesTotal){
|
| 108 |
+
this.dashesLeft--;
|
| 109 |
+
if(this.dashesLeft>0)this.pauseCharges(c,this.move==='chain_dash'?(this.chainLevel===2?1:this.chainLevel===1?5:12):1);
|
| 110 |
+
else if(this.expert&&this.phase===2){
|
| 111 |
+
if(this.move==='dash'){this.pendingChain=true;this.pauseCharges(c,21);}
|
| 112 |
+
else if(this.hp/this.max_hp<0.12){this.pendingChain=true;this.pauseCharges(c,this.hp/this.max_hp<0.04?1:7);}
|
| 113 |
+
else this.startHover(c);
|
| 114 |
+
}else this.startHover(c);
|
| 115 |
+
}
|
| 116 |
+
}else if(this.st==='recover'){
|
| 117 |
+
this.vx*=0.98;this.vy*=0.98;
|
| 118 |
+
this.recoverFrames--;
|
| 119 |
+
if(this.recoverFrames<=0){if(this.pendingChain){this.pendingChain=false;this.startDashes(c,true);}else this.launch(c);}
|
| 120 |
+
}
|
| 121 |
+
this.updateServants(c,b);
|
| 122 |
+
};
|
| 123 |
+
P.hazards=function(){return this.st==='dead'||this.despawned?[]:[{kind:this.phase===2?'maw':'eye',box:this.bodyBox(),dmg:this.dmg,fromX:this.x}].concat(TR.extraHazards(this));};
|
| 124 |
+
BB.CASES['terraria/eye_of_cthulhu'] = TR.register('eye_of_cthulhu','Charging Giant Eye',Eye,'night');
|
| 125 |
+
})(typeof window!=='undefined'?window:globalThis);
|