diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/client.cpp | 17 | ||||
-rw-r--r-- | src/client/client.h | 6 | ||||
-rw-r--r-- | src/client/clientenvironment.cpp | 4 | ||||
-rw-r--r-- | src/client/clientenvironment.h | 4 | ||||
-rw-r--r-- | src/client/content_cao.cpp | 7 | ||||
-rw-r--r-- | src/client/content_cao.h | 2 | ||||
-rw-r--r-- | src/client/hud.cpp | 19 | ||||
-rw-r--r-- | src/content_sao.cpp | 57 | ||||
-rw-r--r-- | src/content_sao.h | 13 | ||||
-rw-r--r-- | src/database/database-files.cpp | 4 | ||||
-rw-r--r-- | src/database/database-postgresql.cpp | 2 | ||||
-rw-r--r-- | src/database/database-sqlite3.cpp | 2 | ||||
-rw-r--r-- | src/genericobject.cpp | 6 | ||||
-rw-r--r-- | src/genericobject.h | 2 | ||||
-rw-r--r-- | src/network/serverpackethandler.cpp | 8 | ||||
-rw-r--r-- | src/object_properties.cpp | 4 | ||||
-rw-r--r-- | src/object_properties.h | 2 | ||||
-rw-r--r-- | src/remoteplayer.cpp | 8 | ||||
-rw-r--r-- | src/script/common/c_content.cpp | 2 | ||||
-rw-r--r-- | src/script/cpp_api/s_entity.cpp | 18 | ||||
-rw-r--r-- | src/script/cpp_api/s_player.cpp | 4 | ||||
-rw-r--r-- | src/script/cpp_api/s_player.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 4 | ||||
-rw-r--r-- | src/server.cpp | 2 | ||||
-rw-r--r-- | src/serverobject.h | 4 |
25 files changed, 67 insertions, 136 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp index 3ba69333a..41893fcba 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -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) diff --git a/src/client/client.h b/src/client/client.h index ef700e477..60735f665 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -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; diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 1783e8961..a788c93c2 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -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); diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index d167902d1..4fa3f4848 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -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 diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 6112edaff..8643b5824 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -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; diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 4627800ee..3ce628d30 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -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 diff --git a/src/client/hud.cpp b/src/client/hud.cpp index fffe85e1d..1a2287a13 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -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)); - } - //////////////////////////////////////////////////////////////////////////// } diff --git a/src/content_sao.cpp b/src/content_sao.cpp index ecacd7452..e0374d28d 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -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; diff --git a/src/content_sao.h b/src/content_sao.h index 6d2f55b70..14f959e30 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -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; diff --git a/src/database/database-files.cpp b/src/database/database-files.cpp index 04ff5230a..d09f1c074 100644 --- a/src/database/database-files.cpp +++ b/src/database/database-files.cpp @@ -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); diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index 522580990..d7c94ff15 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -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); diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index 84d791403..1bacdfe6c 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -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); diff --git a/src/genericobject.cpp b/src/genericobject.cpp index b1ec8ce4e..49d16001f 100644 --- a/src/genericobject.cpp +++ b/src/genericobject.cpp @@ -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(); } diff --git a/src/genericobject.h b/src/genericobject.h index a182c65f3..c83b310d1 100644 --- a/src/genericobject.h +++ b/src/genericobject.h @@ -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); diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 138cf3edb..6f17d666a 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -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); diff --git a/src/object_properties.cpp b/src/object_properties.cpp index e08eca7c9..a037c5f65 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -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); diff --git a/src/object_properties.h b/src/object_properties.h index 3175e6118..199182d70 100644 --- a/src/object_properties.h +++ b/src/object_properties.h @@ -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; diff --git a/src/remoteplayer.cpp b/src/remoteplayer.cpp index fa2200e94..5443b7a2d 100644 --- a/src/remoteplayer.cpp +++ b/src/remoteplayer.cpp @@ -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); diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 7e2f6772f..793485e25 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -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); diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp index a3f7fa68b..8af9f9bf6 100644 --- a/src/script/cpp_api/s_entity.cpp +++ b/src/script/cpp_api/s_entity.cpp @@ -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()); diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index fac86295a..df67ea00c 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -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 diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h index 764455a53..cf24ddc73 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -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); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index e673778e9..9edb2f4f8 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -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); diff --git a/src/server.cpp b/src/server.cpp index 7db06acbf..ad469d655 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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); } diff --git a/src/serverobject.h b/src/serverobject.h index c20ec07e7..4a9430107 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -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) |