Vacuum picks up grains in mid-air (t63)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+21
-1
@@ -2,11 +2,19 @@
|
||||
// Material the vacuum would start on at the cursor: a bar, else the nearest loose grain.
|
||||
function vacuumTargetAt(cx, cy, r) {
|
||||
for (const e of entsInCircle(cx, cy, Math.max(1, r))) return e.m;
|
||||
r = Math.max(1, r);
|
||||
let best = 0, bd = 1e9;
|
||||
forBrush(cx, cy, Math.max(1, r), (x, y, i) => {
|
||||
const m = mat[i], ph = PH[m];
|
||||
if (ph === PH_POWDER || (ph === PH_LIQUID && player.flask)) { const d = (x - cx) * (x - cx) + (y - cy) * (y - cy); if (d < bd) { bd = d; best = m; } }
|
||||
});
|
||||
for (const f of flyers) {
|
||||
if (f.rain) continue; // Rain belongs to the clouds; collecting it would create water.
|
||||
const ph = PH[f.m];
|
||||
if (!(ph === PH_POWDER || (ph === PH_LIQUID && player.flask))) continue;
|
||||
const x = Math.floor(f.x), y = Math.floor(f.y), dx = x - cx, dy = y - cy, d = dx * dx + dy * dy;
|
||||
if (d <= (r + 0.5) * (r + 0.5) && d < bd && inReach(x, y)) { bd = d; best = f.m; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
// Vacuum: picks up loose grains, liquids (with the Flask) and bars for which pick(m) is true.
|
||||
@@ -18,7 +26,19 @@ function toolVacuum(cx, cy, r, pick) {
|
||||
bagAdd(e.m, 1); removeEnt(e); got++; if (!first) first = e.m;
|
||||
emit({ t: 'suck', x: e.ix + 2, y: e.iy + 1, m: e.m });
|
||||
}
|
||||
if (!full) forBrush(cx, cy, r, (x, y, i) => {
|
||||
if (!full) for (let k = flyers.length - 1; k >= 0; k--) {
|
||||
const f = flyers[k], m = f.m, ph = PH[m];
|
||||
if (f.rain) continue; // Rain belongs to the clouds; collecting it would create water.
|
||||
if (!(ph === PH_POWDER || (ph === PH_LIQUID && player.flask)) || !pick(m)) continue;
|
||||
const x = Math.floor(f.x), y = Math.floor(f.y), dx = x - cx, dy = y - cy;
|
||||
if (dx * dx + dy * dy > (r + 0.5) * (r + 0.5) || !inReach(x, y)) continue;
|
||||
if (bagTotal >= bagCap()) { full = true; break; }
|
||||
if (!first) first = m;
|
||||
bagAdd(m, 1); flyers[k] = flyers[flyers.length - 1]; flyers.pop(); got++;
|
||||
if (got & 1) emit({ t: 'suck', x, y, m });
|
||||
if (--budget <= 0) break;
|
||||
}
|
||||
if (!full && budget > 0) forBrush(cx, cy, r, (x, y, i) => {
|
||||
const m = mat[i], ph = PH[m];
|
||||
if (!(ph === PH_POWDER || (ph === PH_LIQUID && player.flask))) return;
|
||||
if (!pick(m)) return;
|
||||
|
||||
Reference in New Issue
Block a user