Consistent HP and damage types (#8167)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Sun, 10 Feb 2019 23:03:26 +0000 (00:03 +0100)
committerParamat <paramat@users.noreply.github.com>
Sun, 10 Feb 2019 23:03:26 +0000 (23:03 +0000)
Remove deprecated HUDs and chat message handling.
Remove unused m_damage variable (compat break).
HP: s32 for setter/calculations, u16 for getter.

25 files changed:
src/client/client.cpp
src/client/client.h
src/client/clientenvironment.cpp
src/client/clientenvironment.h
src/client/content_cao.cpp
src/client/content_cao.h
src/client/hud.cpp
src/content_sao.cpp
src/content_sao.h
src/database/database-files.cpp
src/database/database-postgresql.cpp
src/database/database-sqlite3.cpp
src/genericobject.cpp
src/genericobject.h
src/network/serverpackethandler.cpp
src/object_properties.cpp
src/object_properties.h
src/remoteplayer.cpp
src/script/common/c_content.cpp
src/script/cpp_api/s_entity.cpp
src/script/cpp_api/s_player.cpp
src/script/cpp_api/s_player.h
src/script/lua_api/l_object.cpp
src/server.cpp
src/serverobject.h

index 3ba69333add3354d5b1dfed3b7a51c156e09dcf0..41893fcba787fec962aa7fb3529d6690277826e0 100644 (file)
@@ -437,7 +437,7 @@ void Client::step(float dtime)
                ClientEnvEvent envEvent = m_env.getClientEnvEvent();
 
                if (envEvent.type == CEE_PLAYER_DAMAGE) {
-                       u8 damage = envEvent.player_damage.amount;
+                       u16 damage = envEvent.player_damage.amount;
 
                        if (envEvent.player_damage.send_to_server)
                                sendDamage(damage);
@@ -1213,9 +1213,9 @@ void Client::sendChangePassword(const std::string &oldpassword,
 }
 
 
-void Client::sendDamage(u8 damage)
+void Client::sendDamage(u16 damage)
 {
-       NetworkPacket pkt(TOSERVER_DAMAGE, sizeof(u8));
+       NetworkPacket pkt(TOSERVER_DAMAGE, sizeof(u16));
        pkt << damage;
        Send(&pkt);
 }
@@ -1515,17 +1515,6 @@ void Client::typeChatMessage(const std::wstring &message)
 
        // Send to others
        sendChatMessage(message);
-
-       // Show locally
-       if (message[0] != L'/') {
-               // compatibility code
-               if (m_proto_ver < 29) {
-                       LocalPlayer *player = m_env.getLocalPlayer();
-                       assert(player);
-                       std::wstring name = narrow_to_wide(player->getName());
-                       pushToChatQueue(new ChatMessage(CHATMESSAGE_TYPE_NORMAL, message, name));
-               }
-       }
 }
 
 void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)
index ef700e477c03bbc482af082df511634cd8a20cf7..60735f665300f8c3133b58464bac4d5b4acfdede 100644 (file)
@@ -243,7 +243,7 @@ public:
        void clearOutChatQueue();
        void sendChangePassword(const std::string &oldpassword,
                const std::string &newpassword);
-       void sendDamage(u8 damage);
+       void sendDamage(u16 damage);
        void sendRespawn();
        void sendReady();
 
@@ -342,7 +342,7 @@ public:
        bool mediaReceived()
        { return !m_media_downloader; }
 
-       u8 getProtoVersion()
+       u16 getProtoVersion()
        { return m_proto_ver; }
 
        bool connectedToServer();
@@ -504,7 +504,7 @@ private:
        // and aren't accurate. We simply just don't know, because
        // the server didn't send the version back then.
        // If 0, server init hasn't been received yet.
-       u8 m_proto_ver = 0;
+       u16 m_proto_ver = 0;
 
        u16 m_playeritem = 0;
        bool m_inventory_updated = false;
