diff options
author | Andrew Ward <rw@rubenwardy.com> | 2018-03-28 16:05:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 16:05:18 +0100 |
commit | dfc81983491417c5cd1c99d7db05e421c409379d (patch) | |
tree | 7b0457f0ff86f038cfad1a095d3ab0b6c44f2def /src/content_sao.h | |
parent | 2323842dd3dd336b087ca3cf9756e0680b3a1244 (diff) | |
download | minetest-dfc81983491417c5cd1c99d7db05e421c409379d.tar.gz minetest-dfc81983491417c5cd1c99d7db05e421c409379d.tar.bz2 minetest-dfc81983491417c5cd1c99d7db05e421c409379d.zip |
Add reasons to on_dieplayer and on_hpchange
Diffstat (limited to 'src/content_sao.h')
-rw-r--r-- | src/content_sao.h | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/content_sao.h b/src/content_sao.h index 683a2fb5f..10630014c 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -245,7 +245,7 @@ public: ServerActiveObject *puncher, float time_from_last_punch); void rightClick(ServerActiveObject *clicker) {} - void setHP(s16 hp); + void setHP(s16 hp, const PlayerHPChangeReason &reason); void setHPRaw(s16 hp) { m_hp = hp; } s16 readDamage(); u16 getBreath() const { return m_breath; } @@ -417,3 +417,64 @@ public: bool m_physics_override_new_move = true; bool m_physics_override_sent = false; }; + + +struct PlayerHPChangeReason { + enum Type : u8 { + SET_HP, + PLAYER_PUNCH, + FALL, + NODE_DAMAGE, + DROWNING, + RESPAWN + }; + + Type type = SET_HP; + ServerActiveObject *object; + bool from_mod = false; + int lua_reference = -1; + + bool setTypeFromString(const std::string &typestr) + { + if (typestr == "set_hp") + type = SET_HP; + else if (typestr == "punch") + type = PLAYER_PUNCH; + else if (typestr == "fall") + type = FALL; + else if (typestr == "node_damage") + type = NODE_DAMAGE; + else if (typestr == "drown") + type = DROWNING; + else if (typestr == "respawn") + type = RESPAWN; + else + return false; + + return true; + } + + std::string getTypeAsString() const + { + switch (type) { + case PlayerHPChangeReason::SET_HP: + return "set_hp"; + case PlayerHPChangeReason::PLAYER_PUNCH: + return "punch"; + case PlayerHPChangeReason::FALL: + return "fall"; + case PlayerHPChangeReason::NODE_DAMAGE: + return "node_damage"; + case PlayerHPChangeReason::DROWNING: + return "drown"; + case PlayerHPChangeReason::RESPAWN: + return "respawn"; + default: + return "?"; + } + } + + PlayerHPChangeReason(Type type, ServerActiveObject *object=NULL): + type(type), object(object) + {} +}; |