cortico-world-genesis 2.0.2 → 2.1.4

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/src/world.ts CHANGED
@@ -20,6 +20,9 @@ import {
20
20
  displayName,
21
21
  foundSite,
22
22
  harvestAt,
23
+ transplantAt,
24
+ REMOVE_MIN_HEALTH,
25
+ removePlant,
23
26
  installCore,
24
27
  setGreenhouseTarget,
25
28
  coldStoresAt,
@@ -111,12 +114,13 @@ import {
111
114
  TUNGSTEN_START,
112
115
  type GameState,
113
116
  type Location,
117
+ type StructureRecord,
114
118
  type WaitUntil,
115
119
  } from './game.ts';
116
120
  import { sparkPlugOutputKj } from './trade.ts';
117
121
  import { orderText } from './orders.ts';
118
122
  import { CHAPTER_TITLES, protocolStatus, protocolText } from './protocol.ts';
119
- import { NUTRIENT_NEEDS, SPECIES, SPECIES_IDS, RESOURCE_LABELS, bagWeightKg, type SpeciesId } from './flora.ts';
123
+ import { NUTRIENT_NEEDS, SPECIES, SPECIES_IDS, RESOURCE_LABELS, bagWeightKg, speciesTempLabel, type SpeciesId } from './flora.ts';
120
124
  import { RESIDENTS_PER_LABOR } from './life.ts';
121
125
  import { climateAt, siteKeyOf, type Site } from './site.ts';
122
126
  import { BUY_GOODS, SELL_GOODS, creditTier, dayIndexOf, sellPriceTable, shopOpen, shopWindowText, telescopeWindow } from './trade.ts';
@@ -132,6 +136,9 @@ import { planetVisibility, terrainPatch, terrainPatchText, type TerrainBody } fr
132
136
  import { targetBiomeFor, terraCellsFor, type TerraMap } from './terra.ts';
133
137
  import { guideText, guideTopics } from './guide.ts';
134
138
  import { infoText } from './info.ts';
139
+ import { applyAlgae, breedAt, PLANTER_CLIMATE, PLANTER_SUBSTRATE } from './game.ts';
140
+ import { inspectPlantText } from './inspect.ts';
141
+ import type { ClimateSample } from './flora.ts';
135
142
 
136
143
  const ENV_PROMPT_FILE = fileURLToPath(new URL('./ENV_PROMPT.md', import.meta.url));
137
144
 
@@ -242,8 +249,9 @@ const WAIT_PARAMETERS = {
242
249
  },
243
250
  until: {
244
251
  type: 'string',
245
- enum: ['dawn', 'dusk', 'ripe', 'built', 'arrive'],
246
- description: '等到某个事件:天亮 / 天黑 / 有作物成熟 / 工程完工 / 抵达。和 hours 二选一。',
252
+ enum: ['dawn', 'dusk', 'noon', 'open', 'ripe', 'built', 'arrive'],
253
+ description:
254
+ '等到某个事件:天亮 / 天黑 / 中午 12 时 / 商店开门(也是 12 时)/ 有作物成熟 / 工程完工 / 抵达。和 hours 二选一。',
247
255
  },
248
256
  },
249
257
  } as const;
@@ -356,6 +364,26 @@ const BURN_PARAMETERS = {
356
364
  required: ['kg'],
357
365
  } as const;
358
366
 
