Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
1.5 kB · 48 lines
TypeScript
at develop
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import { threatKnowledge } from "@thorium/.server/ai/threatKnowledge";import { getShipSystem } from "@thorium/utils/.server/ship/getShipSystem";import { type Entity, System } from "@thorium/utils/ecs";export class NPCKnowledgeSystem extends System { static flightMode = ["nova"]; frequency = 10; test(entity: Entity) { return !!(entity.components.isShip && !entity.components.isPlayerShip?.value); } update(entity: Entity, _elapsedMs: number): void { // Make sure the NPC ship has a nearby objects system so it is included in the nearby objects calculation. if (!entity.components.nearbyObjects) { entity.addComponent("nearbyObjects"); }
const sensors = getShipSystem(this.ecs, { shipId: entity.id, systemType: "sensors", });
const activeRange = sensors.components.isSensors?.activeRange; const passiveRange = sensors.components.isSensors?.passiveRange; // TODO March 29, 2025 Make this configurable const weaponsRange = 25_000; // targeting.components.isTargeting?.weaponsRange
const threats = threatKnowledge(entity); // const goals = goalsKnowledge(entity);
entity.updateComponent("npcKnowledge", { activeRange, passiveRange, weaponsRange, threats, }); }}
// Goals are for
// Example goals// search a ship for cargo// pursue a suspicious ship// steal an item from a ship// move into combat position// flee when overly damaged// function goalsKnowledge(_: Entity) {// return {};// }