fix: Changing way to sell with demand

This commit is contained in:
gauvainboiche
2026-10-08 12:34:33 +02:00
parent 1734487f1e
commit c98995f310
7 changed files with 103 additions and 38 deletions
+19 -4
View File
@@ -6,7 +6,8 @@ import { t } from '../services/i18n.js';
import { $, h, icon, refreshStaticIcons } from './dom.js';
const SLIDER_STEPS = 1000;
const TREND = { '-1': '▼', 1: '▲' }; // last move of the material price
const MARKET_TOLERANCE = 1.15; // demand within ±15 % of output counts as balanced
const TREND ={ '-1': '▼', 1: '▲' }; // last move of the material price
function setText(node, text) {
if (node.textContent !== text) node.textContent = text;
@@ -184,14 +185,28 @@ export function createView(actions) {
);
}
/**
* Feedback on the price: what customers want versus what is produced, and
* which side of the balance the player is on. It never gives the balanced
* price itself: it depends on output and every bonus, so it must be found.
*/
function marketHint(d) {
const demand = fmt.number(d.demand);
if (d.rate <= 0) return t('ui.hintDemandOnly', { demand });
const ratio = d.demand / d.rate;
let verdict = 'ui.marketBalanced';
if (ratio > MARKET_TOLERANCE) verdict = 'ui.marketShort';
else if (ratio < 1 / MARKET_TOLERANCE) verdict = 'ui.marketLong';
return `${t('ui.hintDemand', { demand, production: fmt.number(d.rate) })} ${t(verdict)}`;
}
function updateMarket(state, d) {
const { fairPrice, minPrice } = ctx.rules.market;
const { minPrice } = ctx.rules.market;
if (document.activeElement !== el.priceInput) el.priceInput.value = state.price.toFixed(2);
if (document.activeElement !== el.priceSlider) {
el.priceSlider.value = Math.round(sliderFromPrice(Math.max(state.price, minPrice)));
}
const hintKey = state.price > fairPrice ? 'ui.hintHigh' : 'ui.hintFair';
setText(el.priceHint, t(hintKey, { fair: money(fairPrice), demand: fmt.number(d.demand) }));
setText(el.priceHint, marketHint(d));
const nextLevelMultiplier = ctx.rules.marketing.demandPerLevel ** (state.marketing + 1);
setText(