feat: New theme + wire price adjustement

This commit is contained in:
gauvainboiche
2026-10-08 12:25:45 +02:00
parent aa9721ac2a
commit 1734487f1e
19 changed files with 348 additions and 88 deletions
+24
View File
@@ -25,6 +25,30 @@ export function maxAffordable(base, growth, owned, budget) {
return Math.max(n, 0);
}
/**
* Raw-material price per unit of material, before market noise. Expensive at
* first, then cheaper relative to revenue as the operation scales
* (economies of scale): it falls from `startUnitPrice` towards `floorUnitPrice`.
*/
export function materialUnitPrice(mm, totalProduced) {
const scale = 1 / Math.sqrt(1 + totalProduced / mm.scale);
return mm.floorUnitPrice + (mm.startUnitPrice - mm.floorUnitPrice) * scale;
}
/**
* What one purchase of material looks like. The lot grows with the operation
* (a share of everything produced so far, or `batchSecondsOfProduction` of
* current output), in doubling steps so the price stays readable.
* `factor` is the market's current noise, `discount` comes from upgrades.
*/
export function materialBatch(mm, totalProduced, rate, factor, discount) {
const basis = Math.max(totalProduced * mm.batchShareOfTotal, rate * mm.batchSecondsOfProduction);
const doublings = Math.max(0, Math.floor(Math.log2(Math.max(1, basis / mm.minBatch))));
const size = mm.minBatch * 2 ** doublings;
const cost = Math.max(1, Math.ceil(size * materialUnitPrice(mm, totalProduced) * factor * discount));
return { size, cost };
}
/**
* Units customers want to buy per second at `price`.
* Demand is maxed at or below the fair price and drops steeply above it, so