cortico-world-genesis 2.2.7 → 2.6.0

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/game.ts CHANGED
@@ -117,6 +117,7 @@ import {
117
117
  premiumGenes,
118
118
  RESOURCE_LABELS,
119
119
  SPECIES,
120
+ SPECIES_IDS,
120
121
  nutrientFactor,
121
122
  seedId,
122
123
  type ClimateSample,
@@ -256,6 +257,30 @@ export interface GameState {
256
257
  epochRealMs: number;
257
258
  /** 1 星球时 = 多少现实毫秒(= 自转周期 / 24,可按时间加速)。 */
258
259
  msPerPlanetHour: number;
260
+ /** 时间倍速(1–200):只影响「现实时间 → 母星时」的换算,不改历法。 */
261
+ speed?: number;
262
+ /** 本局特许执照:旅游星系或技术星系。选后不可改。 */
263
+ charter?: 'tourism' | 'tech';
264
+ /** 知名度(0–100,只有旅游线用)。 */
265
+ reputation?: number;
266
+ /** 计算力存量(只有科技线用)。 */
267
+ compute?: number;
268
+ /** 昨天来过多少游客(面板显示用)。 */
269
+ visitorsYesterday?: number;
270
+ /** 员工数(外星雇员,吃工资)。 */
271
+ staff?: number;
272
+ /** 上一次结算特许经济(母星时)。 */
273
+ lastCharterHomeHours?: number;
274
+ /** 上一次发工资的日号。 */
275
+ lastPayrollDay?: number;
276
+ /** 上一次特许提醒的日号。 */
277
+ lastCharterWarnDay?: number;
278
+ /** 员工流失按天结算,避免一次清零。 */
279
+ lastAttritionDay?: number;
280
+ /** 唯一的奇观工程(一次只能建一座)。 */
281
+ wonder?: { id: string; progress: number; lastHomeHours: number; stagnantHomeHours: number } | null;
282
+ /** 已经建成的奇观 id。 */
283
+ wonders?: string[];
259
284
  location: Location | null;
260
285
  transit: Transit | null;
261
286
  stargaze: StargazeRecord | null;
@@ -424,6 +449,16 @@ export interface StructureRecord {
424
449
  | 'wind'
425
450
  | 'fire'
426
451
  | 'converter'
452
+ | 'tourism_dock'
453
+ | 'visitor_lodge'
454
+ | 'recruit_office'
455
+ | 'staff_housing'
456
+ | 'fab'
457
+ | 'tour_line'
458
+ | 'souvenir'
459
+ | 'compute_array'
460
+ | 'heavy_water'
461
+ | 'enrichment'
427
462
  | 'duty';
428
463
  siteKey: string;
429
464
  planetIndex: number;
@@ -584,13 +619,31 @@ export function homeKey(state: GameState): string {
584
619
  return `p${state.homePlanetIndex}`;
585
620
  }
586
621
 
622
+ /**
623
+ * 商人今天卖的是哪一种随机种子。
624
+ * 按「日号 + 已买袋数」哈希:同一天固定、第二天换一批,不是永远速生草。
625
+ */
626
+ export function dailyShopSpecies(state: GameState, nowMs: number): SpeciesId {
627
+ const day = dayIndexOf(nowPlanetHours(state, nowMs));
628
+ return SPECIES_IDS[hashSeed(`shopseed:${day}:${state.seedsPurchased}`) % SPECIES_IDS.length]!;
629
+ }
630
+
587
631
  export function msPerPlanetHourFor(cal: HomeCalendar): number {
588
632
  return cal.realHoursPerPlanetHour * REAL_MS_PER_HOUR;
589
633
  }
590
634
 
591
635
  /** 现在(现实毫秒)对应的「自创世起的星球时」。 */
636
+ export function realMsPerHomeHour(state: GameState): number {
637
+ return state.msPerPlanetHour / (state.speed ?? DEFAULT_SPEED);
638
+ }
639
+
640
+ /** 当前倍速下,一个母星时花多少现实分钟(时间显示用,别在别处硬算)。 */
641
+ export function minutesPerHomeHour(state: GameState): number {
642
+ return realMsPerHomeHour(state) / 60_000;
643
+ }
644
+
592
645
  export function nowPlanetHours(state: GameState, nowMs: number): number {
593
- return Math.max(0, (nowMs - state.epochRealMs) / state.msPerPlanetHour);
646
+ return Math.max(0, ((nowMs - state.epochRealMs) * (state.speed ?? DEFAULT_SPEED)) / state.msPerPlanetHour);
594
647
  }
595
648
 
596
649
  export function timeText(state: GameState, nowMs: number): string {
@@ -646,6 +699,13 @@ export function startGame(system: StarSystem, opts: StartOptions, nowMs: number)
646
699
  homePlanetIndex,
647
700
  epochRealMs: nowMs,
648
701
  msPerPlanetHour: msPerPlanetHourFor(cal) / scale,
702
+ speed: DEFAULT_SPEED,
703
+ reputation: 0,
704
+ compute: 0,
705
+ visitorsYesterday: 0,
706
+ staff: 0,
707
+ lastCharterHomeHours: 0,
708
+ lastPayrollDay: -1,
649
709
  location: { planetIndex: homePlanetIndex, ...spawn },
650
710
  transit: null,
651
711
  stargaze: null,
@@ -825,7 +885,9 @@ export function tick(system: StarSystem, state: GameState, nowMs: number): { sta
825
885
  const traded = advanceTerminals(system, scarred, nowMs);
826
886
  const terrafied = advanceTerra(system, traded, nowMs);
827
887
  const industrious = advanceIndustry(system, terrafied.state, nowMs);
828
- const frozen = advanceIce(system, industrious.state, nowMs);
888
+ const chartered = advanceCharter(system, industrious.state, nowMs);
889
+ const wondered = advanceWonder(chartered.state, nowMs);
890
+ const frozen = advanceIce(system, wondered.state, nowMs);
829
891
  const grown = advanceFlora(system, frozen.state, nowMs);
830
892
  const lived = advanceLife(system, grown.state, nowMs);
831
893
  const labored = advanceLabor(system, lived.state, nowMs);
@@ -834,6 +896,8 @@ export function tick(system: StarSystem, state: GameState, nowMs: number): { sta
834
896
  ...armed.events,
835
897
  ...terrafied.events,
836
898
  ...industrious.events,
899
+ ...chartered.events,
900
+ ...wondered.events,
837
901
  ...grown.events,
838
902
  ...lived.events,
839
903
  ...labored.events,
@@ -904,7 +968,7 @@ export function beginSurfaceMove(
904
968
  from: state.location,
905
969
  to,
906
970
  departRealMs: nowMs,
907
- arriveRealMs: nowMs + hours * state.msPerPlanetHour,
971
+ arriveRealMs: nowMs + hours * realMsPerHomeHour(state),
908
972
  distanceKm,
909
973
  };
910
974
  return {
@@ -943,7 +1007,7 @@ export function stargazeAt(system: StarSystem, state: GameState, nowMs: number):
943
1007
  ...state,
944
1008
  stargaze: {
945
1009
  atRealMs: nowMs,
946
- untilRealMs: nowMs + STARGAZE_WINDOW_PLANET_HOURS * state.msPerPlanetHour,
1010
+ untilRealMs: nowMs + STARGAZE_WINDOW_PLANET_HOURS * realMsPerHomeHour(state),
947
1011
  visibleKeys: result.bodies.map((b) => b.key),
948
1012
  },
949
1013
  },
@@ -1033,7 +1097,7 @@ export function beginInterstellar(
1033
1097
  from: state.location,
1034
1098
  to,
1035
1099
  departRealMs: nowMs,
1036
- arriveRealMs: nowMs + hours * state.msPerPlanetHour,
1100
+ arriveRealMs: nowMs + hours * realMsPerHomeHour(state),
1037
1101
  distanceAU: dist,
1038
1102
  };
1039
1103
  return {
@@ -1809,7 +1873,7 @@ export function pressGenerator(state: GameState, nowMs: number): GameState {
1809
1873
  /** 时间真的过了一点(部署设备要 0.1 母星时):把创世时刻往前推,显示的时间就往后跳。 */
1810
1874
  export function advanceHomeHours(state: GameState, homeHours: number): GameState {
1811
1875
  if (!(homeHours > 0)) return state;
1812
- return { ...state, epochRealMs: state.epochRealMs - homeHours * state.msPerPlanetHour };
1876
+ return { ...state, epochRealMs: state.epochRealMs - homeHours * realMsPerHomeHour(state) };
1813
1877
  }
1814
1878
 
1815
1879
  function spendEnergy(state: GameState, costKj: number, what: string): GameState {
@@ -2488,6 +2552,78 @@ export const PLANTER_SUBSTRATE = { n: 0.36, p: 0.24, k: 0.28, trace: 0.12 } as c
2488
2552
  * 20 个人睡着时每小时只吃 20%,40 kg 粮 / 160 L 水 / 24 kg 氧大约够 400 / 400 / 171 母星时。
2489
2553
  * 醒着的人吃居所里的,睡着的人吃着陆舱里的——谁都不能白吃。
2490
2554
  */
2555
+ /* 特许执照:两条广播,各用对方的主货币买。 */
2556
+ export const CHARTER_TOURISM_CREDITS = 5_000;
2557
+ export const CHARTER_TECH_KJ = 300_000;
2558
+ /* 旅游 */
2559
+ export const TOURISM_DOCK_COST_KJ = 30_000;
2560
+ export const TOURISM_DOCK_TUNGSTEN = 2;
2561
+ export const TOURISM_DOCK_HOME_HOURS = 0.5;
2562
+ export const TOURISM_DOCK_KJ_PER_HOUR = 300;
2563
+ export const TOURISM_VISITORS_PER_DOCK = 10;
2564
+ export const VISITOR_KJ_PER_HOUR = 40;
2565
+ export const VISITOR_CREDITS = 12;
2566
+ export const REPUTATION_PER_VISITOR_CYCLE = 0.5;
2567
+ export const REPUTATION_PER_BLACKOUT_HOUR = 6;
2568
+ export const REPUTATION_DAILY_DECAY = 0.3;
2569
+ /* 科技 */
2570
+ /** 员工公寓与访客驿站的体感门槛:室内温度不在区间里,床位就不算数。 */
2571
+ export const STAFF_COMFORT_C = { min: 10, max: 30 } as const;
2572
+ export const LODGE_COMFORT_C = { min: 12, max: 26 } as const;
2573
+ /** 奇观【拟造S2机关】:吃计算力换能量。 */
2574
+ export const S2_ENGINE_MAX = 4;
2575
+ export const S2_COMPUTE_PER_HOUR = 2;
2576
+ export const S2_KJ_PER_COMPUTE = 20_000;
2577
+ export const VISITOR_LODGE_COST_KJ = 60_000;
2578
+ export const VISITOR_LODGE_TUNGSTEN = 4;
2579
+ export const VISITOR_LODGE_HOME_HOURS = 1;
2580
+ export const VISITOR_LODGE_KJ_PER_HOUR = 200;
2581
+ export const RECRUIT_COST_CREDITS = 40_000;
2582
+ export const RECRUIT_HOME_HOURS = 0.5;
2583
+ export const RECRUIT_KJ_PER_HOUR = 100;
2584
+ export const STAFF_PER_OFFICE_PER_DAY = 5;
2585
+ export const STAFF_WAGE_CREDITS_PER_DAY = 8;
2586
+ export const STAFF_HOUSING_COST_KJ = 20_000;
2587
+ export const STAFF_HOUSING_TUNGSTEN = 2;
2588
+ export const STAFF_HOUSING_HOME_HOURS = 0.5;
2589
+ export const STAFF_HOUSING_KJ_PER_HOUR = 150;
2590
+ export const STAFF_PER_HOUSING = 20;
2591
+ export const FAB_COST_KJ = 120_000;
2592
+ export const FAB_TUNGSTEN = 20;
2593
+ export const FAB_HOME_HOURS = 1.5;
2594
+ export const FAB_KJ_PER_HOUR = 2_000;
2595
+ export const FAB_COMPUTE_PER_HOUR = 1;
2596
+ export const FAB_STAFF_NEEDED = 2;
2597
+ export const TOUR_LINE_COST_KJ = 80_000;
2598
+ export const TOUR_LINE_TUNGSTEN = 6;
2599
+ export const TOUR_LINE_HOME_HOURS = 1;
2600
+ export const TOUR_LINE_KJ_PER_HOUR = 150;
2601
+ export const TOUR_LINE_CREDITS_BONUS = 0.5;
2602
+ export const SOUVENIR_COST_KJ = 40_000;
2603
+ export const SOUVENIR_TUNGSTEN = 3;
2604
+ export const SOUVENIR_HOME_HOURS = 0.5;
2605
+ export const SOUVENIR_KJ_PER_HOUR = 80;
2606
+ export const SOUVENIR_CREDITS_PER_VISITOR = 5;
2607
+ export const SOUVENIR_BIOMASS_PER_VISITOR = 0.05;
2608
+ export const COMPUTE_ARRAY_COST_KJ = 200_000;
2609
+ export const COMPUTE_ARRAY_TUNGSTEN = 15;
2610
+ export const COMPUTE_ARRAY_HOME_HOURS = 1;
2611
+ export const COMPUTE_ARRAY_KJ_PER_HOUR = 800;
2612
+ export const COMPUTE_ARRAY_MULTIPLIER = 1.15;
2613
+ export const COMPUTE_ARRAY_MAX_MULTIPLIER = 3;
2614
+ export const HEAVY_WATER_COST_KJ = 150_000;
2615
+ export const HEAVY_WATER_TUNGSTEN = 10;
2616
+ export const HEAVY_WATER_HOME_HOURS = 1;
2617
+ export const HEAVY_WATER_KJ_PER_HOUR = 400;
2618
+ export const ENRICHMENT_COMPUTE_PER_HOUR = 2;
2619
+ export const ENRICHMENT_KG_PER_HOUR = 0.5;
2620
+ export const WONDER_STALL_HOME_HOURS = 72;
2621
+ export const WONDER_DECAY_PER_DAY = 0.05;
2622
+
2623
+ export const MIN_SPEED = 1;
2624
+ export const MAX_SPEED = 200;
2625
+ export const DEFAULT_SPEED = 1;
2626
+
2491
2627
  export const SHIP_POD_ID = 'pod';
2492
2628
  export const POD_STOCK = { biomass: 40, water_drink: 160, oxygen: 24 } as const;
2493
2629
  /** 补给掉到初始量的这个比例以下,提醒一次。 */
@@ -3391,6 +3527,13 @@ function podTightestFraction(store: Record<string, number>): number {
3391
3527
  const planet = system.planets[site.planetIndex - 1]!;
3392
3528
  if (realSite) requireTerrestrial(planet);
3393
3529
  const spec = BUILD_SPECS[kind];
3530
+ if (spec.charter && state.charter !== spec.charter) {
3531
+ throw new Error(
3532
+ spec.charter === 'tourism'
3533
+ ? spec.label + '只在旅游星系有图纸:先去商人那儿买【星际广播 · 旅游星系】(5,000 信用点)。'
3534
+ : spec.label + '只在技术星系有图纸:先去商人那儿买【星际广播 · 技术星系】(300,000 kJ)。',
3535
+ );
3536
+ }
3394
3537
  if (!spec) {
3395
3538
  // 兜底:别让 面板/工具 传错 id 时抛 TypeError,给人一句能看懂的。
3396
3539
  throw new Error(`不认识的建筑:${String(kind) || '(空)'}。`);
@@ -4419,6 +4562,199 @@ export const MUTATION_ROOM_BUILD_HOME_HOURS = 0.5;
4419
4562
  export const MUTATION_MIN_SEEDS = 3;
4420
4563
  export const MUTATION_MAX_SEEDS = 5;
4421
4564
 
4565
+
4566
+ /** 调时间倍速:重锚 epoch,保证「当前母星时」不跳。 */
4567
+ export function setSpeed(state: GameState, speed: number, nowMs: number): GameState {
4568
+ const target = Math.round(speed);
4569
+ if (!Number.isFinite(target) || target < MIN_SPEED || target > MAX_SPEED) {
4570
+ throw new Error('倍速要在 ' + MIN_SPEED + '–' + MAX_SPEED + ' 之间:收到 ' + speed + '。');
4571
+ }
4572
+ const before = state.speed ?? DEFAULT_SPEED;
4573
+ if (target === before) return state;
4574
+ const elapsed = Math.max(0, nowMs - state.epochRealMs);
4575
+ return { ...state, speed: target, epochRealMs: nowMs - (elapsed * before) / target };
4576
+ }
4577
+
4578
+ /** 买【星际广播】:一局只能买一张,买完另一张永久锁死。 */
4579
+ export function buyCharter(
4580
+ state: GameState,
4581
+ which: 'tourism' | 'tech',
4582
+ nowMs: number,
4583
+ ): { state: GameState; text: string } {
4584
+ if (state.charter) {
4585
+ throw new Error(
4586
+ state.charter === 'tourism' ? '已经选了旅游星系:技术星系的广播再也买不到了。' : '已经选了技术星系:旅游星系的广播再也买不到了。',
4587
+ );
4588
+ }
4589
+ const hours = nowPlanetHours(state, nowMs);
4590
+ if (!shopOpen(hours, state.upgrades.telescope)) {
4591
+ throw new Error(shopWindowText(hours, state.upgrades.telescope));
4592
+ }
4593
+ if (which === 'tourism') {
4594
+ if (state.credits < CHARTER_TOURISM_CREDITS) {
4595
+ throw new Error('信用点不够:星际广播 · 旅游星系要 ' + CHARTER_TOURISM_CREDITS.toLocaleString('en-US') + ' 信用点,你现在有 ' + state.credits.toLocaleString('en-US') + '。');
4596
+ }
4597
+ return {
4598
+ state: { ...state, charter: 'tourism', credits: state.credits - CHARTER_TOURISM_CREDITS, reputation: state.reputation ?? 0 },
4599
+ text:
4600
+ '买下了【星际广播 · 旅游星系】:从今天起,你的星系会出现在星际旅游航线上。\n' +
4601
+ '观光塔台与访客驿站有图纸了;技术星系的广播已经买不到了。知名度从 0 开始——先把地标和停泊位做出来。',
4602
+ };
4603
+ }
4604
+ if (state.energyKj < CHARTER_TECH_KJ) {
4605
+ throw new Error('能量不够:星际广播 · 技术星系要 ' + CHARTER_TECH_KJ.toLocaleString('en-US') + ' kJ,你现在有 ' + Math.floor(state.energyKj).toLocaleString('en-US') + ' kJ。');
4606
+ }
4607
+ return {
4608
+ state: { ...state, charter: 'tech', energyKj: state.energyKj - CHARTER_TECH_KJ, compute: state.compute ?? 0 },
4609
+ text:
4610
+ '买下了【星际广播 · 技术星系】:星际商会承认你的工业资格证,员工与设备可以进来了。\n' +
4611
+ '招募站、员工公寓、晶圆厂有图纸了;旅游星系的广播已经买不到了。计算力从 0 开始——先招人,再开厂。',
4612
+ };
4613
+ }
4614
+
4615
+ /** 特许经济:游客、员工、知名度、计算力,一天结算一次。 */
4616
+ export function advanceCharter(system: StarSystem, state: GameState, nowMs: number): { state: GameState; events: GameEvent[] } {
4617
+ const events: GameEvent[] = [];
4618
+ if (!state.charter) return { state, events };
4619
+ const nowHome = nowPlanetHours(state, nowMs);
4620
+ const fromHome = state.lastCharterHomeHours ?? 0;
4621
+ if (nowHome - fromHome < 1) return { state, events };
4622
+ const delta = Math.min(24, nowHome - fromHome);
4623
+ let next: GameState = { ...state, lastCharterHomeHours: fromHome + delta };
4624
+ const planetIndex = next.location?.planetIndex ?? next.homePlanetIndex;
4625
+ const onPlanet = next.structures.filter((s) => s.planetIndex === planetIndex);
4626
+ const powered = (s: StructureRecord): boolean => next.energyKj > 0 || (next.grids[planetIndex] ?? 0) > 0;
4627
+ const day = Math.floor(nowHome / 24);
4628
+
4629
+ if (next.charter === 'tourism') {
4630
+ const docks = onPlanet.filter((s) => s.kind === 'tourism_dock' && powered(s)).length;
4631
+ const lodges = onPlanet.filter((s) => s.kind === 'visitor_lodge' && powered(s) && interiorComfortable(structureInteriorC(system, next, s, nowMs), LODGE_COMFORT_C)).length;
4632
+ const slots = docks * TOURISM_VISITORS_PER_DOCK;
4633
+ const bedLimit = lodges * 30;
4634
+ const reputation = next.reputation ?? 0;
4635
+ const capacity = Math.min(slots, bedLimit);
4636
+ const visitors = Math.max(0, Math.min(capacity, Math.round(capacity * (0.5 + reputation / 100))));
4637
+ if (slots > 0 && bedLimit === 0) {
4638
+ if (!next.lastCharterWarnDay || next.lastCharterWarnDay !== day) {
4639
+ events.push({ type: 'genesis.charter', text: '停泊位有了,但还没有【访客驿站】:游客没地方住,不会下船。' });
4640
+ next = { ...next, lastCharterWarnDay: day };
4641
+ }
4642
+ return { state: next, events };
4643
+ }
4644
+ const draw = visitors * VISITOR_KJ_PER_HOUR * delta;
4645
+ const tourLines = onPlanet.filter((s) => s.kind === 'tour_line' && powered(s)).length;
4646
+ const souvenirs = onPlanet.filter((s) => s.kind === 'souvenir' && powered(s)).length;
4647
+ const biomass = Object.values(next.stores).reduce((sum, st) => sum + (st.biomass ?? 0), 0);
4648
+ const souvenirVisitors = Math.min(visitors, Math.floor(biomass / SOUVENIR_BIOMASS_PER_VISITOR));
4649
+ const earned = Math.round(
4650
+ visitors * VISITOR_CREDITS * (1 + TOUR_LINE_CREDITS_BONUS * tourLines) +
4651
+ souvenirs * souvenirVisitors * SOUVENIR_CREDITS_PER_VISITOR,
4652
+ );
4653
+ next = {
4654
+ ...next,
4655
+ visitorsYesterday: visitors,
4656
+ credits: next.credits + earned,
4657
+ energyKj: Math.max(0, next.energyKj - draw),
4658
+ };
4659
+ if (visitors > 0) {
4660
+ const gained = REPUTATION_PER_VISITOR_CYCLE;
4661
+ next = { ...next, reputation: Math.min(100, reputation + gained) };
4662
+ } else if (reputation > 0) {
4663
+ next = { ...next, reputation: Math.max(0, reputation - REPUTATION_DAILY_DECAY) };
4664
+ }
4665
+ if (earned > 0) {
4666
+ events.push({
4667
+ type: 'genesis.visitors',
4668
+ text:
4669
+ '今天来了 ' + visitors + ' 位游客:付了 ' + earned + ' 信用点,用掉 ' + Math.round(draw) + ' kJ 的停泊与生命维持。',
4670
+ });
4671
+ }
4672
+ return { state: next, events };
4673
+ }
4674
+
4675
+ // 技术线:员工、工资、测算力。
4676
+ const offices = onPlanet.filter((s) => s.kind === 'recruit_office' && powered(s)).length;
4677
+ const housing = onPlanet.filter((s) => s.kind === 'staff_housing' && powered(s) && interiorComfortable(structureInteriorC(system, next, s, nowMs), STAFF_COMFORT_C)).length * STAFF_PER_HOUSING;
4678
+ const fabs = onPlanet.filter((s) => s.kind === 'fab' && powered(s)).length;
4679
+ const staffNow = next.staff ?? 0;
4680
+ let staff = staffNow;
4681
+ if (day !== (next.lastPayrollDay ?? -1) && staff > 0) {
4682
+ const wage = staff * STAFF_WAGE_CREDITS_PER_DAY;
4683
+ if (next.credits >= wage) {
4684
+ next = { ...next, credits: next.credits - wage, lastPayrollDay: day };
4685
+ events.push({ type: 'genesis.payroll', text: '发了今天的工资:' + staff + ' 人 × ' + STAFF_WAGE_CREDITS_PER_DAY + ' 信用点 = ' + wage + '。' });
4686
+ } else {
4687
+ events.push({
4688
+ type: 'genesis.strike',
4689
+ text: '付不起工资(要 ' + wage + ' 信用点,只有 ' + next.credits + '):员工罢工,工厂停转,直到你把信用点补上。',
4690
+ });
4691
+ }
4692
+ }
4693
+ // 住不下(或太热太冷)时,每天走一个人——不是一次清零,给玩家补齐的时间。
4694
+ if (day !== (next.lastAttritionDay ?? -1)) {
4695
+ next = { ...next, lastAttritionDay: day };
4696
+ if (staffNow > housing) {
4697
+ staff = Math.max(housing, staffNow - 1);
4698
+ events.push({
4699
+ type: 'genesis.staff',
4700
+ text: '有员工搬走了:宿舍床位只够 ' + housing + ' 人(太热、太冷或没通电的公寓不算床位),现在是 ' + staff + ' 人。',
4701
+ });
4702
+ }
4703
+ }
4704
+ const canHire = Math.min(housing, staffNow + offices * STAFF_PER_OFFICE_PER_DAY);
4705
+ if (canHire > staffNow) staff = canHire;
4706
+ const paidUp = next.credits >= (next.staff ?? 0) * 0 + 0;
4707
+ const working = staff > 0 && (next.credits > 0 || (next.lastPayrollDay ?? -1) === day);
4708
+ const arrays = onPlanet.filter((s) => s.kind === 'compute_array' && powered(s)).length;
4709
+ const arrayMultiplier = Math.min(COMPUTE_ARRAY_MAX_MULTIPLIER, Math.pow(COMPUTE_ARRAY_MULTIPLIER, arrays));
4710
+ const mirrors = (next.wonders ?? []).includes('orbital_mirror') ? 1 : 0;
4711
+ const valley = (next.wonders ?? []).includes('silicon_valley') ? 2 : 1;
4712
+ const perFab = FAB_COMPUTE_PER_HOUR + mirrors;
4713
+ const compute = (working ? fabs * perFab * arrayMultiplier * valley : 0) * delta;
4714
+ next = {
4715
+ ...next,
4716
+ staff,
4717
+ compute: Math.min(10_000, (next.compute ?? 0) + compute),
4718
+ };
4719
+ // 富集塔吃计算力换氘氚燃料;提取器本身只提供原料(这里合并成一步:有提取器才能富集)。
4720
+ const extractors = onPlanet.filter((s) => s.kind === 'heavy_water' && powered(s)).length;
4721
+ const towers = onPlanet.filter((s) => s.kind === 'enrichment' && powered(s)).length;
4722
+ const pairs = Math.min(extractors, towers);
4723
+ if (pairs > 0) {
4724
+ const wantCompute = pairs * ENRICHMENT_COMPUTE_PER_HOUR * delta;
4725
+ const usedCompute = Math.min(next.compute ?? 0, wantCompute);
4726
+ const kg = (usedCompute / ENRICHMENT_COMPUTE_PER_HOUR) * ENRICHMENT_KG_PER_HOUR;
4727
+ next = {
4728
+ ...next,
4729
+ compute: Math.max(0, (next.compute ?? 0) - usedCompute),
4730
+ inventory: { ...next.inventory, deuterium: Math.round((((next.inventory.deuterium ?? 0) + kg) * 1000)) / 1000 },
4731
+ };
4732
+ if (kg > 0) {
4733
+ events.push({ type: 'genesis.fuel', text: '富集塔出了 ' + kg.toFixed(2) + ' kg 氘氚燃料(现在 ' + (next.inventory.deuterium ?? 0).toFixed(2) + ' kg)。' });
4734
+ }
4735
+ }
4736
+ // 【拟造S2机关】:富集塔优先吃算力,剩下的按 2 算力/时 → 40,000 kJ/时 换成电。
4737
+ const s2 = (next.wonders ?? []).filter((w) => w === 's2_engine').length;
4738
+ if (s2 > 0) {
4739
+ const wantS2 = s2 * S2_COMPUTE_PER_HOUR * delta;
4740
+ const usedS2 = Math.min(next.compute ?? 0, wantS2);
4741
+ if (usedS2 > 0) {
4742
+ const gain = Math.round(usedS2 * (S2_KJ_PER_COMPUTE / S2_COMPUTE_PER_HOUR));
4743
+ next = {
4744
+ ...next,
4745
+ compute: Math.max(0, (next.compute ?? 0) - usedS2),
4746
+ energyKj: next.energyKj + gain,
4747
+ };
4748
+ events.push({ type: 'genesis.compute', text: 'S2 机关烧掉了 ' + Math.round(usedS2) + ' 点计算力,换回 ' + gain + ' kJ。' });
4749
+ }
4750
+ }
4751
+ if (compute > 0) {
4752
+ events.push({ type: 'genesis.compute', text: '晶圆厂出了 ' + Math.round(compute) + ' 点计算力(现在 ' + Math.floor(next.compute ?? 0) + ')。' });
4753
+ }
4754
+ void paidUp;
4755
+ return { state: next, events };
4756
+ }
4757
+
4422
4758
  export const BUILD_SPECS: Record<
4423
4759
  StructureRecord['kind'],
4424
4760
  {
@@ -4429,6 +4765,8 @@ export const BUILD_SPECS: Record<
4429
4765
  costCredits?: number;
4430
4766
  /** 原子打印机要吃的钨(份)。蓝图结构优化后 ×0.75(向下取整,最少 1)。 */
4431
4767
  tungsten: number;
4768
+ /** 本局特许执照要求:没有对应执照就没有图纸。 */
4769
+ charter?: 'tourism' | 'tech';
4432
4770
  }
4433
4771
  > = {
4434
4772
  greenhouse: {
@@ -4438,6 +4776,87 @@ export const BUILD_SPECS: Record<
4438
4776
  upkeepKjPerHour: GREENHOUSE_UPKEEP_KJ_PER_HOUR,
4439
4777
  tungsten: 2,
4440
4778
  },
4779
+ tourism_dock: {
4780
+ label: '观光塔台',
4781
+ costKj: TOURISM_DOCK_COST_KJ,
4782
+ buildHours: TOURISM_DOCK_HOME_HOURS,
4783
+ upkeepKjPerHour: TOURISM_DOCK_KJ_PER_HOUR,
4784
+ tungsten: TOURISM_DOCK_TUNGSTEN,
4785
+ charter: 'tourism',
4786
+ },
4787
+ visitor_lodge: {
4788
+ label: '访客驿站',
4789
+ costKj: VISITOR_LODGE_COST_KJ,
4790
+ buildHours: VISITOR_LODGE_HOME_HOURS,
4791
+ upkeepKjPerHour: VISITOR_LODGE_KJ_PER_HOUR,
4792
+ tungsten: VISITOR_LODGE_TUNGSTEN,
4793
+ charter: 'tourism',
4794
+ },
4795
+ recruit_office: {
4796
+ label: '招募站',
4797
+ costKj: 0,
4798
+ buildHours: RECRUIT_HOME_HOURS,
4799
+ upkeepKjPerHour: RECRUIT_KJ_PER_HOUR,
4800
+ costCredits: RECRUIT_COST_CREDITS,
4801
+ tungsten: 0,
4802
+ charter: 'tech',
4803
+ },
4804
+ staff_housing: {
4805
+ label: '员工公寓',
4806
+ costKj: STAFF_HOUSING_COST_KJ,
4807
+ buildHours: STAFF_HOUSING_HOME_HOURS,
4808
+ upkeepKjPerHour: STAFF_HOUSING_KJ_PER_HOUR,
4809
+ tungsten: STAFF_HOUSING_TUNGSTEN,
4810
+ charter: 'tech',
4811
+ },
4812
+ fab: {
4813
+ label: '晶圆厂',
4814
+ costKj: FAB_COST_KJ,
4815
+ buildHours: FAB_HOME_HOURS,
4816
+ upkeepKjPerHour: FAB_KJ_PER_HOUR,
4817
+ tungsten: FAB_TUNGSTEN,
4818
+ charter: 'tech',
4819
+ },
4820
+ tour_line: {
4821
+ label: '观光线路站',
4822
+ costKj: TOUR_LINE_COST_KJ,
4823
+ buildHours: TOUR_LINE_HOME_HOURS,
4824
+ upkeepKjPerHour: TOUR_LINE_KJ_PER_HOUR,
4825
+ tungsten: TOUR_LINE_TUNGSTEN,
4826
+ charter: 'tourism',
4827
+ },
4828
+ souvenir: {
4829
+ label: '纪念品店',
4830
+ costKj: SOUVENIR_COST_KJ,
4831
+ buildHours: SOUVENIR_HOME_HOURS,
4832
+ upkeepKjPerHour: SOUVENIR_KJ_PER_HOUR,
4833
+ tungsten: SOUVENIR_TUNGSTEN,
4834
+ charter: 'tourism',
4835
+ },
4836
+ compute_array: {
4837
+ label: '计算阵列',
4838
+ costKj: COMPUTE_ARRAY_COST_KJ,
4839
+ buildHours: COMPUTE_ARRAY_HOME_HOURS,
4840
+ upkeepKjPerHour: COMPUTE_ARRAY_KJ_PER_HOUR,
4841
+ tungsten: COMPUTE_ARRAY_TUNGSTEN,
4842
+ charter: 'tech',
4843
+ },
4844
+ heavy_water: {
4845
+ label: '重水提取器',
4846
+ costKj: HEAVY_WATER_COST_KJ,
4847
+ buildHours: HEAVY_WATER_HOME_HOURS,
4848
+ upkeepKjPerHour: HEAVY_WATER_KJ_PER_HOUR,
4849
+ tungsten: HEAVY_WATER_TUNGSTEN,
4850
+ charter: 'tech',
4851
+ },
4852
+ enrichment: {
4853
+ label: '富集塔',
4854
+ costKj: HEAVY_WATER_COST_KJ,
4855
+ buildHours: HEAVY_WATER_HOME_HOURS,
4856
+ upkeepKjPerHour: HEAVY_WATER_KJ_PER_HOUR,
4857
+ tungsten: HEAVY_WATER_TUNGSTEN,
4858
+ charter: 'tech',
4859
+ },
4441
4860
  planter: {
4442
4861
  label: '种植盆',
4443
4862
  costKj: PLANTER_COST_KJ,
@@ -5630,6 +6049,37 @@ export function habitatInteriorC(
5630
6049
  }
5631
6050
 
5632
6051
  /** 居所温度不合人意的说法;住得下就返回 null。 */
6052
+ /** 任意建筑在当前站点的室内温度(不通电=室外)。没有站点(母舰)返回 null。 */
6053
+ export function structureInteriorC(
6054
+ system: StarSystem,
6055
+ state: GameState,
6056
+ structure: StructureRecord,
6057
+ nowMs: number,
6058
+ ): number | null {
6059
+ const site = state.sites.find((s) => s.key === structure.siteKey);
6060
+ if (!site) return null;
6061
+ const planet = system.planets[structure.planetIndex];
6062
+ if (!planet || planet.surface.kind !== 'terrestrial') return null;
6063
+ const ambient = climateAt(
6064
+ planet.surface,
6065
+ site.latDeg,
6066
+ site.lonDeg,
6067
+ nowPlanetHours(state, nowMs),
6068
+ state.calendar.planetDaysPerYear * 24,
6069
+ planet.obliquityDeg,
6070
+ ).tempC;
6071
+ const powered = state.energyKj > 0 || (state.grids[structure.planetIndex] ?? 0) > 0;
6072
+ if (!powered) return round2(ambient);
6073
+ const pull = Math.max(-HABITAT_CLIMATE_PULL_C, Math.min(HABITAT_CLIMATE_PULL_C, 18 - ambient));
6074
+ return round2(ambient + pull);
6075
+ }
6076
+
6077
+ /** 室内温度落在区间内才算有人住。 */
6078
+ export function interiorComfortable(interiorC: number | null, range: { min: number; max: number }): boolean {
6079
+ if (interiorC === null) return true;
6080
+ return interiorC >= range.min && interiorC <= range.max;
6081
+ }
6082
+
5633
6083
  export function habitatComfortIssue(
5634
6084
  system: StarSystem,
5635
6085
  state: GameState,
@@ -5932,6 +6382,31 @@ export function deserializeGame(system: StarSystem, raw: unknown): GameState {
5932
6382
  }
5933
6383
  }
5934
6384
  if (!Array.isArray(g.seedBags)) throw new Error('game.json 的种子袋不是数组。');
6385
+ const wonders = (g as { wonders?: unknown }).wonders;
6386
+ if (wonders !== undefined && (!Array.isArray(wonders) || wonders.some((x) => typeof x !== 'string'))) {
6387
+ throw new Error('game.json 的奇观记录不合法。');
6388
+ }
6389
+ const wonder = (g as { wonder?: unknown }).wonder;
6390
+ if (wonder !== undefined && wonder !== null) {
6391
+ const w = wonder as { id?: unknown; progress?: unknown };
6392
+ if (typeof w.id !== 'string' || typeof w.progress !== 'number' || !Number.isFinite(w.progress)) {
6393
+ throw new Error('game.json 的奇观工程不合法。');
6394
+ }
6395
+ }
6396
+ const charter = (g as { charter?: unknown }).charter;
6397
+ if (charter !== undefined && charter !== 'tourism' && charter !== 'tech') {
6398
+ throw new Error('game.json 的特许执照不合法:' + String(charter) + '。');
6399
+ }
6400
+ const speed = (g as { speed?: unknown }).speed;
6401
+ if (speed !== undefined && (typeof speed !== 'number' || !Number.isInteger(speed) || speed < MIN_SPEED || speed > MAX_SPEED)) {
6402
+ throw new Error('game.json 的时间倍速不合法:' + String(speed) + '。');
6403
+ }
6404
+ for (const key of ['reputation', 'compute', 'staff', 'visitorsYesterday', 'lastCharterHomeHours', 'lastPayrollDay', 'lastCharterWarnDay', 'lastAttritionDay'] as const) {
6405
+ const value = (g as Record<string, unknown>)[key];
6406
+ if (value !== undefined && (typeof value !== 'number' || !Number.isFinite(value))) {
6407
+ throw new Error('game.json 的 ' + key + ' 不合法:' + String(value) + '。');
6408
+ }
6409
+ }
5935
6410
  if (g.fertilizerBought !== undefined && (typeof g.fertilizerBought !== 'number' || !Number.isFinite(g.fertilizerBought) || g.fertilizerBought < 0)) {
5936
6411
  throw new Error('game.json 的复合肥购买量不合法。');
5937
6412
  }
@@ -6705,3 +7180,106 @@ export function applyFertilizer(
6705
7180
  text: `撒了 ${amount} kg 复合肥:氮 ${before.n} → ${next.n}、磷 ${before.p} → ${next.p}、钾 ${before.k} → ${next.k}、微量 ${before.trace} → ${next.trace}。`,
6706
7181
  };
6707
7182
  }
7183
+
7184
+ export type WonderId = 'sky_ring' | 'under_ice_eye' | 'silicon_valley' | 'orbital_mirror' | 's2_engine';
7185
+
7186
+ export const WONDER_SPECS: Record<
7187
+ WonderId,
7188
+ { label: string; charter: 'tourism' | 'tech'; costKj: number; tungsten: number; homeHours: number; effect: string; maxCount?: number }
7189
+ > = {
7190
+ sky_ring: {
7191
+ label: '天穹环',
7192
+ charter: 'tourism',
7193
+ costKj: 2_000_000,
7194
+ tungsten: 150,
7195
+ homeHours: 48,
7196
+ effect: '知名度 +15',
7197
+ },
7198
+ under_ice_eye: {
7199
+ label: '冰下之眼',
7200
+ charter: 'tourism',
7201
+ costKj: 1_200_000,
7202
+ tungsten: 80,
7203
+ homeHours: 36,
7204
+ effect: '知名度 +10',
7205
+ },
7206
+ silicon_valley: {
7207
+ label: '硅谷',
7208
+ charter: 'tech',
7209
+ costKj: 4_000_000,
7210
+ tungsten: 300,
7211
+ homeHours: 72,
7212
+ effect: '晶圆厂的算力翻倍',
7213
+ },
7214
+ s2_engine: {
7215
+ label: '拟造S2机关',
7216
+ charter: 'tech',
7217
+ costKj: 300_000,
7218
+ tungsten: 25,
7219
+ homeHours: 1.5,
7220
+ effect: '吃掉剩余计算力:每座 2 计算力/时 → 40,000 kJ/时',
7221
+ maxCount: S2_ENGINE_MAX,
7222
+ },
7223
+ orbital_mirror: {
7224
+ label: '轨道镜阵',
7225
+ charter: 'tech',
7226
+ costKj: 2_000_000,
7227
+ tungsten: 120,
7228
+ homeHours: 48,
7229
+ effect: '每座晶圆厂再多 1 点算力',
7230
+ },
7231
+ };
7232
+
7233
+ export function startWonder(state: GameState, id: string, nowMs: number): { state: GameState; text: string } {
7234
+ const spec = WONDER_SPECS[id as WonderId];
7235
+ if (!spec) throw new Error('没有这个奇观:' + id + '(可选 sky_ring / under_ice_eye / silicon_valley / orbital_mirror)。');
7236
+ if (!state.charter) throw new Error('还没选执照:奇观要先有星系执照。');
7237
+ if (state.charter !== spec.charter) throw new Error('这座奇观只在' + (spec.charter === 'tourism' ? '旅游' : '技术') + '星系能建。');
7238
+ const built = (state.wonders ?? []).filter((w) => w === id).length;
7239
+ if (spec.maxCount !== undefined) {
7240
+ if (built >= spec.maxCount) throw new Error("【" + spec.label + "】最多 " + spec.maxCount + " 座:已经建满了。");
7241
+ } else if (built > 0) {
7242
+ throw new Error('这座奇观已经建成了。');
7243
+ }
7244
+ if (state.wonder) throw new Error('奇观工程线只有一条:先把【' + (WONDER_SPECS[state.wonder.id as WonderId]?.label ?? state.wonder.id) + '】建完。');
7245
+ if (state.energyKj < spec.costKj) throw new Error('能量不够:' + spec.label + '要 ' + spec.costKj + ' kJ,现在 ' + Math.round(state.energyKj) + ' kJ。');
7246
+ if (state.tungsten < spec.tungsten) throw new Error('钨不够:' + spec.label + '要 ' + spec.tungsten + ' 份,现在 ' + state.tungsten + ' 份。');
7247
+ const next: GameState = {
7248
+ ...state,
7249
+ energyKj: state.energyKj - spec.costKj,
7250
+ tungsten: state.tungsten - spec.tungsten,
7251
+ wonder: { id, progress: 0, lastHomeHours: nowPlanetHours(state, nowMs), stagnantHomeHours: 0 },
7252
+ };
7253
+ return { state: next, text: '开工了:' + spec.label + '(' + spec.homeHours + ' 母星时,一条工程线只能建一座)。' };
7254
+ }
7255
+
7256
+ export function advanceWonder(state: GameState, nowMs: number): { state: GameState; events: GameEvent[] } {
7257
+ const events: GameEvent[] = [];
7258
+ const wonder = state.wonder;
7259
+ if (!wonder) return { state, events };
7260
+ const spec = WONDER_SPECS[wonder.id as WonderId];
7261
+ if (!spec) return { state, events };
7262
+ const nowHome = nowPlanetHours(state, nowMs);
7263
+ const delta = Math.min(24, nowHome - wonder.lastHomeHours);
7264
+ if (delta <= 0) return { state, events };
7265
+ const powered = state.energyKj > 0 || Object.values(state.grids).some((kj) => kj > 0);
7266
+ let progress = wonder.progress + (powered ? delta / spec.homeHours : 0);
7267
+ let stagnant = powered ? 0 : wonder.stagnantHomeHours + delta;
7268
+ if (stagnant > WONDER_STALL_HOME_HOURS) {
7269
+ progress = Math.max(0, progress - WONDER_DECAY_PER_DAY * (delta / 24));
7270
+ }
7271
+ const clamped = Math.min(1, progress);
7272
+ if (clamped >= 1) {
7273
+ const wonders = [...(state.wonders ?? []), wonder.id];
7274
+ let next: GameState = { ...state, wonders, wonder: null };
7275
+ if (wonder.id === 'sky_ring' || wonder.id === 'under_ice_eye') {
7276
+ next = { ...next, reputation: Math.min(100, (next.reputation ?? 0) + (wonder.id === 'sky_ring' ? 15 : 10)) };
7277
+ }
7278
+ events.push({ type: 'genesis.wonder', text: '【' + spec.label + '】落成了:' + spec.effect + '。' });
7279
+ return { state: next, events };
7280
+ }
7281
+ return {
7282
+ state: { ...state, wonder: { ...wonder, progress: clamped, lastHomeHours: wonder.lastHomeHours + delta, stagnantHomeHours: stagnant } },
7283
+ events,
7284
+ };
7285
+ }