diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/scriptapi.cpp | 15 | ||||
-rw-r--r-- | src/tool.cpp | 21 | ||||
-rw-r--r-- | src/tool.h | 6 |
3 files changed, 28 insertions, 14 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 38d681e9b..863e2ba28 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -670,8 +670,19 @@ static ToolCapabilities read_tool_capabilities( // This will be created ToolGroupCap groupcap; // Read simple parameters - getfloatfield(L, table_groupcap, "maxwear", groupcap.maxwear); getintfield(L, table_groupcap, "maxlevel", groupcap.maxlevel); + getintfield(L, table_groupcap, "uses", groupcap.uses); + // DEPRECATED: maxwear + float maxwear = 0; + if(getfloatfield(L, table_groupcap, "maxwear", maxwear)){ + if(maxwear != 0) + groupcap.uses = 1.0/maxwear; + else + groupcap.uses = 0; + infostream<<script_get_backtrace(L)<<std::endl; + infostream<<"WARNING: field \"maxwear\" is deprecated; " + <<"should replace with uses=1/maxwear"<<std::endl; + } // Read "times" table lua_getfield(L, table_groupcap, "times"); if(lua_istable(L, -1)){ @@ -725,8 +736,8 @@ static void set_tool_capabilities(lua_State *L, int table, // Set subtable "times" lua_setfield(L, -2, "times"); // Set simple parameters - setfloatfield(L, -1, "maxwear", groupcap.maxwear); setintfield(L, -1, "maxlevel", groupcap.maxlevel); + setintfield(L, -1, "uses", groupcap.uses); // Insert groupcap table into groupcaps table lua_setfield(L, -2, name.c_str()); } diff --git a/src/tool.cpp b/src/tool.cpp index dcd4fbdf8..2488e0ba2 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., void ToolCapabilities::serialize(std::ostream &os) const { - writeU8(os, 0); // version + writeU8(os, 1); // version writeF1000(os, full_punch_interval); writeS16(os, max_drop_level); writeU32(os, groupcaps.size()); @@ -34,8 +34,8 @@ void ToolCapabilities::serialize(std::ostream &os) const const std::string *name = &i->first; const ToolGroupCap *cap = &i->second; os<<serializeString(*name); - writeF1000(os, cap->maxwear); - writeF1000(os, cap->maxlevel); + writeS16(os, cap->uses); + writeS16(os, cap->maxlevel); writeU32(os, cap->times.size()); for(std::map<int, float>::const_iterator i = cap->times.begin(); i != cap->times.end(); i++){ @@ -48,7 +48,7 @@ void ToolCapabilities::serialize(std::ostream &os) const void ToolCapabilities::deSerialize(std::istream &is) { int version = readU8(is); - if(version != 0) throw SerializationError( + if(version != 1) throw SerializationError( "unsupported ToolCapabilities version"); full_punch_interval = readF1000(is); max_drop_level = readS16(is); @@ -57,8 +57,8 @@ void ToolCapabilities::deSerialize(std::istream &is) for(u32 i=0; i<groupcaps_size; i++){ std::string name = deSerializeString(is); ToolGroupCap cap; - cap.maxwear = readF1000(is); - cap.maxlevel = readF1000(is); + cap.uses = readS16(is); + cap.maxlevel = readS16(is); u32 times_size = readU32(is); for(u32 i=0; i<times_size; i++){ int level = readS16(is); @@ -102,11 +102,14 @@ DigParams getDigParams(const ItemGroupList &groups, float time = 0; bool time_exists = cap.getTime(rating, &time); if(!result_diggable || time < result_time){ - if(cap.maxlevel > level && time_exists){ + if(cap.maxlevel >= level && time_exists){ result_diggable = true; - result_time = time; int leveldiff = cap.maxlevel - level; - result_wear = cap.maxwear / pow(4.0, (double)leveldiff); + result_time = time / MYMAX(1, leveldiff); + if(cap.uses != 0) + result_wear = 1.0 / cap.uses / pow(3.0, (double)leveldiff); + else + result_wear = 0; result_main_group = name; } } diff --git a/src/tool.h b/src/tool.h index a92a77294..32f1962d0 100644 --- a/src/tool.h +++ b/src/tool.h @@ -29,12 +29,12 @@ with this program; if not, write to the Free Software Foundation, Inc., struct ToolGroupCap { std::map<int, float> times; - float maxwear; int maxlevel; + int uses; ToolGroupCap(): - maxwear(0.05), - maxlevel(1) + maxlevel(1), + uses(20) {} bool getTime(int rating, float *time) const |