Consistent HP and damage types (#8167)

Remove deprecated HUDs and chat message handling.
Remove unused m_damage variable (compat break).
HP: s32 for setter/calculations, u16 for getter.
This commit is contained in:
SmallJoker 2019-02-11 00:03:26 +01:00 committed by Paramat
parent ba5a9f2b36
commit ffb17f1c9a
25 changed files with 67 additions and 136 deletions

View File

@ -437,7 +437,7 @@ void Client::step(float dtime)
ClientEnvEvent envEvent = m_env.getClientEnvEvent(); ClientEnvEvent envEvent = m_env.getClientEnvEvent();
if (envEvent.type == CEE_PLAYER_DAMAGE) { 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) if (envEvent.player_damage.send_to_server)
sendDamage(damage); 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; pkt << damage;
Send(&pkt); Send(&pkt);
} }
@ -1515,17 +1515,6 @@ void Client::typeChatMessage(const std::wstring &message)
// Send to others // Send to others
sendChatMessage(message); 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) void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)

View File

@ -243,7 +243,7 @@ public:
void clearOutChatQueue(); void clearOutChatQueue();
void sendChangePassword(const std::string &oldpassword, void sendChangePassword(const std::string &oldpassword,
const std::string &newpassword); const std::string &newpassword);
void sendDamage(u8 damage); void sendDamage(u16 damage);
void sendRespawn(); void sendRespawn();
void sendReady(); void sendReady();
@ -342,7 +342,7 @@ public:
bool mediaReceived() bool mediaReceived()
{ return !m_media_downloader; } { return !m_media_downloader; }
u8 getProtoVersion() u16 getProtoVersion()
{ return m_proto_ver; } { return m_proto_ver; }
bool connectedToServer(); bool connectedToServer();
@ -504,7 +504,7 @@ private:
// and aren't accurate. We simply just don't know, because // and aren't accurate. We simply just don't know, because
// the server didn't send the version back then. // the server didn't send the version back then.
// If 0, server init hasn't been received yet. // If 0, server init hasn't been received yet.
u8 m_proto_ver = 0; u16 m_proto_ver = 0;
u16 m_playeritem = 0; u16 m_playeritem = 0;
bool m_inventory_updated = false; bool m_inventory_updated = false;

View File

