]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/craftdef.cpp
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.git] / src / craftdef.cpp
index b15443607e81e949c1f112f1f2246a84e8386d68..5c7c3a4659d5012ace8901179e61c331cdedafa2 100644 (file)
@@ -1,6 +1,6 @@
 /*
-Minetest-c55
-Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "inventory.h"
 #include "util/serialize.h"
 #include "strfnd.h"
+#include "exceptions.h"
 
 // Check if input matches recipe
 // Takes recipe groups into account
@@ -150,23 +151,6 @@ static bool craftGetBounds(const std::vector<std::string> &items, unsigned int w
        return success;
 }
 
-#if 0
-// This became useless when group support was added to shapeless recipes
-// Convert a list of item names to a multiset
-static std::multiset<std::string> craftMakeMultiset(const std::vector<std::string> &names)
-{
-       std::multiset<std::string> set;
-       for(std::vector<std::string>::const_iterator
-                       i = names.begin();
-                       i != names.end(); i++)
-       {
-               if(*i != "")
-                       set.insert(*i);
-       }
-       return set;
-}
-#endif
-
 // Removes 1 from each item stack
 static void craftDecrementInput(CraftInput &input, IGameDef *gamedef)
 {
@@ -987,6 +971,43 @@ class CCraftDefManager: public IWritableCraftDefManager
                }
                return false;
        }
+       virtual std::vector<CraftDefinition*> getCraftRecipes(CraftOutput &output,
+                       IGameDef *gamedef) const
+       {
+               std::vector<CraftDefinition*> recipes_list;
+               CraftInput input;
+               CraftOutput tmpout;
+               tmpout.item = "";
+               tmpout.time = 0;
+
+               for(std::vector<CraftDefinition*>::const_reverse_iterator
+                               i = m_craft_definitions.rbegin();
+                               i != m_craft_definitions.rend(); i++)
+               {
+                       CraftDefinition *def = *i;
+
+                       /*infostream<<"Checking "<<input.dump()<<std::endl
+                                       <<" against "<<def->dump()<<std::endl;*/
+
+                       try {
+                               tmpout = def->getOutput(input, gamedef);
+                               if(tmpout.item.substr(0,output.item.length()) == output.item)
+                               {
+                                       // Get output, then decrement input (if requested)
+                                       input = def->getInput(output, gamedef);
+                                       recipes_list.push_back(*i);
+                               }
+                       }
+                       catch(SerializationError &e)
+                       {
+                               errorstream<<"getCraftResult: ERROR: "
+                                               <<"Serialization error in recipe "
+                                               <<def->dump()<<std::endl;
+                               // then go on with the next craft definition
+                       }
+               }
+               return recipes_list;
+       }
        virtual std::string dump() const
        {
                std::ostringstream os(std::ios::binary);