feat: More bonus (exponential) and method to list icons needed

This commit is contained in:
gauvainboiche
2026-10-08 14:20:58 +02:00
parent fc0d5e3ba4
commit a88b8f5f14
25 changed files with 977 additions and 40 deletions
+21 -8
View File
@@ -99,11 +99,22 @@ export function click(state, ctx) {
return true;
}
/**
* What a material purchase gives right now: the whole lot when it is affordable,
* otherwise as much of it as the funds allow (same unit price). Partial lots
* make sure a player can never be locked out of buying material.
*/
export function materialPurchase(state, d) {
if (state.funds >= d.batchCost) return { amount: d.batchSize, cost: d.batchCost };
if (!(state.funds >= 0.01)) return { amount: 0, cost: 0 };
return { amount: (d.batchSize * state.funds) / d.batchCost, cost: state.funds };
}
export function buyMaterial(state, ctx) {
const d = derive(state, ctx);
if (state.funds < d.batchCost) return false;
state.funds -= d.batchCost;
state.material += d.batchSize;
const purchase = materialPurchase(state, derive(state, ctx));
if (purchase.amount <= 0) return false;
state.funds -= purchase.cost;
state.material += purchase.amount;
return true;
}
@@ -175,11 +186,13 @@ function step(state, ctx, dt, rng, totals, offline) {
state.totalProduced += made;
state.lifetimeProduced += made;
// Automatic restock: patient while the price is high, urgent when nearly out.
if (d.autoBuyMaterial && state.funds >= d.batchCost) {
// Automatic restock: patient (full lots, at a fair price) while stock is fine,
// urgent (whatever the funds allow) when nearly out.
if (d.autoBuyMaterial) {
const { autoBuyBelowFactor } = ctx.rules.materialMarket;
const low = state.material < d.batchSize / 2 && state.materialFactor <= autoBuyBelowFactor;
if (low || state.material < d.batchSize / 10) buyMaterial(state, ctx);
const patient =
state.material < d.batchSize / 2 && state.materialFactor <= autoBuyBelowFactor && state.funds >= d.batchCost;
if (patient || state.material < d.batchSize / 10) buyMaterial(state, ctx);
}
// Customers buy what they want, up to what is in stock.