367
+ const TRANSPLANT_PARAMETERS = {
368
+ type: 'object',
369
+ additionalProperties: false,
370
+ properties: {
371
+ plant: { type: 'string', description: '哪株/哪群(genesis_flora 里的 id)。' },
372
+ site: { type: 'string', description: '可选:它在哪个站点或种植盆(planter:<id>)。不传就按 id 找。' },
373
+ },
374
+ required: ['plant'],
375
+ } as const;
376
+
377
+ const REMOVE_PARAMETERS = {
378
+ type: 'object',
379
+ additionalProperties: false,
380
+ properties: {
381
+ plant: { type: 'string', description: '哪株/哪群(genesis_flora 里的 id)。' },
382
+ site: { type: 'string', description: '可选:它在哪个站点或种植盆(planter:<id>)。不传就按 id 找。' },
383
+ },
384
+ required: ['plant'],
385
+ } as const;
386
+
359
387
  const BUILD_PARAMETERS = {
360
388
  type: 'object',
361
389
  additionalProperties: false,
@@ -381,7 +409,7 @@ const INSTALL_PARAMETERS = {
381
409
  ],
382
410
  description:
383
411
  '装什么:monitor=环境监测器(150,000 kJ);counter=凌日计数器;sail=太阳能帆(6,000 kJ,建在脚下这块陆地上,产量按经纬度算);' +
384
- 'planter=种植盆(8,000 kJ,不用钨:只能同时种 3 粒,通电就夹在 22℃/湿度 0.7——极热极冷母星的第一口粮);' +
412
+ 'planter=种植盆(8,000 kJ,不用钨:只能同时种 3 粒,通电就夹在 22℃/湿度 0.7;人工基质养分固定、不能施肥也不消耗——极热极冷母星的第一口粮);' +
385
413
  'greenhouse=温室核心;biome_changer=群系改变器;cooler=制冷核心;heater=制热核心;pump=水泵;' +
386
414
  'warehouse=仓库(只能建在陆地站点,1,000 kg);drone_cluster=无人机集群(要 serves 一个仓库,远程取货 100 kJ/kg);rocket=运载火箭(250 kg,星际航行时跟着走);' +
387
415
  'kiln=炭化炉(生物质→活性炭+灰);purifier=净化器(水+活性炭→饮用水);sealer=封装器(氧气+钢瓶→氧气瓶);' +
@@ -818,6 +846,73 @@ export const GENESIS_TOOL_DECLS: ReadonlyArray<Omit<ToolDef, 'handler'>> = [
818
846
  required: ['query'],
819
847
  },
820
848
  },
849
+ {
850
+ name: 'genesis_transplant',
851
+ description:
852
+ '移栽:把一株长起来的地里作物挖回种子袋(500 kJ),基因和原来一模一样——这是保住好基因的办法,代价是这株不能再收了。' +
853
+ '结实的株给 2 粒,长到 15% 以上的给 1 粒,刚发芽的不行。藻类/微生物群落取样本(3 kg,至少要 5 kg 一群),给一袋 5 粒。',
854
+ tags: ['write'],
855
+ parameters: TRANSPLANT_PARAMETERS,
856
+ },
857
+ {
858
+ name: 'genesis_breed',
859
+ description:
860
+ '留种:让一株长到 60% 以上的作物自交(300 kJ / 0.2 母星时 / 3 粒),或者两株同物种杂交(800 kJ / 0.5 母星时 / 4 粒)。' +
861
+ '自交沿用母本基因、产量每代退 4%;杂交取双亲的平均、有三成概率直接继承更好的那个。收割本身不返种子,留种只能靠这里或移栽。',
862
+ tags: ['write'],
863
+ parameters: {
864
+ type: 'object',
865
+ additionalProperties: false,
866
+ properties: {
867
+ plant: { type: 'string', description: '哪一株(id)。' },
868
+ mode: { type: 'string', enum: ['self', 'cross'], description: 'self 自交、cross 杂交。' },
869
+ partner: { type: 'string', description: '杂交的另一株(同站点、同物种、也长到 60% 以上)。' },
870
+ site: { type: 'string', description: '站点/种植盆。不传就在所有地里找这株的 id。' },
871
+ },
872
+ required: ['plant', 'mode'],
873
+ },
874
+ },
875
+ {
876
+ name: 'genesis_algae',
877
+ description:
878
+ '拌藻肥:从一丛蓝藻里取 3 kg(至少要 5 kg 一群),给一块旱地站点补 0.02 氮和 0.005 钾(200 kJ)。' +
879
+ '氮只有三条路:蓝藻在湿地里长、跨格子固氮给附近的旱地,以及这个藻肥——没有别的办法补氮。',
880
+ tags: ['write'],
881
+ parameters: {
882
+ type: 'object',
883
+ additionalProperties: false,
884
+ properties: {
885
+ colony: { type: 'string', description: '哪一丛蓝藻(id)。' },
886
+ site: { type: 'string', description: '泼到哪块旱地站点。' },
887
+ colonySite: { type: 'string', description: '蓝藻所在的湿地站点。不传就自己找。' },
888
+ },
889
+ required: ['colony', 'site'],
890
+ },
891
+ },
892
+ {
893
+ name: 'genesis_inspect',
894
+ description:
895
+ '看一株作物的全部底细:基因四项、有效温区、当前温度湿度肥力、四维养分的当前值与阈值(最缺哪一维)、生长因子的拆解、按当前速度还要多少母星时、预计收成。' +
896
+ '觉得「怎么不快长」的时候先看这个。',
897
+ tags: ['read'],
898
+ parameters: {
899
+ type: 'object',
900
+ additionalProperties: false,
901
+ properties: {
902
+ plant: { type: 'string', description: '哪一株(id)。' },
903
+ site: { type: 'string', description: '站点/种植盆。不传就自己找。' },
904
+ },
905
+ required: ['plant'],
906
+ },
907
+ },
908
+ {
909
+ name: 'genesis_remove',
910
+ description:
911
+ '拔掉一株死掉的作物(枯死,或健康低于 20%):腾出地块/种植盆,不花电、不花时间。' +
912
+ '活着的不能拔——想处理它就收掉(结实的话)或者移栽。',
913
+ tags: ['write'],
914
+ parameters: REMOVE_PARAMETERS,
915
+ },
821
916
  ];
