X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftool.cpp;h=e013d5ea8ad63892b988744dc1855ffcc5982afc;hb=7289d61e99625b46eb2c4d6b90a2a5de42f207e6;hp=2488e0ba2e3015238b6c32193e22b74a69bc3b75;hpb=440e9cdbef19d154f134a85c7e2601f0aff63459;p=minetest.git diff --git a/src/tool.cpp b/src/tool.cpp index 2488e0ba2..e013d5ea8 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -1,31 +1,36 @@ /* -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, 1); // 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()); @@ -43,12 +48,20 @@ void ToolCapabilities::serialize(std::ostream &os) const writeF1000(os, i->second); } } + if(protocol_version > 17){ + writeU32(os, damageGroups.size()); + for(std::map::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 != 1) throw SerializationError( + if(version != 1 && version != 2) throw SerializationError( "unsupported ToolCapabilities version"); full_punch_interval = readF1000(is); max_drop_level = readS16(is); @@ -67,6 +80,15 @@ void ToolCapabilities::deSerialize(std::istream &is) } groupcaps[name] = cap; } + if(version == 2) + { + u32 damage_groups_size = readU32(is); + for(u32 i=0; i tp->full_punch_interval) - time_from_last_punch = tp->full_punch_interval; - // Damage in hp is equivalent to nodes dug in time_from_last_punch - s16 hp = 0; - if(digprop.diggable) - hp = time_from_last_punch / digprop.time; - // Wear is the same as for digging a single node - s16 wear = (float)digprop.wear; - - return HitParams(hp, wear, digprop.main_group); + s16 damage = 0; + float full_punch_interval = tp->full_punch_interval; + + for(std::map::const_iterator + i = tp->damageGroups.begin(); i != tp->damageGroups.end(); i++){ + s16 armor = itemgroup_get(armor_groups, i->first); + damage += i->second * rangelim(time_from_last_punch / full_punch_interval, 0.0, 1.0) + * armor / 100.0; + } + + return HitParams(damage, 0); } -HitParams getHitParams(const ItemGroupList &groups, +HitParams getHitParams(const ItemGroupList &armor_groups, const ToolCapabilities *tp) { - return getHitParams(groups, tp, 1000000); + return getHitParams(armor_groups, tp, 1000000); } PunchDamageResult getPunchDamage( @@ -186,7 +206,6 @@ PunchDamageResult getPunchDamage( result.did_punch = true; result.wear = hitparams.wear; result.damage = hitparams.hp; - result.main_group = hitparams.main_group; } return result;