From 501b8fe743c56ad07c5fd8bdd4bfffa13fcb3c4d Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 5 Mar 2012 01:30:55 +0200 Subject: Damage groups WIP --- src/tool.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/tool.cpp') diff --git a/src/tool.cpp b/src/tool.cpp index da7ee73dc..d6f994307 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "utility.h" #include "itemdef.h" // For itemgroup_get() #include "log.h" +#include "inventory.h" void ToolCapabilities::serialize(std::ostream &os) const { @@ -153,3 +154,36 @@ HitParams getHitParams(const ItemGroupList &groups, return getHitParams(groups, tp, 1000000); } +PunchDamageResult getPunchDamage( + const ItemGroupList &armor_groups, + const ToolCapabilities *toolcap, + const ItemStack *punchitem, + float time_from_last_punch +){ + bool do_hit = true; + { + if(do_hit && punchitem){ + if(itemgroup_get(armor_groups, "punch_operable") && + (toolcap == NULL || punchitem->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; +} + + -- cgit v1.2.3