hughe update

This commit is contained in:
2026-11-15 17:08:11 +01:00
parent 7a69651b6d
commit 319436a5f9
50 changed files with 1987 additions and 313 deletions

View File

@@ -15,10 +15,15 @@
// Arena definitions. `half` = floor from -half..half. Hazards scale with the size. The active arena is
// RC.ARENA; a fight snapshots it into s.arena so several arenas can exist. render3d.js reads s.arena.
function arena(o) {
const h = o.half, g = h - 1.75; // guardian corners
const h = o.half, shape = o.shape || 'square';
// guardians sit in the corners of a square arena; on a round/octagon floor they move inwards
// along the diagonal, otherwise they would stand outside the wall
const g = (h - 1.75) * (shape === 'square' ? 1 : shape === 'round' ? 0.7 : 0.66);
return {
id: o.id, name: o.name, theme: o.theme || 'steel', half: h,
duration: 120, pitOpensAt: 60,
shape: o.shape || 'square', // square | octagon | round
blocks: o.blocks || [], belts: o.belts || [], oil: o.oil || [], rams: o.rams || [],
duration: 120, pitOpensAt: o.pitOpensAt || 60,
pit: { x: 0, z: o.pitZ != null ? o.pitZ : h * 0.52, hw: o.pitW || 1.35, hd: o.pitW || 1.35 },
saws: o.saws, flames: o.flames,
press: { x: g, z: -g, hw: 1.6, hd: 1.6 }, // guardian 1: forge press (corner)
@@ -28,17 +33,49 @@
}
const saw = (x, z, phase) => ({ x, z, r: 0.95, period: 6, on: 2.2, phase });
const flame = (x, z, phase) => ({ x, z, hw: 0.9, hd: 0.9, period: 7, on: 1.8, phase });
const saw2 = saw, flame2 = flame;
const block = (kind, x, z, hw, hd, h2) => ({ kind, x, z, hw, hd, h: h2 || 0.8 });
const belt = (x, z, hw, hd, ax, az, force) => ({ x, z, hw, hd, ax, az, force });
const ram = (x, z, hw, hd, nx, nz, phase) => ({ x, z, hw, hd, nx, nz, period: 5, on: 1.3, phase });
RC.ARENAS = [
arena({ id: 'workshop', name: 'Workshop Pit', theme: 'steel', half: 8,
// tight starter pit: two scrap heaps are the only cover
arena({ id: 'workshop', name: 'Workshop Pit', theme: 'steel', half: 8, shape: 'square',
saws: [saw(-3.2, -3.4, 0), saw(3.2, -3.4, 3)],
flames: [flame(-2.7, 3.3, 1), flame(2.7, 3.3, 4.5)] }),
arena({ id: 'foundry', name: 'The Foundry', theme: 'lava', half: 12, pitW: 1.7,
flames: [flame(-2.7, 3.3, 1), flame(2.7, 3.3, 4.5)],
blocks: [block('scrap', -2.7, -1.2, 0.8, 0.8), block('scrap', 2.7, -1.2, 0.8, 0.8)] }),
// wreck yard: lots of cover and two oil slicks that kill your steering
arena({ id: 'scrapyard', name: 'Scrapyard', theme: 'steel', half: 10, shape: 'square', pitW: 1.5,
saws: [saw(-4, -4, 0), saw(4, -4, 2.5), saw(0, 4.5, 1.5)],
flames: [flame(-5.5, 2, 0), flame(5.5, 2, 3), flame(0, -6, 2)],
blocks: [block('scrap', -3.8, -1.5, 1.0, 0.9, 1.0), block('scrap', 3.8, -1.5, 1.0, 0.9, 1.0),
block('scrap', 0, -5.2, 1.4, 0.8, 0.9), block('crate', -2.8, 3.0, 0.6, 0.6, 0.7), block('crate', 2.8, 3.0, 0.6, 0.6, 0.7)],
oil: [{ x: -2.4, z: 1.0, r: 1.6 }, { x: 2.6, z: -3.4, r: 1.5 }] }),
// foundry: a belt drags you sideways into the flame channel
arena({ id: 'foundry', name: 'The Foundry', theme: 'lava', half: 12, shape: 'octagon', pitW: 1.7,
saws: [saw(-5, -4.5, 0), saw(5, -4.5, 3), saw(0, 4.5, 1.5)],
flames: [flame(-4.5, 1, 0), flame(4.5, 1, 3.5), flame(0, -7.5, 2), flame(-7, 6, 5)] }),
arena({ id: 'arena64', name: 'Mega Dome', theme: 'blue', half: 16, pitW: 2.1,
flames: [flame(-4.5, 1, 0), flame(4.5, 1, 3.5), flame(0, -7.5, 2), flame(-7, 6, 5)],
blocks: [block('barrier', -6.2, -5, 1.3, 0.4, 0.6), block('barrier', 6.2, -5, 1.3, 0.4, 0.6)],
belts: [belt(0, 1, 4.0, 1.1, 1, 0, 9)] }),
// crucible: one pillar in the middle, two wall rams punching inwards
arena({ id: 'crucible', name: 'The Crucible', theme: 'lava', half: 14, shape: 'round', pitW: 1.9,
saws: [saw(-5.5, -5, 0), saw(5.5, -5, 3), saw(-5.5, 5, 1.5), saw(5.5, 5, 4.5)],
flames: [flame(-6, 1.5, 0), flame(6, 1.5, 3), flame(0, 8, 2), flame(0, -8, 4.5)],
blocks: [block('pillar', 0, 0, 1.1, 1.1, 1.8)],
rams: [ram(-11.8, 0, 1.5, 2.2, 1, 0, 0), ram(11.8, 0, 1.5, 2.2, -1, 0, 2.5)] }),
// dome: four pillars to duck behind, and the pit opens early
arena({ id: 'arena64', name: 'Mega Dome', theme: 'blue', half: 16, shape: 'octagon', pitW: 2.1, pitOpensAt: 80,
saws: [saw(-6.5, -6, 0), saw(6.5, -6, 3), saw(-6.5, 6, 1.5), saw(6.5, 6, 4.5), saw(0, 0, 2)],
flames: [flame(-8, 2, 0), flame(8, 2, 2), flame(0, 9, 4), flame(0, -9, 1), flame(-10, -4, 3), flame(10, -4, 5)] }),
flames: [flame(-8, 2, 0), flame(8, 2, 2), flame(0, 9, 4), flame(0, -9, 1), flame(-10, -4, 3), flame(10, -4, 5)],
blocks: [block('pillar', -5, -5, 0.9, 0.9, 2.0), block('pillar', 5, -5, 0.9, 0.9, 2.0),
block('pillar', -5, 5, 0.9, 0.9, 2.0), block('pillar', 5, 5, 0.9, 0.9, 2.0)] }),
// colosseum: huge, a wreck mound in the centre and two belts feeding the pit
arena({ id: 'colosseum', name: 'Grand Colosseum', theme: 'blue', half: 20, shape: 'round', pitW: 2.4,
saws: [saw(-8, -7, 0), saw(8, -7, 3), saw(-8, 7, 1.5), saw(8, 7, 4.5), saw(0, -11, 3.5)],
flames: [flame(-10, 2, 0), flame(10, 2, 2), flame(0, 13, 4), flame(0, -13, 1), flame(-13, -5, 3), flame(13, -5, 5)],
blocks: [block('scrap', 0, 0, 2.0, 1.6, 1.3), block('crate', -7, -2, 0.8, 0.8, 0.9), block('crate', 7, -2, 0.8, 0.8, 0.9)],
belts: [belt(-3.6, 6.5, 1.3, 3.0, 0, 1, 9), belt(3.6, 6.5, 1.3, 3.0, 0, 1, 9)] }),
];
let ARENA = RC.ARENAS[0];
RC.ARENA = ARENA;
RC.setArena = id => { ARENA = RC.ARENAS.find(a => a.id === id) || RC.ARENAS[0]; RC.ARENA = ARENA; return ARENA; };
@@ -50,6 +87,44 @@
let s = seed >>> 0 || 1;
return () => { s = (s + 0x6d2b79f5) >>> 0; let t = s; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
}
// Keep a point inside the arena outline. null = clear of the wall, otherwise the corrected
// spot plus the wall normal pointing INTO the arena. Used by the physics, the AI and the map.
function wallPush(A, x, z, rad) {
const lim = A.half - rad;
if (A.shape === 'round') {
const d = Math.hypot(x, z);
if (d <= lim || d < 1e-6) return null;
return { x: (x / d) * lim, z: (z / d) * lim, nx: -x / d, nz: -z / d };
}
let cx = x, cz = z, nx = 0, nz = 0, hit = false;
if (cx > lim) { cx = lim; nx = -1; hit = true; } else if (cx < -lim) { cx = -lim; nx = 1; hit = true; }
if (cz > lim) { cz = lim; nz = -1; hit = true; } else if (cz < -lim) { cz = -lim; nz = 1; hit = true; }
if (A.shape === 'octagon') { // four corner cuts: |x| + |z| <= dlim
const dlim = lim * 1.34, sx = Math.sign(cx) || 1, sz = Math.sign(cz) || 1;
const over = Math.abs(cx) + Math.abs(cz) - dlim;
if (over > 0) {
cx -= sx * over / 2; cz -= sz * over / 2;
nx = -sx * Math.SQRT1_2; nz = -sz * Math.SQRT1_2; hit = true;
}
}
if (!hit) return null;
const len = Math.hypot(nx, nz) || 1;
return { x: cx, z: cz, nx: nx / len, nz: nz / len };
}
// Is this spot inside a static obstacle? Returns the push-out normal, or null.
function blockPush(A, r, rad) {
for (const b of A.blocks) {
const dx = r.x - b.x, dz = r.z - b.z;
const ox = b.hw + rad - Math.abs(dx), oz = b.hd + rad - Math.abs(dz);
if (ox <= 0 || oz <= 0) continue;
if (ox < oz) { const sx = Math.sign(dx) || 1; r.x = b.x + sx * (b.hw + rad); return { nx: sx, nz: 0 }; }
const sz = Math.sign(dz) || 1; r.z = b.z + sz * (b.hd + rad); return { nx: 0, nz: sz };
}
return null;
}
RC.wallPush = wallPush;
RC.inBlock = (A, x, z, m = 0) => A.blocks.some(b => Math.abs(x - b.x) < b.hw + m && Math.abs(z - b.z) < b.hd + m);
const inRect = (o, x, z, m = 0) => Math.abs(x - o.x) < o.hw + m && Math.abs(z - o.z) < o.hd + m;
const hazardOn = (h, t) => ((t + h.phase) % h.period) < h.on;
RC.hazardOn = hazardOn;
@@ -60,6 +135,9 @@
i, name, st, x: p.x, z: p.z, a: p.a, vx: 0, vz: 0, av: 0, y: 0, vy: 0,
hp: st.hp, maxHp: st.hp, dead: false, out: null, fall: 0,
flipped: 0, stun: 0, lifted: 0, grabbedBy: null, grab: 0,
shield: 0, gcd: 0, gUses: st.gadget && st.gadget.charges || 0,
lost: { armour: false, wheels: false, weapon: false, tower: false }, // parts torn off during the fight
onOil: false, // standing in a slick: less grip, lazy steering
cd: 0, cd2: 0, spin: 0, swing: 0, flipAnim: 0, boost: 0, sawOn: false, flameOn: false, gunOn: false,
turretA: p.a, dealt: 0, taken: 0, pressT: 0, craneT: 0, fx: 0,
};
@@ -78,6 +156,28 @@
return s;
}
// a part that broke off no longer works (and bare metal takes more damage)
const weaponOf = r => (r.lost.weapon ? null : r.st.weapon);
const towerOf = r => (r.lost.tower ? null : r.st.tower);
const reduceOf = r => (r.lost.armour ? r.st.reduce * 0.3 : r.st.reduce);
// battle damage: at these shares of health the next hit tears a part off (no randomness,
// so both sides of an online fight and the tests see exactly the same thing)
const BREAK_AT = [['armour', 0.6], ['wheels', 0.4], ['weapon', 0.25], ['tower', 0.18]];
function breakCheck(s, r) {
if (r.dead || r.out) return;
const f = r.hp / r.maxHp;
for (const [part, at] of BREAK_AT) {
if (r.lost[part] || f >= at) continue;
if (part === 'armour' && !r.st.armour) continue;
if (part === 'weapon' && !r.st.weapon) continue;
if (part === 'tower' && !r.st.tower) continue;
r.lost[part] = true;
if (part === 'weapon') { r.spin = 0; r.swing = 0; if (r.grab > 0) release(s, r, s.robots[1 - r.i]); }
s.events.push({ type: 'broke', who: r.i, part, x: r.x, z: r.z });
}
}
const fwd = r => [Math.cos(r.a), Math.sin(r.a)];
// enemy position in my frame: [forward, side]
function local(me, e) {
@@ -86,7 +186,7 @@
}
function inZone(s, me, e, extra = 0) {
if (e.out || me.out) return false;
const w = me.st.weapon; if (!w) return false;
const w = weaponOf(me); if (!w) return false;
const [lf, ls] = local(me, e);
return lf > 0 && lf < me.st.len / 2 + w.reach + e.st.rad * 0.75 + extra && Math.abs(ls) < me.st.wid / 2 + e.st.rad * 0.55;
}
@@ -101,7 +201,8 @@
function damage(s, target, amount, src, opt = {}) {
if (target.dead || target.out || amount <= 0 || s.result) return 0;
let d = amount * (1 - target.st.reduce * (1 - (opt.pierce || 0)));
let d = amount * (1 - reduceOf(target) * (1 - (opt.pierce || 0)));
if (target.shield > 0 && target.st.gadget) d *= (1 - (target.st.gadget.reduce || 0.6)); // deflector field
const from = opt.from || src; // where the hit comes from (rockets: impact point)
if (from && !opt.noZone) d *= zoneMul(target, from.x, from.z);
d = Math.min(d, target.hp);
@@ -109,6 +210,7 @@
// judges: hazard damage counts for the opponent (pushing into traps pays off)
if (src) src.dealt += d; else s.robots[1 - target.i].dealt += d;
if (d >= 0.5 || opt.tick) s.events.push({ type: 'dmg', who: target.i, amount: d, x: target.x, z: target.z, tick: !!opt.tick, kind: opt.kind || 'hit' });
breakCheck(s, target);
if (target.hp <= 0.001) {
target.hp = 0; target.dead = true;
s.events.push({ type: 'ko', who: target.i, x: target.x, z: target.z });
@@ -138,6 +240,7 @@
for (let k = 0; k < 2; k++) drive(s, R[k], R[1 - k], (s.result ? null : inputs[k]) || {}, dt);
collide(s, R[0], R[1], dt);
for (let k = 0; k < 2; k++) gadgets(s, R[k], R[1 - k], (s.result ? null : inputs[k]) || {}, dt);
for (let k = 0; k < 2; k++) weapons(s, R[k], R[1 - k], (s.result ? null : inputs[k]) || {}, dt);
rockets(s, dt);
hazards(s, dt);
@@ -165,17 +268,19 @@
let vf = r.vx * fx + r.vz * fz, vs = -r.vx * fz + r.vz * fx;
if (canDrive) {
const thr = clamp(inp.throttle || 0, -1, 1), trn = clamp(inp.turn || 0, -1, 1);
let top = st.top * (r.boost > 0 ? 1.65 : 1) * (r.grab > 0 ? 0.6 : 1) * (thr < 0 ? 0.75 : 1);
const target = thr * top, acc = st.accel * (r.boost > 0 ? 2 : 1);
const hurt = r.lost.wheels ? 0.75 : 1; // burst wheel: slower, clumsier
const oil = r.onOil ? 0.55 : 1; // oil slick: hardly any steering
let top = st.top * hurt * (r.boost > 0 ? 1.65 : 1) * (r.grab > 0 ? 0.6 : 1) * (thr < 0 ? 0.75 : 1);
const target = thr * top, acc = st.accel * (r.lost.wheels ? 0.85 : 1) * (r.boost > 0 ? 2 : 1);
const braking = Math.abs(target) < Math.abs(vf) || target * vf < 0;
const rate = acc * (braking ? 1.6 : 1) * dt;
vf += clamp(target - vf, -rate, rate);
r.av += (trn * st.turn - r.av) * Math.min(1, 12 * dt);
r.av += (trn * st.turn * (r.lost.wheels ? 0.8 : 1) * oil - r.av) * Math.min(1, 12 * dt);
} else {
r.av *= Math.max(0, 1 - 6 * dt);
}
if (grounded && !held) {
vs *= Math.max(0, 1 - st.grip * dt);
vs *= Math.max(0, 1 - st.grip * (r.onOil ? 0.3 : 1) * dt);
if (!canDrive) vf *= Math.max(0, 1 - 2.5 * dt);
else if (!(inp.throttle)) vf *= Math.max(0, 1 - 3 * dt);
}
@@ -195,22 +300,32 @@
}
}
// spike walls
const lim = s.arena.half - st.rad * 0.9;
for (const ax of ['x', 'z']) {
const vk = ax === 'x' ? 'vx' : 'vz';
if (Math.abs(r[ax]) > lim) {
const sgn = Math.sign(r[ax]), vn = r[vk] * sgn;
r[ax] = sgn * lim;
if (vn > 0) {
if (vn > 1.8 && !r.out) {
s.events.push({ type: 'wall', who: r.i, x: r.x, z: r.z, speed: vn });
damage(s, r, (vn - 1.8) * 4.5, null, { kind: 'spikes' });
// slammed into the spikes hard -> bounces up and can land on its back
if (vn > 3.5 && r.y < 0.05 && !r.st.invertible && !r.st.lowProfile && s.rand() < 0.3) { r.vy = Math.max(r.vy, 2); r.flipped = 2.2; r.av += (s.rand() - 0.5) * 6; }
}
r[vk] = -r[vk] * 0.45;
// spike walls (follow the arena outline: square, octagon or round)
const rad = st.rad * 0.9;
const w = wallPush(s.arena, r.x, r.z, rad);
if (w) {
r.x = w.x; r.z = w.z;
const vn = -(r.vx * w.nx + r.vz * w.nz); // speed straight into the wall
if (vn > 0) {
if (vn > 1.8 && !r.out) {
s.events.push({ type: 'wall', who: r.i, x: r.x, z: r.z, speed: vn });
damage(s, r, (vn - 1.8) * 4.5, null, { kind: 'spikes' });
// slammed into the spikes hard -> bounces up and can land on its back
if (vn > 3.5 && r.y < 0.05 && !r.st.invertible && !r.st.lowProfile && s.rand() < 0.3) { r.vy = Math.max(r.vy, 2); r.flipped = 2.2; r.av += (s.rand() - 0.5) * 6; }
}
r.vx += w.nx * vn * 1.45; r.vz += w.nz * vn * 1.45; // bounce (0.45 restitution)
}
}
// static obstacles: drive into one and you stop, hit it hard and it hurts
const bp = blockPush(s.arena, r, rad);
if (bp) {
const vn = -(r.vx * bp.nx + r.vz * bp.nz);
if (vn > 0) {
if (vn > 2.2 && !r.out) {
s.events.push({ type: 'wall', who: r.i, x: r.x, z: r.z, speed: vn });
damage(s, r, (vn - 2.2) * 2.6, null, { kind: 'ram' });
}
r.vx += bp.nx * vn * 1.3; r.vz += bp.nz * vn * 1.3;
}
}
}
@@ -241,7 +356,7 @@
const facing = fx * sx + fz * sz;
const myV = me.vx * sx + me.vz * sz;
if (facing > 0.55 && myV > 1.2) {
const w = me.st.weapon;
const w = weaponOf(me);
const ram = w && w.type === 'wedge' ? w.ram : 1;
damage(s, e, (impact - 1) * 2.2 * ram, me, { kind: 'ram' });
// a wedge scoops lighter robots up; any hard enough ram can send one tumbling onto its roof
@@ -259,7 +374,7 @@
function weapons(s, r, e, inp, dt) {
const ok = !r.dead && !r.out && r.lifted <= 0 && r.grabbedBy === null && r.flipped <= 0;
const w = r.st.weapon, [fx, fz] = fwd(r);
const w = weaponOf(r), [fx, fz] = fwd(r);
r.sawOn = false; r.flameOn = false; r.gunOn = false;
if (r.swing > 0) { // hammer comes down
r.swing -= dt;
@@ -314,6 +429,33 @@
s.events.push({ type: 'grab', who: r.i, x: e.x, z: e.z });
}
break;
case 'lifter':
// scoop: tips the enemy up again and again (short cooldown) - made for shoving into the pit
if (inp.fire && r.cd <= 0) {
r.cd = w.cd; r.flipAnim = 0.3;
s.events.push({ type: 'flip', who: r.i, x: r.x + fx, z: r.z + fz });
if (inZone(s, r, e) && e.y < 0.2 && e.grabbedBy === null && e.lifted <= 0) {
const light = Math.sqrt(70 / e.st.mass);
e.vy = Math.max(e.vy, w.launch * light * 0.8);
e.vx += fx * 1.6 * light; e.vz += fz * 1.6 * light;
e.stun = Math.max(e.stun, 0.3); // wheels off the floor: no steering
damage(s, e, w.dmg, r, { kind: 'flip' });
}
}
break;
case 'vspinner':
// vertical disc: throws the enemy into the air instead of sideways
r.spin = inp.fire ? Math.min(1, r.spin + dt / w.spinup) : Math.max(0, r.spin - dt * 0.35);
if (r.spin > 0.25 && r.cd <= 0 && inZone(s, r, e)) {
const k = r.spin, light = Math.sqrt(70 / e.st.mass);
damage(s, e, w.dmg * k, r, { kind: 'spin' });
e.vy = Math.max(e.vy, 6.5 * k * light);
e.vx += fx * 1.5 * k; e.vz += fz * 1.5 * k; e.av += 7 * k;
if (!e.st.invertible && s.rand() < 0.5 * k) e.flipped = 2.2;
r.spin *= 0.3; r.cd = 0.35;
s.events.push({ type: 'spinhit', who: r.i, x: (r.x + e.x) / 2, z: (r.z + e.z) / 2, k });
}
break;
case 'spinner':
r.spin = inp.fire ? Math.min(1, r.spin + dt / w.spinup) : Math.max(0, r.spin - dt * 0.35);
if (r.spin > 0.25 && r.cd <= 0 && inZone(s, r, e)) {
@@ -327,27 +469,45 @@
}
break;
}
} else if (w && w.type === 'spinner') r.spin = Math.max(0, r.spin - dt * 0.5);
} else if (w && (w.type === 'spinner' || w.type === 'vspinner')) r.spin = Math.max(0, r.spin - dt * 0.5);
// turret: turns towards the enemy by itself
const t = r.st.tower;
// turret is bolted facing forward: you aim it by turning the robot, it does not track the enemy
const t = towerOf(r);
if (!t) return;
const want = Math.atan2(e.z - r.z, e.x - r.x), diff = wrap(want - r.turretA);
r.turretA = wrap(r.turretA + clamp(diff, -3.2 * dt, 3.2 * dt));
r.turretA = r.a;
if (!ok || !inp.fire2) return;
const want = Math.atan2(e.z - r.z, e.x - r.x);
const dist = Math.hypot(e.x - r.x, e.z - r.z), aimed = Math.abs(wrap(want - r.turretA));
if (t.type === 'flamer') {
r.flameOn = true;
if (dist < t.range + e.st.rad && aimed < t.cone && !e.out) damage(s, e, t.dps * dt, r, { pierce: 0.5, noZone: true, kind: 'fire', tick: true });
} else if (t.type === 'minigun') {
r.gunOn = aimed < 0.25;
if (r.gunOn && dist < t.range && !e.out) {
r.gunOn = true; // always fires straight ahead, hits only what is in front
if (aimed < 0.25 && dist < t.range && !e.out) {
damage(s, e, t.dps * dt, r, { kind: 'bullet', tick: true });
r.fx -= dt; if (r.fx <= 0) { r.fx = 0.08; s.events.push({ type: 'sparks', x: e.x, z: e.z, n: 2, y: 0.4 }); }
}
} else if (t.type === 'rockets' && r.cd2 <= 0) {
} else if (t.type === 'zapper') {
r.gunOn = true; // short electric arc straight ahead
if (aimed < 0.4 && dist < t.range + e.st.rad && !e.out) {
damage(s, e, t.dps * dt, r, { pierce: 0.8, noZone: true, kind: 'bullet', tick: true });
e.stun = Math.max(e.stun, 0.12);
}
} else if (t.type === 'mortar' && r.cd2 <= 0) {
r.cd2 = t.cd;
s.rockets.push({ owner: r.i, x: r.x, z: r.z, y: r.st.h + 0.45, a: r.turretA, t: 3.2, sp: 6.5 });
// lobbed shell: flies a real arc and bursts where it lands
const flight = clamp(dist / 9, 0.5, 1.8);
s.rockets.push({ kind: 'mortar', owner: r.i, x: r.x, z: r.z, y: r.st.h + 0.5, a: r.turretA,
sp: Math.min(dist / flight, 14), vy: 9 * flight, t: 5, dmg: t.dmg, splash: t.splash });
s.events.push({ type: 'launch', who: r.i, x: r.x, z: r.z });
} else if ((t.type === 'rockets' || t.type === 'swarm') && r.cd2 <= 0) {
r.cd2 = t.cd;
const swarm = t.type === 'swarm', n = swarm ? (t.shots || 3) : 1;
for (let k = 0; k < n; k++) {
const spread = swarm ? (k - (n - 1) / 2) * 0.35 : 0;
s.rockets.push({ kind: 'rocket', owner: r.i, x: r.x, z: r.z, y: r.st.h + 0.45, a: r.turretA + spread,
t: swarm ? 8 : 5, sp: 6.5, max: swarm ? 13 : 11, turn: swarm ? 3.4 : 2.4, dmg: t.dmg });
}
s.events.push({ type: 'launch', who: r.i, x: r.x, z: r.z });
}
}
@@ -357,21 +517,87 @@
if (e.grabbedBy === r.i) { e.grabbedBy = null; }
}
// gadgets (input.fire3): one-shot abilities on a cooldown
function gadgets(s, r, e, inp, dt) {
r.gcd = Math.max(0, r.gcd - dt);
if (r.shield > 0) r.shield = Math.max(0, r.shield - dt);
const g = r.st.gadget;
if (!g || r.out || r.dead || !inp.fire3 || r.gcd > 0) return;
const held = r.lifted > 0 || r.grabbedBy !== null;
switch (g.type) {
case 'righter': // flip back upright
if (r.flipped > 0) { r.flipped = 0; r.av += (s.rand() - 0.5) * 2; }
r.gcd = g.cd;
s.events.push({ type: 'righted', who: r.i, x: r.x, z: r.z });
break;
case 'turbo': // speed burst (reuses the boost mechanic)
if (held || r.flipped > 0 || r.stun > 0) return;
r.boost = Math.max(r.boost, g.dur); r.gcd = g.cd;
break;
case 'shield': // temporary damage field
r.shield = g.dur; r.gcd = g.cd;
break;
case 'repair': // one charge = flat heal
if (r.gUses <= 0) return;
r.hp = Math.min(r.maxHp, r.hp + r.maxHp * g.heal); r.gUses--; r.gcd = g.cd;
break;
case 'emp': // stun the enemy if close
r.gcd = g.cd;
if (!e.out && Math.hypot(e.x - r.x, e.z - r.z) < g.range + e.st.rad) {
e.stun = Math.max(e.stun, g.stun); e.spin = 0; e.boost = 0; e.shield = 0;
s.events.push({ type: 'emp_hit', who: e.i, x: e.x, z: e.z });
}
break;
}
s.events.push({ type: 'gadget', who: r.i, g: g.type, x: r.x, z: r.z });
}
// should the AI / autofire helper fire the gadget now?
function wantGadget(s, me, e) {
const g = me.st.gadget;
if (!g || me.gcd > 0 || me.out || me.dead) return false;
const dist = e.out ? 999 : Math.hypot(e.x - me.x, e.z - me.z);
switch (g.type) {
case 'righter': return me.flipped > 0;
case 'turbo': return me.flipped <= 0 && me.stun <= 0 && dist > 2 && dist < 9;
case 'shield': return dist < 3 && me.flipped <= 0;
case 'repair': return me.gUses > 0 && me.hp < me.maxHp * 0.45;
case 'emp': return !e.out && dist < g.range * 0.9 && (e.boost > 0 || e.spin > 0.2 || dist < 2.5);
}
return false;
}
function rockets(s, dt) {
for (let i = s.rockets.length - 1; i >= 0; i--) {
const k = s.rockets[i], tgt = s.robots[1 - k.owner], own = s.robots[k.owner];
k.t -= dt;
const wall = () => Math.abs(k.x) > s.arena.half || Math.abs(k.z) > s.arena.half;
if (k.kind === 'mortar') {
// thrown in an arc, bursts on the floor with a blast radius
k.vy -= 17 * dt;
k.x += Math.cos(k.a) * k.sp * dt; k.z += Math.sin(k.a) * k.sp * dt; k.y += k.vy * dt;
const direct = !tgt.out && k.y < 0.9 && Math.hypot(tgt.x - k.x, tgt.z - k.z) < tgt.st.rad + 0.2;
if (direct || k.y <= 0.06 || wall() || k.t <= 0) {
s.events.push({ type: 'boom', x: k.x, z: k.z, y: Math.max(0.12, k.y), big: true });
if (!tgt.out) {
const d = Math.hypot(tgt.x - k.x, tgt.z - k.z);
if (d < k.splash) damage(s, tgt, k.dmg * (1 - (d / k.splash) * 0.6), own, { from: { x: k.x, z: k.z }, kind: 'rocket' });
}
s.rockets.splice(i, 1);
}
continue;
}
// seeker: turns after the target and can chase it across the arena
const want = Math.atan2(tgt.z - k.z, tgt.x - k.x);
if (!tgt.out) k.a = wrap(k.a + clamp(wrap(want - k.a), -2.4 * dt, 2.4 * dt));
k.sp = Math.min(11, k.sp + dt * 6);
if (!tgt.out) k.a = wrap(k.a + clamp(wrap(want - k.a), -(k.turn || 2.4) * dt, (k.turn || 2.4) * dt));
k.sp = Math.min(k.max || 11, k.sp + dt * 6);
k.x += Math.cos(k.a) * k.sp * dt; k.z += Math.sin(k.a) * k.sp * dt;
k.y += ((tgt.y + 0.35) - k.y) * Math.min(1, dt * 3);
const hit = !tgt.out && Math.hypot(tgt.x - k.x, tgt.z - k.z) < tgt.st.rad + 0.1;
const wall = Math.abs(k.x) > s.arena.half || Math.abs(k.z) > s.arena.half;
if (hit || wall || k.t <= 0) {
if (hit || wall() || k.t <= 0) {
s.events.push({ type: 'boom', x: k.x, z: k.z, y: k.y });
if (hit) {
damage(s, tgt, own.st.tower.dmg, own, { from: { x: k.x - Math.cos(k.a), z: k.z - Math.sin(k.a) }, kind: 'rocket' });
damage(s, tgt, k.dmg != null ? k.dmg : 17, own, { from: { x: k.x - Math.cos(k.a), z: k.z - Math.sin(k.a) }, kind: 'rocket' });
tgt.vx += Math.cos(k.a) * 1.6; tgt.vz += Math.sin(k.a) * 1.6;
}
s.rockets.splice(i, 1);
@@ -394,6 +620,15 @@
}
// flame grilles
for (const h of A.flames) if (ground && hazardOn(h, s.t) && inRect(h, r.x, r.z, r.st.rad * 0.3)) damage(s, r, 14 * dt, null, { pierce: 0.5, kind: 'fire', tick: true });
// conveyor belts drag everything that stands on them
for (const b of A.belts) if (ground && inRect(b, r.x, r.z, r.st.rad * 0.2)) { r.vx += b.ax * b.force * dt; r.vz += b.az * b.force * dt; }
// oil slicks (checked here, used by drive() on the next step)
r.onOil = ground && A.oil.some(o => Math.hypot(r.x - o.x, r.z - o.z) < o.r + r.st.rad * 0.4);
// wall rams shove anyone loitering in front of them
for (const m of A.rams) if (ground && hazardOn(m, s.t) && inRect(m, r.x, r.z, r.st.rad * 0.3)) {
r.vx += m.nx * 26 * dt; r.vz += m.nz * 26 * dt;
damage(s, r, 9 * dt, null, { kind: 'ram', tick: true });
}
// pit
if (s.pitOpen >= 1 && ground && r.grabbedBy === null && inRect(A.pit, r.x, r.z, -0.15)) {
r.out = 'pit'; r.vx *= 0.2; r.vz *= 0.2;
@@ -453,6 +688,33 @@
}
}
RC.Combat = { create, step, inZone, local };
// What the HUD shows per equipped slot (no DOM, so Node tests can check it):
// p = share of the cooldown still running (1 = just used, 0 = ready), on = doing its thing right now,
// n = charges left where a part has them (repair kit).
function cooldowns(r) {
const out = [], w = r.st.weapon, t = r.st.tower, g = r.st.gadget;
const broke = k => (r.lost && r.lost[k]) || false;
const frac = (left, full) => (full > 0 ? clamp(left / full, 0, 1) : 0);
if (w) {
const e = { slot: 'weapon', id: w.id, p: 0, on: false, broke: broke('weapon') };
if (w.type === 'saw') e.on = !!r.sawOn;
else if (w.type === 'spinner' || w.type === 'vspinner') { e.p = 1 - clamp(r.spin, 0, 1); e.on = r.spin > 0.25; }
else {
e.p = frac(r.cd, w.cd);
e.on = (w.type === 'hammer' && r.swing > 0) || (w.type === 'crusher' && r.grab > 0) || (w.type === 'wedge' && r.boost > 0);
}
out.push(e);
}
if (t) {
const e = { slot: 'tower', id: t.id, p: 0, on: false, broke: broke('tower') };
if (t.type === 'rockets' || t.type === 'mortar' || t.type === 'swarm') e.p = frac(r.cd2, t.cd);
else e.on = t.type === 'flamer' ? !!r.flameOn : !!r.gunOn; // minigun + zapper
out.push(e);
}
if (g) out.push({ slot: 'gadget', id: g.id, p: frac(r.gcd, g.cd), on: r.shield > 0 || (g.type === 'turbo' && r.boost > 0), n: g.charges ? r.gUses : undefined });
return out;
}
RC.Combat = { create, step, inZone, local, wantGadget, cooldowns };
if (typeof module !== 'undefined' && module.exports) module.exports = RC;
})(typeof window !== 'undefined' ? window : globalThis);