big update
This commit is contained in:
@@ -15,6 +15,32 @@
|
||||
const d = (b && b.body) || {};
|
||||
return { hx: clamp(+d.hx || 1, 0.7, 1.6), wx: clamp(+d.wx || 1, 0.8, 1.4), lx: clamp(+d.lx || 1, 0.8, 1.3) };
|
||||
};
|
||||
// where the main weapon is bolted on: front (default), back, left or right.
|
||||
// a = angle offset from the robot's forward (+x); axis = which body half-extent reaches that way.
|
||||
RC.MOUNTS = { front: { a: 0, axis: 'len' }, back: { a: Math.PI, axis: 'len' }, left: { a: Math.PI / 2, axis: 'wid' }, right: { a: -Math.PI / 2, axis: 'wid' } };
|
||||
RC.mountOf = b => {
|
||||
const d = (b && b.mount && b.mount.weapon) || {};
|
||||
const side = RC.MOUNTS[d.side] ? d.side : 'front';
|
||||
return { side, a: RC.MOUNTS[side].a, axis: RC.MOUNTS[side].axis, up: clamp(+d.up || 0, -0.3, 0.6) };
|
||||
};
|
||||
RC.MAX_WEAPONS = 3;
|
||||
// a robot carries up to 3 weapons (same id allowed), each with its own side + height.
|
||||
// new builds use build.weapons = [{id,side,up}]; old builds (single build.weapon + build.mount) are read too.
|
||||
RC.weaponsOf = b => {
|
||||
let list = [];
|
||||
if (b && Array.isArray(b.weapons)) list = b.weapons;
|
||||
else if (b && b.weapon) { const m = b.mount && b.mount.weapon; list = [{ id: b.weapon, side: m && m.side, up: m && m.up }]; }
|
||||
const out = [];
|
||||
for (const w of list) {
|
||||
const p = w && RC.PARTS[w.id];
|
||||
if (!p || p.slot !== 'weapon') continue;
|
||||
const side = RC.MOUNTS[w.side] ? w.side : 'front';
|
||||
out.push({ id: w.id, part: p, side, up: clamp(+w.up || 0, -0.3, 0.6), a: RC.MOUNTS[side].a, axis: RC.MOUNTS[side].axis });
|
||||
if (out.length >= RC.MAX_WEAPONS) break;
|
||||
}
|
||||
return out;
|
||||
};
|
||||
RC.weaponCount = b => (b && Array.isArray(b.weapons) ? b.weapons.filter(w => w && RC.PARTS[w.id] && RC.PARTS[w.id].slot === 'weapon').length : (b && b.weapon ? 1 : 0));
|
||||
const sizeFactor = bo => bo.hx * bo.wx * bo.lx;
|
||||
|
||||
RC.HP_SCALE = 3; // catalogue hp x this = hit points in the arena
|
||||
@@ -23,12 +49,15 @@
|
||||
const errors = [];
|
||||
let weight = 0, power = 0, supply = 0;
|
||||
for (const slot of RC.SLOTS) {
|
||||
if (slot === 'weapon') continue; // weapons are a list now, summed below
|
||||
const p = part(build, slot);
|
||||
if (!p) { if (RC.REQUIRED[slot]) errors.push('need_' + slot); continue; }
|
||||
if (p.slot !== slot) { errors.push('bad_' + slot); continue; }
|
||||
weight += slot === 'chassis' ? Math.round(p.weight * (0.4 + 0.6 * sizeFactor(RC.bodyOf(build)))) : p.weight;
|
||||
if (slot === 'battery') supply += p.power; else power += p.power || 0;
|
||||
}
|
||||
for (const inst of RC.weaponsOf(build)) { weight += inst.part.weight; power += inst.part.power || 0; }
|
||||
if (RC.weaponCount(build) > RC.MAX_WEAPONS) errors.push('too_many_weapons');
|
||||
if (weight > RC.WEIGHT_LIMIT) errors.push('overweight');
|
||||
if (supply && power > supply) errors.push('no_power');
|
||||
return { ok: errors.length === 0, errors, weight, power, supply };
|
||||
@@ -36,15 +65,22 @@
|
||||
|
||||
RC.stats = build => {
|
||||
const ch = part(build, 'chassis'), mo = part(build, 'motor'), wh = part(build, 'wheels');
|
||||
const ar = part(build, 'armour'), we = part(build, 'weapon'), to = part(build, 'tower'), gd = part(build, 'gadget');
|
||||
const ar = part(build, 'armour'), to = part(build, 'tower'), gd = part(build, 'gadget');
|
||||
const v = RC.validate(build);
|
||||
const mass = Math.max(30, v.weight);
|
||||
let value = 0;
|
||||
for (const slot of RC.SLOTS) { const p = part(build, slot); if (p) value += p.cost; }
|
||||
for (const slot of RC.SLOTS) { if (slot === 'weapon') continue; const p = part(build, slot); if (p) value += p.cost; }
|
||||
const weps = RC.weaponsOf(build);
|
||||
for (const w of weps) value += w.part.cost;
|
||||
// per-weapon mount info; combat/render iterate this list, lead weapon kept on st.weapon/mountA for compat
|
||||
const weapons = weps.map(w => ({ id: w.id, part: w.part, side: w.side, mountA: w.a, mountAxis: w.axis, mountUp: w.up }));
|
||||
const lead = weapons[0] || null;
|
||||
const bo = RC.bodyOf(build), size = sizeFactor(bo);
|
||||
const len = (ch ? ch.len : 1.3) * bo.lx, wid = (ch ? ch.wid : 1.0) * bo.wx;
|
||||
return {
|
||||
body: bo,
|
||||
weapons,
|
||||
mountA: lead ? lead.mountA : 0, mountAxis: lead ? lead.mountAxis : 'len', mountUp: lead ? lead.mountUp : 0,
|
||||
topHeavy: bo.hx / ((bo.wx + bo.lx) / 2), // tall + narrow = easier to tip over
|
||||
hp: (Math.round((ch ? ch.hp : 80) * (0.6 + 0.4 * size)) + (ar ? ar.hp : 0)) * RC.HP_SCALE,
|
||||
reduce: ar ? ar.reduce : 0,
|
||||
@@ -56,7 +92,7 @@
|
||||
push: wh ? wh.push : 1,
|
||||
len, wid, h: (ch ? ch.h : 0.42) * bo.hx,
|
||||
rad: Math.hypot(len, wid) / 2 * 0.95, // body corners - bigger = robots keep more distance, less clipping
|
||||
weapon: we, tower: to, gadget: gd, armour: ar,
|
||||
weapon: lead ? lead.part : null, tower: to, gadget: gd, armour: ar,
|
||||
invertible: !!(wh && wh.invertible),
|
||||
lowProfile: !!(ch && ch.lowProfile),
|
||||
frontArmour: ch && ch.frontArmour ? ch.frontArmour : 0,
|
||||
|
||||
Reference in New Issue
Block a user