示例#1
0
void CraftDefinitionFuel::initHash(IGameDef *gamedef)
{
	if (hash_inited)
		return;
	hash_inited = true;
	recipe_name = craftGetItemName(recipe, gamedef);
}
示例#2
0
// (mapcar craftGetItemName itemstrings)
static std::vector<std::string> craftGetItemNames(
		const std::vector<std::string> &itemstrings, IGameDef *gamedef)
{
	std::vector<std::string> result;
	for (const auto &itemstring : itemstrings) {
		result.push_back(craftGetItemName(itemstring, gamedef));
	}
	return result;
}
示例#3
0
	virtual void registerCraft(CraftDefinition *def, IGameDef *gamedef)
	{
		verbosestream << "registerCraft: registering craft definition: "
				<< def->dump() << std::endl;
		m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0].push_back(def);

		CraftInput input;
		std::string output_name = craftGetItemName(
				def->getOutput(input, gamedef).item, gamedef);
		m_output_craft_definitions[output_name].push_back(def);
	}
示例#4
0
// (mapcar craftGetItemName itemstrings)
static std::vector<std::string> craftGetItemNames(
		const std::vector<std::string> &itemstrings, IGameDef *gamedef)
{
	std::vector<std::string> result;
	for (std::vector<std::string>::const_iterator
			it = itemstrings.begin();
			it != itemstrings.end(); it++) {
		result.push_back(craftGetItemName(*it, gamedef));
	}
	return result;
}
示例#5
0
bool CraftDefinitionFuel::check(const CraftInput &input, IGameDef *gamedef) const
{
	if(input.method != CRAFT_METHOD_FUEL)
		return false;

	// Get input item multiset
	std::vector<std::string> inp_names = craftGetItemNames(input.items, gamedef);
	std::multiset<std::string> inp_names_multiset = craftMakeMultiset(inp_names);

	// Get recipe item multiset
	std::multiset<std::string> rec_names_multiset;
	rec_names_multiset.insert(craftGetItemName(recipe, gamedef));

	// Recipe is matched when the multisets coincide
	return inp_names_multiset == rec_names_multiset;
}
示例#6
0
// Removes 1 from each item stack with replacement support
// Example: if replacements contains the pair ("bucket:bucket_water", "bucket:bucket_empty"),
//   a water bucket will not be removed but replaced by an empty bucket.
static void craftDecrementOrReplaceInput(CraftInput &input,
		const CraftReplacements &replacements,
		IGameDef *gamedef)
{
	if (replacements.pairs.empty()) {
		craftDecrementInput(input, gamedef);
		return;
	}

	// Make a copy of the replacements pair list
	std::vector<std::pair<std::string, std::string> > pairs = replacements.pairs;

	for (std::vector<ItemStack>::iterator
			it = input.items.begin();
			it != input.items.end(); it++) {
		if (it->count == 1) {
			// Find an appropriate replacement
			bool found_replacement = false;
			for (std::vector<std::pair<std::string, std::string> >::iterator
					j = pairs.begin();
					j != pairs.end(); j++) {
				if (it->name == craftGetItemName(j->first, gamedef)) {
					it->deSerialize(j->second, gamedef->idef());
					found_replacement = true;
					pairs.erase(j);
					break;
				}
			}
			// No replacement was found, simply decrement count to zero
			if (!found_replacement)
				it->remove(1);
		} else if (it->count >= 2) {
			// Ignore replacements for items with count >= 2
			it->remove(1);
		}
	}
}