X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=inline;f=src%2Ftool.cpp;h=20b71fb316faf8e635dd9ef6fb1b41a5f4d4ee4c;hb=198ed60cabd3066977df5360b7b32a6b895ea744;hp=69141f4e5a4b30be0884d3fc124217e87f2ce901;hpb=0b21618a054fbfa9f4b5e99a5044f2b2dd1d642b;p=minetest.git diff --git a/src/tool.cpp b/src/tool.cpp index 69141f4e5..20b71fb31 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -1,53 +1,66 @@ /* -Minetest-c55 -Copyright (C) 2011 celeron55, Perttu Ahola +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 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 "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) const +void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const { - writeU8(os, 0); // version + if(protocol_version <= 17) + writeU8(os, 1); // version + else + writeU8(os, 2); // 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++){ + for (ToolGCMap::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); + 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++){ + for (UNORDERED_MAP::const_iterator + i = cap->times.begin(); i != cap->times.end(); ++i) { writeS16(os, i->first); writeF1000(os, i->second); } } + if(protocol_version > 17){ + writeU32(os, damageGroups.size()); + for (DamageGroup::const_iterator i = damageGroups.begin(); + i != damageGroups.end(); ++i) { + os<first); + writeS16(os, i->second); + } + } } void ToolCapabilities::deSerialize(std::istream &is) { int version = readU8(is); - if(version != 0) throw SerializationError( + if(version != 1 && version != 2) throw SerializationError( "unsupported ToolCapabilities version"); full_punch_interval = readF1000(is); max_drop_level = readS16(is); @@ -56,8 +69,8 @@ void ToolCapabilities::deSerialize(std::istream &is) for(u32 i=0; i &groups, +DigParams getDigParams(const ItemGroupList &groups, const ToolCapabilities *tp, float time_from_last_punch) { //infostream<<"getDigParams"<name == "")) + 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; +} + +