From 9fe21fcd8883b37bdc30224822e6e42afb35b8f0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 7 Feb 2016 16:18:13 +0300 Subject: Replace most static_cast to shorter versions from defines. --- src/net/tmwa/adminhandler.cpp | 8 ++--- src/net/tmwa/beingrecv.cpp | 70 +++++++++++++++++++------------------- src/net/tmwa/charserverhandler.cpp | 10 +++--- src/net/tmwa/charserverrecv.cpp | 4 +-- src/net/tmwa/chathandler.cpp | 22 ++++++------ src/net/tmwa/chatrecv.cpp | 2 +- src/net/tmwa/generalrecv.cpp | 2 +- src/net/tmwa/guildhandler.cpp | 4 +-- src/net/tmwa/guildrecv.cpp | 2 +- src/net/tmwa/inventoryhandler.cpp | 16 ++++----- src/net/tmwa/inventoryrecv.cpp | 4 +-- src/net/tmwa/itemrecv.cpp | 8 ++--- src/net/tmwa/messagein.cpp | 24 ++++++------- src/net/tmwa/messageout.cpp | 34 +++++++++--------- src/net/tmwa/network.cpp | 4 +-- src/net/tmwa/npchandler.cpp | 12 +++---- src/net/tmwa/partyhandler.cpp | 12 +++---- src/net/tmwa/pethandler.cpp | 4 +-- src/net/tmwa/playerhandler.cpp | 8 ++--- src/net/tmwa/skillhandler.cpp | 22 ++++++------ src/net/tmwa/skillrecv.cpp | 12 +++---- src/net/tmwa/tradehandler.cpp | 4 +-- 22 files changed, 144 insertions(+), 144 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index e77b9afdb..30c2bfe84 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -47,15 +47,15 @@ AdminHandler::AdminHandler() : void AdminHandler::announce(const std::string &text) const { createOutPacket(CMSG_ADMIN_ANNOUNCE); - outMsg.writeInt16(static_cast(text.length() + 4), "len"); - outMsg.writeString(text, static_cast(text.length()), "message"); + outMsg.writeInt16(CAST_S16(text.length() + 4), "len"); + outMsg.writeString(text, CAST_S32(text.length()), "message"); } void AdminHandler::localAnnounce(const std::string &text) const { createOutPacket(CMSG_ADMIN_LOCAL_ANNOUNCE); - outMsg.writeInt16(static_cast(text.length() + 4), "len"); - outMsg.writeString(text, static_cast(text.length()), "message"); + outMsg.writeInt16(CAST_S16(text.length() + 4), "len"); + outMsg.writeString(text, CAST_S32(text.length()), "message"); } void AdminHandler::hide(const bool h A_UNUSED) const diff --git a/src/net/tmwa/beingrecv.cpp b/src/net/tmwa/beingrecv.cpp index 93d4a41dc..ea921f91e 100644 --- a/src/net/tmwa/beingrecv.cpp +++ b/src/net/tmwa/beingrecv.cpp @@ -73,7 +73,7 @@ void BeingRecv::processBeingChangeLook(Net::MessageIn &msg) msg.readBeingId("being id")); const uint8_t type = msg.readUInt8("type"); - const int16_t id = static_cast(msg.readUInt8("id")); + const int16_t id = CAST_S16(msg.readUInt8("id")); const int id2 = 1; if (!localPlayer || !dstBeing) @@ -138,7 +138,7 @@ void BeingRecv::processBeingChangeLookContinue(Net::MessageIn &msg, break; case 1: // eAthena LOOK_HAIR { - const uint16_t look = static_cast(id / 256); + const uint16_t look = CAST_U16(id / 256); const int hair = id % 256; dstBeing->setHairStyle(SPRITE_HAIR_COLOR, hair * -1); dstBeing->setLook(look); @@ -212,7 +212,7 @@ void BeingRecv::processBeingChangeLookContinue(Net::MessageIn &msg, localPlayer->imitateOutfit(dstBeing, SPRITE_EVOL2); break; case 16: - dstBeing->setLook(static_cast(id)); + dstBeing->setLook(CAST_U16(id)); break; default: UNIMPLIMENTEDPACKET; @@ -234,7 +234,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg) const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); - statusEffects |= (static_cast(msg.readInt16("options"))) + statusEffects |= (CAST_U32(msg.readInt16("options"))) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; @@ -301,7 +301,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg) if (guild == 0) dstBeing->clearGuilds(); else - dstBeing->setGuild(Guild::getGuild(static_cast(guild))); + dstBeing->setGuild(Guild::getGuild(CAST_S16(guild))); } msg.readInt16("emblem"); @@ -310,7 +310,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg) dstBeing->setKarma(msg.readUInt8("karma")); // reserving bit for future usage dstBeing->setGender(Being::intToGender( - static_cast(msg.readUInt8("gender") & 3))); + CAST_U8(msg.readUInt8("gender") & 3))); if (!disguiseId) { @@ -339,7 +339,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg) dstBeing->setGM(true); applyPlayerAction(msg, dstBeing, msg.readUInt8("action type")); - const int level = static_cast(msg.readUInt8("level")); + const int level = CAST_S32(msg.readUInt8("level")); if (level) dstBeing->setLevel(level); @@ -348,9 +348,9 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg) dstBeing->setActionTime(tick_time); dstBeing->setStunMode(stunMode); - dstBeing->setStatusEffectBlock(0, static_cast( + dstBeing->setStatusEffectBlock(0, CAST_U16( (statusEffects >> 16) & 0xffff)); - dstBeing->setStatusEffectBlock(16, static_cast( + dstBeing->setStatusEffectBlock(16, CAST_U16( statusEffects & 0xffff)); BLOCK_END("BeingRecv::processPlayerMoveUpdate") @@ -370,7 +370,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg) const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); - statusEffects |= (static_cast(msg.readInt16("options"))) + statusEffects |= (CAST_U32(msg.readInt16("options"))) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; @@ -436,7 +436,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg) if (guild == 0) dstBeing->clearGuilds(); else - dstBeing->setGuild(Guild::getGuild(static_cast(guild))); + dstBeing->setGuild(Guild::getGuild(CAST_S16(guild))); } msg.readInt16("emblem"); @@ -445,7 +445,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg) dstBeing->setKarma(msg.readUInt8("karma")); // reserving bit for future usage dstBeing->setGender(Being::intToGender( - static_cast(msg.readUInt8("gender") & 3))); + CAST_U8(msg.readUInt8("gender") & 3))); if (!disguiseId) { @@ -474,15 +474,15 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg) dstBeing->setGM(true); applyPlayerAction(msg, dstBeing, msg.readUInt8("action type")); - const int level = static_cast(msg.readUInt8("level")); + const int level = CAST_S32(msg.readUInt8("level")); if (level) dstBeing->setLevel(level); dstBeing->setActionTime(tick_time); dstBeing->setStunMode(stunMode); - dstBeing->setStatusEffectBlock(0, static_cast( + dstBeing->setStatusEffectBlock(0, CAST_U16( (statusEffects >> 16) & 0xffff)); - dstBeing->setStatusEffectBlock(16, static_cast( + dstBeing->setStatusEffectBlock(16, CAST_U16( statusEffects & 0xffff)); BLOCK_END("BeingRecv::processPlayerMoveUpdate") @@ -502,7 +502,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg) const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); - statusEffects |= (static_cast(msg.readInt16("options"))) + statusEffects |= (CAST_U32(msg.readInt16("options"))) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; @@ -571,7 +571,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg) if (guild == 0) dstBeing->clearGuilds(); else - dstBeing->setGuild(Guild::getGuild(static_cast(guild))); + dstBeing->setGuild(Guild::getGuild(CAST_S16(guild))); } msg.readInt16("emblem"); @@ -580,7 +580,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg) dstBeing->setKarma(msg.readUInt8("karma")); // reserving bit for future usage dstBeing->setGender(Being::intToGender( - static_cast(msg.readUInt8("gender") & 3))); + CAST_U8(msg.readUInt8("gender") & 3))); if (!disguiseId) { @@ -612,7 +612,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg) const int d = dstBeing->calcDirection(dstX, dstY); if (d && dstBeing->getDirection() != d) - dstBeing->setDirectionDelayed(static_cast(d)); + dstBeing->setDirectionDelayed(CAST_U8(d)); } if (localPlayer->getCurrentAction() != BeingAction::STAND) @@ -630,7 +630,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg) msg.readUInt8("unused"); - const int level = static_cast(msg.readUInt8("level")); + const int level = CAST_S32(msg.readUInt8("level")); if (level) dstBeing->setLevel(level); @@ -640,9 +640,9 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg) dstBeing->setActionTime(tick_time); dstBeing->setStunMode(stunMode); - dstBeing->setStatusEffectBlock(0, static_cast( + dstBeing->setStatusEffectBlock(0, CAST_U16( (statusEffects >> 16) & 0xffff)); - dstBeing->setStatusEffectBlock(16, static_cast( + dstBeing->setStatusEffectBlock(16, CAST_U16( statusEffects & 0xffff)); if (dstBeing->getType() == ActorType::Player) @@ -671,7 +671,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg) int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); - statusEffects |= (static_cast(msg.readInt16("option"))) << 16; + statusEffects |= (CAST_U32(msg.readInt16("option"))) << 16; const int16_t job = msg.readInt16("class"); int disguiseId = 0; if (id == localPlayer->getId() && job >= 1000) @@ -790,7 +790,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg) if (serverFeatures->haveMonsterAttackRange() && dstBeing->getType() == ActorType::Monster) { - const int attackRange = static_cast( + const int attackRange = CAST_S32( msg.readUInt8("attack range (was karma)")); dstBeing->setAttackRange(attackRange); } @@ -852,9 +852,9 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg) msg.readUInt8("unknown"); dstBeing->setStunMode(stunMode); - dstBeing->setStatusEffectBlock(0, static_cast( + dstBeing->setStatusEffectBlock(0, CAST_U16( (statusEffects >> 16) & 0xffff)); - dstBeing->setStatusEffectBlock(16, static_cast( + dstBeing->setStatusEffectBlock(16, CAST_U16( statusEffects & 0xffff)); BLOCK_END("BeingRecv::processBeingVisibleOrMove") } @@ -880,7 +880,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg) int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); - statusEffects |= (static_cast(msg.readInt16("option"))) << 16; + statusEffects |= (CAST_U32(msg.readInt16("option"))) << 16; const int16_t job = msg.readInt16("class"); int disguiseId = 0; if (id == localPlayer->getId() && job >= 1000) @@ -993,7 +993,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg) if (serverFeatures->haveMonsterAttackRange() && dstBeing->getType() == ActorType::Monster) { - const int attackRange = static_cast( + const int attackRange = CAST_S32( msg.readUInt8("attack range (was karma)")); dstBeing->setAttackRange(attackRange); } @@ -1044,9 +1044,9 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg) msg.readUInt8("unknown"); dstBeing->setStunMode(stunMode); - dstBeing->setStatusEffectBlock(0, static_cast( + dstBeing->setStatusEffectBlock(0, CAST_U16( (statusEffects >> 16) & 0xffff)); - dstBeing->setStatusEffectBlock(16, static_cast( + dstBeing->setStatusEffectBlock(16, CAST_U16( statusEffects & 0xffff)); BLOCK_END("BeingRecv::processBeingVisibleOrMove") } @@ -1162,7 +1162,7 @@ void BeingRecv::processBeingChangeDirection(Net::MessageIn &msg) msg.readInt16("unused"); const uint8_t dir = Net::MessageIn::fromServerDirection( - static_cast(msg.readUInt8("direction") & 0x0FU)); + CAST_U8(msg.readUInt8("direction") & 0x0FU)); dstBeing->setDirection(dir); if (localPlayer) localPlayer->imitateDirection(dstBeing, dir); @@ -1193,13 +1193,13 @@ void BeingRecv::processPlaterStatusChange(Net::MessageIn &msg) const uint16_t stunMode = msg.readInt16("stun mode"); uint32_t statusEffects = msg.readInt16("status effect"); - statusEffects |= (static_cast(msg.readInt16("opt?"))) << 16; + statusEffects |= (CAST_U32(msg.readInt16("opt?"))) << 16; msg.readUInt8("Unused?"); dstBeing->setStunMode(stunMode); - dstBeing->setStatusEffectBlock(0, static_cast( + dstBeing->setStatusEffectBlock(0, CAST_U16( (statusEffects >> 16) & 0xffff)); - dstBeing->setStatusEffectBlock(16, static_cast( + dstBeing->setStatusEffectBlock(16, CAST_U16( statusEffects & 0xffff)); BLOCK_END("BeingRecv::processPlayerStop") } @@ -1342,7 +1342,7 @@ void BeingRecv::processPvpSet(Net::MessageIn &msg) if (dstBeing) { dstBeing->setPvpRank(rank); - dstBeing->setTeamId(static_cast(teamId)); + dstBeing->setTeamId(CAST_U16(teamId)); dstBeing->addToCache(); } } diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index af0d4ad42..d7b92be1a 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -65,7 +65,7 @@ void CharServerHandler::chooseCharacter(Net::Character *const character) mCharSelectDialog = nullptr; createOutPacket(CMSG_CHAR_SELECT); - outMsg.writeInt8(static_cast(mSelectedCharacter->slot), + outMsg.writeInt8(CAST_U8(mSelectedCharacter->slot), "slot"); } @@ -80,12 +80,12 @@ void CharServerHandler::newCharacter(const std::string &name, const int slot, createOutPacket(CMSG_CHAR_CREATE); outMsg.writeString(name, 24, "name"); for (int i = 0; i < 6; i++) - outMsg.writeInt8(static_cast(stats[i]), "stat"); + outMsg.writeInt8(CAST_U8(stats[i]), "stat"); - outMsg.writeInt8(static_cast(slot), "slot"); - outMsg.writeInt8(static_cast(hairColor), "hair color"); + outMsg.writeInt8(CAST_U8(slot), "slot"); + outMsg.writeInt8(CAST_S8(hairColor), "hair color"); outMsg.writeInt8(0, "unused"); - outMsg.writeInt8(static_cast(hairstyle), "hair style"); + outMsg.writeInt8(CAST_S8(hairstyle), "hair style"); outMsg.writeInt8(0, "unused"); } diff --git a/src/net/tmwa/charserverrecv.cpp b/src/net/tmwa/charserverrecv.cpp index 1861f8276..5032e4c39 100644 --- a/src/net/tmwa/charserverrecv.cpp +++ b/src/net/tmwa/charserverrecv.cpp @@ -145,7 +145,7 @@ void CharServerRecv::readPlayerData(Net::MessageIn &msg, tempPlayer->setSprite(SPRITE_HEAD_MID, misc2); character->slot = msg.readUInt8("slot"); - const uint8_t sex = static_cast(msg.readUInt8("gender")); + const uint8_t sex = CAST_U8(msg.readUInt8("gender")); if (serverFeatures->haveCreateCharGender()) tempPlayer->setGender(Being::intToGender(sex)); else @@ -159,7 +159,7 @@ void CharServerRecv::processCharLogin(Net::MessageIn &msg) msg.readInt16("len"); const int slots = msg.readInt16("slots"); if (slots > 0 && slots < 30) - loginData.characterSlots = static_cast(slots); + loginData.characterSlots = CAST_U16(slots); msg.skip(18, "unused"); diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 8ac1cf2e6..61a8054ba 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -59,24 +59,24 @@ void ChatHandler::talk(const std::string &restrict text, createOutPacket(CMSG_CHAT_MESSAGE); // Added + 1 in order to let eAthena parse admin commands correctly - outMsg.writeInt16(static_cast(mes.length() + 4 + 1), "len"); - outMsg.writeString(mes, static_cast(mes.length() + 1), "message"); + outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len"); + outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message"); } void ChatHandler::talkRaw(const std::string &mes) const { createOutPacket(CMSG_CHAT_MESSAGE); - outMsg.writeInt16(static_cast(mes.length() + 4), "len"); - outMsg.writeString(mes, static_cast(mes.length()), "message"); + outMsg.writeInt16(CAST_S16(mes.length() + 4), "len"); + outMsg.writeString(mes, CAST_S32(mes.length()), "message"); } void ChatHandler::privateMessage(const std::string &restrict recipient, const std::string &restrict text) { createOutPacket(CMSG_CHAT_WHISPER); - outMsg.writeInt16(static_cast(text.length() + 28), "len"); + outMsg.writeInt16(CAST_S16(text.length() + 28), "len"); outMsg.writeString(recipient, 24, "recipient nick"); - outMsg.writeString(text, static_cast(text.length()), "message"); + outMsg.writeString(text, CAST_S32(text.length()), "message"); Ea::ChatRecv::mSentWhispers.push(recipient); } @@ -107,7 +107,7 @@ void ChatHandler::sendRaw(const std::string &args) const if (pos != std::string::npos) { str = line.substr(0, pos); - const int16_t id = static_cast(parseNumber(str)); + const int16_t id = CAST_S16(parseNumber(str)); outMsg = new MessageOut(id); outMsg->writeInt16(id, "packet id"); line = line.substr(pos + 1); @@ -115,7 +115,7 @@ void ChatHandler::sendRaw(const std::string &args) const } else { - const int16_t id = static_cast(parseNumber(line)); + const int16_t id = CAST_S16(parseNumber(line)); outMsg = new MessageOut(id); outMsg->writeInt16(id, "packet id"); delete outMsg; @@ -145,17 +145,17 @@ void ChatHandler::processRaw(MessageOut &restrict outMsg, { case 'b': { - outMsg.writeInt8(static_cast(i), "raw"); + outMsg.writeInt8(CAST_U8(i), "raw"); break; } case 'w': { - outMsg.writeInt16(static_cast(i), "raw"); + outMsg.writeInt16(CAST_S16(i), "raw"); break; } case 'l': { - outMsg.writeInt32(static_cast(i), "raw"); + outMsg.writeInt32(CAST_S32(i), "raw"); break; } default: diff --git a/src/net/tmwa/chatrecv.cpp b/src/net/tmwa/chatrecv.cpp index afa8c1573..27ca74a41 100644 --- a/src/net/tmwa/chatrecv.cpp +++ b/src/net/tmwa/chatrecv.cpp @@ -314,7 +314,7 @@ void ChatRecv::processBeingChat(Net::MessageIn &msg) if (being) sender_name = being->getName(); if (sender_name.empty()) - sender_name = "?" + toString(static_cast(beingId)); + sender_name = "?" + toString(CAST_S32(beingId)); } else if (being && sender_name != being->getName() && diff --git a/src/net/tmwa/generalrecv.cpp b/src/net/tmwa/generalrecv.cpp index d8b0c808b..2926f0ef5 100644 --- a/src/net/tmwa/generalrecv.cpp +++ b/src/net/tmwa/generalrecv.cpp @@ -40,7 +40,7 @@ ServerInfo mapServer; void GeneralRecv::processConnectionProblem(Net::MessageIn &msg) { const uint8_t code = msg.readUInt8("flag"); - logger->log("Connection problem: %u", static_cast(code)); + logger->log("Connection problem: %u", CAST_U32(code)); switch (code) { diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index dce3385bf..4f0db44c7 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -124,8 +124,8 @@ void GuildHandler::chat(const std::string &text) const const std::string str = std::string(localPlayer->getName()).append( " : ").append(text); createOutPacket(CMSG_GUILD_MESSAGE); - outMsg.writeInt16(static_cast(str.size() + 4), "len"); - outMsg.writeString(str, static_cast(str.length()), "message"); + outMsg.writeInt16(CAST_U16(str.size() + 4), "len"); + outMsg.writeString(str, CAST_S32(str.length()), "message"); } void GuildHandler::memberList() const diff --git a/src/net/tmwa/guildrecv.cpp b/src/net/tmwa/guildrecv.cpp index 53f8aeb71..4073dd936 100644 --- a/src/net/tmwa/guildrecv.cpp +++ b/src/net/tmwa/guildrecv.cpp @@ -55,7 +55,7 @@ void GuildRecv::processGuildPositionInfo(Net::MessageIn &msg) PlayerInfo::setGuildPositionFlags(GuildPositionFlags::Invite); - Guild *const g = Guild::getGuild(static_cast(guildId)); + Guild *const g = Guild::getGuild(CAST_S16(guildId)); if (!g) return; diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 24d76eab7..fa71484e6 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -73,7 +73,7 @@ void InventoryHandler::equipItem(const Item *const item) const return; createOutPacket(CMSG_PLAYER_EQUIP); - outMsg.writeInt16(static_cast( + outMsg.writeInt16(CAST_S16( item->getInvIndex() + INVENTORY_OFFSET), "index"); outMsg.writeInt16(0, "unused"); } @@ -84,7 +84,7 @@ void InventoryHandler::unequipItem(const Item *const item) const return; createOutPacket(CMSG_PLAYER_UNEQUIP); - outMsg.writeInt16(static_cast( + outMsg.writeInt16(CAST_S16( item->getInvIndex() + INVENTORY_OFFSET), "index"); } @@ -94,7 +94,7 @@ void InventoryHandler::useItem(const Item *const item) const return; createOutPacket(CMSG_PLAYER_INVENTORY_USE); - outMsg.writeInt16(static_cast( + outMsg.writeInt16(CAST_S16( item->getInvIndex() + INVENTORY_OFFSET), "index"); outMsg.writeInt32(item->getId(), "item id"); } @@ -105,9 +105,9 @@ void InventoryHandler::dropItem(const Item *const item, const int amount) const return; createOutPacket(CMSG_PLAYER_INVENTORY_DROP); - outMsg.writeInt16(static_cast( + outMsg.writeInt16(CAST_S16( item->getInvIndex() + INVENTORY_OFFSET), "index"); - outMsg.writeInt16(static_cast(amount), "amount"); + outMsg.writeInt16(CAST_S16(amount), "amount"); } void InventoryHandler::closeStorage() const @@ -124,7 +124,7 @@ void InventoryHandler::moveItem2(const InventoryTypeT source, destination == InventoryType::Storage) { createOutPacket(CMSG_MOVE_TO_STORAGE); - outMsg.writeInt16(static_cast(slot + INVENTORY_OFFSET), + outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index"); outMsg.writeInt32(amount, "amount"); } @@ -132,7 +132,7 @@ void InventoryHandler::moveItem2(const InventoryTypeT source, destination == InventoryType::Inventory) { createOutPacket(CMSG_MOVE_FROM_STORAGE); - outMsg.writeInt16(static_cast(slot + STORAGE_OFFSET), + outMsg.writeInt16(CAST_S16(slot + STORAGE_OFFSET), "index"); outMsg.writeInt32(amount, "amount"); } @@ -161,7 +161,7 @@ int InventoryHandler::convertFromServerSlot(const int serverSlot) const if (serverSlot < 0 || serverSlot > 13) return 0; - return static_cast(EQUIP_CONVERT[serverSlot]); + return CAST_S32(EQUIP_CONVERT[serverSlot]); } void InventoryHandler::selectCart(const BeingId accountId A_UNUSED, diff --git a/src/net/tmwa/inventoryrecv.cpp b/src/net/tmwa/inventoryrecv.cpp index ce59dc274..2ba71b73d 100644 --- a/src/net/tmwa/inventoryrecv.cpp +++ b/src/net/tmwa/inventoryrecv.cpp @@ -380,9 +380,9 @@ void InventoryRecv::processPlayerStorageEquip(Net::MessageIn &msg) logger->log("Index: %d, ID: %d, Type: %d, Identified: %u, " "Qty: %d, Cards: %d, %d, %d, %d, Refine: %u", index, itemId, itemType, - static_cast(identified), amount, + CAST_U32(identified), amount, cards[0], cards[1], cards[2], cards[3], - static_cast(refine)); + CAST_U32(refine)); } Ea::InventoryRecv::mInventoryItems.push_back(Ea::InventoryItem( diff --git a/src/net/tmwa/itemrecv.cpp b/src/net/tmwa/itemrecv.cpp index b9a7d55b1..d7038942d 100644 --- a/src/net/tmwa/itemrecv.cpp +++ b/src/net/tmwa/itemrecv.cpp @@ -38,8 +38,8 @@ void ItemRecv::processItemDropped(Net::MessageIn &msg) const Identified identify = fromInt(msg.readUInt8("identify"), Identified); const int x = msg.readInt16("x"); const int y = msg.readInt16("y"); - const int subX = static_cast(msg.readInt8("sub x")); - const int subY = static_cast(msg.readInt8("sub y")); + const int subX = CAST_S32(msg.readInt8("sub x")); + const int subY = CAST_S32(msg.readInt8("sub y")); const int amount = msg.readInt16("amount"); if (actorManager) @@ -67,8 +67,8 @@ void ItemRecv::processItemVisible(Net::MessageIn &msg) const int x = msg.readInt16("x"); const int y = msg.readInt16("y"); const int amount = msg.readInt16("amount"); - const int subX = static_cast(msg.readInt8("sub x")); - const int subY = static_cast(msg.readInt8("sub y")); + const int subX = CAST_S32(msg.readInt8("sub x")); + const int subY = CAST_S32(msg.readInt8("sub y")); if (actorManager) { diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 21e679b25..c8cf350e7 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -56,10 +56,10 @@ uint16_t MessageIn::readId() { #if SDL_BYTEORDER == SDL_BIG_ENDIAN int16_t swap; - memcpy(&swap, mData + static_cast(mPos), sizeof(int16_t)); + memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t)); value = SDL_Swap16(swap); #else - memcpy(&value, mData + static_cast(mPos), sizeof(int16_t)); + memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t)); #endif } return value; @@ -72,14 +72,14 @@ int16_t MessageIn::readInt16(const char *const str) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN int16_t swap; - memcpy(&swap, mData + static_cast(mPos), sizeof(int16_t)); + memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t)); value = SDL_Swap16(swap); #else - memcpy(&value, mData + static_cast(mPos), sizeof(int16_t)); + memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t)); #endif } - DEBUGLOG2("readInt16: " + toStringPrint(static_cast( - static_cast(value))), + DEBUGLOG2("readInt16: " + toStringPrint(CAST_U32( + CAST_U16(value))), mPos, str); mPos += 2; PacketCounters::incInBytes(2); @@ -93,13 +93,13 @@ int32_t MessageIn::readInt32(const char *const str) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap; - memcpy(&swap, mData + static_cast(mPos), sizeof(int32_t)); + memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int32_t)); value = SDL_Swap32(swap); #else - memcpy(&value, mData + static_cast(mPos), sizeof(int32_t)); + memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int32_t)); #endif } - DEBUGLOG2("readInt32: " + toStringPrint(static_cast(value)), + DEBUGLOG2("readInt32: " + toStringPrint(CAST_U32(value)), mPos, str); mPos += 4; PacketCounters::incInBytes(4); @@ -118,13 +118,13 @@ int64_t MessageIn::readInt64(const char *const str) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN int64_t swap; - memcpy(&swap, mData + static_cast(mPos), sizeof(int64_t)); + memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int64_t)); value = SDL_Swap64(swap); #else - memcpy(&value, mData + static_cast(mPos), sizeof(int64_t)); + memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int64_t)); #endif } - DEBUGLOG2("readInt64: " + toStringPrint(static_cast(value)), + DEBUGLOG2("readInt64: " + toStringPrint(CAST_U32(value)), mPos, str); mPos += 8; PacketCounters::incInBytes(8); diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index a2c0770b7..c0ac1ef03 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -40,26 +40,26 @@ MessageOut::MessageOut(const int16_t id) : mNetwork(TmwAthena::Network::instance()) { mNetwork->fixSendBuffer(); - mData = mNetwork->mOutBuffer + static_cast(mNetwork->mOutSize); + mData = mNetwork->mOutBuffer + CAST_SIZE(mNetwork->mOutSize); } void MessageOut::expand(const size_t bytes) { - mNetwork->mOutSize += static_cast(bytes); - PacketCounters::incOutBytes(static_cast(bytes)); + mNetwork->mOutSize += CAST_U32(bytes); + PacketCounters::incOutBytes(CAST_S32(bytes)); } void MessageOut::writeInt16(const int16_t value, const char *const str) { - DEBUGLOG2("writeInt16: " + toStringPrint(static_cast( - static_cast(value))), + DEBUGLOG2("writeInt16: " + toStringPrint(CAST_U32( + CAST_U16(value))), mPos, str); expand(2); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int16_t swap = SDL_Swap16(value); - memcpy(mData + static_cast(mPos), &swap, sizeof(int16_t)); + memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int16_t)); #else - memcpy(mData + static_cast(mPos), &value, sizeof(int16_t)); + memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int16_t)); #endif mPos += 2; PacketCounters::incOutBytes(2); @@ -67,14 +67,14 @@ void MessageOut::writeInt16(const int16_t value, const char *const str) void MessageOut::writeInt32(const int32_t value, const char *const str) { - DEBUGLOG2("writeInt32: " + toStringPrint(static_cast(value)), + DEBUGLOG2("writeInt32: " + toStringPrint(CAST_U32(value)), mPos, str); expand(4); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap = SDL_Swap32(value); - memcpy(mData + static_cast(mPos), &swap, sizeof(int32_t)); + memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int32_t)); #else - memcpy(mData + static_cast(mPos), &value, sizeof(int32_t)); + memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int32_t)); #endif mPos += 4; PacketCounters::incOutBytes(4); @@ -85,9 +85,9 @@ void MessageOut::writeBeingId(const BeingId value, const char *const str) writeInt32(toInt(value, int32_t), str); } -#define LOBYTE(w) (static_cast(w)) -#define HIBYTE(w) (static_cast(( \ -static_cast(w)) >> 8U)) +#define LOBYTE(w) (CAST_U8(w)) +#define HIBYTE(w) (CAST_U8(( \ +CAST_U16(w)) >> 8U)) void MessageOut::writeCoordinates(const uint16_t x, const uint16_t y, @@ -95,10 +95,10 @@ void MessageOut::writeCoordinates(const uint16_t x, const char *const str) { DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u", - static_cast(x), static_cast(y), - static_cast(direction)), mPos, str); + CAST_U32(x), static_cast(y), + CAST_U32(direction)), mPos, str); unsigned char *const data = reinterpret_cast(mData) - + static_cast(mPos); + + CAST_SIZE(mPos); mNetwork->mOutSize += 3; mPos += 3; @@ -108,7 +108,7 @@ void MessageOut::writeCoordinates(const uint16_t x, data[1] = 1; data[2] = 2; data[0] = HIBYTE(temp); - data[1] = static_cast(temp); + data[1] = CAST_U8(temp); temp = y; temp <<= 4; data[1] |= HIBYTE(temp); diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 9be9d34b6..03a842b65 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -156,7 +156,7 @@ bool Network::messageReady() if (mInSize >= 2) { const int msgId = readWord(0); - if (msgId >= 0 && static_cast(msgId) + if (msgId >= 0 && CAST_U32(msgId) < packet_lengths_size) { len = mPackets[msgId].len; @@ -166,7 +166,7 @@ bool Network::messageReady() len = readWord(2); } - const bool ret = (mInSize >= static_cast(len)); + const bool ret = (mInSize >= CAST_U32(len)); SDL_mutexV(mMutexIn); return ret; diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index a3e0ef2c3..ba1c8f7a3 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -100,9 +100,9 @@ void NpcHandler::stringInput(const BeingId npcId, const std::string &value) const { createOutPacket(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(static_cast(value.length() + 9), "len"); + outMsg.writeInt16(CAST_S16(value.length() + 9), "len"); outMsg.writeBeingId(npcId, "npc id"); - outMsg.writeString(value, static_cast(value.length()), "value"); + outMsg.writeString(value, CAST_S32(value.length()), "value"); outMsg.writeInt8(0, "null byte"); } @@ -127,8 +127,8 @@ void NpcHandler::buyItem(const BeingId beingId A_UNUSED, { createOutPacket(CMSG_NPC_BUY_REQUEST); outMsg.writeInt16(8, "len"); - outMsg.writeInt16(static_cast(amount), "amount"); - outMsg.writeInt16(static_cast(itemId), "item id"); + outMsg.writeInt16(CAST_S16(amount), "amount"); + outMsg.writeInt16(CAST_S16(itemId), "item id"); } void NpcHandler::buyItems(std::vector &items A_UNUSED) const @@ -141,9 +141,9 @@ void NpcHandler::sellItem(const BeingId beingId A_UNUSED, { createOutPacket(CMSG_NPC_SELL_REQUEST); outMsg.writeInt16(8, "len"); - outMsg.writeInt16(static_cast( + outMsg.writeInt16(CAST_S16( itemId + INVENTORY_OFFSET), "index"); - outMsg.writeInt16(static_cast(amount), "amount"); + outMsg.writeInt16(CAST_S16(amount), "amount"); } void NpcHandler::sellItems(std::vector &items A_UNUSED) const diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 8c477e9ec..94471e4c3 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -117,8 +117,8 @@ void PartyHandler::kick(const std::string &name) const void PartyHandler::chat(const std::string &text) const { createOutPacket(CMSG_PARTY_MESSAGE); - outMsg.writeInt16(static_cast(text.length() + 4), "len"); - outMsg.writeString(text, static_cast(text.length()), "text"); + outMsg.writeInt16(CAST_S16(text.length() + 4), "len"); + outMsg.writeString(text, CAST_S32(text.length()), "text"); } void PartyHandler::setShareExperience(const PartyShareT share) const @@ -127,8 +127,8 @@ void PartyHandler::setShareExperience(const PartyShareT share) const return; createOutPacket(CMSG_PARTY_SETTINGS); - outMsg.writeInt16(static_cast(share), "share exp"); - outMsg.writeInt16(static_cast(Ea::PartyRecv::mShareItems), + outMsg.writeInt16(CAST_S16(share), "share exp"); + outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareItems), "share items"); } @@ -138,9 +138,9 @@ void PartyHandler::setShareItems(const PartyShareT share) const return; createOutPacket(CMSG_PARTY_SETTINGS); - outMsg.writeInt16(static_cast(Ea::PartyRecv::mShareExp), + outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareExp), "share exp"); - outMsg.writeInt16(static_cast(share), "share items"); + outMsg.writeInt16(CAST_S16(share), "share items"); } void PartyHandler::changeLeader(const std::string &name A_UNUSED) const diff --git a/src/net/tmwa/pethandler.cpp b/src/net/tmwa/pethandler.cpp index 427ec3ba9..1aaf0e710 100644 --- a/src/net/tmwa/pethandler.cpp +++ b/src/net/tmwa/pethandler.cpp @@ -60,7 +60,7 @@ void PetHandler::emote(const uint8_t emoteId, const int petId A_UNUSED) mRandCounter = 1000; chatHandler->talk(strprintf("\302\202\302e%dz%d", - static_cast(emoteId), mRandCounter), GENERAL_CHANNEL); + CAST_S32(emoteId), mRandCounter), GENERAL_CHANNEL); } void PetHandler::catchPet(const Being *const being A_UNUSED) const @@ -98,7 +98,7 @@ void PetHandler::unequip() const void PetHandler::setDirection(const unsigned char type) const { chatHandler->talk(strprintf("\302\202\302d%dg%d", - static_cast(type), tick_time), GENERAL_CHANNEL); + CAST_S32(type), tick_time), GENERAL_CHANNEL); } void PetHandler::startAi(const bool start) const diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index f0ea94947..8f7de1e64 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -70,7 +70,7 @@ void PlayerHandler::increaseAttribute(const AttributesT attr) const if (attr >= Attributes::STR && attr <= Attributes::LUK) { createOutPacket(CMSG_STAT_UPDATE_REQUEST); - outMsg.writeInt16(static_cast(attr), "attribute id"); + outMsg.writeInt16(CAST_S16(attr), "attribute id"); outMsg.writeInt8(1, "increment"); } } @@ -108,9 +108,9 @@ void PlayerHandler::setDestination(const int x, const int y, const int direction) const { createOutPacket(CMSG_PLAYER_CHANGE_DEST); - outMsg.writeCoordinates(static_cast(x), - static_cast(y), - static_cast(direction), "destination"); + outMsg.writeCoordinates(CAST_U16(x), + CAST_U16(y), + CAST_U8(direction), "destination"); } void PlayerHandler::changeAction(const BeingActionT &action) const diff --git a/src/net/tmwa/skillhandler.cpp b/src/net/tmwa/skillhandler.cpp index abd2fd67e..87dc0e189 100644 --- a/src/net/tmwa/skillhandler.cpp +++ b/src/net/tmwa/skillhandler.cpp @@ -42,8 +42,8 @@ void SkillHandler::useBeing(const int id, const int level, const BeingId beingId) const { createOutPacket(CMSG_SKILL_USE_BEING); - outMsg.writeInt16(static_cast(id), "skill id"); - outMsg.writeInt16(static_cast(level), "level"); + outMsg.writeInt16(CAST_S16(id), "skill id"); + outMsg.writeInt16(CAST_S16(level), "level"); outMsg.writeBeingId(beingId, "target id"); } @@ -51,10 +51,10 @@ void SkillHandler::usePos(const int id, const int level, const int x, const int y) const { createOutPacket(CMSG_SKILL_USE_POSITION); - outMsg.writeInt16(static_cast(level), "skill level"); - outMsg.writeInt16(static_cast(id), "skill id"); - outMsg.writeInt16(static_cast(x), "x"); - outMsg.writeInt16(static_cast(y), "y"); + outMsg.writeInt16(CAST_S16(level), "skill level"); + outMsg.writeInt16(CAST_S16(id), "skill id"); + outMsg.writeInt16(CAST_S16(x), "x"); + outMsg.writeInt16(CAST_S16(y), "y"); } void SkillHandler::usePos(const int id, const int level, @@ -62,17 +62,17 @@ void SkillHandler::usePos(const int id, const int level, const std::string &text) const { createOutPacket(CMSG_SKILL_USE_POSITION_MORE); - outMsg.writeInt16(static_cast(level), "skill level"); - outMsg.writeInt16(static_cast(id), "skill id"); - outMsg.writeInt16(static_cast(x), "x"); - outMsg.writeInt16(static_cast(y), "y"); + outMsg.writeInt16(CAST_S16(level), "skill level"); + outMsg.writeInt16(CAST_S16(id), "skill id"); + outMsg.writeInt16(CAST_S16(x), "x"); + outMsg.writeInt16(CAST_S16(y), "y"); outMsg.writeString(text, 80, "text"); } void SkillHandler::useMap(const int id, const std::string &map) const { createOutPacket(CMSG_SKILL_USE_MAP); - outMsg.writeInt16(static_cast(id), "skill id"); + outMsg.writeInt16(CAST_S16(id), "skill id"); outMsg.writeString(map, 16, "map name"); } diff --git a/src/net/tmwa/skillrecv.cpp b/src/net/tmwa/skillrecv.cpp index d79f36422..df914568b 100644 --- a/src/net/tmwa/skillrecv.cpp +++ b/src/net/tmwa/skillrecv.cpp @@ -89,19 +89,19 @@ void SkillRecv::processSkillFailed(Net::MessageIn &msg) msg.readInt16("btype"); const signed char success = msg.readUInt8("success"); const signed char reason = msg.readUInt8("reason"); - if (success != static_cast(SKILL_FAILED) - && bskill == static_cast(BSKILL_EMOTE)) + if (success != CAST_S32(SKILL_FAILED) + && bskill == CAST_S32(BSKILL_EMOTE)) { logger->log("Action: %d/%d", bskill, success); } std::string txt; - if (success == static_cast(SKILL_FAILED) - && skillId == static_cast(SKILL_BASIC)) + if (success == CAST_S32(SKILL_FAILED) + && skillId == CAST_S32(SKILL_BASIC)) { if (localPlayer && - bskill == static_cast(BSKILL_EMOTE) && - reason == static_cast(RFAIL_SKILLDEP)) + bskill == CAST_S32(BSKILL_EMOTE) && + reason == CAST_S32(RFAIL_SKILLDEP)) { localPlayer->stopAdvert(); } diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index 40f737d22..66865740e 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -61,7 +61,7 @@ void TradeHandler::respond(const bool accept) const PlayerInfo::setTrading(Trading_false); createOutPacket(CMSG_TRADE_RESPONSE); - outMsg.writeInt8(static_cast(accept ? 3 : 4), "accept"); + outMsg.writeInt8(CAST_S8(accept ? 3 : 4), "accept"); } void TradeHandler::addItem(const Item *const item, const int amount) const @@ -70,7 +70,7 @@ void TradeHandler::addItem(const Item *const item, const int amount) const return; createOutPacket(CMSG_TRADE_ITEM_ADD_REQUEST); - outMsg.writeInt16(static_cast( + outMsg.writeInt16(CAST_S16( item->getInvIndex() + INVENTORY_OFFSET), "index"); outMsg.writeInt32(amount, "amount"); } -- cgit v1.2.3-60-g2f50