Tune caves
[oweals/minetest.git] / src / tool.cpp
index da7ee73dc5124fc2d05e810c05eaa1bea57ec34a..dcd4fbdf8b9567dafa2cdf6b6e34c1e613801a5e 100644 (file)
@@ -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
 {
@@ -74,12 +75,12 @@ DigParams getDigParams(const ItemGroupList &groups,
        //infostream<<"getDigParams"<<std::endl;
        /* Check group dig_immediate */
        switch(itemgroup_get(groups, "dig_immediate")){
-       case 1:
-               //infostream<<"dig_immediate=1"<<std::endl;
-               return DigParams(true, 0.0, 0);
        case 2:
                //infostream<<"dig_immediate=2"<<std::endl;
-               return DigParams(true, 1.0, 0);
+               return DigParams(true, 0.5, 0, "dig_immediate");
+       case 3:
+               //infostream<<"dig_immediate=3"<<std::endl;
+               return DigParams(true, 0.0, 0, "dig_immediate");
        default:
                break;
        }
@@ -88,6 +89,7 @@ DigParams getDigParams(const ItemGroupList &groups,
        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="<<level<<std::endl;
@@ -105,6 +107,7 @@ DigParams getDigParams(const ItemGroupList &groups,
                                result_time = time;
                                int leveldiff = cap.maxlevel - level;
                                result_wear = cap.maxwear / pow(4.0, (double)leveldiff);
+                               result_main_group = name;
                        }
                }
        }
@@ -120,7 +123,7 @@ DigParams getDigParams(const ItemGroupList &groups,
        }
 
        u16 wear_i = 65535.*result_wear;
-       return DigParams(result_diggable, result_time, wear_i);
+       return DigParams(result_diggable, result_time, wear_i, result_main_group);
 }
 
 DigParams getDigParams(const ItemGroupList &groups,
@@ -144,7 +147,7 @@ HitParams getHitParams(const ItemGroupList &groups,
        // Wear is the same as for digging a single node
        s16 wear = (float)digprop.wear;
 
-       return HitParams(hp, wear);
+       return HitParams(hp, wear, digprop.main_group);
 }
 
 HitParams getHitParams(const ItemGroupList &groups,
@@ -153,3 +156,37 @@ 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;
+               result.main_group = hitparams.main_group;
+       }
+
+       return result;
+}
+
+