Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
2.4 kB · 77 lines
TypeScript
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import { getShipSystems } from "@thorium/utils/.server/ship/getShipSystem";import { type Entity, System } from "@thorium/utils/ecs";
export class LegacyReactorHeatSystem extends System { static flightMode = ["legacy"]; shipSystemPower = new Map<number, number>(); shipReactorPower = new Map<number, number>(); test(entity: Entity) { return !!entity.components.isReactor; } update(entity: Entity, elapsed: number) { const elapsedRatio = elapsed / 1000; const { isReactor, heat: heatComp, damage } = entity.components;
if (!isReactor || !heatComp || !damage) return;
const { efficiency, offline } = damage; const { externalPower } = isReactor; const { heat, maxHeat, nominalHeat, legacyHeatRate } = heatComp;
const heatAdjustment = maxHeat - nominalHeat;
// On external power or when the reactor is offline from damage, // we'll let the Reactor cool down. if (externalPower || offline) { entity.updateComponent("heat", { heat: heat - 0.005 * heatAdjustment * elapsedRatio, }); return; }
const ship = this.ecs.getEntityById(entity.components.isShipSystem?.shipId || -1); if (!ship) return; if (!this.shipSystemPower.has(ship.id)) { this.shipSystemPower.set(ship.id, 0); for (const systemId of ship?.components.shipSystems?.shipSystems.keys() || []) { const system = this.ecs.getEntityById(systemId); this.shipSystemPower.set( ship.id, (this.shipSystemPower.get(ship.id) || 0) + (system?.components.power?.currentPower || 0), ); } } if (!this.shipReactorPower.has(ship.id)) { this.shipReactorPower.set(ship.id, 0); for (const reactor of getShipSystems(this.ecs, { systemType: "reactor", shipId: ship.id, })) { this.shipReactorPower.set( ship.id, (this.shipReactorPower.get(ship.id) || 0) + (reactor.components.isReactor?.maxOutput || 0) * (reactor.components.damage?.efficiency || 0), ); } }
const minute30 = 30 * 60; const standardHeat = efficiency ** 2 / minute30; const unblanaceHeat = Math.abs( Math.cbrt( (this.shipReactorPower.get(ship.id) || 0) - (this.shipSystemPower.get(ship.id) || 0), ), ) / 5000;
entity.updateComponent("heat", { heat: heat + (standardHeat + unblanaceHeat) * legacyHeatRate * heatAdjustment * elapsedRatio, }); }
postUpdate() { this.shipReactorPower.clear(); this.shipSystemPower.clear(); }}