From ef8ef35d28daa3ea7dd542078ac9c0d3f7a9a5e2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 30 Aug 2017 22:51:23 +0300 Subject: Move some variables to better scope. --- src/actions/chat.cpp | 7 +++++-- src/being/being.cpp | 6 +++--- src/gui/gui.cpp | 2 +- src/gui/shortcut/itemshortcut.cpp | 2 +- src/gui/widgets/scrollarea.cpp | 8 ++++---- src/gui/widgets/tabs/chat/whispertab.cpp | 4 ++-- src/gui/widgets/window.cpp | 3 +-- src/gui/windows/chatwindow.cpp | 16 +++++++++------- src/gui/windows/skilldialog.cpp | 8 ++++---- src/input/inputmanager.cpp | 4 +++- src/net/ea/npcrecv.cpp | 4 +++- src/net/eathena/beingrecv.cpp | 9 ++++++--- src/net/eathena/buyingstorerecv.cpp | 9 +++++++-- src/net/eathena/chatrecv.cpp | 9 ++++++++- src/net/eathena/guildrecv.cpp | 17 ++++++++++++++--- src/net/eathena/mailrecv.cpp | 1 + src/net/eathena/npcrecv.cpp | 14 +++++++++++++- src/net/eathena/partyrecv.cpp | 14 +++++++++++++- src/net/eathena/vendingrecv.cpp | 9 +++++++-- src/net/tmwa/beingrecv.cpp | 7 ++++++- src/net/tmwa/chatrecv.cpp | 13 ++++++++----- src/net/tmwa/partyrecv.cpp | 8 +++++++- src/resources/db/itemdb.cpp | 7 +++++-- 23 files changed, 131 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/actions/chat.cpp b/src/actions/chat.cpp index 442597849..307e4556e 100644 --- a/src/actions/chat.cpp +++ b/src/actions/chat.cpp @@ -669,13 +669,16 @@ impHandler(guildNotice) return true; } - const std::string str1 = args.substr(0, 60); std::string str2; if (args.size() > 60) str2 = args.substr(60); const Guild *const guild = localPlayer->getGuild(); if (guild != nullptr) - guildHandler->changeNotice(guild->getId(), str1, str2); + { + guildHandler->changeNotice(guild->getId(), + args.substr(0, 60), + str2); + } return true; } diff --git a/src/being/being.cpp b/src/being/being.cpp index be998d05d..f924c4b47 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -676,9 +676,6 @@ void Being::takeDamage(Being *restrict const attacker, BLOCK_START("Being::takeDamage1") Font *font = nullptr; - const std::string damage = amount != 0 ? toString(amount) : - // TRANSLATORS: dodge or miss message in attacks - type == AttackType::FLEE ? _("dodge") : _("miss"); const Color *color; if (gui != nullptr) @@ -766,6 +763,9 @@ void Being::takeDamage(Being *restrict const attacker, } if (font != nullptr && particleEngine != nullptr) { + const std::string damage = amount != 0 ? toString(amount) : + // TRANSLATORS: dodge or miss message in attacks + type == AttackType::FLEE ? _("dodge") : _("miss"); // Show damage number particleEngine->addTextSplashEffect(damage, mPixelX, diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 67735e2a6..706a5f0b8 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -1257,7 +1257,7 @@ Widget* Gui::getWidgetAt(const int x, const int y) const parent->getAbsolutePosition(parentX, parentY); child = parent->getWidgetAt(x - parentX, y - parentY); parent = swap; - if ((parent != nullptr) && parent->isSelectable()) + if (parent->isSelectable()) selectable = parent; } diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp index 8c091f8c1..f47bfd296 100644 --- a/src/gui/shortcut/itemshortcut.cpp +++ b/src/gui/shortcut/itemshortcut.cpp @@ -121,9 +121,9 @@ void ItemShortcut::save() const { const int itemId = mItems[i] != 0 ? mItems[i] : -1; const int itemColor = toInt(mItemColors[i], int); - const std::string itemData = mItemData[i]; if (itemId != -1) { + const std::string itemData = mItemData[i]; serverConfig.setValue(name + toString(i), itemId); serverConfig.setValue(color + toString(i), itemColor); serverConfig.setValue(data + toString(i), itemData); diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 630f7e9bf..b67ea756a 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -953,7 +953,7 @@ Rect ScrollArea::getVerticalBarDimension() const if (!mVBarVisible) return Rect(0, 0, 0, 0); - const int height = (mVBarVisible && mShowButtons) ? mScrollbarWidth : 0; + const int height = mShowButtons ? mScrollbarWidth : 0; if (mHBarVisible) { return Rect(mDimension.width - mScrollbarWidth, @@ -1122,10 +1122,10 @@ Rect ScrollArea::getDownButtonDimension() const if (!mVBarVisible || !mShowButtons) return Rect(0, 0, 0, 0); - if (mVBarVisible && mHBarVisible) + if (mHBarVisible) { return Rect(mDimension.width - mScrollbarWidth, - mDimension.height - mScrollbarWidth*2, + mDimension.height - mScrollbarWidth * 2, mScrollbarWidth, mScrollbarWidth); } @@ -1150,7 +1150,7 @@ Rect ScrollArea::getRightButtonDimension() const if (!mHBarVisible || !mShowButtons) return Rect(0, 0, 0, 0); - if (mVBarVisible && mHBarVisible) + if (mVBarVisible) { return Rect(mDimension.width - mScrollbarWidth*2, mDimension.height - mScrollbarWidth, diff --git a/src/gui/widgets/tabs/chat/whispertab.cpp b/src/gui/widgets/tabs/chat/whispertab.cpp index d8672b22d..73b73a17c 100644 --- a/src/gui/widgets/tabs/chat/whispertab.cpp +++ b/src/gui/widgets/tabs/chat/whispertab.cpp @@ -71,11 +71,11 @@ void WhisperTab::handleCommandStr(const std::string &msg) const size_t pos = msg.find(' '); const std::string type(msg, 0, pos); - const std::string args(msg, pos == std::string::npos - ? msg.size() : pos + 1); if (type == "me") { + const std::string args(msg, pos == std::string::npos + ? msg.size() : pos + 1); std::string str = textToMe(args); chatHandler->privateMessage(mNick, str); if (localPlayer != nullptr) diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 9d9385f8d..b192bad35 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -642,8 +642,6 @@ void Window::setResizable(const bool r) void Window::widgetResized(const Event &event A_UNUSED) { - const Rect area = getChildrenArea(); - if (mGrip != nullptr) { mGripRect.x = mDimension.width - mGrip->getWidth() - mGripPadding; @@ -652,6 +650,7 @@ void Window::widgetResized(const Event &event A_UNUSED) if (mLayout != nullptr) { + const Rect area = getChildrenArea(); int w = area.width; int h = area.height; mLayout->reflow(w, h); diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index e29212063..25c85638a 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -702,13 +702,15 @@ void ChatWindow::doPresent() const } } - const std::string log = strprintf( - // TRANSLATORS: chat message - _("Present: %s; %d players are present."), - response.c_str(), playercount); - - if (getFocused() != nullptr) - getFocused()->chatLog(log, ChatMsgType::BY_SERVER); + ChatTab *const tab = getFocused(); + if (tab != nullptr) + { + const std::string log = strprintf( + // TRANSLATORS: chat message + _("Present: %s; %d players are present."), + response.c_str(), playercount); + tab->chatLog(log, ChatMsgType::BY_SERVER); + } } void ChatWindow::scroll(const int amount) const diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index b5a49b0ca..20d95a055 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -474,13 +474,13 @@ SkillInfo *SkillDialog::loadSkill(XmlNodeConstPtr node, id += SKILL_VAR_MIN_ID; } - std::string name = XML::langProperty(node, "name", - // TRANSLATORS: skills dialog. skill id - strprintf(_("Skill %d"), id)); - SkillInfo *skill = getSkill(id); if (skill == nullptr) { + std::string name = XML::langProperty(node, "name", + // TRANSLATORS: skills dialog. skill id + strprintf(_("Skill %d"), id)); + skill = new SkillInfo; skill->id = CAST_U32(id); skill->modifiable = Modifiable_false; diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index b0aa18da5..dbe82d5da 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -841,11 +841,13 @@ void InputManager::executeAction(const InputActionT keyNum) restrict2 if (keyNum < InputAction::MOVE_UP || keyNum >= InputAction::TOTAL) return; - InputEvent evt(keyNum, mMask); ActionFuncPtr func = *(inputActionData[CAST_SIZE( keyNum)].action); if (func != nullptr) + { + InputEvent evt(keyNum, mMask); func(evt); + } } bool InputManager::executeChatCommand(const std::string &restrict cmd, diff --git a/src/net/ea/npcrecv.cpp b/src/net/ea/npcrecv.cpp index 16060d6fa..098f07e79 100644 --- a/src/net/ea/npcrecv.cpp +++ b/src/net/ea/npcrecv.cpp @@ -236,9 +236,11 @@ void NpcRecv::processChangeTitle(Net::MessageIn &msg) msg.readInt16("len"); npcHandler->getNpc(msg, NpcAction::Other); mRequestLang = false; - const std::string str = msg.readString(-1, "title"); if (mDialog != nullptr) + { + const std::string str = msg.readString(-1, "title"); mDialog->setCaption(str); + } } } // namespace Ea diff --git a/src/net/eathena/beingrecv.cpp b/src/net/eathena/beingrecv.cpp index ce2b3a581..8d986797b 100644 --- a/src/net/eathena/beingrecv.cpp +++ b/src/net/eathena/beingrecv.cpp @@ -2079,9 +2079,12 @@ void BeingRecv::processSkillCancel(Net::MessageIn &msg) void BeingRecv::processSolveCharName(Net::MessageIn &msg) { const int id = msg.readInt32("char id"); - const std::string name = msg.readString(24, "name"); - if (actorManager != nullptr) - actorManager->addChar(id, name); + if (actorManager == nullptr) + { + msg.readString(24, "name"); + return; + } + actorManager->addChar(id, msg.readString(24, "name")); } void BeingRecv::processGraffiti(Net::MessageIn &msg) diff --git a/src/net/eathena/buyingstorerecv.cpp b/src/net/eathena/buyingstorerecv.cpp index 55c1624f9..bf5d2032b 100644 --- a/src/net/eathena/buyingstorerecv.cpp +++ b/src/net/eathena/buyingstorerecv.cpp @@ -94,10 +94,15 @@ void BuyingStoreRecv::processBuyingStoreOwnItems(Net::MessageIn &msg) void BuyingStoreRecv::processBuyingStoreShowBoard(Net::MessageIn &msg) { const BeingId id = msg.readBeingId("owner id"); - const std::string shopName = msg.readString(80, "shop name"); Being *const dstBeing = actorManager->findBeing(id); if (dstBeing != nullptr) - dstBeing->setBuyBoard(shopName); + { + dstBeing->setBuyBoard(msg.readString(80, "shop name")); + } + else + { + msg.readString(80, "shop name"); + } } void BuyingStoreRecv::processBuyingStoreHideBoard(Net::MessageIn &msg) diff --git a/src/net/eathena/chatrecv.cpp b/src/net/eathena/chatrecv.cpp index d52183962..97f0de803 100644 --- a/src/net/eathena/chatrecv.cpp +++ b/src/net/eathena/chatrecv.cpp @@ -295,9 +295,16 @@ void ChatRecv::processGmChat2(Net::MessageIn &msg) msg.readInt16("font size"); msg.readInt16("font align"); msg.readInt16("font y"); - const std::string chatMsg = msg.readRawString(chatMsgLength, "message"); if (chatWindow != nullptr) + { + const std::string chatMsg = msg.readRawString(chatMsgLength, + "message"); chatWindow->addGlobalMessage(chatMsg); + } + else + { + msg.readRawString(chatMsgLength, "message"); + } } void ChatRecv::processWhisper(Net::MessageIn &msg) diff --git a/src/net/eathena/guildrecv.cpp b/src/net/eathena/guildrecv.cpp index 7f17f57db..d235c23bb 100644 --- a/src/net/eathena/guildrecv.cpp +++ b/src/net/eathena/guildrecv.cpp @@ -377,22 +377,33 @@ void GuildRecv::processGuildSkillInfo(Net::MessageIn &msg) void GuildRecv::processGuildNotice(Net::MessageIn &msg) { - const std::string msg1 = msg.readString(60, "msg1"); - const std::string msg2 = msg.readString(120, "msg2"); if (guildTab != nullptr) { + const std::string msg1 = msg.readString(60, "msg1"); + const std::string msg2 = msg.readString(120, "msg2"); guildTab->chatLog(msg1, ChatMsgType::BY_SERVER); guildTab->chatLog(msg2, ChatMsgType::BY_SERVER); } + else + { + msg.readString(60, "msg1"); + msg.readString(120, "msg2"); + } } void GuildRecv::processGuildInvite(Net::MessageIn &msg) { const int guildId = msg.readInt32("guild id"); - const std::string guildName = msg.readString(24, "guild name"); if (socialWindow != nullptr) + { + const std::string guildName = msg.readString(24, "guild name"); socialWindow->showGuildInvite(guildName, guildId, ""); + } + else + { + msg.readString(24, "guild name"); + } } void GuildRecv::processGuildInviteAck(Net::MessageIn &msg) diff --git a/src/net/eathena/mailrecv.cpp b/src/net/eathena/mailrecv.cpp index 5e5f0939a..b51e418a6 100644 --- a/src/net/eathena/mailrecv.cpp +++ b/src/net/eathena/mailrecv.cpp @@ -123,6 +123,7 @@ void MailRecv::processReadMail(Net::MessageIn &msg) if (!mailWindow) { reportAlways("Mail window not created"); + delete mail; return; } mailWindow->showMessage(mail, itemId != 0 ? 1 : 0); diff --git a/src/net/eathena/npcrecv.cpp b/src/net/eathena/npcrecv.cpp index 875718768..535e57d7c 100644 --- a/src/net/eathena/npcrecv.cpp +++ b/src/net/eathena/npcrecv.cpp @@ -45,6 +45,12 @@ namespace NpcRecv void NpcRecv::processNpcCutin(Net::MessageIn &msg) { Ea::NpcRecv::mRequestLang = false; + if (cutInWindow == nullptr) + { + msg.readString(64, "image name"); + msg.readUInt8("type"); + return; + } const std::string image = msg.readString(64, "image name"); const CutInT cutin = static_cast(msg.readUInt8("type")); if (cutInWindow != nullptr) @@ -112,9 +118,15 @@ void NpcRecv::processNpcSkin(Net::MessageIn &msg) { const int len = msg.readInt16("len"); npcHandler->getNpc(msg, NpcAction::Other); - const std::string skin = msg.readString(len - 8, "skin"); if (Ea::NpcRecv::mDialog != nullptr) + { + const std::string skin = msg.readString(len - 8, "skin"); Ea::NpcRecv::mDialog->setSkin(skin); + } + else + { + msg.readString(len - 8, "skin"); + } } } // namespace EAthena diff --git a/src/net/eathena/partyrecv.cpp b/src/net/eathena/partyrecv.cpp index 2f6482ac1..9ce0dbdce 100644 --- a/src/net/eathena/partyrecv.cpp +++ b/src/net/eathena/partyrecv.cpp @@ -176,9 +176,15 @@ void PartyRecv::processPartyInfo(Net::MessageIn &msg) Ea::taParty->clearMembers(); const int length = msg.readInt16("len"); - const std::string name = msg.readString(24, "party name"); if (Ea::taParty != nullptr) + { + const std::string name = msg.readString(24, "party name"); Ea::taParty->setName(name); + } + else + { + msg.readString(24, "party name"); + } int partySize = 0; int offset = 0; @@ -370,6 +376,12 @@ void PartyRecv::processPartyLeader(Net::MessageIn &msg) void PartyRecv::processPartyInvited(Net::MessageIn &msg) { + if (socialWindow == nullptr) + { + msg.readInt32("party id"); + msg.readString(24, "party name"); + return; + } const int id = msg.readInt32("party id"); const std::string partyName = msg.readString(24, "party name"); diff --git a/src/net/eathena/vendingrecv.cpp b/src/net/eathena/vendingrecv.cpp index 33494fd33..d4f14bc87 100644 --- a/src/net/eathena/vendingrecv.cpp +++ b/src/net/eathena/vendingrecv.cpp @@ -75,10 +75,15 @@ void VendingRecv::processOpenReq(Net::MessageIn &msg) void VendingRecv::processShowBoard(Net::MessageIn &msg) { const BeingId id = msg.readBeingId("owner id"); - const std::string shopName = msg.readString(80, "shop name"); Being *const dstBeing = actorManager->findBeing(id); if (dstBeing != nullptr) - dstBeing->setSellBoard(shopName); + { + dstBeing->setSellBoard(msg.readString(80, "shop name")); + } + else + { + msg.readString(80, "shop name"); + } } void VendingRecv::processHideBoard(Net::MessageIn &msg) diff --git a/src/net/tmwa/beingrecv.cpp b/src/net/tmwa/beingrecv.cpp index 7b37d1438..d73abccc1 100644 --- a/src/net/tmwa/beingrecv.cpp +++ b/src/net/tmwa/beingrecv.cpp @@ -1398,11 +1398,16 @@ void BeingRecv::processIpResponse(Net::MessageIn &msg) Being *const dstBeing = actorManager->findBeing( msg.readBeingId("being id")); - const std::string ip = ipToString(msg.readInt32("ip address")); if (dstBeing != nullptr) + { + const std::string ip = ipToString(msg.readInt32("ip address")); dstBeing->setIp(ip); + } else + { + ipToString(msg.readInt32("ip address")); DEBUGLOGSTR("invisible player?"); + } BLOCK_END("BeingRecv::processIpResponse") } diff --git a/src/net/tmwa/chatrecv.cpp b/src/net/tmwa/chatrecv.cpp index d0ac861df..afa501004 100644 --- a/src/net/tmwa/chatrecv.cpp +++ b/src/net/tmwa/chatrecv.cpp @@ -129,12 +129,15 @@ void ChatRecv::processGmChat(Net::MessageIn &msg) return; } - std::string chatMsg = msg.readRawString(chatMsgLength, "message"); - - if (localChatTab != nullptr) + if (localChatTab != nullptr && + chatWindow != nullptr) + { + std::string chatMsg = msg.readRawString(chatMsgLength, "message"); + chatWindow->addGlobalMessage(chatMsg); + } + else { - if (chatWindow != nullptr) - chatWindow->addGlobalMessage(chatMsg); + msg.readRawString(chatMsgLength, "message"); } BLOCK_END("ChatRecv::processChat") } diff --git a/src/net/tmwa/partyrecv.cpp b/src/net/tmwa/partyrecv.cpp index 819b891d3..b25a501c8 100644 --- a/src/net/tmwa/partyrecv.cpp +++ b/src/net/tmwa/partyrecv.cpp @@ -224,7 +224,6 @@ void PartyRecv::processPartyInviteResponse(Net::MessageIn &msg) void PartyRecv::processPartyInvited(Net::MessageIn &msg) { const BeingId id = msg.readBeingId("account id"); - const std::string partyName = msg.readString(24, "party name"); std::string nick; if (actorManager != nullptr) @@ -238,7 +237,14 @@ void PartyRecv::processPartyInvited(Net::MessageIn &msg) } if (socialWindow != nullptr) + { + const std::string partyName = msg.readString(24, "party name"); socialWindow->showPartyInvite(partyName, nick, 0); + } + else + { + msg.readString(24, "party name"); + } } void PartyRecv::processPartyMove(Net::MessageIn &msg) diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index a1395142a..08055e404 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -991,16 +991,19 @@ static void loadSpriteRef(ItemInfo *const itemInfo, XmlNodeConstPtr node) static void loadSoundRef(ItemInfo *const itemInfo, XmlNodeConstPtr node) { - if ((node == nullptr) || !XmlHaveChildContent(node)) + if (node == nullptr || + !XmlHaveChildContent(node)) + { return; + } const std::string event = XML::getProperty(node, "event", ""); - const std::string filename = XmlChildContent(node); const int delay = XML::getProperty(node, "delay", 0); const std::map::const_iterator it = mSoundNames.find(event); if (it != mSoundNames.end()) { + const std::string filename = XmlChildContent(node); itemInfo->addSound((*it).second, filename, delay); } else -- cgit v1.2.3-60-g2f50