diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-22 13:02:26 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-22 14:32:45 +0100 |
commit | 81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08 (patch) | |
tree | e2619b16a5331e5760d94be389d0a3a01427293f | |
parent | d047db79f7034e0e75a85a656d18f40716d197b9 (diff) | |
download | mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.gz mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.bz2 mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.xz mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.zip |
General code cleanups
* Use default member initializers
* Use range-based loops
* Don't use 'else' after 'return'
* Removed some unused includes
* Construct empty strings with std::string() instead of ""
* Clear strings with .clear() instead of assigning ""
* Check whether strings are empty with .empty() instead of comparing to ""
* Removed redundant initializations
75 files changed, 249 insertions, 362 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 67b086ca..db9f274f 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -321,13 +321,10 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, { clear(); - SpriteRefs it, it_end; - - for (it = display.sprites.begin(), it_end = display.sprites.end(); - it != it_end; it++) + for (const auto &sprite : display.sprites) { - std::string file = paths.getStringValue("sprites") + it->sprite; - int variant = it->variant; + std::string file = paths.getStringValue("sprites") + sprite.sprite; + int variant = sprite.variant; addSprite(AnimatedSprite::load(file, variant)); } @@ -359,11 +356,9 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, //setup particle effects if (Particle::enabled) { - std::list<std::string>::const_iterator it, it_end; - for (it = display.particles.begin(), it_end = display.particles.end(); - it != it_end; it++) + for (const auto &particle : display.particles) { - Particle *p = particleEngine->addEffect(*it, 0, 0); + Particle *p = particleEngine->addEffect(particle, 0, 0); controlParticle(p); } } diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 0ecc731d..75e3fcc2 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -29,7 +29,7 @@ class FindBeingFunctor { public: - bool operator() (ActorSprite *actor) + bool operator() (ActorSprite *actor) const { if (actor->getType() == ActorSprite::FLOOR_ITEM) return false; @@ -37,7 +37,7 @@ class FindBeingFunctor if (!game) return false; - auto* b = static_cast<Being*>(actor); + auto *b = static_cast<Being*>(actor); uint16_t other_y = y + ((b->getType() == ActorSprite::NPC) ? 1 : 0); const Vector &pos = b->getPosition(); @@ -50,7 +50,7 @@ class FindBeingFunctor uint16_t x, y; ActorSprite::Type type; -} beingFinder; +}; class PlayerNamesLister : public AutoCompleteLister { @@ -63,7 +63,7 @@ class PlayerNamesLister : public AutoCompleteLister continue; auto *being = static_cast<Being *>(actor); - if (being->getType() == Being::PLAYER && being->getName() != "") + if (being->getType() == Being::PLAYER && !being->getName().empty()) names.push_back(being->getName()); } } @@ -82,8 +82,7 @@ class PlayerNPCNamesLister : public AutoCompleteLister auto *being = static_cast<Being *>(actor); if ((being->getType() == Being::PLAYER || - being->getType() == Being::NPC) && - being->getName() != "") + being->getType() == Being::NPC) && !being->getName().empty()) names.push_back(being->getName()); } } @@ -157,12 +156,12 @@ Being *ActorSpriteManager::findBeing(int id) const Being *ActorSpriteManager::findBeing(int x, int y, ActorSprite::Type type) const { + FindBeingFunctor beingFinder; beingFinder.x = x; beingFinder.y = y; beingFinder.type = type; - auto it = find_if(mActors.begin(), mActors.end(), - beingFinder); + auto it = find_if(mActors.begin(), mActors.end(), beingFinder); return (it == mActors.end()) ? nullptr : static_cast<Being*>(*it); } @@ -355,7 +354,7 @@ void ActorSpriteManager::updatePlayerNames() continue; auto *being = static_cast<Being *>(actor); - if (being->getType() == ActorSprite::PLAYER && being->getName() != "") + if (being->getType() == ActorSprite::PLAYER && !being->getName().empty()) being->updateName(); } } diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index a9138e36..61f14550 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -31,19 +31,10 @@ #include <cassert> AnimatedSprite::AnimatedSprite(SpriteDef *sprite): - mDirection(DIRECTION_DOWN), - mLastTime(0), - mFrameIndex(0), - mFrameTime(0), - mSprite(sprite), - mAction(nullptr), - mAnimation(nullptr), - mFrame(nullptr) + mSprite(sprite) { assert(mSprite); - mAlpha = 1.0f; - // Take possession of the sprite mSprite->incRef(); @@ -203,18 +194,16 @@ int AnimatedSprite::getDuration() const int AnimatedSprite::getWidth() const { - if (mFrame) - return mFrame->image ? mFrame->image->getWidth() : 0; - else - return 0; + if (mFrame && mFrame->image) + return mFrame->image->getWidth(); + return 0; } int AnimatedSprite::getHeight() const { - if (mFrame) - return mFrame->image ? mFrame->image->getHeight() : 0; - else - return 0; + if (mFrame && mFrame->image) + return mFrame->image->getHeight(); + return 0; } int AnimatedSprite::getOffsetX() const diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 67d3f300..f2e7a9ff 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -24,7 +24,6 @@ #include "sprite.h" -#include <map> #include <string> class Animation; @@ -60,7 +59,7 @@ class AnimatedSprite : public Sprite bool update(int time) override; - bool draw(Graphics* graphics, int posX, int posY) const override; + bool draw(Graphics *graphics, int posX, int posY) const override; int getWidth() const override; @@ -74,9 +73,6 @@ class AnimatedSprite : public Sprite bool setDirection(SpriteDirection direction) override; - int getNumberOfLayers() - { return 1; } - virtual bool drawnWhenBehind() const { return true; } @@ -85,16 +81,16 @@ class AnimatedSprite : public Sprite private: bool updateCurrentAnimation(unsigned int dt); - SpriteDirection mDirection; /**< The sprite direction. */ - int mLastTime; /**< The last time update was called. */ + SpriteDirection mDirection = DIRECTION_DOWN; /**< The sprite direction. */ + int mLastTime = 0; /**< The last time update was called. */ - int mFrameIndex; /**< The index of the current frame. */ - int mFrameTime; /**< The time since start of frame. */ + int mFrameIndex = 0; /**< The index of the current frame. */ + int mFrameTime = 0; /**< The time since start of frame. */ - SpriteDef *mSprite; /**< The sprite definition. */ - Action *mAction; /**< The currently active action. */ - Animation *mAnimation; /**< The currently active animation. */ - Frame *mFrame; /**< The currently active frame. */ + SpriteDef *mSprite; /**< The sprite definition. */ + Action *mAction = nullptr; /**< The currently active action. */ + Animation *mAnimation = nullptr; /**< The currently active animation. */ + Frame *mFrame = nullptr; /**< The currently active frame. */ }; #endif diff --git a/src/avatar.h b/src/avatar.h index bbae9044..29fc8c56 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -27,12 +27,12 @@ class Avatar { public: - Avatar(const std::string &name = ""); + Avatar(const std::string &name = std::string()); /** * Returns the avatar's name. */ - std::string getName() const { return mName; } + const std::string &getName() const { return mName; } /** * Set the avatar's name. diff --git a/src/being.h b/src/being.h index 1c3e250d..4fdef2c5 100644 --- a/src/being.h +++ b/src/being.h @@ -264,7 +264,8 @@ class Being : public ActorSprite, public EventListener void setSpriteID(unsigned int slot, int id); - void setSpriteColor(unsigned int slot, const std::string &color = ""); + void setSpriteColor(unsigned int slot, + const std::string &color = std::string()); /** * Get the number of layers used to draw the being diff --git a/src/client.cpp b/src/client.cpp index 705cfdc0..506ad692 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -880,7 +880,7 @@ int Client::exec() case STATE_REGISTER_ATTEMPT: logger->log("Username is %s", loginData.username.c_str()); Net::getLoginHandler()->registerAccount(&loginData); - loginData.password = ""; + loginData.password.clear(); break; case STATE_CHANGEPASSWORD: @@ -900,8 +900,8 @@ int Client::exec() showOkDialog(_("Password Change"), _("Password changed successfully!"), STATE_CHAR_SELECT); - loginData.password = ""; - loginData.newPassword = ""; + loginData.password.clear(); + loginData.newPassword.clear(); break; case STATE_CHANGEEMAIL: @@ -1317,7 +1317,7 @@ void Client::accountLogin(LoginData *loginData) Net::getLoginHandler()->loginAccount(loginData); // Clear the password, avoids auto login when returning to login - loginData->password = ""; + loginData->password.clear(); // TODO This is not the best place to save the config, but at least better // than the login gui window diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index c35e9ee3..01975d80 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -333,8 +333,8 @@ void CommandHandler::handleWho(const std::string &args, ChatTab *tab) void CommandHandler::handleMsg(const std::string &args, ChatTab *tab) { - std::string recvnick = ""; - std::string msg = ""; + std::string recvnick; + std::string msg; if (args.substr(0, 1) == "\"") { @@ -358,7 +358,7 @@ void CommandHandler::handleMsg(const std::string &args, ChatTab *tab) else { recvnick = std::string(args); - msg = ""; + msg.clear(); } } @@ -412,7 +412,7 @@ void CommandHandler::handleJoin(const std::string &args, ChatTab *tab) { std::string::size_type pos = args.find(' '); std::string name(args, 0, pos); - std::string password(args, pos+1); + std::string password(args, pos + 1); tab->chatLog(strprintf(_("Requesting to join channel %s."), name.c_str())); Net::getChatHandler()->enterChannel(name, password); } @@ -425,21 +425,17 @@ void CommandHandler::handleListChannels(const std::string &args, ChatTab *tab) void CommandHandler::handleCreateParty(const std::string &args, ChatTab *tab) { if (args.empty()) - { tab->chatLog(_("Party name is missing."), BY_SERVER); - } else - { Net::getPartyHandler()->create(args); - } } void CommandHandler::handleParty(const std::string &args, ChatTab *tab) { - if (args != "") - Net::getPartyHandler()->invite(args); - else + if (args.empty()) tab->chatLog(_("Please specify a name."), BY_SERVER); + else + Net::getPartyHandler()->invite(args); } void CommandHandler::handleMe(const std::string &args, ChatTab *tab) diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 2ab911fa..68cdc095 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -29,16 +29,8 @@ #include <SDL.h> -CompoundSprite::CompoundSprite(): - mImage(nullptr), - mAlphaImage(nullptr), - mWidth(0), - mHeight(0), - mOffsetX(0), - mOffsetY(0), - mNeedsRedraw(false) +CompoundSprite::CompoundSprite() { - mAlpha = 1.0f; } CompoundSprite::~CompoundSprite() @@ -54,10 +46,9 @@ bool CompoundSprite::reset() { bool ret = false; - SpriteIterator it, it_end; - for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; it++) - if (*it) - ret |= (*it)->reset(); + for (auto sprite : mSprites) + if (sprite) + ret |= sprite->reset(); mNeedsRedraw |= ret; return ret; @@ -67,10 +58,9 @@ bool CompoundSprite::play(std::string action) { bool ret = false; - SpriteIterator it, it_end; - for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; it++) - if (*it) - ret |= (*it)->play(action); + for (auto sprite : mSprites) + if (sprite) + ret |= sprite->play(action); mNeedsRedraw |= ret; return ret; @@ -80,10 +70,9 @@ bool CompoundSprite::update(int time) { bool ret = false; - SpriteIterator it, it_end; - for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; it++) - if (*it) - ret |= (*it)->update(time); + for (auto sprite : mSprites) + if (sprite) + ret |= sprite->update(time); mNeedsRedraw |= ret; return ret; @@ -104,7 +93,8 @@ bool CompoundSprite::draw(Graphics *graphics, int posX, int posY) const { return graphics->drawImage(mImage, posX, posY); } - else if (mAlpha && mAlphaImage) + + if (mAlpha && mAlphaImage) { if (mAlphaImage->getAlpha() != mAlpha) mAlphaImage->setAlpha(mAlpha); @@ -112,18 +102,14 @@ bool CompoundSprite::draw(Graphics *graphics, int posX, int posY) const return graphics->drawImage(mAlphaImage, posX, posY); } - else + + for (auto sprite : mSprites) { - SpriteConstIterator it, it_end; - for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; it++) + if (sprite) { - Sprite *s = *it; - if (s) - { - if (s->getAlpha() != mAlpha) - s->setAlpha(mAlpha); - s->draw(graphics, posX - s->getWidth() / 2, posY - s->getHeight()); - } + if (sprite->getAlpha() != mAlpha) + sprite->setAlpha(mAlpha); + sprite->draw(graphics, posX - sprite->getWidth() / 2, posY - sprite->getHeight()); } } @@ -139,10 +125,9 @@ bool CompoundSprite::setDirection(SpriteDirection direction) { bool ret = false; - SpriteIterator it, it_end; - for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; it++) - if (*it) - ret |= (*it)->setDirection(direction); + for (auto sprite : mSprites) + if (sprite) + ret |= sprite->setDirection(direction); mNeedsRedraw |= ret; return ret; @@ -152,14 +137,14 @@ int CompoundSprite::getNumberOfLayers() const { if (mImage || mAlphaImage) return 1; - else - return size(); + + return size(); } bool CompoundSprite::drawnWhenBehind() const { // For now, just draw actors with only one layer when obscured - return (getNumberOfLayers() == 1); + return getNumberOfLayers() == 1; } void CompoundSprite::addSprite(Sprite *sprite) @@ -174,8 +159,7 @@ void CompoundSprite::setSprite(int layer, Sprite *sprite) if (mSprites.at(layer) == sprite) return; - if (mSprites.at(layer)) - delete mSprites.at(layer); + delete mSprites.at(layer); mSprites[layer] = sprite; mNeedsRedraw = true; } @@ -214,10 +198,9 @@ void CompoundSprite::ensureSize(size_t layerCount) int CompoundSprite::getDuration() const { int duration = 0; - SpriteConstIterator it, it_end; - for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; it++) - if ((*it) && (*it)->getDuration() > duration) - duration = (*it)->getDuration(); + for (auto sprite : mSprites) + if (sprite && sprite->getDuration() > duration) + duration = sprite->getDuration(); return duration; } diff --git a/src/compoundsprite.h b/src/compoundsprite.h index e5b41973..7c91eb73 100644 --- a/src/compoundsprite.h +++ b/src/compoundsprite.h @@ -95,13 +95,13 @@ private: void redraw() const; - mutable Image *mImage; - mutable Image *mAlphaImage; + mutable Image *mImage = nullptr; + mutable Image *mAlphaImage = nullptr; - mutable int mWidth, mHeight; - mutable int mOffsetX, mOffsetY; + mutable int mWidth = 0, mHeight = 0; + mutable int mOffsetX = 0, mOffsetY = 0; - mutable bool mNeedsRedraw; + mutable bool mNeedsRedraw = false; std::vector<Sprite*> mSprites; }; diff --git a/src/configuration.cpp b/src/configuration.cpp index 74104ec6..f0972052 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -164,7 +164,7 @@ int Configuration::getIntValue(const std::string &key) const std::string Configuration::getStringValue(const std::string &key) const { - std::string defaultValue = ""; + std::string defaultValue; auto iter = mOptions.find(key); if (iter == mOptions.end()) { diff --git a/src/game.cpp b/src/game.cpp index 90721224..ea8cbae3 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -298,14 +298,14 @@ static bool saveScreenshot() logger->log("Directory %s doesn't exist and can't be created! " "Setting screenshot directory to home.", screenshotDirectory.c_str()); - screenshotDirectory = std::string(PHYSFS_getUserDir()); + screenshotDirectory = PHYSFS_getUserDir(); } do { screenshotCount++; - filenameSuffix.str(""); - filename.str(""); + filenameSuffix.str(std::string()); + filename.str(std::string()); filename << screenshotDirectory << "/"; filenameSuffix << branding.getValue("appShort", "Mana") << "_Screenshot_" << screenshotCount << ".png"; diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index 56faed39..9cb585db 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -53,9 +53,7 @@ BeingPopup::BeingPopup(): add(mBeingParty); } -BeingPopup::~BeingPopup() -{ -} +BeingPopup::~BeingPopup() = default; void BeingPopup::show(int x, int y, Being *b) { @@ -84,7 +82,7 @@ void BeingPopup::show(int x, int y, Being *b) } else { - mBeingParty->setCaption(""); + mBeingParty->setCaption(std::string()); setContentSize(minWidth + 10, height + 10); } diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 8cec4279..fd27c89c 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -71,7 +71,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): updateHair(); - mNameField = new TextField(""); + mNameField = new TextField(std::string()); mNameLabel = new Label(_("Name:")); mNextHairColorButton = new Button("", "nextcolor", this); diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 02a89ff2..4bd712f6 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -345,9 +345,9 @@ CharacterDisplay::CharacterDisplay(CharSelectDialog *charSelectDialog): mPlayerBox(new PlayerBox) { mButton = new Button("", "go", charSelectDialog); - mName = new Label(""); - mLevel = new Label(""); - mMoney = new Label(""); + mName = new Label(std::string()); + mLevel = new Label(std::string()); + mMoney = new Label(std::string()); mDelete = new Button(_("Delete"), "delete", charSelectDialog); diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index e1bbed5f..d51c3a25 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -22,18 +22,14 @@ #include "chatwindow.h" #include "actorspritemanager.h" -#include "channel.h" #include "channelmanager.h" #include "configuration.h" #include "localplayer.h" -#include "party.h" #include "playerrelations.h" #include "gui/recorder.h" #include "gui/setup.h" -#include "gui/sdlinput.h" -#include "gui/widgets/channeltab.h" #include "gui/widgets/chattab.h" #include "gui/widgets/itemlinkhandler.h" #include "gui/widgets/layout.h" @@ -45,7 +41,6 @@ #include "net/chathandler.h" #include "net/net.h" -#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -199,7 +194,7 @@ void ChatWindow::action(const gcn::ActionEvent &event) chatInput(message); // Clear the text from the chat input - mChatInput->setText(""); + mChatInput->setText(std::string()); } if (message.empty() || !mReturnToggles) @@ -294,7 +289,7 @@ void ChatWindow::chatInput(const std::string &msg) void ChatWindow::doPresent() { - std::string response = ""; + std::string response; int playercount = 0; for (auto actor : actorSpriteManager->getAll()) diff --git a/src/gui/connectiondialog.cpp b/src/gui/connectiondialog.cpp index 963005cf..2ff68a15 100644 --- a/src/gui/connectiondialog.cpp +++ b/src/gui/connectiondialog.cpp @@ -32,7 +32,7 @@ ConnectionDialog::ConnectionDialog(const std::string &text, State cancelState): - Window(""), + Window(std::string()), mCancelState(cancelState) { setTitleBarHeight(0); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 43d84f61..047e4170 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -59,12 +59,12 @@ public: mFPSText = _("%d FPS"); } - mFPSLabel = new Label(""); - mMusicFileLabel = new Label(""); - mMapLabel = new Label(""); - mMinimapLabel = new Label(""); - mTileMouseLabel = new Label(""); - mParticleCountLabel = new Label(""); + mFPSLabel = new Label(std::string()); + mMusicFileLabel = new Label(std::string()); + mMapLabel = new Label(std::string()); + mMinimapLabel = new Label(std::string()); + mTileMouseLabel = new Label(std::string()); + mParticleCountLabel = new Label(std::string()); LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 7d6cc618..4a940254 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -73,7 +73,7 @@ Minimap::~Minimap() void Minimap::setMap(Map *map) { // Set the title for the Minimap - std::string caption = ""; + std::string caption; std::string minimapName; if (map) diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 13e1ac0d..0ad9e959 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -106,7 +106,7 @@ NpcDialog::NpcDialog(int npcId) mItemList->setVisible(true); // Setup string input box - mTextField = new TextField(""); + mTextField = new TextField(std::string()); mTextField->setVisible(true); // Setup int input box @@ -211,7 +211,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) } else if (mActionState == NPC_ACTION_INPUT) { - std::string printText = ""; // Text that will get printed in the textbox + std::string printText; // Text that will get printed in the textbox if (mInputState == NPC_INPUT_LIST) { @@ -243,7 +243,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) } if (!mLogInteraction) - setText(""); + setText(std::string()); } else if (event.getId() == "reset") { @@ -569,7 +569,7 @@ void NpcEventListener::event(Event::Channel channel, } catch (BadEvent) { - dialog->textRequest(""); + dialog->textRequest(std::string()); } } else if (event.getType() == Event::Next) diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index fc0325a4..36fda2b1 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -124,7 +124,7 @@ class NpcDialog : public Window, /** * Requests a text string from the user. */ - void textRequest(const std::string &defaultText = ""); + void textRequest(const std::string &defaultText = std::string()); bool isInputFocused() const; diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index d1e060f0..0c37af19 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -118,7 +118,7 @@ void OutfitWindow::save() } config.setValue("Outfit" + toString(o), outfitStr); config.setValue("OutfitUnequip" + toString(o), mItemsUnequip[o]); - outfitStr = ""; + outfitStr.clear(); } } diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index 566b160c..07bc5fcd 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -115,5 +115,5 @@ void Recorder::setRecordingFile(const std::string &msg) void Recorder::action(const gcn::ActionEvent &event) { - setRecordingFile(""); + setRecordingFile(std::string()); } diff --git a/src/gui/register.cpp b/src/gui/register.cpp index e394e59b..b57ee975 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -209,8 +209,8 @@ void RegisterDialog::action(const gcn::ActionEvent &event) else if (error == 2) { // Reset password confirmation - mPasswordField->setText(""); - mConfirmField->setText(""); + mPasswordField->setText(std::string()); + mConfirmField->setText(std::string()); mWrongDataNoticeListener->setTarget(this->mPasswordField); } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 9862ee11..69420496 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -169,7 +169,7 @@ Setup_Colors::Setup_Colors() : place(3, 11, mGradDelaySlider); place(5, 11, mGradDelayText).setPadding(1); - mGradTypeText->setCaption(""); + mGradTypeText->setCaption(std::string()); } Setup_Colors::~Setup_Colors() diff --git a/src/gui/setup_interface.cpp b/src/gui/setup_interface.cpp index 619a250c..3697285c 100644 --- a/src/gui/setup_interface.cpp +++ b/src/gui/setup_interface.cpp @@ -113,7 +113,7 @@ Setup_Interface::Setup_Interface(): mPickupParticleCheckBox(new CheckBox(_("as particle"), mPickupParticleEnabled)), mSpeechSlider(new Slider(0, 3)), - mSpeechLabel(new Label("")), + mSpeechLabel(new Label(std::string())), mAlphaSlider(new Slider(0.2, 1.0)), mFontSize(config.getIntValue("fontSize")) { diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 1352aa53..6c902bb7 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -22,7 +22,6 @@ #ifndef GUI_SETUP_VIDEO_H #define GUI_SETUP_VIDEO_H -#include "being.h" #include "guichanfwd.h" #include "gui/widgets/setuptab.h" diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index 26f1e928..e13dcd74 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -21,8 +21,6 @@ #include "gui/shortcutwindow.h" -#include "configuration.h" - #include "gui/setup.h" #include "gui/widgets/layout.h" diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 6ec7f011..96a57e54 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -333,7 +333,7 @@ void SkillDialog::loadSkills() auto *skill = new SkillInfo; skill->id = 1; skill->name = "basic"; - skill->setIcon(""); + skill->setIcon(std::string()); skill->modifiable = true; skill->visible = true; skill->model = model; diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 3fda9aa0..96a9c389 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -360,7 +360,7 @@ SocialWindow::~SocialWindow() mPartyAcceptDialog->scheduleDelete(); mPartyAcceptDialog = nullptr; - mPartyInviter = ""; + mPartyInviter.clear(); } delete mCreatePopup; } @@ -445,7 +445,7 @@ void SocialWindow::action(const gcn::ActionEvent &event) Net::getPartyHandler()->inviteResponse(mPartyInviter, false); } - mPartyInviter = ""; + mPartyInviter.clear(); mPartyAcceptDialog = nullptr; } else if (event.getSource() == mGuildAcceptDialog) diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h index 495d9b54..7ffcec78 100644 --- a/src/gui/socialwindow.h +++ b/src/gui/socialwindow.h @@ -70,7 +70,7 @@ public: void showGuildCreate(); void showPartyInvite(const std::string &inviter, - const std::string &partyName = ""); + const std::string &partyName = std::string()); void showPartyCreate(); diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp index cf237d5a..7094da26 100644 --- a/src/gui/tradewindow.cpp +++ b/src/gui/tradewindow.cpp @@ -165,7 +165,7 @@ void TradeWindow::reset() mOkMe = false; setMoney(0); mMoneyField->setEnabled(true); - mMoneyField->setText(""); + mMoneyField->setText(std::string()); mAddButton->setEnabled(true); mMoneyChangeButton->setEnabled(true); setStatus(PREPARING); @@ -219,7 +219,7 @@ void TradeWindow::setStatus(Status s) break; case PROPOSING: mOkButton->setCaption(CAPTION_CONFIRMED); - mOkButton->setActionEventId(""); + mOkButton->setActionEventId(std::string()); break; case ACCEPTING: mOkButton->setCaption(CAPTION_ACCEPT); @@ -227,7 +227,7 @@ void TradeWindow::setStatus(Status s) break; case ACCEPTED: mOkButton->setCaption(CAPTION_ACCEPTED); - mOkButton->setActionEventId(""); + mOkButton->setActionEventId(std::string()); break; default: break; diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 728b2464..2861f973 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -101,7 +101,7 @@ std::vector<UpdateFile> loadTxtFile(const std::string &fileName) thisFile.hash = hash; thisFile.type = "data"; thisFile.required = true; - thisFile.desc = ""; + thisFile.desc.clear(); if (!thisFile.name.empty()) files.push_back(thisFile); @@ -402,7 +402,7 @@ void UpdaterWindow::logic() { case UPDATE_ERROR: // TODO: Only send complete sentences to gettext - mBrowserBox->addRow(""); + mBrowserBox->addRow(std::string()); mBrowserBox->addRow(_("##1 The update process is incomplete.")); // TRANSLATORS: Continues "you try again later.". mBrowserBox->addRow(_("##1 It is strongly recommended that")); diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 166ad102..5975684d 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -120,7 +120,6 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) CHATLOG tmp; tmp.own = own; - tmp.nick = ""; tmp.text = line; std::string::size_type pos = line.find(" : "); @@ -181,7 +180,7 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) lineColor = "##S"; break; case BY_CHANNEL: - tmp.nick = ""; + tmp.nick.clear(); // TODO: Use a predefined color lineColor = "##2"; // Equiv. to BrowserBox::GREEN break; @@ -193,7 +192,7 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) lineColor = "##I"; break; case BY_LOGGER: - tmp.nick = ""; + tmp.nick.clear(); tmp.text = line; lineColor = "##L"; break; @@ -201,7 +200,7 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) if (tmp.nick == ": ") { - tmp.nick = ""; + tmp.nick.clear(); lineColor = "##S"; } diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index 2aaa63f7..c77bf814 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -55,7 +55,7 @@ class Popup : public Container, public gcn::MouseListener * debugging purposes. * @param skin The location where the Popup's skin XML can be found. */ - Popup(const std::string &name = "", + Popup(const std::string &name = std::string(), const std::string &skin = "window.xml"); /** diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h index d7289816..2f9e665f 100644 --- a/src/gui/widgets/progressbar.h +++ b/src/gui/widgets/progressbar.h @@ -116,7 +116,7 @@ class ProgressBar : public gcn::Widget */ static void render(Graphics *graphics, const gcn::Rectangle &area, const gcn::Color &color, float progress, - const std::string &text = ""); + const std::string &text = std::string()); private: float mProgress, mProgressToGo; diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index ac1c22c9..419fa16e 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -112,7 +112,7 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) { mMinWidth = minWidth; wrappedStream.clear(); - wrappedStream.str(""); + wrappedStream.str(std::string()); spacePos = 0; lastNewlinePos = 0; newlinePos = text.find("\n", lastNewlinePos); diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 872227ea..3e1665d3 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -207,14 +207,14 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) } else { - setText(""); + setText(std::string()); mHistory->current = prevHist; } } else if (!getText().empty()) { // Always clear (easy access to useful function) - setText(""); + setText(std::string()); } } break; diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index bb39810b..3b997ba8 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -65,7 +65,7 @@ struct TextHistory class AutoCompleteLister { public: - virtual ~AutoCompleteLister() {} + virtual ~AutoCompleteLister() = default; virtual void getAutoCompleteList(std::vector<std::string>&) const {} }; @@ -80,7 +80,8 @@ class TextField : public gcn::TextField /** * Constructor, initializes the text field with the given string. */ - TextField(const std::string &text = "", bool loseFocusOnTab = true); + TextField(const std::string &text = std::string(), + bool loseFocusOnTab = true); ~TextField() override; /** diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h index 3e01bb36..646e5d00 100644 --- a/src/gui/widgets/windowcontainer.h +++ b/src/gui/widgets/windowcontainer.h @@ -55,9 +55,7 @@ class WindowContainer : public Container /** * List of widgets that are scheduled to be deleted. */ - using Widgets = std::list<gcn::Widget *>; - using WidgetIterator = Widgets::iterator; - Widgets mDeathList; + std::list<gcn::Widget *> mDeathList; }; extern WindowContainer *windowContainer; diff --git a/src/imagesprite.h b/src/imagesprite.h index c9b5175e..ff18e215 100644 --- a/src/imagesprite.h +++ b/src/imagesprite.h @@ -43,7 +43,7 @@ public: bool update(int time) override { return false; } - bool draw(Graphics* graphics, int posX, int posY) const override; + bool draw(Graphics *graphics, int posX, int posY) const override; int getWidth() const override { return mImage->getWidth(); } @@ -51,15 +51,12 @@ public: int getHeight() const override { return mImage->getHeight(); } - const Image* getImage() const override + const Image *getImage() const override { return mImage; } bool setDirection(SpriteDirection direction) override { return false; } - int getNumberOfLayers() - { return 1; } - int getDuration() const override { return 0; } diff --git a/src/item.cpp b/src/item.cpp index d904a0ab..30536df0 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -30,10 +30,8 @@ #include "resources/theme.h" Item::Item(int id, int quantity, bool equipped): - mImage(nullptr), - mDrawImage(nullptr), mQuantity(quantity), - mEquipped(equipped), mInEquipment(false) + mEquipped(equipped) { setId(id); } @@ -120,13 +120,13 @@ class Item const ItemInfo &getInfo() const { return itemDb->get(mId); } protected: - int mId; /**< Item type id. */ - Image *mImage; /**< Item image. */ - Image *mDrawImage; /**< Draw image. */ - int mQuantity; /**< Number of items. */ - bool mEquipped; /**< Item is equipped. */ - bool mInEquipment; /**< Item is in equipment */ - int mInvIndex; /**< Inventory index. */ + int mId; /**< Item type id. */ + Image *mImage = nullptr; /**< Item image. */ + Image *mDrawImage = nullptr; /**< Draw image. */ + int mQuantity; /**< Number of items. */ + bool mEquipped; /**< Item is equipped. */ + bool mInEquipment = false; /**< Item is in equipment */ + int mInvIndex; /**< Inventory index. */ }; #endif // ITEM_H diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 442ec046..a705197a 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -190,7 +190,7 @@ bool KeyboardConfig::hasConflicts() } } } - mBindError = ""; + mBindError.clear(); return false; } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 934155dd..288dfd33 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -920,7 +920,7 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount, if (mMap && config.getBoolValue("showpickupparticle")) { // Show pickup notification - std::string msg = ""; + std::string msg; if (amount > 1) msg = strprintf("%i ", amount); msg += itemInfo.getName(); diff --git a/src/net/download.cpp b/src/net/download.cpp index 38764d8e..dc928d56 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -63,13 +63,7 @@ Download::Download(void *ptr, const std::string &url, DownloadUpdate updateFunction): mPtr(ptr), mUrl(url), - mFileName(""), - mWriteFunction(nullptr), - mUpdateFunction(updateFunction), - mThread(nullptr), - mCurl(nullptr), - mHeaders(nullptr) - + mUpdateFunction(updateFunction) { mError = (char*) malloc(CURL_ERROR_SIZE); mError[0] = 0; diff --git a/src/net/download.h b/src/net/download.h index 3e740b62..500de0b6 100644 --- a/src/net/download.h +++ b/src/net/download.h @@ -94,12 +94,12 @@ class Download unsigned checkAdler: 1; } mOptions; std::string mFileName; - WriteFunction mWriteFunction; + WriteFunction mWriteFunction = nullptr; unsigned long mAdler; DownloadUpdate mUpdateFunction; - SDL_Thread *mThread; - CURL *mCurl; - curl_slist *mHeaders; + SDL_Thread *mThread = nullptr; + CURL *mCurl = nullptr; + curl_slist *mHeaders = nullptr; char *mError; }; diff --git a/src/net/guildhandler.h b/src/net/guildhandler.h index 11ca93b0..00eae99c 100644 --- a/src/net/guildhandler.h +++ b/src/net/guildhandler.h @@ -47,7 +47,7 @@ class GuildHandler virtual void leave(int guildId) = 0; - virtual void kick(GuildMember *member, std::string reason = "") = 0; + virtual void kick(GuildMember *member, std::string reason = std::string()) = 0; virtual void chat(int guildId, const std::string &text) = 0; diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index 4665a70d..61e44506 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -132,7 +132,7 @@ void CharHandler::handleCharacterCreateResponse(MessageIn &msg) if (errMsg != ERRMSG_OK) { // Character creation failed - std::string errorMessage = ""; + std::string errorMessage; switch (errMsg) { case ERRMSG_NO_LOGIN: @@ -213,7 +213,7 @@ void CharHandler::handleCharacterDeleteResponse(MessageIn &msg) else { // Character deletion failed - std::string errorMessage = ""; + std::string errorMessage; switch (errMsg) { case ERRMSG_NO_LOGIN: diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index 6d0b6b4e..ce21eb2f 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -195,7 +195,7 @@ void ChatHandler::handleEnterChannelResponse(MessageIn &msg) while (msg.getUnreadLength()) { user = msg.readString(); - if (user == "") + if (user.empty()) return; userModes = msg.readString(); if (userModes.find('o') != std::string::npos) @@ -218,7 +218,7 @@ void ChatHandler::handleListChannelsResponse(MessageIn &msg) while (msg.getUnreadLength()) { std::string channelName = msg.readString(); - if (channelName == "") + if (channelName.empty()) return; std::ostringstream numUsers; numUsers << msg.readInt16(); @@ -286,7 +286,7 @@ void ChatHandler::handleListChannelUsersResponse(MessageIn &msg) while (msg.getUnreadLength()) { userNick = msg.readString(); - if (userNick == "") + if (userNick.empty()) { break; } @@ -360,7 +360,7 @@ void ChatHandler::handleWhoResponse(MessageIn &msg) while (msg.getUnreadLength()) { userNick = msg.readString(); - if (userNick == "") + if (userNick.empty()) { break; } diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp index aa62dff1..0692ee82 100644 --- a/src/net/manaserv/generalhandler.cpp +++ b/src/net/manaserv/generalhandler.cpp @@ -23,12 +23,8 @@ #include "client.h" -#include "gui/changeemaildialog.h" -#include "gui/charselectdialog.h" #include "gui/inventorywindow.h" -#include "gui/register.h" #include "gui/skilldialog.h" -#include "gui/specialswindow.h" #include "net/manaserv/adminhandler.h" #include "net/manaserv/beinghandler.h" @@ -51,10 +47,6 @@ #include "resources/attributes.h" -#include "utils/gettext.h" - -#include <list> - extern Net::GeneralHandler *generalHandler; extern ManaServ::LoginHandler *loginHandler; @@ -64,7 +56,7 @@ namespace ManaServ { Connection *accountServerConnection = nullptr; Connection *chatServerConnection = nullptr; Connection *gameServerConnection = nullptr; -std::string netToken = ""; +std::string netToken; ServerInfo gameServer; ServerInfo chatServer; diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index be2a5ec8..398e9c62 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -42,8 +42,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include <iostream> - extern Net::GuildHandler *guildHandler; namespace ManaServ { @@ -143,7 +141,7 @@ void GuildHandler::handleMessage(MessageIn &msg) { name = msg.readString(); online = msg.readInt8(); - if (name != "") + if (!name.empty()) { member = guild->addMember(name); member->setOnline(online); diff --git a/src/net/manaserv/guildhandler.h b/src/net/manaserv/guildhandler.h index b14bb203..8fbb15d1 100644 --- a/src/net/manaserv/guildhandler.h +++ b/src/net/manaserv/guildhandler.h @@ -47,7 +47,7 @@ public: void leave(int guildId) override; - void kick(GuildMember *member, std::string reason = "") override; + void kick(GuildMember *member, std::string reason = std::string()) override; void chat(int guildId, const std::string &text) override; diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp index 416e9422..e10c8a9e 100644 --- a/src/net/manaserv/loginhandler.cpp +++ b/src/net/manaserv/loginhandler.cpp @@ -414,7 +414,7 @@ void LoginHandler::loginAccountContinue() msg.writeString(sha256(sha256(sha256(mLoginData->username + mTmpPassword)) + mLoginData->randomSeed)); accountServerConnection->send(msg); - mTmpPassword = ""; + mTmpPassword.clear(); } void LoginHandler::logout() diff --git a/src/net/manaserv/partyhandler.h b/src/net/manaserv/partyhandler.h index ed8a1f25..1462ead8 100644 --- a/src/net/manaserv/partyhandler.h +++ b/src/net/manaserv/partyhandler.h @@ -39,7 +39,7 @@ public: void handleMessage(MessageIn &msg) override; - void create(const std::string &name = "") override; + void create(const std::string &name = std::string()) override; void join(int partyId) override; diff --git a/src/net/partyhandler.h b/src/net/partyhandler.h index d496ffc0..4e14ddbd 100644 --- a/src/net/partyhandler.h +++ b/src/net/partyhandler.h @@ -38,9 +38,9 @@ namespace Net { class PartyHandler { public: - virtual ~PartyHandler() {} + virtual ~PartyHandler() = default; - virtual void create(const std::string &name = "") = 0; + virtual void create(const std::string &name = std::string()) = 0; virtual void join(int partyId) = 0; diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 0d638ac1..de7bf827 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -30,7 +30,7 @@ namespace Net { class PlayerHandler { public: - virtual ~PlayerHandler() {} + virtual ~PlayerHandler() = default; virtual void attack(int id) = 0; diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 4c7e18bb..50585970 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -410,18 +410,6 @@ void BeingHandler::handleMessage(MessageIn &msg) case SMSG_BEING_CHANGE_LOOKS2: { - /* - * SMSG_BEING_CHANGE_LOOKS (0x00c3) and - * SMSG_BEING_CHANGE_LOOKS2 (0x01d7) do basically the same - * thing. The difference is that ...LOOKS carries a single - * 8 bit value, where ...LOOKS2 carries two 16 bit values. - * - * If type = 2, then the first 16 bit value is the weapon ID, - * and the second 16 bit value is the shield ID. If no - * shield is equipped, or type is not 2, then the second - * 16 bit value will be 0. - */ - if (!(dstBeing = actorSpriteManager->findBeing(msg.readInt32()))) { break; @@ -472,7 +460,7 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing->setSprite(SPRITE_MISC2, id); break; default: - logger->log("SMSG_BEING_CHANGE_LOOKS: unsupported type: " + logger->log("SMSG_BEING_CHANGE_LOOKS2: unsupported type: " "%d, id: %d", type, id); break; } @@ -530,12 +518,9 @@ void BeingHandler::handleMessage(MessageIn &msg) break; } - if (Party *party = local_player->getParty()){ + if (Party *party = local_player->getParty()) if (party->isMember(id)) - { dstBeing->setParty(party); - } - } // The original speed is ticks per tile * 10 if (speed) diff --git a/src/net/tmwa/gui/guildtab.cpp b/src/net/tmwa/gui/guildtab.cpp index b5a3203b..6014e507 100644 --- a/src/net/tmwa/gui/guildtab.cpp +++ b/src/net/tmwa/gui/guildtab.cpp @@ -29,13 +29,9 @@ #include "net/net.h" #include "net/guildhandler.h" -#include "resources/iteminfo.h" -#include "resources/itemdb.h" #include "resources/theme.h" -#include "utils/dtor.h" #include "utils/gettext.h" -#include "utils/stringutils.h" namespace TmwAthena { diff --git a/src/net/tmwa/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp index 19f58777..89f3a769 100644 --- a/src/net/tmwa/gui/partytab.cpp +++ b/src/net/tmwa/gui/partytab.cpp @@ -29,11 +29,8 @@ #include "net/net.h" #include "net/partyhandler.h" -#include "resources/iteminfo.h" -#include "resources/itemdb.h" #include "resources/theme.h" -#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" diff --git a/src/net/tmwa/guildhandler.h b/src/net/tmwa/guildhandler.h index 5f8c987c..4cbdd286 100644 --- a/src/net/tmwa/guildhandler.h +++ b/src/net/tmwa/guildhandler.h @@ -46,7 +46,7 @@ class GuildHandler : public Net::GuildHandler, public MessageHandler void leave(int guildId) override; - void kick(GuildMember *member, std::string reason = "") override; + void kick(GuildMember *member, std::string reason = std::string()) override; void chat(int guildId, const std::string &text) override; diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 17c6b53e..b4ba0b20 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -402,21 +402,21 @@ void Network::dispatchMessages() if (mInSize < len) break; -#ifdef DEBUG - logger->log("Received %s (0x%x) of length %d", packetInfo->name, msgId, len); -#endif - MessageIn message(mInBuffer, len); // Dispatch the message to the appropriate handler auto iter = mMessageHandlers.find(msgId); if (iter != mMessageHandlers.end()) { +#ifdef DEBUG + logger->log("Handling %s (0x%x) of length %d", packetInfo->name, msgId, len); +#endif + iter->second->handleMessage(message); } else { - logger->log("Unhandled packet %s (0x%x)", packetInfo->name, msgId); + logger->log("Unhandled %s (0x%x) of length %d", packetInfo->name, msgId, len); } skip(len); diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 958c8c14..3b636c71 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -25,6 +25,7 @@ #include "event.h" #include "localplayer.h" #include "log.h" +#include "party.h" #include "gui/socialwindow.h" diff --git a/src/net/tmwa/partyhandler.h b/src/net/tmwa/partyhandler.h index 5268f395..7b7e2420 100644 --- a/src/net/tmwa/partyhandler.h +++ b/src/net/tmwa/partyhandler.h @@ -27,8 +27,6 @@ #include "net/tmwa/messagehandler.h" -#include "party.h" - namespace TmwAthena { class PartyHandler : public MessageHandler, public Net::PartyHandler @@ -40,7 +38,7 @@ class PartyHandler : public MessageHandler, public Net::PartyHandler void handleMessage(MessageIn &msg) override; - void create(const std::string &name = "") override; + void create(const std::string &name = std::string()) override; void join(int partyId) override; diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 39a2447a..69e857a7 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -309,7 +309,7 @@ void PlayerRelationsManager::setDefault(unsigned int permissions) mDefaultPermissions = permissions; store(); - signalUpdate(""); + signalUpdate(std::string()); } diff --git a/src/properties.h b/src/properties.h index 84b6d184..7ccf86dc 100644 --- a/src/properties.h +++ b/src/properties.h @@ -32,7 +32,7 @@ class Properties { public: - virtual ~Properties() {} + virtual ~Properties() = default; /** * Get a map property. @@ -43,7 +43,7 @@ class Properties * doesn't exist. */ std::string getProperty(const std::string &name, - const std::string &def = "") const + const std::string &def = std::string()) const { auto i = mProperties.find(name); return (i != mProperties.end()) ? i->second : def; diff --git a/src/resources/attributes.cpp b/src/resources/attributes.cpp index 82871b2f..a9a3bd11 100644 --- a/src/resources/attributes.cpp +++ b/src/resources/attributes.cpp @@ -162,7 +162,6 @@ namespace Attributes { Attribute a; a.id = 16; a.name = _("Strength"); - a.description = ""; a.modifiable = true; a.scope = "character"; a.playerInfoId = -1; @@ -175,7 +174,6 @@ namespace Attributes { Attribute a; a.id = 17; a.name = _("Agility"); - a.description = ""; a.modifiable = true; a.scope = "character"; a.playerInfoId = -1; @@ -188,7 +186,6 @@ namespace Attributes { Attribute a; a.id = 18; a.name = _("Dexterity"); - a.description = ""; a.modifiable = true; a.scope = "character"; a.playerInfoId = -1; @@ -201,7 +198,6 @@ namespace Attributes { Attribute a; a.id = 19; a.name = _("Vitality"); - a.description = ""; a.modifiable = true; a.scope = "character"; a.playerInfoId = -1; @@ -214,7 +210,6 @@ namespace Attributes { Attribute a; a.id = 20; a.name = _("Intelligence"); - a.description = ""; a.modifiable = true; a.scope = "character"; a.playerInfoId = -1; @@ -227,7 +222,6 @@ namespace Attributes { Attribute a; a.id = 21; a.name = _("Willpower"); - a.description = ""; a.modifiable = true; a.scope = "character"; a.playerInfoId = -1; diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index b044e7b6..dff3f2a0 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -35,7 +35,7 @@ class ImageSet; struct SpriteReference { - SpriteReference() {} + SpriteReference() = default; SpriteReference(std::string sprite, int variant): sprite(sprite), @@ -77,7 +77,7 @@ namespace SpriteAction static const std::string USE_SPECIAL = "special"; static const std::string CAST_MAGIC = "magic"; static const std::string USE_ITEM = "item"; - static const std::string INVALID = ""; + static const std::string INVALID; } enum SpriteDirection @@ -121,7 +121,7 @@ class SpriteDef : public Resource * Loads a sprite element. */ void loadSprite(xmlNodePtr spriteNode, int variant, - const std::string &palettes = ""); + const std::string &palettes = std::string()); /** * Loads an imageset element. diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index 8c758280..4686edf1 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -532,7 +532,7 @@ void Theme::loadColors(std::string file) if (file == defaultThemePath) return; // No need to reload - if (file == "") + if (file.empty()) file = defaultThemePath; file += "/colors.xml"; diff --git a/src/resources/theme.h b/src/resources/theme.h index 9e7c4c3e..ae795ed4 100644 --- a/src/resources/theme.h +++ b/src/resources/theme.h @@ -42,7 +42,7 @@ class Skin public: Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown, const std::string &filePath, - const std::string &name = ""); + const std::string &name = std::string()); ~Skin(); @@ -209,7 +209,7 @@ class Theme : public Palette, public EventListener /** * Get the minimum opacity allowed to skins. */ - float getMinimumOpacity() + float getMinimumOpacity() const { return mMinimumOpacity; } /** @@ -237,7 +237,7 @@ class Theme : public Palette, public EventListener static bool tryThemePath(std::string themePath); - void loadColors(std::string file = ""); + void loadColors(std::string file = std::string()); /** * Tells if the current skins opacity diff --git a/src/sprite.h b/src/sprite.h index 3af6eb7c..8eb366d6 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -32,7 +32,7 @@ const int DEFAULT_FRAME_DELAY = 75; class Sprite { public: - virtual ~Sprite() {} + virtual ~Sprite() = default; /** * Resets the sprite. @@ -114,7 +114,7 @@ class Sprite virtual int getDuration() const = 0; protected: - float mAlpha; /**< The alpha opacity used to draw */ + float mAlpha = 1.0f; /**< The alpha opacity used to draw */ }; #endif // SPRITE_H diff --git a/src/units.cpp b/src/units.cpp index 1487eb21..03ec3118 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -26,7 +26,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -#include <cmath> #include <climits> #include <vector> @@ -37,7 +36,7 @@ struct UnitLevel { }; struct UnitDescription { - std::vector<struct UnitLevel> levels; + std::vector<UnitLevel> levels; double conversion; bool mix; }; @@ -48,25 +47,25 @@ enum UnitType { UNIT_END }; -struct UnitDescription units[UNIT_END]; +UnitDescription units[UNIT_END]; void Units::init() { { // Setup default weight - struct UnitDescription ud; + UnitDescription ud; ud.conversion = 1.0; ud.mix = false; - struct UnitLevel bu; + UnitLevel bu; bu.symbol = "g"; bu.count = 1; bu.round = 0; ud.levels.push_back(bu); - struct UnitLevel ul; + UnitLevel ul; ul.symbol = "kg"; ul.count = 1000; ul.round = 2; @@ -77,12 +76,12 @@ void Units::init() } { // Setup default currency - struct UnitDescription ud; + UnitDescription ud; ud.conversion = 1.0; ud.mix = false; - struct UnitLevel bu; + UnitLevel bu; bu.symbol = "¤"; bu.count = 1; bu.round = 0; @@ -95,13 +94,13 @@ void Units::init() void Units::readUnitNode(xmlNodePtr node, const std::string &filename) { - struct UnitDescription ud; + UnitDescription ud; int level = 1; const std::string type = XML::getProperty(node, "type", ""); ud.conversion = XML::getProperty(node, "conversion", 1); ud.mix = XML::getProperty(node, "mix", "no") == "yes"; - struct UnitLevel bu; + UnitLevel bu; bu.symbol = XML::getProperty(node, "base", "¤"); bu.count = 1; bu.round = XML::getProperty(node, "round", 2); @@ -112,7 +111,7 @@ void Units::readUnitNode(xmlNodePtr node, const std::string &filename) { if (xmlStrEqual(uLevel->name, BAD_CAST "level")) { - struct UnitLevel ul; + UnitLevel ul; ul.symbol = XML::getProperty(uLevel, "symbol", strprintf("¤%d",level)); ul.count = XML::getProperty(uLevel, "count", -1); @@ -132,13 +131,10 @@ void Units::readUnitNode(xmlNodePtr node, const std::string &filename) } // Add one more level for saftey - struct UnitLevel ll; - ll.symbol = ""; + UnitLevel &ll = ud.levels.emplace_back(); ll.count = INT_MAX; ll.round = 0; - ud.levels.push_back(ll); - if (type == "weight") units[UNIT_WEIGHT] = ud; else if (type == "currency") @@ -150,13 +146,12 @@ void Units::readUnitNode(xmlNodePtr node, const std::string &filename) void Units::checkStatus() { - } std::string formatUnit(int value, int type) { - struct UnitDescription ud = units[type]; - struct UnitLevel ul; + UnitDescription ud = units[type]; + UnitLevel ul; // Shortcut for 0; do the same for values less than 0 (for now) if (value <= 0) @@ -164,62 +159,59 @@ std::string formatUnit(int value, int type) ul = ud.levels[0]; return strprintf("0%s", ul.symbol.c_str()); } - else - { - double amount = ud.conversion * value; - // If only the first level is needed, act like mix if false - if (ud.mix && ud.levels.size() > 0 && ud.levels[1].count < amount) - { - std::string output; - struct UnitLevel pl = ud.levels[0]; - ul = ud.levels[1]; - int levelAmount = (int) amount; - int nextAmount; + double amount = ud.conversion * value; - levelAmount /= ul.count; + // If only the first level is needed, act like mix if false + if (ud.mix && !ud.levels.empty() && ud.levels[1].count < amount) + { + std::string output; + UnitLevel pl = ud.levels[0]; + ul = ud.levels[1]; + int levelAmount = (int) amount; + int nextAmount; - amount -= levelAmount * ul.count; + levelAmount /= ul.count; - if (amount > 0) - { - output = strprintf("%.*f%s", pl.round, amount, - pl.symbol.c_str()); - } + amount -= levelAmount * ul.count; - for (unsigned int i = 2; i < ud.levels.size(); i++) - { - pl = ul; - ul = ud.levels[i]; + if (amount > 0) + { + output = strprintf("%.*f%s", pl.round, amount, + pl.symbol.c_str()); + } - nextAmount = levelAmount / ul.count; - levelAmount %= ul.count; + for (unsigned int i = 2; i < ud.levels.size(); i++) + { + pl = ul; + ul = ud.levels[i]; - if (levelAmount > 0) output = strprintf("%d%s", - levelAmount, pl.symbol.c_str()) + output; + nextAmount = levelAmount / ul.count; + levelAmount %= ul.count; - if (!nextAmount) break; - levelAmount = nextAmount; - } + if (levelAmount > 0) output = strprintf("%d%s", + levelAmount, pl.symbol.c_str()) + output; - return output; + if (!nextAmount) + break; + levelAmount = nextAmount; } - else - { - for (unsigned int i = 0; i < ud.levels.size(); i++) - { - ul = ud.levels[i]; - if (amount < ul.count && ul.count > 0) - { - ul = ud.levels[i - 1]; - break; - } - amount /= ul.count; - } - return strprintf("%.*f%s", ul.round, amount, ul.symbol.c_str()); + return output; + } + + for (unsigned int i = 0; i < ud.levels.size(); i++) + { + ul = ud.levels[i]; + if (amount < ul.count && ul.count > 0) + { + ul = ud.levels[i - 1]; + break; } + amount /= ul.count; } + + return strprintf("%.*f%s", ul.round, amount, ul.symbol.c_str()); } std::string Units::formatCurrency(int value) diff --git a/src/utils/path.cpp b/src/utils/path.cpp index 95db40d3..c78f0fd7 100644 --- a/src/utils/path.cpp +++ b/src/utils/path.cpp @@ -75,10 +75,8 @@ namespace utils { return path1 + path2; } - else - { - return path1 + "/" + path2; - } + + return path1 + "/" + path2; } /** @@ -86,14 +84,14 @@ namespace utils */ std::string cleanPath(const std::string &path) { - size_t prev, cur; - std::string part, result; + std::string part; + std::string result; std::vector<std::string> pathStack; - prev = 0; + size_t prev = 0; while (true) { - cur = path.find_first_of("/\\", prev); + size_t cur = path.find_first_of("/\\", prev); if (cur == std::string::npos) { // FIXME add everything from prev to the end @@ -114,12 +112,12 @@ namespace utils { // do nothing } - else if (part == "") + else if (part.empty()) { if (pathStack.empty() && cur == 0) { // handle first empty match before the root slash - pathStack.push_back(std::string()); + pathStack.emplace_back(); } else { diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp index a18e5f18..0e44af7a 100644 --- a/src/utils/sha256.cpp +++ b/src/utils/sha256.cpp @@ -264,7 +264,7 @@ std::string SHA256Hash(const char *src, int len) SHA256Final(&ctx, bytehash); // Convert it to hex const char* hxc = "0123456789abcdef"; - std::string hash = ""; + std::string hash; for (unsigned char i : bytehash) { hash += hxc[i / 16]; diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 57138005..32fc3b0c 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -187,8 +187,8 @@ bool getBoolFromString(const std::string &text, bool def) return true; if (a == "false" || a == "0" || a == "off" || a == "no" || a == "n") return false; - else - return def; + + return def; } std::string autocomplete(const std::vector<std::string> &candidates, @@ -196,7 +196,7 @@ std::string autocomplete(const std::vector<std::string> &candidates, { auto i = candidates.begin(); toLower(base); - std::string newName(""); + std::string newName; while (i != candidates.end()) { @@ -208,7 +208,7 @@ std::string autocomplete(const std::vector<std::string> &candidates, std::string::size_type pos = name.find(base, 0); if (pos == 0) { - if (newName != "") + if (!newName.empty()) { toLower(newName); newName = findSameSubstring(name, newName); |