aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-07-10 15:58:32 -0400
committerkwolekr <kwolekr@minetest.net>2015-07-10 15:58:57 -0400
commit1a1774a1051790ef85b1bd8b047ac45a3676b5d6 (patch)
treeb5e0083230d80960f43c7eed3ea5787e92976ae1 /src
parent8eb272cea38325f963c521ecfa7b927a563f8509 (diff)
downloadminetest-1a1774a1051790ef85b1bd8b047ac45a3676b5d6.tar.gz
minetest-1a1774a1051790ef85b1bd8b047ac45a3676b5d6.tar.bz2
minetest-1a1774a1051790ef85b1bd8b047ac45a3676b5d6.zip
Fix damage flash when damage disabled
Diffstat (limited to 'src')
-rw-r--r--src/network/serverpackethandler.cpp10
-rw-r--r--src/script/lua_api/l_object.cpp12
-rw-r--r--src/server.cpp16
-rw-r--r--src/server.h2
4 files changed, 25 insertions, 15 deletions
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 92dfe1020..5493dfec1 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -1151,7 +1151,7 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
<< std::endl;
playersao->setHP(playersao->getHP() - damage);
- SendPlayerHPOrDie(playersao->getPeerID(), playersao->getHP() == 0);
+ SendPlayerHPOrDie(playersao);
}
}
@@ -1510,14 +1510,12 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
// If the object is a player and its HP changed
if (src_original_hp != pointed_object->getHP() &&
pointed_object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- SendPlayerHPOrDie(((PlayerSAO*)pointed_object)->getPeerID(),
- pointed_object->getHP() == 0);
+ SendPlayerHPOrDie((PlayerSAO *)pointed_object);
}
// If the puncher is a player and its HP changed
- if (dst_origin_hp != playersao->getHP()) {
- SendPlayerHPOrDie(playersao->getPeerID(), playersao->getHP() == 0);
- }
+ if (dst_origin_hp != playersao->getHP())
+ SendPlayerHPOrDie(playersao);
}
} // action == 0
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 4b1cc39fb..e407ef162 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -222,15 +222,13 @@ int ObjectRef::l_punch(lua_State *L)
// If the punched is a player, and its HP changed
if (src_original_hp != co->getHP() &&
co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(),
- co->getHP() == 0);
+ getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co);
}
// If the puncher is a player, and its HP changed
if (dst_origin_hp != puncher->getHP() &&
puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)puncher)->getPeerID(),
- puncher->getHP() == 0);
+ getServer(L)->SendPlayerHPOrDie((PlayerSAO *)puncher);
}
return 0;
}
@@ -265,9 +263,9 @@ int ObjectRef::l_set_hp(lua_State *L)
<<" hp="<<hp<<std::endl;*/
// Do it
co->setHP(hp);
- if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(), co->getHP() == 0);
- }
+ if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
+ getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co);
+
// Return
return 0;
}
diff --git a/src/server.cpp b/src/server.cpp
index 19aaa3e7a..9d70ad7b7 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1108,7 +1108,7 @@ PlayerSAO* Server::StageTwoClientInit(u16 peer_id)
SendInventory(playersao);
// Send HP
- SendPlayerHPOrDie(peer_id, playersao->getHP() == 0);
+ SendPlayerHPOrDie(playersao);
// Send Breath
SendPlayerBreath(peer_id);
@@ -1487,6 +1487,20 @@ void Server::SendMovement(u16 peer_id)
Send(&pkt);
}
+void Server::SendPlayerHPOrDie(PlayerSAO *playersao)
+{
+ if (!g_settings->getBool("enable_damage"))
+ return;
+
+ u16 peer_id = playersao->getPeerID();
+ bool is_alive = playersao->getHP() > 0;
+
+ if (is_alive)
+ SendPlayerHP(peer_id);
+ else
+ DiePlayer(peer_id);
+}
+
void Server::SendHP(u16 peer_id, u8 hp)
{
DSTACK(__FUNCTION_NAME);
diff --git a/src/server.h b/src/server.h
index 877109a77..fbca05f26 100644
--- a/src/server.h
+++ b/src/server.h
@@ -374,7 +374,7 @@ public:
u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch,
std::string* vers_string);
- void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
+ void SendPlayerHPOrDie(PlayerSAO *player);
void SendPlayerBreath(u16 peer_id);
void SendInventory(PlayerSAO* playerSAO);
void SendMovePlayer(u16 peer_id);