QcCrafting Namespace
Recipe matching shared by server (authoritative) and client (preview). More...
| Header: | #include <common/gameplay/QcCrafting.h> |
Functions
| int | available(const QcContentRegistry &content, const QcInventory &inventory, const QString &ingredient) |
| bool | consume(const QcContentRegistry &content, QcInventory &inventory, const QcRecipeDefinition &recipe, int times) |
| QList<QcItemStack> | containersLeft(const QcContentRegistry &content, const QcInventory &before, const QcInventory &after) |
| int | gridSizeNeeded(const QcRecipeDefinition &recipe) |
| std::optional<qsizetype> | match(const QcContentRegistry &content, const QList<QcItemStack> &grid, int size) |
| bool | matches(const QcContentRegistry &content, QcItemId item, const QString &ingredient) |
| std::optional<QcItemId> | remainderOf(const QcContentRegistry &content, QcItemId item) |
| bool | removeIngredient(const QcContentRegistry &content, QcInventory &inventory, const QString &ingredient, int count) |
| QList<std::pair<QString, int>> | requirements(const QcRecipeDefinition &recipe) |
| QList<std::pair<QString, int>> | requirements(const QcContentRegistry &content, const QcRecipeDefinition &recipe) |
| int | timesCraftable(const QcContentRegistry &content, const QcInventory &inventory, const QcRecipeDefinition &recipe, int limit) |
Detailed Description
Function Documentation
int QcCrafting::available(const QcContentRegistry &content, const QcInventory &inventory, const QString &ingredient)
Returns how many items of inventory fit ingredient (items of content).
bool QcCrafting::consume(const QcContentRegistry &content, QcInventory &inventory, const QcRecipeDefinition &recipe, int times)
Removes the ingredients of times crafts of recipe from inventory in the order of requirements(content, recipe). Returns false (and possibly some removed) when they are not all there, so callers work on a copy. Server and client use this. Taken ingredients leave their container (a milk bucket its empty bucket, decision E-771); false as well when there is no room for it.
QList<QcItemStack> QcCrafting::containersLeft(const QcContentRegistry &content, const QcInventory &before, const QcInventory &after)
Returns the containers the items taken from before to leave after give back, one stack per container item and taken item, as content defines them.
int QcCrafting::gridSizeNeeded(const QcRecipeDefinition &recipe)
Returns the side length of the smallest grid that holds recipe (2 fits the inventory, 3 needs a table).
std::optional<qsizetype> QcCrafting::match(const QcContentRegistry &content, const QList<QcItemStack> &grid, int size)
Returns the index of the recipe of content that the square grid (size x size, row-major) of stacks produces, if any. Shaped recipes may sit anywhere in the grid and may be mirrored horizontally.
bool QcCrafting::matches(const QcContentRegistry &content, QcItemId item, const QString &ingredient)
Returns whether item of content fits ingredient: the item of that name, or any item with the tag of "#tag".
std::optional<QcItemId> QcCrafting::remainderOf(const QcContentRegistry &content, QcItemId item)
Returns the container item of content leaves when crafted with (its emptiesTo), if any.
bool QcCrafting::removeIngredient(const QcContentRegistry &content, QcInventory &inventory, const QString &ingredient, int count)
Removes count items that fit ingredient from inventory (items of content). Returns false (and possibly some removed) when there are fewer, so callers work on a copy.
QList<std::pair<QString, int>> QcCrafting::requirements(const QcRecipeDefinition &recipe)
Returns the items recipe consumes once, as ingredient (item name or "#tag") -> count; named items come before tags, so a tag never takes an item a named ingredient needs.
QList<std::pair<QString, int>> QcCrafting::requirements(const QcContentRegistry &content, const QcRecipeDefinition &recipe)
Returns the same for recipe, with the tags ordered from the narrowest (fewest items of content carry it) to the widest: an item with two tags goes to the narrower one, which has fewer alternatives.
int QcCrafting::timesCraftable(const QcContentRegistry &content, const QcInventory &inventory, const QcRecipeDefinition &recipe, int limit)
Returns how often (at most limit) inventory holds the ingredients of recipe, as consume() takes them with the items of content.