From 9e1c4533b8a67ee8c90f4aa70f6974b25b55640d Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 15 Nov 2011 02:03:28 +0200 Subject: [PATCH] Move tool definitions to script --- data/scripts/default.lua | 199 +++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 - src/content_tool.cpp | 68 ------------- src/content_tool.h | 24 ----- src/game.cpp | 3 - src/scriptapi.cpp | 97 ++++++++++++++++++- src/server.cpp | 13 ++- src/server.h | 3 + 8 files changed, 307 insertions(+), 101 deletions(-) delete mode 100644 src/content_tool.cpp delete mode 100644 src/content_tool.h diff --git a/data/scripts/default.lua b/data/scripts/default.lua index eda7cd25e..d0479d90d 100644 --- a/data/scripts/default.lua +++ b/data/scripts/default.lua @@ -113,6 +113,205 @@ end minetest.register_globalstep(on_step) +minetest.register_tool("WPick", { + image = "tool_woodpick.png", + basetime = 2.0, + dt_weight = 0, + dt_crackiness = -0.5, + dt_crumbliness = 2, + dt_cuttability = 0, + basedurability = 50, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("STPick", { + image = "tool_stonepick.png", + basetime = 1.5, + dt_weight = 0, + dt_crackiness = -0.5, + dt_crumbliness = 2, + dt_cuttability = 0, + basedurability = 100, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("SteelPick", { + image = "tool_steelpick.png", + basetime = 1.0, + dt_weight = 0, + dt_crackiness = -0.5, + dt_crumbliness = 2, + dt_cuttability = 0, + basedurability = 300, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("MesePick", { + image = "tool_mesepick.png", + basetime = 0, + dt_weight = 0, + dt_crackiness = 0, + dt_crumbliness = 0, + dt_cuttability = 0, + basedurability = 1337, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("WShovel", { + image = "tool_woodshovel.png", + basetime = 2.0, + dt_weight = 0.5, + dt_crackiness = 2, + dt_crumbliness = -1.5, + dt_cuttability = 0.3, + basedurability = 50, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("STShovel", { + image = "tool_stoneshovel.png", + basetime = 1.5, + dt_weight = 0.5, + dt_crackiness = 2, + dt_crumbliness = -1.5, + dt_cuttability = 0.1, + basedurability = 100, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("SteelShovel", { + image = "tool_steelshovel.png", + basetime = 1.0, + dt_weight = 0.5, + dt_crackiness = 2, + dt_crumbliness = -1.5, + dt_cuttability = 0.0, + basedurability = 300, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("WAxe", { + image = "tool_woodaxe.png", + basetime = 2.0, + dt_weight = 0.5, + dt_crackiness = -0.2, + dt_crumbliness = 1, + dt_cuttability = -0.5, + basedurability = 50, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("STAxe", { + image = "tool_stoneaxe.png", + basetime = 1.5, + dt_weight = 0.5, + dt_crackiness = -0.2, + dt_crumbliness = 1, + dt_cuttability = -0.5, + basedurability = 100, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("SteelAxe", { + image = "tool_steelaxe.png", + basetime = 1.0, + dt_weight = 0.5, + dt_crackiness = -0.2, + dt_crumbliness = 1, + dt_cuttability = -0.5, + basedurability = 300, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("WSword", { + image = "tool_woodsword.png", + basetime = 3.0, + dt_weight = 3, + dt_crackiness = 0, + dt_crumbliness = 1, + dt_cuttability = -1, + basedurability = 50, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("STSword", { + image = "tool_stonesword.png", + basetime = 2.5, + dt_weight = 3, + dt_crackiness = 0, + dt_crumbliness = 1, + dt_cuttability = -1, + basedurability = 100, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("SteelSword", { + image = "tool_steelsword.png", + basetime = 2.0, + dt_weight = 3, + dt_crackiness = 0, + dt_crumbliness = 1, + dt_cuttability = -1, + basedurability = 300, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) +minetest.register_tool("", { + image = "", + basetime = 0.5, + dt_weight = 1, + dt_crackiness = 0, + dt_crumbliness = -1, + dt_cuttability = 0, + basedurability = 50, + dd_weight = 0, + dd_crackiness = 0, + dd_crumbliness = 0, + dd_cuttability = 0, +}) + +--[[ +minetest.register_tool("horribletool", { + image = "lava.png", + basetime = 2.0 + dt_weight = 0.2 + dt_crackiness = 0.2 + dt_crumbliness = 0.2 + dt_cuttability = 0.2 + basedurability = 50 + dd_weight = -5 + dd_crackiness = -5 + dd_crumbliness = -5 + dd_cuttability = -5 +}) +--]] + local TNT = { -- Maybe handle gravity and collision this way? dunno physical = true, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f6c567c3..85060ac70 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -94,7 +94,6 @@ configure_file( ) set(common_SRCS - content_tool.cpp tooldef.cpp nodedef.cpp luaentity_common.cpp diff --git a/src/content_tool.cpp b/src/content_tool.cpp deleted file mode 100644 index 0cdce8e91..000000000 --- a/src/content_tool.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -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 "content_tool.h" -#include "tooldef.h" - -void content_tool_init(IWritableToolDefManager *mgr) -{ - mgr->registerTool("WPick", - ToolDefinition("tool_woodpick.png", - ToolDiggingProperties(2.0, 0,-0.5,2,0, 50, 0,0,0,0))); - mgr->registerTool("STPick", - ToolDefinition("tool_stonepick.png", - ToolDiggingProperties(1.5, 0,-0.5,2,0, 100, 0,0,0,0))); - mgr->registerTool("SteelPick", - ToolDefinition("tool_steelpick.png", - ToolDiggingProperties(1.0, 0,-0.5,2,0, 300, 0,0,0,0))); - mgr->registerTool("MesePick", - ToolDefinition("tool_mesepick.png", - ToolDiggingProperties(0, 0,0,0,0, 1337, 0,0,0,0))); - mgr->registerTool("WShovel", - ToolDefinition("tool_woodshovel.png", - ToolDiggingProperties(2.0, 0.5,2,-1.5,0.3, 50, 0,0,0,0))); - mgr->registerTool("STShovel", - ToolDefinition("tool_stoneshovel.png", - ToolDiggingProperties(1.5, 0.5,2,-1.5,0.1, 100, 0,0,0,0))); - mgr->registerTool("SteelShovel", - ToolDefinition("tool_steelshovel.png", - ToolDiggingProperties(1.0, 0.5,2,-1.5,0.0, 300, 0,0,0,0))); - mgr->registerTool("WAxe", - ToolDefinition("tool_woodaxe.png", - ToolDiggingProperties(2.0, 0.5,-0.2,1,-0.5, 50, 0,0,0,0))); - mgr->registerTool("STAxe", - ToolDefinition("tool_stoneaxe.png", - ToolDiggingProperties(1.5, 0.5,-0.2,1,-0.5, 100, 0,0,0,0))); - mgr->registerTool("SteelAxe", - ToolDefinition("tool_steelaxe.png", - ToolDiggingProperties(1.0, 0.5,-0.2,1,-0.5, 300, 0,0,0,0))); - mgr->registerTool("WSword", - ToolDefinition("tool_woodsword.png", - ToolDiggingProperties(3.0, 3,0,1,-1, 50, 0,0,0,0))); - mgr->registerTool("STSword", - ToolDefinition("tool_stonesword.png", - ToolDiggingProperties(2.5, 3,0,1,-1, 100, 0,0,0,0))); - mgr->registerTool("SteelSword", - ToolDefinition("tool_steelsword.png", - ToolDiggingProperties(2.0, 3,0,1,-1, 300, 0,0,0,0))); - mgr->registerTool("", - ToolDefinition("tooldef.hand.png", - ToolDiggingProperties(0.5, 1,0,-1,0, 50, 0,0,0,0))); -} - diff --git a/src/content_tool.h b/src/content_tool.h deleted file mode 100644 index c7f14be31..000000000 --- a/src/content_tool.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -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. -*/ - -class IWritableToolDefManager; - -// Add default tools to manager -void content_tool_init(IWritableToolDefManager *mgr); - diff --git a/src/game.cpp b/src/game.cpp index ae45e5146..6c75863c0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -49,7 +49,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "main.h" // For g_settings #include "content_mapnode.h" // For content_mapnode_init #include "tooldef.h" -#include "content_tool.h" // Default tools #include "content_mapnode.h" // Default nodes /* @@ -646,8 +645,6 @@ void the_game( // Fill node feature table with default definitions content_mapnode_init(tsrc, nodedef); - // Set default tool definitions - content_tool_init(tooldef); /* Create server. diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 7b9a89f57..1bfe337ea 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -35,6 +35,7 @@ extern "C" { //#include "luna.h" #include "luaentity_common.h" #include "content_sao.h" // For LuaEntitySAO +#include "tooldef.h" /* TODO: @@ -141,8 +142,8 @@ v3f readFloatPos(lua_State *L, int index) static int l_register_entity(lua_State *L) { const char *name = luaL_checkstring(L, 1); - luaL_checktype(L, 2, LUA_TTABLE); infostream<<"register_entity: "<getWritableToolDefManager(); + + tooldef->clear(); + + return 0; /* number of results */ +} +#endif + +// register_tool(name, {lots of stuff}) +static int l_register_tool(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + infostream<<"register_tool: "<getWritableToolDefManager(); + + int table = 2; + + ToolDefinition def; + + lua_getfield(L, table, "image"); + if(lua_isstring(L, -1)) + def.imagename = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "basetime"); + def.properties.basetime = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dt_weight"); + def.properties.dt_weight = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dt_crackiness"); + def.properties.dt_crackiness = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dt_crumbliness"); + def.properties.dt_crumbliness = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dt_cuttability"); + def.properties.dt_cuttability = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "basedurability"); + def.properties.basedurability = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dd_weight"); + def.properties.dd_weight = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dd_crackiness"); + def.properties.dd_crackiness = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dd_crumbliness"); + def.properties.dd_crumbliness = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dd_cuttability"); + def.properties.dd_cuttability = lua_tonumber(L, -1); + lua_pop(L, 1); + + tooldef->registerTool(name, def); + + return 0; /* number of results */ +} + static const struct luaL_Reg minetest_f [] = { {"register_entity", l_register_entity}, {"register_globalstep", l_register_globalstep}, + //{"deregister_tools", l_deregister_tools}, + {"register_tool", l_register_tool}, {NULL, NULL} }; @@ -581,6 +672,10 @@ void scriptapi_export(lua_State *L, Server *server) assert(lua_checkstack(L, 20)); infostream<<"scriptapi_export"<