From 440e9cdbef19d154f134a85c7e2601f0aff63459 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 29 Mar 2012 13:35:20 +0300 Subject: Rework tool_capabilities a bit (maxwear->uses, scale dig time according to leveldiff) --- src/scriptapi.cpp | 15 +++++++++++++-- src/tool.cpp | 21 ++++++++++++--------- src/tool.h | 6 +++--- 3 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src') 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<first; const ToolGroupCap *cap = &i->second; os<maxwear); - writeF1000(os, cap->maxlevel); + writeS16(os, cap->uses); + writeS16(os, cap->maxlevel); writeU32(os, cap->times.size()); for(std::map::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 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 times; - float maxwear; int maxlevel; + int uses; ToolGroupCap(): - maxwear(0.05), - maxlevel(1) + maxlevel(1), + uses(20) {} bool getTime(int rating, float *time) const -- cgit v1.2.3