From e070f1e5250b6853788cb827bb2f46ecdbe300a8 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Sat, 11 Feb 2012 18:10:13 +0100 Subject: Allow replacements in cooking and fuel recipes --- src/craftdef.cpp | 68 +++++++++++++++++++++++++++++-------------------------- src/craftdef.h | 17 ++++++++++---- src/scriptapi.cpp | 22 ++++++++++++++++-- 3 files changed, 69 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/craftdef.cpp b/src/craftdef.cpp index e8f67442f..57a1851af 100644 --- a/src/craftdef.cpp +++ b/src/craftdef.cpp @@ -260,6 +260,7 @@ std::string CraftOutput::dump() const /* CraftReplacements */ + std::string CraftReplacements::dump() const { std::ostringstream os(std::ios::binary); @@ -276,6 +277,27 @@ std::string CraftReplacements::dump() const return os.str(); } +void CraftReplacements::serialize(std::ostream &os) const +{ + writeU16(os, pairs.size()); + for(u32 i=0; iregisterCraft(def); } /* @@ -4144,8 +4153,17 @@ static int l_register_craft(lua_State *L) float burntime = getfloatfield_default(L, table, "burntime", 1.0); + CraftReplacements replacements; + lua_getfield(L, table, "replacements"); + if(!lua_isnil(L, -1)) + { + if(!read_craft_replacements(L, -1, replacements)) + throw LuaError(L, "Invalid replacements" + " (fuel recipe=\"" + recipe + "\")"); + } + CraftDefinition *def = new CraftDefinitionFuel( - recipe, burntime); + recipe, burntime, replacements); craftdef->registerCraft(def); } else -- cgit v1.2.3