+HitParams getHitParams(const ItemGroupList &armor_groups,
+ const ToolCapabilities *tp, float time_from_last_punch)
+{
+ s16 damage = 0;
+ float full_punch_interval = tp->full_punch_interval;
+
+ for (const auto &damageGroup : tp->damageGroups) {
+ s16 armor = itemgroup_get(armor_groups, damageGroup.first);
+ damage += damageGroup.second
+ * rangelim(time_from_last_punch / full_punch_interval, 0.0, 1.0)
+ * armor / 100.0;
+ }
+
+ return {damage, 0};
+}
+
+HitParams getHitParams(const ItemGroupList &armor_groups,
+ const ToolCapabilities *tp)
+{
+ return getHitParams(armor_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.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;
+}
+
+