From 29b1aef7d356a3cde0359d5f9724e6c05892b109 Mon Sep 17 00:00:00 2001 From: EugeneTes Date: Fri, 12 Jun 2026 14:20:35 +0000 Subject: [PATCH] fix: clear destroyed-NPC state; use true EV in trade scoring (review) --- src/sim/npc.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sim/npc.js b/src/sim/npc.js index 972244e..4165a46 100644 --- a/src/sim/npc.js +++ b/src/sim/npc.js @@ -70,7 +70,7 @@ export function planNpc(world, npc) { 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)); 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; const days = Math.max(LOCAL_HOP_DAYS, route.days); 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') { npc.alive = false; npc.plan = null; + npc.cargo = null; + npc.state = 'destroyed'; world.stats.npcDestroyed++; return; }