summaryrefslogtreecommitdiff
path: root/src/guild.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-11-07 11:47:24 -0700
committerJared Adams <jaxad0127@gmail.com>2009-11-07 11:47:24 -0700
commit99be9859a30e84e758ee3bfe7dcc3de33dfa2391 (patch)
tree49354012582a4c9e9218ebafad429b07b19b2539 /src/guild.cpp
parent9c1cc1e46fd21ec48809fbb8f64853fcecef2439 (diff)
downloadmana-99be9859a30e84e758ee3bfe7dcc3de33dfa2391.tar.gz
mana-99be9859a30e84e758ee3bfe7dcc3de33dfa2391.tar.bz2
mana-99be9859a30e84e758ee3bfe7dcc3de33dfa2391.tar.xz
mana-99be9859a30e84e758ee3bfe7dcc3de33dfa2391.zip
More eAthena guild stuff
Also some related chenges elsewhere
Diffstat (limited to 'src/guild.cpp')
-rw-r--r--src/guild.cpp176
1 files changed, 163 insertions, 13 deletions
diff --git a/src/guild.cpp b/src/guild.cpp
index be4a5204..3b30ec23 100644
--- a/src/guild.cpp
+++ b/src/guild.cpp
@@ -21,30 +21,114 @@
#include "guild.h"
-Guild::Guild(short id, short rights):
+GuildMember::GuildMember(int guildId, int id, const std::string &name):
+ mName(name), mId(id), mOnline(false)
+{
+ mGuild = Guild::getGuild(guildId);
+};
+
+GuildMember::GuildMember(int guildId, int id):
+ mId(id), mOnline(false)
+{
+ mGuild = Guild::getGuild(guildId);
+};
+
+GuildMember::GuildMember(int guildId, const std::string &name):
+ mName(name), mId(0), mOnline(false)
+{
+ mGuild = Guild::getGuild(guildId);
+};
+
+Guild::GuildMap Guild::guilds;
+
+Guild::Guild(short id):
mId(id),
mCanInviteUsers(false)
{
- // to invite, rights must be greater than 0
- if (rights > 0)
- mCanInviteUsers = true;
+ guilds[id] = this;
}
-void Guild::addMember(const std::string &name)
+void Guild::addMember(GuildMember *member)
{
- if (!isMember(name))
+ if (member->mGuild > 0 && member->mGuild != this)
+ {
+ throw "Member in another guild!";
+ }
+
+ if (!isMember(member))
{
- mMembers.push_back(name);
+ mMembers.push_back(member);
+ member->mGuild = this;
+ }
+}
+
+GuildMember *Guild::getMember(int id)
+{
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while(itr != itr_end)
+ {
+ if((*itr)->mId == id)
+ {
+ return (*itr);
+ }
+ ++itr;
+ }
+
+ return NULL;
+}
+
+GuildMember *Guild::getMember(std::string name)
+{
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while(itr != itr_end)
+ {
+ if((*itr)->mName == name)
+ {
+ return (*itr);
+ }
+ ++itr;
+ }
+
+ return NULL;
+}
+
+void Guild::removeMember(GuildMember *member)
+{
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while(itr != itr_end)
+ {
+ if((*itr)->mId == member->mId && (*itr)->mName == member->mName)
+ {
+ mMembers.erase(itr);
+ }
+ ++itr;
+ }
+}
+
+void Guild::removeMember(int id)
+{
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while(itr != itr_end)
+ {
+ if((*itr)->mId == id)
+ {
+ mMembers.erase(itr);
+ }
+ ++itr;
}
}
void Guild::removeMember(const std::string &name)
{
- std::vector<std::string>::iterator itr = mMembers.begin(),
- itr_end = mMembers.end();
+ MemberList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
while(itr != itr_end)
{
- if((*itr) == name)
+ if((*itr)->mName == name)
{
mMembers.erase(itr);
}
@@ -52,13 +136,70 @@ void Guild::removeMember(const std::string &name)
}
}
+std::string Guild::getElementAt(int index)
+{
+ GuildMember *m = mMembers[index];
+ if (m->mOnline)
+ {
+ return "* " + m->mName;
+ }
+ else
+ {
+ return m->mName;
+ }
+}
+
+void Guild::setRights(short rights)
+{
+ // to invite, rights must be greater than 0
+ if (rights > 0)
+ {
+ mCanInviteUsers = true;
+ }
+}
+
+bool Guild::isMember(GuildMember *member) const
+{
+ if (member->mGuild > 0 && member->mGuild != this)
+ return false;
+
+ MemberList::const_iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while (itr != itr_end)
+ {
+ if ((*itr)->mId == member->mId && (*itr)->mName == member->mName)
+ {
+ return true;
+ }
+ ++itr;
+ }
+
+ return false;
+}
+
+bool Guild::isMember(int id) const
+{
+ MemberList::const_iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
+ while (itr != itr_end)
+ {
+ if ((*itr)->mId == id)
+ {
+ return true;
+ }
+ ++itr;
+ }
+
+ return false;
+}
+
bool Guild::isMember(const std::string &name) const
{
- std::vector<std::string>::const_iterator itr = mMembers.begin(),
- itr_end = mMembers.end();
+ MemberList::const_iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr) == name)
+ if ((*itr)->mName == name)
{
return true;
}
@@ -67,3 +208,12 @@ bool Guild::isMember(const std::string &name) const
return false;
}
+
+Guild *Guild::getGuild(int id)
+{
+ GuildMap::iterator it = guilds.find(id);
+ if (it != guilds.end())
+ return it->second;
+
+ return new Guild(id);
+}