1
0
Fork 0
polaris-task-force/src/lib/base/adjacency.ts
2026-09-20 02:43:23 -04:00

47 lines
1.6 KiB
TypeScript

import type { MapPoint } from "@/lib/map/points";
import { pointDistance } from "@/lib/map/points";
export interface AuraSourceLike {
id: number;
coordinates?: MapPoint | null;
constructionStatus?: string | null;
blueprint?: {
aura?: {
effectType?: string | null;
value?: number | null;
rangeMeters?: number | null;
} | null;
} | null;
}
export interface AdjacencyBonus {
productionMultiplier: number;
capacityMass: number;
}
/**
* Sums the adjacency auras projected onto a site: operational neighbors only
* (building/awaiting sites project nothing), each source counts once, a source
* never buffs itself, and only sources whose blueprint declares an aura with a
* positive value and range inside the distance contribute.
*/
export function auraBonusAt(
target: { id: number; coordinates?: MapPoint | null },
sources: AuraSourceLike[],
): AdjacencyBonus {
const bonus: AdjacencyBonus = { productionMultiplier: 0, capacityMass: 0 };
if (!target.coordinates) return bonus;
for (const source of sources) {
if (source.id === target.id) continue;
if ((source.constructionStatus ?? "complete") !== "complete") continue;
const aura = source.blueprint?.aura;
if (!aura || !aura.effectType) continue;
const value = aura.value ?? 0;
const range = aura.rangeMeters ?? 0;
if (value <= 0 || range <= 0 || !source.coordinates) continue;
if (pointDistance(target.coordinates, source.coordinates) > range) continue;
if (aura.effectType === "production_multiplier") bonus.productionMultiplier += value;
else if (aura.effectType === "capacity_mass") bonus.capacityMass += value;
}
return bonus;
}