fix: Changing way to sell with demand
This commit is contained in:
@@ -45,17 +45,26 @@ 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 };
|
||||
const cents = size * materialUnitPrice(mm, totalProduced) * factor * discount;
|
||||
return { size, cost: Math.max(0.01, Math.round(cents * 100) / 100) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Units customers want to buy per second at `price`.
|
||||
* Demand is maxed at or below the fair price and drops steeply above it, so
|
||||
* extra production is only worth selling at a higher price while supply is
|
||||
* short; to sell more at the fair price, the player needs more demand.
|
||||
* Units customers want to buy per second at `price`: a smooth curve, with more
|
||||
* demand the lower the price and less the higher it is (`referencePrice` is
|
||||
* just where demand equals baseDemand x multiplier).
|
||||
*/
|
||||
export function demandPerSecond(market, price, multiplier) {
|
||||
const overpriced = Math.max(1, price / market.fairPrice);
|
||||
return (market.baseDemand * multiplier) / overpriced ** market.elasticity;
|
||||
return market.baseDemand * multiplier * (market.referencePrice / price) ** market.elasticity;
|
||||
}
|
||||
|
||||
/**
|
||||
* The price at which customers buy exactly what is produced. Selling for less
|
||||
* gains no volume (everything is already sold); selling for more leaves stock
|
||||
* unsold. It moves with output and every demand bonus, and the UI deliberately
|
||||
* does not reveal it: the player finds it from the market feedback.
|
||||
*/
|
||||
export function balancedPrice(market, supplyPerSecond, multiplier) {
|
||||
const demandAtReference = market.baseDemand * multiplier;
|
||||
return market.referencePrice * (demandAtReference / supplyPerSecond) ** (1 / market.elasticity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user