X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftool.cpp;h=c1e268ff11c9ff4f512a3a865924de90e92bba74;hb=ee2d9d973a0397ce244f05d49083250956578780;hp=4a4f0e4675b45351f7fe9c69cb25eea5fff708f4;hpb=5fc791ac9a15ea6f234ca2d23041c83679255746;p=dragonfireclient.git diff --git a/src/tool.cpp b/src/tool.cpp index 4a4f0e467..c1e268ff1 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -3,91 +3,194 @@ 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 +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 "itemdef.h" // For itemgroup_get() +#include "log.h" +#include "inventory.h" +#include "util/serialize.h" +#include "util/numeric.h" -std::string tool_get_imagename(const std::string &toolname) +void ToolCapabilities::serialize(std::ostream &os) const { - if(toolname == "WPick") - return "tool_woodpick.png"; - else if(toolname == "STPick") - return "tool_stonepick.png"; - else if(toolname == "SteelPick") - return "tool_steelpick.png"; - else if(toolname == "MesePick") - return "tool_mesepick.png"; - else if(toolname == "WShovel") - return "tool_woodshovel.png"; - else if(toolname == "STShovel") - return "tool_stoneshovel.png"; - else if(toolname == "SteelShovel") - return "tool_steelshovel.png"; - else if(toolname == "WAxe") - return "tool_woodaxe.png"; - else if(toolname == "STAxe") - return "tool_stoneaxe.png"; - else if(toolname == "SteelAxe") - return "tool_steelaxe.png"; - else if(toolname == "WSword") - return "tool_woodsword.png"; - else if(toolname == "STSword") - return "tool_stonesword.png"; - else if(toolname == "SteelSword") - return "tool_steelsword.png"; - else - return "cloud.png"; + writeU8(os, 1); // 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<uses); + writeS16(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); + } + } } -ToolDiggingProperties tool_get_digging_properties(const std::string &toolname) +void ToolCapabilities::deSerialize(std::istream &is) { - // weight, crackiness, crumbleness, cuttability - if(toolname == "WPick") - return ToolDiggingProperties(2.0, 0,-1,2,0, 50, 0,0,0,0); - else if(toolname == "STPick") - return ToolDiggingProperties(1.5, 0,-1,2,0, 100, 0,0,0,0); - else if(toolname == "SteelPick") - return ToolDiggingProperties(1.0, 0,-1,2,0, 300, 0,0,0,0); - - else if(toolname == "MesePick") - return ToolDiggingProperties(0, 0,0,0,0, 1337, 0,0,0,0); + int version = readU8(is); + if(version != 1) 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; iname == "")) + 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; + result.main_group = hitparams.main_group; + } + + return result; }