hughe update
This commit is contained in:
47
game/ai.js
47
game/ai.js
@@ -6,16 +6,19 @@
|
||||
(function (root) {
|
||||
'use strict';
|
||||
const RC = (root.RC = root.RC || {});
|
||||
const A = () => RC.ARENA;
|
||||
const clamp = (v, a, b) => (v < a ? a : v > b ? b : v);
|
||||
const wrap = a => { while (a > Math.PI) a -= 2 * Math.PI; while (a < -Math.PI) a += 2 * Math.PI; return a; };
|
||||
|
||||
function danger(s, x, z, me) {
|
||||
const ar = A(), m = 0.35;
|
||||
const ar = s.arena || RC.ARENA, m = 0.35;
|
||||
if (s.left < ar.pitOpensAt + 2 && Math.abs(x - ar.pit.x) < ar.pit.hw + me.st.rad && Math.abs(z - ar.pit.z) < ar.pit.hd + me.st.rad) return 3;
|
||||
for (const h of ar.saws) if (RC.hazardOn(h, s.t + 0.4) && Math.hypot(x - h.x, z - h.z) < h.r + me.st.rad) return 2;
|
||||
for (const h of ar.flames) if (RC.hazardOn(h, s.t + 0.4) && Math.abs(x - h.x) < h.hw + m && Math.abs(z - h.z) < h.hd + m) return 2;
|
||||
for (const g of [ar.press, ar.crane]) if (Math.abs(x - g.x) < g.hw + m && Math.abs(z - g.z) < g.hd + m) return 2;
|
||||
for (const r of ar.rams || []) if (RC.hazardOn(r, s.t + 0.4) && Math.abs(x - r.x) < r.hw + m && Math.abs(z - r.z) < r.hd + m) return 2;
|
||||
// solid cover and slicks: drive round them, they are not deadly
|
||||
for (const b of ar.blocks || []) if (Math.abs(x - b.x) < b.hw + me.st.rad && Math.abs(z - b.z) < b.hd + me.st.rad) return 1;
|
||||
for (const o of ar.oil || []) if (Math.hypot(x - o.x, z - o.z) < o.r) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -52,23 +55,21 @@
|
||||
const back = e.a + Math.PI + (rand() < 0.5 ? 0.9 : -0.9);
|
||||
tx = e.x + Math.cos(back) * 1.8; tz = e.z + Math.sin(back) * 1.8;
|
||||
} else if (style === 'pusher') { // line up enemy -> pit (or press corner) and shove
|
||||
const ar = A(), goal = s.pitOpen >= 1 ? ar.pit : ar.press;
|
||||
const ar = s.arena, goal = s.pitOpen >= 1 ? ar.pit : ar.press;
|
||||
const gx = goal.x - e.x, gz = goal.z - e.z, gl = Math.hypot(gx, gz) || 1;
|
||||
const bx = e.x - gx / gl * 1.6, bz = e.z - gz / gl * 1.6;
|
||||
const lined = Math.hypot(me.x - bx, me.z - bz) < 1.0 || dist < me.st.rad + e.st.rad + 0.25;
|
||||
if (!lined && dist > 1.1) { tx = bx; tz = bz; }
|
||||
} else if (style === 'gunner' && t) { // keep distance, circle
|
||||
const want = t.type === 'flamer' ? 1.8 : 4.2;
|
||||
if (dist < want) {
|
||||
const away = Math.atan2(me.z - e.z, me.x - e.x) + 0.9;
|
||||
tx = e.x + Math.cos(away) * want; tz = e.z + Math.sin(away) * want;
|
||||
}
|
||||
} else if (style === 'gunner' && t) { // face the enemy (fixed turret), hold the range
|
||||
tx = e.x; tz = e.z;
|
||||
}
|
||||
let cmd = steer(me, tx, tz, 0.75 + skill * 0.25);
|
||||
// gunner too close: back off but keep the nose (and the turret) on the enemy
|
||||
if (style === 'gunner' && t && dist < ((t.type === 'flamer' || t.type === 'zapper') ? 1.4 : 2.8)) cmd = { turn: cmd.turn, throttle: -0.7 };
|
||||
|
||||
// avoid hazards in front (skilled robots look further)
|
||||
const look = 0.9 + skill * 1.0, fx = Math.cos(me.a), fz = Math.sin(me.a);
|
||||
const dng = danger(s, me.x + fx * look, me.z + fz * look, me);
|
||||
const dng = danger(s, me.x + fx * look, me.z + fz * look, me); // includes blocks + oil now
|
||||
// enemy right in front and closer than the hazard: keep attacking (it lands in there, not me)
|
||||
const enemyAhead = dist < look + me.st.rad + e.st.rad && Math.abs(wrap(Math.atan2(e.z - me.z, e.x - me.x) - me.a)) < 0.6;
|
||||
if (dng && !enemyAhead && (dng === 3 || dist > 2.2) && rand() < 0.3 + skill * 0.6) {
|
||||
@@ -85,7 +86,7 @@
|
||||
const pushing = style === 'pusher' && s.pitOpen >= 1;
|
||||
contact = rammer && !pushing && dist < me.st.rad + e.st.rad + 0.3 ? contact + react : 0;
|
||||
// only back off with room behind (no spike wall, no trap)
|
||||
const half = A().half - me.st.rad - 0.4;
|
||||
const half = s.arena.half - me.st.rad - 0.4;
|
||||
const bx = me.x - fx * 1.4, bz = me.z - fz * 1.4;
|
||||
const roomBehind = Math.abs(bx) < half && Math.abs(bz) < half && !danger(s, bx, bz, me);
|
||||
if (contact > 0.45 && retreat <= 0 && roomBehind && rand() < 0.25 + skill * 0.7) { retreat = 0.35 + rand() * 0.3; contact = 0; }
|
||||
@@ -101,12 +102,18 @@
|
||||
const out = { throttle: h.throttle, turn: h.turn, fire: false, fire2: false };
|
||||
if (style === 'dummy') return out;
|
||||
if (w) {
|
||||
if (w.type === 'spinner') out.fire = dist < 6;
|
||||
if (w.type === 'spinner' || w.type === 'vspinner') out.fire = dist < 6;
|
||||
else if (w.type === 'lifter') out.fire = inZ && rand() < 0.5 + skill * 0.5;
|
||||
else if (w.type === 'saw') out.fire = dist < 2.6;
|
||||
else if (w.type === 'wedge') out.fire = dist > 1.6 && dist < 4.5 && Math.abs(wrap(Math.atan2(e.z - me.z, e.x - me.x) - me.a)) < 0.25 && rand() < 0.08 + skill * 0.1;
|
||||
else out.fire = inZ && rand() < 0.25 + skill * 0.7;
|
||||
}
|
||||
if (t) out.fire2 = dist < t.range * (t.type === 'flamer' ? 1.05 : 0.9);
|
||||
if (t) {
|
||||
const ahead = Math.abs(wrap(Math.atan2(e.z - me.z, e.x - me.x) - me.a));
|
||||
const close = t.type === 'flamer' || t.type === 'zapper';
|
||||
out.fire2 = dist < t.range * (close ? 1.05 : 0.9) && ahead < (close ? 0.5 : 0.3);
|
||||
}
|
||||
if (me.st.gadget) out.fire3 = RC.Combat.wantGadget(s, me, e);
|
||||
return out;
|
||||
}
|
||||
return { think };
|
||||
@@ -115,21 +122,21 @@
|
||||
const pal = (body, accent) => ({ body, accent });
|
||||
RC.LEAGUE = [
|
||||
{ id: 'rustbucket', name: 'Rustbucket', style: 'brawler', skill: 0.1, prize: 250,
|
||||
build: { chassis: 'crate', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'wedge', tower: null }, paint: pal(0x8a5a3a, 0xd9a066) },
|
||||
build: { chassis: 'cage', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'wedge', tower: null }, paint: pal(0x8a5a3a, 0xd9a066) },
|
||||
{ id: 'tintoad', name: 'Tin Toad', style: 'pusher', skill: 0.2, prize: 330,
|
||||
build: { chassis: 'doorstop', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'wedge', tower: null }, paint: pal(0x5d8a3a, 0xc8e070) },
|
||||
{ id: 'buzzkill', name: 'Buzzkill', style: 'brawler', skill: 0.3, prize: 430,
|
||||
build: { chassis: 'crate', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'saw', tower: null }, paint: pal(0xd8b020, 0x202020) },
|
||||
build: { chassis: 'hexpod', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'saw', tower: null }, paint: pal(0xd8b020, 0x202020) },
|
||||
{ id: 'flapjack', name: 'Flapjack', style: 'flanker', skill: 0.38, prize: 560,
|
||||
build: { chassis: 'doorstop', motor: 'sparky', wheels: 'bigtyre', battery: 'lead', armour: null, weapon: 'flipper', tower: null }, paint: pal(0x2a6fd8, 0xffffff) },
|
||||
build: { chassis: 'fang', motor: 'sparky', wheels: 'bigtyre', battery: 'lead', armour: null, weapon: 'flipper', tower: null }, paint: pal(0x2a6fd8, 0xffffff) },
|
||||
{ id: 'pincer', name: 'Pincer', style: 'pusher', skill: 0.55, prize: 700,
|
||||
build: { chassis: 'bulwark', motor: 'bulldog', wheels: 'tracks', battery: 'nicd', armour: 'steel', weapon: 'crusher', tower: null }, paint: pal(0xc0392b, 0xf0c040) },
|
||||
build: { chassis: 'boiler', motor: 'bulldog', wheels: 'tracks', battery: 'lipo', armour: 'steel', weapon: 'crusher', tower: null, gadget: 'repair' }, paint: pal(0xc0392b, 0xf0c040) },
|
||||
{ id: 'thunderclap', name: 'Thunderclap', style: 'brawler', skill: 0.65, prize: 880,
|
||||
build: { chassis: 'bulwark', motor: 'hornet', wheels: 'bigtyre', battery: 'nicd', armour: 'titan', weapon: 'hammer', tower: 'flamer' }, paint: pal(0x6a3fb0, 0xffa020) },
|
||||
build: { chassis: 'plough', motor: 'hornet', wheels: 'bigtyre', battery: 'lipo', armour: 'titan', weapon: 'hammer', tower: 'flamer', gadget: 'shield' }, paint: pal(0x6a3fb0, 0xffa020) },
|
||||
{ id: 'gravedigger', name: 'Gravedigger', style: 'brawler', skill: 0.8, prize: 1100,
|
||||
build: { chassis: 'scarab', motor: 'hornet', wheels: 'tracks', battery: 'lipo', armour: 'titan', weapon: 'flipper', tower: 'rockets' }, paint: pal(0x2b2f36, 0x50e080) },
|
||||
build: { chassis: 'scarab', motor: 'hornet', wheels: 'tracks', battery: 'lipo', armour: 'titan', weapon: 'flipper', tower: 'rockets', gadget: 'turbo' }, paint: pal(0x2b2f36, 0x50e080) },
|
||||
{ id: 'overlord', name: 'Overlord', style: 'flanker', skill: 0.95, prize: 1450,
|
||||
build: { chassis: 'scarab', motor: 'comet', wheels: 'rubber', battery: 'lipo', armour: 'steel', weapon: 'spinner', tower: null }, paint: pal(0x101418, 0xff3030) },
|
||||
build: { chassis: 'discus', motor: 'comet', wheels: 'rubber', battery: 'lipo', armour: 'steel', weapon: 'spinner', tower: null, gadget: 'righter' }, paint: pal(0x101418, 0xff3030) },
|
||||
];
|
||||
RC.DUMMY = { id: 'dummy', name: 'Dummy', style: 'dummy', skill: 0, prize: 0,
|
||||
build: { chassis: 'crate', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: 'steel', weapon: null, tower: null }, paint: pal(0x8c8c8c, 0xff7a1a) };
|
||||
|
||||
Reference in New Issue
Block a user