@idlekit/core 0.7.0 → 0.9.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.
Files changed (107) hide show
  1. package/README.md +35 -0
  2. package/dist/adapters/runtime.d.ts +51 -0
  3. package/dist/adapters/runtime.js +16 -0
  4. package/dist/adapters/runtime.js.map +1 -0
  5. package/dist/engine/breakEternity.d.ts +11 -0
  6. package/dist/engine/breakEternity.js +11 -0
  7. package/dist/engine/breakEternity.js.map +1 -1
  8. package/dist/engine/breakInfinity.d.ts +7 -0
  9. package/dist/engine/breakInfinity.js +7 -0
  10. package/dist/engine/breakInfinity.js.map +1 -1
  11. package/dist/engine/types.d.ts +7 -0
  12. package/dist/index.d.ts +12 -0
  13. package/dist/index.js +12 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/ltv/telemetryLoop.d.ts +203 -0
  16. package/dist/ltv/telemetryLoop.js +389 -0
  17. package/dist/ltv/telemetryLoop.js.map +1 -0
  18. package/dist/models/exponential.d.ts +95 -0
  19. package/dist/models/exponential.js +200 -0
  20. package/dist/models/exponential.js.map +1 -0
  21. package/dist/models/index.d.ts +12 -0
  22. package/dist/models/index.js +18 -0
  23. package/dist/models/index.js.map +1 -0
  24. package/dist/models/jsonSchema.d.ts +13 -0
  25. package/dist/models/jsonSchema.js +30 -0
  26. package/dist/models/jsonSchema.js.map +1 -0
  27. package/dist/models/ledger.d.ts +26 -0
  28. package/dist/models/ledger.js +63 -0
  29. package/dist/models/ledger.js.map +1 -0
  30. package/dist/models/multiCurrency.d.ts +70 -0
  31. package/dist/models/multiCurrency.js +343 -0
  32. package/dist/models/multiCurrency.js.map +1 -0
  33. package/dist/models/prestige.d.ts +123 -0
  34. package/dist/models/prestige.js +183 -0
  35. package/dist/models/prestige.js.map +1 -0
  36. package/dist/models/productionChain.d.ts +114 -0
  37. package/dist/models/productionChain.js +447 -0
  38. package/dist/models/productionChain.js.map +1 -0
  39. package/dist/models/shared.d.ts +59 -0
  40. package/dist/models/shared.js +144 -0
  41. package/dist/models/shared.js.map +1 -0
  42. package/dist/money/types.d.ts +7 -0
  43. package/dist/notation/formatMoney.d.ts +7 -0
  44. package/dist/notation/formatMoney.js +7 -0
  45. package/dist/notation/formatMoney.js.map +1 -1
  46. package/dist/notation/parseMoney.d.ts +7 -0
  47. package/dist/notation/parseMoney.js +7 -0
  48. package/dist/notation/parseMoney.js.map +1 -1
  49. package/dist/notation/suffixer.d.ts +7 -0
  50. package/dist/notation/suffixer.js +7 -0
  51. package/dist/notation/suffixer.js.map +1 -1
  52. package/dist/notation/visibilityTracker.d.ts +7 -0
  53. package/dist/notation/visibilityTracker.js +7 -0
  54. package/dist/notation/visibilityTracker.js.map +1 -1
  55. package/dist/policy/emitter.d.ts +7 -0
  56. package/dist/policy/emitter.js +7 -0
  57. package/dist/policy/emitter.js.map +1 -1
  58. package/dist/policy/tickMoney.d.ts +7 -0
  59. package/dist/policy/tickMoney.js +7 -0
  60. package/dist/policy/tickMoney.js.map +1 -1
  61. package/dist/policy/types.d.ts +7 -0
  62. package/dist/report/chart.d.ts +196 -0
  63. package/dist/report/chart.js +275 -0
  64. package/dist/report/chart.js.map +1 -0
  65. package/dist/report/chartSvg.d.ts +9 -0
  66. package/dist/report/chartSvg.js +465 -0
  67. package/dist/report/chartSvg.js.map +1 -0
  68. package/dist/serde/moneyState.d.ts +7 -0
  69. package/dist/serde/moneyState.js +7 -0
  70. package/dist/serde/moneyState.js.map +1 -1
  71. package/dist/sim/analysis/designSpace.d.ts +23 -0
  72. package/dist/sim/analysis/designSpace.js +66 -0
  73. package/dist/sim/analysis/designSpace.js.map +1 -0
  74. package/dist/sim/analysis/globalSensitivity.d.ts +70 -0
  75. package/dist/sim/analysis/globalSensitivity.js +207 -0
  76. package/dist/sim/analysis/globalSensitivity.js.map +1 -0
  77. package/dist/sim/analysis/parameterSearch.d.ts +44 -0
  78. package/dist/sim/analysis/parameterSearch.js +172 -0
  79. package/dist/sim/analysis/parameterSearch.js.map +1 -0
  80. package/dist/sim/analysis/prestigeCycle.d.ts +1 -1
  81. package/dist/sim/analysis/prestigeCycle.js +7 -1
  82. package/dist/sim/analysis/prestigeCycle.js.map +1 -1
  83. package/dist/sim/analysis/resetInsights.d.ts +68 -0
  84. package/dist/sim/analysis/resetInsights.js +129 -0
  85. package/dist/sim/analysis/resetInsights.js.map +1 -0
  86. package/dist/sim/analysis/sampleStats.d.ts +34 -0
  87. package/dist/sim/analysis/sampleStats.js +97 -0
  88. package/dist/sim/analysis/sampleStats.js.map +1 -0
  89. package/dist/sim/monteCarlo.d.ts +7 -1
  90. package/dist/sim/monteCarlo.js +8 -0
  91. package/dist/sim/monteCarlo.js.map +1 -1
  92. package/dist/sim/random.d.ts +9 -0
  93. package/dist/sim/random.js +10 -1
  94. package/dist/sim/random.js.map +1 -1
  95. package/dist/sim/session.d.ts +2 -0
  96. package/dist/sim/session.js +15 -4
  97. package/dist/sim/session.js.map +1 -1
  98. package/dist/sim/sessionOffline.d.ts +4 -0
  99. package/dist/sim/sessionOffline.js +1 -0
  100. package/dist/sim/sessionOffline.js.map +1 -1
  101. package/dist/sim/stochastic.d.ts +82 -0
  102. package/dist/sim/stochastic.js +174 -0
  103. package/dist/sim/stochastic.js.map +1 -0
  104. package/dist/sim/timedWork.d.ts +10 -0
  105. package/dist/sim/timedWork.js +25 -0
  106. package/dist/sim/timedWork.js.map +1 -0
  107. package/package.json +3 -3
