diff options
author | Hybrid Dog <ovvv@web.de> | 2017-04-10 20:03:53 +0200 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2018-01-03 04:01:15 +0000 |
commit | 345e1041a204ca9d40a25b71ae239ce3275f0755 (patch) | |
tree | bd93d814cac698d5d11bb3867a9999d3c0b963ce /src | |
parent | d7c1f6c92ec612a13850f0aa58c3541c9a1e19c1 (diff) | |
download | minetest-345e1041a204ca9d40a25b71ae239ce3275f0755.tar.gz minetest-345e1041a204ca9d40a25b71ae239ce3275f0755.tar.bz2 minetest-345e1041a204ca9d40a25b71ae239ce3275f0755.zip |
Tool.cpp/.h, lua_api/l_util.cpp: Tidy up code and remove dead code
Diffstat (limited to 'src')
-rw-r--r-- | src/script/lua_api/l_util.cpp | 8 | ||||
-rw-r--r-- | src/tool.cpp | 63 | ||||
-rw-r--r-- | src/tool.h | 3 |
3 files changed, 26 insertions, 48 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 839c4be11..501261dd7 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -158,18 +158,14 @@ int ModApiUtil::l_write_json(lua_State *L) return 1; } -// get_dig_params(groups, tool_capabilities[, time_from_last_punch]) +// get_dig_params(groups, tool_capabilities) int ModApiUtil::l_get_dig_params(lua_State *L) { NO_MAP_LOCK_REQUIRED; ItemGroupList groups; read_groups(L, 1, groups); ToolCapabilities tp = read_tool_capabilities(L, 2); - if(lua_isnoneornil(L, 3)) - push_dig_params(L, getDigParams(groups, &tp)); - else - push_dig_params(L, getDigParams(groups, &tp, - luaL_checknumber(L, 3))); + push_dig_params(L, getDigParams(groups, &tp)); return 1; } diff --git a/src/tool.cpp b/src/tool.cpp index 7128f1915..568f0af54 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -170,16 +170,13 @@ void ToolCapabilities::deserializeJson(std::istream &is) } DigParams getDigParams(const ItemGroupList &groups, - const ToolCapabilities *tp, float time_from_last_punch) + const ToolCapabilities *tp) { - //infostream<<"getDigParams"<<std::endl; - /* Check group dig_immediate */ - switch(itemgroup_get(groups, "dig_immediate")){ + // Group dig_immediate has fixed time and no wear + switch (itemgroup_get(groups, "dig_immediate")) { case 2: - //infostream<<"dig_immediate=2"<<std::endl; return DigParams(true, 0.5, 0, "dig_immediate"); case 3: - //infostream<<"dig_immediate=3"<<std::endl; return DigParams(true, 0, 0, "dig_immediate"); default: break; @@ -192,49 +189,37 @@ DigParams getDigParams(const ItemGroupList &groups, std::string result_main_group; int level = itemgroup_get(groups, "level"); - //infostream<<"level="<<level<<std::endl; for (const auto &groupcap : tp->groupcaps) { - const std::string &name = groupcap.first; - //infostream<<"group="<<name<<std::endl; const ToolGroupCap &cap = groupcap.second; - int rating = itemgroup_get(groups, name); + + int leveldiff = cap.maxlevel - level; + if (leveldiff < 0) + continue; + + const std::string &groupname = groupcap.first; float time = 0; + int rating = itemgroup_get(groups, groupname); bool time_exists = cap.getTime(rating, &time); - int leveldiff = cap.maxlevel - level; - time /= MYMAX(1, leveldiff); - if(!result_diggable || time < result_time){ - if(cap.maxlevel >= level && time_exists){ - result_diggable = true; - result_time = time; - if(cap.uses != 0) - result_wear = 1.0 / cap.uses / pow(3.0, (double)leveldiff); - else - result_wear = 0; - result_main_group = name; - } + if (!time_exists) + continue; + + if (leveldiff > 1) + time /= leveldiff; + if (!result_diggable || time < result_time) { + result_time = time; + result_diggable = true; + if (cap.uses != 0) + result_wear = 1.0 / cap.uses / pow(3.0, leveldiff); + else + result_wear = 0; + result_main_group = groupname; } } - //infostream<<"result_diggable="<<result_diggable<<std::endl; - //infostream<<"result_time="<<result_time<<std::endl; - //infostream<<"result_wear="<<result_wear<<std::endl; - - if(time_from_last_punch < tp->full_punch_interval){ - float f = time_from_last_punch / tp->full_punch_interval; - //infostream<<"f="<<f<<std::endl; - result_time /= f; - result_wear /= f; - } - u16 wear_i = 65535.*result_wear; + u16 wear_i = U16_MAX * result_wear; return DigParams(result_diggable, result_time, wear_i, result_main_group); } -DigParams getDigParams(const ItemGroupList &groups, - const ToolCapabilities *tp) -{ - return getDigParams(groups, tp, 1000000); -} - HitParams getHitParams(const ItemGroupList &armor_groups, const ToolCapabilities *tp, float time_from_last_punch) { diff --git a/src/tool.h b/src/tool.h index f6b196a49..00fae4881 100644 --- a/src/tool.h +++ b/src/tool.h @@ -96,9 +96,6 @@ struct DigParams }; DigParams getDigParams(const ItemGroupList &groups, - const ToolCapabilities *tp, float time_from_last_punch); - -DigParams getDigParams(const ItemGroupList &groups, const ToolCapabilities *tp); struct HitParams |