For AI agents: the complete documentation index is available at /ach-economy/en/llms.txt, the full documentation bundle is available at /ach-economy/en/llms-full.txt, and this page is available as Markdown at /ach-economy/en/api.md.

API

EconomyConfig

The value type holding all tuning values. Override only the fields you need from EconomyConfig.Default.

FieldDefaultDescription
TickInterval1Simulation time (seconds) for one long tick
PriceInertia0.15Speed the long-term price converges to its target (0~1). Symmetric inertia
DemandWeight1Weight of the demand term in the price formula
ShortTermResponse0.5How strongly a single trade pulls the short-term price (0~1)
ShortTermDecay0.25How strongly the short-term price mean-reverts to the long-term price (0~1)
InflationSensitivity0.1Sensitivity of source/sink pressure on the inflation multiplier. 0 disables it
MinPriceMultiplier0.25Lower bound of the final price multiplier
MaxPriceMultiplier4Upper bound of the final price multiplier
InflationAlertThreshold0.2OnInflationAlert fires above this absolute pressure
TradeFlowRate0.1Fraction of stock moved from surplus→deficit nodes each tick (0~1). 0 disables it

Economy

The single entry point (facade) of the dynamic economy.

Construction

Economy(EconomyConfig config, bool autoTick = false)

When autoTick is true, a hidden runner calls Tick every frame. Call Dispose() on shutdown.

Registration

MethodDescription
AddCommodity(id, basePrice, targetStock, baseDemand = 0)Register a commodity definition
AddMarket(id, initialStock = null)Register a market (node). Initial stock optional
AddRecipe(marketId, inputs, outputs, throughput = 1)Production/consumption recipe. Empty outputs = pure consumption
AddTradeRoute(marketA, marketB)Connect two nodes with a trade route

Trading (inflation-neutral)

MethodReturnsDescription
Buy(marketId, commodityId, quantity)TradeResultPlayer buys. Partial fill if stock is short
Sell(marketId, commodityId, quantity)TradeResultPlayer sells

source / sink (causes inflation)

MethodDescription
Inject(commodityId, amount, tag = null)Goods created from nothing (faucet). tag is a telemetry label
Consume(commodityId, amount, tag = null)Goods permanently removed (sink)

Queries

MethodReturnsDescription
GetPrice(marketId, commodityId)floatCurrent unit price (supply/demand + inflation multiplier applied)
GetStock(marketId, commodityId)floatCurrent stock
GetInflationMultiplier(commodityId)floatGlobal inflation multiplier (1 = neutral, <1 surplus, >1 scarce)
GetSinkFaucetRatio(commodityId)floatsink/faucet ratio. Above 1 means sink dominates

Tick

void Tick(float deltaTime)

Each time accumulated time reaches TickInterval, runs a long tick (production → trade → price convergence → inflation update).

Events

EventSignatureWhen
OnPriceChanged(market, commodity, newPrice)Unit price updated
OnStockChanged(market, commodity, newStock)Stock changed
OnTradeExecuted(TradeResult)Trade settled
OnInflationAlert(commodity, pressure)Pressure exceeds the threshold
OnDailyTick()One long tick completed

TradeResult

The result of Buy/Sell. On failure it returns with Success == false instead of throwing.

FieldTypeDescription
SuccessboolWhether it settled
Market / CommoditystringTarget node/commodity id
QuantityfloatActual filled quantity
UnitPricefloatSettled unit price
TotalCostfloatTotal amount
StockAfterfloatStock after the trade
ReasonstringFailure reason (empty string on success)

Price formula

balance multiplier = (targetStock + demand + 1) / (currentStock + demand + 1)
final price        = basePrice × clamp(shortMul × inflationMul, Min, Max)
  • Short multiplier: moves to the balance value by ShortTermResponse on each trade
  • Long multiplier: converges symmetrically to the balance value by PriceInertia each tick; short mean-reverts to long
  • Inflation multiplier: updated by net source/sink pressure — net creation < 1 (cheaper), net removal > 1 (pricier)