/* Minetest Copyright (C) 2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify 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 Lesser General Public License for more details. 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 "itemgroup.h" #include "log.h" #include "inventory.h" #include "exceptions.h" #include "util/serialize.h" #include "util/numeric.h" void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const { writeU8(os, 3); // protocol_version >= 36 writeF1000(os, full_punch_interval); writeS16(os, max_drop_level); writeU32(os, groupcaps.size()); for (const auto &groupcap : groupcaps) { const std::string *name = &groupcap.first; const ToolGroupCap *cap = &groupcap.second; os << serializeString(*name); writeS16(os, cap->uses); writeS16(os, cap->maxlevel); writeU32(os, cap->times.size()); for (const auto &time : cap->times) { writeS16(os, time.first); writeF1000(os, time.second); } } writeU32(os, damageGroups.size()); for (const auto &damageGroup : damageGroups) { os << serializeString(damageGroup.first); writeS16(os, damageGroup.second); } } void ToolCapabilities::deSerialize(std::istream &is) { int version = readU8(is); if (version < 3) 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 < groupcaps_size; i++) { std::string name = deSerializeString(is); ToolGroupCap cap; 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 = readF1000(is); cap.times[level] = time; } groupcaps[name] = cap; } u32 damage_groups_size = readU32(is); for (u32 i = 0; i < damage_groups_size; i++) { std::string name = deSerializeString(is); s16 rating = readS16(is); damageGroups[name] = rating; } } DigParams getDigParams(const ItemGroupList &groups, const ToolCapabilities *tp, float time_from_last_punch) { //infostream<<"getDigParams"<name.empty())) do_hit = false; } if (do_hit) { if(itemgroup_get(armor_groups, "immortal")) do_hit = false; } } PunchDamageResult result; if(do_hit) { HitParams hitparams = getHitParams(armor_groups, toolcap, time_from_last_punch); result.did_punch = true; result.wear = hitparams.wear; result.damage = hitparams.hp; } return result; }