Bag: rock goes in as rubble, older saves convert, list shows everything held

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 16:53:40 -04:00
co-authored by Claude Opus 5.5
parent 569ec6e5b6
commit a671dcb59a
7 changed files with 34 additions and 3 deletions
+3 -2
View File
@@ -57,9 +57,10 @@ function devCommand(text, cursor) {
if (!args.length || !Number.isInteger(n) || n <= 0) return usage();
const m = devMaterial(args.join(' '));
if (typeof m === 'string') return [m];
if (m === EMPTY) return ['Air cannot go in the bag.'];
if (m === EMPTY || PH[m] === PH_GAS || (PH[m] === PH_SOLID && !YLD[m])) return [`${MD[m].name} cannot go in the bag.`];
if (n > 2147483647 - bag[m]) return ['Too many: a material count cannot exceed 2147483647.'];
bagAdd(m, n, true); result = `Added ${n} ${MD[m].name}.`; break;
const into = PH[m] === PH_SOLID && YLD[m] ? YLD[m] : m;
bagAdd(m, n, true); result = `Added ${n} ${MD[into].name}${into !== m ? ` (as ${MD[m].name.toLowerCase()} breaks up)` : ''}.`; break;
}
case 'bit': case 'bag': {
const tiers = cmd === 'bit' ? BIT_TIERS : TANK_TIERS;
+1
View File
@@ -279,6 +279,7 @@ function entsInCircle(cx, cy, r) {
// ---------- Bag ----------
function bagAdd(m, n, force) {
if (PH[m] === PH_SOLID && YLD[m]) m = YLD[m]; // rock and metal go in as what drilling them gives
const room = force ? n : Math.max(0, bagCap() - bagTotal);
const k = Math.min(n, room);
bag[m] += k; bagTotal += k;
+2
View File
@@ -117,6 +117,8 @@ function deserializeWorld(meta, buffers) {
bot.x = meta.bot.x; bot.y = meta.bot.y; bot.lamp = meta.bot.lamp !== false; bot.vx = bot.vy = 0;
bag = new Int32Array(NMAT); meta.bag.forEach((v, k) => { if (k < NMAT) bag[k] = v; });
for (const m of meta.flyers || []) if (m < NMAT) bag[m]++; // grains that were mid-air when saved
// solids saved in the bag (older saves) come back as what drilling them gives
for (let k = 0; k < NMAT; k++) if (bag[k] && PH[k] === PH_SOLID && YLD[k]) { bag[YLD[k]] += bag[k]; bag[k] = 0; }
bagTotal = 0; for (let k = 0; k < NMAT; k++) bagTotal += bag[k];
Object.assign(player, meta.player);
seen = new Uint8Array(NMAT); meta.seen.forEach((v, k) => { if (k < NMAT) seen[k] = v; });