/*
-Minetest-c55
-Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 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.
+GNU Lesser General Public License for more details.
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser 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 "tool.h"
-#include "utility.h"
#include "itemdef.h" // For itemgroup_get()
#include "log.h"
#include "inventory.h"
+#include "util/serialize.h"
+#include "util/numeric.h"
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());
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++){
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);
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);
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;
}
}