/* Minetest-c55 Copyright (C) 2011 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "craftdef.h" #include "irrlichttypes.h" #include "log.h" #include #include "utility.h" #include "gamedef.h" #include "inventory.h" #include "inventorymanager.h" // checkItemCombination CraftPointerInput::~CraftPointerInput() { for(u32 i=0; i items; for(u32 i=0; i items; for(u32 i=0; iserialize(oss); items.push_back(oss.str()); } } return CraftInput(cpi.width, items); } std::string CraftInput::dump() const { std::ostringstream os(std::ios::binary); os<<"(width="< 3){ errorstream<<"getCraftResult(): ERROR: " <<"input_cpi.width > 3; Failing to craft."<= input_cpi.width || y >= input_cpi.height()) input_items[i] = NULL; else input_items[i] = input_cpi.items[y*input_cpi.width+x]; } for(core::list::ConstIterator i = m_craft_definitions.begin(); i != m_craft_definitions.end(); i++) { CraftDefinition *def = *i; /*infostream<<"Checking "<input.dump() <<" (output=\""<output<<"\")"<input, gamedef); if(spec_cpi.width > 3){ errorstream<<"getCraftResult: ERROR: " <<"spec_cpi.width > 3 in recipe " <dump()<= spec_cpi.width || y >= spec_cpi.height()) spec_items[i] = NULL; else spec_items[i] = spec_cpi.items[y*spec_cpi.width+x]; } bool match = checkItemCombination(input_items, spec_items); if(match){ std::istringstream iss(def->output, std::ios::binary); return InventoryItem::deSerialize(iss, gamedef); } } catch(SerializationError &e) { errorstream<<"getCraftResult: ERROR: " <<"Serialization error in recipe " <dump()< 3 || def.input.height() > 3){ errorstream<<"registerCraft: input size is larger than 3x3," <<" ignoring"<::Iterator i = m_craft_definitions.begin(); i != m_craft_definitions.end(); i++){ delete *i; } m_craft_definitions.clear(); } virtual void serialize(std::ostream &os) { writeU8(os, 0); // version u16 count = m_craft_definitions.size(); writeU16(os, count); for(core::list::Iterator i = m_craft_definitions.begin(); i != m_craft_definitions.end(); i++){ CraftDefinition *def = *i; // Serialize wrapped in a string std::ostringstream tmp_os(std::ios::binary); def->serialize(tmp_os); os< m_craft_definitions; }; IWritableCraftDefManager* createCraftDefManager() { return new CCraftDefManager(); }