@ -228,7 +228,7 @@ void ClientEnvironment::step(float dtime)
float speed = pre_factor * speed_diff.getLength(); float speed = pre_factor * speed_diff.getLength();
if (speed > tolerance && !player_immortal) { if (speed > tolerance && !player_immortal) {
f32 damage_f = (speed - tolerance) / BS * post_factor; 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) { if (damage != 0) {
damageLocalPlayer(damage, true); damageLocalPlayer(damage, true);
m_client->getEventManager()->put( m_client->getEventManager()->put(
@ -419,7 +419,7 @@ void ClientEnvironment::processActiveObjectMessage(u16 id, const std::string &da
Callbacks for activeobjects Callbacks for activeobjects
*/ */
void ClientEnvironment::damageLocalPlayer(u8 damage, bool handle_hp) void ClientEnvironment::damageLocalPlayer(u16 damage, bool handle_hp)
{ {
LocalPlayer *lplayer = getLocalPlayer(); LocalPlayer *lplayer = getLocalPlayer();
assert(lplayer); assert(lplayer);

View File

@ -53,7 +53,7 @@ struct ClientEnvEvent
//struct{ //struct{
//} none; //} none;
struct{ struct{
u8 amount; u16 amount;
bool send_to_server; bool send_to_server;
} player_damage; } player_damage;
}; };
@ -115,7 +115,7 @@ public:
Callbacks for activeobjects Callbacks for activeobjects
*/ */
void damageLocalPlayer(u8 damage, bool handle_hp=true); void damageLocalPlayer(u16 damage, bool handle_hp=true);
/* /*
Client likes to call these Client likes to call these

View File

@ -371,7 +371,7 @@ void GenericCAO::processInitData(const std::string &data)
m_id = readU16(is); m_id = readU16(is);
m_position = readV3F32(is); m_position = readV3F32(is);
m_rotation = readV3F32(is); m_rotation = readV3F32(is);
m_hp = readS16(is); m_hp = readU16(is);
const u8 num_messages = readU8(is); const u8 num_messages = readU8(is);
for (int i = 0; i < num_messages; i++) { for (int i = 0; i < num_messages; i++) {
@ -1508,11 +1508,10 @@ void GenericCAO::processMessage(const std::string &data)
updateAttachments(); updateAttachments();
} else if (cmd == GENERIC_CMD_PUNCHED) { } else if (cmd == GENERIC_CMD_PUNCHED) {
/*s16 damage =*/ readS16(is); u16 result_hp = readU16(is);
s16 result_hp = readS16(is);
// Use this instead of the send damage to not interfere with prediction // 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; m_hp = result_hp;

View File

@ -88,7 +88,7 @@ private:
v3f m_velocity; v3f m_velocity;
v3f m_acceleration; v3f m_acceleration;
v3f m_rotation; v3f m_rotation;
s16 m_hp = 1; u16 m_hp = 1;
SmoothTranslator<v3f> pos_translator; SmoothTranslator<v3f> pos_translator;
SmoothTranslatorWrappedv3f rot_translator; SmoothTranslatorWrappedv3f rot_translator;
// Spritesheet/animation stuff // Spritesheet/animation stuff

View File

@ -475,25 +475,6 @@ void Hud::drawHotbar(u16 playeritem) {
hotbar_itemcount / 2, mainlist, playeritem + 1, 0); 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));
}
////////////////////////////////////////////////////////////////////////////
} }

View File

@ -347,7 +347,7 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
{ {
std::string name; std::string name;
std::string state; std::string state;
s16 hp = 1; u16 hp = 1;
v3f velocity; v3f velocity;
v3f rotation; v3f rotation;
@ -364,7 +364,7 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
if (version < 1) if (version < 1)
break; break;
hp = readS16(is); hp = readU16(is);
velocity = readV3F1000(is); velocity = readV3F1000(is);
// yaw must be yaw to be backwards-compatible // yaw must be yaw to be backwards-compatible
rotation.Y = readF1000(is); rotation.Y = readF1000(is);
@ -548,10 +548,10 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
writeU8(os, 1); // version writeU8(os, 1); // version
os << serializeString(""); // name os << serializeString(""); // name
writeU8(os, 0); // is_player writeU8(os, 0); // is_player
writeS16(os, getId()); //id writeU16(os, getId()); //id
writeV3F32(os, m_base_position); writeV3F32(os, m_base_position);
writeV3F32(os, m_rotation); writeV3F32(os, m_rotation);
writeS16(os, m_hp); writeU16(os, m_hp);
std::ostringstream msg_os(std::ios::binary); std::ostringstream msg_os(std::ios::binary);
msg_os << serializeLongString(getPropertyPacket()); // message 1 msg_os << serializeLongString(getPropertyPacket()); // message 1
@ -601,7 +601,7 @@ void LuaEntitySAO::getStaticData(std::string *result) const
} else { } else {
os<<serializeLongString(m_init_state); os<<serializeLongString(m_init_state);
} }
writeS16(os, m_hp); writeU16(os, m_hp);
writeV3F1000(os, m_velocity); writeV3F1000(os, m_velocity);
// yaw // yaw
writeF1000(os, m_rotation.Y); writeF1000(os, m_rotation.Y);
@ -646,7 +646,7 @@ int LuaEntitySAO::punch(v3f dir,
if (!damage_handled) { if (!damage_handled) {
if (result.did_punch) { if (result.did_punch) {
setHP(getHP() - result.damage, setHP((s32)getHP() - result.damage,
PlayerHPChangeReason(PlayerHPChangeReason::SET_HP)); PlayerHPChangeReason(PlayerHPChangeReason::SET_HP));
if (result.damage > 0) { if (result.damage > 0) {
@ -657,7 +657,7 @@ int LuaEntitySAO::punch(v3f dir,
<< " hp, health now " << getHP() << " hp" << std::endl; << " 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 // create message and add to list
ActiveObjectMessage aom(getId(), true, str); ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom); m_messages_out.push(aom);
@ -715,14 +715,12 @@ std::string LuaEntitySAO::getDescription()
return os.str(); return os.str();
} }
void LuaEntitySAO::setHP(s16 hp, const PlayerHPChangeReason &reason) void LuaEntitySAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
{ {
if (hp < 0) m_hp = rangelim(hp, 0, U16_MAX);
hp = 0;
m_hp = hp;
} }
s16 LuaEntitySAO::getHP() const u16 LuaEntitySAO::getHP() const
{ {
return m_hp; return m_hp;
} }
@ -949,7 +947,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
writeS16(os, getId()); // id writeS16(os, getId()); // id
writeV3F32(os, m_base_position); writeV3F32(os, m_base_position);
writeV3F32(os, m_rotation); writeV3F32(os, m_rotation);
writeS16(os, getHP()); writeU16(os, getHP());
std::ostringstream msg_os(std::ios::binary); std::ostringstream msg_os(std::ios::binary);
msg_os << serializeLongString(getPropertyPacket()); // message 1 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); m_env->getGameDef()->ndef()->get(ntop).damage_per_second);
if (damage_per_second != 0 && m_hp > 0) { 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); PlayerHPChangeReason reason(PlayerHPChangeReason::NODE_DAMAGE);
setHP(newhp, reason); setHP(newhp, reason);
m_env->getGameDef()->SendPlayerHPOrDie(this, reason); m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
@ -1272,7 +1270,7 @@ int PlayerSAO::punch(v3f dir,
// No effect if PvP disabled // No effect if PvP disabled
if (!g_settings->getBool("enable_pvp")) { if (!g_settings->getBool("enable_pvp")) {
if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { 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 // create message and add to list
ActiveObjectMessage aom(getId(), true, str); ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom); m_messages_out.push(aom);
@ -1295,11 +1293,11 @@ int PlayerSAO::punch(v3f dir,
hitparams.hp); hitparams.hp);
if (!damage_handled) { if (!damage_handled) {
setHP(getHP() - hitparams.hp, setHP((s32)getHP() - (s32)hitparams.hp,
PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
} else { // override client prediction } else { // override client prediction
if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { 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 // create message and add to list
ActiveObjectMessage aom(getId(), true, str); ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom); m_messages_out.push(aom);
@ -1319,36 +1317,21 @@ int PlayerSAO::punch(v3f dir,
return hitparams.wear; return hitparams.wear;
} }
s16 PlayerSAO::readDamage() void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
{ {
s16 damage = m_damage; s32 oldhp = m_hp;
m_damage = 0;
return damage;
}
void PlayerSAO::setHP(s16 hp, const PlayerHPChangeReason &reason) s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp, reason);
{
s16 oldhp = m_hp;
s16 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp, reason);
if (hp_change == 0) if (hp_change == 0)
return; return;
hp = oldhp + hp_change;
if (hp < 0) hp = rangelim(oldhp + hp_change, 0, m_prop.hp_max);
hp = 0;
else if (hp > m_prop.hp_max)
hp = m_prop.hp_max;
if (hp < oldhp && !g_settings->getBool("enable_damage")) { if (hp < oldhp && !g_settings->getBool("enable_damage"))
return; return;
}
m_hp = hp; m_hp = hp;
if (oldhp > hp)
m_damage += (oldhp - hp);
// Update properties on death // Update properties on death
if ((hp == 0) != (oldhp == 0)) if ((hp == 0) != (oldhp == 0))
m_properties_sent = false; m_properties_sent = false;

View File

@ -39,7 +39,7 @@ public:
// Deprecated // Deprecated
f32 getRadYawDep() const { return (m_rotation.Y + 90.) * core::DEGTORAD; } 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 // Use a function, if isDead can be defined by other conditions
bool isDead() const { return m_hp == 0; } bool isDead() const { return m_hp == 0; }
@ -64,7 +64,7 @@ public:
ObjectProperties* accessObjectProperties(); ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified(); void notifyObjectPropertiesModified();
protected: protected:
s16 m_hp = -1; u16 m_hp = 1;
v3f m_rotation; v3f m_rotation;
@ -127,8 +127,8 @@ public:
void moveTo(v3f pos, bool continuous); void moveTo(v3f pos, bool continuous);
float getMinimumSavedMovement(); float getMinimumSavedMovement();
std::string getDescription(); std::string getDescription();
void setHP(s16 hp, const PlayerHPChangeReason &reason); void setHP(s32 hp, const PlayerHPChangeReason &reason);
s16 getHP() const; u16 getHP() const;
/* LuaEntitySAO-specific */ /* LuaEntitySAO-specific */
void setVelocity(v3f velocity); void setVelocity(v3f velocity);
void addVelocity(v3f velocity) void addVelocity(v3f velocity)
@ -258,8 +258,8 @@ public:
ServerActiveObject *puncher, ServerActiveObject *puncher,
float time_from_last_punch); float time_from_last_punch);
void rightClick(ServerActiveObject *clicker) {} void rightClick(ServerActiveObject *clicker) {}
void setHP(s16 hp, const PlayerHPChangeReason &reason); void setHP(s32 hp, const PlayerHPChangeReason &reason);
void setHPRaw(s16 hp) { m_hp = hp; } void setHPRaw(u16 hp) { m_hp = hp; }
s16 readDamage(); s16 readDamage();
u16 getBreath() const { return m_breath; } u16 getBreath() const { return m_breath; }
void setBreath(const u16 breath, bool send = true); void setBreath(const u16 breath, bool send = true);
@ -351,7 +351,6 @@ private:
RemotePlayer *m_player = nullptr; RemotePlayer *m_player = nullptr;
session_t m_peer_id = 0; session_t m_peer_id = 0;
Inventory *m_inventory = nullptr; Inventory *m_inventory = nullptr;
s16 m_damage = 0;
// Cheat prevention // Cheat prevention
LagPool m_dig_pool; LagPool m_dig_pool;

View File

@ -44,11 +44,11 @@ void PlayerDatabaseFiles::serialize(std::ostringstream &os, RemotePlayer *player
args.set("name", player->getName()); args.set("name", player->getName());
sanity_check(player->getPlayerSAO()); sanity_check(player->getPlayerSAO());
args.setS32("hp", player->getPlayerSAO()->getHP()); args.setU16("hp", player->getPlayerSAO()->getHP());
args.setV3F("position", player->getPlayerSAO()->getBasePosition()); args.setV3F("position", player->getPlayerSAO()->getBasePosition());
args.setFloat("pitch", player->getPlayerSAO()->getLookPitch()); args.setFloat("pitch", player->getPlayerSAO()->getLookPitch());
args.setFloat("yaw", player->getPlayerSAO()->getRotation().Y); args.setFloat("yaw", player->getPlayerSAO()->getRotation().Y);
args.setS32("breath", player->getPlayerSAO()->getBreath()); args.setU16("breath", player->getPlayerSAO()->getBreath());
std::string extended_attrs; std::string extended_attrs;
player->serializeExtraAttributes(extended_attrs); player->serializeExtraAttributes(extended_attrs);

View File

@ -553,7 +553,7 @@ bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
pg_to_float(results, 0, 3), pg_to_float(results, 0, 3),
pg_to_float(results, 0, 4)) 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); sao->setBreath((u16) pg_to_int(results, 0, 6), false);
PQclear(results); PQclear(results);

View File

@ -546,7 +546,7 @@ bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
sao->setLookPitch(sqlite_to_float(m_stmt_player_load, 0)); sao->setLookPitch(sqlite_to_float(m_stmt_player_load, 0));
sao->setPlayerYaw(sqlite_to_float(m_stmt_player_load, 1)); sao->setPlayerYaw(sqlite_to_float(m_stmt_player_load, 1));
sao->setBasePosition(sqlite_to_v3f(m_stmt_player_load, 2)); 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); sao->setBreath((u16) MYMIN(sqlite_to_int(m_stmt_player_load, 6), U16_MAX), false);
sqlite3_reset(m_stmt_player_load); sqlite3_reset(m_stmt_player_load);

View File

@ -92,15 +92,13 @@ std::string gob_cmd_set_sprite(
return os.str(); 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); std::ostringstream os(std::ios::binary);
// command // command
writeU8(os, GENERIC_CMD_PUNCHED); writeU8(os, GENERIC_CMD_PUNCHED);
// damage
writeS16(os, damage);
// result_hp // result_hp
writeS16(os, result_hp); writeU16(os, result_hp);
return os.str(); return os.str();
} }

View File

@ -63,7 +63,7 @@ std::string gob_cmd_set_sprite(
bool select_horiz_by_yawpitch 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); std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups);

View File

@ -776,7 +776,7 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt)
void Server::handleCommand_Damage(NetworkPacket* pkt) void Server::handleCommand_Damage(NetworkPacket* pkt)
{ {
u8 damage; u16 damage;
*pkt >> damage; *pkt >> damage;
@ -812,7 +812,7 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
<< std::endl; << std::endl;
PlayerHPChangeReason reason(PlayerHPChangeReason::FALL); PlayerHPChangeReason reason(PlayerHPChangeReason::FALL);
playersao->setHP(playersao->getHP() - damage, reason); playersao->setHP((s32)playersao->getHP() - (s32)damage, reason);
SendPlayerHPOrDie(playersao, reason); SendPlayerHPOrDie(playersao, reason);
} }
} }
@ -1169,8 +1169,8 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
float time_from_last_punch = float time_from_last_punch =
playersao->resetTimeFromLastPunch(); playersao->resetTimeFromLastPunch();
s16 src_original_hp = pointed_object->getHP(); u16 src_original_hp = pointed_object->getHP();
s16 dst_origin_hp = playersao->getHP(); u16 dst_origin_hp = playersao->getHP();
pointed_object->punch(dir, &toolcap, playersao, pointed_object->punch(dir, &toolcap, playersao,
time_from_last_punch); time_from_last_punch);

View File

@ -75,7 +75,7 @@ std::string ObjectProperties::dump()
void ObjectProperties::serialize(std::ostream &os) const void ObjectProperties::serialize(std::ostream &os) const
{ {
writeU8(os, 4); // PROTOCOL_VERSION >= 37 writeU8(os, 4); // PROTOCOL_VERSION >= 37
writeS16(os, hp_max); writeU16(os, hp_max);
writeU8(os, physical); writeU8(os, physical);
writeF32(os, weight); writeF32(os, weight);
writeV3F32(os, collisionbox.MinEdge); writeV3F32(os, collisionbox.MinEdge);
@ -126,7 +126,7 @@ void ObjectProperties::deSerialize(std::istream &is)
if (version != 4) if (version != 4)
throw SerializationError("unsupported ObjectProperties version"); throw SerializationError("unsupported ObjectProperties version");
hp_max = readS16(is); hp_max = readU16(is);
physical = readU8(is); physical = readU8(is);
weight = readF32(is); weight = readF32(is);
collisionbox.MinEdge = readV3F32(is); collisionbox.MinEdge = readV3F32(is);

View File

@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct ObjectProperties struct ObjectProperties
{ {
s16 hp_max = 1; u16 hp_max = 1;
u16 breath_max = 0; u16 breath_max = 0;
bool physical = false; bool physical = false;
bool collideWithObjects = true; bool collideWithObjects = true;

View File

@ -98,7 +98,7 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
if (sao) { if (sao) {
try { try {
sao->setHPRaw(args.getS32("hp")); sao->setHPRaw(args.getU16("hp"));
} catch(SettingNotFoundException &e) { } catch(SettingNotFoundException &e) {
sao->setHPRaw(PLAYER_MAX_HP_DEFAULT); sao->setHPRaw(PLAYER_MAX_HP_DEFAULT);
} }
@ -115,7 +115,7 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
} catch (SettingNotFoundException &e) {} } catch (SettingNotFoundException &e) {}
try { try {
sao->setBreath(args.getS32("breath"), false); sao->setBreath(args.getU16("breath"), false);
} catch (SettingNotFoundException &e) {} } catch (SettingNotFoundException &e) {}
try { try {
@ -168,11 +168,11 @@ void RemotePlayer::serialize(std::ostream &os)
// This should not happen // This should not happen
assert(m_sao); assert(m_sao);
args.setS32("hp", m_sao->getHP()); args.setU16("hp", m_sao->getHP());
args.setV3F("position", m_sao->getBasePosition()); args.setV3F("position", m_sao->getBasePosition());
args.setFloat("pitch", m_sao->getLookPitch()); args.setFloat("pitch", m_sao->getLookPitch());
args.setFloat("yaw", m_sao->getRotation().Y); args.setFloat("yaw", m_sao->getRotation().Y);
args.setS32("breath", m_sao->getBreath()); args.setU16("breath", m_sao->getBreath());
std::string extended_attrs; std::string extended_attrs;
serializeExtraAttributes(extended_attrs); serializeExtraAttributes(extended_attrs);

View File

@ -191,7 +191,7 @@ void read_object_properties(lua_State *L, int index,
int hp_max = 0; int hp_max = 0;
if (getintfield(L, -1, "hp_max", hp_max)) 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); getintfield(L, -1, "breath_max", prop->breath_max);
getboolfield(L, -1, "physical", prop->physical); getboolfield(L, -1, "physical", prop->physical);

View File

@ -169,24 +169,6 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
// Set default values that differ from ObjectProperties defaults // Set default values that differ from ObjectProperties defaults
prop->hp_max = 10; 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 // Deprecated: read object properties directly
read_object_properties(L, -1, prop, getServer()->idef()); read_object_properties(L, -1, prop, getServer()->idef());

View File

@ -77,8 +77,8 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player,
return readParam<bool>(L, -1); return readParam<bool>(L, -1);
} }
s16 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player, s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,
s16 hp_change, const PlayerHPChangeReason &reason) s32 hp_change, const PlayerHPChangeReason &reason)
{ {
SCRIPTAPI_PRECHECKHEADER SCRIPTAPI_PRECHECKHEADER

View File

@ -46,7 +46,7 @@ public:
bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter, bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter,
float time_from_last_punch, const ToolCapabilities *toolcap, float time_from_last_punch, const ToolCapabilities *toolcap,
v3f dir, s16 damage); 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); const PlayerHPChangeReason &reason);
void on_playerReceiveFields(ServerActiveObject *player, void on_playerReceiveFields(ServerActiveObject *player,
const std::string &formname, const StringMap &fields); const std::string &formname, const StringMap &fields);

View File

@ -183,8 +183,8 @@ int ObjectRef::l_punch(lua_State *L)
ToolCapabilities toolcap = read_tool_capabilities(L, 4); ToolCapabilities toolcap = read_tool_capabilities(L, 4);
dir.normalize(); dir.normalize();
s16 src_original_hp = co->getHP(); u16 src_original_hp = co->getHP();
s16 dst_origin_hp = puncher->getHP(); u16 dst_origin_hp = puncher->getHP();
// Do it // Do it
co->punch(dir, &toolcap, puncher, time_from_last_punch); co->punch(dir, &toolcap, puncher, time_from_last_punch);

View File

@ -1833,7 +1833,7 @@ void Server::SendPlayerHP(session_t peer_id)
m_script->player_event(playersao,"health_changed"); m_script->player_event(playersao,"health_changed");
// Send to other clients // 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); ActiveObjectMessage aom(playersao->getId(), true, str);
playersao->m_messages_out.push(aom); playersao->m_messages_out.push(aom);
} }

View File

@ -140,9 +140,9 @@ public:
{ return 0; } { return 0; }
virtual void rightClick(ServerActiveObject *clicker) 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; } { return 0; }
virtual void setArmorGroups(const ItemGroupList &armor_groups) virtual void setArmorGroups(const ItemGroupList &armor_groups)