cortico-world-genesis 2.1.6 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +16 -1
- package/describe.json +1 -1
- package/dist/webui.js +75 -2
- package/package.json +1 -1
- package/src/ENV_PROMPT.md +7 -0
- package/src/flora.ts +4 -1
- package/src/game.ts +132 -4
- package/src/index.ts +3 -0
- package/src/panel-types.ts +6 -0
- package/src/profile.ts +117 -0
- package/src/site.ts +3 -1
- package/src/store.ts +21 -3
- package/src/webui/client.ts +85 -2
- package/src/world.ts +120 -3
- package/src/world.ts.recovered +0 -3636
package/src/profile.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { populationOf, sleepersOf, type GameState, type SeedBag, type Upgrades } from './game.ts';
|
|
4
|
+
|
|
5
|
+
/** 点火燃料的资源 id(`flora.ts` 的 RESOURCE_LABELS 里叫「氘氚燃料」)。 */
|
|
6
|
+
export const FUEL_RESOURCE = 'deuterium';
|
|
7
|
+
|
|
8
|
+
/** 档案:能跨地图带走的那一小块。其余(站点、建筑、作物、疤)都长在地图上。 */
|
|
9
|
+
export interface Profile {
|
|
10
|
+
schema: 1;
|
|
11
|
+
/** 已经过了几颗星(第一次是 1)。 */
|
|
12
|
+
runs: number;
|
|
13
|
+
/** 上一颗星的名字,星卡里留一行。 */
|
|
14
|
+
lastStar?: string;
|
|
15
|
+
credits: number;
|
|
16
|
+
tungsten: number;
|
|
17
|
+
energyKj: number;
|
|
18
|
+
inventory: Record<string, number>;
|
|
19
|
+
upgrades: Upgrades;
|
|
20
|
+
seedBags: SeedBag[];
|
|
21
|
+
/** 所有人类(醒着的也算)——再创世时全体回休眠舱。 */
|
|
22
|
+
people: number;
|
|
23
|
+
samples: number;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const PROFILE_SCHEMA = 1;
|
|
28
|
+
/** 【再创世】的门槛:一百万 kJ、一百公斤氘氚燃料、一份异星样本、机动核心修好。 */
|
|
29
|
+
export const RECREATE_ENERGY_KJ = 1_000_000;
|
|
30
|
+
export const RECREATE_FUEL_KG = 100;
|
|
31
|
+
export const RECREATE_SAMPLES = 1;
|
|
32
|
+
|
|
33
|
+
/** 从一局游戏里轧出档案。 */
|
|
34
|
+
export function exportProfile(
|
|
35
|
+
state: GameState,
|
|
36
|
+
meta: { runs?: number; lastStar?: string; nowMs?: number } = {},
|
|
37
|
+
): Profile {
|
|
38
|
+
return {
|
|
39
|
+
schema: PROFILE_SCHEMA,
|
|
40
|
+
runs: meta.runs ?? 1,
|
|
41
|
+
...(meta.lastStar ? { lastStar: meta.lastStar } : {}),
|
|
42
|
+
credits: state.credits,
|
|
43
|
+
tungsten: state.tungsten,
|
|
44
|
+
energyKj: state.energyKj,
|
|
45
|
+
inventory: { ...state.inventory, [FUEL_RESOURCE]: state.inventory[FUEL_RESOURCE] ?? 0 },
|
|
46
|
+
upgrades: { ...state.upgrades },
|
|
47
|
+
seedBags: state.seedBags.map((bag) => ({ ...bag, ...(bag.at ? {} : {}) })),
|
|
48
|
+
people: populationOf(state) + sleepersOf(state),
|
|
49
|
+
samples: state.samples,
|
|
50
|
+
updatedAt: new Date(meta.nowMs ?? Date.now()).toISOString(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 门槛检查:返回空数组表示可以点火。 */
|
|
55
|
+
export function recreateBlockers(state: GameState): string[] {
|
|
56
|
+
const blockers: string[] = [];
|
|
57
|
+
if (state.energyKj < RECREATE_ENERGY_KJ) {
|
|
58
|
+
blockers.push(`能量不够:要 ${RECREATE_ENERGY_KJ.toLocaleString('en-US')} kJ,现在 ${Math.round(state.energyKj).toLocaleString('en-US')} kJ。`);
|
|
59
|
+
}
|
|
60
|
+
const fuel = state.inventory[FUEL_RESOURCE] ?? 0;
|
|
61
|
+
if (fuel < RECREATE_FUEL_KG) {
|
|
62
|
+
blockers.push(`氘氚燃料不够:要 ${RECREATE_FUEL_KG} kg,现在 ${fuel} kg。`);
|
|
63
|
+
}
|
|
64
|
+
if (state.samples < RECREATE_SAMPLES) {
|
|
65
|
+
blockers.push(`异星生命样本不够:要 ${RECREATE_SAMPLES} 份,现在 ${state.samples} 份。`);
|
|
66
|
+
}
|
|
67
|
+
if (state.upgrades.mobilityCore !== 'ready') {
|
|
68
|
+
blockers.push('机动核心还没修好:先修它,不然飞船起不来。');
|
|
69
|
+
}
|
|
70
|
+
if (state.transit) blockers.push('移动途中不能点火。');
|
|
71
|
+
return blockers;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 扣掉点火成本(能量、燃料、样本)。 */
|
|
75
|
+
export function consumeRecreate(state: GameState): GameState {
|
|
76
|
+
const blockers = recreateBlockers(state);
|
|
77
|
+
if (blockers.length > 0) throw new Error(blockers.join('\n'));
|
|
78
|
+
return {
|
|
79
|
+
...state,
|
|
80
|
+
energyKj: state.energyKj - RECREATE_ENERGY_KJ,
|
|
81
|
+
inventory: { ...state.inventory, [FUEL_RESOURCE]: (state.inventory[FUEL_RESOURCE] ?? 0) - RECREATE_FUEL_KG },
|
|
82
|
+
samples: state.samples - RECREATE_SAMPLES,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface ProfileStoreOptions {
|
|
87
|
+
dataDir: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** `<dataDir>/genesis/profile.json`:档案单独一份,和地图的 runs/ 分开。 */
|
|
91
|
+
export class ProfileStore {
|
|
92
|
+
readonly file: string;
|
|
93
|
+
|
|
94
|
+
constructor(options: ProfileStoreOptions) {
|
|
95
|
+
this.file = join(options.dataDir, 'genesis', 'profile.json');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async read(): Promise<Profile | null> {
|
|
99
|
+
let raw: string;
|
|
100
|
+
try {
|
|
101
|
+
raw = await readFile(this.file, 'utf8');
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
const parsed = JSON.parse(raw) as Profile;
|
|
107
|
+
if (parsed.schema !== PROFILE_SCHEMA) {
|
|
108
|
+
throw new Error(`profile.json 的 schema 是 ${String(parsed.schema)},这一版只认识 ${PROFILE_SCHEMA}。`);
|
|
109
|
+
}
|
|
110
|
+
return parsed;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async write(profile: Profile): Promise<void> {
|
|
114
|
+
await mkdir(dirname(this.file), { recursive: true });
|
|
115
|
+
await writeFile(this.file, `${JSON.stringify(profile, null, 2)}\n`, 'utf8');
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/site.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface Site {
|
|
|
24
24
|
foundedHomeHours: number;
|
|
25
25
|
/** 四维养分库存;收获会扣,草木灰/堆肥会补。 */
|
|
26
26
|
nutrients: NutrientStock;
|
|
27
|
+
/** 冰盖站点自带冰窖里的水(L,0…100):融雪攒、灌溉喝,同时给作物加湿润度。 */
|
|
28
|
+
waterL?: number;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -177,7 +179,7 @@ export function climateAt(
|
|
|
177
179
|
export function siteRefusal(surface: TerrestrialSurface, latDeg: number, lonDeg: number, existing: Site[]): string | null {
|
|
178
180
|
const sample = sampleCell(surface, latDeg, lonDeg);
|
|
179
181
|
if (!sample.land) return '这里是水面(海洋),站点要建在陆地上。';
|
|
180
|
-
|
|
182
|
+
// 冰盖可以建站(2.1.7):自带 100 L 冰窖、下降风发电,苦但能活。
|
|
181
183
|
const sameCell = existing.filter((site) => site.cellI === sample.cellI && site.cellJ === sample.cellJ);
|
|
182
184
|
if (sameCell.length >= MAX_SITES_PER_CELL) {
|
|
183
185
|
return `这一格已经有 ${MAX_SITES_PER_CELL} 个站点了(上限 ${MAX_SITES_PER_CELL} 个)。`;
|
package/src/store.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdir, readFile, unlink, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import type { GenesisSpec, StarSystem } from './model.ts';
|
|
4
4
|
import { assertSave } from './schema.ts';
|
|
@@ -70,6 +70,24 @@ export class GenesisStore {
|
|
|
70
70
|
return { system, created: true, path: this.file };
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* 把当前这一局归档到 `genesis/runs/<run>/`({system,game}.json 一起搬)。
|
|
75
|
+
* 【再创世】时调用:旧地图从此只读、不再可进。
|
|
76
|
+
*/
|
|
77
|
+
async archiveRun(run: number, gameFile: string): Promise<string> {
|
|
78
|
+
const dir = join(dirname(this.file), 'runs', String(run));
|
|
79
|
+
await mkdir(dir, { recursive: true });
|
|
80
|
+
for (const src of [this.file, gameFile]) {
|
|
81
|
+
const name = src.slice(src.lastIndexOf('\\') + 1).split('/').pop()!;
|
|
82
|
+
try {
|
|
83
|
+
await rename(src, join(dir, name));
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return dir;
|
|
89
|
+
}
|
|
90
|
+
|
|
73
91
|
/** 删档重开。返回是否真的删掉了文件。 */
|
|
74
92
|
async delete(): Promise<boolean> {
|
|
75
93
|
try {
|
|
@@ -81,5 +99,5 @@ export class GenesisStore {
|
|
|
81
99
|
}
|
|
82
100
|
}
|
|
83
101
|
}
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
|
|
103
|
+
|
package/src/webui/client.ts
CHANGED
|
@@ -157,6 +157,13 @@ interface Text {
|
|
|
157
157
|
protoOxygen: string;
|
|
158
158
|
protoHours: string;
|
|
159
159
|
protoWake: string;
|
|
160
|
+
recreateTitle: string;
|
|
161
|
+
recreateDesc: string;
|
|
162
|
+
recreateSeed: string;
|
|
163
|
+
recreateMass: string;
|
|
164
|
+
recreateGo: string;
|
|
165
|
+
recreateBlocked: string;
|
|
166
|
+
recreateDone: string;
|
|
160
167
|
protoAwakened: string;
|
|
161
168
|
protoLocked: string;
|
|
162
169
|
protoPopulation: string;
|
|
@@ -326,6 +333,13 @@ const ZH: Text = {
|
|
|
326
333
|
protoOxygen: '氧气',
|
|
327
334
|
protoHours: '还能撑',
|
|
328
335
|
protoWake: '叫醒他们',
|
|
336
|
+
recreateTitle: '再创世',
|
|
337
|
+
recreateDesc: '带着档案去下一张地图:1,000,000 kJ 能量、100 kg 氘氚燃料、1 份异星生命样本,机动核心还得是修好的。旧地图会归档作废,所有人回休眠舱。',
|
|
338
|
+
recreateSeed: '种子',
|
|
339
|
+
recreateMass: '恒星质量',
|
|
340
|
+
recreateGo: '点火,去下一颗星',
|
|
341
|
+
recreateBlocked: '还差这些',
|
|
342
|
+
recreateDone: '点火了——飞向下一颗星。',
|
|
329
343
|
protoAwakened: '人类已经醒了。',
|
|
330
344
|
protoLocked: '还没有创世。先去「这一颗星球」页签创一次世,这里才会长出清单。',
|
|
331
345
|
protoPopulation: '常住人口',
|
|
@@ -495,6 +509,13 @@ const EN: Text = {
|
|
|
495
509
|
protoOxygen: 'oxygen',
|
|
496
510
|
protoHours: 'lasts',
|
|
497
511
|
protoWake: 'Wake them',
|
|
512
|
+
recreateTitle: 'Recreate',
|
|
513
|
+
recreateDesc: 'Carry the profile to a new map: 1,000,000 kJ, 100 kg of deuterium fuel, 1 alien sample, and a repaired mobility core. The old map is archived and sealed; everyone goes back into the pods.',
|
|
514
|
+
recreateSeed: 'Seed',
|
|
515
|
+
recreateMass: 'Star mass',
|
|
516
|
+
recreateGo: 'Ignite — fly to the next star',
|
|
517
|
+
recreateBlocked: 'Not yet',
|
|
518
|
+
recreateDone: 'Ignited — on our way to the next star.',
|
|
498
519
|
protoAwakened: 'The people are awake.',
|
|
499
520
|
protoLocked: 'Nothing has been created yet — create a world in the "This world" tab first.',
|
|
500
521
|
protoPopulation: 'Colonists',
|
|
@@ -1343,7 +1364,8 @@ const panel: WebUiPanel = {
|
|
|
1343
1364
|
row.style.gap = '8px';
|
|
1344
1365
|
row.style.alignItems = 'center';
|
|
1345
1366
|
const label = ctx.ui.h('span', 'mono', `温室 ${gh.siteKey}`);
|
|
1346
|
-
const
|
|
1367
|
+
const indoors = gh.interiorC === null ? (gh.powered ? '超出温室能力' : '断电,不工作') : `室内 ${gh.interiorC}℃`;
|
|
1368
|
+
const value = ctx.ui.h('span', 'mono', `${gh.targetC === null ? '自动' : `设定 ${gh.targetC}℃`} · ${indoors}(室外 ${gh.ambientC ?? '—'}℃)${gh.realismCores > 0 ? ` · 拟真 ×${gh.realismCores}` : ''}`);
|
|
1347
1369
|
const slider = ctx.ui.h('input') as HTMLInputElement;
|
|
1348
1370
|
slider.type = 'range';
|
|
1349
1371
|
slider.min = '-60';
|
|
@@ -1890,7 +1912,40 @@ const protocolPanel: WebUiPanel = {
|
|
|
1890
1912
|
// 未创世 / 读不到存档时,这个按钮不该存在——它按下去只会报错。
|
|
1891
1913
|
wakeButton.hidden = true;
|
|
1892
1914
|
wakeButton.style.marginTop = '10px';
|
|
1893
|
-
|
|
1915
|
+
// 【再创世】:条件不成就置灰,阻塞原因直接列出来。
|
|
1916
|
+
const recreateBox = ctx.ui.h('div');
|
|
1917
|
+
recreateBox.style.marginTop = '18px';
|
|
1918
|
+
recreateBox.hidden = true;
|
|
1919
|
+
const recreateRow = ctx.ui.rowbar();
|
|
1920
|
+
const recreateSeedInput = ctx.ui.input({ placeholder: '20261111' });
|
|
1921
|
+
recreateSeedInput.type = 'text';
|
|
1922
|
+
recreateSeedInput.style.width = '110px';
|
|
1923
|
+
const recreateMassInput = ctx.ui.input({});
|
|
1924
|
+
recreateMassInput.type = 'range';
|
|
1925
|
+
recreateMassInput.min = '0.15';
|
|
1926
|
+
recreateMassInput.max = '2';
|
|
1927
|
+
recreateMassInput.step = '0.05';
|
|
1928
|
+
const recreateMassLabel = ctx.ui.h('span', 'mono', '1.00');
|
|
1929
|
+
const recreateButton = ctx.ui.button(t.recreateGo, { variant: 'primary' });
|
|
1930
|
+
recreateRow.append(
|
|
1931
|
+
ctx.ui.h('span', 'muted', t.recreateSeed),
|
|
1932
|
+
recreateSeedInput,
|
|
1933
|
+
ctx.ui.h('span', 'muted', t.recreateMass),
|
|
1934
|
+
recreateMassInput,
|
|
1935
|
+
recreateMassLabel,
|
|
1936
|
+
recreateButton,
|
|
1937
|
+
);
|
|
1938
|
+
const recreateList = ctx.ui.h('ul', '');
|
|
1939
|
+
recreateBox.append(ctx.ui.h('h3', '', t.recreateTitle), ctx.ui.h('p', 'muted', t.recreateDesc), recreateRow, recreateList);
|
|
1940
|
+
sheet.body.append(head, body, habitatBox, wakeButton, recreateBox);
|
|
1941
|
+
|
|
1942
|
+
const paintMass = (): void => {
|
|
1943
|
+
recreateMassLabel.textContent = Number(recreateMassInput.value || '1').toFixed(2);
|
|
1944
|
+
};
|
|
1945
|
+
recreateMassInput.addEventListener('input', paintMass);
|
|
1946
|
+
recreateButton.addEventListener('click', () => {
|
|
1947
|
+
void recreate(recreateButton);
|
|
1948
|
+
});
|
|
1894
1949
|
ctx.root.append(sheet.el);
|
|
1895
1950
|
|
|
1896
1951
|
const render = (panel: GenesisProtocolPanel): void => {
|
|
@@ -1936,6 +1991,16 @@ const protocolPanel: WebUiPanel = {
|
|
|
1936
1991
|
),
|
|
1937
1992
|
);
|
|
1938
1993
|
}
|
|
1994
|
+
recreateBox.hidden = false;
|
|
1995
|
+
if (recreateSeedInput.value === '') recreateSeedInput.value = panel.recreate.seed;
|
|
1996
|
+
if (recreateMassInput.value === '') recreateMassInput.value = String(panel.recreate.starMass);
|
|
1997
|
+
paintMass();
|
|
1998
|
+
recreateButton.disabled = !panel.recreate.ready;
|
|
1999
|
+
recreateList.textContent = '';
|
|
2000
|
+
if (!panel.recreate.ready) {
|
|
2001
|
+
recreateList.append(ctx.ui.h('li', 'muted', t.recreateBlocked));
|
|
2002
|
+
for (const blocker of panel.recreate.blockers) recreateList.append(ctx.ui.h('li', '', blocker));
|
|
2003
|
+
}
|
|
1939
2004
|
if (panel.awakened) {
|
|
1940
2005
|
wakeButton.disabled = true;
|
|
1941
2006
|
wakeButton.textContent = t.protoAwakened;
|
|
@@ -1951,6 +2016,7 @@ const protocolPanel: WebUiPanel = {
|
|
|
1951
2016
|
} catch (error) {
|
|
1952
2017
|
// 没有存档是常态(第一次打开面板),不是错误:给一句引导,别留一个会报错的按钮。
|
|
1953
2018
|
wakeButton.hidden = true;
|
|
2019
|
+
recreateBox.hidden = true;
|
|
1954
2020
|
progress.textContent = '';
|
|
1955
2021
|
body.textContent = '';
|
|
1956
2022
|
habitatBox.textContent = '';
|
|
@@ -1975,6 +2041,23 @@ const protocolPanel: WebUiPanel = {
|
|
|
1975
2041
|
}
|
|
1976
2042
|
};
|
|
1977
2043
|
|
|
2044
|
+
const recreate = async (button: HTMLButtonElement): Promise<void> => {
|
|
2045
|
+
button.disabled = true;
|
|
2046
|
+
try {
|
|
2047
|
+
const result = await ctx.invoke<{ text: string }>('recreate', [
|
|
2048
|
+
recreateSeedInput.value,
|
|
2049
|
+
Number(recreateMassInput.value),
|
|
2050
|
+
]);
|
|
2051
|
+
ctx.ui.toast(t.recreateDone, 'ok');
|
|
2052
|
+
progress.textContent = result.text;
|
|
2053
|
+
await load();
|
|
2054
|
+
void ctx.refresh();
|
|
2055
|
+
} catch (error) {
|
|
2056
|
+
ctx.ui.toast(errorText(error), 'bad');
|
|
2057
|
+
button.disabled = false;
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
2060
|
+
|
|
1978
2061
|
await load();
|
|
1979
2062
|
ctx.interval(() => {
|
|
1980
2063
|
void load();
|
package/src/world.ts
CHANGED
|
@@ -106,6 +106,8 @@ import {
|
|
|
106
106
|
armsInCycle,
|
|
107
107
|
relinkArm,
|
|
108
108
|
relinkDuty,
|
|
109
|
+
landingRefusal,
|
|
110
|
+
withIceWater,
|
|
109
111
|
structurePowered,
|
|
110
112
|
ARM_KG_PER_HOUR,
|
|
111
113
|
ARM_RANGE_KM,
|
|
@@ -131,12 +133,14 @@ import { GENESIS_DEFAULTS, GENESIS_LIMITS, validateSpec, type GenesisSpec, type
|
|
|
131
133
|
import type { GenesisBody, GenesisDraft, GenesisPanelProtocol, GenesisPanelState, GenesisPlanetRow, GenesisProtocolPanel, GenesisSurfaceMap } from './panel-types.ts';
|
|
132
134
|
import { GenesisStore } from './store.ts';
|
|
133
135
|
import { stargazeText } from './stargaze.ts';
|
|
134
|
-
import { deriveGenesisShape, describeGenesisMenu, GENESIS_SHAPE } from './system.ts';
|
|
136
|
+
import { createSystem, deriveGenesisShape, describeGenesisMenu, GENESIS_SHAPE } from './system.ts';
|
|
137
|
+
import { hashSeed } from './rng.ts';
|
|
135
138
|
import { planetVisibility, terrainPatch, terrainPatchText, type TerrainBody } from './terrain.ts';
|
|
136
139
|
import { targetBiomeFor, terraCellsFor, type TerraMap } from './terra.ts';
|
|
137
140
|
import { guideText, guideTopics } from './guide.ts';
|
|
138
141
|
import { infoText } from './info.ts';
|
|
139
|
-
import {
|
|
142
|
+
import { ProfileStore, consumeRecreate, exportProfile, recreateBlockers } from './profile.ts';
|
|
143
|
+
import { applyAlgae, breedAt, greenhouseClimate, PLANTER_CLIMATE, PLANTER_SUBSTRATE, PUMP_MAX_WETNESS } from './game.ts';
|
|
140
144
|
import { inspectPlantText } from './inspect.ts';
|
|
141
145
|
import type { ClimateSample } from './flora.ts';
|
|
142
146
|
|
|
@@ -937,11 +941,13 @@ export class GenesisWorld implements World {
|
|
|
937
941
|
|
|
938
942
|
private readonly store: GenesisStore;
|
|
939
943
|
private readonly games: GameStore;
|
|
944
|
+
private readonly profiles: ProfileStore;
|
|
940
945
|
private readonly now: () => number;
|
|
941
946
|
|
|
942
947
|
constructor(private readonly opts: GenesisWorldOptions) {
|
|
943
948
|
this.store = new GenesisStore({ dataDir: opts.dataDir });
|
|
944
949
|
this.games = new GameStore({ dataDir: opts.dataDir });
|
|
950
|
+
this.profiles = new ProfileStore({ dataDir: opts.dataDir });
|
|
945
951
|
this.now = opts.now ?? Date.now;
|
|
946
952
|
}
|
|
947
953
|
|
|
@@ -1289,6 +1295,8 @@ export class GenesisWorld implements World {
|
|
|
1289
1295
|
return this.protocolPanelState();
|
|
1290
1296
|
case 'wake':
|
|
1291
1297
|
return this.wakeFromPanel(args[0]);
|
|
1298
|
+
case 'recreate':
|
|
1299
|
+
return this.recreateFromPanel(args[0], args[1]);
|
|
1292
1300
|
default:
|
|
1293
1301
|
throw new Error(`「协议」面板没有方法:${method}`);
|
|
1294
1302
|
}
|
|
@@ -1503,6 +1511,67 @@ export class GenesisWorld implements World {
|
|
|
1503
1511
|
return { text: woke.text, state: await this.panelState() };
|
|
1504
1512
|
}
|
|
1505
1513
|
|
|
1514
|
+
|
|
1515
|
+
/** 面板【再创世】:带着档案去下一张地图。旧地图归档后作废。 */
|
|
1516
|
+
private async recreateFromPanel(rawSeed: unknown, rawMass: unknown): Promise<{ text: string }> {
|
|
1517
|
+
await this.sync();
|
|
1518
|
+
const system = await this.readSystem();
|
|
1519
|
+
if (!system || !this.game) throw new Error('还没有创世。');
|
|
1520
|
+
const game = this.game;
|
|
1521
|
+
const blockers = recreateBlockers(game);
|
|
1522
|
+
if (blockers.length > 0) throw new Error(blockers.join('\n'));
|
|
1523
|
+
|
|
1524
|
+
const seed = normalizeSeedValue(rawSeed);
|
|
1525
|
+
const raw = typeof rawMass === 'number' ? rawMass : Number(rawMass);
|
|
1526
|
+
const starMass = Math.min(
|
|
1527
|
+
GENESIS_LIMITS.starMass.max,
|
|
1528
|
+
Math.max(GENESIS_LIMITS.starMass.min, Number.isFinite(raw) ? Math.round(raw * 100) / 100 : GENESIS_DEFAULTS.starMass),
|
|
1529
|
+
);
|
|
1530
|
+
const spec: GenesisSpec = { seed, starMass, ...deriveGenesisShape(seed) };
|
|
1531
|
+
const next = createSystem(spec);
|
|
1532
|
+
const refusal = landingRefusal(next);
|
|
1533
|
+
if (refusal) throw new Error(refusal);
|
|
1534
|
+
|
|
1535
|
+
const after = consumeRecreate(game);
|
|
1536
|
+
const runs = ((await this.profiles.read())?.runs ?? 1) + 1;
|
|
1537
|
+
const previousStar = game.names.star;
|
|
1538
|
+
const profile = exportProfile(after, { runs, lastStar: previousStar, nowMs: this.now() });
|
|
1539
|
+
const { starName, homeName } = autoNames(seed, runs);
|
|
1540
|
+
|
|
1541
|
+
await this.store.archiveRun(runs - 1, this.games.file);
|
|
1542
|
+
const created = await this.store.createOnce(spec);
|
|
1543
|
+
const fresh = startGame(
|
|
1544
|
+
created.system,
|
|
1545
|
+
{
|
|
1546
|
+
seed,
|
|
1547
|
+
starName,
|
|
1548
|
+
homeName,
|
|
1549
|
+
carry: {
|
|
1550
|
+
credits: after.credits,
|
|
1551
|
+
tungsten: after.tungsten,
|
|
1552
|
+
energyKj: after.energyKj,
|
|
1553
|
+
inventory: after.inventory,
|
|
1554
|
+
upgrades: after.upgrades,
|
|
1555
|
+
seedBags: after.seedBags,
|
|
1556
|
+
people: profile.people,
|
|
1557
|
+
samples: after.samples,
|
|
1558
|
+
},
|
|
1559
|
+
},
|
|
1560
|
+
this.now(),
|
|
1561
|
+
);
|
|
1562
|
+
this.system = created.system;
|
|
1563
|
+
this.game = fresh;
|
|
1564
|
+
await this.saveGame();
|
|
1565
|
+
await this.profiles.write(profile);
|
|
1566
|
+
await this.push(
|
|
1567
|
+
'genesis.recreated',
|
|
1568
|
+
`点火。『${previousStar}』留在身后,旧地图已归档;这一船 ${profile.people} 个人重新回到休眠舱,飞向『${starName}』。`,
|
|
1569
|
+
);
|
|
1570
|
+
return {
|
|
1571
|
+
text: `再创世完成:点火、离轨,飞向『${starName}』,落脚点叫『${homeName}』。旧地图『${previousStar}』已归档作废。带了 ${profile.people} 个人、${Math.round(profile.energyKj).toLocaleString('en-US')} kJ、${profile.tungsten} 份钨过来——先 genesis_look 看看脚下。`,
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1506
1575
|
/** 面板「去某处」:按经纬度发起地表移动,返回移动中的状态。 */
|
|
1507
1576
|
private async moveFromPanel(input: unknown): Promise<GenesisPanelState> {
|
|
1508
1577
|
await this.sync();
|
|
@@ -1639,8 +1708,29 @@ export class GenesisWorld implements World {
|
|
|
1639
1708
|
game.calendar.planetDaysPerYear * 24,
|
|
1640
1709
|
planet.obliquityDeg,
|
|
1641
1710
|
);
|
|
1711
|
+
const outdoor = withIceWater(site, climate);
|
|
1712
|
+
// 温室:作物感受到的是室内温度,不是室外——面板与详情必须与生长公式同源,
|
|
1713
|
+
// 否则会出现「室外 -8.4℃、详情也 -8.4℃」这种看起来建了温室没用的错觉。
|
|
1714
|
+
const greenhouse = game.structures.find((s) => s.kind === 'greenhouse' && s.siteKey === siteKey);
|
|
1715
|
+
if (greenhouse && structurePowered(game, greenhouse)) {
|
|
1716
|
+
const interior = greenhouseClimate(outdoor.tempC, greenhouse);
|
|
1717
|
+
if (interior !== null) {
|
|
1718
|
+
return {
|
|
1719
|
+
climate: {
|
|
1720
|
+
...outdoor,
|
|
1721
|
+
tempC: interior.tempC,
|
|
1722
|
+
artificialDeltaC: interior.deltaC,
|
|
1723
|
+
realismCores: interior.realismCores,
|
|
1724
|
+
wetness: Math.min(PUMP_MAX_WETNESS, outdoor.wetness + 0.1),
|
|
1725
|
+
fertility: Math.min(1, outdoor.fertility + 0.15),
|
|
1726
|
+
nutrients: site.nutrients,
|
|
1727
|
+
},
|
|
1728
|
+
label: `站点 ${siteKey}(${planet.name} · 温室内 ${interior.tempC}℃)`,
|
|
1729
|
+
};
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1642
1732
|
return {
|
|
1643
|
-
climate: { ...
|
|
1733
|
+
climate: { ...outdoor, nutrients: site.nutrients },
|
|
1644
1734
|
label: `站点 ${siteKey}(${planet.name})`,
|
|
1645
1735
|
};
|
|
1646
1736
|
}
|
|
@@ -1851,11 +1941,15 @@ export class GenesisWorld implements World {
|
|
|
1851
1941
|
const ambient = site ? this.ambientFor(game, system, site) : null;
|
|
1852
1942
|
const target = s.targetTempC ?? null;
|
|
1853
1943
|
const delta = ambient !== null && target !== null ? Math.abs(target - ambient) : 0;
|
|
1944
|
+
const powered = structurePowered(game, s);
|
|
1945
|
+
const interior = powered && ambient !== null ? greenhouseClimate(ambient, s) : null;
|
|
1854
1946
|
return {
|
|
1855
1947
|
siteKey: s.siteKey,
|
|
1856
1948
|
targetC: target,
|
|
1857
1949
|
ambientC: ambient,
|
|
1858
1950
|
deltaC: Math.round(delta * 10) / 10,
|
|
1951
|
+
interiorC: interior === null ? null : interior.tempC,
|
|
1952
|
+
powered,
|
|
1859
1953
|
realismCores: (s.cores ?? []).filter((c) => c === 'realism').length,
|
|
1860
1954
|
coldStores: coldStoresAt(game, s.siteKey),
|
|
1861
1955
|
};
|
|
@@ -1983,6 +2077,10 @@ export class GenesisWorld implements World {
|
|
|
1983
2077
|
? { awake: first.awake, dormant: first.dormant, food: first.food, water: first.water, oxygen: first.oxygen, hoursLeft: first.hoursLeft }
|
|
1984
2078
|
: null,
|
|
1985
2079
|
population: populationStatus(game),
|
|
2080
|
+
recreate: (() => {
|
|
2081
|
+
const blockers = recreateBlockers(game);
|
|
2082
|
+
return { blockers, ready: blockers.length === 0, seed: String(GENESIS_DEFAULTS.seed), starMass: GENESIS_DEFAULTS.starMass };
|
|
2083
|
+
})(),
|
|
1986
2084
|
};
|
|
1987
2085
|
}
|
|
1988
2086
|
|
|
@@ -2169,6 +2267,14 @@ export class GenesisWorld implements World {
|
|
|
2169
2267
|
system: StarSystem;
|
|
2170
2268
|
}> {
|
|
2171
2269
|
const result = await this.createSystem(spec);
|
|
2270
|
+
// 死局判定:母星几乎没有可站人的陆地时,子代理拒绝迫降(不写档、不留半成品)。
|
|
2271
|
+
if (result.created) {
|
|
2272
|
+
const refusal = landingRefusal(result.system);
|
|
2273
|
+
if (refusal) {
|
|
2274
|
+
await this.store.delete();
|
|
2275
|
+
throw new Error(refusal);
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2172
2278
|
if (this.game) return { created: result.created, started: false, system: result.system };
|
|
2173
2279
|
const game = this.startNewGame(result.system, names);
|
|
2174
2280
|
this.game = game;
|
|
@@ -4077,3 +4183,14 @@ export class GenesisWorld implements World {
|
|
|
4077
4183
|
};
|
|
4078
4184
|
}
|
|
4079
4185
|
}
|
|
4186
|
+
|
|
4187
|
+
/** 自动起名:面板【再创世】只有种子与恒星质量两个输入,名字由种子确定性生成。 */
|
|
4188
|
+
const STAR_NAMES = ['启明', '长庚', '天狼', '织女', '南门', '毕宿', '参宿', '心宿', '镇星', '岁星'];
|
|
4189
|
+
const HOME_NAMES = ['栖原', '临渊', '望舒', '沧鸣', '岩湾', '新野', '白岸', '孤屿', '沉岛', '霜原'];
|
|
4190
|
+
|
|
4191
|
+
function autoNames(seed: GenesisSpec['seed'], runs: number): { starName: string; homeName: string } {
|
|
4192
|
+
const key = typeof seed === 'number' ? `n:${seed}` : `s:${seed}`;
|
|
4193
|
+
const star = STAR_NAMES[hashSeed(`star:${key}`) % STAR_NAMES.length]!;
|
|
4194
|
+
const home = HOME_NAMES[hashSeed(`home:${key}:${runs}`) % HOME_NAMES.length]!;
|
|
4195
|
+
return { starName: star, homeName: home };
|
|
4196
|
+
}
|