X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftool.cpp;h=839b1e387891162ccbd6384959c49ab629440b1d;hb=45e9f8081140bfcf45f83508621a94df8f2bce20;hp=d45556269743d6d878b83e93ec5a27877f94f2bf;hpb=abceeee92f99b84ebb79968269835a4f509bfb90;p=dragonfireclient.git diff --git a/src/tool.cpp b/src/tool.cpp index d45556269..839b1e387 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -1,87 +1,207 @@ /* -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 "irrlichttypes.h" +#include "itemgroup.h" #include "log.h" -#include +#include "inventory.h" +#include "exceptions.h" +#include "util/serialize.h" +#include "util/numeric.h" -class CToolDefManager: public IToolDefManager +void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const { -public: - virtual ~CToolDefManager() - { - for(core::map::Iterator - i = m_tool_definitions.getIterator(); - i.atEnd() == false; i++){ - delete i.getNode()->getValue(); + 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); } } - virtual bool registerTool(std::string toolname, const ToolDefinition &def) - { - infostream<<"registerTool: registering tool \""<::Node *n; - n = m_tool_definitions.find(toolname); - if(n != NULL){ - errorstream<<"registerTool: registering tool \""<::Node *n; - n = m_tool_definitions.find(toolname); - if(n == NULL) - return NULL; - return n->getValue(); + + 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; } - virtual std::string getImagename(const std::string &toolname) - { - ToolDefinition *def = getToolDefinition(toolname); - if(def == NULL) - return ""; - return def->imagename; +} + +DigParams getDigParams(const ItemGroupList &groups, + const ToolCapabilities *tp, float time_from_last_punch) +{ + //infostream<<"getDigParams"<properties; + + // Values to be returned (with a bit of conversion) + bool result_diggable = false; + float result_time = 0.0; + float result_wear = 0.0; + std::string result_main_group; + + int level = itemgroup_get(groups, "level"); + //infostream<<"level="<groupcaps) { + const std::string &name = groupcap.first; + //infostream<<"group="<= level && time_exists){ + result_diggable = true; + int leveldiff = cap.maxlevel - level; + result_time = time / MYMAX(1, leveldiff); + if(cap.uses != 0) + result_wear = 1.0 / cap.uses / pow(3.0, (double)leveldiff); + else + result_wear = 0; + result_main_group = name; + } } - return def->properties; } -private: - // Key is name - core::map m_tool_definitions; -}; + //infostream<<"result_diggable="<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; +} + +