From 5e6c7368592c0fbaa4d9d4320767d3cdcfd0261e Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 12 Jun 2012 20:03:46 +0000 Subject: Updated the crafting recipes architecture to better support crafting hooks. Removed the old recipe file and implementation altogether. git-svn-id: http://mc-server.googlecode.com/svn/trunk@597 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/AllToLua.pkg | 3 +- source/Bindings.cpp | 1108 ++++++++++++++++++++++++++++++++++++----- source/Bindings.h | 2 +- source/CraftingRecipes.cpp | 271 +++++++++- source/CraftingRecipes.h | 95 +++- source/cCraftingWindow.cpp | 41 +- source/cCreativeInventory.cpp | 1 - source/cInventory.cpp | 85 +++- source/cItem.h | 61 ++- source/cRecipeChecker.cpp | 467 ----------------- source/cRecipeChecker.h | 39 -- source/cRoot.cpp | 4 - source/cRoot.h | 3 - source/cServer.cpp | 1 - source/cSurvivalInventory.cpp | 35 +- 15 files changed, 1467 insertions(+), 749 deletions(-) delete mode 100644 source/cRecipeChecker.cpp delete mode 100644 source/cRecipeChecker.h (limited to 'source') diff --git a/source/AllToLua.pkg b/source/AllToLua.pkg index 9ccb0eb1d..c6e0f0565 100644 --- a/source/AllToLua.pkg +++ b/source/AllToLua.pkg @@ -45,4 +45,5 @@ $cfile "cGroup.h" $cfile "packets/cPacket_Login.h" $cfile "packets/cPacket_BlockDig.h" $cfile "packets/cPacket_BlockPlace.h" -$cfile "cLuaChunk.h" \ No newline at end of file +$cfile "cLuaChunk.h" +$cfile "CraftingRecipes.h" diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 07adbea1e..56f27fd32 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 06/10/12 15:55:56. +** Generated automatically by tolua++-1.0.92 on 06/12/12 21:57:04. */ #ifndef __cplusplus @@ -56,10 +56,18 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S); #include "packets/cPacket_BlockDig.h" #include "packets/cPacket_BlockPlace.h" #include "cLuaChunk.h" +#include "CraftingRecipes.h" /* function to release collected object via destructor */ #ifdef __cplusplus +static int tolua_collect_cMCLogger (lua_State* tolua_S) +{ + cMCLogger* self = (cMCLogger*) tolua_tousertype(tolua_S,1,0); + Mtolua_delete(self); + return 0; +} + static int tolua_collect_cItem (lua_State* tolua_S) { cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0); @@ -109,9 +117,9 @@ static int tolua_collect_cPlugin (lua_State* tolua_S) return 0; } -static int tolua_collect_cMCLogger (lua_State* tolua_S) +static int tolua_collect_cCraftingGrid (lua_State* tolua_S) { - cMCLogger* self = (cMCLogger*) tolua_tousertype(tolua_S,1,0); + cCraftingGrid* self = (cCraftingGrid*) tolua_tousertype(tolua_S,1,0); Mtolua_delete(self); return 0; } @@ -164,32 +172,33 @@ static int tolua_collect_Vector3d (lua_State* tolua_S) static void tolua_reg_types (lua_State* tolua_S) { tolua_usertype(tolua_S,"TakeDamageInfo"); + tolua_usertype(tolua_S,"cCraftingRecipe"); tolua_usertype(tolua_S,"cPlugin"); - tolua_usertype(tolua_S,"cLuaChunk"); + tolua_usertype(tolua_S,"cCraftingGrid"); tolua_usertype(tolua_S,"cStringMap"); + tolua_usertype(tolua_S,"cLuaChunk"); tolua_usertype(tolua_S,"Lua__cEntity"); tolua_usertype(tolua_S,"Lua__cPacket_BlockDig"); - tolua_usertype(tolua_S,"cTCPLink"); tolua_usertype(tolua_S,"Json::Value"); tolua_usertype(tolua_S,"cInventory"); tolua_usertype(tolua_S,"cRoot"); tolua_usertype(tolua_S,"Lua__cTCPLink"); - tolua_usertype(tolua_S,"cMCLogger"); - tolua_usertype(tolua_S,"cGroup"); + tolua_usertype(tolua_S,"cPlugin_NewLua"); + tolua_usertype(tolua_S,"cTracer"); tolua_usertype(tolua_S,"cPlugin::CommandStruct"); tolua_usertype(tolua_S,"cPickup"); - tolua_usertype(tolua_S,"cTracer"); + tolua_usertype(tolua_S,"cGroup"); tolua_usertype(tolua_S,"cPacket_Login"); tolua_usertype(tolua_S,"cClientHandle"); tolua_usertype(tolua_S,"cStep"); tolua_usertype(tolua_S,"cFurnaceRecipe"); - tolua_usertype(tolua_S,"cCuboid"); + tolua_usertype(tolua_S,"cMCLogger"); tolua_usertype(tolua_S,"cChatColor"); - tolua_usertype(tolua_S,"Vector3i"); + tolua_usertype(tolua_S,"cCuboid"); tolua_usertype(tolua_S,"cPacket_PickupSpawn"); tolua_usertype(tolua_S,"Lua__cWebPlugin"); tolua_usertype(tolua_S,"Lua__cPawn"); - tolua_usertype(tolua_S,"cPlugin_NewLua"); + tolua_usertype(tolua_S,"Vector3i"); tolua_usertype(tolua_S,"cItem"); tolua_usertype(tolua_S,"Vector3f"); tolua_usertype(tolua_S,"cPlugin_Lua"); @@ -198,9 +207,9 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cPacket"); tolua_usertype(tolua_S,"cPacket_BlockDig"); tolua_usertype(tolua_S,"cWebAdmin"); - tolua_usertype(tolua_S,"cCraftingRecipes"); + tolua_usertype(tolua_S,"cTCPLink"); tolua_usertype(tolua_S,"cBlockEntity"); - tolua_usertype(tolua_S,"cRecipeChecker"); + tolua_usertype(tolua_S,"cCraftingRecipes"); tolua_usertype(tolua_S,"cGroupManager"); tolua_usertype(tolua_S,"Lua__cPlugin"); tolua_usertype(tolua_S,"Lua__cPickup"); @@ -11493,6 +11502,37 @@ static int tolua_AllToLua_cItem_Empty00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: Clear of class cItem */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_Clear00 +static int tolua_AllToLua_cItem_Clear00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Clear'", NULL); +#endif + { + self->Clear(); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'Clear'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: IsEmpty of class cItem */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_IsEmpty00 static int tolua_AllToLua_cItem_IsEmpty00(lua_State* tolua_S) @@ -11559,6 +11599,102 @@ static int tolua_AllToLua_cItem_Equals00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: GetMaxDuration of class cItem */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_GetMaxDuration00 +static int tolua_AllToLua_cItem_GetMaxDuration00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cItem",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cItem* self = (const cItem*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxDuration'", NULL); +#endif + { + int tolua_ret = (int) self->GetMaxDuration(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetMaxDuration'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: DamageItem of class cItem */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_DamageItem00 +static int tolua_AllToLua_cItem_DamageItem00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DamageItem'", NULL); +#endif + { + bool tolua_ret = (bool) self->DamageItem(); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'DamageItem'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: HasDuration of class cItem */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_HasDuration00 +static int tolua_AllToLua_cItem_HasDuration00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HasDuration'", NULL); +#endif + { + bool tolua_ret = (bool) self->HasDuration(); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'HasDuration'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: GetJson of class cItem */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_GetJson00 static int tolua_AllToLua_cItem_GetJson00(lua_State* tolua_S) @@ -11625,6 +11761,36 @@ static int tolua_AllToLua_cItem_FromJson00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: IsEnchantable of class cItem */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_IsEnchantable00 +static int tolua_AllToLua_cItem_IsEnchantable00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cItem",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + ENUM_ITEM_ID item = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,2,0)); + { + bool tolua_ret = (bool) cItem::IsEnchantable(item); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'IsEnchantable'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* get function: m_ItemID of class cItem */ #ifndef TOLUA_DISABLE_tolua_get_cItem_m_ItemID static int tolua_get_cItem_m_ItemID(lua_State* tolua_S) @@ -12943,38 +13109,6 @@ static int tolua_AllToLua_cRoot_GetGroupManager00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: GetRecipeChecker of class cRoot */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cRoot_GetRecipeChecker00 -static int tolua_AllToLua_cRoot_GetRecipeChecker00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"cRoot",0,&tolua_err) || - !tolua_isnoobj(tolua_S,2,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - cRoot* self = (cRoot*) tolua_tousertype(tolua_S,1,0); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetRecipeChecker'", NULL); -#endif - { - cRecipeChecker* tolua_ret = (cRecipeChecker*) self->GetRecipeChecker(); - tolua_pushusertype(tolua_S,(void*)tolua_ret,"cRecipeChecker"); - } - } - return 1; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'GetRecipeChecker'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - /* method: GetCraftingRecipes of class cRoot */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cRoot_GetCraftingRecipes00 static int tolua_AllToLua_cRoot_GetCraftingRecipes00(lua_State* tolua_S) @@ -17598,81 +17732,779 @@ static int tolua_AllToLua_cLuaChunk_FillBlocks00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* Open function */ -TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) +/* method: new of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_new00 +static int tolua_AllToLua_cCraftingGrid_new00(lua_State* tolua_S) { - tolua_open(tolua_S); - tolua_reg_types(tolua_S); - tolua_module(tolua_S,NULL,1); - tolua_beginmodule(tolua_S,NULL); - tolua_cclass(tolua_S,"cTorch","cTorch","",NULL); - tolua_beginmodule(tolua_S,"cTorch"); - tolua_function(tolua_S,"DirectionToMetaData",tolua_AllToLua_cTorch_DirectionToMetaData00); - tolua_function(tolua_S,"MetaDataToDirection",tolua_AllToLua_cTorch_MetaDataToDirection00); - tolua_endmodule(tolua_S); - tolua_cclass(tolua_S,"cStairs","cStairs","",NULL); - tolua_beginmodule(tolua_S,"cStairs"); - tolua_function(tolua_S,"RotationToMetaData",tolua_AllToLua_cStairs_RotationToMetaData00); - tolua_endmodule(tolua_S); - tolua_cclass(tolua_S,"cStep","cStep","",NULL); - tolua_beginmodule(tolua_S,"cStep"); - tolua_function(tolua_S,"DirectionToMetaData",tolua_AllToLua_cStep_DirectionToMetaData00); - tolua_endmodule(tolua_S); - tolua_cclass(tolua_S,"cLadder","cLadder","",NULL); - tolua_beginmodule(tolua_S,"cLadder"); - tolua_function(tolua_S,"DirectionToMetaData",tolua_AllToLua_cLadder_DirectionToMetaData00); - tolua_function(tolua_S,"MetaDataToDirection",tolua_AllToLua_cLadder_MetaDataToDirection00); - tolua_endmodule(tolua_S); - #ifdef __cplusplus - tolua_cclass(tolua_S,"cIniFile","cIniFile","",tolua_collect_cIniFile); - #else - tolua_cclass(tolua_S,"cIniFile","cIniFile","",NULL); - #endif - tolua_beginmodule(tolua_S,"cIniFile"); - tolua_constant(tolua_S,"noID",cIniFile::noID); - tolua_function(tolua_S,"new",tolua_AllToLua_cIniFile_new00); - tolua_function(tolua_S,"new_local",tolua_AllToLua_cIniFile_new00_local); - tolua_function(tolua_S,".call",tolua_AllToLua_cIniFile_new00_local); - tolua_function(tolua_S,"CaseSensitive",tolua_AllToLua_cIniFile_CaseSensitive00); - tolua_function(tolua_S,"CaseInsensitive",tolua_AllToLua_cIniFile_CaseInsensitive00); - tolua_function(tolua_S,"Path",tolua_AllToLua_cIniFile_Path00); - tolua_function(tolua_S,"Path",tolua_AllToLua_cIniFile_Path01); - tolua_function(tolua_S,"SetPath",tolua_AllToLua_cIniFile_SetPath00); - tolua_function(tolua_S,"ReadFile",tolua_AllToLua_cIniFile_ReadFile00); - tolua_function(tolua_S,"WriteFile",tolua_AllToLua_cIniFile_WriteFile00); - tolua_function(tolua_S,"Erase",tolua_AllToLua_cIniFile_Erase00); - tolua_function(tolua_S,"Clear",tolua_AllToLua_cIniFile_Clear00); - tolua_function(tolua_S,"Reset",tolua_AllToLua_cIniFile_Reset00); - tolua_function(tolua_S,"FindKey",tolua_AllToLua_cIniFile_FindKey00); - tolua_function(tolua_S,"FindValue",tolua_AllToLua_cIniFile_FindValue00); - tolua_function(tolua_S,"NumKeys",tolua_AllToLua_cIniFile_NumKeys00); - tolua_function(tolua_S,"GetNumKeys",tolua_AllToLua_cIniFile_GetNumKeys00); - tolua_function(tolua_S,"AddKeyName",tolua_AllToLua_cIniFile_AddKeyName00); - tolua_function(tolua_S,"KeyName",tolua_AllToLua_cIniFile_KeyName00); - tolua_function(tolua_S,"GetKeyName",tolua_AllToLua_cIniFile_GetKeyName00); - tolua_function(tolua_S,"NumValues",tolua_AllToLua_cIniFile_NumValues00); - tolua_function(tolua_S,"GetNumValues",tolua_AllToLua_cIniFile_GetNumValues00); - tolua_function(tolua_S,"NumValues",tolua_AllToLua_cIniFile_NumValues01); - tolua_function(tolua_S,"GetNumValues",tolua_AllToLua_cIniFile_GetNumValues01); - tolua_function(tolua_S,"ValueName",tolua_AllToLua_cIniFile_ValueName00); - tolua_function(tolua_S,"GetValueName",tolua_AllToLua_cIniFile_GetValueName00); - tolua_function(tolua_S,"ValueName",tolua_AllToLua_cIniFile_ValueName01); - tolua_function(tolua_S,"GetValueName",tolua_AllToLua_cIniFile_GetValueName01); - tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue00); - tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue01); - tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue02); - tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue03); - tolua_function(tolua_S,"GetValueF",tolua_AllToLua_cIniFile_GetValueF00); - tolua_function(tolua_S,"GetValueI",tolua_AllToLua_cIniFile_GetValueI00); - tolua_function(tolua_S,"GetValueB",tolua_AllToLua_cIniFile_GetValueB00); - tolua_function(tolua_S,"GetValueSet",tolua_AllToLua_cIniFile_GetValueSet00); - tolua_function(tolua_S,"GetValueSet",tolua_AllToLua_cIniFile_GetValueSet01); - tolua_function(tolua_S,"GetValueSetF",tolua_AllToLua_cIniFile_GetValueSetF00); - tolua_function(tolua_S,"GetValueSetI",tolua_AllToLua_cIniFile_GetValueSetI00); - tolua_function(tolua_S,"GetValueSetB",tolua_AllToLua_cIniFile_GetValueSetB00); - tolua_function(tolua_S,"SetValue",tolua_AllToLua_cIniFile_SetValue00); - tolua_function(tolua_S,"SetValue",tolua_AllToLua_cIniFile_SetValue01); - tolua_function(tolua_S,"SetValueI",tolua_AllToLua_cIniFile_SetValueI00); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cCraftingGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + int a_Width = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Height = ((int) tolua_tonumber(tolua_S,3,0)); + { + cCraftingGrid* tolua_ret = (cCraftingGrid*) Mtolua_new((cCraftingGrid)(a_Width,a_Height)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"cCraftingGrid"); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: new_local of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_new00_local +static int tolua_AllToLua_cCraftingGrid_new00_local(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cCraftingGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + int a_Width = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Height = ((int) tolua_tonumber(tolua_S,3,0)); + { + cCraftingGrid* tolua_ret = (cCraftingGrid*) Mtolua_new((cCraftingGrid)(a_Width,a_Height)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"cCraftingGrid"); + tolua_register_gc(tolua_S,lua_gettop(tolua_S)); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetWidth of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_GetWidth00 +static int tolua_AllToLua_cCraftingGrid_GetWidth00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCraftingGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cCraftingGrid* self = (const cCraftingGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWidth'", NULL); +#endif + { + int tolua_ret = (int) self->GetWidth(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetWidth'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetHeight of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_GetHeight00 +static int tolua_AllToLua_cCraftingGrid_GetHeight00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCraftingGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cCraftingGrid* self = (const cCraftingGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetHeight'", NULL); +#endif + { + int tolua_ret = (int) self->GetHeight(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetHeight'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetItem of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_GetItem00 +static int tolua_AllToLua_cCraftingGrid_GetItem00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCraftingGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cCraftingGrid* self = (const cCraftingGrid*) tolua_tousertype(tolua_S,1,0); + int x = ((int) tolua_tonumber(tolua_S,2,0)); + int y = ((int) tolua_tonumber(tolua_S,3,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetItem'", NULL); +#endif + { + cItem& tolua_ret = (cItem&) self->GetItem(x,y); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cItem"); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetItem'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetItem of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_SetItem00 +static int tolua_AllToLua_cCraftingGrid_SetItem00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnumber(tolua_S,5,0,&tolua_err) || + !tolua_isnumber(tolua_S,6,0,&tolua_err) || + !tolua_isnoobj(tolua_S,7,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingGrid* self = (cCraftingGrid*) tolua_tousertype(tolua_S,1,0); + int x = ((int) tolua_tonumber(tolua_S,2,0)); + int y = ((int) tolua_tonumber(tolua_S,3,0)); + ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,4,0)); + short a_ItemHealth = ((short) tolua_tonumber(tolua_S,5,0)); + int a_ItemCount = ((int) tolua_tonumber(tolua_S,6,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetItem'", NULL); +#endif + { + self->SetItem(x,y,a_ItemType,a_ItemHealth,a_ItemCount); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'SetItem'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetItem of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_SetItem01 +static int tolua_AllToLua_cCraftingGrid_SetItem01(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + (tolua_isvaluenil(tolua_S,4,&tolua_err) || !tolua_isusertype(tolua_S,4,"const cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else + { + cCraftingGrid* self = (cCraftingGrid*) tolua_tousertype(tolua_S,1,0); + int x = ((int) tolua_tonumber(tolua_S,2,0)); + int y = ((int) tolua_tonumber(tolua_S,3,0)); + const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,4,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetItem'", NULL); +#endif + { + self->SetItem(x,y,*a_Item); + } + } + return 0; +tolua_lerror: + return tolua_AllToLua_cCraftingGrid_SetItem00(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: Clear of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_Clear00 +static int tolua_AllToLua_cCraftingGrid_Clear00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingGrid* self = (cCraftingGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Clear'", NULL); +#endif + { + self->Clear(); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'Clear'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: ConsumeGrid of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_ConsumeGrid00 +static int tolua_AllToLua_cCraftingGrid_ConsumeGrid00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingGrid",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cCraftingGrid",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingGrid* self = (cCraftingGrid*) tolua_tousertype(tolua_S,1,0); + const cCraftingGrid* a_Grid = ((const cCraftingGrid*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ConsumeGrid'", NULL); +#endif + { + self->ConsumeGrid(*a_Grid); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'ConsumeGrid'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: Dump of class cCraftingGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_Dump00 +static int tolua_AllToLua_cCraftingGrid_Dump00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingGrid* self = (cCraftingGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Dump'", NULL); +#endif + { + self->Dump(); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'Dump'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: Clear of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_Clear00 +static int tolua_AllToLua_cCraftingRecipe_Clear00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingRecipe",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingRecipe* self = (cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Clear'", NULL); +#endif + { + self->Clear(); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'Clear'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetIngredientsWidth of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_GetIngredientsWidth00 +static int tolua_AllToLua_cCraftingRecipe_GetIngredientsWidth00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCraftingRecipe",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cCraftingRecipe* self = (const cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetIngredientsWidth'", NULL); +#endif + { + int tolua_ret = (int) self->GetIngredientsWidth(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetIngredientsWidth'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetIngredientsHeight of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_GetIngredientsHeight00 +static int tolua_AllToLua_cCraftingRecipe_GetIngredientsHeight00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCraftingRecipe",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cCraftingRecipe* self = (const cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetIngredientsHeight'", NULL); +#endif + { + int tolua_ret = (int) self->GetIngredientsHeight(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetIngredientsHeight'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetIngredient of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_GetIngredient00 +static int tolua_AllToLua_cCraftingRecipe_GetIngredient00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCraftingRecipe",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cCraftingRecipe* self = (const cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); + int x = ((int) tolua_tonumber(tolua_S,2,0)); + int y = ((int) tolua_tonumber(tolua_S,3,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetIngredient'", NULL); +#endif + { + cItem& tolua_ret = (cItem&) self->GetIngredient(x,y); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cItem"); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetIngredient'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetResult of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_GetResult00 +static int tolua_AllToLua_cCraftingRecipe_GetResult00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCraftingRecipe",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cCraftingRecipe* self = (const cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResult'", NULL); +#endif + { + const cItem& tolua_ret = (const cItem&) self->GetResult(); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"const cItem"); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetResult'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetResult of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_SetResult00 +static int tolua_AllToLua_cCraftingRecipe_SetResult00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingRecipe",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingRecipe* self = (cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); + ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,2,0)); + short a_ItemHealth = ((short) tolua_tonumber(tolua_S,3,0)); + int a_ItemCount = ((int) tolua_tonumber(tolua_S,4,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetResult'", NULL); +#endif + { + self->SetResult(a_ItemType,a_ItemHealth,a_ItemCount); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'SetResult'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetResult of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_SetResult01 +static int tolua_AllToLua_cCraftingRecipe_SetResult01(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingRecipe",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else + { + cCraftingRecipe* self = (cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); + const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetResult'", NULL); +#endif + { + self->SetResult(*a_Item); + } + } + return 0; +tolua_lerror: + return tolua_AllToLua_cCraftingRecipe_SetResult00(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetIngredient of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_SetIngredient00 +static int tolua_AllToLua_cCraftingRecipe_SetIngredient00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingRecipe",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnumber(tolua_S,5,0,&tolua_err) || + !tolua_isnumber(tolua_S,6,0,&tolua_err) || + !tolua_isnoobj(tolua_S,7,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingRecipe* self = (cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); + int x = ((int) tolua_tonumber(tolua_S,2,0)); + int y = ((int) tolua_tonumber(tolua_S,3,0)); + ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,4,0)); + short a_ItemHealth = ((short) tolua_tonumber(tolua_S,5,0)); + int a_ItemCount = ((int) tolua_tonumber(tolua_S,6,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetIngredient'", NULL); +#endif + { + self->SetIngredient(x,y,a_ItemType,a_ItemHealth,a_ItemCount); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'SetIngredient'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetIngredient of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_SetIngredient01 +static int tolua_AllToLua_cCraftingRecipe_SetIngredient01(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingRecipe",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + (tolua_isvaluenil(tolua_S,4,&tolua_err) || !tolua_isusertype(tolua_S,4,"const cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else + { + cCraftingRecipe* self = (cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); + int x = ((int) tolua_tonumber(tolua_S,2,0)); + int y = ((int) tolua_tonumber(tolua_S,3,0)); + const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,4,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetIngredient'", NULL); +#endif + { + self->SetIngredient(x,y,*a_Item); + } + } + return 0; +tolua_lerror: + return tolua_AllToLua_cCraftingRecipe_SetIngredient00(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: ConsumeIngredients of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_ConsumeIngredients00 +static int tolua_AllToLua_cCraftingRecipe_ConsumeIngredients00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingRecipe",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"cCraftingGrid",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingRecipe* self = (cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); + cCraftingGrid* a_CraftingGrid = ((cCraftingGrid*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ConsumeIngredients'", NULL); +#endif + { + self->ConsumeIngredients(*a_CraftingGrid); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'ConsumeIngredients'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: Dump of class cCraftingRecipe */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingRecipe_Dump00 +static int tolua_AllToLua_cCraftingRecipe_Dump00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCraftingRecipe",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCraftingRecipe* self = (cCraftingRecipe*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Dump'", NULL); +#endif + { + self->Dump(); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'Dump'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* Open function */ +TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) +{ + tolua_open(tolua_S); + tolua_reg_types(tolua_S); + tolua_module(tolua_S,NULL,1); + tolua_beginmodule(tolua_S,NULL); + tolua_cclass(tolua_S,"cTorch","cTorch","",NULL); + tolua_beginmodule(tolua_S,"cTorch"); + tolua_function(tolua_S,"DirectionToMetaData",tolua_AllToLua_cTorch_DirectionToMetaData00); + tolua_function(tolua_S,"MetaDataToDirection",tolua_AllToLua_cTorch_MetaDataToDirection00); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"cStairs","cStairs","",NULL); + tolua_beginmodule(tolua_S,"cStairs"); + tolua_function(tolua_S,"RotationToMetaData",tolua_AllToLua_cStairs_RotationToMetaData00); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"cStep","cStep","",NULL); + tolua_beginmodule(tolua_S,"cStep"); + tolua_function(tolua_S,"DirectionToMetaData",tolua_AllToLua_cStep_DirectionToMetaData00); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"cLadder","cLadder","",NULL); + tolua_beginmodule(tolua_S,"cLadder"); + tolua_function(tolua_S,"DirectionToMetaData",tolua_AllToLua_cLadder_DirectionToMetaData00); + tolua_function(tolua_S,"MetaDataToDirection",tolua_AllToLua_cLadder_MetaDataToDirection00); + tolua_endmodule(tolua_S); + #ifdef __cplusplus + tolua_cclass(tolua_S,"cIniFile","cIniFile","",tolua_collect_cIniFile); + #else + tolua_cclass(tolua_S,"cIniFile","cIniFile","",NULL); + #endif + tolua_beginmodule(tolua_S,"cIniFile"); + tolua_constant(tolua_S,"noID",cIniFile::noID); + tolua_function(tolua_S,"new",tolua_AllToLua_cIniFile_new00); + tolua_function(tolua_S,"new_local",tolua_AllToLua_cIniFile_new00_local); + tolua_function(tolua_S,".call",tolua_AllToLua_cIniFile_new00_local); + tolua_function(tolua_S,"CaseSensitive",tolua_AllToLua_cIniFile_CaseSensitive00); + tolua_function(tolua_S,"CaseInsensitive",tolua_AllToLua_cIniFile_CaseInsensitive00); + tolua_function(tolua_S,"Path",tolua_AllToLua_cIniFile_Path00); + tolua_function(tolua_S,"Path",tolua_AllToLua_cIniFile_Path01); + tolua_function(tolua_S,"SetPath",tolua_AllToLua_cIniFile_SetPath00); + tolua_function(tolua_S,"ReadFile",tolua_AllToLua_cIniFile_ReadFile00); + tolua_function(tolua_S,"WriteFile",tolua_AllToLua_cIniFile_WriteFile00); + tolua_function(tolua_S,"Erase",tolua_AllToLua_cIniFile_Erase00); + tolua_function(tolua_S,"Clear",tolua_AllToLua_cIniFile_Clear00); + tolua_function(tolua_S,"Reset",tolua_AllToLua_cIniFile_Reset00); + tolua_function(tolua_S,"FindKey",tolua_AllToLua_cIniFile_FindKey00); + tolua_function(tolua_S,"FindValue",tolua_AllToLua_cIniFile_FindValue00); + tolua_function(tolua_S,"NumKeys",tolua_AllToLua_cIniFile_NumKeys00); + tolua_function(tolua_S,"GetNumKeys",tolua_AllToLua_cIniFile_GetNumKeys00); + tolua_function(tolua_S,"AddKeyName",tolua_AllToLua_cIniFile_AddKeyName00); + tolua_function(tolua_S,"KeyName",tolua_AllToLua_cIniFile_KeyName00); + tolua_function(tolua_S,"GetKeyName",tolua_AllToLua_cIniFile_GetKeyName00); + tolua_function(tolua_S,"NumValues",tolua_AllToLua_cIniFile_NumValues00); + tolua_function(tolua_S,"GetNumValues",tolua_AllToLua_cIniFile_GetNumValues00); + tolua_function(tolua_S,"NumValues",tolua_AllToLua_cIniFile_NumValues01); + tolua_function(tolua_S,"GetNumValues",tolua_AllToLua_cIniFile_GetNumValues01); + tolua_function(tolua_S,"ValueName",tolua_AllToLua_cIniFile_ValueName00); + tolua_function(tolua_S,"GetValueName",tolua_AllToLua_cIniFile_GetValueName00); + tolua_function(tolua_S,"ValueName",tolua_AllToLua_cIniFile_ValueName01); + tolua_function(tolua_S,"GetValueName",tolua_AllToLua_cIniFile_GetValueName01); + tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue00); + tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue01); + tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue02); + tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue03); + tolua_function(tolua_S,"GetValueF",tolua_AllToLua_cIniFile_GetValueF00); + tolua_function(tolua_S,"GetValueI",tolua_AllToLua_cIniFile_GetValueI00); + tolua_function(tolua_S,"GetValueB",tolua_AllToLua_cIniFile_GetValueB00); + tolua_function(tolua_S,"GetValueSet",tolua_AllToLua_cIniFile_GetValueSet00); + tolua_function(tolua_S,"GetValueSet",tolua_AllToLua_cIniFile_GetValueSet01); + tolua_function(tolua_S,"GetValueSetF",tolua_AllToLua_cIniFile_GetValueSetF00); + tolua_function(tolua_S,"GetValueSetI",tolua_AllToLua_cIniFile_GetValueSetI00); + tolua_function(tolua_S,"GetValueSetB",tolua_AllToLua_cIniFile_GetValueSetB00); + tolua_function(tolua_S,"SetValue",tolua_AllToLua_cIniFile_SetValue00); + tolua_function(tolua_S,"SetValue",tolua_AllToLua_cIniFile_SetValue01); + tolua_function(tolua_S,"SetValueI",tolua_AllToLua_cIniFile_SetValueI00); tolua_function(tolua_S,"SetValueB",tolua_AllToLua_cIniFile_SetValueB00); tolua_function(tolua_S,"SetValueF",tolua_AllToLua_cIniFile_SetValueF00); tolua_function(tolua_S,"DeleteValueByID",tolua_AllToLua_cIniFile_DeleteValueByID00); @@ -18647,10 +19479,15 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"new_local",tolua_AllToLua_cItem_new00_local); tolua_function(tolua_S,".call",tolua_AllToLua_cItem_new00_local); tolua_function(tolua_S,"Empty",tolua_AllToLua_cItem_Empty00); + tolua_function(tolua_S,"Clear",tolua_AllToLua_cItem_Clear00); tolua_function(tolua_S,"IsEmpty",tolua_AllToLua_cItem_IsEmpty00); tolua_function(tolua_S,"Equals",tolua_AllToLua_cItem_Equals00); + tolua_function(tolua_S,"GetMaxDuration",tolua_AllToLua_cItem_GetMaxDuration00); + tolua_function(tolua_S,"DamageItem",tolua_AllToLua_cItem_DamageItem00); + tolua_function(tolua_S,"HasDuration",tolua_AllToLua_cItem_HasDuration00); tolua_function(tolua_S,"GetJson",tolua_AllToLua_cItem_GetJson00); tolua_function(tolua_S,"FromJson",tolua_AllToLua_cItem_FromJson00); + tolua_function(tolua_S,"IsEnchantable",tolua_AllToLua_cItem_IsEnchantable00); tolua_variable(tolua_S,"m_ItemID",tolua_get_cItem_m_ItemID,tolua_set_cItem_m_ItemID); tolua_variable(tolua_S,"m_ItemCount",tolua_get_cItem_m_ItemCount,tolua_set_cItem_m_ItemCount); tolua_variable(tolua_S,"m_ItemHealth",tolua_get_cItem_m_ItemHealth,tolua_set_cItem_m_ItemHealth); @@ -18733,7 +19570,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"GetDefaultWorld",tolua_AllToLua_cRoot_GetDefaultWorld00); tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cRoot_GetWorld00); tolua_function(tolua_S,"GetGroupManager",tolua_AllToLua_cRoot_GetGroupManager00); - tolua_function(tolua_S,"GetRecipeChecker",tolua_AllToLua_cRoot_GetRecipeChecker00); tolua_function(tolua_S,"GetCraftingRecipes",tolua_AllToLua_cRoot_GetCraftingRecipes00); tolua_function(tolua_S,"GetFurnaceRecipe",tolua_AllToLua_cRoot_GetFurnaceRecipe00); tolua_function(tolua_S,"GetWebAdmin",tolua_AllToLua_cRoot_GetWebAdmin00); @@ -18982,6 +19818,38 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"SetBlock",tolua_AllToLua_cLuaChunk_SetBlock00); tolua_function(tolua_S,"FillBlocks",tolua_AllToLua_cLuaChunk_FillBlocks00); tolua_endmodule(tolua_S); + #ifdef __cplusplus + tolua_cclass(tolua_S,"cCraftingGrid","cCraftingGrid","",tolua_collect_cCraftingGrid); + #else + tolua_cclass(tolua_S,"cCraftingGrid","cCraftingGrid","",NULL); + #endif + tolua_beginmodule(tolua_S,"cCraftingGrid"); + tolua_function(tolua_S,"new",tolua_AllToLua_cCraftingGrid_new00); + tolua_function(tolua_S,"new_local",tolua_AllToLua_cCraftingGrid_new00_local); + tolua_function(tolua_S,".call",tolua_AllToLua_cCraftingGrid_new00_local); + tolua_function(tolua_S,"GetWidth",tolua_AllToLua_cCraftingGrid_GetWidth00); + tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cCraftingGrid_GetHeight00); + tolua_function(tolua_S,"GetItem",tolua_AllToLua_cCraftingGrid_GetItem00); + tolua_function(tolua_S,"SetItem",tolua_AllToLua_cCraftingGrid_SetItem00); + tolua_function(tolua_S,"SetItem",tolua_AllToLua_cCraftingGrid_SetItem01); + tolua_function(tolua_S,"Clear",tolua_AllToLua_cCraftingGrid_Clear00); + tolua_function(tolua_S,"ConsumeGrid",tolua_AllToLua_cCraftingGrid_ConsumeGrid00); + tolua_function(tolua_S,"Dump",tolua_AllToLua_cCraftingGrid_Dump00); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"cCraftingRecipe","cCraftingRecipe","",NULL); + tolua_beginmodule(tolua_S,"cCraftingRecipe"); + tolua_function(tolua_S,"Clear",tolua_AllToLua_cCraftingRecipe_Clear00); + tolua_function(tolua_S,"GetIngredientsWidth",tolua_AllToLua_cCraftingRecipe_GetIngredientsWidth00); + tolua_function(tolua_S,"GetIngredientsHeight",tolua_AllToLua_cCraftingRecipe_GetIngredientsHeight00); + tolua_function(tolua_S,"GetIngredient",tolua_AllToLua_cCraftingRecipe_GetIngredient00); + tolua_function(tolua_S,"GetResult",tolua_AllToLua_cCraftingRecipe_GetResult00); + tolua_function(tolua_S,"SetResult",tolua_AllToLua_cCraftingRecipe_SetResult00); + tolua_function(tolua_S,"SetResult",tolua_AllToLua_cCraftingRecipe_SetResult01); + tolua_function(tolua_S,"SetIngredient",tolua_AllToLua_cCraftingRecipe_SetIngredient00); + tolua_function(tolua_S,"SetIngredient",tolua_AllToLua_cCraftingRecipe_SetIngredient01); + tolua_function(tolua_S,"ConsumeIngredients",tolua_AllToLua_cCraftingRecipe_ConsumeIngredients00); + tolua_function(tolua_S,"Dump",tolua_AllToLua_cCraftingRecipe_Dump00); + tolua_endmodule(tolua_S); tolua_endmodule(tolua_S); return 1; } diff --git a/source/Bindings.h b/source/Bindings.h index 436844c7c..f3691a252 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 06/10/12 15:55:56. +** Generated automatically by tolua++-1.0.92 on 06/12/12 21:57:04. */ /* Exported function */ diff --git a/source/CraftingRecipes.cpp b/source/CraftingRecipes.cpp index 37d82965e..5fb705296 100644 --- a/source/CraftingRecipes.cpp +++ b/source/CraftingRecipes.cpp @@ -10,60 +10,287 @@ -cCraftingRecipes::cCraftingRecipes(void) +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCraftingGrid: + +cCraftingGrid::cCraftingGrid(int a_Width, int a_Height) : + m_Width(a_Width), + m_Height(a_Height), + m_Items(new cItem[a_Width * a_Height]) { - LoadRecipes(); } -cCraftingRecipes::~cCraftingRecipes() +cCraftingGrid::cCraftingGrid(cItem * a_Items, int a_Width, int a_Height) : + m_Width(a_Width), + m_Height(a_Height), + m_Items(new cItem[a_Width * a_Height]) { - ClearRecipes(); + for (int i = a_Width * a_Height - 1; i >= 0; i--) + { + m_Items[i] = a_Items[i]; + } } -/// Offers an item resulting from the crafting grid setup. Doesn't modify the grid -cItem cCraftingRecipes::Offer(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight) +cCraftingGrid::cCraftingGrid(const cCraftingGrid & a_Original) : + m_Width(a_Original.m_Width), + m_Height(a_Original.m_Height), + m_Items(new cItem[a_Original.m_Width * a_Original.m_Height]) { - std::auto_ptr Recipe(FindRecipe(a_CraftingGrid, a_GridWidth, a_GridHeight)); - if (Recipe.get() == NULL) + for (int i = m_Width * m_Height - 1; i >= 0; i--) { - return cItem(); + m_Items[i] = a_Original.m_Items[i]; + } +} + + + + + +cCraftingGrid::~cCraftingGrid() +{ + delete[] m_Items; +} + + + + + +cItem & cCraftingGrid::GetItem(int x, int y) const +{ + // Accessible through scripting, must verify parameters: + if ((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height)) + { + LOGERROR("Attempted to get an invalid item from a crafting grid: (%d, %d), grid dimensions: (%d, %d).", + x, y, m_Width, m_Height + ); + return m_Items[0]; + } + return m_Items[x + m_Width * y]; +} + + + + + +void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount) +{ + // Accessible through scripting, must verify parameters: + if ((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height)) + { + LOGERROR("Attempted to set an invalid item in a crafting grid: (%d, %d), grid dimensions: (%d, %d).", + x, y, m_Width, m_Height + ); + return; } - return Recipe->m_Result; + m_Items[x + m_Width * y] = cItem(a_ItemType, a_ItemCount, a_ItemHealth); } -/// Crafts the item resulting from the crafting grid setup. Modifies the grid, returns the crafted item -cItem cCraftingRecipes::Craft(cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight) +void cCraftingGrid::SetItem(int x, int y, const cItem & a_Item) { - std::auto_ptr Recipe(FindRecipe(a_CraftingGrid, a_GridWidth, a_GridHeight)); - if (Recipe.get() == NULL) + // Accessible through scripting, must verify parameters: + if ((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height)) { - return cItem(); + LOGERROR("Attempted to set an invalid item in a crafting grid: (%d, %d), grid dimensions: (%d, %d).", + x, y, m_Width, m_Height + ); + return; } - // Consume the ingredients from the grid: - for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr) + m_Items[x + m_Width * y] = a_Item; +} + + + + + +void cCraftingGrid::Clear(void) +{ + for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++) { - int GridIdx = itr->x + a_GridWidth * itr->y; - a_CraftingGrid[GridIdx].m_ItemCount -= itr->m_Item.m_ItemCount; - if (a_CraftingGrid[GridIdx].m_ItemCount <= 0) + m_Items[x + m_Width * y].Empty(); + } +} + + + + + +void cCraftingGrid::ConsumeGrid(const cCraftingGrid & a_Grid) +{ + if ((a_Grid.m_Width != m_Width) || (a_Grid.m_Height != m_Height)) + { + LOGWARNING("Consuming a grid of different dimensions: (%d, %d) vs (%d, %d)", + a_Grid.m_Width, a_Grid.m_Height, m_Width, m_Height + ); + } + int MinX = std::min(a_Grid.m_Width, m_Width); + int MinY = std::min(a_Grid.m_Height, m_Height); + for (int y = 0; y < MinY; y++) for (int x = 0; x < MinX; x++) + { + int ThatIdx = x + a_Grid.m_Width * y; + if (a_Grid.m_Items[ThatIdx].IsEmpty()) { - a_CraftingGrid[GridIdx].Empty(); + continue; } + int ThisIdx = x + m_Width * y; + if (a_Grid.m_Items[ThatIdx].m_ItemID != m_Items[ThisIdx].m_ItemID) + { + LOGWARNING("Consuming incompatible grids: item at (%d, %d) is %d in grid and %d in ingredients. Item not consumed.", + x, y, m_Items[ThisIdx].m_ItemID, a_Grid.m_Items[ThatIdx].m_ItemID + ); + continue; + } + char NumWantedItems = a_Grid.m_Items[ThatIdx].m_ItemCount; + if (NumWantedItems > m_Items[ThisIdx].m_ItemCount) + { + LOGWARNING("Consuming more items than there actually are in slot (%d, %d), item %d (want %d, have %d). Item zeroed out.", + x, y, m_Items[ThisIdx].m_ItemID, + NumWantedItems, m_Items[ThisIdx].m_ItemCount + ); + NumWantedItems = m_Items[ThisIdx].m_ItemCount; + } + m_Items[ThisIdx].m_ItemCount -= NumWantedItems; + if (m_Items[ThisIdx].m_ItemCount == 0) + { + m_Items[ThisIdx].Clear(); + } + } // for x, for y +} + + + + + +void cCraftingGrid::CopyToItems(cItem * a_Items) const +{ + for (int i = m_Height * m_Width - 1; i >= 0; i--) + { + a_Items[i] = m_Items[i]; + } // for x, for y +} + + + + + +void cCraftingGrid::Dump(void) +{ + for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++) + { + int idx = x + m_Width * y; + LOGD("Slot (%d, %d): Type %d, health %d, count %d", + x, y, m_Items[idx].m_ItemID, m_Items[idx].m_ItemHealth, m_Items[idx].m_ItemCount + ); } - return Recipe->m_Result; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCraftingRecipe: + +cCraftingRecipe::cCraftingRecipe(const cCraftingGrid & a_CraftingGrid) : + m_Ingredients(a_CraftingGrid) +{ +} + + + + + +void cCraftingRecipe::Clear(void) +{ + m_Ingredients.Clear(); + m_Result.Clear(); +} + + + + + +void cCraftingRecipe::SetResult(ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount) +{ + m_Result = cItem(a_ItemType, a_ItemCount, a_ItemHealth); +} + + + + + +void cCraftingRecipe::ConsumeIngredients(cCraftingGrid & a_CraftingGrid) +{ + a_CraftingGrid.ConsumeGrid(m_Ingredients); +} + + + + + +void cCraftingRecipe::Dump(void) +{ + LOGD("Recipe ingredients:"); + m_Ingredients.Dump(); + LOGD("Result: Type %d, health %d, count %d", + m_Result.m_ItemID, m_Result.m_ItemHealth, m_Result.m_ItemCount + ); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCraftingRecipes: + +cCraftingRecipes::cCraftingRecipes(void) +{ + LoadRecipes(); +} + + + + + +cCraftingRecipes::~cCraftingRecipes() +{ + ClearRecipes(); +} + + + + + +void cCraftingRecipes::GetRecipe(const cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe) +{ + // TODO: Allow plugins to intercept recipes, add a pre-craft hook here + std::auto_ptr Recipe(FindRecipe(a_CraftingGrid.GetItems(), a_CraftingGrid.GetWidth(), a_CraftingGrid.GetHeight())); + a_Recipe.Clear(); + if (Recipe.get() == NULL) + { + // TODO: Allow plugins to intercept recipes, add a post-craft hook here + return; + } + for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr) + { + a_Recipe.SetIngredient(itr->x, itr->y, itr->m_Item); + } // for itr + a_Recipe.SetResult(Recipe->m_Result); + // TODO: Allow plugins to intercept recipes, add a post-craft hook here } diff --git a/source/CraftingRecipes.h b/source/CraftingRecipes.h index bf85534b1..3d55a3476 100644 --- a/source/CraftingRecipes.h +++ b/source/CraftingRecipes.h @@ -14,6 +14,90 @@ +class cCraftingGrid // tolua_export +{ // tolua_export +public: + cCraftingGrid(const cCraftingGrid & a_Original); + cCraftingGrid(int a_Width, int a_Height); // tolua_export + cCraftingGrid(cItem * a_Items, int a_Width, int a_Height); + ~cCraftingGrid(); + + // tolua_begin + int GetWidth (void) const {return m_Width; } + int GetHeight(void) const {return m_Height; } + cItem & GetItem (int x, int y) const; + void SetItem (int x, int y, ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount); + void SetItem (int x, int y, const cItem & a_Item); + void Clear (void); + + /// Removes items in a_Grid from m_Items[] (used by cCraftingRecipe::ConsumeIngredients()) + void ConsumeGrid(const cCraftingGrid & a_Grid); + + /// Dumps the entire crafting grid using LOGD() + void Dump(void); + + // tolua_end + + cItem * GetItems(void) const {return m_Items; } + + /// Copies internal contents into the item array specified. Assumes that the array has the same dimensions as self + void CopyToItems(cItem * a_Items) const; + +protected: + + int m_Width; + int m_Height; + cItem * m_Items; +} ; // tolua_export + + + + + +class cCraftingRecipe // tolua_export +{ // tolua_export +public: + cCraftingRecipe(const cCraftingGrid & a_CraftingGrid); + + // tolua_begin + void Clear (void); + int GetIngredientsWidth (void) const {return m_Ingredients.GetWidth(); } + int GetIngredientsHeight(void) const {return m_Ingredients.GetHeight(); } + cItem & GetIngredient (int x, int y) const {return m_Ingredients.GetItem(x, y); } + const cItem & GetResult (void) const {return m_Result; } + void SetResult (ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount); + void SetResult (const cItem & a_Item) + { + m_Result = a_Item; + } + + void SetIngredient (int x, int y, ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount) + { + m_Ingredients.SetItem(x, y, a_ItemType, a_ItemHealth, a_ItemCount); + } + + void SetIngredient (int x, int y, const cItem & a_Item) + { + m_Ingredients.SetItem(x, y, a_Item); + } + + /// Consumes ingredients from the crafting grid specified + void ConsumeIngredients(cCraftingGrid & a_CraftingGrid); + + /// Dumps the entire recipe using LOGD() + void Dump(void); + // tolua_end + +protected: + + cCraftingGrid m_Ingredients; // Adjusted to correspond to the input crafting grid! + cItem m_Result; +} ; // tolua_export + + + + + class cCraftingRecipes { public: @@ -23,11 +107,8 @@ public: cCraftingRecipes(void); ~cCraftingRecipes(); - /// Offers an item resulting from the crafting grid setup. Doesn't modify the grid - cItem Offer(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight); - - /// Crafts the item resulting from the crafting grid setup. Modifies the grid, returns the crafted item - cItem Craft(cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight); + /// Returns the recipe for current crafting grid. Doesn't modify the grid. Clears a_Recipe if no recipe found. + void GetRecipe(const cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe); protected: @@ -38,7 +119,9 @@ protected: } ; typedef std::vector cRecipeSlots; - // A single recipe, stored. Each recipe is normalized right after parsing (NormalizeIngredients()) + /** A single recipe, stored. Each recipe is normalized right after parsing (NormalizeIngredients()) + A normalized recipe starts at (0,0) + */ struct cRecipe { cRecipeSlots m_Ingredients; diff --git a/source/cCraftingWindow.cpp b/source/cCraftingWindow.cpp index 8d499c514..c84121a06 100644 --- a/source/cCraftingWindow.cpp +++ b/source/cCraftingWindow.cpp @@ -3,7 +3,6 @@ #include "cCraftingWindow.h" #include "cItem.h" -#include "cRecipeChecker.h" #include "CraftingRecipes.h" #include "cPlayer.h" #include "cClientHandle.h" @@ -71,34 +70,24 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P if ((a_ClickPacket->m_SlotNum >= 0) && (a_ClickPacket->m_SlotNum < 10)) { - cItem CookedItem; + cCraftingGrid Grid(GetSlots() + 1, 3, 3); + cCraftingRecipe Recipe(Grid); + + cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe); + if ((a_ClickPacket->m_SlotNum == 0) && !bDontCook) { - // Consume the ingredients from the crafting grid: - CookedItem = cRoot::Get()->GetCraftingRecipes()->Craft(GetSlots() + 1, 3, 3); - LOGD("New recipes crafted: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount); - // Upgrade the crafting result from the new crafting grid contents: - CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(GetSlots() + 1, 3, 3); - if (CookedItem.IsEmpty()) - { - // Fallback to the old recipes: - CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( GetSlots()+1, 3, 3, true ); - LOGD("Old recipes crafted: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount ); - } - } - else - { - CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(GetSlots() + 1, 3, 3); - LOGD("New recipes offer: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount ); - if (CookedItem.IsEmpty()) - { - // Fallback to the old recipes - CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( GetSlots()+1, 3, 3 ); - LOGD("Old recipes offer: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount ); - } + // Consume the items from the crafting grid: + Recipe.ConsumeIngredients(Grid); + + // Propagate grid back to m_Slots: + Grid.CopyToItems(GetSlots() + 1); + + // Get the recipe for the new grid contents: + cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe); } - *GetSlot(0) = CookedItem; - LOG("You cooked: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount ); + *GetSlot(0) = Recipe.GetResult(); + LOGD("You cooked: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount ); } SendWholeWindow( a_Player.GetClientHandle() ); a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() ); diff --git a/source/cCreativeInventory.cpp b/source/cCreativeInventory.cpp index f19051c5e..51f4a26ed 100644 --- a/source/cCreativeInventory.cpp +++ b/source/cCreativeInventory.cpp @@ -6,7 +6,6 @@ #include "cClientHandle.h" #include "cWindow.h" #include "cItem.h" -#include "cRecipeChecker.h" #include "cRoot.h" #include diff --git a/source/cInventory.cpp b/source/cInventory.cpp index 93edf2c57..e3c92f307 100644 --- a/source/cInventory.cpp +++ b/source/cInventory.cpp @@ -6,7 +6,6 @@ #include "cClientHandle.h" #include "cWindow.h" #include "cItem.h" -#include "cRecipeChecker.h" #include "cRoot.h" #include @@ -27,6 +26,10 @@ cInventory::~cInventory() CloseWindow(); } + + + + cInventory::cInventory(cPlayer* a_Owner) { m_Owner = a_Owner; @@ -52,6 +55,10 @@ cInventory::cInventory(cPlayer* a_Owner) } } + + + + bool cInventory::AddItem( cItem & a_Item ) { cItem BackupSlots[c_NumSlots]; @@ -84,6 +91,10 @@ bool cInventory::AddItem( cItem & a_Item ) return (a_Item.m_ItemCount == 0); } + + + + // TODO: Right now if you dont have enough items, the items you did have are removed, and the function returns false anyway bool cInventory::RemoveItem( cItem & a_Item ) { @@ -138,13 +149,21 @@ bool cInventory::RemoveItem( cItem & a_Item ) return false; } + + + + void cInventory::Clear() { for(unsigned int i = 0; i < c_NumSlots; i++) m_Slots[i].Empty(); } -cItem* cInventory::GetSlotsForType( int a_Type ) + + + + +cItem * cInventory::GetSlotsForType( int a_Type ) { switch( a_Type ) { @@ -158,19 +177,26 @@ cItem* cInventory::GetSlotsForType( int a_Type ) return 0; } + + + + int cInventory::GetSlotCountForType( int a_Type ) { - switch( a_Type ) + switch (a_Type) { - case -1: - return 36; - case -2: - case -3: - return 4; + case -1: + return 36; + case -2: + case -3: + return 4; } return 0; } - + + + + cItem* cInventory::GetSlot( int a_SlotNum ) { @@ -178,18 +204,33 @@ cItem* cInventory::GetSlot( int a_SlotNum ) return &m_Slots[a_SlotNum]; } + + + + cItem* cInventory::GetFromHotBar( int a_SlotNum ) { - if( a_SlotNum < 0 || a_SlotNum >= 9 ) return 0; + if ((a_SlotNum < 0) || (a_SlotNum >= 9)) + { + return NULL; + } return &m_HotSlots[a_SlotNum]; } + + + + void cInventory::SetEquippedSlot( int a_SlotNum ) { if( a_SlotNum < 0 || a_SlotNum >= 9 ) m_EquippedSlot = 0; else m_EquippedSlot = (short)a_SlotNum; } + + + + cItem & cInventory::GetEquippedItem() { cItem* Item = GetFromHotBar( m_EquippedSlot ); @@ -205,12 +246,20 @@ cItem & cInventory::GetEquippedItem() return *m_EquippedItem; } + + + + void cInventory::SendWholeInventory( cClientHandle* a_Client ) { cPacket_WholeInventory Inventory( this ); a_Client->Send( Inventory ); } + + + + void cInventory::SendSlot( int a_SlotNum ) { cItem* Item = GetSlot( a_SlotNum ); @@ -226,6 +275,10 @@ void cInventory::SendSlot( int a_SlotNum ) } } + + + + bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode /* = 0 */ ) { // Fill already present stacks @@ -273,6 +326,10 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, return true; } + + + + void cInventory::SaveToJson(Json::Value & a_Value) { for(unsigned int i = 0; i < c_NumSlots; i++) @@ -283,6 +340,10 @@ void cInventory::SaveToJson(Json::Value & a_Value) } } + + + + bool cInventory::LoadFromJson(Json::Value & a_Value) { int SlotIdx = 0; @@ -293,3 +354,7 @@ bool cInventory::LoadFromJson(Json::Value & a_Value) } return true; } + + + + diff --git a/source/cItem.h b/source/cItem.h index 4311cc3f0..28eed0d42 100644 --- a/source/cItem.h +++ b/source/cItem.h @@ -12,34 +12,41 @@ namespace Json -class cItem //tolua_export -{ //tolua_export +// tolua_begin +class cItem +{ public: - cItem( ENUM_ITEM_ID a_ItemID = E_ITEM_EMPTY, char a_ItemCount = 0, short a_ItemHealth = 0 ) //tolua_export + cItem( ENUM_ITEM_ID a_ItemID = E_ITEM_EMPTY, char a_ItemCount = 0, short a_ItemHealth = 0 ) : m_ItemID ( a_ItemID ) , m_ItemCount ( a_ItemCount ) , m_ItemHealth ( a_ItemHealth ) - { //tolua_export + { if(!IsValidItem( m_ItemID ) ) m_ItemID = E_ITEM_EMPTY; - } //tolua_export - void Empty() //tolua_export - { //tolua_export + } + void Empty() + { + m_ItemID = E_ITEM_EMPTY; + m_ItemCount = 0; + m_ItemHealth = 0; + } + void Clear(void) + { m_ItemID = E_ITEM_EMPTY; m_ItemCount = 0; m_ItemHealth = 0; - } //tolua_export - bool IsEmpty(void) const //tolua_export - { //tolua_export + } + bool IsEmpty(void) const + { return (m_ItemID <= 0 || m_ItemCount <= 0); - } //tolua_export - bool Equals( cItem & a_Item ) const //tolua_export - { //tolua_export + } + bool Equals( cItem & a_Item ) const + { return ( (m_ItemID == a_Item.m_ItemID) && (m_ItemHealth == a_Item.m_ItemHealth) ); - } //tolua_export + } - //TODO Sorry for writing the functions in the header. But somehow it doesn´t worked when I put them into the cpp File :s + // TODO Sorry for writing the functions in the header. But somehow it doesn´t worked when I put them into the cpp File :s - inline int GetMaxDuration() + inline int GetMaxDuration(void) const { switch(m_ItemID) { @@ -74,31 +81,31 @@ public: } } - //Damages a weapon. Returns true when destroyed - inline bool DamageItem() { - if(HasDuration()) + // Damages a weapon / tool. Returns true when destroyed + inline bool DamageItem() + { + if (HasDuration()) { m_ItemHealth++; - if(m_ItemHealth >= GetMaxDuration()) return true; - } return false; } inline bool HasDuration() { return GetMaxDuration() > 0; } - void GetJson( Json::Value & a_OutValue ) const; //tolua_export - void FromJson( const Json::Value & a_Value ); //tolua_export + void GetJson( Json::Value & a_OutValue ) const; + void FromJson( const Json::Value & a_Value ); static bool IsEnchantable(ENUM_ITEM_ID item); - ENUM_ITEM_ID m_ItemID; //tolua_export - char m_ItemCount; //tolua_export - short m_ItemHealth; //tolua_export + ENUM_ITEM_ID m_ItemID; + char m_ItemCount; + short m_ItemHealth; -}; //tolua_export +}; +// tolua_end typedef std::vector cItems; diff --git a/source/cRecipeChecker.cpp b/source/cRecipeChecker.cpp deleted file mode 100644 index 2052ba97d..000000000 --- a/source/cRecipeChecker.cpp +++ /dev/null @@ -1,467 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cRecipeChecker.h" - -#include -#include - -#ifndef _WIN32 - #include -#endif - -#include "Defines.h" -#include "cRoot.h" - - - - - -typedef std::list< cRecipeChecker::Recipe* > RecipeList; - -struct cRecipeChecker::sRecipeCheckerState -{ - RecipeList Recipes; -}; - - - - - -cRecipeChecker* cRecipeChecker::GetRecipeChecker() -{ - LOGWARN("WARNING: Using deprecated function cRecipeChecker::GetRecipeChecker() use cRoot::Get()->GetRecipeChecker() instead!"); - return cRoot::Get()->GetRecipeChecker(); -} - - - - - -cRecipeChecker::Recipe::~Recipe() -{ - delete [] Slots; - Slots = 0; -} - - - - - -cRecipeChecker::~cRecipeChecker() -{ - ClearRecipes(); - delete m_pState; -} - - - - - -cRecipeChecker::cRecipeChecker() - : m_pState( new sRecipeCheckerState ) -{ - ReloadRecipes(); -} - - - - - -void cRecipeChecker::ClearRecipes() -{ - while( m_pState->Recipes.size() > 0 ) - { - delete *m_pState->Recipes.begin(); - m_pState->Recipes.remove( *m_pState->Recipes.begin() ); - } -} - - - - - -void PrintRecipe( std::vector< cRecipeChecker::RecipeSlot > & RecipeSlots ) -{ - LOG("Recipe:"); - for(unsigned int i = 0; i < RecipeSlots.size(); i++) - { - cRecipeChecker::RecipeSlot Slot = RecipeSlots[i]; - LOG("x:%i y:%i id:%i #%i", Slot.x, Slot.y, Slot.Item.m_ItemID, Slot.Item.m_ItemCount ); - } -} - - - - - -void PrintNear( std::ifstream & f, int a_History = 64 ) -{ - f.clear(); - - // Calculate how far we can move pointer back - std::streamoff Position = f.tellg(); - f.seekg( 0, std::ios_base::beg ); - std::streamoff Difference = Position - f.tellg(); - if( Difference > a_History ) Difference = a_History; - f.seekg( Position - Difference, std::ios_base::beg ); - - std::string Near; - if( f.good() ) - { - while( f.good() && Near.size() < (unsigned int)Difference ) - { - char c; - f.get(c); - Near.push_back( c ); - } - } - LOGERROR("Error near: \"%s\"", Near.c_str() ); -} - - - - - -void cRecipeChecker::ReloadRecipes() -{ - LOG("-- Loading recipes from recipes.txt --"); - ClearRecipes(); - - std::ifstream f; - - char a_File[] = "recipes.txt"; - f.open(a_File, std::ios::in); - std::string input; - - if( !f.good() ) - { - f.close(); - LOG("Could not open file for recipes: %s", a_File); - return; - } - - std::vector< RecipeSlot > RecipeSlots; - - bool bError = false; - while( f.good() ) - { - bool bLoadSlot = false; - bool bLoadResult = false; - - char c; - f >> c; - f.unget(); - if( c == '#' ) - { - //LOG("Ignoring comment"); - while( f.good() && c != '\n' ) - { - f.get( c ); - } - continue; - } - - f.get( c ); - while( f.good() && ( c == '\n' || c == '\r' ) ) { f.get( c ); } - if( f.eof() ) break; - f.unget(); - - int width, height; - f >> width; - f >> c; if( c != 'x' ) { bError=true; break; } - f >> height; - f >> c; - if( c == ',' ) bLoadSlot = true; - - while( f.good() && bLoadSlot ) - { - bool bDontAddRecipe = false; - int x, y, ItemID, Amount; - if( f.peek() == '*' ) - { - f >> c; - x = -1; - } - else - { - f >> x; - } - f >> c; if( c != ':' ) { bError=true; break; } - if( f.peek() == '*' ) - { - f >> c; - y = -1; - } - else - { - f >> y; - } - f >> c; if( c != ':' ) { bError=true; break; } - f >> ItemID; - f >> c; if( c != ':' ) { bError=true; break; } - f >> Amount; - - f >> c; - if( c == '@' ) bLoadResult = true; - if( c != ',' ) bLoadSlot = false; - - if( !IsValidItem( ItemID ) ) - { - LOGERROR("Error in recipes file (%s): Invalid Item ID %i", a_File, ItemID ); - bDontAddRecipe = true; - } - if( x < 0 && y < 0 ) - { - if( Amount < 0 ) - { - LOGERROR("Error in recipes file (%s): Invalid use of negative amount on wildcard coordinates", a_File ); - bDontAddRecipe = true; - } - for(int x = 0; x < width; ++x) for(int y = 0; y < height; ++y ) - { - cItem Item( (ENUM_ITEM_ID)ItemID, (char)Amount ); - RecipeSlot Slot; - Slot.Item = Item; - Slot.x = x; - Slot.y = y; - RecipeSlots.push_back( Slot ); - } - } - else if( x < 0 ) - { - if( Amount < 0 ) - { - for(int x = 0; x < width; ++x) for(int yy = 0; yy < height; ++yy ) - { - if( yy == y-1 ) continue; - cItem Item( (ENUM_ITEM_ID)ItemID, (char)abs(Amount) ); - RecipeSlot Slot; - Slot.Item = Item; - Slot.x = x; - Slot.y = yy; - RecipeSlots.push_back( Slot ); - } - } - else - { - for(int x = 0; x < width; ++x) - { - cItem Item( (ENUM_ITEM_ID)ItemID, (char)Amount ); - RecipeSlot Slot; - Slot.Item = Item; - Slot.x = x; - Slot.y = y-1; - RecipeSlots.push_back( Slot ); - } - } - } - else if( y < 0 ) - { - if( Amount < 0 ) - { - for(int xx = 0; xx < width; ++xx) for(int y = 0; y < height; ++y ) - { - if( xx == x-1 ) continue; - cItem Item( (ENUM_ITEM_ID)ItemID, (char)abs(Amount) ); - RecipeSlot Slot; - Slot.Item = Item; - Slot.x = xx; - Slot.y = y; - RecipeSlots.push_back( Slot ); - } - } - else - { - for(int y = 0; y < height; ++y) - { - cItem Item( (ENUM_ITEM_ID)ItemID, (char)Amount ); - RecipeSlot Slot; - Slot.Item = Item; - Slot.x = x-1; - Slot.y = y; - RecipeSlots.push_back( Slot ); - } - } - } - else - { - if( Amount < 0 ) - { - for(int xx = 0; xx < width; ++xx) for(int yy = 0; yy < height; ++yy ) - { - if( xx == x-1 && yy == y-1 ) continue; - cItem Item( (ENUM_ITEM_ID)ItemID, (char)abs(Amount) ); - RecipeSlot Slot; - Slot.Item = Item; - Slot.x = xx; - Slot.y = yy; - RecipeSlots.push_back( Slot ); - } - } - else - { - cItem Item( (ENUM_ITEM_ID)ItemID, (char)Amount ); - RecipeSlot Slot; - Slot.Item = Item; - Slot.x = x-1; - Slot.y = y-1; - RecipeSlots.push_back( Slot ); - } - } - //LOG("%i %i %i %i", x, y, ItemID, Amount ); - - if( bLoadResult ) - { - bLoadResult = false; - f >> ItemID; - f >> c; if( c != ':' ) { bError=true; break; } - f >> Amount; - //LOG("%i %i", ItemID, Amount ); - if( !IsValidItem( ItemID ) ) - { - LOGERROR("Error in recipes file (%s): Invalid Item ID %i", a_File, ItemID ); - bDontAddRecipe = true; - } - - // Do a sanity check - Handshake algorithm :) - bool bDuplicateEntries = false; - for(unsigned int i = 0; i < RecipeSlots.size(); i++) - { - for(unsigned int j = i+1; j < RecipeSlots.size(); j++) - { - if( RecipeSlots[i].x == RecipeSlots[j].x && RecipeSlots[i].y == RecipeSlots[j].y ) - { - LOGERROR("Error in recipes file (%s): Duplicate item on coordinates %i:%i", a_File, RecipeSlots[i].x+1, RecipeSlots[i].y+1 ); - bDontAddRecipe = true; - bDuplicateEntries = true; - break; - } - } - } - if( bDuplicateEntries ) - { - PrintNear( f, 64 ); - PrintRecipe( RecipeSlots ); - } - - if( bDontAddRecipe == false ) - { - cItem Item( (ENUM_ITEM_ID)ItemID, (char)Amount ); - Recipe* recipe = new Recipe; - recipe->Result = Item; - recipe->NumItems = RecipeSlots.size(); - recipe->Slots = new RecipeSlot[ recipe->NumItems ]; - memcpy( recipe->Slots, &RecipeSlots[0], sizeof(RecipeSlot)*recipe->NumItems ); - m_pState->Recipes.push_back( recipe ); - //LOG("Loaded recipe for %i times %i", Amount, ItemID ); - } - - RecipeSlots.clear(); - } - } - if( bError ) break; - } - if( bError || ( !f.eof() && !f.good() ) ) - { - LOGERROR("Error: Wrong format"); - PrintNear( f, 128 ); - } - f.close(); - - LOG("-- Done loading recipes, found %i recipes --", m_pState->Recipes.size() ); -} - - - - - -cItem cRecipeChecker::CookIngredients( cItem* a_Items, int a_Width, int a_Height, bool a_bConsumeIngredients /* = false */ ) -{ - int iLeft = 999, iTop = 999; - int iRight = 0, iBottom = 0; - for(int y = 0; y < a_Height; y++ ) for(int x = 0; x < a_Width; x++) - { - cItem Item = a_Items[x + y*a_Width]; - if( Item.m_ItemID != E_ITEM_EMPTY && Item.m_ItemCount > 0 ) - { - iRight = MAX(x, iRight); - iBottom = MAX(y, iBottom); - iLeft = MIN(x, iLeft); - iTop = MIN(y, iTop); - } - } - - for(RecipeList::iterator itr = m_pState->Recipes.begin(); itr != m_pState->Recipes.end(); ++itr ) - { - Recipe* recipe = (*itr); - int Left = 999, Top = 999; - int Right = 0, Bottom = 0; - for(unsigned int i = 0; i < recipe->NumItems; i++) - { - Right = MAX(recipe->Slots[i].x, Right); - Bottom = MAX(recipe->Slots[i].y, Bottom); - Left = MIN(recipe->Slots[i].x, Left); - Top = MIN(recipe->Slots[i].y, Top); - } - if( Right-Left != iRight-iLeft || Bottom-Top != iBottom-iTop ) continue; - // it has the right dimensions - - // Check for empty spaces - unsigned int Hash = 0; - for(unsigned int i = 0; i < recipe->NumItems; i++) - { - int x = recipe->Slots[i].x - Left + iLeft +1; - int y = recipe->Slots[i].y - Top + iTop +1; - Hash += x + y * a_Width; - } - for(int y = 0; y < a_Height; y++ ) for(int x = 0; x < a_Width; x++) - { - cItem & Item = a_Items[x + y*a_Width]; - if( Item.m_ItemID != E_ITEM_EMPTY && Item.m_ItemCount > 0 ) - { - Hash -= (x+1) + (y+1)*a_Width; - } - } - if( Hash != 0 ) continue; // Empty spaces not in right place - - bool bWrong = false; - for(unsigned int i = 0; i < recipe->NumItems; i++) - { - int x = recipe->Slots[i].x - Left + iLeft; - int y = recipe->Slots[i].y - Top + iTop; - cItem Item = a_Items[x + y*a_Width]; - if( Item.m_ItemID != recipe->Slots[i].Item.m_ItemID - || Item.m_ItemCount < recipe->Slots[i].Item.m_ItemCount ) - { - bWrong = true; - break; - } - } - if( bWrong ) continue; - - cItem Dish = recipe->Result; - - // else - if( a_bConsumeIngredients ) - { - // Consume! nomnom~ - for(unsigned int i = 0; i < recipe->NumItems; i++) - { - int x = recipe->Slots[i].x - Left + iLeft; - int y = recipe->Slots[i].y - Top + iTop; - a_Items[x + y*a_Width].m_ItemCount -= recipe->Slots[i].Item.m_ItemCount; - if( a_Items[x + y*a_Width].m_ItemCount <= 0 ) a_Items[x + y*a_Width].Empty(); - } - Dish = CookIngredients( a_Items, a_Width, a_Height, false ); - } - - // Return the resulting dish! - return Dish; - } - return cItem(); -} - - - - diff --git a/source/cRecipeChecker.h b/source/cRecipeChecker.h deleted file mode 100644 index 91084b7de..000000000 --- a/source/cRecipeChecker.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "cItem.h" - -class cRecipeChecker -{ -public: - static cRecipeChecker * GetRecipeChecker(); - - // Grid of cItems of a_Width width and a_Height Height - cItem CookIngredients( cItem* a_Items, int a_Width, int a_Height, bool a_bConsumeIngredients = false ); - - struct RecipeSlot - { - cItem Item; - int x, y; - }; - - struct Recipe - { - Recipe() : Slots( 0 ), NumItems( 0 ) {} - ~Recipe(); - RecipeSlot* Slots; // Array of RecipeSlots - unsigned int NumItems; - cItem Result; - }; - - void ReloadRecipes(); - static void DeleteMe(); -private: - friend class cRoot; - cRecipeChecker(); - ~cRecipeChecker(); - - struct sRecipeCheckerState; - sRecipeCheckerState* m_pState; - - void ClearRecipes(); -}; \ No newline at end of file diff --git a/source/cRoot.cpp b/source/cRoot.cpp index 41a1a2432..59f0e47f4 100644 --- a/source/cRoot.cpp +++ b/source/cRoot.cpp @@ -7,7 +7,6 @@ #include "cWebAdmin.h" #include "cFurnaceRecipe.h" #include "cGroupManager.h" -#include "cRecipeChecker.h" #include "CraftingRecipes.h" #include "cPluginManager.h" #include "cMonsterConfig.h" @@ -41,7 +40,6 @@ cRoot::cRoot() : m_Server( 0 ) , m_MonsterConfig( 0 ) , m_GroupManager( 0 ) - , m_RecipeChecker(NULL) , m_CraftingRecipes(NULL) , m_FurnaceRecipe( 0 ) , m_WebAdmin( 0 ) @@ -125,7 +123,6 @@ void cRoot::Start() LOG("Loading settings..."); m_GroupManager = new cGroupManager(); - m_RecipeChecker = new cRecipeChecker(); m_CraftingRecipes = new cCraftingRecipes; m_FurnaceRecipe = new cFurnaceRecipe(); @@ -175,7 +172,6 @@ void cRoot::Start() delete m_WebAdmin; m_WebAdmin = 0; LOG("Unloading recipes..."); delete m_FurnaceRecipe; m_FurnaceRecipe = NULL; - delete m_RecipeChecker; m_RecipeChecker = NULL; delete m_CraftingRecipes; m_CraftingRecipes = NULL; LOG("Forgetting groups..."); delete m_GroupManager; m_GroupManager = 0; diff --git a/source/cRoot.h b/source/cRoot.h index 95edfe73a..7b0a7ea18 100644 --- a/source/cRoot.h +++ b/source/cRoot.h @@ -13,7 +13,6 @@ class cThread; class cMonsterConfig; class cGroupManager; -class cRecipeChecker; class cCraftingRecipes; class cFurnaceRecipe; class cWebAdmin; @@ -48,7 +47,6 @@ public: cMonsterConfig * GetMonsterConfig() { return m_MonsterConfig; } cGroupManager * GetGroupManager (void) { return m_GroupManager; } // tolua_export - cRecipeChecker * GetRecipeChecker (void) { return m_RecipeChecker; } // tolua_export cCraftingRecipes * GetCraftingRecipes(void) { return m_CraftingRecipes; } // tolua_export cFurnaceRecipe * GetFurnaceRecipe (void) { return m_FurnaceRecipe; } // tolua_export cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export @@ -86,7 +84,6 @@ private: cMonsterConfig * m_MonsterConfig; cGroupManager * m_GroupManager; - cRecipeChecker * m_RecipeChecker; cCraftingRecipes * m_CraftingRecipes; cFurnaceRecipe * m_FurnaceRecipe; cWebAdmin * m_WebAdmin; diff --git a/source/cServer.cpp b/source/cServer.cpp index 8f8d28e7b..c0b38c88b 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -18,7 +18,6 @@ #include "cPlayer.h" #include "cInventory.h" #include "cItem.h" -#include "cRecipeChecker.h" #include "cFurnaceRecipe.h" #include "cTracer.h" #include "cWebAdmin.h" diff --git a/source/cSurvivalInventory.cpp b/source/cSurvivalInventory.cpp index a39cc6b59..cd7b96ad8 100644 --- a/source/cSurvivalInventory.cpp +++ b/source/cSurvivalInventory.cpp @@ -6,7 +6,6 @@ #include "cClientHandle.h" #include "cWindow.h" #include "cItem.h" -#include "cRecipeChecker.h" #include "CraftingRecipes.h" #include "cRoot.h" #include "packets/cPacket_WindowClick.h" @@ -72,30 +71,24 @@ void cSurvivalInventory::Clicked( cPacket* a_ClickPacket ) if ((Packet->m_SlotNum >= (short)c_CraftOffset) && (Packet->m_SlotNum < (short)(c_CraftOffset + c_CraftSlots + 1))) { - cItem CookedItem; + cCraftingGrid Grid(m_Slots + c_CraftOffset + 1, 2, 2); + cCraftingRecipe Recipe(Grid); + + cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe); + if ((Packet->m_SlotNum == 0) && !bDontCook) { // Consume the items from the crafting grid: - CookedItem = cRoot::Get()->GetCraftingRecipes()->Craft(m_Slots + c_CraftOffset + 1, 2, 2); - // Upgrade the crafting result from the new crafting grid contents: - CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(m_Slots + c_CraftOffset + 1, 2, 2); - if (CookedItem.IsEmpty()) - { - // Fallback to the old recipes: - CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( m_Slots+c_CraftOffset+1, 2, 2, true ); - } - } - else - { - CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(m_Slots + c_CraftOffset + 1, 2, 2); - if (CookedItem.IsEmpty()) - { - // Fallback to the old recipes: - CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( m_Slots+c_CraftOffset+1, 2, 2 ); - } + Recipe.ConsumeIngredients(Grid); + + // Propagate grid back to m_Slots: + Grid.CopyToItems(m_Slots + c_CraftOffset + 1); + + // Get the recipe for the new grid contents: + cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe); } - m_Slots[c_CraftOffset] = CookedItem; - LOG("You cooked: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount ); + m_Slots[c_CraftOffset] = Recipe.GetResult(); + LOGD("You cooked: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount ); SendWholeInventory( m_Owner->GetClientHandle() ); } SendSlot( 0 ); -- cgit v1.2.3