fix: clear destroyed-NPC state; use true EV in trade scoring (review)

This commit is contained in:
2026-06-12 14:20:35 +00:00
parent 3783a8075b
commit 29b1aef7d3
+3 -1
View File
@@ -70,7 +70,7 @@ export function planNpc(world, npc) {
if (sellP <= buyP * 1.15) continue; // demand a margin over price noise if (sellP <= buyP * 1.15) continue; // demand a margin over price noise
const qty = Math.min(npc.capacity, Math.floor(npc.credits / buyP), Math.floor(origin.stock[good] * 0.5)); const qty = Math.min(npc.capacity, Math.floor(npc.credits / buyP), Math.floor(origin.stock[good] * 0.5));
if (qty < 1) continue; if (qty < 1) continue;
const profit = (sellP - buyP) * qty * survival; const profit = (sellP * survival - buyP) * qty; // EV: buy cost is sunk even if cargo is lost
if (profit <= 0) continue; if (profit <= 0) continue;
const days = Math.max(LOCAL_HOP_DAYS, route.days); const days = Math.max(LOCAL_HOP_DAYS, route.days);
const noise = 0.9 + 0.2 * rollFor(npc.seed, `${planId}:noise:${dest.id}:${good}`); const noise = 0.9 + 0.2 * rollFor(npc.seed, `${planId}:noise:${dest.id}:${good}`);
@@ -111,6 +111,8 @@ export function onNpcArrive(world, { npcId, planId }) {
if (plan.finalOutcome === 'destroyed') { if (plan.finalOutcome === 'destroyed') {
npc.alive = false; npc.alive = false;
npc.plan = null; npc.plan = null;
npc.cargo = null;
npc.state = 'destroyed';
world.stats.npcDestroyed++; world.stats.npcDestroyed++;
return; return;
} }