822
917
 
823
918
  export interface GenesisWorldOptions {
@@ -835,6 +930,10 @@ export class GenesisWorld implements World {
835
930
  private system: StarSystem | null = null;
836
931
  private game: GameState | null = null;
837
932
  private timer: ReturnType<typeof setTimeout> | null = null;
933
+ /** 面板点击期间为 true:事件只攒不推,窗口结束再合并成一条。 */
934
+ private quiet = false;
935
+ private merged: Array<{ type: string; texts: string[] }> = [];
936
+ private lastMergedPushMs = 0;
838
937
 
839
938
  private readonly store: GenesisStore;
840
939
  private readonly games: GameStore;
@@ -907,9 +1006,84 @@ export class GenesisWorld implements World {
907
1006
  this.dutyTool(),
908
1007
  this.resetTool(),
909
1008
  this.infoTool(),
1009
+ this.transplantTool(),
1010
+ this.removeTool(),
1011
+ this.breedTool(),
1012
+ this.algaeTool(),
1013
+ this.inspectTool(),
910
1014
  ];
911
1015
  }
912
1016
 
1017
+ private breedTool(): ToolDef {
1018
+ return {
1019
+ ...GENESIS_TOOL_DECLS[37]!,
1020
+ handler: async (args) => {
1021
+ const ready = await this.readyState();
1022
+ if ('error' in ready) return { text: ready.error, failed: true };
1023
+ await this.sync();
1024
+ const system = await this.readSystem();
1025
+ if (!system || !this.game) return { text: '还没有创世。先 genesis_create。', failed: true };
1026
+ try {
1027
+ const partner = typeof args.partner === 'string' ? args.partner : undefined;
1028
+ const site = typeof args.site === 'string' ? args.site : undefined;
1029
+ const found = this.findPlant(this.game, args.plant, site);
1030
+ const mode = args.mode === 'cross' ? 'cross' : 'self';
1031
+ const result = breedAt(this.game, found.siteKey, found.plant.id, mode, partner);
1032
+ this.game = result.state;
1033
+ await this.saveGame();
1034
+ return { text: result.text };
1035
+ } catch (error) {
1036
+ return { text: error instanceof Error ? error.message : String(error), failed: true };
1037
+ }
1038
+ },
1039
+ };
1040
+ }
1041
+
1042
+ private algaeTool(): ToolDef {
1043
+ return {
1044
+ ...GENESIS_TOOL_DECLS[38]!,
1045
+ handler: async (args) => {
1046
+ const ready = await this.readyState();
1047
+ if ('error' in ready) return { text: ready.error, failed: true };
1048
+ await this.sync();
1049
+ const system = await this.readSystem();
1050
+ if (!system || !this.game) return { text: '还没有创世。先 genesis_create。', failed: true };
1051
+ try {
1052
+ const colonySite = typeof args.colonySite === 'string' ? args.colonySite : undefined;
1053
+ const found = this.findPlant(this.game, args.colony, colonySite);
1054
+ const target = this.resolveSite(this.game, args.site);
1055
+ const result = applyAlgae(system, this.game, target, found.siteKey, found.plant.id);
1056
+ this.game = result.state;
1057
+ await this.saveGame();
1058
+ return { text: result.text };
1059
+ } catch (error) {
1060
+ return { text: error instanceof Error ? error.message : String(error), failed: true };
1061
+ }
1062
+ },
1063
+ };
1064
+ }
1065
+
1066
+ private inspectTool(): ToolDef {
1067
+ return {
1068
+ ...GENESIS_TOOL_DECLS[39]!,
1069
+ handler: async (args) => {
1070
+ const ready = await this.readyState();
1071
+ if ('error' in ready) return { text: ready.error, failed: true };
1072
+ await this.sync();
1073
+ const system = await this.readSystem();
1074
+ if (!system || !this.game) return { text: '还没有创世。先 genesis_create。', failed: true };
1075
+ try {
1076
+ const site = typeof args.site === 'string' ? args.site : undefined;
1077
+ const found = this.findPlant(this.game, args.plant, site);
1078
+ const { climate, label } = this.climateForPlant(this.game, system, found.siteKey);
1079
+ return { text: inspectPlantText(found.plant, climate, label) };
1080
+ } catch (error) {
1081
+ return { text: error instanceof Error ? error.message : String(error), failed: true };
1082
+ }
1083
+ },
1084
+ };
1085
+ }
1086
+
913
1087
  webUi(): WorldWebUiDecl {
914
1088
  return {
915
1089
  label: '创世记',
@@ -926,7 +1100,7 @@ export class GenesisWorld implements World {
926
1100
  id: 'system',
927
1101
  title: '这一颗星球',
928
1102
  description: '开局在这里创世:种子、恒星质量、行星数、卫星上限,还有恒星与母星的名字。写进存档后锁定,删档才能重选。',
929
- getMethods: ['state', 'create', 'reset', 'map', 'press', 'monitor', 'sell', 'site', 'plant', 'harvest', 'burn', 'build', 'install', 'store', 'storeDo', 'look', 'veins', 'survey', 'wait', 'order', 'cylinder', 'chart', 'mutate', 'wake', 'preview'],
1103
+ getMethods: ['state', 'create', 'reset', 'map', 'press', 'monitor', 'sell', 'site', 'plant', 'harvest', 'transplant', 'remove', 'breed', 'algae', 'inspect', 'burn', 'build', 'install', 'store', 'storeDo', 'look', 'veins', 'survey', 'wait', 'order', 'cylinder', 'chart', 'mutate', 'wake', 'preview'],
930
1104
  },
931
1105
  {
932
1106
  id: 'upgrade',
@@ -1006,6 +1180,7 @@ export class GenesisWorld implements World {
1006
1180
  await this.saveGame();
1007
1181
  }
1008
1182
  for (const event of result.events) await this.push(event.type, event.text);
1183
+ if (!this.quiet) await this.flushMerged();
1009
1184
  this.schedule();
1010
1185
  }
1011
1186
 
@@ -1085,6 +1260,19 @@ export class GenesisWorld implements World {
1085
1260
  // —— 面板 ——
1086
1261
 
1087
1262
  private async invoke(panel: string, method: string, args: unknown[]): Promise<unknown> {
1263
+ // 面板上的每一次点击都不是「世界出了事」:时间照推、存档照写,但事件先压着,
1264
+ // 由 flushPanelEvents() 按母星时合并成一条,免得人类连点发电机把模型叫醒十次。
1265
+ const outerQuiet = this.quiet;
1266
+ this.quiet = true;
1267
+ try {
1268
+ return await this.invokePanel(panel, method, args);
1269
+ } finally {
1270
+ this.quiet = outerQuiet;
1271
+ if (!outerQuiet) await this.flushMerged();
1272
+ }
1273
+ }
1274
+
1275
+ private async invokePanel(panel: string, method: string, args: unknown[]): Promise<unknown> {
1088
1276
  if (panel === 'upgrade') {
1089
1277
  switch (method) {
1090
1278
  case 'state':
@@ -1147,6 +1335,16 @@ export class GenesisWorld implements World {
1147
1335
  return this.floraAction('plant', args);
1148
1336
  case 'harvest':
1149
1337
  return this.floraAction('harvest', args);
1338
+ case 'transplant':
1339
+ return this.floraAction('transplant', args);
1340
+ case 'remove':
1341
+ return this.floraAction('remove', args);
1342
+ case 'breed':
1343
+ return this.floraAction('breed', args);
1344
+ case 'algae':
1345
+ return this.floraAction('algae', args);
1346
+ case 'inspect':
1347
+ return this.floraAction('inspect', args);
1150
1348
  case 'burn':
1151
1349
  return this.floraAction('burn', args);
1152
1350
  case 'build':
@@ -1391,6 +1589,62 @@ export class GenesisWorld implements World {
1391
1589
  return this.system;
1392
1590
  }
1393
1591
 
1592
+ /** 按 id 找一株作物(可以指定站点/种植盆)。 */
1593
+ private findPlant(
1594
+ game: GameState,
1595
+ rawId: unknown,
1596
+ rawSite?: unknown,
1597
+ ): { siteKey: string; plant: GameState['plants'][string][number] } {
1598
+ const plantId = String(rawId ?? '').trim();
1599
+ if (!plantId) throw new Error('要指定哪一株:plant 传它的 id。');
1600
+ const asked = String(rawSite ?? '').trim();
1601
+ if (asked) {
1602
+ const plant = (game.plants[asked] ?? []).find((p) => p.id === plantId);
1603
+ if (!plant) throw new Error(`${asked} 里面没有这株作物:${plantId}`);
1604
+ return { siteKey: asked, plant };
1605
+ }
1606
+ for (const [siteKey, list] of Object.entries(game.plants)) {
1607
+ const plant = list.find((p) => p.id === plantId);
1608
+ if (plant) return { siteKey, plant };
1609
+ }
1610
+ throw new Error(`找不到这株作物:${plantId}`);
1611
+ }
1612
+
1613
+ /** 一株作物现在感受的气候:地里按格子算,种植盆用人工气候(通电)。 */
1614
+ private climateForPlant(
1615
+ game: GameState,
1616
+ system: StarSystem | null,
1617
+ siteKey: string,
1618
+ ): { climate: ClimateSample; label: string } {
1619
+ const site = game.sites.find((s) => s.key === siteKey);
1620
+ if (!site) {
1621
+ const planter = game.structures.find((s) => s.kind === 'planter' && siteKey === `planter:${s.id}`);
1622
+ if (!planter) throw new Error(`没有这个站点:${siteKey}`);
1623
+ const powered = structurePowered(game, planter);
1624
+ return {
1625
+ climate: powered
1626
+ ? { ...PLANTER_CLIMATE, nutrients: { ...PLANTER_SUBSTRATE } }
1627
+ : { ...PLANTER_CLIMATE, tempC: 0, wetness: 0.3, fertility: 0.3, nutrients: { ...PLANTER_SUBSTRATE } },
1628
+ label: `种植盆(${powered ? '通电' : '断电'},人工基质)`,
1629
+ };
1630
+ }
1631
+ if (!system) throw new Error('还没有创世。');
1632
+ const planet = system.planets[site.planetIndex - 1];
1633
+ if (!planet || planet.surface.kind !== 'terrestrial') throw new Error('这里没有地表气候。');
1634
+ const climate = climateAt(
1635
+ planet.surface,
1636
+ site.latDeg,
1637
+ site.lonDeg,
1638
+ nowPlanetHours(game, this.now()),
1639
+ game.calendar.planetDaysPerYear * 24,
1640
+ planet.obliquityDeg,
1641
+ );
1642
+ return {
1643
+ climate: { ...climate, nutrients: site.nutrients },
1644
+ label: `站点 ${siteKey}(${planet.name})`,
1645
+ };
1646
+ }
1647
+
1394
1648
  /** 温室所在站点的室外温度;拿不到返回 null(面板滑杆只做参考)。 */
1395
1649
  private ambientFor(game: GameState, system: StarSystem | null, site: Site): number | null {
1396
1650
  if (!system) return null;
@@ -1545,7 +1799,20 @@ export class GenesisWorld implements World {
1545
1799
  name: id === 'survey' ? '测绘数据' : RESOURCE_LABELS[id as keyof typeof RESOURCE_LABELS] ?? id,
1546
1800
  amount: n,
1547
1801
  })),
1548
- bags: game.seedBags.map((b) => ({ id: b.id, name: SPECIES[b.species].name, count: b.count, premium: b.premium })),
1802
+ crops: Object.entries(game.plants).flatMap(([site, list]) =>
1803
+ list.map((p) => ({
1804
+ site,
1805
+ id: p.id,
1806
+ species: p.species,
1807
+ name: SPECIES[p.species].name,
1808
+ stage: p.stage,
1809
+ progress: Math.round(p.progress * 100) / 100,
1810
+ ripe: p.stage === 'ripe',
1811
+ health: Math.round(p.health * 100) / 100,
1812
+ dead: p.stage === 'withering' || p.health < REMOVE_MIN_HEALTH,
1813
+ })),
1814
+ ),
1815
+ bags: game.seedBags.map((b) => ({ id: b.id, name: speciesTempLabel(b.species), count: b.count, premium: b.premium })),
1549
1816
  planters: game.structures
1550
1817
  .filter((s) => s.kind === 'planter')
1551
1818
  .map((s) => {
@@ -1836,8 +2103,16 @@ export class GenesisWorld implements World {
1836
2103
  private async pressFromPanel(): Promise<GenesisPanelState> {
1837
2104
  await this.sync();
1838
2105
  if (!this.game) throw new Error('还没有创世。');
2106
+ const before = this.game.energyKj;
1839
2107
  this.game = pressGenerator(this.game, this.now());
1840
2108
  await this.saveGame();
2109
+ const gained = this.game.energyKj - before;
2110
+ if (gained > 0) {
2111
+ await this.push(
2112
+ 'genesis.hand',
2113
+ `人类手摇了一次动能发电机:+${gained.toFixed(0)} kJ(电池现在 ${Math.floor(this.game.energyKj).toLocaleString('en-US')} kJ)。`,
2114
+ );
2115
+ }
1841
2116
  return this.panelState();
1842
2117
  }
1843
2118
 
@@ -1907,6 +2182,39 @@ export class GenesisWorld implements World {
1907
2182
  }
1908
2183
 
1909
2184
  private async push(type: string, text: string): Promise<void> {
2185
+ // 面板点击期间(quiet)只把事件攒起来,攒到窗口结束再合并成一条;
2186
+ // 这样人类连点十次发电机,模型也只会被叫醒一次。
2187
+ if (this.quiet) {
2188
+ const same = this.merged.find((m) => m.type === type);
2189
+ if (same) same.texts.push(text);
2190
+ else this.merged.push({ type, texts: [text] });
2191
+ return;
2192
+ }
2193
+ await this.pushNow(type, text);
2194
+ }
2195
+
2196
+ /** 合并窗口:一个母星时(至少 60 秒)内最多推一条。 */
2197
+ private mergedWindowMs(): number {
2198
+ return Math.max(60_000, this.game?.msPerPlanetHour ?? 60_000);
2199
+ }
2200
+
2201
+ private async flushMerged(force = false): Promise<void> {
2202
+ if (this.merged.length === 0) return;
2203
+ if (!force && this.now() - this.lastMergedPushMs < this.mergedWindowMs()) return;
2204
+ const groups = this.merged;
2205
+ this.merged = [];
2206
+ this.lastMergedPushMs = this.now();
2207
+ for (const group of groups) {
2208
+ const first = group.texts[0]!;
2209
+ const text =
2210
+ group.texts.length === 1
2211
+ ? first
2212
+ : `${first}(这一母星时里还有 ${group.texts.length - 1} 条同类,一并说了。)`;
2213
+ await this.pushNow(group.type, text);
2214
+ }
2215
+ }
2216
+
2217
+ private async pushNow(type: string, text: string): Promise<void> {
1910
2218
  const host = this.host;
1911
2219
  if (!host) return;
1912
2220
  try {
@@ -2474,7 +2782,7 @@ export class GenesisWorld implements World {
2474
2782
  }
2475
2783
  lines.push(this.inventoryLine(game));
2476
2784
  if (game.seedBags.length > 0) {
2477
- lines.push(`种子袋:${game.seedBags.map((b) => `${b.id}(${SPECIES[b.species].name} ×${b.count}${b.premium ? ',高级' : ''})`).join('、')}`);
2785
+ lines.push(`种子袋:${game.seedBags.map((b) => `${b.id}(${speciesTempLabel(b.species)} ×${b.count}${b.premium ? ',高级' : ''})`).join('、')}`);
2478
2786
  }
2479
2787
  return lines.join('\n');
2480
2788
  }
@@ -2509,7 +2817,7 @@ export class GenesisWorld implements World {
2509
2817
  ).join(';'),
2510
2818
  ];
2511
2819
  if (game.seedBags.length > 0) {
2512
- lines.push(`种子袋:${game.seedBags.map((b) => `${b.id}(${SPECIES[b.species].name} ×${b.count})`).join('、')}`);
2820
+ lines.push(`种子袋:${game.seedBags.map((b) => `${b.id}(${speciesTempLabel(b.species)} ×${b.count})`).join('、')}`);
2513
2821
  }
2514
2822
  return lines.join('\n');
2515
2823
  }
@@ -2754,10 +3062,60 @@ export class GenesisWorld implements World {
2754
3062
  }
2755
3063
  if (!site) throw new Error(`找不到这株作物:${plantId}`);
2756
3064
  next = harvestAt(system, game, site, plantId);
3065
+ } else if (method === 'transplant') {
3066
+ const plantId = String(args[0] ?? '').trim();
3067
+ if (!plantId) throw new Error('要移栽哪一株/哪一群?');
3068
+ const asked = String(args[1] ?? '').trim();
3069
+ const site =
3070
+ asked ||
3071
+ Object.keys(game.plants).find((key) => (game.plants[key] ?? []).some((p) => p.id === plantId));
3072
+ if (!site) throw new Error(`找不到这株作物:${plantId}`);
3073
+ next = transplantAt(game, site, plantId);
3074
+ } else if (method === 'remove') {
3075
+ const plantId = String(args[0] ?? '').trim();
3076
+ if (!plantId) throw new Error('要拔掉哪一株/哪一群?');
3077
+ const asked = String(args[1] ?? '').trim();
3078
+ const site =
3079
+ asked ||
3080
+ Object.keys(game.plants).find((key) => (game.plants[key] ?? []).some((p) => p.id === plantId));
3081
+ if (!site) throw new Error(`找不到这株作物:${plantId}`);
3082
+ next = removePlant(game, site, plantId);
3083
+ } else if (method === 'breed') {
3084
+ const found = this.findPlant(game, args[0], args[1]);
3085
+ const partner = typeof args[2] === 'string' ? args[2] : undefined;
3086
+ next = breedAt(game, found.siteKey, found.plant.id, partner ? 'cross' : 'self', partner);
3087
+ } else if (method === 'algae') {
3088
+ const found = this.findPlant(game, args[0]);
3089
+ const target = this.resolveSite(game, args[1]);
3090
+ next = applyAlgae(system, game, target, found.siteKey, found.plant.id);
3091
+ } else if (method === 'inspect') {
3092
+ const found = this.findPlant(game, args[0], args[1]);
3093
+ const { climate, label } = this.climateForPlant(game, system, found.siteKey);
3094
+ return { text: inspectPlantText(found.plant, climate, label) } as never;
2757
3095
  } else if (method === 'burn') {
2758
3096
  next = burnBiomass(game, Number(args[0] ?? 0));
2759
3097
  } else if (method === 'build') {
2760
- next = buildStructure(system, game, String(args[0]) as 'greenhouse' | 'biome_changer', this.resolveSite(game, args[1]), this.now());
3098
+ // 面板发的是 [{ kind, site? }];早期调用方发的是 [kind, siteKey]。两种都收。
3099
+ const payload = args[0];
3100
+ const askedKind =
3101
+ payload && typeof payload === 'object'
3102
+ ? (payload as { kind?: unknown }).kind
3103
+ : payload;
3104
+ const askedSite =
3105
+ payload && typeof payload === 'object'
3106
+ ? (payload as { site?: unknown }).site
3107
+ : args[1];
3108
+ const kind = String(askedKind ?? '').trim();
3109
+ if (!Object.prototype.hasOwnProperty.call(BUILD_SPECS, kind)) {
3110
+ throw new Error(`不认识的建筑:${kind || '(空)'}——先在建造下拉里挑一个。`);
3111
+ }
3112
+ next = buildStructure(
3113
+ system,
3114
+ game,
3115
+ kind as StructureRecord['kind'],
3116
+ this.resolveSite(game, typeof askedSite === 'string' ? askedSite : undefined),
3117
+ this.now(),
3118
+ );
2761
3119
  }
2762
3120
  if (next) {
2763
3121
  this.game = next.state;
@@ -2826,7 +3184,7 @@ export class GenesisWorld implements World {
2826
3184
  };
2827
3185
  }
2828
3186
  const lines = bags.map(
2829
- (b, i) => ` ${i + 1}. ${b.premium ? '高级' : '随机'}${SPECIES[b.species].name} ×${b.count} 粒(${b.id},${bagWeightKg(b).toFixed(3)} kg)`,
3187
+ (b, i) => ` ${i + 1}. ${b.premium ? '高级' : '随机'}${speciesTempLabel(b.species)} ×${b.count} 粒(${b.id},${bagWeightKg(b).toFixed(3)} kg)`,
2830
3188
  );
2831
3189
  return { text: `${label}(${bags.length}/${CONTAINER_BAG_SLOTS} 袋):\n${lines.join('\n')}\n取一袋:action: "take",building 传这个容器 id,bag 传括号里的 id。` };
2832
3190
  }
@@ -3344,15 +3702,22 @@ export class GenesisWorld implements World {
3344
3702
  await this.sync();
3345
3703
  if (!this.game) throw new Error('还没有创世。');
3346
3704
  const result =
3347
- id === 'telescope'
3348
- ? beginTelescopeUpgrade(this.game, this.now())
3349
- : id === 'spark_plug'
3350
- ? beginSparkPlugUpgrade(this.game, this.now())
3351
- : id === 'battery'
3352
- ? beginBatteryUpgrade(this.game, this.now())
3353
- : id === 'subagent'
3354
- ? beginSubagentUpgrade(this.game, this.now())
3355
- : beginMobilityRepair(this.game, this.now());
3705
+ id === 'mobility_core'
3706
+ ? beginMobilityRepair(this.game, this.now())
3707
+ : id === 'telescope'
3708
+ ? beginTelescopeUpgrade(this.game, this.now())
3709
+ : id === 'spark_plug'
3710
+ ? beginSparkPlugUpgrade(this.game, this.now())
3711
+ : id === 'battery'
3712
+ ? beginBatteryUpgrade(this.game, this.now())
3713
+ : id === 'subagent'
3714
+ ? beginSubagentUpgrade(this.game, this.now())
3715
+ : id === 'blueprints'
3716
+ ? beginBlueprintsUpgrade(this.game, this.now())
3717
+ : id === 'spectrometer'
3718
+ ? beginSpectrometerUpgrade(this.game, this.now())
3719
+ : null;
3720
+ if (!result) throw new Error(`船上没有这个可升级的东西:${id}`);
3356
3721
  this.game = result.state;
3357
3722
  await this.saveGame();
3358
3723
  return this.upgradeState();
@@ -3439,6 +3804,43 @@ export class GenesisWorld implements World {
3439
3804
  };
3440
3805
  }
3441
3806
 
3807
+ private transplantTool(): ToolDef {
3808
+ return this.uprootTool('transplant', 35);
3809
+ }
3810
+
3811
+ private removeTool(): ToolDef {
3812
+ return this.uprootTool('remove', 36);
3813
+ }
3814
+
3815
+ /** 移栽与拔除共用一套「找株 → 动手 → 存盘」;区别只在引擎函数。 */
3816
+ private uprootTool(kind: 'transplant' | 'remove', index: number): ToolDef {
3817
+ return {
3818
+ ...GENESIS_TOOL_DECLS[index]!,
3819
+ handler: async (args) => {
3820
+ const ready = await this.readyState();
3821
+ if ('error' in ready) return { text: ready.error, failed: true };
3822
+ const note = this.transitNote(ready.game);
3823
+ if (note) return note;
3824
+ const plantId = String(args.plant ?? '').trim();
3825
+ if (!plantId) return { text: '要处理哪一株/哪一群?', failed: true };
3826
+ const asked = String(args.site ?? '').trim();
3827
+ const siteKey = asked || Object.keys(ready.game.plants).find((key) => (ready.game.plants[key] ?? []).some((p) => p.id === plantId));
3828
+ if (!siteKey) return { text: `找不到这株作物:${plantId}`, failed: true };
3829
+ try {
3830
+ const result =
3831
+ kind === 'transplant'
3832
+ ? transplantAt(ready.game, siteKey, plantId)
3833
+ : removePlant(ready.game, siteKey, plantId);
3834
+ this.game = result.state;
3835
+ await this.saveGame();
3836
+ return result.text;
3837
+ } catch (error) {
3838
+ return { text: errorText(error), failed: true };
3839
+ }
3840
+ },
3841
+ };
3842
+ }
3843
+
3442
3844
  private protocolTool(): ToolDef {
3443
3845
  return {
3444
3846
  ...GENESIS_TOOL_DECLS[25]!,