From 9d5b458479a4eac14acb5af28f51ad23432264ab Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 17 Nov 2011 02:28:46 +0200 Subject: Crafting definition in scripts --- src/craftdef.cpp | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 src/craftdef.cpp (limited to 'src/craftdef.cpp') diff --git a/src/craftdef.cpp b/src/craftdef.cpp new file mode 100644 index 000000000..79761b857 --- /dev/null +++ b/src/craftdef.cpp @@ -0,0 +1,229 @@ +/* +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" + +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: IGNORING ERROR: " + <<"input_cpi.width > 3"<= 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: IGNORING ERROR: " + <<"spec_cpi.width > 3"<= spec_cpi.width || y >= spec_cpi.height()) + spec_items[i] = NULL; + else + spec_items[i] = spec_cpi.items[y*spec_cpi.width+x]; + infostream<<"spec_items["<output, std::ios::binary); + return InventoryItem::deSerialize(iss, gamedef); + } + } + return NULL; + } + virtual void registerCraft(const CraftDefinition &def) + { + infostream<<"registerCraft: registering craft definition: " + < 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(); +} + -- cgit v1.2.3