feat: player knowledge layer - aging price intel and seen ships
This commit is contained in:
+27
-1
@@ -1 +1,27 @@
|
||||
export function markSeen() {}
|
||||
import { playerSystem } from './player.js';
|
||||
import { shipsIn } from './npc.js';
|
||||
|
||||
// Best price intel the player has for a planet: personal dock visit
|
||||
// vs. news that has reached the player's current location. Caches the
|
||||
// winner in the price book so intel never gets worse.
|
||||
export function playerKnownPrices(world, planetId) {
|
||||
const p = world.player;
|
||||
const sys = playerSystem(world);
|
||||
if (sys == null) return p.priceBook[planetId] ?? null;
|
||||
const planet = world.galaxy.planets[planetId];
|
||||
const news = world.news.knownPrices(planetId, world.hops[sys][planet.systemId], world.t);
|
||||
const book = p.priceBook[planetId] ?? null;
|
||||
let best = book;
|
||||
if (news && (!best || news.time > best.time)) best = news;
|
||||
if (best && (!book || best.time > book.time)) p.priceBook[planetId] = best;
|
||||
return best ? { time: best.time, prices: best.prices, ageDays: world.t - best.time } : null;
|
||||
}
|
||||
|
||||
// Called by the world's observe heartbeat: every concrete ship sharing
|
||||
// the player's system becomes "seen" — its cloud is now player-visible forever.
|
||||
export function markSeen(world) {
|
||||
if (!world.player.alive) return;
|
||||
const sys = playerSystem(world);
|
||||
if (sys == null) return;
|
||||
for (const { npc } of shipsIn(world, sys)) world.player.seenNpcs.add(npc.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user