summaryrefslogtreecommitdiff
path: root/src/content_sao.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-03-05 01:30:55 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-03-10 11:28:13 +0200
commit501b8fe743c56ad07c5fd8bdd4bfffa13fcb3c4d (patch)
tree77400d94bc48a74cb34d6934e4f3d09ef1a49881 /src/content_sao.cpp
parente9cdb938fe44282e09fb88628a6e86e5e7279c69 (diff)
downloadminetest-501b8fe743c56ad07c5fd8bdd4bfffa13fcb3c4d.tar.gz
minetest-501b8fe743c56ad07c5fd8bdd4bfffa13fcb3c4d.tar.bz2
minetest-501b8fe743c56ad07c5fd8bdd4bfffa13fcb3c4d.zip
Damage groups WIP
Diffstat (limited to 'src/content_sao.cpp')
-rw-r--r--src/content_sao.cpp56
1 files changed, 35 insertions, 21 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 5c03c9053..0c105bb0f 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -531,33 +531,47 @@ int LuaEntitySAO::punch(v3f dir,
m_removed = true;
return 0;
}
- lua_State *L = m_env->getLua();
- scriptapi_luaentity_punch(L, m_id, puncher,
- time_from_last_punch, toolcap, dir);
+
+ ItemStack *punchitem = NULL;
+ ItemStack punchitem_static;
+ if(puncher){
+ punchitem_static = puncher->getWieldedItem();
+ punchitem = &punchitem_static;
+ }
- HitParams hitparams = getHitParams(m_armor_groups, toolcap,
+ PunchDamageResult result = getPunchDamage(
+ m_armor_groups,
+ toolcap,
+ punchitem,
time_from_last_punch);
- actionstream<<getDescription()<<" punched by "
- <<puncher->getDescription()<<", damage "<<hitparams.hp
- <<" HP"<<std::endl;
-
- setHP(getHP() - hitparams.hp);
-
+ if(result.did_punch)
{
- std::ostringstream os(std::ios::binary);
- // command
- writeU8(os, LUAENTITY_CMD_PUNCHED);
- // damage
- writeS16(os, hitparams.hp);
- // result_hp
- writeS16(os, getHP());
- // create message and add to list
- ActiveObjectMessage aom(getId(), true, os.str());
- m_messages_out.push_back(aom);
+ actionstream<<getDescription()<<" punched by "
+ <<puncher->getDescription()<<", damage "<<result.damage
+ <<" HP"<<std::endl;
+
+ setHP(getHP() - result.damage);
+
+ {
+ std::ostringstream os(std::ios::binary);
+ // command
+ writeU8(os, LUAENTITY_CMD_PUNCHED);
+ // damage
+ writeS16(os, result.damage);
+ // result_hp
+ writeS16(os, getHP());
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, os.str());
+ m_messages_out.push_back(aom);
+ }
}
- return hitparams.wear;
+ lua_State *L = m_env->getLua();
+ scriptapi_luaentity_punch(L, m_id, puncher,
+ time_from_last_punch, toolcap, dir);
+
+ return result.wear;
}
void LuaEntitySAO::rightClick(ServerActiveObject *clicker)