QcVillagerTrades Class
The offers of the villagers (decision E-414): the offers of each profession from the trade sets of the content (QcTradeSet; offers naming an unknown item are left out with a warning), which of them a villager has, their price, the villager's experience and level, and restocking. More...
| Header: | #include <server/villages/QcVillagerTrades.h> |
Public Types
| struct | Offer |
Public Functions
| QcVillagerTrades() | |
| int | addExperience(QcVillagerRecord &villager, int points) const |
| std::pair<int, int> | levelRange(int level) const |
| QList<const QcVillagerTrades::Offer *> | offersOf(const QcVillagerRecord &villager) const |
| QList<QcVillagerTrades::Offer> | offersOfProfession(const QString &profession) const |
| QList<QcItemStack> | priceOf(const QcVillagerTrades::Offer &offer, const QcVillagerOffer &state) const |
| bool | restock(QcVillagerRecord &villager, double worldTime) const |
| const QcTradingSettings & | settings() const |
| void | sync(QcVillagerRecord &villager) const |
Detailed Description
The trading settings are those of one villager species (QcVillagerSettings::trading, decision E-421); a profession's own offersPerLevel takes the place of the species'.
A villager has, for each level it reached, up to QcTradingSettings::offersPerLevel offers of that level: those of its record that still exist, the free places drawn from its profession's other offers of the level by a stable hash of its look, the level and the offer's id. So it keeps them for good (also when a mod adds or removes offers), two villagers of a profession can differ, and the draw is the same on every Qt version. Its record keeps the uses and demand of each by the offer's id (QcVillagerRecord::offers).
Member Function Documentation
[constexpr noexcept default] QcVillagerTrades::QcVillagerTrades()
Default-constructs an instance of QcVillagerTrades.
int QcVillagerTrades::addExperience(QcVillagerRecord &villager, int points) const
Adds points of trade experience to villager; returns the levels reached by it (offersOf grows, sync follows).
std::pair<int, int> QcVillagerTrades::levelRange(int level) const
Returns the experience of level and of the next (the same at the highest level).
QList<const QcVillagerTrades::Offer *> QcVillagerTrades::offersOf(const QcVillagerRecord &villager) const
Returns the offers of villager by its profession, level and look, those of level 1 first.
QList<QcVillagerTrades::Offer> QcVillagerTrades::offersOfProfession(const QString &profession) const
Returns all offers of profession, by level and then in the order of the content.
QList<QcItemStack> QcVillagerTrades::priceOf(const QcVillagerTrades::Offer &offer, const QcVillagerOffer &state) const
Returns the costs of offer at its current price with the saved state: demand raises the first cost by demand items a step, at most to twice its base count and to its stack size.
bool QcVillagerTrades::restock(QcVillagerRecord &villager, double worldTime) const
villager at its workstation during work at worldTime: restocks when an offer was used, the day's restocks are not spent and the last one lies restockGap ago. Sold-out offers rise in demand, the others fall; all uses start again (after sync). Returns whether it restocked; cheap while no offer was used.
const QcTradingSettings &QcVillagerTrades::settings() const
Returns the trading settings of the species.
void QcVillagerTrades::sync(QcVillagerRecord &villager) const
Aligns the saved state of villager with offersOf: known ids keep their uses and demand, new offers start fresh, others are dropped.