diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-14 01:46:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-14 01:52:42 +0300 |
commit | c0a5fffb45f849e224750f27fa8c3be5ac447ad6 (patch) | |
tree | 1fcac5e9836e119970acae9c5702ac83f40a935f /src/party.cpp | |
parent | 1c62988a9e7ed1038250a2d044889eda046500c5 (diff) | |
download | manaverse-c0a5fffb45f849e224750f27fa8c3be5ac447ad6.tar.gz manaverse-c0a5fffb45f849e224750f27fa8c3be5ac447ad6.tar.bz2 manaverse-c0a5fffb45f849e224750f27fa8c3be5ac447ad6.tar.xz manaverse-c0a5fffb45f849e224750f27fa8c3be5ac447ad6.zip |
Add more checks.
Fix error in event.cpp from last commits.
Improve party members sorting.
Diffstat (limited to 'src/party.cpp')
-rw-r--r-- | src/party.cpp | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/src/party.cpp b/src/party.cpp index 9da1a235d..f561ca49f 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -25,6 +25,8 @@ #include "debug.h" +#include "utils/stringutils.h" + class SortPartyFunctor { public: @@ -37,7 +39,15 @@ class SortPartyFunctor if (p2->getLeader()) return false; - return p1->getName() < p2->getName(); + if (p1->getName() != p2->getName()) + { + std::string s1 = p1->getName(); + std::string s2 = p2->getName(); + toLower(s1); + toLower(s2); + return s1 < s2; + } + return false; } } partySorter; @@ -94,7 +104,7 @@ PartyMember *Party::getMember(const std::string &name) const itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->getName() == name) + if ((*itr) && (*itr)->getName() == name) return (*itr); ++itr; @@ -116,7 +126,7 @@ void Party::removeMember(PartyMember *member) itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->mId == member->mId && + if ((*itr) && (*itr)->mId == member->mId && (*itr)->getName() == member->getName()) { PartyMember *m = (*itr); @@ -140,7 +150,7 @@ void Party::removeMember(int id) itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->mId == id) + if ((*itr) && (*itr)->mId == id) { PartyMember *member = (*itr); mMembers.erase(itr); @@ -163,7 +173,7 @@ void Party::removeMember(const std::string &name) itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->getName() == name) + if ((*itr) && (*itr)->getName() == name) { PartyMember *member = (*itr); mMembers.erase(itr); @@ -213,11 +223,11 @@ bool Party::isMember(PartyMember *member) const if (member->mParty > 0 && member->mParty != this) return false; - MemberList::const_iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::const_iterator itr = mMembers.begin(); + MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->mId == member->mId && + if ((*itr) && (*itr)->mId == member->mId && (*itr)->getName() == member->getName()) { return true; @@ -230,11 +240,11 @@ bool Party::isMember(PartyMember *member) const bool Party::isMember(int id) const { - MemberList::const_iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::const_iterator itr = mMembers.begin(); + MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->mId == id) + if ((*itr) && (*itr)->mId == id) return true; ++itr; } @@ -244,11 +254,11 @@ bool Party::isMember(int id) const bool Party::isMember(const std::string &name) const { - MemberList::const_iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::const_iterator itr = mMembers.begin(); + MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->getName() == name) + if ((*itr) && (*itr)->getName() == name) return true; ++itr; } @@ -259,11 +269,12 @@ bool Party::isMember(const std::string &name) const void Party::getNames(std::vector<std::string> &names) const { names.clear(); - MemberList::const_iterator it = mMembers.begin(), - it_end = mMembers.end(); + MemberList::const_iterator it = mMembers.begin(); + MemberList::const_iterator it_end = mMembers.end(); while (it != it_end) { - names.push_back((*it)->getName()); + if (*it) + names.push_back((*it)->getName()); ++it; } } @@ -271,11 +282,12 @@ void Party::getNames(std::vector<std::string> &names) const void Party::getNamesSet(std::set<std::string> &names) const { names.clear(); - MemberList::const_iterator it = mMembers.begin(), - it_end = mMembers.end(); + MemberList::const_iterator it = mMembers.begin(); + MemberList::const_iterator it_end = mMembers.end(); while (it != it_end) { - names.insert((*it)->getName()); + if (*it) + names.insert((*it)->getName()); ++it; } } |