@@ -0,0 +1,183 @@
1
+ import { z } from "zod";
2
+ import { defineModelFactory } from "../scenario/registry";
3
+ import { createGeneratorCore, exponentialParamsSchema } from "./exponential";
4
+ import { amountOf, finiteAmount, nonNegativeAmount, optionalObjectSchema, pow10 } from "./shared";
5
+ export const PRESTIGE_MODEL_ID = "prestige";
6
+ export const PRESTIGE_RESET_ACTION_ID = "prestige.reset";
7
+ const rootFormula = z.object({
8
+ kind: z.literal("root"),
9
+ /** Points at exactly the requirement. */
10
+ scale: z.number().finite().positive().default(1),
11
+ /** gained = floor(scale * (measure / requirement)^exponent). */
12
+ exponent: z.number().finite().positive().max(1).default(0.5),
13
+ });
14
+ const log10Formula = z.object({
15
+ kind: z.literal("log10"),
16
+ /** gained = floor(scale * (log10(measure / requirement) + 1)). */
17
+ scale: z.number().finite().positive().default(1),
18
+ });
19
+ export const prestigeRulesSchema = z.object({
20
+ /** The run's net worth must reach this amount before a reset is offered. */
21
+ requirement: nonNegativeAmount.refine((value) => Number(value) > 0, "requirement must be > 0").default("1e6"),
22
+ formula: z.discriminatedUnion("kind", [rootFormula, log10Formula]).default({ kind: "root", scale: 1, exponent: 0.5 }),
23
+ /** Multiplier gained per total prestige point. */
24
+ multiplierPerPoint: z.number().finite().nonnegative().default(0.1),
25
+ /** additive: 1 + perPoint * points. compound: (1 + perPoint)^points. */
26
+ multiplierMode: z.enum(["additive", "compound"]).default("additive"),
27
+ /** Seconds a run must last before its reset is offered. The scenario cooldown still applies on top. */
28
+ minRunSec: z.number().finite().nonnegative().default(0),
29
+ /** A reset that would gain fewer points is not offered. */
30
+ minGain: z.number().int().positive().default(1),
31
+ /** Wallet after a reset. */
32
+ starterCash: nonNegativeAmount.default("0"),
33
+ /** Generator levels kept through a reset. */
34
+ keepLevels: z.number().int().nonnegative().default(0),
35
+ });
36
+ export const prestigeParamsSchema = z.object({
37
+ generator: exponentialParamsSchema.default(exponentialParamsSchema.parse({})),
38
+ prestige: prestigeRulesSchema.default(prestigeRulesSchema.parse({})),
39
+ });
40
+ export const prestigeVarsSchema = z
41
+ .object({
42
+ level: z.number().int().nonnegative().default(0),
43
+ /** `t` at which the current run started. Missing means the scenario start, which counts as `0`. */
44
+ runStartT: z.number().finite().nonnegative().default(0),
45
+ })
46
+ .partial();
47
+ export function parsePrestigeParams(raw) {
48
+ return prestigeParamsSchema.parse(raw ?? {});
49
+ }
50
+ /** Points a reset grants at `measure` under these rules. Below the requirement it is zero. */
51
+ export function prestigePointsFor(E, rules, measure) {
52
+ const requirement = amountOf(E, rules.requirement, PRESTIGE_MODEL_ID, "prestige.requirement");
53
+ if (!E.isFinite(measure) || E.cmp(measure, requirement) < 0)
54
+ return E.zero();
55
+ const ratioLog10 = Math.max(0, E.absLog10(measure) - E.absLog10(requirement));
56
+ if (rules.formula.kind === "log10") {
57
+ const gained = Math.floor(rules.formula.scale * (ratioLog10 + 1) + 1e-9);
58
+ return E.from(gained);
59
+ }
60
+ const gainLog10 = Math.log10(rules.formula.scale) + rules.formula.exponent * ratioLog10;
61
+ // Below 1e15 an integer is exact in a Number. Above it the floor is lost in the engine's precision anyway.
62
+ if (gainLog10 < 15)
63
+ return E.from(Math.floor(Math.pow(10, gainLog10) + 1e-9));
64
+ return pow10(E, gainLog10);
65
+ }
66
+ /** The prestige multiplier for a total of `points`. */
67
+ export function prestigeMultiplierFor(E, rules, points) {
68
+ if (rules.multiplierMode === "additive") {
69
+ return finiteAmount(E, E.add(E.from(1), E.mul(points, rules.multiplierPerPoint)), PRESTIGE_MODEL_ID, "multiplier");
70
+ }
71
+ if (rules.multiplierPerPoint === 0 || E.cmp(points, E.zero()) <= 0)
72
+ return E.from(1);
73
+ const pointsNumber = Math.pow(10, E.absLog10(points));
74
+ return finiteAmount(E, pow10(E, pointsNumber * Math.log10(1 + rules.multiplierPerPoint)), PRESTIGE_MODEL_ID, "multiplier");
75
+ }
76
+ /**
77
+ * What a reset at `measure` would grant from `currentPoints`. A design-time hook for tables and for checking
78
+ * reset-policy results by hand. It does not read run time, cooldown, or engine constraints.
79
+ */
80
+ export function previewPrestigeGain(E, params, measure, currentPoints = E.zero()) {
81
+ const rules = prestigeParamsSchema.parse(params).prestige;
82
+ const gainedPoints = prestigePointsFor(E, rules, measure);
83
+ const nextPoints = E.add(currentPoints, gainedPoints);
84
+ return {
85
+ eligible: E.cmp(gainedPoints, E.from(rules.minGain)) >= 0,
86
+ gainedPoints,
87
+ nextPoints,
88
+ nextMultiplier: prestigeMultiplierFor(E, rules, nextPoints),
89
+ };
90
+ }
91
+ /**
92
+ * Built-in `prestige` model: the `exponential` generator plus a first-class reset.
93
+ *
94
+ * The model lists one `prestige.reset` action (kind `prestige`) and a matching `Model.prestige` spec.
95
+ * `resetAdapterFor` picks the action, so `executeResetCycles` and `analyzeResetPolicies` apply exactly one reset
96
+ * per boundary, and the reward they read is `state.prestige.points`.
97
+ * The action has no cost and no income quote, so `greedy` never resets on its own. Reset timing is the
98
+ * caller's: a reset-cycle policy, `idk prestige-cycle`, a scripted strategy, or a plugin strategy.
99
+ */
100
+ export function createPrestigeModel(params = {}) {
101
+ const parsed = prestigeParamsSchema.parse(params);
102
+ const rules = parsed.prestige;
103
+ const core = createGeneratorCore(PRESTIGE_MODEL_ID, parsed.generator);
104
+ const netWorth = (ctx, state) => finiteAmount(ctx.E, ctx.E.add(state.wallet.money.amount, core.investedValue(ctx.E, core.levelOf(state))), PRESTIGE_MODEL_ID, "net worth");
105
+ const runStartOf = (state) => {
106
+ const raw = Number(state.vars?.runStartT ?? 0);
107
+ return Number.isFinite(raw) && raw >= 0 ? raw : 0;
108
+ };
109
+ const gainAt = (ctx, state) => prestigePointsFor(ctx.E, rules, netWorth(ctx, state));
110
+ const ready = (ctx, state) => {
111
+ if (state.t - runStartOf(state) < rules.minRunSec)
112
+ return false;
113
+ return ctx.E.cmp(gainAt(ctx, state), ctx.E.from(rules.minGain)) >= 0;
114
+ };
115
+ const resetState = (ctx, state, gained) => {
116
+ const E = ctx.E;
117
+ const starter = amountOf(E, rules.starterCash, PRESTIGE_MODEL_ID, "prestige.starterCash");
118
+ const nextPoints = finiteAmount(E, E.add(state.prestige.points, gained), PRESTIGE_MODEL_ID, "prestige points");
119
+ return {
120
+ ...state,
121
+ wallet: {
122
+ ...state.wallet,
123
+ money: { ...state.wallet.money, amount: starter },
124
+ bucket: E.zero(),
125
+ },
126
+ maxMoneyEver: { ...state.maxMoneyEver, amount: starter },
127
+ prestige: {
128
+ count: Number(state.prestige.count ?? 0) + 1,
129
+ points: nextPoints,
130
+ multiplier: prestigeMultiplierFor(E, rules, nextPoints),
131
+ },
132
+ vars: {
133
+ ...(state.vars ?? {}),
134
+ level: Math.min(rules.keepLevels, core.levelOf(state)),
135
+ runStartT: state.t,
136
+ },
137
+ };
138
+ };
139
+ const resetAction = (ctx) => ({
140
+ id: PRESTIGE_RESET_ACTION_ID,
141
+ kind: "prestige",
142
+ label: "Prestige Reset",
143
+ canApply: (_ctx, state) => ready(ctx, state),
144
+ cost: () => null,
145
+ apply: (applyCtx, state) => resetState(applyCtx, state, gainAt(applyCtx, state)),
146
+ });
147
+ const spec = {
148
+ pointsFrom: (ctx, state) => gainAt(ctx, state),
149
+ multiplierFrom: (ctx, points) => prestigeMultiplierFor(ctx.E, rules, points),
150
+ resetState,
151
+ };
152
+ return {
153
+ id: PRESTIGE_MODEL_ID,
154
+ version: 1,
155
+ income: (ctx, state) => core.realizedIncome(ctx, state),
156
+ actions: (ctx) => [core.buyAction(ctx), resetAction(ctx)],
157
+ prestige: spec,
158
+ netWorth: (ctx, state) => ({ unit: ctx.unit, amount: netWorth(ctx, state) }),
159
+ analytic: (ctx, state) => (core.stochastic ? null : core.analytic(ctx, state)),
160
+ milestones(ctx, prev, next) {
161
+ const out = core.milestones(ctx, prev, next);
162
+ // The step hook runs before `t` advances, so read `next` at the end of the tick; otherwise a
163
+ // time gate that opens on a tick boundary is ready in both states and the event is lost.
164
+ const dt = typeof ctx.stepSec === "number" && Number.isFinite(ctx.stepSec) && ctx.stepSec > 0 ? ctx.stepSec : 0;
165
+ const nextAtEnd = dt > 0 ? { ...next, t: next.t + dt } : next;
166
+ if (next.prestige.count === prev.prestige.count && !ready(ctx, prev) && ready(ctx, nextAtEnd)) {
167
+ out.push("prestige.reset-available");
168
+ }
169
+ return out;
170
+ },
171
+ };
172
+ }
173
+ /** Built-in `prestige@1`. */
174
+ export function createPrestigeFactory() {
175
+ return defineModelFactory({
176
+ id: PRESTIGE_MODEL_ID,
177
+ version: 1,
178
+ paramsSchema: optionalObjectSchema(prestigeParamsSchema),
179
+ varsSchema: optionalObjectSchema(prestigeVarsSchema),
180
+ create: (raw) => createPrestigeModel(parsePrestigeParams(raw)),
181
+ });
182
+ }
183
+ //# sourceMappingURL=prestige.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prestige.js","sourceRoot":"","sources":["../../src/models/prestige.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAwB,MAAM,eAAe,CAAC;AACnG,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAElG,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAmB,CAAC;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,gBAAyB,CAAC;AAElE,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACvB,yCAAyC;IACzC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAChD,gEAAgE;IAChE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;CAC7D,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACxB,kEAAkE;IAClE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;CACjD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,m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C,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAChH,MAAM,SAAS,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YAC9D,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,KAAK,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,CAAC;gBAC9F,GAAG,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YACvC,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,qBAAqB;IACnC,OAAO,kBAAkB,CAAgC;QACvD,EAAE,EAAE,iBAAiB;QACrB,OAAO,EAAE,CAAC;QACV,YAAY,EAAE,oBAAoB,CAAC,oBAAoB,CAAC;QACxD,UAAU,EAAE,oBAAoB,CAAC,kBAAkB,CAAC;QACpD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;KAC/D,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,114 @@
1
+ import { z } from "zod";
2
+ import { type ModelFactory } from "../scenario/registry";
3
+ import type { Model } from "../sim/types";
4
+ export declare const PRODUCTION_CHAIN_MODEL_ID: "production-chain";
5
+ export declare const productionChainParamsSchema: z.ZodObject<{
6
+ primary: z.ZodDefault<z.ZodObject<{
7
+ idleIncome: z.ZodDefault<z.ZodString>;
8
+ }, z.core.$strip>>;
9
+ resources: z.ZodDefault<z.ZodArray<z.ZodObject<{
10
+ id: z.ZodString;
11
+ initial: z.ZodDefault<z.ZodString>;
12
+ cap: z.ZodOptional<z.ZodString>;
13
+ valueInPrimary: z.ZodDefault<z.ZodNumber>;
14
+ }, z.core.$strip>>>;
15
+ recipes: z.ZodArray<z.ZodObject<{
16
+ id: z.ZodString;
17
+ inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
18
+ outputs: z.ZodRecord<z.ZodString, z.ZodString>;
19
+ timeSec: z.ZodDefault<z.ZodNumber>;
20
+ build: z.ZodDefault<z.ZodObject<{
21
+ currency: z.ZodDefault<z.ZodString>;
22
+ base: z.ZodDefault<z.ZodString>;
23
+ growth: z.ZodDefault<z.ZodNumber>;
24
+ }, z.core.$strip>>;
25
+ maxLevel: z.ZodOptional<z.ZodNumber>;
26
+ unlock: z.ZodDefault<z.ZodArray<z.ZodObject<{
27
+ recipe: z.ZodString;
28
+ level: z.ZodNumber;
29
+ }, z.core.$strip>>>;
30
+ }, z.core.$strip>>;
31
+ }, z.core.$strip>;
32
+ export type ProductionChainParams = z.output<typeof productionChainParamsSchema>;
33
+ export type ProductionChainParamsInput = z.input<typeof productionChainParamsSchema>;
34
+ export declare const productionChainVarsSchema: z.ZodObject<{
35
+ levels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
36
+ stock: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
37
+ }, z.core.$strip>;
38
+ export type ProductionChainVars = Readonly<{
39
+ levels?: Readonly<Record<string, number>>;
40
+ stock?: Readonly<Record<string, string>>;
41
+ }>;
42
+ export declare function parseProductionChainParams(raw: unknown): ProductionChainParams;
43
+ type RecipeShape = Readonly<{
44
+ id: string;
45
+ inputs: Readonly<Record<string, string>>;
46
+ outputs: Readonly<Record<string, string>>;
47
+ }>;
48
+ /**
49
+ * Producers before consumers, ties in declared order. A resource cycle (`primary` excluded) is rejected,
50
+ * because a continuous chain with a loop has no single processing order.
51
+ */
52
+ export declare function recipeOrder<R extends RecipeShape>(recipes: readonly R[]): R[];
53
+ export type ChainLimit = "capacity" | "unbuilt" | "locked" | Readonly<{
54
+ input: string;
55
+ }>;
56
+ export type ChainRecipeFlow = Readonly<{
57
+ id: string;
58
+ /** 1 for a recipe with no resource input. Otherwise 1 + the deepest producer of its inputs. */
59
+ depth: number;
60
+ level: number;
61
+ capacityBatchesPerSec: number;
62
+ batchesPerSec: number;
63
+ /** batchesPerSec / capacityBatchesPerSec, or 0 without capacity. */
64
+ utilization: number;
65
+ limitedBy: ChainLimit;
66
+ /** Extra value per second, in primary, from one more level of this recipe alone. */
67
+ marginalValuePerSec: number;
68
+ }>;
69
+ export type ChainResourceFlow = Readonly<{
70
+ id: string;
71
+ producedPerSec: number;
72
+ consumedPerSec: number;
73
+ surplusPerSec: number;
74
+ }>;
75
+ export type ProductionChainAnalysis = Readonly<{
76
+ /** Longest recipe path. */
77
+ depth: number;
78
+ recipes: readonly ChainRecipeFlow[];
79
+ resources: readonly ChainResourceFlow[];
80
+ /** Net primary per second from recipes, before the prestige multiplier. `primary.idleIncome` is excluded. */
81
+ primaryPerSec: number;
82
+ /** primaryPerSec plus each resource surplus times its valueInPrimary. */
83
+ valuePerSec: number;
84
+ /** The recipe whose next level adds the most value, or null when no level adds any. */
85
+ bottleneck: Readonly<{
86
+ recipe: string;
87
+ marginalValuePerSec: number;
88
+ limitedBy: ChainLimit;
89
+ }> | null;
90
+ /** Recipes held below capacity by an input. */
91
+ starved: readonly string[];
92
+ assumptions: readonly string[];
93
+ }>;
94
+ /**
95
+ * Steady-state flow of a production chain at the given levels, in the Number domain.
96
+ *
97
+ * Recipes run producers first. A resource consumed by two recipes goes to the earlier one first.
98
+ * Stock already held and storage caps are not part of a steady state, so a recipe fed from stock in a
99
+ * simulation can run faster for a while than this flow says.
100
+ */
101
+ export declare function analyzeProductionChain(params: ProductionChainParamsInput, levels?: Readonly<Record<string, number>>): ProductionChainAnalysis;
102
+ /**
103
+ * Built-in `production-chain` model: resources turned into other resources and primary money by recipes.
104
+ *
105
+ * Each recipe level finishes one batch per `timeSec`, as a continuous flow. In `evolve` recipes run producers
106
+ * first. A batch rate is limited by capacity, by each input held, and by the room left under each output cap.
107
+ * Primary outputs are multiplied by the prestige multiplier and added to the wallet. A build paid in a
108
+ * resource has `cost: null` for the wallet and deducts in `apply`. Build quotes carry the steady-state
109
+ * marginal value from `analyzeProductionChain`, so `greedy` builds the current bottleneck first.
110
+ */
111
+ export declare function createProductionChainModel<N, U extends string = string>(params: ProductionChainParamsInput): Model<N, U, ProductionChainVars>;
112
+ /** Built-in `production-chain@1`. */
113
+ export declare function createProductionChainFactory(): ModelFactory;
114
+ export {};