feat(ai): add autorun policies for general and nation management

- Introduced `policies.ts` to define AI policies for generals and nations, including priority actions and flags.
- Implemented `AutorunGeneralPolicy` class to manage general-specific actions based on AI options and server/nation policies.
- Implemented `AutorunNationPolicy` class to handle nation-specific actions, including resource requirements and combat strategies.
- Added types for AI context and world view in `types.ts` to facilitate interaction with game state and entities.
This commit is contained in:
2026-01-11 14:49:42 +00:00
parent cc41d1538e
commit 550910811c
10 changed files with 3623 additions and 4 deletions
@@ -135,6 +135,30 @@ export class InMemoryReservedTurnStore {
this.generalTurns.set(generalId, buildTurnListFromRows(rows, this.maxGeneralTurns));
}
async prefetchGeneralTurns(generalIds: number[]): Promise<void> {
const targetIds = Array.from(new Set(generalIds)).filter((generalId) => !this.dirtyGeneralIds.has(generalId));
if (targetIds.length === 0) {
return;
}
const rows = await this.prisma.generalTurn.findMany({
where: { generalId: { in: targetIds } },
orderBy: [{ generalId: 'asc' }, { turnIdx: 'asc' }],
});
const grouped = new Map<number, typeof rows>();
for (const row of rows) {
const list = grouped.get(row.generalId);
if (list) {
list.push(row);
} else {
grouped.set(row.generalId, [row]);
}
}
for (const generalId of targetIds) {
const list = grouped.get(generalId) ?? [];
this.generalTurns.set(generalId, buildTurnListFromRows(list, this.maxGeneralTurns));
}
}
async refreshNationTurns(nationId: number, officerLevel: number): Promise<void> {
const key = buildNationKey(nationId, officerLevel);
if (this.dirtyNationKeys.has(key)) {