0.1.39 P0: missionIds prune + chronicle smart trim

This commit is contained in:
2026-09-13 12:48:53 +08:00
parent fb23afa322
commit 62da87a4e4
2 changed files with 23 additions and 2 deletions
@@ -191,7 +191,9 @@ export function recallAll(w: World, missionId: string): void {
w.log('info', '探索队伍奉命返家。') w.log('info', '探索队伍奉命返家。')
} }
/** 队伍成员状态归位:伤者保持养伤,其余恢复闲居 */ /** 队伍成员状态归位:伤者保持养伤,其余恢复闲居
* 0.1.39 根治:完成后从 missionIds 移除——missionIds 只跟踪活跃任务 id
* 避免长跑 180 年后死引用堆积百条。state.missions 全量保留用于史书回看。 */
function releaseSquad(w: World, m: MissionState): void { function releaseSquad(w: World, m: MissionState): void {
for (const id of m.memberIds) { for (const id of m.memberIds) {
const c = w.memberById(id) const c = w.memberById(id)
@@ -199,6 +201,9 @@ function releaseSquad(w: World, m: MissionState): void {
if (c.state === 'wounded') continue if (c.state === 'wounded') continue
c.state = 'idle' c.state = 'idle'
} }
// 0.1.39:从 family.missionIds 移除已完成任务的 id
const idx = w.state.family.missionIds.indexOf(m.id)
if (idx >= 0) w.state.family.missionIds.splice(idx, 1)
} }
/** 月度巡查:亡者除名、重伤者离队疗伤;人数不足则提前收队 */ /** 月度巡查:亡者除名、重伤者离队疗伤;人数不足则提前收队 */
+17 -1
View File
@@ -334,6 +334,13 @@ export class World {
this.out.forEach((o) => o.onLog(kind, text)) this.out.forEach((o) => o.onLog(kind, text))
} }
/**
* 0.1.39 根治:chronicle 智能裁剪——保留全部 important=true 里程碑 +
* 最近 MAX_NON_IMPORTANT 条非重要记录。旧版无差别 splice 会丢失关键里程碑。
* 裁剪在 push 后触发,对调用方透明(不改变确定性序列——裁剪不消耗 rng)。
*/
private static readonly CHRONICLE_MAX_NON_IMPORTANT = 400
chronicle(cat: ChronicleEntry['category'], text: string, memberId?: Id, important = false): void { chronicle(cat: ChronicleEntry['category'], text: string, memberId?: Id, important = false): void {
const entry: ChronicleEntry = { const entry: ChronicleEntry = {
id: this.seq(), id: this.seq(),
@@ -345,7 +352,16 @@ export class World {
important important
} }
this.state.chronicle.push(entry) this.state.chronicle.push(entry)
if (this.state.chronicle.length > 520) this.state.chronicle.splice(0, this.state.chronicle.length - 520) // 0.1.39 智能裁剪:仅在总数超限时触发,保留全部 important +最近非 important
const max = World.CHRONICLE_MAX_NON_IMPORTANT
if (this.state.chronicle.length > max + 200) {
const important_ones = this.state.chronicle.filter((e) => e.important)
const non_important = this.state.chronicle.filter((e) => !e.important)
const trimmed_non = non_important.slice(-max)
this.state.chronicle = [...important_ones, ...trimmed_non].sort(
(a, b) => (a.year - b.year) || (a.month - b.month) || (a.id < b.id ? -1 : 1)
)
}
this.out.forEach((o) => o.onChronicle(entry, important)) this.out.forEach((o) => o.onChronicle(entry, important))
} }