1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

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();
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)

View 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;

View 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);

View 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

View 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;

View 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

View 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));
}
////////////////////////////////////////////////////////////////////////////
}