aboutsummaryrefslogtreecommitdiff
path: root/src/content_sao.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/content_sao.h')
-rw-r--r--src/content_sao.h63
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)
+ {}
+};