Hot loads: visible melt damage, rebuild-over repair, warning glow (t69)

This commit is contained in:
2026-10-29 18:30:26 -04:00
parent b655d754b9
commit 5fd8110470
14 changed files with 246 additions and 15 deletions
+31
View File
@@ -46,8 +46,26 @@ function clearStraySeals() {
function wallCells(code, bx, by) {
return blockCellList(bx, by).filter(i => !(isSlope(code) || isSlopeBelt(code)) || slopeCell(code, (i % W) & 3, ((i / W) | 0) & 3));
}
// Missing screw cells persist in part[] already; no separate damage state is needed.
function screwDamageMask(b) {
if (blockP[b] !== BP_SCREW) return 0;
const x = (b % BW) * BS, y = ((b / BW) | 0) * BS;
let mask = 0;
for (let k = 0; k < 16; k++) if (!IS_SCREW[part[(y + (k >> 2)) * W + x + (k & 3)]]) mask |= 1 << k;
return mask;
}
function screwLoadHeat(b) {
const x = (b % BW) * BS, y = ((b / BW) | 0) * BS;
let T = 0;
for (let k = 0; k < 16; k++) {
const i = (y + (k >> 2)) * W + x + (k & 3);
if (IS_SCREW[part[i]] && PH[mat[i]] === PH_POWDER && temp[i] > T) T = temp[i];
}
return T;
}
function canPlaceBlock(bx, by, code = BP_WALL) {
if (bx < 0 || by < 0 || bx >= BW || by >= BH) return 'Out of bounds';
if (code === BP_SCREW && screwDamageMask(by * BW + bx)) return '';
if (blockP[by * BW + bx]) return 'Something is already built there';
for (const i of blockCellList(bx, by)) {
if (mach[i] || (part[i] && slopeSealOwner(i) < 0)) return 'Something is already built there';
@@ -66,6 +84,13 @@ function placeBlock(code, v, bx, by, free, extra) {
if (isWall(code) && !WALL_OF[v]) return 'Pick a wall material with R';
const cost = pieceCost(code, v);
if (!free) { if (!canAfford(cost, 1)) return needText(cost, 1); payCost(cost, 1); }
const b = by * BW + bx, damage = code === BP_SCREW ? screwDamageMask(b) : 0;
if (damage) {
undoNote({ t: 'screw-repair', bx, by, damage, paid: !free });
for (const i of blockCellList(bx, by)) { part[i] = SCREW_PARTS[blockV[b] & 7]; markPow(i, true); wakeIdx(i); }
stats.placed++;
return '';
}
const cells = isSlope(code) || isSlopeBelt(code) ? wallCells(code, bx, by) : blockCellList(bx, by);
if (code !== BP_PIPE) evictCells(cells, by * BS); // a pipe is thin: what is there stays and flows past it
for (const i of cells) {
@@ -215,6 +240,7 @@ function blockInReach(bx, by) { return inBuildRange(bx * BS + BS / 2, by * BS +
// Is block b already exactly this piece (same kind, variant and, for a filter, settings)?
function blockIs(b, code, v, extra) {
if (blockP[b] !== code) return false;
if (code === BP_SCREW && screwDamageMask(b)) return false;
if (isFilter(code)) return (blockV[b] & 128) === filterVariant(code, v) && sameFilter(filterInfo(b), cleanFilterCfg(extra));
return blockV[b] === v;
}
@@ -224,6 +250,11 @@ function placeBlocks(code, v, list, extra, replace) {
for (const [bx, by] of list) {
if (!blockInReach(bx, by)) { last = 'Out of reach'; continue; }
const b = by * BW + bx;
if (code === BP_SCREW && screwDamageMask(b)) {
const r = placeBlock(code, v, bx, by, false, extra);
if (r) { last = r; break; }
n++; continue;
}
if (replace && blockP[b]) {
if (blockIs(b, code, v, extra)) continue;
if (blockP[b] === code && isFilter(code)) { undoNote({ t: 'filter', bx, by, v: blockV[b], extra: filterInfo(b) }); blockV[b] = filterVariant(code, v); setFilter(b, extra); filtersDirty = true; n++; continue; } // just re-set it
+1
View File
@@ -106,6 +106,7 @@ function machinesTick() {
if (stamp[i] === tickStamp) continue;
if (temp[i] > 1000 && rnd() < 0.02) {
part[i] = 0; markPow(i, false); emit({ t: 'warn', x: i % W, y: (i / W) | 0, text: 'melted' }); wakeIdx(i);
if (!ledger.screwMelt) { ledger.screwMelt = true; emit({ t: 'screw_melt' }); }
continue;
}
const s = netSat(i);
+14 -4
View File
@@ -13,6 +13,13 @@ function undoRecord(label, fn) {
undoRec = rec;
try { return fn(); } finally { undoRec = prev; rec.label = typeof label === 'function' ? label(rec) : label; undoPush(rec); }
}
function undoScrewRepair(bx, by, damage, paid) {
if (blockP[by * BW + bx] !== BP_SCREW) return false;
const cells = blockCellList(bx, by);
for (let j = 0; j < 16; j++) if (damage & (1 << j)) { const i = cells[j]; part[i] = 0; markPow(i, false); wakeIdx(i); }
if (paid) refundAt(pieceCost(BP_SCREW, 0), 1, bx * BS + 2, by * BS + 2);
return true;
}
function undoLast() {
const rec = undoStack.pop();
if (!rec) return 'Nothing to undo.';
@@ -21,7 +28,10 @@ function undoLast() {
const fail = () => { fails++; };
for (let k = rec.ops.length - 1; k >= 0; k--) {
const o = rec.ops[k];
if (o.t === 'block+') { if (blockP[o.by * BW + o.bx] === o.code) removeBlock(o.bx, o.by); }
if (o.t === 'screw-repair') {
if (!undoScrewRepair(o.bx, o.by, o.damage, o.paid)) fail();
}
else if (o.t === 'block+') { if (blockP[o.by * BW + o.bx] === o.code) removeBlock(o.bx, o.by); }
else if (o.t === 'block-') { const r = placeBlock(o.code, isFilter(o.code) ? o.v & 128 : o.v, o.bx, o.by, false, o.extra); if (r) fail(r); }
else if (o.t === 'filter') { const b = o.by * BW + o.bx; if (isFilter(blockP[b])) { blockV[b] = o.v & 128; setFilter(b, o.extra); filtersDirty = true; } }
else if (o.t === 'mach+') { const mm = machines.find(m => m && m.type === o.type && m.x === o.bx * BS && m.y === o.by * BS); if (mm && siloFull(mm)) fail('empty the silo first'); else if (mm) removeMachine(mm.id, true, false); }
@@ -30,7 +40,7 @@ function undoLast() {
else if (o.t === 'mold-') { const r = placeMoldAt(o.kind, o.bx, o.by, o.wall); if (r) fail(r); }
else if (o.t === 'paste') {
// ghosts still waiting are cleared; anything already built from them is taken back
for (const [bx, by, code] of o.blocks) { const b = by * BW + bx; if (ghostBlocks.has(b)) { ghostBlocks.delete(b); ghostBlocked.delete(b); } else if (blockP[b] === code) removeBlock(bx, by); }
for (const [bx, by, code, damage] of o.blocks) { const b = by * BW + bx; if (ghostBlocks.has(b)) { ghostBlocks.delete(b); ghostBlocked.delete(b); } else if (damage) { if (!undoScrewRepair(bx, by, damage, true)) fail(); } else if (blockP[b] === code) removeBlock(bx, by); }
for (const g of o.machines) { const k = ghostMachines.indexOf(g); if (k >= 0) ghostMachines.splice(k, 1); else { const mm = machines.find(m => m && m.type === g.type && m.x === g.bx * BS && m.y === g.by * BS); if (mm) removeMachine(mm.id, true, false); } }
for (const g of o.molds) { const k = ghostMolds.indexOf(g); if (k >= 0) ghostMolds.splice(k, 1); else { const mo = molds.find(m => m.kind === g.kind && m.x === g.bx * BS && m.y === g.by * BS); if (mo) removeMold(mo); } }
}
@@ -56,13 +66,13 @@ function ghostTick0() {
if (nx.done) { ghostIter = ghostBlocks.entries(); nx = ghostIter.next(); if (nx.done) break; }
const [b, [code, v, e, swap]] = nx.value;
const bx = b % BW, by = (b / BW) | 0;
if (blockP[b] === code && blockV[b] === (isFilter(code) ? v & 128 : v)) {
if (blockP[b] === code && blockV[b] === (isFilter(code) ? v & 128 : v) && !screwDamageMask(b)) {
if (isFilter(code) && e && !sameFilter(filterInfo(b), cleanFilterCfg(e))) setFilter(b, e); // same piece, new settings
ghostBlocks.delete(b); ghostBlocked.delete(b); continue;
}
if (!blockInReach(bx, by)) continue;
// a replacing ghost takes down what is there (refunded) and builds itself, like a replace in reach
if (swap && blockP[b]) {
if (swap && blockP[b] && !(code === BP_SCREW && screwDamageMask(b))) {
if (blockP[b] === code && isFilter(code)) { blockV[b] = filterVariant(code, v); setFilter(b, e); filtersDirty = true; ghostBlocks.delete(b); ghostBlocked.delete(b); budget--; continue; }
if (!canAfford(pieceCost(code, v), 1)) { ghostMissing++; continue; }
removeBlock(bx, by);