diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-09 09:47:21 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-13 12:57:16 +0100 |
commit | c70be70cab3615cb36cc5f244671cf5d39f1fda8 (patch) | |
tree | b15e68552ffd6adda832a9ae5d38160ef8299d7f /src/guild.cpp | |
parent | 717eb07c0d51098e319059883b11ba6e2bf4cbb8 (diff) | |
download | mana-c70be70cab3615cb36cc5f244671cf5d39f1fda8.tar.gz mana-c70be70cab3615cb36cc5f244671cf5d39f1fda8.tar.bz2 mana-c70be70cab3615cb36cc5f244671cf5d39f1fda8.tar.xz mana-c70be70cab3615cb36cc5f244671cf5d39f1fda8.zip |
General code cleanups
* Removing unused includes
* Use member initialization
* Use range-based for loops
* Use nullptr
* Removed no longer used aliases
* Use override
* Don't use else after return
* Use '= delete' to remove implicit members
* Use std::string::empty instead of comparing to ""
Diffstat (limited to 'src/guild.cpp')
-rw-r--r-- | src/guild.cpp | 105 |
1 files changed, 28 insertions, 77 deletions
diff --git a/src/guild.cpp b/src/guild.cpp index f21f015a..a6f783d4 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -24,20 +24,19 @@ #include "actorspritemanager.h" GuildMember::GuildMember(Guild *guild, int id, const std::string &name): - Avatar(name), mId(id), mGuild(guild) + Avatar(name), mId(id), mGuild(guild) { } GuildMember::GuildMember(Guild *guild, const std::string &name): - Avatar(name), mId(0), mGuild(guild) + Avatar(name), mGuild(guild) { } Guild::GuildMap Guild::guilds; Guild::Guild(short id): - mId(id), - mCanInviteUsers(false) + mId(id) { guilds[id] = this; } @@ -74,84 +73,63 @@ GuildMember *Guild::addMember(const std::string &name) GuildMember *Guild::getMember(int id) const { - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while (itr != itr_end) - { - if ((*itr)->mId == id) - return (*itr); - ++itr; - } + for (auto member : mMembers) + if (member->mId == id) + return member; return nullptr; } GuildMember *Guild::getMember(const std::string &name) const { - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while (itr != itr_end) - { - if ((*itr)->getName() == name) - { - return (*itr); - } - ++itr; - } + for (auto member : mMembers) + if (member->getName() == name) + return member; return nullptr; } void Guild::removeMember(GuildMember *member) { - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while (itr != itr_end) + for (auto itr = mMembers.begin(), itr_end = mMembers.end(); + itr != itr_end; ++itr) { - if((*itr)->mId == member->mId && - (*itr)->getName() == member->getName()) + if ((*itr)->mId == member->mId && + (*itr)->getName() == member->getName()) { mMembers.erase(itr); } - ++itr; } } void Guild::removeMember(int id) { - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while (itr != itr_end) + for (auto itr = mMembers.begin(), itr_end = mMembers.end(); + itr != itr_end; ++itr) { if ((*itr)->mId == id) mMembers.erase(itr); - ++itr; } } void Guild::removeMember(const std::string &name) { - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while (itr != itr_end) + for (auto itr = mMembers.begin(), itr_end = mMembers.end(); + itr != itr_end; ++itr) { - if((*itr)->getName() == name) + if ((*itr)->getName() == name) { mMembers.erase(itr); } - ++itr; } } void Guild::removeFromMembers() { - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while(itr != itr_end) + for (auto member : mMembers) { - Being *b = actorSpriteManager->findBeing((*itr)->getID()); + Being *b = actorSpriteManager->findBeing(member->getID()); b->removeGuild(getId()); - ++itr; } } @@ -172,16 +150,13 @@ bool Guild::isMember(GuildMember *member) const if (member->mGuild != nullptr && member->mGuild != this) return false; - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while (itr != itr_end) + for (auto mMember : mMembers) { - if ((*itr)->mId == member->mId && - (*itr)->getName() == member->getName()) + if (mMember->mId == member->mId && + mMember->getName() == member->getName()) { return true; } - ++itr; } return false; @@ -189,44 +164,20 @@ bool Guild::isMember(GuildMember *member) const bool Guild::isMember(int id) const { - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while (itr != itr_end) - { - if ((*itr)->mId == id) - return true; - ++itr; - } - - return false; + return getMember(id) != nullptr; } bool Guild::isMember(const std::string &name) const { - auto itr = mMembers.begin(), - itr_end = mMembers.end(); - while (itr != itr_end) - { - if ((*itr)->getName() == name) - { - return true; - } - ++itr; - } - - return false; + return getMember(name) != nullptr; } void Guild::getNames(std::vector<std::string> &names) const { names.clear(); - auto it = mMembers.begin(), - it_end = mMembers.end(); - while (it != it_end) - { - names.push_back((*it)->getName()); - ++it; - } + + for (auto member : mMembers) + names.push_back(member->getName()); } Guild *Guild::getGuild(int id) |