index 1783e89617ced425c2eea7c4abf903a39d7fa535..a788c93c2b58089472a627ab646f9a4a2a2349e1 100644 (file)
@@ -228,7 +228,7 @@ void ClientEnvironment::step(float dtime)
                float speed = pre_factor * speed_diff.getLength();
                if (speed > tolerance && !player_immortal) {
                        f32 damage_f = (speed - tolerance) / BS * post_factor;
-                       u8 damage = (u8)MYMIN(damage_f + 0.5, 255);
+                       u16 damage = (u16)MYMIN(damage_f + 0.5, U16_MAX);
                        if (damage != 0) {
                                damageLocalPlayer(damage, true);
                                m_client->getEventManager()->put(
@@ -419,7 +419,7 @@ void ClientEnvironment::processActiveObjectMessage(u16 id, const std::string &da
        Callbacks for activeobjects
 */
 
-void ClientEnvironment::damageLocalPlayer(u8 damage, bool handle_hp)
+void ClientEnvironment::damageLocalPlayer(u16 damage, bool handle_hp)
 {
        LocalPlayer *lplayer = getLocalPlayer();
        assert(lplayer);
index d167902d19628a10d66a58267660bb0d837ac857..4fa3f4848f2aab1625be181bf8c191a57b43b1d9 100644 (file)
@@ -53,7 +53,7 @@ struct ClientEnvEvent
                //struct{
                //} none;
                struct{
-                       u8 amount;
+                       u16 amount;
                        bool send_to_server;
                } player_damage;
        };
@@ -115,7 +115,7 @@ public:
                Callbacks for activeobjects
        */
 
-       void damageLocalPlayer(u8 damage, bool handle_hp=true);
+       void damageLocalPlayer(u16 damage, bool handle_hp=true);
 
        /*
                Client likes to call these
index 6112edaffccbcba72648c113d96fedbbdbf04f99..8643b5824b031f3b27e9e45485cab0d2fc3a3b23 100644 (file)
@@ -371,7 +371,7 @@ void GenericCAO::processInitData(const std::string &data)
        m_id = readU16(is);
        m_position = readV3F32(is);
        m_rotation = readV3F32(is);
-       m_hp = readS16(is);
+       m_hp = readU16(is);
        const u8 num_messages = readU8(is);
 
        for (int i = 0; i < num_messages; i++) {
@@ -1508,11 +1508,10 @@ void GenericCAO::processMessage(const std::string &data)
 
                updateAttachments();
        } else if (cmd == GENERIC_CMD_PUNCHED) {
-               /*s16 damage =*/ readS16(is);
-               s16 result_hp = readS16(is);
+               u16 result_hp = readU16(is);
 
                // Use this instead of the send damage to not interfere with prediction
-               s16 damage = m_hp - result_hp;
+               s32 damage = (s32)m_hp - (s32)result_hp;
 
                m_hp = result_hp;
 
index 4627800eeaef06a1cc8f9316b156325276eb3e96..3ce628d30c2104a3c09e245d5f11defa267d1c92 100644 (file)
@@ -88,7 +88,7 @@ private:
        v3f m_velocity;
        v3f m_acceleration;
        v3f m_rotation;
-       s16 m_hp = 1;
+       u16 m_hp = 1;
        SmoothTranslator<v3f> pos_translator;
        SmoothTranslatorWrappedv3f rot_translator;
        // Spritesheet/animation stuff
index fffe85e1df228af470fa6e856071370d6b297c28..1a2287a13bc872fe64948faaebcc6b27929eed60 100644 (file)
@@ -475,25 +475,6 @@ void Hud::drawHotbar(u16 playeritem) {
                                hotbar_itemcount / 2, mainlist, playeritem + 1, 0);
                }
        }
-
-       //////////////////////////// compatibility code to be removed //////////////
-       // this is ugly as hell but there's no other way to keep compatibility to
-       // old servers
-       if ((player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE)) {
-               drawStatbar(v2s32(floor(0.5 * (float)m_screensize.X + 0.5),
-                       floor(1 * (float) m_screensize.Y + 0.5)),
-                       HUD_CORNER_UPPER, 0, "heart.png",
-                       player->hp, v2s32((-10*24)-25,-(48+24+10)), v2s32(24,24));
-       }
-
-       if ((player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE) &&
-                       (player->getBreath() < 11)) {
-               drawStatbar(v2s32(floor(0.5 * (float)m_screensize.X + 0.5),
-                       floor(1 * (float) m_screensize.Y + 0.5)),
-                       HUD_CORNER_UPPER, 0, "bubble.png",
-                       player->getBreath(), v2s32(25,-(48+24+10)), v2s32(24,24));
-       }
-       ////////////////////////////////////////////////////////////////////////////
 }
 
 
index ecacd74529268c54b841a791fd66f7e4667b9d86..e0374d28d15554f49d034ae1ff2e0a08903aa4da 100644 (file)
@@ -347,7 +347,7 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
 {
        std::string name;
        std::string state;
-       s16 hp = 1;
+       u16 hp = 1;
        v3f velocity;
        v3f rotation;
 
@@ -364,7 +364,7 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
                if (version < 1)
                        break;
 
-               hp = readS16(is);
+               hp = readU16(is);
                velocity = readV3F1000(is);
                // yaw must be yaw to be backwards-compatible
                rotation.Y = readF1000(is);
@@ -548,10 +548,10 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
        writeU8(os, 1); // version
        os << serializeString(""); // name
        writeU8(os, 0); // is_player
-       writeS16(os, getId()); //id
+       writeU16(os, getId()); //id
        writeV3F32(os, m_base_position);
        writeV3F32(os, m_rotation);
-       writeS16(os, m_hp);
+       writeU16(os, m_hp);
 
        std::ostringstream msg_os(std::ios::binary);
        msg_os << serializeLongString(getPropertyPacket()); // message 1
@@ -601,7 +601,7 @@ void LuaEntitySAO::getStaticData(std::string *result) const
        } else {
                os<<serializeLongString(m_init_state);
        }
-       writeS16(os, m_hp);
+       writeU16(os, m_hp);
        writeV3F1000(os, m_velocity);
        // yaw
        writeF1000(os, m_rotation.Y);
@@ -646,7 +646,7 @@ int LuaEntitySAO::punch(v3f dir,
 
        if (!damage_handled) {
                if (result.did_punch) {
-                       setHP(getHP() - result.damage,
+                       setHP((s32)getHP() - result.damage,
                                PlayerHPChangeReason(PlayerHPChangeReason::SET_HP));
 
                        if (result.damage > 0) {
@@ -657,7 +657,7 @@ int LuaEntitySAO::punch(v3f dir,
                                                << " hp, health now " << getHP() << " hp" << std::endl;
                        }
 
-                       std::string str = gob_cmd_punched(result.damage, getHP());
+                       std::string str = gob_cmd_punched(getHP());
                        // create message and add to list
                        ActiveObjectMessage aom(getId(), true, str);
                        m_messages_out.push(aom);
@@ -715,14 +715,12 @@ std::string LuaEntitySAO::getDescription()
        return os.str();
 }
 
-void LuaEntitySAO::setHP(s16 hp, const PlayerHPChangeReason &reason)
+void LuaEntitySAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
 {
-       if (hp < 0)
-               hp = 0;
-       m_hp = hp;
+       m_hp = rangelim(hp, 0, U16_MAX);
 }
 
-s16 LuaEntitySAO::getHP() const
+u16 LuaEntitySAO::getHP() const
 {
        return m_hp;
 }
@@ -949,7 +947,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
        writeS16(os, getId()); // id
        writeV3F32(os, m_base_position);
        writeV3F32(os, m_rotation);
-       writeS16(os, getHP());
+       writeU16(os, getHP());
 
        std::ostringstream msg_os(std::ios::binary);
        msg_os << serializeLongString(getPropertyPacket()); // message 1
@@ -1044,7 +1042,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
                        m_env->getGameDef()->ndef()->get(ntop).damage_per_second);
 
                if (damage_per_second != 0 && m_hp > 0) {
-                       s16 newhp = ((s32) damage_per_second > m_hp ? 0 : m_hp - damage_per_second);
+                       s32 newhp = (s32)m_hp - (s32)damage_per_second;
                        PlayerHPChangeReason reason(PlayerHPChangeReason::NODE_DAMAGE);
                        setHP(newhp, reason);
                        m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
@@ -1272,7 +1270,7 @@ int PlayerSAO::punch(v3f dir,
        // No effect if PvP disabled
        if (!g_settings->getBool("enable_pvp")) {
                if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
-                       std::string str = gob_cmd_punched(0, getHP());
+                       std::string str = gob_cmd_punched(getHP());
                        // create message and add to list
                        ActiveObjectMessage aom(getId(), true, str);
                        m_messages_out.push(aom);
@@ -1295,11 +1293,11 @@ int PlayerSAO::punch(v3f dir,
                                hitparams.hp);
 
        if (!damage_handled) {
-               setHP(getHP() - hitparams.hp,
+               setHP((s32)getHP() - (s32)hitparams.hp,
                                PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
        } else { // override client prediction
                if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
-                       std::string str = gob_cmd_punched(0, getHP());
+                       std::string str = gob_cmd_punched(getHP());
                        // create message and add to list
                        ActiveObjectMessage aom(getId(), true, str);
                        m_messages_out.push(aom);
@@ -1319,36 +1317,21 @@ int PlayerSAO::punch(v3f dir,
        return hitparams.wear;
 }
 
-s16 PlayerSAO::readDamage()
-{
-       s16 damage = m_damage;
-       m_damage = 0;
-       return damage;
-}
-
-void PlayerSAO::setHP(s16 hp, const PlayerHPChangeReason &reason)
+void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
 {
-       s16 oldhp = m_hp;
+       s32 oldhp = m_hp;
 
-       s16 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp, reason);
+       s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp, reason);
        if (hp_change == 0)
                return;
-       hp = oldhp + hp_change;
 
-       if (hp < 0)
-               hp = 0;
-       else if (hp > m_prop.hp_max)
-               hp = m_prop.hp_max;
+       hp = rangelim(oldhp + hp_change, 0, m_prop.hp_max);
 
-       if (hp < oldhp && !g_settings->getBool("enable_damage")) {
+       if (hp < oldhp && !g_settings->getBool("enable_damage"))
                return;
-       }
 
        m_hp = hp;
 
-       if (oldhp > hp)
-               m_damage += (oldhp - hp);
-
        // Update properties on death
        if ((hp == 0) != (oldhp == 0))
                m_properties_sent = false;
index 6d2f55b70bf7fee0f2d1c826343e9d99c135b958..14f959e30c51f8f9be62f5278ac0311e18177779 100644 (file)
@@ -39,7 +39,7 @@ public:
        // Deprecated
        f32 getRadYawDep() const { return (m_rotation.Y + 90.) * core::DEGTORAD; }
 
-       s16 getHP() const { return m_hp; }
+       u16 getHP() const { return m_hp; }
        // Use a function, if isDead can be defined by other conditions
        bool isDead() const { return m_hp == 0; }
 
@@ -64,7 +64,7 @@ public:
        ObjectProperties* accessObjectProperties();
        void notifyObjectPropertiesModified();
 protected:
-       s16 m_hp = -1;
+       u16 m_hp = 1;
 
        v3f m_rotation;
 
@@ -127,8 +127,8 @@ public:
        void moveTo(v3f pos, bool continuous);
        float getMinimumSavedMovement();
        std::string getDescription();
-       void setHP(s16 hp, const PlayerHPChangeReason &reason);
-       s16 getHP() const;
+       void setHP(s32 hp, const PlayerHPChangeReason &reason);
+       u16 getHP() const;
        /* LuaEntitySAO-specific */
        void setVelocity(v3f velocity);
        void addVelocity(v3f velocity)
@@ -258,8 +258,8 @@ public:
                ServerActiveObject *puncher,
                float time_from_last_punch);
        void rightClick(ServerActiveObject *clicker) {}
-       void setHP(s16 hp, const PlayerHPChangeReason &reason);
-       void setHPRaw(s16 hp) { m_hp = hp; }
+       void setHP(s32 hp, const PlayerHPChangeReason &reason);
+       void setHPRaw(u16 hp) { m_hp = hp; }
        s16 readDamage();
        u16 getBreath() const { return m_breath; }
        void setBreath(const u16 breath, bool send = true);
@@ -351,7 +351,6 @@ private:
        RemotePlayer *m_player = nullptr;
        session_t m_peer_id = 0;
        Inventory *m_inventory = nullptr;
-       s16 m_damage = 0;
 
        // Cheat prevention
        LagPool m_dig_pool;
index 04ff5230a3685f26eb9ff4d4526ee5de089506ec..d09f1c07466ac78ea2081da8e2f8c2033eada980 100644 (file)
@@ -44,11 +44,11 @@ void PlayerDatabaseFiles::serialize(std::ostringstream &os, RemotePlayer *player
        args.set("name", player->getName());
 
        sanity_check(player->getPlayerSAO());
-       args.setS32("hp", player->getPlayerSAO()->getHP());
+       args.setU16("hp", player->getPlayerSAO()->getHP());
        args.setV3F("position", player->getPlayerSAO()->getBasePosition());
        args.setFloat("pitch", player->getPlayerSAO()->getLookPitch());
        args.setFloat("yaw", player->getPlayerSAO()->getRotation().Y);
-       args.setS32("breath", player->getPlayerSAO()->getBreath());
+       args.setU16("breath", player->getPlayerSAO()->getBreath());
 
        std::string extended_attrs;
        player->serializeExtraAttributes(extended_attrs);
index 522580990a54ae33db7c34c3eeff866f7a59eb62..d7c94ff15b4ed52dcd0c5358e9d15a6c8aeae833 100644 (file)
@@ -553,7 +553,7 @@ bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
                pg_to_float(results, 0, 3),
                pg_to_float(results, 0, 4))
        );
-       sao->setHPRaw((s16) pg_to_int(results, 0, 5));
+       sao->setHPRaw((u16) pg_to_int(results, 0, 5));
        sao->setBreath((u16) pg_to_int(results, 0, 6), false);
 
        PQclear(results);
index 84d7914039fa824c8ecffa668f8e68895efedb31..1bacdfe6c93be4d16f7c47144d7d41ebf88d7bcd 100644 (file)
@@ -546,7 +546,7 @@ bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
        sao->setLookPitch(sqlite_to_float(m_stmt_player_load, 0));
        sao->setPlayerYaw(sqlite_to_float(m_stmt_player_load, 1));
        sao->setBasePosition(sqlite_to_v3f(m_stmt_player_load, 2));
-       sao->setHPRaw((s16) MYMIN(sqlite_to_int(m_stmt_player_load, 5), S16_MAX));
+       sao->setHPRaw((u16) MYMIN(sqlite_to_int(m_stmt_player_load, 5), U16_MAX));
        sao->setBreath((u16) MYMIN(sqlite_to_int(m_stmt_player_load, 6), U16_MAX), false);
        sqlite3_reset(m_stmt_player_load);
 
index b1ec8ce4e2252e24d14ad96dba0e5cc220dd211f..49d16001ff15293b34a1ab0e175c678ce460c4b9 100644 (file)
@@ -92,15 +92,13 @@ std::string gob_cmd_set_sprite(
        return os.str();
 }
 
-std::string gob_cmd_punched(s16 damage, s16 result_hp)
+std::string gob_cmd_punched(u16 result_hp)
 {
        std::ostringstream os(std::ios::binary);
        // command
        writeU8(os, GENERIC_CMD_PUNCHED);
-       // damage
-       writeS16(os, damage);
        // result_hp
-       writeS16(os, result_hp);
+       writeU16(os, result_hp);
        return os.str();
 }
 
index a182c65f3cc797ebd90ef8adc8347eda79d9a6e4..c83b310d1c846ff2aeb2aca978f0aef997a4cc16 100644 (file)
@@ -63,7 +63,7 @@ std::string gob_cmd_set_sprite(
        bool select_horiz_by_yawpitch
 );
 
-std::string gob_cmd_punched(s16 damage, s16 result_hp);
+std::string gob_cmd_punched(u16 result_hp);
 
 std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups);
 
index 138cf3edbdd0d690a396bcc86f1437e99ac9b059..6f17d666a7c828c5819d6712c953da6538414f03 100644 (file)
@@ -776,7 +776,7 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt)
 
 void Server::handleCommand_Damage(NetworkPacket* pkt)
 {
-       u8 damage;
+       u16 damage;
 
        *pkt >> damage;
 
@@ -812,7 +812,7 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
                                << std::endl;
 
                PlayerHPChangeReason reason(PlayerHPChangeReason::FALL);
-               playersao->setHP(playersao->getHP() - damage, reason);
+               playersao->setHP((s32)playersao->getHP() - (s32)damage, reason);
                SendPlayerHPOrDie(playersao, reason);
        }
 }
@@ -1169,8 +1169,8 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
                        float time_from_last_punch =
                                playersao->resetTimeFromLastPunch();
 
-                       s16 src_original_hp = pointed_object->getHP();
-                       s16 dst_origin_hp = playersao->getHP();
+                       u16 src_original_hp = pointed_object->getHP();
+                       u16 dst_origin_hp = playersao->getHP();
 
                        pointed_object->punch(dir, &toolcap, playersao,
                                        time_from_last_punch);
index e08eca7c92b99a38d8fd92b6c5efbc088d67fbd5..a037c5f65c62ac11494cc96b93d0b19312f0c86f 100644 (file)
@@ -75,7 +75,7 @@ std::string ObjectProperties::dump()
 void ObjectProperties::serialize(std::ostream &os) const
 {
        writeU8(os, 4); // PROTOCOL_VERSION >= 37
-       writeS16(os, hp_max);
+       writeU16(os, hp_max);
        writeU8(os, physical);
        writeF32(os, weight);
        writeV3F32(os, collisionbox.MinEdge);
@@ -126,7 +126,7 @@ void ObjectProperties::deSerialize(std::istream &is)
        if (version != 4)
                throw SerializationError("unsupported ObjectProperties version");
 
-       hp_max = readS16(is);
+       hp_max = readU16(is);
        physical = readU8(is);
        weight = readF32(is);
        collisionbox.MinEdge = readV3F32(is);
index 3175e61181326cf47a289813797a45b579d9c106..199182d70839ced53c4a803e8acc7579f87788f1 100644 (file)
@@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 struct ObjectProperties
 {
-       s16 hp_max = 1;
+       u16 hp_max = 1;
        u16 breath_max = 0;
        bool physical = false;
        bool collideWithObjects = true;
index fa2200e94433c67226193651aeac7afec8eeb6a0..5443b7a2ddacddcbe73b9dbcb37815e10c327b13 100644 (file)
@@ -98,7 +98,7 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
 
        if (sao) {
                try {
-                       sao->setHPRaw(args.getS32("hp"));
+                       sao->setHPRaw(args.getU16("hp"));
                } catch(SettingNotFoundException &e) {
                        sao->setHPRaw(PLAYER_MAX_HP_DEFAULT);
                }
@@ -115,7 +115,7 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
                } catch (SettingNotFoundException &e) {}
 
                try {
-                       sao->setBreath(args.getS32("breath"), false);
+                       sao->setBreath(args.getU16("breath"), false);
                } catch (SettingNotFoundException &e) {}
 
                try {
@@ -168,11 +168,11 @@ void RemotePlayer::serialize(std::ostream &os)
 
        // This should not happen
        assert(m_sao);
-       args.setS32("hp", m_sao->getHP());
+       args.setU16("hp", m_sao->getHP());
        args.setV3F("position", m_sao->getBasePosition());
        args.setFloat("pitch", m_sao->getLookPitch());
        args.setFloat("yaw", m_sao->getRotation().Y);
-       args.setS32("breath", m_sao->getBreath());
+       args.setU16("breath", m_sao->getBreath());
 
        std::string extended_attrs;
        serializeExtraAttributes(extended_attrs);
index 7e2f6772f0e0e9561230a4e4905be2bab232c830..793485e25e07fe8335edc67f021d20b7e6482a79 100644 (file)
@@ -191,7 +191,7 @@ void read_object_properties(lua_State *L, int index,
 
        int hp_max = 0;
        if (getintfield(L, -1, "hp_max", hp_max))
-               prop->hp_max = (s16)rangelim(hp_max, 0, S16_MAX);
+               prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
 
        getintfield(L, -1, "breath_max", prop->breath_max);
        getboolfield(L, -1, "physical", prop->physical);
index a3f7fa68bbeb95dca7e598e8c5ea6f552ac3b38f..8af9f9bf67c6ba01b3f85045363e345fd69f2248 100644 (file)
@@ -169,24 +169,6 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
        // Set default values that differ from ObjectProperties defaults
        prop->hp_max = 10;
 
-       /* Read stuff */
-
-       prop->hp_max = getintfield_default(L, -1, "hp_max", 10);
-
-       getboolfield(L, -1, "physical", prop->physical);
-       getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects);
-
-       getfloatfield(L, -1, "weight", prop->weight);
-
-       lua_getfield(L, -1, "collisionbox");
-       if (lua_istable(L, -1))
-               prop->collisionbox = read_aabb3f(L, -1, 1.0);
-       lua_pop(L, 1);
-
-       getstringfield(L, -1, "visual", prop->visual);
-
-       getstringfield(L, -1, "mesh", prop->mesh);
-
        // Deprecated: read object properties directly
        read_object_properties(L, -1, prop, getServer()->idef());
 
index fac86295ab8af0e30e1a1c2b3affed798c818376..df67ea00c5fb789f3a149dbcdebd14423bb85c74 100644 (file)
@@ -77,8 +77,8 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player,
        return readParam<bool>(L, -1);
 }
 
-s16 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,
-       s16 hp_change, const PlayerHPChangeReason &reason)
+s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,
+       s32 hp_change, const PlayerHPChangeReason &reason)
 {
        SCRIPTAPI_PRECHECKHEADER
 
index 764455a532a9a5622f807ab0cd168143c4aec0e7..cf24ddc730ca4943c6433b59e7a6a2cd305fe425 100644 (file)
@@ -46,7 +46,7 @@ public:
        bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter,
                        float time_from_last_punch, const ToolCapabilities *toolcap,
                        v3f dir, s16 damage);
-       s16 on_player_hpchange(ServerActiveObject *player, s16 hp_change,
+       s32 on_player_hpchange(ServerActiveObject *player, s32 hp_change,
                        const PlayerHPChangeReason &reason);
        void on_playerReceiveFields(ServerActiveObject *player,
                        const std::string &formname, const StringMap &fields);
index e673778e9d711790174703e65adf4e094b3a5565..9edb2f4f828ab4712fba469e2cdef339b47c68ec 100644 (file)
@@ -183,8 +183,8 @@ int ObjectRef::l_punch(lua_State *L)
        ToolCapabilities toolcap = read_tool_capabilities(L, 4);
        dir.normalize();
 
-       s16 src_original_hp = co->getHP();
-       s16 dst_origin_hp = puncher->getHP();
+       u16 src_original_hp = co->getHP();
+       u16 dst_origin_hp = puncher->getHP();
 
        // Do it
        co->punch(dir, &toolcap, puncher, time_from_last_punch);
index 7db06acbfbd8e05cd690795b8ad0b3f3eea4a495..ad469d655f7c0ec1d95bf275a9983468d318f526 100644 (file)
@@ -1833,7 +1833,7 @@ void Server::SendPlayerHP(session_t peer_id)
        m_script->player_event(playersao,"health_changed");
 
        // Send to other clients
-       std::string str = gob_cmd_punched(playersao->readDamage(), playersao->getHP());
+       std::string str = gob_cmd_punched(playersao->getHP());
        ActiveObjectMessage aom(playersao->getId(), true, str);
        playersao->m_messages_out.push(aom);
 }
index c20ec07e7c600034ba5fd6715cf551c0e79fb306..4a9430107fbc6c08b4e562333f9912e8382f7567 100644 (file)
@@ -140,9 +140,9 @@ public:
        { return 0; }
        virtual void rightClick(ServerActiveObject *clicker)
        {}
-       virtual void setHP(s16 hp, const PlayerHPChangeReason &reason)
+       virtual void setHP(s32 hp, const PlayerHPChangeReason &reason)
        {}
-       virtual s16 getHP() const
+       virtual u16 getHP() const
        { return 0; }
 
        virtual void setArmorGroups(const ItemGroupList &armor_groups)