From 562ac3bce9fae076562bd2e92e7d330c296ac1b0 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 28 Feb 2012 19:45:23 +0200 Subject: Digging time groups WIP --- src/tool.cpp | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/tool.cpp (limited to 'src/tool.cpp') diff --git a/src/tool.cpp b/src/tool.cpp new file mode 100644 index 000000000..3c61ad6e7 --- /dev/null +++ b/src/tool.cpp @@ -0,0 +1,153 @@ +/* +Minetest-c55 +Copyright (C) 2011 celeron55, Perttu Ahola + +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 +(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. + +You should have received a copy of the GNU 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" + +void ToolCapabilities::serialize(std::ostream &os) const +{ + writeU8(os, 0); // version + writeF1000(os, full_punch_interval); + writeS16(os, max_drop_level); + writeU32(os, groupcaps.size()); + for(std::map::const_iterator + i = groupcaps.begin(); i != groupcaps.end(); i++){ + const std::string *name = &i->first; + const ToolGroupCap *cap = &i->second; + os<maxwear); + writeF1000(os, cap->maxlevel); + writeU32(os, cap->times.size()); + for(std::map::const_iterator + i = cap->times.begin(); i != cap->times.end(); i++){ + writeS16(os, i->first); + writeF1000(os, i->second); + } + } +} + +void ToolCapabilities::deSerialize(std::istream &is) +{ + int version = readU8(is); + if(version != 0) throw SerializationError( + "unsupported ToolCapabilities version"); + full_punch_interval = readF1000(is); + max_drop_level = readS16(is); + groupcaps.clear(); + u32 groupcaps_size = readU32(is); + for(u32 i=0; i &groups, + const ToolCapabilities *tp, float time_from_last_punch) +{ + //infostream<<"getDigParams"<