summaryrefslogtreecommitdiff
path: root/src/scriptapi_common.cpp
diff options
context:
space:
mode:
authorPilzAdam <pilzadam@minetest.net>2013-03-28 21:40:44 +0100
committerPilzAdam <pilzadam@minetest.net>2013-03-29 20:14:09 +0100
commit7d9329ecfe84733cdefa34eab25ee3d124c94c59 (patch)
treec31fa17924b27fc57e30e5c3fe619d96b75f14d4 /src/scriptapi_common.cpp
parent3640c8c051bc6b72f4af52752b2d48ced274f539 (diff)
downloadminetest-7d9329ecfe84733cdefa34eab25ee3d124c94c59.tar.gz
minetest-7d9329ecfe84733cdefa34eab25ee3d124c94c59.tar.bz2
minetest-7d9329ecfe84733cdefa34eab25ee3d124c94c59.zip
New damage system, add damageGroups to ToolCapabilities, bump protocol version
Diffstat (limited to 'src/scriptapi_common.cpp')
-rw-r--r--src/scriptapi_common.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/scriptapi_common.cpp b/src/scriptapi_common.cpp
index 8ee8d6a84..2d6f6c72b 100644
--- a/src/scriptapi_common.cpp
+++ b/src/scriptapi_common.cpp
@@ -117,6 +117,20 @@ ToolCapabilities read_tool_capabilities(
}
}
lua_pop(L, 1);
+ lua_getfield(L, table, "damage_groups");
+ if(lua_istable(L, -1)){
+ int table_damage_groups = lua_gettop(L);
+ lua_pushnil(L);
+ while(lua_next(L, table_damage_groups) != 0){
+ // key at index -2 and value at index -1
+ std::string groupname = luaL_checkstring(L, -2);
+ u16 value = luaL_checkinteger(L, -1);
+ toolcap.damageGroups[groupname] = value;
+ // removes value, keeps key for next iteration
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
return toolcap;
}
@@ -154,6 +168,16 @@ void set_tool_capabilities(lua_State *L, int table,
}
// Set groupcaps table
lua_setfield(L, -2, "groupcaps");
+ //Create damage_groups table
+ lua_newtable(L);
+ // For each damage group
+ for(std::map<std::string, s16>::const_iterator
+ i = toolcap.damageGroups.begin(); i != toolcap.damageGroups.end(); i++){
+ // Create damage group table
+ lua_pushinteger(L, i->second);
+ lua_setfield(L, -2, i->first.c_str());
+ }
+ lua_setfield(L, -2, "damage_groups");
}
void push_tool_capabilities(lua_State *L,